Netdev List
 help / color / mirror / Atom feed
From: Michael Chan <michael.chan@broadcom.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, andrew+netdev@lunn.ch,
	pavan.chebbi@broadcom.com, andrew.gospodarek@broadcom.com
Subject: [PATCH net-next v4 7/8] bnxt_en: Refactor bnxt_num_cp_to_tx()/bnxt_num_tx_to_cp() helpers
Date: Thu, 15 Oct 2026 23:44:26 -0700	[thread overview]
Message-ID: <20261016064427.496944-8-michael.chan@broadcom.com> (raw)
In-Reply-To: <20261016064427.496944-1-michael.chan@broadcom.com>

Add 2 parameters tx_xdp and rx to these 2 helpers.  tx_xdp will be
passed in by the caller instead of always using bp->tx_nr_rings_xdp.
All current callers will pass in bp->tx_nr_rings_xdp so there is no
change in behavior.  The rx parameter is unused until the next patch
to clamp the XDP rings.  The callers now pass in the correct rx
value for this purpose.

To be consistent in bnxt_num_cp_to_tx(), tcs is now correctly set to 1
when bp->num_tc is 0.

Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 28 +++++++++++------------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |  2 +-
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 79057a5a2b7a..5949fc72aaa5 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -8161,7 +8161,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh);
 	if (bp->flags & BNXT_FLAG_AGG_RINGS)
 		hwr.rx = rx_rings << 1;
-	tx_cp = bnxt_num_tx_to_cp(bp, hwr.tx);
+	tx_cp = bnxt_num_tx_to_cp(bp, hwr.tx, bp->tx_nr_rings_xdp, rx_rings);
 	hwr.cp = sh ? max_t(int, tx_cp, rx_rings) : tx_cp + rx_rings;
 	if (hwr.tx != bp->tx_nr_rings) {
 		netdev_warn(bp->dev,
@@ -11294,27 +11294,24 @@ static int __bnxt_num_tx_to_cp(struct bnxt *bp, int tx, int tx_sets, int tx_xdp)
 	return (tx - tx_xdp) / tx_sets + tx_xdp;
 }
 
-int bnxt_num_tx_to_cp(struct bnxt *bp, int tx)
+int bnxt_num_tx_to_cp(struct bnxt *bp, int tx, int tx_xdp, int rx)
 {
-	int tcs = bp->num_tc;
+	int tcs = bp->num_tc ? bp->num_tc : 1;
 
-	if (!tcs)
-		tcs = 1;
-	return __bnxt_num_tx_to_cp(bp, tx, tcs, bp->tx_nr_rings_xdp);
+	return __bnxt_num_tx_to_cp(bp, tx, tcs, tx_xdp);
 }
 
-static int bnxt_num_cp_to_tx(struct bnxt *bp, int tx_cp)
+static int bnxt_num_cp_to_tx(struct bnxt *bp, int tx_cp, int tx_xdp, int rx)
 {
-	int tcs = bp->num_tc;
+	int tcs = bp->num_tc ? bp->num_tc : 1;
 
-	return (tx_cp - bp->tx_nr_rings_xdp) * tcs +
-	       bp->tx_nr_rings_xdp;
+	return (tx_cp - tx_xdp) * tcs + tx_xdp;
 }
 
 static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
 			   bool sh)
 {
-	int tx_cp = bnxt_num_tx_to_cp(bp, *tx);
+	int tx_cp = bnxt_num_tx_to_cp(bp, *tx, bp->tx_nr_rings_xdp, *rx);
 
 	if (tx_cp != *tx) {
 		int tx_saved = tx_cp, rc;
@@ -11323,7 +11320,8 @@ static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
 		if (rc)
 			return rc;
 		if (tx_cp != tx_saved)
-			*tx = bnxt_num_cp_to_tx(bp, tx_cp);
+			*tx = bnxt_num_cp_to_tx(bp, tx_cp, bp->tx_nr_rings_xdp,
+						*rx);
 		return 0;
 	}
 	return __bnxt_trim_rings(bp, rx, tx, max, sh);
@@ -11536,7 +11534,8 @@ static int bnxt_init_int_mode(struct bnxt *bp)
 	if (rc)
 		goto msix_setup_exit;
 
-	tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
+	tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings, bp->tx_nr_rings_xdp,
+				  bp->rx_nr_rings);
 	bp->cp_nr_rings = (min == 1) ?
 			  max_t(int, tx_cp, bp->rx_nr_rings) :
 			  tx_cp + bp->rx_nr_rings;
@@ -15647,7 +15646,8 @@ static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
 
 void bnxt_set_cp_rings(struct bnxt *bp, bool sh)
 {
-	int tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
+	int tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings, bp->tx_nr_rings_xdp,
+				      bp->rx_nr_rings);
 
 	bp->cp_nr_rings = sh ? max_t(int, tx_cp, bp->rx_nr_rings) :
 			       tx_cp + bp->rx_nr_rings;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 51a269d06c49..5ca98394a9ab 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -3003,7 +3003,7 @@ int bnxt_hwrm_set_coal(struct bnxt *);
 size_t bnxt_copy_ctx_mem(struct bnxt *bp, struct bnxt_ctx_mem_type *ctxm,
 			 void *buf, size_t offset);
 void bnxt_free_ctx_mem(struct bnxt *bp, bool force);
-int bnxt_num_tx_to_cp(struct bnxt *bp, int tx);
+int bnxt_num_tx_to_cp(struct bnxt *bp, int tx, int tx_xdp, int rx);
 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
 unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt *bp);
 unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp);
-- 
2.51.0


  parent reply	other threads:[~2026-10-16  6:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  6:44 [PATCH net-next v4 0/8] bnxt_en: Ring accounting fixes Michael Chan
2026-10-16  6:44 ` [PATCH net-next v4 1/8] bnxt_en: Clear bp->total_irqs when disabling IRQs Michael Chan
2026-10-16  6:44 ` [PATCH net-next v4 2/8] bnxt_en: Fix bnxt_reinit_features() when irq_re_init is true Michael Chan
2026-10-16  6:44 ` [PATCH net-next v4 3/8] bnxt_en: Refactor RSS table check logic Michael Chan
2026-10-16  6:44 ` [PATCH net-next v4 4/8] bnxt_en: Refactor IRQs required logic Michael Chan
2026-10-16  6:44 ` [PATCH net-next v4 5/8] bnxt_en: Reinit IRQ when configuring LRO/GRO/HDS Michael Chan
2026-10-16  6:44 ` [PATCH net-next v4 6/8] bnxt_en: Remove support for the old NITRO A0 chip Michael Chan
2026-10-16  6:44 ` Michael Chan [this message]
2026-10-16  6:44 ` [PATCH net-next v4 8/8] bnxt_en: Fix ring accounting and validation when rings are constrained Michael Chan

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=20261016064427.496944-8-michael.chan@broadcom.com \
    --to=michael.chan@broadcom.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox