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