🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by James Hilliard Tue, 17 Nov 2026 16:40
[PATCH net v2] net: stmmac: preserve RX checksum capability when offload is disabled
#17982
Author: James Hilliard
Date: Tue, 17 Nov 2026 16:40
55 lines
13565 bytes
The GMAC, GMAC4 and XGMAC rx_ipc callbacks return whether checksum offload
is enabled after programming the requested state. A zero return is
therefore expected when hw->rx_csum is zero.

stmmac_hw_setup() treats every zero return as a lack of hardware support
and clears plat->rx_coe. Disabling RX checksum offload with ethtool and
then reopening the interface loses the saved capability. Subsequent
attempts to enable offload are rejected by stmmac_fix_features(), which
uses plat->rx_coe to filter NETIF_F_RXCSUM.

Only clear the capability if offload was requested but could not be
enabled. Keep calling rx_ipc when offload is disabled so that the hardware
is still programmed with the requested state.

Found while investigating RX checksum offload behavior on H616. Maxime
Chevallier reproduced the capability loss on AgileX5, CycloneV and
STM32MP1 and verified that this change fixes it.

Fixes: d2afb5bdffde3 ("stmmac: fix the rx csum feature")
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes in v2:
- Correct the Fixes tag to reference the mainline commit.
- Add Maxime Chevallier's Reviewed-by and Tested-by tags.
- Include the discovery and hardware confirmation context.
- Link to v1: https://patch.msgid.link/20261115-submit-stmmac-rx-checksum-capability-v1-v1-1-ea26fa3689be@gmail.com
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 25894771e9e9..e162976be2e6 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3723,7 +3723,7 @@ static int stmmac_hw_setup(struct net_device *dev)
 	stmmac_safety_feat_configuration(priv);
 
 	ret = stmmac_rx_ipc(priv, priv->hw);
-	if (!ret) {
+	if (priv->hw->rx_csum && !ret) {
 		netdev_warn(priv->dev, "RX IPC Checksum Offload disabled\n");
 		priv->plat->rx_coe = STMMAC_RX_COE_NONE;
 		priv->hw->rx_csum = 0;

---
base-commit: 5e9b2ad9b8384cd3c417cd5e2c3bc7eee4a72791
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git main
change-id: 20261115-submit-stmmac-rx-checksum-capability-v1-ef6645788992

Best regards,
--  
James Hilliard <james.hilliard1@gmail.com>
Re: [PATCH net v2] net: stmmac: preserve RX checksum capability when offload is disabled
#19342
Author: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 19:40
151 lines
13918 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1 (1)

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] After this patch, stmmac_hw_setup()
  (drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3725-3729) checks…
- [Low] The struct stmmac_ops comment for rx_ipc
  (drivers/net/ethernet/stmicro/stmmac/hwif.h:322) still says "Enable…

Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but
  sun8i_dwmac_rx_ipc_enable()…

--

net: stmmac: preserve RX checksum capability when offload is disabled

This patch changes stmmac_hw_setup() so that a zero return from
stmmac_rx_ipc() clears plat->rx_coe only when RX checksum offload was
requested, meaning hw->rx_csum is non-zero. Before this, the RX COE
capability was lost when the interface was reopened after RX checksum
offload had been turned off with ethtool.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 25894771e9e9f..e162976be2e6d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -3723,7 +3723,7 @@ static int stmmac_hw_setup(struct net_device *dev)
>  	stmmac_safety_feat_configuration(priv);
>  
>  	ret = stmmac_rx_ipc(priv, priv->hw);
> -	if (!ret) {
> +	if (priv->hw->rx_csum && !ret) {

[Severity: Medium]
Can plat->rx_coe now stay unverified when RX checksum offload is off at
every stmmac_hw_setup() since probe?

For example, if "ethtool -K ethX rx off" runs before the first
"ip link set up", the readback is never checked. plat->rx_coe then keeps
whatever value the HW feature register or platform data reported.

If RX checksum is later enabled while the interface is up,
stmmac_fix_features() keeps NETIF_F_RXCSUM because rx_coe is not
STMMAC_RX_COE_NONE. stmmac_set_features() then ignores the rx_ipc result:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_set_features() {
	if (features & NETIF_F_RXCSUM)
		priv->hw->rx_csum = priv->plat->rx_coe;
	else
		priv->hw->rx_csum = 0;
	/* No check needed because rx_coe has been set before and it will be
	 * fixed in case of issue.
	 */
	stmmac_rx_ipc(priv, priv->hw);
	...
}

That comment assumes the stmmac_hw_setup() check has already run, and
after this patch that is not guaranteed. Before this patch, any open
with a zero readback cleared rx_coe. So once the interface had been
opened, offload could not be enabled at runtime without a check.

Some hardware may advertise RX COE while its IPC bit does not latch. On
such hardware, hw->rx_csum would be non-zero while the MAC is not
validating checksums. stmmac_rx() and stmmac_construct_skb_zc() would
then mark IP frames CHECKSUM_UNNECESSARY based on hw->rx_csum:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_construct_skb_zc() {
	...
	if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb))
		skb_checksum_none_assert(skb);
	else
		skb->ip_summed = CHECKSUM_UNNECESSARY;
	...
}

The zero-copy path does not look at descriptor status at all. Split
header is also enabled from rx_csum > 0.

This would last until the next stmmac_hw_setup() with a non-zero
rx_csum, for example after down/up, resume or an MTU change.

I could not find a specific part where the IPC bit fails to latch, so
this depends on the hardware case that the stmmac_hw_setup() check
exists for.

Would it make sense to check the stmmac_rx_ipc() return in
stmmac_set_features() when offload is enabled? Another option is to
verify the capability once, whatever state was requested.

[Severity: Low]
This isn't a bug, but should the rx_ipc comment in struct stmmac_ops be
updated to match the contract this check now depends on?

drivers/net/ethernet/stmicro/stmmac/hwif.h:
	/* Enable and verify that the IPC module is supported */
	int (*rx_ipc)(struct mac_device_info *hw);

The commit message says the callbacks program the state requested in
hw->rx_csum and return whether IPC is enabled afterwards.
dwmac1000_rx_ipc_enable(), dwmac4_rx_ipc_enable() and dwxgmac2_rx_ipc()
behave that way. The hwif.h comment still reads as if a zero return
means the IPC module is unsupported.

sun8i_dwmac_rx_ipc_enable() already uses the other reading ("caution
this function must return non 0 to work") and ignores hw->rx_csum.

>  		netdev_warn(priv->dev, "RX IPC Checksum Offload disabled\n");
>  		priv->plat->rx_coe = STMMAC_RX_COE_NONE;
>  		priv->hw->rx_csum = 0;

[Severity: Low]
This is a pre-existing issue, not one introduced by this patch, but the
commit message says:

  Keep calling rx_ipc when offload is disabled so that the hardware
  is still programmed with the requested state.

Does that hold for the sun8i EMAC used on H616? The commit message
limits this claim to the GMAC, GMAC4 and XGMAC callbacks.
sun8i_dwmac_rx_ipc_enable() ignores hw->rx_csum and never clears
EMAC_RX_DO_CRC:

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c:sun8i_dwmac_rx_ipc_enable() {
	...
	v = readl(ioaddr + EMAC_RX_CTL0);
	v |= EMAC_RX_DO_CRC;
	writel(v, ioaddr + EMAC_RX_CTL0);

	return 1;
}

So on sun8i, "ethtool -K ethX rx off" leaves the EMAC checksum engine
on.

stmmac_rx() still treats these frames as CHECKSUM_NONE because coe is
0, so I could not find any frames being marked with the wrong checksum
state. The problem is that the register state does not match the
requested state.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-submit-stmmac-rx-checksum-capability-v1-v2-1-059f9499c386%40gmail.com
Re: [PATCH net v2] net: stmmac: preserve RX checksum capability when offload is disabled
#19914
Author: James Hilliard
Date: Fri, 20 Nov 2026 17:53
193 lines
18015 bytes
On Thu, Nov 19, 2026 at 12:40 PM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1 (1)
>
> 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] After this patch, stmmac_hw_setup()
>   (drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3725-3729) checks…
> - [Low] The struct stmmac_ops comment for rx_ipc
>   (drivers/net/ethernet/stmicro/stmmac/hwif.h:322) still says "Enable…
>
> Pre-existing issues:
> - [Low] This problem wasn't introduced by this patch, but
>   sun8i_dwmac_rx_ipc_enable()…
>
> --
>
> net: stmmac: preserve RX checksum capability when offload is disabled
>
> This patch changes stmmac_hw_setup() so that a zero return from
> stmmac_rx_ipc() clears plat->rx_coe only when RX checksum offload was
> requested, meaning hw->rx_csum is non-zero. Before this, the RX COE
> capability was lost when the interface was reopened after RX checksum
> offload had been turned off with ethtool.
>
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 25894771e9e9f..e162976be2e6d 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -3723,7 +3723,7 @@ static int stmmac_hw_setup(struct net_device *dev)
> >       stmmac_safety_feat_configuration(priv);
> >
> >       ret = stmmac_rx_ipc(priv, priv->hw);
> > -     if (!ret) {
> > +     if (priv->hw->rx_csum && !ret) {
>
> [Severity: Medium]
> Can plat->rx_coe now stay unverified when RX checksum offload is off at
> every stmmac_hw_setup() since probe?

Yes. On GMAC, GMAC4 and XGMAC, zero is the expected readback when
offload is disabled. Clearing plat->rx_coe on that basis is what makes
a working feature disappear after the interface is reopened.

What v2 misses is the later live enable. stmmac_set_features() sets
hw->rx_csum from plat->rx_coe and ignores the readback. If the enable
bit stays clear, the RX path can mark an unchecked packet as
CHECKSUM_UNNECESSARY. I haven't seen the bit fail to latch on hardware,
but the driver should check it when enabling offload and leave software
checksum reporting off if the enable fails. The rx_ipc comment should
also say that these callbacks return whether the checker is enabled,
not whether the hardware supports it.

>
> For example, if "ethtool -K ethX rx off" runs before the first
> "ip link set up", the readback is never checked. plat->rx_coe then keeps
> whatever value the HW feature register or platform data reported.
>
> If RX checksum is later enabled while the interface is up,
> stmmac_fix_features() keeps NETIF_F_RXCSUM because rx_coe is not
> STMMAC_RX_COE_NONE. stmmac_set_features() then ignores the rx_ipc result:
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_set_features() {
>         if (features & NETIF_F_RXCSUM)
>                 priv->hw->rx_csum = priv->plat->rx_coe;
>         else
>                 priv->hw->rx_csum = 0;
>         /* No check needed because rx_coe has been set before and it will be
>          * fixed in case of issue.
>          */
>         stmmac_rx_ipc(priv, priv->hw);
>         ...
> }
>
> That comment assumes the stmmac_hw_setup() check has already run, and
> after this patch that is not guaranteed. Before this patch, any open
> with a zero readback cleared rx_coe. So once the interface had been
> opened, offload could not be enabled at runtime without a check.
>
> Some hardware may advertise RX COE while its IPC bit does not latch. On
> such hardware, hw->rx_csum would be non-zero while the MAC is not
> validating checksums. stmmac_rx() and stmmac_construct_skb_zc() would
> then mark IP frames CHECKSUM_UNNECESSARY based on hw->rx_csum:
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_construct_skb_zc() {
>         ...
>         if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb))
>                 skb_checksum_none_assert(skb);
>         else
>                 skb->ip_summed = CHECKSUM_UNNECESSARY;
>         ...
> }
>
> The zero-copy path does not look at descriptor status at all. Split
> header is also enabled from rx_csum > 0.
>
> This would last until the next stmmac_hw_setup() with a non-zero
> rx_csum, for example after down/up, resume or an MTU change.
>
> I could not find a specific part where the IPC bit fails to latch, so
> this depends on the hardware case that the stmmac_hw_setup() check
> exists for.
>
> Would it make sense to check the stmmac_rx_ipc() return in
> stmmac_set_features() when offload is enabled? Another option is to
> verify the capability once, whatever state was requested.
>
> [Severity: Low]
> This isn't a bug, but should the rx_ipc comment in struct stmmac_ops be
> updated to match the contract this check now depends on?
>
> drivers/net/ethernet/stmicro/stmmac/hwif.h:
>         /* Enable and verify that the IPC module is supported */
>         int (*rx_ipc)(struct mac_device_info *hw);
>
> The commit message says the callbacks program the state requested in
> hw->rx_csum and return whether IPC is enabled afterwards.
> dwmac1000_rx_ipc_enable(), dwmac4_rx_ipc_enable() and dwxgmac2_rx_ipc()
> behave that way. The hwif.h comment still reads as if a zero return
> means the IPC module is unsupported.
>
> sun8i_dwmac_rx_ipc_enable() already uses the other reading ("caution
> this function must return non 0 to work") and ignores hw->rx_csum.
>
> >               netdev_warn(priv->dev, "RX IPC Checksum Offload disabled\n");
> >               priv->plat->rx_coe = STMMAC_RX_COE_NONE;
> >               priv->hw->rx_csum = 0;
>
> [Severity: Low]
> This is a pre-existing issue, not one introduced by this patch, but the
> commit message says:
>
>   Keep calling rx_ipc when offload is disabled so that the hardware
>   is still programmed with the requested state.
>
> Does that hold for the sun8i EMAC used on H616? The commit message
> limits this claim to the GMAC, GMAC4 and XGMAC callbacks.
> sun8i_dwmac_rx_ipc_enable() ignores hw->rx_csum and never clears
> EMAC_RX_DO_CRC:

That's correct. The sun8i callback always returns 1, so it doesn't
trigger the capability loss fixed here. The separate sun8i patch [0]
keeps the hardware checker enabled in both modes and lets packets
whose only error is a bad IP or transport checksum reach the stack as
CHECKSUM_NONE. On that MAC, ethtool rx off controls whether the driver
reports a checksum as verified, not whether the MAC checks it.

[0] https://lore.kernel.org/r/20261120-submit-sun8i-rx-features-v1-v1-1-5058fecba6b3@gmail.com/

pw-bot: cr

>
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c:sun8i_dwmac_rx_ipc_enable() {
>         ...
>         v = readl(ioaddr + EMAC_RX_CTL0);
>         v |= EMAC_RX_DO_CRC;
>         writel(v, ioaddr + EMAC_RX_CTL0);
>
>         return 1;
> }
>
> So on sun8i, "ethtool -K ethX rx off" leaves the EMAC checksum engine
> on.
>
> stmmac_rx() still treats these frames as CHECKSUM_NONE because coe is
> 0, so I could not find any frames being marked with the wrong checksum
> state. The problem is that the register state does not match the
> requested state.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-submit-stmmac-rx-checksum-capability-v1-v2-1-059f9499c386%40gmail.com
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