GNU Linux-libre 5.10.215-gnu1
[releases.git] / drivers / net / ethernet / qlogic / qed / qed_dev_api.h
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  * @brief qed_init_dp - initialize the debug level
19  *
20  * @param cdev
21  * @param dp_module
22  * @param dp_level
23  */
24 void qed_init_dp(struct qed_dev *cdev,
25                  u32 dp_module,
26                  u8 dp_level);
27
28 /**
29  * @brief qed_init_struct - initialize the device structure to
30  *        its defaults
31  *
32  * @param cdev
33  */
34 void qed_init_struct(struct qed_dev *cdev);
35
36 /**
37  * @brief qed_resc_free -
38  *
39  * @param cdev
40  */
41 void qed_resc_free(struct qed_dev *cdev);
42
43 /**
44  * @brief qed_resc_alloc -
45  *
46  * @param cdev
47  *
48  * @return int
49  */
50 int qed_resc_alloc(struct qed_dev *cdev);
51
52 /**
53  * @brief qed_resc_setup -
54  *
55  * @param cdev
56  */
57 void qed_resc_setup(struct qed_dev *cdev);
58
59 enum qed_override_force_load {
60         QED_OVERRIDE_FORCE_LOAD_NONE,
61         QED_OVERRIDE_FORCE_LOAD_ALWAYS,
62         QED_OVERRIDE_FORCE_LOAD_NEVER,
63 };
64
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.
70          */
71         bool is_crash_kernel;
72
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.
76          */
77         u8 mfw_timeout_val;
78 #define QED_LOAD_REQ_LOCK_TO_DEFAULT    0
79 #define QED_LOAD_REQ_LOCK_TO_NONE       255
80
81         /* Avoid engine reset when first PF loads on it */
82         bool avoid_eng_reset;
83
84         /* Allow overriding the default force load behavior */
85         enum qed_override_force_load override_force_load;
86 };
87
88 struct qed_hw_init_params {
89         /* Tunneling parameters */
90         struct qed_tunnel_info *p_tunn;
91
92         bool b_hw_start;
93
94         /* Interrupt mode [msix, inta, etc.] to use */
95         enum qed_int_mode int_mode;
96
97         /* NPAR tx switching to be used for vports for tx-switching */
98         bool allow_npar_tx_switch;
99
100         /* Binary fw data pointer in binary fw file */
101         const u8 *bin_fw_data;
102
103         /* Driver load parameters */
104         struct qed_drv_load_params *p_drv_load_params;
105 };
106
107 /**
108  * @brief qed_hw_init -
109  *
110  * @param cdev
111  * @param p_params
112  *
113  * @return int
114  */
115 int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params);
116
117 /**
118  * @brief qed_hw_timers_stop_all - stop the timers HW block
119  *
120  * @param cdev
121  *
122  * @return void
123  */
124 void qed_hw_timers_stop_all(struct qed_dev *cdev);
125
126 /**
127  * @brief qed_hw_stop -
128  *
129  * @param cdev
130  *
131  * @return int
132  */
133 int qed_hw_stop(struct qed_dev *cdev);
134
135 /**
136  * @brief qed_hw_stop_fastpath -should be called incase
137  *              slowpath is still required for the device,
138  *              but fastpath is not.
139  *
140  * @param cdev
141  *
142  * @return int
143  */
144 int qed_hw_stop_fastpath(struct qed_dev *cdev);
145
146 /**
147  * @brief qed_hw_start_fastpath -restart fastpath traffic,
148  *              only if hw_stop_fastpath was called
149  *
150  * @param p_hwfn
151  *
152  * @return int
153  */
154 int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn);
155
156
157 /**
158  * @brief qed_hw_prepare -
159  *
160  * @param cdev
161  * @param personality - personality to initialize
162  *
163  * @return int
164  */
165 int qed_hw_prepare(struct qed_dev *cdev,
166                    int personality);
167
168 /**
169  * @brief qed_hw_remove -
170  *
171  * @param cdev
172  */
173 void qed_hw_remove(struct qed_dev *cdev);
174
175 /**
176  * @brief qed_ptt_acquire - Allocate a PTT window
177  *
178  * Should be called at the entry point to the driver (at the beginning of an
179  * exported function)
180  *
181  * @param p_hwfn
182  *
183  * @return struct qed_ptt
184  */
185 struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn);
186
187 /**
188  * @brief qed_ptt_release - Release PTT Window
189  *
190  * Should be called at the end of a flow - at the end of the function that
191  * acquired the PTT.
192  *
193  *
194  * @param p_hwfn
195  * @param p_ptt
196  */
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);
200
201 enum qed_dmae_address_type_t {
202         QED_DMAE_ADDRESS_HOST_VIRT,
203         QED_DMAE_ADDRESS_HOST_PHYS,
204         QED_DMAE_ADDRESS_GRC
205 };
206
207 /**
208  * @brief qed_dmae_host2grc - copy data from source addr to
209  * dmae registers using the given ptt
210  *
211  * @param p_hwfn
212  * @param p_ptt
213  * @param source_addr
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)
217  */
218 int
219 qed_dmae_host2grc(struct qed_hwfn *p_hwfn,
220                   struct qed_ptt *p_ptt,
221                   u64 source_addr,
222                   u32 grc_addr,
223                   u32 size_in_dwords,
224                   struct qed_dmae_params *p_params);
225
226  /**
227  * @brief qed_dmae_grc2host - Read data from dmae data offset
228  * to source address using the given ptt
229  *
230  * @param p_ptt
231  * @param grc_addr (dmae_data_offset)
232  * @param dest_addr
233  * @param size_in_dwords
234  * @param p_params (default parameters will be used in case of NULL)
235  */
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);
239
240 /**
241  * @brief qed_dmae_host2host - copy data from to source address
242  * to a destination adress (for SRIOV) using the given ptt
243  *
244  * @param p_hwfn
245  * @param p_ptt
246  * @param source_addr
247  * @param dest_addr
248  * @param size_in_dwords
249  * @param p_params (default parameters will be used in case of NULL)
250  */
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);
256
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);
260
261 /**
262  * @@brief qed_fw_l2_queue - Get absolute L2 queue ID
263  *
264  *  @param p_hwfn
265  *  @param src_id - relative to p_hwfn
266  *  @param dst_id - absolute per engine
267  *
268  *  @return int
269  */
270 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
271                     u16 src_id,
272                     u16 *dst_id);
273
274 /**
275  * @@brief qed_fw_vport - Get absolute vport ID
276  *
277  *  @param p_hwfn
278  *  @param src_id - relative to p_hwfn
279  *  @param dst_id - absolute per engine
280  *
281  *  @return int
282  */
283 int qed_fw_vport(struct qed_hwfn *p_hwfn,
284                  u8 src_id,
285                  u8 *dst_id);
286
287 /**
288  * @@brief qed_fw_rss_eng - Get absolute RSS engine ID
289  *
290  *  @param p_hwfn
291  *  @param src_id - relative to p_hwfn
292  *  @param dst_id - absolute per engine
293  *
294  *  @return int
295  */
296 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
297                    u8 src_id,
298                    u8 *dst_id);
299
300 /**
301  * @brief qed_llh_get_num_ppfid - Return the allocated number of LLH filter
302  *      banks that are allocated to the PF.
303  *
304  * @param cdev
305  *
306  * @return u8 - Number of LLH filter banks
307  */
308 u8 qed_llh_get_num_ppfid(struct qed_dev *cdev);
309
310 enum qed_eng {
311         QED_ENG0,
312         QED_ENG1,
313         QED_BOTH_ENG,
314 };
315
316 /**
317  * @brief qed_llh_set_ppfid_affinity - Set the engine affinity for the given
318  *      LLH filter bank.
319  *
320  * @param cdev
321  * @param ppfid - relative within the allocated ppfids ('0' is the default one).
322  * @param eng
323  *
324  * @return int
325  */
326 int qed_llh_set_ppfid_affinity(struct qed_dev *cdev,
327                                u8 ppfid, enum qed_eng eng);
328
329 /**
330  * @brief qed_llh_set_roce_affinity - Set the RoCE engine affinity
331  *
332  * @param cdev
333  * @param eng
334  *
335  * @return int
336  */
337 int qed_llh_set_roce_affinity(struct qed_dev *cdev, enum qed_eng eng);
338
339 /**
340  * @brief qed_llh_add_mac_filter - Add a LLH MAC filter into the given filter
341  *      bank.
342  *
343  * @param cdev
344  * @param ppfid - relative within the allocated ppfids ('0' is the default one).
345  * @param mac_addr - MAC to add
346  */
347 int qed_llh_add_mac_filter(struct qed_dev *cdev,
348                            u8 ppfid, u8 mac_addr[ETH_ALEN]);
349
350 /**
351  * @brief qed_llh_remove_mac_filter - Remove a LLH MAC filter from the given
352  *      filter bank.
353  *
354  * @param p_ptt
355  * @param p_filter - MAC to remove
356  */
357 void qed_llh_remove_mac_filter(struct qed_dev *cdev,
358                                u8 ppfid, u8 mac_addr[ETH_ALEN]);
359
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
368 };
369
370 /**
371  * @brief qed_llh_add_protocol_filter - Add a LLH protocol filter into the
372  *      given filter bank.
373  *
374  * @param cdev
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
380  */
381 int
382 qed_llh_add_protocol_filter(struct qed_dev *cdev,
383                             u8 ppfid,
384                             enum qed_llh_prot_filter_type_t type,
385                             u16 source_port_or_eth_type, u16 dest_port);
386
387 /**
388  * @brief qed_llh_remove_protocol_filter - Remove a LLH protocol filter from
389  *      the given filter bank.
390  *
391  * @param cdev
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
396  */
397 void
398 qed_llh_remove_protocol_filter(struct qed_dev *cdev,
399                                u8 ppfid,
400                                enum qed_llh_prot_filter_type_t type,
401                                u16 source_port_or_eth_type, u16 dest_port);
402
403 /**
404  * *@brief Cleanup of previous driver remains prior to load
405  *
406  * @param p_hwfn
407  * @param p_ptt
408  * @param id - For PF, engine-relative. For VF, PF-relative.
409  * @param is_vf - true iff cleanup is made for a VF.
410  *
411  * @return int
412  */
413 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
414                       struct qed_ptt *p_ptt, u16 id, bool is_vf);
415
416 /**
417  * @brief qed_get_queue_coalesce - Retrieve coalesce value for a given queue.
418  *
419  * @param p_hwfn
420  * @param p_coal - store coalesce value read from the hardware.
421  * @param p_handle
422  *
423  * @return int
424  **/
425 int qed_get_queue_coalesce(struct qed_hwfn *p_hwfn, u16 *coal, void *handle);
426
427 /**
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.
435  *
436  *
437  * @param rx_coal - Rx Coalesce value in micro seconds.
438  * @param tx_coal - TX Coalesce value in micro seconds.
439  * @param p_handle
440  *
441  * @return int
442  **/
443 int
444 qed_set_queue_coalesce(u16 rx_coal, u16 tx_coal, void *p_handle);
445
446 /**
447  * @brief qed_pglueb_set_pfid_enable - Enable or disable PCI BUS MASTER
448  *
449  * @param p_hwfn
450  * @param p_ptt
451  * @param b_enable - true/false
452  *
453  * @return int
454  */
455 int qed_pglueb_set_pfid_enable(struct qed_hwfn *p_hwfn,
456                                struct qed_ptt *p_ptt, bool b_enable);
457
458 /**
459  * @brief db_recovery_add - add doorbell information to the doorbell
460  * recovery mechanism.
461  *
462  * @param cdev
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
467  */
468 int qed_db_recovery_add(struct qed_dev *cdev,
469                         void __iomem *db_addr,
470                         void *db_data,
471                         enum qed_db_rec_width db_width,
472                         enum qed_db_rec_space db_space);
473
474 /**
475  * @brief db_recovery_del - remove doorbell information from the doorbell
476  * recovery mechanism. db_data serves as key (db_addr is not unique).
477  *
478  * @param cdev
479  * @param db_addr - doorbell address
480  * @param db_data - address where db_data is stored. Serves as key for the
481  *                  entry to delete.
482  */
483 int qed_db_recovery_del(struct qed_dev *cdev,
484                         void __iomem *db_addr, void *db_data);
485
486
487 const char *qed_hw_get_resc_name(enum qed_resources res_id);
488 #endif