net: bcmgenet, systemport: DIM and Rx discard fixes
Subsystems (4)
Nicolai Buchwitz
maintainerv2 cover net: bcmgenet, systemport: DIM and Rx discard fixes
Sashiko has flagged a few genet bugs over time. I'll work through them as time permits, fixing the ones that seem worth it.
DIM on genet and systemport wants running totals but gets per-poll counts, so it picks bogus profiles from the wrong numbers.
The series also fixes DIM getting stuck after a down/up or suspend and resets the Rx discard count with the ring.
Patches 1-3 have been tested on a Raspberry Pi CM4. I don't have any systemport hardware, but the bugs there are the same.
---
Changes in v2:
- genet: flush the DIM work instead of cancelling it, which also covers
WoL suspend (Sashiko)
- genet: reset DIM before switching to running totals, so a stale sample
can't wrap after a reopen (Sashiko)
- genet, systemport: run net_dim() before napi_complete_done(), so no
DIM work can be queued after napi_disable()
- systemport: add the same DIM reset (Sashiko)
- systemport: the set_coalesce vs DIM work race is pre-existing and left
for a separate patch
- Link to v1: https://patch.msgid.link/[email protected]
---
Nicolai Buchwitz (5):
net: bcmgenet: keep DIM from getting stuck after close or suspend
net: bcmgenet: accumulate the DIM packet and byte counters
net: bcmgenet: reset the Rx discard count with the ring
net: systemport: restart DIM from the default profile on start
net: systemport: accumulate the DIM packet and byte counters
drivers/net/ethernet/broadcom/bcmsysport.c | 20 ++++++++++++-------- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-)
---
base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
change-id: 20261118-nb-genet-dim-stats-net-b6b6fd30398f
Best regards,
Signature · 1 line
Nicolai Buchwitz <[email protected]>
Nicolai Buchwitz
maintainerPATCH v2 1/5 net: bcmgenet: keep DIM from getting stuck after close or suspend
A close or WoL suspend cancels the pending profile work and can leave DIM in DIM_APPLY_NEW_PROFILE, where net_dim() does nothing. Adaptive coalescing then stays stuck after the next open or resume, and the profile index no longer matches the hardware. The poll also calls net_dim() after napi_complete_done(), so it can queue new work after napi_disable() has returned.
Run net_dim() before completing NAPI and flush the work instead of cancelling it, so the pending profile gets applied. Also reset the DIM state on ring init and start from the default profile, which is what bcmgenet_init_rx_coalesce() programs.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +9 -4
@@ -2502,15 +2502,16 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget) work_done =bcmgenet_desc_rx (ring, budget); -if (work_done < budget &&napi_complete_done (napi, work_done)) -bcmgenet_rx_ring_int_enable (ring); - +/* net_dim() can queue work, so run it while NAPI is still owned */ if (ring->dim.use_dim) {dim_update_sample (ring->dim.event_ctr, ring->dim.packets, ring->dim.bytes, &dim_sample);net_dim (&ring->dim.dim, &dim_sample); } +if (work_done < budget &&napi_complete_done (napi, work_done)) +bcmgenet_rx_ring_int_enable (ring); +return work_done; }
@@ -2702,8 +2703,11 @@ static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring, {struct bcmgenet_net_dim *dim = &ring->dim; +memset (&dim->dim,0 ,sizeof (dim->dim));INIT_WORK (&dim->dim.work, cb); dim->dim.mode =DIM_CQ_PERIOD_MODE_START_FROM_EQE ; +/* Match the profile bcmgenet_init_rx_coalesce() programs */ + dim->dim.profile_ix =NET_DIM_DEF_PROFILE_EQE ; dim->event_ctr =0 ; dim->packets =0 ; dim->bytes =0 ;
@@ -3014,7 +3018,8 @@ static void bcmgenet_disable_rx_napi(struct bcmgenet_priv *priv)for (i =0 ; i <= priv->hw_params->rx_queues; ++i) { ring = &priv->rx_rings[i];napi_disable (&ring->napi); -cancel_work_sync (&ring->dim.dim.work); +/* Cancelling would leave DIM stuck in DIM_APPLY_NEW_PROFILE */ +flush_work (&ring->dim.dim.work); } }
Signature · 1 line
2.53.0
Re: [PATCH net v2 1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
Quoted 7 lines · Nicolai Buchwitz
A close or WoL suspend cancels the pending profile work and can leave DIM in
DIM_APPLY_NEW_PROFILE, wherenet_dim()does nothing. Adaptive coalescing then stays stuck after the next open or resume, and the profile index no longer matches the hardware. The poll also callsnet_dim()afternapi_complete_done(), so it can queue new work afternapi_disable()has returned.
Quoted 7 lines
Run
net_dim()before completing NAPI and flush the work instead of cancelling it, so the pending profile gets applied. Also reset the DIM state on ring init and start from the default profile, which is whatbcmgenet_init_rx_coalesce()programs.Fixes 9f4ca05827a2 ("net: bcmgenet: Add support for adaptive RX coalescing")Signed-off-by Nicolai Buchwitz <[email protected]>
Signature · 1 line
Florian
[email protected]
AI reviewRe: [PATCH net v2 1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
In reply to Nicolai BuchwitzThank 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: 0 · 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).
- [Medium] The patch fixes the profile-index/hardware mismatch only in bcmgenet_init_dim().
--
net: bcmgenet: keep DIM from getting stuck after close or suspend
The patch moves net_dim() so it runs before napi_complete_done() in the RX poll, and it flushes the DIM work on close/suspend instead of cancelling it. It also resets the DIM state in bcmgenet_init_dim() and starts profile_ix from the default profile, so that it matches what bcmgenet_init_rx_coalesce() programs into the hardware.
Quoted 4 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/genet/bcmgenet.c static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring, · line 2710
Quoted 9 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +3
-0@@ -2702,8 +2703,11 @@ static void bcmgenet_init_dim(struct bcmgenet_rx_ring *ring, {struct bcmgenet_net_dim *dim = &ring->dim; +memset (&dim->dim,0 ,sizeof (dim->dim));INIT_WORK (&dim->dim.work, cb); dim->dim.mode =DIM_CQ_PERIOD_MODE_START_FROM_EQE ; +/* Match the profile bcmgenet_init_rx_coalesce() programs */ + dim->dim.profile_ix =NET_DIM_DEF_PROFILE_EQE ;
[Severity: Medium]
Does the same profile index mismatch still happen through the ethtool path?
bcmgenet_init_dim() only runs from bcmgenet_init_rx_ring(), which means on open or resume. The default profile is also written to the hardware at runtime by bcmgenet_set_ring_rx_coalesce(), and that path does not touch ring->dim.dim:
drivers/net/ethernet/broadcom/genet/bcmgenet.c:bcmgenet_set_ring_rx_coalesce() {
...
if (ec->use_adaptive_rx_coalesce && !ring->dim.use_dim) {
moder = net_dim_get_def_rx_moderation(ring->dim.dim.mode);
usecs = moder.usec;
pkts = moder.pkts;
}
ring->dim.use_dim = ec->use_adaptive_rx_coalesce;
bcmgenet_set_rx_coalesce(ring, usecs, pkts);
}Here is one sequence on a running interface. DIM moves to profile 3. Then the user runs "ethtool -C ethX adaptive-rx off" followed by "ethtool -C ethX adaptive-rx on". The hardware now has the default EQE profile, but profile_ix, tune_state, steps, prev_stats and start_sample still hold the values from before adaptive-rx was turned off.
On the next net_dim(), net_dim_decision() steps from the stale profile_ix. bcmgenet_dim_work() then programs a profile that is a neighbour of 3 instead of a neighbour of the default.
If tune_state is DIM_PARKING_ON_TOP and traffic is steady, no work gets queued at all. The hardware then stays on the default profile while DIM believes another profile is active.
This looks like the "profile index no longer matches the hardware" state the commit message describes, reached here without any close or suspend. Would it make sense to reset ring->dim.dim (state and profile_ix) in bcmgenet_set_ring_rx_coalesce() whenever the default profile is programmed?
A related case: when adaptive-rx is already on, any "ethtool -C" call skips the default-profile branch. It writes the static rx_coalesce_usecs/rx_max_coalesced_frames into every RX ring, while DIM keeps its old profile_ix.
bcmgenet_get_coalesce() reports ring 0's hardware values. So in that case, could rings other than ring 0 end up with ring 0's DIM-chosen values while their own DIM state points somewhere else?
Quoted 3 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +0
-0dim->event_ctr =0 ; dim->packets =0 ; dim->bytes =0 ;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-nb-genet-dim-stats-net-v2-0-1a7cece7dd1a%40tipi-net.de
Nicolai Buchwitz
maintainerRe: [PATCH net v2 1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
Quoted 5 lines · On 23.11.2026 23:44, [email protected] wrote:
[...]
[Severity: Medium]
Does the same profile index mismatch still happen through the ethtool path?
IMHO pre-existing in the ethtool path and not stuck like close/suspend. Also DIM recovers when the traffic changes. I'd rather fix this as a follow-up in net-next.
It has a single Rx ring on all versions, so there is no multi-ring case.
Quoted 1 line
[...]
Nicolai Buchwitz
maintainerPATCH v2 2/5 net: bcmgenet: accumulate the DIM packet and byte counters
In reply to Nicolai Buchwitznet_dim() computes rates from the difference between two samples and needs running totals, but bcmgenet_desc_rx() passes the counts of the last poll. Adaptive coalescing then picks profiles from wrong rates.
On a CM4 at a steady 300 Mbit/s UDP, DIM changed profile about 1000 times in 20 s. With the fix it settles, and Rx interrupts drop from about 4500/s to 2240/s.
Accumulate the counters instead.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -2
@@ -2486,8 +2486,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,bcmgenet_rdma_ring_writel (priv, ring->index, ring->c_index,RDMA_CONS_INDEX ); } - ring->dim.bytes = bytes_processed; - ring->dim.packets = rxpktprocessed; + ring->dim.bytes += bytes_processed; + ring->dim.packets += rxpktprocessed;return rxpktprocessed; }
Signature · 1 line
2.53.0
Nicolai Buchwitz
maintainerPATCH v2 3/5 net: bcmgenet: reset the Rx discard count with the ring
In reply to Nicolai BuchwitzRing init clears the hardware discard counter but not ring->old_discards. Discards after an ifdown and ifup or a resume are then missing from rx_missed. On a CM4, after an ifdown and ifup, 3666 discards showed up as 0 in rx_missed.
Reset old_discards together with the ring.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
@@ -2826,6 +2826,8 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv, ring->read_ptr = start_ptr; ring->cb_ptr = start_ptr; ring->end_ptr = end_ptr -1 ; +/* Zeroing RDMA_PROD_INDEX below also clears the discard counter */ + ring->old_discards =0 ; ret =bcmgenet_rx_ring_create_pool (priv, ring);if (ret)
Signature · 1 line
2.53.0
Nicolai Buchwitz
maintainerPATCH v2 4/5 net: systemport: restart DIM from the default profile on start
In reply to Nicolai BuchwitzA close or suspend can cancel the pending profile work and leave DIM in DIM_APPLY_NEW_PROFILE, where net_dim() does nothing. Adaptive coalescing then stays stuck after the next open or resume. The poll also calls net_dim() after napi_complete_done(), so it can queue new work after napi_disable() has returned.
Run net_dim() before completing NAPI. Reset the DIM state on start and begin from the default profile, which is what bcm_sysport_init_rx_coalesce() programs.
--- drivers/net/ethernet/broadcom/bcmsysport.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/bcmsysport.c +10 -6
@@ -1012,18 +1012,19 @@ static int bcm_sysport_poll(struct napi_struct *napi, int budget)else rdma_writel (priv, priv->rx_c_index <<16 ,RDMA_CONS_INDEX ); -if (work_done < budget) { -napi_complete_done (napi, work_done); -/* re-enable RX interrupts */ -intrl2_0_mask_clear (priv,INTRL2_0_RDMA_MBDONE ); - } - +/* net_dim() can queue work, so run it while NAPI is still owned */ if (priv->dim.use_dim) {dim_update_sample (priv->dim.event_ctr, priv->dim.packets, priv->dim.bytes, &dim_sample);net_dim (&priv->dim.dim, &dim_sample); } +if (work_done < budget) { +napi_complete_done (napi, work_done); +/* re-enable RX interrupts */ +intrl2_0_mask_clear (priv,INTRL2_0_RDMA_MBDONE ); + } +return work_done; }
@@ -1452,8 +1453,11 @@ static void bcm_sysport_init_dim(struct bcm_sysport_priv *priv, {struct bcm_sysport_net_dim *dim = &priv->dim; +memset (&dim->dim,0 ,sizeof (dim->dim));INIT_WORK (&dim->dim.work, cb); dim->dim.mode =DIM_CQ_PERIOD_MODE_START_FROM_EQE ; +/* Match the profile bcm_sysport_init_rx_coalesce() programs */ + dim->dim.profile_ix =NET_DIM_DEF_PROFILE_EQE ; dim->event_ctr =0 ; dim->packets =0 ; dim->bytes =0 ;
Signature · 1 line
2.53.0
Nicolai Buchwitz
maintainerPATCH v2 5/5 net: systemport: accumulate the DIM packet and byte counters
In reply to Nicolai Buchwitznet_dim() computes rates from the difference between two samples and needs running totals, but bcm_sysport_desc_rx() passes the counts of the last poll. Adaptive coalescing then picks profiles from wrong rates.
Accumulate the counters instead.
--- drivers/net/ethernet/broadcom/bcmsysport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bcmsysport.c +2 -2
@@ -844,8 +844,8 @@ static unsigned int bcm_sysport_desc_rx(struct bcm_sysport_priv *priv, priv->rx_read_ptr =0 ; } - priv->dim.packets = processed; - priv->dim.bytes = processed_bytes; + priv->dim.packets += processed; + priv->dim.bytes += processed_bytes;return processed; }
Signature · 1 line
2.53.0
This series was applied to netdev/net.git (main) by Willem de Bruijn <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Willem de Bruijn <[email protected]>:
Quoted 10 lines · On Fri, 20 Nov 2026 23:42:34 +0100 you wrote:
Sashiko has flagged a few genet bugs over time. I'll work through them as time permits, fixing the ones that seem worth it.
DIM on genet and systemport wants running totals but gets per-poll counts, so it picks bogus profiles from the wrong numbers.
The series also fixes DIM getting stuck after a down/up or suspend and resets the Rx discard count with the ring.
[...]
Here is the summary with links:
- [net,v2,1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
https://git.kernel.org/netdev/net/c/aa5a537ec43c - [net,v2,2/5] net: bcmgenet: accumulate the DIM packet and byte counters https://git.kernel.org/netdev/net/c/a15079369636 - [net,v2,3/5] net: bcmgenet: reset the Rx discard count with the ring https://git.kernel.org/netdev/net/c/e99faa3a1620 - [net,v2,4/5] net: systemport: restart DIM from the default profile on start https://git.kernel.org/netdev/net/c/8e428e263fa4 - [net,v2,5/5] net: systemport: accumulate the DIM packet and byte counters https://git.kernel.org/netdev/net/c/3e7e20beef4e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html