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_CXT_H
34 #define _QED_CXT_H
35 
36 #include <linux/types.h>
37 #include <linux/slab.h>
38 #include <linux/qed/qed_if.h>
39 #include "qed_hsi.h"
40 #include "qed.h"
41 
42 struct qed_cxt_info {
43 	void			*p_cxt;
44 	u32			iid;
45 	enum protocol_type	type;
46 };
47 
48 #define MAX_TID_BLOCKS                  512
49 struct qed_tid_mem {
50 	u32 tid_size;
51 	u32 num_tids_per_block;
52 	u32 waste;
53 	u8 *blocks[MAX_TID_BLOCKS];	/* 4K */
54 };
55 
56 /**
57  * @brief qedo_cid_get_cxt_info - Returns the context info for a specific cid
58  *
59  *
60  * @param p_hwfn
61  * @param p_info in/out
62  *
63  * @return int
64  */
65 int qed_cxt_get_cid_info(struct qed_hwfn *p_hwfn,
66 			 struct qed_cxt_info *p_info);
67 
68 /**
69  * @brief qed_cxt_get_tid_mem_info
70  *
71  * @param p_hwfn
72  * @param p_info
73  *
74  * @return int
75  */
76 int qed_cxt_get_tid_mem_info(struct qed_hwfn *p_hwfn,
77 			     struct qed_tid_mem *p_info);
78 
79 #define QED_CXT_ISCSI_TID_SEG	PROTOCOLID_ISCSI
80 #define QED_CXT_ROCE_TID_SEG	PROTOCOLID_ROCE
81 #define QED_CXT_FCOE_TID_SEG	PROTOCOLID_FCOE
82 enum qed_cxt_elem_type {
83 	QED_ELEM_CXT,
84 	QED_ELEM_SRQ,
85 	QED_ELEM_TASK,
86 	QED_ELEM_XRC_SRQ,
87 };
88 
89 u32 qed_cxt_get_proto_cid_count(struct qed_hwfn *p_hwfn,
90 				enum protocol_type type, u32 *vf_cid);
91 
92 /**
93  * @brief qed_cxt_set_pf_params - Set the PF params for cxt init
94  *
95  * @param p_hwfn
96  * @param rdma_tasks - requested maximum
97  * @return int
98  */
99 int qed_cxt_set_pf_params(struct qed_hwfn *p_hwfn, u32 rdma_tasks);
100 
101 /**
102  * @brief qed_cxt_cfg_ilt_compute - compute ILT init parameters
103  *
104  * @param p_hwfn
105  * @param last_line
106  *
107  * @return int
108  */
109 int qed_cxt_cfg_ilt_compute(struct qed_hwfn *p_hwfn, u32 *last_line);
110 
111 /**
112  * @brief qed_cxt_cfg_ilt_compute_excess - how many lines can be decreased
113  *
114  * @param p_hwfn
115  * @param used_lines
116  */
117 u32 qed_cxt_cfg_ilt_compute_excess(struct qed_hwfn *p_hwfn, u32 used_lines);
118 
119 /**
120  * @brief qed_cxt_mngr_alloc - Allocate and init the context manager struct
121  *
122  * @param p_hwfn
123  *
124  * @return int
125  */
126 int qed_cxt_mngr_alloc(struct qed_hwfn *p_hwfn);
127 
128 /**
129  * @brief qed_cxt_mngr_free
130  *
131  * @param p_hwfn
132  */
133 void qed_cxt_mngr_free(struct qed_hwfn *p_hwfn);
134 
135 /**
136  * @brief qed_cxt_tables_alloc - Allocate ILT shadow, Searcher T2, acquired map
137  *
138  * @param p_hwfn
139  *
140  * @return int
141  */
142 int qed_cxt_tables_alloc(struct qed_hwfn *p_hwfn);
143 
144 /**
145  * @brief qed_cxt_mngr_setup - Reset the acquired CIDs
146  *
147  * @param p_hwfn
148  */
149 void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn);
150 
151 /**
152  * @brief qed_cxt_hw_init_common - Initailze ILT and DQ, common phase, per path.
153  *
154  *
155  *
156  * @param p_hwfn
157  */
158 void qed_cxt_hw_init_common(struct qed_hwfn *p_hwfn);
159 
160 /**
161  * @brief qed_cxt_hw_init_pf - Initailze ILT and DQ, PF phase, per path.
162  *
163  * @param p_hwfn
164  * @param p_ptt
165  */
166 void qed_cxt_hw_init_pf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
167 
168 /**
169  * @brief qed_qm_init_pf - Initailze the QM PF phase, per path
170  *
171  * @param p_hwfn
172  * @param p_ptt
173  * @param is_pf_loading
174  */
175 void qed_qm_init_pf(struct qed_hwfn *p_hwfn,
176 		    struct qed_ptt *p_ptt, bool is_pf_loading);
177 
178 /**
179  * @brief Reconfigures QM pf on the fly
180  *
181  * @param p_hwfn
182  * @param p_ptt
183  *
184  * @return int
185  */
186 int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
187 
188 #define QED_CXT_PF_CID (0xff)
189 
190 /**
191  * @brief qed_cxt_release - Release a cid
192  *
193  * @param p_hwfn
194  * @param cid
195  */
196 void qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid);
197 
198 /**
199  * @brief qed_cxt_release - Release a cid belonging to a vf-queue
200  *
201  * @param p_hwfn
202  * @param cid
203  * @param vfid - engine relative index. QED_CXT_PF_CID if belongs to PF
204  */
205 void _qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid, u8 vfid);
206 
207 /**
208  * @brief qed_cxt_acquire - Acquire a new cid of a specific protocol type
209  *
210  * @param p_hwfn
211  * @param type
212  * @param p_cid
213  *
214  * @return int
215  */
216 int qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn,
217 			enum protocol_type type, u32 *p_cid);
218 
219 /**
220  * @brief _qed_cxt_acquire - Acquire a new cid of a specific protocol type
221  *                           for a vf-queue
222  *
223  * @param p_hwfn
224  * @param type
225  * @param p_cid
226  * @param vfid - engine relative index. QED_CXT_PF_CID if belongs to PF
227  *
228  * @return int
229  */
230 int _qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn,
231 			 enum protocol_type type, u32 *p_cid, u8 vfid);
232 
233 int qed_cxt_dynamic_ilt_alloc(struct qed_hwfn *p_hwfn,
234 			      enum qed_cxt_elem_type elem_type, u32 iid);
235 u32 qed_cxt_get_proto_tid_count(struct qed_hwfn *p_hwfn,
236 				enum protocol_type type);
237 u32 qed_cxt_get_proto_cid_start(struct qed_hwfn *p_hwfn,
238 				enum protocol_type type);
239 int qed_cxt_free_proto_ilt(struct qed_hwfn *p_hwfn, enum protocol_type proto);
240 
241 #define QED_CTX_WORKING_MEM 0
242 #define QED_CTX_FL_MEM 1
243 int qed_cxt_get_task_ctx(struct qed_hwfn *p_hwfn,
244 			 u32 tid, u8 ctx_type, void **task_ctx);
245 
246 /* Max number of connection types in HW (DQ/CDU etc.) */
247 #define MAX_CONN_TYPES          PROTOCOLID_COMMON
248 #define NUM_TASK_TYPES          2
249 #define NUM_TASK_PF_SEGMENTS    4
250 #define NUM_TASK_VF_SEGMENTS    1
251 
252 /* PF per protocl configuration object */
253 #define TASK_SEGMENTS   (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
254 #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
255 
256 struct qed_tid_seg {
257 	u32 count;
258 	u8 type;
259 	bool has_fl_mem;
260 };
261 
262 struct qed_conn_type_cfg {
263 	u32 cid_count;
264 	u32 cids_per_vf;
265 	struct qed_tid_seg tid_seg[TASK_SEGMENTS];
266 };
267 
268 /* ILT Client configuration,
269  * Per connection type (protocol) resources (cids, tis, vf cids etc.)
270  * 1 - for connection context (CDUC) and for each task context we need two
271  * values, for regular task context and for force load memory
272  */
273 #define ILT_CLI_PF_BLOCKS       (1 + NUM_TASK_PF_SEGMENTS * 2)
274 #define ILT_CLI_VF_BLOCKS       (1 + NUM_TASK_VF_SEGMENTS * 2)
275 #define CDUC_BLK                (0)
276 #define SRQ_BLK                 (0)
277 #define CDUT_SEG_BLK(n)         (1 + (u8)(n))
278 #define CDUT_FL_SEG_BLK(n, X)   (1 + (n) + NUM_TASK_ ## X ## _SEGMENTS)
279 
280 struct ilt_cfg_pair {
281 	u32 reg;
282 	u32 val;
283 };
284 
285 struct qed_ilt_cli_blk {
286 	u32 total_size;		/* 0 means not active */
287 	u32 real_size_in_page;
288 	u32 start_line;
289 	u32 dynamic_line_offset;
290 	u32 dynamic_line_cnt;
291 };
292 
293 struct qed_ilt_client_cfg {
294 	bool active;
295 
296 	/* ILT boundaries */
297 	struct ilt_cfg_pair first;
298 	struct ilt_cfg_pair last;
299 	struct ilt_cfg_pair p_size;
300 
301 	/* ILT client blocks for PF */
302 	struct qed_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS];
303 	u32 pf_total_lines;
304 
305 	/* ILT client blocks for VFs */
306 	struct qed_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS];
307 	u32 vf_total_lines;
308 };
309 
310 struct qed_cid_acquired_map {
311 	u32		start_cid;
312 	u32		max_count;
313 	unsigned long	*cid_map;
314 };
315 
316 struct qed_src_t2 {
317 	struct phys_mem_desc *dma_mem;
318 	u32 num_pages;
319 	u64 first_free;
320 	u64 last_free;
321 };
322 
323 struct qed_cxt_mngr {
324 	/* Per protocl configuration */
325 	struct qed_conn_type_cfg	conn_cfg[MAX_CONN_TYPES];
326 
327 	/* computed ILT structure */
328 	struct qed_ilt_client_cfg	clients[MAX_ILT_CLIENTS];
329 
330 	/* Task type sizes */
331 	u32 task_type_size[NUM_TASK_TYPES];
332 
333 	/* total number of VFs for this hwfn -
334 	 * ALL VFs are symmetric in terms of HW resources
335 	 */
336 	u32 vf_count;
337 	u32 first_vf_in_pf;
338 
339 	/* Acquired CIDs */
340 	struct qed_cid_acquired_map	acquired[MAX_CONN_TYPES];
341 
342 	struct qed_cid_acquired_map
343 	acquired_vf[MAX_CONN_TYPES][MAX_NUM_VFS];
344 
345 	/* ILT  shadow table */
346 	struct phys_mem_desc *ilt_shadow;
347 	u32 ilt_shadow_size;
348 	u32 pf_start_line;
349 
350 	/* Mutex for a dynamic ILT allocation */
351 	struct mutex mutex;
352 
353 	/* SRC T2 */
354 	struct qed_src_t2 src_t2;
355 	u32 t2_num_pages;
356 	u64 first_free;
357 	u64 last_free;
358 
359 	/* total number of SRQ's for this hwfn */
360 	u32 srq_count;
361 	u32 xrc_srq_count;
362 
363 	/* Maximal number of L2 steering filters */
364 	u32 arfs_count;
365 
366 	u8 task_type_id;
367 	u16 task_ctx_size;
368 	u16 conn_ctx_size;
369 };
370 
371 u16 qed_get_cdut_num_pf_init_pages(struct qed_hwfn *p_hwfn);
372 u16 qed_get_cdut_num_vf_init_pages(struct qed_hwfn *p_hwfn);
373 u16 qed_get_cdut_num_pf_work_pages(struct qed_hwfn *p_hwfn);
374 u16 qed_get_cdut_num_vf_work_pages(struct qed_hwfn *p_hwfn);
375 
376 u32 qed_cxt_get_ilt_page_size(struct qed_hwfn *p_hwfn,
377 			      enum ilt_clients ilt_client);
378 
379 u32 qed_cxt_get_total_srq_count(struct qed_hwfn *p_hwfn);
380 
381 #endif
382