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.
10 #include <linux/types.h>
11 #include <linux/slab.h>
12 #include <linux/qed/qed_if.h>
19 enum protocol_type type
;
22 #define MAX_TID_BLOCKS 512
25 u32 num_tids_per_block
;
27 u8
*blocks
[MAX_TID_BLOCKS
]; /* 4K */
31 * qed_cxt_get_cid_info(): Returns the context info for a specific cidi.
33 * @p_hwfn: HW device data.
38 int qed_cxt_get_cid_info(struct qed_hwfn
*p_hwfn
,
39 struct qed_cxt_info
*p_info
);
42 * qed_cxt_get_tid_mem_info(): Returns the tid mem info.
44 * @p_hwfn: HW device data.
49 int qed_cxt_get_tid_mem_info(struct qed_hwfn
*p_hwfn
,
50 struct qed_tid_mem
*p_info
);
52 #define QED_CXT_TCP_ULP_TID_SEG PROTOCOLID_TCP_ULP
53 #define QED_CXT_ROCE_TID_SEG PROTOCOLID_ROCE
54 #define QED_CXT_FCOE_TID_SEG PROTOCOLID_FCOE
55 enum qed_cxt_elem_type
{
62 u32
qed_cxt_get_proto_cid_count(struct qed_hwfn
*p_hwfn
,
63 enum protocol_type type
, u32
*vf_cid
);
66 * qed_cxt_set_pf_params(): Set the PF params for cxt init.
68 * @p_hwfn: HW device data.
69 * @rdma_tasks: Requested maximum.
73 int qed_cxt_set_pf_params(struct qed_hwfn
*p_hwfn
, u32 rdma_tasks
);
76 * qed_cxt_cfg_ilt_compute(): Compute ILT init parameters.
78 * @p_hwfn: HW device data.
79 * @last_line: Last_line.
83 int qed_cxt_cfg_ilt_compute(struct qed_hwfn
*p_hwfn
, u32
*last_line
);
86 * qed_cxt_cfg_ilt_compute_excess(): How many lines can be decreased.
88 * @p_hwfn: HW device data.
89 * @used_lines: Used lines.
93 u32
qed_cxt_cfg_ilt_compute_excess(struct qed_hwfn
*p_hwfn
, u32 used_lines
);
96 * qed_cxt_mngr_alloc(): Allocate and init the context manager struct.
98 * @p_hwfn: HW device data.
102 int qed_cxt_mngr_alloc(struct qed_hwfn
*p_hwfn
);
105 * qed_cxt_mngr_free() - Context manager free.
107 * @p_hwfn: HW device data.
111 void qed_cxt_mngr_free(struct qed_hwfn
*p_hwfn
);
114 * qed_cxt_tables_alloc(): Allocate ILT shadow, Searcher T2, acquired map.
116 * @p_hwfn: HW device data.
120 int qed_cxt_tables_alloc(struct qed_hwfn
*p_hwfn
);
123 * qed_cxt_mngr_setup(): Reset the acquired CIDs.
125 * @p_hwfn: HW device data.
127 void qed_cxt_mngr_setup(struct qed_hwfn
*p_hwfn
);
130 * qed_cxt_hw_init_common(): Initailze ILT and DQ, common phase, per path.
132 * @p_hwfn: HW device data.
136 void qed_cxt_hw_init_common(struct qed_hwfn
*p_hwfn
);
139 * qed_cxt_hw_init_pf(): Initailze ILT and DQ, PF phase, per path.
141 * @p_hwfn: HW device data.
146 void qed_cxt_hw_init_pf(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
149 * qed_qm_init_pf(): Initailze the QM PF phase, per path.
151 * @p_hwfn: HW device data.
153 * @is_pf_loading: Is pf pending.
157 void qed_qm_init_pf(struct qed_hwfn
*p_hwfn
,
158 struct qed_ptt
*p_ptt
, bool is_pf_loading
);
161 * qed_qm_reconf(): Reconfigures QM pf on the fly.
163 * @p_hwfn: HW device data.
168 int qed_qm_reconf(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
170 #define QED_CXT_PF_CID (0xff)
173 * qed_cxt_release_cid(): Release a cid.
175 * @p_hwfn: HW device data.
180 void qed_cxt_release_cid(struct qed_hwfn
*p_hwfn
, u32 cid
);
183 * _qed_cxt_release_cid(): Release a cid belonging to a vf-queue.
185 * @p_hwfn: HW device data.
187 * @vfid: Engine relative index. QED_CXT_PF_CID if belongs to PF.
191 void _qed_cxt_release_cid(struct qed_hwfn
*p_hwfn
, u32 cid
, u8 vfid
);
194 * qed_cxt_acquire_cid(): Acquire a new cid of a specific protocol type.
196 * @p_hwfn: HW device data.
198 * @p_cid: Pointer cid.
202 int qed_cxt_acquire_cid(struct qed_hwfn
*p_hwfn
,
203 enum protocol_type type
, u32
*p_cid
);
206 * _qed_cxt_acquire_cid(): Acquire a new cid of a specific protocol type
209 * @p_hwfn: HW device data.
211 * @p_cid: Pointer cid.
212 * @vfid: Engine relative index. QED_CXT_PF_CID if belongs to PF.
216 int _qed_cxt_acquire_cid(struct qed_hwfn
*p_hwfn
,
217 enum protocol_type type
, u32
*p_cid
, u8 vfid
);
219 int qed_cxt_dynamic_ilt_alloc(struct qed_hwfn
*p_hwfn
,
220 enum qed_cxt_elem_type elem_type
, u32 iid
);
221 u32
qed_cxt_get_proto_tid_count(struct qed_hwfn
*p_hwfn
,
222 enum protocol_type type
);
223 u32
qed_cxt_get_proto_cid_start(struct qed_hwfn
*p_hwfn
,
224 enum protocol_type type
);
225 int qed_cxt_free_proto_ilt(struct qed_hwfn
*p_hwfn
, enum protocol_type proto
);
227 #define QED_CTX_WORKING_MEM 0
228 #define QED_CTX_FL_MEM 1
229 int qed_cxt_get_task_ctx(struct qed_hwfn
*p_hwfn
,
230 u32 tid
, u8 ctx_type
, void **task_ctx
);
232 /* Max number of connection types in HW (DQ/CDU etc.) */
233 #define MAX_CONN_TYPES PROTOCOLID_COMMON
234 #define NUM_TASK_TYPES 2
235 #define NUM_TASK_PF_SEGMENTS 4
236 #define NUM_TASK_VF_SEGMENTS 1
238 /* PF per protocl configuration object */
239 #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
240 #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
248 struct qed_conn_type_cfg
{
251 struct qed_tid_seg tid_seg
[TASK_SEGMENTS
];
254 /* ILT Client configuration,
255 * Per connection type (protocol) resources (cids, tis, vf cids etc.)
256 * 1 - for connection context (CDUC) and for each task context we need two
257 * values, for regular task context and for force load memory
259 #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2)
260 #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2)
263 #define CDUT_SEG_BLK(n) (1 + (u8)(n))
264 #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_ ## X ## _SEGMENTS)
266 struct ilt_cfg_pair
{
271 struct qed_ilt_cli_blk
{
272 u32 total_size
; /* 0 means not active */
273 u32 real_size_in_page
;
275 u32 dynamic_line_offset
;
276 u32 dynamic_line_cnt
;
279 struct qed_ilt_client_cfg
{
283 struct ilt_cfg_pair first
;
284 struct ilt_cfg_pair last
;
285 struct ilt_cfg_pair p_size
;
287 /* ILT client blocks for PF */
288 struct qed_ilt_cli_blk pf_blks
[ILT_CLI_PF_BLOCKS
];
291 /* ILT client blocks for VFs */
292 struct qed_ilt_cli_blk vf_blks
[ILT_CLI_VF_BLOCKS
];
296 struct qed_cid_acquired_map
{
299 unsigned long *cid_map
;
303 struct phys_mem_desc
*dma_mem
;
309 struct qed_cxt_mngr
{
310 /* Per protocl configuration */
311 struct qed_conn_type_cfg conn_cfg
[MAX_CONN_TYPES
];
313 /* computed ILT structure */
314 struct qed_ilt_client_cfg clients
[MAX_ILT_CLIENTS
];
316 /* Task type sizes */
317 u32 task_type_size
[NUM_TASK_TYPES
];
319 /* total number of VFs for this hwfn -
320 * ALL VFs are symmetric in terms of HW resources
326 struct qed_cid_acquired_map acquired
[MAX_CONN_TYPES
];
328 struct qed_cid_acquired_map
329 acquired_vf
[MAX_CONN_TYPES
][MAX_NUM_VFS
];
331 /* ILT shadow table */
332 struct phys_mem_desc
*ilt_shadow
;
336 /* Mutex for a dynamic ILT allocation */
340 struct qed_src_t2 src_t2
;
342 /* total number of SRQ's for this hwfn */
346 /* Maximal number of L2 steering filters */
349 u16 iscsi_task_pages
;
357 u16
qed_get_cdut_num_pf_init_pages(struct qed_hwfn
*p_hwfn
);
358 u16
qed_get_cdut_num_vf_init_pages(struct qed_hwfn
*p_hwfn
);
359 u16
qed_get_cdut_num_pf_work_pages(struct qed_hwfn
*p_hwfn
);
360 u16
qed_get_cdut_num_vf_work_pages(struct qed_hwfn
*p_hwfn
);
362 u32
qed_cxt_get_ilt_page_size(struct qed_hwfn
*p_hwfn
,
363 enum ilt_clients ilt_client
);
365 u32
qed_cxt_get_total_srq_count(struct qed_hwfn
*p_hwfn
);