xref: /linux/drivers/net/ethernet/qlogic/qed/qed_dev_api.h (revision cbdb1f163af2bb90d01be1f0263df1d8d5c9d9d3)
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.
5  */
6 
7 #ifndef _QED_DEV_API_H
8 #define _QED_DEV_API_H
9 
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>
15 #include "qed_int.h"
16 
17 /**
18  * qed_init_dp(): Initialize the debug level.
19  *
20  * @cdev: Qed dev pointer.
21  * @dp_module: Module debug parameter.
22  * @dp_level: Module debug level.
23  *
24  * Return: Void.
25  */
26 void qed_init_dp(struct qed_dev *cdev,
27 		 u32 dp_module,
28 		 u8 dp_level);
29 
30 /**
31  * qed_init_struct(): Initialize the device structure to
32  *                    its defaults.
33  *
34  * @cdev: Qed dev pointer.
35  *
36  * Return: Void.
37  */
38 void qed_init_struct(struct qed_dev *cdev);
39 
40 /**
41  * qed_resc_free: Free device resources.
42  *
43  * @cdev: Qed dev pointer.
44  *
45  * Return: Void.
46  */
47 void qed_resc_free(struct qed_dev *cdev);
48 
49 /**
50  * qed_resc_alloc(): Alloc device resources.
51  *
52  * @cdev: Qed dev pointer.
53  *
54  * Return: Int.
55  */
56 int qed_resc_alloc(struct qed_dev *cdev);
57 
58 /**
59  * qed_resc_setup(): Setup device resources.
60  *
61  * @cdev: Qed dev pointer.
62  *
63  * Return: Void.
64  */
65 void qed_resc_setup(struct qed_dev *cdev);
66 
67 enum qed_override_force_load {
68 	QED_OVERRIDE_FORCE_LOAD_NONE,
69 	QED_OVERRIDE_FORCE_LOAD_ALWAYS,
70 	QED_OVERRIDE_FORCE_LOAD_NEVER,
71 };
72 
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.
78 	 */
79 	bool is_crash_kernel;
80 
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.
84 	 */
85 	u8 mfw_timeout_val;
86 #define QED_LOAD_REQ_LOCK_TO_DEFAULT    0
87 #define QED_LOAD_REQ_LOCK_TO_NONE       255
88 
89 	/* Avoid engine reset when first PF loads on it */
90 	bool avoid_eng_reset;
91 
92 	/* Allow overriding the default force load behavior */
93 	enum qed_override_force_load override_force_load;
94 };
95 
96 struct qed_hw_init_params {
97 	/* Tunneling parameters */
98 	struct qed_tunnel_info *p_tunn;
99 
100 	bool b_hw_start;
101 
102 	/* Interrupt mode [msix, inta, etc.] to use */
103 	enum qed_int_mode int_mode;
104 
105 	/* NPAR tx switching to be used for vports for tx-switching */
106 	bool allow_npar_tx_switch;
107 
108 	/* Binary fw data pointer in binary fw file */
109 	const u8 *bin_fw_data;
110 
111 	/* Driver load parameters */
112 	struct qed_drv_load_params *p_drv_load_params;
113 };
114 
115 /**
116  * qed_hw_init(): Init Qed hardware.
117  *
118  * @cdev: Qed dev pointer.
119  * @p_params: Pointers to params.
120  *
121  * Return: Int.
122  */
123 int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params);
124 
125 /**
126  * qed_hw_timers_stop_all(): Stop the timers HW block.
127  *
128  * @cdev: Qed dev pointer.
129  *
130  * Return: void.
131  */
132 void qed_hw_timers_stop_all(struct qed_dev *cdev);
133 
134 /**
135  * qed_hw_stop(): Stop Qed hardware.
136  *
137  * @cdev: Qed dev pointer.
138  *
139  * Return: int.
140  */
141 int qed_hw_stop(struct qed_dev *cdev);
142 
143 /**
144  * qed_hw_stop_fastpath(): Should be called incase
145  *		           slowpath is still required for the device,
146  *		           but fastpath is not.
147  *
148  * @cdev: Qed dev pointer.
149  *
150  * Return: Int.
151  */
152 int qed_hw_stop_fastpath(struct qed_dev *cdev);
153 
154 /**
155  * qed_hw_start_fastpath(): Restart fastpath traffic,
156  *		            only if hw_stop_fastpath was called.
157  *
158  * @p_hwfn: HW device data.
159  *
160  * Return: Int.
161  */
162 int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn);
163 
164 /**
165  * qed_hw_prepare(): Prepare Qed hardware.
166  *
167  * @cdev: Qed dev pointer.
168  * @personality: Personality to initialize.
169  *
170  * Return: Int.
171  */
172 int qed_hw_prepare(struct qed_dev *cdev,
173 		   int personality);
174 
175 /**
176  * qed_hw_remove(): Remove Qed hardware.
177  *
178  * @cdev: Qed dev pointer.
179  *
180  * Return: Void.
181  */
182 void qed_hw_remove(struct qed_dev *cdev);
183 
184 /**
185  * qed_ptt_acquire(): Allocate a PTT window.
186  *
187  * @p_hwfn: HW device data.
188  *
189  * Return: struct qed_ptt.
190  *
191  * Should be called at the entry point to the driver (at the beginning of an
192  * exported function).
193  */
194 struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn);
195 
196 /**
197  * qed_ptt_release(): Release PTT Window.
198  *
199  * @p_hwfn: HW device data.
200  * @p_ptt: P_ptt.
201  *
202  * Return: Void.
203  *
204  * Should be called at the end of a flow - at the end of the function that
205  * acquired the PTT.
206  */
207 void qed_ptt_release(struct qed_hwfn *p_hwfn,
208 		     struct qed_ptt *p_ptt);
209 void qed_reset_vport_stats(struct qed_dev *cdev);
210 
211 enum qed_dmae_address_type_t {
212 	QED_DMAE_ADDRESS_HOST_VIRT,
213 	QED_DMAE_ADDRESS_HOST_PHYS,
214 	QED_DMAE_ADDRESS_GRC
215 };
216 
217 /**
218  * qed_dmae_host2grc(): Copy data from source addr to
219  *                      dmae registers using the given ptt.
220  *
221  * @p_hwfn: HW device data.
222  * @p_ptt: P_ptt.
223  * @source_addr: Source address.
224  * @grc_addr: GRC address (dmae_data_offset).
225  * @size_in_dwords: Size.
226  * @p_params: (default parameters will be used in case of NULL).
227  *
228  * Return: Int.
229  */
230 int
231 qed_dmae_host2grc(struct qed_hwfn *p_hwfn,
232 		  struct qed_ptt *p_ptt,
233 		  u64 source_addr,
234 		  u32 grc_addr,
235 		  u32 size_in_dwords,
236 		  struct qed_dmae_params *p_params);
237 
238  /**
239  * qed_dmae_grc2host(): Read data from dmae data offset
240  *                      to source address using the given ptt.
241  *
242  * @p_ptt: P_ptt.
243  * @grc_addr: GRC address (dmae_data_offset).
244  * @dest_addr: Destination Address.
245  * @size_in_dwords: Size.
246  * @p_params: (default parameters will be used in case of NULL).
247  *
248  * Return: Int.
249  */
250 int qed_dmae_grc2host(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
251 		      u32 grc_addr, dma_addr_t dest_addr, u32 size_in_dwords,
252 		      struct qed_dmae_params *p_params);
253 
254 /**
255  * qed_dmae_host2host(): Copy data from to source address
256  *                       to a destination adrress (for SRIOV) using the given
257  *                       ptt.
258  *
259  * @p_hwfn: HW device data.
260  * @p_ptt: P_ptt.
261  * @source_addr: Source address.
262  * @dest_addr: Destination address.
263  * @size_in_dwords: size.
264  * @p_params: (default parameters will be used in case of NULL).
265  *
266  * Return: Int.
267  */
268 int qed_dmae_host2host(struct qed_hwfn *p_hwfn,
269 		       struct qed_ptt *p_ptt,
270 		       dma_addr_t source_addr,
271 		       dma_addr_t dest_addr,
272 		       u32 size_in_dwords, struct qed_dmae_params *p_params);
273 
274 int qed_chain_alloc(struct qed_dev *cdev, struct qed_chain *chain,
275 		    struct qed_chain_init_params *params);
276 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *chain);
277 
278 /**
279  * qed_fw_l2_queue(): Get absolute L2 queue ID.
280  *
281  * @p_hwfn: HW device data.
282  * @src_id: Relative to p_hwfn.
283  * @dst_id: Absolute per engine.
284  *
285  * Return: Int.
286  */
287 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
288 		    u16 src_id,
289 		    u16 *dst_id);
290 
291 /**
292  * qed_fw_vport(): Get absolute vport ID.
293  *
294  * @p_hwfn: HW device data.
295  * @src_id: Relative to p_hwfn.
296  * @dst_id: Absolute per engine.
297  *
298  * Return: Int.
299  */
300 int qed_fw_vport(struct qed_hwfn *p_hwfn,
301 		 u8 src_id,
302 		 u8 *dst_id);
303 
304 /**
305  * qed_fw_rss_eng(): Get absolute RSS engine ID.
306  *
307  * @p_hwfn: HW device data.
308  * @src_id: Relative to p_hwfn.
309  * @dst_id: Absolute per engine.
310  *
311  * Return: Int.
312  */
313 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
314 		   u8 src_id,
315 		   u8 *dst_id);
316 
317 /**
318  * qed_llh_get_num_ppfid(): Return the allocated number of LLH filter
319  *	                    banks that are allocated to the PF.
320  *
321  * @cdev: Qed dev pointer.
322  *
323  * Return: u8 Number of LLH filter banks.
324  */
325 u8 qed_llh_get_num_ppfid(struct qed_dev *cdev);
326 
327 enum qed_eng {
328 	QED_ENG0,
329 	QED_ENG1,
330 	QED_BOTH_ENG,
331 };
332 
333 /**
334  * qed_llh_set_ppfid_affinity(): Set the engine affinity for the given
335  *	                         LLH filter bank.
336  *
337  * @cdev: Qed dev pointer.
338  * @ppfid: Relative within the allocated ppfids ('0' is the default one).
339  * @eng: Engine.
340  *
341  * Return: Int.
342  */
343 int qed_llh_set_ppfid_affinity(struct qed_dev *cdev,
344 			       u8 ppfid, enum qed_eng eng);
345 
346 /**
347  * qed_llh_set_roce_affinity(): Set the RoCE engine affinity.
348  *
349  * @cdev: Qed dev pointer.
350  * @eng: Engine.
351  *
352  * Return: Int.
353  */
354 int qed_llh_set_roce_affinity(struct qed_dev *cdev, enum qed_eng eng);
355 
356 /**
357  * qed_llh_add_mac_filter(): Add a LLH MAC filter into the given filter
358  *	                     bank.
359  *
360  * @cdev: Qed dev pointer.
361  * @ppfid: Relative within the allocated ppfids ('0' is the default one).
362  * @mac_addr: MAC to add.
363  *
364  * Return: Int.
365  */
366 int qed_llh_add_mac_filter(struct qed_dev *cdev,
367 			   u8 ppfid, const u8 mac_addr[ETH_ALEN]);
368 
369 /**
370  * qed_llh_remove_mac_filter(): Remove a LLH MAC filter from the given
371  *	                        filter bank.
372  *
373  * @cdev: Qed dev pointer.
374  * @ppfid: Ppfid.
375  * @mac_addr: MAC to remove
376  *
377  * Return: Void.
378  */
379 void qed_llh_remove_mac_filter(struct qed_dev *cdev,
380 			       u8 ppfid, u8 mac_addr[ETH_ALEN]);
381 
382 enum qed_llh_prot_filter_type_t {
383 	QED_LLH_FILTER_ETHERTYPE,
384 	QED_LLH_FILTER_TCP_SRC_PORT,
385 	QED_LLH_FILTER_TCP_DEST_PORT,
386 	QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
387 	QED_LLH_FILTER_UDP_SRC_PORT,
388 	QED_LLH_FILTER_UDP_DEST_PORT,
389 	QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT
390 };
391 
392 /**
393  * qed_llh_add_protocol_filter(): Add a LLH protocol filter into the
394  *	                          given filter bank.
395  *
396  * @cdev: Qed dev pointer.
397  * @ppfid: Relative within the allocated ppfids ('0' is the default one).
398  * @type: Type of filters and comparing.
399  * @source_port_or_eth_type: Source port or ethertype to add.
400  * @dest_port: Destination port to add.
401  *
402  * Return: Int.
403  */
404 int
405 qed_llh_add_protocol_filter(struct qed_dev *cdev,
406 			    u8 ppfid,
407 			    enum qed_llh_prot_filter_type_t type,
408 			    u16 source_port_or_eth_type, u16 dest_port);
409 
410 /**
411  * qed_llh_remove_protocol_filter(): Remove a LLH protocol filter from
412  *	                             the given filter bank.
413  *
414  * @cdev: Qed dev pointer.
415  * @ppfid: Relative within the allocated ppfids ('0' is the default one).
416  * @type: Type of filters and comparing.
417  * @source_port_or_eth_type: Source port or ethertype to add.
418  * @dest_port: Destination port to add.
419  */
420 void
421 qed_llh_remove_protocol_filter(struct qed_dev *cdev,
422 			       u8 ppfid,
423 			       enum qed_llh_prot_filter_type_t type,
424 			       u16 source_port_or_eth_type, u16 dest_port);
425 
426 /**
427  * qed_final_cleanup(): Cleanup of previous driver remains prior to load.
428  *
429  * @p_hwfn: HW device data.
430  * @p_ptt: P_ptt.
431  * @id: For PF, engine-relative. For VF, PF-relative.
432  * @is_vf: True iff cleanup is made for a VF.
433  *
434  * Return: Int.
435  */
436 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
437 		      struct qed_ptt *p_ptt, u16 id, bool is_vf);
438 
439 /**
440  * qed_get_queue_coalesce(): Retrieve coalesce value for a given queue.
441  *
442  * @p_hwfn: HW device data.
443  * @coal: Store coalesce value read from the hardware.
444  * @handle: P_handle.
445  *
446  * Return: Int.
447  **/
448 int qed_get_queue_coalesce(struct qed_hwfn *p_hwfn, u16 *coal, void *handle);
449 
450 /**
451  * qed_set_queue_coalesce(): Configure coalesce parameters for Rx and
452  *    Tx queue. The fact that we can configure coalescing to up to 511, but on
453  *    varying accuracy [the bigger the value the less accurate] up to a mistake
454  *    of 3usec for the highest values.
455  *    While the API allows setting coalescing per-qid, all queues sharing a SB
456  *    should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
457  *    otherwise configuration would break.
458  *
459  * @rx_coal: Rx Coalesce value in micro seconds.
460  * @tx_coal: TX Coalesce value in micro seconds.
461  * @p_handle: P_handle.
462  *
463  * Return: Int.
464  **/
465 int
466 qed_set_queue_coalesce(u16 rx_coal, u16 tx_coal, void *p_handle);
467 
468 /**
469  * qed_pglueb_set_pfid_enable(): Enable or disable PCI BUS MASTER.
470  *
471  * @p_hwfn: HW device data.
472  * @p_ptt: P_ptt.
473  * @b_enable: True/False.
474  *
475  * Return: Int.
476  */
477 int qed_pglueb_set_pfid_enable(struct qed_hwfn *p_hwfn,
478 			       struct qed_ptt *p_ptt, bool b_enable);
479 
480 /**
481  * qed_db_recovery_add(): add doorbell information to the doorbell
482  *                    recovery mechanism.
483  *
484  * @cdev: Qed dev pointer.
485  * @db_addr: Doorbell address.
486  * @db_data: Address of where db_data is stored.
487  * @db_width: Doorbell is 32b pr 64b.
488  * @db_space: Doorbell recovery addresses are user or kernel space.
489  *
490  * Return: Int.
491  */
492 int qed_db_recovery_add(struct qed_dev *cdev,
493 			void __iomem *db_addr,
494 			void *db_data,
495 			enum qed_db_rec_width db_width,
496 			enum qed_db_rec_space db_space);
497 
498 /**
499  * qed_db_recovery_del() - remove doorbell information from the doorbell
500  * recovery mechanism. db_data serves as key (db_addr is not unique).
501  *
502  * @cdev: Qed dev pointer.
503  * @db_addr: doorbell address.
504  * @db_data: address where db_data is stored. Serves as key for the
505  *                  entry to delete.
506  *
507  * Return: Int.
508  */
509 int qed_db_recovery_del(struct qed_dev *cdev,
510 			void __iomem *db_addr, void *db_data);
511 
512 const char *qed_hw_get_resc_name(enum qed_resources res_id);
513 #endif
514