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