* [PATCH net v2] net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack
@ 2026-11-22 7:32 James Hilliard
2026-11-23 7:34 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-11-22 7:32 UTC (permalink / raw)
To: netdev, Maxime Chevallier, Andrew Lunn, David S. Miller,
Eric Dumazet, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, LABBE Corentin
Cc: Jakub Kicinski, Oleksij Rempel, linux-arm-kernel, linux-sunxi,
James Hilliard
The sun8i MAC drops packets with a bad IP or transport checksum before
packet sockets or the protocol stack can see them, even with RX checksum
offload disabled. Its error-forwarding bit controls Ethernet and IP
errors together.
This was observed while testing an Allwinner H616 with an AC200 PHY:
the MAC dropped packets with a bad UDP checksum even with RX checksum
offload disabled.
Enable error forwarding and decode the sun8i RX status in both receive
paths. Give checksum failures and unchecked packets to the stack with
CHECKSUM_NONE. Continue to discard Ethernet errors, incomplete frames
and lengths that cannot fit in the receive buffer. Address filter and
VLAN indications are not checksum errors.
Keep the hardware checker running whenever the receiver is enabled.
Turning RX checksum reporting back on can then use the result already
recorded in queued descriptors without flushing the ring.
Fixes: 9f93ac8d4085 ("net-next: stmmac: Add dwmac-sun8i")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes in v2:
- Submit the checksum-delivery fix alone for net, following Maxime's
review. The RXALL feature will be submitted separately for net-next.
- Link to v1: https://patch.msgid.link/20261120-submit-sun8i-rx-features-v1-v1-0-5058fecba6b3@gmail.com
---
drivers/net/ethernet/stmicro/stmmac/common.h | 2 +
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 98 ++++++++++++++++++++---
drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +-
4 files changed, 94 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index a972bee66504..706feb7bcbed 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -615,6 +615,8 @@ struct mii_regs {
struct mac_device_info {
const struct stmmac_ops *mac;
const struct stmmac_desc_ops *desc;
+ /* Defaults to the descriptor format's decoder unless the MAC overrides it. */
+ int (*rx_status)(struct stmmac_extra_stats *x, struct dma_desc *p);
const struct stmmac_dma_ops *dma;
const struct stmmac_mode_ops *mode;
const struct stmmac_hwtimestamp *ptp;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 2ece7ba9dd73..0ad2203f76c3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -5,6 +5,7 @@
* Copyright (C) 2017 Corentin Labbe <clabbe.montjoie@gmail.com>
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/iopoll.h>
@@ -197,6 +198,7 @@ static const struct emac_variant emac_variant_h616_emac1 = {
/* Used in RX_CTL1*/
#define EMAC_RX_MD BIT(1)
+#define EMAC_RX_ERR_FRM BIT(3)
#define EMAC_RX_TH_MASK GENMASK(5, 4)
#define EMAC_RX_TH_32 0
#define EMAC_RX_TH_64 (0x1 << 4)
@@ -644,6 +646,9 @@ static void sun8i_dwmac_core_init(struct mac_device_info *hw,
v = (8 << EMAC_BURSTLEN_SHIFT); /* burst len */
writel(v, ioaddr + EMAC_BASIC_CTL1);
+
+ /* Forward checksum failures to software before starting RX. */
+ writel(EMAC_RX_ERR_FRM, ioaddr + EMAC_RX_CTL1);
}
static void sun8i_dwmac_set_mac(void __iomem *ioaddr, bool enable)
@@ -654,7 +659,7 @@ static void sun8i_dwmac_set_mac(void __iomem *ioaddr, bool enable)
r = readl(ioaddr + EMAC_RX_CTL0);
if (enable) {
t |= EMAC_TX_TRANSMITTER_EN;
- r |= EMAC_RX_RECEIVER_EN;
+ r |= EMAC_RX_RECEIVER_EN | EMAC_RX_DO_CRC;
} else {
t &= ~EMAC_TX_TRANSMITTER_EN;
r &= ~EMAC_RX_RECEIVER_EN;
@@ -698,16 +703,9 @@ static void sun8i_dwmac_get_umac_addr(struct mac_device_info *hw,
EMAC_MACADDR_LO(reg_n));
}
-/* caution this function must return non 0 to work */
-static int sun8i_dwmac_rx_ipc_enable(struct mac_device_info *hw)
+static int sun8i_dwmac_rx_ipc(struct mac_device_info *hw)
{
- void __iomem *ioaddr = hw->pcsr;
- u32 v;
-
- v = readl(ioaddr + EMAC_RX_CTL0);
- v |= EMAC_RX_DO_CRC;
- writel(v, ioaddr + EMAC_RX_CTL0);
-
+ /* The receiver always records the checksum result, even with RXCSUM off. */
return 1;
}
@@ -1053,7 +1051,7 @@ static const struct stmmac_ops sun8i_dwmac_ops = {
.core_init = sun8i_dwmac_core_init,
.set_mac = sun8i_dwmac_set_mac,
.dump_regs = sun8i_dwmac_dump_mac_regs,
- .rx_ipc = sun8i_dwmac_rx_ipc_enable,
+ .rx_ipc = sun8i_dwmac_rx_ipc,
.set_filter = sun8i_dwmac_set_filter,
.flow_ctrl = sun8i_dwmac_flow_ctrl,
.set_umac_addr = sun8i_dwmac_set_umac_addr,
@@ -1061,6 +1059,83 @@ static const struct stmmac_ops sun8i_dwmac_ops = {
.set_mac_loopback = sun8i_dwmac_set_mac_loopback,
};
+static void sun8i_dwmac_rx_error_stats(struct stmmac_extra_stats *x, u32 status)
+{
+ if (status & RDES0_DESCRIPTOR_ERROR)
+ x->rx_desc++;
+ if (status & RDES0_OVERFLOW_ERROR)
+ x->overflow_error++;
+ if (status & RDES0_RECEIVE_WATCHDOG)
+ x->rx_watchdog++;
+ if (status & RDES0_SA_FILTER_FAIL)
+ x->sa_filter_fail++;
+ if ((status & RDES0_FRAME_TYPE) && (status & RDES0_IPC_CSUM_ERROR))
+ x->ipc_csum_error++;
+ if (status & RDES0_COLLISION)
+ x->rx_collision++;
+ if (status & RDES0_CRC_ERROR)
+ x->rx_crc_errors++;
+ if (status & RDES0_MII_ERROR)
+ x->rx_mii++;
+ if (status & RDES0_LENGTH_ERROR)
+ x->rx_length++;
+}
+
+static int sun8i_dwmac_rx_status(struct stmmac_extra_stats *x, struct dma_desc *p)
+{
+ const u32 csum_mask = RDES0_IPC_CSUM_ERROR | RDES0_PAYLOAD_CSUM_ERR;
+ const u32 dma_errors = RDES0_DESCRIPTOR_ERROR | RDES0_OVERFLOW_ERROR;
+ const u32 wire_errors = RDES0_CRC_ERROR | RDES0_MII_ERROR |
+ RDES0_RECEIVE_WATCHDOG | RDES0_COLLISION |
+ RDES0_LENGTH_ERROR;
+ u32 status = le32_to_cpu(READ_ONCE(p->des0));
+ u32 len = FIELD_GET(RDES0_FRAME_LEN_MASK, status);
+ bool runt = len < ETH_ZLEN + ETH_FCS_LEN;
+
+ if (unlikely(status & RDES0_OWN))
+ return dma_own;
+ if (unlikely(!(status & RDES0_LAST_DESCRIPTOR)))
+ return discard_frame | rx_not_ls;
+ if (unlikely(!(status & RDES0_FIRST_DESCRIPTOR))) {
+ x->rx_length++;
+ return discard_frame;
+ }
+
+#ifdef STMMAC_VLAN_TAG_USED
+ if (status & RDES0_VLAN_TAG)
+ x->vlan_tag++;
+#endif
+ if (unlikely(status & RDES0_DRIBBLING))
+ x->dribbling_bit++;
+ if (unlikely(status & (RDES0_ERROR_SUMMARY | wire_errors | dma_errors))) {
+ sun8i_dwmac_rx_error_stats(x, status);
+ if (status & dma_errors)
+ return discard_frame;
+ /* An unexplained error summary is not a checksum verdict. */
+ if (!(status & wire_errors) &&
+ (!(status & RDES0_FRAME_TYPE) || !(status & csum_mask)))
+ return discard_frame;
+ }
+
+ /* One buffer per chain descriptor; the reported length includes FCS. */
+ if (unlikely(len < ETH_HLEN + ETH_FCS_LEN ||
+ len > FIELD_GET(RDES1_BUFFER1_SIZE_MASK, le32_to_cpu(p->des1)))) {
+ x->rx_desc++;
+ return discard_frame;
+ }
+ if (unlikely(runt || (status & wire_errors))) {
+ if (runt && !(status & RDES0_LENGTH_ERROR))
+ x->rx_length++;
+ return discard_frame;
+ }
+
+ /* Only a checked IP frame is eligible for CHECKSUM_UNNECESSARY. */
+ if (!(status & RDES0_FRAME_TYPE) || (status & (csum_mask | RDES0_DRIBBLING)))
+ return csum_none;
+
+ return good_frame;
+}
+
static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac)
{
struct stmmac_priv *priv = ppriv;
@@ -1068,6 +1143,7 @@ static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac)
mac->pcsr = priv->ioaddr;
mac->mac = &sun8i_dwmac_ops;
mac->dma = &sun8i_dwmac_dma_ops;
+ mac->rx_status = sun8i_dwmac_rx_status;
priv->dev->priv_flags |= IFF_UNICAST_FLT;
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 8ae95e91a36a..047d809b8b88 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -125,8 +125,6 @@ struct stmmac_desc_ops {
stmmac_do_void_callback(__priv, desc, set_rx_owner, __args)
#define stmmac_get_rx_frame_len(__priv, __args...) \
stmmac_do_callback(__priv, desc, get_rx_frame_len, __args)
-#define stmmac_rx_status(__priv, __args...) \
- stmmac_do_callback(__priv, desc, rx_status, __args)
#define stmmac_rx_extended_status(__priv, __args...) \
stmmac_do_callback(__priv, desc, rx_extended_status, __args)
#define stmmac_enable_tx_timestamp(__priv, __args...) \
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a685ce4638f6..20e9aa7b14f5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -5723,7 +5723,7 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
p = stmmac_get_rx_desc(priv, rx_q, entry);
/* read the status of the incoming frame */
- status = stmmac_rx_status(priv, &priv->xstats, p);
+ status = priv->hw->rx_status(&priv->xstats, p);
/* check if managed by the DMA otherwise go ahead */
if (unlikely(status & dma_own))
break;
@@ -5926,7 +5926,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
p = stmmac_get_rx_desc(priv, rx_q, entry);
/* read the status of the incoming frame */
- status = stmmac_rx_status(priv, &priv->xstats, p);
+ status = priv->hw->rx_status(&priv->xstats, p);
/* check if managed by the DMA otherwise go ahead */
if (unlikely(status & dma_own))
break;
@@ -7732,6 +7732,9 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
return ret;
}
+ if (!priv->hw->rx_status)
+ priv->hw->rx_status = priv->hw->desc->rx_status;
+
/* Set alternate descriptor size (which tells the hardware that
* descriptors are 8 32-bit words) when using extended descriptors
* with ring mode. Only applicable for pre-v4.0 cores. Platform glue
---
base-commit: af6737b9066832a2017c281159950ba92385ce00
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git main
change-id: 20261119-submit-sun8i-rx-features-v1-9177e8328598
Best regards,
--
James Hilliard <james.hilliard1@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack
2026-11-22 7:32 [PATCH net v2] net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack James Hilliard
@ 2026-11-23 7:34 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 7:34 UTC (permalink / raw)
To: james.hilliard1
Cc: netdev, maxime.chevallier, andrew+netdev, davem, edumazet, pabeni,
mcoquelin.stm32, alexandre.torgue, wens, jernej.skrabec, samuel,
clabbe.montjoie, kuba, o.rempel, linux-arm-kernel, linux-sunxi
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 commit message does not describe the patch's changes to
shared stmmac code.
--
net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack
This patch turns on error frame forwarding on the sun8i EMAC. It adds a
sun8i RX status decoder so frames that fail the checksum check reach the
stack with CHECKSUM_NONE instead of being dropped. To do that it adds a
per-MAC rx_status hook to struct mac_device_info, used by stmmac_rx() and
stmmac_rx_zc(), and it moves the EMAC_RX_DO_CRC setting into
sun8i_dwmac_set_mac().
> diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
> index a972bee66504b..706feb7bcbeda 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/common.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/common.h
> @@ -615,6 +615,8 @@ struct mii_regs {
> struct mac_device_info {
> const struct stmmac_ops *mac;
> const struct stmmac_desc_ops *desc;
> + /* Defaults to the descriptor format's decoder unless the MAC overrides it. */
> + int (*rx_status)(struct stmmac_extra_stats *x, struct dma_desc *p);
> const struct stmmac_dma_ops *dma;
> const struct stmmac_mode_ops *mode;
> const struct stmmac_hwtimestamp *ptp;
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 2ece7ba9dd73b..0ad2203f76c34 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
[ ... ]
> @@ -654,7 +659,7 @@ static void sun8i_dwmac_set_mac(void __iomem *ioaddr, bool enable)
> r = readl(ioaddr + EMAC_RX_CTL0);
> if (enable) {
> t |= EMAC_TX_TRANSMITTER_EN;
> - r |= EMAC_RX_RECEIVER_EN;
> + r |= EMAC_RX_RECEIVER_EN | EMAC_RX_DO_CRC;
> } else {
> t &= ~EMAC_TX_TRANSMITTER_EN;
> r &= ~EMAC_RX_RECEIVER_EN;
> @@ -698,16 +703,9 @@ static void sun8i_dwmac_get_umac_addr(struct mac_device_info *hw,
> EMAC_MACADDR_LO(reg_n));
> }
>
> -/* caution this function must return non 0 to work */
> -static int sun8i_dwmac_rx_ipc_enable(struct mac_device_info *hw)
> +static int sun8i_dwmac_rx_ipc(struct mac_device_info *hw)
> {
> - void __iomem *ioaddr = hw->pcsr;
> - u32 v;
> -
> - v = readl(ioaddr + EMAC_RX_CTL0);
> - v |= EMAC_RX_DO_CRC;
> - writel(v, ioaddr + EMAC_RX_CTL0);
> -
> + /* The receiver always records the checksum result, even with RXCSUM off. */
> return 1;
> }
[ ... ]
> diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
> index 8ae95e91a36ab..047d809b8b889 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
> @@ -125,8 +125,6 @@ struct stmmac_desc_ops {
> stmmac_do_void_callback(__priv, desc, set_rx_owner, __args)
> #define stmmac_get_rx_frame_len(__priv, __args...) \
> stmmac_do_callback(__priv, desc, get_rx_frame_len, __args)
> -#define stmmac_rx_status(__priv, __args...) \
> - stmmac_do_callback(__priv, desc, rx_status, __args)
> #define stmmac_rx_extended_status(__priv, __args...) \
> stmmac_do_callback(__priv, desc, rx_extended_status, __args)
> #define stmmac_enable_tx_timestamp(__priv, __args...) \
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a685ce4638f61..20e9aa7b14f56 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -5723,7 +5723,7 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
> p = stmmac_get_rx_desc(priv, rx_q, entry);
>
> /* read the status of the incoming frame */
> - status = stmmac_rx_status(priv, &priv->xstats, p);
> + status = priv->hw->rx_status(&priv->xstats, p);
> /* check if managed by the DMA otherwise go ahead */
> if (unlikely(status & dma_own))
> break;
> @@ -5926,7 +5926,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
> p = stmmac_get_rx_desc(priv, rx_q, entry);
>
> /* read the status of the incoming frame */
> - status = stmmac_rx_status(priv, &priv->xstats, p);
> + status = priv->hw->rx_status(&priv->xstats, p);
> /* check if managed by the DMA otherwise go ahead */
> if (unlikely(status & dma_own))
> break;
> @@ -7732,6 +7732,9 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
> return ret;
> }
>
> + if (!priv->hw->rx_status)
> + priv->hw->rx_status = priv->hw->desc->rx_status;
> +
[Severity: Medium]
Should the commit message also describe the changes to the shared stmmac
code? The subject and body only cover dwmac-sun8i, but the patch also
changes the RX path for every stmmac platform:
- It adds a new rx_status hook to struct mac_device_info.
- It removes the stmmac_rx_status() wrapper from hwif.h. That wrapper
went through stmmac_do_callback(), which checks for NULL.
- stmmac_rx() and stmmac_rx_zc() now call priv->hw->rx_status()
directly.
- stmmac_hw_init() sets the default from priv->hw->desc->rx_status.
The default has to be set after hwif_quirks runs, because
stmmac_dwmac1_quirks() is what sets mac->desc for dwmac1000/100. The
message does not mention that ordering requirement.
All four stmmac_desc_ops tables set .rx_status today, so a NULL
dereference does not appear reachable. But this patch has a Fixes: tag
pointing back to the original 2017 dwmac-sun8i commit, and a backport will
depend on this plumbing. Could the message describe it?
Separately, the commit message says:
Keep the hardware checker running whenever the receiver is enabled.
Turning RX checksum reporting back on can then use the result already
recorded in queued descriptors without flushing the ring.
Is this actually a change in behaviour? Before the patch,
sun8i_dwmac_rx_ipc_enable() set EMAC_RX_DO_CRC every time it was called,
from both stmmac_hw_setup() and stmmac_set_features(). Nothing cleared
the bit, including sun8i_dwmac_set_mac(false).
Moving the bit into sun8i_dwmac_set_mac() looks like a code move that does
not change how the hardware behaves. Could that paragraph be reworded so
it does not read as new behaviour?
> /* Set alternate descriptor size (which tells the hardware that
> * descriptors are 8 32-bit words) when using extended descriptors
> * with ring mode. Only applicable for pre-v4.0 cores. Platform glue
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-submit-sun8i-rx-features-v1-v2-1-24a2564f6edf%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 8:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 7:32 [PATCH net v2] net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack James Hilliard
2026-11-23 7:34 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox