bnge: Make NQ0 persistent across open/close
v4 cover bnge: Make NQ0 persistent across open/close
Hi,
This series ensures the bnge driver's Notification Queue 0 (NQ0) remains persistent across interface close/open cycles rather than being destroyed and recreated on each cycle.
Currently, NQ0 exists only between ndo_open() and ndo_stop(), so firmware async events (e.g., link changes) and HWRM completions are not received while the interface is down.
NQ0 and its MSI-X vector are now allocated at probe and retained until remove. To conserve MSI-X vectors for Rx/Tx queues, vector 0 is shared. NQ0's NAPI exists only between ndo_open() and ndo_stop(), like every other NQ. While the interface is up, NQ0 runs via NAPI; while down, an IRQ-triggered work item processes non-datapath events.
Patches 1-4: Preparatory refactoring (alloc/free helpers, logging
fallbacks, NQ iterator, irq_tbl layout). No functional change apart from the items noted in their commit messages.
Patch 5 : Create NQ0 at probe, free it at remove, and add the worker
fallback.
irq_tbl layout after this series:
Vector 0 : NQ0 (probe to remove)
Vectors 1..A : RoCE (auxiliary driver)
Vectors A+1..N : Main L2 NQs (open/close only)
v4:
Addressed feedback from Jakub Kicinski on v3:
- NQ0's NAPI no longer outlives the open state: it is added in ndo_open() and deleted in ndo_stop(), like every other NQ.
- While down, the NQ0 IRQ handler queues a work item for async and HWRM events instead. The mode switches only in open/stop, so one context consumes NQ0 at a time.
https://lore.kernel.org/all/[email protected]/
v3:
Addressed feedback from Simon Horman:
- Extracted the failure-path NULL dereference fix in bnge_alloc_core() and submitted it as a standalone patch to 'net'.
- Dropped unnecessary defensive NULL checks (!bn->rx_ring and !bn->tx_ring) from bnge_free_tpa_info(), bnge_free_rx_rings(), and bnge_free_tx_rings().
Addressed comments from Sashiko:
https://sashiko.dev/#/patchset/20260922052904.59237-1-bhargava.marreddy%40broadcom.com
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922052904.59237-1-bhargava.marreddy%40broadcom.com
Other changes:
- Renamed series from "bnge: Support async events while down" to "bnge:
Make NQ0 persistent across open/close" to accurately reflect the streamlined focus on NQ0 persistence.
- Completely reorganized and streamlined the series from 6 patches down to 5.
- Redesigned and shifted the MSI-X vector/offset mapping layout:
Vector 0 (IRQ0) : Permanently dedicated to NQ0 at probe
(no longer recreated on RoCE load/unload or open/close)
Vectors 1..A : RoCE (aux) queues
Vectors A..N : Main L2 queues
- Added a new patch introducing bnge_err()/bnge_warn()/bnge_dbg() logging helper macros to fall back to PCI dev-level logging before netdev registration during probe (Patch 2).
- Switched to the bnge_for_each_open_nq() loop iterator to clarify which loops are open-only versus those that cover all NQs (Patch 3).
- Enhanced safety in bnge_napi_poll() to skip CQ notification processing on NQ0 when completion rings are unallocated while the interface is down, preventing invalid dereferences of cp_ring_arr (Patch 5).
v2:
https://lore.kernel.org/all/[email protected]/
Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20260901191728.643212-1-bhargava.marreddy%40broadcom.com
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260901191728.643212-1-bhargava.marreddy%40broadcom.com
- Dropped patch 7/7 ("bnge: Process async events while administratively down"):
- Link events while down are unnecessary to process since bnge_open() already queries and updates PHY settings via bnge_update_phy_setting().
- Keeps the series focused strictly on the NQ0/NAPI lifecycle refactoring.
- Corrected the order of operations in bnge_quiesce_nq0() to disable NAPI first, synchronize IRQ, and then ring the doorbell to prevent NAPI rescheduling race conditions.
- Added support for dynamic MSI-X vector reallocation by introducing bnge_reinit_nq0() during interface open.
- Fixed potential NULL pointer dereferences in core ring cleanups (e.g. bn->rx_ring,
bn->tx_ring, and bn->grp_info) on allocation failure paths and failed opens.
- Fixed a resource leak in bnge_init_nic() where RX ring pair buffers were leaked if chip initialization failed.
- Corrected the MSI-X vector demand check in bnge_resc.c to ensure sufficient vectors are allocated for both NQ0/aux and main rings.
- Changed CPU affinity hint failure from a fatal error to a warning.
- Added robust NULL pointer and safety checks in ring allocation and cleanup paths to prevent potential kernel crashes on allocation failures.
v1: https://lore.kernel.org/all/[email protected]/
Bhargava Marreddy (5):
bnge: factor out per-NQ alloc/free helpers
bnge: add bnge_err()/bnge_warn()/bnge_dbg() logging helpers
bnge: add bnge_for_each_open_nq() iterator
bnge: make irq_tbl layout depend on BNGE_FIRST_OPEN_NQ
bnge: create NQ0 during probe and keep it active across open/close
drivers/net/ethernet/broadcom/bnge/bnge.h | 47 ++ .../net/ethernet/broadcom/bnge/bnge_auxr.c | 4 +- .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 8 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 518 +++++++++++++----- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 5 + .../net/ethernet/broadcom/bnge/bnge_rmem.c | 10 - .../net/ethernet/broadcom/bnge/bnge_txrx.c | 57 +- .../net/ethernet/broadcom/bnge/bnge_txrx.h | 3 + 8 files changed, 493 insertions(+), 159 deletions(-)
Signature · 1 line
2.47.3
PATCH v4 1/5 bnge: factor out per-NQ alloc/free helpers
The descriptor array, ring memory, firmware ring and IRQ of an NQ are allocated and released inside loops over all NQs, and the NQ ring memory is set up with the completion rings.
Factor the per-NQ parts out into bnge_alloc_nq()/bnge_free_nq(), bnge_hwrm_nq_alloc()/bnge_hwrm_nq_free() and bnge_nq_request_irq()/bnge_nq_free_irq() so a single NQ can be created and destroyed independently of the others. Rename bnge_{alloc,free}_nq_arrays() to bnge_{alloc,free}_nqs().
The NQ ring_mem setup, ring allocation and fw_ring_id initialization move into bnge_alloc_nq(), so the NQ ring memory is allocated with the NQ descriptor arrays rather than with the completion rings. The fw_ring_id initialization thus moves from bnge_init_nic(), which runs on every open, to bnge_alloc_core(), which also runs on every open. The IRQ map index is also set there; the value is unchanged. The aux vector count it depends on is sampled once in bnge_alloc_nqs() and passed to bnge_alloc_nq(), so every NQ of one allocation gets a distinct irq_tbl index even if RoCE is disabled concurrently. The affinity hint is now derived from bnapi->index, which equals the loop index used before. The error path of bnge_alloc_nqs() now unwinds only the NQs allocated so far.
Also rename bnge_{alloc,free,init}_nq_tree() to bnge_{alloc,free,init}_cp_rings(), since they no longer touch the NQ itself, only the completion rings hanging off it.
One behavioral difference: bnge_hwrm_ring_free() now resets grp_info[i].nq_fw_ring_id to INVALID_HW_RING_ID for every NQ, not only for the NQs that had a valid firmware ring ID. Otherwise there is no functional change.
--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 290 ++++++++++-------- .../net/ethernet/broadcom/bnge/bnge_rmem.c | 10 - 2 files changed, 169 insertions(+), 131 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +169 -121
@@ -503,61 +503,95 @@ static int bnge_alloc_cp_desc_arr(struct bnge_cp_ring_info *cpr, int n)return -ENOMEM ; } -static void bnge_free_nq_arrays (struct bnge_net *bn) +static void bnge_free_nq (struct bnge_net *bn,struct bnge_napi *bnapi) { -struct bnge_dev *bd = bn->bd; -int i; +struct bnge_nq_ring_info *nqr = &bnapi->nq_ring; -for (i =0 ; i < bd->nq_nr_rings; i++) { -struct bnge_napi *bnapi = bn->bnapi[i]; +bnge_free_ring (bn->bd, &nqr->ring_struct.ring_mem); +bnge_free_nq_desc_arr (nqr); +} + +static int bnge_alloc_nq (struct bnge_net *bn,struct bnge_napi *bnapi, +u16 aux_msix) +{ +struct bnge_nq_ring_info *nqr = &bnapi->nq_ring; +struct bnge_ring_mem_info *rmem; +struct bnge_ring_struct *ring; +int rc; + + ring = &nqr->ring_struct; + rmem = &ring->ring_mem; -bnge_free_nq_desc_arr (&bnapi->nq_ring); + rc =bnge_alloc_nq_desc_arr (nqr, bn->cp_nr_pages); +if (rc) +return rc; + + nqr->bnapi = bnapi; + rmem->nr_pages = bn->cp_nr_pages; + rmem->page_size =HW_CMPD_RING_SIZE ; + rmem->pg_arr = (void **)nqr->desc_ring; + rmem->dma_arr = nqr->desc_mapping; + rmem->vmem_size =0 ; + rmem->flags =BNGE_RMEM_RING_PTE_FLAG ; + rc =bnge_alloc_ring (bn->bd, rmem); +if (rc) { +bnge_free_nq_desc_arr (nqr); +return rc; } + + ring->fw_ring_id =INVALID_HW_RING_ID_32BIT ; + ring->map_idx = aux_msix + bnapi->index; +return 0 ; } -static int bnge_alloc_nq_arrays (struct bnge_net *bn) +static void bnge_free_nqs (struct bnge_net *bn) {struct bnge_dev *bd = bn->bd; +int i; + +for (i =0 ; i < bd->nq_nr_rings; i++) +bnge_free_nq (bn, bn->bnapi[i]); +} + +static int bnge_alloc_nqs (struct bnge_net *bn) +{ +struct bnge_dev *bd = bn->bd; +u16 aux_msix;int i, rc; +/* RoCE can be disabled concurrently; sample the aux vector count once +* so every NQ gets a distinct irq_tbl index. +*/ + aux_msix =bnge_aux_get_msix (bd);for (i =0 ; i < bd->nq_nr_rings; i++) { -struct bnge_napi *bnapi = bn->bnapi[i]; - - rc =bnge_alloc_nq_desc_arr (&bnapi->nq_ring, bn->cp_nr_pages); + rc =bnge_alloc_nq (bn, bn->bnapi[i], aux_msix);if (rc) - goto err_free_nq_arrays; + goto err_free_nqs; }return 0 ; -err_free_nq_arrays: -bnge_free_nq_arrays (bn); +err_free_nqs: +while (--i >=0 ) +bnge_free_nq (bn, bn->bnapi[i]);return rc; } -static void bnge_free_nq_tree (struct bnge_net *bn) +static void bnge_free_cp_rings (struct bnge_net *bn) {struct bnge_dev *bd = bn->bd;int i;for (i =0 ; i < bd->nq_nr_rings; i++) { -struct bnge_napi *bnapi = bn->bnapi[i]; -struct bnge_nq_ring_info *nqr; -struct bnge_ring_struct *ring; +struct bnge_nq_ring_info *nqr = &bn->bnapi[i]->nq_ring;int j; - nqr = &bnapi->nq_ring; - ring = &nqr->ring_struct; - -bnge_free_ring (bd, &ring->ring_mem); -if (!nqr->cp_ring_arr)continue ;for (j =0 ; j < nqr->cp_ring_count; j++) {struct bnge_cp_ring_info *cpr = &nqr->cp_ring_arr[j]; - ring = &cpr->ring_struct; -bnge_free_ring (bd, &ring->ring_mem); +bnge_free_ring (bd, &cpr->ring_struct.ring_mem);bnge_free_cp_desc_arr (cpr); }kfree (nqr->cp_ring_arr);
@@ -594,31 +628,21 @@ static int alloc_one_cp_ring(struct bnge_net *bn,return rc; } -static int bnge_alloc_nq_tree (struct bnge_net *bn) +static int bnge_alloc_cp_rings (struct bnge_net *bn) {struct bnge_dev *bd = bn->bd; -int i, j, ulp_msix, rc; +int i, j, rc;int tcs =1 ; - ulp_msix =bnge_aux_get_msix (bd);for (i =0 , j =0 ; i < bd->nq_nr_rings; i++) {bool sh = !!(bd->flags &BNGE_EN_SHARED_CHNL );struct bnge_napi *bnapi = bn->bnapi[i];struct bnge_nq_ring_info *nqr;struct bnge_cp_ring_info *cpr; -struct bnge_ring_struct *ring;int cp_count =0 , k;int rx =0 , tx =0 ; nqr = &bnapi->nq_ring; - nqr->bnapi = bnapi; - ring = &nqr->ring_struct; - - rc =bnge_alloc_ring (bd, &ring->ring_mem); -if (rc) - goto err_free_nq_tree; - - ring->map_idx = ulp_msix + i;if (i < bd->rx_nr_rings) { cp_count++;
@@ -634,7 +658,7 @@ static int bnge_alloc_nq_tree(struct bnge_net *bn) nqr->cp_ring_arr =kzalloc_objs (*cpr, cp_count);if (!nqr->cp_ring_arr) { rc = -ENOMEM ; - goto err_free_nq_tree; + goto err_free_cp_rings; } nqr->cp_ring_count = cp_count;
@@ -643,7 +667,7 @@ static int bnge_alloc_nq_tree(struct bnge_net *bn) cpr = &nqr->cp_ring_arr[k]; rc =alloc_one_cp_ring (bn, cpr);if (rc) - goto err_free_nq_tree; + goto err_free_cp_rings; cpr->bnapi = bnapi; cpr->cp_idx = k;
@@ -663,8 +687,8 @@ static int bnge_alloc_nq_tree(struct bnge_net *bn) }return 0 ; -err_free_nq_tree: -bnge_free_nq_tree (bn); +err_free_cp_rings: +bnge_free_cp_rings (bn);return rc; }
@@ -1200,8 +1224,8 @@ static void bnge_free_core(struct bnge_net *bn)bnge_free_vnic_attributes (bn);bnge_free_tx_rings (bn);bnge_free_rx_rings (bn); -bnge_free_nq_tree (bn); -bnge_free_nq_arrays (bn); +bnge_free_cp_rings (bn); +bnge_free_nqs (bn);bnge_free_ring_stats (bn);bnge_free_ring_grps (bn);bnge_free_vnics (bn);
@@ -1232,13 +1256,9 @@ static int bnge_alloc_core(struct bnge_net *bn) bn->bnapi = bnapi; bnapi += arr_size;for (i =0 ; i < bd->nq_nr_rings; i++, bnapi += size) { -struct bnge_nq_ring_info *nqr; - bn->bnapi[i] = bnapi; bn->bnapi[i]->index = i; bn->bnapi[i]->bn = bn; - nqr = &bn->bnapi[i]->nq_ring; - nqr->ring_struct.ring_mem.flags =BNGE_RMEM_RING_PTE_FLAG ; } bn->rx_ring = kzalloc_objs(struct bnge_rx_ring_info, bd->rx_nr_rings);
@@ -1297,7 +1317,7 @@ static int bnge_alloc_core(struct bnge_net *bn)if (rc) goto err_free_ring_stats; - rc =bnge_alloc_nq_arrays (bn); + rc =bnge_alloc_nqs (bn);if (rc) goto err_free_vnics;
@@ -1305,13 +1325,13 @@ static int bnge_alloc_core(struct bnge_net *bn) rc =bnge_alloc_rx_rings (bn);if (rc) - goto err_free_nq_arrays; + goto err_free_nqs; rc =bnge_alloc_tx_rings (bn);if (rc) goto err_free_rx_rings; - rc =bnge_alloc_nq_tree (bn); + rc =bnge_alloc_cp_rings (bn);if (rc) goto err_free_tx_rings;
@@ -1320,17 +1340,17 @@ static int bnge_alloc_core(struct bnge_net *bn)BNGE_VNIC_UCAST_FLAG ; rc =bnge_alloc_vnic_attributes (bn);if (rc) - goto err_free_nq_tree; + goto err_free_cp_rings;return 0 ; -err_free_nq_tree: -bnge_free_nq_tree (bn); +err_free_cp_rings: +bnge_free_cp_rings (bn); err_free_tx_rings:bnge_free_tx_rings (bn); err_free_rx_rings:bnge_free_rx_rings (bn); -err_free_nq_arrays: -bnge_free_nq_arrays (bn); +err_free_nqs: +bnge_free_nqs (bn); err_free_vnics:bnge_free_vnics (bn); err_free_ring_stats:
@@ -1389,21 +1409,18 @@ static int bnge_cp_num_to_irq_num(struct bnge_net *bn, int n)return nqr->ring_struct.map_idx; } -static void bnge_init_nq_tree (struct bnge_net *bn) +static void bnge_init_cp_rings (struct bnge_net *bn) {struct bnge_dev *bd = bn->bd;int i, j;for (i =0 ; i < bd->nq_nr_rings; i++) {struct bnge_nq_ring_info *nqr = &bn->bnapi[i]->nq_ring; -struct bnge_ring_struct *ring = &nqr->ring_struct; - ring->fw_ring_id =INVALID_HW_RING_ID_32BIT ;for (j =0 ; j < nqr->cp_ring_count; j++) {struct bnge_cp_ring_info *cpr = &nqr->cp_ring_arr[j]; - ring = &cpr->ring_struct; - ring->fw_ring_id =INVALID_HW_RING_ID_32BIT ; + cpr->ring_struct.fw_ring_id =INVALID_HW_RING_ID_32BIT ; } } }
@@ -1914,6 +1931,44 @@ static int bnge_hwrm_rx_ring_alloc(struct bnge_net *bn,return 0 ; } +static int bnge_hwrm_nq_alloc (struct bnge_net *bn,struct bnge_napi *bnapi) +{ +struct bnge_nq_ring_info *nqr = &bnapi->nq_ring; +u32 type =HWRM_RING_ALLOC_NQ ; +struct bnge_ring_struct *ring; +unsigned int vector; +u32 map_idx; +int rc; + + ring = &nqr->ring_struct; + map_idx = ring->map_idx; + + vector = bn->bd->irq_tbl[map_idx].vector; +disable_irq_nosync (vector); + rc =hwrm_ring_alloc_send_msg (bn, ring, type, map_idx); +if (rc) { +enable_irq (vector); +return rc; + } +bnge_set_db (bn, &nqr->nq_db, type, map_idx, ring->fw_ring_id); +bnge_db_nq (bn, &nqr->nq_db, nqr->nq_raw_cons); +enable_irq (vector); + +return 0 ; +} + +static void bnge_hwrm_nq_free (struct bnge_net *bn,struct bnge_napi *bnapi) +{ +struct bnge_ring_struct *ring = &bnapi->nq_ring.ring_struct; + +if (ring->fw_ring_id ==INVALID_HW_RING_ID_32BIT ) +return ; + +hwrm_ring_free_send_msg (bn, ring,RING_FREE_REQ_RING_TYPE_NQ , +INVALID_HW_RING_ID ); + ring->fw_ring_id =INVALID_HW_RING_ID_32BIT ; +} +static int bnge_hwrm_ring_alloc (struct bnge_net *bn) {struct bnge_dev *bd = bn->bd;
@@ -1923,22 +1978,11 @@ static int bnge_hwrm_ring_alloc(struct bnge_net *bn) agg_rings = !!(bnge_is_agg_reqd (bd));for (i =0 ; i < bd->nq_nr_rings; i++) {struct bnge_napi *bnapi = bn->bnapi[i]; -struct bnge_nq_ring_info *nqr = &bnapi->nq_ring; -struct bnge_ring_struct *ring = &nqr->ring_struct; -u32 type =HWRM_RING_ALLOC_NQ ; -u32 map_idx = ring->map_idx; -unsigned int vector; +struct bnge_ring_struct *ring = &bnapi->nq_ring.ring_struct; - vector = bd->irq_tbl[map_idx].vector; -disable_irq_nosync (vector); - rc =hwrm_ring_alloc_send_msg (bn, ring, type, map_idx); -if (rc) { -enable_irq (vector); + rc =bnge_hwrm_nq_alloc (bn, bnapi); +if (rc) goto err_out; - } -bnge_set_db (bn, &nqr->nq_db, type, map_idx, ring->fw_ring_id); -bnge_db_nq (bn, &nqr->nq_db, nqr->nq_raw_cons); -enable_irq (vector); bn->grp_info[i].nq_fw_ring_id = (u16 )ring->fw_ring_id;if (!i) {
@@ -2566,23 +2610,14 @@ static void bnge_hwrm_ring_free(struct bnge_net *bn, bool close_path)bnge_disable_int_sync (bn);for (i =0 ; i < bd->nq_nr_rings; i++) { -struct bnge_napi *bnapi = bn->bnapi[i]; -struct bnge_nq_ring_info *nqr; -struct bnge_ring_struct *ring; +struct bnge_nq_ring_info *nqr = &bn->bnapi[i]->nq_ring;int j; - nqr = &bnapi->nq_ring;for (j =0 ; j < nqr->cp_ring_count && nqr->cp_ring_arr; j++)bnge_hwrm_cp_ring_free (bn, &nqr->cp_ring_arr[j]); - ring = &nqr->ring_struct; -if (ring->fw_ring_id !=INVALID_HW_RING_ID_32BIT ) { -hwrm_ring_free_send_msg (bn, ring, -RING_FREE_REQ_RING_TYPE_NQ , -INVALID_HW_RING_ID ); - ring->fw_ring_id =INVALID_HW_RING_ID_32BIT ; - bn->grp_info[i].nq_fw_ring_id =INVALID_HW_RING_ID ; - } +bnge_hwrm_nq_free (bn, bn->bnapi[i]); + bn->grp_info[i].nq_fw_ring_id =INVALID_HW_RING_ID ; } }
@@ -2627,27 +2662,60 @@ static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path)bnge_hwrm_stat_ctx_free (bn); } -static void bnge_free_irq (struct bnge_net *bn) +static void bnge_nq_free_irq (struct bnge_net *bn,struct bnge_napi *bnapi) { +int map_idx = bnapi->nq_ring.ring_struct.map_idx; +struct bnge_irq *irq = &bn->bd->irq_tbl[map_idx]; + +if (irq->requested) { +if (irq->have_cpumask) { +irq_set_affinity_hint (irq->vector,NULL ); +free_cpumask_var (irq->cpu_mask); + irq->have_cpumask =0 ; + } +free_irq (irq->vector, bnapi); + } + + irq->requested =0 ; +} + +static int bnge_nq_request_irq (struct bnge_net *bn,struct bnge_napi *bnapi) +{ +int map_idx = bnapi->nq_ring.ring_struct.map_idx;struct bnge_dev *bd = bn->bd;struct bnge_irq *irq; -int i; +int rc; -for (i =0 ; i < bd->nq_nr_rings; i++) { -int map_idx =bnge_cp_num_to_irq_num (bn, i); + irq = &bd->irq_tbl[map_idx]; - irq = &bd->irq_tbl[map_idx]; -if (irq->requested) { -if (irq->have_cpumask) { -irq_set_affinity_hint (irq->vector,NULL ); -free_cpumask_var (irq->cpu_mask); - irq->have_cpumask =0 ; - } -free_irq (irq->vector, bn->bnapi[i]); - } + rc =request_irq (irq->vector, irq->handler,0 , irq->name, bnapi); +if (rc) +return rc; + +netif_napi_set_irq_locked (&bnapi->napi, irq->vector); + irq->requested =1 ; + +if (zalloc_cpumask_var (&irq->cpu_mask,GFP_KERNEL )) { +int numa_node =dev_to_node (&bd->pdev->dev); - irq->requested =0 ; + irq->have_cpumask =1 ; +cpumask_set_cpu (cpumask_local_spread (bnapi->index, numa_node), + irq->cpu_mask); +if (irq_set_affinity_hint (irq->vector, irq->cpu_mask)) +netdev_warn (bn->netdev, +"Set affinity failed, IRQ = %d\n" , + irq->vector); } +return 0 ; +} + +static void bnge_free_irq (struct bnge_net *bn) +{ +struct bnge_dev *bd = bn->bd; +int i; + +for (i =0 ; i < bd->nq_nr_rings; i++) +bnge_nq_free_irq (bn, bn->bnapi[i]); }static int bnge_request_irq (struct bnge_net *bn)
@@ -2661,29 +2729,9 @@ static int bnge_request_irq(struct bnge_net *bn)return rc; }for (i =0 ; i < bd->nq_nr_rings; i++) { -int map_idx =bnge_cp_num_to_irq_num (bn, i); -struct bnge_irq *irq = &bd->irq_tbl[map_idx]; - - rc =request_irq (irq->vector, irq->handler,0 , irq->name, - bn->bnapi[i]); + rc =bnge_nq_request_irq (bn, bn->bnapi[i]);if (rc) goto err_free_irq; - -netif_napi_set_irq_locked (&bn->bnapi[i]->napi, irq->vector); - irq->requested =1 ; - -if (zalloc_cpumask_var (&irq->cpu_mask,GFP_KERNEL )) { -int numa_node =dev_to_node (&bd->pdev->dev); - - irq->have_cpumask =1 ; -cpumask_set_cpu (cpumask_local_spread (i, numa_node), - irq->cpu_mask); -if (irq_set_affinity_hint (irq->vector, irq->cpu_mask)) { -netdev_warn (bn->netdev, -"Set affinity failed, IRQ = %d\n" , - irq->vector); - } - } }return 0 ;
@@ -2830,7 +2878,7 @@ static int bnge_init_nic(struct bnge_net *bn) {int rc; -bnge_init_nq_tree (bn); +bnge_init_cp_rings (bn);bnge_init_rx_rings (bn); rc =bnge_alloc_rx_ring_pair_bufs (bn);
drivers/net/ethernet/broadcom/bnge/bnge_rmem.c +0 -10
@@ -431,20 +431,10 @@ void bnge_init_ring_struct(struct bnge_net *bn)for (i =0 ; i < bd->nq_nr_rings; i++) {struct bnge_napi *bnapi = bn->bnapi[i];struct bnge_ring_mem_info *rmem; -struct bnge_nq_ring_info *nqr;struct bnge_rx_ring_info *rxr;struct bnge_tx_ring_info *txr;struct bnge_ring_struct *ring; - nqr = &bnapi->nq_ring; - ring = &nqr->ring_struct; - rmem = &ring->ring_mem; - rmem->nr_pages = bn->cp_nr_pages; - rmem->page_size =HW_CMPD_RING_SIZE ; - rmem->pg_arr = (void **)nqr->desc_ring; - rmem->dma_arr = nqr->desc_mapping; - rmem->vmem_size =0 ; - rxr = bnapi->rx_ring;if (!rxr) goto skip_rx;
Signature · 1 line
2.47.3
PATCH v4 2/5 bnge: add bnge_err()/bnge_warn()/bnge_dbg() logging helpers
In reply to Bhargava Marreddynetdev_err() and netdev_warn() print "(unnamed net_device) (uninitialized)" instead of the interface name while the netdev has not been registered yet. Later patches in this series run NQ0 init before register_netdev() in probe, so messages from the HWRM ring alloc/free paths and from NQ0's async event handling would be logged that way.
Add bnge_err(), bnge_warn() and bnge_dbg(), which take a struct bnge_dev and log through the netdev once it has been registered, including while it is being unregistered and after, where it keeps its name. Before that, fall back to dev_err()/dev_warn()/dev_dbg() on the PCI device.
Convert the HWRM ring alloc/free error messages, the IRQ affinity hint warning and the async event debug message, which are reachable from those paths. No other message is changed.
No functional change, apart from the log prefix of these messages before register_netdev().
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 18 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_hwrm_lib.c | 8 +++++--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 5 ++--- drivers/net/ethernet/broadcom/bnge/bnge_txrx.c | 4 ++-- 4 files changed, 27 insertions(+), 8 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +18 -0
@@ -220,6 +220,24 @@ struct bnge_dev {u32 phy_flags; }; +/* The netdev has no name until register_netdev(), so log through the PCI +* device before that (e.g. during probe). +*/ +#define bnge_log (level, bd, fmt, ...) \ + do { \ + struct bnge_dev *__bd = (bd); \ + \ + if (__bd->netdev && \ + READ_ONCE(__bd->netdev->reg_state) != NETREG_UNINITIALIZED)\ + netdev_##level(__bd->netdev, fmt, ##__VA_ARGS__);\ + else \ + dev_##level(__bd->dev, fmt, ##__VA_ARGS__); \ + } while (0) + +#define bnge_err (bd, fmt, ...) bnge_log(err, bd, fmt, ##__VA_ARGS__) +#define bnge_warn (bd, fmt, ...) bnge_log(warn, bd, fmt, ##__VA_ARGS__) +#define bnge_dbg (bd, fmt, ...) bnge_log(dbg, bd, fmt, ##__VA_ARGS__) +static inline bool bnge_is_roce_en (struct bnge_dev *bd) {return bd->flags &BNGE_EN_ROCE ;
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +5 -3
@@ -1302,7 +1302,8 @@ int hwrm_ring_free_send_msg(struct bnge_net *bn,bnge_hwrm_req_drop (bd, req); exit:if (rc) { -netdev_err (bd->netdev,"hwrm_ring_free type %d failed. rc:%d\n" , ring_type, rc); +bnge_err (bd,"hwrm_ring_free type %d failed. rc:%d\n" , + ring_type, rc);return -EIO ; }return 0 ;
@@ -1395,7 +1396,7 @@ int hwrm_ring_alloc_send_msg(struct bnge_net *bn, req->int_mode =RING_ALLOC_REQ_INT_MODE_MSIX ;break ;default : -netdev_err (bn->netdev,"hwrm alloc invalid ring type %d\n" , ring_type); +bnge_err (bd,"hwrm alloc invalid ring type %d\n" , ring_type);return -EINVAL ; }
@@ -1406,7 +1407,8 @@ int hwrm_ring_alloc_send_msg(struct bnge_net *bn, exit:if (rc) { -netdev_err (bd->netdev,"hwrm_ring_alloc type %d failed. rc:%d\n" , ring_type, rc); +bnge_err (bd,"hwrm_ring_alloc type %d failed. rc:%d\n" , + ring_type, rc);return -EIO ; } ring->fw_ring_id = ring_id;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2 -3
@@ -2702,9 +2702,8 @@ static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi)cpumask_set_cpu (cpumask_local_spread (bnapi->index, numa_node), irq->cpu_mask);if (irq_set_affinity_hint (irq->vector, irq->cpu_mask)) -netdev_warn (bn->netdev, -"Set affinity failed, IRQ = %d\n" , - irq->vector); +bnge_warn (bd,"Set affinity failed, IRQ = %d\n" , + irq->vector); }return 0 ; }
drivers/net/ethernet/broadcom/bnge/bnge_txrx.c +2 -2
@@ -1135,8 +1135,8 @@ static void bnge_async_event_process(struct bnge_net *bn,u32 data1 =le32_to_cpu (cmpl->event_data1);u32 data2 =le32_to_cpu (cmpl->event_data2); -netdev_dbg (bn->netdev,"hwrm event 0x%x {0x%x, 0x%x}\n" , - event_id, data1, data2); +bnge_dbg (bn->bd,"hwrm event 0x%x {0x%x, 0x%x}\n" , + event_id, data1, data2);switch (event_id) {case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE :
Signature · 1 line
2.47.3
PATCH v4 3/5 bnge: add bnge_for_each_open_nq() iterator
In reply to Bhargava MarreddyAdd BNGE_FIRST_OPEN_NQ and bnge_for_each_open_nq(), and use them in the loops that will need to skip the NQ that is created at probe once it is split out. The "open" NQs are those whose IRQs and firmware rings are created in ndo_open() and destroyed in ndo_stop(), i.e., all NQs from index BNGE_FIRST_OPEN_NQ on.
The loops over the Completion Rings (CP rings), per-NQ stats, and NAPI registration (init/del) are intentionally left alone to cover all NQs (including NQ0), as NQ0's completion structures and NAPI registration remain tied to open/stop. The bnapi allocation and NAPI enable/disable loops are converted here; NQ0's NAPI enable/disable is handled separately by a later patch in this series.
In bnge_hwrm_ring_free(), split the NQ free out of the completion ring loop so that it can use the iterator, mirroring bnge_hwrm_ring_alloc(). This changes the order of the firmware commands: previously each NQ was freed right after its own completion rings, now all completion rings are freed first and all NQs after. Each completion ring is still freed before the NQ it belongs to.
BNGE_FIRST_OPEN_NQ is 0 for now, i.e., every NQ is an open NQ, so the macro expands to the loops it replaces. Apart from the firmware command order above, no functional change.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 8 ++++++ .../net/ethernet/broadcom/bnge/bnge_netdev.c | 25 +++++++++++-------- 2 files changed, 22 insertions(+), 11 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +8 -0
@@ -238,6 +238,14 @@ struct bnge_dev {#define bnge_warn (bd, fmt, ...) bnge_log(warn, bd, fmt, ##__VA_ARGS__)#define bnge_dbg (bd, fmt, ...) bnge_log(dbg, bd, fmt, ##__VA_ARGS__) +/* Index of the first NQ created in ndo_open() and destroyed in ndo_stop(); +* lower NQs live from probe to remove. +*/ +#define BNGE_FIRST_OPEN_NQ 0 + +#define bnge_for_each_open_nq (i, bd) \ + for ((i) = BNGE_FIRST_OPEN_NQ; (i) < (bd)->nq_nr_rings; (i)++) +static inline bool bnge_is_roce_en (struct bnge_dev *bd) {return bd->flags &BNGE_EN_ROCE ;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +14 -11
@@ -549,7 +549,7 @@ static void bnge_free_nqs(struct bnge_net *bn)struct bnge_dev *bd = bn->bd;int i; -for (i =0 ; i < bd->nq_nr_rings; i++) +bnge_for_each_open_nq (i, bd)bnge_free_nq (bn, bn->bnapi[i]); }
@@ -563,7 +563,7 @@ static int bnge_alloc_nqs(struct bnge_net *bn)* so every NQ gets a distinct irq_tbl index. */ aux_msix =bnge_aux_get_msix (bd); -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) { rc =bnge_alloc_nq (bn, bn->bnapi[i], aux_msix);if (rc) goto err_free_nqs;
@@ -571,7 +571,7 @@ static int bnge_alloc_nqs(struct bnge_net *bn)return 0 ; err_free_nqs: -while (--i >=0 ) +while (--i >=BNGE_FIRST_OPEN_NQ )bnge_free_nq (bn, bn->bnapi[i]);return rc; }
@@ -1255,10 +1255,11 @@ static int bnge_alloc_core(struct bnge_net *bn) bn->bnapi = bnapi; bnapi += arr_size; -for (i =0 ; i < bd->nq_nr_rings; i++, bnapi += size) { +bnge_for_each_open_nq (i, bd) { bn->bnapi[i] = bnapi; bn->bnapi[i]->index = i; bn->bnapi[i]->bn = bn; + bnapi += size; } bn->rx_ring = kzalloc_objs(struct bnge_rx_ring_info, bd->rx_nr_rings);
@@ -1976,7 +1977,7 @@ static int bnge_hwrm_ring_alloc(struct bnge_net *bn)int i, rc =0 ; agg_rings = !!(bnge_is_agg_reqd (bd)); -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) {struct bnge_napi *bnapi = bn->bnapi[i];struct bnge_ring_struct *ring = &bnapi->nq_ring.ring_struct;
@@ -2432,7 +2433,7 @@ static void bnge_enable_int(struct bnge_net *bn)struct bnge_dev *bd = bn->bd;int i; -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) {struct bnge_napi *bnapi = bn->bnapi[i];struct bnge_nq_ring_info *nqr;
@@ -2449,7 +2450,7 @@ static void bnge_disable_napi(struct bnge_net *bn)if (test_and_set_bit (BNGE_STATE_NAPI_DISABLED , &bn->state))return ; -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) {struct bnge_napi *bnapi = bn->bnapi[i];napi_disable_locked (&bnapi->napi);
@@ -2462,7 +2463,7 @@ static void bnge_enable_napi(struct bnge_net *bn)int i;clear_bit (BNGE_STATE_NAPI_DISABLED , &bn->state); -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) {struct bnge_napi *bnapi = bn->bnapi[i]; bnapi->in_reset = false;
@@ -2615,7 +2616,9 @@ static void bnge_hwrm_ring_free(struct bnge_net *bn, bool close_path)for (j =0 ; j < nqr->cp_ring_count && nqr->cp_ring_arr; j++)bnge_hwrm_cp_ring_free (bn, &nqr->cp_ring_arr[j]); + } +bnge_for_each_open_nq (i, bd) {bnge_hwrm_nq_free (bn, bn->bnapi[i]); bn->grp_info[i].nq_fw_ring_id =INVALID_HW_RING_ID ; }
@@ -2628,7 +2631,7 @@ static void bnge_setup_msix(struct bnge_net *bn)int len, i; len =sizeof (bd->irq_tbl[0 ].name); -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) {int map_idx =bnge_cp_num_to_irq_num (bn, i);char *attr;
@@ -2713,7 +2716,7 @@ static void bnge_free_irq(struct bnge_net *bn)struct bnge_dev *bd = bn->bd;int i; -for (i =0 ; i < bd->nq_nr_rings; i++) +bnge_for_each_open_nq (i, bd)bnge_nq_free_irq (bn, bn->bnapi[i]); }
@@ -2727,7 +2730,7 @@ static int bnge_request_irq(struct bnge_net *bn)netdev_err (bn->netdev,"bnge_setup_interrupts err: %d\n" , rc);return rc; } -for (i =0 ; i < bd->nq_nr_rings; i++) { +bnge_for_each_open_nq (i, bd) { rc =bnge_nq_request_irq (bn, bn->bnapi[i]);if (rc) goto err_free_irq;
Signature · 1 line
2.47.3
PATCH v4 4/5 bnge: make irq_tbl layout depend on BNGE_FIRST_OPEN_NQ
In reply to Bhargava MarreddyNQ0 will be created at probe, before the aux (RoCE) device has been given its MSI-X vectors, and must keep its vector for the lifetime of the driver. So the probe NQs must come first in irq_tbl, followed by the aux vectors and then the open NQs, instead of putting all NQs after the aux vectors.
Describe the irq_tbl layout once, next to BNGE_FIRST_OPEN_NQ, and add bnge_nq_irq_idx() and bnge_aux_irq_idx() to compute the irq_tbl index of an NQ and of an aux vector from it. bnge_fill_msix_vecs() uses the latter to hand the aux device the vectors that follow the probe NQs.
The ring_idx passed to the aux device changes meaning accordingly: it is the irq_tbl index of the vector, not an index within the aux range. This matches how NQ rings are created, where the ring index is used as the logical ID that ties the ring to its doorbell and MSI-X vector. The aux driver uses the values it is given, so it needs no change. The total number of vectors is unchanged.
BNGE_FIRST_OPEN_NQ is 0 for now, so the layout is unchanged. No functional change.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 19 +++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_auxr.c | 4 ++-- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +19 -0
@@ -240,6 +240,8 @@ struct bnge_dev {/* Index of the first NQ created in ndo_open() and destroyed in ndo_stop(); * lower NQs live from probe to remove. +* +* irq_tbl order: probe-time NQs, aux (RoCE) vectors, open-time NQs. */ #define BNGE_FIRST_OPEN_NQ 0
@@ -289,4 +291,21 @@ static inline void bnge_db_write(struct bnge_dev *bd, struct bnge_db_info *db,bool bnge_aux_registered (struct bnge_dev *bd);u16 bnge_aux_get_msix (struct bnge_dev *bd); +/* irq_tbl index of the i-th aux vector, also used as its ring_idx */ +static inline int bnge_aux_irq_idx (int i) +{ +return BNGE_FIRST_OPEN_NQ + i; +} + +/* irq_tbl index of NQ nq_idx. @aux_msix is a single bnge_aux_get_msix() +* sample shared by all NQs of one allocation. +*/ +static inline int bnge_nq_irq_idx (u16 aux_msix,int nq_idx) +{ +if (nq_idx <BNGE_FIRST_OPEN_NQ ) +return nq_idx; + +return aux_msix + nq_idx; +} +#endif /* _BNGE_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_auxr.c +2 -2
@@ -34,9 +34,9 @@ static void bnge_fill_msix_vecs(struct bnge_dev *bd, } num_msix = auxr_dev->auxr_info->msix_requested;for (i =0 ; i < num_msix; i++) { - info[i].vector = bd->irq_tbl[i].vector; + info[i].vector = bd->irq_tbl[bnge_aux_irq_idx (i)].vector; info[i].db_offset = bd->db_offset; - info[i].ring_idx = i; + info[i].ring_idx =bnge_aux_irq_idx (i); } }
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +1 -1
@@ -540,7 +540,7 @@ static int bnge_alloc_nq(struct bnge_net *bn, struct bnge_napi *bnapi, } ring->fw_ring_id =INVALID_HW_RING_ID_32BIT ; - ring->map_idx = aux_msix + bnapi->index; + ring->map_idx =bnge_nq_irq_idx (aux_msix, bnapi->index);return 0 ; }
Signature · 1 line
2.47.3
PATCH v4 5/5 bnge: create NQ0 during probe and keep it active across open/close
In reply to Bhargava MarreddyUnlike the other NQs, NQ0 is not only a datapath queue. Besides Rx/Tx completions it also delivers firmware async events (including link events) and HWRM command completions. It is currently created in ndo_open() and destroyed in ndo_stop(), so none of these non-datapath events are received while the interface is down.
Create NQ0 once at probe and keep it, together with its MSI-X vector, until remove. NAPI is not kept around: as for every other NQ, NQ0's NAPI exists only between ndo_open() and ndo_stop(). A dedicated async-only vector would avoid sharing but would cost one MSI-X per function, taking it away from the Rx/Tx queues, so NQ0's vector is shared instead.
The vector's handler serves NQ0 in one of two ways, selected by the new BNGE_STATE_NQ0_NAPI bit:
- NAPI mode (interface up): the handler schedules NQ0's NAPI, which handles Rx/Tx, async and HWRM events.
- Worker mode (interface down): there is no NAPI instance, so the handler queues nq0_work. The worker runs bnge_nq0_poll(), which handles async events and HWRM completions, discards completion notifications for CQs (none exist while down) and re-arms the NQ.
The mode changes only in open and stop, with NQ0's IRQ disabled and nq0_work cancelled, so one context consumes NQ0 at a time. Unread notifications for the destroyed rings are dropped before NAPI is re-enabled, so bnge_napi_poll() needs no bounds check on the CQ handle.
nq0_work runs on a dedicated ordered workqueue, nq0_wq.
Async events received while the interface is down are queued to sp_task, which ignores them until open. This patch only makes NQ0 persistent across open/close; acting on events received while down is left for later. Link and module status are read again at the end of open, so no state is lost.
NQ0 always uses irq_tbl[0], independent of the aux (RoCE) vector count.
User-visible and behavioral changes:
- NQ0's vector is named <pci_name>-nq0 and remains requested while the interface is down. It no longer appears as <ifname>-TxRx-0 (or <ifname>-rx-0) in /proc/interrupts. Other vectors keep their names.
- BNGE_FIRST_OPEN_NQ becomes 1, so aux (RoCE) vectors start at irq_tbl[1], and the ring_idx handed to the RoCE driver shifts accordingly.
- The async event completion ring is configured once at probe rather than on every open. If NQ0 or this configuration fails, probe now fails; previously a configuration failure only logged a warning during open.
This relies on firmware keeping NQ0 and the async event completion ring configured across FUNC_DRV_IF_CHANGE down/up.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 10 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 214 ++++++++++++++++-- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 5 + .../net/ethernet/broadcom/bnge/bnge_txrx.c | 53 +++++ .../net/ethernet/broadcom/bnge/bnge_txrx.h | 3 + 5 files changed, 266 insertions(+), 19 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +6 -4
@@ -238,12 +238,14 @@ struct bnge_dev {#define bnge_warn (bd, fmt, ...) bnge_log(warn, bd, fmt, ##__VA_ARGS__)#define bnge_dbg (bd, fmt, ...) bnge_log(dbg, bd, fmt, ##__VA_ARGS__) -/* Index of the first NQ created in ndo_open() and destroyed in ndo_stop(); -* lower NQs live from probe to remove. +/* Index of the first NQ created in ndo_open() and destroyed in ndo_stop(). +* NQ0 (index 0) lives from probe to remove and is managed by +* bnge_nq0_init()/uninit() and the nq0 handoff helpers; therefore, +* bnge_for_each_open_nq() skips it. * -* irq_tbl order: probe-time NQs, aux (RoCE) vectors, open-time NQs. +* irq_tbl order: NQ0, aux (RoCE) vectors, open-time NQs. */ -#define BNGE_FIRST_OPEN_NQ 0 +#define BNGE_FIRST_OPEN_NQ 1#define bnge_for_each_open_nq (i, bd) \ for ((i) = BNGE_FIRST_OPEN_NQ; (i) < (bd)->nq_nr_rings; (i)++)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +199 -15
373 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +5 -0
@@ -266,6 +266,7 @@ struct bnge_stats_mem {enum bnge_net_state {BNGE_STATE_NAPI_DISABLED ,BNGE_STATE_STATS_ENABLE , +BNGE_STATE_NQ0_NAPI , };#define BNGE_TIMER_INTERVAL HZ
@@ -315,6 +316,8 @@ struct bnge_net {u32 hash_seed;u64 toeplitz_prefix; +/* Lives from probe to remove. bnapi[0] points to it. */ +struct bnge_napi *nq0;struct bnge_napi **bnapi;struct bnge_rx_ring_info *rx_ring;
@@ -350,7 +353,9 @@ struct bnge_net {unsigned int current_interval;struct timer_list timer;struct workqueue_struct *bnge_pf_wq; +struct workqueue_struct *nq0_wq;struct work_struct sp_task; +struct work_struct nq0_work;unsigned long sp_event;struct bnge_ethtool_link_info eth_link_info;
drivers/net/ethernet/broadcom/bnge/bnge_txrx.c +53 -0
65 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_txrx.h +3 -0
@@ -120,6 +120,9 @@ irqreturn_t bnge_msix(int irq, void *dev_instance);netdev_tx_t bnge_start_xmit (struct sk_buff *skb,struct net_device *dev);void bnge_reuse_rx_data (struct bnge_rx_ring_info *rxr,u16 cons,void *data);int bnge_napi_poll (struct napi_struct *napi,int budget); +irqreturn_t bnge_nq0_msix (int irq,void *dev_instance); +void bnge_nq0_poll (struct bnge_net *bn); +void bnge_nq0_work (struct work_struct *work);netdev_features_t bnge_features_check (struct sk_buff *skb,struct net_device *dev,netdev_features_t features);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v4 5/5] bnge: create NQ0 during probe and keep it active across open/close
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · 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] bnge: race between bnge_napi_poll() and bnge_shutdown_nic() on NQ0
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch adds more callers that hit it.
--
bnge: create NQ0 during probe and keep it active across open/close
This commit creates NQ0 and its MSI-X vector once at probe and keeps them until remove, so firmware async events and HWRM completions are still received while the interface is down. While the interface is up NQ0 is serviced by NAPI, and while it is down it is serviced by a new nq0_work worker. The BNGE_STATE_NQ0_NAPI bit selects which one is used, and it is switched in open and stop.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0
[ ... ]
Quoted 20 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +16
-0@@ -2963,11 +3057,32 @@ static int bnge_hwrm_if_change(struct bnge_dev *bd, bool up)return bnge_hwrm_req_send (bd, req); } +/* Hand NQ0 from nq0_work to NAPI. The caller keeps NQ0's IRQ disabled; it is +* re-enabled here. +*/ +static void bnge_nq0_wq_to_napi (struct bnge_net *bn) +{ +struct bnge_nq_ring_info *nqr = &bn->nq0->nq_ring; +struct bnge_napi *bnapi = bn->nq0; +struct bnge_dev *bd = bn->bd; + + bnapi->in_reset = false; + bnapi->tx_fault =0 ; +napi_enable_locked (&bnapi->napi); +set_bit (BNGE_STATE_NQ0_NAPI , &bn->state); +BNGE_DB_NQ_ARM (bd, &nqr->nq_db, nqr->nq_raw_cons); +enable_irq (bd->irq_tbl[nqr->ring_struct.map_idx].vector); +}
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_open_core(struct bnge_net *bn) · line 3144
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +1
-0@@ -3017,6 +3141,7 @@ static int bnge_open_core(struct bnge_net *bn)set_bit (BNGE_STATE_STATS_ENABLE , &bn->state);bnge_enable_int (bn); +bnge_nq0_wq_to_napi (bn);
[Severity: High]
This isn't a bug introduced by this patch, but the patch adds more callers that run into it. On 32-bit builds, bnge_writeq() takes bd->db_lock with a plain spin_lock() and leaves BH enabled:
drivers/net/ethernet/broadcom/bnge/bnge.h:bnge_writeq() {
#if BITS_PER_LONG == 32
spin_lock(&bd->db_lock);
lo_hi_writeq(val, addr);
spin_unlock(&bd->db_lock);
...
}bnge_writeq_relaxed() in bnge_txrx.h does the same thing. Softirq code takes the same lock too: bnge_napi_poll() takes it through BNGE_DB_NQ(), BNGE_DB_NQ_ARM() and the CQ doorbells, and the xmit path takes it as well.
Here bnge_nq0_wq_to_napi() writes BNGE_DB_NQ_ARM() from process context. By that point bnge_enable_int() has already armed NQ1..n with their NAPIs enabled. The close path has the same ordering:
bnge_close_core()
bnge_nq0_napi_to_wq()
bnge_nq0_poll()
BNGE_DB_NQ_ARM()
bnge_writeq() bnge_disable_napi() <- NAPI for NQ1..n is only disabled here
Can this self-deadlock on a 32-bit kernel? Suppose an interrupt for one of the other NQs lands on the same CPU while process context holds db_lock. irq_exit() can then run NET_RX softirq:
process context same CPU, softirq from irq_exit()bnge_nq0_wq_to_napi()
bnge_writeq()
spin_lock(&bd->db_lock)
bnge_napi_poll()
BNGE_DB_NQ_ARM()
bnge_writeq()
spin_lock(&bd->db_lock) <- spinsWith lockdep enabled, this should also be reported as an inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} lock state once traffic flows after the first open.
The existing process-context callers bnge_enable_int() and bnge_disable_int() already followed this pattern before this patch.
Would it make sense to use spin_lock_bh() or spin_lock_irqsave() in bnge_writeq() and bnge_writeq_relaxed()? Disabling BH around the process-context doorbell writes would also work.
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static void bnge_close_core(struct bnge_net *bn) · line 3409
Quoted 9 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2
-0@@ -3243,6 +3402,8 @@ static void bnge_close_core(struct bnge_net *bn)timer_delete_sync (&bn->timer);bnge_shutdown_nic (bn); + +bnge_nq0_napi_to_wq (bn);bnge_disable_napi (bn);/* Save ring stats before shutdown */
[Severity: High]
Does this ordering leave a window where NQ0's NAPI is still running against rings that firmware is tearing down?
bnge_shutdown_nic() calls bnge_hwrm_resource_free(bn, 1), which calls bnge_hwrm_ring_free(bn, 1). At that point NQ0 is still in NAPI mode:BNGE_STATE_NQ0_NAPI is set, vector0 is enabled and NAPI is enabled.
On the close path, bnge_hwrm_tx_ring_free(), bnge_hwrm_rx_ring_free() and bnge_hwrm_rx_agg_ring_free() point cmpl_ring at the L2 completion ring. __hwrm_send_ctx() therefore waits until bnge_napi_poll() reaches bnge_hwrm_update_token() through __bnge_poll_work() and bnge_hwrm_handler().
The waiter can wake up as soon as the token becomes BNGE_HWRM_COMPLETE. bnge_napi_poll() may still be inside its loop and may not yet have updated nqr->nq_raw_cons or written the NQ doorbell. bnge_hwrm_ring_free() then goes straight to bnge_disable_int_sync() and bnge_hwrm_cp_ring_free():
CPU0 (ndo_stop) CPU1 (NET_RX softirq)bnge_hwrm_ring_free() bnge_napi_poll() on NQ0
rx/agg ring free __bnge_poll_work()
waits for token bnge_hwrm_update_token()
<- wakes up ...
bnge_disable_int_sync()
bnge_disable_int()
reads nqr->nq_raw_cons
nqr->nq_raw_cons = raw_cons
BNGE_DB_NQ_ARM()
bnge_db_nq() with old cons
synchronize_irq() bnge_hwrm_cp_ring_free()
synchronize_irq() waits only for the hardirq handler, not for the softirq poll. Nothing here orders the two doorbell writers, so one of two things can happen:
- The mask write goes out with a stale consumer index after the poll has advanced it.
- The poll re-arms NQ0 after it was masked. This happens while NQ0's completion rings and stat contexts are being freed in firmware, and while vector0 is still routed to NAPI.
Before this patch, NQ0 was freed in firmware on close and re-created on open, so any state this race left on the NQ was discarded. Now NQ0 persists. The same NQ also carries the async events and HWRM completions that the worker mode depends on while the interface is down.
Is the bnge_nq0_poll() re-arm in bnge_nq0_napi_to_wq() meant to repair NQ0's doorbell state after this race? If not, would it be better to quiesce NQ0's NAPI, and the other NQs' NAPIs, after the TX/RX/AGG ring frees but before bnge_disable_int_sync() and the completion ring frees? That would replace doing it only after bnge_shutdown_nic() has returned.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111190011.53437-1-bhargava.marreddy%40broadcom.com
Re: [PATCH net-next v4 5/5] bnge: create NQ0 during probe and keep it active across open/close
Quoted 111 lines · On Mon, Nov 16, 2026 at 12:59 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · 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] bnge: race between
bnge_napi_poll()andbnge_shutdown_nic()on NQ0Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch adds more callers that hit it.--
bnge: create NQ0 during probe and keep it active across open/close
This commit creates NQ0 and its MSI-X vector once at probe and keeps them until remove, so firmware async events and HWRM completions are still received while the interface is down. While the interface is up NQ0 is serviced by NAPI, and while it is down it is serviced by a new
nq0_workworker. TheBNGE_STATE_NQ0_NAPIbit selects which one is used, and it is switched in open and stop.Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0[ ... ]
Quoted 20 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +16
-0@@ -2963,11 +3057,32 @@ static int bnge_hwrm_if_change(struct bnge_dev *bd, bool up)return bnge_hwrm_req_send (bd, req); } +/* Hand NQ0 from nq0_work to NAPI. The caller keeps NQ0's IRQ disabled; it is +* re-enabled here. +*/ +static void bnge_nq0_wq_to_napi (struct bnge_net *bn) +{ +struct bnge_nq_ring_info *nqr = &bn->nq0->nq_ring; +struct bnge_napi *bnapi = bn->nq0; +struct bnge_dev *bd = bn->bd; + + bnapi->in_reset = false; + bnapi->tx_fault =0 ; +napi_enable_locked (&bnapi->napi); +set_bit (BNGE_STATE_NQ0_NAPI , &bn->state); +BNGE_DB_NQ_ARM (bd, &nqr->nq_db, nqr->nq_raw_cons); +enable_irq (bd->irq_tbl[nqr->ring_struct.map_idx].vector); +}[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_open_core(struct bnge_net *bn) · line 3144
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +1
-0@@ -3017,6 +3141,7 @@ static int bnge_open_core(struct bnge_net *bn)set_bit (BNGE_STATE_STATS_ENABLE , &bn->state);bnge_enable_int (bn); +bnge_nq0_wq_to_napi (bn);[Severity: High]
This isn't a bug introduced by this patch, but the patch adds more callers that run into it. On 32-bit builds,bnge_writeq()takesbd->db_lockwith a plainspin_lock()and leaves BH enabled:drivers/net/ethernet/broadcom/bnge/bnge.h:bnge_writeq() {
#if BITS_PER_LONG == 32 spin_lock(&bd->db_lock); lo_hi_writeq(val, addr); spin_unlock(&bd->db_lock); ... }
bnge_writeq_relaxed()inbnge_txrx.hdoes the same thing. Softirq code takes the same lock too:bnge_napi_poll()takes it throughBNGE_DB_NQ(),BNGE_DB_NQ_ARM()and the CQ doorbells, and the xmit path takes it as well.Here
bnge_nq0_wq_to_napi()writesBNGE_DB_NQ_ARM()from process context. By that pointbnge_enable_int()has already armed NQ1..n with their NAPIs enabled. The close path has the same ordering:
bnge_close_core()
bnge_nq0_napi_to_wq()bnge_nq0_poll() BNGE_DB_NQ_ARM() bnge_writeq()
bnge_disable_napi()<- NAPI for NQ1..n is only disabled hereCan this self-deadlock on a 32-bit kernel? Suppose an interrupt for one of the other NQs lands on the same CPU while process context holds
db_lock.irq_exit()can then runNET_RXsoftirq:process context same CPU, softirq from
irq_exit()bnge_nq0_wq_to_napi()
bnge_writeq()spin_lock(&bd->db_lock) bnge_napi_poll() BNGE_DB_NQ_ARM() bnge_writeq() spin_lock(&bd->db_lock) <- spinsWith lockdep enabled, this should also be reported as an inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} lock state once traffic flows after the first open.
Quoted 6 lines
The existing process-context callers
bnge_enable_int()andbnge_disable_int()already followed this pattern before this patch.Would it make sense to use
spin_lock_bh()orspin_lock_irqsave()inbnge_writeq()andbnge_writeq_relaxed()? Disabling BH around the process-context doorbell writes would also work.
Yes. bnge_writeq() and bnge_writeq_relaxed() take db_lock with plain spin_lock() while the same lock is taken from softirq. This is pre-existing:bnge_enable_int() and bnge_disable_int() already did this, and this series only adds another process-context caller. I'll send a separate fix to net that switches the writeq helpers to spin_lock_bh().
Quoted 63 lines
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static void bnge_close_core(struct bnge_net *bn) · line 3409
Quoted 9 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2
-0@@ -3243,6 +3402,8 @@ static void bnge_close_core(struct bnge_net *bn)timer_delete_sync (&bn->timer);bnge_shutdown_nic (bn); + +bnge_nq0_napi_to_wq (bn);bnge_disable_napi (bn);/* Save ring stats before shutdown */ [Severity: High]
Does this ordering leave a window where NQ0's NAPI is still running against rings that firmware is tearing down?
bnge_shutdown_nic()callsbnge_hwrm_resource_free(bn, 1), which callsbnge_hwrm_ring_free(bn, 1). At that point NQ0 is still in NAPI mode:BNGE_STATE_NQ0_NAPIis set, vector0 is enabled and NAPI is enabled.On the close path,
bnge_hwrm_tx_ring_free(),bnge_hwrm_rx_ring_free()andbnge_hwrm_rx_agg_ring_free()pointcmpl_ringat the L2 completion ring.__hwrm_send_ctx()therefore waits untilbnge_napi_poll()reachesbnge_hwrm_update_token()through__bnge_poll_work()andbnge_hwrm_handler().The waiter can wake up as soon as the token becomes
BNGE_HWRM_COMPLETE.bnge_napi_poll()may still be inside its loop and may not yet have updatednqr->nq_raw_consor written the NQ doorbell.bnge_hwrm_ring_free()then goes straight tobnge_disable_int_sync()andbnge_hwrm_cp_ring_free():CPU0 (
ndo_stop) CPU1 (NET_RXsoftirq)bnge_hwrm_ring_free()bnge_napi_poll()on NQ0
rx/agg ring free__bnge_poll_work()
waits for tokenbnge_hwrm_update_token()
<- wakes up ...
bnge_disable_int_sync()bnge_disable_int() reads nqr->nq_raw_cons nqr->nq_raw_cons = raw_cons BNGE_DB_NQ_ARM() bnge_db_nq() with old cons synchronize_irq()
bnge_hwrm_cp_ring_free()
synchronize_irq()waits only for the hardirq handler, not for the softirq poll. Nothing here orders the two doorbell writers, so one of two things can happen:- The mask write goes out with a stale consumer index after the poll has advanced it.
- The poll re-arms NQ0 after it was masked. This happens while NQ0's completion rings and stat contexts are being freed in firmware, and while vector0 is still routed to NAPI.Before this patch, NQ0 was freed in firmware on close and re-created on open, so any state this race left on the NQ was discarded. Now NQ0 persists. The same NQ also carries the async events and HWRM completions that the worker mode depends on while the interface is down.
Quoted 6 lines
Is the
bnge_nq0_poll()re-arm inbnge_nq0_napi_to_wq()meant to repair NQ0's doorbell state after this race? If not, would it be better to quiesce NQ0's NAPI, and the other NQs' NAPIs, after the TX/RX/AGG ring frees but beforebnge_disable_int_sync()and the completion ring frees? That would replace doing it only afterbnge_shutdown_nic()has returned.
Yes. bnge_disable_int() already runs while bnge_napi_poll() can still be active, so this is pre-existing, but it is worse with a persistent NQ0. A stale doorbell write or a late re-arm used to be discarded when NQ0 was freed on close. Now it survives. I'll fix it in v5 by stopping NAPI (with synchronize_net()) after the Tx/Rx/Agg ring frees and before masking the NQs in bnge_hwrm_ring_free().
Thanks,
Bhargava Marreddy
pw-bot: cr
Quoted 3 lines
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111190011.53437-1-bhargava.marreddy%40broadcom.com