1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
7 #ifndef __ECORE_DEV_API_H__
8 #define __ECORE_DEV_API_H__
10 #include "ecore_status.h"
11 #include "ecore_chain.h"
12 #include "ecore_int_api.h"
15 * @brief ecore_init_dp - initialize the debug level
22 void ecore_init_dp(struct ecore_dev *p_dev,
28 * @brief ecore_init_struct - initialize the device structure to
33 enum _ecore_status_t ecore_init_struct(struct ecore_dev *p_dev);
36 * @brief ecore_resc_free -
40 void ecore_resc_free(struct ecore_dev *p_dev);
43 * @brief ecore_resc_alloc -
47 * @return enum _ecore_status_t
49 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev);
52 * @brief ecore_resc_setup -
56 void ecore_resc_setup(struct ecore_dev *p_dev);
58 enum ecore_mfw_timeout_fallback {
59 ECORE_TO_FALLBACK_TO_NONE,
60 ECORE_TO_FALLBACK_TO_DEFAULT,
61 ECORE_TO_FALLBACK_FAIL_LOAD,
64 enum ecore_override_force_load {
65 ECORE_OVERRIDE_FORCE_LOAD_NONE,
66 ECORE_OVERRIDE_FORCE_LOAD_ALWAYS,
67 ECORE_OVERRIDE_FORCE_LOAD_NEVER,
70 struct ecore_drv_load_params {
71 /* Indicates whether the driver is running over a crash kernel.
72 * As part of the load request, this will be used for providing the
73 * driver role to the MFW.
74 * In case of a crash kernel over PDA - this should be set to false.
78 /* The timeout value that the MFW should use when locking the engine for
79 * the driver load process.
80 * A value of '0' means the default value, and '255' means no timeout.
83 #define ECORE_LOAD_REQ_LOCK_TO_DEFAULT 0
84 #define ECORE_LOAD_REQ_LOCK_TO_NONE 255
86 /* Action to take in case the MFW doesn't support timeout values other
87 * than default and none.
89 enum ecore_mfw_timeout_fallback mfw_timeout_fallback;
91 /* Avoid engine reset when first PF loads on it */
94 /* Allow overriding the default force load behavior */
95 enum ecore_override_force_load override_force_load;
98 struct ecore_hw_init_params {
99 /* Tunneling parameters */
100 struct ecore_tunnel_info *p_tunn;
104 /* Interrupt mode [msix, inta, etc.] to use */
105 enum ecore_int_mode int_mode;
107 /* NPAR tx switching to be used for vports configured for tx-switching
109 bool allow_npar_tx_switch;
111 /* Binary fw data pointer in binary fw file */
112 const u8 *bin_fw_data;
114 /* Driver load parameters */
115 struct ecore_drv_load_params *p_drv_load_params;
117 /* Avoid engine affinity for RoCE/storage in case of CMT mode */
118 bool avoid_eng_affin;
120 /* SPQ block timeout in msec */
125 * @brief ecore_hw_init -
130 * @return enum _ecore_status_t
132 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
133 struct ecore_hw_init_params *p_params);
136 * @brief ecore_hw_timers_stop_all -
142 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev);
145 * @brief ecore_hw_stop -
149 * @return enum _ecore_status_t
151 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev);
154 * @brief ecore_hw_stop_fastpath -should be called incase
155 * slowpath is still required for the device,
156 * but fastpath is not.
160 * @return enum _ecore_status_t
162 enum _ecore_status_t ecore_hw_stop_fastpath(struct ecore_dev *p_dev);
166 * @brief ecore_prepare_hibernate -should be called when
167 * the system is going into the hibernate state
172 void ecore_prepare_hibernate(struct ecore_dev *p_dev);
174 enum ecore_db_rec_width {
179 enum ecore_db_rec_space {
185 * @brief db_recovery_add - add doorbell information to the doorbell
186 * recovery mechanism.
189 * @param db_addr - doorbell address
190 * @param db_data - address of where db_data is stored
191 * @param db_width - doorbell is 32b pr 64b
192 * @param db_space - doorbell recovery addresses are user or kernel space
194 enum _ecore_status_t ecore_db_recovery_add(struct ecore_dev *p_dev,
195 void OSAL_IOMEM *db_addr,
197 enum ecore_db_rec_width db_width,
198 enum ecore_db_rec_space db_space);
201 * @brief db_recovery_del - remove doorbell information from the doorbell
202 * recovery mechanism. db_data serves as key (db_addr is not unique).
205 * @param db_addr - doorbell address
206 * @param db_data - address where db_data is stored. Serves as key for the
209 enum _ecore_status_t ecore_db_recovery_del(struct ecore_dev *p_dev,
210 void OSAL_IOMEM *db_addr,
213 static OSAL_INLINE bool ecore_is_mf_ufp(struct ecore_hwfn *p_hwfn)
215 return !!OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits);
221 * @brief ecore_hw_start_fastpath -restart fastpath traffic,
222 * only if hw_stop_fastpath was called
226 * @return enum _ecore_status_t
228 enum _ecore_status_t ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn);
230 enum ecore_hw_prepare_result {
231 ECORE_HW_PREPARE_SUCCESS,
233 /* FAILED results indicate probe has failed & cleaned up */
234 ECORE_HW_PREPARE_FAILED_ENG2,
235 ECORE_HW_PREPARE_FAILED_ME,
236 ECORE_HW_PREPARE_FAILED_MEM,
237 ECORE_HW_PREPARE_FAILED_DEV,
238 ECORE_HW_PREPARE_FAILED_NVM,
240 /* BAD results indicate probe is passed even though some wrongness
241 * has occurred; Trying to actually use [I.e., hw_init()] might have
242 * dire reprecautions.
244 ECORE_HW_PREPARE_BAD_IOV,
245 ECORE_HW_PREPARE_BAD_MCP,
246 ECORE_HW_PREPARE_BAD_IGU,
249 struct ecore_hw_prepare_params {
250 /* Personality to initialize */
253 /* Force the driver's default resource allocation */
256 /* Check the reg_fifo after any register access */
259 /* Request the MFW to initiate PF FLR */
260 bool initiate_pf_flr;
262 /* The OS Epoch time in seconds */
265 /* Allow the MFW to collect a crash dump */
268 /* Allow prepare to pass even if some initializations are failing.
269 * If set, the `p_prepare_res' field would be set with the return,
270 * and might allow probe to pass even if there are certain issues.
272 bool b_relaxed_probe;
273 enum ecore_hw_prepare_result p_relaxed_res;
275 /* Enable/disable request by ecore client for pacing */
278 /* Indicates whether this PF serves a storage target */
283 * @brief ecore_hw_prepare -
288 * @return enum _ecore_status_t
290 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
291 struct ecore_hw_prepare_params *p_params);
294 * @brief ecore_hw_remove -
298 void ecore_hw_remove(struct ecore_dev *p_dev);
301 * @brief ecore_ptt_acquire - Allocate a PTT window
303 * Should be called at the entry point to the driver (at the beginning of an
308 * @return struct ecore_ptt
310 struct ecore_ptt *ecore_ptt_acquire(struct ecore_hwfn *p_hwfn);
313 * @brief ecore_ptt_release - Release PTT Window
315 * Should be called at the end of a flow - at the end of the function that
322 void ecore_ptt_release(struct ecore_hwfn *p_hwfn,
323 struct ecore_ptt *p_ptt);
325 struct ecore_eth_stats_common {
326 u64 no_buff_discards;
327 u64 packet_too_big_discard;
335 u64 mftag_filter_discards;
336 u64 mac_filter_discards;
344 u64 tx_err_drop_pkts;
345 u64 tpa_coalesced_pkts;
346 u64 tpa_coalesced_events;
348 u64 tpa_not_coalesced_pkts;
349 u64 tpa_coalesced_bytes;
352 u64 rx_64_byte_packets;
353 u64 rx_65_to_127_byte_packets;
354 u64 rx_128_to_255_byte_packets;
355 u64 rx_256_to_511_byte_packets;
356 u64 rx_512_to_1023_byte_packets;
357 u64 rx_1024_to_1518_byte_packets;
359 u64 rx_mac_crtl_frames;
363 u64 rx_carrier_errors;
364 u64 rx_oversize_packets;
366 u64 rx_undersize_packets;
368 u64 tx_64_byte_packets;
369 u64 tx_65_to_127_byte_packets;
370 u64 tx_128_to_255_byte_packets;
371 u64 tx_256_to_511_byte_packets;
372 u64 tx_512_to_1023_byte_packets;
373 u64 tx_1024_to_1518_byte_packets;
379 u64 rx_mac_uc_packets;
380 u64 rx_mac_mc_packets;
381 u64 rx_mac_bc_packets;
382 u64 rx_mac_frames_ok;
384 u64 tx_mac_uc_packets;
385 u64 tx_mac_mc_packets;
386 u64 tx_mac_bc_packets;
387 u64 tx_mac_ctrl_frames;
388 u64 link_change_count;
391 struct ecore_eth_stats_bb {
392 u64 rx_1519_to_1522_byte_packets;
393 u64 rx_1519_to_2047_byte_packets;
394 u64 rx_2048_to_4095_byte_packets;
395 u64 rx_4096_to_9216_byte_packets;
396 u64 rx_9217_to_16383_byte_packets;
397 u64 tx_1519_to_2047_byte_packets;
398 u64 tx_2048_to_4095_byte_packets;
399 u64 tx_4096_to_9216_byte_packets;
400 u64 tx_9217_to_16383_byte_packets;
401 u64 tx_lpi_entry_count;
402 u64 tx_total_collisions;
405 struct ecore_eth_stats_ah {
406 u64 rx_1519_to_max_byte_packets;
407 u64 tx_1519_to_max_byte_packets;
410 struct ecore_eth_stats {
411 struct ecore_eth_stats_common common;
413 struct ecore_eth_stats_bb bb;
414 struct ecore_eth_stats_ah ah;
418 enum ecore_dmae_address_type_t {
419 ECORE_DMAE_ADDRESS_HOST_VIRT,
420 ECORE_DMAE_ADDRESS_HOST_PHYS,
421 ECORE_DMAE_ADDRESS_GRC
424 /* value of flags If ECORE_DMAE_FLAG_RW_REPL_SRC flag is set and the
425 * source is a block of length DMAE_MAX_RW_SIZE and the
426 * destination is larger, the source block will be duplicated as
427 * many times as required to fill the destination block. This is
428 * used mostly to write a zeroed buffer to destination address
431 #define ECORE_DMAE_FLAG_RW_REPL_SRC 0x00000001
432 #define ECORE_DMAE_FLAG_VF_SRC 0x00000002
433 #define ECORE_DMAE_FLAG_VF_DST 0x00000004
434 #define ECORE_DMAE_FLAG_COMPLETION_DST 0x00000008
435 #define ECORE_DMAE_FLAG_PORT 0x00000010
436 #define ECORE_DMAE_FLAG_PF_SRC 0x00000020
437 #define ECORE_DMAE_FLAG_PF_DST 0x00000040
439 struct ecore_dmae_params {
440 u32 flags; /* consists of ECORE_DMAE_FLAG_* values */
449 * @brief ecore_dmae_host2grc - copy data from source addr to
450 * dmae registers using the given ptt
455 * @param grc_addr (dmae_data_offset)
456 * @param size_in_dwords
457 * @param p_params (default parameters will be used in case of OSAL_NULL)
459 * @return enum _ecore_status_t
462 ecore_dmae_host2grc(struct ecore_hwfn *p_hwfn,
463 struct ecore_ptt *p_ptt,
467 struct ecore_dmae_params *p_params);
470 * @brief ecore_dmae_grc2host - Read data from dmae data offset
471 * to source address using the given ptt
474 * @param grc_addr (dmae_data_offset)
476 * @param size_in_dwords
477 * @param p_params (default parameters will be used in case of OSAL_NULL)
479 * @return enum _ecore_status_t
482 ecore_dmae_grc2host(struct ecore_hwfn *p_hwfn,
483 struct ecore_ptt *p_ptt,
485 dma_addr_t dest_addr,
487 struct ecore_dmae_params *p_params);
490 * @brief ecore_dmae_host2host - copy data from to source address
491 * to a destination address (for SRIOV) using the given ptt
497 * @param size_in_dwords
498 * @param p_params (default parameters will be used in case of OSAL_NULL)
500 * @return enum _ecore_status_t
503 ecore_dmae_host2host(struct ecore_hwfn *p_hwfn,
504 struct ecore_ptt *p_ptt,
505 dma_addr_t source_addr,
506 dma_addr_t dest_addr,
508 struct ecore_dmae_params *p_params);
511 * @brief ecore_chain_alloc - Allocate and initialize a chain
514 * @param intended_use
520 * @return enum _ecore_status_t
523 ecore_chain_alloc(struct ecore_dev *p_dev,
524 enum ecore_chain_use_mode intended_use,
525 enum ecore_chain_mode mode,
526 enum ecore_chain_cnt_type cnt_type,
528 osal_size_t elem_size,
529 struct ecore_chain *p_chain,
530 struct ecore_chain_ext_pbl *ext_pbl);
533 * @brief ecore_chain_free - Free chain DMA memory
538 void ecore_chain_free(struct ecore_dev *p_dev,
539 struct ecore_chain *p_chain);
542 * @@brief ecore_fw_l2_queue - Get absolute L2 queue ID
545 * @param src_id - relative to p_hwfn
546 * @param dst_id - absolute per engine
548 * @return enum _ecore_status_t
550 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
555 * @@brief ecore_fw_vport - Get absolute vport ID
558 * @param src_id - relative to p_hwfn
559 * @param dst_id - absolute per engine
561 * @return enum _ecore_status_t
563 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
568 * @@brief ecore_fw_rss_eng - Get absolute RSS engine ID
571 * @param src_id - relative to p_hwfn
572 * @param dst_id - absolute per engine
574 * @return enum _ecore_status_t
576 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
581 * @brief ecore_llh_get_num_ppfid - Return the allocated number of LLH filter
582 * banks that are allocated to the PF.
586 * @return u8 - Number of LLH filter banks
588 u8 ecore_llh_get_num_ppfid(struct ecore_dev *p_dev);
597 * @brief ecore_llh_get_l2_affinity_hint - Return the hint for the L2 affinity
601 * @return enum ecore_eng - L2 affintiy hint
603 enum ecore_eng ecore_llh_get_l2_affinity_hint(struct ecore_dev *p_dev);
606 * @brief ecore_llh_set_ppfid_affinity - Set the engine affinity for the given
610 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
613 * @return enum _ecore_status_t
615 enum _ecore_status_t ecore_llh_set_ppfid_affinity(struct ecore_dev *p_dev,
616 u8 ppfid, enum ecore_eng eng);
619 * @brief ecore_llh_set_roce_affinity - Set the RoCE engine affinity
624 * @return enum _ecore_status_t
626 enum _ecore_status_t ecore_llh_set_roce_affinity(struct ecore_dev *p_dev,
630 * @brief ecore_llh_add_mac_filter - Add a LLH MAC filter into the given filter
634 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
635 * @param mac_addr - MAC to add
637 * @return enum _ecore_status_t
639 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_dev *p_dev, u8 ppfid,
640 u8 mac_addr[ETH_ALEN]);
643 * @brief ecore_llh_remove_mac_filter - Remove a LLH MAC filter from the given
647 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
648 * @param mac_addr - MAC to remove
650 void ecore_llh_remove_mac_filter(struct ecore_dev *p_dev, u8 ppfid,
651 u8 mac_addr[ETH_ALEN]);
653 enum ecore_llh_prot_filter_type_t {
654 ECORE_LLH_FILTER_ETHERTYPE,
655 ECORE_LLH_FILTER_TCP_SRC_PORT,
656 ECORE_LLH_FILTER_TCP_DEST_PORT,
657 ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
658 ECORE_LLH_FILTER_UDP_SRC_PORT,
659 ECORE_LLH_FILTER_UDP_DEST_PORT,
660 ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT
664 * @brief ecore_llh_add_protocol_filter - Add a LLH protocol filter into the
668 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
669 * @param type - type of filters and comparing
670 * @param source_port_or_eth_type - source port or ethertype to add
671 * @param dest_port - destination port to add
673 * @return enum _ecore_status_t
676 ecore_llh_add_protocol_filter(struct ecore_dev *p_dev, u8 ppfid,
677 enum ecore_llh_prot_filter_type_t type,
678 u16 source_port_or_eth_type, u16 dest_port);
681 * @brief ecore_llh_remove_protocol_filter - Remove a LLH protocol filter from
682 * the given filter bank.
685 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
686 * @param type - type of filters and comparing
687 * @param source_port_or_eth_type - source port or ethertype to add
688 * @param dest_port - destination port to add
690 void ecore_llh_remove_protocol_filter(struct ecore_dev *p_dev, u8 ppfid,
691 enum ecore_llh_prot_filter_type_t type,
692 u16 source_port_or_eth_type,
696 * @brief ecore_llh_clear_ppfid_filters - Remove all LLH filters from the given
700 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
702 void ecore_llh_clear_ppfid_filters(struct ecore_dev *p_dev, u8 ppfid);
705 * @brief ecore_llh_clear_all_filters - Remove all LLH filters
709 void ecore_llh_clear_all_filters(struct ecore_dev *p_dev);
712 * @brief ecore_llh_set_function_as_default - set function as default per port
718 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
719 struct ecore_ptt *p_ptt);
722 *@brief Cleanup of previous driver remains prior to load
726 * @param id - For PF, engine-relative. For VF, PF-relative.
727 * @param is_vf - true iff cleanup is made for a VF.
729 * @return enum _ecore_status_t
731 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
732 struct ecore_ptt *p_ptt,
737 * @brief ecore_get_queue_coalesce - Retrieve coalesce value for a given queue.
740 * @param p_coal - store coalesce value read from the hardware.
743 * @return enum _ecore_status_t
746 ecore_get_queue_coalesce(struct ecore_hwfn *p_hwfn, u16 *coal,
750 * @brief ecore_set_queue_coalesce - Configure coalesce parameters for Rx and
751 * Tx queue. The fact that we can configure coalescing to up to 511, but on
752 * varying accuracy [the bigger the value the less accurate] up to a mistake
753 * of 3usec for the highest values.
754 * While the API allows setting coalescing per-qid, all queues sharing a SB
755 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
756 * otherwise configuration would break.
759 * @param rx_coal - Rx Coalesce value in micro seconds.
760 * @param tx_coal - TX Coalesce value in micro seconds.
763 * @return enum _ecore_status_t
766 ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn, u16 rx_coal,
767 u16 tx_coal, void *p_handle);
770 * @brief ecore_pglueb_set_pfid_enable - Enable or disable PCI BUS MASTER
774 * @param b_enable - true/false
776 * @return enum _ecore_status_t
778 enum _ecore_status_t ecore_pglueb_set_pfid_enable(struct ecore_hwfn *p_hwfn,
779 struct ecore_ptt *p_ptt,
783 * @brief Whether FIP discovery fallback special mode is enabled or not.
787 * @return true if device is in FIP special mode, false otherwise.
789 bool ecore_is_mf_fip_special(struct ecore_dev *p_dev);