1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /* QLogic qed NIC Driver
3 * Copyright (c) 2015-2017 QLogic Corporation
4 * Copyright (c) 2019-2020 Marvell International Ltd.
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/qed/qed_chain.h>
14 #include <linux/qed/qed_if.h>
18 * @brief qed_init_dp - initialize the debug level
24 void qed_init_dp(struct qed_dev
*cdev
,
29 * @brief qed_init_struct - initialize the device structure to
34 void qed_init_struct(struct qed_dev
*cdev
);
37 * @brief qed_resc_free -
41 void qed_resc_free(struct qed_dev
*cdev
);
44 * @brief qed_resc_alloc -
50 int qed_resc_alloc(struct qed_dev
*cdev
);
53 * @brief qed_resc_setup -
57 void qed_resc_setup(struct qed_dev
*cdev
);
59 enum qed_override_force_load
{
60 QED_OVERRIDE_FORCE_LOAD_NONE
,
61 QED_OVERRIDE_FORCE_LOAD_ALWAYS
,
62 QED_OVERRIDE_FORCE_LOAD_NEVER
,
65 struct qed_drv_load_params
{
66 /* Indicates whether the driver is running over a crash kernel.
67 * As part of the load request, this will be used for providing the
68 * driver role to the MFW.
69 * In case of a crash kernel over PDA - this should be set to false.
73 /* The timeout value that the MFW should use when locking the engine for
74 * the driver load process.
75 * A value of '0' means the default value, and '255' means no timeout.
78 #define QED_LOAD_REQ_LOCK_TO_DEFAULT 0
79 #define QED_LOAD_REQ_LOCK_TO_NONE 255
81 /* Avoid engine reset when first PF loads on it */
84 /* Allow overriding the default force load behavior */
85 enum qed_override_force_load override_force_load
;
88 struct qed_hw_init_params
{
89 /* Tunneling parameters */
90 struct qed_tunnel_info
*p_tunn
;
94 /* Interrupt mode [msix, inta, etc.] to use */
95 enum qed_int_mode int_mode
;
97 /* NPAR tx switching to be used for vports for tx-switching */
98 bool allow_npar_tx_switch
;
100 /* Binary fw data pointer in binary fw file */
101 const u8
*bin_fw_data
;
103 /* Driver load parameters */
104 struct qed_drv_load_params
*p_drv_load_params
;
108 * @brief qed_hw_init -
115 int qed_hw_init(struct qed_dev
*cdev
, struct qed_hw_init_params
*p_params
);
118 * @brief qed_hw_timers_stop_all - stop the timers HW block
124 void qed_hw_timers_stop_all(struct qed_dev
*cdev
);
127 * @brief qed_hw_stop -
133 int qed_hw_stop(struct qed_dev
*cdev
);
136 * @brief qed_hw_stop_fastpath -should be called incase
137 * slowpath is still required for the device,
138 * but fastpath is not.
144 int qed_hw_stop_fastpath(struct qed_dev
*cdev
);
147 * @brief qed_hw_start_fastpath -restart fastpath traffic,
148 * only if hw_stop_fastpath was called
154 int qed_hw_start_fastpath(struct qed_hwfn
*p_hwfn
);
158 * @brief qed_hw_prepare -
161 * @param personality - personality to initialize
165 int qed_hw_prepare(struct qed_dev
*cdev
,
169 * @brief qed_hw_remove -
173 void qed_hw_remove(struct qed_dev
*cdev
);
176 * @brief qed_ptt_acquire - Allocate a PTT window
178 * Should be called at the entry point to the driver (at the beginning of an
183 * @return struct qed_ptt
185 struct qed_ptt
*qed_ptt_acquire(struct qed_hwfn
*p_hwfn
);
188 * @brief qed_ptt_release - Release PTT Window
190 * Should be called at the end of a flow - at the end of the function that
197 void qed_ptt_release(struct qed_hwfn
*p_hwfn
,
198 struct qed_ptt
*p_ptt
);
199 void qed_reset_vport_stats(struct qed_dev
*cdev
);
201 enum qed_dmae_address_type_t
{
202 QED_DMAE_ADDRESS_HOST_VIRT
,
203 QED_DMAE_ADDRESS_HOST_PHYS
,
208 * @brief qed_dmae_host2grc - copy data from source addr to
209 * dmae registers using the given ptt
214 * @param grc_addr (dmae_data_offset)
215 * @param size_in_dwords
216 * @param p_params (default parameters will be used in case of NULL)
219 qed_dmae_host2grc(struct qed_hwfn
*p_hwfn
,
220 struct qed_ptt
*p_ptt
,
224 struct qed_dmae_params
*p_params
);
227 * @brief qed_dmae_grc2host - Read data from dmae data offset
228 * to source address using the given ptt
231 * @param grc_addr (dmae_data_offset)
233 * @param size_in_dwords
234 * @param p_params (default parameters will be used in case of NULL)
236 int qed_dmae_grc2host(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,
237 u32 grc_addr
, dma_addr_t dest_addr
, u32 size_in_dwords
,
238 struct qed_dmae_params
*p_params
);
241 * @brief qed_dmae_host2host - copy data from to source address
242 * to a destination adress (for SRIOV) using the given ptt
248 * @param size_in_dwords
249 * @param p_params (default parameters will be used in case of NULL)
251 int qed_dmae_host2host(struct qed_hwfn
*p_hwfn
,
252 struct qed_ptt
*p_ptt
,
253 dma_addr_t source_addr
,
254 dma_addr_t dest_addr
,
255 u32 size_in_dwords
, struct qed_dmae_params
*p_params
);
257 int qed_chain_alloc(struct qed_dev
*cdev
, struct qed_chain
*chain
,
258 struct qed_chain_init_params
*params
);
259 void qed_chain_free(struct qed_dev
*cdev
, struct qed_chain
*chain
);
262 * @@brief qed_fw_l2_queue - Get absolute L2 queue ID
265 * @param src_id - relative to p_hwfn
266 * @param dst_id - absolute per engine
270 int qed_fw_l2_queue(struct qed_hwfn
*p_hwfn
,
275 * @@brief qed_fw_vport - Get absolute vport ID
278 * @param src_id - relative to p_hwfn
279 * @param dst_id - absolute per engine
283 int qed_fw_vport(struct qed_hwfn
*p_hwfn
,
288 * @@brief qed_fw_rss_eng - Get absolute RSS engine ID
291 * @param src_id - relative to p_hwfn
292 * @param dst_id - absolute per engine
296 int qed_fw_rss_eng(struct qed_hwfn
*p_hwfn
,
301 * @brief qed_llh_get_num_ppfid - Return the allocated number of LLH filter
302 * banks that are allocated to the PF.
306 * @return u8 - Number of LLH filter banks
308 u8
qed_llh_get_num_ppfid(struct qed_dev
*cdev
);
317 * @brief qed_llh_set_ppfid_affinity - Set the engine affinity for the given
321 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
326 int qed_llh_set_ppfid_affinity(struct qed_dev
*cdev
,
327 u8 ppfid
, enum qed_eng eng
);
330 * @brief qed_llh_set_roce_affinity - Set the RoCE engine affinity
337 int qed_llh_set_roce_affinity(struct qed_dev
*cdev
, enum qed_eng eng
);
340 * @brief qed_llh_add_mac_filter - Add a LLH MAC filter into the given filter
344 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
345 * @param mac_addr - MAC to add
347 int qed_llh_add_mac_filter(struct qed_dev
*cdev
,
348 u8 ppfid
, u8 mac_addr
[ETH_ALEN
]);
351 * @brief qed_llh_remove_mac_filter - Remove a LLH MAC filter from the given
355 * @param p_filter - MAC to remove
357 void qed_llh_remove_mac_filter(struct qed_dev
*cdev
,
358 u8 ppfid
, u8 mac_addr
[ETH_ALEN
]);
360 enum qed_llh_prot_filter_type_t
{
361 QED_LLH_FILTER_ETHERTYPE
,
362 QED_LLH_FILTER_TCP_SRC_PORT
,
363 QED_LLH_FILTER_TCP_DEST_PORT
,
364 QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT
,
365 QED_LLH_FILTER_UDP_SRC_PORT
,
366 QED_LLH_FILTER_UDP_DEST_PORT
,
367 QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT
371 * @brief qed_llh_add_protocol_filter - Add a LLH protocol filter into the
375 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
376 * @param type - type of filters and comparing
377 * @param source_port_or_eth_type - source port or ethertype to add
378 * @param dest_port - destination port to add
379 * @param type - type of filters and comparing
382 qed_llh_add_protocol_filter(struct qed_dev
*cdev
,
384 enum qed_llh_prot_filter_type_t type
,
385 u16 source_port_or_eth_type
, u16 dest_port
);
388 * @brief qed_llh_remove_protocol_filter - Remove a LLH protocol filter from
389 * the given filter bank.
392 * @param ppfid - relative within the allocated ppfids ('0' is the default one).
393 * @param type - type of filters and comparing
394 * @param source_port_or_eth_type - source port or ethertype to add
395 * @param dest_port - destination port to add
398 qed_llh_remove_protocol_filter(struct qed_dev
*cdev
,
400 enum qed_llh_prot_filter_type_t type
,
401 u16 source_port_or_eth_type
, u16 dest_port
);
404 * *@brief Cleanup of previous driver remains prior to load
408 * @param id - For PF, engine-relative. For VF, PF-relative.
409 * @param is_vf - true iff cleanup is made for a VF.
413 int qed_final_cleanup(struct qed_hwfn
*p_hwfn
,
414 struct qed_ptt
*p_ptt
, u16 id
, bool is_vf
);
417 * @brief qed_get_queue_coalesce - Retrieve coalesce value for a given queue.
420 * @param p_coal - store coalesce value read from the hardware.
425 int qed_get_queue_coalesce(struct qed_hwfn
*p_hwfn
, u16
*coal
, void *handle
);
428 * @brief qed_set_queue_coalesce - Configure coalesce parameters for Rx and
429 * Tx queue. The fact that we can configure coalescing to up to 511, but on
430 * varying accuracy [the bigger the value the less accurate] up to a mistake
431 * of 3usec for the highest values.
432 * While the API allows setting coalescing per-qid, all queues sharing a SB
433 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
434 * otherwise configuration would break.
437 * @param rx_coal - Rx Coalesce value in micro seconds.
438 * @param tx_coal - TX Coalesce value in micro seconds.
444 qed_set_queue_coalesce(u16 rx_coal
, u16 tx_coal
, void *p_handle
);
447 * @brief qed_pglueb_set_pfid_enable - Enable or disable PCI BUS MASTER
451 * @param b_enable - true/false
455 int qed_pglueb_set_pfid_enable(struct qed_hwfn
*p_hwfn
,
456 struct qed_ptt
*p_ptt
, bool b_enable
);
459 * @brief db_recovery_add - add doorbell information to the doorbell
460 * recovery mechanism.
463 * @param db_addr - doorbell address
464 * @param db_data - address of where db_data is stored
465 * @param db_width - doorbell is 32b pr 64b
466 * @param db_space - doorbell recovery addresses are user or kernel space
468 int qed_db_recovery_add(struct qed_dev
*cdev
,
469 void __iomem
*db_addr
,
471 enum qed_db_rec_width db_width
,
472 enum qed_db_rec_space db_space
);
475 * @brief db_recovery_del - remove doorbell information from the doorbell
476 * recovery mechanism. db_data serves as key (db_addr is not unique).
479 * @param db_addr - doorbell address
480 * @param db_data - address where db_data is stored. Serves as key for the
483 int qed_db_recovery_del(struct qed_dev
*cdev
,
484 void __iomem
*db_addr
, void *db_data
);
487 const char *qed_hw_get_resc_name(enum qed_resources res_id
);