Skip to contentSkip to conversation

bnxt_en: Ring accounting fixes

PATCH Superseded Michael Chan 5 participants 17 messages Oct 12 – Oct 14

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Michael Chan

author maintainer
#0 lore raw

v3 cover bnxt_en: Ring accounting fixes

The main purpose of this patchset is to fix ring accounting bugs specifically when FW is unable to reserve all the rings requested by the driver. This issue was first reported by Sashiko when reviewing the driver patches to support kTLS (patch #3 of 15):

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

kTLS support requires the new MPC rings, so the patches touch the existing ring reservstion logic and exposed the issues to Sashiko. The issues are real but only likely to be hit with a large number of VFs, stressing the ring resources to the limit. These issues were not found in the lab or by users, so Jakub suggested splitting these out and posting them to net-next.

The patchset includes some refactoring and some related fixes in this code path. The driver will now scale down the rings properly when FW is unable reserve all the rings requested by the driver. The default RSS context is also reset if the RX
rings have been reduced if needed. Note that additional RSS
contexts and n-tuple filters have similar problems if the RX rings are reduced and the fixes are deferred to a future patchset.

Patch #6 is new and removes support for the obsolete NITRO A0, to make the fixes in patch #7 simpler.

v3:
Split from the original -net patchset (patchs 1 to 6) Updated to address some more Sashiko comments. Added the new patch #6 to remove NITRO A0.

v2:
Updated to address some Sashiko comments.

https://lore.kernel.org/netdev/[email protected]/

v1:
https://lore.kernel.org/netdev/[email protected]/

Michael Chan (7):
bnxt_en: Clear bp->total_irqs in bnxt_init_int_mode() during error
bnxt_en: Fix bnxt_reinit_features() when irq_re_init is true
bnxt_en: Refactor RSS table check logic
bnxt_en: Refactor IRQs required logic
bnxt_en: Reinit IRQ when configuring LRO/GRO/HDS
bnxt_en: Remove support for the old NITRO A0 chip
bnxt_en: Fix ring accounting and validation when rings are constrained

 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 446 ++++++++----------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  12 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  22 +-
 3 files changed, 211 insertions(+), 269 deletions(-)
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH v3 1/7 bnxt_en: Clear bp->total_irqs in bnxt_init_int_mode() during error

During error, bnxt_init_int_mode() will free bp->irq_tbl but bp->total_irqs retains the old value. If a subsequent reinitialization happens, bnxt_reserve_rings() may see that bp->total_irqs does not match a new irqs_required. It will then try to adjust if dynamic MSI-X is supported and call bnxt_change_msix(). It will then crash when dereferencing the NULL bp->irq_tbl.

Fix it by clearing bp->total_irqs when freeing bp->irq_tbl. Dynamic MSI-X adjustments should only proceed if bp->irq_tbl is valid which means that MSI-X has been initialized and can be adjusted.

Add a bp->irq_tbl_size to prevent OOB bp->irq_tbl[] array access in case MSI-X capabilities change during re-init. For dynamic MSI-X, allocate the biggest bp->irq_tbl that is not clamped by CP/NQ rings to allow dynamic MSI-X to grow to the max.

In the AER path, if MSI-X capabilities change, bnxt_reserve_rings() will initialize MSI-X if BNXT_NEW_RM() is true. Add a check in bnxt_io_resume() to skip doing it again later.

Fixes e68256c8a73c ("bnxt_en: Support dynamic MSIX")
Fixes c2d20a3814d1 ("bnxt_en: delay pci_alloc_irq_vectors() in the AER path")

---
v3:
Added an additional Fixes tag.

v2:
https://lore.kernel.org/netdev/[email protected]/

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 18 ++++++++++++++----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |  1 +
 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +14 -4
index c1d3fcc7ae84..2bd2c039ce43 100644
@@ -11510,6 +11510,12 @@ static int bnxt_change_msix(struct bnxt *bp, int total)
 	struct msi_map map;
 	int i;
 
+	if (!bp->irq_tbl)
+		return 0;
+
+	if (total > bp->irq_tbl_size)
+		return bp->total_irqs;
+
 	/* add MSIX to the end if needed */
 	for (i = bp->total_irqs; i < total; i++) {
 		map = pci_msix_alloc_irq_at(bp->pdev, i, NULL);
@@ -11652,12 +11658,13 @@ static int bnxt_init_int_mode(struct bnxt *bp)
 
 	tbl_size = total_vecs;
 	if (pci_msix_can_alloc_dyn(bp->pdev))
-		tbl_size = max;
+		tbl_size = bp->hw_resc.max_irqs;
 	bp->irq_tbl = kzalloc_objs(*bp->irq_tbl, tbl_size);
 	if (!bp->irq_tbl) {
 		rc = -ENOMEM;
 		goto msix_setup_exit;
 	}
+	bp->irq_tbl_size = tbl_size;
 
 	for (i = 0; i < total_vecs; i++)
 		bp->irq_tbl[i].vector = pci_irq_vector(bp->pdev, i);
@@ -11680,6 +11687,8 @@ static int bnxt_init_int_mode(struct bnxt *bp)
 	netdev_err(bp->dev, "bnxt_init_int_mode err: %x\n", rc);
 	kfree(bp->irq_tbl);
 	bp->irq_tbl = NULL;
+	bp->total_irqs = 0;
+	bp->irq_tbl_size = 0;
 	pci_free_irq_vectors(bp->pdev);
 	return rc;
 }
@@ -11690,6 +11699,7 @@ static void bnxt_clear_int_mode(struct bnxt *bp)
 
 	kfree(bp->irq_tbl);
 	bp->irq_tbl = NULL;
+	bp->irq_tbl_size = 0;
 }
 
 int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
@@ -11716,7 +11726,7 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 
 	if (irq_re_init && BNXT_NEW_RM(bp) && irqs_required != bp->total_irqs) {
 		irq_change = true;
-		if (!pci_msix_can_alloc_dyn(bp->pdev)) {
+		if (!pci_msix_can_alloc_dyn(bp->pdev) || !bp->irq_tbl) {
 			bnxt_ulp_irq_stop(bp);
 			bnxt_clear_int_mode(bp);
 			irq_cleared = true;
@@ -15080,7 +15090,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
 			hwr.cp += bnxt_get_ulp_msix_num(bp);
 			hwr.cp = min_t(int, hwr.cp, bnxt_get_max_func_irqs(bp));
 		}
-		if (hwr.cp > bp->total_irqs) {
+		if (bp->irq_tbl && hwr.cp > bp->total_irqs) {
 			int total_msix = bnxt_change_msix(bp, hwr.cp);
 
 			if (total_msix < hwr.cp) {
@@ -17743,7 +17753,7 @@ static void bnxt_io_resume(struct pci_dev *pdev)
 			err = bnxt_open(netdev);
 		} else {
 			err = bnxt_reserve_rings(bp, true);
-			if (!err)
+			if (!err && !bp->irq_tbl)
 				err = bnxt_init_int_mode(bp);
 		}
 	}
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -0
index 41d05efd6307..75428a585577 100644
@@ -2489,6 +2489,7 @@ struct bnxt {
 	 */
 	unsigned long		*ring_affinity_set;
 	int			max_irqs;
+	int			irq_tbl_size;
 	int			total_irqs;
 	int			ulp_num_msix_want;
 	u8			mac_addr[ETH_ALEN];
Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH v3 2/7 bnxt_en: Fix bnxt_reinit_features() when irq_re_init is true

In reply to Michael Chan

bnxt_set_features() takes a snapshot of bp->flags, closes the device, and then blindly restores the entire bp->flags. bp->flags contains statistics flags that may be cleared and the memory freed when irq_re_init is true. Do not restore these statistics flags until bnxt_open_nic() reallocates the memory. bnxt_open_nic() can potentially fail to allocate the stats memory and the restored flags can potentially cause NULL dereference of the stats memory.

Fixes 93e90104bd12 ("bnxt_en: Create and setup the additional VNIC for adding ntuple filters")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
index 2bd2c039ce43..d23b40b0cb92 100644
@@ -14090,7 +14090,8 @@ static int bnxt_reinit_features(struct bnxt *bp, bool irq_re_init,
 				bool link_re_init, u32 flags, bool update_tpa)
 {
 	bnxt_close_nic(bp, irq_re_init, link_re_init);
-	bp->flags = flags;
+	bp->flags = (bp->flags & ~BNXT_FLAG_ALL_CONFIG_FEATS) |
+		    (flags & BNXT_FLAG_ALL_CONFIG_FEATS);
 	if (update_tpa)
 		bnxt_set_ring_params(bp);
 	return bnxt_open_nic(bp, irq_re_init, link_re_init);
Signature · 1 line
2.51.0
author maintainer
#3 lore raw

PATCH v3 3/7 bnxt_en: Refactor RSS table check logic

In reply to Michael Chan

We have logic to see if we need to reset the user configured RSS table for the default RSS context if the RX rings have changed in __bnxt_reserve_rings(). Refactor this code into a helper that will be used by other callers later in the patch series. There is no change in behavior.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +15 -6
index d23b40b0cb92..1c38e15fbe7e 100644
@@ -8168,6 +8168,20 @@ static bool bnxt_rings_ok(struct bnxt *bp, struct bnxt_hw_rings *hwr)
 	       hwr->stat && (hwr->cp_p5 || !(bp->flags & BNXT_FLAG_CHIP_P5_PLUS));
 }
 
+/* Check to see if we need to reset the user configured RSS table
+ * (default RSS context) because of change in RX rings from
+ * old_rx to new_rx.
+ */
+static void bnxt_check_rss_tbl_lost(struct bnxt *bp, int old_rx, int new_rx)
+{
+	if (netif_is_rxfh_configured(bp->dev) &&
+	    (bnxt_get_nr_rss_ctxs(bp, old_rx) !=
+	     bnxt_get_nr_rss_ctxs(bp, new_rx) ||
+	     bnxt_get_max_rss_ring(bp) >= new_rx)) {
+		ethtool_rxfh_indir_lost(bp->dev);
+	}
+}
+
 static int bnxt_get_avail_msix(struct bnxt *bp, int num);
 
 static int __bnxt_reserve_rings(struct bnxt *bp)
@@ -8257,12 +8271,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	if (rx_rings != bp->rx_nr_rings) {
 		netdev_warn(bp->dev, "Able to reserve only %d out of %d requested RX rings\n",
 			    rx_rings, bp->rx_nr_rings);
-		if (netif_is_rxfh_configured(bp->dev) &&
-		    (bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings) !=
-		     bnxt_get_nr_rss_ctxs(bp, rx_rings) ||
-		     bnxt_get_max_rss_ring(bp) >= rx_rings)) {
-			ethtool_rxfh_indir_lost(bp->dev);
-		}
+		bnxt_check_rss_tbl_lost(bp, bp->rx_nr_rings, rx_rings);
 	}
 	bp->rx_nr_rings = rx_rings;
 	bp->cp_nr_rings = hwr.cp;
Signature · 1 line
2.51.0
author maintainer
#7 lore raw

PATCH v3 5/7 bnxt_en: Reinit IRQ when configuring LRO/GRO/HDS

In reply to Michael Chan

When configuring LRO/GRO/HDS, a new set of RX Aggregation rings may be required. It is possible that the FW cannot grant the desired number of Agg rings, causing the driver to reduce the number of ethtool channels to adjust. This means that the number of IRQs/NAPIs may change and we must set irq_re_init to true to make that work. Without this patch, when the driver is eventually shutdown, some memory for the unused NAPIs may never be freed properly if the rings have shrunk.

Fixes 87c8f8496a05 ("bnxt_en: add support for tcp-data-split ethtool command")
Fixes c0c050c58d84 ("bnxt_en: New Broadcom ethernet driver.")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c         | 11 ++++++++---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 10 ++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -3
index 05e609adf6a3..2ada2bb8fd57 100644
@@ -14115,10 +14115,11 @@ static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
 {
 	bool update_tpa = false, update_ntuple = false;
 	struct bnxt *bp = netdev_priv(dev);
+	bool irq_re_init = false;
 	u32 flags = bp->flags;
+	bool re_init = false;
 	u32 changes;
 	int rc = 0;
-	bool re_init = false;
 
 	bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
 				   bnxt_min_tx_desc_cnt(bp, features));
@@ -14145,8 +14146,12 @@ static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
 		update_tpa = true;
 		if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
 		    (flags & BNXT_FLAG_TPA) == 0 ||
-		    (bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
+		    (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)) {
 			re_init = true;
+			if (!(bp->flags & BNXT_FLAG_AGG_RINGS) &&
+			    (flags & BNXT_FLAG_AGG_RINGS))
+				irq_re_init = true;
+		}
 	}
 
 	if (changes & ~BNXT_FLAG_TPA)
@@ -14169,7 +14174,7 @@ static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
 			return bnxt_reinit_features(bp, true, false, flags, update_tpa);
 
 		if (re_init)
-			return bnxt_reinit_features(bp, false, false, flags, update_tpa);
+			return bnxt_reinit_features(bp, irq_re_init, false, flags, update_tpa);
 
 		if (update_tpa) {
 			bp->flags = flags;
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +8 -2
index 622e89587e5d..5c9e770960e6 100644
@@ -853,6 +853,7 @@ static int bnxt_set_ringparam(struct net_device *dev,
 {
 	u8 tcp_data_split = kernel_ering->tcp_data_split;
 	struct bnxt *bp = netdev_priv(dev);
+	bool irq_re_init = false;
 	u8 hds_config_mod;
 	int rc;
 
@@ -876,8 +877,13 @@ static int bnxt_set_ringparam(struct net_device *dev,
 		return -EINVAL;
 	}
 
+	if (hds_config_mod &&
+	    tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED &&
+	    !(bp->flags & BNXT_FLAG_AGG_RINGS))
+		irq_re_init = true;
+
 	if (netif_running(dev))
-		bnxt_close_nic(bp, false, false);
+		bnxt_close_nic(bp, irq_re_init, false);
 
 	if (hds_config_mod) {
 		if (tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED)
@@ -891,7 +897,7 @@ static int bnxt_set_ringparam(struct net_device *dev,
 	bnxt_set_ring_params(bp);
 
 	if (netif_running(dev)) {
-		rc = bnxt_open_nic(bp, false, false);
+		rc = bnxt_open_nic(bp, irq_re_init, false);
 		if (rc)
 			return rc;
 	}
Signature · 1 line
2.51.0
author maintainer
#5 lore raw

PATCH v3 4/7 bnxt_en: Refactor IRQs required logic

In reply to Michael Chan

Refactor the logic to determine the required IRQ vectors into a new helper. Later patches in the series will make additional use of the helper. There is no change in behavior.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 25 ++++++++++++++---------
 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +15 -10
index 1c38e15fbe7e..05e609adf6a3 100644
@@ -11711,9 +11711,22 @@ static void bnxt_clear_int_mode(struct bnxt *bp)
 	bp->irq_tbl_size = 0;
 }
 
-int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
+static int bnxt_irqs_required(struct bnxt *bp)
 {
 	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
+		int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
+
+		if (ulp_msix > bp->ulp_num_msix_want)
+			ulp_msix = bp->ulp_num_msix_want;
+		return ulp_msix + bp->cp_nr_rings;
+	}
+	return bnxt_get_num_msix(bp);
+}
+
+int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
+{
 	bool irq_cleared = false;
 	bool irq_change = false;
 	int tcs = bp->num_tc;
@@ -11723,15 +11736,7 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 	if (!bnxt_need_reserve_rings(bp))
 		return 0;
 
-	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
-		int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
-
-		if (ulp_msix > bp->ulp_num_msix_want)
-			ulp_msix = bp->ulp_num_msix_want;
-		irqs_required = ulp_msix + bp->cp_nr_rings;
-	} else {
-		irqs_required = bnxt_get_num_msix(bp);
-	}
+	irqs_required = bnxt_irqs_required(bp);
 
 	if (irq_re_init && BNXT_NEW_RM(bp) && irqs_required != bp->total_irqs) {
 		irq_change = true;
Signature · 1 line
2.51.0
author maintainer
#8 lore raw

PATCH v3 6/7 bnxt_en: Remove support for the old NITRO A0 chip

In reply to Michael Chan

Nitro A0 was a very old pre-production chip that requires significant workarounds. For example, it requires an extra (hidden) RX ring and CP ring to work, adding a lot of complexity. The workaround code is very buggy and breaks in many cases, including ethtool ring changes initiated by the user.

Remove all Nitro A0 workaround code completely. Print an error and abort if the chip is detected. This will simplify the next patch that fixes ring accounting bugs.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 185 ++----------------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  11 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  12 +-
 3 files changed, 19 insertions(+), 189 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +14 -171
index 2ada2bb8fd57..ed3f67dea030 100644
@@ -3209,82 +3209,6 @@ static int bnxt_poll_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
 	return rx_pkts;
 }
 
-static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
-{
-	struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
-	struct bnxt *bp = bnapi->bp;
-	struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
-	struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
-	struct tx_cmp *txcmp;
-	struct rx_cmp_ext *rxcmp1;
-	u32 cp_cons, tmp_raw_cons;
-	u32 raw_cons = cpr->cp_raw_cons;
-	bool flush_xdp = false;
-	u32 rx_pkts = 0;
-	u8 event = 0;
-
-	while (1) {
-		int rc;
-
-		cp_cons = RING_CMP(raw_cons);
-		txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
-
-		if (!TX_CMP_VALID(txcmp, raw_cons))
-			break;
-
-		/* The valid test of the entry must be done first before
-		 * reading any further.
-		 */
-		dma_rmb();
-		if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
-			tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
-			cp_cons = RING_CMP(tmp_raw_cons);
-			rxcmp1 = (struct rx_cmp_ext *)
-			  &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
-
-			if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
-				break;
-
-			/* force an error to recycle the buffer */
-			rxcmp1->rx_cmp_cfa_code_errors_v2 |=
-				cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
-
-			rc = bnxt_rx_pkt(bp, cpr, &raw_cons, &event);
-			if (likely(rc == -EIO) && budget)
-				rx_pkts++;
-			else if (rc == -EBUSY)	/* partial completion */
-				break;
-			if (event & BNXT_REDIRECT_EVENT)
-				flush_xdp = true;
-		} else if (unlikely(TX_CMP_TYPE(txcmp) ==
-				    CMPL_BASE_TYPE_HWRM_DONE)) {
-			bnxt_hwrm_handler(bp, txcmp);
-		} else {
-			netdev_err(bp->dev,
-				   "Invalid completion received on special ring\n");
-		}
-		raw_cons = NEXT_RAW_CMP(raw_cons);
-
-		if (rx_pkts == budget)
-			break;
-	}
-
-	cpr->cp_raw_cons = raw_cons;
-	BNXT_DB_CQ(&cpr->cp_db, cpr->cp_raw_cons);
-	bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
-
-	if (event & BNXT_AGG_EVENT)
-		bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
-	if (flush_xdp)
-		xdp_do_flush();
-
-	if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
-		napi_complete_done(napi, rx_pkts);
-		BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
-	}
-	return rx_pkts;
-}
-
 static int bnxt_poll(struct napi_struct *napi, int budget)
 {
 	struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
@@ -4791,9 +4715,6 @@ static int bnxt_alloc_vnics(struct bnxt *bp)
 	}
 #endif
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		num_vnics++;
-
 	bp->vnic_info = kzalloc_objs(struct bnxt_vnic_info, num_vnics);
 	if (!bp->vnic_info)
 		return -ENOMEM;
@@ -6327,11 +6248,8 @@ int bnxt_hwrm_l2_filter_alloc(struct bnxt *bp, struct bnxt_l2_filter *fltr)
 		return rc;
 
 	req->target_id = cpu_to_le16(target_id);
-	req->flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
-
-	if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
-		req->flags |=
-			cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
+	req->flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX |
+				 CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
 	req->dst_id = cpu_to_le16(fltr->base.fw_vnic_id);
 	req->enables =
 		cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
@@ -6688,10 +6606,7 @@ void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp,
 	if (!bp->rx_nr_rings)
 		return;
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		max_rings = bp->rx_nr_rings - 1;
-	else
-		max_rings = bp->rx_nr_rings;
+	max_rings = bp->rx_nr_rings;
 
 	max_entries = bnxt_get_rxfh_indir_size(bp->dev);
 	if (rss_ctx)
@@ -6731,8 +6646,6 @@ int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings)
 		return bnxt_calc_nr_ring_pages(rx_rings - 1,
 					       BNXT_RSS_TABLE_ENTRIES_P5);
 	}
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		return 2;
 	return 1;
 }
 
@@ -6757,8 +6670,6 @@ static void bnxt_fill_hw_rss_tbl(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 		vnic->default_rx_ring = min_j;
 	else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
 		vnic->default_rx_ring = vnic->vnic_id - 1;
-	else if ((vnic->vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
-		vnic->default_rx_ring = bp->rx_nr_rings - 1;
 	else
 		vnic->default_rx_ring = 0;
 }
@@ -7013,13 +6924,7 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 		req->rss_rule = cpu_to_le16(0xffff);
 	}
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
-	    (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
-		req->cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
-		req->enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
-	} else {
-		req->cos_rule = cpu_to_le16(0xffff);
-	}
+	req->cos_rule = cpu_to_le16(0xffff);
 
 	ring = vnic->default_rx_ring;
 	grp_idx = bp->rx_ring[ring].bnapi->index;
@@ -8617,9 +8522,6 @@ static void bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
 	if (!bp->bnapi)
 		return;
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		return;
-
 	if (hwrm_req_init(bp, req, HWRM_STAT_CTX_FREE))
 		return;
 	if (BNXT_FW_MAJ(bp) <= 20) {
@@ -8656,9 +8558,6 @@ static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
 	struct hwrm_stat_ctx_alloc_input *req;
 	int rc, i;
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		return 0;
-
 	rc = hwrm_req_init(bp, req, HWRM_STAT_CTX_ALLOC);
 	if (rc)
 		return rc;
@@ -10489,9 +10388,6 @@ static int bnxt_hwrm_ver_get(struct bnxt *bp)
 
 	bp->chip_num = le16_to_cpu(resp->chip_num);
 	bp->chip_rev = resp->chip_rev;
-	if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
-	    !resp->chip_metal)
-		bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
 
 	dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
 	if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
@@ -10906,16 +10802,6 @@ static int __bnxt_setup_vnic(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 	}
 	bp->rsscos_nr_ctxs++;
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
-		rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, 1);
-		if (rc) {
-			netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
-				   vnic->vnic_id, rc);
-			goto vnic_setup_err;
-		}
-		bp->rsscos_nr_ctxs++;
-	}
-
 skip_rss_ctx:
 	bnxt_fill_hw_rss_tbl(bp, vnic);
 	/* configure default vnic, ring grp */
@@ -11216,30 +11102,6 @@ static bool bnxt_promisc_ok(struct bnxt *bp)
 	return true;
 }
 
-static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
-{
-	struct bnxt_vnic_info *vnic = &bp->vnic_info[1];
-	unsigned int rc = 0;
-
-	rc = bnxt_hwrm_vnic_alloc(bp, vnic, bp->rx_nr_rings - 1, 1);
-	if (rc) {
-		netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
-			   rc);
-		return rc;
-	}
-
-	/* Setup the proper default RX ring */
-	bnxt_fill_hw_rss_tbl(bp, vnic);
-
-	rc = bnxt_hwrm_vnic_cfg(bp, vnic);
-	if (rc) {
-		netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
-			   rc);
-		return rc;
-	}
-	return rc;
-}
-
 static int bnxt_cfg_rx_mode(struct bnxt *, struct netdev_hw_addr_list *, bool);
 static bool bnxt_mc_list_updated(struct bnxt *, u32 *,
 				 const struct netdev_hw_addr_list *);
@@ -11248,7 +11110,6 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 {
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[BNXT_VNIC_DEFAULT];
 	int rc = 0;
-	unsigned int rx_nr_rings = bp->rx_nr_rings;
 
 	if (irq_re_init) {
 		rc = bnxt_hwrm_stat_ctx_alloc(bp);
@@ -11271,11 +11132,8 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 		goto err_out;
 	}
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		rx_nr_rings--;
-
 	/* default vnic 0 */
-	rc = bnxt_hwrm_vnic_alloc(bp, vnic, 0, rx_nr_rings);
+	rc = bnxt_hwrm_vnic_alloc(bp, vnic, 0, bp->rx_nr_rings);
 	if (rc) {
 		netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
 		goto err_out;
@@ -11350,13 +11208,6 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 		netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
 				rc);
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
-		rc = bnxt_setup_nitroa0_vnic(bp);
-		if (rc)
-			netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
-				   rc);
-	}
-
 	if (BNXT_VF(bp)) {
 		bnxt_hwrm_func_qcfg(bp);
 		netdev_update_features(bp->dev);
@@ -12108,26 +11959,19 @@ static void bnxt_del_napi(struct bnxt *bp)
 static void bnxt_init_napi(struct bnxt *bp)
 {
 	int (*poll_fn)(struct napi_struct *, int) = bnxt_poll;
-	unsigned int cp_nr_rings = bp->cp_nr_rings;
 	struct bnxt_napi *bnapi;
 	int i;
 
 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
 		poll_fn = bnxt_poll_p5;
-	else if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-		cp_nr_rings--;
 
 	set_bit(BNXT_STATE_NAPI_DISABLED, &bp->state);
 
-	for (i = 0; i < cp_nr_rings; i++) {
+	for (i = 0; i < bp->cp_nr_rings; i++) {
 		bnapi = bp->bnapi[i];
 		netif_napi_add_config_locked(bp->dev, &bnapi->napi, poll_fn,
 					     bnapi->index);
 	}
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
-		bnapi = bp->bnapi[cp_nr_rings];
-		netif_napi_add_locked(bp->dev, &bnapi->napi, bnxt_poll_nitroa0);
-	}
 }
 
 static void bnxt_disable_napi(struct bnxt *bp)
@@ -14001,7 +13845,7 @@ static bool bnxt_rfs_supported(struct bnxt *bp)
 	/* 212 firmware is broken for aRFS */
 	if (BNXT_FW_MAJ(bp) == 212)
 		return false;
-	if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
+	if (BNXT_PF(bp))
 		return true;
 	if (bp->rss_cap & BNXT_RSS_CAP_NEW_RSS_CAP)
 		return true;
@@ -16824,10 +16668,6 @@ static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
 	if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
 		*max_cp = min_t(int, *max_cp, max_irq);
 	max_ring_grps = hw_resc->max_hw_ring_grps;
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
-		*max_cp -= 1;
-		*max_rx -= 2;
-	}
 	if (bp->flags & BNXT_FLAG_AGG_RINGS)
 		*max_rx >>= 1;
 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {
@@ -16977,10 +16817,6 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
 			netdev_warn(bp->dev, "2nd rings reservation failed.\n");
 		bnxt_adj_tx_rings(bp);
 	}
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
-		bp->rx_nr_rings++;
-		bp->cp_nr_rings++;
-	}
 	if (rc) {
 		bp->tx_nr_rings = 0;
 		bp->rx_nr_rings = 0;
@@ -17251,6 +17087,13 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		goto init_err_pci_clean;
 
+	if (bp->chip_num == CHIP_NUM_58700 && !bp->chip_rev &&
+	    !bp->ver_resp.chip_metal) {
+		dev_err(&pdev->dev, "58700 A0 unsupported, aborting\n");
+		rc = -ENODEV;
+		goto init_err_pci_clean;
+	}
+
 	if (BNXT_PF(bp))
 		bnxt_vpd_read_info(bp);
 
drivers/net/ethernet/broadcom/bnxt/bnxt.h +3 -8
index 75428a585577..51a269d06c49 100644
@@ -2295,7 +2295,6 @@ struct bnxt {
 	#define BNXT_FLAG_DSN_VALID	0x200000
 	#define BNXT_FLAG_DOUBLE_DB	0x400000
 	#define BNXT_FLAG_UDP_GSO_CAP	0x800000
-	#define BNXT_FLAG_CHIP_NITRO_A0	0x1000000
 	#define BNXT_FLAG_DIM		0x2000000
 	#define BNXT_FLAG_ROCE_MIRROR_CAP	0x4000000
 	#define BNXT_FLAG_TX_COAL_CMPL	0x8000000
@@ -2323,10 +2322,8 @@ struct bnxt {
 #define BNXT_PHY_CFG_ABLE(bp)	((BNXT_SINGLE_PF(bp) ||			\
 				  BNXT_SH_PORT_CFG_OK(bp)) &&		\
 				 (bp)->link_info.phy_state == BNXT_PHY_STATE_ENABLED)
-#define BNXT_CHIP_TYPE_NITRO_A0(bp) ((bp)->flags & BNXT_FLAG_CHIP_NITRO_A0)
 #define BNXT_RX_PAGE_MODE(bp)	((bp)->flags & BNXT_FLAG_RX_PAGE_MODE)
-#define BNXT_SUPPORTS_TPA(bp)	(!BNXT_CHIP_TYPE_NITRO_A0(bp) &&	\
-				 (!((bp)->flags & BNXT_FLAG_CHIP_P5_PLUS) ||\
+#define BNXT_SUPPORTS_TPA(bp)	((!((bp)->flags & BNXT_FLAG_CHIP_P5_PLUS) ||\
 				  (bp)->max_tpa_v2) && !is_kdump_kernel())
 #define BNXT_RX_JUMBO_MODE(bp)	((bp)->flags & BNXT_FLAG_JUMBO)
 
@@ -2347,13 +2344,11 @@ struct bnxt {
 	(BNXT_CHIP_NUM_57X1X((bp)->chip_num) ||	\
 	 BNXT_CHIP_NUM_5745X((bp)->chip_num) ||	\
 	 BNXT_CHIP_NUM_588XX((bp)->chip_num) ||	\
-	 (BNXT_CHIP_NUM_58700((bp)->chip_num) &&	\
-	  !BNXT_CHIP_TYPE_NITRO_A0(bp)))
+	 BNXT_CHIP_NUM_58700((bp)->chip_num))
 
 /* Chip class phase 3.x */
 #define BNXT_CHIP_P3(bp)			\
-	(BNXT_CHIP_NUM_57X0X((bp)->chip_num) ||	\
-	 BNXT_CHIP_TYPE_NITRO_A0(bp))
+	(BNXT_CHIP_NUM_57X0X((bp)->chip_num))
 
 #define BNXT_CHIP_P4_PLUS(bp)			\
 	(BNXT_CHIP_P4(bp) || BNXT_CHIP_P5_PLUS(bp))
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +2 -10
index 5c9e770960e6..62f894021fd1 100644
@@ -949,13 +949,9 @@ static void bnxt_get_channels(struct net_device *dev,
 	channel->max_other = 0;
 	if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
 		channel->combined_count = bp->rx_nr_rings;
-		if (BNXT_CHIP_TYPE_NITRO_A0(bp))
-			channel->combined_count--;
 	} else {
-		if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
-			channel->rx_count = bp->rx_nr_rings;
-			channel->tx_count = bp->tx_nr_rings_per_tc;
-		}
+		channel->rx_count = bp->rx_nr_rings;
+		channel->tx_count = bp->tx_nr_rings_per_tc;
 	}
 }
 
@@ -980,10 +976,6 @@ static int bnxt_set_channels(struct net_device *dev,
 	    (channel->rx_count || channel->tx_count))
 		return -EINVAL;
 
-	if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
-					    channel->tx_count))
-		return -EINVAL;
-
 	if (channel->combined_count)
 		sh = true;
 
Signature · 1 line
2.51.0
author maintainer
#10 lore raw

PATCH v3 7/7 bnxt_en: Fix ring accounting and validation when rings are constrained

In reply to Michael Chan

When __bnxt_reserve_rings() reserves fewer TX rings than requested, and an XDP program is attached, the driver used to blindly subtract bp->tx_nr_rings_xdp from bp->tx_nr_rings, potentially causing an integer underflow.

This patch mainly fixes the existing bnxt_adj_tx_rings() and bnxt_rings_ok():

1. bnxt_adj_tx_rings() is now renamed bnxt_adj_rings() to reflect that all rings (tx, rx, cp) may adjust if needed. It will now correctly scale down TX rings for XDP and TCs evenly. Because XDP requires a 1:1 TX/RX ring mapping in combined channel mode, it will now clamp the RX rings to match. CP rings will also be reduced if necessary. Any leftover rings after integer division are intentionally left unused.

2. bnxt_rings_ok() is now updated to robustly check for the absolute minimum viable ring configuration. We now call bnxt_rings_ok() to make sure we have the bare minimum before calling the new bnxt_adj_rings(). This now guarantees that bnxt_adj_rings() will never underflow or truncate any rings to 0.

With these 2 main changes, we can now centralize bnxt_adj_rings() in __bnxt_reserve_rings() and bnxt_init_int_mode() and delete other adjustments and checks in other functions. Note that in __bnxt_reserve_rings(), we only need to call bnxt_adj_rings() if irq_re_init is true which means that bp->bnapi has not been allocated. In this context, we may be asking for more rings than FW can grant and we need to call bnxt_adj_rings() for possible adjustments. We need to be careful when aborting __bnxt_reserve_rings() and bnxt_init_int_mode() to restore the possibly truncated rings if necessary so that the driver state is consistent.

We now remove the error path at the end of bnxt_reserve_rings() to abort and reset the TCs if the rings cannot satisfy the TC requirements. The user will have to reduce the TCs and retry.

There are other related changes to reset the RSS table if needed and to recalculate the IRQs required if the rings have shrunk. Note that the latter can only be done if the NAPIs have not been allocated yet.

As noted in the cover letter, we have similar existing issues regarding RSS tables for non-default RSS contexts and user defined n-tuple filters when RX rings shrink due to FW or MSI-X constraints. The fixes for these are deferred to a separate patchset.

These existing issues were detected by Sashiko when reviewing the new kTLS patchset (patch #3 of 15):

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

Fixes 1ee581c24dfd ("bnxt_en: Adjust TX rings if reservation is less than requested")
Fixes 674f50a5b026 ("bnxt_en: Implement new method to reserve rings.")

---
v3:
No longer have to deal with dropped NITRO A0 Fix the dynamic IRQ code path in bnxt_reserve_rings(). Use the proper __bnxt_num_tx_to_cp() in bnxt_rings_ok().

v2:
Reduce RX and CP rings if needed when TX rings are reduced to keep it consistent.
Handle NITRO_A0 special RX requirements to keep it consistent. Fix all unwind issues in these code paths.

https://lore.kernel.org/netdev/[email protected]/

v1:
https://lore.kernel.org/netdev/[email protected]/

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 185 +++++++++++++++-------
 1 file changed, 130 insertions(+), 55 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +130 -55
index ed3f67dea030..cbf7aef1d5b8 100644
@@ -8050,6 +8050,8 @@ static bool bnxt_need_reserve_rings(struct bnxt *bp)
 	return false;
 }
 
+static int __bnxt_num_tx_to_cp(struct bnxt *bp, int tx, int tx_sets, int tx_xdp);
+
 static void bnxt_copy_reserved_rings(struct bnxt *bp, struct bnxt_hw_rings *hwr)
 {
 	struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
@@ -8069,8 +8071,25 @@ static void bnxt_copy_reserved_rings(struct bnxt *bp, struct bnxt_hw_rings *hwr)
 
 static bool bnxt_rings_ok(struct bnxt *bp, struct bnxt_hw_rings *hwr)
 {
-	return hwr->tx && hwr->rx && hwr->cp && hwr->grp && hwr->vnic &&
-	       hwr->stat && (hwr->cp_p5 || !(bp->flags & BNXT_FLAG_CHIP_P5_PLUS));
+	int tcs = bp->num_tc ? bp->num_tc : 1;
+	int min_tx_xdp = 0;
+	int min_tx = tcs;
+	int min_rx = 1;
+	int min_cp = 1;
+	int tx_cp;
+
+	if (bp->tx_nr_rings_xdp) {
+		min_tx++;
+		min_tx_xdp = 1;
+	}
+
+	if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) {
+		tx_cp = __bnxt_num_tx_to_cp(bp, min_tx, tcs, min_tx_xdp);
+		min_cp = tx_cp + min_rx;
+	}
+	return hwr->tx >= min_tx && hwr->rx >= min_rx && hwr->cp >= min_cp &&
+	       hwr->grp && hwr->vnic && hwr->stat &&
+	       (hwr->cp_p5 || !(bp->flags & BNXT_FLAG_CHIP_P5_PLUS));
 }
 
 /* Check to see if we need to reset the user configured RSS table
@@ -8088,10 +8107,13 @@ static void bnxt_check_rss_tbl_lost(struct bnxt *bp, int old_rx, int new_rx)
 }
 
 static int bnxt_get_avail_msix(struct bnxt *bp, int num);
+static void bnxt_adj_rings(struct bnxt *bp);
 
 static int __bnxt_reserve_rings(struct bnxt *bp)
 {
 	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+	int req_rx_rings = bp->rx_nr_rings;
+	int req_tx_rings = bp->tx_nr_rings;
 	struct bnxt_hw_rings hwr = {0};
 	int rx_rings, old_rx_rings, rc;
 	int cp = bp->cp_nr_rings;
@@ -8159,49 +8181,68 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 		hwr.stat -= bnxt_get_ulp_stat_ctxs(bp);
 	hwr.cp = min_t(int, hwr.cp, hwr.stat);
 	rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh);
+	if (rc)
+		goto reserve_rings_exit;
+
+	if (bp->bnapi && (rx_rings < bp->rx_nr_rings ||
+			  hwr.tx < bp->tx_nr_rings)) {
+		netdev_err(bp->dev, "Unexpected ring shrinkage %d/%d RX/TX to %d/%d\n",
+			   bp->rx_nr_rings, bp->tx_nr_rings, rx_rings, hwr.tx);
+		rc = -ENOSPC;
+		goto reserve_rings_exit;
+	}
 	if (bp->flags & BNXT_FLAG_AGG_RINGS)
 		hwr.rx = rx_rings << 1;
 	tx_cp = bnxt_num_tx_to_cp(bp, hwr.tx);
 	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,
-			    "Able to reserve only %d out of %d requested TX rings\n",
-			    hwr.tx, bp->tx_nr_rings);
+
+	if (!bnxt_rings_ok(bp, &hwr)) {
+		rc = -ENOMEM;
+		goto reserve_rings_exit;
 	}
+
 	bp->tx_nr_rings = hwr.tx;
+	bp->rx_nr_rings = rx_rings;
+	bp->cp_nr_rings = hwr.cp;
+
+	if (!bp->bnapi)
+		bnxt_adj_rings(bp);
 
+	if (req_tx_rings != bp->tx_nr_rings) {
+		netdev_warn(bp->dev,
+			    "Able to reserve only %d out of %d requested TX rings\n",
+			    bp->tx_nr_rings, req_tx_rings);
+	}
 	/* If we cannot reserve all the RX rings, reset the RSS map only
 	 * if absolutely necessary
 	 */
-	if (rx_rings != bp->rx_nr_rings) {
+	if (req_rx_rings != bp->rx_nr_rings) {
 		netdev_warn(bp->dev, "Able to reserve only %d out of %d requested RX rings\n",
-			    rx_rings, bp->rx_nr_rings);
-		bnxt_check_rss_tbl_lost(bp, bp->rx_nr_rings, rx_rings);
+			    bp->rx_nr_rings, req_rx_rings);
+		bnxt_check_rss_tbl_lost(bp, req_rx_rings, bp->rx_nr_rings);
 	}
-	bp->rx_nr_rings = rx_rings;
-	bp->cp_nr_rings = hwr.cp;
 
 	/* Fall back if we cannot reserve enough HW RSS contexts */
 	if ((bp->rss_cap & BNXT_RSS_CAP_LARGE_RSS_CTX) &&
 	    hwr.rss_ctx < bnxt_get_total_rss_ctxs(bp, &hwr))
 		bp->rss_cap &= ~BNXT_RSS_CAP_LARGE_RSS_CTX;
 
-	if (!bnxt_rings_ok(bp, &hwr))
-		return -ENOMEM;
-
-	if (old_rx_rings != bp->hw_resc.resv_rx_rings &&
+	if ((old_rx_rings != bp->hw_resc.resv_rx_rings ||
+	     req_rx_rings != bp->rx_nr_rings) &&
 	    !netif_is_rxfh_configured(bp->dev))
 		bnxt_set_dflt_rss_indir_tbl(bp, NULL);
 
+reserve_rings_exit:
 	if (!bnxt_ulp_registered(edev) && BNXT_NEW_RM(bp)) {
 		int resv_msix, resv_ctx, ulp_ctxs;
 		struct bnxt_hw_resc *hw_resc;
 
 		hw_resc = &bp->hw_resc;
-		resv_msix = hw_resc->resv_irqs - bp->cp_nr_rings;
+		resv_msix = max_t(int, hw_resc->resv_irqs - bp->cp_nr_rings, 0);
 		ulp_msix = min_t(int, resv_msix, ulp_msix);
 		bnxt_set_ulp_msix_num(bp, ulp_msix);
-		resv_ctx = hw_resc->resv_stat_ctxs  - bp->cp_nr_rings;
+		resv_ctx = max_t(int, hw_resc->resv_stat_ctxs - bp->cp_nr_rings,
+				 0);
 		ulp_ctxs = min(resv_ctx, bnxt_get_ulp_stat_ctxs(bp));
 		bnxt_set_ulp_stat_ctxs(bp, ulp_ctxs);
 	}
@@ -11495,7 +11536,9 @@ static int bnxt_get_num_msix(struct bnxt *bp)
 
 static int bnxt_init_int_mode(struct bnxt *bp)
 {
-	int i, total_vecs, max, rc, min = 1, ulp_msix, tx_cp, tbl_size;
+	int i, total_vecs, max, rc, min = 1, ulp_msix, tbl_size, req_rx_rings;
+	int min_tx, req_tx_rings, req_cp_rings, req_tx_per_tc, req_tx_xdp;
+	int tcs = bp->num_tc ? bp->num_tc : 1;
 
 	total_vecs = bnxt_get_num_msix(bp);
 	max = bnxt_get_max_func_irqs(bp);
@@ -11530,19 +11573,50 @@ static int bnxt_init_int_mode(struct bnxt *bp)
 		bp->irq_tbl[i].vector = pci_irq_vector(bp->pdev, i);
 
 	bp->total_irqs = total_vecs;
+	req_tx_rings = bp->tx_nr_rings;
+	req_tx_per_tc = bp->tx_nr_rings_per_tc;
+	req_tx_xdp = bp->tx_nr_rings_xdp;
+	req_rx_rings = bp->rx_nr_rings;
+	req_cp_rings = bp->cp_nr_rings;
+
 	/* Trim rings based upon num of vectors allocated */
 	rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
 			     total_vecs - ulp_msix, min == 1);
 	if (rc)
 		goto msix_setup_exit;
 
-	tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
-	bp->cp_nr_rings = (min == 1) ?
-			  max_t(int, tx_cp, bp->rx_nr_rings) :
-			  tx_cp + bp->rx_nr_rings;
+	min_tx = bp->tx_nr_rings_xdp ? tcs + 1 : tcs;
+	if (bp->tx_nr_rings < min_tx) {
+		netdev_err(bp->dev, "Not enough MSI-X to satisfy min. TX rings\n");
+		rc = -ENOMEM;
+		goto msix_setup_exit_restore;
+	}
+
+	bnxt_adj_rings(bp);
+
+	if (bp->bnapi && (req_tx_rings != bp->tx_nr_rings ||
+			  req_rx_rings != bp->rx_nr_rings)) {
+		netdev_err(bp->dev, "Cannot shrink rings once NAPI is allocated\n");
+		rc = -ENOSPC;
+		goto msix_setup_exit_restore;
+	}
 
+	if (req_rx_rings != bp->rx_nr_rings) {
+		netdev_warn(bp->dev, "RX rings reduced from %d to %d\n",
+			    req_rx_rings, bp->rx_nr_rings);
+		bnxt_check_rss_tbl_lost(bp, req_rx_rings, bp->rx_nr_rings);
+		if (!netif_is_rxfh_configured(bp->dev))
+			bnxt_set_dflt_rss_indir_tbl(bp, NULL);
+	}
 	return 0;
 
+msix_setup_exit_restore:
+	bp->tx_nr_rings = req_tx_rings;
+	bp->tx_nr_rings_per_tc = req_tx_per_tc;
+	bp->tx_nr_rings_xdp = req_tx_xdp;
+	bp->rx_nr_rings = req_rx_rings;
+	bp->cp_nr_rings = req_cp_rings;
+
 msix_setup_exit:
 	netdev_err(bp->dev, "bnxt_init_int_mode err: %x\n", rc);
 	kfree(bp->irq_tbl);
@@ -11579,8 +11653,6 @@ static int bnxt_irqs_required(struct bnxt *bp)
 int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 {
 	bool irq_cleared = false;
-	bool irq_change = false;
-	int tcs = bp->num_tc;
 	int irqs_required;
 	int rc;
 
@@ -11590,7 +11662,6 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 	irqs_required = bnxt_irqs_required(bp);
 
 	if (irq_re_init && BNXT_NEW_RM(bp) && irqs_required != bp->total_irqs) {
-		irq_change = true;
 		if (!pci_msix_can_alloc_dyn(bp->pdev) || !bp->irq_tbl) {
 			bnxt_ulp_irq_stop(bp);
 			bnxt_clear_int_mode(bp);
@@ -11602,25 +11673,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 		if (!rc)
 			rc = bnxt_init_int_mode(bp);
 		bnxt_ulp_irq_restart(bp, rc);
-	} else if (irq_change && !rc) {
-		if (bnxt_change_msix(bp, irqs_required) != irqs_required)
-			rc = -ENOSPC;
+	} else if (irq_re_init && BNXT_NEW_RM(bp) && !rc) {
+		/* __bnxt_reserve_rings() may have shrunk the rings */
+		irqs_required = bnxt_irqs_required(bp);
+		if (irqs_required != bp->total_irqs) {
+			/* Don't bother reducing static IRQs to avoid disrupting
+			 * RoCE.
+			 */
+			if (pci_msix_can_alloc_dyn(bp->pdev) &&
+			    bnxt_change_msix(bp, irqs_required) !=
+			    irqs_required)
+				rc = -ENOSPC;
+		}
 	}
 	if (rc) {
 		netdev_err(bp->dev, "ring reservation/IRQ init failure rc: %d\n", rc);
 		return rc;
 	}
-	if (tcs && (bp->tx_nr_rings_per_tc * tcs !=
-		    bp->tx_nr_rings - bp->tx_nr_rings_xdp)) {
-		netdev_err(bp->dev, "tx ring reservation failure\n");
-		netdev_reset_tc(bp->dev);
-		bp->num_tc = 0;
-		if (bp->tx_nr_rings_xdp)
-			bp->tx_nr_rings_per_tc = bp->tx_nr_rings_xdp;
-		else
-			bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
-		return -ENOMEM;
-	}
 	return 0;
 }
 
@@ -13118,13 +13187,29 @@ static void bnxt_set_xdp_tx_rings(struct bnxt *bp)
 	bp->tx_nr_rings += bp->tx_nr_rings_xdp;
 }
 
-static void bnxt_adj_tx_rings(struct bnxt *bp)
+static void bnxt_adj_rings(struct bnxt *bp)
 {
-	/* Make adjustments if reserved TX rings are less than requested */
-	bp->tx_nr_rings -= bp->tx_nr_rings_xdp;
-	bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
-	if (bp->tx_nr_rings_xdp)
-		bnxt_set_xdp_tx_rings(bp);
+	int tcs = bp->num_tc ? bp->num_tc : 1;
+	int rx = bp->rx_nr_rings;
+
+	/* Make adjustments to rings based on TC/XDP/shared rings policies */
+	if (bp->tx_nr_rings_xdp) {
+		tcs++;
+		bp->tx_nr_rings_per_tc = bp->tx_nr_rings / tcs;
+		bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
+	} else {
+		bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
+	}
+
+	if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
+		bp->tx_nr_rings_per_tc = min(bp->tx_nr_rings_per_tc, rx);
+		bp->rx_nr_rings = bp->tx_nr_rings_per_tc;
+		if (bp->tx_nr_rings_xdp)
+			bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
+	}
+
+	bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs;
+	bnxt_set_cp_rings(bp, bp->flags & BNXT_FLAG_SHARED_RINGS);
 }
 
 static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
@@ -13144,7 +13229,6 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
 	if (rc)
 		return rc;
 
-	bnxt_adj_tx_rings(bp);
 	rc = bnxt_alloc_mem(bp, irq_re_init);
 	if (rc) {
 		netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
@@ -16806,7 +16890,6 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
 	if (rc && rc != -ENODEV)
 		netdev_warn(bp->dev, "Unable to reserve tx rings\n");
 
-	bnxt_adj_tx_rings(bp);
 	if (sh)
 		bnxt_adj_dflt_rings(bp, true);
 
@@ -16815,7 +16898,6 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
 		rc = __bnxt_reserve_rings(bp);
 		if (rc && rc != -ENODEV)
 			netdev_warn(bp->dev, "2nd rings reservation failed.\n");
-		bnxt_adj_tx_rings(bp);
 	}
 	if (rc) {
 		bp->tx_nr_rings = 0;
@@ -16845,8 +16927,6 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp)
 	if (rc)
 		goto init_dflt_ring_err;
 
-	bnxt_adj_tx_rings(bp);
-
 	bnxt_set_dflt_rfs(bp);
 
 init_dflt_ring_err:
@@ -17240,11 +17320,6 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		goto init_err_pci_clean;
 
-	/* No TC has been set yet and rings may have been trimmed due to
-	 * limited MSIX, so we re-initialize the TX rings per TC.
-	 */
-	bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
-
 	if (BNXT_PF(bp)) {
 		if (!bnxt_pf_wq) {
 			bnxt_pf_wq =
Signature · 1 line
2.51.0
#15 lore raw
In reply to Michael Chan
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

author maintainer
#16 lore raw
Quoted 10 lines · On Mon, Oct 12, 2026 at 3:15 PM <[email protected]> wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Sorry, missed this information:

The patches were tested on 5750X and 5760X chips using production FW version 237.x.x.x.

Reviewed-by on v3 3/7
#4 lore raw

Re: [PATCH net-next v3 3/7] bnxt_en: Refactor RSS table check logic

In reply to Michael Chan
Quoted 6 lines · Michael Chan

We have logic to see if we need to reset the user configured RSS table for the default RSS context if the RX rings have changed in __bnxt_reserve_rings(). Refactor this code into a helper that will be used by other callers later in the patch series. There is no change in behavior.

Quoted 6 lines
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
Reviewed-by on v3 4/7
#6 lore raw

Re: [PATCH net-next v3 4/7] bnxt_en: Refactor IRQs required logic

In reply to Michael Chan
Quoted 10 lines · Michael Chan

Refactor the logic to determine the required IRQ vectors into a new helper. Later patches in the series will make additional use of the helper. There is no change in behavior.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 25 ++++++++++++++---------
 1 file changed, 15 insertions(+), 10 deletions(-)
Reviewed-by on v3 6/7
#9 lore raw

Re: [PATCH net-next v3 6/7] bnxt_en: Remove support for the old NITRO A0 chip

In reply to Michael Chan
Quoted 10 lines · Michael Chan

Nitro A0 was a very old pre-production chip that requires significant workarounds. For example, it requires an extra (hidden) RX ring and CP ring to work, adding a lot of complexity. The workaround code is very buggy and breaks in many cases, including ethtool ring changes initiated by the user.

Remove all Nitro A0 workaround code completely. Print an error and abort if the chip is detected. This will simplify the next patch that fixes ring accounting bugs.

Quoted 7 lines
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 185 ++----------------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  11 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  12 +-
 3 files changed, 19 insertions(+), 189 deletions(-)
#11 lore raw

Re: [PATCH net-next v3 7/7] bnxt_en: Fix ring accounting and validation when rings are constrained

In reply to Michael Chan
Quoted 5 lines · Michael Chan

When __bnxt_reserve_rings() reserves fewer TX rings than requested, and an XDP program is attached, the driver used to blindly subtract bp->tx_nr_rings_xdp from bp->tx_nr_rings, potentially causing an integer underflow.

This is outside my normal space, was reviewing this for testing and had an agent spot what it thinks is a bug. It seemed reasonable to me but if you think this is wrong, please ignore.

drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 11676

Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -3
@@ -11602,25 +11673,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 		if (!rc)
 			rc = bnxt_init_int_mode(bp);
 		bnxt_ulp_irq_restart(bp, rc);
-	} else if (irq_change && !rc) {
-		if (bnxt_change_msix(bp, irqs_required) != irqs_required)
-			rc = -ENOSPC;
+	} else if (irq_re_init && BNXT_NEW_RM(bp) && !rc) {

should this be:

       } else if (irq_re_init && BNXT_NEW_RM(bp) && bp->irq_tbl && !rc) {

Note from the LLM was:

Unlike irq_change, this no longer implies bp->irq_tbl != NULL. After a FW/AER reset irq_tbl is gone but total_irqs is stale, so if the rings shrink we call bnxt_change_msix() with no table and fail with -ENOSPC.

Should this also check bp->irq_tbl?

~Gregory

#13 lore raw

Re: [PATCH net-next v3 7/7] bnxt_en: Fix ring accounting and validation when rings are constrained

In reply to Michael Chan
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] bnxt_reserve_rings() has a new branch, else if (irq_re_init && BNXT_NEW_RM(bp) && !rc), that can call bnxt_change_msix() while…
- [Medium] In bnxt_reserve_rings()'s callees, __bnxt_reserve_rings() and bnxt_init_int_mode(), bnxt_trim_rings() still runs before…

Pre-existing issues:
- [High] The patch adds a new way for RX rings to shrink, and that path reaches an existing out-of-bounds access.

--

bnxt_en: Fix ring accounting and validation when rings are constrained

This patch renames bnxt_adj_tx_rings() to bnxt_adj_rings(). TX, RX and CP rings are now scaled down together for XDP, TCs and shared rings, and bnxt_rings_ok() now checks for a minimum viable ring layout. The adjustment is centralized in __bnxt_reserve_rings() and bnxt_init_int_mode(), and bnxt_reserve_rings() recomputes the required IRQs after the rings may have shrunk.

Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index ed3f67dea0306..cbf7aef1d5b82 100644

[ ... ]

Quoted 18 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -2
@@ -11530,19 +11573,50 @@ static int bnxt_init_int_mode(struct bnxt *bp)
 		bp->irq_tbl[i].vector = pci_irq_vector(bp->pdev, i);
 
 	bp->total_irqs = total_vecs;
+	req_tx_rings = bp->tx_nr_rings;
+	req_tx_per_tc = bp->tx_nr_rings_per_tc;
+	req_tx_xdp = bp->tx_nr_rings_xdp;
+	req_rx_rings = bp->rx_nr_rings;
+	req_cp_rings = bp->cp_nr_rings;
+
 	/* Trim rings based upon num of vectors allocated */
 	rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
 			     total_vecs - ulp_msix, min == 1);
 	if (rc)
 		goto msix_setup_exit;
 
-	tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
-	bp->cp_nr_rings = (min == 1) ?

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_init_int_mode(struct bnxt *bp) · line 11595

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -2
-			  max_t(int, tx_cp, bp->rx_nr_rings) :
-			  tx_cp + bp->rx_nr_rings;
+	min_tx = bp->tx_nr_rings_xdp ? tcs + 1 : tcs;
+	if (bp->tx_nr_rings < min_tx) {
+		netdev_err(bp->dev, "Not enough MSI-X to satisfy min. TX rings\n");
+		rc = -ENOMEM;
+		goto msix_setup_exit_restore;
+	}
+
+	bnxt_adj_rings(bp);

[Severity: Medium]
Can the TX count returned by bnxt_trim_rings() be negative or too small here when XDP and mqprio TCs are both in use?

bnxt_trim_rings() still runs before bnxt_adj_rings(). When it trims the CP count, it converts back to a TX count with:

bnxt_num_cp_to_tx() {
	int tcs = bp->num_tc;

	return (tx_cp - bp->tx_nr_rings_xdp) * tcs +
	       bp->tx_nr_rings_xdp;
}

This uses the untrimmed tx_nr_rings_xdp. Take num_tc=2 with XDP, per_tc=8, xdp=8 and tx=24, so tx_cp is 16. With a limit of 5, tx becomes (5 - 8) * 2 + 8 = 2. That is below min_tx = 3, so this returns -ENOMEM.

The layout per_tc=2, xdp=2, tx=6, rx=2 needs only cp = max(4, 2) = 4, which fits in 5.

The result is also not monotonic. A limit of 6 gives tx=4, which bnxt_adj_rings() turns into a valid per_tc=1 layout, but limits of 5 and 4 both fail.

__bnxt_reserve_rings() has the same trim. The hwr.tx it produces is then rejected by the new bnxt_rings_ok() check.

The commit message says:

It will now correctly scale down TX rings for XDP and TCs evenly.

Should the trim path also scale the XDP rings down, rather than failing with -ENOMEM when a smaller valid layout exists?

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -0
+
+	if (bp->bnapi && (req_tx_rings != bp->tx_nr_rings ||
+			  req_rx_rings != bp->rx_nr_rings)) {

[ ... ]

Quoted 16 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -4
@@ -11590,7 +11662,6 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 	irqs_required = bnxt_irqs_required(bp);
 
 	if (irq_re_init && BNXT_NEW_RM(bp) && irqs_required != bp->total_irqs) {
-		irq_change = true;
 		if (!pci_msix_can_alloc_dyn(bp->pdev) || !bp->irq_tbl) {
 			bnxt_ulp_irq_stop(bp);
 			bnxt_clear_int_mode(bp);
@@ -11602,25 +11673,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 		if (!rc)
 			rc = bnxt_init_int_mode(bp);
 		bnxt_ulp_irq_restart(bp, rc);
-	} else if (irq_change && !rc) {
-		if (bnxt_change_msix(bp, irqs_required) != irqs_required)
-			rc = -ENOSPC;
+	} else if (irq_re_init && BNXT_NEW_RM(bp) && !rc) {

drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 11686

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+		/* __bnxt_reserve_rings() may have shrunk the rings */
+		irqs_required = bnxt_irqs_required(bp);
+		if (irqs_required != bp->total_irqs) {
+			/* Don't bother reducing static IRQs to avoid disrupting
+			 * RoCE.
+			 */
+			if (pci_msix_can_alloc_dyn(bp->pdev) &&
+			    bnxt_change_msix(bp, irqs_required) !=
+			    irqs_required)
+				rc = -ENOSPC;

[Severity: High]
Can this new branch be reached while bp->irq_tbl is NULL?

bnxt_clear_int_mode() frees the vectors and irq_tbl but does not reset bp->total_irqs:

bnxt_clear_int_mode() {
	pci_free_irq_vectors(bp->pdev);

	kfree(bp->irq_tbl);
	bp->irq_tbl = NULL;
	bp->irq_tbl_size = 0;
}

If the ring config has not changed, irqs_required still equals the stale bp->total_irqs at the first check, so irq_cleared stays false.

__bnxt_reserve_rings() can then shrink the rings, since bnapi is NULL and bnxt_adj_rings() runs. After that, the recomputed irqs_required differs from total_irqs and this calls bnxt_change_msix(), which returns early:

bnxt_change_msix() {
	if (!bp->irq_tbl)
		return 0;
	...
}

So rc becomes -ENOSPC whenever pci_msix_can_alloc_dyn() is true.

Before this patch, irq_change was set only when the first comparison mismatched. With a NULL irq_tbl, that always took the irq_cleared path, so bnxt_change_msix() was never called without a table.

Two paths appear to reach this state. The first is AER recovery:

bnxt_io_slot_reset()
bnxt_clear_int_mode()
(reservations cleared)
bnxt_io_resume()

    err = bnxt_reserve_rings(bp, true);
    if (!err && !bp->irq_tbl)
        err = bnxt_init_int_mode(bp);

The second is bnxt_hwrm_if_change() on a FW reset or caps change. It calls bnxt_clear_int_mode() and bnxt_cancel_reservations() before __bnxt_open_nic()->bnxt_reserve_rings(bp, true).

If firmware grants fewer rings after the reset, does bnxt_io_resume() skip netif_device_attach() and leave the device detached? On the FW reset path, does bnxt_open() fail?

Would adding a bp->irq_tbl check to this condition, or resetting bp->total_irqs in bnxt_clear_int_mode(), avoid this?

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
+		}
 	}

[ ... ]

Quoted 17 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -6
@@ -13118,13 +13187,29 @@ static void bnxt_set_xdp_tx_rings(struct bnxt *bp)
 	bp->tx_nr_rings += bp->tx_nr_rings_xdp;
 }
 
-static void bnxt_adj_tx_rings(struct bnxt *bp)
+static void bnxt_adj_rings(struct bnxt *bp)
 {
-	/* Make adjustments if reserved TX rings are less than requested */
-	bp->tx_nr_rings -= bp->tx_nr_rings_xdp;
-	bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
-	if (bp->tx_nr_rings_xdp)
-		bnxt_set_xdp_tx_rings(bp);
+	int tcs = bp->num_tc ? bp->num_tc : 1;
+	int rx = bp->rx_nr_rings;
+
+	/* Make adjustments to rings based on TC/XDP/shared rings policies */
+	if (bp->tx_nr_rings_xdp) {

drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_set_xdp_tx_rings(struct bnxt *bp) · line 13206

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+		tcs++;
+		bp->tx_nr_rings_per_tc = bp->tx_nr_rings / tcs;
+		bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
+	} else {
+		bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
+	}
+
+	if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
+		bp->tx_nr_rings_per_tc = min(bp->tx_nr_rings_per_tc, rx);
+		bp->rx_nr_rings = bp->tx_nr_rings_per_tc;

[Severity: High]
This is a pre-existing issue, but this clamp is a new way for the RX rings to shrink, and it leads to an existing out-of-bounds access through non-default RSS contexts.

In shared mode, a shortfall in TX alone now reduces RX. For example, with TCs=2, 8 combined channels, and FW granting 8 of 16 TX rings, RX drops from 8 to 4. The old bnxt_adj_tx_rings() left RX unchanged in this case.

bnxt_check_rss_tbl_lost() and bnxt_get_max_rss_ring() only look at the default bp->rss_indir_tbl. Additional RSS contexts created with "ethtool -X ... context N" keep their old indices.

On the next open, bnxt_alloc_mem() sizes bp->rx_ring[] from the smaller rx_nr_rings, and then:

bnxt_hwrm_realloc_rss_ctx_vnic()
__bnxt_setup_vnic_p5()

    bnxt_fill_hw_rss_tbl_p5()
		else if (vnic->flags & BNXT_VNIC_RSSCTX_FLAG)
			j = ethtool_rxfh_context_indir(vnic->rss_ctx)[i];
		...
		rxr = &bp->rx_ring[j];

		ring_id = rxr->rx_ring_struct.fw_ring_id;
		*ring_tbl++ = cpu_to_le16(ring_id);
		ring_id = bnxt_cp_ring_for_rx(bp, rxr);

Does this read past the end of bp->rx_ring[] on P5+ chips? It would then dereference rxr->rx_cpr taken from out-of-bounds memory and write garbage ring IDs into the hardware RSS table.

The commit message says the RSS context and n-tuple filter problems on RX shrink will be fixed in a separate patchset. This patch makes the shrink reachable in TX-constrained combined-mode setups that used to keep RX intact. Should that fix land together with this one?

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -0
+		if (bp->tx_nr_rings_xdp)
+			bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
+	}
+
+	bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs;
+	bnxt_set_cp_rings(bp, bp->flags & BNXT_FLAG_SHARED_RINGS);
 }

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012220827.340998-1-michael.chan%40broadcom.com
author maintainer
#14 lore raw

Re: [PATCH net-next v3 7/7] bnxt_en: Fix ring accounting and validation when rings are constrained

Quoted 13 lines · On Tue, Oct 13, 2026 at 4:01 PM <[email protected]> wrote:

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_init_int_mode(struct bnxt *bp) · line 11595

Quoted 12 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -4
-     tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
-     bp->cp_nr_rings = (min == 1) ?
-                       max_t(int, tx_cp, bp->rx_nr_rings) :
-                       tx_cp + bp->rx_nr_rings;
+     min_tx = bp->tx_nr_rings_xdp ? tcs + 1 : tcs;
+     if (bp->tx_nr_rings < min_tx) {
+             netdev_err(bp->dev, "Not enough MSI-X to satisfy min. TX rings\n");
+             rc = -ENOMEM;
+             goto msix_setup_exit_restore;
+     }
+
+     bnxt_adj_rings(bp);
Quoted 5 lines

[Severity: Medium]
Can the TX count returned by bnxt_trim_rings() be negative or too small here when XDP and mqprio TCs are both in use?

bnxt_trim_rings() still runs before bnxt_adj_rings().

...

This is a pre-existing problem in bnxt_trim_rings(). But since it is directly related to the issue fixed in this patch, I'll add a new patch to fix bnxt_trim_rings().

Quoted 22 lines
Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -3
@@ -11602,25 +11673,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
              if (!rc)
                      rc = bnxt_init_int_mode(bp);
              bnxt_ulp_irq_restart(bp, rc);
-     } else if (irq_change && !rc) {
-             if (bnxt_change_msix(bp, irqs_required) != irqs_required)
-                     rc = -ENOSPC;
+     } else if (irq_re_init && BNXT_NEW_RM(bp) && !rc) {

drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 11686

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+             /* __bnxt_reserve_rings() may have shrunk the rings */
+             irqs_required = bnxt_irqs_required(bp);
+             if (irqs_required != bp->total_irqs) {
+                     /* Don't bother reducing static IRQs to avoid disrupting
+                      * RoCE.
+                      */
+                     if (pci_msix_can_alloc_dyn(bp->pdev) &&
+                         bnxt_change_msix(bp, irqs_required) !=
+                         irqs_required)
+                             rc = -ENOSPC;

[Severity: High]
Can this new branch be reached while bp->irq_tbl is NULL?

Quoted 2 lines

bnxt_clear_int_mode() frees the vectors and irq_tbl but does not reset bp->total_irqs:

I can add this to the first patch in the series to clear bp->total_irqs more completely.

pw-bot: cr

Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +13 -6
@@ -13118,13 +13187,29 @@ static void bnxt_set_xdp_tx_rings(struct bnxt *bp)
      bp->tx_nr_rings += bp->tx_nr_rings_xdp;
 }
 
-static void bnxt_adj_tx_rings(struct bnxt *bp)
+static void bnxt_adj_rings(struct bnxt *bp)
 {
-     /* Make adjustments if reserved TX rings are less than requested */
-     bp->tx_nr_rings -= bp->tx_nr_rings_xdp;
-     bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
-     if (bp->tx_nr_rings_xdp)
-             bnxt_set_xdp_tx_rings(bp);
+     int tcs = bp->num_tc ? bp->num_tc : 1;
+     int rx = bp->rx_nr_rings;
+
+     /* Make adjustments to rings based on TC/XDP/shared rings policies */
+     if (bp->tx_nr_rings_xdp) {
+             tcs++;
+             bp->tx_nr_rings_per_tc = bp->tx_nr_rings / tcs;
+             bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
+     } else {
+             bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
+     }
+
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_set_xdp_tx_rings(struct bnxt *bp) · line 13206

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -0
+     if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
+             bp->tx_nr_rings_per_tc = min(bp->tx_nr_rings_per_tc, rx);
+             bp->rx_nr_rings = bp->tx_nr_rings_per_tc;

[Severity: High]
This is a pre-existing issue, but this clamp is a new way for the RX rings to shrink, and it leads to an existing out-of-bounds access through non-default RSS contexts.

It's already mentioned in the cover letter and the commit message that this will be deferred and addressed in a future patchset.

author maintainer
#12 lore raw

Re: [PATCH net-next v3 7/7] bnxt_en: Fix ring accounting and validation when rings are constrained

In reply to Gregory Price
Quoted 13 lines · Gregory Price

drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 11676

Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -3
@@ -11602,25 +11673,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
              if (!rc)
                      rc = bnxt_init_int_mode(bp);
              bnxt_ulp_irq_restart(bp, rc);
-     } else if (irq_change && !rc) {
-             if (bnxt_change_msix(bp, irqs_required) != irqs_required)
-                     rc = -ENOSPC;
+     } else if (irq_re_init && BNXT_NEW_RM(bp) && !rc) {

should this be:

       } else if (irq_re_init && BNXT_NEW_RM(bp) && bp->irq_tbl && !rc) {
Quoted 8 lines

Note from the LLM was:

Unlike irq_change, this no longer implies bp->irq_tbl != NULL. After a FW/AER reset irq_tbl is gone but total_irqs is stale, so if the rings shrink we call bnxt_change_msix() with no table and fail with -ENOSPC.

Should this also check bp->irq_tbl?

This is similar to the High issue that Sashiko found. My plan is to fix it more holistically in patch #1 in the series.

Thanks.