All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lance Richardson <lance.richardson@broadcom.com>
To: dev@dpdk.org
Cc: ajit.khaparde@broadcom.com, ferruh.yigit@intel.com,
	Lance Richardson <lance.richardson@broadcom.com>
Subject: [dpdk-dev] [PATCH 08/11] net/bnxt: refactor ring allocation code
Date: Sun,  2 Jun 2019 13:42:43 -0400	[thread overview]
Message-ID: <20190602174247.32368-9-lance.richardson@broadcom.com> (raw)
In-Reply-To: <20190602174247.32368-1-lance.richardson@broadcom.com>

Reduce code duplication and prepare for supporting hardware with
different ring allocation requirements by refactoring ring
allocation code.

Signed-off-by: Lance Richardson <lance.richardson@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_ring.c | 167 ++++++++++++++++++-----------------
 1 file changed, 85 insertions(+), 82 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c
index 15d418977..8473e4abe 100644
--- a/drivers/net/bnxt/bnxt_ring.c
+++ b/drivers/net/bnxt/bnxt_ring.c
@@ -295,29 +295,94 @@ static void bnxt_set_db(struct bnxt *bp,
 	}
 }
 
-int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index)
+static int bnxt_alloc_cmpl_ring(struct bnxt *bp, int queue_index,
+				struct bnxt_cp_ring_info *cpr)
+{
+	struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
+	uint8_t ring_type;
+	int rc = 0;
+
+	ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
+
+	rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, queue_index,
+				  HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE);
+	if (rc)
+		return rc;
+
+	cpr->cp_cons = 0;
+	bnxt_set_db(bp, &cpr->cp_db, ring_type, queue_index);
+	bnxt_db_cq(cpr);
+
+	return 0;
+}
+
+static int bnxt_alloc_rx_ring(struct bnxt *bp, int queue_index)
 {
 	struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
 	struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
 	struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
 	struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
 	struct bnxt_ring *ring = rxr->rx_ring_struct;
+	uint8_t ring_type;
+	int rc = 0;
+
+	ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
+
+	rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type,
+				  queue_index, cpr->hw_stats_ctx_id,
+				  cp_ring->fw_ring_id);
+	if (rc)
+		return rc;
+
+	rxr->rx_prod = 0;
+	bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id;
+	bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index);
+	bnxt_db_write(&rxr->rx_db, rxr->rx_prod);
+
+	return 0;
+}
+
+static int bnxt_alloc_rx_agg_ring(struct bnxt *bp, int queue_index)
+{
 	unsigned int map_idx = queue_index + bp->rx_cp_nr_rings;
+	struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
+	struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
+	struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
+	struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
+	struct bnxt_ring *ring = rxr->ag_ring_struct;
+	uint32_t hw_stats_ctx_id = HWRM_NA_SIGNATURE;
 	uint8_t ring_type;
 	int rc = 0;
 
-	bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id;
+	ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
+
+	rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx,
+				  hw_stats_ctx_id, cp_ring->fw_ring_id);
 
-	/* Rx cmpl */
-	ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
-	rc = bnxt_hwrm_ring_alloc(bp, cp_ring,  ring_type, queue_index,
-				  HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE);
 	if (rc)
+		return rc;
+
+	rxr->ag_prod = 0;
+	bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id;
+	bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx);
+	bnxt_db_write(&rxr->ag_db, rxr->ag_prod);
+
+	return 0;
+}
+
+int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index)
+{
+	struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
+	struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
+	struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
+	struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
+	int rc = 0;
+
+	if (bnxt_alloc_cmpl_ring(bp, queue_index, cpr))
 		goto err_out;
 
+	bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id;
 	bp->grp_info[queue_index].cp_fw_ring_id = cp_ring->fw_ring_id;
-	bnxt_set_db(bp, &cpr->cp_db, ring_type, queue_index);
-	bnxt_db_cq(cpr);
 
 	if (!queue_index) {
 		/*
@@ -330,34 +395,12 @@ int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index)
 		if (rc)
 			goto err_out;
 	}
-	/* Rx ring */
-	ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
-	rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, queue_index,
-				  cpr->hw_stats_ctx_id, cp_ring->fw_ring_id);
-	if (rc)
-		goto err_out;
-
-	rxr->rx_prod = 0;
-	bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id;
-	bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index);
-	bnxt_db_write(&rxr->rx_db, rxr->rx_prod);
-
-	/* Agg ring */
-	ring = rxr->ag_ring_struct;
-	if (!ring)
-		PMD_DRV_LOG(ERR, "Alloc AGG Ring is NULL!\n");
 
-	ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
-	rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx,
-				  HWRM_NA_SIGNATURE, cp_ring->fw_ring_id);
-	if (rc)
+	if (bnxt_alloc_rx_ring(bp, queue_index))
 		goto err_out;
 
-	PMD_DRV_LOG(DEBUG, "Alloc AGG Done!\n");
-	rxr->ag_prod = 0;
-	bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id;
-	bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx);
-	bnxt_db_write(&rxr->ag_db, rxr->ag_prod);
+	if (bnxt_alloc_rx_agg_ring(bp, queue_index))
+		goto err_out;
 
 	rxq->rx_buf_use_size = BNXT_MAX_MTU + RTE_ETHER_HDR_LEN +
 		RTE_ETHER_CRC_LEN + (2 * VLAN_TAG_SIZE);
@@ -403,21 +446,14 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
 		struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
 		struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
-		struct bnxt_ring *ring = rxr->rx_ring_struct;
-		unsigned int map_idx = i + bp->rx_cp_nr_rings;
 
 		bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
 
-		/* Rx cmpl */
-		ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
-		rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, i,
-					  HWRM_NA_SIGNATURE,
-					  HWRM_NA_SIGNATURE);
-		if (rc)
+		if (bnxt_alloc_cmpl_ring(bp, i, cpr))
 			goto err_out;
+
+		bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
 		bp->grp_info[i].cp_fw_ring_id = cp_ring->fw_ring_id;
-		bnxt_set_db(bp, &cpr->cp_db, ring_type, i);
-		bnxt_db_cq(cpr);
 
 		bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id);
 
@@ -434,38 +470,12 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 				goto err_out;
 		}
 
-		/* Rx ring */
-		ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
-		rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, i,
-					  cpr->hw_stats_ctx_id,
-					  cp_ring->fw_ring_id);
-		if (rc)
-			goto err_out;
-		rxr->rx_prod = 0;
-		bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id;
-		bnxt_set_db(bp, &rxr->rx_db, ring_type, i);
-		bnxt_db_write(&rxr->rx_db, rxr->rx_prod);
-
-		/* Agg ring */
-		ring = rxr->ag_ring_struct;
-
-		if (ring == NULL) {
-			PMD_DRV_LOG(ERR, "Alloc AGG Ring is NULL!\n");
+		if (bnxt_alloc_rx_ring(bp, i))
 			goto err_out;
-		}
 
-		ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
-		rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx,
-					  HWRM_NA_SIGNATURE,
-					  cp_ring->fw_ring_id);
-		if (rc)
+		if (bnxt_alloc_rx_agg_ring(bp, i))
 			goto err_out;
 
-		rxr->ag_prod = 0;
-		bp->grp_info[i].ag_fw_ring_id = ring->fw_ring_id;
-		bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx);
-		bnxt_db_write(&rxr->ag_db, rxr->ag_prod);
-
 		rxq->rx_buf_use_size = BNXT_MAX_MTU + RTE_ETHER_HDR_LEN +
 					RTE_ETHER_CRC_LEN + (2 * VLAN_TAG_SIZE);
 		if (bnxt_init_one_rx_ring(rxq)) {
@@ -486,21 +496,14 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		struct bnxt_ring *ring = txr->tx_ring_struct;
 		unsigned int idx = i + bp->rx_cp_nr_rings;
 
-		/* Tx cmpl */
-		ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
-		rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, idx,
-					  HWRM_NA_SIGNATURE,
-					  HWRM_NA_SIGNATURE);
-		if (rc)
+		if (bnxt_alloc_cmpl_ring(bp, idx, cpr))
 			goto err_out;
 
-		bnxt_set_db(bp, &cpr->cp_db, ring_type, idx);
-		bnxt_db_cq(cpr);
-
 		/* Tx ring */
 		ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_TX;
-		rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, idx,
-					  cpr->hw_stats_ctx_id,
+		rc = bnxt_hwrm_ring_alloc(bp, ring,
+					  ring_type,
+					  idx, cpr->hw_stats_ctx_id,
 					  cp_ring->fw_ring_id);
 		if (rc)
 			goto err_out;
-- 
2.17.1


  parent reply	other threads:[~2019-06-02 17:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-02 17:42 [dpdk-dev] [PATCH 00/11] add support for BCM57508 controller Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 01/11] net/bnxt: endianness conversions in cp ring macros Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 02/11] net/bnxt: fix ring type macro name usage Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 03/11] net/bnxt: fix width in stats ctx endian conversion Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 04/11] net/bnxt: use consistent values for vnic RSS rule Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 05/11] net/bnxt: reset function earlier in initialization Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 06/11] net/bnxt: support extended hwrm request sizes Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 07/11] net/bnxt: refactor doorbell handling Lance Richardson
2019-06-02 17:42 ` Lance Richardson [this message]
2019-06-02 17:42 ` [dpdk-dev] [PATCH 09/11] net/bnxt: add support for thor controller Lance Richardson
2019-06-14  2:17   ` [dpdk-dev] compilation failing - " Thomas Monjalon
2019-06-14  3:34     ` Ajit Khaparde
2019-06-14  3:42       ` Lance Richardson
2019-06-14  4:20     ` [dpdk-dev] [PATCH] net/bnxt: fix compilation error with some compilers Ajit Khaparde
2019-06-14  6:56       ` Thomas Monjalon
2019-06-02 17:42 ` [dpdk-dev] [PATCH 10/11] net/bnxt: enable completion coalescing for thor Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 11/11] net/bnxt: enable RSS for thor-based adapters Lance Richardson
2019-06-02 17:42 ` [dpdk-dev] [PATCH 11/11] net/bnxt: enable RSS for thor-based controllers Lance Richardson
2019-06-07 10:48 ` [dpdk-dev] [PATCH 00/11] add support for BCM57508 controller Ferruh Yigit
2019-06-07 10:52   ` Ferruh Yigit
2019-06-07 13:45     ` Lance Richardson
2019-06-07 14:13       ` Ferruh Yigit

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=20190602174247.32368-9-lance.richardson@broadcom.com \
    --to=lance.richardson@broadcom.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.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.