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