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  */
5 
6 #ifndef _QED_SP_H
7 #define _QED_SP_H
8 
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/list.h>
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/qed/qed_chain.h>
15 #include "qed.h"
16 #include "qed_hsi.h"
17 
18 enum spq_mode {
19 	QED_SPQ_MODE_BLOCK,     /* Client will poll a designated mem. address */
20 	QED_SPQ_MODE_CB,        /* Client supplies a callback */
21 	QED_SPQ_MODE_EBLOCK,    /* QED should block until completion */
22 };
23 
24 struct qed_spq_comp_cb {
25 	void	(*function)(struct qed_hwfn *,
26 			    void *,
27 			    union event_ring_data *,
28 			    u8 fw_return_code);
29 	void	*cookie;
30 };
31 
32 /**
33  * @brief qed_eth_cqe_completion - handles the completion of a
34  *        ramrod on the cqe ring
35  *
36  * @param p_hwfn
37  * @param cqe
38  *
39  * @return int
40  */
41 int qed_eth_cqe_completion(struct qed_hwfn *p_hwfn,
42 			   struct eth_slow_path_rx_cqe *cqe);
43 
44 /**
45  *  @file
46  *
47  *  QED Slow-hwfn queue interface
48  */
49 
50 union ramrod_data {
51 	struct pf_start_ramrod_data pf_start;
52 	struct pf_update_ramrod_data pf_update;
53 	struct rx_queue_start_ramrod_data rx_queue_start;
54 	struct rx_queue_update_ramrod_data rx_queue_update;
55 	struct rx_queue_stop_ramrod_data rx_queue_stop;
56 	struct tx_queue_start_ramrod_data tx_queue_start;
57 	struct tx_queue_stop_ramrod_data tx_queue_stop;
58 	struct vport_start_ramrod_data vport_start;
59 	struct vport_stop_ramrod_data vport_stop;
60 	struct rx_update_gft_filter_data rx_update_gft;
61 	struct vport_update_ramrod_data vport_update;
62 	struct core_rx_start_ramrod_data core_rx_queue_start;
63 	struct core_rx_stop_ramrod_data core_rx_queue_stop;
64 	struct core_tx_start_ramrod_data core_tx_queue_start;
65 	struct core_tx_stop_ramrod_data core_tx_queue_stop;
66 	struct vport_filter_update_ramrod_data vport_filter_update;
67 
68 	struct rdma_init_func_ramrod_data rdma_init_func;
69 	struct rdma_close_func_ramrod_data rdma_close_func;
70 	struct rdma_register_tid_ramrod_data rdma_register_tid;
71 	struct rdma_deregister_tid_ramrod_data rdma_deregister_tid;
72 	struct roce_create_qp_resp_ramrod_data roce_create_qp_resp;
73 	struct roce_create_qp_req_ramrod_data roce_create_qp_req;
74 	struct roce_modify_qp_resp_ramrod_data roce_modify_qp_resp;
75 	struct roce_modify_qp_req_ramrod_data roce_modify_qp_req;
76 	struct roce_query_qp_resp_ramrod_data roce_query_qp_resp;
77 	struct roce_query_qp_req_ramrod_data roce_query_qp_req;
78 	struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp;
79 	struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req;
80 	struct roce_init_func_ramrod_data roce_init_func;
81 	struct rdma_create_cq_ramrod_data rdma_create_cq;
82 	struct rdma_destroy_cq_ramrod_data rdma_destroy_cq;
83 	struct rdma_srq_create_ramrod_data rdma_create_srq;
84 	struct rdma_srq_destroy_ramrod_data rdma_destroy_srq;
85 	struct rdma_srq_modify_ramrod_data rdma_modify_srq;
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_init_func_ramrod_data iwarp_init_func;
91 	struct fcoe_init_ramrod_params fcoe_init;
92 	struct fcoe_conn_offload_ramrod_params fcoe_conn_ofld;
93 	struct fcoe_conn_terminate_ramrod_params fcoe_conn_terminate;
94 	struct fcoe_stat_ramrod_params fcoe_stat;
95 
96 	struct iscsi_init_ramrod_params iscsi_init;
97 	struct iscsi_spe_conn_offload iscsi_conn_offload;
98 	struct iscsi_conn_update_ramrod_params iscsi_conn_update;
99 	struct iscsi_spe_conn_mac_update iscsi_conn_mac_update;
100 	struct iscsi_spe_conn_termination iscsi_conn_terminate;
101 
102 	struct vf_start_ramrod_data vf_start;
103 	struct vf_stop_ramrod_data vf_stop;
104 };
105 
106 #define EQ_MAX_CREDIT   0xffffffff
107 
108 enum spq_priority {
109 	QED_SPQ_PRIORITY_NORMAL,
110 	QED_SPQ_PRIORITY_HIGH,
111 };
112 
113 union qed_spq_req_comp {
114 	struct qed_spq_comp_cb	cb;
115 	u64			*done_addr;
116 };
117 
118 struct qed_spq_comp_done {
119 	unsigned int	done;
120 	u8		fw_return_code;
121 };
122 
123 struct qed_spq_entry {
124 	struct list_head		list;
125 
126 	u8				flags;
127 
128 	/* HSI slow path element */
129 	struct slow_path_element	elem;
130 
131 	union ramrod_data		ramrod;
132 
133 	enum spq_priority		priority;
134 
135 	/* pending queue for this entry */
136 	struct list_head		*queue;
137 
138 	enum spq_mode			comp_mode;
139 	struct qed_spq_comp_cb		comp_cb;
140 	struct qed_spq_comp_done	comp_done; /* SPQ_MODE_EBLOCK */
141 
142 	/* Posted entry for unlimited list entry in EBLOCK mode */
143 	struct qed_spq_entry		*post_ent;
144 };
145 
146 struct qed_eq {
147 	struct qed_chain	chain;
148 	u8			eq_sb_index;    /* index within the SB */
149 	__le16			*p_fw_cons;     /* ptr to index value */
150 };
151 
152 struct qed_consq {
153 	struct qed_chain chain;
154 };
155 
156 typedef int
157 (*qed_spq_async_comp_cb)(struct qed_hwfn *p_hwfn,
158 			 u8 opcode,
159 			 u16 echo,
160 			 union event_ring_data *data,
161 			 u8 fw_return_code);
162 
163 int
164 qed_spq_register_async_cb(struct qed_hwfn *p_hwfn,
165 			  enum protocol_type protocol_id,
166 			  qed_spq_async_comp_cb cb);
167 
168 void
169 qed_spq_unregister_async_cb(struct qed_hwfn *p_hwfn,
170 			    enum protocol_type protocol_id);
171 
172 struct qed_spq {
173 	spinlock_t		lock; /* SPQ lock */
174 
175 	struct list_head	unlimited_pending;
176 	struct list_head	pending;
177 	struct list_head	completion_pending;
178 	struct list_head	free_pool;
179 
180 	struct qed_chain	chain;
181 
182 	/* allocated dma-able memory for spq entries (+ramrod data) */
183 	dma_addr_t		p_phys;
184 	struct qed_spq_entry	*p_virt;
185 
186 #define SPQ_RING_SIZE \
187 	(CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
188 
189 	/* Bitmap for handling out-of-order completions */
190 	DECLARE_BITMAP(p_comp_bitmap, SPQ_RING_SIZE);
191 	u8			comp_bitmap_idx;
192 
193 	/* Statistics */
194 	u32			unlimited_pending_count;
195 	u32			normal_count;
196 	u32			high_count;
197 	u32			comp_sent_count;
198 	u32			comp_count;
199 
200 	u32			cid;
201 	u32			db_addr_offset;
202 	struct core_db_data	db_data;
203 	qed_spq_async_comp_cb	async_comp_cb[MAX_PROTOCOL_TYPE];
204 };
205 
206 /**
207  * @brief qed_spq_post - Posts a Slow hwfn request to FW, or lacking that
208  *        Pends it to the future list.
209  *
210  * @param p_hwfn
211  * @param p_req
212  *
213  * @return int
214  */
215 int qed_spq_post(struct qed_hwfn *p_hwfn,
216 		 struct qed_spq_entry *p_ent,
217 		 u8 *fw_return_code);
218 
219 /**
220  * @brief qed_spq_allocate - Alloocates & initializes the SPQ and EQ.
221  *
222  * @param p_hwfn
223  *
224  * @return int
225  */
226 int qed_spq_alloc(struct qed_hwfn *p_hwfn);
227 
228 /**
229  * @brief qed_spq_setup - Reset the SPQ to its start state.
230  *
231  * @param p_hwfn
232  */
233 void qed_spq_setup(struct qed_hwfn *p_hwfn);
234 
235 /**
236  * @brief qed_spq_deallocate - Deallocates the given SPQ struct.
237  *
238  * @param p_hwfn
239  */
240 void qed_spq_free(struct qed_hwfn *p_hwfn);
241 
242 /**
243  * @brief qed_spq_get_entry - Obtain an entrry from the spq
244  *        free pool list.
245  *
246  *
247  *
248  * @param p_hwfn
249  * @param pp_ent
250  *
251  * @return int
252  */
253 int
254 qed_spq_get_entry(struct qed_hwfn *p_hwfn,
255 		  struct qed_spq_entry **pp_ent);
256 
257 /**
258  * @brief qed_spq_return_entry - Return an entry to spq free
259  *                                 pool list
260  *
261  * @param p_hwfn
262  * @param p_ent
263  */
264 void qed_spq_return_entry(struct qed_hwfn *p_hwfn,
265 			  struct qed_spq_entry *p_ent);
266 /**
267  * @brief qed_eq_allocate - Allocates & initializes an EQ struct
268  *
269  * @param p_hwfn
270  * @param num_elem number of elements in the eq
271  *
272  * @return int
273  */
274 int qed_eq_alloc(struct qed_hwfn *p_hwfn, u16 num_elem);
275 
276 /**
277  * @brief qed_eq_setup - Reset the EQ to its start state.
278  *
279  * @param p_hwfn
280  */
281 void qed_eq_setup(struct qed_hwfn *p_hwfn);
282 
283 /**
284  * @brief qed_eq_free - deallocates the given EQ struct.
285  *
286  * @param p_hwfn
287  */
288 void qed_eq_free(struct qed_hwfn *p_hwfn);
289 
290 /**
291  * @brief qed_eq_prod_update - update the FW with default EQ producer
292  *
293  * @param p_hwfn
294  * @param prod
295  */
296 void qed_eq_prod_update(struct qed_hwfn *p_hwfn,
297 			u16 prod);
298 
299 /**
300  * @brief qed_eq_completion - Completes currently pending EQ elements
301  *
302  * @param p_hwfn
303  * @param cookie
304  *
305  * @return int
306  */
307 int qed_eq_completion(struct qed_hwfn *p_hwfn,
308 		      void *cookie);
309 
310 /**
311  * @brief qed_spq_completion - Completes a single event
312  *
313  * @param p_hwfn
314  * @param echo - echo value from cookie (used for determining completion)
315  * @param p_data - data from cookie (used in callback function if applicable)
316  *
317  * @return int
318  */
319 int qed_spq_completion(struct qed_hwfn *p_hwfn,
320 		       __le16 echo,
321 		       u8 fw_return_code,
322 		       union event_ring_data *p_data);
323 
324 /**
325  * @brief qed_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
326  *
327  * @param p_hwfn
328  *
329  * @return u32 - SPQ CID
330  */
331 u32 qed_spq_get_cid(struct qed_hwfn *p_hwfn);
332 
333 /**
334  * @brief qed_consq_alloc - Allocates & initializes an ConsQ
335  *        struct
336  *
337  * @param p_hwfn
338  *
339  * @return int
340  */
341 int qed_consq_alloc(struct qed_hwfn *p_hwfn);
342 
343 /**
344  * @brief qed_consq_setup - Reset the ConsQ to its start state.
345  *
346  * @param p_hwfn
347  */
348 void qed_consq_setup(struct qed_hwfn *p_hwfn);
349 
350 /**
351  * @brief qed_consq_free - deallocates the given ConsQ struct.
352  *
353  * @param p_hwfn
354  */
355 void qed_consq_free(struct qed_hwfn *p_hwfn);
356 int qed_spq_pend_post(struct qed_hwfn *p_hwfn);
357 
358 /**
359  * @file
360  *
361  * @brief Slow-hwfn low-level commands (Ramrods) function definitions.
362  */
363 
364 #define QED_SP_EQ_COMPLETION  0x01
365 #define QED_SP_CQE_COMPLETION 0x02
366 
367 struct qed_sp_init_data {
368 	u32			cid;
369 	u16			opaque_fid;
370 
371 	/* Information regarding operation upon sending & completion */
372 	enum spq_mode		comp_mode;
373 	struct qed_spq_comp_cb *p_comp_data;
374 };
375 
376 /**
377  * @brief Returns a SPQ entry to the pool / frees the entry if allocated.
378  *        Should be called on in error flows after initializing the SPQ entry
379  *        and before posting it.
380  *
381  * @param p_hwfn
382  * @param p_ent
383  */
384 void qed_sp_destroy_request(struct qed_hwfn *p_hwfn,
385 			    struct qed_spq_entry *p_ent);
386 
387 int qed_sp_init_request(struct qed_hwfn *p_hwfn,
388 			struct qed_spq_entry **pp_ent,
389 			u8 cmd,
390 			u8 protocol,
391 			struct qed_sp_init_data *p_data);
392 
393 /**
394  * @brief qed_sp_pf_start - PF Function Start Ramrod
395  *
396  * This ramrod is sent to initialize a physical function (PF). It will
397  * configure the function related parameters and write its completion to the
398  * event ring specified in the parameters.
399  *
400  * Ramrods complete on the common event ring for the PF. This ring is
401  * allocated by the driver on host memory and its parameters are written
402  * to the internal RAM of the UStorm by the Function Start Ramrod.
403  *
404  * @param p_hwfn
405  * @param p_ptt
406  * @param p_tunn
407  * @param allow_npar_tx_switch
408  *
409  * @return int
410  */
411 
412 int qed_sp_pf_start(struct qed_hwfn *p_hwfn,
413 		    struct qed_ptt *p_ptt,
414 		    struct qed_tunnel_info *p_tunn,
415 		    bool allow_npar_tx_switch);
416 
417 /**
418  * @brief qed_sp_pf_update - PF Function Update Ramrod
419  *
420  * This ramrod updates function-related parameters. Every parameter can be
421  * updated independently, according to configuration flags.
422  *
423  * @param p_hwfn
424  *
425  * @return int
426  */
427 
428 int qed_sp_pf_update(struct qed_hwfn *p_hwfn);
429 
430 /**
431  * @brief qed_sp_pf_update_stag - Update firmware of new outer tag
432  *
433  * @param p_hwfn
434  *
435  * @return int
436  */
437 int qed_sp_pf_update_stag(struct qed_hwfn *p_hwfn);
438 
439 /**
440  * @brief qed_sp_pf_stop - PF Function Stop Ramrod
441  *
442  * This ramrod is sent to close a Physical Function (PF). It is the last ramrod
443  * sent and the last completion written to the PFs Event Ring. This ramrod also
444  * deletes the context for the Slowhwfn connection on this PF.
445  *
446  * @note Not required for first packet.
447  *
448  * @param p_hwfn
449  *
450  * @return int
451  */
452 
453 /**
454  * @brief qed_sp_pf_update_ufp - PF ufp update Ramrod
455  *
456  * @param p_hwfn
457  *
458  * @return int
459  */
460 int qed_sp_pf_update_ufp(struct qed_hwfn *p_hwfn);
461 
462 int qed_sp_pf_stop(struct qed_hwfn *p_hwfn);
463 
464 int qed_sp_pf_update_tunn_cfg(struct qed_hwfn *p_hwfn,
465 			      struct qed_ptt *p_ptt,
466 			      struct qed_tunnel_info *p_tunn,
467 			      enum spq_mode comp_mode,
468 			      struct qed_spq_comp_cb *p_comp_data);
469 /**
470  * @brief qed_sp_heartbeat_ramrod - Send empty Ramrod
471  *
472  * @param p_hwfn
473  *
474  * @return int
475  */
476 
477 int qed_sp_heartbeat_ramrod(struct qed_hwfn *p_hwfn);
478 
479 #endif
480