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