2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
11 #include "common_hsi.h"
12 #include "ecore_hsi_common.h"
13 #include "ecore_hsi_eth.h"
14 #include "ecore_rt_defs.h"
15 #include "ecore_status.h"
17 #include "ecore_init_ops.h"
18 #include "ecore_init_fw_funcs.h"
19 #include "ecore_cxt.h"
21 #include "ecore_dev_api.h"
22 #include "ecore_sriov.h"
23 #include "ecore_mcp.h"
25 /* Max number of connection types in HW (DQ/CDU etc.) */
26 #define MAX_CONN_TYPES PROTOCOLID_COMMON
27 #define NUM_TASK_TYPES 2
28 #define NUM_TASK_PF_SEGMENTS 4
29 #define NUM_TASK_VF_SEGMENTS 1
31 /* Doorbell-Queue constants */
32 #define DQ_RANGE_SHIFT 4
33 #define DQ_RANGE_ALIGN (1 << DQ_RANGE_SHIFT)
35 /* Searcher constants */
36 #define SRC_MIN_NUM_ELEMS 256
38 /* Timers constants */
40 #define TM_ALIGN (1 << TM_SHIFT)
41 #define TM_ELEM_SIZE 4
44 #define ILT_DEFAULT_HW_P_SIZE 4
46 #define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12))
47 #define ILT_CFG_REG(cli, reg) PSWRQ2_REG_##cli##_##reg##_RT_OFFSET
49 /* ILT entry structure */
50 #define ILT_ENTRY_PHY_ADDR_MASK 0x000FFFFFFFFFFFULL
51 #define ILT_ENTRY_PHY_ADDR_SHIFT 0
52 #define ILT_ENTRY_VALID_MASK 0x1ULL
53 #define ILT_ENTRY_VALID_SHIFT 52
54 #define ILT_ENTRY_IN_REGS 2
55 #define ILT_REG_SIZE_IN_BYTES 4
57 /* connection context union */
59 struct e4_core_conn_context core_ctx;
60 struct e4_eth_conn_context eth_ctx;
63 /* TYPE-0 task context - iSCSI, FCOE */
64 union type0_task_context {
67 /* TYPE-1 task context - ROCE */
68 union type1_task_context {
76 #define CDUT_SEG_ALIGNMET 3 /* in 4k chunks */
77 #define CDUT_SEG_ALIGNMET_IN_BYTES (1 << (CDUT_SEG_ALIGNMET + 12))
79 #define CONN_CXT_SIZE(p_hwfn) \
80 ALIGNED_TYPE_SIZE(union conn_context, p_hwfn)
82 #define SRQ_CXT_SIZE (sizeof(struct regpair) * 8) /* @DPDK */
84 #define TYPE0_TASK_CXT_SIZE(p_hwfn) \
85 ALIGNED_TYPE_SIZE(union type0_task_context, p_hwfn)
87 /* Alignment is inherent to the type1_task_context structure */
88 #define TYPE1_TASK_CXT_SIZE(p_hwfn) sizeof(union type1_task_context)
90 /* PF per protocl configuration object */
91 #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
92 #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
94 struct ecore_tid_seg {
100 struct ecore_conn_type_cfg {
103 struct ecore_tid_seg tid_seg[TASK_SEGMENTS];
106 /* ILT Client configuration,
107 * Per connection type (protocol) resources (cids, tis, vf cids etc.)
108 * 1 - for connection context (CDUC) and for each task context we need two
109 * values, for regular task context and for force load memory
111 #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2)
112 #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2)
115 #define CDUT_SEG_BLK(n) (1 + (u8)(n))
116 #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_##X##_SEGMENTS)
128 struct ilt_cfg_pair {
133 struct ecore_ilt_cli_blk {
134 u32 total_size; /* 0 means not active */
135 u32 real_size_in_page;
137 u32 dynamic_line_cnt;
140 struct ecore_ilt_client_cfg {
144 struct ilt_cfg_pair first;
145 struct ilt_cfg_pair last;
146 struct ilt_cfg_pair p_size;
148 /* ILT client blocks for PF */
149 struct ecore_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS];
152 /* ILT client blocks for VFs */
153 struct ecore_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS];
159 * Protocol acquired CID lists
160 * PF start line in ILT
162 struct ecore_dma_mem {
168 #define MAP_WORD_SIZE sizeof(unsigned long)
169 #define BITS_PER_MAP_WORD (MAP_WORD_SIZE * 8)
171 struct ecore_cid_acquired_map {
174 unsigned long *cid_map;
177 struct ecore_cxt_mngr {
178 /* Per protocl configuration */
179 struct ecore_conn_type_cfg conn_cfg[MAX_CONN_TYPES];
181 /* computed ILT structure */
182 struct ecore_ilt_client_cfg clients[ILT_CLI_MAX];
184 /* Task type sizes */
185 u32 task_type_size[NUM_TASK_TYPES];
187 /* total number of VFs for this hwfn -
188 * ALL VFs are symmetric in terms of HW resources
193 struct ecore_cid_acquired_map acquired[MAX_CONN_TYPES];
194 /* TBD - do we want this allocated to reserve space? */
195 struct ecore_cid_acquired_map
196 acquired_vf[MAX_CONN_TYPES][COMMON_MAX_NUM_VFS];
198 /* ILT shadow table */
199 struct ecore_dma_mem *ilt_shadow;
202 /* Mutex for a dynamic ILT allocation */
206 struct ecore_dma_mem *t2;
211 /* The infrastructure originally was very generic and context/task
212 * oriented - per connection-type we would set how many of those
213 * are needed, and later when determining how much memory we're
214 * needing for a given block we'd iterate over all the relevant
216 * But since then we've had some additional resources, some of which
217 * require memory which is indepent of the general context/task
218 * scheme. We add those here explicitly per-feature.
221 /* total number of SRQ's for this hwfn */
224 /* Maximal number of L2 steering filters */
227 /* TODO - VF arfs filters ? */
230 static OSAL_INLINE bool tm_cid_proto(enum protocol_type type)
232 return type == PROTOCOLID_TOE;
235 static bool tm_tid_proto(enum protocol_type type)
237 return type == PROTOCOLID_FCOE;
240 /* counts the iids for the CDU/CDUC ILT client configuration */
241 struct ecore_cdu_iids {
246 static void ecore_cxt_cdu_iids(struct ecore_cxt_mngr *p_mngr,
247 struct ecore_cdu_iids *iids)
251 for (type = 0; type < MAX_CONN_TYPES; type++) {
252 iids->pf_cids += p_mngr->conn_cfg[type].cid_count;
253 iids->per_vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
257 /* counts the iids for the Searcher block configuration */
258 struct ecore_src_iids {
263 static void ecore_cxt_src_iids(struct ecore_cxt_mngr *p_mngr,
264 struct ecore_src_iids *iids)
268 for (i = 0; i < MAX_CONN_TYPES; i++) {
269 iids->pf_cids += p_mngr->conn_cfg[i].cid_count;
270 iids->per_vf_cids += p_mngr->conn_cfg[i].cids_per_vf;
273 /* Add L2 filtering filters in addition */
274 iids->pf_cids += p_mngr->arfs_count;
277 /* counts the iids for the Timers block configuration */
278 struct ecore_tm_iids {
280 u32 pf_tids[NUM_TASK_PF_SEGMENTS]; /* per segment */
286 static void ecore_cxt_tm_iids(struct ecore_cxt_mngr *p_mngr,
287 struct ecore_tm_iids *iids)
289 bool tm_vf_required = false;
290 bool tm_required = false;
293 for (i = 0; i < MAX_CONN_TYPES; i++) {
294 struct ecore_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[i];
296 if (tm_cid_proto(i) || tm_required) {
297 if (p_cfg->cid_count)
300 iids->pf_cids += p_cfg->cid_count;
303 if (tm_cid_proto(i) || tm_vf_required) {
304 if (p_cfg->cids_per_vf)
305 tm_vf_required = true;
309 if (tm_tid_proto(i)) {
310 struct ecore_tid_seg *segs = p_cfg->tid_seg;
312 /* for each segment there is at most one
313 * protocol for which count is not 0.
315 for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
316 iids->pf_tids[j] += segs[j].count;
318 /* The last array elelment is for the VFs. As for PF
319 * segments there can be only one protocol for
320 * which this value is not 0.
322 iids->per_vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
326 iids->pf_cids = ROUNDUP(iids->pf_cids, TM_ALIGN);
327 iids->per_vf_cids = ROUNDUP(iids->per_vf_cids, TM_ALIGN);
328 iids->per_vf_tids = ROUNDUP(iids->per_vf_tids, TM_ALIGN);
330 for (iids->pf_tids_total = 0, j = 0; j < NUM_TASK_PF_SEGMENTS; j++) {
331 iids->pf_tids[j] = ROUNDUP(iids->pf_tids[j], TM_ALIGN);
332 iids->pf_tids_total += iids->pf_tids[j];
336 static void ecore_cxt_qm_iids(struct ecore_hwfn *p_hwfn,
337 struct ecore_qm_iids *iids)
339 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
340 struct ecore_tid_seg *segs;
341 u32 vf_cids = 0, type, j;
344 for (type = 0; type < MAX_CONN_TYPES; type++) {
345 iids->cids += p_mngr->conn_cfg[type].cid_count;
346 vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
348 segs = p_mngr->conn_cfg[type].tid_seg;
349 /* for each segment there is at most one
350 * protocol for which count is not 0.
352 for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
353 iids->tids += segs[j].count;
355 /* The last array elelment is for the VFs. As for PF
356 * segments there can be only one protocol for
357 * which this value is not 0.
359 vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
362 iids->vf_cids += vf_cids * p_mngr->vf_count;
363 iids->tids += vf_tids * p_mngr->vf_count;
365 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
366 "iids: CIDS %08x vf_cids %08x tids %08x vf_tids %08x\n",
367 iids->cids, iids->vf_cids, iids->tids, vf_tids);
370 static struct ecore_tid_seg *ecore_cxt_tid_seg_info(struct ecore_hwfn *p_hwfn,
373 struct ecore_cxt_mngr *p_cfg = p_hwfn->p_cxt_mngr;
376 /* Find the protocol with tid count > 0 for this segment.
377 * Note: there can only be one and this is already validated.
379 for (i = 0; i < MAX_CONN_TYPES; i++) {
380 if (p_cfg->conn_cfg[i].tid_seg[seg].count)
381 return &p_cfg->conn_cfg[i].tid_seg[seg];
386 static void ecore_cxt_set_srq_count(struct ecore_hwfn *p_hwfn, u32 num_srqs)
388 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
390 p_mgr->srq_count = num_srqs;
393 u32 ecore_cxt_get_srq_count(struct ecore_hwfn *p_hwfn)
395 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
397 return p_mgr->srq_count;
400 /* set the iids (cid/tid) count per protocol */
401 static void ecore_cxt_set_proto_cid_count(struct ecore_hwfn *p_hwfn,
402 enum protocol_type type,
403 u32 cid_count, u32 vf_cid_cnt)
405 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
406 struct ecore_conn_type_cfg *p_conn = &p_mgr->conn_cfg[type];
408 p_conn->cid_count = ROUNDUP(cid_count, DQ_RANGE_ALIGN);
409 p_conn->cids_per_vf = ROUNDUP(vf_cid_cnt, DQ_RANGE_ALIGN);
412 u32 ecore_cxt_get_proto_cid_count(struct ecore_hwfn *p_hwfn,
413 enum protocol_type type, u32 *vf_cid)
416 *vf_cid = p_hwfn->p_cxt_mngr->conn_cfg[type].cids_per_vf;
418 return p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count;
421 u32 ecore_cxt_get_proto_cid_start(struct ecore_hwfn *p_hwfn,
422 enum protocol_type type)
424 return p_hwfn->p_cxt_mngr->acquired[type].start_cid;
427 u32 ecore_cxt_get_proto_tid_count(struct ecore_hwfn *p_hwfn,
428 enum protocol_type type)
433 for (i = 0; i < TASK_SEGMENTS; i++)
434 cnt += p_hwfn->p_cxt_mngr->conn_cfg[type].tid_seg[i].count;
439 static OSAL_INLINE void
440 ecore_cxt_set_proto_tid_count(struct ecore_hwfn *p_hwfn,
441 enum protocol_type proto,
442 u8 seg, u8 seg_type, u32 count, bool has_fl)
444 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
445 struct ecore_tid_seg *p_seg = &p_mngr->conn_cfg[proto].tid_seg[seg];
447 p_seg->count = count;
448 p_seg->has_fl_mem = has_fl;
449 p_seg->type = seg_type;
452 /* the *p_line parameter must be either 0 for the first invocation or the
453 * value returned in the previous invocation.
455 static void ecore_ilt_cli_blk_fill(struct ecore_ilt_client_cfg *p_cli,
456 struct ecore_ilt_cli_blk *p_blk,
458 u32 total_size, u32 elem_size)
460 u32 ilt_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val);
462 /* verify that it's called once for each block */
463 if (p_blk->total_size)
466 p_blk->total_size = total_size;
467 p_blk->real_size_in_page = 0;
469 p_blk->real_size_in_page = (ilt_size / elem_size) * elem_size;
470 p_blk->start_line = start_line;
473 static void ecore_ilt_cli_adv_line(struct ecore_hwfn *p_hwfn,
474 struct ecore_ilt_client_cfg *p_cli,
475 struct ecore_ilt_cli_blk *p_blk,
476 u32 *p_line, enum ilt_clients client_id)
478 if (!p_blk->total_size)
482 p_cli->first.val = *p_line;
484 p_cli->active = true;
485 *p_line += DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page);
486 p_cli->last.val = *p_line - 1;
488 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
489 "ILT[Client %d] - Lines: [%08x - %08x]. Block - Size %08x"
490 " [Real %08x] Start line %d\n",
491 client_id, p_cli->first.val, p_cli->last.val,
492 p_blk->total_size, p_blk->real_size_in_page,
496 static u32 ecore_ilt_get_dynamic_line_cnt(struct ecore_hwfn *p_hwfn,
497 enum ilt_clients ilt_client)
499 u32 cid_count = p_hwfn->p_cxt_mngr->conn_cfg[PROTOCOLID_ROCE].cid_count;
500 struct ecore_ilt_client_cfg *p_cli;
501 u32 lines_to_skip = 0;
504 /* TBD MK: ILT code should be simplified once PROTO enum is changed */
506 if (ilt_client == ILT_CLI_CDUC) {
507 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
509 cxts_per_p = ILT_PAGE_IN_BYTES(p_cli->p_size.val) /
510 (u32)CONN_CXT_SIZE(p_hwfn);
512 lines_to_skip = cid_count / cxts_per_p;
515 return lines_to_skip;
518 enum _ecore_status_t ecore_cxt_cfg_ilt_compute(struct ecore_hwfn *p_hwfn)
520 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
521 u32 curr_line, total, i, task_size, line;
522 struct ecore_ilt_client_cfg *p_cli;
523 struct ecore_ilt_cli_blk *p_blk;
524 struct ecore_cdu_iids cdu_iids;
525 struct ecore_src_iids src_iids;
526 struct ecore_qm_iids qm_iids;
527 struct ecore_tm_iids tm_iids;
528 struct ecore_tid_seg *p_seg;
530 OSAL_MEM_ZERO(&qm_iids, sizeof(qm_iids));
531 OSAL_MEM_ZERO(&cdu_iids, sizeof(cdu_iids));
532 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
533 OSAL_MEM_ZERO(&tm_iids, sizeof(tm_iids));
535 p_mngr->pf_start_line = RESC_START(p_hwfn, ECORE_ILT);
537 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
538 "hwfn [%d] - Set context mngr starting line to be 0x%08x\n",
539 p_hwfn->my_id, p_hwfn->p_cxt_mngr->pf_start_line);
542 p_cli = &p_mngr->clients[ILT_CLI_CDUC];
544 curr_line = p_mngr->pf_start_line;
547 p_cli->pf_total_lines = 0;
549 /* get the counters for the CDUC,CDUC and QM clients */
550 ecore_cxt_cdu_iids(p_mngr, &cdu_iids);
552 p_blk = &p_cli->pf_blks[CDUC_BLK];
554 total = cdu_iids.pf_cids * CONN_CXT_SIZE(p_hwfn);
556 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
557 total, CONN_CXT_SIZE(p_hwfn));
559 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
560 p_cli->pf_total_lines = curr_line - p_blk->start_line;
562 p_blk->dynamic_line_cnt = ecore_ilt_get_dynamic_line_cnt(p_hwfn,
566 p_blk = &p_cli->vf_blks[CDUC_BLK];
567 total = cdu_iids.per_vf_cids * CONN_CXT_SIZE(p_hwfn);
569 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
570 total, CONN_CXT_SIZE(p_hwfn));
572 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
573 p_cli->vf_total_lines = curr_line - p_blk->start_line;
575 for (i = 1; i < p_mngr->vf_count; i++)
576 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
580 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
581 p_cli->first.val = curr_line;
583 /* first the 'working' task memory */
584 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
585 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
586 if (!p_seg || p_seg->count == 0)
589 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(i)];
590 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
591 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total,
592 p_mngr->task_type_size[p_seg->type]);
594 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
598 /* next the 'init' task memory (forced load memory) */
599 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
600 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
601 if (!p_seg || p_seg->count == 0)
604 p_blk = &p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)];
606 if (!p_seg->has_fl_mem) {
607 /* The segment is active (total size pf 'working'
608 * memory is > 0) but has no FL (forced-load, Init)
611 * 1. The total-size in the corrsponding FL block of
612 * the ILT client is set to 0 - No ILT line are
613 * provisioned and no ILT memory allocated.
615 * 2. The start-line of said block is set to the
616 * start line of the matching working memory
617 * block in the ILT client. This is later used to
618 * configure the CDU segment offset registers and
619 * results in an FL command for TIDs of this
620 * segment behaves as regular load commands
621 * (loading TIDs from the working memory).
623 line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line;
625 ecore_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
628 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
630 ecore_ilt_cli_blk_fill(p_cli, p_blk,
632 p_mngr->task_type_size[p_seg->type]);
634 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
637 p_cli->pf_total_lines = curr_line - p_cli->pf_blks[0].start_line;
640 p_seg = ecore_cxt_tid_seg_info(p_hwfn, TASK_SEGMENT_VF);
641 if (p_seg && p_seg->count) {
642 /* Stricly speaking we need to iterate over all VF
643 * task segment types, but a VF has only 1 segment
646 /* 'working' memory */
647 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
649 p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)];
650 ecore_ilt_cli_blk_fill(p_cli, p_blk,
652 p_mngr->task_type_size[p_seg->type]);
654 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
658 p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)];
659 if (!p_seg->has_fl_mem) {
660 /* see comment above */
661 line = p_cli->vf_blks[CDUT_SEG_BLK(0)].start_line;
662 ecore_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
664 task_size = p_mngr->task_type_size[p_seg->type];
665 ecore_ilt_cli_blk_fill(p_cli, p_blk,
666 curr_line, total, task_size);
667 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
670 p_cli->vf_total_lines = curr_line -
671 p_cli->vf_blks[0].start_line;
673 /* Now for the rest of the VFs */
674 for (i = 1; i < p_mngr->vf_count; i++) {
675 p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)];
676 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
679 p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)];
680 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
686 p_cli = &p_mngr->clients[ILT_CLI_QM];
687 p_blk = &p_cli->pf_blks[0];
689 ecore_cxt_qm_iids(p_hwfn, &qm_iids);
690 total = ecore_qm_pf_mem_size(qm_iids.cids,
691 qm_iids.vf_cids, qm_iids.tids,
692 p_hwfn->qm_info.num_pqs,
693 p_hwfn->qm_info.num_vf_pqs);
695 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
696 "QM ILT Info, (cids=%d, vf_cids=%d, tids=%d, num_pqs=%d,"
697 " num_vf_pqs=%d, memory_size=%d)\n",
698 qm_iids.cids, qm_iids.vf_cids, qm_iids.tids,
699 p_hwfn->qm_info.num_pqs, p_hwfn->qm_info.num_vf_pqs, total);
701 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total * 0x1000,
704 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_QM);
705 p_cli->pf_total_lines = curr_line - p_blk->start_line;
708 p_cli = &p_mngr->clients[ILT_CLI_SRC];
709 ecore_cxt_src_iids(p_mngr, &src_iids);
711 /* Both the PF and VFs searcher connections are stored in the per PF
712 * database. Thus sum the PF searcher cids and all the VFs searcher
715 total = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
717 u32 local_max = OSAL_MAX_T(u32, total,
720 total = OSAL_ROUNDUP_POW_OF_TWO(local_max);
722 p_blk = &p_cli->pf_blks[0];
723 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
724 total * sizeof(struct src_ent),
725 sizeof(struct src_ent));
727 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
729 p_cli->pf_total_lines = curr_line - p_blk->start_line;
733 p_cli = &p_mngr->clients[ILT_CLI_TM];
734 ecore_cxt_tm_iids(p_mngr, &tm_iids);
735 total = tm_iids.pf_cids + tm_iids.pf_tids_total;
737 p_blk = &p_cli->pf_blks[0];
738 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
739 total * TM_ELEM_SIZE, TM_ELEM_SIZE);
741 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
743 p_cli->pf_total_lines = curr_line - p_blk->start_line;
747 total = tm_iids.per_vf_cids + tm_iids.per_vf_tids;
749 p_blk = &p_cli->vf_blks[0];
750 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
751 total * TM_ELEM_SIZE, TM_ELEM_SIZE);
753 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
756 p_cli->vf_total_lines = curr_line - p_blk->start_line;
757 for (i = 1; i < p_mngr->vf_count; i++) {
758 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
763 /* TSDM (SRQ CONTEXT) */
764 total = ecore_cxt_get_srq_count(p_hwfn);
767 p_cli = &p_mngr->clients[ILT_CLI_TSDM];
768 p_blk = &p_cli->pf_blks[SRQ_BLK];
769 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
770 total * SRQ_CXT_SIZE, SRQ_CXT_SIZE);
772 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
774 p_cli->pf_total_lines = curr_line - p_blk->start_line;
777 if (curr_line - p_hwfn->p_cxt_mngr->pf_start_line >
778 RESC_NUM(p_hwfn, ECORE_ILT)) {
779 DP_ERR(p_hwfn, "too many ilt lines...#lines=%d\n",
780 curr_line - p_hwfn->p_cxt_mngr->pf_start_line);
784 return ECORE_SUCCESS;
787 static void ecore_cxt_src_t2_free(struct ecore_hwfn *p_hwfn)
789 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
795 for (i = 0; i < p_mngr->t2_num_pages; i++)
796 if (p_mngr->t2[i].p_virt)
797 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
798 p_mngr->t2[i].p_virt,
799 p_mngr->t2[i].p_phys,
802 OSAL_FREE(p_hwfn->p_dev, p_mngr->t2);
805 static enum _ecore_status_t ecore_cxt_src_t2_alloc(struct ecore_hwfn *p_hwfn)
807 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
808 u32 conn_num, total_size, ent_per_page, psz, i;
809 struct ecore_ilt_client_cfg *p_src;
810 struct ecore_src_iids src_iids;
811 struct ecore_dma_mem *p_t2;
812 enum _ecore_status_t rc;
814 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
816 /* if the SRC ILT client is inactive - there are no connection
817 * requiring the searcer, leave.
819 p_src = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_SRC];
821 return ECORE_SUCCESS;
823 ecore_cxt_src_iids(p_mngr, &src_iids);
824 conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
825 total_size = conn_num * sizeof(struct src_ent);
827 /* use the same page size as the SRC ILT client */
828 psz = ILT_PAGE_IN_BYTES(p_src->p_size.val);
829 p_mngr->t2_num_pages = DIV_ROUND_UP(total_size, psz);
832 p_mngr->t2 = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
833 p_mngr->t2_num_pages *
834 sizeof(struct ecore_dma_mem));
836 DP_NOTICE(p_hwfn, true, "Failed to allocate t2 table\n");
841 /* allocate t2 pages */
842 for (i = 0; i < p_mngr->t2_num_pages; i++) {
843 u32 size = OSAL_MIN_T(u32, total_size, psz);
844 void **p_virt = &p_mngr->t2[i].p_virt;
846 *p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
847 &p_mngr->t2[i].p_phys, size);
848 if (!p_mngr->t2[i].p_virt) {
852 OSAL_MEM_ZERO(*p_virt, size);
853 p_mngr->t2[i].size = size;
857 /* Set the t2 pointers */
859 /* entries per page - must be a power of two */
860 ent_per_page = psz / sizeof(struct src_ent);
862 p_mngr->first_free = (u64)p_mngr->t2[0].p_phys;
864 p_t2 = &p_mngr->t2[(conn_num - 1) / ent_per_page];
865 p_mngr->last_free = (u64)p_t2->p_phys +
866 ((conn_num - 1) & (ent_per_page - 1)) * sizeof(struct src_ent);
868 for (i = 0; i < p_mngr->t2_num_pages; i++) {
869 u32 ent_num = OSAL_MIN_T(u32, ent_per_page, conn_num);
870 struct src_ent *entries = p_mngr->t2[i].p_virt;
871 u64 p_ent_phys = (u64)p_mngr->t2[i].p_phys, val;
874 for (j = 0; j < ent_num - 1; j++) {
875 val = p_ent_phys + (j + 1) * sizeof(struct src_ent);
876 entries[j].next = OSAL_CPU_TO_BE64(val);
879 if (i < p_mngr->t2_num_pages - 1)
880 val = (u64)p_mngr->t2[i + 1].p_phys;
883 entries[j].next = OSAL_CPU_TO_BE64(val);
888 return ECORE_SUCCESS;
891 ecore_cxt_src_t2_free(p_hwfn);
895 #define for_each_ilt_valid_client(pos, clients) \
896 for (pos = 0; pos < ILT_CLI_MAX; pos++) \
897 if (!clients[pos].active) { \
902 /* Total number of ILT lines used by this PF */
903 static u32 ecore_cxt_ilt_shadow_size(struct ecore_ilt_client_cfg *ilt_clients)
908 for_each_ilt_valid_client(i, ilt_clients)
909 size += (ilt_clients[i].last.val -
910 ilt_clients[i].first.val + 1);
915 static void ecore_ilt_shadow_free(struct ecore_hwfn *p_hwfn)
917 struct ecore_ilt_client_cfg *p_cli = p_hwfn->p_cxt_mngr->clients;
918 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
921 ilt_size = ecore_cxt_ilt_shadow_size(p_cli);
923 for (i = 0; p_mngr->ilt_shadow && i < ilt_size; i++) {
924 struct ecore_dma_mem *p_dma = &p_mngr->ilt_shadow[i];
927 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
929 p_dma->p_phys, p_dma->size);
930 p_dma->p_virt = OSAL_NULL;
932 OSAL_FREE(p_hwfn->p_dev, p_mngr->ilt_shadow);
935 static enum _ecore_status_t
936 ecore_ilt_blk_alloc(struct ecore_hwfn *p_hwfn,
937 struct ecore_ilt_cli_blk *p_blk,
938 enum ilt_clients ilt_client, u32 start_line_offset)
940 struct ecore_dma_mem *ilt_shadow = p_hwfn->p_cxt_mngr->ilt_shadow;
941 u32 lines, line, sz_left, lines_to_skip = 0;
943 /* Special handling for RoCE that supports dynamic allocation */
944 if (ilt_client == ILT_CLI_CDUT || ilt_client == ILT_CLI_TSDM)
945 return ECORE_SUCCESS;
947 lines_to_skip = p_blk->dynamic_line_cnt;
949 if (!p_blk->total_size)
950 return ECORE_SUCCESS;
952 sz_left = p_blk->total_size;
953 lines = DIV_ROUND_UP(sz_left, p_blk->real_size_in_page) - lines_to_skip;
954 line = p_blk->start_line + start_line_offset -
955 p_hwfn->p_cxt_mngr->pf_start_line + lines_to_skip;
957 for (; lines; lines--) {
962 size = OSAL_MIN_T(u32, sz_left, p_blk->real_size_in_page);
965 #define ILT_BLOCK_ALIGN_SIZE 0x1000
966 p_virt = OSAL_DMA_ALLOC_COHERENT_ALIGNED(p_hwfn->p_dev,
968 ILT_BLOCK_ALIGN_SIZE);
971 OSAL_MEM_ZERO(p_virt, size);
973 ilt_shadow[line].p_phys = p_phys;
974 ilt_shadow[line].p_virt = p_virt;
975 ilt_shadow[line].size = size;
977 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
978 "ILT shadow: Line [%d] Physical 0x%lx"
979 " Virtual %p Size %d\n",
980 line, (unsigned long)p_phys, p_virt, size);
986 return ECORE_SUCCESS;
989 static enum _ecore_status_t ecore_ilt_shadow_alloc(struct ecore_hwfn *p_hwfn)
991 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
992 struct ecore_ilt_client_cfg *clients = p_mngr->clients;
993 struct ecore_ilt_cli_blk *p_blk;
995 enum _ecore_status_t rc;
997 size = ecore_cxt_ilt_shadow_size(clients);
998 p_mngr->ilt_shadow = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
999 size * sizeof(struct ecore_dma_mem));
1001 if (!p_mngr->ilt_shadow) {
1002 DP_NOTICE(p_hwfn, true,
1003 "Failed to allocate ilt shadow table\n");
1005 goto ilt_shadow_fail;
1008 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1009 "Allocated 0x%x bytes for ilt shadow\n",
1010 (u32)(size * sizeof(struct ecore_dma_mem)));
1012 for_each_ilt_valid_client(i, clients) {
1013 for (j = 0; j < ILT_CLI_PF_BLOCKS; j++) {
1014 p_blk = &clients[i].pf_blks[j];
1015 rc = ecore_ilt_blk_alloc(p_hwfn, p_blk, i, 0);
1016 if (rc != ECORE_SUCCESS)
1017 goto ilt_shadow_fail;
1019 for (k = 0; k < p_mngr->vf_count; k++) {
1020 for (j = 0; j < ILT_CLI_VF_BLOCKS; j++) {
1021 u32 lines = clients[i].vf_total_lines * k;
1023 p_blk = &clients[i].vf_blks[j];
1024 rc = ecore_ilt_blk_alloc(p_hwfn, p_blk,
1026 if (rc != ECORE_SUCCESS)
1027 goto ilt_shadow_fail;
1032 return ECORE_SUCCESS;
1035 ecore_ilt_shadow_free(p_hwfn);
1039 static void ecore_cid_map_free(struct ecore_hwfn *p_hwfn)
1041 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1044 for (type = 0; type < MAX_CONN_TYPES; type++) {
1045 OSAL_FREE(p_hwfn->p_dev, p_mngr->acquired[type].cid_map);
1046 p_mngr->acquired[type].max_count = 0;
1047 p_mngr->acquired[type].start_cid = 0;
1049 for (vf = 0; vf < COMMON_MAX_NUM_VFS; vf++) {
1050 OSAL_FREE(p_hwfn->p_dev,
1051 p_mngr->acquired_vf[type][vf].cid_map);
1052 p_mngr->acquired_vf[type][vf].max_count = 0;
1053 p_mngr->acquired_vf[type][vf].start_cid = 0;
1058 static enum _ecore_status_t
1059 ecore_cid_map_alloc_single(struct ecore_hwfn *p_hwfn, u32 type,
1060 u32 cid_start, u32 cid_count,
1061 struct ecore_cid_acquired_map *p_map)
1066 return ECORE_SUCCESS;
1068 size = MAP_WORD_SIZE * DIV_ROUND_UP(cid_count, BITS_PER_MAP_WORD);
1069 p_map->cid_map = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, size);
1070 if (p_map->cid_map == OSAL_NULL)
1073 p_map->max_count = cid_count;
1074 p_map->start_cid = cid_start;
1076 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
1077 "Type %08x start: %08x count %08x\n",
1078 type, p_map->start_cid, p_map->max_count);
1080 return ECORE_SUCCESS;
1083 static enum _ecore_status_t ecore_cid_map_alloc(struct ecore_hwfn *p_hwfn)
1085 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1086 u32 start_cid = 0, vf_start_cid = 0;
1089 for (type = 0; type < MAX_CONN_TYPES; type++) {
1090 struct ecore_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[type];
1091 struct ecore_cid_acquired_map *p_map;
1093 /* Handle PF maps */
1094 p_map = &p_mngr->acquired[type];
1095 if (ecore_cid_map_alloc_single(p_hwfn, type, start_cid,
1096 p_cfg->cid_count, p_map))
1099 /* Handle VF maps */
1100 for (vf = 0; vf < COMMON_MAX_NUM_VFS; vf++) {
1101 p_map = &p_mngr->acquired_vf[type][vf];
1102 if (ecore_cid_map_alloc_single(p_hwfn, type,
1109 start_cid += p_cfg->cid_count;
1110 vf_start_cid += p_cfg->cids_per_vf;
1113 return ECORE_SUCCESS;
1116 ecore_cid_map_free(p_hwfn);
1120 enum _ecore_status_t ecore_cxt_mngr_alloc(struct ecore_hwfn *p_hwfn)
1122 struct ecore_ilt_client_cfg *clients;
1123 struct ecore_cxt_mngr *p_mngr;
1126 p_mngr = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_mngr));
1128 DP_NOTICE(p_hwfn, true,
1129 "Failed to allocate `struct ecore_cxt_mngr'\n");
1133 /* Initialize ILT client registers */
1134 clients = p_mngr->clients;
1135 clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT);
1136 clients[ILT_CLI_CDUC].last.reg = ILT_CFG_REG(CDUC, LAST_ILT);
1137 clients[ILT_CLI_CDUC].p_size.reg = ILT_CFG_REG(CDUC, P_SIZE);
1139 clients[ILT_CLI_QM].first.reg = ILT_CFG_REG(QM, FIRST_ILT);
1140 clients[ILT_CLI_QM].last.reg = ILT_CFG_REG(QM, LAST_ILT);
1141 clients[ILT_CLI_QM].p_size.reg = ILT_CFG_REG(QM, P_SIZE);
1143 clients[ILT_CLI_TM].first.reg = ILT_CFG_REG(TM, FIRST_ILT);
1144 clients[ILT_CLI_TM].last.reg = ILT_CFG_REG(TM, LAST_ILT);
1145 clients[ILT_CLI_TM].p_size.reg = ILT_CFG_REG(TM, P_SIZE);
1147 clients[ILT_CLI_SRC].first.reg = ILT_CFG_REG(SRC, FIRST_ILT);
1148 clients[ILT_CLI_SRC].last.reg = ILT_CFG_REG(SRC, LAST_ILT);
1149 clients[ILT_CLI_SRC].p_size.reg = ILT_CFG_REG(SRC, P_SIZE);
1151 clients[ILT_CLI_CDUT].first.reg = ILT_CFG_REG(CDUT, FIRST_ILT);
1152 clients[ILT_CLI_CDUT].last.reg = ILT_CFG_REG(CDUT, LAST_ILT);
1153 clients[ILT_CLI_CDUT].p_size.reg = ILT_CFG_REG(CDUT, P_SIZE);
1155 clients[ILT_CLI_TSDM].first.reg = ILT_CFG_REG(TSDM, FIRST_ILT);
1156 clients[ILT_CLI_TSDM].last.reg = ILT_CFG_REG(TSDM, LAST_ILT);
1157 clients[ILT_CLI_TSDM].p_size.reg = ILT_CFG_REG(TSDM, P_SIZE);
1159 /* default ILT page size for all clients is 64K */
1160 for (i = 0; i < ILT_CLI_MAX; i++)
1161 p_mngr->clients[i].p_size.val = ILT_DEFAULT_HW_P_SIZE;
1163 /* due to removal of ISCSI/FCoE files union type0_task_context
1164 * task_type_size will be 0. So hardcoded for now.
1166 p_mngr->task_type_size[0] = 512; /* @DPDK */
1167 p_mngr->task_type_size[1] = 128; /* @DPDK */
1169 if (p_hwfn->p_dev->p_iov_info)
1170 p_mngr->vf_count = p_hwfn->p_dev->p_iov_info->total_vfs;
1172 /* Initialize the dynamic ILT allocation mutex */
1173 #ifdef CONFIG_ECORE_LOCK_ALLOC
1174 OSAL_MUTEX_ALLOC(p_hwfn, &p_mngr->mutex);
1176 OSAL_MUTEX_INIT(&p_mngr->mutex);
1178 /* Set the cxt mangr pointer priori to further allocations */
1179 p_hwfn->p_cxt_mngr = p_mngr;
1181 return ECORE_SUCCESS;
1184 enum _ecore_status_t ecore_cxt_tables_alloc(struct ecore_hwfn *p_hwfn)
1186 enum _ecore_status_t rc;
1188 /* Allocate the ILT shadow table */
1189 rc = ecore_ilt_shadow_alloc(p_hwfn);
1191 DP_NOTICE(p_hwfn, true, "Failed to allocate ilt memory\n");
1192 goto tables_alloc_fail;
1195 /* Allocate the T2 table */
1196 rc = ecore_cxt_src_t2_alloc(p_hwfn);
1198 DP_NOTICE(p_hwfn, true, "Failed to allocate T2 memory\n");
1199 goto tables_alloc_fail;
1202 /* Allocate and initialize the acquired cids bitmaps */
1203 rc = ecore_cid_map_alloc(p_hwfn);
1205 DP_NOTICE(p_hwfn, true, "Failed to allocate cid maps\n");
1206 goto tables_alloc_fail;
1209 return ECORE_SUCCESS;
1212 ecore_cxt_mngr_free(p_hwfn);
1216 void ecore_cxt_mngr_free(struct ecore_hwfn *p_hwfn)
1218 if (!p_hwfn->p_cxt_mngr)
1221 ecore_cid_map_free(p_hwfn);
1222 ecore_cxt_src_t2_free(p_hwfn);
1223 ecore_ilt_shadow_free(p_hwfn);
1224 #ifdef CONFIG_ECORE_LOCK_ALLOC
1225 OSAL_MUTEX_DEALLOC(&p_hwfn->p_cxt_mngr->mutex);
1227 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_cxt_mngr);
1230 void ecore_cxt_mngr_setup(struct ecore_hwfn *p_hwfn)
1232 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1233 struct ecore_cid_acquired_map *p_map;
1234 struct ecore_conn_type_cfg *p_cfg;
1238 /* Reset acquired cids */
1239 for (type = 0; type < MAX_CONN_TYPES; type++) {
1242 p_cfg = &p_mngr->conn_cfg[type];
1243 if (p_cfg->cid_count) {
1244 p_map = &p_mngr->acquired[type];
1245 len = DIV_ROUND_UP(p_map->max_count,
1246 BITS_PER_MAP_WORD) *
1248 OSAL_MEM_ZERO(p_map->cid_map, len);
1251 if (!p_cfg->cids_per_vf)
1254 for (vf = 0; vf < COMMON_MAX_NUM_VFS; vf++) {
1255 p_map = &p_mngr->acquired_vf[type][vf];
1256 len = DIV_ROUND_UP(p_map->max_count,
1257 BITS_PER_MAP_WORD) *
1259 OSAL_MEM_ZERO(p_map->cid_map, len);
1264 /* HW initialization helper (per Block, per phase) */
1267 #define CDUC_CXT_SIZE_SHIFT \
1268 CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE_SHIFT
1270 #define CDUC_CXT_SIZE_MASK \
1271 (CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE >> CDUC_CXT_SIZE_SHIFT)
1273 #define CDUC_BLOCK_WASTE_SHIFT \
1274 CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE_SHIFT
1276 #define CDUC_BLOCK_WASTE_MASK \
1277 (CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE >> CDUC_BLOCK_WASTE_SHIFT)
1279 #define CDUC_NCIB_SHIFT \
1280 CDU_REG_CID_ADDR_PARAMS_NCIB_SHIFT
1282 #define CDUC_NCIB_MASK \
1283 (CDU_REG_CID_ADDR_PARAMS_NCIB >> CDUC_NCIB_SHIFT)
1285 #define CDUT_TYPE0_CXT_SIZE_SHIFT \
1286 CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE_SHIFT
1288 #define CDUT_TYPE0_CXT_SIZE_MASK \
1289 (CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE >> \
1290 CDUT_TYPE0_CXT_SIZE_SHIFT)
1292 #define CDUT_TYPE0_BLOCK_WASTE_SHIFT \
1293 CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE_SHIFT
1295 #define CDUT_TYPE0_BLOCK_WASTE_MASK \
1296 (CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE >> \
1297 CDUT_TYPE0_BLOCK_WASTE_SHIFT)
1299 #define CDUT_TYPE0_NCIB_SHIFT \
1300 CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK_SHIFT
1302 #define CDUT_TYPE0_NCIB_MASK \
1303 (CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK >> \
1304 CDUT_TYPE0_NCIB_SHIFT)
1306 #define CDUT_TYPE1_CXT_SIZE_SHIFT \
1307 CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE_SHIFT
1309 #define CDUT_TYPE1_CXT_SIZE_MASK \
1310 (CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE >> \
1311 CDUT_TYPE1_CXT_SIZE_SHIFT)
1313 #define CDUT_TYPE1_BLOCK_WASTE_SHIFT \
1314 CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE_SHIFT
1316 #define CDUT_TYPE1_BLOCK_WASTE_MASK \
1317 (CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE >> \
1318 CDUT_TYPE1_BLOCK_WASTE_SHIFT)
1320 #define CDUT_TYPE1_NCIB_SHIFT \
1321 CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK_SHIFT
1323 #define CDUT_TYPE1_NCIB_MASK \
1324 (CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK >> \
1325 CDUT_TYPE1_NCIB_SHIFT)
1327 static void ecore_cdu_init_common(struct ecore_hwfn *p_hwfn)
1329 u32 page_sz, elems_per_page, block_waste, cxt_size, cdu_params = 0;
1331 /* CDUC - connection configuration */
1332 page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
1333 cxt_size = CONN_CXT_SIZE(p_hwfn);
1334 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1335 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1337 SET_FIELD(cdu_params, CDUC_CXT_SIZE, cxt_size);
1338 SET_FIELD(cdu_params, CDUC_BLOCK_WASTE, block_waste);
1339 SET_FIELD(cdu_params, CDUC_NCIB, elems_per_page);
1340 STORE_RT_REG(p_hwfn, CDU_REG_CID_ADDR_PARAMS_RT_OFFSET, cdu_params);
1342 /* CDUT - type-0 tasks configuration */
1343 page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT].p_size.val;
1344 cxt_size = p_hwfn->p_cxt_mngr->task_type_size[0];
1345 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1346 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1348 /* cxt size and block-waste are multipes of 8 */
1350 SET_FIELD(cdu_params, CDUT_TYPE0_CXT_SIZE, (cxt_size >> 3));
1351 SET_FIELD(cdu_params, CDUT_TYPE0_BLOCK_WASTE, (block_waste >> 3));
1352 SET_FIELD(cdu_params, CDUT_TYPE0_NCIB, elems_per_page);
1353 STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT0_PARAMS_RT_OFFSET, cdu_params);
1355 /* CDUT - type-1 tasks configuration */
1356 cxt_size = p_hwfn->p_cxt_mngr->task_type_size[1];
1357 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1358 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1360 /* cxt size and block-waste are multipes of 8 */
1362 SET_FIELD(cdu_params, CDUT_TYPE1_CXT_SIZE, (cxt_size >> 3));
1363 SET_FIELD(cdu_params, CDUT_TYPE1_BLOCK_WASTE, (block_waste >> 3));
1364 SET_FIELD(cdu_params, CDUT_TYPE1_NCIB, elems_per_page);
1365 STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT1_PARAMS_RT_OFFSET, cdu_params);
1369 #define CDU_SEG_REG_TYPE_SHIFT CDU_SEG_TYPE_OFFSET_REG_TYPE_SHIFT
1370 #define CDU_SEG_REG_TYPE_MASK 0x1
1371 #define CDU_SEG_REG_OFFSET_SHIFT 0
1372 #define CDU_SEG_REG_OFFSET_MASK CDU_SEG_TYPE_OFFSET_REG_OFFSET_MASK
1374 static void ecore_cdu_init_pf(struct ecore_hwfn *p_hwfn)
1376 struct ecore_ilt_client_cfg *p_cli;
1377 struct ecore_tid_seg *p_seg;
1378 u32 cdu_seg_params, offset;
1381 static const u32 rt_type_offset_arr[] = {
1382 CDU_REG_PF_SEG0_TYPE_OFFSET_RT_OFFSET,
1383 CDU_REG_PF_SEG1_TYPE_OFFSET_RT_OFFSET,
1384 CDU_REG_PF_SEG2_TYPE_OFFSET_RT_OFFSET,
1385 CDU_REG_PF_SEG3_TYPE_OFFSET_RT_OFFSET
1388 static const u32 rt_type_offset_fl_arr[] = {
1389 CDU_REG_PF_FL_SEG0_TYPE_OFFSET_RT_OFFSET,
1390 CDU_REG_PF_FL_SEG1_TYPE_OFFSET_RT_OFFSET,
1391 CDU_REG_PF_FL_SEG2_TYPE_OFFSET_RT_OFFSET,
1392 CDU_REG_PF_FL_SEG3_TYPE_OFFSET_RT_OFFSET
1395 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1397 /* There are initializations only for CDUT during pf Phase */
1398 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
1400 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
1404 /* Note: start_line is already adjusted for the CDU
1405 * segment register granularity, so we just need to
1406 * divide. Adjustment is implicit as we assume ILT
1407 * Page size is larger than 32K!
1409 offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
1410 (p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line -
1411 p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
1414 SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
1415 SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
1416 STORE_RT_REG(p_hwfn, rt_type_offset_arr[i], cdu_seg_params);
1418 offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
1419 (p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)].start_line -
1420 p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
1423 SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
1424 SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
1425 STORE_RT_REG(p_hwfn, rt_type_offset_fl_arr[i], cdu_seg_params);
1429 void ecore_qm_init_pf(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1431 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
1432 struct ecore_mcp_link_state *p_link;
1433 struct ecore_qm_iids iids;
1435 OSAL_MEM_ZERO(&iids, sizeof(iids));
1436 ecore_cxt_qm_iids(p_hwfn, &iids);
1438 p_link = &ECORE_LEADING_HWFN(p_hwfn->p_dev)->mcp_info->link_output;
1440 ecore_qm_pf_rt_init(p_hwfn, p_ptt, p_hwfn->port_id,
1441 p_hwfn->rel_pf_id, qm_info->max_phys_tcs_per_port,
1442 iids.cids, iids.vf_cids, iids.tids,
1444 qm_info->num_pqs - qm_info->num_vf_pqs,
1445 qm_info->num_vf_pqs,
1446 qm_info->start_vport,
1447 qm_info->num_vports, qm_info->pf_wfq,
1448 qm_info->pf_rl, p_link->speed,
1449 p_hwfn->qm_info.qm_pq_params,
1450 p_hwfn->qm_info.qm_vport_params);
1454 static void ecore_cm_init_pf(struct ecore_hwfn *p_hwfn)
1456 STORE_RT_REG(p_hwfn, XCM_REG_CON_PHY_Q3_RT_OFFSET,
1457 ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB));
1461 static void ecore_dq_init_pf(struct ecore_hwfn *p_hwfn)
1463 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1464 u32 dq_pf_max_cid = 0, dq_vf_max_cid = 0;
1466 dq_pf_max_cid += (p_mngr->conn_cfg[0].cid_count >> DQ_RANGE_SHIFT);
1467 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_0_RT_OFFSET, dq_pf_max_cid);
1469 dq_vf_max_cid += (p_mngr->conn_cfg[0].cids_per_vf >> DQ_RANGE_SHIFT);
1470 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_0_RT_OFFSET, dq_vf_max_cid);
1472 dq_pf_max_cid += (p_mngr->conn_cfg[1].cid_count >> DQ_RANGE_SHIFT);
1473 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_1_RT_OFFSET, dq_pf_max_cid);
1475 dq_vf_max_cid += (p_mngr->conn_cfg[1].cids_per_vf >> DQ_RANGE_SHIFT);
1476 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_1_RT_OFFSET, dq_vf_max_cid);
1478 dq_pf_max_cid += (p_mngr->conn_cfg[2].cid_count >> DQ_RANGE_SHIFT);
1479 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_2_RT_OFFSET, dq_pf_max_cid);
1481 dq_vf_max_cid += (p_mngr->conn_cfg[2].cids_per_vf >> DQ_RANGE_SHIFT);
1482 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_2_RT_OFFSET, dq_vf_max_cid);
1484 dq_pf_max_cid += (p_mngr->conn_cfg[3].cid_count >> DQ_RANGE_SHIFT);
1485 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_3_RT_OFFSET, dq_pf_max_cid);
1487 dq_vf_max_cid += (p_mngr->conn_cfg[3].cids_per_vf >> DQ_RANGE_SHIFT);
1488 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_3_RT_OFFSET, dq_vf_max_cid);
1490 dq_pf_max_cid += (p_mngr->conn_cfg[4].cid_count >> DQ_RANGE_SHIFT);
1491 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_4_RT_OFFSET, dq_pf_max_cid);
1493 dq_vf_max_cid += (p_mngr->conn_cfg[4].cids_per_vf >> DQ_RANGE_SHIFT);
1494 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_4_RT_OFFSET, dq_vf_max_cid);
1496 dq_pf_max_cid += (p_mngr->conn_cfg[5].cid_count >> DQ_RANGE_SHIFT);
1497 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_5_RT_OFFSET, dq_pf_max_cid);
1499 dq_vf_max_cid += (p_mngr->conn_cfg[5].cids_per_vf >> DQ_RANGE_SHIFT);
1500 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_5_RT_OFFSET, dq_vf_max_cid);
1502 /* Connection types 6 & 7 are not in use, yet they must be configured
1503 * as the highest possible connection. Not configuring them means the
1504 * defaults will be used, and with a large number of cids a bug may
1505 * occur, if the defaults will be smaller than dq_pf_max_cid /
1508 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_6_RT_OFFSET, dq_pf_max_cid);
1509 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_6_RT_OFFSET, dq_vf_max_cid);
1511 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_7_RT_OFFSET, dq_pf_max_cid);
1512 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_7_RT_OFFSET, dq_vf_max_cid);
1515 static void ecore_ilt_bounds_init(struct ecore_hwfn *p_hwfn)
1517 struct ecore_ilt_client_cfg *ilt_clients;
1520 ilt_clients = p_hwfn->p_cxt_mngr->clients;
1521 for_each_ilt_valid_client(i, ilt_clients) {
1522 STORE_RT_REG(p_hwfn,
1523 ilt_clients[i].first.reg,
1524 ilt_clients[i].first.val);
1525 STORE_RT_REG(p_hwfn,
1526 ilt_clients[i].last.reg, ilt_clients[i].last.val);
1527 STORE_RT_REG(p_hwfn,
1528 ilt_clients[i].p_size.reg,
1529 ilt_clients[i].p_size.val);
1533 static void ecore_ilt_vf_bounds_init(struct ecore_hwfn *p_hwfn)
1535 struct ecore_ilt_client_cfg *p_cli;
1538 /* For simplicty we set the 'block' to be an ILT page */
1539 if (p_hwfn->p_dev->p_iov_info) {
1540 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
1542 STORE_RT_REG(p_hwfn,
1543 PSWRQ2_REG_VF_BASE_RT_OFFSET,
1544 p_iov->first_vf_in_pf);
1545 STORE_RT_REG(p_hwfn,
1546 PSWRQ2_REG_VF_LAST_ILT_RT_OFFSET,
1547 p_iov->first_vf_in_pf + p_iov->total_vfs);
1550 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
1551 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1552 if (p_cli->active) {
1553 STORE_RT_REG(p_hwfn,
1554 PSWRQ2_REG_CDUC_BLOCKS_FACTOR_RT_OFFSET,
1556 STORE_RT_REG(p_hwfn,
1557 PSWRQ2_REG_CDUC_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1558 p_cli->pf_total_lines);
1559 STORE_RT_REG(p_hwfn,
1560 PSWRQ2_REG_CDUC_VF_BLOCKS_RT_OFFSET,
1561 p_cli->vf_total_lines);
1564 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1565 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1566 if (p_cli->active) {
1567 STORE_RT_REG(p_hwfn,
1568 PSWRQ2_REG_CDUT_BLOCKS_FACTOR_RT_OFFSET,
1570 STORE_RT_REG(p_hwfn,
1571 PSWRQ2_REG_CDUT_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1572 p_cli->pf_total_lines);
1573 STORE_RT_REG(p_hwfn,
1574 PSWRQ2_REG_CDUT_VF_BLOCKS_RT_OFFSET,
1575 p_cli->vf_total_lines);
1578 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TM];
1579 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1580 if (p_cli->active) {
1581 STORE_RT_REG(p_hwfn,
1582 PSWRQ2_REG_TM_BLOCKS_FACTOR_RT_OFFSET, blk_factor);
1583 STORE_RT_REG(p_hwfn,
1584 PSWRQ2_REG_TM_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1585 p_cli->pf_total_lines);
1586 STORE_RT_REG(p_hwfn,
1587 PSWRQ2_REG_TM_VF_BLOCKS_RT_OFFSET,
1588 p_cli->vf_total_lines);
1592 /* ILT (PSWRQ2) PF */
1593 static void ecore_ilt_init_pf(struct ecore_hwfn *p_hwfn)
1595 struct ecore_ilt_client_cfg *clients;
1596 struct ecore_cxt_mngr *p_mngr;
1597 struct ecore_dma_mem *p_shdw;
1598 u32 line, rt_offst, i;
1600 ecore_ilt_bounds_init(p_hwfn);
1601 ecore_ilt_vf_bounds_init(p_hwfn);
1603 p_mngr = p_hwfn->p_cxt_mngr;
1604 p_shdw = p_mngr->ilt_shadow;
1605 clients = p_hwfn->p_cxt_mngr->clients;
1607 for_each_ilt_valid_client(i, clients) {
1608 /* Client's 1st val and RT array are absolute, ILT shadows'
1609 * lines are relative.
1611 line = clients[i].first.val - p_mngr->pf_start_line;
1612 rt_offst = PSWRQ2_REG_ILT_MEMORY_RT_OFFSET +
1613 clients[i].first.val * ILT_ENTRY_IN_REGS;
1615 for (; line <= clients[i].last.val - p_mngr->pf_start_line;
1616 line++, rt_offst += ILT_ENTRY_IN_REGS) {
1617 u64 ilt_hw_entry = 0;
1619 /** p_virt could be OSAL_NULL incase of dynamic
1622 if (p_shdw[line].p_virt != OSAL_NULL) {
1623 SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
1624 SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR,
1625 (p_shdw[line].p_phys >> 12));
1627 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1628 "Setting RT[0x%08x] from"
1629 " ILT[0x%08x] [Client is %d] to"
1630 " Physical addr: 0x%lx\n",
1632 (unsigned long)(p_shdw[line].
1636 STORE_RT_REG_AGG(p_hwfn, rt_offst, ilt_hw_entry);
1641 /* SRC (Searcher) PF */
1642 static void ecore_src_init_pf(struct ecore_hwfn *p_hwfn)
1644 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1645 u32 rounded_conn_num, conn_num, conn_max;
1646 struct ecore_src_iids src_iids;
1648 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
1649 ecore_cxt_src_iids(p_mngr, &src_iids);
1650 conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
1654 conn_max = OSAL_MAX_T(u32, conn_num, SRC_MIN_NUM_ELEMS);
1655 rounded_conn_num = OSAL_ROUNDUP_POW_OF_TWO(conn_max);
1657 STORE_RT_REG(p_hwfn, SRC_REG_COUNTFREE_RT_OFFSET, conn_num);
1658 STORE_RT_REG(p_hwfn, SRC_REG_NUMBER_HASH_BITS_RT_OFFSET,
1659 OSAL_LOG2(rounded_conn_num));
1661 STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET,
1662 p_hwfn->p_cxt_mngr->first_free);
1663 STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET,
1664 p_hwfn->p_cxt_mngr->last_free);
1665 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1666 "Configured SEARCHER for 0x%08x connections\n",
1671 #define TM_CFG_NUM_IDS_SHIFT 0
1672 #define TM_CFG_NUM_IDS_MASK 0xFFFFULL
1673 #define TM_CFG_PRE_SCAN_OFFSET_SHIFT 16
1674 #define TM_CFG_PRE_SCAN_OFFSET_MASK 0x1FFULL
1675 #define TM_CFG_PARENT_PF_SHIFT 25
1676 #define TM_CFG_PARENT_PF_MASK 0x7ULL
1678 #define TM_CFG_CID_PRE_SCAN_ROWS_SHIFT 30
1679 #define TM_CFG_CID_PRE_SCAN_ROWS_MASK 0x1FFULL
1681 #define TM_CFG_TID_OFFSET_SHIFT 30
1682 #define TM_CFG_TID_OFFSET_MASK 0x7FFFFULL
1683 #define TM_CFG_TID_PRE_SCAN_ROWS_SHIFT 49
1684 #define TM_CFG_TID_PRE_SCAN_ROWS_MASK 0x1FFULL
1686 static void ecore_tm_init_pf(struct ecore_hwfn *p_hwfn)
1688 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1689 u32 active_seg_mask = 0, tm_offset, rt_reg;
1690 struct ecore_tm_iids tm_iids;
1694 OSAL_MEM_ZERO(&tm_iids, sizeof(tm_iids));
1695 ecore_cxt_tm_iids(p_mngr, &tm_iids);
1697 /* @@@TBD No pre-scan for now */
1699 /* Note: We assume consecutive VFs for a PF */
1700 for (i = 0; i < p_mngr->vf_count; i++) {
1702 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_cids);
1703 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1704 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
1705 SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
1707 rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
1708 (sizeof(cfg_word) / sizeof(u32)) *
1709 (p_hwfn->p_dev->p_iov_info->first_vf_in_pf + i);
1710 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1714 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_cids);
1715 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1716 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); /* n/a for PF */
1717 SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
1719 rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
1720 (sizeof(cfg_word) / sizeof(u32)) *
1721 (NUM_OF_VFS(p_hwfn->p_dev) + p_hwfn->rel_pf_id);
1722 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1725 STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_CONN_RT_OFFSET,
1726 tm_iids.pf_cids ? 0x1 : 0x0);
1728 /* @@@TBD how to enable the scan for the VFs */
1730 tm_offset = tm_iids.per_vf_cids;
1732 /* Note: We assume consecutive VFs for a PF */
1733 for (i = 0; i < p_mngr->vf_count; i++) {
1735 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_tids);
1736 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1737 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
1738 SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
1739 SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64)0);
1741 rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
1742 (sizeof(cfg_word) / sizeof(u32)) *
1743 (p_hwfn->p_dev->p_iov_info->first_vf_in_pf + i);
1745 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1748 tm_offset = tm_iids.pf_cids;
1749 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
1751 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_tids[i]);
1752 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1753 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0);
1754 SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
1755 SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64)0);
1757 rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
1758 (sizeof(cfg_word) / sizeof(u32)) *
1759 (NUM_OF_VFS(p_hwfn->p_dev) +
1760 p_hwfn->rel_pf_id * NUM_TASK_PF_SEGMENTS + i);
1762 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1763 active_seg_mask |= (tm_iids.pf_tids[i] ? (1 << i) : 0);
1765 tm_offset += tm_iids.pf_tids[i];
1768 STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_TASK_RT_OFFSET, active_seg_mask);
1770 /* @@@TBD how to enable the scan for the VFs */
1773 static void ecore_prs_init_pf(struct ecore_hwfn *p_hwfn)
1775 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1776 struct ecore_conn_type_cfg *p_fcoe;
1777 struct ecore_tid_seg *p_tid;
1779 p_fcoe = &p_mngr->conn_cfg[PROTOCOLID_FCOE];
1781 /* If FCoE is active set the MAX OX_ID (tid) in the Parser */
1782 if (!p_fcoe->cid_count)
1785 p_tid = &p_fcoe->tid_seg[ECORE_CXT_FCOE_TID_SEG];
1786 STORE_RT_REG_AGG(p_hwfn,
1787 PRS_REG_TASK_ID_MAX_INITIATOR_PF_RT_OFFSET,
1791 void ecore_cxt_hw_init_common(struct ecore_hwfn *p_hwfn)
1793 /* CDU configuration */
1794 ecore_cdu_init_common(p_hwfn);
1797 void ecore_cxt_hw_init_pf(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1799 ecore_qm_init_pf(p_hwfn, p_ptt);
1800 ecore_cm_init_pf(p_hwfn);
1801 ecore_dq_init_pf(p_hwfn);
1802 ecore_cdu_init_pf(p_hwfn);
1803 ecore_ilt_init_pf(p_hwfn);
1804 ecore_src_init_pf(p_hwfn);
1805 ecore_tm_init_pf(p_hwfn);
1806 ecore_prs_init_pf(p_hwfn);
1809 enum _ecore_status_t _ecore_cxt_acquire_cid(struct ecore_hwfn *p_hwfn,
1810 enum protocol_type type,
1811 u32 *p_cid, u8 vfid)
1813 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1814 struct ecore_cid_acquired_map *p_map;
1817 if (type >= MAX_CONN_TYPES) {
1818 DP_NOTICE(p_hwfn, true, "Invalid protocol type %d", type);
1822 if (vfid >= COMMON_MAX_NUM_VFS && vfid != ECORE_CXT_PF_CID) {
1823 DP_NOTICE(p_hwfn, true, "VF [%02x] is out of range\n", vfid);
1827 /* Determine the right map to take this CID from */
1828 if (vfid == ECORE_CXT_PF_CID)
1829 p_map = &p_mngr->acquired[type];
1831 p_map = &p_mngr->acquired_vf[type][vfid];
1833 if (p_map->cid_map == OSAL_NULL) {
1834 DP_NOTICE(p_hwfn, true, "Invalid protocol type %d", type);
1838 rel_cid = OSAL_FIND_FIRST_ZERO_BIT(p_map->cid_map,
1841 if (rel_cid >= p_map->max_count) {
1842 DP_NOTICE(p_hwfn, false, "no CID available for protocol %d\n",
1844 return ECORE_NORESOURCES;
1847 OSAL_SET_BIT(rel_cid, p_map->cid_map);
1849 *p_cid = rel_cid + p_map->start_cid;
1851 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
1852 "Acquired cid 0x%08x [rel. %08x] vfid %02x type %d\n",
1853 *p_cid, rel_cid, vfid, type);
1855 return ECORE_SUCCESS;
1858 enum _ecore_status_t ecore_cxt_acquire_cid(struct ecore_hwfn *p_hwfn,
1859 enum protocol_type type,
1862 return _ecore_cxt_acquire_cid(p_hwfn, type, p_cid, ECORE_CXT_PF_CID);
1865 static bool ecore_cxt_test_cid_acquired(struct ecore_hwfn *p_hwfn,
1867 enum protocol_type *p_type,
1868 struct ecore_cid_acquired_map **pp_map)
1870 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1873 /* Iterate over protocols and find matching cid range */
1874 for (*p_type = 0; *p_type < MAX_CONN_TYPES; (*p_type)++) {
1875 if (vfid == ECORE_CXT_PF_CID)
1876 *pp_map = &p_mngr->acquired[*p_type];
1878 *pp_map = &p_mngr->acquired_vf[*p_type][vfid];
1880 if (!((*pp_map)->cid_map))
1882 if (cid >= (*pp_map)->start_cid &&
1883 cid < (*pp_map)->start_cid + (*pp_map)->max_count) {
1887 if (*p_type == MAX_CONN_TYPES) {
1888 DP_NOTICE(p_hwfn, true, "Invalid CID %d vfid %02x", cid, vfid);
1892 rel_cid = cid - (*pp_map)->start_cid;
1893 if (!OSAL_TEST_BIT(rel_cid, (*pp_map)->cid_map)) {
1894 DP_NOTICE(p_hwfn, true,
1895 "CID %d [vifd %02x] not acquired", cid, vfid);
1901 *p_type = MAX_CONN_TYPES;
1902 *pp_map = OSAL_NULL;
1906 void _ecore_cxt_release_cid(struct ecore_hwfn *p_hwfn, u32 cid, u8 vfid)
1908 struct ecore_cid_acquired_map *p_map = OSAL_NULL;
1909 enum protocol_type type;
1913 if (vfid != ECORE_CXT_PF_CID && vfid > COMMON_MAX_NUM_VFS) {
1914 DP_NOTICE(p_hwfn, true,
1915 "Trying to return incorrect CID belonging to VF %02x\n",
1920 /* Test acquired and find matching per-protocol map */
1921 b_acquired = ecore_cxt_test_cid_acquired(p_hwfn, cid, vfid,
1927 rel_cid = cid - p_map->start_cid;
1928 OSAL_CLEAR_BIT(rel_cid, p_map->cid_map);
1930 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
1931 "Released CID 0x%08x [rel. %08x] vfid %02x type %d\n",
1932 cid, rel_cid, vfid, type);
1935 void ecore_cxt_release_cid(struct ecore_hwfn *p_hwfn, u32 cid)
1937 _ecore_cxt_release_cid(p_hwfn, cid, ECORE_CXT_PF_CID);
1940 enum _ecore_status_t ecore_cxt_get_cid_info(struct ecore_hwfn *p_hwfn,
1941 struct ecore_cxt_info *p_info)
1943 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1944 struct ecore_cid_acquired_map *p_map = OSAL_NULL;
1945 u32 conn_cxt_size, hw_p_size, cxts_per_p, line;
1946 enum protocol_type type;
1949 /* Test acquired and find matching per-protocol map */
1950 b_acquired = ecore_cxt_test_cid_acquired(p_hwfn, p_info->iid,
1957 /* set the protocl type */
1958 p_info->type = type;
1960 /* compute context virtual pointer */
1961 hw_p_size = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
1963 conn_cxt_size = CONN_CXT_SIZE(p_hwfn);
1964 cxts_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / conn_cxt_size;
1965 line = p_info->iid / cxts_per_p;
1967 /* Make sure context is allocated (dynamic allocation) */
1968 if (!p_mngr->ilt_shadow[line].p_virt)
1971 p_info->p_cxt = (u8 *)p_mngr->ilt_shadow[line].p_virt +
1972 p_info->iid % cxts_per_p * conn_cxt_size;
1974 DP_VERBOSE(p_hwfn, (ECORE_MSG_ILT | ECORE_MSG_CXT),
1975 "Accessing ILT shadow[%d]: CXT pointer is at %p (for iid %d)\n",
1976 (p_info->iid / cxts_per_p), p_info->p_cxt, p_info->iid);
1978 return ECORE_SUCCESS;
1981 enum _ecore_status_t ecore_cxt_set_pf_params(struct ecore_hwfn *p_hwfn)
1983 /* Set the number of required CORE connections */
1984 u32 core_cids = 1; /* SPQ */
1986 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_CORE, core_cids, 0);
1988 switch (p_hwfn->hw_info.personality) {
1993 struct ecore_eth_pf_params *p_params =
1994 &p_hwfn->pf_params.eth_pf_params;
1996 if (!p_params->num_vf_cons)
1997 p_params->num_vf_cons = ETH_PF_PARAMS_VF_CONS_DEFAULT;
1998 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
2000 p_params->num_vf_cons);
2002 count = p_params->num_arfs_filters;
2004 if (!OSAL_TEST_BIT(ECORE_MF_DISABLE_ARFS,
2005 &p_hwfn->p_dev->mf_bits))
2006 p_hwfn->p_cxt_mngr->arfs_count = count;
2014 return ECORE_SUCCESS;
2017 /* This function is very RoCE oriented, if another protocol in the future
2018 * will want this feature we'll need to modify the function to be more generic
2020 enum _ecore_status_t
2021 ecore_cxt_dynamic_ilt_alloc(struct ecore_hwfn *p_hwfn,
2022 enum ecore_cxt_elem_type elem_type,
2025 u32 reg_offset, shadow_line, elem_size, hw_p_size, elems_per_p, line;
2026 struct ecore_ilt_client_cfg *p_cli;
2027 struct ecore_ilt_cli_blk *p_blk;
2028 struct ecore_ptt *p_ptt;
2032 enum _ecore_status_t rc = ECORE_SUCCESS;
2034 switch (elem_type) {
2035 case ECORE_ELEM_CXT:
2036 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
2037 elem_size = CONN_CXT_SIZE(p_hwfn);
2038 p_blk = &p_cli->pf_blks[CDUC_BLK];
2040 case ECORE_ELEM_SRQ:
2041 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
2042 elem_size = SRQ_CXT_SIZE;
2043 p_blk = &p_cli->pf_blks[SRQ_BLK];
2045 case ECORE_ELEM_TASK:
2046 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
2047 elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
2048 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(ECORE_CXT_ROCE_TID_SEG)];
2051 DP_NOTICE(p_hwfn, false,
2052 "ECORE_INVALID elem type = %d", elem_type);
2056 /* Calculate line in ilt */
2057 hw_p_size = p_cli->p_size.val;
2058 elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
2059 line = p_blk->start_line + (iid / elems_per_p);
2060 shadow_line = line - p_hwfn->p_cxt_mngr->pf_start_line;
2062 /* If line is already allocated, do nothing, otherwise allocate it and
2063 * write it to the PSWRQ2 registers.
2064 * This section can be run in parallel from different contexts and thus
2065 * a mutex protection is needed.
2068 OSAL_MUTEX_ACQUIRE(&p_hwfn->p_cxt_mngr->mutex);
2070 if (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt)
2073 p_ptt = ecore_ptt_acquire(p_hwfn);
2075 DP_NOTICE(p_hwfn, false,
2076 "ECORE_TIME_OUT on ptt acquire - dynamic allocation");
2081 p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
2083 p_blk->real_size_in_page);
2088 OSAL_MEM_ZERO(p_virt, p_blk->real_size_in_page);
2090 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt = p_virt;
2091 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys = p_phys;
2092 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].size =
2093 p_blk->real_size_in_page;
2095 /* compute absolute offset */
2096 reg_offset = PSWRQ2_REG_ILT_MEMORY +
2097 (line * ILT_REG_SIZE_IN_BYTES * ILT_ENTRY_IN_REGS);
2100 SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
2101 SET_FIELD(ilt_hw_entry,
2103 (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys >> 12));
2105 /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a wide-bus */
2107 ecore_dmae_host2grc(p_hwfn, p_ptt, (u64)(osal_uintptr_t)&ilt_hw_entry,
2108 reg_offset, sizeof(ilt_hw_entry) / sizeof(u32),
2111 if (elem_type == ECORE_ELEM_CXT) {
2112 u32 last_cid_allocated = (1 + (iid / elems_per_p)) *
2115 /* Update the relevant register in the parser */
2116 ecore_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF,
2117 last_cid_allocated - 1);
2119 if (!p_hwfn->b_rdma_enabled_in_prs) {
2120 /* Enable RoCE search */
2121 ecore_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
2122 p_hwfn->b_rdma_enabled_in_prs = true;
2127 ecore_ptt_release(p_hwfn, p_ptt);
2129 OSAL_MUTEX_RELEASE(&p_hwfn->p_cxt_mngr->mutex);
2134 /* This function is very RoCE oriented, if another protocol in the future
2135 * will want this feature we'll need to modify the function to be more generic
2137 static enum _ecore_status_t
2138 ecore_cxt_free_ilt_range(struct ecore_hwfn *p_hwfn,
2139 enum ecore_cxt_elem_type elem_type,
2140 u32 start_iid, u32 count)
2142 u32 start_line, end_line, shadow_start_line, shadow_end_line;
2143 u32 reg_offset, elem_size, hw_p_size, elems_per_p;
2144 struct ecore_ilt_client_cfg *p_cli;
2145 struct ecore_ilt_cli_blk *p_blk;
2146 u32 end_iid = start_iid + count;
2147 struct ecore_ptt *p_ptt;
2148 u64 ilt_hw_entry = 0;
2151 switch (elem_type) {
2152 case ECORE_ELEM_CXT:
2153 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
2154 elem_size = CONN_CXT_SIZE(p_hwfn);
2155 p_blk = &p_cli->pf_blks[CDUC_BLK];
2157 case ECORE_ELEM_SRQ:
2158 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
2159 elem_size = SRQ_CXT_SIZE;
2160 p_blk = &p_cli->pf_blks[SRQ_BLK];
2162 case ECORE_ELEM_TASK:
2163 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
2164 elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
2165 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(ECORE_CXT_ROCE_TID_SEG)];
2168 DP_NOTICE(p_hwfn, false,
2169 "ECORE_INVALID elem type = %d", elem_type);
2173 /* Calculate line in ilt */
2174 hw_p_size = p_cli->p_size.val;
2175 elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
2176 start_line = p_blk->start_line + (start_iid / elems_per_p);
2177 end_line = p_blk->start_line + (end_iid / elems_per_p);
2178 if (((end_iid + 1) / elems_per_p) != (end_iid / elems_per_p))
2181 shadow_start_line = start_line - p_hwfn->p_cxt_mngr->pf_start_line;
2182 shadow_end_line = end_line - p_hwfn->p_cxt_mngr->pf_start_line;
2184 p_ptt = ecore_ptt_acquire(p_hwfn);
2186 DP_NOTICE(p_hwfn, false,
2187 "ECORE_TIME_OUT on ptt acquire - dynamic allocation");
2188 return ECORE_TIMEOUT;
2191 for (i = shadow_start_line; i < shadow_end_line; i++) {
2192 if (!p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt)
2195 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
2196 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt,
2197 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys,
2198 p_hwfn->p_cxt_mngr->ilt_shadow[i].size);
2200 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt = OSAL_NULL;
2201 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys = 0;
2202 p_hwfn->p_cxt_mngr->ilt_shadow[i].size = 0;
2204 /* compute absolute offset */
2205 reg_offset = PSWRQ2_REG_ILT_MEMORY +
2206 ((start_line++) * ILT_REG_SIZE_IN_BYTES *
2209 /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a
2212 ecore_dmae_host2grc(p_hwfn, p_ptt,
2213 (u64)(osal_uintptr_t)&ilt_hw_entry,
2215 sizeof(ilt_hw_entry) / sizeof(u32),
2219 ecore_ptt_release(p_hwfn, p_ptt);
2221 return ECORE_SUCCESS;
2224 enum _ecore_status_t ecore_cxt_free_proto_ilt(struct ecore_hwfn *p_hwfn,
2225 enum protocol_type proto)
2227 enum _ecore_status_t rc;
2230 /* Free Connection CXT */
2231 rc = ecore_cxt_free_ilt_range(p_hwfn, ECORE_ELEM_CXT,
2232 ecore_cxt_get_proto_cid_start(p_hwfn,
2234 ecore_cxt_get_proto_cid_count(p_hwfn,
2242 rc = ecore_cxt_free_ilt_range(p_hwfn, ECORE_ELEM_TASK, 0,
2243 ecore_cxt_get_proto_tid_count(p_hwfn,
2249 rc = ecore_cxt_free_ilt_range(p_hwfn, ECORE_ELEM_SRQ, 0,
2250 ecore_cxt_get_srq_count(p_hwfn));