patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Ajit Khaparde <ajit.khaparde@broadcom.com>
To: stable@dpdk.org
Cc: luca.boccassi@gmail.com
Subject: [dpdk-stable] [PATCH 1/2] net/bnxt: fix group info usage
Date: Fri,  2 Feb 2018 12:05:25 -0800	[thread overview]
Message-ID: <20180202200526.96248-2-ajit.khaparde@broadcom.com> (raw)
In-Reply-To: <20180202200526.96248-1-ajit.khaparde@broadcom.com>

Ring groups is a Rx only attribute. Make sure there are sufficient
ring groups available. Return an error if they are not available.

[ upstream commit ee5d7bddab27 ("net/bnxt: fix group info usage") ]

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_ethdev.c |  4 +++-
 drivers/net/bnxt/bnxt_hwrm.c   | 38 ++++++++++++++++++++++++--------------
 drivers/net/bnxt/bnxt_hwrm.h   |  4 +++-
 drivers/net/bnxt/bnxt_ring.c   | 24 +++++++++++++++++-------
 drivers/net/bnxt/bnxt_ring.h   |  3 ++-
 5 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 64cc7217c..359a95d4e 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -315,7 +315,9 @@ static int bnxt_init_nic(struct bnxt *bp)
 {
 	int rc;
 
-	bnxt_init_ring_grps(bp);
+	rc = bnxt_init_ring_grps(bp);
+	if (rc)
+		return rc;
 	bnxt_init_vnics(bp);
 	bnxt_init_filters(bp);
 
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 619bc979c..8eb559708 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -604,7 +604,7 @@ int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
 			 struct bnxt_ring *ring,
 			 uint32_t ring_type, uint32_t map_index,
-			 uint32_t stats_ctx_id)
+			 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
 {
 	int rc = 0;
 	struct hwrm_ring_alloc_input req = {.req_type = 0 };
@@ -625,11 +625,12 @@ int bnxt_hwrm_ring_alloc(struct bnxt *bp,
 		/* FALLTHROUGH */
 	case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
 		req.ring_type = ring_type;
-		req.cmpl_ring_id =
-		    rte_cpu_to_le_16(bp->grp_info[map_index].cp_fw_ring_id);
+		req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
 		req.length = rte_cpu_to_le_32(ring->ring_size);
 		req.stat_ctx_id = rte_cpu_to_le_16(stats_ctx_id);
-		req.enables = rte_cpu_to_le_32(rte_le_to_cpu_32(req.enables) |
+		if (stats_ctx_id != INVALID_STATS_CTX_ID)
+			req.enables =
+			rte_cpu_to_le_32(rte_le_to_cpu_32(req.enables) |
 			HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID);
 		break;
 	case HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL:
@@ -796,7 +797,9 @@ int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp,
 	HWRM_CHECK_RESULT;
 
 	cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
-	bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
+	//Tx rings don't need grp_info entry. It is a Rx only attribute.
+	if (idx)
+		bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
 
 	return rc;
 }
@@ -818,7 +821,9 @@ int bnxt_hwrm_stat_ctx_free(struct bnxt *bp,
 	HWRM_CHECK_RESULT;
 
 	cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
-	bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
+	//Tx rings don't have a grp_info entry. It is a Rx only attribute.
+	if (idx)
+		bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
 
 	return rc;
 }
@@ -1025,10 +1030,13 @@ int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
 	for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
 		unsigned int idx = i + 1;
 
-		if (i >= bp->rx_cp_nr_rings)
+		if (i >= bp->rx_cp_nr_rings) {
 			cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
-		else
+			//Tx rings don't have a grp_info entry.
+			idx = 0;
+		} else {
 			cpr = bp->rx_queues[i]->cp_ring;
+		}
 		if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
 			rc = bnxt_hwrm_stat_ctx_free(bp, cpr, idx);
 			if (rc)
@@ -1052,6 +1060,8 @@ int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
 		if (i >= bp->rx_cp_nr_rings) {
 			txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
 			cpr = txq->cp_ring;
+			//Tx rings don't need grp_info entry.
+			idx = 0;
 		} else {
 			rxq = bp->rx_queues[i];
 			cpr = rxq->cp_ring;
@@ -1089,14 +1099,13 @@ int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
 }
 
 static void bnxt_free_cp_ring(struct bnxt *bp,
-			      struct bnxt_cp_ring_info *cpr, unsigned int idx)
+			      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_CMPL);
 	cp_ring->fw_ring_id = INVALID_HW_RING_ID;
-	bp->grp_info[idx].cp_fw_ring_id = 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;
@@ -1112,7 +1121,6 @@ int bnxt_free_all_hwrm_rings(struct bnxt *bp)
 		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;
-		unsigned int idx = bp->rx_cp_nr_rings + i + 1;
 
 		if (ring->fw_ring_id != INVALID_HW_RING_ID) {
 			bnxt_hwrm_ring_free(bp, ring,
@@ -1128,7 +1136,7 @@ int bnxt_free_all_hwrm_rings(struct bnxt *bp)
 			txr->tx_cons = 0;
 		}
 		if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
-			bnxt_free_cp_ring(bp, cpr, idx);
+			bnxt_free_cp_ring(bp, cpr);
 	}
 
 	for (i = 0; i < bp->rx_cp_nr_rings; i++) {
@@ -1152,7 +1160,8 @@ int bnxt_free_all_hwrm_rings(struct bnxt *bp)
 			rxr->rx_prod = 0;
 		}
 		if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
-			bnxt_free_cp_ring(bp, cpr, idx);
+			bnxt_free_cp_ring(bp, cpr);
+		bp->grp_info[idx].cp_fw_ring_id = INVALID_HW_RING_ID;
 	}
 
 	/* Default completion ring */
@@ -1160,7 +1169,8 @@ int bnxt_free_all_hwrm_rings(struct bnxt *bp)
 		struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
 
 		if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
-			bnxt_free_cp_ring(bp, cpr, 0);
+			bnxt_free_cp_ring(bp, cpr);
+		bp->grp_info[0].cp_fw_ring_id = INVALID_HW_RING_ID;
 	}
 
 	return rc;
diff --git a/drivers/net/bnxt/bnxt_hwrm.h b/drivers/net/bnxt/bnxt_hwrm.h
index 6519ef21a..32c74c8b1 100644
--- a/drivers/net/bnxt/bnxt_hwrm.h
+++ b/drivers/net/bnxt/bnxt_hwrm.h
@@ -65,7 +65,7 @@ int bnxt_hwrm_queue_qportcfg(struct bnxt *bp);
 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
 			 struct bnxt_ring *ring,
 			 uint32_t ring_type, uint32_t map_index,
-			 uint32_t stats_ctx_id);
+			 uint32_t stats_ctx_id, uint32_t cmpl_ring_id);
 int bnxt_hwrm_ring_free(struct bnxt *bp,
 			struct bnxt_ring *ring, uint32_t ring_type);
 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx);
@@ -101,5 +101,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp);
 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link);
 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up);
 int bnxt_hwrm_func_qcfg(struct bnxt *bp);
+#define HWRM_RING_ALLOC_INPUT_EN_STAT_CTX_ID_VALID \
+	HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID
 
 #endif
diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c
index 3f81ffcc5..2bceb4dba 100644
--- a/drivers/net/bnxt/bnxt_ring.c
+++ b/drivers/net/bnxt/bnxt_ring.c
@@ -61,13 +61,19 @@ void bnxt_free_ring(struct bnxt_ring *ring)
  * Ring groups
  */
 
-void bnxt_init_ring_grps(struct bnxt *bp)
+int bnxt_init_ring_grps(struct bnxt *bp)
 {
 	unsigned int i;
 
+	//One slot is still consumed by Default ring.
+	if (bp->max_ring_grps < 1 + bp->rx_cp_nr_rings)
+		return -ENOMEM;
+
 	for (i = 0; i < bp->max_ring_grps; i++)
 		memset(&bp->grp_info[i], (uint8_t)HWRM_NA_SIGNATURE,
 		       sizeof(struct bnxt_ring_grp_info));
+
+	return 0;
 }
 
 /*
@@ -219,7 +225,8 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 
 		rc = bnxt_hwrm_ring_alloc(bp, cp_ring,
 					  HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
-					  0, HWRM_NA_SIGNATURE);
+					  0, HWRM_NA_SIGNATURE,
+					  HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
 		cpr->cp_doorbell =
@@ -239,7 +246,8 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		/* Rx cmpl */
 		rc = bnxt_hwrm_ring_alloc(bp, cp_ring,
 					HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
-					idx, HWRM_NA_SIGNATURE);
+					idx, HWRM_NA_SIGNATURE,
+					HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
 		cpr->cp_doorbell =
@@ -251,7 +259,8 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		/* Rx ring */
 		rc = bnxt_hwrm_ring_alloc(bp, ring,
 					HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
-					idx, cpr->hw_stats_ctx_id);
+					idx, cpr->hw_stats_ctx_id,
+					cp_ring->fw_ring_id);
 		if (rc)
 			goto err_out;
 		rxr->rx_prod = 0;
@@ -279,20 +288,21 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		/* Tx cmpl */
 		rc = bnxt_hwrm_ring_alloc(bp, cp_ring,
 					HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
-					idx, HWRM_NA_SIGNATURE);
+					idx, HWRM_NA_SIGNATURE,
+					HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
 
 		cpr->cp_doorbell =
 		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
-		bp->grp_info[idx].cp_fw_ring_id = cp_ring->fw_ring_id;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
 
 		/* Tx ring */
 		rc = bnxt_hwrm_ring_alloc(bp, ring,
 					HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
-					idx, cpr->hw_stats_ctx_id);
+					idx, cpr->hw_stats_ctx_id,
+					cp_ring->fw_ring_id);
 		if (rc)
 			goto err_out;
 
diff --git a/drivers/net/bnxt/bnxt_ring.h b/drivers/net/bnxt/bnxt_ring.h
index 8656549a5..22a56eb13 100644
--- a/drivers/net/bnxt/bnxt_ring.h
+++ b/drivers/net/bnxt/bnxt_ring.h
@@ -65,6 +65,7 @@
 #define MAX_CP_DESC_CNT (16 * 1024)
 
 #define INVALID_HW_RING_ID      ((uint16_t)-1)
+#define INVALID_STATS_CTX_ID	((uint16_t)-1)
 
 struct bnxt_ring {
 	void			*bd;
@@ -92,7 +93,7 @@ struct bnxt_tx_ring_info;
 struct bnxt_rx_ring_info;
 struct bnxt_cp_ring_info;
 void bnxt_free_ring(struct bnxt_ring *ring);
-void bnxt_init_ring_grps(struct bnxt *bp);
+int bnxt_init_ring_grps(struct bnxt *bp);
 int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
 			    struct bnxt_tx_ring_info *tx_ring_info,
 			    struct bnxt_rx_ring_info *rx_ring_info,
-- 
2.14.3 (Apple Git-98)

  reply	other threads:[~2018-02-02 20:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-26 13:30 [dpdk-stable] please help backporting some patches to LTS release 16.11.5 luca.boccassi
2018-01-26 18:26 ` Yongseok Koh
2018-01-26 18:40   ` Luca Boccassi
2018-01-28  5:47 ` Matan Azrad
2018-01-28 14:17   ` Luca Boccassi
2018-01-30 14:26 ` Nélio Laranjeiro
2018-01-30 14:36   ` Luca Boccassi
2018-02-02 20:05 ` [dpdk-stable] [PATCH 0/2] bnxt patchset for 16.11 Ajit Khaparde
2018-02-02 20:05   ` Ajit Khaparde [this message]
2018-02-02 20:05   ` [dpdk-stable] [PATCH 2/2] net/bnxt: fix broadcast cofiguration Ajit Khaparde
2018-02-05 13:46   ` [dpdk-stable] [PATCH 0/2] bnxt patchset for 16.11 Luca Boccassi
2018-02-07 19:14 ` [dpdk-stable] please help backporting some patches to LTS release 16.11.5 luca.boccassi
2018-02-08  1:53   ` Tan, Jianfeng
2018-02-08 10:37     ` Luca Boccassi
2018-02-08 21:47   ` Ajit Khaparde
2018-02-08 22:31     ` Luca Boccassi
2018-02-11  7:49   ` Matan Azrad
2018-02-11 11:26     ` Luca Boccassi
2018-02-14  8:46   ` Olivier Matz
2018-02-14 10:16     ` Luca Boccassi

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=20180202200526.96248-2-ajit.khaparde@broadcom.com \
    --to=ajit.khaparde@broadcom.com \
    --cc=luca.boccassi@gmail.com \
    --cc=stable@dpdk.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).