All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ajit Khaparde <ajit.khaparde@broadcom.com>
To: dev@dpdk.org
Cc: Somnath Kotur <somnath.kotur@broadcom.com>
Subject: [dpdk-dev] [PATCH 2/2] net/bnxt: fix ring alloc and free logic
Date: Fri, 25 Jun 2021 15:34:01 -0700	[thread overview]
Message-ID: <20210625223401.45505-3-ajit.khaparde@broadcom.com> (raw)
In-Reply-To: <20210625223401.45505-1-ajit.khaparde@broadcom.com>

[-- Attachment #1: Type: text/plain, Size: 11455 bytes --]

Fix handling of ring alloc and free logic to fix check for invalid ring and
context IDs. This also avoids code duplication.

Fixes: 6133f207970c ("net/bnxt: add Rx queue create/destroy")
Fixes: 51c87ebafc7d ("net/bnxt: add Tx queue create/destroy")

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
---
 drivers/net/bnxt/bnxt_hwrm.c | 173 +++++++++++++++--------------------
 drivers/net/bnxt/bnxt_ring.c |  30 +-----
 2 files changed, 78 insertions(+), 125 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 1a4968abe6..4593991af8 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -1810,6 +1810,9 @@ int bnxt_hwrm_ring_free(struct bnxt *bp,
 	struct hwrm_ring_free_input req = {.req_type = 0 };
 	struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
 
+	if (ring->fw_ring_id == INVALID_HW_RING_ID)
+		return -EINVAL;
+
 	HWRM_PREP(&req, HWRM_RING_FREE, BNXT_USE_CHIMP_MB);
 
 	req.ring_type = ring_type;
@@ -1817,6 +1820,7 @@ int bnxt_hwrm_ring_free(struct bnxt *bp,
 	req.cmpl_ring = rte_cpu_to_le_16(cp_ring_id);
 
 	rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
+	ring->fw_ring_id = INVALID_HW_RING_ID;
 
 	if (rc || resp->error_code) {
 		if (rc == 0 && resp->error_code)
@@ -1902,7 +1906,7 @@ int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
 	struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
 	struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
 
-	if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
+	if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE)
 		return rc;
 
 	HWRM_PREP(&req, HWRM_STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
@@ -1923,6 +1927,9 @@ int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
 	struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
 	struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
 
+	if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE)
+		return 0;
+
 	HWRM_PREP(&req, HWRM_STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
 
 	req.update_period_ms = rte_cpu_to_le_32(0);
@@ -1946,6 +1953,9 @@ static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cp
 	struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
 	struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
 
+	if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE)
+		return 0;
+
 	HWRM_PREP(&req, HWRM_STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
 
 	req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
@@ -1955,6 +1965,8 @@ static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cp
 	HWRM_CHECK_RESULT();
 	HWRM_UNLOCK();
 
+	cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
+
 	return rc;
 }
 
@@ -2600,49 +2612,54 @@ bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
 	unsigned int i;
 	struct bnxt_cp_ring_info *cpr;
 
-	for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
+	for (i = 0; i < bp->rx_cp_nr_rings; i++) {
 
-		if (i >= bp->rx_cp_nr_rings) {
-			cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
-		} else {
-			cpr = bp->rx_queues[i]->cp_ring;
-			if (BNXT_HAS_RING_GRPS(bp))
-				bp->grp_info[i].fw_stats_ctx = -1;
-		}
-		if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
-			rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
-			cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
-			if (rc)
-				return rc;
-		}
+		cpr = bp->rx_queues[i]->cp_ring;
+		if (BNXT_HAS_RING_GRPS(bp))
+			bp->grp_info[i].fw_stats_ctx = -1;
+		rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
+		if (rc)
+			return rc;
+	}
+
+	for (i = 0; i < bp->tx_cp_nr_rings; i++) {
+		cpr = bp->tx_queues[i]->cp_ring;
+		rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
+		if (rc)
+			return rc;
 	}
+
 	return 0;
 }
 
 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
 {
+	struct bnxt_cp_ring_info *cpr;
 	unsigned int i;
 	int rc = 0;
 
-	for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
-		struct bnxt_tx_queue *txq;
-		struct bnxt_rx_queue *rxq;
-		struct bnxt_cp_ring_info *cpr;
+	for (i = 0; i < bp->rx_cp_nr_rings; i++) {
+		struct bnxt_rx_queue *rxq = bp->rx_queues[i];
 
-		if (i >= bp->rx_cp_nr_rings) {
-			txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
-			cpr = txq->cp_ring;
-		} else {
-			rxq = bp->rx_queues[i];
-			cpr = rxq->cp_ring;
+		cpr = rxq->cp_ring;
+		if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE) {
+			rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr);
+			if (rc)
+				return rc;
 		}
+	}
+
+	for (i = 0; i < bp->tx_cp_nr_rings; i++) {
+		struct bnxt_tx_queue *txq = bp->tx_queues[i];
 
+		cpr = txq->cp_ring;
 		if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE) {
 			rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr);
 			if (rc)
 				return rc;
 		}
 	}
+
 	return rc;
 }
 
@@ -2675,9 +2692,8 @@ void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
 	bnxt_hwrm_ring_free(bp, cp_ring,
 			    HWRM_RING_FREE_INPUT_RING_TYPE_NQ,
 			    INVALID_HW_RING_ID);
-	cp_ring->fw_ring_id = INVALID_HW_RING_ID;
-	memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
-				     sizeof(*cpr->cp_desc_ring));
+	memset(cpr->cp_desc_ring, 0,
+	       cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring));
 	cpr->cp_raw_cons = 0;
 }
 
@@ -2686,11 +2702,10 @@ void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
 	struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
 
 	bnxt_hwrm_ring_free(bp, cp_ring,
-			HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL,
-			INVALID_HW_RING_ID);
-	cp_ring->fw_ring_id = INVALID_HW_RING_ID;
-	memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
-			sizeof(*cpr->cp_desc_ring));
+			    HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL,
+			    INVALID_HW_RING_ID);
+	memset(cpr->cp_desc_ring, 0,
+	       cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring));
 	cpr->cp_raw_cons = 0;
 }
 
@@ -2701,34 +2716,24 @@ void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
 	struct bnxt_ring *ring = rxr->rx_ring_struct;
 	struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
 
-	if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-		bnxt_hwrm_ring_free(bp, ring,
-				    HWRM_RING_FREE_INPUT_RING_TYPE_RX,
-				    cpr->cp_ring_struct->fw_ring_id);
-		ring->fw_ring_id = INVALID_HW_RING_ID;
-		if (BNXT_HAS_RING_GRPS(bp))
-			bp->grp_info[queue_index].rx_fw_ring_id =
-							INVALID_HW_RING_ID;
-	}
+	bnxt_hwrm_ring_free(bp, ring,
+			    HWRM_RING_FREE_INPUT_RING_TYPE_RX,
+			    cpr->cp_ring_struct->fw_ring_id);
+	if (BNXT_HAS_RING_GRPS(bp))
+		bp->grp_info[queue_index].rx_fw_ring_id = INVALID_HW_RING_ID;
+
 	ring = rxr->ag_ring_struct;
-	if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-		bnxt_hwrm_ring_free(bp, ring,
-				    BNXT_CHIP_P5(bp) ?
-				    HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
-				    HWRM_RING_FREE_INPUT_RING_TYPE_RX,
-				    cpr->cp_ring_struct->fw_ring_id);
-		if (BNXT_HAS_RING_GRPS(bp))
-			bp->grp_info[queue_index].ag_fw_ring_id =
-							INVALID_HW_RING_ID;
-	}
+	bnxt_hwrm_ring_free(bp, ring,
+			    BNXT_CHIP_P5(bp) ?
+			    HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
+			    HWRM_RING_FREE_INPUT_RING_TYPE_RX,
+			    cpr->cp_ring_struct->fw_ring_id);
+	if (BNXT_HAS_RING_GRPS(bp))
+		bp->grp_info[queue_index].ag_fw_ring_id = INVALID_HW_RING_ID;
 
-	if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
-		bnxt_hwrm_stat_ctx_free(bp, cpr);
-		cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
-	}
+	bnxt_hwrm_stat_ctx_free(bp, cpr);
 
-	if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
-		bnxt_free_cp_ring(bp, cpr);
+	bnxt_free_cp_ring(bp, cpr);
 
 	if (BNXT_HAS_RING_GRPS(bp))
 		bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
@@ -2758,31 +2763,8 @@ bnxt_free_all_hwrm_rings(struct bnxt *bp)
 {
 	unsigned int i;
 
-	for (i = 0; i < bp->tx_cp_nr_rings; i++) {
-		struct bnxt_tx_queue *txq = bp->tx_queues[i];
-		struct bnxt_tx_ring_info *txr = txq->tx_ring;
-		struct bnxt_ring *ring = txr->tx_ring_struct;
-		struct bnxt_cp_ring_info *cpr = txq->cp_ring;
-
-		if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-			bnxt_hwrm_ring_free(bp, ring,
-					HWRM_RING_FREE_INPUT_RING_TYPE_TX,
-					cpr->cp_ring_struct->fw_ring_id);
-			ring->fw_ring_id = INVALID_HW_RING_ID;
-			memset(txr->tx_desc_ring, 0,
-					txr->tx_ring_struct->ring_size *
-					sizeof(*txr->tx_desc_ring));
-			memset(txr->tx_buf_ring, 0,
-					txr->tx_ring_struct->ring_size *
-					sizeof(*txr->tx_buf_ring));
-			txr->tx_raw_prod = 0;
-			txr->tx_raw_cons = 0;
-		}
-		if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
-			bnxt_free_cp_ring(bp, cpr);
-			cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
-		}
-	}
+	for (i = 0; i < bp->tx_cp_nr_rings; i++)
+		bnxt_free_hwrm_tx_ring(bp, i);
 
 	for (i = 0; i < bp->rx_cp_nr_rings; i++)
 		bnxt_free_hwrm_rx_ring(bp, i);
@@ -6207,20 +6189,17 @@ void bnxt_free_hwrm_tx_ring(struct bnxt *bp, int queue_index)
 	struct bnxt_ring *ring = txr->tx_ring_struct;
 	struct bnxt_cp_ring_info *cpr = txq->cp_ring;
 
-	if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-		bnxt_hwrm_ring_free(bp, ring,
-				    HWRM_RING_FREE_INPUT_RING_TYPE_TX,
-				    cpr->cp_ring_struct->fw_ring_id);
-		ring->fw_ring_id = INVALID_HW_RING_ID;
-	}
+	bnxt_hwrm_ring_free(bp, ring,
+			    HWRM_RING_FREE_INPUT_RING_TYPE_TX,
+			    cpr->cp_ring_struct->fw_ring_id);
+	txr->tx_raw_prod = 0;
+	txr->tx_raw_cons = 0;
+	memset(txr->tx_desc_ring, 0,
+		txr->tx_ring_struct->ring_size * sizeof(*txr->tx_desc_ring));
+	memset(txr->tx_buf_ring, 0,
+		txr->tx_ring_struct->ring_size * sizeof(*txr->tx_buf_ring));
 
-	if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
-		bnxt_hwrm_stat_ctx_free(bp, cpr);
-		cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
-	}
+	bnxt_hwrm_stat_ctx_free(bp, cpr);
 
-	if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
-		bnxt_free_cp_ring(bp, cpr);
-		cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
-	}
+	bnxt_free_cp_ring(bp, cpr);
 }
diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c
index 9ec0c10911..b05c470766 100644
--- a/drivers/net/bnxt/bnxt_ring.c
+++ b/drivers/net/bnxt/bnxt_ring.c
@@ -700,7 +700,6 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 {
 	struct bnxt_coal coal;
 	unsigned int i;
-	uint8_t ring_type;
 	int rc = 0;
 
 	bnxt_init_dflt_coal(&coal);
@@ -712,36 +711,11 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 			goto err_out;
 	}
 
+	/* If something is wrong with Rx ring alloc, skip Tx ring alloc */
 	for (i = 0; i < bp->tx_cp_nr_rings; i++) {
-		struct bnxt_tx_queue *txq = bp->tx_queues[i];
-		struct bnxt_cp_ring_info *cpr = txq->cp_ring;
-		struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
-		struct bnxt_tx_ring_info *txr = txq->tx_ring;
-		struct bnxt_ring *ring = txr->tx_ring_struct;
-		unsigned int idx = i + bp->rx_cp_nr_rings;
-		uint16_t tx_cosq_id = 0;
-
-		if (bnxt_alloc_cmpl_ring(bp, idx, cpr))
-			goto err_out;
-
-		if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
-			tx_cosq_id = bp->tx_cosq_id[i < bp->max_lltc ? i : 0];
-		else
-			tx_cosq_id = bp->tx_cosq_id[0];
-		/* Tx ring */
-		ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_TX;
-		rc = bnxt_hwrm_ring_alloc(bp, ring,
-					  ring_type,
-					  i, cpr->hw_stats_ctx_id,
-					  cp_ring->fw_ring_id,
-					  tx_cosq_id);
+		rc = bnxt_alloc_hwrm_tx_ring(bp, i);
 		if (rc)
 			goto err_out;
-
-		bnxt_set_db(bp, &txr->tx_db, ring_type, i, ring->fw_ring_id,
-			    ring->ring_mask);
-		txq->index = idx;
-		bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id);
 	}
 
 err_out:
-- 
2.21.1 (Apple Git-122.3)


  parent reply	other threads:[~2021-06-25 22:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25 22:33 [dpdk-dev] [PATCH 0/2] bet/bnxt: add runtime queue setup support Ajit Khaparde
2021-06-25 22:34 ` [dpdk-dev] [PATCH 1/2] net/bnxt: add support for runtime queue setup Ajit Khaparde
2021-06-25 22:34 ` Ajit Khaparde [this message]
2021-06-29 19:44 ` [dpdk-dev] [PATCH 0/2] bet/bnxt: add runtime queue setup support Ajit Khaparde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210625223401.45505-3-ajit.khaparde@broadcom.com \
    --to=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=somnath.kotur@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.