2 * Copyright (c) 2017-2018 Cavium, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __ECORE_DEV_API_H__
32 #define __ECORE_DEV_API_H__
34 #include "ecore_status.h"
35 #include "ecore_chain.h"
36 #include "ecore_int_api.h"
38 struct ecore_wake_info {
46 * @brief ecore_init_dp - initialize the debug level
53 void ecore_init_dp(struct ecore_dev *p_dev,
59 * @brief ecore_init_struct - initialize the device structure to
64 void ecore_init_struct(struct ecore_dev *p_dev);
67 * @brief ecore_resc_free -
71 void ecore_resc_free(struct ecore_dev *p_dev);
74 * @brief ecore_resc_alloc -
78 * @return enum _ecore_status_t
80 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev);
83 * @brief ecore_resc_setup -
87 void ecore_resc_setup(struct ecore_dev *p_dev);
89 enum ecore_override_force_load {
90 ECORE_OVERRIDE_FORCE_LOAD_NONE,
91 ECORE_OVERRIDE_FORCE_LOAD_ALWAYS,
92 ECORE_OVERRIDE_FORCE_LOAD_NEVER,
95 struct ecore_drv_load_params {
96 /* Indicates whether the driver is running over a crash kernel.
97 * As part of the load request, this will be used for providing the
98 * driver role to the MFW.
99 * In case of a crash kernel over PDA - this should be set to false.
101 bool is_crash_kernel;
103 /* The timeout value that the MFW should use when locking the engine for
104 * the driver load process.
105 * A value of '0' means the default value, and '255' means no timeout.
108 #define ECORE_LOAD_REQ_LOCK_TO_DEFAULT 0
109 #define ECORE_LOAD_REQ_LOCK_TO_NONE 255
111 /* Avoid engine reset when first PF loads on it */
112 bool avoid_eng_reset;
114 /* Allow overriding the default force load behavior */
115 enum ecore_override_force_load override_force_load;
118 struct ecore_hw_init_params {
119 /* Tunneling parameters */
120 struct ecore_tunnel_info *p_tunn;
124 /* Interrupt mode [msix, inta, etc.] to use */
125 enum ecore_int_mode int_mode;
127 /* NPAR tx switching to be used for vports configured for tx-switching */
128 bool allow_npar_tx_switch;
130 /* Binary fw data pointer in binary fw file */
131 const u8 *bin_fw_data;
133 /* Driver load parameters */
134 struct ecore_drv_load_params *p_drv_load_params;
138 * @brief ecore_hw_init -
143 * @return enum _ecore_status_t
145 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
146 struct ecore_hw_init_params *p_params);
149 * @brief ecore_hw_timers_stop_all -
155 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev);
158 * @brief ecore_hw_stop -
162 * @return enum _ecore_status_t
164 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev);
167 * @brief ecore_hw_stop_fastpath -should be called incase
168 * slowpath is still required for the device,
169 * but fastpath is not.
173 * @return enum _ecore_status_t
175 enum _ecore_status_t ecore_hw_stop_fastpath(struct ecore_dev *p_dev);
178 * @brief ecore_hw_hibernate_prepare -should be called when
179 * the system is going into the hibernate state
184 void ecore_hw_hibernate_prepare(struct ecore_dev *p_dev);
187 * @brief ecore_hw_hibernate_resume -should be called when the system is
188 resuming from D3 power state and before calling ecore_hw_init.
193 void ecore_hw_hibernate_resume(struct ecore_dev *p_dev);
197 * @brief ecore_hw_start_fastpath -restart fastpath traffic,
198 * only if hw_stop_fastpath was called
202 * @return enum _ecore_status_t
204 enum _ecore_status_t ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn);
206 enum ecore_hw_prepare_result {
207 ECORE_HW_PREPARE_SUCCESS,
209 /* FAILED results indicate probe has failed & cleaned up */
210 ECORE_HW_PREPARE_FAILED_ENG2,
211 ECORE_HW_PREPARE_FAILED_ME,
212 ECORE_HW_PREPARE_FAILED_MEM,
213 ECORE_HW_PREPARE_FAILED_DEV,
214 ECORE_HW_PREPARE_FAILED_NVM,
216 /* BAD results indicate probe is passed even though some wrongness
217 * has occurred; Trying to actually use [I.e., hw_init()] might have
218 * dire reprecautions.
220 ECORE_HW_PREPARE_BAD_IOV,
221 ECORE_HW_PREPARE_BAD_MCP,
222 ECORE_HW_PREPARE_BAD_IGU,
225 struct ecore_hw_prepare_params {
226 /* Personality to initialize */
229 /* Force the driver's default resource allocation */
232 /* Check the reg_fifo after any register access */
235 /* Request the MFW to initiate PF FLR */
236 bool initiate_pf_flr;
238 /* The OS Epoch time in seconds */
241 /* Allow the MFW to collect a crash dump */
244 /* Allow prepare to pass even if some initializations are failing.
245 * If set, the `p_prepare_res' field would be set with the return,
246 * and might allow probe to pass even if there are certain issues.
248 bool b_relaxed_probe;
249 enum ecore_hw_prepare_result p_relaxed_res;
253 * @brief ecore_hw_prepare -
258 * @return enum _ecore_status_t
260 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
261 struct ecore_hw_prepare_params *p_params);
264 * @brief ecore_hw_remove -
268 void ecore_hw_remove(struct ecore_dev *p_dev);
271 * @brief ecore_set_nwuf_reg -
274 * @param reg_idx - Index of the pattern register
275 * @param pattern_size - size of pattern
276 * @param crc - CRC value of patter & mask
278 * @return enum _ecore_status_t
280 enum _ecore_status_t ecore_set_nwuf_reg(struct ecore_dev *p_dev,
281 u32 reg_idx, u32 pattern_size, u32 crc);
284 * @brief ecore_get_wake_info - get magic packet buffer
288 * @param wake_info - pointer to ecore_wake_info buffer
290 * @return enum _ecore_status_t
292 enum _ecore_status_t ecore_get_wake_info(struct ecore_hwfn *p_hwfn,
293 struct ecore_ptt *p_ptt,
294 struct ecore_wake_info *wake_info);
297 * @brief ecore_wol_buffer_clear - Clear magic package buffer
304 void ecore_wol_buffer_clear(struct ecore_hwfn *p_hwfn,
305 struct ecore_ptt *p_ptt);
308 * @brief ecore_ptt_acquire - Allocate a PTT window
310 * Should be called at the entry point to the driver (at the beginning of an
315 * @return struct ecore_ptt
317 struct ecore_ptt *ecore_ptt_acquire(struct ecore_hwfn *p_hwfn);
320 * @brief ecore_ptt_release - Release PTT Window
322 * Should be called at the end of a flow - at the end of the function that
329 void ecore_ptt_release(struct ecore_hwfn *p_hwfn,
330 struct ecore_ptt *p_ptt);
332 #ifndef __EXTRACT__LINUX__
333 struct ecore_eth_stats_common {
334 u64 no_buff_discards;
335 u64 packet_too_big_discard;
343 u64 mftag_filter_discards;
344 u64 mac_filter_discards;
351 u64 tx_err_drop_pkts;
352 u64 tpa_coalesced_pkts;
353 u64 tpa_coalesced_events;
355 u64 tpa_not_coalesced_pkts;
356 u64 tpa_coalesced_bytes;
359 u64 rx_64_byte_packets;
360 u64 rx_65_to_127_byte_packets;
361 u64 rx_128_to_255_byte_packets;
362 u64 rx_256_to_511_byte_packets;
363 u64 rx_512_to_1023_byte_packets;
364 u64 rx_1024_to_1518_byte_packets;
366 u64 rx_mac_crtl_frames;
370 u64 rx_carrier_errors;
371 u64 rx_oversize_packets;
373 u64 rx_undersize_packets;
375 u64 tx_64_byte_packets;
376 u64 tx_65_to_127_byte_packets;
377 u64 tx_128_to_255_byte_packets;
378 u64 tx_256_to_511_byte_packets;
379 u64 tx_512_to_1023_byte_packets;
380 u64 tx_1024_to_1518_byte_packets;
386 u64 rx_mac_uc_packets;
387 u64 rx_mac_mc_packets;
388 u64 rx_mac_bc_packets;
389 u64 rx_mac_frames_ok;
391 u64 tx_mac_uc_packets;
392 u64 tx_mac_mc_packets;
393 u64 tx_mac_bc_packets;
394 u64 tx_mac_ctrl_frames;
397 struct ecore_eth_stats_bb {
398 u64 rx_1519_to_1522_byte_packets;
399 u64 rx_1519_to_2047_byte_packets;
400 u64 rx_2048_to_4095_byte_packets;
401 u64 rx_4096_to_9216_byte_packets;
402 u64 rx_9217_to_16383_byte_packets;
403 u64 tx_1519_to_2047_byte_packets;
404 u64 tx_2048_to_4095_byte_packets;
405 u64 tx_4096_to_9216_byte_packets;
406 u64 tx_9217_to_16383_byte_packets;
407 u64 tx_lpi_entry_count;
408 u64 tx_total_collisions;
411 struct ecore_eth_stats_ah {
412 u64 rx_1519_to_max_byte_packets;
413 u64 tx_1519_to_max_byte_packets;
416 struct ecore_eth_stats {
417 struct ecore_eth_stats_common common;
419 struct ecore_eth_stats_bb bb;
420 struct ecore_eth_stats_ah ah;
425 enum ecore_dmae_address_type_t {
426 ECORE_DMAE_ADDRESS_HOST_VIRT,
427 ECORE_DMAE_ADDRESS_HOST_PHYS,
428 ECORE_DMAE_ADDRESS_GRC
431 /* value of flags If ECORE_DMAE_FLAG_RW_REPL_SRC flag is set and the
432 * source is a block of length DMAE_MAX_RW_SIZE and the
433 * destination is larger, the source block will be duplicated as
434 * many times as required to fill the destination block. This is
435 * used mostly to write a zeroed buffer to destination address
438 #define ECORE_DMAE_FLAG_RW_REPL_SRC 0x00000001
439 #define ECORE_DMAE_FLAG_VF_SRC 0x00000002
440 #define ECORE_DMAE_FLAG_VF_DST 0x00000004
441 #define ECORE_DMAE_FLAG_COMPLETION_DST 0x00000008
443 struct ecore_dmae_params {
444 u32 flags; /* consists of ECORE_DMAE_FLAG_* values */
450 * @brief ecore_dmae_host2grc - copy data from source addr to
451 * dmae registers using the given ptt
456 * @param grc_addr (dmae_data_offset)
457 * @param size_in_dwords
458 * @param flags (one of the flags defined above)
461 ecore_dmae_host2grc(struct ecore_hwfn *p_hwfn,
462 struct ecore_ptt *p_ptt,
469 * @brief ecore_dmae_grc2host - Read data from dmae data offset
470 * to source address using the given ptt
473 * @param grc_addr (dmae_data_offset)
475 * @param size_in_dwords
476 * @param flags - one of the flags defined above
479 ecore_dmae_grc2host(struct ecore_hwfn *p_hwfn,
480 struct ecore_ptt *p_ptt,
482 dma_addr_t dest_addr,
487 * @brief ecore_dmae_host2host - copy data from to source address
488 * to a destination adress (for SRIOV) using the given ptt
494 * @param size_in_dwords
498 ecore_dmae_host2host(struct ecore_hwfn *p_hwfn,
499 struct ecore_ptt *p_ptt,
500 dma_addr_t source_addr,
501 dma_addr_t dest_addr,
503 struct ecore_dmae_params *p_params);
506 * @brief ecore_chain_alloc - Allocate and initialize a chain
509 * @param intended_use
515 * @return enum _ecore_status_t
518 ecore_chain_alloc(struct ecore_dev *p_dev,
519 enum ecore_chain_use_mode intended_use,
520 enum ecore_chain_mode mode,
521 enum ecore_chain_cnt_type cnt_type,
523 osal_size_t elem_size,
524 struct ecore_chain *p_chain,
525 struct ecore_chain_ext_pbl *ext_pbl);
528 * @brief ecore_chain_free - Free chain DMA memory
533 void ecore_chain_free(struct ecore_dev *p_dev,
534 struct ecore_chain *p_chain);
537 * @@brief ecore_fw_l2_queue - Get absolute L2 queue ID
540 * @param src_id - relative to p_hwfn
541 * @param dst_id - absolute per engine
543 * @return enum _ecore_status_t
545 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
550 * @@brief ecore_fw_vport - Get absolute vport ID
553 * @param src_id - relative to p_hwfn
554 * @param dst_id - absolute per engine
556 * @return enum _ecore_status_t
558 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
563 * @@brief ecore_fw_rss_eng - Get absolute RSS engine ID
566 * @param src_id - relative to p_hwfn
567 * @param dst_id - absolute per engine
569 * @return enum _ecore_status_t
571 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
576 * @brief ecore_llh_add_mac_filter - configures a MAC filter in llh
580 * @param p_filter - MAC to add
582 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
583 struct ecore_ptt *p_ptt,
587 * @brief ecore_llh_remove_mac_filter - removes a MAC filtre from llh
591 * @param p_filter - MAC to remove
593 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
594 struct ecore_ptt *p_ptt,
597 enum ecore_llh_port_filter_type_t {
598 ECORE_LLH_FILTER_ETHERTYPE,
599 ECORE_LLH_FILTER_TCP_SRC_PORT,
600 ECORE_LLH_FILTER_TCP_DEST_PORT,
601 ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
602 ECORE_LLH_FILTER_UDP_SRC_PORT,
603 ECORE_LLH_FILTER_UDP_DEST_PORT,
604 ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT
608 * @brief ecore_llh_add_protocol_filter - configures a protocol filter in llh
612 * @param source_port_or_eth_type - source port or ethertype to add
613 * @param dest_port - destination port to add
614 * @param type - type of filters and comparing
617 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
618 struct ecore_ptt *p_ptt,
619 u16 source_port_or_eth_type,
621 enum ecore_llh_port_filter_type_t type);
624 * @brief ecore_llh_remove_protocol_filter - remove a protocol filter in llh
628 * @param source_port_or_eth_type - source port or ethertype to add
629 * @param dest_port - destination port to add
630 * @param type - type of filters and comparing
633 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
634 struct ecore_ptt *p_ptt,
635 u16 source_port_or_eth_type,
637 enum ecore_llh_port_filter_type_t type);
640 * @brief ecore_llh_clear_all_filters - removes all MAC filters from llh
645 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
646 struct ecore_ptt *p_ptt);
649 * @brief ecore_llh_set_function_as_default - set function as defult per port
655 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
656 struct ecore_ptt *p_ptt);
659 *@brief Cleanup of previous driver remains prior to load
663 * @param id - For PF, engine-relative. For VF, PF-relative.
664 * @param is_vf - true iff cleanup is made for a VF.
666 * @return enum _ecore_status_t
668 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
669 struct ecore_ptt *p_ptt,
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 - Recalculate feature distributions based on HW resources and
694 * user inputs. Currently this affects RDMA_CNQ, PF_L2_QUE and VF_L2_QUE.
695 * As a result, this must not be called while RDMA is active or while VFs
700 void ecore_hw_set_feat(struct ecore_hwfn *p_hwfn);
703 * @brief ecore_change_pci_hwfn - Enable or disable PCI BUS MASTER
707 * @param enable - true/false
709 * @return enum _ecore_status_t
712 ecore_change_pci_hwfn(struct ecore_hwfn *p_hwfn,
713 struct ecore_ptt *p_ptt,
716 #ifndef __EXTRACT__LINUX__
717 enum ecore_db_rec_width {
722 enum ecore_db_rec_space {
729 * @brief db_recovery_add - add doorbell information to the doorbell
730 * recovery mechanism.
733 * @param db_addr - doorbell address
734 * @param db_data - address of where db_data is stored
735 * @param db_width - doorbell is 32b pr 64b
736 * @param db_space - doorbell recovery addresses are user or kernel space
738 enum _ecore_status_t ecore_db_recovery_add(struct ecore_dev *p_dev,
739 void OSAL_IOMEM *db_addr,
741 enum ecore_db_rec_width db_width,
742 enum ecore_db_rec_space db_space);
745 * @brief db_recovery_del - remove doorbell information from the doorbell
746 * recovery mechanism. db_data serves as key (db_addr is not unique).
749 * @param db_addr - doorbell address
750 * @param db_data - address where db_data is stored. Serves as key for the
753 enum _ecore_status_t ecore_db_recovery_del(struct ecore_dev *p_dev,
754 void OSAL_IOMEM *db_addr,