๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Nicolai Buchwitz Fri, 20 Nov 2026 22:42
[PATCH net v2 1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
#19999
Author: Nicolai Buchwitz
Date: Fri, 20 Nov 2026 22:42
68 lines
10982 bytes
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.

Fixes: 9f4ca05827a2 ("net: bcmgenet: Add support for adaptive RX coalescing")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 4d2be2a21ed1..f702916e7bfa 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -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);
 	}
 }
 

-- 
2.53.0
Re: [PATCH net v2 1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
#21357
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 22:44
100 lines
11900 bytes
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.

> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index 4d2be2a21ed1b..f702916e7bfaf 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c

[ ... ]

> @@ -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?

>  	dim->event_ctr = 0;
>  	dim->packets = 0;
>  	dim->bytes = 0;

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-nb-genet-dim-stats-net-v2-0-1a7cece7dd1a%40tipi-net.de
Re: [PATCH net v2 1/5] net: bcmgenet: keep DIM from getting stuck after close or suspend
#21539
Author: Nicolai Buchwitz
Date: Tue, 24 Nov 2026 06:05
17 lines
8951 bytes
On 23.11.2026 23:44, netdev-bot+sashiko@kernel.org 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.

> [...]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads