WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / ethernet / qlogic / qed / qed_cxt.h
blob056e79620a0e2fc6c870f352e063c7e9158a6478
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 * Copyright (c) 2019-2020 Marvell International Ltd.
5 */
7 #ifndef _QED_CXT_H
8 #define _QED_CXT_H
10 #include <linux/types.h>
11 #include <linux/slab.h>
12 #include <linux/qed/qed_if.h>
13 #include "qed_hsi.h"
14 #include "qed.h"
16 struct qed_cxt_info {
17 void *p_cxt;
18 u32 iid;
19 enum protocol_type type;
22 #define MAX_TID_BLOCKS 512
23 struct qed_tid_mem {
24 u32 tid_size;
25 u32 num_tids_per_block;
26 u32 waste;
27 u8 *blocks[MAX_TID_BLOCKS]; /* 4K */
30 /**
31 * @brief qedo_cid_get_cxt_info - Returns the context info for a specific cid
34 * @param p_hwfn
35 * @param p_info in/out
37 * @return int
39 int qed_cxt_get_cid_info(struct qed_hwfn *p_hwfn,
40 struct qed_cxt_info *p_info);
42 /**
43 * @brief qed_cxt_get_tid_mem_info
45 * @param p_hwfn
46 * @param p_info
48 * @return int
50 int qed_cxt_get_tid_mem_info(struct qed_hwfn *p_hwfn,
51 struct qed_tid_mem *p_info);
53 #define QED_CXT_ISCSI_TID_SEG PROTOCOLID_ISCSI
54 #define QED_CXT_ROCE_TID_SEG PROTOCOLID_ROCE
55 #define QED_CXT_FCOE_TID_SEG PROTOCOLID_FCOE
56 enum qed_cxt_elem_type {
57 QED_ELEM_CXT,
58 QED_ELEM_SRQ,
59 QED_ELEM_TASK,
60 QED_ELEM_XRC_SRQ,
63 u32 qed_cxt_get_proto_cid_count(struct qed_hwfn *p_hwfn,
64 enum protocol_type type, u32 *vf_cid);
66 /**
67 * @brief qed_cxt_set_pf_params - Set the PF params for cxt init
69 * @param p_hwfn
70 * @param rdma_tasks - requested maximum
71 * @return int
73 int qed_cxt_set_pf_params(struct qed_hwfn *p_hwfn, u32 rdma_tasks);
75 /**
76 * @brief qed_cxt_cfg_ilt_compute - compute ILT init parameters
78 * @param p_hwfn
79 * @param last_line
81 * @return int
83 int qed_cxt_cfg_ilt_compute(struct qed_hwfn *p_hwfn, u32 *last_line);
85 /**
86 * @brief qed_cxt_cfg_ilt_compute_excess - how many lines can be decreased
88 * @param p_hwfn
89 * @param used_lines
91 u32 qed_cxt_cfg_ilt_compute_excess(struct qed_hwfn *p_hwfn, u32 used_lines);
93 /**
94 * @brief qed_cxt_mngr_alloc - Allocate and init the context manager struct
96 * @param p_hwfn
98 * @return int
100 int qed_cxt_mngr_alloc(struct qed_hwfn *p_hwfn);
103 * @brief qed_cxt_mngr_free
105 * @param p_hwfn
107 void qed_cxt_mngr_free(struct qed_hwfn *p_hwfn);
110 * @brief qed_cxt_tables_alloc - Allocate ILT shadow, Searcher T2, acquired map
112 * @param p_hwfn
114 * @return int
116 int qed_cxt_tables_alloc(struct qed_hwfn *p_hwfn);
119 * @brief qed_cxt_mngr_setup - Reset the acquired CIDs
121 * @param p_hwfn
123 void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn);
126 * @brief qed_cxt_hw_init_common - Initailze ILT and DQ, common phase, per path.
130 * @param p_hwfn
132 void qed_cxt_hw_init_common(struct qed_hwfn *p_hwfn);
135 * @brief qed_cxt_hw_init_pf - Initailze ILT and DQ, PF phase, per path.
137 * @param p_hwfn
138 * @param p_ptt
140 void qed_cxt_hw_init_pf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
143 * @brief qed_qm_init_pf - Initailze the QM PF phase, per path
145 * @param p_hwfn
146 * @param p_ptt
147 * @param is_pf_loading
149 void qed_qm_init_pf(struct qed_hwfn *p_hwfn,
150 struct qed_ptt *p_ptt, bool is_pf_loading);
153 * @brief Reconfigures QM pf on the fly
155 * @param p_hwfn
156 * @param p_ptt
158 * @return int
160 int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
162 #define QED_CXT_PF_CID (0xff)
165 * @brief qed_cxt_release - Release a cid
167 * @param p_hwfn
168 * @param cid
170 void qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid);
173 * @brief qed_cxt_release - Release a cid belonging to a vf-queue
175 * @param p_hwfn
176 * @param cid
177 * @param vfid - engine relative index. QED_CXT_PF_CID if belongs to PF
179 void _qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid, u8 vfid);
182 * @brief qed_cxt_acquire - Acquire a new cid of a specific protocol type
184 * @param p_hwfn
185 * @param type
186 * @param p_cid
188 * @return int
190 int qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn,
191 enum protocol_type type, u32 *p_cid);
194 * @brief _qed_cxt_acquire - Acquire a new cid of a specific protocol type
195 * for a vf-queue
197 * @param p_hwfn
198 * @param type
199 * @param p_cid
200 * @param vfid - engine relative index. QED_CXT_PF_CID if belongs to PF
202 * @return int
204 int _qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn,
205 enum protocol_type type, u32 *p_cid, u8 vfid);
207 int qed_cxt_dynamic_ilt_alloc(struct qed_hwfn *p_hwfn,
208 enum qed_cxt_elem_type elem_type, u32 iid);
209 u32 qed_cxt_get_proto_tid_count(struct qed_hwfn *p_hwfn,
210 enum protocol_type type);
211 u32 qed_cxt_get_proto_cid_start(struct qed_hwfn *p_hwfn,
212 enum protocol_type type);
213 int qed_cxt_free_proto_ilt(struct qed_hwfn *p_hwfn, enum protocol_type proto);
215 #define QED_CTX_WORKING_MEM 0
216 #define QED_CTX_FL_MEM 1
217 int qed_cxt_get_task_ctx(struct qed_hwfn *p_hwfn,
218 u32 tid, u8 ctx_type, void **task_ctx);
220 /* Max number of connection types in HW (DQ/CDU etc.) */
221 #define MAX_CONN_TYPES PROTOCOLID_COMMON
222 #define NUM_TASK_TYPES 2
223 #define NUM_TASK_PF_SEGMENTS 4
224 #define NUM_TASK_VF_SEGMENTS 1
226 /* PF per protocl configuration object */
227 #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
228 #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
230 struct qed_tid_seg {
231 u32 count;
232 u8 type;
233 bool has_fl_mem;
236 struct qed_conn_type_cfg {
237 u32 cid_count;
238 u32 cids_per_vf;
239 struct qed_tid_seg tid_seg[TASK_SEGMENTS];
242 /* ILT Client configuration,
243 * Per connection type (protocol) resources (cids, tis, vf cids etc.)
244 * 1 - for connection context (CDUC) and for each task context we need two
245 * values, for regular task context and for force load memory
247 #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2)
248 #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2)
249 #define CDUC_BLK (0)
250 #define SRQ_BLK (0)
251 #define CDUT_SEG_BLK(n) (1 + (u8)(n))
252 #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_ ## X ## _SEGMENTS)
254 struct ilt_cfg_pair {
255 u32 reg;
256 u32 val;
259 struct qed_ilt_cli_blk {
260 u32 total_size; /* 0 means not active */
261 u32 real_size_in_page;
262 u32 start_line;
263 u32 dynamic_line_offset;
264 u32 dynamic_line_cnt;
267 struct qed_ilt_client_cfg {
268 bool active;
270 /* ILT boundaries */
271 struct ilt_cfg_pair first;
272 struct ilt_cfg_pair last;
273 struct ilt_cfg_pair p_size;
275 /* ILT client blocks for PF */
276 struct qed_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS];
277 u32 pf_total_lines;
279 /* ILT client blocks for VFs */
280 struct qed_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS];
281 u32 vf_total_lines;
284 struct qed_cid_acquired_map {
285 u32 start_cid;
286 u32 max_count;
287 unsigned long *cid_map;
290 struct qed_src_t2 {
291 struct phys_mem_desc *dma_mem;
292 u32 num_pages;
293 u64 first_free;
294 u64 last_free;
297 struct qed_cxt_mngr {
298 /* Per protocl configuration */
299 struct qed_conn_type_cfg conn_cfg[MAX_CONN_TYPES];
301 /* computed ILT structure */
302 struct qed_ilt_client_cfg clients[MAX_ILT_CLIENTS];
304 /* Task type sizes */
305 u32 task_type_size[NUM_TASK_TYPES];
307 /* total number of VFs for this hwfn -
308 * ALL VFs are symmetric in terms of HW resources
310 u32 vf_count;
311 u32 first_vf_in_pf;
313 /* Acquired CIDs */
314 struct qed_cid_acquired_map acquired[MAX_CONN_TYPES];
316 struct qed_cid_acquired_map
317 acquired_vf[MAX_CONN_TYPES][MAX_NUM_VFS];
319 /* ILT shadow table */
320 struct phys_mem_desc *ilt_shadow;
321 u32 ilt_shadow_size;
322 u32 pf_start_line;
324 /* Mutex for a dynamic ILT allocation */
325 struct mutex mutex;
327 /* SRC T2 */
328 struct qed_src_t2 src_t2;
330 /* total number of SRQ's for this hwfn */
331 u32 srq_count;
332 u32 xrc_srq_count;
334 /* Maximal number of L2 steering filters */
335 u32 arfs_count;
337 u8 task_type_id;
338 u16 task_ctx_size;
339 u16 conn_ctx_size;
342 u16 qed_get_cdut_num_pf_init_pages(struct qed_hwfn *p_hwfn);
343 u16 qed_get_cdut_num_vf_init_pages(struct qed_hwfn *p_hwfn);
344 u16 qed_get_cdut_num_pf_work_pages(struct qed_hwfn *p_hwfn);
345 u16 qed_get_cdut_num_vf_work_pages(struct qed_hwfn *p_hwfn);
347 u32 qed_cxt_get_ilt_page_size(struct qed_hwfn *p_hwfn,
348 enum ilt_clients ilt_client);
350 u32 qed_cxt_get_total_srq_count(struct qed_hwfn *p_hwfn);
352 #endif