xref: /illumos-gate/usr/src/uts/common/io/qede/579xx/drivers/ecore/ecore_spq.h (revision 14b24e2b79293068c8e016a69ef1d872fb5e2fd5)
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, v.1,  (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 
22 /*
23 * Copyright 2014-2017 Cavium, Inc.
24 * The contents of this file are subject to the terms of the Common Development
25 * and Distribution License, v.1,  (the "License").
26 
27 * You may not use this file except in compliance with the License.
28 
29 * You can obtain a copy of the License at available
30 * at http://opensource.org/licenses/CDDL-1.0
31 
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35 
36 #ifndef __ECORE_SPQ_H__
37 #define __ECORE_SPQ_H__
38 
39 #include "ecore_hsi_common.h"
40 #include "ecore_status.h"
41 #include "ecore_hsi_eth.h"
42 #include "ecore_hsi_fcoe.h"
43 #include "tcp_common.h"
44 #include "ecore_hsi_iscsi.h"
45 #include "ecore_hsi_roce.h"
46 #include "ecore_hsi_iwarp.h"
47 #include "ecore_chain.h"
48 #include "ecore_sp_api.h"
49 
50 union ramrod_data
51 {
52 	struct pf_start_ramrod_data			pf_start;
53 	struct pf_update_ramrod_data			pf_update;
54 	struct rl_update_ramrod_data			rl_update;
55 	struct rx_queue_start_ramrod_data		rx_queue_start;
56 	struct rx_queue_update_ramrod_data		rx_queue_update;
57 	struct rx_queue_stop_ramrod_data		rx_queue_stop;
58 	struct tx_queue_start_ramrod_data		tx_queue_start;
59 	struct tx_queue_stop_ramrod_data		tx_queue_stop;
60 	struct vport_start_ramrod_data			vport_start;
61 	struct vport_stop_ramrod_data			vport_stop;
62 	struct rx_update_gft_filter_data		rx_update_gft;
63 	struct vport_update_ramrod_data			vport_update;
64 	struct core_rx_start_ramrod_data		core_rx_queue_start;
65 	struct core_rx_stop_ramrod_data			core_rx_queue_stop;
66 	struct core_tx_start_ramrod_data		core_tx_queue_start;
67 	struct core_tx_stop_ramrod_data			core_tx_queue_stop;
68 	struct vport_filter_update_ramrod_data		vport_filter_update;
69 
70 	struct rdma_init_func_ramrod_data		rdma_init_func;
71 	struct rdma_close_func_ramrod_data		rdma_close_func;
72 	struct rdma_register_tid_ramrod_data		rdma_register_tid;
73 	struct rdma_deregister_tid_ramrod_data		rdma_deregister_tid;
74 	struct roce_create_qp_resp_ramrod_data		roce_create_qp_resp;
75 	struct roce_create_qp_req_ramrod_data		roce_create_qp_req;
76 	struct roce_modify_qp_resp_ramrod_data		roce_modify_qp_resp;
77 	struct roce_modify_qp_req_ramrod_data		roce_modify_qp_req;
78 	struct roce_query_qp_resp_ramrod_data		roce_query_qp_resp;
79 	struct roce_query_qp_req_ramrod_data		roce_query_qp_req;
80 	struct roce_destroy_qp_resp_ramrod_data		roce_destroy_qp_resp;
81 	struct roce_destroy_qp_req_ramrod_data		roce_destroy_qp_req;
82 	struct roce_init_func_ramrod_data		roce_init_func;
83 
84 	struct rdma_create_cq_ramrod_data		rdma_create_cq;
85 	struct rdma_resize_cq_ramrod_data		rdma_resize_cq;
86 	struct rdma_destroy_cq_ramrod_data		rdma_destroy_cq;
87 	struct rdma_srq_create_ramrod_data		rdma_create_srq;
88 	struct rdma_srq_destroy_ramrod_data		rdma_destroy_srq;
89 	struct rdma_srq_modify_ramrod_data		rdma_modify_srq;
90 
91 	struct iwarp_create_qp_ramrod_data		iwarp_create_qp;
92 	struct iwarp_tcp_offload_ramrod_data		iwarp_tcp_offload;
93 	struct iwarp_mpa_offload_ramrod_data		iwarp_mpa_offload;
94 	struct iwarp_modify_qp_ramrod_data		iwarp_modify_qp;
95 	struct iwarp_query_qp_ramrod_data		iwarp_query_qp;
96 	struct iwarp_init_func_ramrod_data		iwarp_init_func;
97 
98 	struct fcoe_init_ramrod_params			fcoe_init;
99 	struct fcoe_conn_offload_ramrod_params		fcoe_conn_ofld;
100 	struct fcoe_conn_terminate_ramrod_params	fcoe_conn_terminate;
101 	struct fcoe_stat_ramrod_params			fcoe_stat;
102 
103 	struct iscsi_slow_path_hdr			iscsi_empty;
104 	struct iscsi_init_ramrod_params			iscsi_init;
105 	struct iscsi_spe_func_dstry			iscsi_destroy;
106 	struct iscsi_spe_conn_offload			iscsi_conn_offload;
107 	struct iscsi_conn_update_ramrod_params		iscsi_conn_update;
108 	struct iscsi_spe_conn_mac_update		iscsi_conn_mac_update;
109 	struct iscsi_spe_conn_termination		iscsi_conn_terminate;
110 
111 	struct vf_start_ramrod_data			vf_start;
112 	struct vf_stop_ramrod_data			vf_stop;
113 };
114 
115 #define EQ_MAX_CREDIT	0xffffffff
116 
117 enum spq_priority {
118 	ECORE_SPQ_PRIORITY_NORMAL,
119 	ECORE_SPQ_PRIORITY_HIGH,
120 };
121 
122 union ecore_spq_req_comp {
123 	struct ecore_spq_comp_cb cb;
124 	u64			 *done_addr;
125 };
126 
127 /* SPQ_MODE_EBLOCK */
128 struct ecore_spq_comp_done {
129 	u64 done;
130 	u8  fw_return_code;
131 };
132 
133 struct ecore_spq_entry {
134 	osal_list_entry_t		list;
135 
136 	u8				flags;
137 
138 	/* HSI slow path element */
139 	struct slow_path_element	elem;
140 
141 	union ramrod_data		ramrod;
142 
143 	enum spq_priority		priority;
144 
145 	/* pending queue for this entry */
146 	osal_list_t			*queue;
147 
148 	enum spq_mode			comp_mode;
149 	struct ecore_spq_comp_cb	comp_cb;
150 	struct ecore_spq_comp_done	comp_done; /* SPQ_MODE_EBLOCK */
151 };
152 
153 struct ecore_eq {
154 	struct ecore_chain	chain;
155 	u8			eq_sb_index;	/* index within the SB */
156 	__le16			*p_fw_cons;	/* ptr to index value */
157 };
158 
159 struct ecore_consq {
160 	struct ecore_chain	chain;
161 };
162 
163 struct ecore_spq {
164 	osal_spinlock_t			lock;
165 
166 	osal_list_t			unlimited_pending;
167 	osal_list_t			pending;
168 	osal_list_t			completion_pending;
169 	osal_list_t			free_pool;
170 
171 	struct ecore_chain		chain;
172 
173 	/* allocated dma-able memory for spq entries (+ramrod data) */
174 	dma_addr_t			p_phys;
175 	struct ecore_spq_entry		*p_virt;
176 
177 	/* Bitmap for handling out-of-order completions */
178 #define SPQ_RING_SIZE		\
179 	(CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
180 #define SPQ_COMP_BMAP_SIZE	(SPQ_RING_SIZE / (sizeof(unsigned long) * 8 /* BITS_PER_LONG */))
181 	unsigned long			p_comp_bitmap[SPQ_COMP_BMAP_SIZE];
182 	u8				comp_bitmap_idx;
183 #define SPQ_COMP_BMAP_SET_BIT(p_spq, idx)					\
184 	do {									\
185 		OSAL_SET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap);	\
186 	} while (0)
187 #define SPQ_COMP_BMAP_CLEAR_BIT(p_spq, idx)						\
188 	do {										\
189 		OSAL_CLEAR_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap);	\
190 	} while (0)
191 #define SPQ_COMP_BMAP_TEST_BIT(p_spq, idx)	\
192 	(OSAL_TEST_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap))
193 
194 	/* Statistics */
195 	u32				unlimited_pending_count;
196 	u32				normal_count;
197 	u32				high_count;
198 	u32				comp_sent_count;
199 	u32				comp_count;
200 
201 	u32				cid;
202 };
203 
204 struct ecore_port;
205 struct ecore_hwfn;
206 
207 /**
208  * @brief ecore_spq_post - Posts a Slow hwfn request to FW, or lacking that
209  *        Pends it to the future list.
210  *
211  * @param p_hwfn
212  * @param p_req
213  *
214  * @return enum _ecore_status_t
215  */
216 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn	   *p_hwfn,
217 				    struct ecore_spq_entry *p_ent,
218 				    u8                     *fw_return_code);
219 
220 /**
221  * @brief ecore_spq_allocate - Alloocates & initializes the SPQ and EQ.
222  *
223  * @param p_hwfn
224  *
225  * @return enum _ecore_status_t
226  */
227 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn	*p_hwfn);
228 
229 /**
230  * @brief ecore_spq_setup - Reset the SPQ to its start state.
231  *
232  * @param p_hwfn
233  */
234 void ecore_spq_setup(struct ecore_hwfn *p_hwfn);
235 
236 /**
237  * @brief ecore_spq_deallocate - Deallocates the given SPQ struct.
238  *
239  * @param p_hwfn
240  */
241 void ecore_spq_free(struct ecore_hwfn *p_hwfn);
242 
243 /**
244  * @brief ecore_spq_get_entry - Obtain an entrry from the spq
245  *        free pool list.
246  *
247  *
248  *
249  * @param p_hwfn
250  * @param pp_ent
251  *
252  * @return enum _ecore_status_t
253  */
254 enum _ecore_status_t
255 ecore_spq_get_entry(struct ecore_hwfn		*p_hwfn,
256 		    struct ecore_spq_entry	**pp_ent);
257 
258 /**
259  * @brief ecore_spq_return_entry - Return an entry to spq free
260  *                                 pool list
261  *
262  * @param p_hwfn
263  * @param p_ent
264  */
265 void ecore_spq_return_entry(struct ecore_hwfn		*p_hwfn,
266 			    struct ecore_spq_entry      *p_ent);
267 /**
268  * @brief ecore_eq_allocate - Allocates & initializes an EQ struct
269  *
270  * @param p_hwfn
271  * @param num_elem number of elements in the eq
272  *
273  * @return enum _ecore_status_t
274  */
275 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn	*p_hwfn, u16 num_elem);
276 
277 /**
278  * @brief ecore_eq_setup - Reset the EQ to its start state.
279  *
280  * @param p_hwfn
281  */
282 void ecore_eq_setup(struct ecore_hwfn *p_hwfn);
283 
284 /**
285  * @brief ecore_eq_free - deallocates the given EQ struct.
286  *
287  * @param p_hwfn
288  */
289 void ecore_eq_free(struct ecore_hwfn *p_hwfn);
290 
291 /**
292  * @brief ecore_eq_prod_update - update the FW with default EQ producer
293  *
294  * @param p_hwfn
295  * @param prod
296  */
297 void ecore_eq_prod_update(struct ecore_hwfn	*p_hwfn,
298 			  u16			prod);
299 
300 /**
301  * @brief ecore_eq_completion - Completes currently pending EQ elements
302  *
303  * @param p_hwfn
304  * @param cookie
305  *
306  * @return enum _ecore_status_t
307  */
308 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn	*p_hwfn,
309 					 void			*cookie);
310 
311 /**
312  * @brief ecore_spq_completion - Completes a single event
313  *
314  * @param p_hwfn
315  * @param echo - echo value from cookie (used for determining completion)
316  * @param p_data - data from cookie (used in callback function if applicable)
317  *
318  * @return enum _ecore_status_t
319  */
320 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn	*p_hwfn,
321 					  __le16		echo,
322 					  u8                    fw_return_code,
323 					  union event_ring_data	*p_data);
324 
325 /**
326  * @brief ecore_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
327  *
328  * @param p_hwfn
329  *
330  * @return u32 - SPQ CID
331  */
332 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn);
333 
334 /**
335  * @brief ecore_consq_alloc - Allocates & initializes an ConsQ struct
336  *
337  * @param p_hwfn
338  *
339  * @return enum _ecore_status_t
340  */
341 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn);
342 
343 /**
344  * @brief ecore_consq_setup - Reset the ConsQ to its start state.
345  *
346  * @param p_hwfn
347  */
348 void ecore_consq_setup(struct ecore_hwfn *p_hwfn);
349 
350 /**
351  * @brief ecore_consq_free - deallocates the given ConsQ struct.
352  *
353  * @param p_hwfn
354  */
355 void ecore_consq_free(struct ecore_hwfn *p_hwfn);
356 
357 #endif /* __ECORE_SPQ_H__ */
358