2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
11 #include "ecore_hsi_common.h"
12 #include "ecore_hsi_eth.h"
13 #include "ecore_rt_defs.h"
14 #include "ecore_status.h"
16 #include "ecore_init_ops.h"
17 #include "ecore_init_fw_funcs.h"
18 #include "ecore_cxt.h"
20 #include "ecore_dev_api.h"
21 #include "ecore_sriov.h"
22 #include "ecore_mcp.h"
24 /* Max number of connection types in HW (DQ/CDU etc.) */
25 #define MAX_CONN_TYPES PROTOCOLID_COMMON
26 #define NUM_TASK_TYPES 2
27 #define NUM_TASK_PF_SEGMENTS 4
28 #define NUM_TASK_VF_SEGMENTS 1
30 /* Doorbell-Queue constants */
31 #define DQ_RANGE_SHIFT 4
32 #define DQ_RANGE_ALIGN (1 << DQ_RANGE_SHIFT)
34 /* Searcher constants */
35 #define SRC_MIN_NUM_ELEMS 256
37 /* Timers constants */
39 #define TM_ALIGN (1 << TM_SHIFT)
40 #define TM_ELEM_SIZE 4
43 /* If for some reason, HW P size is modified to be less than 32K,
44 * special handling needs to be made for CDU initialization
46 #define ILT_DEFAULT_HW_P_SIZE 3
48 #define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12))
49 #define ILT_CFG_REG(cli, reg) PSWRQ2_REG_##cli##_##reg##_RT_OFFSET
51 /* ILT entry structure */
52 #define ILT_ENTRY_PHY_ADDR_MASK 0x000FFFFFFFFFFFULL
53 #define ILT_ENTRY_PHY_ADDR_SHIFT 0
54 #define ILT_ENTRY_VALID_MASK 0x1ULL
55 #define ILT_ENTRY_VALID_SHIFT 52
56 #define ILT_ENTRY_IN_REGS 2
57 #define ILT_REG_SIZE_IN_BYTES 4
59 /* connection context union */
61 struct core_conn_context core_ctx;
62 struct eth_conn_context eth_ctx;
65 /* TYPE-0 task context - iSCSI, FCOE */
66 union type0_task_context {
69 /* TYPE-1 task context - ROCE */
70 union type1_task_context {
78 #define CDUT_SEG_ALIGNMET 3 /* in 4k chunks */
79 #define CDUT_SEG_ALIGNMET_IN_BYTES (1 << (CDUT_SEG_ALIGNMET + 12))
81 #define CONN_CXT_SIZE(p_hwfn) \
82 ALIGNED_TYPE_SIZE(union conn_context, p_hwfn)
84 #define SRQ_CXT_SIZE (sizeof(struct regpair) * 8) /* @DPDK */
86 #define TYPE0_TASK_CXT_SIZE(p_hwfn) \
87 ALIGNED_TYPE_SIZE(union type0_task_context, p_hwfn)
89 /* Alignment is inherent to the type1_task_context structure */
90 #define TYPE1_TASK_CXT_SIZE(p_hwfn) sizeof(union type1_task_context)
92 /* PF per protocl configuration object */
93 #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
94 #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
96 struct ecore_tid_seg {
102 struct ecore_conn_type_cfg {
106 struct ecore_tid_seg tid_seg[TASK_SEGMENTS];
109 /* ILT Client configuration,
110 * Per connection type (protocol) resources (cids, tis, vf cids etc.)
111 * 1 - for connection context (CDUC) and for each task context we need two
112 * values, for regular task context and for force load memory
114 #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2)
115 #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2)
118 #define CDUT_SEG_BLK(n) (1 + (u8)(n))
119 #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_##X##_SEGMENTS)
131 struct ilt_cfg_pair {
136 struct ecore_ilt_cli_blk {
137 u32 total_size; /* 0 means not active */
138 u32 real_size_in_page;
140 u32 dynamic_line_cnt;
143 struct ecore_ilt_client_cfg {
147 struct ilt_cfg_pair first;
148 struct ilt_cfg_pair last;
149 struct ilt_cfg_pair p_size;
151 /* ILT client blocks for PF */
152 struct ecore_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS];
155 /* ILT client blocks for VFs */
156 struct ecore_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS];
162 * Protocol acquired CID lists
163 * PF start line in ILT
165 struct ecore_dma_mem {
171 #define MAP_WORD_SIZE sizeof(unsigned long)
172 #define BITS_PER_MAP_WORD (MAP_WORD_SIZE * 8)
174 struct ecore_cid_acquired_map {
177 unsigned long *cid_map;
180 struct ecore_cxt_mngr {
181 /* Per protocl configuration */
182 struct ecore_conn_type_cfg conn_cfg[MAX_CONN_TYPES];
184 /* computed ILT structure */
185 struct ecore_ilt_client_cfg clients[ILT_CLI_MAX];
187 /* Task type sizes */
188 u32 task_type_size[NUM_TASK_TYPES];
190 /* total number of VFs for this hwfn -
191 * ALL VFs are symmetric in terms of HW resources
195 /* total number of SRQ's for this hwfn */
199 struct ecore_cid_acquired_map acquired[MAX_CONN_TYPES];
201 /* ILT shadow table */
202 struct ecore_dma_mem *ilt_shadow;
205 /* Mutex for a dynamic ILT allocation */
209 struct ecore_dma_mem *t2;
215 /* check if resources/configuration is required according to protocol type */
216 static OSAL_INLINE bool src_proto(enum protocol_type type)
218 return type == PROTOCOLID_TOE;
221 static OSAL_INLINE bool tm_cid_proto(enum protocol_type type)
223 return type == PROTOCOLID_TOE;
226 static bool tm_tid_proto(enum protocol_type type)
228 return type == PROTOCOLID_FCOE;
231 /* counts the iids for the CDU/CDUC ILT client configuration */
232 struct ecore_cdu_iids {
237 static void ecore_cxt_cdu_iids(struct ecore_cxt_mngr *p_mngr,
238 struct ecore_cdu_iids *iids)
242 for (type = 0; type < MAX_CONN_TYPES; type++) {
243 iids->pf_cids += p_mngr->conn_cfg[type].cid_count;
244 iids->per_vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
248 /* counts the iids for the Searcher block configuration */
249 struct ecore_src_iids {
254 static OSAL_INLINE void ecore_cxt_src_iids(struct ecore_cxt_mngr *p_mngr,
255 struct ecore_src_iids *iids)
259 for (i = 0; i < MAX_CONN_TYPES; i++) {
263 iids->pf_cids += p_mngr->conn_cfg[i].cid_count;
264 iids->per_vf_cids += p_mngr->conn_cfg[i].cids_per_vf;
268 /* counts the iids for the Timers block configuration */
269 struct ecore_tm_iids {
271 u32 pf_tids[NUM_TASK_PF_SEGMENTS]; /* per segment */
277 static OSAL_INLINE void ecore_cxt_tm_iids(struct ecore_cxt_mngr *p_mngr,
278 struct ecore_tm_iids *iids)
280 bool tm_vf_required = false;
281 bool tm_required = false;
284 for (i = 0; i < MAX_CONN_TYPES; i++) {
285 struct ecore_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[i];
287 if (tm_cid_proto(i) || tm_required) {
288 if (p_cfg->cid_count)
291 iids->pf_cids += p_cfg->cid_count;
294 if (tm_cid_proto(i) || tm_vf_required) {
295 if (p_cfg->cids_per_vf)
296 tm_vf_required = true;
300 if (tm_tid_proto(i)) {
301 struct ecore_tid_seg *segs = p_cfg->tid_seg;
303 /* for each segment there is at most one
304 * protocol for which count is not 0.
306 for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
307 iids->pf_tids[j] += segs[j].count;
309 /* The last array elelment is for the VFs. As for PF
310 * segments there can be only one protocol for
311 * which this value is not 0.
313 iids->per_vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
317 iids->pf_cids = ROUNDUP(iids->pf_cids, TM_ALIGN);
318 iids->per_vf_cids = ROUNDUP(iids->per_vf_cids, TM_ALIGN);
319 iids->per_vf_tids = ROUNDUP(iids->per_vf_tids, TM_ALIGN);
321 for (iids->pf_tids_total = 0, j = 0; j < NUM_TASK_PF_SEGMENTS; j++) {
322 iids->pf_tids[j] = ROUNDUP(iids->pf_tids[j], TM_ALIGN);
323 iids->pf_tids_total += iids->pf_tids[j];
327 void ecore_cxt_qm_iids(struct ecore_hwfn *p_hwfn, struct ecore_qm_iids *iids)
329 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
330 struct ecore_tid_seg *segs;
331 u32 vf_cids = 0, type, j;
334 for (type = 0; type < MAX_CONN_TYPES; type++) {
335 iids->cids += p_mngr->conn_cfg[type].cid_count;
336 vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
338 segs = p_mngr->conn_cfg[type].tid_seg;
339 /* for each segment there is at most one
340 * protocol for which count is not 0.
342 for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
343 iids->tids += segs[j].count;
345 /* The last array elelment is for the VFs. As for PF
346 * segments there can be only one protocol for
347 * which this value is not 0.
349 vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
352 iids->vf_cids += vf_cids * p_mngr->vf_count;
353 iids->tids += vf_tids * p_mngr->vf_count;
355 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
356 "iids: CIDS %08x vf_cids %08x tids %08x vf_tids %08x\n",
357 iids->cids, iids->vf_cids, iids->tids, vf_tids);
360 static struct ecore_tid_seg *ecore_cxt_tid_seg_info(struct ecore_hwfn *p_hwfn,
363 struct ecore_cxt_mngr *p_cfg = p_hwfn->p_cxt_mngr;
366 /* Find the protocol with tid count > 0 for this segment.
367 * Note: there can only be one and this is already validated.
369 for (i = 0; i < MAX_CONN_TYPES; i++) {
370 if (p_cfg->conn_cfg[i].tid_seg[seg].count)
371 return &p_cfg->conn_cfg[i].tid_seg[seg];
376 /* set the iids (cid/tid) count per protocol */
377 static void ecore_cxt_set_proto_cid_count(struct ecore_hwfn *p_hwfn,
378 enum protocol_type type,
379 u32 cid_count, u32 vf_cid_cnt)
381 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
382 struct ecore_conn_type_cfg *p_conn = &p_mgr->conn_cfg[type];
384 p_conn->cid_count = ROUNDUP(cid_count, DQ_RANGE_ALIGN);
385 p_conn->cids_per_vf = ROUNDUP(vf_cid_cnt, DQ_RANGE_ALIGN);
388 u32 ecore_cxt_get_proto_cid_count(struct ecore_hwfn *p_hwfn,
389 enum protocol_type type, u32 *vf_cid)
392 *vf_cid = p_hwfn->p_cxt_mngr->conn_cfg[type].cids_per_vf;
394 return p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count;
397 u32 ecore_cxt_get_proto_cid_start(struct ecore_hwfn *p_hwfn,
398 enum protocol_type type)
400 return p_hwfn->p_cxt_mngr->acquired[type].start_cid;
403 u32 ecore_cxt_get_proto_tid_count(struct ecore_hwfn *p_hwfn,
404 enum protocol_type type)
409 for (i = 0; i < TASK_SEGMENTS; i++)
410 cnt += p_hwfn->p_cxt_mngr->conn_cfg[type].tid_seg[i].count;
415 static OSAL_INLINE void
416 ecore_cxt_set_proto_tid_count(struct ecore_hwfn *p_hwfn,
417 enum protocol_type proto,
418 u8 seg, u8 seg_type, u32 count, bool has_fl)
420 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
421 struct ecore_tid_seg *p_seg = &p_mngr->conn_cfg[proto].tid_seg[seg];
423 p_seg->count = count;
424 p_seg->has_fl_mem = has_fl;
425 p_seg->type = seg_type;
428 /* the *p_line parameter must be either 0 for the first invocation or the
429 * value returned in the previous invocation.
431 static void ecore_ilt_cli_blk_fill(struct ecore_ilt_client_cfg *p_cli,
432 struct ecore_ilt_cli_blk *p_blk,
434 u32 total_size, u32 elem_size)
436 u32 ilt_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val);
438 /* verify that it's called once for each block */
439 if (p_blk->total_size)
442 p_blk->total_size = total_size;
443 p_blk->real_size_in_page = 0;
445 p_blk->real_size_in_page = (ilt_size / elem_size) * elem_size;
446 p_blk->start_line = start_line;
449 static void ecore_ilt_cli_adv_line(struct ecore_hwfn *p_hwfn,
450 struct ecore_ilt_client_cfg *p_cli,
451 struct ecore_ilt_cli_blk *p_blk,
452 u32 *p_line, enum ilt_clients client_id)
454 if (!p_blk->total_size)
458 p_cli->first.val = *p_line;
460 p_cli->active = true;
461 *p_line += DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page);
462 p_cli->last.val = *p_line - 1;
464 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
465 "ILT[Client %d] - Lines: [%08x - %08x]. Block - Size %08x"
466 " [Real %08x] Start line %d\n",
467 client_id, p_cli->first.val, p_cli->last.val,
468 p_blk->total_size, p_blk->real_size_in_page,
472 static u32 ecore_ilt_get_dynamic_line_cnt(struct ecore_hwfn *p_hwfn,
473 enum ilt_clients ilt_client)
475 u32 cid_count = p_hwfn->p_cxt_mngr->conn_cfg[PROTOCOLID_ROCE].cid_count;
476 struct ecore_ilt_client_cfg *p_cli;
477 u32 lines_to_skip = 0;
480 /* TBD MK: ILT code should be simplified once PROTO enum is changed */
482 if (ilt_client == ILT_CLI_CDUC) {
483 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
485 cxts_per_p = ILT_PAGE_IN_BYTES(p_cli->p_size.val) /
486 (u32)CONN_CXT_SIZE(p_hwfn);
488 lines_to_skip = cid_count / cxts_per_p;
491 return lines_to_skip;
494 enum _ecore_status_t ecore_cxt_cfg_ilt_compute(struct ecore_hwfn *p_hwfn)
496 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
497 u32 curr_line, total, i, task_size, line;
498 struct ecore_ilt_client_cfg *p_cli;
499 struct ecore_ilt_cli_blk *p_blk;
500 struct ecore_cdu_iids cdu_iids;
501 struct ecore_src_iids src_iids;
502 struct ecore_qm_iids qm_iids;
503 struct ecore_tm_iids tm_iids;
504 struct ecore_tid_seg *p_seg;
506 OSAL_MEM_ZERO(&qm_iids, sizeof(qm_iids));
507 OSAL_MEM_ZERO(&cdu_iids, sizeof(cdu_iids));
508 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
509 OSAL_MEM_ZERO(&tm_iids, sizeof(tm_iids));
511 p_mngr->pf_start_line = RESC_START(p_hwfn, ECORE_ILT);
513 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
514 "hwfn [%d] - Set context mngr starting line to be 0x%08x\n",
515 p_hwfn->my_id, p_hwfn->p_cxt_mngr->pf_start_line);
518 p_cli = &p_mngr->clients[ILT_CLI_CDUC];
520 curr_line = p_mngr->pf_start_line;
523 p_cli->pf_total_lines = 0;
525 /* get the counters for the CDUC,CDUC and QM clients */
526 ecore_cxt_cdu_iids(p_mngr, &cdu_iids);
528 p_blk = &p_cli->pf_blks[CDUC_BLK];
530 total = cdu_iids.pf_cids * CONN_CXT_SIZE(p_hwfn);
532 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
533 total, CONN_CXT_SIZE(p_hwfn));
535 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
536 p_cli->pf_total_lines = curr_line - p_blk->start_line;
538 p_blk->dynamic_line_cnt = ecore_ilt_get_dynamic_line_cnt(p_hwfn,
542 p_blk = &p_cli->vf_blks[CDUC_BLK];
543 total = cdu_iids.per_vf_cids * CONN_CXT_SIZE(p_hwfn);
545 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
546 total, CONN_CXT_SIZE(p_hwfn));
548 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
549 p_cli->vf_total_lines = curr_line - p_blk->start_line;
551 for (i = 1; i < p_mngr->vf_count; i++)
552 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
556 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
557 p_cli->first.val = curr_line;
559 /* first the 'working' task memory */
560 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
561 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
562 if (!p_seg || p_seg->count == 0)
565 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(i)];
566 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
567 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total,
568 p_mngr->task_type_size[p_seg->type]);
570 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
574 /* next the 'init' task memory (forced load memory) */
575 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
576 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
577 if (!p_seg || p_seg->count == 0)
580 p_blk = &p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)];
582 if (!p_seg->has_fl_mem) {
583 /* The segment is active (total size pf 'working'
584 * memory is > 0) but has no FL (forced-load, Init)
587 * 1. The total-size in the corrsponding FL block of
588 * the ILT client is set to 0 - No ILT line are
589 * provisioned and no ILT memory allocated.
591 * 2. The start-line of said block is set to the
592 * start line of the matching working memory
593 * block in the ILT client. This is later used to
594 * configure the CDU segment offset registers and
595 * results in an FL command for TIDs of this
596 * segment behaves as regular load commands
597 * (loading TIDs from the working memory).
599 line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line;
601 ecore_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
604 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
606 ecore_ilt_cli_blk_fill(p_cli, p_blk,
608 p_mngr->task_type_size[p_seg->type]);
610 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
613 p_cli->pf_total_lines = curr_line - p_cli->pf_blks[0].start_line;
616 p_seg = ecore_cxt_tid_seg_info(p_hwfn, TASK_SEGMENT_VF);
617 if (p_seg && p_seg->count) {
618 /* Stricly speaking we need to iterate over all VF
619 * task segment types, but a VF has only 1 segment
622 /* 'working' memory */
623 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
625 p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)];
626 ecore_ilt_cli_blk_fill(p_cli, p_blk,
628 p_mngr->task_type_size[p_seg->type]);
630 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
634 p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)];
635 if (!p_seg->has_fl_mem) {
636 /* see comment above */
637 line = p_cli->vf_blks[CDUT_SEG_BLK(0)].start_line;
638 ecore_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
640 task_size = p_mngr->task_type_size[p_seg->type];
641 ecore_ilt_cli_blk_fill(p_cli, p_blk,
642 curr_line, total, task_size);
643 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
646 p_cli->vf_total_lines = curr_line -
647 p_cli->vf_blks[0].start_line;
649 /* Now for the rest of the VFs */
650 for (i = 1; i < p_mngr->vf_count; i++) {
651 p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)];
652 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
655 p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)];
656 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
662 p_cli = &p_mngr->clients[ILT_CLI_QM];
663 p_blk = &p_cli->pf_blks[0];
665 ecore_cxt_qm_iids(p_hwfn, &qm_iids);
666 total = ecore_qm_pf_mem_size(p_hwfn->rel_pf_id, qm_iids.cids,
667 qm_iids.vf_cids, qm_iids.tids,
668 p_hwfn->qm_info.num_pqs,
669 p_hwfn->qm_info.num_vf_pqs);
671 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
672 "QM ILT Info, (cids=%d, vf_cids=%d, tids=%d, num_pqs=%d,"
673 " num_vf_pqs=%d, memory_size=%d)\n",
674 qm_iids.cids, qm_iids.vf_cids, qm_iids.tids,
675 p_hwfn->qm_info.num_pqs, p_hwfn->qm_info.num_vf_pqs, total);
677 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total * 0x1000,
680 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_QM);
681 p_cli->pf_total_lines = curr_line - p_blk->start_line;
684 p_cli = &p_mngr->clients[ILT_CLI_SRC];
685 ecore_cxt_src_iids(p_mngr, &src_iids);
687 /* Both the PF and VFs searcher connections are stored in the per PF
688 * database. Thus sum the PF searcher cids and all the VFs searcher
691 total = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
693 u32 local_max = OSAL_MAX_T(u32, total,
696 total = OSAL_ROUNDUP_POW_OF_TWO(local_max);
698 p_blk = &p_cli->pf_blks[0];
699 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
700 total * sizeof(struct src_ent),
701 sizeof(struct src_ent));
703 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
705 p_cli->pf_total_lines = curr_line - p_blk->start_line;
709 p_cli = &p_mngr->clients[ILT_CLI_TM];
710 ecore_cxt_tm_iids(p_mngr, &tm_iids);
711 total = tm_iids.pf_cids + tm_iids.pf_tids_total;
713 p_blk = &p_cli->pf_blks[0];
714 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
715 total * TM_ELEM_SIZE, TM_ELEM_SIZE);
717 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
719 p_cli->pf_total_lines = curr_line - p_blk->start_line;
723 total = tm_iids.per_vf_cids + tm_iids.per_vf_tids;
725 p_blk = &p_cli->vf_blks[0];
726 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
727 total * TM_ELEM_SIZE, TM_ELEM_SIZE);
729 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
732 p_cli->vf_total_lines = curr_line - p_blk->start_line;
733 for (i = 1; i < p_mngr->vf_count; i++) {
734 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
739 /* TSDM (SRQ CONTEXT) */
740 total = ecore_cxt_get_srq_count(p_hwfn);
743 p_cli = &p_mngr->clients[ILT_CLI_TSDM];
744 p_blk = &p_cli->pf_blks[SRQ_BLK];
745 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
746 total * SRQ_CXT_SIZE, SRQ_CXT_SIZE);
748 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
750 p_cli->pf_total_lines = curr_line - p_blk->start_line;
753 if (curr_line - p_hwfn->p_cxt_mngr->pf_start_line >
754 RESC_NUM(p_hwfn, ECORE_ILT)) {
755 DP_ERR(p_hwfn, "too many ilt lines...#lines=%d\n",
756 curr_line - p_hwfn->p_cxt_mngr->pf_start_line);
760 return ECORE_SUCCESS;
763 static void ecore_cxt_src_t2_free(struct ecore_hwfn *p_hwfn)
765 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
771 for (i = 0; i < p_mngr->t2_num_pages; i++)
772 if (p_mngr->t2[i].p_virt)
773 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
774 p_mngr->t2[i].p_virt,
775 p_mngr->t2[i].p_phys,
778 OSAL_FREE(p_hwfn->p_dev, p_mngr->t2);
781 static enum _ecore_status_t ecore_cxt_src_t2_alloc(struct ecore_hwfn *p_hwfn)
783 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
784 u32 conn_num, total_size, ent_per_page, psz, i;
785 struct ecore_ilt_client_cfg *p_src;
786 struct ecore_src_iids src_iids;
787 struct ecore_dma_mem *p_t2;
788 enum _ecore_status_t rc;
790 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
792 /* if the SRC ILT client is inactive - there are no connection
793 * requiring the searcer, leave.
795 p_src = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_SRC];
797 return ECORE_SUCCESS;
799 ecore_cxt_src_iids(p_mngr, &src_iids);
800 conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
801 total_size = conn_num * sizeof(struct src_ent);
803 /* use the same page size as the SRC ILT client */
804 psz = ILT_PAGE_IN_BYTES(p_src->p_size.val);
805 p_mngr->t2_num_pages = DIV_ROUND_UP(total_size, psz);
808 p_mngr->t2 = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
809 p_mngr->t2_num_pages *
810 sizeof(struct ecore_dma_mem));
812 DP_NOTICE(p_hwfn, true, "Failed to allocate t2 table\n");
817 /* allocate t2 pages */
818 for (i = 0; i < p_mngr->t2_num_pages; i++) {
819 u32 size = OSAL_MIN_T(u32, total_size, psz);
820 void **p_virt = &p_mngr->t2[i].p_virt;
822 *p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
823 &p_mngr->t2[i].p_phys, size);
824 if (!p_mngr->t2[i].p_virt) {
828 OSAL_MEM_ZERO(*p_virt, size);
829 p_mngr->t2[i].size = size;
833 /* Set the t2 pointers */
835 /* entries per page - must be a power of two */
836 ent_per_page = psz / sizeof(struct src_ent);
838 p_mngr->first_free = (u64)p_mngr->t2[0].p_phys;
840 p_t2 = &p_mngr->t2[(conn_num - 1) / ent_per_page];
841 p_mngr->last_free = (u64)p_t2->p_phys +
842 ((conn_num - 1) & (ent_per_page - 1)) * sizeof(struct src_ent);
844 for (i = 0; i < p_mngr->t2_num_pages; i++) {
845 u32 ent_num = OSAL_MIN_T(u32, ent_per_page, conn_num);
846 struct src_ent *entries = p_mngr->t2[i].p_virt;
847 u64 p_ent_phys = (u64)p_mngr->t2[i].p_phys, val;
850 for (j = 0; j < ent_num - 1; j++) {
851 val = p_ent_phys + (j + 1) * sizeof(struct src_ent);
852 entries[j].next = OSAL_CPU_TO_BE64(val);
855 if (i < p_mngr->t2_num_pages - 1)
856 val = (u64)p_mngr->t2[i + 1].p_phys;
859 entries[j].next = OSAL_CPU_TO_BE64(val);
864 return ECORE_SUCCESS;
867 ecore_cxt_src_t2_free(p_hwfn);
871 #define for_each_ilt_valid_client(pos, clients) \
872 for (pos = 0; pos < ILT_CLI_MAX; pos++) \
873 if (!clients[pos].active) { \
878 /* Total number of ILT lines used by this PF */
879 static u32 ecore_cxt_ilt_shadow_size(struct ecore_ilt_client_cfg *ilt_clients)
884 for_each_ilt_valid_client(i, ilt_clients)
885 size += (ilt_clients[i].last.val -
886 ilt_clients[i].first.val + 1);
891 static void ecore_ilt_shadow_free(struct ecore_hwfn *p_hwfn)
893 struct ecore_ilt_client_cfg *p_cli = p_hwfn->p_cxt_mngr->clients;
894 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
897 ilt_size = ecore_cxt_ilt_shadow_size(p_cli);
899 for (i = 0; p_mngr->ilt_shadow && i < ilt_size; i++) {
900 struct ecore_dma_mem *p_dma = &p_mngr->ilt_shadow[i];
903 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
905 p_dma->p_phys, p_dma->size);
906 p_dma->p_virt = OSAL_NULL;
908 OSAL_FREE(p_hwfn->p_dev, p_mngr->ilt_shadow);
911 static enum _ecore_status_t
912 ecore_ilt_blk_alloc(struct ecore_hwfn *p_hwfn,
913 struct ecore_ilt_cli_blk *p_blk,
914 enum ilt_clients ilt_client, u32 start_line_offset)
916 struct ecore_dma_mem *ilt_shadow = p_hwfn->p_cxt_mngr->ilt_shadow;
917 u32 lines, line, sz_left, lines_to_skip = 0;
919 /* Special handling for RoCE that supports dynamic allocation */
920 if (ilt_client == ILT_CLI_CDUT || ilt_client == ILT_CLI_TSDM)
921 return ECORE_SUCCESS;
923 lines_to_skip = p_blk->dynamic_line_cnt;
925 if (!p_blk->total_size)
926 return ECORE_SUCCESS;
928 sz_left = p_blk->total_size;
929 lines = DIV_ROUND_UP(sz_left, p_blk->real_size_in_page) - lines_to_skip;
930 line = p_blk->start_line + start_line_offset -
931 p_hwfn->p_cxt_mngr->pf_start_line + lines_to_skip;
933 for (; lines; lines--) {
938 size = OSAL_MIN_T(u32, sz_left, p_blk->real_size_in_page);
941 #define ILT_BLOCK_ALIGN_SIZE 0x1000
942 p_virt = OSAL_DMA_ALLOC_COHERENT_ALIGNED(p_hwfn->p_dev,
944 ILT_BLOCK_ALIGN_SIZE);
947 OSAL_MEM_ZERO(p_virt, size);
949 ilt_shadow[line].p_phys = p_phys;
950 ilt_shadow[line].p_virt = p_virt;
951 ilt_shadow[line].size = size;
953 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
954 "ILT shadow: Line [%d] Physical 0x%lx"
955 " Virtual %p Size %d\n",
956 line, (unsigned long)p_phys, p_virt, size);
962 return ECORE_SUCCESS;
965 static enum _ecore_status_t ecore_ilt_shadow_alloc(struct ecore_hwfn *p_hwfn)
967 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
968 struct ecore_ilt_client_cfg *clients = p_mngr->clients;
969 struct ecore_ilt_cli_blk *p_blk;
971 enum _ecore_status_t rc;
973 size = ecore_cxt_ilt_shadow_size(clients);
974 p_mngr->ilt_shadow = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
975 size * sizeof(struct ecore_dma_mem));
977 if (!p_mngr->ilt_shadow) {
978 DP_NOTICE(p_hwfn, true,
979 "Failed to allocate ilt shadow table\n");
981 goto ilt_shadow_fail;
984 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
985 "Allocated 0x%x bytes for ilt shadow\n",
986 (u32)(size * sizeof(struct ecore_dma_mem)));
988 for_each_ilt_valid_client(i, clients) {
989 for (j = 0; j < ILT_CLI_PF_BLOCKS; j++) {
990 p_blk = &clients[i].pf_blks[j];
991 rc = ecore_ilt_blk_alloc(p_hwfn, p_blk, i, 0);
992 if (rc != ECORE_SUCCESS)
993 goto ilt_shadow_fail;
995 for (k = 0; k < p_mngr->vf_count; k++) {
996 for (j = 0; j < ILT_CLI_VF_BLOCKS; j++) {
997 u32 lines = clients[i].vf_total_lines * k;
999 p_blk = &clients[i].vf_blks[j];
1000 rc = ecore_ilt_blk_alloc(p_hwfn, p_blk,
1002 if (rc != ECORE_SUCCESS)
1003 goto ilt_shadow_fail;
1008 return ECORE_SUCCESS;
1011 ecore_ilt_shadow_free(p_hwfn);
1015 static void ecore_cid_map_free(struct ecore_hwfn *p_hwfn)
1017 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1020 for (type = 0; type < MAX_CONN_TYPES; type++) {
1021 OSAL_FREE(p_hwfn->p_dev, p_mngr->acquired[type].cid_map);
1022 p_mngr->acquired[type].max_count = 0;
1023 p_mngr->acquired[type].start_cid = 0;
1027 static enum _ecore_status_t ecore_cid_map_alloc(struct ecore_hwfn *p_hwfn)
1029 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1033 for (type = 0; type < MAX_CONN_TYPES; type++) {
1034 u32 cid_cnt = p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count;
1040 size = MAP_WORD_SIZE * DIV_ROUND_UP(cid_cnt, BITS_PER_MAP_WORD);
1041 p_mngr->acquired[type].cid_map = OSAL_ZALLOC(p_hwfn->p_dev,
1043 if (!p_mngr->acquired[type].cid_map)
1046 p_mngr->acquired[type].max_count = cid_cnt;
1047 p_mngr->acquired[type].start_cid = start_cid;
1049 p_hwfn->p_cxt_mngr->conn_cfg[type].cid_start = start_cid;
1051 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
1052 "Type %08x start: %08x count %08x\n",
1053 type, p_mngr->acquired[type].start_cid,
1054 p_mngr->acquired[type].max_count);
1055 start_cid += cid_cnt;
1058 return ECORE_SUCCESS;
1061 ecore_cid_map_free(p_hwfn);
1065 enum _ecore_status_t ecore_cxt_mngr_alloc(struct ecore_hwfn *p_hwfn)
1067 struct ecore_ilt_client_cfg *clients;
1068 struct ecore_cxt_mngr *p_mngr;
1071 p_mngr = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_mngr));
1073 DP_NOTICE(p_hwfn, true,
1074 "Failed to allocate `struct ecore_cxt_mngr'\n");
1078 /* Initialize ILT client registers */
1079 clients = p_mngr->clients;
1080 clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT);
1081 clients[ILT_CLI_CDUC].last.reg = ILT_CFG_REG(CDUC, LAST_ILT);
1082 clients[ILT_CLI_CDUC].p_size.reg = ILT_CFG_REG(CDUC, P_SIZE);
1084 clients[ILT_CLI_QM].first.reg = ILT_CFG_REG(QM, FIRST_ILT);
1085 clients[ILT_CLI_QM].last.reg = ILT_CFG_REG(QM, LAST_ILT);
1086 clients[ILT_CLI_QM].p_size.reg = ILT_CFG_REG(QM, P_SIZE);
1088 clients[ILT_CLI_TM].first.reg = ILT_CFG_REG(TM, FIRST_ILT);
1089 clients[ILT_CLI_TM].last.reg = ILT_CFG_REG(TM, LAST_ILT);
1090 clients[ILT_CLI_TM].p_size.reg = ILT_CFG_REG(TM, P_SIZE);
1092 clients[ILT_CLI_SRC].first.reg = ILT_CFG_REG(SRC, FIRST_ILT);
1093 clients[ILT_CLI_SRC].last.reg = ILT_CFG_REG(SRC, LAST_ILT);
1094 clients[ILT_CLI_SRC].p_size.reg = ILT_CFG_REG(SRC, P_SIZE);
1096 clients[ILT_CLI_CDUT].first.reg = ILT_CFG_REG(CDUT, FIRST_ILT);
1097 clients[ILT_CLI_CDUT].last.reg = ILT_CFG_REG(CDUT, LAST_ILT);
1098 clients[ILT_CLI_CDUT].p_size.reg = ILT_CFG_REG(CDUT, P_SIZE);
1100 clients[ILT_CLI_TSDM].first.reg = ILT_CFG_REG(TSDM, FIRST_ILT);
1101 clients[ILT_CLI_TSDM].last.reg = ILT_CFG_REG(TSDM, LAST_ILT);
1102 clients[ILT_CLI_TSDM].p_size.reg = ILT_CFG_REG(TSDM, P_SIZE);
1104 /* default ILT page size for all clients is 32K */
1105 for (i = 0; i < ILT_CLI_MAX; i++)
1106 p_mngr->clients[i].p_size.val = ILT_DEFAULT_HW_P_SIZE;
1108 /* due to removal of ISCSI/FCoE files union type0_task_context
1109 * task_type_size will be 0. So hardcoded for now.
1111 p_mngr->task_type_size[0] = 512; /* @DPDK */
1112 p_mngr->task_type_size[1] = 128; /* @DPDK */
1114 if (p_hwfn->p_dev->p_iov_info)
1115 p_mngr->vf_count = p_hwfn->p_dev->p_iov_info->total_vfs;
1117 /* Initialize the dynamic ILT allocation mutex */
1118 OSAL_MUTEX_ALLOC(p_hwfn, &p_mngr->mutex);
1119 OSAL_MUTEX_INIT(&p_mngr->mutex);
1121 /* Set the cxt mangr pointer priori to further allocations */
1122 p_hwfn->p_cxt_mngr = p_mngr;
1124 return ECORE_SUCCESS;
1127 enum _ecore_status_t ecore_cxt_tables_alloc(struct ecore_hwfn *p_hwfn)
1129 enum _ecore_status_t rc;
1131 /* Allocate the ILT shadow table */
1132 rc = ecore_ilt_shadow_alloc(p_hwfn);
1134 DP_NOTICE(p_hwfn, true, "Failed to allocate ilt memory\n");
1135 goto tables_alloc_fail;
1138 /* Allocate the T2 table */
1139 rc = ecore_cxt_src_t2_alloc(p_hwfn);
1141 DP_NOTICE(p_hwfn, true, "Failed to allocate T2 memory\n");
1142 goto tables_alloc_fail;
1145 /* Allocate and initialize the acquired cids bitmaps */
1146 rc = ecore_cid_map_alloc(p_hwfn);
1148 DP_NOTICE(p_hwfn, true, "Failed to allocate cid maps\n");
1149 goto tables_alloc_fail;
1152 return ECORE_SUCCESS;
1155 ecore_cxt_mngr_free(p_hwfn);
1159 void ecore_cxt_mngr_free(struct ecore_hwfn *p_hwfn)
1161 if (!p_hwfn->p_cxt_mngr)
1164 ecore_cid_map_free(p_hwfn);
1165 ecore_cxt_src_t2_free(p_hwfn);
1166 ecore_ilt_shadow_free(p_hwfn);
1167 OSAL_MUTEX_DEALLOC(&p_hwfn->p_cxt_mngr->mutex);
1168 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_cxt_mngr);
1171 void ecore_cxt_mngr_setup(struct ecore_hwfn *p_hwfn)
1173 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1176 /* Reset acquired cids */
1177 for (type = 0; type < MAX_CONN_TYPES; type++) {
1178 u32 cid_cnt = p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count;
1184 for (i = 0; i < DIV_ROUND_UP(cid_cnt, BITS_PER_MAP_WORD); i++)
1185 p_mngr->acquired[type].cid_map[i] = 0;
1189 /* HW initialization helper (per Block, per phase) */
1192 #define CDUC_CXT_SIZE_SHIFT \
1193 CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE_SHIFT
1195 #define CDUC_CXT_SIZE_MASK \
1196 (CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE >> CDUC_CXT_SIZE_SHIFT)
1198 #define CDUC_BLOCK_WASTE_SHIFT \
1199 CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE_SHIFT
1201 #define CDUC_BLOCK_WASTE_MASK \
1202 (CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE >> CDUC_BLOCK_WASTE_SHIFT)
1204 #define CDUC_NCIB_SHIFT \
1205 CDU_REG_CID_ADDR_PARAMS_NCIB_SHIFT
1207 #define CDUC_NCIB_MASK \
1208 (CDU_REG_CID_ADDR_PARAMS_NCIB >> CDUC_NCIB_SHIFT)
1210 #define CDUT_TYPE0_CXT_SIZE_SHIFT \
1211 CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE_SHIFT
1213 #define CDUT_TYPE0_CXT_SIZE_MASK \
1214 (CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE >> \
1215 CDUT_TYPE0_CXT_SIZE_SHIFT)
1217 #define CDUT_TYPE0_BLOCK_WASTE_SHIFT \
1218 CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE_SHIFT
1220 #define CDUT_TYPE0_BLOCK_WASTE_MASK \
1221 (CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE >> \
1222 CDUT_TYPE0_BLOCK_WASTE_SHIFT)
1224 #define CDUT_TYPE0_NCIB_SHIFT \
1225 CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK_SHIFT
1227 #define CDUT_TYPE0_NCIB_MASK \
1228 (CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK >> \
1229 CDUT_TYPE0_NCIB_SHIFT)
1231 #define CDUT_TYPE1_CXT_SIZE_SHIFT \
1232 CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE_SHIFT
1234 #define CDUT_TYPE1_CXT_SIZE_MASK \
1235 (CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE >> \
1236 CDUT_TYPE1_CXT_SIZE_SHIFT)
1238 #define CDUT_TYPE1_BLOCK_WASTE_SHIFT \
1239 CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE_SHIFT
1241 #define CDUT_TYPE1_BLOCK_WASTE_MASK \
1242 (CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE >> \
1243 CDUT_TYPE1_BLOCK_WASTE_SHIFT)
1245 #define CDUT_TYPE1_NCIB_SHIFT \
1246 CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK_SHIFT
1248 #define CDUT_TYPE1_NCIB_MASK \
1249 (CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK >> \
1250 CDUT_TYPE1_NCIB_SHIFT)
1252 static void ecore_cdu_init_common(struct ecore_hwfn *p_hwfn)
1254 u32 page_sz, elems_per_page, block_waste, cxt_size, cdu_params = 0;
1256 /* CDUC - connection configuration */
1257 page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
1258 cxt_size = CONN_CXT_SIZE(p_hwfn);
1259 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1260 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1262 SET_FIELD(cdu_params, CDUC_CXT_SIZE, cxt_size);
1263 SET_FIELD(cdu_params, CDUC_BLOCK_WASTE, block_waste);
1264 SET_FIELD(cdu_params, CDUC_NCIB, elems_per_page);
1265 STORE_RT_REG(p_hwfn, CDU_REG_CID_ADDR_PARAMS_RT_OFFSET, cdu_params);
1267 /* CDUT - type-0 tasks configuration */
1268 page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT].p_size.val;
1269 cxt_size = p_hwfn->p_cxt_mngr->task_type_size[0];
1270 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1271 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1273 /* cxt size and block-waste are multipes of 8 */
1275 SET_FIELD(cdu_params, CDUT_TYPE0_CXT_SIZE, (cxt_size >> 3));
1276 SET_FIELD(cdu_params, CDUT_TYPE0_BLOCK_WASTE, (block_waste >> 3));
1277 SET_FIELD(cdu_params, CDUT_TYPE0_NCIB, elems_per_page);
1278 STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT0_PARAMS_RT_OFFSET, cdu_params);
1280 /* CDUT - type-1 tasks configuration */
1281 cxt_size = p_hwfn->p_cxt_mngr->task_type_size[1];
1282 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1283 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1285 /* cxt size and block-waste are multipes of 8 */
1287 SET_FIELD(cdu_params, CDUT_TYPE1_CXT_SIZE, (cxt_size >> 3));
1288 SET_FIELD(cdu_params, CDUT_TYPE1_BLOCK_WASTE, (block_waste >> 3));
1289 SET_FIELD(cdu_params, CDUT_TYPE1_NCIB, elems_per_page);
1290 STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT1_PARAMS_RT_OFFSET, cdu_params);
1294 #define CDU_SEG_REG_TYPE_SHIFT CDU_SEG_TYPE_OFFSET_REG_TYPE_SHIFT
1295 #define CDU_SEG_REG_TYPE_MASK 0x1
1296 #define CDU_SEG_REG_OFFSET_SHIFT 0
1297 #define CDU_SEG_REG_OFFSET_MASK CDU_SEG_TYPE_OFFSET_REG_OFFSET_MASK
1299 static void ecore_cdu_init_pf(struct ecore_hwfn *p_hwfn)
1301 struct ecore_ilt_client_cfg *p_cli;
1302 struct ecore_tid_seg *p_seg;
1303 u32 cdu_seg_params, offset;
1306 static const u32 rt_type_offset_arr[] = {
1307 CDU_REG_PF_SEG0_TYPE_OFFSET_RT_OFFSET,
1308 CDU_REG_PF_SEG1_TYPE_OFFSET_RT_OFFSET,
1309 CDU_REG_PF_SEG2_TYPE_OFFSET_RT_OFFSET,
1310 CDU_REG_PF_SEG3_TYPE_OFFSET_RT_OFFSET
1313 static const u32 rt_type_offset_fl_arr[] = {
1314 CDU_REG_PF_FL_SEG0_TYPE_OFFSET_RT_OFFSET,
1315 CDU_REG_PF_FL_SEG1_TYPE_OFFSET_RT_OFFSET,
1316 CDU_REG_PF_FL_SEG2_TYPE_OFFSET_RT_OFFSET,
1317 CDU_REG_PF_FL_SEG3_TYPE_OFFSET_RT_OFFSET
1320 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1322 /* There are initializations only for CDUT during pf Phase */
1323 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
1325 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
1329 /* Note: start_line is already adjusted for the CDU
1330 * segment register granularity, so we just need to
1331 * divide. Adjustment is implicit as we assume ILT
1332 * Page size is larger than 32K!
1334 offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
1335 (p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line -
1336 p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
1339 SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
1340 SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
1341 STORE_RT_REG(p_hwfn, rt_type_offset_arr[i], cdu_seg_params);
1343 offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
1344 (p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)].start_line -
1345 p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
1348 SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
1349 SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
1350 STORE_RT_REG(p_hwfn, rt_type_offset_fl_arr[i], cdu_seg_params);
1354 void ecore_qm_init_pf(struct ecore_hwfn *p_hwfn)
1356 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
1357 struct ecore_qm_iids iids;
1359 OSAL_MEM_ZERO(&iids, sizeof(iids));
1360 ecore_cxt_qm_iids(p_hwfn, &iids);
1362 ecore_qm_pf_rt_init(p_hwfn, p_hwfn->p_main_ptt, p_hwfn->port_id,
1363 p_hwfn->rel_pf_id, qm_info->max_phys_tcs_per_port,
1364 p_hwfn->first_on_engine,
1365 iids.cids, iids.vf_cids, iids.tids,
1367 qm_info->num_pqs - qm_info->num_vf_pqs,
1368 qm_info->num_vf_pqs,
1369 qm_info->start_vport,
1370 qm_info->num_vports, qm_info->pf_wfq,
1371 qm_info->pf_rl, p_hwfn->qm_info.qm_pq_params,
1372 p_hwfn->qm_info.qm_vport_params);
1376 void ecore_cm_init_pf(struct ecore_hwfn *p_hwfn)
1378 STORE_RT_REG(p_hwfn, XCM_REG_CON_PHY_Q3_RT_OFFSET,
1379 ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB));
1383 static void ecore_dq_init_pf(struct ecore_hwfn *p_hwfn)
1385 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1386 u32 dq_pf_max_cid = 0, dq_vf_max_cid = 0;
1388 dq_pf_max_cid += (p_mngr->conn_cfg[0].cid_count >> DQ_RANGE_SHIFT);
1389 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_0_RT_OFFSET, dq_pf_max_cid);
1391 dq_vf_max_cid += (p_mngr->conn_cfg[0].cids_per_vf >> DQ_RANGE_SHIFT);
1392 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_0_RT_OFFSET, dq_vf_max_cid);
1394 dq_pf_max_cid += (p_mngr->conn_cfg[1].cid_count >> DQ_RANGE_SHIFT);
1395 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_1_RT_OFFSET, dq_pf_max_cid);
1397 dq_vf_max_cid += (p_mngr->conn_cfg[1].cids_per_vf >> DQ_RANGE_SHIFT);
1398 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_1_RT_OFFSET, dq_vf_max_cid);
1400 dq_pf_max_cid += (p_mngr->conn_cfg[2].cid_count >> DQ_RANGE_SHIFT);
1401 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_2_RT_OFFSET, dq_pf_max_cid);
1403 dq_vf_max_cid += (p_mngr->conn_cfg[2].cids_per_vf >> DQ_RANGE_SHIFT);
1404 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_2_RT_OFFSET, dq_vf_max_cid);
1406 dq_pf_max_cid += (p_mngr->conn_cfg[3].cid_count >> DQ_RANGE_SHIFT);
1407 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_3_RT_OFFSET, dq_pf_max_cid);
1409 dq_vf_max_cid += (p_mngr->conn_cfg[3].cids_per_vf >> DQ_RANGE_SHIFT);
1410 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_3_RT_OFFSET, dq_vf_max_cid);
1412 dq_pf_max_cid += (p_mngr->conn_cfg[4].cid_count >> DQ_RANGE_SHIFT);
1413 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_4_RT_OFFSET, dq_pf_max_cid);
1415 dq_vf_max_cid += (p_mngr->conn_cfg[4].cids_per_vf >> DQ_RANGE_SHIFT);
1416 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_4_RT_OFFSET, dq_vf_max_cid);
1418 dq_pf_max_cid += (p_mngr->conn_cfg[5].cid_count >> DQ_RANGE_SHIFT);
1419 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_5_RT_OFFSET, dq_pf_max_cid);
1421 dq_vf_max_cid += (p_mngr->conn_cfg[5].cids_per_vf >> DQ_RANGE_SHIFT);
1422 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_5_RT_OFFSET, dq_vf_max_cid);
1424 /* Connection types 6 & 7 are not in use, yet they must be configured
1425 * as the highest possible connection. Not configuring them means the
1426 * defaults will be used, and with a large number of cids a bug may
1427 * occur, if the defaults will be smaller than dq_pf_max_cid /
1430 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_6_RT_OFFSET, dq_pf_max_cid);
1431 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_6_RT_OFFSET, dq_vf_max_cid);
1433 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_7_RT_OFFSET, dq_pf_max_cid);
1434 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_7_RT_OFFSET, dq_vf_max_cid);
1437 static void ecore_ilt_bounds_init(struct ecore_hwfn *p_hwfn)
1439 struct ecore_ilt_client_cfg *ilt_clients;
1442 ilt_clients = p_hwfn->p_cxt_mngr->clients;
1443 for_each_ilt_valid_client(i, ilt_clients) {
1444 STORE_RT_REG(p_hwfn,
1445 ilt_clients[i].first.reg,
1446 ilt_clients[i].first.val);
1447 STORE_RT_REG(p_hwfn,
1448 ilt_clients[i].last.reg, ilt_clients[i].last.val);
1449 STORE_RT_REG(p_hwfn,
1450 ilt_clients[i].p_size.reg,
1451 ilt_clients[i].p_size.val);
1455 static void ecore_ilt_vf_bounds_init(struct ecore_hwfn *p_hwfn)
1457 struct ecore_ilt_client_cfg *p_cli;
1460 /* For simplicty we set the 'block' to be an ILT page */
1461 if (p_hwfn->p_dev->p_iov_info) {
1462 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
1464 STORE_RT_REG(p_hwfn,
1465 PSWRQ2_REG_VF_BASE_RT_OFFSET,
1466 p_iov->first_vf_in_pf);
1467 STORE_RT_REG(p_hwfn,
1468 PSWRQ2_REG_VF_LAST_ILT_RT_OFFSET,
1469 p_iov->first_vf_in_pf + p_iov->total_vfs);
1472 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
1473 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1474 if (p_cli->active) {
1475 STORE_RT_REG(p_hwfn,
1476 PSWRQ2_REG_CDUC_BLOCKS_FACTOR_RT_OFFSET,
1478 STORE_RT_REG(p_hwfn,
1479 PSWRQ2_REG_CDUC_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1480 p_cli->pf_total_lines);
1481 STORE_RT_REG(p_hwfn,
1482 PSWRQ2_REG_CDUC_VF_BLOCKS_RT_OFFSET,
1483 p_cli->vf_total_lines);
1486 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1487 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1488 if (p_cli->active) {
1489 STORE_RT_REG(p_hwfn,
1490 PSWRQ2_REG_CDUT_BLOCKS_FACTOR_RT_OFFSET,
1492 STORE_RT_REG(p_hwfn,
1493 PSWRQ2_REG_CDUT_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1494 p_cli->pf_total_lines);
1495 STORE_RT_REG(p_hwfn,
1496 PSWRQ2_REG_CDUT_VF_BLOCKS_RT_OFFSET,
1497 p_cli->vf_total_lines);
1500 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TM];
1501 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1502 if (p_cli->active) {
1503 STORE_RT_REG(p_hwfn,
1504 PSWRQ2_REG_TM_BLOCKS_FACTOR_RT_OFFSET, blk_factor);
1505 STORE_RT_REG(p_hwfn,
1506 PSWRQ2_REG_TM_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1507 p_cli->pf_total_lines);
1508 STORE_RT_REG(p_hwfn,
1509 PSWRQ2_REG_TM_VF_BLOCKS_RT_OFFSET,
1510 p_cli->vf_total_lines);
1514 /* ILT (PSWRQ2) PF */
1515 static void ecore_ilt_init_pf(struct ecore_hwfn *p_hwfn)
1517 struct ecore_ilt_client_cfg *clients;
1518 struct ecore_cxt_mngr *p_mngr;
1519 struct ecore_dma_mem *p_shdw;
1520 u32 line, rt_offst, i;
1522 ecore_ilt_bounds_init(p_hwfn);
1523 ecore_ilt_vf_bounds_init(p_hwfn);
1525 p_mngr = p_hwfn->p_cxt_mngr;
1526 p_shdw = p_mngr->ilt_shadow;
1527 clients = p_hwfn->p_cxt_mngr->clients;
1529 for_each_ilt_valid_client(i, clients) {
1530 /* Client's 1st val and RT array are absolute, ILT shadows'
1531 * lines are relative.
1533 line = clients[i].first.val - p_mngr->pf_start_line;
1534 rt_offst = PSWRQ2_REG_ILT_MEMORY_RT_OFFSET +
1535 clients[i].first.val * ILT_ENTRY_IN_REGS;
1537 for (; line <= clients[i].last.val - p_mngr->pf_start_line;
1538 line++, rt_offst += ILT_ENTRY_IN_REGS) {
1539 u64 ilt_hw_entry = 0;
1541 /** p_virt could be OSAL_NULL incase of dynamic
1544 if (p_shdw[line].p_virt != OSAL_NULL) {
1545 SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
1546 SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR,
1547 (p_shdw[line].p_phys >> 12));
1549 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1550 "Setting RT[0x%08x] from"
1551 " ILT[0x%08x] [Client is %d] to"
1552 " Physical addr: 0x%lx\n",
1554 (unsigned long)(p_shdw[line].
1558 STORE_RT_REG_AGG(p_hwfn, rt_offst, ilt_hw_entry);
1563 /* SRC (Searcher) PF */
1564 static void ecore_src_init_pf(struct ecore_hwfn *p_hwfn)
1566 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1567 u32 rounded_conn_num, conn_num, conn_max;
1568 struct ecore_src_iids src_iids;
1570 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
1571 ecore_cxt_src_iids(p_mngr, &src_iids);
1572 conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
1576 conn_max = OSAL_MAX_T(u32, conn_num, SRC_MIN_NUM_ELEMS);
1577 rounded_conn_num = OSAL_ROUNDUP_POW_OF_TWO(conn_max);
1579 STORE_RT_REG(p_hwfn, SRC_REG_COUNTFREE_RT_OFFSET, conn_num);
1580 STORE_RT_REG(p_hwfn, SRC_REG_NUMBER_HASH_BITS_RT_OFFSET,
1581 OSAL_LOG2(rounded_conn_num));
1583 STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET,
1584 p_hwfn->p_cxt_mngr->first_free);
1585 STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET,
1586 p_hwfn->p_cxt_mngr->last_free);
1590 #define TM_CFG_NUM_IDS_SHIFT 0
1591 #define TM_CFG_NUM_IDS_MASK 0xFFFFULL
1592 #define TM_CFG_PRE_SCAN_OFFSET_SHIFT 16
1593 #define TM_CFG_PRE_SCAN_OFFSET_MASK 0x1FFULL
1594 #define TM_CFG_PARENT_PF_SHIFT 25
1595 #define TM_CFG_PARENT_PF_MASK 0x7ULL
1597 #define TM_CFG_CID_PRE_SCAN_ROWS_SHIFT 30
1598 #define TM_CFG_CID_PRE_SCAN_ROWS_MASK 0x1FFULL
1600 #define TM_CFG_TID_OFFSET_SHIFT 30
1601 #define TM_CFG_TID_OFFSET_MASK 0x7FFFFULL
1602 #define TM_CFG_TID_PRE_SCAN_ROWS_SHIFT 49
1603 #define TM_CFG_TID_PRE_SCAN_ROWS_MASK 0x1FFULL
1605 static void ecore_tm_init_pf(struct ecore_hwfn *p_hwfn)
1607 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1608 u32 active_seg_mask = 0, tm_offset, rt_reg;
1609 struct ecore_tm_iids tm_iids;
1613 OSAL_MEM_ZERO(&tm_iids, sizeof(tm_iids));
1614 ecore_cxt_tm_iids(p_mngr, &tm_iids);
1616 /* @@@TBD No pre-scan for now */
1618 /* Note: We assume consecutive VFs for a PF */
1619 for (i = 0; i < p_mngr->vf_count; i++) {
1621 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_cids);
1622 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1623 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
1624 SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
1626 rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
1627 (sizeof(cfg_word) / sizeof(u32)) *
1628 (p_hwfn->p_dev->p_iov_info->first_vf_in_pf + i);
1629 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1633 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_cids);
1634 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1635 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); /* n/a for PF */
1636 SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
1638 rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
1639 (sizeof(cfg_word) / sizeof(u32)) *
1640 (NUM_OF_VFS(p_hwfn->p_dev) + p_hwfn->rel_pf_id);
1641 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1644 STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_CONN_RT_OFFSET,
1645 tm_iids.pf_cids ? 0x1 : 0x0);
1647 /* @@@TBD how to enable the scan for the VFs */
1649 tm_offset = tm_iids.per_vf_cids;
1651 /* Note: We assume consecutive VFs for a PF */
1652 for (i = 0; i < p_mngr->vf_count; i++) {
1654 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_tids);
1655 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1656 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
1657 SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
1658 SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64)0);
1660 rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
1661 (sizeof(cfg_word) / sizeof(u32)) *
1662 (p_hwfn->p_dev->p_iov_info->first_vf_in_pf + i);
1664 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1667 tm_offset = tm_iids.pf_cids;
1668 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
1670 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_tids[i]);
1671 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1672 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0);
1673 SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
1674 SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64)0);
1676 rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
1677 (sizeof(cfg_word) / sizeof(u32)) *
1678 (NUM_OF_VFS(p_hwfn->p_dev) +
1679 p_hwfn->rel_pf_id * NUM_TASK_PF_SEGMENTS + i);
1681 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1682 active_seg_mask |= (tm_iids.pf_tids[i] ? (1 << i) : 0);
1684 tm_offset += tm_iids.pf_tids[i];
1687 STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_TASK_RT_OFFSET, active_seg_mask);
1689 /* @@@TBD how to enable the scan for the VFs */
1692 static void ecore_prs_init_pf(struct ecore_hwfn *p_hwfn)
1694 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1695 struct ecore_conn_type_cfg *p_fcoe = &p_mngr->conn_cfg[PROTOCOLID_FCOE];
1696 struct ecore_tid_seg *p_tid;
1698 /* If FCoE is active set the MAX OX_ID (tid) in the Parser */
1699 if (!p_fcoe->cid_count)
1702 p_tid = &p_fcoe->tid_seg[ECORE_CXT_FCOE_TID_SEG];
1703 STORE_RT_REG_AGG(p_hwfn,
1704 PRS_REG_TASK_ID_MAX_INITIATOR_PF_RT_OFFSET,
1708 void ecore_cxt_hw_init_common(struct ecore_hwfn *p_hwfn)
1710 /* CDU configuration */
1711 ecore_cdu_init_common(p_hwfn);
1714 void ecore_cxt_hw_init_pf(struct ecore_hwfn *p_hwfn)
1716 ecore_qm_init_pf(p_hwfn);
1717 ecore_cm_init_pf(p_hwfn);
1718 ecore_dq_init_pf(p_hwfn);
1719 ecore_cdu_init_pf(p_hwfn);
1720 ecore_ilt_init_pf(p_hwfn);
1721 ecore_src_init_pf(p_hwfn);
1722 ecore_tm_init_pf(p_hwfn);
1723 ecore_prs_init_pf(p_hwfn);
1726 enum _ecore_status_t ecore_cxt_acquire_cid(struct ecore_hwfn *p_hwfn,
1727 enum protocol_type type, u32 *p_cid)
1729 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1732 if (type >= MAX_CONN_TYPES || !p_mngr->acquired[type].cid_map) {
1733 DP_NOTICE(p_hwfn, true, "Invalid protocol type %d", type);
1737 rel_cid = OSAL_FIND_FIRST_ZERO_BIT(p_mngr->acquired[type].cid_map,
1738 p_mngr->acquired[type].max_count);
1740 if (rel_cid >= p_mngr->acquired[type].max_count) {
1741 DP_NOTICE(p_hwfn, false, "no CID available for protocol %d\n",
1743 return ECORE_NORESOURCES;
1746 OSAL_SET_BIT(rel_cid, p_mngr->acquired[type].cid_map);
1748 *p_cid = rel_cid + p_mngr->acquired[type].start_cid;
1750 return ECORE_SUCCESS;
1753 static bool ecore_cxt_test_cid_acquired(struct ecore_hwfn *p_hwfn,
1754 u32 cid, enum protocol_type *p_type)
1756 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1757 struct ecore_cid_acquired_map *p_map;
1758 enum protocol_type p;
1761 /* Iterate over protocols and find matching cid range */
1762 for (p = 0; p < MAX_CONN_TYPES; p++) {
1763 p_map = &p_mngr->acquired[p];
1765 if (!p_map->cid_map)
1767 if (cid >= p_map->start_cid &&
1768 cid < p_map->start_cid + p_map->max_count) {
1774 if (p == MAX_CONN_TYPES) {
1775 DP_NOTICE(p_hwfn, true, "Invalid CID %d", cid);
1778 rel_cid = cid - p_map->start_cid;
1779 if (!OSAL_TEST_BIT(rel_cid, p_map->cid_map)) {
1780 DP_NOTICE(p_hwfn, true, "CID %d not acquired", cid);
1786 void ecore_cxt_release_cid(struct ecore_hwfn *p_hwfn, u32 cid)
1788 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1789 enum protocol_type type;
1793 /* Test acquired and find matching per-protocol map */
1794 b_acquired = ecore_cxt_test_cid_acquired(p_hwfn, cid, &type);
1799 rel_cid = cid - p_mngr->acquired[type].start_cid;
1800 OSAL_CLEAR_BIT(rel_cid, p_mngr->acquired[type].cid_map);
1803 enum _ecore_status_t ecore_cxt_get_cid_info(struct ecore_hwfn *p_hwfn,
1804 struct ecore_cxt_info *p_info)
1806 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1807 u32 conn_cxt_size, hw_p_size, cxts_per_p, line;
1808 enum protocol_type type;
1811 /* Test acquired and find matching per-protocol map */
1812 b_acquired = ecore_cxt_test_cid_acquired(p_hwfn, p_info->iid, &type);
1817 /* set the protocl type */
1818 p_info->type = type;
1820 /* compute context virtual pointer */
1821 hw_p_size = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
1823 conn_cxt_size = CONN_CXT_SIZE(p_hwfn);
1824 cxts_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / conn_cxt_size;
1825 line = p_info->iid / cxts_per_p;
1827 /* Make sure context is allocated (dynamic allocation) */
1828 if (!p_mngr->ilt_shadow[line].p_virt)
1831 p_info->p_cxt = (u8 *)p_mngr->ilt_shadow[line].p_virt +
1832 p_info->iid % cxts_per_p * conn_cxt_size;
1834 DP_VERBOSE(p_hwfn, (ECORE_MSG_ILT | ECORE_MSG_CXT),
1835 "Accessing ILT shadow[%d]: CXT pointer is at %p (for iid %d)\n",
1836 (p_info->iid / cxts_per_p), p_info->p_cxt, p_info->iid);
1838 return ECORE_SUCCESS;
1841 void ecore_cxt_set_srq_count(struct ecore_hwfn *p_hwfn, u32 num_srqs)
1843 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
1845 p_mgr->srq_count = num_srqs;
1848 u32 ecore_cxt_get_srq_count(struct ecore_hwfn *p_hwfn)
1850 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
1852 return p_mgr->srq_count;
1855 enum _ecore_status_t ecore_cxt_set_pf_params(struct ecore_hwfn *p_hwfn)
1857 /* Set the number of required CORE connections */
1858 u32 core_cids = 1; /* SPQ */
1860 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_CORE, core_cids, 0);
1862 switch (p_hwfn->hw_info.personality) {
1865 struct ecore_eth_pf_params *p_params =
1866 &p_hwfn->pf_params.eth_pf_params;
1868 ecore_cxt_set_proto_cid_count(p_hwfn,
1870 p_params->num_cons, 1); /* FIXME VF count... */
1878 return ECORE_SUCCESS;
1881 enum _ecore_status_t ecore_cxt_get_tid_mem_info(struct ecore_hwfn *p_hwfn,
1882 struct ecore_tid_mem *p_info)
1884 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1885 u32 proto, seg, total_lines, i, shadow_line;
1886 struct ecore_ilt_client_cfg *p_cli;
1887 struct ecore_ilt_cli_blk *p_fl_seg;
1888 struct ecore_tid_seg *p_seg_info;
1890 /* Verify the personality */
1891 switch (p_hwfn->hw_info.personality) {
1896 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
1900 p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg];
1901 if (!p_seg_info->has_fl_mem)
1904 p_fl_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)];
1905 total_lines = DIV_ROUND_UP(p_fl_seg->total_size,
1906 p_fl_seg->real_size_in_page);
1908 for (i = 0; i < total_lines; i++) {
1909 shadow_line = i + p_fl_seg->start_line -
1910 p_hwfn->p_cxt_mngr->pf_start_line;
1911 p_info->blocks[i] = p_mngr->ilt_shadow[shadow_line].p_virt;
1913 p_info->waste = ILT_PAGE_IN_BYTES(p_cli->p_size.val) -
1914 p_fl_seg->real_size_in_page;
1915 p_info->tid_size = p_mngr->task_type_size[p_seg_info->type];
1916 p_info->num_tids_per_block = p_fl_seg->real_size_in_page /
1919 return ECORE_SUCCESS;
1922 /* This function is very RoCE oriented, if another protocol in the future
1923 * will want this feature we'll need to modify the function to be more generic
1925 enum _ecore_status_t
1926 ecore_cxt_dynamic_ilt_alloc(struct ecore_hwfn *p_hwfn,
1927 enum ecore_cxt_elem_type elem_type,
1930 u32 reg_offset, shadow_line, elem_size, hw_p_size, elems_per_p, line;
1931 struct ecore_ilt_client_cfg *p_cli;
1932 struct ecore_ilt_cli_blk *p_blk;
1933 struct ecore_ptt *p_ptt;
1937 enum _ecore_status_t rc = ECORE_SUCCESS;
1939 switch (elem_type) {
1940 case ECORE_ELEM_CXT:
1941 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
1942 elem_size = CONN_CXT_SIZE(p_hwfn);
1943 p_blk = &p_cli->pf_blks[CDUC_BLK];
1945 case ECORE_ELEM_SRQ:
1946 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
1947 elem_size = SRQ_CXT_SIZE;
1948 p_blk = &p_cli->pf_blks[SRQ_BLK];
1950 case ECORE_ELEM_TASK:
1951 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1952 elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
1953 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(ECORE_CXT_ROCE_TID_SEG)];
1956 DP_NOTICE(p_hwfn, false,
1957 "ECORE_INVALID elem type = %d", elem_type);
1961 /* Calculate line in ilt */
1962 hw_p_size = p_cli->p_size.val;
1963 elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
1964 line = p_blk->start_line + (iid / elems_per_p);
1965 shadow_line = line - p_hwfn->p_cxt_mngr->pf_start_line;
1967 /* If line is already allocated, do nothing, otherwise allocate it and
1968 * write it to the PSWRQ2 registers.
1969 * This section can be run in parallel from different contexts and thus
1970 * a mutex protection is needed.
1973 OSAL_MUTEX_ACQUIRE(&p_hwfn->p_cxt_mngr->mutex);
1975 if (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt)
1978 p_ptt = ecore_ptt_acquire(p_hwfn);
1980 DP_NOTICE(p_hwfn, false,
1981 "ECORE_TIME_OUT on ptt acquire - dynamic allocation");
1986 p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
1988 p_blk->real_size_in_page);
1993 OSAL_MEM_ZERO(p_virt, p_blk->real_size_in_page);
1995 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt = p_virt;
1996 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys = p_phys;
1997 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].size =
1998 p_blk->real_size_in_page;
2000 /* compute absolute offset */
2001 reg_offset = PSWRQ2_REG_ILT_MEMORY +
2002 (line * ILT_REG_SIZE_IN_BYTES * ILT_ENTRY_IN_REGS);
2005 SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
2006 SET_FIELD(ilt_hw_entry,
2008 (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys >> 12));
2010 /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a wide-bus */
2012 ecore_dmae_host2grc(p_hwfn, p_ptt, (u64)(osal_uintptr_t)&ilt_hw_entry,
2013 reg_offset, sizeof(ilt_hw_entry) / sizeof(u32),
2016 if (elem_type == ECORE_ELEM_CXT) {
2017 u32 last_cid_allocated = (1 + (iid / elems_per_p)) *
2020 /* Update the relevant register in the parser */
2021 ecore_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF,
2022 last_cid_allocated - 1);
2024 if (!p_hwfn->b_rdma_enabled_in_prs) {
2025 /* Enable RoCE search */
2026 ecore_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
2027 p_hwfn->b_rdma_enabled_in_prs = true;
2032 ecore_ptt_release(p_hwfn, p_ptt);
2034 OSAL_MUTEX_RELEASE(&p_hwfn->p_cxt_mngr->mutex);
2039 /* This function is very RoCE oriented, if another protocol in the future
2040 * will want this feature we'll need to modify the function to be more generic
2042 static enum _ecore_status_t
2043 ecore_cxt_free_ilt_range(struct ecore_hwfn *p_hwfn,
2044 enum ecore_cxt_elem_type elem_type,
2045 u32 start_iid, u32 count)
2047 u32 start_line, end_line, shadow_start_line, shadow_end_line;
2048 u32 reg_offset, elem_size, hw_p_size, elems_per_p;
2049 struct ecore_ilt_client_cfg *p_cli;
2050 struct ecore_ilt_cli_blk *p_blk;
2051 u32 end_iid = start_iid + count;
2052 struct ecore_ptt *p_ptt;
2053 u64 ilt_hw_entry = 0;
2056 switch (elem_type) {
2057 case ECORE_ELEM_CXT:
2058 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
2059 elem_size = CONN_CXT_SIZE(p_hwfn);
2060 p_blk = &p_cli->pf_blks[CDUC_BLK];
2062 case ECORE_ELEM_SRQ:
2063 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
2064 elem_size = SRQ_CXT_SIZE;
2065 p_blk = &p_cli->pf_blks[SRQ_BLK];
2067 case ECORE_ELEM_TASK:
2068 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
2069 elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
2070 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(ECORE_CXT_ROCE_TID_SEG)];
2073 DP_NOTICE(p_hwfn, false,
2074 "ECORE_INVALID elem type = %d", elem_type);
2078 /* Calculate line in ilt */
2079 hw_p_size = p_cli->p_size.val;
2080 elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
2081 start_line = p_blk->start_line + (start_iid / elems_per_p);
2082 end_line = p_blk->start_line + (end_iid / elems_per_p);
2083 if (((end_iid + 1) / elems_per_p) != (end_iid / elems_per_p))
2086 shadow_start_line = start_line - p_hwfn->p_cxt_mngr->pf_start_line;
2087 shadow_end_line = end_line - p_hwfn->p_cxt_mngr->pf_start_line;
2089 p_ptt = ecore_ptt_acquire(p_hwfn);
2091 DP_NOTICE(p_hwfn, false,
2092 "ECORE_TIME_OUT on ptt acquire - dynamic allocation");
2093 return ECORE_TIMEOUT;
2096 for (i = shadow_start_line; i < shadow_end_line; i++) {
2097 if (!p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt)
2100 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
2101 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt,
2102 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys,
2103 p_hwfn->p_cxt_mngr->ilt_shadow[i].size);
2105 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt = OSAL_NULL;
2106 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys = 0;
2107 p_hwfn->p_cxt_mngr->ilt_shadow[i].size = 0;
2109 /* compute absolute offset */
2110 reg_offset = PSWRQ2_REG_ILT_MEMORY +
2111 ((start_line++) * ILT_REG_SIZE_IN_BYTES *
2114 /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a
2117 ecore_dmae_host2grc(p_hwfn, p_ptt,
2118 (u64)(osal_uintptr_t)&ilt_hw_entry,
2120 sizeof(ilt_hw_entry) / sizeof(u32),
2124 ecore_ptt_release(p_hwfn, p_ptt);
2126 return ECORE_SUCCESS;
2129 enum _ecore_status_t ecore_cxt_free_proto_ilt(struct ecore_hwfn *p_hwfn,
2130 enum protocol_type proto)
2132 enum _ecore_status_t rc;
2135 /* Free Connection CXT */
2136 rc = ecore_cxt_free_ilt_range(p_hwfn, ECORE_ELEM_CXT,
2137 ecore_cxt_get_proto_cid_start(p_hwfn,
2139 ecore_cxt_get_proto_cid_count(p_hwfn,
2147 rc = ecore_cxt_free_ilt_range(p_hwfn, ECORE_ELEM_TASK, 0,
2148 ecore_cxt_get_proto_tid_count(p_hwfn,
2154 rc = ecore_cxt_free_ilt_range(p_hwfn, ECORE_ELEM_SRQ, 0,
2155 ecore_cxt_get_srq_count(p_hwfn));
2160 enum _ecore_status_t ecore_cxt_get_task_ctx(struct ecore_hwfn *p_hwfn,
2162 u8 ctx_type, void **pp_task_ctx)
2164 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
2165 struct ecore_ilt_client_cfg *p_cli;
2166 struct ecore_ilt_cli_blk *p_seg;
2167 struct ecore_tid_seg *p_seg_info;
2170 u32 tid_size, ilt_idx;
2171 u32 num_tids_per_block;
2173 /* Verify the personality */
2174 switch (p_hwfn->hw_info.personality) {
2179 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
2183 p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg];
2185 if (ctx_type == ECORE_CTX_WORKING_MEM) {
2186 p_seg = &p_cli->pf_blks[CDUT_SEG_BLK(seg)];
2187 } else if (ctx_type == ECORE_CTX_FL_MEM) {
2188 if (!p_seg_info->has_fl_mem)
2190 p_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)];
2194 total_lines = DIV_ROUND_UP(p_seg->total_size, p_seg->real_size_in_page);
2195 tid_size = p_mngr->task_type_size[p_seg_info->type];
2196 num_tids_per_block = p_seg->real_size_in_page / tid_size;
2198 if (total_lines < tid / num_tids_per_block)
2201 ilt_idx = tid / num_tids_per_block + p_seg->start_line -
2202 p_mngr->pf_start_line;
2203 *pp_task_ctx = (u8 *)p_mngr->ilt_shadow[ilt_idx].p_virt +
2204 (tid % num_tids_per_block) * tid_size;
2206 return ECORE_SUCCESS;