Skip to contentSkip to conversation

net: stmmac: support ethtool rx-all on sun8i

PATCH Superseded James Hilliard 3 participants 9 messages Dec 2 – Dec 3

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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.

The sun8i RX checksum-delivery fix previously posted for net [0] is carried as patch 1 here, superseding that standalone submission. The remaining patches add common stmmac RXALL handling and enable it for sun8i. The fix and feature were split into net and net-next submissions following Maxime's review [1], but the posted fix cannot apply as a prerequisite on current net-next, as reported for v2 [2].

[0] https://lore.kernel.org/r/[email protected]/
[1] https://lore.kernel.org/r/[email protected]/
[2] 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 (4):
net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack
net: stmmac: dwmac-sun8i: align EMAC_RX_MD with tabs
net: stmmac: add common RXALL handling
net: stmmac: dwmac-sun8i: support ethtool rx-all

 drivers/net/ethernet/stmicro/stmmac/common.h      |   4 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 115 +++++++++++++++++++---
 drivers/net/ethernet/stmicro/stmmac/hwif.h        |   4 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |  59 +++++++----
 4 files changed, 150 insertions(+), 32 deletions(-)

---
base-commit: 0a837a30e55bbea2afb01cf0b3ec0c1d789a73ad
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]>
#1 lore raw

PATCH v3 1/4 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.

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")

---
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
index a972bee66504..706feb7bcbed 100644
@@ -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;
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
index 047bda5cbd92..9ea76de030e4 100644
@@ -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
index ca4c7fb11b73..70157efc2255 100644
@@ -5766,7 +5766,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;
@@ -5969,7 +5969,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;
@@ -7800,6 +7800,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
#2 lore raw

Re: [PATCH net-next v3 1/4] net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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] Undocumented stable-backport prerequisite.
- [Medium] The new sun8i_dwmac_rx_status() (drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c) assumes the…

--

net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack

This patch sets the sun8i EMAC error-forwarding bit, so frames with bad IP or transport checksums now reach the stack. It also adds a sun8i-specific RX status decoder that both stmmac_rx() and stmmac_rx_zc() use. The hardware checksum checker now stays enabled whenever the receiver is on, and checksum failures and unchecked frames are returned as csum_none.

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
index 613199da57c1b..a7e4fca50141f 100644

[ ... ]

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c static void sun8i_dwmac_core_init(struct mac_device_info *hw, · line 659

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +3 -0
@@ -652,6 +653,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);
 }

[Severity: Medium]
With EMAC_RX_ERR_FRM set, the MAC now passes frames with bad IP/TCP/UDP checksums up instead of dropping them. This patch never sets skb->ip_summed itself. These frames only end up as CHECKSUM_NONE because the common RX paths check csum_none:

stmmac_rx():

		if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
		    (status & csum_none))
			skb_checksum_none_assert(skb);
		else
			skb->ip_summed = CHECKSUM_UNNECESSARY;

In stmmac_rx(), the csum_none test came from ee0aace5f844 ("net: stmmac:
Correctly handle Rx checksum offload errors"), which has no Fixes: or
Cc: stable tag. In stmmac_dispatch_skb_zc(), it came from fcfc52fcf89a ("net: stmmac: honour Rx checksum errors in the AF_XDP zero-copy path").

This patch carries Fixes: 9f93ac8d4085, so stable may pick it up for every tree back to the original dwmac-sun8i addition. In a tree without ee0aace5f844, stmmac_rx() marks a frame CHECKSUM_UNNECESSARY whenever coe is set and the ethertype is IP. sun8i uses STMMAC_RX_COE_TYPE2, and RXCSUM is on by default.

In such a tree, would a backport cause frames with corrupted TCP/UDP payloads to be accepted by the stack as already verified?

The v3 notes say:

- Document the checksum-status requirements for stable backports.

However, the commit message does not mention any prerequisite, and the notes below the --- line are dropped when the patch is applied. Could the dependencies on ee0aace5f844 and fcfc52fcf89a be recorded in the commit message, for example as prerequisite annotations on Cc: stable lines?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
@@ -1081,6 +1078,83 @@ static const struct stmmac_ops sun8i_dwmac_ops = {
 	.set_mac_loopback = sun8i_dwmac_set_mac_loopback,
 };
 

[ ... ]

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +7 -0
+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;

[ ... ]

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +9 -0
+	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;
+	}

[ ... ]

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c static const struct stmmac_ops sun8i_dwmac_ops = { · line 1156

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +6 -0
+	/* 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;
+}

[Severity: Medium]
Is it known that the Allwinner EMAC fills RDES0 bits 5, 7 and 0 (RDES0_FRAME_TYPE, RDES0_IPC_CSUM_ERROR, RDES0_PAYLOAD_CSUM_ERR) using the Synopsys Type-2 COE encoding?

The previous sun8i decoder, ndesc_get_rx_status() in norm_desc.c, never read RDES0_FRAME_TYPE. Only enh_desc_coe_rdes0() decodes these three bits, and sun8i does not use enhanced descriptors. The probe code only says the rx_coe TYPE2 setting was copied from the Allwinner drivers.

If the hardware does not set bit 5 for checked IPv4/IPv6 frames, every frame would return csum_none in sun8i_dwmac_rx_status(). Would that silently disable RX checksum offload on all sun8i/H6/H616 boards?

The test in the commit message shows that frames with a bad UDP checksum are delivered. It does not show that good frames still get CHECKSUM_UNNECESSARY.

Bits 7 and 0 might also mean something else when the error summary is set, for example the giant frame or Rx MAC address meanings in the Synopsys layout. In that case, could the error summary branch treat non-checksum error frames as checksum failures and deliver them? Those frames would still get CHECKSUM_NONE and go through the buffer length check.

Is there a datasheet reference, or a test with good frames, that confirms this encoding?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-submit-sun8i-rxall-v1-v3-0-01aa6280e6ae%40gmail.com
#3 lore raw

PATCH v3 2/4 net: stmmac: dwmac-sun8i: align EMAC_RX_MD with tabs

In reply to James Hilliard

Use 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
index a7e4fca50141..8377dc798537 100644
@@ -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
#4 lore raw

PATCH v3 3/4 net: stmmac: add common RXALL handling

In reply to James Hilliard

Allow 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
index 706feb7bcbed..ab959ee3a5dd 100644
@@ -360,6 +360,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
index 9ea76de030e4..81c8ac3756a7 100644
@@ -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
#5 lore raw

Re: [PATCH net-next v3 3/4] net: stmmac: add common RXALL handling

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

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 new stmops->set_rx_all() hook is called from stmmac_set_features() holding only RTNL and the netdev ops lock.

--

net: stmmac: add common RXALL handling

This adds an rx_error_frame status so a MAC can mark complete frames with wire errors separately from descriptors that must always be discarded. With NETIF_F_RXALL enabled, those frames are delivered without being counted as good packets. A new set_rx_all() stmmac_ops hook is called from stmmac_set_features(), and rx-all is advertised only when the MAC provides that hook.

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 70157efc22559..8102a72c52c5d 100644

[ ... ]

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_set_features(struct net_device *netdev, · line 6482

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -0
@@ -6462,6 +6475,11 @@ static int stmmac_set_features(struct net_device *netdev,
 			stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan);
 	}
 
+	if (((netdev->features ^ features) & NETIF_F_RXALL) &&
+	    netif_running(netdev) && netif_device_present(netdev) &&
+	    priv->hw->mac->set_rx_all)
+		priv->hw->mac->set_rx_all(priv, features & NETIF_F_RXALL);
+

[Severity: Medium]

Is anything serializing set_rx_all() against other writers of the same MAC register that run without RTNL?

stmmac_set_features() calls the hook while holding only RTNL and the netdev ops lock. The new set_rx_all member in struct stmmac_ops does not document any locking or context rules for implementers.

The only implementation in the series is sun8i_dwmac_set_rx_all(), from "net: stmmac: dwmac-sun8i: support ethtool rx-all". It does a plain read-modify-write of EMAC_RX_CTL1:

dwmac-sun8i.c:sun8i_dwmac_set_rx_all() {
    u32 v = readl(priv->ioaddr + EMAC_RX_CTL1);

    if (enable)
        v |= EMAC_RX_RUNT_FRM;
    else
        v &= ~EMAC_RX_RUNT_FRM;
    writel(v, priv->ioaddr + EMAC_RX_CTL1);
}

sun8i_dwmac_flow_ctrl() also does a read-modify-write of EMAC_RX_CTL1:

dwmac-sun8i.c:sun8i_dwmac_flow_ctrl() {
    v = readl(ioaddr + EMAC_RX_CTL1);
    v &= ~(EMAC_RX_FIFO_FLOW_CTL | EMAC_RX_FLOW_CTL_TH_ACT |
           EMAC_RX_FLOW_CTL_TH_DEACT);
    ...
    writel(v, ioaddr + EMAC_RX_CTL1);
}

That second function runs from the phylink resolve work item:

phylink_resolve()
phylink_link_up()

    stmmac_mac_link_up()
      stmmac_mac_flow_ctrl()
        sun8i_dwmac_flow_ctrl()

phylink_resolve() holds pl->phydev_mutex, phydev->lock and pl->state_mutex, but not RTNL.

If "ethtool -K ethX rx-all on" runs while a link-up is being resolved, can the two read-modify-writes interleave and lose one of the updates?

One outcome is that the EMAC_RX_RUNT_FRM change is undone. Then dev->features shows rx-all on while the MAC still drops runts, or the reverse.

The other outcome is that the negotiated RX FIFO flow-control and threshold bits are cleared while phylink believes TX pause is active.

The sun8i commit message says the direct register update is safe because RTNL serializes it with open, close and reset, and because the IRQ handler does not touch the RX threshold. Does that reasoning cover the phylink link-up path?

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	if (features & NETIF_F_HW_VLAN_CTAG_RX)
 		priv->hw->hw_vlan_en = true;
 	else

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-submit-sun8i-rxall-v1-v3-0-01aa6280e6ae%40gmail.com
#6 lore raw

PATCH v3 4/4 net: stmmac: dwmac-sun8i: support ethtool rx-all

In reply to James Hilliard

Allow 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 that bit when the setting changes on a running interface. RX_CTL1 also controls DMA, but RTNL serializes the ethtool update with open, close and reset. System suspend freezes userspace before stopping DMA, and the sun8i interrupt handler does not change the RX threshold. The setter can therefore update the register directly. Keep error forwarding enabled in both modes for RX checksum handling.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +18 -2
index 8377dc798537..c1c5ab38022a 100644
@@ -198,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_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
@@ -655,7 +656,21 @@ 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)
+{
+	u32 v = readl(priv->ioaddr + EMAC_RX_CTL1);
+
+	if (enable)
+		v |= EMAC_RX_RUNT_FRM;
+	else
+		v &= ~EMAC_RX_RUNT_FRM;
+	writel(v, priv->ioaddr + EMAC_RX_CTL1);
 }
 
 static void sun8i_dwmac_set_mac(void __iomem *ioaddr, bool enable)
@@ -1072,6 +1087,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,
@@ -1145,7 +1161,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
#7 lore raw

Re: [PATCH net-next v3 4/4] net: stmmac: dwmac-sun8i: support ethtool rx-all

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: stmmac: dwmac-sun8i: EMAC_RX_CTL1 RMW race in sun8i_dwmac_set_rx_all() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: stmmac: dwmac-sun8i: EMAC_RX_CTL1 RMW race in sun8i_dwmac_set_rx_all()
--

commit 39ced794d174f2d3a44a86ff63330a2f1a439467
Author: James Hilliard <[email protected]>

net: stmmac: dwmac-sun8i: support ethtool rx-all

This commit adds NETIF_F_RXALL support for dwmac-sun8i by controlling EMAC_RX_RUNT_FRM in EMAC_RX_CTL1 and returning rx_error_frame | csum_none for runt and wire-errored frames.

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
index 8377dc7985377..c1c5ab38022ac 100644

[ ... ]

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +6 -1
@@ -655,7 +656,21 @@ 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);
+}
+

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c static void sun8i_dwmac_core_init(struct mac_device_info *hw, · line 674

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +9 -0
+static void sun8i_dwmac_set_rx_all(struct stmmac_priv *priv, bool enable)
+{
+	u32 v = readl(priv->ioaddr + EMAC_RX_CTL1);
+
+	if (enable)
+		v |= EMAC_RX_RUNT_FRM;
+	else
+		v &= ~EMAC_RX_RUNT_FRM;
+	writel(v, priv->ioaddr + EMAC_RX_CTL1);
 }

[Severity: Medium]
Can sun8i_dwmac_set_rx_all() race with sun8i_dwmac_flow_ctrl() on EMAC_RX_CTL1?

stmmac_set_features() calls set_rx_all() under rtnl_lock(), whereas sun8i_dwmac_flow_ctrl() also updates EMAC_RX_CTL1 from phylink_resolve() workqueue context under pl->state_mutex without holding rtnl_lock():

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c:sun8i_dwmac_flow_ctrl() {
    ...
	v = readl(ioaddr + EMAC_RX_CTL1);
	v &= ~(EMAC_RX_FIFO_FLOW_CTL | EMAC_RX_FLOW_CTL_TH_ACT |
	       EMAC_RX_FLOW_CTL_TH_DEACT);
	if (fc & FLOW_TX)
		v |= EMAC_RX_FIFO_FLOW_CTL |
		     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_ACT,
				EMAC_RX_FLOW_CTL_TH_2K) |
		     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_DEACT,
				EMAC_RX_FLOW_CTL_TH_4K);
	writel(v, ioaddr + EMAC_RX_CTL1);
    ...
}

If an ethtool rx-all toggle overlaps with link-up resolution, the two read-modify-write sequences can interleave:

CPU0 CPU1 (kworker)
stmmac_set_features() phylink_resolve()
sun8i_dwmac_set_rx_all() ...

    v = readl(... + EMAC_RX_CTL1)         stmmac_mac_link_up()
                                            ...
                                              sun8i_dwmac_flow_ctrl()
                                                v = readl(... + EMAC_RX_CTL1)
                                                v |= EMAC_RX_FIFO_FLOW_CTL...
                                                writel(v, ... + EMAC_RX_CTL1)
    v |= EMAC_RX_RUNT_FRM
    writel(v, ... + EMAC_RX_CTL1)  <-- overwrites flow control bits

Depending on which write finishes last, either the RX FIFO flow-control settings or EMAC_RX_RUNT_FRM is lost.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#8 lore raw

Re: [PATCH net-next v3 4/4] net: stmmac: dwmac-sun8i: support ethtool rx-all

In reply to James Hilliard
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

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] sun8i_dwmac_set_rx_all() (drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c:665-674) does an…

--

net: stmmac: dwmac-sun8i: support ethtool rx-all

This patch adds rx-all support to dwmac-sun8i. Runt forwarding in EMAC_RX_CTL1 is set from NETIF_F_RXALL at core init, and a new set_rx_all op updates the bit on a running interface. Frames with complete wire errors, runts included, are now returned as rx_error_frame | csum_none instead of discard_frame.

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
index 8377dc7985377..c1c5ab38022ac 100644

[ ... ]

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c static void sun8i_dwmac_core_init(struct mac_device_info *hw, · line 674

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +9 -0
+static void sun8i_dwmac_set_rx_all(struct stmmac_priv *priv, bool enable)
+{
+	u32 v = readl(priv->ioaddr + EMAC_RX_CTL1);
+
+	if (enable)
+		v |= EMAC_RX_RUNT_FRM;
+	else
+		v &= ~EMAC_RX_RUNT_FRM;
+	writel(v, priv->ioaddr + EMAC_RX_CTL1);
 }

[Severity: Medium]
Can this read-modify-write of EMAC_RX_CTL1 race with sun8i_dwmac_flow_ctrl()?

The commit message says:

"RX_CTL1 also controls DMA, but RTNL serializes the ethtool update with open, close and reset. ... The setter can therefore update the register directly."

sun8i_dwmac_flow_ctrl() also does a read-modify-write of the same register:

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c:sun8i_dwmac_flow_ctrl() {
    ...
	v = readl(ioaddr + EMAC_RX_CTL1);
	v &= ~(EMAC_RX_FIFO_FLOW_CTL | EMAC_RX_FLOW_CTL_TH_ACT |
	       EMAC_RX_FLOW_CTL_TH_DEACT);
	if (fc & FLOW_TX)
		v |= EMAC_RX_FIFO_FLOW_CTL | ...
	writel(v, ioaddr + EMAC_RX_CTL1);
    ...
}

It runs on every link-up from the phylink resolve worker:

phylink_resolve()
phylink_link_up()

    stmmac_mac_link_up()
      stmmac_mac_flow_ctrl()
        sun8i_dwmac_flow_ctrl()

phylink_resolve() takes pl->phydev_mutex, phy->lock and pl->state_mutex. It never takes RTNL.

The new setter is only protected by RTNL in stmmac_set_features():

	if (((netdev->features ^ features) & NETIF_F_RXALL) &&
	    netif_running(netdev) && netif_device_present(netdev) &&
	    priv->hw->mac->set_rx_all)
		priv->hw->mac->set_rx_all(priv, features & NETIF_F_RXALL);

Close and reset go through phylink_stop(), which stops the resolve work, so their RX_CTL1 writes are safe. The ethtool path does not stop it.

So "ethtool -K ethX rx-all on" can overlap with a link-up resolve. If the worker reads RX_CTL1, the setter then writes RUNT_FRM, and the worker writes back its stale value, RUNT_FRM is lost. NETIF_F_RXALL then reports on while the MAC still drops runts.

The opposite order can also happen. The setter reads, the worker programs the negotiated EMAC_RX_FIFO_FLOW_CTL and threshold bits, and the setter writes back its stale value. The flow-control setup is then lost until the next link change.

Would some locking between the two paths be needed here? If not, could the commit message be updated to cover the phylink resolve worker?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-submit-sun8i-rxall-v1-v3-0-01aa6280e6ae%40gmail.com