2 * Copyright (c) 2017-2018 Cavium, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
36 #include "common_hsi.h"
37 #include "ecore_hsi_common.h"
38 #include "ecore_hsi_eth.h"
39 #include "tcp_common.h"
40 #include "ecore_hsi_iscsi.h"
41 #include "ecore_hsi_fcoe.h"
42 #include "ecore_hsi_roce.h"
43 #include "ecore_hsi_iwarp.h"
44 #include "ecore_rt_defs.h"
45 #include "ecore_status.h"
47 #include "ecore_init_ops.h"
48 #include "ecore_init_fw_funcs.h"
49 #include "ecore_cxt.h"
51 #include "ecore_dev_api.h"
52 #include "ecore_sriov.h"
53 #include "ecore_roce.h"
54 #include "ecore_mcp.h"
56 /* Max number of connection types in HW (DQ/CDU etc.) */
57 #define MAX_CONN_TYPES PROTOCOLID_COMMON
58 #define NUM_TASK_TYPES 2
59 #define NUM_TASK_PF_SEGMENTS 4
60 #define NUM_TASK_VF_SEGMENTS 1
62 /* Doorbell-Queue constants */
63 #define DQ_RANGE_SHIFT 4
64 #define DQ_RANGE_ALIGN (1 << DQ_RANGE_SHIFT)
66 /* Searcher constants */
67 #define SRC_MIN_NUM_ELEMS 256
69 /* Timers constants */
71 #define TM_ALIGN (1 << TM_SHIFT)
72 #define TM_ELEM_SIZE 4
75 #define ILT_DEFAULT_HW_P_SIZE 4
77 #define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12))
78 #define ILT_CFG_REG(cli, reg) PSWRQ2_REG_##cli##_##reg##_RT_OFFSET
80 /* ILT entry structure */
81 #define ILT_ENTRY_PHY_ADDR_MASK 0x000FFFFFFFFFFFULL
82 #define ILT_ENTRY_PHY_ADDR_SHIFT 0
83 #define ILT_ENTRY_VALID_MASK 0x1ULL
84 #define ILT_ENTRY_VALID_SHIFT 52
85 #define ILT_ENTRY_IN_REGS 2
86 #define ILT_REG_SIZE_IN_BYTES 4
88 /* connection context union */
90 struct e4_core_conn_context core_ctx;
91 struct e4_eth_conn_context eth_ctx;
92 struct e4_iscsi_conn_context iscsi_ctx;
93 struct e4_fcoe_conn_context fcoe_ctx;
94 struct e4_roce_conn_context roce_ctx;
97 /* TYPE-0 task context - iSCSI, FCOE */
98 union type0_task_context {
99 struct e4_iscsi_task_context iscsi_ctx;
100 struct e4_fcoe_task_context fcoe_ctx;
103 /* TYPE-1 task context - ROCE */
104 union type1_task_context {
105 struct e4_rdma_task_context roce_ctx;
113 #define CDUT_SEG_ALIGNMET 3 /* in 4k chunks */
114 #define CDUT_SEG_ALIGNMET_IN_BYTES (1 << (CDUT_SEG_ALIGNMET + 12))
116 #define CONN_CXT_SIZE(p_hwfn) \
117 ALIGNED_TYPE_SIZE(union conn_context, p_hwfn)
119 #define SRQ_CXT_SIZE (sizeof(struct rdma_srq_context))
121 #define TYPE0_TASK_CXT_SIZE(p_hwfn) \
122 ALIGNED_TYPE_SIZE(union type0_task_context, p_hwfn)
124 /* Alignment is inherent to the type1_task_context structure */
125 #define TYPE1_TASK_CXT_SIZE(p_hwfn) sizeof(union type1_task_context)
127 /* PF per protocl configuration object */
128 #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
129 #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
131 struct ecore_tid_seg {
137 struct ecore_conn_type_cfg {
140 struct ecore_tid_seg tid_seg[TASK_SEGMENTS];
143 /* ILT Client configuration,
144 * Per connection type (protocol) resources (cids, tis, vf cids etc.)
145 * 1 - for connection context (CDUC) and for each task context we need two
146 * values, for regular task context and for force load memory
148 #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2)
149 #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2)
152 #define CDUT_SEG_BLK(n) (1 + (u8)(n))
153 #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_##X##_SEGMENTS)
165 struct ilt_cfg_pair {
170 struct ecore_ilt_cli_blk {
171 u32 total_size; /* 0 means not active */
172 u32 real_size_in_page;
174 u32 dynamic_line_cnt;
177 struct ecore_ilt_client_cfg {
181 struct ilt_cfg_pair first;
182 struct ilt_cfg_pair last;
183 struct ilt_cfg_pair p_size;
185 /* ILT client blocks for PF */
186 struct ecore_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS];
189 /* ILT client blocks for VFs */
190 struct ecore_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS];
196 * Protocol acquired CID lists
197 * PF start line in ILT
199 struct ecore_dma_mem {
205 #define MAP_WORD_SIZE sizeof(unsigned long)
206 #define BITS_PER_MAP_WORD (MAP_WORD_SIZE * 8)
208 struct ecore_cid_acquired_map {
211 unsigned long *cid_map;
214 struct ecore_cxt_mngr {
215 /* Per protocl configuration */
216 struct ecore_conn_type_cfg conn_cfg[MAX_CONN_TYPES];
218 /* computed ILT structure */
219 struct ecore_ilt_client_cfg clients[ILT_CLI_MAX];
221 /* Task type sizes */
222 u32 task_type_size[NUM_TASK_TYPES];
224 /* total number of VFs for this hwfn -
225 * ALL VFs are symmetric in terms of HW resources
230 struct ecore_cid_acquired_map acquired[MAX_CONN_TYPES];
231 /* TBD - do we want this allocated to reserve space? */
232 struct ecore_cid_acquired_map acquired_vf[MAX_CONN_TYPES][COMMON_MAX_NUM_VFS];
234 /* ILT shadow table */
235 struct ecore_dma_mem *ilt_shadow;
238 /* Mutex for a dynamic ILT allocation */
242 struct ecore_dma_mem *t2;
247 /* The infrastructure originally was very generic and context/task
248 * oriented - per connection-type we would set how many of those
249 * are needed, and later when determining how much memory we're
250 * needing for a given block we'd iterate over all the relevant
252 * But since then we've had some additional resources, some of which
253 * require memory which is indepent of the general context/task
254 * scheme. We add those here explicitly per-feature.
257 /* total number of SRQ's for this hwfn */
260 /* Maximal number of L2 steering filters */
263 /* TODO - VF arfs filters ? */
266 /* check if resources/configuration is required according to protocol type */
267 static bool src_proto(enum protocol_type type)
269 return type == PROTOCOLID_ISCSI ||
270 type == PROTOCOLID_FCOE ||
271 type == PROTOCOLID_IWARP;
274 static bool tm_cid_proto(enum protocol_type type)
276 return type == PROTOCOLID_ISCSI ||
277 type == PROTOCOLID_FCOE ||
278 type == PROTOCOLID_ROCE ||
279 type == PROTOCOLID_IWARP;
282 static bool tm_tid_proto(enum protocol_type type)
284 return type == PROTOCOLID_FCOE;
287 /* counts the iids for the CDU/CDUC ILT client configuration */
288 struct ecore_cdu_iids {
293 static void ecore_cxt_cdu_iids(struct ecore_cxt_mngr *p_mngr,
294 struct ecore_cdu_iids *iids)
298 for (type = 0; type < MAX_CONN_TYPES; type++) {
299 iids->pf_cids += p_mngr->conn_cfg[type].cid_count;
300 iids->per_vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
304 /* counts the iids for the Searcher block configuration */
305 struct ecore_src_iids {
310 static void ecore_cxt_src_iids(struct ecore_cxt_mngr *p_mngr,
311 struct ecore_src_iids *iids)
315 for (i = 0; i < MAX_CONN_TYPES; i++) {
319 iids->pf_cids += p_mngr->conn_cfg[i].cid_count;
320 iids->per_vf_cids += p_mngr->conn_cfg[i].cids_per_vf;
323 /* Add L2 filtering filters in addition */
324 iids->pf_cids += p_mngr->arfs_count;
327 /* counts the iids for the Timers block configuration */
328 struct ecore_tm_iids {
330 u32 pf_tids[NUM_TASK_PF_SEGMENTS]; /* per segment */
336 static void ecore_cxt_tm_iids(struct ecore_cxt_mngr *p_mngr,
337 struct ecore_tm_iids *iids)
339 bool tm_vf_required = false;
340 bool tm_required = false;
343 /* Timers is a special case -> we don't count how many cids require
344 * timers but what's the max cid that will be used by the timer block.
345 * therefore we traverse in reverse order, and once we hit a protocol
346 * that requires the timers memory, we'll sum all the protocols up
349 for (i = MAX_CONN_TYPES - 1; i >= 0; i--) {
350 struct ecore_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[i];
352 if (tm_cid_proto(i) || tm_required) {
353 if (p_cfg->cid_count)
356 iids->pf_cids += p_cfg->cid_count;
359 if (tm_cid_proto(i) || tm_vf_required) {
360 if (p_cfg->cids_per_vf)
361 tm_vf_required = true;
363 iids->per_vf_cids += p_cfg->cids_per_vf;
366 if (tm_tid_proto(i)) {
367 struct ecore_tid_seg *segs = p_cfg->tid_seg;
369 /* for each segment there is at most one
370 * protocol for which count is not 0.
372 for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
373 iids->pf_tids[j] += segs[j].count;
375 /* The last array elelment is for the VFs. As for PF
376 * segments there can be only one protocol for
377 * which this value is not 0.
379 iids->per_vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
383 iids->pf_cids = ROUNDUP(iids->pf_cids, TM_ALIGN);
384 iids->per_vf_cids = ROUNDUP(iids->per_vf_cids, TM_ALIGN);
385 iids->per_vf_tids = ROUNDUP(iids->per_vf_tids, TM_ALIGN);
387 for (iids->pf_tids_total = 0, j = 0; j < NUM_TASK_PF_SEGMENTS; j++) {
388 iids->pf_tids[j] = ROUNDUP(iids->pf_tids[j], TM_ALIGN);
389 iids->pf_tids_total += iids->pf_tids[j];
393 static void ecore_cxt_qm_iids(struct ecore_hwfn *p_hwfn,
394 struct ecore_qm_iids *iids)
396 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
397 struct ecore_tid_seg *segs;
398 u32 vf_cids = 0, type, j;
401 for (type = 0; type < MAX_CONN_TYPES; type++) {
402 iids->cids += p_mngr->conn_cfg[type].cid_count;
403 vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
405 segs = p_mngr->conn_cfg[type].tid_seg;
406 /* for each segment there is at most one
407 * protocol for which count is not 0.
409 for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
410 iids->tids += segs[j].count;
412 /* The last array elelment is for the VFs. As for PF
413 * segments there can be only one protocol for
414 * which this value is not 0.
416 vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
419 iids->vf_cids += vf_cids * p_mngr->vf_count;
420 iids->tids += vf_tids * p_mngr->vf_count;
422 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
423 "iids: CIDS %08x vf_cids %08x tids %08x vf_tids %08x\n",
424 iids->cids, iids->vf_cids, iids->tids, vf_tids);
427 static struct ecore_tid_seg *ecore_cxt_tid_seg_info(struct ecore_hwfn *p_hwfn,
430 struct ecore_cxt_mngr *p_cfg = p_hwfn->p_cxt_mngr;
433 /* Find the protocol with tid count > 0 for this segment.
434 Note: there can only be one and this is already validated.
436 for (i = 0; i < MAX_CONN_TYPES; i++) {
437 if (p_cfg->conn_cfg[i].tid_seg[seg].count)
438 return &p_cfg->conn_cfg[i].tid_seg[seg];
443 static void ecore_cxt_set_srq_count(struct ecore_hwfn *p_hwfn, u32 num_srqs)
445 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
447 p_mgr->srq_count = num_srqs;
450 u32 ecore_cxt_get_srq_count(struct ecore_hwfn *p_hwfn)
452 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
454 return p_mgr->srq_count;
457 /* set the iids (cid/tid) count per protocol */
458 static void ecore_cxt_set_proto_cid_count(struct ecore_hwfn *p_hwfn,
459 enum protocol_type type,
460 u32 cid_count, u32 vf_cid_cnt)
462 struct ecore_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
463 struct ecore_conn_type_cfg *p_conn = &p_mgr->conn_cfg[type];
465 p_conn->cid_count = ROUNDUP(cid_count, DQ_RANGE_ALIGN);
466 p_conn->cids_per_vf = ROUNDUP(vf_cid_cnt, DQ_RANGE_ALIGN);
468 if (type == PROTOCOLID_ROCE) {
469 u32 page_sz = p_mgr->clients[ILT_CLI_CDUC].p_size.val;
470 u32 cxt_size = CONN_CXT_SIZE(p_hwfn);
471 u32 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
472 u32 align = elems_per_page * DQ_RANGE_ALIGN;
474 p_conn->cid_count = ROUNDUP(p_conn->cid_count, align);
478 u32 ecore_cxt_get_proto_cid_count(struct ecore_hwfn *p_hwfn,
479 enum protocol_type type,
483 *vf_cid = p_hwfn->p_cxt_mngr->conn_cfg[type].cids_per_vf;
485 return p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count;
488 u32 ecore_cxt_get_proto_cid_start(struct ecore_hwfn *p_hwfn,
489 enum protocol_type type)
491 return p_hwfn->p_cxt_mngr->acquired[type].start_cid;
494 u32 ecore_cxt_get_proto_tid_count(struct ecore_hwfn *p_hwfn,
495 enum protocol_type type)
500 for (i = 0; i < TASK_SEGMENTS; i++)
501 cnt += p_hwfn->p_cxt_mngr->conn_cfg[type].tid_seg[i].count;
506 static void ecore_cxt_set_proto_tid_count(struct ecore_hwfn *p_hwfn,
507 enum protocol_type proto,
513 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
514 struct ecore_tid_seg *p_seg = &p_mngr->conn_cfg[proto].tid_seg[seg];
516 p_seg->count = count;
517 p_seg->has_fl_mem = has_fl;
518 p_seg->type = seg_type;
521 /* the *p_line parameter must be either 0 for the first invocation or the
522 value returned in the previous invocation.
524 static void ecore_ilt_cli_blk_fill(struct ecore_ilt_client_cfg *p_cli,
525 struct ecore_ilt_cli_blk *p_blk,
530 u32 ilt_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val);
532 /* verify that it's called once for each block */
533 if (p_blk->total_size)
536 p_blk->total_size = total_size;
537 p_blk->real_size_in_page = 0;
539 p_blk->real_size_in_page = (ilt_size / elem_size) * elem_size;
540 p_blk->start_line = start_line;
543 static void ecore_ilt_cli_adv_line(struct ecore_hwfn *p_hwfn,
544 struct ecore_ilt_client_cfg *p_cli,
545 struct ecore_ilt_cli_blk *p_blk,
547 enum ilt_clients client_id)
549 if (!p_blk->total_size)
553 p_cli->first.val = *p_line;
555 p_cli->active = true;
556 *p_line += DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page);
557 p_cli->last.val = *p_line-1;
559 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
560 "ILT[Client %d] - Lines: [%08x - %08x]. Block - Size %08x [Real %08x] Start line %d\n",
561 client_id, p_cli->first.val, p_cli->last.val,
562 p_blk->total_size, p_blk->real_size_in_page,
566 static u32 ecore_ilt_get_dynamic_line_cnt(struct ecore_hwfn *p_hwfn,
567 enum ilt_clients ilt_client)
569 u32 cid_count = p_hwfn->p_cxt_mngr->conn_cfg[PROTOCOLID_ROCE].cid_count;
570 struct ecore_ilt_client_cfg *p_cli;
571 u32 lines_to_skip = 0;
574 /* TBD MK: ILT code should be simplified once PROTO enum is changed */
576 if (ilt_client == ILT_CLI_CDUC) {
577 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
579 cxts_per_p = ILT_PAGE_IN_BYTES(p_cli->p_size.val) /
580 (u32)CONN_CXT_SIZE(p_hwfn);
582 lines_to_skip = cid_count / cxts_per_p;
585 return lines_to_skip;
588 static struct ecore_ilt_client_cfg *
589 ecore_cxt_set_cli(struct ecore_ilt_client_cfg *p_cli)
591 p_cli->active = false;
592 p_cli->first.val = 0;
597 static struct ecore_ilt_cli_blk *
598 ecore_cxt_set_blk(struct ecore_ilt_cli_blk *p_blk)
600 p_blk->total_size = 0;
604 enum _ecore_status_t ecore_cxt_cfg_ilt_compute(struct ecore_hwfn *p_hwfn,
607 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
608 u32 curr_line, total, i, task_size, line;
609 struct ecore_ilt_client_cfg *p_cli;
610 struct ecore_ilt_cli_blk *p_blk;
611 struct ecore_cdu_iids cdu_iids;
612 struct ecore_src_iids src_iids;
613 struct ecore_qm_iids qm_iids;
614 struct ecore_tm_iids tm_iids;
615 struct ecore_tid_seg *p_seg;
617 OSAL_MEM_ZERO(&qm_iids, sizeof(qm_iids));
618 OSAL_MEM_ZERO(&cdu_iids, sizeof(cdu_iids));
619 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
620 OSAL_MEM_ZERO(&tm_iids, sizeof(tm_iids));
622 p_mngr->pf_start_line = RESC_START(p_hwfn, ECORE_ILT);
624 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
625 "hwfn [%d] - Set context manager starting line to be 0x%08x\n",
626 p_hwfn->my_id, p_hwfn->p_cxt_mngr->pf_start_line);
629 p_cli = ecore_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUC]);
631 curr_line = p_mngr->pf_start_line;
634 p_cli->pf_total_lines = 0;
636 /* get the counters for the CDUC,CDUC and QM clients */
637 ecore_cxt_cdu_iids(p_mngr, &cdu_iids);
639 p_blk = ecore_cxt_set_blk(&p_cli->pf_blks[CDUC_BLK]);
641 total = cdu_iids.pf_cids * CONN_CXT_SIZE(p_hwfn);
643 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
644 total, CONN_CXT_SIZE(p_hwfn));
646 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
647 p_cli->pf_total_lines = curr_line - p_blk->start_line;
649 p_blk->dynamic_line_cnt = ecore_ilt_get_dynamic_line_cnt(p_hwfn,
653 p_blk = ecore_cxt_set_blk(&p_cli->vf_blks[CDUC_BLK]);
654 total = cdu_iids.per_vf_cids * CONN_CXT_SIZE(p_hwfn);
656 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
657 total, CONN_CXT_SIZE(p_hwfn));
659 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
660 p_cli->vf_total_lines = curr_line - p_blk->start_line;
662 for (i = 1; i < p_mngr->vf_count; i++)
663 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
667 p_cli = ecore_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUT]);
668 p_cli->first.val = curr_line;
670 /* first the 'working' task memory */
671 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
672 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
673 if (!p_seg || p_seg->count == 0)
676 p_blk = ecore_cxt_set_blk(&p_cli->pf_blks[CDUT_SEG_BLK(i)]);
677 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
678 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total,
679 p_mngr->task_type_size[p_seg->type]);
681 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
685 /* next the 'init' task memory (forced load memory) */
686 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
687 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
688 if (!p_seg || p_seg->count == 0)
691 p_blk = ecore_cxt_set_blk(
692 &p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)]);
694 if (!p_seg->has_fl_mem) {
695 /* The segment is active (total size pf 'working'
696 * memory is > 0) but has no FL (forced-load, Init)
699 * 1. The total-size in the corrsponding FL block of
700 * the ILT client is set to 0 - No ILT line are
701 * provisioned and no ILT memory allocated.
703 * 2. The start-line of said block is set to the
704 * start line of the matching working memory
705 * block in the ILT client. This is later used to
706 * configure the CDU segment offset registers and
707 * results in an FL command for TIDs of this
708 * segement behaves as regular load commands
709 * (loading TIDs from the working memory).
711 line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line;
713 ecore_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
716 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
718 ecore_ilt_cli_blk_fill(p_cli, p_blk,
720 p_mngr->task_type_size[p_seg->type]);
722 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
725 p_cli->pf_total_lines = curr_line - p_cli->pf_blks[0].start_line;
728 p_seg = ecore_cxt_tid_seg_info(p_hwfn, TASK_SEGMENT_VF);
729 if (p_seg && p_seg->count) {
730 /* Stricly speaking we need to iterate over all VF
731 * task segment types, but a VF has only 1 segment
734 /* 'working' memory */
735 total = p_seg->count * p_mngr->task_type_size[p_seg->type];
737 p_blk = ecore_cxt_set_blk(&p_cli->vf_blks[CDUT_SEG_BLK(0)]);
738 ecore_ilt_cli_blk_fill(p_cli, p_blk,
740 p_mngr->task_type_size[p_seg->type]);
742 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
746 p_blk = ecore_cxt_set_blk(
747 &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)]);
748 if (!p_seg->has_fl_mem) {
749 /* see comment above */
750 line = p_cli->vf_blks[CDUT_SEG_BLK(0)].start_line;
751 ecore_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
753 task_size = p_mngr->task_type_size[p_seg->type];
754 ecore_ilt_cli_blk_fill(p_cli, p_blk,
757 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
760 p_cli->vf_total_lines = curr_line -
761 p_cli->vf_blks[0].start_line;
763 /* Now for the rest of the VFs */
764 for (i = 1; i < p_mngr->vf_count; i++) {
765 /* don't set p_blk i.e. don't clear total_size */
766 p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)];
767 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
770 /* don't set p_blk i.e. don't clear total_size */
771 p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)];
772 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
778 p_cli = ecore_cxt_set_cli(&p_mngr->clients[ILT_CLI_QM]);
779 p_blk = ecore_cxt_set_blk(&p_cli->pf_blks[0]);
781 ecore_cxt_qm_iids(p_hwfn, &qm_iids);
782 total = ecore_qm_pf_mem_size(qm_iids.cids,
783 qm_iids.vf_cids, qm_iids.tids,
784 p_hwfn->qm_info.num_pqs,
785 p_hwfn->qm_info.num_vf_pqs);
787 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
788 "QM ILT Info, (cids=%d, vf_cids=%d, tids=%d, num_pqs=%d, num_vf_pqs=%d, memory_size=%d)\n",
789 qm_iids.cids, qm_iids.vf_cids, qm_iids.tids,
790 p_hwfn->qm_info.num_pqs, p_hwfn->qm_info.num_vf_pqs, total);
792 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total * 0x1000,
795 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_QM);
796 p_cli->pf_total_lines = curr_line - p_blk->start_line;
799 p_cli = ecore_cxt_set_cli(&p_mngr->clients[ILT_CLI_SRC]);
800 ecore_cxt_src_iids(p_mngr, &src_iids);
802 /* Both the PF and VFs searcher connections are stored in the per PF
803 * database. Thus sum the PF searcher cids and all the VFs searcher
806 total = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
808 u32 local_max = OSAL_MAX_T(u32, total,
811 total = OSAL_ROUNDUP_POW_OF_TWO(local_max);
813 p_blk = ecore_cxt_set_blk(&p_cli->pf_blks[0]);
814 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
815 total * sizeof(struct src_ent),
816 sizeof(struct src_ent));
818 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
820 p_cli->pf_total_lines = curr_line - p_blk->start_line;
824 p_cli = ecore_cxt_set_cli(&p_mngr->clients[ILT_CLI_TM]);
825 ecore_cxt_tm_iids(p_mngr, &tm_iids);
826 total = tm_iids.pf_cids + tm_iids.pf_tids_total;
828 p_blk = ecore_cxt_set_blk(&p_cli->pf_blks[0]);
829 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
830 total * TM_ELEM_SIZE,
833 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
835 p_cli->pf_total_lines = curr_line - p_blk->start_line;
839 total = tm_iids.per_vf_cids + tm_iids.per_vf_tids;
841 p_blk = ecore_cxt_set_blk(&p_cli->vf_blks[0]);
842 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
843 total * TM_ELEM_SIZE,
846 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
849 p_cli->vf_total_lines = curr_line - p_blk->start_line;
850 for (i = 1; i < p_mngr->vf_count; i++) {
851 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
856 /* TSDM (SRQ CONTEXT) */
857 total = ecore_cxt_get_srq_count(p_hwfn);
860 p_cli = ecore_cxt_set_cli(&p_mngr->clients[ILT_CLI_TSDM]);
861 p_blk = ecore_cxt_set_blk(&p_cli->pf_blks[SRQ_BLK]);
862 ecore_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
863 total * SRQ_CXT_SIZE, SRQ_CXT_SIZE);
865 ecore_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
867 p_cli->pf_total_lines = curr_line - p_blk->start_line;
870 *line_count = curr_line - p_hwfn->p_cxt_mngr->pf_start_line;
872 if (curr_line - p_hwfn->p_cxt_mngr->pf_start_line >
873 RESC_NUM(p_hwfn, ECORE_ILT)) {
877 return ECORE_SUCCESS;
880 u32 ecore_cxt_cfg_ilt_compute_excess(struct ecore_hwfn *p_hwfn, u32 used_lines)
882 struct ecore_ilt_client_cfg *p_cli;
883 u32 excess_lines, available_lines;
884 struct ecore_cxt_mngr *p_mngr;
885 u32 ilt_page_size, elem_size;
886 struct ecore_tid_seg *p_seg;
889 available_lines = RESC_NUM(p_hwfn, ECORE_ILT);
890 excess_lines = used_lines - available_lines;
895 if (!ECORE_IS_RDMA_PERSONALITY(p_hwfn))
898 p_mngr = p_hwfn->p_cxt_mngr;
899 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
900 ilt_page_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val);
902 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
903 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
904 if (!p_seg || p_seg->count == 0)
907 elem_size = p_mngr->task_type_size[p_seg->type];
911 return (ilt_page_size / elem_size) * excess_lines;
914 DP_ERR(p_hwfn, "failed computing excess ILT lines\n");
918 static void ecore_cxt_src_t2_free(struct ecore_hwfn *p_hwfn)
920 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
926 for (i = 0; i < p_mngr->t2_num_pages; i++)
927 if (p_mngr->t2[i].p_virt)
928 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
929 p_mngr->t2[i].p_virt,
930 p_mngr->t2[i].p_phys,
933 OSAL_FREE(p_hwfn->p_dev, p_mngr->t2);
934 p_mngr->t2 = OSAL_NULL;
937 static enum _ecore_status_t ecore_cxt_src_t2_alloc(struct ecore_hwfn *p_hwfn)
939 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
940 u32 conn_num, total_size, ent_per_page, psz, i;
941 struct ecore_ilt_client_cfg *p_src;
942 struct ecore_src_iids src_iids;
943 struct ecore_dma_mem *p_t2;
944 enum _ecore_status_t rc;
946 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
948 /* if the SRC ILT client is inactive - there are no connection
949 * requiring the searcer, leave.
951 p_src = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_SRC];
953 return ECORE_SUCCESS;
955 ecore_cxt_src_iids(p_mngr, &src_iids);
956 conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
957 total_size = conn_num * sizeof(struct src_ent);
959 /* use the same page size as the SRC ILT client */
960 psz = ILT_PAGE_IN_BYTES(p_src->p_size.val);
961 p_mngr->t2_num_pages = DIV_ROUND_UP(total_size, psz);
964 p_mngr->t2 = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
965 p_mngr->t2_num_pages *
966 sizeof(struct ecore_dma_mem));
968 DP_NOTICE(p_hwfn, true, "Failed to allocate t2 table\n");
973 /* allocate t2 pages */
974 for (i = 0; i < p_mngr->t2_num_pages; i++) {
975 u32 size = OSAL_MIN_T(u32, total_size, psz);
976 void **p_virt = &p_mngr->t2[i].p_virt;
978 *p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
979 &p_mngr->t2[i].p_phys,
981 if (!p_mngr->t2[i].p_virt) {
985 OSAL_MEM_ZERO(*p_virt, size);
986 p_mngr->t2[i].size = size;
990 /* Set the t2 pointers */
992 /* entries per page - must be a power of two */
993 ent_per_page = psz / sizeof(struct src_ent);
995 p_mngr->first_free = (u64)p_mngr->t2[0].p_phys;
997 p_t2 = &p_mngr->t2[(conn_num - 1) / ent_per_page];
998 p_mngr->last_free = (u64)p_t2->p_phys +
999 ((conn_num - 1) & (ent_per_page - 1)) *
1000 sizeof(struct src_ent);
1002 for (i = 0; i < p_mngr->t2_num_pages; i++) {
1003 u32 ent_num = OSAL_MIN_T(u32, ent_per_page, conn_num);
1004 struct src_ent *entries = p_mngr->t2[i].p_virt;
1005 u64 p_ent_phys = (u64)p_mngr->t2[i].p_phys, val;
1008 for (j = 0; j < ent_num - 1; j++) {
1010 (j + 1) * sizeof(struct src_ent);
1011 entries[j].next = OSAL_CPU_TO_BE64(val);
1014 if (i < p_mngr->t2_num_pages - 1)
1015 val = (u64)p_mngr->t2[i + 1].p_phys;
1018 entries[j].next = OSAL_CPU_TO_BE64(val);
1020 conn_num -= ent_num;
1023 return ECORE_SUCCESS;
1026 ecore_cxt_src_t2_free(p_hwfn);
1030 #define for_each_ilt_valid_client(pos, clients) \
1031 for (pos = 0; pos < ILT_CLI_MAX; pos++) \
1032 if (!clients[pos].active) { \
1037 /* Total number of ILT lines used by this PF */
1038 static u32 ecore_cxt_ilt_shadow_size(struct ecore_ilt_client_cfg *ilt_clients)
1043 for_each_ilt_valid_client(i, ilt_clients)
1044 size += (ilt_clients[i].last.val -
1045 ilt_clients[i].first.val + 1);
1050 static void ecore_ilt_shadow_free(struct ecore_hwfn *p_hwfn)
1052 struct ecore_ilt_client_cfg *p_cli = p_hwfn->p_cxt_mngr->clients;
1053 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1056 ilt_size = ecore_cxt_ilt_shadow_size(p_cli);
1058 for (i = 0; p_mngr->ilt_shadow && i < ilt_size; i++) {
1059 struct ecore_dma_mem *p_dma = &p_mngr->ilt_shadow[i];
1062 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1066 p_dma->p_virt = OSAL_NULL;
1068 OSAL_FREE(p_hwfn->p_dev, p_mngr->ilt_shadow);
1071 static enum _ecore_status_t ecore_ilt_blk_alloc(struct ecore_hwfn *p_hwfn,
1072 struct ecore_ilt_cli_blk *p_blk,
1073 enum ilt_clients ilt_client,
1074 u32 start_line_offset)
1076 struct ecore_dma_mem *ilt_shadow = p_hwfn->p_cxt_mngr->ilt_shadow;
1077 u32 lines, line, sz_left, lines_to_skip = 0;
1079 /* Special handling for RoCE that supports dynamic allocation */
1080 if (ECORE_IS_RDMA_PERSONALITY(p_hwfn) &&
1081 ((ilt_client == ILT_CLI_CDUT) || ilt_client == ILT_CLI_TSDM))
1082 return ECORE_SUCCESS;
1084 lines_to_skip = p_blk->dynamic_line_cnt;
1086 if (!p_blk->total_size)
1087 return ECORE_SUCCESS;
1089 sz_left = p_blk->total_size;
1090 lines = DIV_ROUND_UP(sz_left, p_blk->real_size_in_page) -
1092 line = p_blk->start_line + start_line_offset -
1093 p_hwfn->p_cxt_mngr->pf_start_line + lines_to_skip;
1095 for (; lines; lines--) {
1100 size = OSAL_MIN_T(u32, sz_left, p_blk->real_size_in_page);
1101 p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
1105 OSAL_MEM_ZERO(p_virt, size);
1107 ilt_shadow[line].p_phys = p_phys;
1108 ilt_shadow[line].p_virt = p_virt;
1109 ilt_shadow[line].size = size;
1111 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1112 "ILT shadow: Line [%d] Physical 0x%llx Virtual %p Size %d\n",
1113 line, (unsigned long long)p_phys, p_virt, size);
1119 return ECORE_SUCCESS;
1122 static enum _ecore_status_t ecore_ilt_shadow_alloc(struct ecore_hwfn *p_hwfn)
1124 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1125 struct ecore_ilt_client_cfg *clients = p_mngr->clients;
1126 struct ecore_ilt_cli_blk *p_blk;
1128 enum _ecore_status_t rc;
1130 size = ecore_cxt_ilt_shadow_size(clients);
1131 p_mngr->ilt_shadow = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
1132 size * sizeof(struct ecore_dma_mem));
1134 if (!p_mngr->ilt_shadow) {
1135 DP_NOTICE(p_hwfn, true, "Failed to allocate ilt shadow table\n");
1137 goto ilt_shadow_fail;
1140 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1141 "Allocated 0x%x bytes for ilt shadow\n",
1142 (u32)(size * sizeof(struct ecore_dma_mem)));
1144 for_each_ilt_valid_client(i, clients) {
1145 for (j = 0; j < ILT_CLI_PF_BLOCKS; j++) {
1146 p_blk = &clients[i].pf_blks[j];
1147 rc = ecore_ilt_blk_alloc(p_hwfn, p_blk, i, 0);
1148 if (rc != ECORE_SUCCESS)
1149 goto ilt_shadow_fail;
1151 for (k = 0; k < p_mngr->vf_count; k++) {
1152 for (j = 0; j < ILT_CLI_VF_BLOCKS; j++) {
1153 u32 lines = clients[i].vf_total_lines * k;
1155 p_blk = &clients[i].vf_blks[j];
1156 rc = ecore_ilt_blk_alloc(p_hwfn, p_blk,
1158 if (rc != ECORE_SUCCESS)
1159 goto ilt_shadow_fail;
1164 return ECORE_SUCCESS;
1167 ecore_ilt_shadow_free(p_hwfn);
1171 static void ecore_cid_map_free(struct ecore_hwfn *p_hwfn)
1173 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1176 for (type = 0; type < MAX_CONN_TYPES; type++) {
1177 OSAL_FREE(p_hwfn->p_dev, p_mngr->acquired[type].cid_map);
1178 p_mngr->acquired[type].max_count = 0;
1179 p_mngr->acquired[type].start_cid = 0;
1181 for (vf = 0; vf < COMMON_MAX_NUM_VFS; vf++) {
1182 OSAL_FREE(p_hwfn->p_dev,
1183 p_mngr->acquired_vf[type][vf].cid_map);
1184 p_mngr->acquired_vf[type][vf].max_count = 0;
1185 p_mngr->acquired_vf[type][vf].start_cid = 0;
1190 static enum _ecore_status_t
1191 ecore_cid_map_alloc_single(struct ecore_hwfn *p_hwfn, u32 type,
1192 u32 cid_start, u32 cid_count,
1193 struct ecore_cid_acquired_map *p_map)
1198 return ECORE_SUCCESS;
1200 size = MAP_WORD_SIZE * DIV_ROUND_UP(cid_count, BITS_PER_MAP_WORD);
1201 p_map->cid_map = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, size);
1202 if (p_map->cid_map == OSAL_NULL)
1205 p_map->max_count = cid_count;
1206 p_map->start_cid = cid_start;
1208 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
1209 "Type %08x start: %08x count %08x\n",
1210 type, p_map->start_cid, p_map->max_count);
1212 return ECORE_SUCCESS;
1215 static enum _ecore_status_t ecore_cid_map_alloc(struct ecore_hwfn *p_hwfn)
1217 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1218 u32 start_cid = 0, vf_start_cid = 0;
1221 for (type = 0; type < MAX_CONN_TYPES; type++) {
1222 struct ecore_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[type];
1223 struct ecore_cid_acquired_map *p_map;
1225 /* Handle PF maps */
1226 p_map = &p_mngr->acquired[type];
1227 if (ecore_cid_map_alloc_single(p_hwfn, type, start_cid,
1228 p_cfg->cid_count, p_map))
1231 /* Handle VF maps */
1232 for (vf = 0; vf < COMMON_MAX_NUM_VFS; vf++) {
1233 p_map = &p_mngr->acquired_vf[type][vf];
1234 if (ecore_cid_map_alloc_single(p_hwfn, type,
1241 start_cid += p_cfg->cid_count;
1242 vf_start_cid += p_cfg->cids_per_vf;
1245 return ECORE_SUCCESS;
1248 ecore_cid_map_free(p_hwfn);
1252 enum _ecore_status_t ecore_cxt_mngr_alloc(struct ecore_hwfn *p_hwfn)
1254 struct ecore_ilt_client_cfg *clients;
1255 struct ecore_cxt_mngr *p_mngr;
1258 p_mngr = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_mngr));
1260 DP_NOTICE(p_hwfn, true, "Failed to allocate `struct ecore_cxt_mngr'\n");
1264 /* Initialize ILT client registers */
1265 clients = p_mngr->clients;
1266 clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT);
1267 clients[ILT_CLI_CDUC].last.reg = ILT_CFG_REG(CDUC, LAST_ILT);
1268 clients[ILT_CLI_CDUC].p_size.reg = ILT_CFG_REG(CDUC, P_SIZE);
1270 clients[ILT_CLI_QM].first.reg = ILT_CFG_REG(QM, FIRST_ILT);
1271 clients[ILT_CLI_QM].last.reg = ILT_CFG_REG(QM, LAST_ILT);
1272 clients[ILT_CLI_QM].p_size.reg = ILT_CFG_REG(QM, P_SIZE);
1274 clients[ILT_CLI_TM].first.reg = ILT_CFG_REG(TM, FIRST_ILT);
1275 clients[ILT_CLI_TM].last.reg = ILT_CFG_REG(TM, LAST_ILT);
1276 clients[ILT_CLI_TM].p_size.reg = ILT_CFG_REG(TM, P_SIZE);
1278 clients[ILT_CLI_SRC].first.reg = ILT_CFG_REG(SRC, FIRST_ILT);
1279 clients[ILT_CLI_SRC].last.reg = ILT_CFG_REG(SRC, LAST_ILT);
1280 clients[ILT_CLI_SRC].p_size.reg = ILT_CFG_REG(SRC, P_SIZE);
1282 clients[ILT_CLI_CDUT].first.reg = ILT_CFG_REG(CDUT, FIRST_ILT);
1283 clients[ILT_CLI_CDUT].last.reg = ILT_CFG_REG(CDUT, LAST_ILT);
1284 clients[ILT_CLI_CDUT].p_size.reg = ILT_CFG_REG(CDUT, P_SIZE);
1286 clients[ILT_CLI_TSDM].first.reg = ILT_CFG_REG(TSDM, FIRST_ILT);
1287 clients[ILT_CLI_TSDM].last.reg = ILT_CFG_REG(TSDM, LAST_ILT);
1288 clients[ILT_CLI_TSDM].p_size.reg = ILT_CFG_REG(TSDM, P_SIZE);
1290 /* default ILT page size for all clients is 64K */
1291 for (i = 0; i < ILT_CLI_MAX; i++)
1292 p_mngr->clients[i].p_size.val = ILT_DEFAULT_HW_P_SIZE;
1294 /* Initialize task sizes */
1295 p_mngr->task_type_size[0] = TYPE0_TASK_CXT_SIZE(p_hwfn);
1296 p_mngr->task_type_size[1] = TYPE1_TASK_CXT_SIZE(p_hwfn);
1298 if (p_hwfn->p_dev->p_iov_info)
1299 p_mngr->vf_count = p_hwfn->p_dev->p_iov_info->total_vfs;
1301 /* Initialize the dynamic ILT allocation mutex */
1302 #ifdef CONFIG_ECORE_LOCK_ALLOC
1303 OSAL_MUTEX_ALLOC(p_hwfn, &p_mngr->mutex);
1305 OSAL_MUTEX_INIT(&p_mngr->mutex);
1307 /* Set the cxt mangr pointer priori to further allocations */
1308 p_hwfn->p_cxt_mngr = p_mngr;
1310 return ECORE_SUCCESS;
1313 enum _ecore_status_t ecore_cxt_tables_alloc(struct ecore_hwfn *p_hwfn)
1315 enum _ecore_status_t rc;
1317 /* Allocate the ILT shadow table */
1318 rc = ecore_ilt_shadow_alloc(p_hwfn);
1320 DP_NOTICE(p_hwfn, true, "Failed to allocate ilt memory\n");
1321 goto tables_alloc_fail;
1324 /* Allocate the T2 table */
1325 rc = ecore_cxt_src_t2_alloc(p_hwfn);
1327 DP_NOTICE(p_hwfn, true, "Failed to allocate T2 memory\n");
1328 goto tables_alloc_fail;
1331 /* Allocate and initialize the acquired cids bitmaps */
1332 rc = ecore_cid_map_alloc(p_hwfn);
1334 DP_NOTICE(p_hwfn, true, "Failed to allocate cid maps\n");
1335 goto tables_alloc_fail;
1338 return ECORE_SUCCESS;
1341 ecore_cxt_mngr_free(p_hwfn);
1344 void ecore_cxt_mngr_free(struct ecore_hwfn *p_hwfn)
1346 if (!p_hwfn->p_cxt_mngr)
1349 ecore_cid_map_free(p_hwfn);
1350 ecore_cxt_src_t2_free(p_hwfn);
1351 ecore_ilt_shadow_free(p_hwfn);
1352 #ifdef CONFIG_ECORE_LOCK_ALLOC
1353 OSAL_MUTEX_DEALLOC(&p_hwfn->p_cxt_mngr->mutex);
1355 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_cxt_mngr);
1357 p_hwfn->p_cxt_mngr = OSAL_NULL;
1360 void ecore_cxt_mngr_setup(struct ecore_hwfn *p_hwfn)
1362 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1363 struct ecore_cid_acquired_map *p_map;
1364 struct ecore_conn_type_cfg *p_cfg;
1368 /* Reset acquired cids */
1369 for (type = 0; type < MAX_CONN_TYPES; type++) {
1372 p_cfg = &p_mngr->conn_cfg[type];
1373 if (p_cfg->cid_count) {
1374 p_map = &p_mngr->acquired[type];
1375 len = DIV_ROUND_UP(p_map->max_count,
1376 BITS_PER_MAP_WORD) *
1378 OSAL_MEM_ZERO(p_map->cid_map, len);
1381 if (!p_cfg->cids_per_vf)
1384 for (vf = 0; vf < COMMON_MAX_NUM_VFS; vf++) {
1385 p_map = &p_mngr->acquired_vf[type][vf];
1386 len = DIV_ROUND_UP(p_map->max_count,
1387 BITS_PER_MAP_WORD) *
1389 OSAL_MEM_ZERO(p_map->cid_map, len);
1394 /* HW initialization helper (per Block, per phase) */
1397 #define CDUC_CXT_SIZE_SHIFT \
1398 CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE_SHIFT
1400 #define CDUC_CXT_SIZE_MASK \
1401 (CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE >> CDUC_CXT_SIZE_SHIFT)
1403 #define CDUC_BLOCK_WASTE_SHIFT \
1404 CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE_SHIFT
1406 #define CDUC_BLOCK_WASTE_MASK \
1407 (CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE >> CDUC_BLOCK_WASTE_SHIFT)
1409 #define CDUC_NCIB_SHIFT \
1410 CDU_REG_CID_ADDR_PARAMS_NCIB_SHIFT
1412 #define CDUC_NCIB_MASK \
1413 (CDU_REG_CID_ADDR_PARAMS_NCIB >> CDUC_NCIB_SHIFT)
1415 #define CDUT_TYPE0_CXT_SIZE_SHIFT \
1416 CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE_SHIFT
1418 #define CDUT_TYPE0_CXT_SIZE_MASK \
1419 (CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE >> \
1420 CDUT_TYPE0_CXT_SIZE_SHIFT)
1422 #define CDUT_TYPE0_BLOCK_WASTE_SHIFT \
1423 CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE_SHIFT
1425 #define CDUT_TYPE0_BLOCK_WASTE_MASK \
1426 (CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE >> \
1427 CDUT_TYPE0_BLOCK_WASTE_SHIFT)
1429 #define CDUT_TYPE0_NCIB_SHIFT \
1430 CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK_SHIFT
1432 #define CDUT_TYPE0_NCIB_MASK \
1433 (CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK >> \
1434 CDUT_TYPE0_NCIB_SHIFT)
1436 #define CDUT_TYPE1_CXT_SIZE_SHIFT \
1437 CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE_SHIFT
1439 #define CDUT_TYPE1_CXT_SIZE_MASK \
1440 (CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE >> \
1441 CDUT_TYPE1_CXT_SIZE_SHIFT)
1443 #define CDUT_TYPE1_BLOCK_WASTE_SHIFT \
1444 CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE_SHIFT
1446 #define CDUT_TYPE1_BLOCK_WASTE_MASK \
1447 (CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE >> \
1448 CDUT_TYPE1_BLOCK_WASTE_SHIFT)
1450 #define CDUT_TYPE1_NCIB_SHIFT \
1451 CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK_SHIFT
1453 #define CDUT_TYPE1_NCIB_MASK \
1454 (CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK >> \
1455 CDUT_TYPE1_NCIB_SHIFT)
1457 static void ecore_cdu_init_common(struct ecore_hwfn *p_hwfn)
1459 u32 page_sz, elems_per_page, block_waste, cxt_size, cdu_params = 0;
1461 /* CDUC - connection configuration */
1462 page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
1463 cxt_size = CONN_CXT_SIZE(p_hwfn);
1464 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1465 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1467 SET_FIELD(cdu_params, CDUC_CXT_SIZE, cxt_size);
1468 SET_FIELD(cdu_params, CDUC_BLOCK_WASTE, block_waste);
1469 SET_FIELD(cdu_params, (u32)CDUC_NCIB, elems_per_page);
1470 STORE_RT_REG(p_hwfn, CDU_REG_CID_ADDR_PARAMS_RT_OFFSET, cdu_params);
1472 /* CDUT - type-0 tasks configuration */
1473 page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT].p_size.val;
1474 cxt_size = p_hwfn->p_cxt_mngr->task_type_size[0];
1475 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1476 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1478 /* cxt size and block-waste are multipes of 8 */
1480 SET_FIELD(cdu_params, (u32)CDUT_TYPE0_CXT_SIZE, (cxt_size >> 3));
1481 SET_FIELD(cdu_params, CDUT_TYPE0_BLOCK_WASTE, (block_waste >> 3));
1482 SET_FIELD(cdu_params, CDUT_TYPE0_NCIB, elems_per_page);
1483 STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT0_PARAMS_RT_OFFSET, cdu_params);
1485 /* CDUT - type-1 tasks configuration */
1486 cxt_size = p_hwfn->p_cxt_mngr->task_type_size[1];
1487 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
1488 block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
1490 /* cxt size and block-waste are multipes of 8 */
1492 SET_FIELD(cdu_params, (u32)CDUT_TYPE1_CXT_SIZE, (cxt_size >> 3));
1493 SET_FIELD(cdu_params, CDUT_TYPE1_BLOCK_WASTE, (block_waste >> 3));
1494 SET_FIELD(cdu_params, CDUT_TYPE1_NCIB, elems_per_page);
1495 STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT1_PARAMS_RT_OFFSET, cdu_params);
1499 #define CDU_SEG_REG_TYPE_SHIFT CDU_SEG_TYPE_OFFSET_REG_TYPE_SHIFT
1500 #define CDU_SEG_REG_TYPE_MASK 0x1
1501 #define CDU_SEG_REG_OFFSET_SHIFT 0
1502 #define CDU_SEG_REG_OFFSET_MASK CDU_SEG_TYPE_OFFSET_REG_OFFSET_MASK
1504 static void ecore_cdu_init_pf(struct ecore_hwfn *p_hwfn)
1506 struct ecore_ilt_client_cfg *p_cli;
1507 struct ecore_tid_seg *p_seg;
1508 u32 cdu_seg_params, offset;
1511 static const u32 rt_type_offset_arr[] = {
1512 CDU_REG_PF_SEG0_TYPE_OFFSET_RT_OFFSET,
1513 CDU_REG_PF_SEG1_TYPE_OFFSET_RT_OFFSET,
1514 CDU_REG_PF_SEG2_TYPE_OFFSET_RT_OFFSET,
1515 CDU_REG_PF_SEG3_TYPE_OFFSET_RT_OFFSET
1518 static const u32 rt_type_offset_fl_arr[] = {
1519 CDU_REG_PF_FL_SEG0_TYPE_OFFSET_RT_OFFSET,
1520 CDU_REG_PF_FL_SEG1_TYPE_OFFSET_RT_OFFSET,
1521 CDU_REG_PF_FL_SEG2_TYPE_OFFSET_RT_OFFSET,
1522 CDU_REG_PF_FL_SEG3_TYPE_OFFSET_RT_OFFSET
1525 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1527 /* There are initializations only for CDUT during pf Phase */
1528 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
1530 p_seg = ecore_cxt_tid_seg_info(p_hwfn, i);
1534 /* Note: start_line is already adjusted for the CDU
1535 * segment register granularity, so we just need to
1536 * divide. Adjustment is implicit as we assume ILT
1537 * Page size is larger than 32K!
1539 offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
1540 (p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line -
1541 p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
1544 SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
1545 SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
1546 STORE_RT_REG(p_hwfn, rt_type_offset_arr[i],
1549 offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
1550 (p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)].start_line -
1551 p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
1554 SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
1555 SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
1556 STORE_RT_REG(p_hwfn, rt_type_offset_fl_arr[i],
1562 void ecore_qm_init_pf(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1564 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
1565 struct ecore_qm_iids iids;
1567 OSAL_MEM_ZERO(&iids, sizeof(iids));
1568 ecore_cxt_qm_iids(p_hwfn, &iids);
1570 ecore_qm_pf_rt_init(p_hwfn, p_ptt, p_hwfn->port_id,
1571 p_hwfn->rel_pf_id, qm_info->max_phys_tcs_per_port,
1572 iids.cids, iids.vf_cids, iids.tids,
1574 qm_info->num_pqs - qm_info->num_vf_pqs,
1575 qm_info->num_vf_pqs,
1576 qm_info->start_vport,
1577 qm_info->num_vports, qm_info->pf_wfq, qm_info->pf_rl,
1578 p_hwfn->qm_info.qm_pq_params,
1579 p_hwfn->qm_info.qm_vport_params);
1583 static void ecore_cm_init_pf(struct ecore_hwfn *p_hwfn)
1585 STORE_RT_REG(p_hwfn, XCM_REG_CON_PHY_Q3_RT_OFFSET, ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB));
1589 static void ecore_dq_init_pf(struct ecore_hwfn *p_hwfn)
1591 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1592 u32 dq_pf_max_cid = 0, dq_vf_max_cid = 0;
1594 dq_pf_max_cid += (p_mngr->conn_cfg[0].cid_count >> DQ_RANGE_SHIFT);
1595 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_0_RT_OFFSET, dq_pf_max_cid);
1597 dq_vf_max_cid += (p_mngr->conn_cfg[0].cids_per_vf >> DQ_RANGE_SHIFT);
1598 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_0_RT_OFFSET, dq_vf_max_cid);
1600 dq_pf_max_cid += (p_mngr->conn_cfg[1].cid_count >> DQ_RANGE_SHIFT);
1601 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_1_RT_OFFSET, dq_pf_max_cid);
1603 dq_vf_max_cid += (p_mngr->conn_cfg[1].cids_per_vf >> DQ_RANGE_SHIFT);
1604 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_1_RT_OFFSET, dq_vf_max_cid);
1606 dq_pf_max_cid += (p_mngr->conn_cfg[2].cid_count >> DQ_RANGE_SHIFT);
1607 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_2_RT_OFFSET, dq_pf_max_cid);
1609 dq_vf_max_cid += (p_mngr->conn_cfg[2].cids_per_vf >> DQ_RANGE_SHIFT);
1610 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_2_RT_OFFSET, dq_vf_max_cid);
1612 dq_pf_max_cid += (p_mngr->conn_cfg[3].cid_count >> DQ_RANGE_SHIFT);
1613 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_3_RT_OFFSET, dq_pf_max_cid);
1615 dq_vf_max_cid += (p_mngr->conn_cfg[3].cids_per_vf >> DQ_RANGE_SHIFT);
1616 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_3_RT_OFFSET, dq_vf_max_cid);
1618 dq_pf_max_cid += (p_mngr->conn_cfg[4].cid_count >> DQ_RANGE_SHIFT);
1619 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_4_RT_OFFSET, dq_pf_max_cid);
1621 dq_vf_max_cid += (p_mngr->conn_cfg[4].cids_per_vf >> DQ_RANGE_SHIFT);
1622 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_4_RT_OFFSET, dq_vf_max_cid);
1624 dq_pf_max_cid += (p_mngr->conn_cfg[5].cid_count >> DQ_RANGE_SHIFT);
1625 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_5_RT_OFFSET, dq_pf_max_cid);
1627 dq_vf_max_cid += (p_mngr->conn_cfg[5].cids_per_vf >> DQ_RANGE_SHIFT);
1628 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_5_RT_OFFSET, dq_vf_max_cid);
1630 /* Connection types 6 & 7 are not in use, yet they must be configured
1631 * as the highest possible connection. Not configuring them means the
1632 * defaults will be used, and with a large number of cids a bug may
1633 * occur, if the defaults will be smaller than dq_pf_max_cid /
1636 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_6_RT_OFFSET, dq_pf_max_cid);
1637 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_6_RT_OFFSET, dq_vf_max_cid);
1639 STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_7_RT_OFFSET, dq_pf_max_cid);
1640 STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_7_RT_OFFSET, dq_vf_max_cid);
1643 static void ecore_ilt_bounds_init(struct ecore_hwfn *p_hwfn)
1645 struct ecore_ilt_client_cfg *ilt_clients;
1648 ilt_clients = p_hwfn->p_cxt_mngr->clients;
1649 for_each_ilt_valid_client(i, ilt_clients) {
1650 STORE_RT_REG(p_hwfn,
1651 ilt_clients[i].first.reg,
1652 ilt_clients[i].first.val);
1653 STORE_RT_REG(p_hwfn,
1654 ilt_clients[i].last.reg,
1655 ilt_clients[i].last.val);
1656 STORE_RT_REG(p_hwfn,
1657 ilt_clients[i].p_size.reg,
1658 ilt_clients[i].p_size.val);
1662 static void ecore_ilt_vf_bounds_init(struct ecore_hwfn *p_hwfn)
1664 struct ecore_ilt_client_cfg *p_cli;
1667 /* For simplicty we set the 'block' to be an ILT page */
1668 if (p_hwfn->p_dev->p_iov_info) {
1669 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
1671 STORE_RT_REG(p_hwfn,
1672 PSWRQ2_REG_VF_BASE_RT_OFFSET,
1673 p_iov->first_vf_in_pf);
1674 STORE_RT_REG(p_hwfn,
1675 PSWRQ2_REG_VF_LAST_ILT_RT_OFFSET,
1676 p_iov->first_vf_in_pf + p_iov->total_vfs);
1679 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
1680 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1681 if (p_cli->active) {
1682 STORE_RT_REG(p_hwfn,
1683 PSWRQ2_REG_CDUC_BLOCKS_FACTOR_RT_OFFSET,
1685 STORE_RT_REG(p_hwfn,
1686 PSWRQ2_REG_CDUC_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1687 p_cli->pf_total_lines);
1688 STORE_RT_REG(p_hwfn,
1689 PSWRQ2_REG_CDUC_VF_BLOCKS_RT_OFFSET,
1690 p_cli->vf_total_lines);
1693 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
1694 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1695 if (p_cli->active) {
1696 STORE_RT_REG(p_hwfn,
1697 PSWRQ2_REG_CDUT_BLOCKS_FACTOR_RT_OFFSET,
1699 STORE_RT_REG(p_hwfn,
1700 PSWRQ2_REG_CDUT_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1701 p_cli->pf_total_lines);
1702 STORE_RT_REG(p_hwfn,
1703 PSWRQ2_REG_CDUT_VF_BLOCKS_RT_OFFSET,
1704 p_cli->vf_total_lines);
1707 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TM];
1708 blk_factor = OSAL_LOG2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
1709 if (p_cli->active) {
1710 STORE_RT_REG(p_hwfn,
1711 PSWRQ2_REG_TM_BLOCKS_FACTOR_RT_OFFSET,
1713 STORE_RT_REG(p_hwfn,
1714 PSWRQ2_REG_TM_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
1715 p_cli->pf_total_lines);
1716 STORE_RT_REG(p_hwfn,
1717 PSWRQ2_REG_TM_VF_BLOCKS_RT_OFFSET,
1718 p_cli->vf_total_lines);
1722 /* ILT (PSWRQ2) PF */
1723 static void ecore_ilt_init_pf(struct ecore_hwfn *p_hwfn)
1725 struct ecore_ilt_client_cfg *clients;
1726 struct ecore_cxt_mngr *p_mngr;
1727 struct ecore_dma_mem *p_shdw;
1728 u32 line, rt_offst, i;
1730 ecore_ilt_bounds_init(p_hwfn);
1731 ecore_ilt_vf_bounds_init(p_hwfn);
1733 p_mngr = p_hwfn->p_cxt_mngr;
1734 p_shdw = p_mngr->ilt_shadow;
1735 clients = p_hwfn->p_cxt_mngr->clients;
1737 for_each_ilt_valid_client(i, clients) {
1738 /* Client's 1st val and RT array are absolute, ILT shadows'
1739 * lines are relative.
1741 line = clients[i].first.val - p_mngr->pf_start_line;
1742 rt_offst = PSWRQ2_REG_ILT_MEMORY_RT_OFFSET +
1743 clients[i].first.val * ILT_ENTRY_IN_REGS;
1745 for (; line <= clients[i].last.val - p_mngr->pf_start_line;
1746 line++, rt_offst += ILT_ENTRY_IN_REGS) {
1747 u64 ilt_hw_entry = 0;
1749 /** p_virt could be OSAL_NULL incase of dynamic
1752 if (p_shdw[line].p_virt != OSAL_NULL) {
1753 SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
1754 SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR,
1755 (unsigned long long)(p_shdw[line].p_phys >> 12));
1758 p_hwfn, ECORE_MSG_ILT,
1759 "Setting RT[0x%08x] from ILT[0x%08x] [Client is %d] to Physical addr: 0x%llx\n",
1761 (unsigned long long)(p_shdw[line].p_phys >> 12));
1764 STORE_RT_REG_AGG(p_hwfn, rt_offst, ilt_hw_entry);
1769 /* SRC (Searcher) PF */
1770 static void ecore_src_init_pf(struct ecore_hwfn *p_hwfn)
1772 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1773 u32 rounded_conn_num, conn_num, conn_max;
1774 struct ecore_src_iids src_iids;
1776 OSAL_MEM_ZERO(&src_iids, sizeof(src_iids));
1777 ecore_cxt_src_iids(p_mngr, &src_iids);
1778 conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
1782 conn_max = OSAL_MAX_T(u32, conn_num, SRC_MIN_NUM_ELEMS);
1783 rounded_conn_num = OSAL_ROUNDUP_POW_OF_TWO(conn_max);
1785 STORE_RT_REG(p_hwfn, SRC_REG_COUNTFREE_RT_OFFSET, conn_num);
1786 STORE_RT_REG(p_hwfn, SRC_REG_NUMBER_HASH_BITS_RT_OFFSET,
1787 OSAL_LOG2(rounded_conn_num));
1789 STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET,
1790 p_hwfn->p_cxt_mngr->first_free);
1791 STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET,
1792 p_hwfn->p_cxt_mngr->last_free);
1793 DP_VERBOSE(p_hwfn, ECORE_MSG_ILT,
1794 "Configured SEARCHER for 0x%08x connections\n",
1799 #define TM_CFG_NUM_IDS_SHIFT 0
1800 #define TM_CFG_NUM_IDS_MASK 0xFFFFULL
1801 #define TM_CFG_PRE_SCAN_OFFSET_SHIFT 16
1802 #define TM_CFG_PRE_SCAN_OFFSET_MASK 0x1FFULL
1803 #define TM_CFG_PARENT_PF_SHIFT 25
1804 #define TM_CFG_PARENT_PF_MASK 0x7ULL
1806 #define TM_CFG_CID_PRE_SCAN_ROWS_SHIFT 30
1807 #define TM_CFG_CID_PRE_SCAN_ROWS_MASK 0x1FFULL
1809 #define TM_CFG_TID_OFFSET_SHIFT 30
1810 #define TM_CFG_TID_OFFSET_MASK 0x7FFFFULL
1811 #define TM_CFG_TID_PRE_SCAN_ROWS_SHIFT 49
1812 #define TM_CFG_TID_PRE_SCAN_ROWS_MASK 0x1FFULL
1814 static void ecore_tm_init_pf(struct ecore_hwfn *p_hwfn)
1816 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1817 u32 active_seg_mask = 0, tm_offset, rt_reg;
1818 struct ecore_tm_iids tm_iids;
1822 OSAL_MEM_ZERO(&tm_iids, sizeof(tm_iids));
1823 ecore_cxt_tm_iids(p_mngr, &tm_iids);
1825 /* @@@TBD No pre-scan for now */
1827 /* Note: We assume consecutive VFs for a PF */
1828 for (i = 0; i < p_mngr->vf_count; i++) {
1830 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_cids);
1831 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1832 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
1833 SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
1835 rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
1836 (sizeof(cfg_word) / sizeof(u32)) *
1837 (p_hwfn->p_dev->p_iov_info->first_vf_in_pf + i);
1838 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1842 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_cids);
1843 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1844 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); /* n/a for PF */
1845 SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
1847 rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
1848 (sizeof(cfg_word) / sizeof(u32)) *
1849 (NUM_OF_VFS(p_hwfn->p_dev) + p_hwfn->rel_pf_id);
1850 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1853 STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_CONN_RT_OFFSET,
1854 tm_iids.pf_cids ? 0x1 : 0x0);
1856 /* @@@TBD how to enable the scan for the VFs */
1858 tm_offset = tm_iids.per_vf_cids;
1860 /* Note: We assume consecutive VFs for a PF */
1861 for (i = 0; i < p_mngr->vf_count; i++) {
1863 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_tids);
1864 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1865 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
1866 SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
1867 SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64)0);
1869 rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
1870 (sizeof(cfg_word) / sizeof(u32)) *
1871 (p_hwfn->p_dev->p_iov_info->first_vf_in_pf + i);
1873 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1876 tm_offset = tm_iids.pf_cids;
1877 for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
1879 SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_tids[i]);
1880 SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
1881 SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0);
1882 SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
1883 SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64)0);
1885 rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
1886 (sizeof(cfg_word) / sizeof(u32)) *
1887 (NUM_OF_VFS(p_hwfn->p_dev) +
1888 p_hwfn->rel_pf_id * NUM_TASK_PF_SEGMENTS + i);
1890 STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
1891 active_seg_mask |= (tm_iids.pf_tids[i] ? (1 << i) : 0);
1893 tm_offset += tm_iids.pf_tids[i];
1896 if (ECORE_IS_RDMA_PERSONALITY(p_hwfn))
1897 active_seg_mask = 0;
1899 STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_TASK_RT_OFFSET, active_seg_mask);
1901 /* @@@TBD how to enable the scan for the VFs */
1904 static void ecore_prs_init_common(struct ecore_hwfn *p_hwfn)
1906 if ((p_hwfn->hw_info.personality == ECORE_PCI_FCOE) &&
1907 p_hwfn->pf_params.fcoe_pf_params.is_target)
1908 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_RESP_INITIATOR_TYPE_RT_OFFSET, 0);
1911 static void ecore_prs_init_pf(struct ecore_hwfn *p_hwfn)
1913 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1914 struct ecore_conn_type_cfg *p_fcoe;
1915 struct ecore_tid_seg *p_tid;
1917 p_fcoe = &p_mngr->conn_cfg[PROTOCOLID_FCOE];
1919 /* If FCoE is active set the MAX OX_ID (tid) in the Parser */
1920 if (!p_fcoe->cid_count)
1923 p_tid = &p_fcoe->tid_seg[ECORE_CXT_FCOE_TID_SEG];
1924 if (p_hwfn->pf_params.fcoe_pf_params.is_target) {
1925 STORE_RT_REG_AGG(p_hwfn,
1926 PRS_REG_TASK_ID_MAX_TARGET_PF_RT_OFFSET,
1929 STORE_RT_REG_AGG(p_hwfn,
1930 PRS_REG_TASK_ID_MAX_INITIATOR_PF_RT_OFFSET,
1935 void ecore_cxt_hw_init_common(struct ecore_hwfn *p_hwfn)
1937 /* CDU configuration */
1938 ecore_cdu_init_common(p_hwfn);
1939 ecore_prs_init_common(p_hwfn);
1942 void ecore_cxt_hw_init_pf(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1944 ecore_qm_init_pf(p_hwfn, p_ptt);
1945 ecore_cm_init_pf(p_hwfn);
1946 ecore_dq_init_pf(p_hwfn);
1947 ecore_cdu_init_pf(p_hwfn);
1948 ecore_ilt_init_pf(p_hwfn);
1949 ecore_src_init_pf(p_hwfn);
1950 ecore_tm_init_pf(p_hwfn);
1951 ecore_prs_init_pf(p_hwfn);
1954 enum _ecore_status_t _ecore_cxt_acquire_cid(struct ecore_hwfn *p_hwfn,
1955 enum protocol_type type,
1956 u32 *p_cid, u8 vfid)
1958 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
1959 struct ecore_cid_acquired_map *p_map;
1962 if (type >= MAX_CONN_TYPES) {
1963 DP_NOTICE(p_hwfn, true, "Invalid protocol type %d", type);
1967 if (vfid >= COMMON_MAX_NUM_VFS && vfid != ECORE_CXT_PF_CID) {
1968 DP_NOTICE(p_hwfn, true, "VF [%02x] is out of range\n", vfid);
1972 /* Determine the right map to take this CID from */
1973 if (vfid == ECORE_CXT_PF_CID)
1974 p_map = &p_mngr->acquired[type];
1976 p_map = &p_mngr->acquired_vf[type][vfid];
1978 if (p_map->cid_map == OSAL_NULL) {
1979 DP_NOTICE(p_hwfn, true, "Invalid protocol type %d", type);
1983 rel_cid = OSAL_FIND_FIRST_ZERO_BIT(p_map->cid_map,
1986 if (rel_cid >= p_map->max_count) {
1987 DP_NOTICE(p_hwfn, false, "no CID available for protocol %d\n",
1989 return ECORE_NORESOURCES;
1992 OSAL_SET_BIT(rel_cid, p_map->cid_map);
1994 *p_cid = rel_cid + p_map->start_cid;
1996 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
1997 "Acquired cid 0x%08x [rel. %08x] vfid %02x type %d\n",
1998 *p_cid, rel_cid, vfid, type);
2000 return ECORE_SUCCESS;
2003 enum _ecore_status_t ecore_cxt_acquire_cid(struct ecore_hwfn *p_hwfn,
2004 enum protocol_type type,
2007 return _ecore_cxt_acquire_cid(p_hwfn, type, p_cid, ECORE_CXT_PF_CID);
2010 static bool ecore_cxt_test_cid_acquired(struct ecore_hwfn *p_hwfn,
2012 enum protocol_type *p_type,
2013 struct ecore_cid_acquired_map **pp_map)
2015 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
2018 /* Iterate over protocols and find matching cid range */
2019 for (*p_type = 0; *p_type < MAX_CONN_TYPES; (*p_type)++) {
2020 if (vfid == ECORE_CXT_PF_CID)
2021 *pp_map = &p_mngr->acquired[*p_type];
2023 *pp_map = &p_mngr->acquired_vf[*p_type][vfid];
2025 if (!((*pp_map)->cid_map))
2027 if (cid >= (*pp_map)->start_cid &&
2028 cid < (*pp_map)->start_cid + (*pp_map)->max_count) {
2033 if (*p_type == MAX_CONN_TYPES) {
2034 DP_NOTICE(p_hwfn, true, "Invalid CID %d vfid %02x", cid, vfid);
2038 rel_cid = cid - (*pp_map)->start_cid;
2039 if (!OSAL_TEST_BIT(rel_cid, (*pp_map)->cid_map)) {
2040 DP_NOTICE(p_hwfn, true,
2041 "CID %d [vifd %02x] not acquired", cid, vfid);
2047 *p_type = MAX_CONN_TYPES;
2048 *pp_map = OSAL_NULL;
2052 void _ecore_cxt_release_cid(struct ecore_hwfn *p_hwfn, u32 cid, u8 vfid)
2054 struct ecore_cid_acquired_map *p_map = OSAL_NULL;
2055 enum protocol_type type;
2059 if (vfid != ECORE_CXT_PF_CID && vfid > COMMON_MAX_NUM_VFS) {
2060 DP_NOTICE(p_hwfn, true,
2061 "Trying to return incorrect CID belonging to VF %02x\n",
2066 /* Test acquired and find matching per-protocol map */
2067 b_acquired = ecore_cxt_test_cid_acquired(p_hwfn, cid, vfid,
2073 rel_cid = cid - p_map->start_cid;
2074 OSAL_CLEAR_BIT(rel_cid, p_map->cid_map);
2076 DP_VERBOSE(p_hwfn, ECORE_MSG_CXT,
2077 "Released CID 0x%08x [rel. %08x] vfid %02x type %d\n",
2078 cid, rel_cid, vfid, type);
2081 void ecore_cxt_release_cid(struct ecore_hwfn *p_hwfn, u32 cid)
2083 _ecore_cxt_release_cid(p_hwfn, cid, ECORE_CXT_PF_CID);
2086 enum _ecore_status_t ecore_cxt_get_cid_info(struct ecore_hwfn *p_hwfn,
2087 struct ecore_cxt_info *p_info)
2089 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
2090 struct ecore_cid_acquired_map *p_map = OSAL_NULL;
2091 u32 conn_cxt_size, hw_p_size, cxts_per_p, line;
2092 enum protocol_type type;
2095 /* Test acquired and find matching per-protocol map */
2096 b_acquired = ecore_cxt_test_cid_acquired(p_hwfn, p_info->iid,
2103 /* set the protocl type */
2104 p_info->type = type;
2106 /* compute context virtual pointer */
2107 hw_p_size = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
2109 conn_cxt_size = CONN_CXT_SIZE(p_hwfn);
2110 cxts_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / conn_cxt_size;
2111 line = p_info->iid / cxts_per_p;
2113 /* Make sure context is allocated (dynamic allocation) */
2114 if (!p_mngr->ilt_shadow[line].p_virt)
2117 p_info->p_cxt = (u8 *)p_mngr->ilt_shadow[line].p_virt +
2118 p_info->iid % cxts_per_p * conn_cxt_size;
2120 DP_VERBOSE(p_hwfn, (ECORE_MSG_ILT | ECORE_MSG_CXT),
2121 "Accessing ILT shadow[%d]: CXT pointer is at %p (for iid %d)\n",
2122 (p_info->iid / cxts_per_p), p_info->p_cxt, p_info->iid);
2124 return ECORE_SUCCESS;
2127 static void ecore_rdma_set_pf_params(struct ecore_hwfn *p_hwfn,
2128 struct ecore_rdma_pf_params *p_params,
2131 u32 num_cons, num_qps, num_srqs;
2132 enum protocol_type proto;
2134 /* Override personality with rdma flavor */
2135 num_srqs = OSAL_MIN_T(u32, ECORE_RDMA_MAX_SRQS, p_params->num_srqs);
2137 /* The only case RDMA personality can be overriden is if NVRAM is
2138 * configured with ETH_RDMA or if no rdma protocol was requested
2140 switch (p_params->rdma_protocol) {
2141 case ECORE_RDMA_PROTOCOL_DEFAULT:
2142 if (p_hwfn->mcp_info->func_info.protocol ==
2143 ECORE_PCI_ETH_RDMA) {
2144 DP_NOTICE(p_hwfn, false,
2145 "Current day drivers don't support RoCE & iWARP. Default to RoCE-only\n");
2146 p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
2149 case ECORE_RDMA_PROTOCOL_NONE:
2150 p_hwfn->hw_info.personality = ECORE_PCI_ETH;
2151 return; /* intentional... nothing left to do... */
2152 case ECORE_RDMA_PROTOCOL_ROCE:
2153 if (p_hwfn->mcp_info->func_info.protocol == ECORE_PCI_ETH_RDMA)
2154 p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
2156 case ECORE_RDMA_PROTOCOL_IWARP:
2157 if (p_hwfn->mcp_info->func_info.protocol == ECORE_PCI_ETH_RDMA)
2158 p_hwfn->hw_info.personality = ECORE_PCI_ETH_IWARP;
2162 switch (p_hwfn->hw_info.personality) {
2163 case ECORE_PCI_ETH_IWARP:
2164 /* Each QP requires one connection */
2165 num_cons = OSAL_MIN_T(u32, IWARP_MAX_QPS, p_params->num_qps);
2166 #ifdef CONFIG_ECORE_IWARP /* required for the define */
2167 /* additional connections required for passive tcp handling */
2168 num_cons += ECORE_IWARP_PREALLOC_CNT;
2170 proto = PROTOCOLID_IWARP;
2171 p_params->roce_edpm_mode = false;
2173 case ECORE_PCI_ETH_ROCE:
2174 num_qps = OSAL_MIN_T(u32, ROCE_MAX_QPS, p_params->num_qps);
2175 num_cons = num_qps * 2; /* each QP requires two connections */
2176 proto = PROTOCOLID_ROCE;
2182 if (num_cons && num_tasks) {
2183 ecore_cxt_set_proto_cid_count(p_hwfn, proto,
2186 /* Deliberatly passing ROCE for tasks id. This is because
2187 * iWARP / RoCE share the task id.
2189 ecore_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_ROCE,
2190 ECORE_CXT_ROCE_TID_SEG,
2191 1, /* RoCE segment type */
2193 false); /* !force load */
2194 ecore_cxt_set_srq_count(p_hwfn, num_srqs);
2197 DP_INFO(p_hwfn->p_dev,
2198 "RDMA personality used without setting params!\n");
2202 enum _ecore_status_t ecore_cxt_set_pf_params(struct ecore_hwfn *p_hwfn,
2205 /* Set the number of required CORE connections */
2206 u32 core_cids = 1; /* SPQ */
2208 if (p_hwfn->using_ll2)
2209 core_cids += 4; /* @@@TBD Use the proper #define */
2211 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_CORE, core_cids, 0);
2213 switch (p_hwfn->hw_info.personality) {
2214 case ECORE_PCI_ETH_RDMA:
2215 case ECORE_PCI_ETH_IWARP:
2216 case ECORE_PCI_ETH_ROCE:
2218 ecore_rdma_set_pf_params(p_hwfn,
2219 &p_hwfn->pf_params.rdma_pf_params,
2222 /* no need for break since RoCE coexist with Ethernet */
2226 struct ecore_eth_pf_params *p_params =
2227 &p_hwfn->pf_params.eth_pf_params;
2229 if (!p_params->num_vf_cons)
2230 p_params->num_vf_cons = ETH_PF_PARAMS_VF_CONS_DEFAULT;
2231 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
2233 p_params->num_vf_cons);
2234 p_hwfn->p_cxt_mngr->arfs_count = p_params->num_arfs_filters;
2238 case ECORE_PCI_FCOE:
2240 struct ecore_fcoe_pf_params *p_params;
2242 p_params = &p_hwfn->pf_params.fcoe_pf_params;
2244 if (p_params->num_cons && p_params->num_tasks) {
2245 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_FCOE,
2246 p_params->num_cons, 0);
2248 ecore_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_FCOE,
2249 ECORE_CXT_FCOE_TID_SEG,
2250 0, /* segment type */
2251 p_params->num_tasks,
2254 DP_INFO(p_hwfn->p_dev,
2255 "Fcoe personality used without setting params!\n");
2259 case ECORE_PCI_ISCSI:
2261 struct ecore_iscsi_pf_params *p_params;
2263 p_params = &p_hwfn->pf_params.iscsi_pf_params;
2265 if (p_params->num_cons && p_params->num_tasks) {
2266 ecore_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_ISCSI,
2267 p_params->num_cons, 0);
2269 ecore_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_ISCSI,
2270 ECORE_CXT_ISCSI_TID_SEG,
2271 0, /* segment type */
2272 p_params->num_tasks,
2275 DP_INFO(p_hwfn->p_dev,
2276 "Iscsi personality used without setting params!\n");
2284 return ECORE_SUCCESS;
2287 enum _ecore_status_t ecore_cxt_get_tid_mem_info(struct ecore_hwfn *p_hwfn,
2288 struct ecore_tid_mem *p_info)
2290 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
2291 u32 proto, seg, total_lines, i, shadow_line;
2292 struct ecore_ilt_client_cfg *p_cli;
2293 struct ecore_ilt_cli_blk *p_fl_seg;
2294 struct ecore_tid_seg *p_seg_info;
2296 /* Verify the personality */
2297 switch (p_hwfn->hw_info.personality) {
2298 case ECORE_PCI_FCOE:
2299 proto = PROTOCOLID_FCOE;
2300 seg = ECORE_CXT_FCOE_TID_SEG;
2302 case ECORE_PCI_ISCSI:
2303 proto = PROTOCOLID_ISCSI;
2304 seg = ECORE_CXT_ISCSI_TID_SEG;
2310 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
2311 if (!p_cli->active) {
2315 p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg];
2316 if (!p_seg_info->has_fl_mem)
2319 p_fl_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)];
2320 total_lines = DIV_ROUND_UP(p_fl_seg->total_size,
2321 p_fl_seg->real_size_in_page);
2323 for (i = 0; i < total_lines; i++) {
2324 shadow_line = i + p_fl_seg->start_line -
2325 p_hwfn->p_cxt_mngr->pf_start_line;
2326 p_info->blocks[i] = p_mngr->ilt_shadow[shadow_line].p_virt;
2328 p_info->waste = ILT_PAGE_IN_BYTES(p_cli->p_size.val) -
2329 p_fl_seg->real_size_in_page;
2330 p_info->tid_size = p_mngr->task_type_size[p_seg_info->type];
2331 p_info->num_tids_per_block = p_fl_seg->real_size_in_page /
2334 return ECORE_SUCCESS;
2337 /* This function is very RoCE oriented, if another protocol in the future
2338 * will want this feature we'll need to modify the function to be more generic
2340 enum _ecore_status_t
2341 ecore_cxt_dynamic_ilt_alloc(struct ecore_hwfn *p_hwfn,
2342 enum ecore_cxt_elem_type elem_type,
2345 u32 reg_offset, shadow_line, elem_size, hw_p_size, elems_per_p, line;
2346 struct ecore_ilt_client_cfg *p_cli;
2347 struct ecore_ilt_cli_blk *p_blk;
2348 struct ecore_ptt *p_ptt;
2352 enum _ecore_status_t rc = ECORE_SUCCESS;
2354 switch (elem_type) {
2355 case ECORE_ELEM_CXT:
2356 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
2357 elem_size = CONN_CXT_SIZE(p_hwfn);
2358 p_blk = &p_cli->pf_blks[CDUC_BLK];
2360 case ECORE_ELEM_SRQ:
2361 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
2362 elem_size = SRQ_CXT_SIZE;
2363 p_blk = &p_cli->pf_blks[SRQ_BLK];
2365 case ECORE_ELEM_TASK:
2366 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
2367 elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
2368 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(ECORE_CXT_ROCE_TID_SEG)];
2371 DP_NOTICE(p_hwfn, false,
2372 "ECORE_INVALID elem type = %d", elem_type);
2376 /* Calculate line in ilt */
2377 hw_p_size = p_cli->p_size.val;
2378 elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
2379 line = p_blk->start_line + (iid / elems_per_p);
2380 shadow_line = line - p_hwfn->p_cxt_mngr->pf_start_line;
2382 /* If line is already allocated, do nothing, otherwise allocate it and
2383 * write it to the PSWRQ2 registers.
2384 * This section can be run in parallel from different contexts and thus
2385 * a mutex protection is needed.
2388 OSAL_MUTEX_ACQUIRE(&p_hwfn->p_cxt_mngr->mutex);
2390 if (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt)
2393 p_ptt = ecore_ptt_acquire(p_hwfn);
2395 DP_NOTICE(p_hwfn, false,
2396 "ECORE_TIME_OUT on ptt acquire - dynamic allocation");
2401 p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
2403 p_blk->real_size_in_page);
2408 OSAL_MEM_ZERO(p_virt, p_blk->real_size_in_page);
2410 /* configuration of refTagMask to 0xF is required for RoCE DIF MR only,
2411 * to compensate for a HW bug, but it is configured even if DIF is not
2412 * enabled. This is harmless and allows us to avoid a dedicated API. We
2413 * configure the field for all of the contexts on the newly allocated
2416 if (elem_type == ECORE_ELEM_TASK) {
2418 u8 *elem_start = (u8 *)p_virt;
2419 union type1_task_context *elem;
2421 for (elem_i = 0; elem_i < elems_per_p; elem_i++) {
2422 elem = (union type1_task_context *)elem_start;
2423 SET_FIELD(elem->roce_ctx.tdif_context.flags1,
2424 TDIF_TASK_CONTEXT_REFTAGMASK , 0xf);
2425 elem_start += TYPE1_TASK_CXT_SIZE(p_hwfn);
2429 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt = p_virt;
2430 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys = p_phys;
2431 p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].size =
2432 p_blk->real_size_in_page;
2434 /* compute absolute offset */
2435 reg_offset = PSWRQ2_REG_ILT_MEMORY +
2436 (line * ILT_REG_SIZE_IN_BYTES * ILT_ENTRY_IN_REGS);
2439 SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
2440 SET_FIELD(ilt_hw_entry,
2442 (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys >> 12));
2444 /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a wide-bus */
2445 ecore_dmae_host2grc(p_hwfn, p_ptt, (u64)(osal_uintptr_t)&ilt_hw_entry,
2446 reg_offset, sizeof(ilt_hw_entry) / sizeof(u32),
2449 if (elem_type == ECORE_ELEM_CXT) {
2450 u32 last_cid_allocated = (1 + (iid / elems_per_p)) *
2453 /* Update the relevant register in the parser */
2454 ecore_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF,
2455 last_cid_allocated - 1);
2457 /* RoCE w/a -> we don't write to the prs search reg until first
2458 * cid is allocated. This is because the prs checks
2459 * last_cid-1 >=0 making 0 a valid value... this will cause
2460 * the a context load to occur on a RoCE packet received with
2461 * cid=0 even before context was initialized, can happen with a
2462 * stray packet from switch or a packet with crc-error
2465 if (!p_hwfn->b_rdma_enabled_in_prs) {
2466 /* Enable Rdma search */
2467 ecore_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
2468 p_hwfn->b_rdma_enabled_in_prs = true;
2473 ecore_ptt_release(p_hwfn, p_ptt);
2475 OSAL_MUTEX_RELEASE(&p_hwfn->p_cxt_mngr->mutex);
2480 /* This function is very RoCE oriented, if another protocol in the future
2481 * will want this feature we'll need to modify the function to be more generic
2483 enum _ecore_status_t
2484 ecore_cxt_free_ilt_range(struct ecore_hwfn *p_hwfn,
2485 enum ecore_cxt_elem_type elem_type,
2486 u32 start_iid, u32 count)
2488 u32 start_line, end_line, shadow_start_line, shadow_end_line;
2489 u32 reg_offset, elem_size, hw_p_size, elems_per_p;
2490 struct ecore_ilt_client_cfg *p_cli;
2491 struct ecore_ilt_cli_blk *p_blk;
2492 u32 end_iid = start_iid + count;
2493 struct ecore_ptt *p_ptt;
2494 u64 ilt_hw_entry = 0;
2497 switch (elem_type) {
2498 case ECORE_ELEM_CXT:
2499 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
2500 elem_size = CONN_CXT_SIZE(p_hwfn);
2501 p_blk = &p_cli->pf_blks[CDUC_BLK];
2503 case ECORE_ELEM_SRQ:
2504 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
2505 elem_size = SRQ_CXT_SIZE;
2506 p_blk = &p_cli->pf_blks[SRQ_BLK];
2508 case ECORE_ELEM_TASK:
2509 p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
2510 elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
2511 p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(ECORE_CXT_ROCE_TID_SEG)];
2514 DP_NOTICE(p_hwfn, false,
2515 "ECORE_INVALID elem type = %d", elem_type);
2519 /* Calculate line in ilt */
2520 hw_p_size = p_cli->p_size.val;
2521 elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
2522 start_line = p_blk->start_line + (start_iid / elems_per_p);
2523 end_line = p_blk->start_line + (end_iid / elems_per_p);
2524 if (((end_iid + 1) / elems_per_p) != (end_iid / elems_per_p))
2527 shadow_start_line = start_line - p_hwfn->p_cxt_mngr->pf_start_line;
2528 shadow_end_line = end_line - p_hwfn->p_cxt_mngr->pf_start_line;
2530 p_ptt = ecore_ptt_acquire(p_hwfn);
2532 DP_NOTICE(p_hwfn, false, "ECORE_TIME_OUT on ptt acquire - dynamic allocation");
2533 return ECORE_TIMEOUT;
2536 for (i = shadow_start_line; i < shadow_end_line; i++) {
2537 if (!p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt)
2540 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
2541 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt,
2542 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys,
2543 p_hwfn->p_cxt_mngr->ilt_shadow[i].size);
2545 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt = OSAL_NULL;
2546 p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys = 0;
2547 p_hwfn->p_cxt_mngr->ilt_shadow[i].size = 0;
2549 /* compute absolute offset */
2550 reg_offset = PSWRQ2_REG_ILT_MEMORY +
2551 ((start_line++) * ILT_REG_SIZE_IN_BYTES *
2554 /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a
2557 ecore_dmae_host2grc(p_hwfn, p_ptt,
2558 (u64)(osal_uintptr_t)&ilt_hw_entry,
2560 sizeof(ilt_hw_entry) / sizeof(u32),
2564 ecore_ptt_release(p_hwfn, p_ptt);
2566 return ECORE_SUCCESS;
2569 enum _ecore_status_t ecore_cxt_get_task_ctx(struct ecore_hwfn *p_hwfn,
2574 struct ecore_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
2575 struct ecore_ilt_client_cfg *p_cli;
2576 struct ecore_tid_seg *p_seg_info;
2577 struct ecore_ilt_cli_blk *p_seg;
2578 u32 num_tids_per_block;
2579 u32 tid_size, ilt_idx;
2583 /* Verify the personality */
2584 switch (p_hwfn->hw_info.personality) {
2585 case ECORE_PCI_FCOE:
2586 proto = PROTOCOLID_FCOE;
2587 seg = ECORE_CXT_FCOE_TID_SEG;
2589 case ECORE_PCI_ISCSI:
2590 proto = PROTOCOLID_ISCSI;
2591 seg = ECORE_CXT_ISCSI_TID_SEG;
2597 p_cli = &p_mngr->clients[ILT_CLI_CDUT];
2598 if (!p_cli->active) {
2602 p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg];
2604 if (ctx_type == ECORE_CTX_WORKING_MEM) {
2605 p_seg = &p_cli->pf_blks[CDUT_SEG_BLK(seg)];
2606 } else if (ctx_type == ECORE_CTX_FL_MEM) {
2607 if (!p_seg_info->has_fl_mem) {
2610 p_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)];
2614 total_lines = DIV_ROUND_UP(p_seg->total_size,
2615 p_seg->real_size_in_page);
2616 tid_size = p_mngr->task_type_size[p_seg_info->type];
2617 num_tids_per_block = p_seg->real_size_in_page / tid_size;
2619 if (total_lines < tid/num_tids_per_block)
2622 ilt_idx = tid / num_tids_per_block + p_seg->start_line -
2623 p_mngr->pf_start_line;
2624 *pp_task_ctx = (u8 *)p_mngr->ilt_shadow[ilt_idx].p_virt +
2625 (tid % num_tids_per_block) * tid_size;
2627 return ECORE_SUCCESS;