net: stmmac: support ethtool rx-all on sun8i
Subsystems (5)
v4 cover net: stmmac: support ethtool rx-all on sun8i
On H616 the PHY can count a bad-FCS frame even when it does not appear in a packet capture. Enabling rx-all lets a capture see the complete errored frames the MAC can forward. On this hardware, a 64-byte frame with a bad FCS reaches DMA, but a 63-byte one does not, even with runt forwarding enabled. Both lengths include the FCS.
Patch 1 supersedes the standalone sun8i RX checksum-delivery fix [0]. The series also serializes changes to the register shared by RX DMA, pause thresholds and runt forwarding before adding the rx-all switch.
[0] https://lore.kernel.org/r/[email protected]/
---
Changes in v4:
- Serialize live RX_CTL1 updates, including phylink pause configuration
and RX DMA start/stop, before using the register for rx-all. Sashiko
reported the ethtool/phylink race [1]; Codex helped implement and
check the locking change.
- Record the H616 checksum status encoding and the two stmmac checksum
fixes needed for backports in patch 1.
- Link to v3: https://patch.msgid.link/[email protected]
[1] https://lore.kernel.org/r/[email protected]/
Changes in v3:
- Carry the checksum-delivery fix as patch 1 against net-next, superseding
its separate net submission and removing the external prerequisite.
- Rebase onto net-next at 0a837a30e55b, following Willem's review.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Drop the RX_CTL1 lock and leave DMA start, stop and mode setup unchanged.
- Align the EMAC_RX_MD definition in a separate patch, as Andrew requested.
- Apply rx-all alongside the other receive filters, independently of RX checksum reporting.
- Link to v1: https://patch.msgid.link/[email protected]
---
James Hilliard (5):
net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack
net: stmmac: dwmac-sun8i: align EMAC_RX_MD with tabs
net: stmmac: dwmac-sun8i: serialize RX_CTL1 updates
net: stmmac: add common RXALL handling
net: stmmac: dwmac-sun8i: support ethtool rx-all
drivers/net/ethernet/stmicro/stmmac/common.h | 10 +- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 185 +++++++++++++++------ .../net/ethernet/stmicro/stmmac/dwmac1000_core.c | 4 +- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 4 +- .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 4 +- drivers/net/ethernet/stmicro/stmmac/hwif.c | 2 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 4 +- drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c | 4 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 59 +++++-- 9 files changed, 191 insertions(+), 85 deletions(-)
---
base-commit: c1165beb053a652299b1503b2dd7674ced0b1596
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git main
change-id: 20261122-submit-sun8i-rxall-v1-2666ccf2a020
Best regards,
Signature · 1 line
James Hilliard <[email protected]>
PATCH v4 1/5 net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack
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.
On H616, IPv4 and IPv6 UDP frames with a valid checksum had RX status bit 5 set and bits 7 and 0 clear. Sending the same frames with a bad UDP checksum also set bit 0. This matches the checksum status encoding in the Allwinner driver.
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.
Backports need commit ee0aace5f844 ("net: stmmac: Correctly handle Rx checksum offload errors") so the skb path honors CHECKSUM_NONE. Trees with the AF_XDP zero-copy receive path also need commit fcfc52fcf89a ("net: stmmac: honour Rx checksum errors in the AF_XDP zero-copy path").
---
Standalone checksum-delivery revision notes:
Changes in v3:
- Explain how both RX paths select their decoder and why the default
is installed after descriptor selection.
- Clarify that moving the checker enable preserves its behavior.
- Document the checksum-status requirements for stable backports.
- Link to v2: https://patch.msgid.link/[email protected]
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/[email protected]
--- drivers/net/ethernet/stmicro/stmmac/common.h | 2 + drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 97 ++++++++++++++++++++--- drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 - drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +- 4 files changed, 93 insertions(+), 15 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +2 -0
@@ -627,6 +627,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;
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +86 -11
140 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/hwif.h +0 -2
@@ -127,8 +127,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...) \
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -2
@@ -5772,7 +5772,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 ;
@@ -5975,7 +5975,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 ;
@@ -7806,6 +7806,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
Signature · 1 line
2.53.0
PATCH v4 2/5 net: stmmac: dwmac-sun8i: align EMAC_RX_MD with tabs
In reply to James HilliardUse tabs to align the receive mode bit with the receive error and threshold definitions in the same register.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
@@ -197,7 +197,7 @@ static const struct emac_variant emac_variant_h616_emac1 = {#define EMAC_FRM_FLT_MULTICAST BIT(16)/* Used in RX_CTL1*/ -#define EMAC_RX_MD BIT(1) +#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
Signature · 1 line
2.53.0
PATCH v4 3/5 net: stmmac: dwmac-sun8i: serialize RX_CTL1 updates
In reply to James HilliardA link-up event can race with RX queue reconfiguration on sun8i. If phylink reads RX_CTL1 before the queue stops RX DMA and writes its pause settings afterward, it restores the old DMA enable bit. The opposite ordering can lose the new pause thresholds.
Use the per-MAC register lock for live changes to RX_CTL1. The DMA start, stop and mode callbacks and the phylink flow-control callback now update only their own fields under that lock. Reset and core initialization write the whole register before these users run.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 6 +- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 75 ++++++++++------------ .../net/ethernet/stmicro/stmmac/dwmac1000_core.c | 4 +- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 4 +- .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 4 +- drivers/net/ethernet/stmicro/stmmac/hwif.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c | 4 +- 7 files changed, 46 insertions(+), 53 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +2 -4
@@ -655,10 +655,8 @@ struct mac_device_info {bool additional_32_addr;bool additional_64_addr; -/* This spinlock protects read-modify-write of the interrupt -* mask/enable registers. -*/ -spinlock_t irq_ctrl_lock; +/* Serializes updates to shared MAC control registers. */ +spinlock_t reg_lock; };struct stmmac_rx_routing {
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +35 -40
116 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +2 -2
@@ -70,11 +70,11 @@ static void dwmac1000_irq_modify(struct mac_device_info *hw, u32 disable,unsigned long flags;u32 value; -spin_lock_irqsave (&hw->irq_ctrl_lock, flags); +spin_lock_irqsave (&hw->reg_lock, flags); value =readl (int_mask) | disable; value &= ~enable;writel (value, int_mask); -spin_unlock_irqrestore (&hw->irq_ctrl_lock, flags); +spin_unlock_irqrestore (&hw->reg_lock, flags); }static int dwmac1000_rx_ipc_enable (struct mac_device_info *hw)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +2 -2
@@ -71,11 +71,11 @@ static void dwmac4_irq_modify(struct mac_device_info *hw, u32 disable,unsigned long flags;u32 value; -spin_lock_irqsave (&hw->irq_ctrl_lock, flags); +spin_lock_irqsave (&hw->reg_lock, flags); value =readl (int_mask) & ~disable; value |= enable;writel (value, int_mask); -spin_unlock_irqrestore (&hw->irq_ctrl_lock, flags); +spin_unlock_irqrestore (&hw->reg_lock, flags); }static void dwmac4_update_caps (struct stmmac_priv *priv)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +2 -2
@@ -36,11 +36,11 @@ static void dwxgmac2_irq_modify(struct mac_device_info *hw, u32 disable,unsigned long flags;u32 value; -spin_lock_irqsave (&hw->irq_ctrl_lock, flags); +spin_lock_irqsave (&hw->reg_lock, flags); value =readl (int_mask) & ~disable; value |= enable;writel (value, int_mask); -spin_unlock_irqrestore (&hw->irq_ctrl_lock, flags); +spin_unlock_irqrestore (&hw->reg_lock, flags); }static void dwxgmac2_update_caps (struct stmmac_priv *priv)
drivers/net/ethernet/stmicro/stmmac/hwif.c +1 -1
@@ -341,7 +341,7 @@ int stmmac_hwif_init(struct stmmac_priv *priv) needs_setup = false; } -spin_lock_init (&mac->irq_ctrl_lock); +spin_lock_init (&mac->reg_lock);/* Fallback to generic HW */
drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c +2 -2
@@ -73,7 +73,7 @@ static void stmmac_fpe_configure_pmac(struct ethtool_mmsv *mmsv, bool pmac_enablunsigned long flags;u32 value; -spin_lock_irqsave (&priv->hw->irq_ctrl_lock, flags); +spin_lock_irqsave (&priv->hw->reg_lock, flags); value =readl (ioaddr + reg->int_en_reg);if (pmac_enable) {
@@ -88,7 +88,7 @@ static void stmmac_fpe_configure_pmac(struct ethtool_mmsv *mmsv, bool pmac_enabl }writel (value, ioaddr + reg->int_en_reg); -spin_unlock_irqrestore (&priv->hw->irq_ctrl_lock, flags); +spin_unlock_irqrestore (&priv->hw->reg_lock, flags); } static void stmmac_fpe_send_mpacket(struct ethtool_mmsv *mmsv,
Signature · 1 line
2.53.0
PATCH v4 4/5 net: stmmac: add common RXALL handling
In reply to James HilliardAllow a MAC to distinguish complete frames with wire errors from descriptors that must always be discarded. When rx-all is enabled, deliver the former without trusting their checksum or counting them as good packets. Keep counting the errors in either mode.
Apply the same policy to page-pool and zero-copy RX. Advertise rx-all only when the MAC supplies the receive-mode callback; leave it off by default.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 2 + drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 52 ++++++++++++++++------- 3 files changed, 40 insertions(+), 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +2 -0
@@ -372,6 +372,8 @@ enum rx_frame_status { llc_snap =0x4 , dma_own =0x8 , rx_not_ls =0x10 , +/* Complete frame with a wire error, deliverable only with RXALL. */ + rx_error_frame = 0x20, };/* Tx status */
drivers/net/ethernet/stmicro/stmmac/hwif.h +2 -0
@@ -354,6 +354,8 @@ struct stmmac_ops { struct mac_device_info *hw, u32 chan);/* Multicast filter setting */ void (*set_filter)(struct mac_device_info *hw,struct net_device *dev); +/* Program the MAC receive mode for NETIF_F_RXALL. */ +void (*set_rx_all)(struct stmmac_priv *priv,bool enable);/* Flow control setting */ void (*flow_ctrl)(struct mac_device_info *hw,unsigned int duplex,unsigned int fc,unsigned int pause_time,u8 tx_cnt);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +36 -16
94 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 5/5 net: stmmac: dwmac-sun8i: support ethtool rx-all
In reply to James HilliardAllow packet captures to see complete frames that the sun8i MAC forwards with wire errors. Mark these frames, including runts, as errored with an unverified checksum so stmmac can deliver them when rx-all is enabled. Incomplete frames and DMA errors still require a drop.
Set runt forwarding from the rx-all setting at initialization and update just that bit under the RX_CTL1 lock when the setting changes on a running interface. Keep error forwarding enabled in both modes so checksum failures still reach the stack.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +13 -2
@@ -194,6 +194,7 @@ static const struct emac_variant emac_variant_h616_emac1 = {/* Used in RX_CTL1*/ #define EMAC_RX_MD BIT(1) +#define EMAC_RX_RUNT_FRM BIT(2)#define EMAC_RX_ERR_FRM BIT(3)#define EMAC_RX_TH_MASK GENMASK(5, 4)#define EMAC_RX_TH_32 0
@@ -653,7 +654,16 @@ static void sun8i_dwmac_core_init(struct mac_device_info *hw,writel (v, ioaddr +EMAC_BASIC_CTL1 );/* Forward checksum failures to software before starting RX. */ -writel (EMAC_RX_ERR_FRM , ioaddr +EMAC_RX_CTL1 ); + v =EMAC_RX_ERR_FRM ; +if (dev->features &NETIF_F_RXALL ) + v |=EMAC_RX_RUNT_FRM ; +writel (v, ioaddr +EMAC_RX_CTL1 ); +} + +static void sun8i_dwmac_set_rx_all (struct stmmac_priv *priv,bool enable) +{ +sun8i_dwmac_update_rx_ctl1 (priv->hw,EMAC_RX_RUNT_FRM , + enable ?EMAC_RX_RUNT_FRM :0 ); }static void sun8i_dwmac_set_mac (void __iomem *ioaddr,bool enable)
@@ -1067,6 +1077,7 @@ static const struct stmmac_ops sun8i_dwmac_ops = { .dump_regs = sun8i_dwmac_dump_mac_regs, .rx_ipc = sun8i_dwmac_rx_ipc, .set_filter = sun8i_dwmac_set_filter, + .set_rx_all = sun8i_dwmac_set_rx_all, .flow_ctrl = sun8i_dwmac_flow_ctrl, .set_umac_addr = sun8i_dwmac_set_umac_addr, .get_umac_addr = sun8i_dwmac_get_umac_addr,
@@ -1140,7 +1151,7 @@ static int sun8i_dwmac_rx_status(struct stmmac_extra_stats *x, struct dma_desc *if (unlikely (runt || (status & wire_errors))) {if (runt && !(status &RDES0_LENGTH_ERROR )) x->rx_length++; -return discard_frame; +return rx_error_frame | csum_none; }/* Only a checked IP frame is eligible for CHECKSUM_UNNECESSARY. */
Signature · 1 line
2.53.0
[email protected]
AI reviewThis 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:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
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.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.