Skip to contentSkip to conversation

net: stmmac: fix RX coalesce frames counter

PATCH Applied Pengfei Zhang 3 participants 4 messages Oct 9 – Oct 16

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: fix RX coalesce frames counter

The RX refill path should set the IC bit once every rx_coal_frames descriptors and leave the rest to the RX watchdog (RIWT), as done by commit d429b66e2ebc ("net: stmmac: Implement RX Coalesce Frames setting").

Since commit 6fa9d691b91a ("net: stmmac: Prevent divide-by-zero") the counter is increased by N+1 for each descriptor and then compared against N, so it is always reset to 0. With a non-zero rx-frames, IC is therefore set on every descriptor and every frame raises an interrupt.

Fix this by counting one descriptor at a time in a helper used by both stmmac_rx_refill() and stmmac_rx_refill_zc(). Platforms without RIWT (IC on every descriptor) are unaffected.

Fixes 6fa9d691b91a ("net: stmmac: Prevent divide-by-zero")

---
The default rx-frames is 0 (watchdog only) since commit da2024510031 ("net: stmmac: Tune-up default coalesce settings"), so this is only hit when rx-frames is set explicitly.

Verified with "ethtool -C eth0 rx-frames 16" under UDP load: without this patch almost every received frame raised an RX interrupt, about twice as many interrupts as with rx-frames 0.

 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 36 +++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +18 -18
index b837e8e27..72678760e 100644
@@ -5071,6 +5071,22 @@ static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
 	}
 }
 
+static bool stmmac_rx_need_ic(struct stmmac_priv *priv,
+			      struct stmmac_rx_queue *rx_q, u32 queue)
+{
+	u32 frames = priv->rx_coal_frames[queue];
+
+	/* without the RX watchdog every descriptor needs IC */
+	if (!priv->use_riwt)
+		return true;
+
+	if (!frames || ++rx_q->rx_count_frames < frames)
+		return false;
+
+	rx_q->rx_count_frames = 0;
+	return true;
+}
+
 /**
  * stmmac_rx_refill - refill used skb preallocated buffers
  * @priv: driver private structure
@@ -5116,15 +5132,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
 					 stmmac_rx_check_buf2_cap(priv));
 		stmmac_refill_desc3(priv, rx_q, p);
 
-		rx_q->rx_count_frames++;
-		rx_q->rx_count_frames += priv->rx_coal_frames[queue];
-		if (rx_q->rx_count_frames > priv->rx_coal_frames[queue])
-			rx_q->rx_count_frames = 0;
-
-		use_rx_wd = !priv->rx_coal_frames[queue];
-		use_rx_wd |= rx_q->rx_count_frames > 0;
-		if (!priv->use_riwt)
-			use_rx_wd = false;
+		use_rx_wd = !stmmac_rx_need_ic(priv, rx_q, queue);
 
 		dma_wmb();
 		stmmac_set_rx_owner(priv, p, use_rx_wd);
@@ -5492,15 +5500,7 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
 		stmmac_set_desc_sec_addr(priv, rx_desc, 0, false);
 		stmmac_refill_desc3(priv, rx_q, rx_desc);
 
-		rx_q->rx_count_frames++;
-		rx_q->rx_count_frames += priv->rx_coal_frames[queue];
-		if (rx_q->rx_count_frames > priv->rx_coal_frames[queue])
-			rx_q->rx_count_frames = 0;
-
-		use_rx_wd = !priv->rx_coal_frames[queue];
-		use_rx_wd |= rx_q->rx_count_frames > 0;
-		if (!priv->use_riwt)
-			use_rx_wd = false;
+		use_rx_wd = !stmmac_rx_need_ic(priv, rx_q, queue);
 
 		dma_wmb();
 		stmmac_set_rx_owner(priv, rx_desc, use_rx_wd);
Signature · 1 line
2.54.0
#1 lore raw
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.

#2 lore raw

It has been tested on the hardware device (not publicly available), a DWC XGMAC with the RX watchdog enabled, using
"ethtool -C eth0 rx-frames 16" under UDP load.

#3 lore raw
In reply to Pengfei Zhang
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Fri, 9 Oct 2026 19:11:37 +0800 you wrote:

The RX refill path should set the IC bit once every rx_coal_frames descriptors and leave the rest to the RX watchdog (RIWT), as done by commit d429b66e2ebc ("net: stmmac: Implement RX Coalesce Frames setting").

Since commit 6fa9d691b91a ("net: stmmac: Prevent divide-by-zero") the counter is increased by N+1 for each descriptor and then compared against N, so it is always reset to 0. With a non-zero rx-frames, IC is therefore set on every descriptor and every frame raises an interrupt.

[...]

Here is the summary with links:
- [net] net: stmmac: fix RX coalesce frames counter

    https://git.kernel.org/netdev/net-next/c/0d20963e0aeb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html