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