xref: /linux/drivers/net/ethernet/qlogic/qed/qed_dev_api.h (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015-2017  QLogic Corporation
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and /or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #ifndef _QED_DEV_API_H
34 #define _QED_DEV_API_H
35 
36 #include <linux/types.h>
37 #include <linux/kernel.h>
38 #include <linux/slab.h>
39 #include <linux/qed/qed_chain.h>
40 #include <linux/qed/qed_if.h>
41 #include "qed_int.h"
42 
43 /**
44  * @brief qed_init_dp - initialize the debug level
45  *
46  * @param cdev
47  * @param dp_module
48  * @param dp_level
49  */
50 void qed_init_dp(struct qed_dev *cdev,
51 		 u32 dp_module,
52 		 u8 dp_level);
53 
54 /**
55  * @brief qed_init_struct - initialize the device structure to
56  *        its defaults
57  *
58  * @param cdev
59  */
60 void qed_init_struct(struct qed_dev *cdev);
61 
62 /**
63  * @brief qed_resc_free -
64  *
65  * @param cdev
66  */
67 void qed_resc_free(struct qed_dev *cdev);
68 
69 /**
70  * @brief qed_resc_alloc -
71  *
72  * @param cdev
73  *
74  * @return int
75  */
76 int qed_resc_alloc(struct qed_dev *cdev);
77 
78 /**
79  * @brief qed_resc_setup -
80  *
81  * @param cdev
82  */
83 void qed_resc_setup(struct qed_dev *cdev);
84 
85 /**
86  * @brief qed_hw_init -
87  *
88  * @param cdev
89  * @param p_tunn
90  * @param b_hw_start
91  * @param int_mode - interrupt mode [msix, inta, etc.] to use.
92  * @param allow_npar_tx_switch - npar tx switching to be used
93  *	  for vports configured for tx-switching.
94  * @param bin_fw_data - binary fw data pointer in binary fw file.
95  *			Pass NULL if not using binary fw file.
96  *
97  * @return int
98  */
99 int qed_hw_init(struct qed_dev *cdev,
100 		struct qed_tunn_start_params *p_tunn,
101 		bool b_hw_start,
102 		enum qed_int_mode int_mode,
103 		bool allow_npar_tx_switch,
104 		const u8 *bin_fw_data);
105 
106 /**
107  * @brief qed_hw_timers_stop_all - stop the timers HW block
108  *
109  * @param cdev
110  *
111  * @return void
112  */
113 void qed_hw_timers_stop_all(struct qed_dev *cdev);
114 
115 /**
116  * @brief qed_hw_stop -
117  *
118  * @param cdev
119  *
120  * @return int
121  */
122 int qed_hw_stop(struct qed_dev *cdev);
123 
124 /**
125  * @brief qed_hw_stop_fastpath -should be called incase
126  *		slowpath is still required for the device,
127  *		but fastpath is not.
128  *
129  * @param cdev
130  *
131  */
132 void qed_hw_stop_fastpath(struct qed_dev *cdev);
133 
134 /**
135  * @brief qed_hw_start_fastpath -restart fastpath traffic,
136  *		only if hw_stop_fastpath was called
137  *
138  * @param cdev
139  *
140  */
141 void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn);
142 
143 /**
144  * @brief qed_hw_reset -
145  *
146  * @param cdev
147  *
148  * @return int
149  */
150 int qed_hw_reset(struct qed_dev *cdev);
151 
152 /**
153  * @brief qed_hw_prepare -
154  *
155  * @param cdev
156  * @param personality - personality to initialize
157  *
158  * @return int
159  */
160 int qed_hw_prepare(struct qed_dev *cdev,
161 		   int personality);
162 
163 /**
164  * @brief qed_hw_remove -
165  *
166  * @param cdev
167  */
168 void qed_hw_remove(struct qed_dev *cdev);
169 
170 /**
171  * @brief qed_ptt_acquire - Allocate a PTT window
172  *
173  * Should be called at the entry point to the driver (at the beginning of an
174  * exported function)
175  *
176  * @param p_hwfn
177  *
178  * @return struct qed_ptt
179  */
180 struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn);
181 
182 /**
183  * @brief qed_ptt_release - Release PTT Window
184  *
185  * Should be called at the end of a flow - at the end of the function that
186  * acquired the PTT.
187  *
188  *
189  * @param p_hwfn
190  * @param p_ptt
191  */
192 void qed_ptt_release(struct qed_hwfn *p_hwfn,
193 		     struct qed_ptt *p_ptt);
194 void qed_reset_vport_stats(struct qed_dev *cdev);
195 
196 enum qed_dmae_address_type_t {
197 	QED_DMAE_ADDRESS_HOST_VIRT,
198 	QED_DMAE_ADDRESS_HOST_PHYS,
199 	QED_DMAE_ADDRESS_GRC
200 };
201 
202 /* value of flags If QED_DMAE_FLAG_RW_REPL_SRC flag is set and the
203  * source is a block of length DMAE_MAX_RW_SIZE and the
204  * destination is larger, the source block will be duplicated as
205  * many times as required to fill the destination block. This is
206  * used mostly to write a zeroed buffer to destination address
207  * using DMA
208  */
209 #define QED_DMAE_FLAG_RW_REPL_SRC	0x00000001
210 #define QED_DMAE_FLAG_VF_SRC		0x00000002
211 #define QED_DMAE_FLAG_VF_DST		0x00000004
212 #define QED_DMAE_FLAG_COMPLETION_DST	0x00000008
213 
214 struct qed_dmae_params {
215 	u32 flags; /* consists of QED_DMAE_FLAG_* values */
216 	u8 src_vfid;
217 	u8 dst_vfid;
218 };
219 
220 /**
221  * @brief qed_dmae_host2grc - copy data from source addr to
222  * dmae registers using the given ptt
223  *
224  * @param p_hwfn
225  * @param p_ptt
226  * @param source_addr
227  * @param grc_addr (dmae_data_offset)
228  * @param size_in_dwords
229  * @param flags (one of the flags defined above)
230  */
231 int
232 qed_dmae_host2grc(struct qed_hwfn *p_hwfn,
233 		  struct qed_ptt *p_ptt,
234 		  u64 source_addr,
235 		  u32 grc_addr,
236 		  u32 size_in_dwords,
237 		  u32 flags);
238 
239  /**
240  * @brief qed_dmae_grc2host - Read data from dmae data offset
241  * to source address using the given ptt
242  *
243  * @param p_ptt
244  * @param grc_addr (dmae_data_offset)
245  * @param dest_addr
246  * @param size_in_dwords
247  * @param flags - one of the flags defined above
248  */
249 int qed_dmae_grc2host(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
250 		      u32 grc_addr, dma_addr_t dest_addr, u32 size_in_dwords,
251 		      u32 flags);
252 
253 /**
254  * @brief qed_dmae_host2host - copy data from to source address
255  * to a destination adress (for SRIOV) using the given ptt
256  *
257  * @param p_hwfn
258  * @param p_ptt
259  * @param source_addr
260  * @param dest_addr
261  * @param size_in_dwords
262  * @param params
263  */
264 int qed_dmae_host2host(struct qed_hwfn *p_hwfn,
265 		       struct qed_ptt *p_ptt,
266 		       dma_addr_t source_addr,
267 		       dma_addr_t dest_addr,
268 		       u32 size_in_dwords, struct qed_dmae_params *p_params);
269 
270 /**
271  * @brief qed_chain_alloc - Allocate and initialize a chain
272  *
273  * @param p_hwfn
274  * @param intended_use
275  * @param mode
276  * @param num_elems
277  * @param elem_size
278  * @param p_chain
279  *
280  * @return int
281  */
282 int
283 qed_chain_alloc(struct qed_dev *cdev,
284 		enum qed_chain_use_mode intended_use,
285 		enum qed_chain_mode mode,
286 		enum qed_chain_cnt_type cnt_type,
287 		u32 num_elems, size_t elem_size, struct qed_chain *p_chain);
288 
289 /**
290  * @brief qed_chain_free - Free chain DMA memory
291  *
292  * @param p_hwfn
293  * @param p_chain
294  */
295 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain);
296 
297 /**
298  * @@brief qed_fw_l2_queue - Get absolute L2 queue ID
299  *
300  *  @param p_hwfn
301  *  @param src_id - relative to p_hwfn
302  *  @param dst_id - absolute per engine
303  *
304  *  @return int
305  */
306 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
307 		    u16 src_id,
308 		    u16 *dst_id);
309 
310 /**
311  * @@brief qed_fw_vport - Get absolute vport ID
312  *
313  *  @param p_hwfn
314  *  @param src_id - relative to p_hwfn
315  *  @param dst_id - absolute per engine
316  *
317  *  @return int
318  */
319 int qed_fw_vport(struct qed_hwfn *p_hwfn,
320 		 u8 src_id,
321 		 u8 *dst_id);
322 
323 /**
324  * @@brief qed_fw_rss_eng - Get absolute RSS engine ID
325  *
326  *  @param p_hwfn
327  *  @param src_id - relative to p_hwfn
328  *  @param dst_id - absolute per engine
329  *
330  *  @return int
331  */
332 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
333 		   u8 src_id,
334 		   u8 *dst_id);
335 
336 /**
337  * @brief qed_llh_add_mac_filter - configures a MAC filter in llh
338  *
339  * @param p_hwfn
340  * @param p_ptt
341  * @param p_filter - MAC to add
342  */
343 int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
344 			   struct qed_ptt *p_ptt, u8 *p_filter);
345 
346 /**
347  * @brief qed_llh_remove_mac_filter - removes a MAC filter from llh
348  *
349  * @param p_hwfn
350  * @param p_ptt
351  * @param p_filter - MAC to remove
352  */
353 void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
354 			       struct qed_ptt *p_ptt, u8 *p_filter);
355 
356 enum qed_llh_port_filter_type_t {
357 	QED_LLH_FILTER_ETHERTYPE,
358 	QED_LLH_FILTER_TCP_SRC_PORT,
359 	QED_LLH_FILTER_TCP_DEST_PORT,
360 	QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
361 	QED_LLH_FILTER_UDP_SRC_PORT,
362 	QED_LLH_FILTER_UDP_DEST_PORT,
363 	QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT
364 };
365 
366 /**
367  * @brief qed_llh_add_protocol_filter - configures a protocol filter in llh
368  *
369  * @param p_hwfn
370  * @param p_ptt
371  * @param source_port_or_eth_type - source port or ethertype to add
372  * @param dest_port - destination port to add
373  * @param type - type of filters and comparing
374  */
375 int
376 qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
377 			    struct qed_ptt *p_ptt,
378 			    u16 source_port_or_eth_type,
379 			    u16 dest_port,
380 			    enum qed_llh_port_filter_type_t type);
381 
382 /**
383  * @brief qed_llh_remove_protocol_filter - remove a protocol filter in llh
384  *
385  * @param p_hwfn
386  * @param p_ptt
387  * @param source_port_or_eth_type - source port or ethertype to add
388  * @param dest_port - destination port to add
389  * @param type - type of filters and comparing
390  */
391 void
392 qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
393 			       struct qed_ptt *p_ptt,
394 			       u16 source_port_or_eth_type,
395 			       u16 dest_port,
396 			       enum qed_llh_port_filter_type_t type);
397 
398 /**
399  * *@brief Cleanup of previous driver remains prior to load
400  *
401  * @param p_hwfn
402  * @param p_ptt
403  * @param id - For PF, engine-relative. For VF, PF-relative.
404  * @param is_vf - true iff cleanup is made for a VF.
405  *
406  * @return int
407  */
408 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
409 		      struct qed_ptt *p_ptt, u16 id, bool is_vf);
410 
411 /**
412  * @brief qed_set_rxq_coalesce - Configure coalesce parameters for an Rx queue
413  * The fact that we can configure coalescing to up to 511, but on varying
414  * accuracy [the bigger the value the less accurate] up to a mistake of 3usec
415  * for the highest values.
416  *
417  * @param p_hwfn
418  * @param p_ptt
419  * @param coalesce - Coalesce value in micro seconds.
420  * @param qid - Queue index.
421  * @param qid - SB Id
422  *
423  * @return int
424  */
425 int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
426 			 u16 coalesce, u8 qid, u16 sb_id);
427 
428 /**
429  * @brief qed_set_txq_coalesce - Configure coalesce parameters for a Tx queue
430  * While the API allows setting coalescing per-qid, all tx queues sharing a
431  * SB should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
432  * otherwise configuration would break.
433  *
434  * @param p_hwfn
435  * @param p_ptt
436  * @param coalesce - Coalesce value in micro seconds.
437  * @param qid - Queue index.
438  * @param qid - SB Id
439  *
440  * @return int
441  */
442 int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
443 			 u16 coalesce, u8 qid, u16 sb_id);
444 #endif
445