1fe56b9e6SYuval Mintz /* QLogic qed NIC Driver 2e8f1cb50SMintz, Yuval * Copyright (c) 2015-2017 QLogic Corporation 3fe56b9e6SYuval Mintz * 4e8f1cb50SMintz, Yuval * This software is available to you under a choice of one of two 5e8f1cb50SMintz, Yuval * licenses. You may choose to be licensed under the terms of the GNU 6e8f1cb50SMintz, Yuval * General Public License (GPL) Version 2, available from the file 7e8f1cb50SMintz, Yuval * COPYING in the main directory of this source tree, or the 8e8f1cb50SMintz, Yuval * OpenIB.org BSD license below: 9e8f1cb50SMintz, Yuval * 10e8f1cb50SMintz, Yuval * Redistribution and use in source and binary forms, with or 11e8f1cb50SMintz, Yuval * without modification, are permitted provided that the following 12e8f1cb50SMintz, Yuval * conditions are met: 13e8f1cb50SMintz, Yuval * 14e8f1cb50SMintz, Yuval * - Redistributions of source code must retain the above 15e8f1cb50SMintz, Yuval * copyright notice, this list of conditions and the following 16e8f1cb50SMintz, Yuval * disclaimer. 17e8f1cb50SMintz, Yuval * 18e8f1cb50SMintz, Yuval * - Redistributions in binary form must reproduce the above 19e8f1cb50SMintz, Yuval * copyright notice, this list of conditions and the following 20e8f1cb50SMintz, Yuval * disclaimer in the documentation and /or other materials 21e8f1cb50SMintz, Yuval * provided with the distribution. 22e8f1cb50SMintz, Yuval * 23e8f1cb50SMintz, Yuval * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24e8f1cb50SMintz, Yuval * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25e8f1cb50SMintz, Yuval * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26e8f1cb50SMintz, Yuval * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27e8f1cb50SMintz, Yuval * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28e8f1cb50SMintz, Yuval * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29e8f1cb50SMintz, Yuval * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30e8f1cb50SMintz, Yuval * SOFTWARE. 31fe56b9e6SYuval Mintz */ 32fe56b9e6SYuval Mintz 33fe56b9e6SYuval Mintz #include <linux/types.h> 34fe56b9e6SYuval Mintz #include <linux/bitops.h> 35fe56b9e6SYuval Mintz #include <linux/dma-mapping.h> 36fe56b9e6SYuval Mintz #include <linux/errno.h> 37fe56b9e6SYuval Mintz #include <linux/kernel.h> 38fe56b9e6SYuval Mintz #include <linux/list.h> 39fe56b9e6SYuval Mintz #include <linux/log2.h> 40fe56b9e6SYuval Mintz #include <linux/pci.h> 41fe56b9e6SYuval Mintz #include <linux/slab.h> 42fe56b9e6SYuval Mintz #include <linux/string.h> 43fe56b9e6SYuval Mintz #include <linux/bitops.h> 44fe56b9e6SYuval Mintz #include "qed.h" 45fe56b9e6SYuval Mintz #include "qed_cxt.h" 46fe56b9e6SYuval Mintz #include "qed_dev_api.h" 47fe56b9e6SYuval Mintz #include "qed_hsi.h" 48fe56b9e6SYuval Mintz #include "qed_hw.h" 49fe56b9e6SYuval Mintz #include "qed_init_ops.h" 50fe56b9e6SYuval Mintz #include "qed_reg_addr.h" 511408cc1fSYuval Mintz #include "qed_sriov.h" 52fe56b9e6SYuval Mintz 53fe56b9e6SYuval Mintz /* Max number of connection types in HW (DQ/CDU etc.) */ 54fe56b9e6SYuval Mintz #define MAX_CONN_TYPES PROTOCOLID_COMMON 55fe56b9e6SYuval Mintz #define NUM_TASK_TYPES 2 56fe56b9e6SYuval Mintz #define NUM_TASK_PF_SEGMENTS 4 571408cc1fSYuval Mintz #define NUM_TASK_VF_SEGMENTS 1 58fe56b9e6SYuval Mintz 59fe56b9e6SYuval Mintz /* QM constants */ 60fe56b9e6SYuval Mintz #define QM_PQ_ELEMENT_SIZE 4 /* in bytes */ 61fe56b9e6SYuval Mintz 62fe56b9e6SYuval Mintz /* Doorbell-Queue constants */ 63fe56b9e6SYuval Mintz #define DQ_RANGE_SHIFT 4 64fe56b9e6SYuval Mintz #define DQ_RANGE_ALIGN BIT(DQ_RANGE_SHIFT) 65fe56b9e6SYuval Mintz 66dbb799c3SYuval Mintz /* Searcher constants */ 67dbb799c3SYuval Mintz #define SRC_MIN_NUM_ELEMS 256 68dbb799c3SYuval Mintz 69dbb799c3SYuval Mintz /* Timers constants */ 70dbb799c3SYuval Mintz #define TM_SHIFT 7 71dbb799c3SYuval Mintz #define TM_ALIGN BIT(TM_SHIFT) 72dbb799c3SYuval Mintz #define TM_ELEM_SIZE 4 73dbb799c3SYuval Mintz 74be086e7cSMintz, Yuval #define ILT_DEFAULT_HW_P_SIZE 4 7551ff1725SRam Amrani 76fe56b9e6SYuval Mintz #define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12)) 77fe56b9e6SYuval Mintz #define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET 78fe56b9e6SYuval Mintz 79fe56b9e6SYuval Mintz /* ILT entry structure */ 80fe56b9e6SYuval Mintz #define ILT_ENTRY_PHY_ADDR_MASK 0x000FFFFFFFFFFFULL 81fe56b9e6SYuval Mintz #define ILT_ENTRY_PHY_ADDR_SHIFT 0 82fe56b9e6SYuval Mintz #define ILT_ENTRY_VALID_MASK 0x1ULL 83fe56b9e6SYuval Mintz #define ILT_ENTRY_VALID_SHIFT 52 84fe56b9e6SYuval Mintz #define ILT_ENTRY_IN_REGS 2 85fe56b9e6SYuval Mintz #define ILT_REG_SIZE_IN_BYTES 4 86fe56b9e6SYuval Mintz 87fe56b9e6SYuval Mintz /* connection context union */ 88fe56b9e6SYuval Mintz union conn_context { 89*21dd79e8STomer Tayar struct e4_core_conn_context core_ctx; 90*21dd79e8STomer Tayar struct e4_eth_conn_context eth_ctx; 91*21dd79e8STomer Tayar struct e4_iscsi_conn_context iscsi_ctx; 92*21dd79e8STomer Tayar struct e4_fcoe_conn_context fcoe_ctx; 93*21dd79e8STomer Tayar struct e4_roce_conn_context roce_ctx; 94fe56b9e6SYuval Mintz }; 95fe56b9e6SYuval Mintz 961e128c81SArun Easi /* TYPE-0 task context - iSCSI, FCOE */ 97dbb799c3SYuval Mintz union type0_task_context { 98*21dd79e8STomer Tayar struct e4_iscsi_task_context iscsi_ctx; 99*21dd79e8STomer Tayar struct e4_fcoe_task_context fcoe_ctx; 100dbb799c3SYuval Mintz }; 101dbb799c3SYuval Mintz 102dbb799c3SYuval Mintz /* TYPE-1 task context - ROCE */ 103dbb799c3SYuval Mintz union type1_task_context { 104*21dd79e8STomer Tayar struct e4_rdma_task_context roce_ctx; 105dbb799c3SYuval Mintz }; 106dbb799c3SYuval Mintz 107dbb799c3SYuval Mintz struct src_ent { 108dbb799c3SYuval Mintz u8 opaque[56]; 109dbb799c3SYuval Mintz u64 next; 110dbb799c3SYuval Mintz }; 111dbb799c3SYuval Mintz 112dbb799c3SYuval Mintz #define CDUT_SEG_ALIGNMET 3 /* in 4k chunks */ 113a2e7699eSTomer Tayar #define CDUT_SEG_ALIGNMET_IN_BYTES BIT(CDUT_SEG_ALIGNMET + 12) 114dbb799c3SYuval Mintz 115fe56b9e6SYuval Mintz #define CONN_CXT_SIZE(p_hwfn) \ 116fe56b9e6SYuval Mintz ALIGNED_TYPE_SIZE(union conn_context, p_hwfn) 117fe56b9e6SYuval Mintz 118dbb799c3SYuval Mintz #define SRQ_CXT_SIZE (sizeof(struct rdma_srq_context)) 119dbb799c3SYuval Mintz 120dbb799c3SYuval Mintz #define TYPE0_TASK_CXT_SIZE(p_hwfn) \ 121dbb799c3SYuval Mintz ALIGNED_TYPE_SIZE(union type0_task_context, p_hwfn) 122dbb799c3SYuval Mintz 123dbb799c3SYuval Mintz /* Alignment is inherent to the type1_task_context structure */ 124dbb799c3SYuval Mintz #define TYPE1_TASK_CXT_SIZE(p_hwfn) sizeof(union type1_task_context) 125dbb799c3SYuval Mintz 126fe56b9e6SYuval Mintz /* PF per protocl configuration object */ 127dbb799c3SYuval Mintz #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS) 128dbb799c3SYuval Mintz #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS) 129dbb799c3SYuval Mintz 130dbb799c3SYuval Mintz struct qed_tid_seg { 131dbb799c3SYuval Mintz u32 count; 132dbb799c3SYuval Mintz u8 type; 133dbb799c3SYuval Mintz bool has_fl_mem; 134dbb799c3SYuval Mintz }; 135dbb799c3SYuval Mintz 136fe56b9e6SYuval Mintz struct qed_conn_type_cfg { 137fe56b9e6SYuval Mintz u32 cid_count; 1381408cc1fSYuval Mintz u32 cids_per_vf; 139dbb799c3SYuval Mintz struct qed_tid_seg tid_seg[TASK_SEGMENTS]; 140fe56b9e6SYuval Mintz }; 141fe56b9e6SYuval Mintz 142fe56b9e6SYuval Mintz /* ILT Client configuration, Per connection type (protocol) resources. */ 143fe56b9e6SYuval Mintz #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2) 1441408cc1fSYuval Mintz #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2) 145fe56b9e6SYuval Mintz #define CDUC_BLK (0) 146dbb799c3SYuval Mintz #define SRQ_BLK (0) 147dbb799c3SYuval Mintz #define CDUT_SEG_BLK(n) (1 + (u8)(n)) 148dbb799c3SYuval Mintz #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_ ## X ## _SEGMENTS) 149fe56b9e6SYuval Mintz 150fe56b9e6SYuval Mintz enum ilt_clients { 151fe56b9e6SYuval Mintz ILT_CLI_CDUC, 152dbb799c3SYuval Mintz ILT_CLI_CDUT, 153fe56b9e6SYuval Mintz ILT_CLI_QM, 154dbb799c3SYuval Mintz ILT_CLI_TM, 155dbb799c3SYuval Mintz ILT_CLI_SRC, 156dbb799c3SYuval Mintz ILT_CLI_TSDM, 157fe56b9e6SYuval Mintz ILT_CLI_MAX 158fe56b9e6SYuval Mintz }; 159fe56b9e6SYuval Mintz 160fe56b9e6SYuval Mintz struct ilt_cfg_pair { 161fe56b9e6SYuval Mintz u32 reg; 162fe56b9e6SYuval Mintz u32 val; 163fe56b9e6SYuval Mintz }; 164fe56b9e6SYuval Mintz 165fe56b9e6SYuval Mintz struct qed_ilt_cli_blk { 166fe56b9e6SYuval Mintz u32 total_size; /* 0 means not active */ 167fe56b9e6SYuval Mintz u32 real_size_in_page; 168fe56b9e6SYuval Mintz u32 start_line; 169dbb799c3SYuval Mintz u32 dynamic_line_cnt; 170fe56b9e6SYuval Mintz }; 171fe56b9e6SYuval Mintz 172fe56b9e6SYuval Mintz struct qed_ilt_client_cfg { 173fe56b9e6SYuval Mintz bool active; 174fe56b9e6SYuval Mintz 175fe56b9e6SYuval Mintz /* ILT boundaries */ 176fe56b9e6SYuval Mintz struct ilt_cfg_pair first; 177fe56b9e6SYuval Mintz struct ilt_cfg_pair last; 178fe56b9e6SYuval Mintz struct ilt_cfg_pair p_size; 179fe56b9e6SYuval Mintz 180fe56b9e6SYuval Mintz /* ILT client blocks for PF */ 181fe56b9e6SYuval Mintz struct qed_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS]; 182fe56b9e6SYuval Mintz u32 pf_total_lines; 1831408cc1fSYuval Mintz 1841408cc1fSYuval Mintz /* ILT client blocks for VFs */ 1851408cc1fSYuval Mintz struct qed_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS]; 1861408cc1fSYuval Mintz u32 vf_total_lines; 187fe56b9e6SYuval Mintz }; 188fe56b9e6SYuval Mintz 189fe56b9e6SYuval Mintz /* Per Path - 190fe56b9e6SYuval Mintz * ILT shadow table 191fe56b9e6SYuval Mintz * Protocol acquired CID lists 192fe56b9e6SYuval Mintz * PF start line in ILT 193fe56b9e6SYuval Mintz */ 194fe56b9e6SYuval Mintz struct qed_dma_mem { 195fe56b9e6SYuval Mintz dma_addr_t p_phys; 196fe56b9e6SYuval Mintz void *p_virt; 197fe56b9e6SYuval Mintz size_t size; 198fe56b9e6SYuval Mintz }; 199fe56b9e6SYuval Mintz 200fe56b9e6SYuval Mintz struct qed_cid_acquired_map { 201fe56b9e6SYuval Mintz u32 start_cid; 202fe56b9e6SYuval Mintz u32 max_count; 203fe56b9e6SYuval Mintz unsigned long *cid_map; 204fe56b9e6SYuval Mintz }; 205fe56b9e6SYuval Mintz 206fe56b9e6SYuval Mintz struct qed_cxt_mngr { 207fe56b9e6SYuval Mintz /* Per protocl configuration */ 208fe56b9e6SYuval Mintz struct qed_conn_type_cfg conn_cfg[MAX_CONN_TYPES]; 209fe56b9e6SYuval Mintz 210fe56b9e6SYuval Mintz /* computed ILT structure */ 211fe56b9e6SYuval Mintz struct qed_ilt_client_cfg clients[ILT_CLI_MAX]; 212fe56b9e6SYuval Mintz 213dbb799c3SYuval Mintz /* Task type sizes */ 214dbb799c3SYuval Mintz u32 task_type_size[NUM_TASK_TYPES]; 215dbb799c3SYuval Mintz 2161408cc1fSYuval Mintz /* total number of VFs for this hwfn - 2171408cc1fSYuval Mintz * ALL VFs are symmetric in terms of HW resources 2181408cc1fSYuval Mintz */ 2191408cc1fSYuval Mintz u32 vf_count; 2201408cc1fSYuval Mintz 221fe56b9e6SYuval Mintz /* Acquired CIDs */ 222fe56b9e6SYuval Mintz struct qed_cid_acquired_map acquired[MAX_CONN_TYPES]; 223fe56b9e6SYuval Mintz 2246bea61daSMintz, Yuval struct qed_cid_acquired_map 2256bea61daSMintz, Yuval acquired_vf[MAX_CONN_TYPES][MAX_NUM_VFS]; 2266bea61daSMintz, Yuval 227fe56b9e6SYuval Mintz /* ILT shadow table */ 228fe56b9e6SYuval Mintz struct qed_dma_mem *ilt_shadow; 229fe56b9e6SYuval Mintz u32 pf_start_line; 230dbb799c3SYuval Mintz 231dbb799c3SYuval Mintz /* Mutex for a dynamic ILT allocation */ 232dbb799c3SYuval Mintz struct mutex mutex; 233dbb799c3SYuval Mintz 234dbb799c3SYuval Mintz /* SRC T2 */ 235dbb799c3SYuval Mintz struct qed_dma_mem *t2; 236dbb799c3SYuval Mintz u32 t2_num_pages; 237dbb799c3SYuval Mintz u64 first_free; 238dbb799c3SYuval Mintz u64 last_free; 239d51e4af5SChopra, Manish 240d51e4af5SChopra, Manish /* total number of SRQ's for this hwfn */ 241d51e4af5SChopra, Manish u32 srq_count; 242d51e4af5SChopra, Manish 243d51e4af5SChopra, Manish /* Maximal number of L2 steering filters */ 244d51e4af5SChopra, Manish u32 arfs_count; 245fe56b9e6SYuval Mintz }; 246dbb799c3SYuval Mintz static bool src_proto(enum protocol_type type) 247dbb799c3SYuval Mintz { 248dbb799c3SYuval Mintz return type == PROTOCOLID_ISCSI || 2495d7dc962SKalderon, Michal type == PROTOCOLID_FCOE || 2505d7dc962SKalderon, Michal type == PROTOCOLID_IWARP; 251dbb799c3SYuval Mintz } 252dbb799c3SYuval Mintz 253dbb799c3SYuval Mintz static bool tm_cid_proto(enum protocol_type type) 254dbb799c3SYuval Mintz { 255dbb799c3SYuval Mintz return type == PROTOCOLID_ISCSI || 2561e128c81SArun Easi type == PROTOCOLID_FCOE || 2575d7dc962SKalderon, Michal type == PROTOCOLID_ROCE || 2585d7dc962SKalderon, Michal type == PROTOCOLID_IWARP; 259dbb799c3SYuval Mintz } 260fe56b9e6SYuval Mintz 2611e128c81SArun Easi static bool tm_tid_proto(enum protocol_type type) 2621e128c81SArun Easi { 2631e128c81SArun Easi return type == PROTOCOLID_FCOE; 2641e128c81SArun Easi } 2651e128c81SArun Easi 2661408cc1fSYuval Mintz /* counts the iids for the CDU/CDUC ILT client configuration */ 2671408cc1fSYuval Mintz struct qed_cdu_iids { 2681408cc1fSYuval Mintz u32 pf_cids; 2691408cc1fSYuval Mintz u32 per_vf_cids; 2701408cc1fSYuval Mintz }; 2711408cc1fSYuval Mintz 2721408cc1fSYuval Mintz static void qed_cxt_cdu_iids(struct qed_cxt_mngr *p_mngr, 2731408cc1fSYuval Mintz struct qed_cdu_iids *iids) 274fe56b9e6SYuval Mintz { 2751408cc1fSYuval Mintz u32 type; 276fe56b9e6SYuval Mintz 2771408cc1fSYuval Mintz for (type = 0; type < MAX_CONN_TYPES; type++) { 2781408cc1fSYuval Mintz iids->pf_cids += p_mngr->conn_cfg[type].cid_count; 2791408cc1fSYuval Mintz iids->per_vf_cids += p_mngr->conn_cfg[type].cids_per_vf; 2801408cc1fSYuval Mintz } 281fe56b9e6SYuval Mintz } 282fe56b9e6SYuval Mintz 283dbb799c3SYuval Mintz /* counts the iids for the Searcher block configuration */ 284dbb799c3SYuval Mintz struct qed_src_iids { 285dbb799c3SYuval Mintz u32 pf_cids; 286dbb799c3SYuval Mintz u32 per_vf_cids; 287dbb799c3SYuval Mintz }; 288dbb799c3SYuval Mintz 289dbb799c3SYuval Mintz static void qed_cxt_src_iids(struct qed_cxt_mngr *p_mngr, 290dbb799c3SYuval Mintz struct qed_src_iids *iids) 291dbb799c3SYuval Mintz { 292dbb799c3SYuval Mintz u32 i; 293dbb799c3SYuval Mintz 294dbb799c3SYuval Mintz for (i = 0; i < MAX_CONN_TYPES; i++) { 295dbb799c3SYuval Mintz if (!src_proto(i)) 296dbb799c3SYuval Mintz continue; 297dbb799c3SYuval Mintz 298dbb799c3SYuval Mintz iids->pf_cids += p_mngr->conn_cfg[i].cid_count; 299dbb799c3SYuval Mintz iids->per_vf_cids += p_mngr->conn_cfg[i].cids_per_vf; 300dbb799c3SYuval Mintz } 301d51e4af5SChopra, Manish 302d51e4af5SChopra, Manish /* Add L2 filtering filters in addition */ 303d51e4af5SChopra, Manish iids->pf_cids += p_mngr->arfs_count; 304dbb799c3SYuval Mintz } 305dbb799c3SYuval Mintz 306dbb799c3SYuval Mintz /* counts the iids for the Timers block configuration */ 307dbb799c3SYuval Mintz struct qed_tm_iids { 308dbb799c3SYuval Mintz u32 pf_cids; 309dbb799c3SYuval Mintz u32 pf_tids[NUM_TASK_PF_SEGMENTS]; /* per segment */ 310dbb799c3SYuval Mintz u32 pf_tids_total; 311dbb799c3SYuval Mintz u32 per_vf_cids; 312dbb799c3SYuval Mintz u32 per_vf_tids; 313dbb799c3SYuval Mintz }; 314dbb799c3SYuval Mintz 31544531ba4SMichal Kalderon static void qed_cxt_tm_iids(struct qed_hwfn *p_hwfn, 31644531ba4SMichal Kalderon struct qed_cxt_mngr *p_mngr, 317dbb799c3SYuval Mintz struct qed_tm_iids *iids) 318dbb799c3SYuval Mintz { 31944531ba4SMichal Kalderon bool tm_vf_required = false; 32044531ba4SMichal Kalderon bool tm_required = false; 32144531ba4SMichal Kalderon int i, j; 322dbb799c3SYuval Mintz 32344531ba4SMichal Kalderon /* Timers is a special case -> we don't count how many cids require 32444531ba4SMichal Kalderon * timers but what's the max cid that will be used by the timer block. 32544531ba4SMichal Kalderon * therefore we traverse in reverse order, and once we hit a protocol 32644531ba4SMichal Kalderon * that requires the timers memory, we'll sum all the protocols up 32744531ba4SMichal Kalderon * to that one. 32844531ba4SMichal Kalderon */ 32944531ba4SMichal Kalderon for (i = MAX_CONN_TYPES - 1; i >= 0; i--) { 330dbb799c3SYuval Mintz struct qed_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[i]; 331dbb799c3SYuval Mintz 33244531ba4SMichal Kalderon if (tm_cid_proto(i) || tm_required) { 33344531ba4SMichal Kalderon if (p_cfg->cid_count) 33444531ba4SMichal Kalderon tm_required = true; 33544531ba4SMichal Kalderon 336dbb799c3SYuval Mintz iids->pf_cids += p_cfg->cid_count; 33744531ba4SMichal Kalderon } 33844531ba4SMichal Kalderon 33944531ba4SMichal Kalderon if (tm_cid_proto(i) || tm_vf_required) { 34044531ba4SMichal Kalderon if (p_cfg->cids_per_vf) 34144531ba4SMichal Kalderon tm_vf_required = true; 34244531ba4SMichal Kalderon 343dbb799c3SYuval Mintz iids->per_vf_cids += p_cfg->cids_per_vf; 344dbb799c3SYuval Mintz } 3451e128c81SArun Easi 3461e128c81SArun Easi if (tm_tid_proto(i)) { 3471e128c81SArun Easi struct qed_tid_seg *segs = p_cfg->tid_seg; 3481e128c81SArun Easi 3491e128c81SArun Easi /* for each segment there is at most one 3501e128c81SArun Easi * protocol for which count is not 0. 3511e128c81SArun Easi */ 3521e128c81SArun Easi for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++) 3531e128c81SArun Easi iids->pf_tids[j] += segs[j].count; 3541e128c81SArun Easi 3551e128c81SArun Easi /* The last array elelment is for the VFs. As for PF 3561e128c81SArun Easi * segments there can be only one protocol for 3571e128c81SArun Easi * which this value is not 0. 3581e128c81SArun Easi */ 3591e128c81SArun Easi iids->per_vf_tids += segs[NUM_TASK_PF_SEGMENTS].count; 3601e128c81SArun Easi } 361dbb799c3SYuval Mintz } 362dbb799c3SYuval Mintz 363dbb799c3SYuval Mintz iids->pf_cids = roundup(iids->pf_cids, TM_ALIGN); 364dbb799c3SYuval Mintz iids->per_vf_cids = roundup(iids->per_vf_cids, TM_ALIGN); 365dbb799c3SYuval Mintz iids->per_vf_tids = roundup(iids->per_vf_tids, TM_ALIGN); 366dbb799c3SYuval Mintz 367dbb799c3SYuval Mintz for (iids->pf_tids_total = 0, j = 0; j < NUM_TASK_PF_SEGMENTS; j++) { 368dbb799c3SYuval Mintz iids->pf_tids[j] = roundup(iids->pf_tids[j], TM_ALIGN); 369dbb799c3SYuval Mintz iids->pf_tids_total += iids->pf_tids[j]; 370dbb799c3SYuval Mintz } 371dbb799c3SYuval Mintz } 372dbb799c3SYuval Mintz 373fe56b9e6SYuval Mintz static void qed_cxt_qm_iids(struct qed_hwfn *p_hwfn, 374fe56b9e6SYuval Mintz struct qed_qm_iids *iids) 375fe56b9e6SYuval Mintz { 376fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 377dbb799c3SYuval Mintz struct qed_tid_seg *segs; 378dbb799c3SYuval Mintz u32 vf_cids = 0, type, j; 379dbb799c3SYuval Mintz u32 vf_tids = 0; 380fe56b9e6SYuval Mintz 3811408cc1fSYuval Mintz for (type = 0; type < MAX_CONN_TYPES; type++) { 382fe56b9e6SYuval Mintz iids->cids += p_mngr->conn_cfg[type].cid_count; 3831408cc1fSYuval Mintz vf_cids += p_mngr->conn_cfg[type].cids_per_vf; 384dbb799c3SYuval Mintz 385dbb799c3SYuval Mintz segs = p_mngr->conn_cfg[type].tid_seg; 386dbb799c3SYuval Mintz /* for each segment there is at most one 387dbb799c3SYuval Mintz * protocol for which count is not 0. 388dbb799c3SYuval Mintz */ 389dbb799c3SYuval Mintz for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++) 390dbb799c3SYuval Mintz iids->tids += segs[j].count; 391dbb799c3SYuval Mintz 392dbb799c3SYuval Mintz /* The last array elelment is for the VFs. As for PF 393dbb799c3SYuval Mintz * segments there can be only one protocol for 394dbb799c3SYuval Mintz * which this value is not 0. 395dbb799c3SYuval Mintz */ 396dbb799c3SYuval Mintz vf_tids += segs[NUM_TASK_PF_SEGMENTS].count; 3971408cc1fSYuval Mintz } 398fe56b9e6SYuval Mintz 3991408cc1fSYuval Mintz iids->vf_cids += vf_cids * p_mngr->vf_count; 400dbb799c3SYuval Mintz iids->tids += vf_tids * p_mngr->vf_count; 401dbb799c3SYuval Mintz 4021408cc1fSYuval Mintz DP_VERBOSE(p_hwfn, QED_MSG_ILT, 403dbb799c3SYuval Mintz "iids: CIDS %08x vf_cids %08x tids %08x vf_tids %08x\n", 404dbb799c3SYuval Mintz iids->cids, iids->vf_cids, iids->tids, vf_tids); 405dbb799c3SYuval Mintz } 406dbb799c3SYuval Mintz 407dbb799c3SYuval Mintz static struct qed_tid_seg *qed_cxt_tid_seg_info(struct qed_hwfn *p_hwfn, 408dbb799c3SYuval Mintz u32 seg) 409dbb799c3SYuval Mintz { 410dbb799c3SYuval Mintz struct qed_cxt_mngr *p_cfg = p_hwfn->p_cxt_mngr; 411dbb799c3SYuval Mintz u32 i; 412dbb799c3SYuval Mintz 413dbb799c3SYuval Mintz /* Find the protocol with tid count > 0 for this segment. 414dbb799c3SYuval Mintz * Note: there can only be one and this is already validated. 415dbb799c3SYuval Mintz */ 416dbb799c3SYuval Mintz for (i = 0; i < MAX_CONN_TYPES; i++) 417dbb799c3SYuval Mintz if (p_cfg->conn_cfg[i].tid_seg[seg].count) 418dbb799c3SYuval Mintz return &p_cfg->conn_cfg[i].tid_seg[seg]; 419dbb799c3SYuval Mintz return NULL; 420dbb799c3SYuval Mintz } 421dbb799c3SYuval Mintz 4228c93beafSYuval Mintz static void qed_cxt_set_srq_count(struct qed_hwfn *p_hwfn, u32 num_srqs) 423dbb799c3SYuval Mintz { 424dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; 425dbb799c3SYuval Mintz 426dbb799c3SYuval Mintz p_mgr->srq_count = num_srqs; 427dbb799c3SYuval Mintz } 428dbb799c3SYuval Mintz 4298c93beafSYuval Mintz static u32 qed_cxt_get_srq_count(struct qed_hwfn *p_hwfn) 430dbb799c3SYuval Mintz { 431dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; 432dbb799c3SYuval Mintz 433dbb799c3SYuval Mintz return p_mgr->srq_count; 434fe56b9e6SYuval Mintz } 435fe56b9e6SYuval Mintz 436fe56b9e6SYuval Mintz /* set the iids count per protocol */ 437fe56b9e6SYuval Mintz static void qed_cxt_set_proto_cid_count(struct qed_hwfn *p_hwfn, 438fe56b9e6SYuval Mintz enum protocol_type type, 4391408cc1fSYuval Mintz u32 cid_count, u32 vf_cid_cnt) 440fe56b9e6SYuval Mintz { 441fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; 442fe56b9e6SYuval Mintz struct qed_conn_type_cfg *p_conn = &p_mgr->conn_cfg[type]; 443fe56b9e6SYuval Mintz 444fe56b9e6SYuval Mintz p_conn->cid_count = roundup(cid_count, DQ_RANGE_ALIGN); 4451408cc1fSYuval Mintz p_conn->cids_per_vf = roundup(vf_cid_cnt, DQ_RANGE_ALIGN); 446dbb799c3SYuval Mintz 447dbb799c3SYuval Mintz if (type == PROTOCOLID_ROCE) { 448dbb799c3SYuval Mintz u32 page_sz = p_mgr->clients[ILT_CLI_CDUC].p_size.val; 449dbb799c3SYuval Mintz u32 cxt_size = CONN_CXT_SIZE(p_hwfn); 450dbb799c3SYuval Mintz u32 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; 451f3e48119SRam Amrani u32 align = elems_per_page * DQ_RANGE_ALIGN; 452dbb799c3SYuval Mintz 453f3e48119SRam Amrani p_conn->cid_count = roundup(p_conn->cid_count, align); 454dbb799c3SYuval Mintz } 4551408cc1fSYuval Mintz } 4561408cc1fSYuval Mintz 4571408cc1fSYuval Mintz u32 qed_cxt_get_proto_cid_count(struct qed_hwfn *p_hwfn, 4581a635e48SYuval Mintz enum protocol_type type, u32 *vf_cid) 4591408cc1fSYuval Mintz { 4601408cc1fSYuval Mintz if (vf_cid) 4611408cc1fSYuval Mintz *vf_cid = p_hwfn->p_cxt_mngr->conn_cfg[type].cids_per_vf; 4621408cc1fSYuval Mintz 4631408cc1fSYuval Mintz return p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count; 464fe56b9e6SYuval Mintz } 465fe56b9e6SYuval Mintz 466dbb799c3SYuval Mintz u32 qed_cxt_get_proto_cid_start(struct qed_hwfn *p_hwfn, 467dbb799c3SYuval Mintz enum protocol_type type) 468dbb799c3SYuval Mintz { 469dbb799c3SYuval Mintz return p_hwfn->p_cxt_mngr->acquired[type].start_cid; 470dbb799c3SYuval Mintz } 471dbb799c3SYuval Mintz 472dbb799c3SYuval Mintz u32 qed_cxt_get_proto_tid_count(struct qed_hwfn *p_hwfn, 473dbb799c3SYuval Mintz enum protocol_type type) 474dbb799c3SYuval Mintz { 475dbb799c3SYuval Mintz u32 cnt = 0; 476dbb799c3SYuval Mintz int i; 477dbb799c3SYuval Mintz 478dbb799c3SYuval Mintz for (i = 0; i < TASK_SEGMENTS; i++) 479dbb799c3SYuval Mintz cnt += p_hwfn->p_cxt_mngr->conn_cfg[type].tid_seg[i].count; 480dbb799c3SYuval Mintz 481dbb799c3SYuval Mintz return cnt; 482dbb799c3SYuval Mintz } 483dbb799c3SYuval Mintz 4841a635e48SYuval Mintz static void qed_cxt_set_proto_tid_count(struct qed_hwfn *p_hwfn, 485dbb799c3SYuval Mintz enum protocol_type proto, 4861a635e48SYuval Mintz u8 seg, 4871a635e48SYuval Mintz u8 seg_type, u32 count, bool has_fl) 488dbb799c3SYuval Mintz { 489dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 490dbb799c3SYuval Mintz struct qed_tid_seg *p_seg = &p_mngr->conn_cfg[proto].tid_seg[seg]; 491dbb799c3SYuval Mintz 492dbb799c3SYuval Mintz p_seg->count = count; 493dbb799c3SYuval Mintz p_seg->has_fl_mem = has_fl; 494dbb799c3SYuval Mintz p_seg->type = seg_type; 495dbb799c3SYuval Mintz } 496dbb799c3SYuval Mintz 497fe56b9e6SYuval Mintz static void qed_ilt_cli_blk_fill(struct qed_ilt_client_cfg *p_cli, 498fe56b9e6SYuval Mintz struct qed_ilt_cli_blk *p_blk, 4991a635e48SYuval Mintz u32 start_line, u32 total_size, u32 elem_size) 500fe56b9e6SYuval Mintz { 501fe56b9e6SYuval Mintz u32 ilt_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val); 502fe56b9e6SYuval Mintz 503fe56b9e6SYuval Mintz /* verify thatits called only once for each block */ 504fe56b9e6SYuval Mintz if (p_blk->total_size) 505fe56b9e6SYuval Mintz return; 506fe56b9e6SYuval Mintz 507fe56b9e6SYuval Mintz p_blk->total_size = total_size; 508fe56b9e6SYuval Mintz p_blk->real_size_in_page = 0; 509fe56b9e6SYuval Mintz if (elem_size) 510fe56b9e6SYuval Mintz p_blk->real_size_in_page = (ilt_size / elem_size) * elem_size; 511fe56b9e6SYuval Mintz p_blk->start_line = start_line; 512fe56b9e6SYuval Mintz } 513fe56b9e6SYuval Mintz 514fe56b9e6SYuval Mintz static void qed_ilt_cli_adv_line(struct qed_hwfn *p_hwfn, 515fe56b9e6SYuval Mintz struct qed_ilt_client_cfg *p_cli, 516fe56b9e6SYuval Mintz struct qed_ilt_cli_blk *p_blk, 517fe56b9e6SYuval Mintz u32 *p_line, enum ilt_clients client_id) 518fe56b9e6SYuval Mintz { 519fe56b9e6SYuval Mintz if (!p_blk->total_size) 520fe56b9e6SYuval Mintz return; 521fe56b9e6SYuval Mintz 522fe56b9e6SYuval Mintz if (!p_cli->active) 523fe56b9e6SYuval Mintz p_cli->first.val = *p_line; 524fe56b9e6SYuval Mintz 525fe56b9e6SYuval Mintz p_cli->active = true; 5261a635e48SYuval Mintz *p_line += DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page); 527fe56b9e6SYuval Mintz p_cli->last.val = *p_line - 1; 528fe56b9e6SYuval Mintz 529fe56b9e6SYuval Mintz DP_VERBOSE(p_hwfn, QED_MSG_ILT, 530fe56b9e6SYuval Mintz "ILT[Client %d] - Lines: [%08x - %08x]. Block - Size %08x [Real %08x] Start line %d\n", 531fe56b9e6SYuval Mintz client_id, p_cli->first.val, 532fe56b9e6SYuval Mintz p_cli->last.val, p_blk->total_size, 533fe56b9e6SYuval Mintz p_blk->real_size_in_page, p_blk->start_line); 534fe56b9e6SYuval Mintz } 535fe56b9e6SYuval Mintz 536dbb799c3SYuval Mintz static u32 qed_ilt_get_dynamic_line_cnt(struct qed_hwfn *p_hwfn, 537dbb799c3SYuval Mintz enum ilt_clients ilt_client) 538dbb799c3SYuval Mintz { 539dbb799c3SYuval Mintz u32 cid_count = p_hwfn->p_cxt_mngr->conn_cfg[PROTOCOLID_ROCE].cid_count; 540dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_cli; 541dbb799c3SYuval Mintz u32 lines_to_skip = 0; 542dbb799c3SYuval Mintz u32 cxts_per_p; 543dbb799c3SYuval Mintz 544dbb799c3SYuval Mintz if (ilt_client == ILT_CLI_CDUC) { 545dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; 546dbb799c3SYuval Mintz 547dbb799c3SYuval Mintz cxts_per_p = ILT_PAGE_IN_BYTES(p_cli->p_size.val) / 548dbb799c3SYuval Mintz (u32) CONN_CXT_SIZE(p_hwfn); 549dbb799c3SYuval Mintz 550dbb799c3SYuval Mintz lines_to_skip = cid_count / cxts_per_p; 551dbb799c3SYuval Mintz } 552dbb799c3SYuval Mintz 553dbb799c3SYuval Mintz return lines_to_skip; 554dbb799c3SYuval Mintz } 555dbb799c3SYuval Mintz 556f9dc4d1fSRam Amrani static struct qed_ilt_client_cfg *qed_cxt_set_cli(struct qed_ilt_client_cfg 557f9dc4d1fSRam Amrani *p_cli) 558f9dc4d1fSRam Amrani { 559f9dc4d1fSRam Amrani p_cli->active = false; 560f9dc4d1fSRam Amrani p_cli->first.val = 0; 561f9dc4d1fSRam Amrani p_cli->last.val = 0; 562f9dc4d1fSRam Amrani return p_cli; 563f9dc4d1fSRam Amrani } 564f9dc4d1fSRam Amrani 565f9dc4d1fSRam Amrani static struct qed_ilt_cli_blk *qed_cxt_set_blk(struct qed_ilt_cli_blk *p_blk) 566f9dc4d1fSRam Amrani { 567f9dc4d1fSRam Amrani p_blk->total_size = 0; 568f9dc4d1fSRam Amrani return p_blk; 569f9dc4d1fSRam Amrani } 570f9dc4d1fSRam Amrani 571f9dc4d1fSRam Amrani int qed_cxt_cfg_ilt_compute(struct qed_hwfn *p_hwfn, u32 *line_count) 572fe56b9e6SYuval Mintz { 573fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 574dbb799c3SYuval Mintz u32 curr_line, total, i, task_size, line; 575fe56b9e6SYuval Mintz struct qed_ilt_client_cfg *p_cli; 576fe56b9e6SYuval Mintz struct qed_ilt_cli_blk *p_blk; 5771408cc1fSYuval Mintz struct qed_cdu_iids cdu_iids; 578dbb799c3SYuval Mintz struct qed_src_iids src_iids; 579fe56b9e6SYuval Mintz struct qed_qm_iids qm_iids; 580dbb799c3SYuval Mintz struct qed_tm_iids tm_iids; 581dbb799c3SYuval Mintz struct qed_tid_seg *p_seg; 582fe56b9e6SYuval Mintz 583fe56b9e6SYuval Mintz memset(&qm_iids, 0, sizeof(qm_iids)); 5841408cc1fSYuval Mintz memset(&cdu_iids, 0, sizeof(cdu_iids)); 585dbb799c3SYuval Mintz memset(&src_iids, 0, sizeof(src_iids)); 586dbb799c3SYuval Mintz memset(&tm_iids, 0, sizeof(tm_iids)); 587fe56b9e6SYuval Mintz 588fe56b9e6SYuval Mintz p_mngr->pf_start_line = RESC_START(p_hwfn, QED_ILT); 589fe56b9e6SYuval Mintz 590fe56b9e6SYuval Mintz DP_VERBOSE(p_hwfn, QED_MSG_ILT, 591fe56b9e6SYuval Mintz "hwfn [%d] - Set context manager starting line to be 0x%08x\n", 592fe56b9e6SYuval Mintz p_hwfn->my_id, p_hwfn->p_cxt_mngr->pf_start_line); 593fe56b9e6SYuval Mintz 594fe56b9e6SYuval Mintz /* CDUC */ 595f9dc4d1fSRam Amrani p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUC]); 596f9dc4d1fSRam Amrani 597fe56b9e6SYuval Mintz curr_line = p_mngr->pf_start_line; 5981408cc1fSYuval Mintz 5991408cc1fSYuval Mintz /* CDUC PF */ 600fe56b9e6SYuval Mintz p_cli->pf_total_lines = 0; 601fe56b9e6SYuval Mintz 602fe56b9e6SYuval Mintz /* get the counters for the CDUC and QM clients */ 6031408cc1fSYuval Mintz qed_cxt_cdu_iids(p_mngr, &cdu_iids); 604fe56b9e6SYuval Mintz 605f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->pf_blks[CDUC_BLK]); 606fe56b9e6SYuval Mintz 6071408cc1fSYuval Mintz total = cdu_iids.pf_cids * CONN_CXT_SIZE(p_hwfn); 608fe56b9e6SYuval Mintz 609fe56b9e6SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, 610fe56b9e6SYuval Mintz total, CONN_CXT_SIZE(p_hwfn)); 611fe56b9e6SYuval Mintz 612fe56b9e6SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC); 613fe56b9e6SYuval Mintz p_cli->pf_total_lines = curr_line - p_blk->start_line; 614fe56b9e6SYuval Mintz 615dbb799c3SYuval Mintz p_blk->dynamic_line_cnt = qed_ilt_get_dynamic_line_cnt(p_hwfn, 616dbb799c3SYuval Mintz ILT_CLI_CDUC); 617dbb799c3SYuval Mintz 6181408cc1fSYuval Mintz /* CDUC VF */ 619f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->vf_blks[CDUC_BLK]); 6201408cc1fSYuval Mintz total = cdu_iids.per_vf_cids * CONN_CXT_SIZE(p_hwfn); 6211408cc1fSYuval Mintz 6221408cc1fSYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, 6231408cc1fSYuval Mintz total, CONN_CXT_SIZE(p_hwfn)); 6241408cc1fSYuval Mintz 6251408cc1fSYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC); 6261408cc1fSYuval Mintz p_cli->vf_total_lines = curr_line - p_blk->start_line; 6271408cc1fSYuval Mintz 6281408cc1fSYuval Mintz for (i = 1; i < p_mngr->vf_count; i++) 6291408cc1fSYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 6301408cc1fSYuval Mintz ILT_CLI_CDUC); 6311408cc1fSYuval Mintz 632dbb799c3SYuval Mintz /* CDUT PF */ 633f9dc4d1fSRam Amrani p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUT]); 634dbb799c3SYuval Mintz p_cli->first.val = curr_line; 635dbb799c3SYuval Mintz 636dbb799c3SYuval Mintz /* first the 'working' task memory */ 637dbb799c3SYuval Mintz for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { 638dbb799c3SYuval Mintz p_seg = qed_cxt_tid_seg_info(p_hwfn, i); 639dbb799c3SYuval Mintz if (!p_seg || p_seg->count == 0) 640dbb799c3SYuval Mintz continue; 641dbb799c3SYuval Mintz 642f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->pf_blks[CDUT_SEG_BLK(i)]); 643dbb799c3SYuval Mintz total = p_seg->count * p_mngr->task_type_size[p_seg->type]; 644dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total, 645dbb799c3SYuval Mintz p_mngr->task_type_size[p_seg->type]); 646dbb799c3SYuval Mintz 647dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 648dbb799c3SYuval Mintz ILT_CLI_CDUT); 649dbb799c3SYuval Mintz } 650dbb799c3SYuval Mintz 651dbb799c3SYuval Mintz /* next the 'init' task memory (forced load memory) */ 652dbb799c3SYuval Mintz for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { 653dbb799c3SYuval Mintz p_seg = qed_cxt_tid_seg_info(p_hwfn, i); 654dbb799c3SYuval Mintz if (!p_seg || p_seg->count == 0) 655dbb799c3SYuval Mintz continue; 656dbb799c3SYuval Mintz 657f9dc4d1fSRam Amrani p_blk = 658f9dc4d1fSRam Amrani qed_cxt_set_blk(&p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)]); 659dbb799c3SYuval Mintz 660dbb799c3SYuval Mintz if (!p_seg->has_fl_mem) { 661dbb799c3SYuval Mintz /* The segment is active (total size pf 'working' 662dbb799c3SYuval Mintz * memory is > 0) but has no FL (forced-load, Init) 663dbb799c3SYuval Mintz * memory. Thus: 664dbb799c3SYuval Mintz * 665dbb799c3SYuval Mintz * 1. The total-size in the corrsponding FL block of 666dbb799c3SYuval Mintz * the ILT client is set to 0 - No ILT line are 667dbb799c3SYuval Mintz * provisioned and no ILT memory allocated. 668dbb799c3SYuval Mintz * 669dbb799c3SYuval Mintz * 2. The start-line of said block is set to the 670dbb799c3SYuval Mintz * start line of the matching working memory 671dbb799c3SYuval Mintz * block in the ILT client. This is later used to 672dbb799c3SYuval Mintz * configure the CDU segment offset registers and 673dbb799c3SYuval Mintz * results in an FL command for TIDs of this 674dbb799c3SYuval Mintz * segement behaves as regular load commands 675dbb799c3SYuval Mintz * (loading TIDs from the working memory). 676dbb799c3SYuval Mintz */ 677dbb799c3SYuval Mintz line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line; 678dbb799c3SYuval Mintz 679dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0); 680dbb799c3SYuval Mintz continue; 681dbb799c3SYuval Mintz } 682dbb799c3SYuval Mintz total = p_seg->count * p_mngr->task_type_size[p_seg->type]; 683dbb799c3SYuval Mintz 684dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, 685dbb799c3SYuval Mintz curr_line, total, 686dbb799c3SYuval Mintz p_mngr->task_type_size[p_seg->type]); 687dbb799c3SYuval Mintz 688dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 689dbb799c3SYuval Mintz ILT_CLI_CDUT); 690dbb799c3SYuval Mintz } 691dbb799c3SYuval Mintz p_cli->pf_total_lines = curr_line - p_cli->pf_blks[0].start_line; 692dbb799c3SYuval Mintz 693dbb799c3SYuval Mintz /* CDUT VF */ 694dbb799c3SYuval Mintz p_seg = qed_cxt_tid_seg_info(p_hwfn, TASK_SEGMENT_VF); 695dbb799c3SYuval Mintz if (p_seg && p_seg->count) { 696dbb799c3SYuval Mintz /* Stricly speaking we need to iterate over all VF 697dbb799c3SYuval Mintz * task segment types, but a VF has only 1 segment 698dbb799c3SYuval Mintz */ 699dbb799c3SYuval Mintz 700dbb799c3SYuval Mintz /* 'working' memory */ 701dbb799c3SYuval Mintz total = p_seg->count * p_mngr->task_type_size[p_seg->type]; 702dbb799c3SYuval Mintz 703f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->vf_blks[CDUT_SEG_BLK(0)]); 704dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, 705dbb799c3SYuval Mintz curr_line, total, 706dbb799c3SYuval Mintz p_mngr->task_type_size[p_seg->type]); 707dbb799c3SYuval Mintz 708dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 709dbb799c3SYuval Mintz ILT_CLI_CDUT); 710dbb799c3SYuval Mintz 711dbb799c3SYuval Mintz /* 'init' memory */ 712f9dc4d1fSRam Amrani p_blk = 713f9dc4d1fSRam Amrani qed_cxt_set_blk(&p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)]); 714dbb799c3SYuval Mintz if (!p_seg->has_fl_mem) { 715dbb799c3SYuval Mintz /* see comment above */ 716dbb799c3SYuval Mintz line = p_cli->vf_blks[CDUT_SEG_BLK(0)].start_line; 717dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0); 718dbb799c3SYuval Mintz } else { 719dbb799c3SYuval Mintz task_size = p_mngr->task_type_size[p_seg->type]; 720dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, 721dbb799c3SYuval Mintz curr_line, total, task_size); 722dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 723dbb799c3SYuval Mintz ILT_CLI_CDUT); 724dbb799c3SYuval Mintz } 725dbb799c3SYuval Mintz p_cli->vf_total_lines = curr_line - 726dbb799c3SYuval Mintz p_cli->vf_blks[0].start_line; 727dbb799c3SYuval Mintz 728dbb799c3SYuval Mintz /* Now for the rest of the VFs */ 729dbb799c3SYuval Mintz for (i = 1; i < p_mngr->vf_count; i++) { 730dbb799c3SYuval Mintz p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)]; 731dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 732dbb799c3SYuval Mintz ILT_CLI_CDUT); 733dbb799c3SYuval Mintz 734dbb799c3SYuval Mintz p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)]; 735dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 736dbb799c3SYuval Mintz ILT_CLI_CDUT); 737dbb799c3SYuval Mintz } 738dbb799c3SYuval Mintz } 739dbb799c3SYuval Mintz 740fe56b9e6SYuval Mintz /* QM */ 741f9dc4d1fSRam Amrani p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_QM]); 742f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]); 743fe56b9e6SYuval Mintz 744fe56b9e6SYuval Mintz qed_cxt_qm_iids(p_hwfn, &qm_iids); 7451408cc1fSYuval Mintz total = qed_qm_pf_mem_size(p_hwfn->rel_pf_id, qm_iids.cids, 746dbb799c3SYuval Mintz qm_iids.vf_cids, qm_iids.tids, 7471408cc1fSYuval Mintz p_hwfn->qm_info.num_pqs, 7481408cc1fSYuval Mintz p_hwfn->qm_info.num_vf_pqs); 749fe56b9e6SYuval Mintz 7501408cc1fSYuval Mintz DP_VERBOSE(p_hwfn, 7511408cc1fSYuval Mintz QED_MSG_ILT, 752dbb799c3SYuval Mintz "QM ILT Info, (cids=%d, vf_cids=%d, tids=%d, num_pqs=%d, num_vf_pqs=%d, memory_size=%d)\n", 7531408cc1fSYuval Mintz qm_iids.cids, 7541408cc1fSYuval Mintz qm_iids.vf_cids, 755dbb799c3SYuval Mintz qm_iids.tids, 7561408cc1fSYuval Mintz p_hwfn->qm_info.num_pqs, p_hwfn->qm_info.num_vf_pqs, total); 757fe56b9e6SYuval Mintz 758fe56b9e6SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, 759fe56b9e6SYuval Mintz curr_line, total * 0x1000, 760fe56b9e6SYuval Mintz QM_PQ_ELEMENT_SIZE); 761fe56b9e6SYuval Mintz 762fe56b9e6SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_QM); 763fe56b9e6SYuval Mintz p_cli->pf_total_lines = curr_line - p_blk->start_line; 764fe56b9e6SYuval Mintz 765dbb799c3SYuval Mintz /* SRC */ 766f9dc4d1fSRam Amrani p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_SRC]); 767dbb799c3SYuval Mintz qed_cxt_src_iids(p_mngr, &src_iids); 768dbb799c3SYuval Mintz 769dbb799c3SYuval Mintz /* Both the PF and VFs searcher connections are stored in the per PF 770dbb799c3SYuval Mintz * database. Thus sum the PF searcher cids and all the VFs searcher 771dbb799c3SYuval Mintz * cids. 772dbb799c3SYuval Mintz */ 773dbb799c3SYuval Mintz total = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count; 774dbb799c3SYuval Mintz if (total) { 775dbb799c3SYuval Mintz u32 local_max = max_t(u32, total, 776dbb799c3SYuval Mintz SRC_MIN_NUM_ELEMS); 777dbb799c3SYuval Mintz 778dbb799c3SYuval Mintz total = roundup_pow_of_two(local_max); 779dbb799c3SYuval Mintz 780f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]); 781dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, 782dbb799c3SYuval Mintz total * sizeof(struct src_ent), 783dbb799c3SYuval Mintz sizeof(struct src_ent)); 784dbb799c3SYuval Mintz 785dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 786dbb799c3SYuval Mintz ILT_CLI_SRC); 787dbb799c3SYuval Mintz p_cli->pf_total_lines = curr_line - p_blk->start_line; 788dbb799c3SYuval Mintz } 789dbb799c3SYuval Mintz 790dbb799c3SYuval Mintz /* TM PF */ 791f9dc4d1fSRam Amrani p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_TM]); 79244531ba4SMichal Kalderon qed_cxt_tm_iids(p_hwfn, p_mngr, &tm_iids); 793dbb799c3SYuval Mintz total = tm_iids.pf_cids + tm_iids.pf_tids_total; 794dbb799c3SYuval Mintz if (total) { 795f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]); 796dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, 797dbb799c3SYuval Mintz total * TM_ELEM_SIZE, TM_ELEM_SIZE); 798dbb799c3SYuval Mintz 799dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 800dbb799c3SYuval Mintz ILT_CLI_TM); 801dbb799c3SYuval Mintz p_cli->pf_total_lines = curr_line - p_blk->start_line; 802dbb799c3SYuval Mintz } 803dbb799c3SYuval Mintz 804dbb799c3SYuval Mintz /* TM VF */ 805dbb799c3SYuval Mintz total = tm_iids.per_vf_cids + tm_iids.per_vf_tids; 806dbb799c3SYuval Mintz if (total) { 807f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->vf_blks[0]); 808dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, 809dbb799c3SYuval Mintz total * TM_ELEM_SIZE, TM_ELEM_SIZE); 810dbb799c3SYuval Mintz 811dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 812dbb799c3SYuval Mintz ILT_CLI_TM); 813dbb799c3SYuval Mintz 81470566b42SMintz, Yuval p_cli->vf_total_lines = curr_line - p_blk->start_line; 815dbb799c3SYuval Mintz for (i = 1; i < p_mngr->vf_count; i++) 816dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 817dbb799c3SYuval Mintz ILT_CLI_TM); 818dbb799c3SYuval Mintz } 819dbb799c3SYuval Mintz 820dbb799c3SYuval Mintz /* TSDM (SRQ CONTEXT) */ 821dbb799c3SYuval Mintz total = qed_cxt_get_srq_count(p_hwfn); 822dbb799c3SYuval Mintz 823dbb799c3SYuval Mintz if (total) { 824f9dc4d1fSRam Amrani p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_TSDM]); 825f9dc4d1fSRam Amrani p_blk = qed_cxt_set_blk(&p_cli->pf_blks[SRQ_BLK]); 826dbb799c3SYuval Mintz qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, 827dbb799c3SYuval Mintz total * SRQ_CXT_SIZE, SRQ_CXT_SIZE); 828dbb799c3SYuval Mintz 829dbb799c3SYuval Mintz qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, 830dbb799c3SYuval Mintz ILT_CLI_TSDM); 831dbb799c3SYuval Mintz p_cli->pf_total_lines = curr_line - p_blk->start_line; 832dbb799c3SYuval Mintz } 833dbb799c3SYuval Mintz 834f9dc4d1fSRam Amrani *line_count = curr_line - p_hwfn->p_cxt_mngr->pf_start_line; 835f9dc4d1fSRam Amrani 836fe56b9e6SYuval Mintz if (curr_line - p_hwfn->p_cxt_mngr->pf_start_line > 837f9dc4d1fSRam Amrani RESC_NUM(p_hwfn, QED_ILT)) 838fe56b9e6SYuval Mintz return -EINVAL; 839f9dc4d1fSRam Amrani 840f9dc4d1fSRam Amrani return 0; 841fe56b9e6SYuval Mintz } 842fe56b9e6SYuval Mintz 843f9dc4d1fSRam Amrani u32 qed_cxt_cfg_ilt_compute_excess(struct qed_hwfn *p_hwfn, u32 used_lines) 844f9dc4d1fSRam Amrani { 845f9dc4d1fSRam Amrani struct qed_ilt_client_cfg *p_cli; 846f9dc4d1fSRam Amrani u32 excess_lines, available_lines; 847f9dc4d1fSRam Amrani struct qed_cxt_mngr *p_mngr; 848f9dc4d1fSRam Amrani u32 ilt_page_size, elem_size; 849f9dc4d1fSRam Amrani struct qed_tid_seg *p_seg; 850f9dc4d1fSRam Amrani int i; 851f9dc4d1fSRam Amrani 852f9dc4d1fSRam Amrani available_lines = RESC_NUM(p_hwfn, QED_ILT); 853f9dc4d1fSRam Amrani excess_lines = used_lines - available_lines; 854f9dc4d1fSRam Amrani 855f9dc4d1fSRam Amrani if (!excess_lines) 856f9dc4d1fSRam Amrani return 0; 857f9dc4d1fSRam Amrani 858c851a9dcSKalderon, Michal if (!QED_IS_RDMA_PERSONALITY(p_hwfn)) 859f9dc4d1fSRam Amrani return 0; 860f9dc4d1fSRam Amrani 861f9dc4d1fSRam Amrani p_mngr = p_hwfn->p_cxt_mngr; 862f9dc4d1fSRam Amrani p_cli = &p_mngr->clients[ILT_CLI_CDUT]; 863f9dc4d1fSRam Amrani ilt_page_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val); 864f9dc4d1fSRam Amrani 865f9dc4d1fSRam Amrani for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { 866f9dc4d1fSRam Amrani p_seg = qed_cxt_tid_seg_info(p_hwfn, i); 867f9dc4d1fSRam Amrani if (!p_seg || p_seg->count == 0) 868f9dc4d1fSRam Amrani continue; 869f9dc4d1fSRam Amrani 870f9dc4d1fSRam Amrani elem_size = p_mngr->task_type_size[p_seg->type]; 871f9dc4d1fSRam Amrani if (!elem_size) 872f9dc4d1fSRam Amrani continue; 873f9dc4d1fSRam Amrani 874f9dc4d1fSRam Amrani return (ilt_page_size / elem_size) * excess_lines; 875f9dc4d1fSRam Amrani } 876f9dc4d1fSRam Amrani 877f9dc4d1fSRam Amrani DP_NOTICE(p_hwfn, "failed computing excess ILT lines\n"); 878fe56b9e6SYuval Mintz return 0; 879fe56b9e6SYuval Mintz } 880fe56b9e6SYuval Mintz 881dbb799c3SYuval Mintz static void qed_cxt_src_t2_free(struct qed_hwfn *p_hwfn) 882dbb799c3SYuval Mintz { 883dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 884dbb799c3SYuval Mintz u32 i; 885dbb799c3SYuval Mintz 886dbb799c3SYuval Mintz if (!p_mngr->t2) 887dbb799c3SYuval Mintz return; 888dbb799c3SYuval Mintz 889dbb799c3SYuval Mintz for (i = 0; i < p_mngr->t2_num_pages; i++) 890dbb799c3SYuval Mintz if (p_mngr->t2[i].p_virt) 891dbb799c3SYuval Mintz dma_free_coherent(&p_hwfn->cdev->pdev->dev, 892dbb799c3SYuval Mintz p_mngr->t2[i].size, 893dbb799c3SYuval Mintz p_mngr->t2[i].p_virt, 894dbb799c3SYuval Mintz p_mngr->t2[i].p_phys); 895dbb799c3SYuval Mintz 896dbb799c3SYuval Mintz kfree(p_mngr->t2); 897dbb799c3SYuval Mintz p_mngr->t2 = NULL; 898dbb799c3SYuval Mintz } 899dbb799c3SYuval Mintz 900dbb799c3SYuval Mintz static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn) 901dbb799c3SYuval Mintz { 902dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 903dbb799c3SYuval Mintz u32 conn_num, total_size, ent_per_page, psz, i; 904dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_src; 905dbb799c3SYuval Mintz struct qed_src_iids src_iids; 906dbb799c3SYuval Mintz struct qed_dma_mem *p_t2; 907dbb799c3SYuval Mintz int rc; 908dbb799c3SYuval Mintz 909dbb799c3SYuval Mintz memset(&src_iids, 0, sizeof(src_iids)); 910dbb799c3SYuval Mintz 911dbb799c3SYuval Mintz /* if the SRC ILT client is inactive - there are no connection 912dbb799c3SYuval Mintz * requiring the searcer, leave. 913dbb799c3SYuval Mintz */ 914dbb799c3SYuval Mintz p_src = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_SRC]; 915dbb799c3SYuval Mintz if (!p_src->active) 916dbb799c3SYuval Mintz return 0; 917dbb799c3SYuval Mintz 918dbb799c3SYuval Mintz qed_cxt_src_iids(p_mngr, &src_iids); 919dbb799c3SYuval Mintz conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count; 920dbb799c3SYuval Mintz total_size = conn_num * sizeof(struct src_ent); 921dbb799c3SYuval Mintz 922dbb799c3SYuval Mintz /* use the same page size as the SRC ILT client */ 923dbb799c3SYuval Mintz psz = ILT_PAGE_IN_BYTES(p_src->p_size.val); 924dbb799c3SYuval Mintz p_mngr->t2_num_pages = DIV_ROUND_UP(total_size, psz); 925dbb799c3SYuval Mintz 926dbb799c3SYuval Mintz /* allocate t2 */ 9272591c280SJoe Perches p_mngr->t2 = kcalloc(p_mngr->t2_num_pages, sizeof(struct qed_dma_mem), 928dbb799c3SYuval Mintz GFP_KERNEL); 929dbb799c3SYuval Mintz if (!p_mngr->t2) { 930dbb799c3SYuval Mintz rc = -ENOMEM; 931dbb799c3SYuval Mintz goto t2_fail; 932dbb799c3SYuval Mintz } 933dbb799c3SYuval Mintz 934dbb799c3SYuval Mintz /* allocate t2 pages */ 935dbb799c3SYuval Mintz for (i = 0; i < p_mngr->t2_num_pages; i++) { 936dbb799c3SYuval Mintz u32 size = min_t(u32, total_size, psz); 937dbb799c3SYuval Mintz void **p_virt = &p_mngr->t2[i].p_virt; 938dbb799c3SYuval Mintz 939dbb799c3SYuval Mintz *p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, 940dbb799c3SYuval Mintz size, 941dbb799c3SYuval Mintz &p_mngr->t2[i].p_phys, GFP_KERNEL); 942dbb799c3SYuval Mintz if (!p_mngr->t2[i].p_virt) { 943dbb799c3SYuval Mintz rc = -ENOMEM; 944dbb799c3SYuval Mintz goto t2_fail; 945dbb799c3SYuval Mintz } 946dbb799c3SYuval Mintz memset(*p_virt, 0, size); 947dbb799c3SYuval Mintz p_mngr->t2[i].size = size; 948dbb799c3SYuval Mintz total_size -= size; 949dbb799c3SYuval Mintz } 950dbb799c3SYuval Mintz 951dbb799c3SYuval Mintz /* Set the t2 pointers */ 952dbb799c3SYuval Mintz 953dbb799c3SYuval Mintz /* entries per page - must be a power of two */ 954dbb799c3SYuval Mintz ent_per_page = psz / sizeof(struct src_ent); 955dbb799c3SYuval Mintz 956dbb799c3SYuval Mintz p_mngr->first_free = (u64) p_mngr->t2[0].p_phys; 957dbb799c3SYuval Mintz 958dbb799c3SYuval Mintz p_t2 = &p_mngr->t2[(conn_num - 1) / ent_per_page]; 959dbb799c3SYuval Mintz p_mngr->last_free = (u64) p_t2->p_phys + 960dbb799c3SYuval Mintz ((conn_num - 1) & (ent_per_page - 1)) * sizeof(struct src_ent); 961dbb799c3SYuval Mintz 962dbb799c3SYuval Mintz for (i = 0; i < p_mngr->t2_num_pages; i++) { 963dbb799c3SYuval Mintz u32 ent_num = min_t(u32, 964dbb799c3SYuval Mintz ent_per_page, 965dbb799c3SYuval Mintz conn_num); 966dbb799c3SYuval Mintz struct src_ent *entries = p_mngr->t2[i].p_virt; 967dbb799c3SYuval Mintz u64 p_ent_phys = (u64) p_mngr->t2[i].p_phys, val; 968dbb799c3SYuval Mintz u32 j; 969dbb799c3SYuval Mintz 970dbb799c3SYuval Mintz for (j = 0; j < ent_num - 1; j++) { 971dbb799c3SYuval Mintz val = p_ent_phys + (j + 1) * sizeof(struct src_ent); 972dbb799c3SYuval Mintz entries[j].next = cpu_to_be64(val); 973dbb799c3SYuval Mintz } 974dbb799c3SYuval Mintz 975dbb799c3SYuval Mintz if (i < p_mngr->t2_num_pages - 1) 976dbb799c3SYuval Mintz val = (u64) p_mngr->t2[i + 1].p_phys; 977dbb799c3SYuval Mintz else 978dbb799c3SYuval Mintz val = 0; 979dbb799c3SYuval Mintz entries[j].next = cpu_to_be64(val); 980dbb799c3SYuval Mintz 98101e517f1SDan Carpenter conn_num -= ent_num; 982dbb799c3SYuval Mintz } 983dbb799c3SYuval Mintz 984dbb799c3SYuval Mintz return 0; 985dbb799c3SYuval Mintz 986dbb799c3SYuval Mintz t2_fail: 987dbb799c3SYuval Mintz qed_cxt_src_t2_free(p_hwfn); 988dbb799c3SYuval Mintz return rc; 989dbb799c3SYuval Mintz } 990dbb799c3SYuval Mintz 991fe56b9e6SYuval Mintz #define for_each_ilt_valid_client(pos, clients) \ 992dbb799c3SYuval Mintz for (pos = 0; pos < ILT_CLI_MAX; pos++) \ 993dbb799c3SYuval Mintz if (!clients[pos].active) { \ 994dbb799c3SYuval Mintz continue; \ 995dbb799c3SYuval Mintz } else \ 996fe56b9e6SYuval Mintz 997fe56b9e6SYuval Mintz /* Total number of ILT lines used by this PF */ 998fe56b9e6SYuval Mintz static u32 qed_cxt_ilt_shadow_size(struct qed_ilt_client_cfg *ilt_clients) 999fe56b9e6SYuval Mintz { 1000fe56b9e6SYuval Mintz u32 size = 0; 1001fe56b9e6SYuval Mintz u32 i; 1002fe56b9e6SYuval Mintz 1003dbb799c3SYuval Mintz for_each_ilt_valid_client(i, ilt_clients) 1004dbb799c3SYuval Mintz size += (ilt_clients[i].last.val - ilt_clients[i].first.val + 1); 1005fe56b9e6SYuval Mintz 1006fe56b9e6SYuval Mintz return size; 1007fe56b9e6SYuval Mintz } 1008fe56b9e6SYuval Mintz 1009fe56b9e6SYuval Mintz static void qed_ilt_shadow_free(struct qed_hwfn *p_hwfn) 1010fe56b9e6SYuval Mintz { 1011fe56b9e6SYuval Mintz struct qed_ilt_client_cfg *p_cli = p_hwfn->p_cxt_mngr->clients; 1012fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 1013fe56b9e6SYuval Mintz u32 ilt_size, i; 1014fe56b9e6SYuval Mintz 1015fe56b9e6SYuval Mintz ilt_size = qed_cxt_ilt_shadow_size(p_cli); 1016fe56b9e6SYuval Mintz 1017fe56b9e6SYuval Mintz for (i = 0; p_mngr->ilt_shadow && i < ilt_size; i++) { 1018fe56b9e6SYuval Mintz struct qed_dma_mem *p_dma = &p_mngr->ilt_shadow[i]; 1019fe56b9e6SYuval Mintz 1020fe56b9e6SYuval Mintz if (p_dma->p_virt) 1021fe56b9e6SYuval Mintz dma_free_coherent(&p_hwfn->cdev->pdev->dev, 1022fe56b9e6SYuval Mintz p_dma->size, p_dma->p_virt, 1023fe56b9e6SYuval Mintz p_dma->p_phys); 1024fe56b9e6SYuval Mintz p_dma->p_virt = NULL; 1025fe56b9e6SYuval Mintz } 1026fe56b9e6SYuval Mintz kfree(p_mngr->ilt_shadow); 1027fe56b9e6SYuval Mintz } 1028fe56b9e6SYuval Mintz 1029fe56b9e6SYuval Mintz static int qed_ilt_blk_alloc(struct qed_hwfn *p_hwfn, 1030fe56b9e6SYuval Mintz struct qed_ilt_cli_blk *p_blk, 1031fe56b9e6SYuval Mintz enum ilt_clients ilt_client, 1032fe56b9e6SYuval Mintz u32 start_line_offset) 1033fe56b9e6SYuval Mintz { 1034fe56b9e6SYuval Mintz struct qed_dma_mem *ilt_shadow = p_hwfn->p_cxt_mngr->ilt_shadow; 1035dbb799c3SYuval Mintz u32 lines, line, sz_left, lines_to_skip = 0; 1036dbb799c3SYuval Mintz 1037dbb799c3SYuval Mintz /* Special handling for RoCE that supports dynamic allocation */ 1038c851a9dcSKalderon, Michal if (QED_IS_RDMA_PERSONALITY(p_hwfn) && 1039dbb799c3SYuval Mintz ((ilt_client == ILT_CLI_CDUT) || ilt_client == ILT_CLI_TSDM)) 1040dbb799c3SYuval Mintz return 0; 1041dbb799c3SYuval Mintz 1042dbb799c3SYuval Mintz lines_to_skip = p_blk->dynamic_line_cnt; 1043fe56b9e6SYuval Mintz 1044fe56b9e6SYuval Mintz if (!p_blk->total_size) 1045fe56b9e6SYuval Mintz return 0; 1046fe56b9e6SYuval Mintz 1047fe56b9e6SYuval Mintz sz_left = p_blk->total_size; 1048dbb799c3SYuval Mintz lines = DIV_ROUND_UP(sz_left, p_blk->real_size_in_page) - lines_to_skip; 1049fe56b9e6SYuval Mintz line = p_blk->start_line + start_line_offset - 1050dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->pf_start_line + lines_to_skip; 1051fe56b9e6SYuval Mintz 1052fe56b9e6SYuval Mintz for (; lines; lines--) { 1053fe56b9e6SYuval Mintz dma_addr_t p_phys; 1054fe56b9e6SYuval Mintz void *p_virt; 1055fe56b9e6SYuval Mintz u32 size; 1056fe56b9e6SYuval Mintz 10571a635e48SYuval Mintz size = min_t(u32, sz_left, p_blk->real_size_in_page); 1058fe56b9e6SYuval Mintz p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, 10591a635e48SYuval Mintz size, &p_phys, GFP_KERNEL); 1060fe56b9e6SYuval Mintz if (!p_virt) 1061fe56b9e6SYuval Mintz return -ENOMEM; 1062fe56b9e6SYuval Mintz memset(p_virt, 0, size); 1063fe56b9e6SYuval Mintz 1064fe56b9e6SYuval Mintz ilt_shadow[line].p_phys = p_phys; 1065fe56b9e6SYuval Mintz ilt_shadow[line].p_virt = p_virt; 1066fe56b9e6SYuval Mintz ilt_shadow[line].size = size; 1067fe56b9e6SYuval Mintz 1068fe56b9e6SYuval Mintz DP_VERBOSE(p_hwfn, QED_MSG_ILT, 1069fe56b9e6SYuval Mintz "ILT shadow: Line [%d] Physical 0x%llx Virtual %p Size %d\n", 1070fe56b9e6SYuval Mintz line, (u64)p_phys, p_virt, size); 1071fe56b9e6SYuval Mintz 1072fe56b9e6SYuval Mintz sz_left -= size; 1073fe56b9e6SYuval Mintz line++; 1074fe56b9e6SYuval Mintz } 1075fe56b9e6SYuval Mintz 1076fe56b9e6SYuval Mintz return 0; 1077fe56b9e6SYuval Mintz } 1078fe56b9e6SYuval Mintz 1079fe56b9e6SYuval Mintz static int qed_ilt_shadow_alloc(struct qed_hwfn *p_hwfn) 1080fe56b9e6SYuval Mintz { 1081fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 1082fe56b9e6SYuval Mintz struct qed_ilt_client_cfg *clients = p_mngr->clients; 1083fe56b9e6SYuval Mintz struct qed_ilt_cli_blk *p_blk; 10841408cc1fSYuval Mintz u32 size, i, j, k; 1085fe56b9e6SYuval Mintz int rc; 1086fe56b9e6SYuval Mintz 1087fe56b9e6SYuval Mintz size = qed_cxt_ilt_shadow_size(clients); 1088fe56b9e6SYuval Mintz p_mngr->ilt_shadow = kcalloc(size, sizeof(struct qed_dma_mem), 1089fe56b9e6SYuval Mintz GFP_KERNEL); 1090fe56b9e6SYuval Mintz if (!p_mngr->ilt_shadow) { 1091fe56b9e6SYuval Mintz rc = -ENOMEM; 1092fe56b9e6SYuval Mintz goto ilt_shadow_fail; 1093fe56b9e6SYuval Mintz } 1094fe56b9e6SYuval Mintz 1095fe56b9e6SYuval Mintz DP_VERBOSE(p_hwfn, QED_MSG_ILT, 1096fe56b9e6SYuval Mintz "Allocated 0x%x bytes for ilt shadow\n", 1097fe56b9e6SYuval Mintz (u32)(size * sizeof(struct qed_dma_mem))); 1098fe56b9e6SYuval Mintz 1099fe56b9e6SYuval Mintz for_each_ilt_valid_client(i, clients) { 1100fe56b9e6SYuval Mintz for (j = 0; j < ILT_CLI_PF_BLOCKS; j++) { 1101fe56b9e6SYuval Mintz p_blk = &clients[i].pf_blks[j]; 1102fe56b9e6SYuval Mintz rc = qed_ilt_blk_alloc(p_hwfn, p_blk, i, 0); 11031a635e48SYuval Mintz if (rc) 1104fe56b9e6SYuval Mintz goto ilt_shadow_fail; 1105fe56b9e6SYuval Mintz } 11061408cc1fSYuval Mintz for (k = 0; k < p_mngr->vf_count; k++) { 11071408cc1fSYuval Mintz for (j = 0; j < ILT_CLI_VF_BLOCKS; j++) { 11081408cc1fSYuval Mintz u32 lines = clients[i].vf_total_lines * k; 11091408cc1fSYuval Mintz 11101408cc1fSYuval Mintz p_blk = &clients[i].vf_blks[j]; 11111408cc1fSYuval Mintz rc = qed_ilt_blk_alloc(p_hwfn, p_blk, i, lines); 11121a635e48SYuval Mintz if (rc) 11131408cc1fSYuval Mintz goto ilt_shadow_fail; 11141408cc1fSYuval Mintz } 11151408cc1fSYuval Mintz } 1116fe56b9e6SYuval Mintz } 1117fe56b9e6SYuval Mintz 1118fe56b9e6SYuval Mintz return 0; 1119fe56b9e6SYuval Mintz 1120fe56b9e6SYuval Mintz ilt_shadow_fail: 1121fe56b9e6SYuval Mintz qed_ilt_shadow_free(p_hwfn); 1122fe56b9e6SYuval Mintz return rc; 1123fe56b9e6SYuval Mintz } 1124fe56b9e6SYuval Mintz 1125fe56b9e6SYuval Mintz static void qed_cid_map_free(struct qed_hwfn *p_hwfn) 1126fe56b9e6SYuval Mintz { 1127fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 11286bea61daSMintz, Yuval u32 type, vf; 1129fe56b9e6SYuval Mintz 1130fe56b9e6SYuval Mintz for (type = 0; type < MAX_CONN_TYPES; type++) { 1131fe56b9e6SYuval Mintz kfree(p_mngr->acquired[type].cid_map); 1132fe56b9e6SYuval Mintz p_mngr->acquired[type].max_count = 0; 1133fe56b9e6SYuval Mintz p_mngr->acquired[type].start_cid = 0; 11346bea61daSMintz, Yuval 11356bea61daSMintz, Yuval for (vf = 0; vf < MAX_NUM_VFS; vf++) { 11366bea61daSMintz, Yuval kfree(p_mngr->acquired_vf[type][vf].cid_map); 11376bea61daSMintz, Yuval p_mngr->acquired_vf[type][vf].max_count = 0; 11386bea61daSMintz, Yuval p_mngr->acquired_vf[type][vf].start_cid = 0; 1139fe56b9e6SYuval Mintz } 1140fe56b9e6SYuval Mintz } 11416bea61daSMintz, Yuval } 11426bea61daSMintz, Yuval 11436bea61daSMintz, Yuval static int 11446bea61daSMintz, Yuval qed_cid_map_alloc_single(struct qed_hwfn *p_hwfn, 11456bea61daSMintz, Yuval u32 type, 11466bea61daSMintz, Yuval u32 cid_start, 11476bea61daSMintz, Yuval u32 cid_count, struct qed_cid_acquired_map *p_map) 11486bea61daSMintz, Yuval { 11496bea61daSMintz, Yuval u32 size; 11506bea61daSMintz, Yuval 11516bea61daSMintz, Yuval if (!cid_count) 11526bea61daSMintz, Yuval return 0; 11536bea61daSMintz, Yuval 11546bea61daSMintz, Yuval size = DIV_ROUND_UP(cid_count, 11556bea61daSMintz, Yuval sizeof(unsigned long) * BITS_PER_BYTE) * 11566bea61daSMintz, Yuval sizeof(unsigned long); 11576bea61daSMintz, Yuval p_map->cid_map = kzalloc(size, GFP_KERNEL); 11586bea61daSMintz, Yuval if (!p_map->cid_map) 11596bea61daSMintz, Yuval return -ENOMEM; 11606bea61daSMintz, Yuval 11616bea61daSMintz, Yuval p_map->max_count = cid_count; 11626bea61daSMintz, Yuval p_map->start_cid = cid_start; 11636bea61daSMintz, Yuval 11646bea61daSMintz, Yuval DP_VERBOSE(p_hwfn, QED_MSG_CXT, 11656bea61daSMintz, Yuval "Type %08x start: %08x count %08x\n", 11666bea61daSMintz, Yuval type, p_map->start_cid, p_map->max_count); 11676bea61daSMintz, Yuval 11686bea61daSMintz, Yuval return 0; 11696bea61daSMintz, Yuval } 1170fe56b9e6SYuval Mintz 1171fe56b9e6SYuval Mintz static int qed_cid_map_alloc(struct qed_hwfn *p_hwfn) 1172fe56b9e6SYuval Mintz { 1173fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 11746bea61daSMintz, Yuval u32 start_cid = 0, vf_start_cid = 0; 11756bea61daSMintz, Yuval u32 type, vf; 1176fe56b9e6SYuval Mintz 1177fe56b9e6SYuval Mintz for (type = 0; type < MAX_CONN_TYPES; type++) { 11786bea61daSMintz, Yuval struct qed_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[type]; 11796bea61daSMintz, Yuval struct qed_cid_acquired_map *p_map; 1180fe56b9e6SYuval Mintz 11816bea61daSMintz, Yuval /* Handle PF maps */ 11826bea61daSMintz, Yuval p_map = &p_mngr->acquired[type]; 11836bea61daSMintz, Yuval if (qed_cid_map_alloc_single(p_hwfn, type, start_cid, 11846bea61daSMintz, Yuval p_cfg->cid_count, p_map)) 1185fe56b9e6SYuval Mintz goto cid_map_fail; 1186fe56b9e6SYuval Mintz 11876bea61daSMintz, Yuval /* Handle VF maps */ 11886bea61daSMintz, Yuval for (vf = 0; vf < MAX_NUM_VFS; vf++) { 11896bea61daSMintz, Yuval p_map = &p_mngr->acquired_vf[type][vf]; 11906bea61daSMintz, Yuval if (qed_cid_map_alloc_single(p_hwfn, type, 11916bea61daSMintz, Yuval vf_start_cid, 11926bea61daSMintz, Yuval p_cfg->cids_per_vf, p_map)) 11936bea61daSMintz, Yuval goto cid_map_fail; 11946bea61daSMintz, Yuval } 1195fe56b9e6SYuval Mintz 11966bea61daSMintz, Yuval start_cid += p_cfg->cid_count; 11976bea61daSMintz, Yuval vf_start_cid += p_cfg->cids_per_vf; 1198fe56b9e6SYuval Mintz } 1199fe56b9e6SYuval Mintz 1200fe56b9e6SYuval Mintz return 0; 1201fe56b9e6SYuval Mintz 1202fe56b9e6SYuval Mintz cid_map_fail: 1203fe56b9e6SYuval Mintz qed_cid_map_free(p_hwfn); 1204fe56b9e6SYuval Mintz return -ENOMEM; 1205fe56b9e6SYuval Mintz } 1206fe56b9e6SYuval Mintz 1207fe56b9e6SYuval Mintz int qed_cxt_mngr_alloc(struct qed_hwfn *p_hwfn) 1208fe56b9e6SYuval Mintz { 1209dbb799c3SYuval Mintz struct qed_ilt_client_cfg *clients; 1210fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr; 1211fe56b9e6SYuval Mintz u32 i; 1212fe56b9e6SYuval Mintz 121360fffb3bSYuval Mintz p_mngr = kzalloc(sizeof(*p_mngr), GFP_KERNEL); 12142591c280SJoe Perches if (!p_mngr) 1215fe56b9e6SYuval Mintz return -ENOMEM; 1216fe56b9e6SYuval Mintz 1217fe56b9e6SYuval Mintz /* Initialize ILT client registers */ 1218dbb799c3SYuval Mintz clients = p_mngr->clients; 1219dbb799c3SYuval Mintz clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT); 1220dbb799c3SYuval Mintz clients[ILT_CLI_CDUC].last.reg = ILT_CFG_REG(CDUC, LAST_ILT); 1221dbb799c3SYuval Mintz clients[ILT_CLI_CDUC].p_size.reg = ILT_CFG_REG(CDUC, P_SIZE); 1222fe56b9e6SYuval Mintz 1223dbb799c3SYuval Mintz clients[ILT_CLI_QM].first.reg = ILT_CFG_REG(QM, FIRST_ILT); 1224dbb799c3SYuval Mintz clients[ILT_CLI_QM].last.reg = ILT_CFG_REG(QM, LAST_ILT); 1225dbb799c3SYuval Mintz clients[ILT_CLI_QM].p_size.reg = ILT_CFG_REG(QM, P_SIZE); 1226fe56b9e6SYuval Mintz 1227dbb799c3SYuval Mintz clients[ILT_CLI_TM].first.reg = ILT_CFG_REG(TM, FIRST_ILT); 1228dbb799c3SYuval Mintz clients[ILT_CLI_TM].last.reg = ILT_CFG_REG(TM, LAST_ILT); 1229dbb799c3SYuval Mintz clients[ILT_CLI_TM].p_size.reg = ILT_CFG_REG(TM, P_SIZE); 1230dbb799c3SYuval Mintz 1231dbb799c3SYuval Mintz clients[ILT_CLI_SRC].first.reg = ILT_CFG_REG(SRC, FIRST_ILT); 1232dbb799c3SYuval Mintz clients[ILT_CLI_SRC].last.reg = ILT_CFG_REG(SRC, LAST_ILT); 1233dbb799c3SYuval Mintz clients[ILT_CLI_SRC].p_size.reg = ILT_CFG_REG(SRC, P_SIZE); 1234dbb799c3SYuval Mintz 1235dbb799c3SYuval Mintz clients[ILT_CLI_CDUT].first.reg = ILT_CFG_REG(CDUT, FIRST_ILT); 1236dbb799c3SYuval Mintz clients[ILT_CLI_CDUT].last.reg = ILT_CFG_REG(CDUT, LAST_ILT); 1237dbb799c3SYuval Mintz clients[ILT_CLI_CDUT].p_size.reg = ILT_CFG_REG(CDUT, P_SIZE); 1238dbb799c3SYuval Mintz 1239dbb799c3SYuval Mintz clients[ILT_CLI_TSDM].first.reg = ILT_CFG_REG(TSDM, FIRST_ILT); 1240dbb799c3SYuval Mintz clients[ILT_CLI_TSDM].last.reg = ILT_CFG_REG(TSDM, LAST_ILT); 1241dbb799c3SYuval Mintz clients[ILT_CLI_TSDM].p_size.reg = ILT_CFG_REG(TSDM, P_SIZE); 1242be086e7cSMintz, Yuval /* default ILT page size for all clients is 64K */ 1243fe56b9e6SYuval Mintz for (i = 0; i < ILT_CLI_MAX; i++) 1244fe56b9e6SYuval Mintz p_mngr->clients[i].p_size.val = ILT_DEFAULT_HW_P_SIZE; 1245fe56b9e6SYuval Mintz 1246dbb799c3SYuval Mintz /* Initialize task sizes */ 1247dbb799c3SYuval Mintz p_mngr->task_type_size[0] = TYPE0_TASK_CXT_SIZE(p_hwfn); 1248dbb799c3SYuval Mintz p_mngr->task_type_size[1] = TYPE1_TASK_CXT_SIZE(p_hwfn); 1249dbb799c3SYuval Mintz 12501408cc1fSYuval Mintz if (p_hwfn->cdev->p_iov_info) 12511408cc1fSYuval Mintz p_mngr->vf_count = p_hwfn->cdev->p_iov_info->total_vfs; 1252dbb799c3SYuval Mintz /* Initialize the dynamic ILT allocation mutex */ 1253dbb799c3SYuval Mintz mutex_init(&p_mngr->mutex); 12541408cc1fSYuval Mintz 1255fe56b9e6SYuval Mintz /* Set the cxt mangr pointer priori to further allocations */ 1256fe56b9e6SYuval Mintz p_hwfn->p_cxt_mngr = p_mngr; 1257fe56b9e6SYuval Mintz 1258fe56b9e6SYuval Mintz return 0; 1259fe56b9e6SYuval Mintz } 1260fe56b9e6SYuval Mintz 1261fe56b9e6SYuval Mintz int qed_cxt_tables_alloc(struct qed_hwfn *p_hwfn) 1262fe56b9e6SYuval Mintz { 1263fe56b9e6SYuval Mintz int rc; 1264fe56b9e6SYuval Mintz 1265fe56b9e6SYuval Mintz /* Allocate the ILT shadow table */ 1266fe56b9e6SYuval Mintz rc = qed_ilt_shadow_alloc(p_hwfn); 12672591c280SJoe Perches if (rc) 1268fe56b9e6SYuval Mintz goto tables_alloc_fail; 1269fe56b9e6SYuval Mintz 1270dbb799c3SYuval Mintz /* Allocate the T2 table */ 1271dbb799c3SYuval Mintz rc = qed_cxt_src_t2_alloc(p_hwfn); 12722591c280SJoe Perches if (rc) 1273dbb799c3SYuval Mintz goto tables_alloc_fail; 1274dbb799c3SYuval Mintz 1275fe56b9e6SYuval Mintz /* Allocate and initialize the acquired cids bitmaps */ 1276fe56b9e6SYuval Mintz rc = qed_cid_map_alloc(p_hwfn); 12772591c280SJoe Perches if (rc) 1278fe56b9e6SYuval Mintz goto tables_alloc_fail; 1279fe56b9e6SYuval Mintz 1280fe56b9e6SYuval Mintz return 0; 1281fe56b9e6SYuval Mintz 1282fe56b9e6SYuval Mintz tables_alloc_fail: 1283fe56b9e6SYuval Mintz qed_cxt_mngr_free(p_hwfn); 1284fe56b9e6SYuval Mintz return rc; 1285fe56b9e6SYuval Mintz } 1286fe56b9e6SYuval Mintz 1287fe56b9e6SYuval Mintz void qed_cxt_mngr_free(struct qed_hwfn *p_hwfn) 1288fe56b9e6SYuval Mintz { 1289fe56b9e6SYuval Mintz if (!p_hwfn->p_cxt_mngr) 1290fe56b9e6SYuval Mintz return; 1291fe56b9e6SYuval Mintz 1292fe56b9e6SYuval Mintz qed_cid_map_free(p_hwfn); 1293dbb799c3SYuval Mintz qed_cxt_src_t2_free(p_hwfn); 1294fe56b9e6SYuval Mintz qed_ilt_shadow_free(p_hwfn); 1295fe56b9e6SYuval Mintz kfree(p_hwfn->p_cxt_mngr); 1296fe56b9e6SYuval Mintz 1297fe56b9e6SYuval Mintz p_hwfn->p_cxt_mngr = NULL; 1298fe56b9e6SYuval Mintz } 1299fe56b9e6SYuval Mintz 1300fe56b9e6SYuval Mintz void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn) 1301fe56b9e6SYuval Mintz { 1302fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 13036bea61daSMintz, Yuval struct qed_cid_acquired_map *p_map; 13046bea61daSMintz, Yuval struct qed_conn_type_cfg *p_cfg; 1305fe56b9e6SYuval Mintz int type; 13066bea61daSMintz, Yuval u32 len; 1307fe56b9e6SYuval Mintz 1308fe56b9e6SYuval Mintz /* Reset acquired cids */ 1309fe56b9e6SYuval Mintz for (type = 0; type < MAX_CONN_TYPES; type++) { 13106bea61daSMintz, Yuval u32 vf; 1311fe56b9e6SYuval Mintz 13126bea61daSMintz, Yuval p_cfg = &p_mngr->conn_cfg[type]; 13136bea61daSMintz, Yuval if (p_cfg->cid_count) { 13146bea61daSMintz, Yuval p_map = &p_mngr->acquired[type]; 13156bea61daSMintz, Yuval len = DIV_ROUND_UP(p_map->max_count, 13166bea61daSMintz, Yuval sizeof(unsigned long) * 13176bea61daSMintz, Yuval BITS_PER_BYTE) * 13186bea61daSMintz, Yuval sizeof(unsigned long); 13196bea61daSMintz, Yuval memset(p_map->cid_map, 0, len); 13206bea61daSMintz, Yuval } 13216bea61daSMintz, Yuval 13226bea61daSMintz, Yuval if (!p_cfg->cids_per_vf) 1323fe56b9e6SYuval Mintz continue; 1324fe56b9e6SYuval Mintz 13256bea61daSMintz, Yuval for (vf = 0; vf < MAX_NUM_VFS; vf++) { 13266bea61daSMintz, Yuval p_map = &p_mngr->acquired_vf[type][vf]; 13276bea61daSMintz, Yuval len = DIV_ROUND_UP(p_map->max_count, 13286bea61daSMintz, Yuval sizeof(unsigned long) * 13296bea61daSMintz, Yuval BITS_PER_BYTE) * 13306bea61daSMintz, Yuval sizeof(unsigned long); 13316bea61daSMintz, Yuval memset(p_map->cid_map, 0, len); 13326bea61daSMintz, Yuval } 1333fe56b9e6SYuval Mintz } 1334fe56b9e6SYuval Mintz } 1335fe56b9e6SYuval Mintz 1336fe56b9e6SYuval Mintz /* CDU Common */ 1337fe56b9e6SYuval Mintz #define CDUC_CXT_SIZE_SHIFT \ 1338fe56b9e6SYuval Mintz CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE_SHIFT 1339fe56b9e6SYuval Mintz 1340fe56b9e6SYuval Mintz #define CDUC_CXT_SIZE_MASK \ 1341fe56b9e6SYuval Mintz (CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE >> CDUC_CXT_SIZE_SHIFT) 1342fe56b9e6SYuval Mintz 1343fe56b9e6SYuval Mintz #define CDUC_BLOCK_WASTE_SHIFT \ 1344fe56b9e6SYuval Mintz CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE_SHIFT 1345fe56b9e6SYuval Mintz 1346fe56b9e6SYuval Mintz #define CDUC_BLOCK_WASTE_MASK \ 1347fe56b9e6SYuval Mintz (CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE >> CDUC_BLOCK_WASTE_SHIFT) 1348fe56b9e6SYuval Mintz 1349fe56b9e6SYuval Mintz #define CDUC_NCIB_SHIFT \ 1350fe56b9e6SYuval Mintz CDU_REG_CID_ADDR_PARAMS_NCIB_SHIFT 1351fe56b9e6SYuval Mintz 1352fe56b9e6SYuval Mintz #define CDUC_NCIB_MASK \ 1353fe56b9e6SYuval Mintz (CDU_REG_CID_ADDR_PARAMS_NCIB >> CDUC_NCIB_SHIFT) 1354fe56b9e6SYuval Mintz 1355dbb799c3SYuval Mintz #define CDUT_TYPE0_CXT_SIZE_SHIFT \ 1356dbb799c3SYuval Mintz CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE_SHIFT 1357dbb799c3SYuval Mintz 1358dbb799c3SYuval Mintz #define CDUT_TYPE0_CXT_SIZE_MASK \ 1359dbb799c3SYuval Mintz (CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE >> \ 1360dbb799c3SYuval Mintz CDUT_TYPE0_CXT_SIZE_SHIFT) 1361dbb799c3SYuval Mintz 1362dbb799c3SYuval Mintz #define CDUT_TYPE0_BLOCK_WASTE_SHIFT \ 1363dbb799c3SYuval Mintz CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE_SHIFT 1364dbb799c3SYuval Mintz 1365dbb799c3SYuval Mintz #define CDUT_TYPE0_BLOCK_WASTE_MASK \ 1366dbb799c3SYuval Mintz (CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE >> \ 1367dbb799c3SYuval Mintz CDUT_TYPE0_BLOCK_WASTE_SHIFT) 1368dbb799c3SYuval Mintz 1369dbb799c3SYuval Mintz #define CDUT_TYPE0_NCIB_SHIFT \ 1370dbb799c3SYuval Mintz CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK_SHIFT 1371dbb799c3SYuval Mintz 1372dbb799c3SYuval Mintz #define CDUT_TYPE0_NCIB_MASK \ 1373dbb799c3SYuval Mintz (CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK >> \ 1374dbb799c3SYuval Mintz CDUT_TYPE0_NCIB_SHIFT) 1375dbb799c3SYuval Mintz 1376dbb799c3SYuval Mintz #define CDUT_TYPE1_CXT_SIZE_SHIFT \ 1377dbb799c3SYuval Mintz CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE_SHIFT 1378dbb799c3SYuval Mintz 1379dbb799c3SYuval Mintz #define CDUT_TYPE1_CXT_SIZE_MASK \ 1380dbb799c3SYuval Mintz (CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE >> \ 1381dbb799c3SYuval Mintz CDUT_TYPE1_CXT_SIZE_SHIFT) 1382dbb799c3SYuval Mintz 1383dbb799c3SYuval Mintz #define CDUT_TYPE1_BLOCK_WASTE_SHIFT \ 1384dbb799c3SYuval Mintz CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE_SHIFT 1385dbb799c3SYuval Mintz 1386dbb799c3SYuval Mintz #define CDUT_TYPE1_BLOCK_WASTE_MASK \ 1387dbb799c3SYuval Mintz (CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE >> \ 1388dbb799c3SYuval Mintz CDUT_TYPE1_BLOCK_WASTE_SHIFT) 1389dbb799c3SYuval Mintz 1390dbb799c3SYuval Mintz #define CDUT_TYPE1_NCIB_SHIFT \ 1391dbb799c3SYuval Mintz CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK_SHIFT 1392dbb799c3SYuval Mintz 1393dbb799c3SYuval Mintz #define CDUT_TYPE1_NCIB_MASK \ 1394dbb799c3SYuval Mintz (CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK >> \ 1395dbb799c3SYuval Mintz CDUT_TYPE1_NCIB_SHIFT) 1396dbb799c3SYuval Mintz 1397fe56b9e6SYuval Mintz static void qed_cdu_init_common(struct qed_hwfn *p_hwfn) 1398fe56b9e6SYuval Mintz { 1399fe56b9e6SYuval Mintz u32 page_sz, elems_per_page, block_waste, cxt_size, cdu_params = 0; 1400fe56b9e6SYuval Mintz 1401fe56b9e6SYuval Mintz /* CDUC - connection configuration */ 1402fe56b9e6SYuval Mintz page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val; 1403fe56b9e6SYuval Mintz cxt_size = CONN_CXT_SIZE(p_hwfn); 1404fe56b9e6SYuval Mintz elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; 1405fe56b9e6SYuval Mintz block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size; 1406fe56b9e6SYuval Mintz 1407fe56b9e6SYuval Mintz SET_FIELD(cdu_params, CDUC_CXT_SIZE, cxt_size); 1408fe56b9e6SYuval Mintz SET_FIELD(cdu_params, CDUC_BLOCK_WASTE, block_waste); 1409fe56b9e6SYuval Mintz SET_FIELD(cdu_params, CDUC_NCIB, elems_per_page); 1410fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, CDU_REG_CID_ADDR_PARAMS_RT_OFFSET, cdu_params); 1411dbb799c3SYuval Mintz 1412dbb799c3SYuval Mintz /* CDUT - type-0 tasks configuration */ 1413dbb799c3SYuval Mintz page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT].p_size.val; 1414dbb799c3SYuval Mintz cxt_size = p_hwfn->p_cxt_mngr->task_type_size[0]; 1415dbb799c3SYuval Mintz elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; 1416dbb799c3SYuval Mintz block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size; 1417dbb799c3SYuval Mintz 1418dbb799c3SYuval Mintz /* cxt size and block-waste are multipes of 8 */ 1419dbb799c3SYuval Mintz cdu_params = 0; 1420dbb799c3SYuval Mintz SET_FIELD(cdu_params, CDUT_TYPE0_CXT_SIZE, (cxt_size >> 3)); 1421dbb799c3SYuval Mintz SET_FIELD(cdu_params, CDUT_TYPE0_BLOCK_WASTE, (block_waste >> 3)); 1422dbb799c3SYuval Mintz SET_FIELD(cdu_params, CDUT_TYPE0_NCIB, elems_per_page); 1423dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT0_PARAMS_RT_OFFSET, cdu_params); 1424dbb799c3SYuval Mintz 1425dbb799c3SYuval Mintz /* CDUT - type-1 tasks configuration */ 1426dbb799c3SYuval Mintz cxt_size = p_hwfn->p_cxt_mngr->task_type_size[1]; 1427dbb799c3SYuval Mintz elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; 1428dbb799c3SYuval Mintz block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size; 1429dbb799c3SYuval Mintz 1430dbb799c3SYuval Mintz /* cxt size and block-waste are multipes of 8 */ 1431dbb799c3SYuval Mintz cdu_params = 0; 1432dbb799c3SYuval Mintz SET_FIELD(cdu_params, CDUT_TYPE1_CXT_SIZE, (cxt_size >> 3)); 1433dbb799c3SYuval Mintz SET_FIELD(cdu_params, CDUT_TYPE1_BLOCK_WASTE, (block_waste >> 3)); 1434dbb799c3SYuval Mintz SET_FIELD(cdu_params, CDUT_TYPE1_NCIB, elems_per_page); 1435dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT1_PARAMS_RT_OFFSET, cdu_params); 1436dbb799c3SYuval Mintz } 1437dbb799c3SYuval Mintz 1438dbb799c3SYuval Mintz /* CDU PF */ 1439dbb799c3SYuval Mintz #define CDU_SEG_REG_TYPE_SHIFT CDU_SEG_TYPE_OFFSET_REG_TYPE_SHIFT 1440dbb799c3SYuval Mintz #define CDU_SEG_REG_TYPE_MASK 0x1 1441dbb799c3SYuval Mintz #define CDU_SEG_REG_OFFSET_SHIFT 0 1442dbb799c3SYuval Mintz #define CDU_SEG_REG_OFFSET_MASK CDU_SEG_TYPE_OFFSET_REG_OFFSET_MASK 1443dbb799c3SYuval Mintz 1444dbb799c3SYuval Mintz static void qed_cdu_init_pf(struct qed_hwfn *p_hwfn) 1445dbb799c3SYuval Mintz { 1446dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_cli; 1447dbb799c3SYuval Mintz struct qed_tid_seg *p_seg; 1448dbb799c3SYuval Mintz u32 cdu_seg_params, offset; 1449dbb799c3SYuval Mintz int i; 1450dbb799c3SYuval Mintz 1451dbb799c3SYuval Mintz static const u32 rt_type_offset_arr[] = { 1452dbb799c3SYuval Mintz CDU_REG_PF_SEG0_TYPE_OFFSET_RT_OFFSET, 1453dbb799c3SYuval Mintz CDU_REG_PF_SEG1_TYPE_OFFSET_RT_OFFSET, 1454dbb799c3SYuval Mintz CDU_REG_PF_SEG2_TYPE_OFFSET_RT_OFFSET, 1455dbb799c3SYuval Mintz CDU_REG_PF_SEG3_TYPE_OFFSET_RT_OFFSET 1456dbb799c3SYuval Mintz }; 1457dbb799c3SYuval Mintz 1458dbb799c3SYuval Mintz static const u32 rt_type_offset_fl_arr[] = { 1459dbb799c3SYuval Mintz CDU_REG_PF_FL_SEG0_TYPE_OFFSET_RT_OFFSET, 1460dbb799c3SYuval Mintz CDU_REG_PF_FL_SEG1_TYPE_OFFSET_RT_OFFSET, 1461dbb799c3SYuval Mintz CDU_REG_PF_FL_SEG2_TYPE_OFFSET_RT_OFFSET, 1462dbb799c3SYuval Mintz CDU_REG_PF_FL_SEG3_TYPE_OFFSET_RT_OFFSET 1463dbb799c3SYuval Mintz }; 1464dbb799c3SYuval Mintz 1465dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; 1466dbb799c3SYuval Mintz 1467dbb799c3SYuval Mintz /* There are initializations only for CDUT during pf Phase */ 1468dbb799c3SYuval Mintz for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { 1469dbb799c3SYuval Mintz /* Segment 0 */ 1470dbb799c3SYuval Mintz p_seg = qed_cxt_tid_seg_info(p_hwfn, i); 1471dbb799c3SYuval Mintz if (!p_seg) 1472dbb799c3SYuval Mintz continue; 1473dbb799c3SYuval Mintz 1474dbb799c3SYuval Mintz /* Note: start_line is already adjusted for the CDU 1475dbb799c3SYuval Mintz * segment register granularity, so we just need to 1476dbb799c3SYuval Mintz * divide. Adjustment is implicit as we assume ILT 1477dbb799c3SYuval Mintz * Page size is larger than 32K! 1478dbb799c3SYuval Mintz */ 1479dbb799c3SYuval Mintz offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) * 1480dbb799c3SYuval Mintz (p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line - 1481dbb799c3SYuval Mintz p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES; 1482dbb799c3SYuval Mintz 1483dbb799c3SYuval Mintz cdu_seg_params = 0; 1484dbb799c3SYuval Mintz SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type); 1485dbb799c3SYuval Mintz SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset); 1486dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, rt_type_offset_arr[i], cdu_seg_params); 1487dbb799c3SYuval Mintz 1488dbb799c3SYuval Mintz offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) * 1489dbb799c3SYuval Mintz (p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)].start_line - 1490dbb799c3SYuval Mintz p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES; 1491dbb799c3SYuval Mintz 1492dbb799c3SYuval Mintz cdu_seg_params = 0; 1493dbb799c3SYuval Mintz SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type); 1494dbb799c3SYuval Mintz SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset); 1495dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, rt_type_offset_fl_arr[i], cdu_seg_params); 1496dbb799c3SYuval Mintz } 1497fe56b9e6SYuval Mintz } 1498fe56b9e6SYuval Mintz 149915582962SRahul Verma void qed_qm_init_pf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 1500fe56b9e6SYuval Mintz { 1501fe56b9e6SYuval Mintz struct qed_qm_pf_rt_init_params params; 1502fe56b9e6SYuval Mintz struct qed_qm_info *qm_info = &p_hwfn->qm_info; 1503fe56b9e6SYuval Mintz struct qed_qm_iids iids; 1504fe56b9e6SYuval Mintz 1505fe56b9e6SYuval Mintz memset(&iids, 0, sizeof(iids)); 1506fe56b9e6SYuval Mintz qed_cxt_qm_iids(p_hwfn, &iids); 1507fe56b9e6SYuval Mintz 1508fe56b9e6SYuval Mintz memset(¶ms, 0, sizeof(params)); 1509fe56b9e6SYuval Mintz params.port_id = p_hwfn->port_id; 1510fe56b9e6SYuval Mintz params.pf_id = p_hwfn->rel_pf_id; 1511fe56b9e6SYuval Mintz params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port; 1512fe56b9e6SYuval Mintz params.is_first_pf = p_hwfn->first_on_engine; 1513fe56b9e6SYuval Mintz params.num_pf_cids = iids.cids; 15141408cc1fSYuval Mintz params.num_vf_cids = iids.vf_cids; 1515c9f0523bSMintz, Yuval params.num_tids = iids.tids; 1516fe56b9e6SYuval Mintz params.start_pq = qm_info->start_pq; 15171408cc1fSYuval Mintz params.num_pf_pqs = qm_info->num_pqs - qm_info->num_vf_pqs; 15181408cc1fSYuval Mintz params.num_vf_pqs = qm_info->num_vf_pqs; 1519fc48b7a6SYuval Mintz params.start_vport = qm_info->start_vport; 1520fc48b7a6SYuval Mintz params.num_vports = qm_info->num_vports; 1521fe56b9e6SYuval Mintz params.pf_wfq = qm_info->pf_wfq; 1522fe56b9e6SYuval Mintz params.pf_rl = qm_info->pf_rl; 1523fe56b9e6SYuval Mintz params.pq_params = qm_info->qm_pq_params; 1524fe56b9e6SYuval Mintz params.vport_params = qm_info->qm_vport_params; 1525fe56b9e6SYuval Mintz 152615582962SRahul Verma qed_qm_pf_rt_init(p_hwfn, p_ptt, ¶ms); 1527fe56b9e6SYuval Mintz } 1528fe56b9e6SYuval Mintz 1529fe56b9e6SYuval Mintz /* CM PF */ 1530b5a9ee7cSAriel Elior void qed_cm_init_pf(struct qed_hwfn *p_hwfn) 1531fe56b9e6SYuval Mintz { 1532fe56b9e6SYuval Mintz /* XCM pure-LB queue */ 1533b5a9ee7cSAriel Elior STORE_RT_REG(p_hwfn, XCM_REG_CON_PHY_Q3_RT_OFFSET, 1534b5a9ee7cSAriel Elior qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB)); 1535fe56b9e6SYuval Mintz } 1536fe56b9e6SYuval Mintz 1537fe56b9e6SYuval Mintz /* DQ PF */ 1538fe56b9e6SYuval Mintz static void qed_dq_init_pf(struct qed_hwfn *p_hwfn) 1539fe56b9e6SYuval Mintz { 1540fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 15411408cc1fSYuval Mintz u32 dq_pf_max_cid = 0, dq_vf_max_cid = 0; 1542fe56b9e6SYuval Mintz 1543fe56b9e6SYuval Mintz dq_pf_max_cid += (p_mngr->conn_cfg[0].cid_count >> DQ_RANGE_SHIFT); 1544fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_0_RT_OFFSET, dq_pf_max_cid); 1545fe56b9e6SYuval Mintz 15461408cc1fSYuval Mintz dq_vf_max_cid += (p_mngr->conn_cfg[0].cids_per_vf >> DQ_RANGE_SHIFT); 15471408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_0_RT_OFFSET, dq_vf_max_cid); 15481408cc1fSYuval Mintz 1549fe56b9e6SYuval Mintz dq_pf_max_cid += (p_mngr->conn_cfg[1].cid_count >> DQ_RANGE_SHIFT); 1550fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_1_RT_OFFSET, dq_pf_max_cid); 1551fe56b9e6SYuval Mintz 15521408cc1fSYuval Mintz dq_vf_max_cid += (p_mngr->conn_cfg[1].cids_per_vf >> DQ_RANGE_SHIFT); 15531408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_1_RT_OFFSET, dq_vf_max_cid); 15541408cc1fSYuval Mintz 1555fe56b9e6SYuval Mintz dq_pf_max_cid += (p_mngr->conn_cfg[2].cid_count >> DQ_RANGE_SHIFT); 1556fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_2_RT_OFFSET, dq_pf_max_cid); 1557fe56b9e6SYuval Mintz 15581408cc1fSYuval Mintz dq_vf_max_cid += (p_mngr->conn_cfg[2].cids_per_vf >> DQ_RANGE_SHIFT); 15591408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_2_RT_OFFSET, dq_vf_max_cid); 15601408cc1fSYuval Mintz 1561fe56b9e6SYuval Mintz dq_pf_max_cid += (p_mngr->conn_cfg[3].cid_count >> DQ_RANGE_SHIFT); 1562fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_3_RT_OFFSET, dq_pf_max_cid); 1563fe56b9e6SYuval Mintz 15641408cc1fSYuval Mintz dq_vf_max_cid += (p_mngr->conn_cfg[3].cids_per_vf >> DQ_RANGE_SHIFT); 15651408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_3_RT_OFFSET, dq_vf_max_cid); 15661408cc1fSYuval Mintz 1567fe56b9e6SYuval Mintz dq_pf_max_cid += (p_mngr->conn_cfg[4].cid_count >> DQ_RANGE_SHIFT); 1568fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_4_RT_OFFSET, dq_pf_max_cid); 1569fe56b9e6SYuval Mintz 15701408cc1fSYuval Mintz dq_vf_max_cid += (p_mngr->conn_cfg[4].cids_per_vf >> DQ_RANGE_SHIFT); 15711408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_4_RT_OFFSET, dq_vf_max_cid); 15721408cc1fSYuval Mintz 1573fe56b9e6SYuval Mintz dq_pf_max_cid += (p_mngr->conn_cfg[5].cid_count >> DQ_RANGE_SHIFT); 1574fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_5_RT_OFFSET, dq_pf_max_cid); 15751408cc1fSYuval Mintz 15761408cc1fSYuval Mintz dq_vf_max_cid += (p_mngr->conn_cfg[5].cids_per_vf >> DQ_RANGE_SHIFT); 15771408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_5_RT_OFFSET, dq_vf_max_cid); 15781408cc1fSYuval Mintz 15791408cc1fSYuval Mintz /* Connection types 6 & 7 are not in use, yet they must be configured 15801408cc1fSYuval Mintz * as the highest possible connection. Not configuring them means the 15811408cc1fSYuval Mintz * defaults will be used, and with a large number of cids a bug may 15821408cc1fSYuval Mintz * occur, if the defaults will be smaller than dq_pf_max_cid / 15831408cc1fSYuval Mintz * dq_vf_max_cid. 15841408cc1fSYuval Mintz */ 15851408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_6_RT_OFFSET, dq_pf_max_cid); 15861408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_6_RT_OFFSET, dq_vf_max_cid); 15871408cc1fSYuval Mintz 15881408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_7_RT_OFFSET, dq_pf_max_cid); 15891408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_7_RT_OFFSET, dq_vf_max_cid); 1590fe56b9e6SYuval Mintz } 1591fe56b9e6SYuval Mintz 1592fe56b9e6SYuval Mintz static void qed_ilt_bounds_init(struct qed_hwfn *p_hwfn) 1593fe56b9e6SYuval Mintz { 1594fe56b9e6SYuval Mintz struct qed_ilt_client_cfg *ilt_clients; 1595fe56b9e6SYuval Mintz int i; 1596fe56b9e6SYuval Mintz 1597fe56b9e6SYuval Mintz ilt_clients = p_hwfn->p_cxt_mngr->clients; 1598fe56b9e6SYuval Mintz for_each_ilt_valid_client(i, ilt_clients) { 1599fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, 1600fe56b9e6SYuval Mintz ilt_clients[i].first.reg, 1601fe56b9e6SYuval Mintz ilt_clients[i].first.val); 1602fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, 1603dbb799c3SYuval Mintz ilt_clients[i].last.reg, ilt_clients[i].last.val); 1604fe56b9e6SYuval Mintz STORE_RT_REG(p_hwfn, 1605fe56b9e6SYuval Mintz ilt_clients[i].p_size.reg, 1606fe56b9e6SYuval Mintz ilt_clients[i].p_size.val); 1607fe56b9e6SYuval Mintz } 1608fe56b9e6SYuval Mintz } 1609fe56b9e6SYuval Mintz 16101408cc1fSYuval Mintz static void qed_ilt_vf_bounds_init(struct qed_hwfn *p_hwfn) 16111408cc1fSYuval Mintz { 16121408cc1fSYuval Mintz struct qed_ilt_client_cfg *p_cli; 16131408cc1fSYuval Mintz u32 blk_factor; 16141408cc1fSYuval Mintz 16151408cc1fSYuval Mintz /* For simplicty we set the 'block' to be an ILT page */ 16161408cc1fSYuval Mintz if (p_hwfn->cdev->p_iov_info) { 16171408cc1fSYuval Mintz struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info; 16181408cc1fSYuval Mintz 16191408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, 16201408cc1fSYuval Mintz PSWRQ2_REG_VF_BASE_RT_OFFSET, 16211408cc1fSYuval Mintz p_iov->first_vf_in_pf); 16221408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, 16231408cc1fSYuval Mintz PSWRQ2_REG_VF_LAST_ILT_RT_OFFSET, 16241408cc1fSYuval Mintz p_iov->first_vf_in_pf + p_iov->total_vfs); 16251408cc1fSYuval Mintz } 16261408cc1fSYuval Mintz 16271408cc1fSYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; 16281408cc1fSYuval Mintz blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10); 16291408cc1fSYuval Mintz if (p_cli->active) { 16301408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, 16311408cc1fSYuval Mintz PSWRQ2_REG_CDUC_BLOCKS_FACTOR_RT_OFFSET, 16321408cc1fSYuval Mintz blk_factor); 16331408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, 16341408cc1fSYuval Mintz PSWRQ2_REG_CDUC_NUMBER_OF_PF_BLOCKS_RT_OFFSET, 16351408cc1fSYuval Mintz p_cli->pf_total_lines); 16361408cc1fSYuval Mintz STORE_RT_REG(p_hwfn, 16371408cc1fSYuval Mintz PSWRQ2_REG_CDUC_VF_BLOCKS_RT_OFFSET, 16381408cc1fSYuval Mintz p_cli->vf_total_lines); 16391408cc1fSYuval Mintz } 1640dbb799c3SYuval Mintz 1641dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; 1642dbb799c3SYuval Mintz blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10); 1643dbb799c3SYuval Mintz if (p_cli->active) { 1644dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, 1645dbb799c3SYuval Mintz PSWRQ2_REG_CDUT_BLOCKS_FACTOR_RT_OFFSET, 1646dbb799c3SYuval Mintz blk_factor); 1647dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, 1648dbb799c3SYuval Mintz PSWRQ2_REG_CDUT_NUMBER_OF_PF_BLOCKS_RT_OFFSET, 1649dbb799c3SYuval Mintz p_cli->pf_total_lines); 1650dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, 1651dbb799c3SYuval Mintz PSWRQ2_REG_CDUT_VF_BLOCKS_RT_OFFSET, 1652dbb799c3SYuval Mintz p_cli->vf_total_lines); 1653dbb799c3SYuval Mintz } 1654dbb799c3SYuval Mintz 1655dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TM]; 1656dbb799c3SYuval Mintz blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10); 1657dbb799c3SYuval Mintz if (p_cli->active) { 1658dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, 1659dbb799c3SYuval Mintz PSWRQ2_REG_TM_BLOCKS_FACTOR_RT_OFFSET, blk_factor); 1660dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, 1661dbb799c3SYuval Mintz PSWRQ2_REG_TM_NUMBER_OF_PF_BLOCKS_RT_OFFSET, 1662dbb799c3SYuval Mintz p_cli->pf_total_lines); 1663dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, 1664dbb799c3SYuval Mintz PSWRQ2_REG_TM_VF_BLOCKS_RT_OFFSET, 1665dbb799c3SYuval Mintz p_cli->vf_total_lines); 1666dbb799c3SYuval Mintz } 16671408cc1fSYuval Mintz } 16681408cc1fSYuval Mintz 1669fe56b9e6SYuval Mintz /* ILT (PSWRQ2) PF */ 1670fe56b9e6SYuval Mintz static void qed_ilt_init_pf(struct qed_hwfn *p_hwfn) 1671fe56b9e6SYuval Mintz { 1672fe56b9e6SYuval Mintz struct qed_ilt_client_cfg *clients; 1673fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr; 1674fe56b9e6SYuval Mintz struct qed_dma_mem *p_shdw; 1675fe56b9e6SYuval Mintz u32 line, rt_offst, i; 1676fe56b9e6SYuval Mintz 1677fe56b9e6SYuval Mintz qed_ilt_bounds_init(p_hwfn); 16781408cc1fSYuval Mintz qed_ilt_vf_bounds_init(p_hwfn); 1679fe56b9e6SYuval Mintz 1680fe56b9e6SYuval Mintz p_mngr = p_hwfn->p_cxt_mngr; 1681fe56b9e6SYuval Mintz p_shdw = p_mngr->ilt_shadow; 1682fe56b9e6SYuval Mintz clients = p_hwfn->p_cxt_mngr->clients; 1683fe56b9e6SYuval Mintz 1684fe56b9e6SYuval Mintz for_each_ilt_valid_client(i, clients) { 1685fe56b9e6SYuval Mintz /** Client's 1st val and RT array are absolute, ILT shadows' 1686fe56b9e6SYuval Mintz * lines are relative. 1687fe56b9e6SYuval Mintz */ 1688fe56b9e6SYuval Mintz line = clients[i].first.val - p_mngr->pf_start_line; 1689fe56b9e6SYuval Mintz rt_offst = PSWRQ2_REG_ILT_MEMORY_RT_OFFSET + 1690fe56b9e6SYuval Mintz clients[i].first.val * ILT_ENTRY_IN_REGS; 1691fe56b9e6SYuval Mintz 1692fe56b9e6SYuval Mintz for (; line <= clients[i].last.val - p_mngr->pf_start_line; 1693fe56b9e6SYuval Mintz line++, rt_offst += ILT_ENTRY_IN_REGS) { 1694fe56b9e6SYuval Mintz u64 ilt_hw_entry = 0; 1695fe56b9e6SYuval Mintz 1696fe56b9e6SYuval Mintz /** p_virt could be NULL incase of dynamic 1697fe56b9e6SYuval Mintz * allocation 1698fe56b9e6SYuval Mintz */ 1699fe56b9e6SYuval Mintz if (p_shdw[line].p_virt) { 1700fe56b9e6SYuval Mintz SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL); 1701fe56b9e6SYuval Mintz SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR, 1702fe56b9e6SYuval Mintz (p_shdw[line].p_phys >> 12)); 1703fe56b9e6SYuval Mintz 1704fe56b9e6SYuval Mintz DP_VERBOSE(p_hwfn, QED_MSG_ILT, 1705fe56b9e6SYuval Mintz "Setting RT[0x%08x] from ILT[0x%08x] [Client is %d] to Physical addr: 0x%llx\n", 1706fe56b9e6SYuval Mintz rt_offst, line, i, 1707fe56b9e6SYuval Mintz (u64)(p_shdw[line].p_phys >> 12)); 1708fe56b9e6SYuval Mintz } 1709fe56b9e6SYuval Mintz 1710fe56b9e6SYuval Mintz STORE_RT_REG_AGG(p_hwfn, rt_offst, ilt_hw_entry); 1711fe56b9e6SYuval Mintz } 1712fe56b9e6SYuval Mintz } 1713fe56b9e6SYuval Mintz } 1714fe56b9e6SYuval Mintz 1715dbb799c3SYuval Mintz /* SRC (Searcher) PF */ 1716dbb799c3SYuval Mintz static void qed_src_init_pf(struct qed_hwfn *p_hwfn) 1717dbb799c3SYuval Mintz { 1718dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 1719dbb799c3SYuval Mintz u32 rounded_conn_num, conn_num, conn_max; 1720dbb799c3SYuval Mintz struct qed_src_iids src_iids; 1721dbb799c3SYuval Mintz 1722dbb799c3SYuval Mintz memset(&src_iids, 0, sizeof(src_iids)); 1723dbb799c3SYuval Mintz qed_cxt_src_iids(p_mngr, &src_iids); 1724dbb799c3SYuval Mintz conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count; 1725dbb799c3SYuval Mintz if (!conn_num) 1726dbb799c3SYuval Mintz return; 1727dbb799c3SYuval Mintz 1728dbb799c3SYuval Mintz conn_max = max_t(u32, conn_num, SRC_MIN_NUM_ELEMS); 1729dbb799c3SYuval Mintz rounded_conn_num = roundup_pow_of_two(conn_max); 1730dbb799c3SYuval Mintz 1731dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, SRC_REG_COUNTFREE_RT_OFFSET, conn_num); 1732dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, SRC_REG_NUMBER_HASH_BITS_RT_OFFSET, 1733dbb799c3SYuval Mintz ilog2(rounded_conn_num)); 1734dbb799c3SYuval Mintz 1735dbb799c3SYuval Mintz STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET, 1736dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->first_free); 1737dbb799c3SYuval Mintz STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET, 1738dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->last_free); 1739dbb799c3SYuval Mintz } 1740dbb799c3SYuval Mintz 1741dbb799c3SYuval Mintz /* Timers PF */ 1742dbb799c3SYuval Mintz #define TM_CFG_NUM_IDS_SHIFT 0 1743dbb799c3SYuval Mintz #define TM_CFG_NUM_IDS_MASK 0xFFFFULL 1744dbb799c3SYuval Mintz #define TM_CFG_PRE_SCAN_OFFSET_SHIFT 16 1745dbb799c3SYuval Mintz #define TM_CFG_PRE_SCAN_OFFSET_MASK 0x1FFULL 1746dbb799c3SYuval Mintz #define TM_CFG_PARENT_PF_SHIFT 25 1747dbb799c3SYuval Mintz #define TM_CFG_PARENT_PF_MASK 0x7ULL 1748dbb799c3SYuval Mintz 1749dbb799c3SYuval Mintz #define TM_CFG_CID_PRE_SCAN_ROWS_SHIFT 30 1750dbb799c3SYuval Mintz #define TM_CFG_CID_PRE_SCAN_ROWS_MASK 0x1FFULL 1751dbb799c3SYuval Mintz 1752dbb799c3SYuval Mintz #define TM_CFG_TID_OFFSET_SHIFT 30 1753dbb799c3SYuval Mintz #define TM_CFG_TID_OFFSET_MASK 0x7FFFFULL 1754dbb799c3SYuval Mintz #define TM_CFG_TID_PRE_SCAN_ROWS_SHIFT 49 1755dbb799c3SYuval Mintz #define TM_CFG_TID_PRE_SCAN_ROWS_MASK 0x1FFULL 1756dbb799c3SYuval Mintz 1757dbb799c3SYuval Mintz static void qed_tm_init_pf(struct qed_hwfn *p_hwfn) 1758dbb799c3SYuval Mintz { 1759dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 1760dbb799c3SYuval Mintz u32 active_seg_mask = 0, tm_offset, rt_reg; 1761dbb799c3SYuval Mintz struct qed_tm_iids tm_iids; 1762dbb799c3SYuval Mintz u64 cfg_word; 1763dbb799c3SYuval Mintz u8 i; 1764dbb799c3SYuval Mintz 1765dbb799c3SYuval Mintz memset(&tm_iids, 0, sizeof(tm_iids)); 176644531ba4SMichal Kalderon qed_cxt_tm_iids(p_hwfn, p_mngr, &tm_iids); 1767dbb799c3SYuval Mintz 1768dbb799c3SYuval Mintz /* @@@TBD No pre-scan for now */ 1769dbb799c3SYuval Mintz 1770dbb799c3SYuval Mintz /* Note: We assume consecutive VFs for a PF */ 1771dbb799c3SYuval Mintz for (i = 0; i < p_mngr->vf_count; i++) { 1772dbb799c3SYuval Mintz cfg_word = 0; 1773dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_cids); 1774dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); 1775dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id); 1776dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); 1777dbb799c3SYuval Mintz rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET + 1778dbb799c3SYuval Mintz (sizeof(cfg_word) / sizeof(u32)) * 1779dbb799c3SYuval Mintz (p_hwfn->cdev->p_iov_info->first_vf_in_pf + i); 1780dbb799c3SYuval Mintz STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); 1781dbb799c3SYuval Mintz } 1782dbb799c3SYuval Mintz 1783dbb799c3SYuval Mintz cfg_word = 0; 1784dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_cids); 1785dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); 1786dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); /* n/a for PF */ 1787dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */ 1788dbb799c3SYuval Mintz 1789dbb799c3SYuval Mintz rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET + 1790dbb799c3SYuval Mintz (sizeof(cfg_word) / sizeof(u32)) * 1791dbb799c3SYuval Mintz (NUM_OF_VFS(p_hwfn->cdev) + p_hwfn->rel_pf_id); 1792dbb799c3SYuval Mintz STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); 1793dbb799c3SYuval Mintz 1794dbb799c3SYuval Mintz /* enale scan */ 1795dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_CONN_RT_OFFSET, 1796dbb799c3SYuval Mintz tm_iids.pf_cids ? 0x1 : 0x0); 1797dbb799c3SYuval Mintz 1798dbb799c3SYuval Mintz /* @@@TBD how to enable the scan for the VFs */ 1799dbb799c3SYuval Mintz 1800dbb799c3SYuval Mintz tm_offset = tm_iids.per_vf_cids; 1801dbb799c3SYuval Mintz 1802dbb799c3SYuval Mintz /* Note: We assume consecutive VFs for a PF */ 1803dbb799c3SYuval Mintz for (i = 0; i < p_mngr->vf_count; i++) { 1804dbb799c3SYuval Mintz cfg_word = 0; 1805dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_tids); 1806dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); 1807dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id); 1808dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset); 1809dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64) 0); 1810dbb799c3SYuval Mintz 1811dbb799c3SYuval Mintz rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET + 1812dbb799c3SYuval Mintz (sizeof(cfg_word) / sizeof(u32)) * 1813dbb799c3SYuval Mintz (p_hwfn->cdev->p_iov_info->first_vf_in_pf + i); 1814dbb799c3SYuval Mintz 1815dbb799c3SYuval Mintz STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); 1816dbb799c3SYuval Mintz } 1817dbb799c3SYuval Mintz 1818dbb799c3SYuval Mintz tm_offset = tm_iids.pf_cids; 1819dbb799c3SYuval Mintz for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) { 1820dbb799c3SYuval Mintz cfg_word = 0; 1821dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_tids[i]); 1822dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0); 1823dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); 1824dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset); 1825dbb799c3SYuval Mintz SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64) 0); 1826dbb799c3SYuval Mintz 1827dbb799c3SYuval Mintz rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET + 1828dbb799c3SYuval Mintz (sizeof(cfg_word) / sizeof(u32)) * 1829dbb799c3SYuval Mintz (NUM_OF_VFS(p_hwfn->cdev) + 1830dbb799c3SYuval Mintz p_hwfn->rel_pf_id * NUM_TASK_PF_SEGMENTS + i); 1831dbb799c3SYuval Mintz 1832dbb799c3SYuval Mintz STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word); 18331a635e48SYuval Mintz active_seg_mask |= (tm_iids.pf_tids[i] ? BIT(i) : 0); 1834dbb799c3SYuval Mintz 1835dbb799c3SYuval Mintz tm_offset += tm_iids.pf_tids[i]; 1836dbb799c3SYuval Mintz } 1837dbb799c3SYuval Mintz 1838c851a9dcSKalderon, Michal if (QED_IS_RDMA_PERSONALITY(p_hwfn)) 1839dbb799c3SYuval Mintz active_seg_mask = 0; 1840dbb799c3SYuval Mintz 1841dbb799c3SYuval Mintz STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_TASK_RT_OFFSET, active_seg_mask); 1842dbb799c3SYuval Mintz 1843dbb799c3SYuval Mintz /* @@@TBD how to enable the scan for the VFs */ 1844dbb799c3SYuval Mintz } 1845dbb799c3SYuval Mintz 18461e128c81SArun Easi static void qed_prs_init_common(struct qed_hwfn *p_hwfn) 18471e128c81SArun Easi { 18481e128c81SArun Easi if ((p_hwfn->hw_info.personality == QED_PCI_FCOE) && 18491e128c81SArun Easi p_hwfn->pf_params.fcoe_pf_params.is_target) 18501e128c81SArun Easi STORE_RT_REG(p_hwfn, 18511e128c81SArun Easi PRS_REG_SEARCH_RESP_INITIATOR_TYPE_RT_OFFSET, 0); 18521e128c81SArun Easi } 18531e128c81SArun Easi 18541e128c81SArun Easi static void qed_prs_init_pf(struct qed_hwfn *p_hwfn) 18551e128c81SArun Easi { 18561e128c81SArun Easi struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 18571e128c81SArun Easi struct qed_conn_type_cfg *p_fcoe; 18581e128c81SArun Easi struct qed_tid_seg *p_tid; 18591e128c81SArun Easi 18601e128c81SArun Easi p_fcoe = &p_mngr->conn_cfg[PROTOCOLID_FCOE]; 18611e128c81SArun Easi 18621e128c81SArun Easi /* If FCoE is active set the MAX OX_ID (tid) in the Parser */ 18631e128c81SArun Easi if (!p_fcoe->cid_count) 18641e128c81SArun Easi return; 18651e128c81SArun Easi 18661e128c81SArun Easi p_tid = &p_fcoe->tid_seg[QED_CXT_FCOE_TID_SEG]; 18671e128c81SArun Easi if (p_hwfn->pf_params.fcoe_pf_params.is_target) { 18681e128c81SArun Easi STORE_RT_REG_AGG(p_hwfn, 18691e128c81SArun Easi PRS_REG_TASK_ID_MAX_TARGET_PF_RT_OFFSET, 18701e128c81SArun Easi p_tid->count); 18711e128c81SArun Easi } else { 18721e128c81SArun Easi STORE_RT_REG_AGG(p_hwfn, 18731e128c81SArun Easi PRS_REG_TASK_ID_MAX_INITIATOR_PF_RT_OFFSET, 18741e128c81SArun Easi p_tid->count); 18751e128c81SArun Easi } 18761e128c81SArun Easi } 18771e128c81SArun Easi 1878fe56b9e6SYuval Mintz void qed_cxt_hw_init_common(struct qed_hwfn *p_hwfn) 1879fe56b9e6SYuval Mintz { 1880fe56b9e6SYuval Mintz qed_cdu_init_common(p_hwfn); 18811e128c81SArun Easi qed_prs_init_common(p_hwfn); 1882fe56b9e6SYuval Mintz } 1883fe56b9e6SYuval Mintz 188415582962SRahul Verma void qed_cxt_hw_init_pf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 1885fe56b9e6SYuval Mintz { 188615582962SRahul Verma qed_qm_init_pf(p_hwfn, p_ptt); 1887fe56b9e6SYuval Mintz qed_cm_init_pf(p_hwfn); 1888fe56b9e6SYuval Mintz qed_dq_init_pf(p_hwfn); 1889dbb799c3SYuval Mintz qed_cdu_init_pf(p_hwfn); 1890fe56b9e6SYuval Mintz qed_ilt_init_pf(p_hwfn); 1891dbb799c3SYuval Mintz qed_src_init_pf(p_hwfn); 1892dbb799c3SYuval Mintz qed_tm_init_pf(p_hwfn); 18931e128c81SArun Easi qed_prs_init_pf(p_hwfn); 1894fe56b9e6SYuval Mintz } 1895fe56b9e6SYuval Mintz 18966bea61daSMintz, Yuval int _qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn, 18976bea61daSMintz, Yuval enum protocol_type type, u32 *p_cid, u8 vfid) 1898fe56b9e6SYuval Mintz { 1899fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 19006bea61daSMintz, Yuval struct qed_cid_acquired_map *p_map; 1901fe56b9e6SYuval Mintz u32 rel_cid; 1902fe56b9e6SYuval Mintz 19036bea61daSMintz, Yuval if (type >= MAX_CONN_TYPES) { 1904fe56b9e6SYuval Mintz DP_NOTICE(p_hwfn, "Invalid protocol type %d", type); 1905fe56b9e6SYuval Mintz return -EINVAL; 1906fe56b9e6SYuval Mintz } 1907fe56b9e6SYuval Mintz 19086bea61daSMintz, Yuval if (vfid >= MAX_NUM_VFS && vfid != QED_CXT_PF_CID) { 19096bea61daSMintz, Yuval DP_NOTICE(p_hwfn, "VF [%02x] is out of range\n", vfid); 19106bea61daSMintz, Yuval return -EINVAL; 19116bea61daSMintz, Yuval } 1912fe56b9e6SYuval Mintz 19136bea61daSMintz, Yuval /* Determine the right map to take this CID from */ 19146bea61daSMintz, Yuval if (vfid == QED_CXT_PF_CID) 19156bea61daSMintz, Yuval p_map = &p_mngr->acquired[type]; 19166bea61daSMintz, Yuval else 19176bea61daSMintz, Yuval p_map = &p_mngr->acquired_vf[type][vfid]; 19186bea61daSMintz, Yuval 19196bea61daSMintz, Yuval if (!p_map->cid_map) { 19206bea61daSMintz, Yuval DP_NOTICE(p_hwfn, "Invalid protocol type %d", type); 19216bea61daSMintz, Yuval return -EINVAL; 19226bea61daSMintz, Yuval } 19236bea61daSMintz, Yuval 19246bea61daSMintz, Yuval rel_cid = find_first_zero_bit(p_map->cid_map, p_map->max_count); 19256bea61daSMintz, Yuval 19266bea61daSMintz, Yuval if (rel_cid >= p_map->max_count) { 19271a635e48SYuval Mintz DP_NOTICE(p_hwfn, "no CID available for protocol %d\n", type); 1928fe56b9e6SYuval Mintz return -EINVAL; 1929fe56b9e6SYuval Mintz } 1930fe56b9e6SYuval Mintz 19316bea61daSMintz, Yuval __set_bit(rel_cid, p_map->cid_map); 1932fe56b9e6SYuval Mintz 19336bea61daSMintz, Yuval *p_cid = rel_cid + p_map->start_cid; 19346bea61daSMintz, Yuval 19356bea61daSMintz, Yuval DP_VERBOSE(p_hwfn, QED_MSG_CXT, 19366bea61daSMintz, Yuval "Acquired cid 0x%08x [rel. %08x] vfid %02x type %d\n", 19376bea61daSMintz, Yuval *p_cid, rel_cid, vfid, type); 1938fe56b9e6SYuval Mintz 1939fe56b9e6SYuval Mintz return 0; 1940fe56b9e6SYuval Mintz } 1941fe56b9e6SYuval Mintz 19426bea61daSMintz, Yuval int qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn, 19436bea61daSMintz, Yuval enum protocol_type type, u32 *p_cid) 19446bea61daSMintz, Yuval { 19456bea61daSMintz, Yuval return _qed_cxt_acquire_cid(p_hwfn, type, p_cid, QED_CXT_PF_CID); 19466bea61daSMintz, Yuval } 19476bea61daSMintz, Yuval 1948fe56b9e6SYuval Mintz static bool qed_cxt_test_cid_acquired(struct qed_hwfn *p_hwfn, 19496bea61daSMintz, Yuval u32 cid, 19506bea61daSMintz, Yuval u8 vfid, 19516bea61daSMintz, Yuval enum protocol_type *p_type, 19526bea61daSMintz, Yuval struct qed_cid_acquired_map **pp_map) 1953fe56b9e6SYuval Mintz { 1954fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 1955fe56b9e6SYuval Mintz u32 rel_cid; 1956fe56b9e6SYuval Mintz 1957fe56b9e6SYuval Mintz /* Iterate over protocols and find matching cid range */ 19586bea61daSMintz, Yuval for (*p_type = 0; *p_type < MAX_CONN_TYPES; (*p_type)++) { 19596bea61daSMintz, Yuval if (vfid == QED_CXT_PF_CID) 19606bea61daSMintz, Yuval *pp_map = &p_mngr->acquired[*p_type]; 19616bea61daSMintz, Yuval else 19626bea61daSMintz, Yuval *pp_map = &p_mngr->acquired_vf[*p_type][vfid]; 1963fe56b9e6SYuval Mintz 19646bea61daSMintz, Yuval if (!((*pp_map)->cid_map)) 1965fe56b9e6SYuval Mintz continue; 19666bea61daSMintz, Yuval if (cid >= (*pp_map)->start_cid && 19676bea61daSMintz, Yuval cid < (*pp_map)->start_cid + (*pp_map)->max_count) 1968fe56b9e6SYuval Mintz break; 1969fe56b9e6SYuval Mintz } 1970fe56b9e6SYuval Mintz 19716bea61daSMintz, Yuval if (*p_type == MAX_CONN_TYPES) { 19726bea61daSMintz, Yuval DP_NOTICE(p_hwfn, "Invalid CID %d vfid %02x", cid, vfid); 19736bea61daSMintz, Yuval goto fail; 1974fe56b9e6SYuval Mintz } 1975fe56b9e6SYuval Mintz 19766bea61daSMintz, Yuval rel_cid = cid - (*pp_map)->start_cid; 19776bea61daSMintz, Yuval if (!test_bit(rel_cid, (*pp_map)->cid_map)) { 19786bea61daSMintz, Yuval DP_NOTICE(p_hwfn, "CID %d [vifd %02x] not acquired", 19796bea61daSMintz, Yuval cid, vfid); 19806bea61daSMintz, Yuval goto fail; 1981fe56b9e6SYuval Mintz } 19826bea61daSMintz, Yuval 1983fe56b9e6SYuval Mintz return true; 19846bea61daSMintz, Yuval fail: 19856bea61daSMintz, Yuval *p_type = MAX_CONN_TYPES; 19866bea61daSMintz, Yuval *pp_map = NULL; 19876bea61daSMintz, Yuval return false; 1988fe56b9e6SYuval Mintz } 1989fe56b9e6SYuval Mintz 19906bea61daSMintz, Yuval void _qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid, u8 vfid) 1991fe56b9e6SYuval Mintz { 19926bea61daSMintz, Yuval struct qed_cid_acquired_map *p_map = NULL; 1993fe56b9e6SYuval Mintz enum protocol_type type; 1994fe56b9e6SYuval Mintz bool b_acquired; 1995fe56b9e6SYuval Mintz u32 rel_cid; 1996fe56b9e6SYuval Mintz 19976bea61daSMintz, Yuval if (vfid != QED_CXT_PF_CID && vfid > MAX_NUM_VFS) { 19986bea61daSMintz, Yuval DP_NOTICE(p_hwfn, 19996bea61daSMintz, Yuval "Trying to return incorrect CID belonging to VF %02x\n", 20006bea61daSMintz, Yuval vfid); 20016bea61daSMintz, Yuval return; 20026bea61daSMintz, Yuval } 20036bea61daSMintz, Yuval 2004fe56b9e6SYuval Mintz /* Test acquired and find matching per-protocol map */ 20056bea61daSMintz, Yuval b_acquired = qed_cxt_test_cid_acquired(p_hwfn, cid, vfid, 20066bea61daSMintz, Yuval &type, &p_map); 2007fe56b9e6SYuval Mintz 2008fe56b9e6SYuval Mintz if (!b_acquired) 2009fe56b9e6SYuval Mintz return; 2010fe56b9e6SYuval Mintz 20116bea61daSMintz, Yuval rel_cid = cid - p_map->start_cid; 20126bea61daSMintz, Yuval clear_bit(rel_cid, p_map->cid_map); 20136bea61daSMintz, Yuval 20146bea61daSMintz, Yuval DP_VERBOSE(p_hwfn, QED_MSG_CXT, 20156bea61daSMintz, Yuval "Released CID 0x%08x [rel. %08x] vfid %02x type %d\n", 20166bea61daSMintz, Yuval cid, rel_cid, vfid, type); 20176bea61daSMintz, Yuval } 20186bea61daSMintz, Yuval 20196bea61daSMintz, Yuval void qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid) 20206bea61daSMintz, Yuval { 20216bea61daSMintz, Yuval _qed_cxt_release_cid(p_hwfn, cid, QED_CXT_PF_CID); 2022fe56b9e6SYuval Mintz } 2023fe56b9e6SYuval Mintz 20241a635e48SYuval Mintz int qed_cxt_get_cid_info(struct qed_hwfn *p_hwfn, struct qed_cxt_info *p_info) 2025fe56b9e6SYuval Mintz { 2026fe56b9e6SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 20276bea61daSMintz, Yuval struct qed_cid_acquired_map *p_map = NULL; 2028fe56b9e6SYuval Mintz u32 conn_cxt_size, hw_p_size, cxts_per_p, line; 2029fe56b9e6SYuval Mintz enum protocol_type type; 2030fe56b9e6SYuval Mintz bool b_acquired; 2031fe56b9e6SYuval Mintz 2032fe56b9e6SYuval Mintz /* Test acquired and find matching per-protocol map */ 20336bea61daSMintz, Yuval b_acquired = qed_cxt_test_cid_acquired(p_hwfn, p_info->iid, 20346bea61daSMintz, Yuval QED_CXT_PF_CID, &type, &p_map); 2035fe56b9e6SYuval Mintz 2036fe56b9e6SYuval Mintz if (!b_acquired) 2037fe56b9e6SYuval Mintz return -EINVAL; 2038fe56b9e6SYuval Mintz 2039fe56b9e6SYuval Mintz /* set the protocl type */ 2040fe56b9e6SYuval Mintz p_info->type = type; 2041fe56b9e6SYuval Mintz 2042fe56b9e6SYuval Mintz /* compute context virtual pointer */ 2043fe56b9e6SYuval Mintz hw_p_size = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val; 2044fe56b9e6SYuval Mintz 2045fe56b9e6SYuval Mintz conn_cxt_size = CONN_CXT_SIZE(p_hwfn); 2046fe56b9e6SYuval Mintz cxts_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / conn_cxt_size; 2047fe56b9e6SYuval Mintz line = p_info->iid / cxts_per_p; 2048fe56b9e6SYuval Mintz 2049fe56b9e6SYuval Mintz /* Make sure context is allocated (dynamic allocation) */ 2050fe56b9e6SYuval Mintz if (!p_mngr->ilt_shadow[line].p_virt) 2051fe56b9e6SYuval Mintz return -EINVAL; 2052fe56b9e6SYuval Mintz 2053fe56b9e6SYuval Mintz p_info->p_cxt = p_mngr->ilt_shadow[line].p_virt + 2054fe56b9e6SYuval Mintz p_info->iid % cxts_per_p * conn_cxt_size; 2055fe56b9e6SYuval Mintz 2056fe56b9e6SYuval Mintz DP_VERBOSE(p_hwfn, (QED_MSG_ILT | QED_MSG_CXT), 2057fe56b9e6SYuval Mintz "Accessing ILT shadow[%d]: CXT pointer is at %p (for iid %d)\n", 2058fe56b9e6SYuval Mintz p_info->iid / cxts_per_p, p_info->p_cxt, p_info->iid); 2059fe56b9e6SYuval Mintz 2060fe56b9e6SYuval Mintz return 0; 2061fe56b9e6SYuval Mintz } 2062fe56b9e6SYuval Mintz 20638c93beafSYuval Mintz static void qed_rdma_set_pf_params(struct qed_hwfn *p_hwfn, 2064f9dc4d1fSRam Amrani struct qed_rdma_pf_params *p_params, 2065f9dc4d1fSRam Amrani u32 num_tasks) 2066dbb799c3SYuval Mintz { 2067f9dc4d1fSRam Amrani u32 num_cons, num_qps, num_srqs; 2068dbb799c3SYuval Mintz enum protocol_type proto; 2069dbb799c3SYuval Mintz 2070dbb799c3SYuval Mintz num_srqs = min_t(u32, 32 * 1024, p_params->num_srqs); 2071dbb799c3SYuval Mintz 2072e0a8f9deSMichal Kalderon if (p_hwfn->mcp_info->func_info.protocol == QED_PCI_ETH_RDMA) { 2073e0a8f9deSMichal Kalderon DP_NOTICE(p_hwfn, 2074e0a8f9deSMichal Kalderon "Current day drivers don't support RoCE & iWARP simultaneously on the same PF. Default to RoCE-only\n"); 2075e0a8f9deSMichal Kalderon p_hwfn->hw_info.personality = QED_PCI_ETH_ROCE; 2076e0a8f9deSMichal Kalderon } 2077e0a8f9deSMichal Kalderon 2078dbb799c3SYuval Mintz switch (p_hwfn->hw_info.personality) { 20795d7dc962SKalderon, Michal case QED_PCI_ETH_IWARP: 20805d7dc962SKalderon, Michal /* Each QP requires one connection */ 20815d7dc962SKalderon, Michal num_cons = min_t(u32, IWARP_MAX_QPS, p_params->num_qps); 20825d7dc962SKalderon, Michal proto = PROTOCOLID_IWARP; 20835d7dc962SKalderon, Michal break; 2084dbb799c3SYuval Mintz case QED_PCI_ETH_ROCE: 2085dbb799c3SYuval Mintz num_qps = min_t(u32, ROCE_MAX_QPS, p_params->num_qps); 2086dbb799c3SYuval Mintz num_cons = num_qps * 2; /* each QP requires two connections */ 2087dbb799c3SYuval Mintz proto = PROTOCOLID_ROCE; 2088dbb799c3SYuval Mintz break; 2089dbb799c3SYuval Mintz default: 2090dbb799c3SYuval Mintz return; 2091dbb799c3SYuval Mintz } 2092dbb799c3SYuval Mintz 2093dbb799c3SYuval Mintz if (num_cons && num_tasks) { 2094dbb799c3SYuval Mintz qed_cxt_set_proto_cid_count(p_hwfn, proto, num_cons, 0); 2095dbb799c3SYuval Mintz 2096dbb799c3SYuval Mintz /* Deliberatly passing ROCE for tasks id. This is because 2097dbb799c3SYuval Mintz * iWARP / RoCE share the task id. 2098dbb799c3SYuval Mintz */ 2099dbb799c3SYuval Mintz qed_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_ROCE, 2100dbb799c3SYuval Mintz QED_CXT_ROCE_TID_SEG, 1, 2101dbb799c3SYuval Mintz num_tasks, false); 2102dbb799c3SYuval Mintz qed_cxt_set_srq_count(p_hwfn, num_srqs); 2103dbb799c3SYuval Mintz } else { 2104dbb799c3SYuval Mintz DP_INFO(p_hwfn->cdev, 2105dbb799c3SYuval Mintz "RDMA personality used without setting params!\n"); 2106dbb799c3SYuval Mintz } 2107dbb799c3SYuval Mintz } 2108dbb799c3SYuval Mintz 2109f9dc4d1fSRam Amrani int qed_cxt_set_pf_params(struct qed_hwfn *p_hwfn, u32 rdma_tasks) 2110fe56b9e6SYuval Mintz { 2111fe56b9e6SYuval Mintz /* Set the number of required CORE connections */ 2112fe56b9e6SYuval Mintz u32 core_cids = 1; /* SPQ */ 2113fe56b9e6SYuval Mintz 21140a7fb11cSYuval Mintz if (p_hwfn->using_ll2) 21150a7fb11cSYuval Mintz core_cids += 4; 21161408cc1fSYuval Mintz qed_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_CORE, core_cids, 0); 2117fe56b9e6SYuval Mintz 2118dbb799c3SYuval Mintz switch (p_hwfn->hw_info.personality) { 21195d7dc962SKalderon, Michal case QED_PCI_ETH_RDMA: 21205d7dc962SKalderon, Michal case QED_PCI_ETH_IWARP: 2121dbb799c3SYuval Mintz case QED_PCI_ETH_ROCE: 2122dbb799c3SYuval Mintz { 2123dbb799c3SYuval Mintz qed_rdma_set_pf_params(p_hwfn, 2124dbb799c3SYuval Mintz &p_hwfn-> 2125f9dc4d1fSRam Amrani pf_params.rdma_pf_params, 2126f9dc4d1fSRam Amrani rdma_tasks); 2127dbb799c3SYuval Mintz /* no need for break since RoCE coexist with Ethernet */ 2128dbb799c3SYuval Mintz } 2129dbb799c3SYuval Mintz case QED_PCI_ETH: 2130dbb799c3SYuval Mintz { 2131dbb799c3SYuval Mintz struct qed_eth_pf_params *p_params = 2132dbb799c3SYuval Mintz &p_hwfn->pf_params.eth_pf_params; 2133dbb799c3SYuval Mintz 213408bc8f15SMintz, Yuval if (!p_params->num_vf_cons) 213508bc8f15SMintz, Yuval p_params->num_vf_cons = 213608bc8f15SMintz, Yuval ETH_PF_PARAMS_VF_CONS_DEFAULT; 2137fe56b9e6SYuval Mintz qed_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_ETH, 213808bc8f15SMintz, Yuval p_params->num_cons, 213908bc8f15SMintz, Yuval p_params->num_vf_cons); 2140d51e4af5SChopra, Manish p_hwfn->p_cxt_mngr->arfs_count = p_params->num_arfs_filters; 2141dbb799c3SYuval Mintz break; 2142dbb799c3SYuval Mintz } 21431e128c81SArun Easi case QED_PCI_FCOE: 21441e128c81SArun Easi { 21451e128c81SArun Easi struct qed_fcoe_pf_params *p_params; 21461e128c81SArun Easi 21471e128c81SArun Easi p_params = &p_hwfn->pf_params.fcoe_pf_params; 21481e128c81SArun Easi 21491e128c81SArun Easi if (p_params->num_cons && p_params->num_tasks) { 21501e128c81SArun Easi qed_cxt_set_proto_cid_count(p_hwfn, 21511e128c81SArun Easi PROTOCOLID_FCOE, 21521e128c81SArun Easi p_params->num_cons, 21531e128c81SArun Easi 0); 21541e128c81SArun Easi 21551e128c81SArun Easi qed_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_FCOE, 21561e128c81SArun Easi QED_CXT_FCOE_TID_SEG, 0, 21571e128c81SArun Easi p_params->num_tasks, true); 21581e128c81SArun Easi } else { 21591e128c81SArun Easi DP_INFO(p_hwfn->cdev, 21601e128c81SArun Easi "Fcoe personality used without setting params!\n"); 21611e128c81SArun Easi } 21621e128c81SArun Easi break; 21631e128c81SArun Easi } 2164dbb799c3SYuval Mintz case QED_PCI_ISCSI: 2165dbb799c3SYuval Mintz { 2166dbb799c3SYuval Mintz struct qed_iscsi_pf_params *p_params; 2167dbb799c3SYuval Mintz 2168dbb799c3SYuval Mintz p_params = &p_hwfn->pf_params.iscsi_pf_params; 2169dbb799c3SYuval Mintz 2170dbb799c3SYuval Mintz if (p_params->num_cons && p_params->num_tasks) { 2171dbb799c3SYuval Mintz qed_cxt_set_proto_cid_count(p_hwfn, 2172dbb799c3SYuval Mintz PROTOCOLID_ISCSI, 2173dbb799c3SYuval Mintz p_params->num_cons, 2174dbb799c3SYuval Mintz 0); 2175dbb799c3SYuval Mintz 2176dbb799c3SYuval Mintz qed_cxt_set_proto_tid_count(p_hwfn, 2177dbb799c3SYuval Mintz PROTOCOLID_ISCSI, 2178dbb799c3SYuval Mintz QED_CXT_ISCSI_TID_SEG, 2179dbb799c3SYuval Mintz 0, 2180dbb799c3SYuval Mintz p_params->num_tasks, 2181dbb799c3SYuval Mintz true); 2182dbb799c3SYuval Mintz } else { 2183dbb799c3SYuval Mintz DP_INFO(p_hwfn->cdev, 2184dbb799c3SYuval Mintz "Iscsi personality used without setting params!\n"); 2185dbb799c3SYuval Mintz } 2186dbb799c3SYuval Mintz break; 2187dbb799c3SYuval Mintz } 2188dbb799c3SYuval Mintz default: 2189dbb799c3SYuval Mintz return -EINVAL; 2190dbb799c3SYuval Mintz } 2191dbb799c3SYuval Mintz 2192dbb799c3SYuval Mintz return 0; 2193dbb799c3SYuval Mintz } 2194dbb799c3SYuval Mintz 2195dbb799c3SYuval Mintz int qed_cxt_get_tid_mem_info(struct qed_hwfn *p_hwfn, 2196dbb799c3SYuval Mintz struct qed_tid_mem *p_info) 2197dbb799c3SYuval Mintz { 2198dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 2199dbb799c3SYuval Mintz u32 proto, seg, total_lines, i, shadow_line; 2200dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_cli; 2201dbb799c3SYuval Mintz struct qed_ilt_cli_blk *p_fl_seg; 2202dbb799c3SYuval Mintz struct qed_tid_seg *p_seg_info; 2203dbb799c3SYuval Mintz 2204dbb799c3SYuval Mintz /* Verify the personality */ 2205dbb799c3SYuval Mintz switch (p_hwfn->hw_info.personality) { 22061e128c81SArun Easi case QED_PCI_FCOE: 22071e128c81SArun Easi proto = PROTOCOLID_FCOE; 22081e128c81SArun Easi seg = QED_CXT_FCOE_TID_SEG; 22091e128c81SArun Easi break; 2210dbb799c3SYuval Mintz case QED_PCI_ISCSI: 2211dbb799c3SYuval Mintz proto = PROTOCOLID_ISCSI; 2212dbb799c3SYuval Mintz seg = QED_CXT_ISCSI_TID_SEG; 2213dbb799c3SYuval Mintz break; 2214dbb799c3SYuval Mintz default: 2215dbb799c3SYuval Mintz return -EINVAL; 2216dbb799c3SYuval Mintz } 2217dbb799c3SYuval Mintz 2218dbb799c3SYuval Mintz p_cli = &p_mngr->clients[ILT_CLI_CDUT]; 2219dbb799c3SYuval Mintz if (!p_cli->active) 2220dbb799c3SYuval Mintz return -EINVAL; 2221dbb799c3SYuval Mintz 2222dbb799c3SYuval Mintz p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg]; 2223dbb799c3SYuval Mintz if (!p_seg_info->has_fl_mem) 2224dbb799c3SYuval Mintz return -EINVAL; 2225dbb799c3SYuval Mintz 2226dbb799c3SYuval Mintz p_fl_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)]; 2227dbb799c3SYuval Mintz total_lines = DIV_ROUND_UP(p_fl_seg->total_size, 2228dbb799c3SYuval Mintz p_fl_seg->real_size_in_page); 2229dbb799c3SYuval Mintz 2230dbb799c3SYuval Mintz for (i = 0; i < total_lines; i++) { 2231dbb799c3SYuval Mintz shadow_line = i + p_fl_seg->start_line - 2232dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->pf_start_line; 2233dbb799c3SYuval Mintz p_info->blocks[i] = p_mngr->ilt_shadow[shadow_line].p_virt; 2234dbb799c3SYuval Mintz } 2235dbb799c3SYuval Mintz p_info->waste = ILT_PAGE_IN_BYTES(p_cli->p_size.val) - 2236dbb799c3SYuval Mintz p_fl_seg->real_size_in_page; 2237dbb799c3SYuval Mintz p_info->tid_size = p_mngr->task_type_size[p_seg_info->type]; 2238dbb799c3SYuval Mintz p_info->num_tids_per_block = p_fl_seg->real_size_in_page / 2239dbb799c3SYuval Mintz p_info->tid_size; 2240dbb799c3SYuval Mintz 2241dbb799c3SYuval Mintz return 0; 2242dbb799c3SYuval Mintz } 2243dbb799c3SYuval Mintz 2244dbb799c3SYuval Mintz /* This function is very RoCE oriented, if another protocol in the future 2245dbb799c3SYuval Mintz * will want this feature we'll need to modify the function to be more generic 2246dbb799c3SYuval Mintz */ 2247dbb799c3SYuval Mintz int 2248dbb799c3SYuval Mintz qed_cxt_dynamic_ilt_alloc(struct qed_hwfn *p_hwfn, 2249dbb799c3SYuval Mintz enum qed_cxt_elem_type elem_type, u32 iid) 2250dbb799c3SYuval Mintz { 2251dbb799c3SYuval Mintz u32 reg_offset, shadow_line, elem_size, hw_p_size, elems_per_p, line; 2252dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_cli; 2253dbb799c3SYuval Mintz struct qed_ilt_cli_blk *p_blk; 2254dbb799c3SYuval Mintz struct qed_ptt *p_ptt; 2255dbb799c3SYuval Mintz dma_addr_t p_phys; 2256dbb799c3SYuval Mintz u64 ilt_hw_entry; 2257dbb799c3SYuval Mintz void *p_virt; 2258dbb799c3SYuval Mintz int rc = 0; 2259dbb799c3SYuval Mintz 2260dbb799c3SYuval Mintz switch (elem_type) { 2261dbb799c3SYuval Mintz case QED_ELEM_CXT: 2262dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; 2263dbb799c3SYuval Mintz elem_size = CONN_CXT_SIZE(p_hwfn); 2264dbb799c3SYuval Mintz p_blk = &p_cli->pf_blks[CDUC_BLK]; 2265dbb799c3SYuval Mintz break; 2266dbb799c3SYuval Mintz case QED_ELEM_SRQ: 2267dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM]; 2268dbb799c3SYuval Mintz elem_size = SRQ_CXT_SIZE; 2269dbb799c3SYuval Mintz p_blk = &p_cli->pf_blks[SRQ_BLK]; 2270dbb799c3SYuval Mintz break; 2271dbb799c3SYuval Mintz case QED_ELEM_TASK: 2272dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; 2273dbb799c3SYuval Mintz elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn); 2274dbb799c3SYuval Mintz p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(QED_CXT_ROCE_TID_SEG)]; 2275dbb799c3SYuval Mintz break; 2276dbb799c3SYuval Mintz default: 2277dbb799c3SYuval Mintz DP_NOTICE(p_hwfn, "-EINVALID elem type = %d", elem_type); 2278dbb799c3SYuval Mintz return -EINVAL; 2279dbb799c3SYuval Mintz } 2280dbb799c3SYuval Mintz 2281dbb799c3SYuval Mintz /* Calculate line in ilt */ 2282dbb799c3SYuval Mintz hw_p_size = p_cli->p_size.val; 2283dbb799c3SYuval Mintz elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size; 2284dbb799c3SYuval Mintz line = p_blk->start_line + (iid / elems_per_p); 2285dbb799c3SYuval Mintz shadow_line = line - p_hwfn->p_cxt_mngr->pf_start_line; 2286dbb799c3SYuval Mintz 2287dbb799c3SYuval Mintz /* If line is already allocated, do nothing, otherwise allocate it and 2288dbb799c3SYuval Mintz * write it to the PSWRQ2 registers. 2289dbb799c3SYuval Mintz * This section can be run in parallel from different contexts and thus 2290dbb799c3SYuval Mintz * a mutex protection is needed. 2291dbb799c3SYuval Mintz */ 2292dbb799c3SYuval Mintz 2293dbb799c3SYuval Mintz mutex_lock(&p_hwfn->p_cxt_mngr->mutex); 2294dbb799c3SYuval Mintz 2295dbb799c3SYuval Mintz if (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt) 2296dbb799c3SYuval Mintz goto out0; 2297dbb799c3SYuval Mintz 2298dbb799c3SYuval Mintz p_ptt = qed_ptt_acquire(p_hwfn); 2299dbb799c3SYuval Mintz if (!p_ptt) { 2300dbb799c3SYuval Mintz DP_NOTICE(p_hwfn, 2301dbb799c3SYuval Mintz "QED_TIME_OUT on ptt acquire - dynamic allocation"); 2302dbb799c3SYuval Mintz rc = -EBUSY; 2303dbb799c3SYuval Mintz goto out0; 2304dbb799c3SYuval Mintz } 2305dbb799c3SYuval Mintz 2306dbb799c3SYuval Mintz p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, 2307dbb799c3SYuval Mintz p_blk->real_size_in_page, 2308dbb799c3SYuval Mintz &p_phys, GFP_KERNEL); 2309dbb799c3SYuval Mintz if (!p_virt) { 2310dbb799c3SYuval Mintz rc = -ENOMEM; 2311dbb799c3SYuval Mintz goto out1; 2312dbb799c3SYuval Mintz } 2313dbb799c3SYuval Mintz memset(p_virt, 0, p_blk->real_size_in_page); 2314dbb799c3SYuval Mintz 2315dbb799c3SYuval Mintz /* configuration of refTagMask to 0xF is required for RoCE DIF MR only, 2316dbb799c3SYuval Mintz * to compensate for a HW bug, but it is configured even if DIF is not 2317dbb799c3SYuval Mintz * enabled. This is harmless and allows us to avoid a dedicated API. We 2318dbb799c3SYuval Mintz * configure the field for all of the contexts on the newly allocated 2319dbb799c3SYuval Mintz * page. 2320dbb799c3SYuval Mintz */ 2321dbb799c3SYuval Mintz if (elem_type == QED_ELEM_TASK) { 2322dbb799c3SYuval Mintz u32 elem_i; 2323dbb799c3SYuval Mintz u8 *elem_start = (u8 *)p_virt; 2324dbb799c3SYuval Mintz union type1_task_context *elem; 2325dbb799c3SYuval Mintz 2326dbb799c3SYuval Mintz for (elem_i = 0; elem_i < elems_per_p; elem_i++) { 2327dbb799c3SYuval Mintz elem = (union type1_task_context *)elem_start; 2328dbb799c3SYuval Mintz SET_FIELD(elem->roce_ctx.tdif_context.flags1, 2329a2e7699eSTomer Tayar TDIF_TASK_CONTEXT_REF_TAG_MASK, 0xf); 2330dbb799c3SYuval Mintz elem_start += TYPE1_TASK_CXT_SIZE(p_hwfn); 2331dbb799c3SYuval Mintz } 2332dbb799c3SYuval Mintz } 2333dbb799c3SYuval Mintz 2334dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt = p_virt; 2335dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys = p_phys; 2336dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].size = 2337dbb799c3SYuval Mintz p_blk->real_size_in_page; 2338dbb799c3SYuval Mintz 2339dbb799c3SYuval Mintz /* compute absolute offset */ 2340dbb799c3SYuval Mintz reg_offset = PSWRQ2_REG_ILT_MEMORY + 2341dbb799c3SYuval Mintz (line * ILT_REG_SIZE_IN_BYTES * ILT_ENTRY_IN_REGS); 2342dbb799c3SYuval Mintz 2343dbb799c3SYuval Mintz ilt_hw_entry = 0; 2344dbb799c3SYuval Mintz SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL); 2345dbb799c3SYuval Mintz SET_FIELD(ilt_hw_entry, 2346dbb799c3SYuval Mintz ILT_ENTRY_PHY_ADDR, 2347dbb799c3SYuval Mintz (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys >> 12)); 2348dbb799c3SYuval Mintz 2349dbb799c3SYuval Mintz /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a wide-bus */ 2350dbb799c3SYuval Mintz qed_dmae_host2grc(p_hwfn, p_ptt, (u64) (uintptr_t)&ilt_hw_entry, 2351dbb799c3SYuval Mintz reg_offset, sizeof(ilt_hw_entry) / sizeof(u32), 0); 2352dbb799c3SYuval Mintz 2353dbb799c3SYuval Mintz if (elem_type == QED_ELEM_CXT) { 2354dbb799c3SYuval Mintz u32 last_cid_allocated = (1 + (iid / elems_per_p)) * 2355dbb799c3SYuval Mintz elems_per_p; 2356dbb799c3SYuval Mintz 2357dbb799c3SYuval Mintz /* Update the relevant register in the parser */ 2358dbb799c3SYuval Mintz qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 2359dbb799c3SYuval Mintz last_cid_allocated - 1); 2360dbb799c3SYuval Mintz 2361dbb799c3SYuval Mintz if (!p_hwfn->b_rdma_enabled_in_prs) { 2362c851a9dcSKalderon, Michal /* Enable RDMA search */ 2363dbb799c3SYuval Mintz qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1); 2364dbb799c3SYuval Mintz p_hwfn->b_rdma_enabled_in_prs = true; 2365dbb799c3SYuval Mintz } 2366dbb799c3SYuval Mintz } 2367dbb799c3SYuval Mintz 2368dbb799c3SYuval Mintz out1: 2369dbb799c3SYuval Mintz qed_ptt_release(p_hwfn, p_ptt); 2370dbb799c3SYuval Mintz out0: 2371dbb799c3SYuval Mintz mutex_unlock(&p_hwfn->p_cxt_mngr->mutex); 2372dbb799c3SYuval Mintz 2373dbb799c3SYuval Mintz return rc; 2374dbb799c3SYuval Mintz } 2375dbb799c3SYuval Mintz 2376dbb799c3SYuval Mintz /* This function is very RoCE oriented, if another protocol in the future 2377dbb799c3SYuval Mintz * will want this feature we'll need to modify the function to be more generic 2378dbb799c3SYuval Mintz */ 2379dbb799c3SYuval Mintz static int 2380dbb799c3SYuval Mintz qed_cxt_free_ilt_range(struct qed_hwfn *p_hwfn, 2381dbb799c3SYuval Mintz enum qed_cxt_elem_type elem_type, 2382dbb799c3SYuval Mintz u32 start_iid, u32 count) 2383dbb799c3SYuval Mintz { 2384dbb799c3SYuval Mintz u32 start_line, end_line, shadow_start_line, shadow_end_line; 2385dbb799c3SYuval Mintz u32 reg_offset, elem_size, hw_p_size, elems_per_p; 2386dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_cli; 2387dbb799c3SYuval Mintz struct qed_ilt_cli_blk *p_blk; 2388dbb799c3SYuval Mintz u32 end_iid = start_iid + count; 2389dbb799c3SYuval Mintz struct qed_ptt *p_ptt; 2390dbb799c3SYuval Mintz u64 ilt_hw_entry = 0; 2391dbb799c3SYuval Mintz u32 i; 2392dbb799c3SYuval Mintz 2393dbb799c3SYuval Mintz switch (elem_type) { 2394dbb799c3SYuval Mintz case QED_ELEM_CXT: 2395dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC]; 2396dbb799c3SYuval Mintz elem_size = CONN_CXT_SIZE(p_hwfn); 2397dbb799c3SYuval Mintz p_blk = &p_cli->pf_blks[CDUC_BLK]; 2398dbb799c3SYuval Mintz break; 2399dbb799c3SYuval Mintz case QED_ELEM_SRQ: 2400dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM]; 2401dbb799c3SYuval Mintz elem_size = SRQ_CXT_SIZE; 2402dbb799c3SYuval Mintz p_blk = &p_cli->pf_blks[SRQ_BLK]; 2403dbb799c3SYuval Mintz break; 2404dbb799c3SYuval Mintz case QED_ELEM_TASK: 2405dbb799c3SYuval Mintz p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT]; 2406dbb799c3SYuval Mintz elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn); 2407dbb799c3SYuval Mintz p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(QED_CXT_ROCE_TID_SEG)]; 2408dbb799c3SYuval Mintz break; 2409dbb799c3SYuval Mintz default: 2410dbb799c3SYuval Mintz DP_NOTICE(p_hwfn, "-EINVALID elem type = %d", elem_type); 2411dbb799c3SYuval Mintz return -EINVAL; 2412dbb799c3SYuval Mintz } 2413dbb799c3SYuval Mintz 2414dbb799c3SYuval Mintz /* Calculate line in ilt */ 2415dbb799c3SYuval Mintz hw_p_size = p_cli->p_size.val; 2416dbb799c3SYuval Mintz elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size; 2417dbb799c3SYuval Mintz start_line = p_blk->start_line + (start_iid / elems_per_p); 2418dbb799c3SYuval Mintz end_line = p_blk->start_line + (end_iid / elems_per_p); 2419dbb799c3SYuval Mintz if (((end_iid + 1) / elems_per_p) != (end_iid / elems_per_p)) 2420dbb799c3SYuval Mintz end_line--; 2421dbb799c3SYuval Mintz 2422dbb799c3SYuval Mintz shadow_start_line = start_line - p_hwfn->p_cxt_mngr->pf_start_line; 2423dbb799c3SYuval Mintz shadow_end_line = end_line - p_hwfn->p_cxt_mngr->pf_start_line; 2424dbb799c3SYuval Mintz 2425dbb799c3SYuval Mintz p_ptt = qed_ptt_acquire(p_hwfn); 2426dbb799c3SYuval Mintz if (!p_ptt) { 2427dbb799c3SYuval Mintz DP_NOTICE(p_hwfn, 2428dbb799c3SYuval Mintz "QED_TIME_OUT on ptt acquire - dynamic allocation"); 2429dbb799c3SYuval Mintz return -EBUSY; 2430dbb799c3SYuval Mintz } 2431dbb799c3SYuval Mintz 2432dbb799c3SYuval Mintz for (i = shadow_start_line; i < shadow_end_line; i++) { 2433dbb799c3SYuval Mintz if (!p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt) 2434dbb799c3SYuval Mintz continue; 2435dbb799c3SYuval Mintz 2436dbb799c3SYuval Mintz dma_free_coherent(&p_hwfn->cdev->pdev->dev, 2437dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[i].size, 2438dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt, 2439dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys); 2440dbb799c3SYuval Mintz 2441dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt = NULL; 2442dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys = 0; 2443dbb799c3SYuval Mintz p_hwfn->p_cxt_mngr->ilt_shadow[i].size = 0; 2444dbb799c3SYuval Mintz 2445dbb799c3SYuval Mintz /* compute absolute offset */ 2446dbb799c3SYuval Mintz reg_offset = PSWRQ2_REG_ILT_MEMORY + 2447dbb799c3SYuval Mintz ((start_line++) * ILT_REG_SIZE_IN_BYTES * 2448dbb799c3SYuval Mintz ILT_ENTRY_IN_REGS); 2449dbb799c3SYuval Mintz 2450dbb799c3SYuval Mintz /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a 2451dbb799c3SYuval Mintz * wide-bus. 2452dbb799c3SYuval Mintz */ 2453dbb799c3SYuval Mintz qed_dmae_host2grc(p_hwfn, p_ptt, 2454dbb799c3SYuval Mintz (u64) (uintptr_t) &ilt_hw_entry, 2455dbb799c3SYuval Mintz reg_offset, 2456dbb799c3SYuval Mintz sizeof(ilt_hw_entry) / sizeof(u32), 2457dbb799c3SYuval Mintz 0); 2458dbb799c3SYuval Mintz } 2459dbb799c3SYuval Mintz 2460dbb799c3SYuval Mintz qed_ptt_release(p_hwfn, p_ptt); 2461dbb799c3SYuval Mintz 2462dbb799c3SYuval Mintz return 0; 2463dbb799c3SYuval Mintz } 2464dbb799c3SYuval Mintz 2465dbb799c3SYuval Mintz int qed_cxt_free_proto_ilt(struct qed_hwfn *p_hwfn, enum protocol_type proto) 2466dbb799c3SYuval Mintz { 2467dbb799c3SYuval Mintz int rc; 2468dbb799c3SYuval Mintz u32 cid; 2469dbb799c3SYuval Mintz 2470dbb799c3SYuval Mintz /* Free Connection CXT */ 2471dbb799c3SYuval Mintz rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_CXT, 2472dbb799c3SYuval Mintz qed_cxt_get_proto_cid_start(p_hwfn, 2473dbb799c3SYuval Mintz proto), 2474dbb799c3SYuval Mintz qed_cxt_get_proto_cid_count(p_hwfn, 2475dbb799c3SYuval Mintz proto, &cid)); 2476dbb799c3SYuval Mintz 2477dbb799c3SYuval Mintz if (rc) 2478dbb799c3SYuval Mintz return rc; 2479dbb799c3SYuval Mintz 2480dbb799c3SYuval Mintz /* Free Task CXT */ 2481dbb799c3SYuval Mintz rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_TASK, 0, 2482dbb799c3SYuval Mintz qed_cxt_get_proto_tid_count(p_hwfn, proto)); 2483dbb799c3SYuval Mintz if (rc) 2484dbb799c3SYuval Mintz return rc; 2485dbb799c3SYuval Mintz 2486dbb799c3SYuval Mintz /* Free TSDM CXT */ 2487dbb799c3SYuval Mintz rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_SRQ, 0, 2488dbb799c3SYuval Mintz qed_cxt_get_srq_count(p_hwfn)); 2489dbb799c3SYuval Mintz 2490dbb799c3SYuval Mintz return rc; 2491dbb799c3SYuval Mintz } 2492dbb799c3SYuval Mintz 2493dbb799c3SYuval Mintz int qed_cxt_get_task_ctx(struct qed_hwfn *p_hwfn, 2494dbb799c3SYuval Mintz u32 tid, u8 ctx_type, void **pp_task_ctx) 2495dbb799c3SYuval Mintz { 2496dbb799c3SYuval Mintz struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; 2497dbb799c3SYuval Mintz struct qed_ilt_client_cfg *p_cli; 2498dbb799c3SYuval Mintz struct qed_tid_seg *p_seg_info; 24991e128c81SArun Easi struct qed_ilt_cli_blk *p_seg; 2500dbb799c3SYuval Mintz u32 num_tids_per_block; 25011e128c81SArun Easi u32 tid_size, ilt_idx; 25021e128c81SArun Easi u32 total_lines; 25031e128c81SArun Easi u32 proto, seg; 2504dbb799c3SYuval Mintz 2505dbb799c3SYuval Mintz /* Verify the personality */ 2506dbb799c3SYuval Mintz switch (p_hwfn->hw_info.personality) { 25071e128c81SArun Easi case QED_PCI_FCOE: 25081e128c81SArun Easi proto = PROTOCOLID_FCOE; 25091e128c81SArun Easi seg = QED_CXT_FCOE_TID_SEG; 25101e128c81SArun Easi break; 2511dbb799c3SYuval Mintz case QED_PCI_ISCSI: 2512dbb799c3SYuval Mintz proto = PROTOCOLID_ISCSI; 2513dbb799c3SYuval Mintz seg = QED_CXT_ISCSI_TID_SEG; 2514dbb799c3SYuval Mintz break; 2515dbb799c3SYuval Mintz default: 2516dbb799c3SYuval Mintz return -EINVAL; 2517dbb799c3SYuval Mintz } 2518dbb799c3SYuval Mintz 2519dbb799c3SYuval Mintz p_cli = &p_mngr->clients[ILT_CLI_CDUT]; 2520dbb799c3SYuval Mintz if (!p_cli->active) 2521dbb799c3SYuval Mintz return -EINVAL; 2522dbb799c3SYuval Mintz 2523dbb799c3SYuval Mintz p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg]; 2524dbb799c3SYuval Mintz 2525dbb799c3SYuval Mintz if (ctx_type == QED_CTX_WORKING_MEM) { 2526dbb799c3SYuval Mintz p_seg = &p_cli->pf_blks[CDUT_SEG_BLK(seg)]; 2527dbb799c3SYuval Mintz } else if (ctx_type == QED_CTX_FL_MEM) { 2528dbb799c3SYuval Mintz if (!p_seg_info->has_fl_mem) 2529dbb799c3SYuval Mintz return -EINVAL; 2530dbb799c3SYuval Mintz p_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)]; 2531dbb799c3SYuval Mintz } else { 2532dbb799c3SYuval Mintz return -EINVAL; 2533dbb799c3SYuval Mintz } 2534dbb799c3SYuval Mintz total_lines = DIV_ROUND_UP(p_seg->total_size, p_seg->real_size_in_page); 2535dbb799c3SYuval Mintz tid_size = p_mngr->task_type_size[p_seg_info->type]; 2536dbb799c3SYuval Mintz num_tids_per_block = p_seg->real_size_in_page / tid_size; 2537dbb799c3SYuval Mintz 2538dbb799c3SYuval Mintz if (total_lines < tid / num_tids_per_block) 2539dbb799c3SYuval Mintz return -EINVAL; 2540dbb799c3SYuval Mintz 2541dbb799c3SYuval Mintz ilt_idx = tid / num_tids_per_block + p_seg->start_line - 2542dbb799c3SYuval Mintz p_mngr->pf_start_line; 2543dbb799c3SYuval Mintz *pp_task_ctx = (u8 *)p_mngr->ilt_shadow[ilt_idx].p_virt + 2544dbb799c3SYuval Mintz (tid % num_tids_per_block) * tid_size; 2545fe56b9e6SYuval Mintz 2546fe56b9e6SYuval Mintz return 0; 2547fe56b9e6SYuval Mintz } 2548