74a15ef8f1c09a33bbe1e72320ee74a544d75acd
[dpdk.git] / drivers / net / qede / base / ecore_dev_api.h
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #ifndef __ECORE_DEV_API_H__
10 #define __ECORE_DEV_API_H__
11
12 #include "ecore_status.h"
13 #include "ecore_chain.h"
14 #include "ecore_int_api.h"
15
16 /**
17  * @brief ecore_init_dp - initialize the debug level
18  *
19  * @param p_dev
20  * @param dp_module
21  * @param dp_level
22  * @param dp_ctx
23  */
24 void ecore_init_dp(struct ecore_dev *p_dev,
25                    u32 dp_module,
26                    u8 dp_level,
27                    void *dp_ctx);
28
29 /**
30  * @brief ecore_init_struct - initialize the device structure to
31  *        its defaults
32  *
33  * @param p_dev
34  */
35 void ecore_init_struct(struct ecore_dev *p_dev);
36
37 /**
38  * @brief ecore_resc_free -
39  *
40  * @param p_dev
41  */
42 void ecore_resc_free(struct ecore_dev *p_dev);
43
44 /**
45  * @brief ecore_resc_alloc -
46  *
47  * @param p_dev
48  *
49  * @return enum _ecore_status_t
50  */
51 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev);
52
53 /**
54  * @brief ecore_resc_setup -
55  *
56  * @param p_dev
57  */
58 void ecore_resc_setup(struct ecore_dev *p_dev);
59
60 struct ecore_hw_init_params {
61         /* tunnelling parameters */
62         struct ecore_tunn_start_params *p_tunn;
63         bool b_hw_start;
64         /* interrupt mode [msix, inta, etc.] to use */
65         enum ecore_int_mode int_mode;
66 /* npar tx switching to be used for vports configured for tx-switching */
67
68         bool allow_npar_tx_switch;
69         /* binary fw data pointer in binary fw file */
70         const u8 *bin_fw_data;
71 };
72
73 /**
74  * @brief ecore_hw_init -
75  *
76  * @param p_dev
77  * @param p_params
78  *
79  * @return enum _ecore_status_t
80  */
81 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
82                                    struct ecore_hw_init_params *p_params);
83
84 /**
85  * @brief ecore_hw_timers_stop_all -
86  *
87  * @param p_dev
88  *
89  * @return void
90  */
91 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev);
92
93 /**
94  * @brief ecore_hw_stop -
95  *
96  * @param p_dev
97  *
98  * @return enum _ecore_status_t
99  */
100 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev);
101
102 /**
103  * @brief ecore_hw_stop_fastpath -should be called incase
104  *        slowpath is still required for the device,
105  *        but fastpath is not.
106  *
107  * @param p_dev
108  *
109  */
110 void ecore_hw_stop_fastpath(struct ecore_dev *p_dev);
111
112 #ifndef LINUX_REMOVE
113 /**
114  * @brief ecore_prepare_hibernate -should be called when
115  *        the system is going into the hibernate state
116  *
117  * @param p_dev
118  *
119  */
120 void ecore_prepare_hibernate(struct ecore_dev *p_dev);
121 #endif
122
123 /**
124  * @brief ecore_hw_start_fastpath -restart fastpath traffic,
125  *        only if hw_stop_fastpath was called
126
127  * @param p_dev
128  *
129  */
130 void ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn);
131
132 /**
133  * @brief ecore_hw_reset -
134  *
135  * @param p_dev
136  *
137  * @return enum _ecore_status_t
138  */
139 enum _ecore_status_t ecore_hw_reset(struct ecore_dev *p_dev);
140
141 enum ecore_hw_prepare_result {
142         ECORE_HW_PREPARE_SUCCESS,
143
144         /* FAILED results indicate probe has failed & cleaned up */
145         ECORE_HW_PREPARE_FAILED_ENG2,
146         ECORE_HW_PREPARE_FAILED_ME,
147         ECORE_HW_PREPARE_FAILED_MEM,
148         ECORE_HW_PREPARE_FAILED_DEV,
149         ECORE_HW_PREPARE_FAILED_NVM,
150
151         /* BAD results indicate probe is passed even though some wrongness
152          * has occurred; Trying to actually use [I.e., hw_init()] might have
153          * dire reprecautions.
154          */
155         ECORE_HW_PREPARE_BAD_IOV,
156         ECORE_HW_PREPARE_BAD_MCP,
157         ECORE_HW_PREPARE_BAD_IGU,
158 };
159
160 struct ecore_hw_prepare_params {
161         /* Personality to initialize */
162         int personality;
163
164         /* Force the driver's default resource allocation */
165         bool drv_resc_alloc;
166
167         /* Check the reg_fifo after any register access */
168         bool chk_reg_fifo;
169
170         /* Request the MFW to initiate PF FLR */
171         bool initiate_pf_flr;
172
173         /* The OS Epoch time in seconds */
174         u32 epoch;
175
176         /* Allow prepare to pass even if some initializations are failing.
177          * If set, the `p_prepare_res' field would be set with the return,
178          * and might allow probe to pass even if there are certain issues.
179          */
180         bool b_relaxed_probe;
181         enum ecore_hw_prepare_result p_relaxed_res;
182 };
183
184 /**
185  * @brief ecore_hw_prepare -
186  *
187  * @param p_dev
188  * @param p_params
189  *
190  * @return enum _ecore_status_t
191  */
192 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
193                                       struct ecore_hw_prepare_params *p_params);
194
195 /**
196  * @brief ecore_hw_remove -
197  *
198  * @param p_dev
199  */
200 void ecore_hw_remove(struct ecore_dev *p_dev);
201
202 /**
203  * @brief ecore_ptt_acquire - Allocate a PTT window
204  *
205  * Should be called at the entry point to the driver (at the beginning of an
206  * exported function)
207  *
208  * @param p_hwfn
209  *
210  * @return struct ecore_ptt
211  */
212 struct ecore_ptt *ecore_ptt_acquire(struct ecore_hwfn *p_hwfn);
213
214 /**
215  * @brief ecore_ptt_release - Release PTT Window
216  *
217  * Should be called at the end of a flow - at the end of the function that
218  * acquired the PTT.
219  *
220  *
221  * @param p_hwfn
222  * @param p_ptt
223  */
224 void ecore_ptt_release(struct ecore_hwfn *p_hwfn,
225                        struct ecore_ptt *p_ptt);
226
227 #ifndef __EXTRACT__LINUX__
228 struct ecore_eth_stats {
229         u64 no_buff_discards;
230         u64 packet_too_big_discard;
231         u64 ttl0_discard;
232         u64 rx_ucast_bytes;
233         u64 rx_mcast_bytes;
234         u64 rx_bcast_bytes;
235         u64 rx_ucast_pkts;
236         u64 rx_mcast_pkts;
237         u64 rx_bcast_pkts;
238         u64 mftag_filter_discards;
239         u64 mac_filter_discards;
240         u64 tx_ucast_bytes;
241         u64 tx_mcast_bytes;
242         u64 tx_bcast_bytes;
243         u64 tx_ucast_pkts;
244         u64 tx_mcast_pkts;
245         u64 tx_bcast_pkts;
246         u64 tx_err_drop_pkts;
247         u64 tpa_coalesced_pkts;
248         u64 tpa_coalesced_events;
249         u64 tpa_aborts_num;
250         u64 tpa_not_coalesced_pkts;
251         u64 tpa_coalesced_bytes;
252
253         /* port */
254         u64 rx_64_byte_packets;
255         u64 rx_65_to_127_byte_packets;
256         u64 rx_128_to_255_byte_packets;
257         u64 rx_256_to_511_byte_packets;
258         u64 rx_512_to_1023_byte_packets;
259         u64 rx_1024_to_1518_byte_packets;
260         u64 rx_1519_to_1522_byte_packets;
261         u64 rx_1519_to_2047_byte_packets;
262         u64 rx_2048_to_4095_byte_packets;
263         u64 rx_4096_to_9216_byte_packets;
264         u64 rx_9217_to_16383_byte_packets;
265         u64 rx_crc_errors;
266         u64 rx_mac_crtl_frames;
267         u64 rx_pause_frames;
268         u64 rx_pfc_frames;
269         u64 rx_align_errors;
270         u64 rx_carrier_errors;
271         u64 rx_oversize_packets;
272         u64 rx_jabbers;
273         u64 rx_undersize_packets;
274         u64 rx_fragments;
275         u64 tx_64_byte_packets;
276         u64 tx_65_to_127_byte_packets;
277         u64 tx_128_to_255_byte_packets;
278         u64 tx_256_to_511_byte_packets;
279         u64 tx_512_to_1023_byte_packets;
280         u64 tx_1024_to_1518_byte_packets;
281         u64 tx_1519_to_2047_byte_packets;
282         u64 tx_2048_to_4095_byte_packets;
283         u64 tx_4096_to_9216_byte_packets;
284         u64 tx_9217_to_16383_byte_packets;
285         u64 tx_pause_frames;
286         u64 tx_pfc_frames;
287         u64 tx_lpi_entry_count;
288         u64 tx_total_collisions;
289         u64 brb_truncates;
290         u64 brb_discards;
291         u64 rx_mac_bytes;
292         u64 rx_mac_uc_packets;
293         u64 rx_mac_mc_packets;
294         u64 rx_mac_bc_packets;
295         u64 rx_mac_frames_ok;
296         u64 tx_mac_bytes;
297         u64 tx_mac_uc_packets;
298         u64 tx_mac_mc_packets;
299         u64 tx_mac_bc_packets;
300         u64 tx_mac_ctrl_frames;
301 };
302 #endif
303
304 enum ecore_dmae_address_type_t {
305         ECORE_DMAE_ADDRESS_HOST_VIRT,
306         ECORE_DMAE_ADDRESS_HOST_PHYS,
307         ECORE_DMAE_ADDRESS_GRC
308 };
309
310 /* value of flags If ECORE_DMAE_FLAG_RW_REPL_SRC flag is set and the
311  * source is a block of length DMAE_MAX_RW_SIZE and the
312  * destination is larger, the source block will be duplicated as
313  * many times as required to fill the destination block. This is
314  * used mostly to write a zeroed buffer to destination address
315  * using DMA
316  */
317 #define ECORE_DMAE_FLAG_RW_REPL_SRC     0x00000001
318 #define ECORE_DMAE_FLAG_VF_SRC          0x00000002
319 #define ECORE_DMAE_FLAG_VF_DST          0x00000004
320 #define ECORE_DMAE_FLAG_COMPLETION_DST  0x00000008
321
322 struct ecore_dmae_params {
323         u32 flags; /* consists of ECORE_DMAE_FLAG_* values */
324         u8 src_vfid;
325         u8 dst_vfid;
326 };
327
328 /**
329  * @brief ecore_dmae_host2grc - copy data from source addr to
330  * dmae registers using the given ptt
331  *
332  * @param p_hwfn
333  * @param p_ptt
334  * @param source_addr
335  * @param grc_addr (dmae_data_offset)
336  * @param size_in_dwords
337  * @param flags (one of the flags defined above)
338  */
339 enum _ecore_status_t
340 ecore_dmae_host2grc(struct ecore_hwfn *p_hwfn,
341                     struct ecore_ptt *p_ptt,
342                     u64 source_addr,
343                     u32 grc_addr,
344                     u32 size_in_dwords,
345                     u32 flags);
346
347 /**
348  * @brief ecore_dmae_grc2host - Read data from dmae data offset
349  * to source address using the given ptt
350  *
351  * @param p_ptt
352  * @param grc_addr (dmae_data_offset)
353  * @param dest_addr
354  * @param size_in_dwords
355  * @param flags - one of the flags defined above
356  */
357 enum _ecore_status_t
358 ecore_dmae_grc2host(struct ecore_hwfn *p_hwfn,
359                     struct ecore_ptt *p_ptt,
360                     u32 grc_addr,
361                     dma_addr_t dest_addr,
362                     u32 size_in_dwords,
363                     u32 flags);
364
365 /**
366  * @brief ecore_dmae_host2host - copy data from to source address
367  * to a destination address (for SRIOV) using the given ptt
368  *
369  * @param p_hwfn
370  * @param p_ptt
371  * @param source_addr
372  * @param dest_addr
373  * @param size_in_dwords
374  * @param params
375  */
376 enum _ecore_status_t
377 ecore_dmae_host2host(struct ecore_hwfn *p_hwfn,
378                      struct ecore_ptt *p_ptt,
379                      dma_addr_t source_addr,
380                      dma_addr_t dest_addr,
381                      u32 size_in_dwords,
382                      struct ecore_dmae_params *p_params);
383
384 /**
385  * @brief ecore_chain_alloc - Allocate and initialize a chain
386  *
387  * @param p_hwfn
388  * @param intended_use
389  * @param mode
390  * @param num_elems
391  * @param elem_size
392  * @param p_chain
393  *
394  * @return enum _ecore_status_t
395  */
396 enum _ecore_status_t
397 ecore_chain_alloc(struct ecore_dev *p_dev,
398                   enum ecore_chain_use_mode intended_use,
399                   enum ecore_chain_mode mode,
400                   enum ecore_chain_cnt_type cnt_type,
401                   u32 num_elems,
402                   osal_size_t elem_size,
403                   struct ecore_chain *p_chain,
404                   struct ecore_chain_ext_pbl *ext_pbl);
405
406 /**
407  * @brief ecore_chain_free - Free chain DMA memory
408  *
409  * @param p_hwfn
410  * @param p_chain
411  */
412 void ecore_chain_free(struct ecore_dev *p_dev,
413                       struct ecore_chain *p_chain);
414
415 /**
416  * @@brief ecore_fw_l2_queue - Get absolute L2 queue ID
417  *
418  *  @param p_hwfn
419  *  @param src_id - relative to p_hwfn
420  *  @param dst_id - absolute per engine
421  *
422  *  @return enum _ecore_status_t
423  */
424 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
425                                        u16 src_id,
426                                        u16 *dst_id);
427
428 /**
429  * @@brief ecore_fw_vport - Get absolute vport ID
430  *
431  *  @param p_hwfn
432  *  @param src_id - relative to p_hwfn
433  *  @param dst_id - absolute per engine
434  *
435  *  @return enum _ecore_status_t
436  */
437 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
438                                     u8 src_id,
439                                     u8 *dst_id);
440
441 /**
442  * @@brief ecore_fw_rss_eng - Get absolute RSS engine ID
443  *
444  *  @param p_hwfn
445  *  @param src_id - relative to p_hwfn
446  *  @param dst_id - absolute per engine
447  *
448  *  @return enum _ecore_status_t
449  */
450 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
451                                       u8 src_id,
452                                       u8 *dst_id);
453
454 /**
455  * @brief ecore_llh_add_mac_filter - configures a MAC filter in llh
456  *
457  * @param p_hwfn
458  * @param p_ptt
459  * @param p_filter - MAC to add
460  */
461 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
462                                           struct ecore_ptt *p_ptt,
463                                           u8 *p_filter);
464
465 /**
466  * @brief ecore_llh_remove_mac_filter - removes a MAC filtre from llh
467  *
468  * @param p_hwfn
469  * @param p_ptt
470  * @param p_filter - MAC to remove
471  */
472 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
473                              struct ecore_ptt *p_ptt,
474                              u8 *p_filter);
475
476 enum ecore_llh_port_filter_type_t {
477         ECORE_LLH_FILTER_ETHERTYPE,
478         ECORE_LLH_FILTER_TCP_SRC_PORT,
479         ECORE_LLH_FILTER_TCP_DEST_PORT,
480         ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
481         ECORE_LLH_FILTER_UDP_SRC_PORT,
482         ECORE_LLH_FILTER_UDP_DEST_PORT,
483         ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT
484 };
485
486 /**
487  * @brief ecore_llh_add_protocol_filter - configures a protocol filter in llh
488  *
489  * @param p_hwfn
490  * @param p_ptt
491  * @param source_port_or_eth_type - source port or ethertype to add
492  * @param dest_port - destination port to add
493  * @param type - type of filters and comparing
494  */
495 enum _ecore_status_t
496 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
497                               struct ecore_ptt *p_ptt,
498                               u16 source_port_or_eth_type,
499                               u16 dest_port,
500                               enum ecore_llh_port_filter_type_t type);
501
502 /**
503  * @brief ecore_llh_remove_protocol_filter - remove a protocol filter in llh
504  *
505  * @param p_hwfn
506  * @param p_ptt
507  * @param source_port_or_eth_type - source port or ethertype to add
508  * @param dest_port - destination port to add
509  * @param type - type of filters and comparing
510  */
511 void
512 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
513                                  struct ecore_ptt *p_ptt,
514                                  u16 source_port_or_eth_type,
515                                  u16 dest_port,
516                                  enum ecore_llh_port_filter_type_t type);
517
518 /**
519  * @brief ecore_llh_clear_all_filters - removes all MAC filters from llh
520  *
521  * @param p_hwfn
522  * @param p_ptt
523  */
524 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
525                              struct ecore_ptt *p_ptt);
526
527 /**
528  * @brief ecore_llh_set_function_as_default - set function as default per port
529  *
530  * @param p_hwfn
531  * @param p_ptt
532  */
533 enum _ecore_status_t
534 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
535                                   struct ecore_ptt *p_ptt);
536
537 /**
538  *@brief Cleanup of previous driver remains prior to load
539  *
540  * @param p_hwfn
541  * @param p_ptt
542  * @param id - For PF, engine-relative. For VF, PF-relative.
543  * @param is_vf - true iff cleanup is made for a VF.
544  *
545  * @return enum _ecore_status_t
546  */
547 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn      *p_hwfn,
548                                          struct ecore_ptt       *p_ptt,
549                                          u16                    id,
550                                          bool                   is_vf);
551
552 /**
553  * @brief ecore_set_rxq_coalesce - Configure coalesce parameters for an Rx queue
554  *    The fact that we can configure coalescing to up to 511, but on varying
555  *    accuracy [the bigger the value the less accurate] up to a mistake of 3usec
556  *    for the highest values.
557  *
558  * @param p_hwfn
559  * @param p_ptt
560  * @param coalesce - Coalesce value in micro seconds.
561  * @param qid - Queue index.
562  * @param qid - SB Id
563  *
564  * @return enum _ecore_status_t
565  */
566 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
567                                             struct ecore_ptt *p_ptt,
568                                             u16 coalesce, u16 qid, u16 sb_id);
569
570 /**
571  * @brief ecore_set_txq_coalesce - Configure coalesce parameters for a Tx queue
572  *    While the API allows setting coalescing per-qid, all tx queues sharing a
573  *    SB should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
574  *    otherwise configuration would break.
575  *
576  * @param p_hwfn
577  * @param p_ptt
578  * @param coalesce - Coalesce value in micro seconds.
579  * @param qid - Queue index.
580  * @param qid - SB Id
581  *
582  * @return enum _ecore_status_t
583  */
584 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
585                                             struct ecore_ptt *p_ptt,
586                                             u16 coalesce, u16 qid, u16 sb_id);
587
588 #endif