[2/8] net/nfp: fix configuration BAR problem

Message ID 20240419031226.1191069-3-chaoyong.he@corigine.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers
Series refactor logic to support secondary process |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He April 19, 2024, 3:12 a.m. UTC
  All the configuration bars are sit in an array, and the initial logic
sort all the configuration BAR from small to large based on size and index,
which result all valid bars are behind the invalid bars.
But the BAR alloc logic search this array from the very beginning and
only try limited times (equal to the valid bars number).
It's ok for primary process because which has enough valid bars, and
finally it can find one to use.

But for secondary process and run with igb_uio driver, the valid bars
are very limit, and it can not find one, and the logic will fail.

Fix this by drop the sort logic, and search the bar array from the end
to begin.

Fixes: 1fbe51cd9c3a ("net/nfp: extend usage of BAR from 8 to 24")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfpcore/nfp6000_pcie.c | 34 +++++++++-----------------
 1 file changed, 11 insertions(+), 23 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
index a6fd89b6c8..ef1ffd6d01 100644
--- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c
+++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
@@ -263,19 +263,6 @@  nfp_bitsize_calc(uint64_t mask)
 	return bit_size;
 }
 
-static int
-nfp_cmp_bars(const void *ptr_a,
-		const void *ptr_b)
-{
-	const struct nfp_bar *a = ptr_a;
-	const struct nfp_bar *b = ptr_b;
-
-	if (a->bitsize == b->bitsize)
-		return a->index - b->index;
-	else
-		return a->bitsize - b->bitsize;
-}
-
 static bool
 nfp_bars_for_secondary(uint32_t index)
 {
@@ -383,9 +370,6 @@  nfp_enable_bars(struct nfp_pcie_user *nfp)
 	if (nfp_bar_write(nfp, bar, barcfg_msix_general) < 0)
 		return -EIO;
 
-	/* Sort bars by bit size - use the smallest possible first. */
-	qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars);
-
 	return 0;
 }
 
@@ -466,16 +450,18 @@  find_matching_bar(struct nfp_pcie_user *nfp,
 		int width)
 {
 	uint32_t n;
+	uint32_t index;
 
-	for (n = 0; n < nfp->bars; n++) {
-		struct nfp_bar *bar = &nfp->bar[n];
+	for (n = RTE_DIM(nfp->bar) ; n > 0; n--) {
+		index = n - 1;
+		struct nfp_bar *bar = &nfp->bar[index];
 
 		if (bar->lock)
 			continue;
 
 		if (matching_bar_exist(bar, target, action, token,
 				offset, size, width))
-			return n;
+			return index;
 	}
 
 	return -1;
@@ -493,10 +479,12 @@  find_unused_bar_noblock(struct nfp_pcie_user *nfp,
 {
 	int ret;
 	uint32_t n;
+	uint32_t index;
 	const struct nfp_bar *bar;
 
-	for (n = 0; n < nfp->bars; n++) {
-		bar = &nfp->bar[n];
+	for (n = RTE_DIM(nfp->bar); n > 0; n--) {
+		index = n - 1;
+		bar = &nfp->bar[index];
 
 		if (bar->bitsize == 0)
 			continue;
@@ -508,7 +496,7 @@  find_unused_bar_noblock(struct nfp_pcie_user *nfp,
 			continue;
 
 		if (!bar->lock)
-			return n;
+			return index;
 	}
 
 	return -EAGAIN;
@@ -561,7 +549,7 @@  nfp_disable_bars(struct nfp_pcie_user *nfp)
 	uint32_t i;
 	struct nfp_bar *bar;
 
-	for (i = 0; i < nfp->bars; i++) {
+	for (i = 0; i < RTE_DIM(nfp->bar); i++) {
 		bar = &nfp->bar[i];
 		if (bar->iomem != NULL) {
 			bar->iomem = NULL;