From: Pengfei Zhang <zhangfeionline@gmail.com>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>,
zhangpengfei16@xiaomi.com, netdev@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net] net: stmmac: fix RX coalesce frames counter
Date: Fri, 9 Oct 2026 19:11:37 +0800 [thread overview]
Message-ID: <20261009111138.320089-1-zhangfeionline@gmail.com> (raw)
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")
Signed-off-by: Pengfei Zhang <zhangfeionline@gmail.com>
---
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(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b837e8e27..72678760e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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);
--
2.54.0
next reply other threads:[~2026-10-09 11:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 11:11 Pengfei Zhang [this message]
2026-10-09 11:14 ` [PATCH net] net: stmmac: fix RX coalesce frames counter netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261009111138.320089-1-zhangfeionline@gmail.com \
--to=zhangfeionline@gmail.com \
--cc=Jose.Abreu@synopsys.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=maxime.chevallier@bootlin.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=zhangpengfei16@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox