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 * qed_init_dp(): Initialize the debug level.
20 * @cdev: Qed dev pointer.
21 * @dp_module: Module debug parameter.
22 * @dp_level: Module debug level.
26 void qed_init_dp(struct qed_dev
*cdev
,
31 * qed_init_struct(): Initialize the device structure to
34 * @cdev: Qed dev pointer.
38 void qed_init_struct(struct qed_dev
*cdev
);
41 * qed_resc_free: Free device resources.
43 * @cdev: Qed dev pointer.
47 void qed_resc_free(struct qed_dev
*cdev
);
50 * qed_resc_alloc(): Alloc device resources.
52 * @cdev: Qed dev pointer.
56 int qed_resc_alloc(struct qed_dev
*cdev
);
59 * qed_resc_setup(): Setup device resources.
61 * @cdev: Qed dev pointer.
65 void qed_resc_setup(struct qed_dev
*cdev
);
67 enum qed_override_force_load
{
68 QED_OVERRIDE_FORCE_LOAD_NONE
,
69 QED_OVERRIDE_FORCE_LOAD_ALWAYS
,
70 QED_OVERRIDE_FORCE_LOAD_NEVER
,
73 struct qed_drv_load_params
{
74 /* Indicates whether the driver is running over a crash kernel.
75 * As part of the load request, this will be used for providing the
76 * driver role to the MFW.
77 * In case of a crash kernel over PDA - this should be set to false.
81 /* The timeout value that the MFW should use when locking the engine for
82 * the driver load process.
83 * A value of '0' means the default value, and '255' means no timeout.
86 #define QED_LOAD_REQ_LOCK_TO_DEFAULT 0
87 #define QED_LOAD_REQ_LOCK_TO_NONE 255
89 /* Avoid engine reset when first PF loads on it */
92 /* Allow overriding the default force load behavior */
93 enum qed_override_force_load override_force_load
;
96 struct qed_hw_init_params
{
97 /* Tunneling parameters */
98 struct qed_tunnel_info
*p_tunn
;
102 /* Interrupt mode [msix, inta, etc.] to use */
103 enum qed_int_mode int_mode
;
105 /* NPAR tx switching to be used for vports for tx-switching */
106 bool allow_npar_tx_switch
;
108 /* Binary fw data pointer in binary fw file */
109 const u8
*bin_fw_data
;
111 /* Driver load parameters */
112 struct qed_drv_load_params
*p_drv_load_params
;
116 * qed_hw_init(): Init Qed hardware.
118 * @cdev: Qed dev pointer.
119 * @p_params: Pointers to params.
123 int qed_hw_init(struct qed_dev
*cdev
, struct qed_hw_init_params
*p_params
);
126 * qed_hw_timers_stop_all(): Stop the timers HW block.
128 * @cdev: Qed dev pointer.
132 void qed_hw_timers_stop_all(struct qed_dev
*cdev
);
135 * qed_hw_stop(): Stop Qed hardware.
137 * @cdev: Qed dev pointer.
141 int qed_hw_stop(struct qed_dev
*cdev
);
144 * qed_hw_stop_fastpath(): Should be called incase
145 * slowpath is still required for the device,
146 * but fastpath is not.
148 * @cdev: Qed dev pointer.
152 int qed_hw_stop_fastpath(struct qed_dev
*cdev
);
155 * qed_hw_start_fastpath(): Restart fastpath traffic,
156 * only if hw_stop_fastpath was called.
158 * @p_hwfn: HW device data.
162 int qed_hw_start_fastpath(struct qed_hwfn
*p_hwfn
);
165 * qed_hw_prepare(): Prepare Qed hardware.
167 * @cdev: Qed dev pointer.
168 * @personality: Personality to initialize.
172 int qed_hw_prepare(struct qed_dev
*cdev
,
176 * qed_hw_remove(): Remove Qed hardware.
178 * @cdev: Qed dev pointer.
182 void qed_hw_remove(struct qed_dev
*cdev
);
185 * qed_ptt_acquire(): Allocate a PTT window.
187 * @p_hwfn: HW device data.
189 * Return: struct qed_ptt.
191 * Should be called at the entry point to the driver (at the beginning of an
192 * exported function).
194 struct qed_ptt
*qed_ptt_acquire(struct qed_hwfn
*p_hwfn
);
197 * qed_ptt_acquire_context(): Allocate a PTT window honoring the context
200 * @p_hwfn: HW device data.
201 * @is_atomic: Hint from the caller - if the func can sleep or not.
203 * Context: The function should not sleep in case is_atomic == true.
204 * Return: struct qed_ptt.
206 * Should be called at the entry point to the driver
207 * (at the beginning of an exported function).
209 struct qed_ptt
*qed_ptt_acquire_context(struct qed_hwfn
*p_hwfn
,
213 * qed_ptt_release(): Release PTT Window.
215 * @p_hwfn: HW device data.
220 * Should be called at the end of a flow - at the end of the function that
223 void qed_ptt_release(struct qed_hwfn
*p_hwfn
,
224 struct qed_ptt
*p_ptt
);
225 void qed_reset_vport_stats(struct qed_dev
*cdev
);
227 enum qed_dmae_address_type_t
{
228 QED_DMAE_ADDRESS_HOST_VIRT
,
229 QED_DMAE_ADDRESS_HOST_PHYS
,
234 * qed_dmae_host2grc(): Copy data from source addr to
235 * dmae registers using the given ptt.
237 * @p_hwfn: HW device data.
239 * @source_addr: Source address.
240 * @grc_addr: GRC address (dmae_data_offset).
241 * @size_in_dwords: Size.
242 * @p_params: (default parameters will be used in case of NULL).
247 qed_dmae_host2grc(struct qed_hwfn
*p_hwfn
,
248 struct qed_ptt
*p_ptt
,
252 struct qed_dmae_params
*p_params
);
255 * qed_dmae_grc2host(): Read data from dmae data offset
256 * to source address using the given ptt.
259 * @grc_addr: GRC address (dmae_data_offset).
260 * @dest_addr: Destination Address.
261 * @size_in_dwords: Size.
262 * @p_params: (default parameters will be used in case of NULL).
266 int qed_dmae_grc2host(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,
267 u32 grc_addr
, dma_addr_t dest_addr
, u32 size_in_dwords
,
268 struct qed_dmae_params
*p_params
);
271 * qed_dmae_host2host(): Copy data from to source address
272 * to a destination adrress (for SRIOV) using the given
275 * @p_hwfn: HW device data.
277 * @source_addr: Source address.
278 * @dest_addr: Destination address.
279 * @size_in_dwords: size.
280 * @p_params: (default parameters will be used in case of NULL).
284 int qed_dmae_host2host(struct qed_hwfn
*p_hwfn
,
285 struct qed_ptt
*p_ptt
,
286 dma_addr_t source_addr
,
287 dma_addr_t dest_addr
,
288 u32 size_in_dwords
, struct qed_dmae_params
*p_params
);
290 int qed_chain_alloc(struct qed_dev
*cdev
, struct qed_chain
*chain
,
291 struct qed_chain_init_params
*params
);
292 void qed_chain_free(struct qed_dev
*cdev
, struct qed_chain
*chain
);
295 * qed_fw_l2_queue(): Get absolute L2 queue ID.
297 * @p_hwfn: HW device data.
298 * @src_id: Relative to p_hwfn.
299 * @dst_id: Absolute per engine.
303 int qed_fw_l2_queue(struct qed_hwfn
*p_hwfn
,
308 * qed_fw_vport(): Get absolute vport ID.
310 * @p_hwfn: HW device data.
311 * @src_id: Relative to p_hwfn.
312 * @dst_id: Absolute per engine.
316 int qed_fw_vport(struct qed_hwfn
*p_hwfn
,
321 * qed_fw_rss_eng(): Get absolute RSS engine ID.
323 * @p_hwfn: HW device data.
324 * @src_id: Relative to p_hwfn.
325 * @dst_id: Absolute per engine.
329 int qed_fw_rss_eng(struct qed_hwfn
*p_hwfn
,
334 * qed_llh_get_num_ppfid(): Return the allocated number of LLH filter
335 * banks that are allocated to the PF.
337 * @cdev: Qed dev pointer.
339 * Return: u8 Number of LLH filter banks.
341 u8
qed_llh_get_num_ppfid(struct qed_dev
*cdev
);
350 * qed_llh_set_ppfid_affinity(): Set the engine affinity for the given
353 * @cdev: Qed dev pointer.
354 * @ppfid: Relative within the allocated ppfids ('0' is the default one).
359 int qed_llh_set_ppfid_affinity(struct qed_dev
*cdev
,
360 u8 ppfid
, enum qed_eng eng
);
363 * qed_llh_set_roce_affinity(): Set the RoCE engine affinity.
365 * @cdev: Qed dev pointer.
370 int qed_llh_set_roce_affinity(struct qed_dev
*cdev
, enum qed_eng eng
);
373 * qed_llh_add_mac_filter(): Add a LLH MAC filter into the given filter
376 * @cdev: Qed dev pointer.
377 * @ppfid: Relative within the allocated ppfids ('0' is the default one).
378 * @mac_addr: MAC to add.
382 int qed_llh_add_mac_filter(struct qed_dev
*cdev
,
383 u8 ppfid
, const u8 mac_addr
[ETH_ALEN
]);
386 * qed_llh_remove_mac_filter(): Remove a LLH MAC filter from the given
389 * @cdev: Qed dev pointer.
391 * @mac_addr: MAC to remove
395 void qed_llh_remove_mac_filter(struct qed_dev
*cdev
,
396 u8 ppfid
, u8 mac_addr
[ETH_ALEN
]);
398 enum qed_llh_prot_filter_type_t
{
399 QED_LLH_FILTER_ETHERTYPE
,
400 QED_LLH_FILTER_TCP_SRC_PORT
,
401 QED_LLH_FILTER_TCP_DEST_PORT
,
402 QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT
,
403 QED_LLH_FILTER_UDP_SRC_PORT
,
404 QED_LLH_FILTER_UDP_DEST_PORT
,
405 QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT
409 * qed_llh_add_protocol_filter(): Add a LLH protocol filter into the
412 * @cdev: Qed dev pointer.
413 * @ppfid: Relative within the allocated ppfids ('0' is the default one).
414 * @type: Type of filters and comparing.
415 * @source_port_or_eth_type: Source port or ethertype to add.
416 * @dest_port: Destination port to add.
421 qed_llh_add_protocol_filter(struct qed_dev
*cdev
,
423 enum qed_llh_prot_filter_type_t type
,
424 u16 source_port_or_eth_type
, u16 dest_port
);
427 * qed_llh_remove_protocol_filter(): Remove a LLH protocol filter from
428 * the given filter bank.
430 * @cdev: Qed dev pointer.
431 * @ppfid: Relative within the allocated ppfids ('0' is the default one).
432 * @type: Type of filters and comparing.
433 * @source_port_or_eth_type: Source port or ethertype to add.
434 * @dest_port: Destination port to add.
437 qed_llh_remove_protocol_filter(struct qed_dev
*cdev
,
439 enum qed_llh_prot_filter_type_t type
,
440 u16 source_port_or_eth_type
, u16 dest_port
);
443 * qed_final_cleanup(): Cleanup of previous driver remains prior to load.
445 * @p_hwfn: HW device data.
447 * @id: For PF, engine-relative. For VF, PF-relative.
448 * @is_vf: True iff cleanup is made for a VF.
452 int qed_final_cleanup(struct qed_hwfn
*p_hwfn
,
453 struct qed_ptt
*p_ptt
, u16 id
, bool is_vf
);
456 * qed_get_queue_coalesce(): Retrieve coalesce value for a given queue.
458 * @p_hwfn: HW device data.
459 * @coal: Store coalesce value read from the hardware.
464 int qed_get_queue_coalesce(struct qed_hwfn
*p_hwfn
, u16
*coal
, void *handle
);
467 * qed_set_queue_coalesce(): Configure coalesce parameters for Rx and
468 * Tx queue. The fact that we can configure coalescing to up to 511, but on
469 * varying accuracy [the bigger the value the less accurate] up to a mistake
470 * of 3usec for the highest values.
471 * While the API allows setting coalescing per-qid, all queues sharing a SB
472 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
473 * otherwise configuration would break.
475 * @rx_coal: Rx Coalesce value in micro seconds.
476 * @tx_coal: TX Coalesce value in micro seconds.
477 * @p_handle: P_handle.
482 qed_set_queue_coalesce(u16 rx_coal
, u16 tx_coal
, void *p_handle
);
485 * qed_pglueb_set_pfid_enable(): Enable or disable PCI BUS MASTER.
487 * @p_hwfn: HW device data.
489 * @b_enable: True/False.
493 int qed_pglueb_set_pfid_enable(struct qed_hwfn
*p_hwfn
,
494 struct qed_ptt
*p_ptt
, bool b_enable
);
497 * qed_db_recovery_add(): add doorbell information to the doorbell
498 * recovery mechanism.
500 * @cdev: Qed dev pointer.
501 * @db_addr: Doorbell address.
502 * @db_data: Address of where db_data is stored.
503 * @db_width: Doorbell is 32b pr 64b.
504 * @db_space: Doorbell recovery addresses are user or kernel space.
508 int qed_db_recovery_add(struct qed_dev
*cdev
,
509 void __iomem
*db_addr
,
511 enum qed_db_rec_width db_width
,
512 enum qed_db_rec_space db_space
);
515 * qed_db_recovery_del() - remove doorbell information from the doorbell
516 * recovery mechanism. db_data serves as key (db_addr is not unique).
518 * @cdev: Qed dev pointer.
519 * @db_addr: doorbell address.
520 * @db_data: address where db_data is stored. Serves as key for the
525 int qed_db_recovery_del(struct qed_dev
*cdev
,
526 void __iomem
*db_addr
, void *db_data
);
528 const char *qed_hw_get_resc_name(enum qed_resources res_id
);