[v2,05/14] net/bnxt: refactor mem zone allocation

Message ID 20231210012455.20229-6-ajit.khaparde@broadcom.com (mailing list archive)
State Changes Requested
Delegated to: Ajit Khaparde
Headers
Series support new 5760X P7 devices |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ajit Khaparde Dec. 10, 2023, 1:24 a.m. UTC
  Currently we are allocating memzone for VNIC attributes per VNIC.
In cases where the firmware supports a higher VNIC count, this could
lead to a higher number of memzone segments than supported.

Move the memzone for VNIC attributes per function instead of per
VNIC. Divide the memzone per VNIC as needed.

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
---
 drivers/net/bnxt/bnxt.h      |  1 +
 drivers/net/bnxt/bnxt_vnic.c | 52 +++++++++++++++++++-----------------
 drivers/net/bnxt/bnxt_vnic.h |  1 -
 3 files changed, 28 insertions(+), 26 deletions(-)
  

Patch

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 542ef13f7c..6af668e92f 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -772,6 +772,7 @@  struct bnxt {
 
 	struct bnxt_vnic_info	*vnic_info;
 	STAILQ_HEAD(, bnxt_vnic_info)	free_vnic_list;
+	const struct rte_memzone *vnic_rss_mz;
 
 	struct bnxt_filter_info	*filter_info;
 	STAILQ_HEAD(, bnxt_filter_info)	free_filter_list;
diff --git a/drivers/net/bnxt/bnxt_vnic.c b/drivers/net/bnxt/bnxt_vnic.c
index f86d27fd79..d40daf631e 100644
--- a/drivers/net/bnxt/bnxt_vnic.c
+++ b/drivers/net/bnxt/bnxt_vnic.c
@@ -123,13 +123,11 @@  void bnxt_free_vnic_attributes(struct bnxt *bp)
 
 	for (i = 0; i < bp->max_vnics; i++) {
 		vnic = &bp->vnic_info[i];
-		if (vnic->rss_mz != NULL) {
-			rte_memzone_free(vnic->rss_mz);
-			vnic->rss_mz = NULL;
-			vnic->rss_hash_key = NULL;
-			vnic->rss_table = NULL;
-		}
+		vnic->rss_hash_key = NULL;
+		vnic->rss_table = NULL;
 	}
+	rte_memzone_free(bp->vnic_rss_mz);
+	bp->vnic_rss_mz = NULL;
 }
 
 int bnxt_alloc_vnic_attributes(struct bnxt *bp, bool reconfig)
@@ -153,31 +151,35 @@  int bnxt_alloc_vnic_attributes(struct bnxt *bp, bool reconfig)
 
 	entry_length = RTE_CACHE_LINE_ROUNDUP(entry_length + rss_table_size);
 
-	for (i = 0; i < bp->max_vnics; i++) {
-		vnic = &bp->vnic_info[i];
-
-		snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
-			 "bnxt_" PCI_PRI_FMT "_vnicattr_%d", pdev->addr.domain,
-			 pdev->addr.bus, pdev->addr.devid, pdev->addr.function, i);
-		mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
-		mz = rte_memzone_lookup(mz_name);
-		if (mz == NULL) {
-			mz = rte_memzone_reserve(mz_name,
-						 entry_length,
+	snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
+		 "bnxt_" PCI_PRI_FMT "_vnicattr", pdev->addr.domain,
+		 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
+	mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
+	mz = rte_memzone_lookup(mz_name);
+	if (mz == NULL) {
+		mz = rte_memzone_reserve_aligned(mz_name,
+						 entry_length * bp->max_vnics,
 						 bp->eth_dev->device->numa_node,
 						 RTE_MEMZONE_2MB |
 						 RTE_MEMZONE_SIZE_HINT_ONLY |
-						 RTE_MEMZONE_IOVA_CONTIG);
-			if (mz == NULL) {
-				PMD_DRV_LOG(ERR, "Cannot allocate bnxt vnic_attributes memory\n");
-				return -ENOMEM;
-			}
+						 RTE_MEMZONE_IOVA_CONTIG,
+						 BNXT_PAGE_SIZE);
+		if (mz == NULL) {
+			PMD_DRV_LOG(ERR,
+				    "Cannot allocate vnic_attributes memory\n");
+			return -ENOMEM;
 		}
-		vnic->rss_mz = mz;
-		mz_phys_addr = mz->iova;
+	}
+	bp->vnic_rss_mz = mz;
+	for (i = 0; i < bp->max_vnics; i++) {
+		uint32_t offset = entry_length * i;
+
+		vnic = &bp->vnic_info[i];
+
+		mz_phys_addr = mz->iova + offset;
 
 		/* Allocate rss table and hash key */
-		vnic->rss_table = (void *)((char *)mz->addr);
+		vnic->rss_table = (void *)((char *)mz->addr + offset);
 		vnic->rss_table_dma_addr = mz_phys_addr;
 		memset(vnic->rss_table, -1, entry_length);
 
diff --git a/drivers/net/bnxt/bnxt_vnic.h b/drivers/net/bnxt/bnxt_vnic.h
index 4396d95bda..7a6a0aa739 100644
--- a/drivers/net/bnxt/bnxt_vnic.h
+++ b/drivers/net/bnxt/bnxt_vnic.h
@@ -47,7 +47,6 @@  struct bnxt_vnic_info {
 	uint16_t	hash_type;
 	uint8_t		hash_mode;
 	uint8_t		prev_hash_mode;
-	const struct rte_memzone *rss_mz;
 	rte_iova_t	rss_table_dma_addr;
 	uint16_t	*rss_table;
 	rte_iova_t	rss_hash_key_dma_addr;