| 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 |
*/ |
| 6 |
|
| 7 |
#include <linux/types.h> |
| 8 |
#include <linux/bitops.h> |
| 9 |
#include <linux/dma-mapping.h> |
| 10 |
#include <linux/errno.h> |
| 11 |
#include <linux/kernel.h> |
| 12 |
#include <linux/list.h> |
| 13 |
#include <linux/log2.h> |
| 14 |
#include <linux/pci.h> |
| 15 |
#include <linux/slab.h> |
| 16 |
#include <linux/string.h> |
| 17 |
#include "qed.h" |
| 18 |
#include "qed_cxt.h" |
| 19 |
#include "qed_dev_api.h" |
| 20 |
#include "qed_hsi.h" |
| 21 |
#include "qed_hw.h" |
| 22 |
#include "qed_init_ops.h" |
| 23 |
#include "qed_rdma.h" |
| 24 |
#include "qed_reg_addr.h" |
| 25 |
#include "qed_sriov.h" |
| 26 |
|
| 27 |
/* QM constants */ |
| 28 |
#define QM_PQ_ELEMENT_SIZE 4 /* in bytes */ |
| 29 |
|
| 30 |
/* Doorbell-Queue constants */ |
| 31 |
#define DQ_RANGE_SHIFT 4 |
| 32 |
#define DQ_RANGE_ALIGN BIT(DQ_RANGE_SHIFT) |
| 33 |
|
| 34 |
/* Searcher constants */ |
| 35 |
#define SRC_MIN_NUM_ELEMS 256 |
| 36 |
|
| 37 |
/* Timers constants */ |
| 38 |
#define TM_SHIFT 7 |
| 39 |
#define TM_ALIGN BIT(TM_SHIFT) |
| 40 |
#define TM_ELEM_SIZE 4 |
| 41 |
|
| 42 |
#define ILT_DEFAULT_HW_P_SIZE 4 |
| 43 |
|
| 44 |
#define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12)) |
| 45 |
#define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET |
| 46 |
|
| 47 |
/* ILT entry structure */ |
| 48 |
#define ILT_ENTRY_PHY_ADDR_MASK (~0ULL >> 12) |
| 49 |
#define ILT_ENTRY_PHY_ADDR_SHIFT 0 |
| 50 |
#define ILT_ENTRY_VALID_MASK 0x1ULL |
| 51 |
#define ILT_ENTRY_VALID_SHIFT 52 |
| 52 |
#define ILT_ENTRY_IN_REGS 2 |
| 53 |
#define ILT_REG_SIZE_IN_BYTES 4 |
| 54 |
|
| 55 |
/* connection context union */ |
| 56 |
union conn_context { |
| 57 |
struct core_conn_context core_ctx; |
| 58 |
struct eth_conn_context eth_ctx; |
| 59 |
struct iscsi_conn_context iscsi_ctx; |
| 60 |
struct fcoe_conn_context fcoe_ctx; |
| 61 |
struct roce_conn_context roce_ctx; |
| 62 |
}; |
| 63 |
|
| 64 |
/* TYPE-0 task context - iSCSI, FCOE */ |
| 65 |
union type0_task_context { |
| 66 |
struct iscsi_task_context iscsi_ctx; |
| 67 |
struct fcoe_task_context fcoe_ctx; |
| 68 |
}; |
| 69 |
|
| 70 |
/* TYPE-1 task context - ROCE */ |
| 71 |
union type1_task_context { |
| 72 |
struct rdma_task_context roce_ctx; |
| 73 |
}; |
| 74 |
|
| 75 |
struct src_ent { |
| 76 |
__u8 opaque[56]; |
| 77 |
__be64 next; |
| 78 |
}; |
| 79 |
|
| 80 |
#define CDUT_SEG_ALIGNMET 3 /* in 4k chunks */ |
| 81 |
#define CDUT_SEG_ALIGNMET_IN_BYTES BIT(CDUT_SEG_ALIGNMET + 12) |
| 82 |
|
| 83 |
#define CONN_CXT_SIZE(p_hwfn) \ |
| 84 |
ALIGNED_TYPE_SIZE(union conn_context, p_hwfn) |
| 85 |
|
| 86 |
#define SRQ_CXT_SIZE (sizeof(struct rdma_srq_context)) |
| 87 |
#define XRC_SRQ_CXT_SIZE (sizeof(struct rdma_xrc_srq_context)) |
| 88 |
|
| 89 |
#define TYPE0_TASK_CXT_SIZE(p_hwfn) \ |
| 90 |
ALIGNED_TYPE_SIZE(union type0_task_context, p_hwfn) |
| 91 |
|
| 92 |
/* Alignment is inherent to the type1_task_context structure */ |
| 93 |
#define TYPE1_TASK_CXT_SIZE(p_hwfn) sizeof(union type1_task_context) |
| 94 |
|
| 95 |
static bool src_proto(enum protocol_type type) |
| 96 |
{ |
| 97 |
return type == PROTOCOLID_TCP_ULP || |
| 98 |
type == PROTOCOLID_FCOE || |
| 99 |
type == PROTOCOLID_IWARP; |
| 100 |
} |
| 101 |
|
| 102 |
static bool tm_cid_proto(enum protocol_type type) |
| 103 |
{ |
| 104 |
return type == PROTOCOLID_TCP_ULP || |
| 105 |
type == PROTOCOLID_FCOE || |
| 106 |
type == PROTOCOLID_ROCE || |
| 107 |
type == PROTOCOLID_IWARP; |
| 108 |
} |
| 109 |
|
| 110 |
static bool tm_tid_proto(enum protocol_type type) |
| 111 |
{ |
| 112 |
return type == PROTOCOLID_FCOE; |
| 113 |
} |
| 114 |
|
| 115 |
/* counts the iids for the CDU/CDUC ILT client configuration */ |
| 116 |
struct qed_cdu_iids { |
| 117 |
u32 pf_cids; |
| 118 |
u32 per_vf_cids; |
| 119 |
}; |
| 120 |
|
| 121 |
static void qed_cxt_cdu_iids(struct qed_cxt_mngr *p_mngr, |
| 122 |
struct qed_cdu_iids *iids) |
| 123 |
{ |
| 124 |
u32 type; |
| 125 |
|
| 126 |
for (type = 0; type < MAX_CONN_TYPES; type++) { |
| 127 |
iids->pf_cids += p_mngr->conn_cfg[type].cid_count; |
| 128 |
iids->per_vf_cids += p_mngr->conn_cfg[type].cids_per_vf; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/* counts the iids for the Searcher block configuration */ |
| 133 |
struct qed_src_iids { |
| 134 |
u32 pf_cids; |
| 135 |
u32 per_vf_cids; |
| 136 |
}; |
| 137 |
|
| 138 |
static void qed_cxt_src_iids(struct qed_cxt_mngr *p_mngr, |
| 139 |
struct qed_src_iids *iids) |
| 140 |
{ |
| 141 |
u32 i; |
| 142 |
|
| 143 |
for (i = 0; i < MAX_CONN_TYPES; i++) { |
| 144 |
if (!src_proto(i)) |
| 145 |
continue; |
| 146 |
|
| 147 |
iids->pf_cids += p_mngr->conn_cfg[i].cid_count; |
| 148 |
iids->per_vf_cids += p_mngr->conn_cfg[i].cids_per_vf; |
| 149 |
} |
| 150 |
|
| 151 |
/* Add L2 filtering filters in addition */ |
| 152 |
iids->pf_cids += p_mngr->arfs_count; |
| 153 |
} |
| 154 |
|
| 155 |
/* counts the iids for the Timers block configuration */ |
| 156 |
struct qed_tm_iids { |
| 157 |
u32 pf_cids; |
| 158 |
u32 pf_tids[NUM_TASK_PF_SEGMENTS]; /* per segment */ |
| 159 |
u32 pf_tids_total; |
| 160 |
u32 per_vf_cids; |
| 161 |
u32 per_vf_tids; |
| 162 |
}; |
| 163 |
|
| 164 |
static void qed_cxt_tm_iids(struct qed_hwfn *p_hwfn, |
| 165 |
struct qed_cxt_mngr *p_mngr, |
| 166 |
struct qed_tm_iids *iids) |
| 167 |
{ |
| 168 |
bool tm_vf_required = false; |
| 169 |
bool tm_required = false; |
| 170 |
int i, j; |
| 171 |
|
| 172 |
/* Timers is a special case -> we don't count how many cids require |
| 173 |
* timers but what's the max cid that will be used by the timer block. |
| 174 |
* therefore we traverse in reverse order, and once we hit a protocol |
| 175 |
* that requires the timers memory, we'll sum all the protocols up |
| 176 |
* to that one. |
| 177 |
*/ |
| 178 |
for (i = MAX_CONN_TYPES - 1; i >= 0; i--) { |
| 179 |
struct qed_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[i]; |
| 180 |
|
| 181 |
if (tm_cid_proto(i) || tm_required) { |
| 182 |
if (p_cfg->cid_count) |
| 183 |
tm_required = true; |
| 184 |
|
| 185 |
iids->pf_cids += p_cfg->cid_count; |
| 186 |
} |
| 187 |
|
| 188 |
if (tm_cid_proto(i) || tm_vf_required) { |
| 189 |
if (p_cfg->cids_per_vf) |
| 190 |
tm_vf_required = true; |
| 191 |
|
| 192 |
iids->per_vf_cids += p_cfg->cids_per_vf; |
| 193 |
} |
| 194 |
|
| 195 |
if (tm_tid_proto(i)) { |
| 196 |
struct qed_tid_seg *segs = p_cfg->tid_seg; |
| 197 |
|
| 198 |
/* for each segment there is at most one |
| 199 |
* protocol for which count is not 0. |
| 200 |
*/ |
| 201 |
for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++) |
| 202 |
iids->pf_tids[j] += segs[j].count; |
| 203 |
|
| 204 |
/* The last array elelment is for the VFs. As for PF |
| 205 |
* segments there can be only one protocol for |
| 206 |
* which this value is not 0. |
| 207 |
*/ |
| 208 |
iids->per_vf_tids += segs[NUM_TASK_PF_SEGMENTS].count; |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
iids->pf_cids = roundup(iids->pf_cids, TM_ALIGN); |
| 213 |
iids->per_vf_cids = roundup(iids->per_vf_cids, TM_ALIGN); |
| 214 |
iids->per_vf_tids = roundup(iids->per_vf_tids, TM_ALIGN); |
| 215 |
|
| 216 |
for (iids->pf_tids_total = 0, j = 0; j < NUM_TASK_PF_SEGMENTS; j++) { |
| 217 |
iids->pf_tids[j] = roundup(iids->pf_tids[j], TM_ALIGN); |
| 218 |
iids->pf_tids_total += iids->pf_tids[j]; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
static void qed_cxt_qm_iids(struct qed_hwfn *p_hwfn, |
| 223 |
struct qed_qm_iids *iids) |
| 224 |
{ |
| 225 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 226 |
struct qed_tid_seg *segs; |
| 227 |
u32 vf_cids = 0, type, j; |
| 228 |
u32 vf_tids = 0; |
| 229 |
|
| 230 |
for (type = 0; type < MAX_CONN_TYPES; type++) { |
| 231 |
iids->cids += p_mngr->conn_cfg[type].cid_count; |
| 232 |
vf_cids += p_mngr->conn_cfg[type].cids_per_vf; |
| 233 |
|
| 234 |
segs = p_mngr->conn_cfg[type].tid_seg; |
| 235 |
/* for each segment there is at most one |
| 236 |
* protocol for which count is not 0. |
| 237 |
*/ |
| 238 |
for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++) |
| 239 |
iids->tids += segs[j].count; |
| 240 |
|
| 241 |
/* The last array elelment is for the VFs. As for PF |
| 242 |
* segments there can be only one protocol for |
| 243 |
* which this value is not 0. |
| 244 |
*/ |
| 245 |
vf_tids += segs[NUM_TASK_PF_SEGMENTS].count; |
| 246 |
} |
| 247 |
|
| 248 |
iids->vf_cids = vf_cids; |
| 249 |
iids->tids += vf_tids * p_mngr->vf_count; |
| 250 |
|
| 251 |
DP_VERBOSE(p_hwfn, QED_MSG_ILT, |
| 252 |
"iids: CIDS %08x vf_cids %08x tids %08x vf_tids %08x\n", |
| 253 |
iids->cids, iids->vf_cids, iids->tids, vf_tids); |
| 254 |
} |
| 255 |
|
| 256 |
static struct qed_tid_seg *qed_cxt_tid_seg_info(struct qed_hwfn *p_hwfn, |
| 257 |
u32 seg) |
| 258 |
{ |
| 259 |
struct qed_cxt_mngr *p_cfg = p_hwfn->p_cxt_mngr; |
| 260 |
u32 i; |
| 261 |
|
| 262 |
/* Find the protocol with tid count > 0 for this segment. |
| 263 |
* Note: there can only be one and this is already validated. |
| 264 |
*/ |
| 265 |
for (i = 0; i < MAX_CONN_TYPES; i++) |
| 266 |
if (p_cfg->conn_cfg[i].tid_seg[seg].count) |
| 267 |
return &p_cfg->conn_cfg[i].tid_seg[seg]; |
| 268 |
return NULL; |
| 269 |
} |
| 270 |
|
| 271 |
static void qed_cxt_set_srq_count(struct qed_hwfn *p_hwfn, |
| 272 |
u32 num_srqs, u32 num_xrc_srqs) |
| 273 |
{ |
| 274 |
struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; |
| 275 |
|
| 276 |
p_mgr->srq_count = num_srqs; |
| 277 |
p_mgr->xrc_srq_count = num_xrc_srqs; |
| 278 |
} |
| 279 |
|
| 280 |
u32 qed_cxt_get_ilt_page_size(struct qed_hwfn *p_hwfn, |
| 281 |
enum ilt_clients ilt_client) |
| 282 |
{ |
| 283 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 284 |
struct qed_ilt_client_cfg *p_cli = &p_mngr->clients[ilt_client]; |
| 285 |
|
| 286 |
return ILT_PAGE_IN_BYTES(p_cli->p_size.val); |
| 287 |
} |
| 288 |
|
| 289 |
static u32 qed_cxt_xrc_srqs_per_page(struct qed_hwfn *p_hwfn) |
| 290 |
{ |
| 291 |
u32 page_size; |
| 292 |
|
| 293 |
page_size = qed_cxt_get_ilt_page_size(p_hwfn, ILT_CLI_TSDM); |
| 294 |
return page_size / XRC_SRQ_CXT_SIZE; |
| 295 |
} |
| 296 |
|
| 297 |
u32 qed_cxt_get_total_srq_count(struct qed_hwfn *p_hwfn) |
| 298 |
{ |
| 299 |
struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; |
| 300 |
u32 total_srqs; |
| 301 |
|
| 302 |
total_srqs = p_mgr->srq_count + p_mgr->xrc_srq_count; |
| 303 |
|
| 304 |
return total_srqs; |
| 305 |
} |
| 306 |
|
| 307 |
/* set the iids count per protocol */ |
| 308 |
static void qed_cxt_set_proto_cid_count(struct qed_hwfn *p_hwfn, |
| 309 |
enum protocol_type type, |
| 310 |
u32 cid_count, u32 vf_cid_cnt) |
| 311 |
{ |
| 312 |
struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; |
| 313 |
struct qed_conn_type_cfg *p_conn = &p_mgr->conn_cfg[type]; |
| 314 |
|
| 315 |
p_conn->cid_count = roundup(cid_count, DQ_RANGE_ALIGN); |
| 316 |
p_conn->cids_per_vf = roundup(vf_cid_cnt, DQ_RANGE_ALIGN); |
| 317 |
|
| 318 |
if (type == PROTOCOLID_ROCE) { |
| 319 |
u32 page_sz = p_mgr->clients[ILT_CLI_CDUC].p_size.val; |
| 320 |
u32 cxt_size = CONN_CXT_SIZE(p_hwfn); |
| 321 |
u32 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; |
| 322 |
u32 align = elems_per_page * DQ_RANGE_ALIGN; |
| 323 |
|
| 324 |
p_conn->cid_count = roundup(p_conn->cid_count, align); |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
u32 qed_cxt_get_proto_cid_count(struct qed_hwfn *p_hwfn, |
| 329 |
enum protocol_type type, u32 *vf_cid) |
| 330 |
{ |
| 331 |
if (vf_cid) |
| 332 |
*vf_cid = p_hwfn->p_cxt_mngr->conn_cfg[type].cids_per_vf; |
| 333 |
|
| 334 |
return p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count; |
| 335 |
} |
| 336 |
|
| 337 |
u32 qed_cxt_get_proto_cid_start(struct qed_hwfn *p_hwfn, |
| 338 |
enum protocol_type type) |
| 339 |
{ |
| 340 |
return p_hwfn->p_cxt_mngr->acquired[type].start_cid; |
| 341 |
} |
| 342 |
|
| 343 |
u32 qed_cxt_get_proto_tid_count(struct qed_hwfn *p_hwfn, |
| 344 |
enum protocol_type type) |
| 345 |
{ |
| 346 |
u32 cnt = 0; |
| 347 |
int i; |
| 348 |
|
| 349 |
for (i = 0; i < TASK_SEGMENTS; i++) |
| 350 |
cnt += p_hwfn->p_cxt_mngr->conn_cfg[type].tid_seg[i].count; |
| 351 |
|
| 352 |
return cnt; |
| 353 |
} |
| 354 |
|
| 355 |
static void qed_cxt_set_proto_tid_count(struct qed_hwfn *p_hwfn, |
| 356 |
enum protocol_type proto, |
| 357 |
u8 seg, |
| 358 |
u8 seg_type, u32 count, bool has_fl) |
| 359 |
{ |
| 360 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 361 |
struct qed_tid_seg *p_seg = &p_mngr->conn_cfg[proto].tid_seg[seg]; |
| 362 |
|
| 363 |
p_seg->count = count; |
| 364 |
p_seg->has_fl_mem = has_fl; |
| 365 |
p_seg->type = seg_type; |
| 366 |
} |
| 367 |
|
| 368 |
static void qed_ilt_cli_blk_fill(struct qed_ilt_client_cfg *p_cli, |
| 369 |
struct qed_ilt_cli_blk *p_blk, |
| 370 |
u32 start_line, u32 total_size, u32 elem_size) |
| 371 |
{ |
| 372 |
u32 ilt_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val); |
| 373 |
|
| 374 |
/* verify thatits called only once for each block */ |
| 375 |
if (p_blk->total_size) |
| 376 |
return; |
| 377 |
|
| 378 |
p_blk->total_size = total_size; |
| 379 |
p_blk->real_size_in_page = 0; |
| 380 |
if (elem_size) |
| 381 |
p_blk->real_size_in_page = (ilt_size / elem_size) * elem_size; |
| 382 |
p_blk->start_line = start_line; |
| 383 |
} |
| 384 |
|
| 385 |
static void qed_ilt_cli_adv_line(struct qed_hwfn *p_hwfn, |
| 386 |
struct qed_ilt_client_cfg *p_cli, |
| 387 |
struct qed_ilt_cli_blk *p_blk, |
| 388 |
u32 *p_line, enum ilt_clients client_id) |
| 389 |
{ |
| 390 |
if (!p_blk->total_size) |
| 391 |
return; |
| 392 |
|
| 393 |
if (!p_cli->active) |
| 394 |
p_cli->first.val = *p_line; |
| 395 |
|
| 396 |
p_cli->active = true; |
| 397 |
*p_line += DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page); |
| 398 |
p_cli->last.val = *p_line - 1; |
| 399 |
|
| 400 |
DP_VERBOSE(p_hwfn, QED_MSG_ILT, |
| 401 |
"ILT[Client %d] - Lines: [%08x - %08x]. Block - Size %08x [Real %08x] Start line %d\n", |
| 402 |
client_id, p_cli->first.val, |
| 403 |
p_cli->last.val, p_blk->total_size, |
| 404 |
p_blk->real_size_in_page, p_blk->start_line); |
| 405 |
} |
| 406 |
|
| 407 |
static u32 qed_ilt_get_dynamic_line_cnt(struct qed_hwfn *p_hwfn, |
| 408 |
enum ilt_clients ilt_client) |
| 409 |
{ |
| 410 |
u32 cid_count = p_hwfn->p_cxt_mngr->conn_cfg[PROTOCOLID_ROCE].cid_count; |
| 411 |
struct qed_ilt_client_cfg *p_cli; |
| 412 |
u32 lines_to_skip = 0; |
| 413 |
u32 cxts_per_p; |
| 414 |
|
| 415 |
if (ilt_client == ILT_CLI_CDUC) { |
| 416 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; |
| 417 |
|
| 418 |
cxts_per_p = ILT_PAGE_IN_BYTES(p_cli->p_size.val) / |
| 419 |
(u32) CONN_CXT_SIZE(p_hwfn); |
| 420 |
|
| 421 |
lines_to_skip = cid_count / cxts_per_p; |
| 422 |
} |
| 423 |
|
| 424 |
return lines_to_skip; |
| 425 |
} |
| 426 |
|
| 427 |
static struct qed_ilt_client_cfg *qed_cxt_set_cli(struct qed_ilt_client_cfg |
| 428 |
*p_cli) |
| 429 |
{ |
| 430 |
p_cli->active = false; |
| 431 |
p_cli->first.val = 0; |
| 432 |
p_cli->last.val = 0; |
| 433 |
return p_cli; |
| 434 |
} |
| 435 |
|
| 436 |
static struct qed_ilt_cli_blk *qed_cxt_set_blk(struct qed_ilt_cli_blk *p_blk) |
| 437 |
{ |
| 438 |
p_blk->total_size = 0; |
| 439 |
return p_blk; |
| 440 |
} |
| 441 |
|
| 442 |
static void qed_cxt_ilt_blk_reset(struct qed_hwfn *p_hwfn) |
| 443 |
{ |
| 444 |
struct qed_ilt_client_cfg *clients = p_hwfn->p_cxt_mngr->clients; |
| 445 |
u32 cli_idx, blk_idx; |
| 446 |
|
| 447 |
for (cli_idx = 0; cli_idx < MAX_ILT_CLIENTS; cli_idx++) { |
| 448 |
for (blk_idx = 0; blk_idx < ILT_CLI_PF_BLOCKS; blk_idx++) |
| 449 |
clients[cli_idx].pf_blks[blk_idx].total_size = 0; |
| 450 |
|
| 451 |
for (blk_idx = 0; blk_idx < ILT_CLI_VF_BLOCKS; blk_idx++) |
| 452 |
clients[cli_idx].vf_blks[blk_idx].total_size = 0; |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
int qed_cxt_cfg_ilt_compute(struct qed_hwfn *p_hwfn, u32 *line_count) |
| 457 |
{ |
| 458 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 459 |
u32 curr_line, total, i, task_size, line; |
| 460 |
struct qed_ilt_client_cfg *p_cli; |
| 461 |
struct qed_ilt_cli_blk *p_blk; |
| 462 |
struct qed_cdu_iids cdu_iids; |
| 463 |
struct qed_src_iids src_iids; |
| 464 |
struct qed_qm_iids qm_iids; |
| 465 |
struct qed_tm_iids tm_iids; |
| 466 |
struct qed_tid_seg *p_seg; |
| 467 |
|
| 468 |
memset(&qm_iids, 0, sizeof(qm_iids)); |
| 469 |
memset(&cdu_iids, 0, sizeof(cdu_iids)); |
| 470 |
memset(&src_iids, 0, sizeof(src_iids)); |
| 471 |
memset(&tm_iids, 0, sizeof(tm_iids)); |
| 472 |
|
| 473 |
p_mngr->pf_start_line = RESC_START(p_hwfn, QED_ILT); |
| 474 |
|
| 475 |
/* Reset all ILT blocks at the beginning of ILT computing in order |
| 476 |
* to prevent memory allocation for irrelevant blocks afterwards. |
| 477 |
*/ |
| 478 |
qed_cxt_ilt_blk_reset(p_hwfn); |
| 479 |
|
| 480 |
DP_VERBOSE(p_hwfn, QED_MSG_ILT, |
| 481 |
"hwfn [%d] - Set context manager starting line to be 0x%08x\n", |
| 482 |
p_hwfn->my_id, p_hwfn->p_cxt_mngr->pf_start_line); |
| 483 |
|
| 484 |
/* CDUC */ |
| 485 |
p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUC]); |
| 486 |
|
| 487 |
curr_line = p_mngr->pf_start_line; |
| 488 |
|
| 489 |
/* CDUC PF */ |
| 490 |
p_cli->pf_total_lines = 0; |
| 491 |
|
| 492 |
/* get the counters for the CDUC and QM clients */ |
| 493 |
qed_cxt_cdu_iids(p_mngr, &cdu_iids); |
| 494 |
|
| 495 |
p_blk = qed_cxt_set_blk(&p_cli->pf_blks[CDUC_BLK]); |
| 496 |
|
| 497 |
total = cdu_iids.pf_cids * CONN_CXT_SIZE(p_hwfn); |
| 498 |
|
| 499 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, |
| 500 |
total, CONN_CXT_SIZE(p_hwfn)); |
| 501 |
|
| 502 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC); |
| 503 |
p_cli->pf_total_lines = curr_line - p_blk->start_line; |
| 504 |
|
| 505 |
p_blk->dynamic_line_cnt = qed_ilt_get_dynamic_line_cnt(p_hwfn, |
| 506 |
ILT_CLI_CDUC); |
| 507 |
|
| 508 |
/* CDUC VF */ |
| 509 |
p_blk = qed_cxt_set_blk(&p_cli->vf_blks[CDUC_BLK]); |
| 510 |
total = cdu_iids.per_vf_cids * CONN_CXT_SIZE(p_hwfn); |
| 511 |
|
| 512 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, |
| 513 |
total, CONN_CXT_SIZE(p_hwfn)); |
| 514 |
|
| 515 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC); |
| 516 |
p_cli->vf_total_lines = curr_line - p_blk->start_line; |
| 517 |
|
| 518 |
for (i = 1; i < p_mngr->vf_count; i++) |
| 519 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 520 |
ILT_CLI_CDUC); |
| 521 |
|
| 522 |
/* CDUT PF */ |
| 523 |
p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUT]); |
| 524 |
p_cli->first.val = curr_line; |
| 525 |
|
| 526 |
/* first the 'working' task memory */ |
| 527 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 528 |
p_seg = qed_cxt_tid_seg_info(p_hwfn, i); |
| 529 |
if (!p_seg || p_seg->count == 0) |
| 530 |
continue; |
| 531 |
|
| 532 |
p_blk = qed_cxt_set_blk(&p_cli->pf_blks[CDUT_SEG_BLK(i)]); |
| 533 |
total = p_seg->count * p_mngr->task_type_size[p_seg->type]; |
| 534 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total, |
| 535 |
p_mngr->task_type_size[p_seg->type]); |
| 536 |
|
| 537 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 538 |
ILT_CLI_CDUT); |
| 539 |
} |
| 540 |
|
| 541 |
/* next the 'init' task memory (forced load memory) */ |
| 542 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 543 |
p_seg = qed_cxt_tid_seg_info(p_hwfn, i); |
| 544 |
if (!p_seg || p_seg->count == 0) |
| 545 |
continue; |
| 546 |
|
| 547 |
p_blk = |
| 548 |
qed_cxt_set_blk(&p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)]); |
| 549 |
|
| 550 |
if (!p_seg->has_fl_mem) { |
| 551 |
/* The segment is active (total size pf 'working' |
| 552 |
* memory is > 0) but has no FL (forced-load, Init) |
| 553 |
* memory. Thus: |
| 554 |
* |
| 555 |
* 1. The total-size in the corrsponding FL block of |
| 556 |
* the ILT client is set to 0 - No ILT line are |
| 557 |
* provisioned and no ILT memory allocated. |
| 558 |
* |
| 559 |
* 2. The start-line of said block is set to the |
| 560 |
* start line of the matching working memory |
| 561 |
* block in the ILT client. This is later used to |
| 562 |
* configure the CDU segment offset registers and |
| 563 |
* results in an FL command for TIDs of this |
| 564 |
* segement behaves as regular load commands |
| 565 |
* (loading TIDs from the working memory). |
| 566 |
*/ |
| 567 |
line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line; |
| 568 |
|
| 569 |
qed_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0); |
| 570 |
continue; |
| 571 |
} |
| 572 |
total = p_seg->count * p_mngr->task_type_size[p_seg->type]; |
| 573 |
|
| 574 |
qed_ilt_cli_blk_fill(p_cli, p_blk, |
| 575 |
curr_line, total, |
| 576 |
p_mngr->task_type_size[p_seg->type]); |
| 577 |
|
| 578 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 579 |
ILT_CLI_CDUT); |
| 580 |
} |
| 581 |
p_cli->pf_total_lines = curr_line - p_cli->pf_blks[0].start_line; |
| 582 |
|
| 583 |
/* CDUT VF */ |
| 584 |
p_seg = qed_cxt_tid_seg_info(p_hwfn, TASK_SEGMENT_VF); |
| 585 |
if (p_seg && p_seg->count) { |
| 586 |
/* Stricly speaking we need to iterate over all VF |
| 587 |
* task segment types, but a VF has only 1 segment |
| 588 |
*/ |
| 589 |
|
| 590 |
/* 'working' memory */ |
| 591 |
total = p_seg->count * p_mngr->task_type_size[p_seg->type]; |
| 592 |
|
| 593 |
p_blk = qed_cxt_set_blk(&p_cli->vf_blks[CDUT_SEG_BLK(0)]); |
| 594 |
qed_ilt_cli_blk_fill(p_cli, p_blk, |
| 595 |
curr_line, total, |
| 596 |
p_mngr->task_type_size[p_seg->type]); |
| 597 |
|
| 598 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 599 |
ILT_CLI_CDUT); |
| 600 |
|
| 601 |
/* 'init' memory */ |
| 602 |
p_blk = |
| 603 |
qed_cxt_set_blk(&p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)]); |
| 604 |
if (!p_seg->has_fl_mem) { |
| 605 |
/* see comment above */ |
| 606 |
line = p_cli->vf_blks[CDUT_SEG_BLK(0)].start_line; |
| 607 |
qed_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0); |
| 608 |
} else { |
| 609 |
task_size = p_mngr->task_type_size[p_seg->type]; |
| 610 |
qed_ilt_cli_blk_fill(p_cli, p_blk, |
| 611 |
curr_line, total, task_size); |
| 612 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 613 |
ILT_CLI_CDUT); |
| 614 |
} |
| 615 |
p_cli->vf_total_lines = curr_line - |
| 616 |
p_cli->vf_blks[0].start_line; |
| 617 |
|
| 618 |
/* Now for the rest of the VFs */ |
| 619 |
for (i = 1; i < p_mngr->vf_count; i++) { |
| 620 |
p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)]; |
| 621 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 622 |
ILT_CLI_CDUT); |
| 623 |
|
| 624 |
p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)]; |
| 625 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 626 |
ILT_CLI_CDUT); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
/* QM */ |
| 631 |
p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_QM]); |
| 632 |
p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]); |
| 633 |
|
| 634 |
qed_cxt_qm_iids(p_hwfn, &qm_iids); |
| 635 |
total = qed_qm_pf_mem_size(qm_iids.cids, |
| 636 |
qm_iids.vf_cids, qm_iids.tids, |
| 637 |
p_hwfn->qm_info.num_pqs, |
| 638 |
p_hwfn->qm_info.num_vf_pqs); |
| 639 |
|
| 640 |
DP_VERBOSE(p_hwfn, |
| 641 |
QED_MSG_ILT, |
| 642 |
"QM ILT Info, (cids=%d, vf_cids=%d, tids=%d, num_pqs=%d, num_vf_pqs=%d, memory_size=%d)\n", |
| 643 |
qm_iids.cids, |
| 644 |
qm_iids.vf_cids, |
| 645 |
qm_iids.tids, |
| 646 |
p_hwfn->qm_info.num_pqs, p_hwfn->qm_info.num_vf_pqs, total); |
| 647 |
|
| 648 |
qed_ilt_cli_blk_fill(p_cli, p_blk, |
| 649 |
curr_line, total * 0x1000, |
| 650 |
QM_PQ_ELEMENT_SIZE); |
| 651 |
|
| 652 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_QM); |
| 653 |
p_cli->pf_total_lines = curr_line - p_blk->start_line; |
| 654 |
|
| 655 |
/* SRC */ |
| 656 |
p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_SRC]); |
| 657 |
qed_cxt_src_iids(p_mngr, &src_iids); |
| 658 |
|
| 659 |
/* Both the PF and VFs searcher connections are stored in the per PF |
| 660 |
* database. Thus sum the PF searcher cids and all the VFs searcher |
| 661 |
* cids. |
| 662 |
*/ |
| 663 |
total = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count; |
| 664 |
if (total) { |
| 665 |
u32 local_max = max_t(u32, total, |
| 666 |
SRC_MIN_NUM_ELEMS); |
| 667 |
|
| 668 |
total = roundup_pow_of_two(local_max); |
| 669 |
|
| 670 |
p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]); |
| 671 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, |
| 672 |
total * sizeof(struct src_ent), |
| 673 |
sizeof(struct src_ent)); |
| 674 |
|
| 675 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 676 |
ILT_CLI_SRC); |
| 677 |
p_cli->pf_total_lines = curr_line - p_blk->start_line; |
| 678 |
} |
| 679 |
|
| 680 |
/* TM PF */ |
| 681 |
p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_TM]); |
| 682 |
qed_cxt_tm_iids(p_hwfn, p_mngr, &tm_iids); |
| 683 |
total = tm_iids.pf_cids + tm_iids.pf_tids_total; |
| 684 |
if (total) { |
| 685 |
p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]); |
| 686 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, |
| 687 |
total * TM_ELEM_SIZE, TM_ELEM_SIZE); |
| 688 |
|
| 689 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 690 |
ILT_CLI_TM); |
| 691 |
p_cli->pf_total_lines = curr_line - p_blk->start_line; |
| 692 |
} |
| 693 |
|
| 694 |
/* TM VF */ |
| 695 |
total = tm_iids.per_vf_cids + tm_iids.per_vf_tids; |
| 696 |
if (total) { |
| 697 |
p_blk = qed_cxt_set_blk(&p_cli->vf_blks[0]); |
| 698 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, |
| 699 |
total * TM_ELEM_SIZE, TM_ELEM_SIZE); |
| 700 |
|
| 701 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 702 |
ILT_CLI_TM); |
| 703 |
|
| 704 |
p_cli->vf_total_lines = curr_line - p_blk->start_line; |
| 705 |
for (i = 1; i < p_mngr->vf_count; i++) |
| 706 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 707 |
ILT_CLI_TM); |
| 708 |
} |
| 709 |
|
| 710 |
/* TSDM (SRQ CONTEXT) */ |
| 711 |
total = qed_cxt_get_total_srq_count(p_hwfn); |
| 712 |
|
| 713 |
if (total) { |
| 714 |
p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_TSDM]); |
| 715 |
p_blk = qed_cxt_set_blk(&p_cli->pf_blks[SRQ_BLK]); |
| 716 |
qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, |
| 717 |
total * SRQ_CXT_SIZE, SRQ_CXT_SIZE); |
| 718 |
|
| 719 |
qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, |
| 720 |
ILT_CLI_TSDM); |
| 721 |
p_cli->pf_total_lines = curr_line - p_blk->start_line; |
| 722 |
} |
| 723 |
|
| 724 |
*line_count = curr_line - p_hwfn->p_cxt_mngr->pf_start_line; |
| 725 |
|
| 726 |
if (curr_line - p_hwfn->p_cxt_mngr->pf_start_line > |
| 727 |
RESC_NUM(p_hwfn, QED_ILT)) |
| 728 |
return -EINVAL; |
| 729 |
|
| 730 |
return 0; |
| 731 |
} |
| 732 |
|
| 733 |
u32 qed_cxt_cfg_ilt_compute_excess(struct qed_hwfn *p_hwfn, u32 used_lines) |
| 734 |
{ |
| 735 |
struct qed_ilt_client_cfg *p_cli; |
| 736 |
u32 excess_lines, available_lines; |
| 737 |
struct qed_cxt_mngr *p_mngr; |
| 738 |
u32 ilt_page_size, elem_size; |
| 739 |
struct qed_tid_seg *p_seg; |
| 740 |
int i; |
| 741 |
|
| 742 |
available_lines = RESC_NUM(p_hwfn, QED_ILT); |
| 743 |
excess_lines = used_lines - available_lines; |
| 744 |
|
| 745 |
if (!excess_lines) |
| 746 |
return 0; |
| 747 |
|
| 748 |
if (!QED_IS_RDMA_PERSONALITY(p_hwfn)) |
| 749 |
return 0; |
| 750 |
|
| 751 |
p_mngr = p_hwfn->p_cxt_mngr; |
| 752 |
p_cli = &p_mngr->clients[ILT_CLI_CDUT]; |
| 753 |
ilt_page_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val); |
| 754 |
|
| 755 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 756 |
p_seg = qed_cxt_tid_seg_info(p_hwfn, i); |
| 757 |
if (!p_seg || p_seg->count == 0) |
| 758 |
continue; |
| 759 |
|
| 760 |
elem_size = p_mngr->task_type_size[p_seg->type]; |
| 761 |
if (!elem_size) |
| 762 |
continue; |
| 763 |
|
| 764 |
return (ilt_page_size / elem_size) * excess_lines; |
| 765 |
} |
| 766 |
|
| 767 |
DP_NOTICE(p_hwfn, "failed computing excess ILT lines\n"); |
| 768 |
return 0; |
| 769 |
} |
| 770 |
|
| 771 |
static void qed_cxt_src_t2_free(struct qed_hwfn *p_hwfn) |
| 772 |
{ |
| 773 |
struct qed_src_t2 *p_t2 = &p_hwfn->p_cxt_mngr->src_t2; |
| 774 |
u32 i; |
| 775 |
|
| 776 |
if (!p_t2 || !p_t2->dma_mem) |
| 777 |
return; |
| 778 |
|
| 779 |
for (i = 0; i < p_t2->num_pages; i++) |
| 780 |
if (p_t2->dma_mem[i].virt_addr) |
| 781 |
dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 782 |
p_t2->dma_mem[i].size, |
| 783 |
p_t2->dma_mem[i].virt_addr, |
| 784 |
p_t2->dma_mem[i].phys_addr); |
| 785 |
|
| 786 |
kfree(p_t2->dma_mem); |
| 787 |
p_t2->dma_mem = NULL; |
| 788 |
} |
| 789 |
|
| 790 |
static int |
| 791 |
qed_cxt_t2_alloc_pages(struct qed_hwfn *p_hwfn, |
| 792 |
struct qed_src_t2 *p_t2, u32 total_size, u32 page_size) |
| 793 |
{ |
| 794 |
void **p_virt; |
| 795 |
u32 size, i; |
| 796 |
|
| 797 |
if (!p_t2 || !p_t2->dma_mem) |
| 798 |
return -EINVAL; |
| 799 |
|
| 800 |
for (i = 0; i < p_t2->num_pages; i++) { |
| 801 |
size = min_t(u32, total_size, page_size); |
| 802 |
p_virt = &p_t2->dma_mem[i].virt_addr; |
| 803 |
|
| 804 |
*p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 805 |
size, |
| 806 |
&p_t2->dma_mem[i].phys_addr, |
| 807 |
GFP_KERNEL); |
| 808 |
if (!p_t2->dma_mem[i].virt_addr) |
| 809 |
return -ENOMEM; |
| 810 |
|
| 811 |
memset(*p_virt, 0, size); |
| 812 |
p_t2->dma_mem[i].size = size; |
| 813 |
total_size -= size; |
| 814 |
} |
| 815 |
|
| 816 |
return 0; |
| 817 |
} |
| 818 |
|
| 819 |
static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn) |
| 820 |
{ |
| 821 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 822 |
u32 conn_num, total_size, ent_per_page, psz, i; |
| 823 |
struct phys_mem_desc *p_t2_last_page; |
| 824 |
struct qed_ilt_client_cfg *p_src; |
| 825 |
struct qed_src_iids src_iids; |
| 826 |
struct qed_src_t2 *p_t2; |
| 827 |
int rc; |
| 828 |
|
| 829 |
memset(&src_iids, 0, sizeof(src_iids)); |
| 830 |
|
| 831 |
/* if the SRC ILT client is inactive - there are no connection |
| 832 |
* requiring the searcer, leave. |
| 833 |
*/ |
| 834 |
p_src = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_SRC]; |
| 835 |
if (!p_src->active) |
| 836 |
return 0; |
| 837 |
|
| 838 |
qed_cxt_src_iids(p_mngr, &src_iids); |
| 839 |
conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count; |
| 840 |
total_size = conn_num * sizeof(struct src_ent); |
| 841 |
|
| 842 |
/* use the same page size as the SRC ILT client */ |
| 843 |
psz = ILT_PAGE_IN_BYTES(p_src->p_size.val); |
| 844 |
p_t2 = &p_mngr->src_t2; |
| 845 |
p_t2->num_pages = DIV_ROUND_UP(total_size, psz); |
| 846 |
|
| 847 |
/* allocate t2 */ |
| 848 |
p_t2->dma_mem = kzalloc_objs(struct phys_mem_desc, p_t2->num_pages); |
| 849 |
if (!p_t2->dma_mem) { |
| 850 |
DP_NOTICE(p_hwfn, "Failed to allocate t2 table\n"); |
| 851 |
rc = -ENOMEM; |
| 852 |
goto t2_fail; |
| 853 |
} |
| 854 |
|
| 855 |
rc = qed_cxt_t2_alloc_pages(p_hwfn, p_t2, total_size, psz); |
| 856 |
if (rc) |
| 857 |
goto t2_fail; |
| 858 |
|
| 859 |
/* Set the t2 pointers */ |
| 860 |
|
| 861 |
/* entries per page - must be a power of two */ |
| 862 |
ent_per_page = psz / sizeof(struct src_ent); |
| 863 |
|
| 864 |
p_t2->first_free = (u64)p_t2->dma_mem[0].phys_addr; |
| 865 |
|
| 866 |
p_t2_last_page = &p_t2->dma_mem[(conn_num - 1) / ent_per_page]; |
| 867 |
p_t2->last_free = (u64)p_t2_last_page->phys_addr + |
| 868 |
((conn_num - 1) & (ent_per_page - 1)) * sizeof(struct src_ent); |
| 869 |
|
| 870 |
for (i = 0; i < p_t2->num_pages; i++) { |
| 871 |
u32 ent_num = min_t(u32, |
| 872 |
ent_per_page, |
| 873 |
conn_num); |
| 874 |
struct src_ent *entries = p_t2->dma_mem[i].virt_addr; |
| 875 |
u64 p_ent_phys = (u64)p_t2->dma_mem[i].phys_addr, val; |
| 876 |
u32 j; |
| 877 |
|
| 878 |
for (j = 0; j < ent_num - 1; j++) { |
| 879 |
val = p_ent_phys + (j + 1) * sizeof(struct src_ent); |
| 880 |
entries[j].next = cpu_to_be64(val); |
| 881 |
} |
| 882 |
|
| 883 |
if (i < p_t2->num_pages - 1) |
| 884 |
val = (u64)p_t2->dma_mem[i + 1].phys_addr; |
| 885 |
else |
| 886 |
val = 0; |
| 887 |
entries[j].next = cpu_to_be64(val); |
| 888 |
|
| 889 |
conn_num -= ent_num; |
| 890 |
} |
| 891 |
|
| 892 |
return 0; |
| 893 |
|
| 894 |
t2_fail: |
| 895 |
qed_cxt_src_t2_free(p_hwfn); |
| 896 |
return rc; |
| 897 |
} |
| 898 |
|
| 899 |
#define for_each_ilt_valid_client(pos, clients) \ |
| 900 |
for (pos = 0; pos < MAX_ILT_CLIENTS; pos++) \ |
| 901 |
if (!clients[pos].active) { \ |
| 902 |
continue; \ |
| 903 |
} else \ |
| 904 |
|
| 905 |
/* Total number of ILT lines used by this PF */ |
| 906 |
static u32 qed_cxt_ilt_shadow_size(struct qed_ilt_client_cfg *ilt_clients) |
| 907 |
{ |
| 908 |
u32 size = 0; |
| 909 |
u32 i; |
| 910 |
|
| 911 |
for_each_ilt_valid_client(i, ilt_clients) |
| 912 |
size += (ilt_clients[i].last.val - ilt_clients[i].first.val + 1); |
| 913 |
|
| 914 |
return size; |
| 915 |
} |
| 916 |
|
| 917 |
static void qed_ilt_shadow_free(struct qed_hwfn *p_hwfn) |
| 918 |
{ |
| 919 |
struct qed_ilt_client_cfg *p_cli = p_hwfn->p_cxt_mngr->clients; |
| 920 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 921 |
u32 ilt_size, i; |
| 922 |
|
| 923 |
ilt_size = qed_cxt_ilt_shadow_size(p_cli); |
| 924 |
|
| 925 |
for (i = 0; p_mngr->ilt_shadow && i < ilt_size; i++) { |
| 926 |
struct phys_mem_desc *p_dma = &p_mngr->ilt_shadow[i]; |
| 927 |
|
| 928 |
if (p_dma->virt_addr) |
| 929 |
dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 930 |
p_dma->size, p_dma->virt_addr, |
| 931 |
p_dma->phys_addr); |
| 932 |
p_dma->virt_addr = NULL; |
| 933 |
} |
| 934 |
kfree(p_mngr->ilt_shadow); |
| 935 |
p_mngr->ilt_shadow = NULL; |
| 936 |
} |
| 937 |
|
| 938 |
static int qed_ilt_blk_alloc(struct qed_hwfn *p_hwfn, |
| 939 |
struct qed_ilt_cli_blk *p_blk, |
| 940 |
enum ilt_clients ilt_client, |
| 941 |
u32 start_line_offset) |
| 942 |
{ |
| 943 |
struct phys_mem_desc *ilt_shadow = p_hwfn->p_cxt_mngr->ilt_shadow; |
| 944 |
u32 lines, line, sz_left, lines_to_skip = 0; |
| 945 |
|
| 946 |
/* Special handling for RoCE that supports dynamic allocation */ |
| 947 |
if (QED_IS_RDMA_PERSONALITY(p_hwfn) && |
| 948 |
((ilt_client == ILT_CLI_CDUT) || ilt_client == ILT_CLI_TSDM)) |
| 949 |
return 0; |
| 950 |
|
| 951 |
lines_to_skip = p_blk->dynamic_line_cnt; |
| 952 |
|
| 953 |
if (!p_blk->total_size) |
| 954 |
return 0; |
| 955 |
|
| 956 |
sz_left = p_blk->total_size; |
| 957 |
lines = DIV_ROUND_UP(sz_left, p_blk->real_size_in_page) - lines_to_skip; |
| 958 |
line = p_blk->start_line + start_line_offset - |
| 959 |
p_hwfn->p_cxt_mngr->pf_start_line + lines_to_skip; |
| 960 |
|
| 961 |
for (; lines; lines--) { |
| 962 |
dma_addr_t p_phys; |
| 963 |
void *p_virt; |
| 964 |
u32 size; |
| 965 |
|
| 966 |
size = min_t(u32, sz_left, p_blk->real_size_in_page); |
| 967 |
p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, size, |
| 968 |
&p_phys, GFP_KERNEL); |
| 969 |
if (!p_virt) |
| 970 |
return -ENOMEM; |
| 971 |
|
| 972 |
ilt_shadow[line].phys_addr = p_phys; |
| 973 |
ilt_shadow[line].virt_addr = p_virt; |
| 974 |
ilt_shadow[line].size = size; |
| 975 |
|
| 976 |
DP_VERBOSE(p_hwfn, QED_MSG_ILT, |
| 977 |
"ILT shadow: Line [%d] Physical 0x%llx Virtual %p Size %d\n", |
| 978 |
line, (u64)p_phys, p_virt, size); |
| 979 |
|
| 980 |
sz_left -= size; |
| 981 |
line++; |
| 982 |
} |
| 983 |
|
| 984 |
return 0; |
| 985 |
} |
| 986 |
|
| 987 |
static int qed_ilt_shadow_alloc(struct qed_hwfn *p_hwfn) |
| 988 |
{ |
| 989 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 990 |
struct qed_ilt_client_cfg *clients = p_mngr->clients; |
| 991 |
struct qed_ilt_cli_blk *p_blk; |
| 992 |
u32 size, i, j, k; |
| 993 |
int rc; |
| 994 |
|
| 995 |
size = qed_cxt_ilt_shadow_size(clients); |
| 996 |
p_mngr->ilt_shadow = kzalloc_objs(struct phys_mem_desc, size); |
| 997 |
if (!p_mngr->ilt_shadow) { |
| 998 |
rc = -ENOMEM; |
| 999 |
goto ilt_shadow_fail; |
| 1000 |
} |
| 1001 |
|
| 1002 |
DP_VERBOSE(p_hwfn, QED_MSG_ILT, |
| 1003 |
"Allocated 0x%x bytes for ilt shadow\n", |
| 1004 |
(u32)(size * sizeof(struct phys_mem_desc))); |
| 1005 |
|
| 1006 |
for_each_ilt_valid_client(i, clients) { |
| 1007 |
for (j = 0; j < ILT_CLI_PF_BLOCKS; j++) { |
| 1008 |
p_blk = &clients[i].pf_blks[j]; |
| 1009 |
rc = qed_ilt_blk_alloc(p_hwfn, p_blk, i, 0); |
| 1010 |
if (rc) |
| 1011 |
goto ilt_shadow_fail; |
| 1012 |
} |
| 1013 |
for (k = 0; k < p_mngr->vf_count; k++) { |
| 1014 |
for (j = 0; j < ILT_CLI_VF_BLOCKS; j++) { |
| 1015 |
u32 lines = clients[i].vf_total_lines * k; |
| 1016 |
|
| 1017 |
p_blk = &clients[i].vf_blks[j]; |
| 1018 |
rc = qed_ilt_blk_alloc(p_hwfn, p_blk, i, lines); |
| 1019 |
if (rc) |
| 1020 |
goto ilt_shadow_fail; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
|
| 1025 |
return 0; |
| 1026 |
|
| 1027 |
ilt_shadow_fail: |
| 1028 |
qed_ilt_shadow_free(p_hwfn); |
| 1029 |
return rc; |
| 1030 |
} |
| 1031 |
|
| 1032 |
static void qed_cid_map_free(struct qed_hwfn *p_hwfn) |
| 1033 |
{ |
| 1034 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1035 |
u32 type, vf; |
| 1036 |
|
| 1037 |
for (type = 0; type < MAX_CONN_TYPES; type++) { |
| 1038 |
bitmap_free(p_mngr->acquired[type].cid_map); |
| 1039 |
p_mngr->acquired[type].max_count = 0; |
| 1040 |
p_mngr->acquired[type].start_cid = 0; |
| 1041 |
|
| 1042 |
for (vf = 0; vf < MAX_NUM_VFS; vf++) { |
| 1043 |
bitmap_free(p_mngr->acquired_vf[type][vf].cid_map); |
| 1044 |
p_mngr->acquired_vf[type][vf].max_count = 0; |
| 1045 |
p_mngr->acquired_vf[type][vf].start_cid = 0; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
static int |
| 1051 |
qed_cid_map_alloc_single(struct qed_hwfn *p_hwfn, |
| 1052 |
u32 type, |
| 1053 |
u32 cid_start, |
| 1054 |
u32 cid_count, struct qed_cid_acquired_map *p_map) |
| 1055 |
{ |
| 1056 |
if (!cid_count) |
| 1057 |
return 0; |
| 1058 |
|
| 1059 |
p_map->cid_map = bitmap_zalloc(cid_count, GFP_KERNEL); |
| 1060 |
if (!p_map->cid_map) |
| 1061 |
return -ENOMEM; |
| 1062 |
|
| 1063 |
p_map->max_count = cid_count; |
| 1064 |
p_map->start_cid = cid_start; |
| 1065 |
|
| 1066 |
DP_VERBOSE(p_hwfn, QED_MSG_CXT, |
| 1067 |
"Type %08x start: %08x count %08x\n", |
| 1068 |
type, p_map->start_cid, p_map->max_count); |
| 1069 |
|
| 1070 |
return 0; |
| 1071 |
} |
| 1072 |
|
| 1073 |
static int qed_cid_map_alloc(struct qed_hwfn *p_hwfn) |
| 1074 |
{ |
| 1075 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1076 |
u32 start_cid = 0, vf_start_cid = 0; |
| 1077 |
u32 type, vf; |
| 1078 |
|
| 1079 |
for (type = 0; type < MAX_CONN_TYPES; type++) { |
| 1080 |
struct qed_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[type]; |
| 1081 |
struct qed_cid_acquired_map *p_map; |
| 1082 |
|
| 1083 |
/* Handle PF maps */ |
| 1084 |
p_map = &p_mngr->acquired[type]; |
| 1085 |
if (qed_cid_map_alloc_single(p_hwfn, type, start_cid, |
| 1086 |
p_cfg->cid_count, p_map)) |
| 1087 |
goto cid_map_fail; |
| 1088 |
|
| 1089 |
/* Handle VF maps */ |
| 1090 |
for (vf = 0; vf < MAX_NUM_VFS; vf++) { |
| 1091 |
p_map = &p_mngr->acquired_vf[type][vf]; |
| 1092 |
if (qed_cid_map_alloc_single(p_hwfn, type, |
| 1093 |
vf_start_cid, |
| 1094 |
p_cfg->cids_per_vf, p_map)) |
| 1095 |
goto cid_map_fail; |
| 1096 |
} |
| 1097 |
|
| 1098 |
start_cid += p_cfg->cid_count; |
| 1099 |
vf_start_cid += p_cfg->cids_per_vf; |
| 1100 |
} |
| 1101 |
|
| 1102 |
return 0; |
| 1103 |
|
| 1104 |
cid_map_fail: |
| 1105 |
qed_cid_map_free(p_hwfn); |
| 1106 |
return -ENOMEM; |
| 1107 |
} |
| 1108 |
|
| 1109 |
int qed_cxt_mngr_alloc(struct qed_hwfn *p_hwfn) |
| 1110 |
{ |
| 1111 |
struct qed_ilt_client_cfg *clients; |
| 1112 |
struct qed_cxt_mngr *p_mngr; |
| 1113 |
u32 i; |
| 1114 |
|
| 1115 |
p_mngr = kzalloc_obj(*p_mngr); |
| 1116 |
if (!p_mngr) |
| 1117 |
return -ENOMEM; |
| 1118 |
|
| 1119 |
/* Initialize ILT client registers */ |
| 1120 |
clients = p_mngr->clients; |
| 1121 |
clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT); |
| 1122 |
clients[ILT_CLI_CDUC].last.reg = ILT_CFG_REG(CDUC, LAST_ILT); |
| 1123 |
clients[ILT_CLI_CDUC].p_size.reg = ILT_CFG_REG(CDUC, P_SIZE); |
| 1124 |
|
| 1125 |
clients[ILT_CLI_QM].first.reg = ILT_CFG_REG(QM, FIRST_ILT); |
| 1126 |
clients[ILT_CLI_QM].last.reg = ILT_CFG_REG(QM, LAST_ILT); |
| 1127 |
clients[ILT_CLI_QM].p_size.reg = ILT_CFG_REG(QM, P_SIZE); |
| 1128 |
|
| 1129 |
clients[ILT_CLI_TM].first.reg = ILT_CFG_REG(TM, FIRST_ILT); |
| 1130 |
clients[ILT_CLI_TM].last.reg = ILT_CFG_REG(TM, LAST_ILT); |
| 1131 |
clients[ILT_CLI_TM].p_size.reg = ILT_CFG_REG(TM, P_SIZE); |
| 1132 |
|
| 1133 |
clients[ILT_CLI_SRC].first.reg = ILT_CFG_REG(SRC, FIRST_ILT); |
| 1134 |
clients[ILT_CLI_SRC].last.reg = ILT_CFG_REG(SRC, LAST_ILT); |
| 1135 |
clients[ILT_CLI_SRC].p_size.reg = ILT_CFG_REG(SRC, P_SIZE); |
| 1136 |
|
| 1137 |
clients[ILT_CLI_CDUT].first.reg = ILT_CFG_REG(CDUT, FIRST_ILT); |
| 1138 |
clients[ILT_CLI_CDUT].last.reg = ILT_CFG_REG(CDUT, LAST_ILT); |
| 1139 |
clients[ILT_CLI_CDUT].p_size.reg = ILT_CFG_REG(CDUT, P_SIZE); |
| 1140 |
|
| 1141 |
clients[ILT_CLI_TSDM].first.reg = ILT_CFG_REG(TSDM, FIRST_ILT); |
| 1142 |
clients[ILT_CLI_TSDM].last.reg = ILT_CFG_REG(TSDM, LAST_ILT); |
| 1143 |
clients[ILT_CLI_TSDM].p_size.reg = ILT_CFG_REG(TSDM, P_SIZE); |
| 1144 |
/* default ILT page size for all clients is 64K */ |
| 1145 |
for (i = 0; i < MAX_ILT_CLIENTS; i++) |
| 1146 |
p_mngr->clients[i].p_size.val = ILT_DEFAULT_HW_P_SIZE; |
| 1147 |
|
| 1148 |
p_mngr->conn_ctx_size = CONN_CXT_SIZE(p_hwfn); |
| 1149 |
|
| 1150 |
/* Initialize task sizes */ |
| 1151 |
p_mngr->task_type_size[0] = TYPE0_TASK_CXT_SIZE(p_hwfn); |
| 1152 |
p_mngr->task_type_size[1] = TYPE1_TASK_CXT_SIZE(p_hwfn); |
| 1153 |
|
| 1154 |
if (p_hwfn->cdev->p_iov_info) { |
| 1155 |
p_mngr->vf_count = p_hwfn->cdev->p_iov_info->total_vfs; |
| 1156 |
p_mngr->first_vf_in_pf = |
| 1157 |
p_hwfn->cdev->p_iov_info->first_vf_in_pf; |
| 1158 |
} |
| 1159 |
/* Initialize the dynamic ILT allocation mutex */ |
| 1160 |
mutex_init(&p_mngr->mutex); |
| 1161 |
|
| 1162 |
/* Set the cxt mangr pointer priori to further allocations */ |
| 1163 |
p_hwfn->p_cxt_mngr = p_mngr; |
| 1164 |
|
| 1165 |
return 0; |
| 1166 |
} |
| 1167 |
|
| 1168 |
int qed_cxt_tables_alloc(struct qed_hwfn *p_hwfn) |
| 1169 |
{ |
| 1170 |
int rc; |
| 1171 |
|
| 1172 |
/* Allocate the ILT shadow table */ |
| 1173 |
rc = qed_ilt_shadow_alloc(p_hwfn); |
| 1174 |
if (rc) |
| 1175 |
goto tables_alloc_fail; |
| 1176 |
|
| 1177 |
/* Allocate the T2 table */ |
| 1178 |
rc = qed_cxt_src_t2_alloc(p_hwfn); |
| 1179 |
if (rc) |
| 1180 |
goto tables_alloc_fail; |
| 1181 |
|
| 1182 |
/* Allocate and initialize the acquired cids bitmaps */ |
| 1183 |
rc = qed_cid_map_alloc(p_hwfn); |
| 1184 |
if (rc) |
| 1185 |
goto tables_alloc_fail; |
| 1186 |
|
| 1187 |
return 0; |
| 1188 |
|
| 1189 |
tables_alloc_fail: |
| 1190 |
qed_cxt_mngr_free(p_hwfn); |
| 1191 |
return rc; |
| 1192 |
} |
| 1193 |
|
| 1194 |
void qed_cxt_mngr_free(struct qed_hwfn *p_hwfn) |
| 1195 |
{ |
| 1196 |
if (!p_hwfn->p_cxt_mngr) |
| 1197 |
return; |
| 1198 |
|
| 1199 |
qed_cid_map_free(p_hwfn); |
| 1200 |
qed_cxt_src_t2_free(p_hwfn); |
| 1201 |
qed_ilt_shadow_free(p_hwfn); |
| 1202 |
kfree(p_hwfn->p_cxt_mngr); |
| 1203 |
|
| 1204 |
p_hwfn->p_cxt_mngr = NULL; |
| 1205 |
} |
| 1206 |
|
| 1207 |
void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn) |
| 1208 |
{ |
| 1209 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1210 |
struct qed_cid_acquired_map *p_map; |
| 1211 |
struct qed_conn_type_cfg *p_cfg; |
| 1212 |
int type; |
| 1213 |
|
| 1214 |
/* Reset acquired cids */ |
| 1215 |
for (type = 0; type < MAX_CONN_TYPES; type++) { |
| 1216 |
u32 vf; |
| 1217 |
|
| 1218 |
p_cfg = &p_mngr->conn_cfg[type]; |
| 1219 |
if (p_cfg->cid_count) { |
| 1220 |
p_map = &p_mngr->acquired[type]; |
| 1221 |
bitmap_zero(p_map->cid_map, p_map->max_count); |
| 1222 |
} |
| 1223 |
|
| 1224 |
if (!p_cfg->cids_per_vf) |
| 1225 |
continue; |
| 1226 |
|
| 1227 |
for (vf = 0; vf < MAX_NUM_VFS; vf++) { |
| 1228 |
p_map = &p_mngr->acquired_vf[type][vf]; |
| 1229 |
bitmap_zero(p_map->cid_map, p_map->max_count); |
| 1230 |
} |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
/* CDU Common */ |
| 1235 |
#define CDUC_CXT_SIZE_SHIFT \ |
| 1236 |
CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE_SHIFT |
| 1237 |
|
| 1238 |
#define CDUC_CXT_SIZE_MASK \ |
| 1239 |
(CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE >> CDUC_CXT_SIZE_SHIFT) |
| 1240 |
|
| 1241 |
#define CDUC_BLOCK_WASTE_SHIFT \ |
| 1242 |
CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE_SHIFT |
| 1243 |
|
| 1244 |
#define CDUC_BLOCK_WASTE_MASK \ |
| 1245 |
(CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE >> CDUC_BLOCK_WASTE_SHIFT) |
| 1246 |
|
| 1247 |
#define CDUC_NCIB_SHIFT \ |
| 1248 |
CDU_REG_CID_ADDR_PARAMS_NCIB_SHIFT |
| 1249 |
|
| 1250 |
#define CDUC_NCIB_MASK \ |
| 1251 |
(CDU_REG_CID_ADDR_PARAMS_NCIB >> CDUC_NCIB_SHIFT) |
| 1252 |
|
| 1253 |
#define CDUT_TYPE0_CXT_SIZE_SHIFT \ |
| 1254 |
CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE_SHIFT |
| 1255 |
|
| 1256 |
#define CDUT_TYPE0_CXT_SIZE_MASK \ |
| 1257 |
(CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE >> \ |
| 1258 |
CDUT_TYPE0_CXT_SIZE_SHIFT) |
| 1259 |
|
| 1260 |
#define CDUT_TYPE0_BLOCK_WASTE_SHIFT \ |
| 1261 |
CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE_SHIFT |
| 1262 |
|
| 1263 |
#define CDUT_TYPE0_BLOCK_WASTE_MASK \ |
| 1264 |
(CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE >> \ |
| 1265 |
CDUT_TYPE0_BLOCK_WASTE_SHIFT) |
| 1266 |
|
| 1267 |
#define CDUT_TYPE0_NCIB_SHIFT \ |
| 1268 |
CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK_SHIFT |
| 1269 |
|
| 1270 |
#define CDUT_TYPE0_NCIB_MASK \ |
| 1271 |
(CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK >> \ |
| 1272 |
CDUT_TYPE0_NCIB_SHIFT) |
| 1273 |
|
| 1274 |
#define CDUT_TYPE1_CXT_SIZE_SHIFT \ |
| 1275 |
CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE_SHIFT |
| 1276 |
|
| 1277 |
#define CDUT_TYPE1_CXT_SIZE_MASK \ |
| 1278 |
(CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE >> \ |
| 1279 |
CDUT_TYPE1_CXT_SIZE_SHIFT) |
| 1280 |
|
| 1281 |
#define CDUT_TYPE1_BLOCK_WASTE_SHIFT \ |
| 1282 |
CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE_SHIFT |
| 1283 |
|
| 1284 |
#define CDUT_TYPE1_BLOCK_WASTE_MASK \ |
| 1285 |
(CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE >> \ |
| 1286 |
CDUT_TYPE1_BLOCK_WASTE_SHIFT) |
| 1287 |
|
| 1288 |
#define CDUT_TYPE1_NCIB_SHIFT \ |
| 1289 |
CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK_SHIFT |
| 1290 |
|
| 1291 |
#define CDUT_TYPE1_NCIB_MASK \ |
| 1292 |
(CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK >> \ |
| 1293 |
CDUT_TYPE1_NCIB_SHIFT) |
| 1294 |
|
| 1295 |
static void qed_cdu_init_common(struct qed_hwfn *p_hwfn) |
| 1296 |
{ |
| 1297 |
u32 page_sz, elems_per_page, block_waste, cxt_size, cdu_params = 0; |
| 1298 |
|
| 1299 |
/* CDUC - connection configuration */ |
| 1300 |
page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val; |
| 1301 |
cxt_size = CONN_CXT_SIZE(p_hwfn); |
| 1302 |
elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; |
| 1303 |
block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size; |
| 1304 |
|
| 1305 |
SET_FIELD(cdu_params, CDUC_CXT_SIZE, cxt_size); |
| 1306 |
SET_FIELD(cdu_params, CDUC_BLOCK_WASTE, block_waste); |
| 1307 |
SET_FIELD(cdu_params, CDUC_NCIB, elems_per_page); |
| 1308 |
STORE_RT_REG(p_hwfn, CDU_REG_CID_ADDR_PARAMS_RT_OFFSET, cdu_params); |
| 1309 |
|
| 1310 |
/* CDUT - type-0 tasks configuration */ |
| 1311 |
page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT].p_size.val; |
| 1312 |
cxt_size = p_hwfn->p_cxt_mngr->task_type_size[0]; |
| 1313 |
elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; |
| 1314 |
block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size; |
| 1315 |
|
| 1316 |
/* cxt size and block-waste are multipes of 8 */ |
| 1317 |
cdu_params = 0; |
| 1318 |
SET_FIELD(cdu_params, CDUT_TYPE0_CXT_SIZE, (cxt_size >> 3)); |
| 1319 |
SET_FIELD(cdu_params, CDUT_TYPE0_BLOCK_WASTE, (block_waste >> 3)); |
| 1320 |
SET_FIELD(cdu_params, CDUT_TYPE0_NCIB, elems_per_page); |
| 1321 |
STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT0_PARAMS_RT_OFFSET, cdu_params); |
| 1322 |
|
| 1323 |
/* CDUT - type-1 tasks configuration */ |
| 1324 |
cxt_size = p_hwfn->p_cxt_mngr->task_type_size[1]; |
| 1325 |
elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; |
| 1326 |
block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size; |
| 1327 |
|
| 1328 |
/* cxt size and block-waste are multipes of 8 */ |
| 1329 |
cdu_params = 0; |
| 1330 |
SET_FIELD(cdu_params, CDUT_TYPE1_CXT_SIZE, (cxt_size >> 3)); |
| 1331 |
SET_FIELD(cdu_params, CDUT_TYPE1_BLOCK_WASTE, (block_waste >> 3)); |
| 1332 |
SET_FIELD(cdu_params, CDUT_TYPE1_NCIB, elems_per_page); |
| 1333 |
STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT1_PARAMS_RT_OFFSET, cdu_params); |
| 1334 |
} |
| 1335 |
|
| 1336 |
/* CDU PF */ |
| 1337 |
#define CDU_SEG_REG_TYPE_SHIFT CDU_SEG_TYPE_OFFSET_REG_TYPE_SHIFT |
| 1338 |
#define CDU_SEG_REG_TYPE_MASK 0x1 |
| 1339 |
#define CDU_SEG_REG_OFFSET_SHIFT 0 |
| 1340 |
#define CDU_SEG_REG_OFFSET_MASK CDU_SEG_TYPE_OFFSET_REG_OFFSET_MASK |
| 1341 |
|
| 1342 |
static void qed_cdu_init_pf(struct qed_hwfn *p_hwfn) |
| 1343 |
{ |
| 1344 |
struct qed_ilt_client_cfg *p_cli; |
| 1345 |
struct qed_tid_seg *p_seg; |
| 1346 |
u32 cdu_seg_params, offset; |
| 1347 |
int i; |
| 1348 |
|
| 1349 |
static const u32 rt_type_offset_arr[] = { |
| 1350 |
CDU_REG_PF_SEG0_TYPE_OFFSET_RT_OFFSET, |
| 1351 |
CDU_REG_PF_SEG1_TYPE_OFFSET_RT_OFFSET, |
| 1352 |
CDU_REG_PF_SEG2_TYPE_OFFSET_RT_OFFSET, |
| 1353 |
CDU_REG_PF_SEG3_TYPE_OFFSET_RT_OFFSET |
| 1354 |
}; |
| 1355 |
|
| 1356 |
static const u32 rt_type_offset_fl_arr[] = { |
| 1357 |
CDU_REG_PF_FL_SEG0_TYPE_OFFSET_RT_OFFSET, |
| 1358 |
CDU_REG_PF_FL_SEG1_TYPE_OFFSET_RT_OFFSET, |
| 1359 |
CDU_REG_PF_FL_SEG2_TYPE_OFFSET_RT_OFFSET, |
| 1360 |
CDU_REG_PF_FL_SEG3_TYPE_OFFSET_RT_OFFSET |
| 1361 |
}; |
| 1362 |
|
| 1363 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 1364 |
|
| 1365 |
/* There are initializations only for CDUT during pf Phase */ |
| 1366 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 1367 |
/* Segment 0 */ |
| 1368 |
p_seg = qed_cxt_tid_seg_info(p_hwfn, i); |
| 1369 |
if (!p_seg) |
| 1370 |
continue; |
| 1371 |
|
| 1372 |
/* Note: start_line is already adjusted for the CDU |
| 1373 |
* segment register granularity, so we just need to |
| 1374 |
* divide. Adjustment is implicit as we assume ILT |
| 1375 |
* Page size is larger than 32K! |
| 1376 |
*/ |
| 1377 |
offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) * |
| 1378 |
(p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line - |
| 1379 |
p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES; |
| 1380 |
|
| 1381 |
cdu_seg_params = 0; |
| 1382 |
SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type); |
| 1383 |
SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset); |
| 1384 |
STORE_RT_REG(p_hwfn, rt_type_offset_arr[i], cdu_seg_params); |
| 1385 |
|
| 1386 |
offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) * |
| 1387 |
(p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)].start_line - |
| 1388 |
p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES; |
| 1389 |
|
| 1390 |
cdu_seg_params = 0; |
| 1391 |
SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type); |
| 1392 |
SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset); |
| 1393 |
STORE_RT_REG(p_hwfn, rt_type_offset_fl_arr[i], cdu_seg_params); |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
void qed_qm_init_pf(struct qed_hwfn *p_hwfn, |
| 1398 |
struct qed_ptt *p_ptt, bool is_pf_loading) |
| 1399 |
{ |
| 1400 |
struct qed_qm_info *qm_info = &p_hwfn->qm_info; |
| 1401 |
struct qed_qm_pf_rt_init_params params; |
| 1402 |
struct qed_qm_iids iids; |
| 1403 |
|
| 1404 |
memset(&iids, 0, sizeof(iids)); |
| 1405 |
qed_cxt_qm_iids(p_hwfn, &iids); |
| 1406 |
|
| 1407 |
memset(¶ms, 0, sizeof(params)); |
| 1408 |
params.port_id = p_hwfn->port_id; |
| 1409 |
params.pf_id = p_hwfn->rel_pf_id; |
| 1410 |
params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port; |
| 1411 |
params.is_pf_loading = is_pf_loading; |
| 1412 |
params.num_pf_cids = iids.cids; |
| 1413 |
params.num_vf_cids = iids.vf_cids; |
| 1414 |
params.num_tids = iids.tids; |
| 1415 |
params.start_pq = qm_info->start_pq; |
| 1416 |
params.num_pf_pqs = qm_info->num_pqs - qm_info->num_vf_pqs; |
| 1417 |
params.num_vf_pqs = qm_info->num_vf_pqs; |
| 1418 |
params.start_vport = qm_info->start_vport; |
| 1419 |
params.num_vports = qm_info->num_vports; |
| 1420 |
params.pf_wfq = qm_info->pf_wfq; |
| 1421 |
params.pf_rl = qm_info->pf_rl; |
| 1422 |
params.pq_params = qm_info->qm_pq_params; |
| 1423 |
params.vport_params = qm_info->qm_vport_params; |
| 1424 |
|
| 1425 |
qed_qm_pf_rt_init(p_hwfn, p_ptt, ¶ms); |
| 1426 |
} |
| 1427 |
|
| 1428 |
/* CM PF */ |
| 1429 |
static void qed_cm_init_pf(struct qed_hwfn *p_hwfn) |
| 1430 |
{ |
| 1431 |
/* XCM pure-LB queue */ |
| 1432 |
STORE_RT_REG(p_hwfn, XCM_REG_CON_PHY_Q3_RT_OFFSET, |
| 1433 |
qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB)); |
| 1434 |
} |
| 1435 |
|
| 1436 |
/* DQ PF */ |
| 1437 |
static void qed_dq_init_pf(struct qed_hwfn *p_hwfn) |
| 1438 |
{ |
| 1439 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1440 |
u32 dq_pf_max_cid = 0, dq_vf_max_cid = 0; |
| 1441 |
|
| 1442 |
dq_pf_max_cid += (p_mngr->conn_cfg[0].cid_count >> DQ_RANGE_SHIFT); |
| 1443 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_0_RT_OFFSET, dq_pf_max_cid); |
| 1444 |
|
| 1445 |
dq_vf_max_cid += (p_mngr->conn_cfg[0].cids_per_vf >> DQ_RANGE_SHIFT); |
| 1446 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_0_RT_OFFSET, dq_vf_max_cid); |
| 1447 |
|
| 1448 |
dq_pf_max_cid += (p_mngr->conn_cfg[1].cid_count >> DQ_RANGE_SHIFT); |
| 1449 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_1_RT_OFFSET, dq_pf_max_cid); |
| 1450 |
|
| 1451 |
dq_vf_max_cid += (p_mngr->conn_cfg[1].cids_per_vf >> DQ_RANGE_SHIFT); |
| 1452 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_1_RT_OFFSET, dq_vf_max_cid); |
| 1453 |
|
| 1454 |
dq_pf_max_cid += (p_mngr->conn_cfg[2].cid_count >> DQ_RANGE_SHIFT); |
| 1455 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_2_RT_OFFSET, dq_pf_max_cid); |
| 1456 |
|
| 1457 |
dq_vf_max_cid += (p_mngr->conn_cfg[2].cids_per_vf >> DQ_RANGE_SHIFT); |
| 1458 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_2_RT_OFFSET, dq_vf_max_cid); |
| 1459 |
|
| 1460 |
dq_pf_max_cid += (p_mngr->conn_cfg[3].cid_count >> DQ_RANGE_SHIFT); |
| 1461 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_3_RT_OFFSET, dq_pf_max_cid); |
| 1462 |
|
| 1463 |
dq_vf_max_cid += (p_mngr->conn_cfg[3].cids_per_vf >> DQ_RANGE_SHIFT); |
| 1464 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_3_RT_OFFSET, dq_vf_max_cid); |
| 1465 |
|
| 1466 |
dq_pf_max_cid += (p_mngr->conn_cfg[4].cid_count >> DQ_RANGE_SHIFT); |
| 1467 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_4_RT_OFFSET, dq_pf_max_cid); |
| 1468 |
|
| 1469 |
dq_vf_max_cid += (p_mngr->conn_cfg[4].cids_per_vf >> DQ_RANGE_SHIFT); |
| 1470 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_4_RT_OFFSET, dq_vf_max_cid); |
| 1471 |
|
| 1472 |
dq_pf_max_cid += (p_mngr->conn_cfg[5].cid_count >> DQ_RANGE_SHIFT); |
| 1473 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_5_RT_OFFSET, dq_pf_max_cid); |
| 1474 |
|
| 1475 |
dq_vf_max_cid += (p_mngr->conn_cfg[5].cids_per_vf >> DQ_RANGE_SHIFT); |
| 1476 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_5_RT_OFFSET, dq_vf_max_cid); |
| 1477 |
|
| 1478 |
/* Connection types 6 & 7 are not in use, yet they must be configured |
| 1479 |
* as the highest possible connection. Not configuring them means the |
| 1480 |
* defaults will be used, and with a large number of cids a bug may |
| 1481 |
* occur, if the defaults will be smaller than dq_pf_max_cid / |
| 1482 |
* dq_vf_max_cid. |
| 1483 |
*/ |
| 1484 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_6_RT_OFFSET, dq_pf_max_cid); |
| 1485 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_6_RT_OFFSET, dq_vf_max_cid); |
| 1486 |
|
| 1487 |
STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_7_RT_OFFSET, dq_pf_max_cid); |
| 1488 |
STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_7_RT_OFFSET, dq_vf_max_cid); |
| 1489 |
} |
| 1490 |
|
| 1491 |
static void qed_ilt_bounds_init(struct qed_hwfn *p_hwfn) |
| 1492 |
{ |
| 1493 |
struct qed_ilt_client_cfg *ilt_clients; |
| 1494 |
int i; |
| 1495 |
|
| 1496 |
ilt_clients = p_hwfn->p_cxt_mngr->clients; |
| 1497 |
for_each_ilt_valid_client(i, ilt_clients) { |
| 1498 |
STORE_RT_REG(p_hwfn, |
| 1499 |
ilt_clients[i].first.reg, |
| 1500 |
ilt_clients[i].first.val); |
| 1501 |
STORE_RT_REG(p_hwfn, |
| 1502 |
ilt_clients[i].last.reg, ilt_clients[i].last.val); |
| 1503 |
STORE_RT_REG(p_hwfn, |
| 1504 |
ilt_clients[i].p_size.reg, |
| 1505 |
ilt_clients[i].p_size.val); |
| 1506 |
} |
| 1507 |
} |
| 1508 |
|
| 1509 |
static void qed_ilt_vf_bounds_init(struct qed_hwfn *p_hwfn) |
| 1510 |
{ |
| 1511 |
struct qed_ilt_client_cfg *p_cli; |
| 1512 |
u32 blk_factor; |
| 1513 |
|
| 1514 |
/* For simplicty we set the 'block' to be an ILT page */ |
| 1515 |
if (p_hwfn->cdev->p_iov_info) { |
| 1516 |
struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info; |
| 1517 |
|
| 1518 |
STORE_RT_REG(p_hwfn, |
| 1519 |
PSWRQ2_REG_VF_BASE_RT_OFFSET, |
| 1520 |
p_iov->first_vf_in_pf); |
| 1521 |
STORE_RT_REG(p_hwfn, |
| 1522 |
PSWRQ2_REG_VF_LAST_ILT_RT_OFFSET, |
| 1523 |
p_iov->first_vf_in_pf + p_iov->total_vfs); |
| 1524 |
} |
| 1525 |
|
| 1526 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; |
| 1527 |
blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10); |
| 1528 |
if (p_cli->active) { |
| 1529 |
STORE_RT_REG(p_hwfn, |
| 1530 |
PSWRQ2_REG_CDUC_BLOCKS_FACTOR_RT_OFFSET, |
| 1531 |
blk_factor); |
| 1532 |
STORE_RT_REG(p_hwfn, |
| 1533 |
PSWRQ2_REG_CDUC_NUMBER_OF_PF_BLOCKS_RT_OFFSET, |
| 1534 |
p_cli->pf_total_lines); |
| 1535 |
STORE_RT_REG(p_hwfn, |
| 1536 |
PSWRQ2_REG_CDUC_VF_BLOCKS_RT_OFFSET, |
| 1537 |
p_cli->vf_total_lines); |
| 1538 |
} |
| 1539 |
|
| 1540 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 1541 |
blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10); |
| 1542 |
if (p_cli->active) { |
| 1543 |
STORE_RT_REG(p_hwfn, |
| 1544 |
PSWRQ2_REG_CDUT_BLOCKS_FACTOR_RT_OFFSET, |
| 1545 |
blk_factor); |
| 1546 |
STORE_RT_REG(p_hwfn, |
| 1547 |
PSWRQ2_REG_CDUT_NUMBER_OF_PF_BLOCKS_RT_OFFSET, |
| 1548 |
p_cli->pf_total_lines); |
| 1549 |
STORE_RT_REG(p_hwfn, |
| 1550 |
PSWRQ2_REG_CDUT_VF_BLOCKS_RT_OFFSET, |
| 1551 |
p_cli->vf_total_lines); |
| 1552 |
} |
| 1553 |
|
| 1554 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TM]; |
| 1555 |
blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10); |
| 1556 |
if (p_cli->active) { |
| 1557 |
STORE_RT_REG(p_hwfn, |
| 1558 |
PSWRQ2_REG_TM_BLOCKS_FACTOR_RT_OFFSET, blk_factor); |
| 1559 |
STORE_RT_REG(p_hwfn, |
| 1560 |
PSWRQ2_REG_TM_NUMBER_OF_PF_BLOCKS_RT_OFFSET, |
| 1561 |
p_cli->pf_total_lines); |
| 1562 |
STORE_RT_REG(p_hwfn, |
| 1563 |
PSWRQ2_REG_TM_VF_BLOCKS_RT_OFFSET, |
| 1564 |
p_cli->vf_total_lines); |
| 1565 |
} |
| 1566 |
} |
| 1567 |
|
| 1568 |
/* ILT (PSWRQ2) PF */ |
| 1569 |
static void qed_ilt_init_pf(struct qed_hwfn *p_hwfn) |
| 1570 |
{ |
| 1571 |
struct qed_ilt_client_cfg *clients; |
| 1572 |
struct qed_cxt_mngr *p_mngr; |
| 1573 |
struct phys_mem_desc *p_shdw; |
| 1574 |
u32 line, rt_offst, i; |
| 1575 |
|
| 1576 |
qed_ilt_bounds_init(p_hwfn); |
| 1577 |
qed_ilt_vf_bounds_init(p_hwfn); |
| 1578 |
|
| 1579 |
p_mngr = p_hwfn->p_cxt_mngr; |
| 1580 |
p_shdw = p_mngr->ilt_shadow; |
| 1581 |
clients = p_hwfn->p_cxt_mngr->clients; |
| 1582 |
|
| 1583 |
for_each_ilt_valid_client(i, clients) { |
| 1584 |
/** Client's 1st val and RT array are absolute, ILT shadows' |
| 1585 |
* lines are relative. |
| 1586 |
*/ |
| 1587 |
line = clients[i].first.val - p_mngr->pf_start_line; |
| 1588 |
rt_offst = PSWRQ2_REG_ILT_MEMORY_RT_OFFSET + |
| 1589 |
clients[i].first.val * ILT_ENTRY_IN_REGS; |
| 1590 |
|
| 1591 |
for (; line <= clients[i].last.val - p_mngr->pf_start_line; |
| 1592 |
line++, rt_offst += ILT_ENTRY_IN_REGS) { |
| 1593 |
u64 ilt_hw_entry = 0; |
| 1594 |
|
| 1595 |
/** p_virt could be NULL incase of dynamic |
| 1596 |
* allocation |
| 1597 |
*/ |
| 1598 |
if (p_shdw[line].virt_addr) { |
| 1599 |
SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL); |
| 1600 |
SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR, |
| 1601 |
(p_shdw[line].phys_addr >> 12)); |
| 1602 |
|
| 1603 |
DP_VERBOSE(p_hwfn, QED_MSG_ILT, |
| 1604 |
"Setting RT[0x%08x] from ILT[0x%08x] [Client is %d] to Physical addr: 0x%llx\n", |
| 1605 |
rt_offst, line, i, |
| 1606 |
(u64)(p_shdw[line].phys_addr >> 12)); |
| 1607 |
} |
| 1608 |
|
| 1609 |
STORE_RT_REG_AGG(p_hwfn, rt_offst, ilt_hw_entry); |
| 1610 |
} |
| 1611 |
} |
| 1612 |
} |
| 1613 |
|
| 1614 |
/* SRC (Searcher) PF */ |
| 1615 |
static void qed_src_init_pf(struct qed_hwfn *p_hwfn) |
| 1616 |
{ |
| 1617 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1618 |
u32 rounded_conn_num, conn_num, conn_max; |
| 1619 |
struct qed_src_iids src_iids; |
| 1620 |
|
| 1621 |
memset(&src_iids, 0, sizeof(src_iids)); |
| 1622 |
qed_cxt_src_iids(p_mngr, &src_iids); |
| 1623 |
conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count; |
| 1624 |
if (!conn_num) |
| 1625 |
return; |
| 1626 |
|
| 1627 |
conn_max = max_t(u32, conn_num, SRC_MIN_NUM_ELEMS); |
| 1628 |
rounded_conn_num = roundup_pow_of_two(conn_max); |
| 1629 |
|
| 1630 |
STORE_RT_REG(p_hwfn, SRC_REG_COUNTFREE_RT_OFFSET, conn_num); |
| 1631 |
STORE_RT_REG(p_hwfn, SRC_REG_NUMBER_HASH_BITS_RT_OFFSET, |
| 1632 |
ilog2(rounded_conn_num)); |
| 1633 |
|
| 1634 |
STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET, |
| 1635 |
p_hwfn->p_cxt_mngr->src_t2.first_free); |
| 1636 |
STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET, |
| 1637 |
p_hwfn->p_cxt_mngr->src_t2.last_free); |
| 1638 |
} |
| 1639 |
|
| 1640 |
/* Timers PF */ |
| 1641 |
#define TM_CFG_NUM_IDS_SHIFT 0 |
| 1642 |
#define TM_CFG_NUM_IDS_MASK 0xFFFFULL |
| 1643 |
#define TM_CFG_PRE_SCAN_OFFSET_SHIFT 16 |
| 1644 |
#define TM_CFG_PRE_SCAN_OFFSET_MASK 0x1FFULL |
| 1645 |
#define TM_CFG_PARENT_PF_SHIFT 25 |
| 1646 |
#define TM_CFG_PARENT_PF_MASK 0x7ULL |
| 1647 |
|
| 1648 |
#define TM_CFG_CID_PRE_SCAN_ROWS_SHIFT 30 |
| 1649 |
#define TM_CFG_CID_PRE_SCAN_ROWS_MASK 0x1FFULL |
| 1650 |
|
| 1651 |
#define TM_CFG_TID_OFFSET_SHIFT 30 |
| 1652 |
#define TM_CFG_TID_OFFSET_MASK 0x7FFFFULL |
| 1653 |
#define TM_CFG_TID_PRE_SCAN_ROWS_SHIFT 49 |
| 1654 |
#define TM_CFG_TID_PRE_SCAN_ROWS_MASK 0x1FFULL |
| 1655 |
|
| 1656 |
static void qed_tm_init_pf(struct qed_hwfn *p_hwfn) |
| 1657 |
{ |
| 1658 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1659 |
u32 active_seg_mask = 0, tm_offset, rt_reg; |
| 1660 |
struct qed_tm_iids tm_iids; |
| 1661 |
u64 cfg_word; |
| 1662 |
u8 i; |
| 1663 |
|
| 1664 |
memset(&tm_iids, 0, sizeof(tm_iids)); |
| 1665 |
qed_cxt_tm_iids(p_hwfn, p_mngr, &tm_iids); |
| 1666 |
|
| 1667 |
/* @@@TBD No pre-scan for now */ |
| 1668 |
|
| 1669 |
/* Note: We assume consecutive VFs for a PF */ |
| 1670 |
for (i = 0; i < p_mngr->vf_count; i++) { |
| 1671 |
cfg_word = 0; |
| 1672 |
SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_cids); |
| 1673 |
SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); |
| 1674 |
SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id); |
| 1675 |
SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); |
| 1676 |
rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET + |
| 1677 |
(sizeof(cfg_word) / sizeof(u32)) * |
| 1678 |
(p_hwfn->cdev->p_iov_info->first_vf_in_pf + i); |
| 1679 |
STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); |
| 1680 |
} |
| 1681 |
|
| 1682 |
cfg_word = 0; |
| 1683 |
SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_cids); |
| 1684 |
SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); |
| 1685 |
SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); /* n/a for PF */ |
| 1686 |
SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */ |
| 1687 |
|
| 1688 |
rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET + |
| 1689 |
(sizeof(cfg_word) / sizeof(u32)) * |
| 1690 |
(NUM_OF_VFS(p_hwfn->cdev) + p_hwfn->rel_pf_id); |
| 1691 |
STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); |
| 1692 |
|
| 1693 |
/* enale scan */ |
| 1694 |
STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_CONN_RT_OFFSET, |
| 1695 |
tm_iids.pf_cids ? 0x1 : 0x0); |
| 1696 |
|
| 1697 |
/* @@@TBD how to enable the scan for the VFs */ |
| 1698 |
|
| 1699 |
tm_offset = tm_iids.per_vf_cids; |
| 1700 |
|
| 1701 |
/* Note: We assume consecutive VFs for a PF */ |
| 1702 |
for (i = 0; i < p_mngr->vf_count; i++) { |
| 1703 |
cfg_word = 0; |
| 1704 |
SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_tids); |
| 1705 |
SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); |
| 1706 |
SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id); |
| 1707 |
SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset); |
| 1708 |
SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64) 0); |
| 1709 |
|
| 1710 |
rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET + |
| 1711 |
(sizeof(cfg_word) / sizeof(u32)) * |
| 1712 |
(p_hwfn->cdev->p_iov_info->first_vf_in_pf + i); |
| 1713 |
|
| 1714 |
STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); |
| 1715 |
} |
| 1716 |
|
| 1717 |
tm_offset = tm_iids.pf_cids; |
| 1718 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 1719 |
cfg_word = 0; |
| 1720 |
SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_tids[i]); |
| 1721 |
SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); |
| 1722 |
SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); |
| 1723 |
SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset); |
| 1724 |
SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64) 0); |
| 1725 |
|
| 1726 |
rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET + |
| 1727 |
(sizeof(cfg_word) / sizeof(u32)) * |
| 1728 |
(NUM_OF_VFS(p_hwfn->cdev) + |
| 1729 |
p_hwfn->rel_pf_id * NUM_TASK_PF_SEGMENTS + i); |
| 1730 |
|
| 1731 |
STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); |
| 1732 |
active_seg_mask |= (tm_iids.pf_tids[i] ? BIT(i) : 0); |
| 1733 |
|
| 1734 |
tm_offset += tm_iids.pf_tids[i]; |
| 1735 |
} |
| 1736 |
|
| 1737 |
if (QED_IS_RDMA_PERSONALITY(p_hwfn)) |
| 1738 |
active_seg_mask = 0; |
| 1739 |
|
| 1740 |
STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_TASK_RT_OFFSET, active_seg_mask); |
| 1741 |
|
| 1742 |
/* @@@TBD how to enable the scan for the VFs */ |
| 1743 |
} |
| 1744 |
|
| 1745 |
static void qed_prs_init_common(struct qed_hwfn *p_hwfn) |
| 1746 |
{ |
| 1747 |
if ((p_hwfn->hw_info.personality == QED_PCI_FCOE) && |
| 1748 |
p_hwfn->pf_params.fcoe_pf_params.is_target) |
| 1749 |
STORE_RT_REG(p_hwfn, |
| 1750 |
PRS_REG_SEARCH_RESP_INITIATOR_TYPE_RT_OFFSET, 0); |
| 1751 |
} |
| 1752 |
|
| 1753 |
static void qed_prs_init_pf(struct qed_hwfn *p_hwfn) |
| 1754 |
{ |
| 1755 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1756 |
struct qed_conn_type_cfg *p_fcoe; |
| 1757 |
struct qed_tid_seg *p_tid; |
| 1758 |
|
| 1759 |
p_fcoe = &p_mngr->conn_cfg[PROTOCOLID_FCOE]; |
| 1760 |
|
| 1761 |
/* If FCoE is active set the MAX OX_ID (tid) in the Parser */ |
| 1762 |
if (!p_fcoe->cid_count) |
| 1763 |
return; |
| 1764 |
|
| 1765 |
p_tid = &p_fcoe->tid_seg[QED_CXT_FCOE_TID_SEG]; |
| 1766 |
if (p_hwfn->pf_params.fcoe_pf_params.is_target) { |
| 1767 |
STORE_RT_REG_AGG(p_hwfn, |
| 1768 |
PRS_REG_TASK_ID_MAX_TARGET_PF_RT_OFFSET, |
| 1769 |
p_tid->count); |
| 1770 |
} else { |
| 1771 |
STORE_RT_REG_AGG(p_hwfn, |
| 1772 |
PRS_REG_TASK_ID_MAX_INITIATOR_PF_RT_OFFSET, |
| 1773 |
p_tid->count); |
| 1774 |
} |
| 1775 |
} |
| 1776 |
|
| 1777 |
void qed_cxt_hw_init_common(struct qed_hwfn *p_hwfn) |
| 1778 |
{ |
| 1779 |
qed_cdu_init_common(p_hwfn); |
| 1780 |
qed_prs_init_common(p_hwfn); |
| 1781 |
} |
| 1782 |
|
| 1783 |
void qed_cxt_hw_init_pf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 1784 |
{ |
| 1785 |
qed_qm_init_pf(p_hwfn, p_ptt, true); |
| 1786 |
qed_cm_init_pf(p_hwfn); |
| 1787 |
qed_dq_init_pf(p_hwfn); |
| 1788 |
qed_cdu_init_pf(p_hwfn); |
| 1789 |
qed_ilt_init_pf(p_hwfn); |
| 1790 |
qed_src_init_pf(p_hwfn); |
| 1791 |
qed_tm_init_pf(p_hwfn); |
| 1792 |
qed_prs_init_pf(p_hwfn); |
| 1793 |
} |
| 1794 |
|
| 1795 |
int _qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn, |
| 1796 |
enum protocol_type type, u32 *p_cid, u8 vfid) |
| 1797 |
{ |
| 1798 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1799 |
struct qed_cid_acquired_map *p_map; |
| 1800 |
u32 rel_cid; |
| 1801 |
|
| 1802 |
if (type >= MAX_CONN_TYPES) { |
| 1803 |
DP_NOTICE(p_hwfn, "Invalid protocol type %d", type); |
| 1804 |
return -EINVAL; |
| 1805 |
} |
| 1806 |
|
| 1807 |
if (vfid >= MAX_NUM_VFS && vfid != QED_CXT_PF_CID) { |
| 1808 |
DP_NOTICE(p_hwfn, "VF [%02x] is out of range\n", vfid); |
| 1809 |
return -EINVAL; |
| 1810 |
} |
| 1811 |
|
| 1812 |
/* Determine the right map to take this CID from */ |
| 1813 |
if (vfid == QED_CXT_PF_CID) |
| 1814 |
p_map = &p_mngr->acquired[type]; |
| 1815 |
else |
| 1816 |
p_map = &p_mngr->acquired_vf[type][vfid]; |
| 1817 |
|
| 1818 |
if (!p_map->cid_map) { |
| 1819 |
DP_NOTICE(p_hwfn, "Invalid protocol type %d", type); |
| 1820 |
return -EINVAL; |
| 1821 |
} |
| 1822 |
|
| 1823 |
rel_cid = find_first_zero_bit(p_map->cid_map, p_map->max_count); |
| 1824 |
|
| 1825 |
if (rel_cid >= p_map->max_count) { |
| 1826 |
DP_NOTICE(p_hwfn, "no CID available for protocol %d\n", type); |
| 1827 |
return -EINVAL; |
| 1828 |
} |
| 1829 |
|
| 1830 |
__set_bit(rel_cid, p_map->cid_map); |
| 1831 |
|
| 1832 |
*p_cid = rel_cid + p_map->start_cid; |
| 1833 |
|
| 1834 |
DP_VERBOSE(p_hwfn, QED_MSG_CXT, |
| 1835 |
"Acquired cid 0x%08x [rel. %08x] vfid %02x type %d\n", |
| 1836 |
*p_cid, rel_cid, vfid, type); |
| 1837 |
|
| 1838 |
return 0; |
| 1839 |
} |
| 1840 |
|
| 1841 |
int qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn, |
| 1842 |
enum protocol_type type, u32 *p_cid) |
| 1843 |
{ |
| 1844 |
return _qed_cxt_acquire_cid(p_hwfn, type, p_cid, QED_CXT_PF_CID); |
| 1845 |
} |
| 1846 |
|
| 1847 |
static bool qed_cxt_test_cid_acquired(struct qed_hwfn *p_hwfn, |
| 1848 |
u32 cid, |
| 1849 |
u8 vfid, |
| 1850 |
enum protocol_type *p_type, |
| 1851 |
struct qed_cid_acquired_map **pp_map) |
| 1852 |
{ |
| 1853 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1854 |
u32 rel_cid; |
| 1855 |
|
| 1856 |
/* Iterate over protocols and find matching cid range */ |
| 1857 |
for (*p_type = 0; *p_type < MAX_CONN_TYPES; (*p_type)++) { |
| 1858 |
if (vfid == QED_CXT_PF_CID) |
| 1859 |
*pp_map = &p_mngr->acquired[*p_type]; |
| 1860 |
else |
| 1861 |
*pp_map = &p_mngr->acquired_vf[*p_type][vfid]; |
| 1862 |
|
| 1863 |
if (!((*pp_map)->cid_map)) |
| 1864 |
continue; |
| 1865 |
if (cid >= (*pp_map)->start_cid && |
| 1866 |
cid < (*pp_map)->start_cid + (*pp_map)->max_count) |
| 1867 |
break; |
| 1868 |
} |
| 1869 |
|
| 1870 |
if (*p_type == MAX_CONN_TYPES) { |
| 1871 |
DP_NOTICE(p_hwfn, "Invalid CID %d vfid %02x", cid, vfid); |
| 1872 |
goto fail; |
| 1873 |
} |
| 1874 |
|
| 1875 |
rel_cid = cid - (*pp_map)->start_cid; |
| 1876 |
if (!test_bit(rel_cid, (*pp_map)->cid_map)) { |
| 1877 |
DP_NOTICE(p_hwfn, "CID %d [vifd %02x] not acquired", |
| 1878 |
cid, vfid); |
| 1879 |
goto fail; |
| 1880 |
} |
| 1881 |
|
| 1882 |
return true; |
| 1883 |
fail: |
| 1884 |
*p_type = MAX_CONN_TYPES; |
| 1885 |
*pp_map = NULL; |
| 1886 |
return false; |
| 1887 |
} |
| 1888 |
|
| 1889 |
void _qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid, u8 vfid) |
| 1890 |
{ |
| 1891 |
struct qed_cid_acquired_map *p_map = NULL; |
| 1892 |
enum protocol_type type; |
| 1893 |
bool b_acquired; |
| 1894 |
u32 rel_cid; |
| 1895 |
|
| 1896 |
if (vfid != QED_CXT_PF_CID && vfid > MAX_NUM_VFS) { |
| 1897 |
DP_NOTICE(p_hwfn, |
| 1898 |
"Trying to return incorrect CID belonging to VF %02x\n", |
| 1899 |
vfid); |
| 1900 |
return; |
| 1901 |
} |
| 1902 |
|
| 1903 |
/* Test acquired and find matching per-protocol map */ |
| 1904 |
b_acquired = qed_cxt_test_cid_acquired(p_hwfn, cid, vfid, |
| 1905 |
&type, &p_map); |
| 1906 |
|
| 1907 |
if (!b_acquired) |
| 1908 |
return; |
| 1909 |
|
| 1910 |
rel_cid = cid - p_map->start_cid; |
| 1911 |
clear_bit(rel_cid, p_map->cid_map); |
| 1912 |
|
| 1913 |
DP_VERBOSE(p_hwfn, QED_MSG_CXT, |
| 1914 |
"Released CID 0x%08x [rel. %08x] vfid %02x type %d\n", |
| 1915 |
cid, rel_cid, vfid, type); |
| 1916 |
} |
| 1917 |
|
| 1918 |
void qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid) |
| 1919 |
{ |
| 1920 |
_qed_cxt_release_cid(p_hwfn, cid, QED_CXT_PF_CID); |
| 1921 |
} |
| 1922 |
|
| 1923 |
int qed_cxt_get_cid_info(struct qed_hwfn *p_hwfn, struct qed_cxt_info *p_info) |
| 1924 |
{ |
| 1925 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 1926 |
struct qed_cid_acquired_map *p_map = NULL; |
| 1927 |
u32 conn_cxt_size, hw_p_size, cxts_per_p, line; |
| 1928 |
enum protocol_type type; |
| 1929 |
bool b_acquired; |
| 1930 |
|
| 1931 |
/* Test acquired and find matching per-protocol map */ |
| 1932 |
b_acquired = qed_cxt_test_cid_acquired(p_hwfn, p_info->iid, |
| 1933 |
QED_CXT_PF_CID, &type, &p_map); |
| 1934 |
|
| 1935 |
if (!b_acquired) |
| 1936 |
return -EINVAL; |
| 1937 |
|
| 1938 |
/* set the protocl type */ |
| 1939 |
p_info->type = type; |
| 1940 |
|
| 1941 |
/* compute context virtual pointer */ |
| 1942 |
hw_p_size = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val; |
| 1943 |
|
| 1944 |
conn_cxt_size = CONN_CXT_SIZE(p_hwfn); |
| 1945 |
cxts_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / conn_cxt_size; |
| 1946 |
line = p_info->iid / cxts_per_p; |
| 1947 |
|
| 1948 |
/* Make sure context is allocated (dynamic allocation) */ |
| 1949 |
if (!p_mngr->ilt_shadow[line].virt_addr) |
| 1950 |
return -EINVAL; |
| 1951 |
|
| 1952 |
p_info->p_cxt = p_mngr->ilt_shadow[line].virt_addr + |
| 1953 |
p_info->iid % cxts_per_p * conn_cxt_size; |
| 1954 |
|
| 1955 |
DP_VERBOSE(p_hwfn, (QED_MSG_ILT | QED_MSG_CXT), |
| 1956 |
"Accessing ILT shadow[%d]: CXT pointer is at %p (for iid %d)\n", |
| 1957 |
p_info->iid / cxts_per_p, p_info->p_cxt, p_info->iid); |
| 1958 |
|
| 1959 |
return 0; |
| 1960 |
} |
| 1961 |
|
| 1962 |
static void qed_rdma_set_pf_params(struct qed_hwfn *p_hwfn, |
| 1963 |
struct qed_rdma_pf_params *p_params, |
| 1964 |
u32 num_tasks) |
| 1965 |
{ |
| 1966 |
u32 num_cons, num_qps; |
| 1967 |
enum protocol_type proto; |
| 1968 |
|
| 1969 |
if (p_hwfn->mcp_info->func_info.protocol == QED_PCI_ETH_RDMA) { |
| 1970 |
DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 1971 |
"Current day drivers don't support RoCE & iWARP simultaneously on the same PF. Default to RoCE-only\n"); |
| 1972 |
p_hwfn->hw_info.personality = QED_PCI_ETH_ROCE; |
| 1973 |
} |
| 1974 |
|
| 1975 |
switch (p_hwfn->hw_info.personality) { |
| 1976 |
case QED_PCI_ETH_IWARP: |
| 1977 |
/* Each QP requires one connection */ |
| 1978 |
num_cons = min_t(u32, IWARP_MAX_QPS, p_params->num_qps); |
| 1979 |
proto = PROTOCOLID_IWARP; |
| 1980 |
break; |
| 1981 |
case QED_PCI_ETH_ROCE: |
| 1982 |
num_qps = min_t(u32, ROCE_MAX_QPS, p_params->num_qps); |
| 1983 |
num_cons = num_qps * 2; /* each QP requires two connections */ |
| 1984 |
proto = PROTOCOLID_ROCE; |
| 1985 |
break; |
| 1986 |
default: |
| 1987 |
return; |
| 1988 |
} |
| 1989 |
|
| 1990 |
if (num_cons && num_tasks) { |
| 1991 |
u32 num_srqs, num_xrc_srqs; |
| 1992 |
|
| 1993 |
qed_cxt_set_proto_cid_count(p_hwfn, proto, num_cons, 0); |
| 1994 |
|
| 1995 |
/* Deliberatly passing ROCE for tasks id. This is because |
| 1996 |
* iWARP / RoCE share the task id. |
| 1997 |
*/ |
| 1998 |
qed_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_ROCE, |
| 1999 |
QED_CXT_ROCE_TID_SEG, 1, |
| 2000 |
num_tasks, false); |
| 2001 |
|
| 2002 |
num_srqs = min_t(u32, QED_RDMA_MAX_SRQS, p_params->num_srqs); |
| 2003 |
|
| 2004 |
/* XRC SRQs populate a single ILT page */ |
| 2005 |
num_xrc_srqs = qed_cxt_xrc_srqs_per_page(p_hwfn); |
| 2006 |
|
| 2007 |
qed_cxt_set_srq_count(p_hwfn, num_srqs, num_xrc_srqs); |
| 2008 |
} else { |
| 2009 |
DP_INFO(p_hwfn->cdev, |
| 2010 |
"RDMA personality used without setting params!\n"); |
| 2011 |
} |
| 2012 |
} |
| 2013 |
|
| 2014 |
int qed_cxt_set_pf_params(struct qed_hwfn *p_hwfn, u32 rdma_tasks) |
| 2015 |
{ |
| 2016 |
/* Set the number of required CORE connections */ |
| 2017 |
u32 core_cids = 1; /* SPQ */ |
| 2018 |
|
| 2019 |
if (p_hwfn->using_ll2) |
| 2020 |
core_cids += 4; |
| 2021 |
qed_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_CORE, core_cids, 0); |
| 2022 |
|
| 2023 |
switch (p_hwfn->hw_info.personality) { |
| 2024 |
case QED_PCI_ETH_RDMA: |
| 2025 |
case QED_PCI_ETH_IWARP: |
| 2026 |
case QED_PCI_ETH_ROCE: |
| 2027 |
{ |
| 2028 |
qed_rdma_set_pf_params(p_hwfn, |
| 2029 |
&p_hwfn-> |
| 2030 |
pf_params.rdma_pf_params, |
| 2031 |
rdma_tasks); |
| 2032 |
/* no need for break since RoCE coexist with Ethernet */ |
| 2033 |
} |
| 2034 |
fallthrough; |
| 2035 |
case QED_PCI_ETH: |
| 2036 |
{ |
| 2037 |
struct qed_eth_pf_params *p_params = |
| 2038 |
&p_hwfn->pf_params.eth_pf_params; |
| 2039 |
|
| 2040 |
if (!p_params->num_vf_cons) |
| 2041 |
p_params->num_vf_cons = |
| 2042 |
ETH_PF_PARAMS_VF_CONS_DEFAULT; |
| 2043 |
qed_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_ETH, |
| 2044 |
p_params->num_cons, |
| 2045 |
p_params->num_vf_cons); |
| 2046 |
p_hwfn->p_cxt_mngr->arfs_count = p_params->num_arfs_filters; |
| 2047 |
break; |
| 2048 |
} |
| 2049 |
case QED_PCI_FCOE: |
| 2050 |
{ |
| 2051 |
struct qed_fcoe_pf_params *p_params; |
| 2052 |
|
| 2053 |
p_params = &p_hwfn->pf_params.fcoe_pf_params; |
| 2054 |
|
| 2055 |
if (p_params->num_cons && p_params->num_tasks) { |
| 2056 |
qed_cxt_set_proto_cid_count(p_hwfn, |
| 2057 |
PROTOCOLID_FCOE, |
| 2058 |
p_params->num_cons, |
| 2059 |
0); |
| 2060 |
qed_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_FCOE, |
| 2061 |
QED_CXT_FCOE_TID_SEG, 0, |
| 2062 |
p_params->num_tasks, true); |
| 2063 |
} else { |
| 2064 |
DP_INFO(p_hwfn->cdev, |
| 2065 |
"Fcoe personality used without setting params!\n"); |
| 2066 |
} |
| 2067 |
break; |
| 2068 |
} |
| 2069 |
case QED_PCI_ISCSI: |
| 2070 |
{ |
| 2071 |
struct qed_iscsi_pf_params *p_params; |
| 2072 |
|
| 2073 |
p_params = &p_hwfn->pf_params.iscsi_pf_params; |
| 2074 |
|
| 2075 |
if (p_params->num_cons && p_params->num_tasks) { |
| 2076 |
qed_cxt_set_proto_cid_count(p_hwfn, |
| 2077 |
PROTOCOLID_TCP_ULP, |
| 2078 |
p_params->num_cons, |
| 2079 |
0); |
| 2080 |
qed_cxt_set_proto_tid_count(p_hwfn, |
| 2081 |
PROTOCOLID_TCP_ULP, |
| 2082 |
QED_CXT_TCP_ULP_TID_SEG, |
| 2083 |
0, |
| 2084 |
p_params->num_tasks, |
| 2085 |
true); |
| 2086 |
} else { |
| 2087 |
DP_INFO(p_hwfn->cdev, |
| 2088 |
"Iscsi personality used without setting params!\n"); |
| 2089 |
} |
| 2090 |
break; |
| 2091 |
} |
| 2092 |
case QED_PCI_NVMETCP: |
| 2093 |
{ |
| 2094 |
struct qed_nvmetcp_pf_params *p_params; |
| 2095 |
|
| 2096 |
p_params = &p_hwfn->pf_params.nvmetcp_pf_params; |
| 2097 |
|
| 2098 |
if (p_params->num_cons && p_params->num_tasks) { |
| 2099 |
qed_cxt_set_proto_cid_count(p_hwfn, |
| 2100 |
PROTOCOLID_TCP_ULP, |
| 2101 |
p_params->num_cons, |
| 2102 |
0); |
| 2103 |
qed_cxt_set_proto_tid_count(p_hwfn, |
| 2104 |
PROTOCOLID_TCP_ULP, |
| 2105 |
QED_CXT_TCP_ULP_TID_SEG, |
| 2106 |
0, |
| 2107 |
p_params->num_tasks, |
| 2108 |
true); |
| 2109 |
} else { |
| 2110 |
DP_INFO(p_hwfn->cdev, |
| 2111 |
"NvmeTCP personality used without setting params!\n"); |
| 2112 |
} |
| 2113 |
break; |
| 2114 |
} |
| 2115 |
default: |
| 2116 |
return -EINVAL; |
| 2117 |
} |
| 2118 |
|
| 2119 |
return 0; |
| 2120 |
} |
| 2121 |
|
| 2122 |
int qed_cxt_get_tid_mem_info(struct qed_hwfn *p_hwfn, |
| 2123 |
struct qed_tid_mem *p_info) |
| 2124 |
{ |
| 2125 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 2126 |
u32 proto, seg, total_lines, i, shadow_line; |
| 2127 |
struct qed_ilt_client_cfg *p_cli; |
| 2128 |
struct qed_ilt_cli_blk *p_fl_seg; |
| 2129 |
struct qed_tid_seg *p_seg_info; |
| 2130 |
|
| 2131 |
/* Verify the personality */ |
| 2132 |
switch (p_hwfn->hw_info.personality) { |
| 2133 |
case QED_PCI_FCOE: |
| 2134 |
proto = PROTOCOLID_FCOE; |
| 2135 |
seg = QED_CXT_FCOE_TID_SEG; |
| 2136 |
break; |
| 2137 |
case QED_PCI_ISCSI: |
| 2138 |
case QED_PCI_NVMETCP: |
| 2139 |
proto = PROTOCOLID_TCP_ULP; |
| 2140 |
seg = QED_CXT_TCP_ULP_TID_SEG; |
| 2141 |
break; |
| 2142 |
default: |
| 2143 |
return -EINVAL; |
| 2144 |
} |
| 2145 |
|
| 2146 |
p_cli = &p_mngr->clients[ILT_CLI_CDUT]; |
| 2147 |
if (!p_cli->active) |
| 2148 |
return -EINVAL; |
| 2149 |
|
| 2150 |
p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg]; |
| 2151 |
if (!p_seg_info->has_fl_mem) |
| 2152 |
return -EINVAL; |
| 2153 |
|
| 2154 |
p_fl_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)]; |
| 2155 |
total_lines = DIV_ROUND_UP(p_fl_seg->total_size, |
| 2156 |
p_fl_seg->real_size_in_page); |
| 2157 |
|
| 2158 |
for (i = 0; i < total_lines; i++) { |
| 2159 |
shadow_line = i + p_fl_seg->start_line - |
| 2160 |
p_hwfn->p_cxt_mngr->pf_start_line; |
| 2161 |
p_info->blocks[i] = p_mngr->ilt_shadow[shadow_line].virt_addr; |
| 2162 |
} |
| 2163 |
p_info->waste = ILT_PAGE_IN_BYTES(p_cli->p_size.val) - |
| 2164 |
p_fl_seg->real_size_in_page; |
| 2165 |
p_info->tid_size = p_mngr->task_type_size[p_seg_info->type]; |
| 2166 |
p_info->num_tids_per_block = p_fl_seg->real_size_in_page / |
| 2167 |
p_info->tid_size; |
| 2168 |
|
| 2169 |
return 0; |
| 2170 |
} |
| 2171 |
|
| 2172 |
/* This function is very RoCE oriented, if another protocol in the future |
| 2173 |
* will want this feature we'll need to modify the function to be more generic |
| 2174 |
*/ |
| 2175 |
int |
| 2176 |
qed_cxt_dynamic_ilt_alloc(struct qed_hwfn *p_hwfn, |
| 2177 |
enum qed_cxt_elem_type elem_type, u32 iid) |
| 2178 |
{ |
| 2179 |
u32 reg_offset, shadow_line, elem_size, hw_p_size, elems_per_p, line; |
| 2180 |
struct tdif_task_context *tdif_context; |
| 2181 |
struct qed_ilt_client_cfg *p_cli; |
| 2182 |
struct qed_ilt_cli_blk *p_blk; |
| 2183 |
struct qed_ptt *p_ptt; |
| 2184 |
dma_addr_t p_phys; |
| 2185 |
u64 ilt_hw_entry; |
| 2186 |
void *p_virt; |
| 2187 |
u32 flags1; |
| 2188 |
int rc = 0; |
| 2189 |
|
| 2190 |
switch (elem_type) { |
| 2191 |
case QED_ELEM_CXT: |
| 2192 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; |
| 2193 |
elem_size = CONN_CXT_SIZE(p_hwfn); |
| 2194 |
p_blk = &p_cli->pf_blks[CDUC_BLK]; |
| 2195 |
break; |
| 2196 |
case QED_ELEM_SRQ: |
| 2197 |
/* The first ILT page is not used for regular SRQs. Skip it. */ |
| 2198 |
iid += p_hwfn->p_cxt_mngr->xrc_srq_count; |
| 2199 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM]; |
| 2200 |
elem_size = SRQ_CXT_SIZE; |
| 2201 |
p_blk = &p_cli->pf_blks[SRQ_BLK]; |
| 2202 |
break; |
| 2203 |
case QED_ELEM_XRC_SRQ: |
| 2204 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM]; |
| 2205 |
elem_size = XRC_SRQ_CXT_SIZE; |
| 2206 |
p_blk = &p_cli->pf_blks[SRQ_BLK]; |
| 2207 |
break; |
| 2208 |
case QED_ELEM_TASK: |
| 2209 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 2210 |
elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn); |
| 2211 |
p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(QED_CXT_ROCE_TID_SEG)]; |
| 2212 |
break; |
| 2213 |
default: |
| 2214 |
DP_NOTICE(p_hwfn, "-EOPNOTSUPP elem type = %d", elem_type); |
| 2215 |
return -EOPNOTSUPP; |
| 2216 |
} |
| 2217 |
|
| 2218 |
/* Calculate line in ilt */ |
| 2219 |
hw_p_size = p_cli->p_size.val; |
| 2220 |
elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size; |
| 2221 |
line = p_blk->start_line + (iid / elems_per_p); |
| 2222 |
shadow_line = line - p_hwfn->p_cxt_mngr->pf_start_line; |
| 2223 |
|
| 2224 |
/* If line is already allocated, do nothing, otherwise allocate it and |
| 2225 |
* write it to the PSWRQ2 registers. |
| 2226 |
* This section can be run in parallel from different contexts and thus |
| 2227 |
* a mutex protection is needed. |
| 2228 |
*/ |
| 2229 |
|
| 2230 |
mutex_lock(&p_hwfn->p_cxt_mngr->mutex); |
| 2231 |
|
| 2232 |
if (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].virt_addr) |
| 2233 |
goto out0; |
| 2234 |
|
| 2235 |
p_ptt = qed_ptt_acquire(p_hwfn); |
| 2236 |
if (!p_ptt) { |
| 2237 |
DP_NOTICE(p_hwfn, |
| 2238 |
"QED_TIME_OUT on ptt acquire - dynamic allocation"); |
| 2239 |
rc = -EBUSY; |
| 2240 |
goto out0; |
| 2241 |
} |
| 2242 |
|
| 2243 |
p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 2244 |
p_blk->real_size_in_page, &p_phys, |
| 2245 |
GFP_KERNEL); |
| 2246 |
if (!p_virt) { |
| 2247 |
rc = -ENOMEM; |
| 2248 |
goto out1; |
| 2249 |
} |
| 2250 |
|
| 2251 |
/* configuration of refTagMask to 0xF is required for RoCE DIF MR only, |
| 2252 |
* to compensate for a HW bug, but it is configured even if DIF is not |
| 2253 |
* enabled. This is harmless and allows us to avoid a dedicated API. We |
| 2254 |
* configure the field for all of the contexts on the newly allocated |
| 2255 |
* page. |
| 2256 |
*/ |
| 2257 |
if (elem_type == QED_ELEM_TASK) { |
| 2258 |
u32 elem_i; |
| 2259 |
u8 *elem_start = (u8 *)p_virt; |
| 2260 |
union type1_task_context *elem; |
| 2261 |
|
| 2262 |
for (elem_i = 0; elem_i < elems_per_p; elem_i++) { |
| 2263 |
elem = (union type1_task_context *)elem_start; |
| 2264 |
tdif_context = &elem->roce_ctx.tdif_context; |
| 2265 |
|
| 2266 |
flags1 = le32_to_cpu(tdif_context->flags1); |
| 2267 |
SET_FIELD(flags1, TDIF_TASK_CONTEXT_REF_TAG_MASK, 0xf); |
| 2268 |
tdif_context->flags1 = cpu_to_le32(flags1); |
| 2269 |
|
| 2270 |
elem_start += TYPE1_TASK_CXT_SIZE(p_hwfn); |
| 2271 |
} |
| 2272 |
} |
| 2273 |
|
| 2274 |
p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].virt_addr = p_virt; |
| 2275 |
p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].phys_addr = p_phys; |
| 2276 |
p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].size = |
| 2277 |
p_blk->real_size_in_page; |
| 2278 |
|
| 2279 |
/* compute absolute offset */ |
| 2280 |
reg_offset = PSWRQ2_REG_ILT_MEMORY + |
| 2281 |
(line * ILT_REG_SIZE_IN_BYTES * ILT_ENTRY_IN_REGS); |
| 2282 |
|
| 2283 |
ilt_hw_entry = 0; |
| 2284 |
SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL); |
| 2285 |
SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR, |
| 2286 |
(p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].phys_addr |
| 2287 |
>> 12)); |
| 2288 |
|
| 2289 |
/* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a wide-bus */ |
| 2290 |
qed_dmae_host2grc(p_hwfn, p_ptt, (u64) (uintptr_t)&ilt_hw_entry, |
| 2291 |
reg_offset, sizeof(ilt_hw_entry) / sizeof(u32), |
| 2292 |
NULL); |
| 2293 |
|
| 2294 |
if (elem_type == QED_ELEM_CXT) { |
| 2295 |
u32 last_cid_allocated = (1 + (iid / elems_per_p)) * |
| 2296 |
elems_per_p; |
| 2297 |
|
| 2298 |
/* Update the relevant register in the parser */ |
| 2299 |
qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, |
| 2300 |
last_cid_allocated - 1); |
| 2301 |
|
| 2302 |
if (!p_hwfn->b_rdma_enabled_in_prs) { |
| 2303 |
/* Enable RDMA search */ |
| 2304 |
qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1); |
| 2305 |
p_hwfn->b_rdma_enabled_in_prs = true; |
| 2306 |
} |
| 2307 |
} |
| 2308 |
|
| 2309 |
out1: |
| 2310 |
qed_ptt_release(p_hwfn, p_ptt); |
| 2311 |
out0: |
| 2312 |
mutex_unlock(&p_hwfn->p_cxt_mngr->mutex); |
| 2313 |
|
| 2314 |
return rc; |
| 2315 |
} |
| 2316 |
|
| 2317 |
/* This function is very RoCE oriented, if another protocol in the future |
| 2318 |
* will want this feature we'll need to modify the function to be more generic |
| 2319 |
*/ |
| 2320 |
static int |
| 2321 |
qed_cxt_free_ilt_range(struct qed_hwfn *p_hwfn, |
| 2322 |
enum qed_cxt_elem_type elem_type, |
| 2323 |
u32 start_iid, u32 count) |
| 2324 |
{ |
| 2325 |
u32 start_line, end_line, shadow_start_line, shadow_end_line; |
| 2326 |
u32 reg_offset, elem_size, hw_p_size, elems_per_p; |
| 2327 |
struct qed_ilt_client_cfg *p_cli; |
| 2328 |
struct qed_ilt_cli_blk *p_blk; |
| 2329 |
u32 end_iid = start_iid + count; |
| 2330 |
struct qed_ptt *p_ptt; |
| 2331 |
u64 ilt_hw_entry = 0; |
| 2332 |
u32 i; |
| 2333 |
|
| 2334 |
switch (elem_type) { |
| 2335 |
case QED_ELEM_CXT: |
| 2336 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; |
| 2337 |
elem_size = CONN_CXT_SIZE(p_hwfn); |
| 2338 |
p_blk = &p_cli->pf_blks[CDUC_BLK]; |
| 2339 |
break; |
| 2340 |
case QED_ELEM_SRQ: |
| 2341 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM]; |
| 2342 |
elem_size = SRQ_CXT_SIZE; |
| 2343 |
p_blk = &p_cli->pf_blks[SRQ_BLK]; |
| 2344 |
break; |
| 2345 |
case QED_ELEM_XRC_SRQ: |
| 2346 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM]; |
| 2347 |
elem_size = XRC_SRQ_CXT_SIZE; |
| 2348 |
p_blk = &p_cli->pf_blks[SRQ_BLK]; |
| 2349 |
break; |
| 2350 |
case QED_ELEM_TASK: |
| 2351 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 2352 |
elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn); |
| 2353 |
p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(QED_CXT_ROCE_TID_SEG)]; |
| 2354 |
break; |
| 2355 |
default: |
| 2356 |
DP_NOTICE(p_hwfn, "-EINVALID elem type = %d", elem_type); |
| 2357 |
return -EINVAL; |
| 2358 |
} |
| 2359 |
|
| 2360 |
/* Calculate line in ilt */ |
| 2361 |
hw_p_size = p_cli->p_size.val; |
| 2362 |
elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size; |
| 2363 |
start_line = p_blk->start_line + (start_iid / elems_per_p); |
| 2364 |
end_line = p_blk->start_line + (end_iid / elems_per_p); |
| 2365 |
if (((end_iid + 1) / elems_per_p) != (end_iid / elems_per_p)) |
| 2366 |
end_line--; |
| 2367 |
|
| 2368 |
shadow_start_line = start_line - p_hwfn->p_cxt_mngr->pf_start_line; |
| 2369 |
shadow_end_line = end_line - p_hwfn->p_cxt_mngr->pf_start_line; |
| 2370 |
|
| 2371 |
p_ptt = qed_ptt_acquire(p_hwfn); |
| 2372 |
if (!p_ptt) { |
| 2373 |
DP_NOTICE(p_hwfn, |
| 2374 |
"QED_TIME_OUT on ptt acquire - dynamic allocation"); |
| 2375 |
return -EBUSY; |
| 2376 |
} |
| 2377 |
|
| 2378 |
for (i = shadow_start_line; i < shadow_end_line; i++) { |
| 2379 |
if (!p_hwfn->p_cxt_mngr->ilt_shadow[i].virt_addr) |
| 2380 |
continue; |
| 2381 |
|
| 2382 |
dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 2383 |
p_hwfn->p_cxt_mngr->ilt_shadow[i].size, |
| 2384 |
p_hwfn->p_cxt_mngr->ilt_shadow[i].virt_addr, |
| 2385 |
p_hwfn->p_cxt_mngr->ilt_shadow[i].phys_addr); |
| 2386 |
|
| 2387 |
p_hwfn->p_cxt_mngr->ilt_shadow[i].virt_addr = NULL; |
| 2388 |
p_hwfn->p_cxt_mngr->ilt_shadow[i].phys_addr = 0; |
| 2389 |
p_hwfn->p_cxt_mngr->ilt_shadow[i].size = 0; |
| 2390 |
|
| 2391 |
/* compute absolute offset */ |
| 2392 |
reg_offset = PSWRQ2_REG_ILT_MEMORY + |
| 2393 |
((start_line++) * ILT_REG_SIZE_IN_BYTES * |
| 2394 |
ILT_ENTRY_IN_REGS); |
| 2395 |
|
| 2396 |
/* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a |
| 2397 |
* wide-bus. |
| 2398 |
*/ |
| 2399 |
qed_dmae_host2grc(p_hwfn, p_ptt, |
| 2400 |
(u64) (uintptr_t) &ilt_hw_entry, |
| 2401 |
reg_offset, |
| 2402 |
sizeof(ilt_hw_entry) / sizeof(u32), |
| 2403 |
NULL); |
| 2404 |
} |
| 2405 |
|
| 2406 |
qed_ptt_release(p_hwfn, p_ptt); |
| 2407 |
|
| 2408 |
return 0; |
| 2409 |
} |
| 2410 |
|
| 2411 |
int qed_cxt_free_proto_ilt(struct qed_hwfn *p_hwfn, enum protocol_type proto) |
| 2412 |
{ |
| 2413 |
int rc; |
| 2414 |
u32 cid; |
| 2415 |
|
| 2416 |
/* Free Connection CXT */ |
| 2417 |
rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_CXT, |
| 2418 |
qed_cxt_get_proto_cid_start(p_hwfn, |
| 2419 |
proto), |
| 2420 |
qed_cxt_get_proto_cid_count(p_hwfn, |
| 2421 |
proto, &cid)); |
| 2422 |
|
| 2423 |
if (rc) |
| 2424 |
return rc; |
| 2425 |
|
| 2426 |
/* Free Task CXT ( Intentionally RoCE as task-id is shared between |
| 2427 |
* RoCE and iWARP ) |
| 2428 |
*/ |
| 2429 |
proto = PROTOCOLID_ROCE; |
| 2430 |
rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_TASK, 0, |
| 2431 |
qed_cxt_get_proto_tid_count(p_hwfn, proto)); |
| 2432 |
if (rc) |
| 2433 |
return rc; |
| 2434 |
|
| 2435 |
/* Free TSDM CXT */ |
| 2436 |
rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_XRC_SRQ, 0, |
| 2437 |
p_hwfn->p_cxt_mngr->xrc_srq_count); |
| 2438 |
|
| 2439 |
rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_SRQ, |
| 2440 |
p_hwfn->p_cxt_mngr->xrc_srq_count, |
| 2441 |
p_hwfn->p_cxt_mngr->srq_count); |
| 2442 |
|
| 2443 |
return rc; |
| 2444 |
} |
| 2445 |
|
| 2446 |
int qed_cxt_get_task_ctx(struct qed_hwfn *p_hwfn, |
| 2447 |
u32 tid, u8 ctx_type, void **pp_task_ctx) |
| 2448 |
{ |
| 2449 |
struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; |
| 2450 |
struct qed_ilt_client_cfg *p_cli; |
| 2451 |
struct qed_tid_seg *p_seg_info; |
| 2452 |
struct qed_ilt_cli_blk *p_seg; |
| 2453 |
u32 num_tids_per_block; |
| 2454 |
u32 tid_size, ilt_idx; |
| 2455 |
u32 total_lines; |
| 2456 |
u32 proto, seg; |
| 2457 |
|
| 2458 |
/* Verify the personality */ |
| 2459 |
switch (p_hwfn->hw_info.personality) { |
| 2460 |
case QED_PCI_FCOE: |
| 2461 |
proto = PROTOCOLID_FCOE; |
| 2462 |
seg = QED_CXT_FCOE_TID_SEG; |
| 2463 |
break; |
| 2464 |
case QED_PCI_ISCSI: |
| 2465 |
case QED_PCI_NVMETCP: |
| 2466 |
proto = PROTOCOLID_TCP_ULP; |
| 2467 |
seg = QED_CXT_TCP_ULP_TID_SEG; |
| 2468 |
break; |
| 2469 |
default: |
| 2470 |
return -EINVAL; |
| 2471 |
} |
| 2472 |
|
| 2473 |
p_cli = &p_mngr->clients[ILT_CLI_CDUT]; |
| 2474 |
if (!p_cli->active) |
| 2475 |
return -EINVAL; |
| 2476 |
|
| 2477 |
p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg]; |
| 2478 |
|
| 2479 |
if (ctx_type == QED_CTX_WORKING_MEM) { |
| 2480 |
p_seg = &p_cli->pf_blks[CDUT_SEG_BLK(seg)]; |
| 2481 |
} else if (ctx_type == QED_CTX_FL_MEM) { |
| 2482 |
if (!p_seg_info->has_fl_mem) |
| 2483 |
return -EINVAL; |
| 2484 |
p_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)]; |
| 2485 |
} else { |
| 2486 |
return -EINVAL; |
| 2487 |
} |
| 2488 |
total_lines = DIV_ROUND_UP(p_seg->total_size, p_seg->real_size_in_page); |
| 2489 |
tid_size = p_mngr->task_type_size[p_seg_info->type]; |
| 2490 |
num_tids_per_block = p_seg->real_size_in_page / tid_size; |
| 2491 |
|
| 2492 |
if (total_lines < tid / num_tids_per_block) |
| 2493 |
return -EINVAL; |
| 2494 |
|
| 2495 |
ilt_idx = tid / num_tids_per_block + p_seg->start_line - |
| 2496 |
p_mngr->pf_start_line; |
| 2497 |
*pp_task_ctx = (u8 *)p_mngr->ilt_shadow[ilt_idx].virt_addr + |
| 2498 |
(tid % num_tids_per_block) * tid_size; |
| 2499 |
|
| 2500 |
return 0; |
| 2501 |
} |
| 2502 |
|
| 2503 |
static u16 qed_blk_calculate_pages(struct qed_ilt_cli_blk *p_blk) |
| 2504 |
{ |
| 2505 |
if (p_blk->real_size_in_page == 0) |
| 2506 |
return 0; |
| 2507 |
|
| 2508 |
return DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page); |
| 2509 |
} |
| 2510 |
|
| 2511 |
u16 qed_get_cdut_num_pf_init_pages(struct qed_hwfn *p_hwfn) |
| 2512 |
{ |
| 2513 |
struct qed_ilt_client_cfg *p_cli; |
| 2514 |
struct qed_ilt_cli_blk *p_blk; |
| 2515 |
u16 i, pages = 0; |
| 2516 |
|
| 2517 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 2518 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 2519 |
p_blk = &p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)]; |
| 2520 |
pages += qed_blk_calculate_pages(p_blk); |
| 2521 |
} |
| 2522 |
|
| 2523 |
return pages; |
| 2524 |
} |
| 2525 |
|
| 2526 |
u16 qed_get_cdut_num_vf_init_pages(struct qed_hwfn *p_hwfn) |
| 2527 |
{ |
| 2528 |
struct qed_ilt_client_cfg *p_cli; |
| 2529 |
struct qed_ilt_cli_blk *p_blk; |
| 2530 |
u16 i, pages = 0; |
| 2531 |
|
| 2532 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 2533 |
for (i = 0; i < NUM_TASK_VF_SEGMENTS; i++) { |
| 2534 |
p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(i, VF)]; |
| 2535 |
pages += qed_blk_calculate_pages(p_blk); |
| 2536 |
} |
| 2537 |
|
| 2538 |
return pages; |
| 2539 |
} |
| 2540 |
|
| 2541 |
u16 qed_get_cdut_num_pf_work_pages(struct qed_hwfn *p_hwfn) |
| 2542 |
{ |
| 2543 |
struct qed_ilt_client_cfg *p_cli; |
| 2544 |
struct qed_ilt_cli_blk *p_blk; |
| 2545 |
u16 i, pages = 0; |
| 2546 |
|
| 2547 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 2548 |
for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { |
| 2549 |
p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(i)]; |
| 2550 |
pages += qed_blk_calculate_pages(p_blk); |
| 2551 |
} |
| 2552 |
|
| 2553 |
return pages; |
| 2554 |
} |
| 2555 |
|
| 2556 |
u16 qed_get_cdut_num_vf_work_pages(struct qed_hwfn *p_hwfn) |
| 2557 |
{ |
| 2558 |
struct qed_ilt_client_cfg *p_cli; |
| 2559 |
struct qed_ilt_cli_blk *p_blk; |
| 2560 |
u16 pages = 0, i; |
| 2561 |
|
| 2562 |
p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; |
| 2563 |
for (i = 0; i < NUM_TASK_VF_SEGMENTS; i++) { |
| 2564 |
p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(i)]; |
| 2565 |
pages += qed_blk_calculate_pages(p_blk); |
| 2566 |
} |
| 2567 |
|
| 2568 |
return pages; |
| 2569 |
} |