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 /* SPQ block timeout in msec */
122 * @brief ecore_hw_init -
127 * @return enum _ecore_status_t
129 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
130 struct ecore_hw_init_params *p_params);
133 * @brief ecore_hw_timers_stop_all -
139 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev);
142 * @brief ecore_hw_stop -
146 * @return enum _ecore_status_t
148 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev);
151 * @brief ecore_hw_stop_fastpath -should be called incase
152 * slowpath is still required for the device,
153 * but fastpath is not.
157 * @return enum _ecore_status_t
159 enum _ecore_status_t ecore_hw_stop_fastpath(struct ecore_dev *p_dev);
163 * @brief ecore_prepare_hibernate -should be called when
164 * the system is going into the hibernate state
169 void ecore_prepare_hibernate(struct ecore_dev *p_dev);
171 enum ecore_db_rec_width {
176 enum ecore_db_rec_space {
182 * @brief db_recovery_add - add doorbell information to the doorbell
183 * recovery mechanism.
186 * @param db_addr - doorbell address
187 * @param db_data - address of where db_data is stored
188 * @param db_width - doorbell is 32b pr 64b
189 * @param db_space - doorbell recovery addresses are user or kernel space
191 enum _ecore_status_t ecore_db_recovery_add(struct ecore_dev *p_dev,
192 void OSAL_IOMEM *db_addr,
194 enum ecore_db_rec_width db_width,
195 enum ecore_db_rec_space db_space);
198 * @brief db_recovery_del - remove doorbell information from the doorbell
199 * recovery mechanism. db_data serves as key (db_addr is not unique).
202 * @param db_addr - doorbell address
203 * @param db_data - address where db_data is stored. Serves as key for the
206 enum _ecore_status_t ecore_db_recovery_del(struct ecore_dev *p_dev,
207 void OSAL_IOMEM *db_addr,
210 static OSAL_INLINE bool ecore_is_mf_ufp(struct ecore_hwfn *p_hwfn)
212 return !!OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits);
218 * @brief ecore_hw_start_fastpath -restart fastpath traffic,
219 * only if hw_stop_fastpath was called
223 * @return enum _ecore_status_t
225 enum _ecore_status_t ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn);
227 enum ecore_hw_prepare_result {
228 ECORE_HW_PREPARE_SUCCESS,
230 /* FAILED results indicate probe has failed & cleaned up */
231 ECORE_HW_PREPARE_FAILED_ENG2,
232 ECORE_HW_PREPARE_FAILED_ME,
233 ECORE_HW_PREPARE_FAILED_MEM,
234 ECORE_HW_PREPARE_FAILED_DEV,
235 ECORE_HW_PREPARE_FAILED_NVM,
237 /* BAD results indicate probe is passed even though some wrongness
238 * has occurred; Trying to actually use [I.e., hw_init()] might have
239 * dire reprecautions.
241 ECORE_HW_PREPARE_BAD_IOV,
242 ECORE_HW_PREPARE_BAD_MCP,
243 ECORE_HW_PREPARE_BAD_IGU,
246 struct ecore_hw_prepare_params {
247 /* Personality to initialize */
250 /* Force the driver's default resource allocation */
253 /* Check the reg_fifo after any register access */
256 /* Request the MFW to initiate PF FLR */
257 bool initiate_pf_flr;
259 /* The OS Epoch time in seconds */
262 /* Allow the MFW to collect a crash dump */
265 /* Allow prepare to pass even if some initializations are failing.
266 * If set, the `p_prepare_res' field would be set with the return,
267 * and might allow probe to pass even if there are certain issues.
269 bool b_relaxed_probe;
270 enum ecore_hw_prepare_result p_relaxed_res;
272 /* Enable/disable request by ecore client for pacing */
277 * @brief ecore_hw_prepare -
282 * @return enum _ecore_status_t
284 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
285 struct ecore_hw_prepare_params *p_params);
288 * @brief ecore_hw_remove -
292 void ecore_hw_remove(struct ecore_dev *p_dev);
295 * @brief ecore_ptt_acquire - Allocate a PTT window
297 * Should be called at the entry point to the driver (at the beginning of an
302 * @return struct ecore_ptt
304 struct ecore_ptt *ecore_ptt_acquire(struct ecore_hwfn *p_hwfn);
307 * @brief ecore_ptt_release - Release PTT Window
309 * Should be called at the end of a flow - at the end of the function that
316 void ecore_ptt_release(struct ecore_hwfn *p_hwfn,
317 struct ecore_ptt *p_ptt);
319 struct ecore_eth_stats_common {
320 u64 no_buff_discards;
321 u64 packet_too_big_discard;
329 u64 mftag_filter_discards;
330 u64 mac_filter_discards;
337 u64 tx_err_drop_pkts;
338 u64 tpa_coalesced_pkts;
339 u64 tpa_coalesced_events;
341 u64 tpa_not_coalesced_pkts;
342 u64 tpa_coalesced_bytes;
345 u64 rx_64_byte_packets;
346 u64 rx_65_to_127_byte_packets;
347 u64 rx_128_to_255_byte_packets;
348 u64 rx_256_to_511_byte_packets;
349 u64 rx_512_to_1023_byte_packets;
350 u64 rx_1024_to_1518_byte_packets;
352 u64 rx_mac_crtl_frames;
356 u64 rx_carrier_errors;
357 u64 rx_oversize_packets;
359 u64 rx_undersize_packets;
361 u64 tx_64_byte_packets;
362 u64 tx_65_to_127_byte_packets;
363 u64 tx_128_to_255_byte_packets;
364 u64 tx_256_to_511_byte_packets;
365 u64 tx_512_to_1023_byte_packets;
366 u64 tx_1024_to_1518_byte_packets;
372 u64 rx_mac_uc_packets;
373 u64 rx_mac_mc_packets;
374 u64 rx_mac_bc_packets;
375 u64 rx_mac_frames_ok;
377 u64 tx_mac_uc_packets;
378 u64 tx_mac_mc_packets;
379 u64 tx_mac_bc_packets;
380 u64 tx_mac_ctrl_frames;
381 u64 link_change_count;
384 struct ecore_eth_stats_bb {
385 u64 rx_1519_to_1522_byte_packets;
386 u64 rx_1519_to_2047_byte_packets;
387 u64 rx_2048_to_4095_byte_packets;
388 u64 rx_4096_to_9216_byte_packets;
389 u64 rx_9217_to_16383_byte_packets;
390 u64 tx_1519_to_2047_byte_packets;
391 u64 tx_2048_to_4095_byte_packets;
392 u64 tx_4096_to_9216_byte_packets;
393 u64 tx_9217_to_16383_byte_packets;
394 u64 tx_lpi_entry_count;
395 u64 tx_total_collisions;
398 struct ecore_eth_stats_ah {
399 u64 rx_1519_to_max_byte_packets;
400 u64 tx_1519_to_max_byte_packets;
403 struct ecore_eth_stats {
404 struct ecore_eth_stats_common common;
406 struct ecore_eth_stats_bb bb;
407 struct ecore_eth_stats_ah ah;
411 enum ecore_dmae_address_type_t {
412 ECORE_DMAE_ADDRESS_HOST_VIRT,
413 ECORE_DMAE_ADDRESS_HOST_PHYS,
414 ECORE_DMAE_ADDRESS_GRC
417 /* value of flags If ECORE_DMAE_FLAG_RW_REPL_SRC flag is set and the
418 * source is a block of length DMAE_MAX_RW_SIZE and the
419 * destination is larger, the source block will be duplicated as
420 * many times as required to fill the destination block. This is
421 * used mostly to write a zeroed buffer to destination address
424 #define ECORE_DMAE_FLAG_RW_REPL_SRC 0x00000001
425 #define ECORE_DMAE_FLAG_VF_SRC 0x00000002
426 #define ECORE_DMAE_FLAG_VF_DST 0x00000004
427 #define ECORE_DMAE_FLAG_COMPLETION_DST 0x00000008
429 struct ecore_dmae_params {
430 u32 flags; /* consists of ECORE_DMAE_FLAG_* values */
436 * @brief ecore_dmae_host2grc - copy data from source addr to
437 * dmae registers using the given ptt
442 * @param grc_addr (dmae_data_offset)
443 * @param size_in_dwords
444 * @param flags (one of the flags defined above)
447 ecore_dmae_host2grc(struct ecore_hwfn *p_hwfn,
448 struct ecore_ptt *p_ptt,
455 * @brief ecore_dmae_grc2host - Read data from dmae data offset
456 * to source address using the given ptt
459 * @param grc_addr (dmae_data_offset)
461 * @param size_in_dwords
462 * @param flags - one of the flags defined above
465 ecore_dmae_grc2host(struct ecore_hwfn *p_hwfn,
466 struct ecore_ptt *p_ptt,
468 dma_addr_t dest_addr,
473 * @brief ecore_dmae_host2host - copy data from to source address
474 * to a destination address (for SRIOV) using the given ptt
480 * @param size_in_dwords
484 ecore_dmae_host2host(struct ecore_hwfn *p_hwfn,
485 struct ecore_ptt *p_ptt,
486 dma_addr_t source_addr,
487 dma_addr_t dest_addr,
489 struct ecore_dmae_params *p_params);
492 * @brief ecore_chain_alloc - Allocate and initialize a chain
495 * @param intended_use
501 * @return enum _ecore_status_t
504 ecore_chain_alloc(struct ecore_dev *p_dev,
505 enum ecore_chain_use_mode intended_use,
506 enum ecore_chain_mode mode,
507 enum ecore_chain_cnt_type cnt_type,
509 osal_size_t elem_size,
510 struct ecore_chain *p_chain,
511 struct ecore_chain_ext_pbl *ext_pbl);
514 * @brief ecore_chain_free - Free chain DMA memory
519 void ecore_chain_free(struct ecore_dev *p_dev,
520 struct ecore_chain *p_chain);
523 * @@brief ecore_fw_l2_queue - Get absolute L2 queue ID
526 * @param src_id - relative to p_hwfn
527 * @param dst_id - absolute per engine
529 * @return enum _ecore_status_t
531 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
536 * @@brief ecore_fw_vport - Get absolute vport ID
539 * @param src_id - relative to p_hwfn
540 * @param dst_id - absolute per engine
542 * @return enum _ecore_status_t
544 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
549 * @@brief ecore_fw_rss_eng - Get absolute RSS engine ID
552 * @param src_id - relative to p_hwfn
553 * @param dst_id - absolute per engine
555 * @return enum _ecore_status_t
557 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
562 * @brief ecore_llh_add_mac_filter - configures a MAC filter in llh
566 * @param p_filter - MAC to add
568 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
569 struct ecore_ptt *p_ptt,
573 * @brief ecore_llh_remove_mac_filter - removes a MAC filtre from llh
577 * @param p_filter - MAC to remove
579 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
580 struct ecore_ptt *p_ptt,
583 enum ecore_llh_port_filter_type_t {
584 ECORE_LLH_FILTER_ETHERTYPE,
585 ECORE_LLH_FILTER_TCP_SRC_PORT,
586 ECORE_LLH_FILTER_TCP_DEST_PORT,
587 ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
588 ECORE_LLH_FILTER_UDP_SRC_PORT,
589 ECORE_LLH_FILTER_UDP_DEST_PORT,
590 ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT
594 * @brief ecore_llh_add_protocol_filter - configures a protocol filter in llh
598 * @param source_port_or_eth_type - source port or ethertype to add
599 * @param dest_port - destination port to add
600 * @param type - type of filters and comparing
603 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
604 struct ecore_ptt *p_ptt,
605 u16 source_port_or_eth_type,
607 enum ecore_llh_port_filter_type_t type);
610 * @brief ecore_llh_remove_protocol_filter - remove a protocol filter in llh
614 * @param source_port_or_eth_type - source port or ethertype to add
615 * @param dest_port - destination port to add
616 * @param type - type of filters and comparing
619 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
620 struct ecore_ptt *p_ptt,
621 u16 source_port_or_eth_type,
623 enum ecore_llh_port_filter_type_t type);
626 * @brief ecore_llh_clear_all_filters - removes all MAC filters from llh
631 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
632 struct ecore_ptt *p_ptt);
635 * @brief ecore_llh_set_function_as_default - set function as default per port
641 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
642 struct ecore_ptt *p_ptt);
645 *@brief Cleanup of previous driver remains prior to load
649 * @param id - For PF, engine-relative. For VF, PF-relative.
650 * @param is_vf - true iff cleanup is made for a VF.
652 * @return enum _ecore_status_t
654 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
655 struct ecore_ptt *p_ptt,
660 * @brief ecore_get_queue_coalesce - Retrieve coalesce value for a given queue.
663 * @param p_coal - store coalesce value read from the hardware.
666 * @return enum _ecore_status_t
669 ecore_get_queue_coalesce(struct ecore_hwfn *p_hwfn, u16 *coal,
673 * @brief ecore_set_queue_coalesce - Configure coalesce parameters for Rx and
674 * Tx queue. The fact that we can configure coalescing to up to 511, but on
675 * varying accuracy [the bigger the value the less accurate] up to a mistake
676 * of 3usec for the highest values.
677 * While the API allows setting coalescing per-qid, all queues sharing a SB
678 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
679 * otherwise configuration would break.
682 * @param rx_coal - Rx Coalesce value in micro seconds.
683 * @param tx_coal - TX Coalesce value in micro seconds.
686 * @return enum _ecore_status_t
689 ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn, u16 rx_coal,
690 u16 tx_coal, void *p_handle);
693 * @brief ecore_pglueb_set_pfid_enable - Enable or disable PCI BUS MASTER
697 * @param b_enable - true/false
699 * @return enum _ecore_status_t
701 enum _ecore_status_t ecore_pglueb_set_pfid_enable(struct ecore_hwfn *p_hwfn,
702 struct ecore_ptt *p_ptt,