0dee68a9b21540ee58cef270101b08ff3ea77372
[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 struct ecore_hw_prepare_params {
142         /* personality to initialize */
143         int personality;
144         /* force the driver's default resource allocation */
145         bool drv_resc_alloc;
146         /* check the reg_fifo after any register access */
147         bool chk_reg_fifo;
148         /* request the MFW to initiate PF FLR */
149         bool initiate_pf_flr;
150         /* the OS Epoch time in seconds */
151         u32 epoch;
152 };
153
154 /**
155  * @brief ecore_hw_prepare -
156  *
157  * @param p_dev
158  * @param p_params
159  *
160  * @return enum _ecore_status_t
161  */
162 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
163                                       struct ecore_hw_prepare_params *p_params);
164
165 /**
166  * @brief ecore_hw_remove -
167  *
168  * @param p_dev
169  */
170 void ecore_hw_remove(struct ecore_dev *p_dev);
171
172 /**
173  * @brief ecore_ptt_acquire - Allocate a PTT window
174  *
175  * Should be called at the entry point to the driver (at the beginning of an
176  * exported function)
177  *
178  * @param p_hwfn
179  *
180  * @return struct ecore_ptt
181  */
182 struct ecore_ptt *ecore_ptt_acquire(struct ecore_hwfn *p_hwfn);
183
184 /**
185  * @brief ecore_ptt_release - Release PTT Window
186  *
187  * Should be called at the end of a flow - at the end of the function that
188  * acquired the PTT.
189  *
190  *
191  * @param p_hwfn
192  * @param p_ptt
193  */
194 void ecore_ptt_release(struct ecore_hwfn *p_hwfn,
195                        struct ecore_ptt *p_ptt);
196
197 #ifndef __EXTRACT__LINUX__
198 struct ecore_eth_stats {
199         u64 no_buff_discards;
200         u64 packet_too_big_discard;
201         u64 ttl0_discard;
202         u64 rx_ucast_bytes;
203         u64 rx_mcast_bytes;
204         u64 rx_bcast_bytes;
205         u64 rx_ucast_pkts;
206         u64 rx_mcast_pkts;
207         u64 rx_bcast_pkts;
208         u64 mftag_filter_discards;
209         u64 mac_filter_discards;
210         u64 tx_ucast_bytes;
211         u64 tx_mcast_bytes;
212         u64 tx_bcast_bytes;
213         u64 tx_ucast_pkts;
214         u64 tx_mcast_pkts;
215         u64 tx_bcast_pkts;
216         u64 tx_err_drop_pkts;
217         u64 tpa_coalesced_pkts;
218         u64 tpa_coalesced_events;
219         u64 tpa_aborts_num;
220         u64 tpa_not_coalesced_pkts;
221         u64 tpa_coalesced_bytes;
222
223         /* port */
224         u64 rx_64_byte_packets;
225         u64 rx_65_to_127_byte_packets;
226         u64 rx_128_to_255_byte_packets;
227         u64 rx_256_to_511_byte_packets;
228         u64 rx_512_to_1023_byte_packets;
229         u64 rx_1024_to_1518_byte_packets;
230         u64 rx_1519_to_1522_byte_packets;
231         u64 rx_1519_to_2047_byte_packets;
232         u64 rx_2048_to_4095_byte_packets;
233         u64 rx_4096_to_9216_byte_packets;
234         u64 rx_9217_to_16383_byte_packets;
235         u64 rx_crc_errors;
236         u64 rx_mac_crtl_frames;
237         u64 rx_pause_frames;
238         u64 rx_pfc_frames;
239         u64 rx_align_errors;
240         u64 rx_carrier_errors;
241         u64 rx_oversize_packets;
242         u64 rx_jabbers;
243         u64 rx_undersize_packets;
244         u64 rx_fragments;
245         u64 tx_64_byte_packets;
246         u64 tx_65_to_127_byte_packets;
247         u64 tx_128_to_255_byte_packets;
248         u64 tx_256_to_511_byte_packets;
249         u64 tx_512_to_1023_byte_packets;
250         u64 tx_1024_to_1518_byte_packets;
251         u64 tx_1519_to_2047_byte_packets;
252         u64 tx_2048_to_4095_byte_packets;
253         u64 tx_4096_to_9216_byte_packets;
254         u64 tx_9217_to_16383_byte_packets;
255         u64 tx_pause_frames;
256         u64 tx_pfc_frames;
257         u64 tx_lpi_entry_count;
258         u64 tx_total_collisions;
259         u64 brb_truncates;
260         u64 brb_discards;
261         u64 rx_mac_bytes;
262         u64 rx_mac_uc_packets;
263         u64 rx_mac_mc_packets;
264         u64 rx_mac_bc_packets;
265         u64 rx_mac_frames_ok;
266         u64 tx_mac_bytes;
267         u64 tx_mac_uc_packets;
268         u64 tx_mac_mc_packets;
269         u64 tx_mac_bc_packets;
270         u64 tx_mac_ctrl_frames;
271 };
272 #endif
273
274 enum ecore_dmae_address_type_t {
275         ECORE_DMAE_ADDRESS_HOST_VIRT,
276         ECORE_DMAE_ADDRESS_HOST_PHYS,
277         ECORE_DMAE_ADDRESS_GRC
278 };
279
280 /* value of flags If ECORE_DMAE_FLAG_RW_REPL_SRC flag is set and the
281  * source is a block of length DMAE_MAX_RW_SIZE and the
282  * destination is larger, the source block will be duplicated as
283  * many times as required to fill the destination block. This is
284  * used mostly to write a zeroed buffer to destination address
285  * using DMA
286  */
287 #define ECORE_DMAE_FLAG_RW_REPL_SRC     0x00000001
288 #define ECORE_DMAE_FLAG_VF_SRC          0x00000002
289 #define ECORE_DMAE_FLAG_VF_DST          0x00000004
290 #define ECORE_DMAE_FLAG_COMPLETION_DST  0x00000008
291
292 struct ecore_dmae_params {
293         u32 flags; /* consists of ECORE_DMAE_FLAG_* values */
294         u8 src_vfid;
295         u8 dst_vfid;
296 };
297
298 /**
299  * @brief ecore_dmae_host2grc - copy data from source addr to
300  * dmae registers using the given ptt
301  *
302  * @param p_hwfn
303  * @param p_ptt
304  * @param source_addr
305  * @param grc_addr (dmae_data_offset)
306  * @param size_in_dwords
307  * @param flags (one of the flags defined above)
308  */
309 enum _ecore_status_t
310 ecore_dmae_host2grc(struct ecore_hwfn *p_hwfn,
311                     struct ecore_ptt *p_ptt,
312                     u64 source_addr,
313                     u32 grc_addr,
314                     u32 size_in_dwords,
315                     u32 flags);
316
317 /**
318  * @brief ecore_dmae_grc2host - Read data from dmae data offset
319  * to source address using the given ptt
320  *
321  * @param p_ptt
322  * @param grc_addr (dmae_data_offset)
323  * @param dest_addr
324  * @param size_in_dwords
325  * @param flags - one of the flags defined above
326  */
327 enum _ecore_status_t
328 ecore_dmae_grc2host(struct ecore_hwfn *p_hwfn,
329                     struct ecore_ptt *p_ptt,
330                     u32 grc_addr,
331                     dma_addr_t dest_addr,
332                     u32 size_in_dwords,
333                     u32 flags);
334
335 /**
336  * @brief ecore_dmae_host2host - copy data from to source address
337  * to a destination address (for SRIOV) using the given ptt
338  *
339  * @param p_hwfn
340  * @param p_ptt
341  * @param source_addr
342  * @param dest_addr
343  * @param size_in_dwords
344  * @param params
345  */
346 enum _ecore_status_t
347 ecore_dmae_host2host(struct ecore_hwfn *p_hwfn,
348                      struct ecore_ptt *p_ptt,
349                      dma_addr_t source_addr,
350                      dma_addr_t dest_addr,
351                      u32 size_in_dwords,
352                      struct ecore_dmae_params *p_params);
353
354 /**
355  * @brief ecore_chain_alloc - Allocate and initialize a chain
356  *
357  * @param p_hwfn
358  * @param intended_use
359  * @param mode
360  * @param num_elems
361  * @param elem_size
362  * @param p_chain
363  *
364  * @return enum _ecore_status_t
365  */
366 enum _ecore_status_t
367 ecore_chain_alloc(struct ecore_dev *p_dev,
368                   enum ecore_chain_use_mode intended_use,
369                   enum ecore_chain_mode mode,
370                   enum ecore_chain_cnt_type cnt_type,
371                   u32 num_elems,
372                   osal_size_t elem_size,
373                   struct ecore_chain *p_chain,
374                   struct ecore_chain_ext_pbl *ext_pbl);
375
376 /**
377  * @brief ecore_chain_free - Free chain DMA memory
378  *
379  * @param p_hwfn
380  * @param p_chain
381  */
382 void ecore_chain_free(struct ecore_dev *p_dev,
383                       struct ecore_chain *p_chain);
384
385 /**
386  * @@brief ecore_fw_l2_queue - Get absolute L2 queue ID
387  *
388  *  @param p_hwfn
389  *  @param src_id - relative to p_hwfn
390  *  @param dst_id - absolute per engine
391  *
392  *  @return enum _ecore_status_t
393  */
394 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
395                                        u16 src_id,
396                                        u16 *dst_id);
397
398 /**
399  * @@brief ecore_fw_vport - Get absolute vport ID
400  *
401  *  @param p_hwfn
402  *  @param src_id - relative to p_hwfn
403  *  @param dst_id - absolute per engine
404  *
405  *  @return enum _ecore_status_t
406  */
407 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
408                                     u8 src_id,
409                                     u8 *dst_id);
410
411 /**
412  * @@brief ecore_fw_rss_eng - Get absolute RSS engine ID
413  *
414  *  @param p_hwfn
415  *  @param src_id - relative to p_hwfn
416  *  @param dst_id - absolute per engine
417  *
418  *  @return enum _ecore_status_t
419  */
420 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
421                                       u8 src_id,
422                                       u8 *dst_id);
423
424 /**
425  * @brief ecore_llh_add_mac_filter - configures a MAC filter in llh
426  *
427  * @param p_hwfn
428  * @param p_ptt
429  * @param p_filter - MAC to add
430  */
431 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
432                                           struct ecore_ptt *p_ptt,
433                                           u8 *p_filter);
434
435 /**
436  * @brief ecore_llh_remove_mac_filter - removes a MAC filtre from llh
437  *
438  * @param p_hwfn
439  * @param p_ptt
440  * @param p_filter - MAC to remove
441  */
442 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
443                              struct ecore_ptt *p_ptt,
444                              u8 *p_filter);
445
446 enum ecore_llh_port_filter_type_t {
447         ECORE_LLH_FILTER_ETHERTYPE,
448         ECORE_LLH_FILTER_TCP_SRC_PORT,
449         ECORE_LLH_FILTER_TCP_DEST_PORT,
450         ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
451         ECORE_LLH_FILTER_UDP_SRC_PORT,
452         ECORE_LLH_FILTER_UDP_DEST_PORT,
453         ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT
454 };
455
456 /**
457  * @brief ecore_llh_add_protocol_filter - configures a protocol filter in llh
458  *
459  * @param p_hwfn
460  * @param p_ptt
461  * @param source_port_or_eth_type - source port or ethertype to add
462  * @param dest_port - destination port to add
463  * @param type - type of filters and comparing
464  */
465 enum _ecore_status_t
466 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
467                               struct ecore_ptt *p_ptt,
468                               u16 source_port_or_eth_type,
469                               u16 dest_port,
470                               enum ecore_llh_port_filter_type_t type);
471
472 /**
473  * @brief ecore_llh_remove_protocol_filter - remove a protocol filter in llh
474  *
475  * @param p_hwfn
476  * @param p_ptt
477  * @param source_port_or_eth_type - source port or ethertype to add
478  * @param dest_port - destination port to add
479  * @param type - type of filters and comparing
480  */
481 void
482 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
483                                  struct ecore_ptt *p_ptt,
484                                  u16 source_port_or_eth_type,
485                                  u16 dest_port,
486                                  enum ecore_llh_port_filter_type_t type);
487
488 /**
489  * @brief ecore_llh_clear_all_filters - removes all MAC filters from llh
490  *
491  * @param p_hwfn
492  * @param p_ptt
493  */
494 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
495                              struct ecore_ptt *p_ptt);
496
497 /**
498  * @brief ecore_llh_set_function_as_default - set function as default per port
499  *
500  * @param p_hwfn
501  * @param p_ptt
502  */
503 enum _ecore_status_t
504 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
505                                   struct ecore_ptt *p_ptt);
506
507 /**
508  *@brief Cleanup of previous driver remains prior to load
509  *
510  * @param p_hwfn
511  * @param p_ptt
512  * @param id - For PF, engine-relative. For VF, PF-relative.
513  * @param is_vf - true iff cleanup is made for a VF.
514  *
515  * @return enum _ecore_status_t
516  */
517 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn      *p_hwfn,
518                                          struct ecore_ptt       *p_ptt,
519                                          u16                    id,
520                                          bool                   is_vf);
521
522 /**
523  * @brief ecore_set_rxq_coalesce - Configure coalesce parameters for an Rx queue
524  *    The fact that we can configure coalescing to up to 511, but on varying
525  *    accuracy [the bigger the value the less accurate] up to a mistake of 3usec
526  *    for the highest values.
527  *
528  * @param p_hwfn
529  * @param p_ptt
530  * @param coalesce - Coalesce value in micro seconds.
531  * @param qid - Queue index.
532  * @param qid - SB Id
533  *
534  * @return enum _ecore_status_t
535  */
536 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
537                                             struct ecore_ptt *p_ptt,
538                                             u16 coalesce, u8 qid, u16 sb_id);
539
540 /**
541  * @brief ecore_set_txq_coalesce - Configure coalesce parameters for a Tx queue
542  *    While the API allows setting coalescing per-qid, all tx queues sharing a
543  *    SB should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
544  *    otherwise configuration would break.
545  *
546  * @param p_hwfn
547  * @param p_ptt
548  * @param coalesce - Coalesce value in micro seconds.
549  * @param qid - Queue index.
550  * @param qid - SB Id
551  *
552  * @return enum _ecore_status_t
553  */
554 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
555                                             struct ecore_ptt *p_ptt,
556                                             u16 coalesce, u8 qid, u16 sb_id);
557
558 #endif