From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EB398A04C1; Wed, 20 Nov 2019 04:48:55 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 57B971BE95; Wed, 20 Nov 2019 04:48:26 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 7A9CB1BE91 for ; Wed, 20 Nov 2019 04:48:24 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xAK3jThk022968 for ; Tue, 19 Nov 2019 19:48:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=ChvK1plukAa61xnj/Lpsvof+0XkODuxHmsPR3S+wEkI=; b=YLKg8FwuLb5gC+X9GkD+2xC2U8G3dnbcX2UGi2jZpgHlrXLm/eV7GeTIoXgwfq64yRim kcf6OdNfn/VtUv0ihXte1d1AUBI/ZIaRfWLpZAJB2bhhLpLNOJM+BJJgz3k1DRDVCTTx cSjgRFps5lWbDRt/Ka5DSAFg2mXVYA+PXK5iBjpCpK/4DT9i3/Nf/fTZvONLTR5o1dU5 m+sKYO+rW7VVQ1x3f6dcmwvHoMvEbpxj6d1VanFuXq90JjqAzSqXG+B+6r0GrewJFnts cg0gkk3Fm0Bv0kziAJ2EQ5QVlS6jMMKj3W0ejpL+kxyG2jPh/ssrQABUnCv4oksP6EFK 2Q== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 2wc82vnp3a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 19 Nov 2019 19:48:23 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 19 Nov 2019 19:48:22 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 19 Nov 2019 19:48:22 -0800 Received: from BG-LT7430.marvell.com (unknown [10.28.17.72]) by maili.marvell.com (Postfix) with ESMTP id ACC8A3F703F; Tue, 19 Nov 2019 19:48:20 -0800 (PST) From: To: CC: , Pavan Nikhilesh Date: Wed, 20 Nov 2019 09:18:05 +0530 Message-ID: <20191120034808.2760-5-pbhagavatula@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191120034808.2760-1-pbhagavatula@marvell.com> References: <20191120034808.2760-1-pbhagavatula@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-19_08:2019-11-15,2019-11-19 signatures=0 Subject: [dpdk-dev] [PATCH v2 4/6] mempool/octeontx: add application domain validation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Pavan Nikhilesh Add application domain validation for OCTEON TX FPA vfs. Signed-off-by: Pavan Nikhilesh --- drivers/mempool/octeontx/octeontx_fpavf.c | 86 +++++++++++++++-------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/drivers/mempool/octeontx/octeontx_fpavf.c b/drivers/mempool/octeontx/octeontx_fpavf.c index ec84a5cff..c97267db3 100644 --- a/drivers/mempool/octeontx/octeontx_fpavf.c +++ b/drivers/mempool/octeontx/octeontx_fpavf.c @@ -119,20 +119,22 @@ RTE_INIT(otx_pool_init_log) static int octeontx_fpa_gpool_alloc(unsigned int object_size) { + uint16_t global_domain = octeontx_get_global_domain(); struct fpavf_res *res = NULL; - uint16_t gpool; unsigned int sz128; + int i; sz128 = FPA_OBJSZ_2_CACHE_LINE(object_size); - for (gpool = 0; gpool < FPA_VF_MAX; gpool++) { + for (i = 0; i < FPA_VF_MAX; i++) { /* Skip VF that is not mapped Or _inuse */ - if ((fpadev.pool[gpool].bar0 == NULL) || - (fpadev.pool[gpool].is_inuse == true)) + if ((fpadev.pool[i].bar0 == NULL) || + (fpadev.pool[i].is_inuse == true) || + (fpadev.pool[i].domain_id != global_domain)) continue; - res = &fpadev.pool[gpool]; + res = &fpadev.pool[i]; RTE_ASSERT(res->domain_id != (uint16_t)~0); RTE_ASSERT(res->vf_id != (uint16_t)~0); @@ -140,15 +142,34 @@ octeontx_fpa_gpool_alloc(unsigned int object_size) if (res->sz128 == 0) { res->sz128 = sz128; + fpavf_log_dbg("gpool %d blk_sz %d\n", res->vf_id, + sz128); - fpavf_log_dbg("gpool %d blk_sz %d\n", gpool, sz128); - return gpool; + return res->vf_id; } } return -ENOSPC; } +static __rte_always_inline struct fpavf_res * +octeontx_get_fpavf(uint16_t gpool) +{ + uint16_t global_domain = octeontx_get_global_domain(); + int i; + + for (i = 0; i < FPA_VF_MAX; i++) { + if (fpadev.pool[i].domain_id != global_domain) + continue; + if (fpadev.pool[i].vf_id != gpool) + continue; + + return &fpadev.pool[i]; + } + + return NULL; +} + /* lock is taken by caller */ static __rte_always_inline uintptr_t octeontx_fpa_gpool2handle(uint16_t gpool) @@ -156,8 +177,10 @@ octeontx_fpa_gpool2handle(uint16_t gpool) struct fpavf_res *res = NULL; RTE_ASSERT(gpool < FPA_VF_MAX); + res = octeontx_get_fpavf(gpool); + if (res == NULL) + return 0; - res = &fpadev.pool[gpool]; return (uintptr_t)res->bar0 | gpool; } @@ -182,7 +205,7 @@ octeontx_fpa_handle_valid(uintptr_t handle) continue; /* validate gpool */ - if (gpool != i) + if (gpool != fpadev.pool[i].vf_id) return false; res = &fpadev.pool[i]; @@ -212,7 +235,10 @@ octeontx_fpapf_pool_setup(unsigned int gpool, unsigned int buf_size, struct octeontx_mbox_fpa_cfg cfg; int ret = -1; - fpa = &fpadev.pool[gpool]; + fpa = octeontx_get_fpavf(gpool); + if (fpa == NULL) + return -EINVAL; + memsz = FPA_ROUND_UP(max_buf_count / fpa->stack_ln_ptr, FPA_LN_SIZE) * FPA_LN_SIZE; @@ -278,7 +304,11 @@ octeontx_fpapf_pool_destroy(unsigned int gpool_index) struct fpavf_res *fpa = NULL; int ret = -1; - fpa = &fpadev.pool[gpool_index]; + fpa = octeontx_get_fpavf(gpool_index); + if (fpa == NULL) { + ret = -EINVAL; + goto err; + } hdr.coproc = FPA_COPROC; hdr.msg = FPA_CONFIGSET; @@ -422,6 +452,7 @@ octeontx_fpapf_start_count(uint16_t gpool_index) static __rte_always_inline int octeontx_fpavf_free(unsigned int gpool) { + struct fpavf_res *res = octeontx_get_fpavf(gpool); int ret = 0; if (gpool >= FPA_MAX_POOL) { @@ -430,7 +461,8 @@ octeontx_fpavf_free(unsigned int gpool) } /* Pool is free */ - fpadev.pool[gpool].is_inuse = false; + if (res != NULL) + res->is_inuse = false; err: return ret; @@ -439,8 +471,10 @@ octeontx_fpavf_free(unsigned int gpool) static __rte_always_inline int octeontx_gpool_free(uint16_t gpool) { - if (fpadev.pool[gpool].sz128 != 0) { - fpadev.pool[gpool].sz128 = 0; + struct fpavf_res *res = octeontx_get_fpavf(gpool); + + if (res && res->sz128 != 0) { + res->sz128 = 0; return 0; } return -EINVAL; @@ -460,8 +494,8 @@ octeontx_fpa_bufpool_block_size(uintptr_t handle) /* get the gpool */ gpool = octeontx_fpa_bufpool_gpool(handle); - res = &fpadev.pool[gpool]; - return FPA_CACHE_LINE_2_OBJSZ(res->sz128); + res = octeontx_get_fpavf(gpool); + return res ? FPA_CACHE_LINE_2_OBJSZ(res->sz128) : 0; } int @@ -722,6 +756,7 @@ octeontx_fpavf_identify(void *bar0) uint16_t domain_id; uint16_t vf_id; uint64_t stack_ln_ptr; + static uint16_t vf_idx; val = fpavf_read64((void *)((uintptr_t)bar0 + FPA_VF_VHAURA_CNT_THRESHOLD(0))); @@ -731,23 +766,18 @@ octeontx_fpavf_identify(void *bar0) stack_ln_ptr = fpavf_read64((void *)((uintptr_t)bar0 + FPA_VF_VHPOOL_THRESHOLD(0))); - if (vf_id >= FPA_VF_MAX) { + if (vf_idx >= FPA_VF_MAX) { fpavf_log_err("vf_id(%d) greater than max vf (32)\n", vf_id); - return -1; - } - - if (fpadev.pool[vf_id].is_inuse) { - fpavf_log_err("vf_id %d is_inuse\n", vf_id); - return -1; + return -E2BIG; } - fpadev.pool[vf_id].domain_id = domain_id; - fpadev.pool[vf_id].vf_id = vf_id; - fpadev.pool[vf_id].bar0 = bar0; - fpadev.pool[vf_id].stack_ln_ptr = stack_ln_ptr; + fpadev.pool[vf_idx].domain_id = domain_id; + fpadev.pool[vf_idx].vf_id = vf_id; + fpadev.pool[vf_idx].bar0 = bar0; + fpadev.pool[vf_idx].stack_ln_ptr = stack_ln_ptr; /* SUCCESS */ - return vf_id; + return vf_idx++; } /* FPAVF pcie device aka mempool probe */ -- 2.17.1