From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 89A5A42B7D; Tue, 23 May 2023 12:55:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3FD4F40A80; Tue, 23 May 2023 12:55:20 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 1A98E40689 for ; Tue, 23 May 2023 12:55:18 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N1lDSi030947 for ; Tue, 23 May 2023 03:55:18 -0700 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=pfpt0220; bh=bTdDlunJIK8LakzZadxuRIfbydy0uJ/b528pon9A9FI=; b=AH+Ux3K3Iw8qyoSChDHZaO8OkdU3aoCUR2KQV8LpPKHCqUtOExh3W8/5LMt/H0gGNpQd fMdUG9T4AYSpPomwNA1jKnBbuT0RKVN95SvBuJ38J1p15H8t/iApGlWeWj/BiTxYS6a/ ttsHCyxRBivdsYSyvBud7Qy10nxMVlMyR2QInltrF5KRL8xJq/+VjEuBQxu4jOgzmse7 BX8kHfxuNi1wryGPXssGP3n0AeyI9/jOSeEScJLeUSX4cc95JqIDGi0QthcLnojjazMo gFSFpVpIWUAonuFd/iCOumzpKEXykFR9RcPJ1/BChzS8ShpQVg6kVmvf/OBpM2JVps/z iA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qrm46hsph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 23 May 2023 03:55:18 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 23 May 2023 03:55:16 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Tue, 23 May 2023 03:55:16 -0700 Received: from localhost.localdomain (unknown [10.28.36.142]) by maili.marvell.com (Postfix) with ESMTP id 882B83F7074; Tue, 23 May 2023 03:55:12 -0700 (PDT) From: Ashwin Sekhar T K To: , Ashwin Sekhar T K , Pavan Nikhilesh CC: , , , , , , , , Subject: [PATCH v2 4/5] mempool/cnxk: add hwpool ops Date: Tue, 23 May 2023 16:24:32 +0530 Message-ID: <20230523105433.719998-4-asekhar@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230523105433.719998-1-asekhar@marvell.com> References: <20230411075528.1125799-1-asekhar@marvell.com> <20230523105433.719998-1-asekhar@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: DF5R8RnUMb-7eQqAIouVzz0UuZ6SnvYX X-Proofpoint-GUID: DF5R8RnUMb-7eQqAIouVzz0UuZ6SnvYX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_06,2023-05-23_02,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add hwpool ops which can used to create a rte_mempool that attaches to another rte_mempool. The hwpool will not have its own buffers and will have a dummy populate callback. Only an NPA aura will be allocated for this rte_mempool. The buffers will be allocate from the NPA pool of the attached rte_mempool. Only mbuf objects are supported in hwpool. Generic objects are not supported. Note that this pool will not have any range check enabled. So user will be able to free any pointer into this pool. HW will not throw error interrupts if invalid buffers are passed. So user must be careful when using this pool. Signed-off-by: Ashwin Sekhar T K --- drivers/mempool/cnxk/cn10k_hwpool_ops.c | 211 ++++++++++++++++++++++++ drivers/mempool/cnxk/cnxk_mempool.h | 4 + drivers/mempool/cnxk/meson.build | 1 + 3 files changed, 216 insertions(+) create mode 100644 drivers/mempool/cnxk/cn10k_hwpool_ops.c diff --git a/drivers/mempool/cnxk/cn10k_hwpool_ops.c b/drivers/mempool/cnxk/cn10k_hwpool_ops.c new file mode 100644 index 0000000000..9238765155 --- /dev/null +++ b/drivers/mempool/cnxk/cn10k_hwpool_ops.c @@ -0,0 +1,211 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell. + */ + +#include + +#include "roc_api.h" +#include "cnxk_mempool.h" + +#define CN10K_HWPOOL_MEM_SIZE 128 + +static int __rte_hot +cn10k_hwpool_enq(struct rte_mempool *hp, void *const *obj_table, unsigned int n) +{ + struct rte_mempool *mp; + unsigned int index; + + mp = CNXK_MEMPOOL_CONFIG(hp); + /* Ensure mbuf init changes are written before the free pointers + * are enqueued to the stack. + */ + rte_io_wmb(); + for (index = 0; index < n; index++) { + struct rte_mempool_objhdr *hdr; + struct rte_mbuf *m; + + m = PLT_PTR_CAST(obj_table[index]); + /* Update mempool information in the mbuf */ + hdr = rte_mempool_get_header(obj_table[index]); +#ifdef RTE_LIBRTE_MEMPOOL_DEBUG + if (hdr->mp != m->pool || hdr->mp != hp) + plt_err("Pool Header Mismatch"); +#endif + m->pool = mp; + hdr->mp = mp; + roc_npa_aura_op_free(hp->pool_id, 0, + (uint64_t)obj_table[index]); + } + + return 0; +} + +static int __rte_hot +cn10k_hwpool_deq(struct rte_mempool *hp, void **obj_table, unsigned int n) +{ + unsigned int index; + uint64_t obj; +#ifdef RTE_LIBRTE_MEMPOOL_DEBUG + struct rte_mempool *mp; + + mp = CNXK_MEMPOOL_CONFIG(hp); +#endif + + for (index = 0; index < n; index++, obj_table++) { + struct rte_mempool_objhdr *hdr; + struct rte_mbuf *m; + int retry = 4; + + /* Retry few times before failing */ + do { + obj = roc_npa_aura_op_alloc(hp->pool_id, 0); + } while (retry-- && (obj == 0)); + + if (obj == 0) { + cn10k_hwpool_enq(hp, obj_table - index, index); + return -ENOENT; + } + /* Update mempool information in the mbuf */ + hdr = rte_mempool_get_header(PLT_PTR_CAST(obj)); + m = PLT_PTR_CAST(obj); +#ifdef RTE_LIBRTE_MEMPOOL_DEBUG + if (hdr->mp != m->pool || hdr->mp != mp) + plt_err("Pool Header Mismatch"); +#endif + m->pool = hp; + hdr->mp = hp; + *obj_table = (void *)obj; + } + + return 0; +} + +static unsigned int +cn10k_hwpool_get_count(const struct rte_mempool *hp) +{ + return (unsigned int)roc_npa_aura_op_available(hp->pool_id); +} + +static int +cn10k_hwpool_alloc(struct rte_mempool *hp) +{ + uint64_t aura_handle = 0; + struct rte_mempool *mp; + uint32_t pool_id; + int rc; + + if (hp->cache_size) { + plt_err("Hwpool does not support cache"); + return -EINVAL; + } + + if (CNXK_MEMPOOL_FLAGS(hp)) { + plt_err("Flags must not be passed to hwpool ops"); + return -EINVAL; + } + + mp = CNXK_MEMPOOL_CONFIG(hp); + if (!mp) { + plt_err("Invalid rte_mempool passed as pool_config"); + return -EINVAL; + } + if (mp->cache_size) { + plt_err("Hwpool does not support attaching to pool with cache"); + return -EINVAL; + } + + if (hp->elt_size != mp->elt_size || + hp->header_size != mp->header_size || + hp->trailer_size != mp->trailer_size || hp->size != mp->size) { + plt_err("Hwpool parameters matching with master pool"); + return -EINVAL; + } + + /* Create the NPA aura */ + pool_id = roc_npa_aura_handle_to_aura(mp->pool_id); + rc = roc_npa_aura_create(&aura_handle, hp->size, NULL, (int)pool_id, 0); + if (rc) { + plt_err("Failed to create aura rc=%d", rc); + return rc; + } + + /* Set the flags for the hardware pool */ + CNXK_MEMPOOL_SET_FLAGS(hp, CNXK_MEMPOOL_F_IS_HWPOOL); + hp->pool_id = aura_handle; + plt_npa_dbg("aura_handle=0x%" PRIx64, aura_handle); + + return 0; +} + +static void +cn10k_hwpool_free(struct rte_mempool *hp) +{ + int rc = 0; + + plt_npa_dbg("aura_handle=0x%" PRIx64, hp->pool_id); + /* It can happen that rte_mempool_free() is called immediately after + * rte_mempool_create_empty(). In such cases the NPA pool will not be + * allocated. + */ + if (roc_npa_aura_handle_to_base(hp->pool_id) == 0) + return; + + rc = roc_npa_aura_destroy(hp->pool_id); + if (rc) + plt_err("Failed to destroy aura rc=%d", rc); +} + +static ssize_t +cn10k_hwpool_calc_mem_size(const struct rte_mempool *hp, uint32_t obj_num, + uint32_t pg_shift, size_t *min_chunk_size, + size_t *align) +{ + RTE_SET_USED(hp); + RTE_SET_USED(obj_num); + RTE_SET_USED(pg_shift); + *min_chunk_size = CN10K_HWPOOL_MEM_SIZE; + *align = CN10K_HWPOOL_MEM_SIZE; + /* Return a minimum mem size so that hwpool can also be initialized just + * like a regular pool. This memzone will not be used anywhere. + */ + return CN10K_HWPOOL_MEM_SIZE; +} + +static int +cn10k_hwpool_populate(struct rte_mempool *hp, unsigned int max_objs, + void *vaddr, rte_iova_t iova, size_t len, + rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg) +{ + uint64_t start_iova, end_iova; + struct rte_mempool *mp; + + RTE_SET_USED(max_objs); + RTE_SET_USED(vaddr); + RTE_SET_USED(iova); + RTE_SET_USED(len); + RTE_SET_USED(obj_cb); + RTE_SET_USED(obj_cb_arg); + /* HW pools does not require populating anything as these pools are + * only associated with NPA aura. The NPA pool being used is that of + * another rte_mempool. Only copy the iova range from the aura of + * the other rte_mempool to this pool's aura. + */ + mp = CNXK_MEMPOOL_CONFIG(hp); + roc_npa_aura_op_range_get(mp->pool_id, &start_iova, &end_iova); + roc_npa_aura_op_range_set(hp->pool_id, start_iova, end_iova); + + return hp->size; +} + +static struct rte_mempool_ops cn10k_hwpool_ops = { + .name = "cn10k_hwpool_ops", + .alloc = cn10k_hwpool_alloc, + .free = cn10k_hwpool_free, + .enqueue = cn10k_hwpool_enq, + .dequeue = cn10k_hwpool_deq, + .get_count = cn10k_hwpool_get_count, + .calc_mem_size = cn10k_hwpool_calc_mem_size, + .populate = cn10k_hwpool_populate, +}; + +RTE_MEMPOOL_REGISTER_OPS(cn10k_hwpool_ops); diff --git a/drivers/mempool/cnxk/cnxk_mempool.h b/drivers/mempool/cnxk/cnxk_mempool.h index fc2e4b5b70..4ca05d53e1 100644 --- a/drivers/mempool/cnxk/cnxk_mempool.h +++ b/drivers/mempool/cnxk/cnxk_mempool.h @@ -16,6 +16,10 @@ enum cnxk_mempool_flags { * as pool config to create the pool. */ CNXK_MEMPOOL_F_CUSTOM_AURA = RTE_BIT64(1), + /* This flag indicates whether the pool is a hardware pool or not. + * This flag is set by the driver. + */ + CNXK_MEMPOOL_F_IS_HWPOOL = RTE_BIT64(2), }; #define CNXK_MEMPOOL_F_MASK 0xFUL diff --git a/drivers/mempool/cnxk/meson.build b/drivers/mempool/cnxk/meson.build index 50856ecde8..ce152bedd2 100644 --- a/drivers/mempool/cnxk/meson.build +++ b/drivers/mempool/cnxk/meson.build @@ -14,6 +14,7 @@ sources = files( 'cnxk_mempool_telemetry.c', 'cn9k_mempool_ops.c', 'cn10k_mempool_ops.c', + 'cn10k_hwpool_ops.c', ) deps += ['eal', 'mbuf', 'kvargs', 'bus_pci', 'common_cnxk', 'mempool'] -- 2.25.1