xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_spq.h (revision 42249ef2)
1 /*
2  * Copyright (c) 2017-2018 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  */
30 
31 #ifndef __ECORE_SPQ_H__
32 #define __ECORE_SPQ_H__
33 
34 #include "ecore_hsi_common.h"
35 #include "ecore_status.h"
36 #include "ecore_hsi_eth.h"
37 #include "ecore_hsi_fcoe.h"
38 #include "tcp_common.h"
39 #include "ecore_hsi_iscsi.h"
40 #include "ecore_hsi_roce.h"
41 #include "ecore_hsi_iwarp.h"
42 #include "ecore_chain.h"
43 #include "ecore_sp_api.h"
44 
45 union ramrod_data
46 {
47 	struct pf_start_ramrod_data			pf_start;
48 	struct pf_update_ramrod_data			pf_update;
49 	struct rl_update_ramrod_data			rl_update;
50 	struct rx_queue_start_ramrod_data		rx_queue_start;
51 	struct rx_queue_update_ramrod_data		rx_queue_update;
52 	struct rx_queue_stop_ramrod_data		rx_queue_stop;
53 	struct tx_queue_start_ramrod_data		tx_queue_start;
54 	struct tx_queue_stop_ramrod_data		tx_queue_stop;
55 	struct vport_start_ramrod_data			vport_start;
56 	struct vport_stop_ramrod_data			vport_stop;
57 	struct rx_update_gft_filter_data		rx_update_gft;
58 	struct vport_update_ramrod_data			vport_update;
59 	struct core_rx_start_ramrod_data		core_rx_queue_start;
60 	struct core_rx_stop_ramrod_data			core_rx_queue_stop;
61 	struct core_tx_start_ramrod_data		core_tx_queue_start;
62 	struct core_tx_stop_ramrod_data			core_tx_queue_stop;
63 	struct vport_filter_update_ramrod_data		vport_filter_update;
64 
65 	struct rdma_init_func_ramrod_data		rdma_init_func;
66 	struct rdma_close_func_ramrod_data		rdma_close_func;
67 	struct rdma_register_tid_ramrod_data		rdma_register_tid;
68 	struct rdma_deregister_tid_ramrod_data		rdma_deregister_tid;
69 	struct roce_create_qp_resp_ramrod_data		roce_create_qp_resp;
70 	struct roce_create_qp_req_ramrod_data		roce_create_qp_req;
71 	struct roce_modify_qp_resp_ramrod_data		roce_modify_qp_resp;
72 	struct roce_modify_qp_req_ramrod_data		roce_modify_qp_req;
73 	struct roce_query_qp_resp_ramrod_data		roce_query_qp_resp;
74 	struct roce_query_qp_req_ramrod_data		roce_query_qp_req;
75 	struct roce_destroy_qp_resp_ramrod_data		roce_destroy_qp_resp;
76 	struct roce_destroy_qp_req_ramrod_data		roce_destroy_qp_req;
77 	struct roce_init_func_ramrod_data		roce_init_func;
78 
79 	struct rdma_create_cq_ramrod_data		rdma_create_cq;
80 	struct rdma_resize_cq_ramrod_data		rdma_resize_cq;
81 	struct rdma_destroy_cq_ramrod_data		rdma_destroy_cq;
82 	struct rdma_srq_create_ramrod_data		rdma_create_srq;
83 	struct rdma_srq_destroy_ramrod_data		rdma_destroy_srq;
84 	struct rdma_srq_modify_ramrod_data		rdma_modify_srq;
85 
86 	struct iwarp_create_qp_ramrod_data		iwarp_create_qp;
87 	struct iwarp_tcp_offload_ramrod_data		iwarp_tcp_offload;
88 	struct iwarp_mpa_offload_ramrod_data		iwarp_mpa_offload;
89 	struct iwarp_modify_qp_ramrod_data		iwarp_modify_qp;
90 	struct iwarp_query_qp_ramrod_data		iwarp_query_qp;
91 	struct iwarp_init_func_ramrod_data		iwarp_init_func;
92 
93 	struct fcoe_init_ramrod_params			fcoe_init;
94 	struct fcoe_conn_offload_ramrod_params		fcoe_conn_ofld;
95 	struct fcoe_conn_terminate_ramrod_params	fcoe_conn_terminate;
96 	struct fcoe_stat_ramrod_params			fcoe_stat;
97 
98 	struct iscsi_slow_path_hdr			iscsi_empty;
99 	struct iscsi_init_ramrod_params			iscsi_init;
100 	struct iscsi_spe_func_dstry			iscsi_destroy;
101 	struct iscsi_spe_conn_offload			iscsi_conn_offload;
102 	struct iscsi_conn_update_ramrod_params		iscsi_conn_update;
103 	struct iscsi_spe_conn_mac_update		iscsi_conn_mac_update;
104 	struct iscsi_spe_conn_termination		iscsi_conn_terminate;
105 	struct iscsi_spe_conn_statistics		iscsi_conn_statistics;
106 
107 	struct vf_start_ramrod_data			vf_start;
108 	struct vf_stop_ramrod_data			vf_stop;
109 };
110 
111 #define EQ_MAX_CREDIT	0xffffffff
112 
113 enum spq_priority {
114 	ECORE_SPQ_PRIORITY_NORMAL,
115 	ECORE_SPQ_PRIORITY_HIGH,
116 };
117 
118 union ecore_spq_req_comp {
119 	struct ecore_spq_comp_cb cb;
120 	u64			 *done_addr;
121 };
122 
123 /* SPQ_MODE_EBLOCK */
124 struct ecore_spq_comp_done {
125 	u64 done;
126 	u8  fw_return_code;
127 };
128 
129 struct ecore_spq_entry {
130 	osal_list_entry_t		list;
131 
132 	u8				flags;
133 
134 	/* HSI slow path element */
135 	struct slow_path_element	elem;
136 
137 	union ramrod_data		ramrod;
138 
139 	enum spq_priority		priority;
140 
141 	/* pending queue for this entry */
142 	osal_list_t			*queue;
143 
144 	enum spq_mode			comp_mode;
145 	struct ecore_spq_comp_cb	comp_cb;
146 	struct ecore_spq_comp_done	comp_done; /* SPQ_MODE_EBLOCK */
147 };
148 
149 struct ecore_eq {
150 	struct ecore_chain	chain;
151 	u8			eq_sb_index;	/* index within the SB */
152 	__le16			*p_fw_cons;	/* ptr to index value */
153 };
154 
155 struct ecore_consq {
156 	struct ecore_chain	chain;
157 };
158 
159 typedef enum _ecore_status_t
160 (*ecore_spq_async_comp_cb)(struct ecore_hwfn *p_hwfn,
161 			   u8 opcode,
162 			   u16 echo,
163 			   union event_ring_data *data,
164 			   u8 fw_return_code);
165 
166 enum _ecore_status_t
167 ecore_spq_register_async_cb(struct ecore_hwfn *p_hwfn,
168 			    enum protocol_type protocol_id,
169 			    ecore_spq_async_comp_cb cb);
170 
171 void
172 ecore_spq_unregister_async_cb(struct ecore_hwfn *p_hwfn,
173 			      enum protocol_type protocol_id);
174 
175 struct ecore_spq {
176 	osal_spinlock_t			lock;
177 
178 	osal_list_t			unlimited_pending;
179 	osal_list_t			pending;
180 	osal_list_t			completion_pending;
181 	osal_list_t			free_pool;
182 
183 	struct ecore_chain		chain;
184 
185 	/* allocated dma-able memory for spq entries (+ramrod data) */
186 	dma_addr_t			p_phys;
187 	struct ecore_spq_entry		*p_virt;
188 
189 	/* Bitmap for handling out-of-order completions */
190 #define SPQ_RING_SIZE		\
191 	(CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
192 #define SPQ_COMP_BMAP_SIZE	(SPQ_RING_SIZE / (sizeof(unsigned long) * 8 /* BITS_PER_LONG */))
193 	unsigned long			p_comp_bitmap[SPQ_COMP_BMAP_SIZE];
194 	u8				comp_bitmap_idx;
195 #define SPQ_COMP_BMAP_SET_BIT(p_spq, idx)					\
196 	do {									\
197 		OSAL_SET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap);	\
198 	} while (0)
199 #define SPQ_COMP_BMAP_CLEAR_BIT(p_spq, idx)						\
200 	do {										\
201 		OSAL_CLEAR_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap);	\
202 	} while (0)
203 #define SPQ_COMP_BMAP_TEST_BIT(p_spq, idx)	\
204 	(OSAL_TEST_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap))
205 
206 	/* Statistics */
207 	u32				unlimited_pending_count;
208 	u32				normal_count;
209 	u32				high_count;
210 	u32				comp_sent_count;
211 	u32				comp_count;
212 
213 	u32				cid;
214 
215 	u32				db_addr_offset;
216 	struct core_db_data		db_data;
217 	ecore_spq_async_comp_cb		async_comp_cb[MAX_PROTOCOL_TYPE];
218 };
219 
220 struct ecore_port;
221 struct ecore_hwfn;
222 
223 /**
224  * @brief ecore_spq_post - Posts a Slow hwfn request to FW, or lacking that
225  *        Pends it to the future list.
226  *
227  * @param p_hwfn
228  * @param p_req
229  *
230  * @return enum _ecore_status_t
231  */
232 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn	   *p_hwfn,
233 				    struct ecore_spq_entry *p_ent,
234 				    u8                     *fw_return_code);
235 
236 /**
237  * @brief ecore_spq_allocate - Alloocates & initializes the SPQ and EQ.
238  *
239  * @param p_hwfn
240  *
241  * @return enum _ecore_status_t
242  */
243 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn	*p_hwfn);
244 
245 /**
246  * @brief ecore_spq_setup - Reset the SPQ to its start state.
247  *
248  * @param p_hwfn
249  */
250 void ecore_spq_setup(struct ecore_hwfn *p_hwfn);
251 
252 /**
253  * @brief ecore_spq_deallocate - Deallocates the given SPQ struct.
254  *
255  * @param p_hwfn
256  */
257 void ecore_spq_free(struct ecore_hwfn *p_hwfn);
258 
259 /**
260  * @brief ecore_spq_get_entry - Obtain an entrry from the spq
261  *        free pool list.
262  *
263  *
264  *
265  * @param p_hwfn
266  * @param pp_ent
267  *
268  * @return enum _ecore_status_t
269  */
270 enum _ecore_status_t
271 ecore_spq_get_entry(struct ecore_hwfn		*p_hwfn,
272 		    struct ecore_spq_entry	**pp_ent);
273 
274 /**
275  * @brief ecore_spq_return_entry - Return an entry to spq free
276  *                                 pool list
277  *
278  * @param p_hwfn
279  * @param p_ent
280  */
281 void ecore_spq_return_entry(struct ecore_hwfn		*p_hwfn,
282 			    struct ecore_spq_entry      *p_ent);
283 /**
284  * @brief ecore_eq_allocate - Allocates & initializes an EQ struct
285  *
286  * @param p_hwfn
287  * @param num_elem number of elements in the eq
288  *
289  * @return enum _ecore_status_t
290  */
291 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn	*p_hwfn, u16 num_elem);
292 
293 /**
294  * @brief ecore_eq_setup - Reset the EQ to its start state.
295  *
296  * @param p_hwfn
297  */
298 void ecore_eq_setup(struct ecore_hwfn *p_hwfn);
299 
300 /**
301  * @brief ecore_eq_free - deallocates the given EQ struct.
302  *
303  * @param p_hwfn
304  */
305 void ecore_eq_free(struct ecore_hwfn *p_hwfn);
306 
307 /**
308  * @brief ecore_eq_prod_update - update the FW with default EQ producer
309  *
310  * @param p_hwfn
311  * @param prod
312  */
313 void ecore_eq_prod_update(struct ecore_hwfn	*p_hwfn,
314 			  u16			prod);
315 
316 /**
317  * @brief ecore_eq_completion - Completes currently pending EQ elements
318  *
319  * @param p_hwfn
320  * @param cookie
321  *
322  * @return enum _ecore_status_t
323  */
324 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn	*p_hwfn,
325 					 void			*cookie);
326 
327 /**
328  * @brief ecore_spq_completion - Completes a single event
329  *
330  * @param p_hwfn
331  * @param echo - echo value from cookie (used for determining completion)
332  * @param p_data - data from cookie (used in callback function if applicable)
333  *
334  * @return enum _ecore_status_t
335  */
336 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn	*p_hwfn,
337 					  __le16		echo,
338 					  u8                    fw_return_code,
339 					  union event_ring_data	*p_data);
340 
341 /**
342  * @brief ecore_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
343  *
344  * @param p_hwfn
345  *
346  * @return u32 - SPQ CID
347  */
348 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn);
349 
350 /**
351  * @brief ecore_consq_alloc - Allocates & initializes an ConsQ struct
352  *
353  * @param p_hwfn
354  *
355  * @return enum _ecore_status_t
356  */
357 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn);
358 
359 /**
360  * @brief ecore_consq_setup - Reset the ConsQ to its start state.
361  *
362  * @param p_hwfn
363  */
364 void ecore_consq_setup(struct ecore_hwfn *p_hwfn);
365 
366 /**
367  * @brief ecore_consq_free - deallocates the given ConsQ struct.
368  *
369  * @param p_hwfn
370  */
371 void ecore_consq_free(struct ecore_hwfn *p_hwfn);
372 enum _ecore_status_t ecore_spq_pend_post(struct ecore_hwfn *p_hwfn);
373 #endif /* __ECORE_SPQ_H__ */
374