* [PATCH net v2] net: mdio: aspeed: add dummy read to avoid read-after-write issue
@ 2025-12-09 11:15 Jacky Chou
2025-12-09 11:27 ` Russell King (Oracle)
0 siblings, 1 reply; 3+ messages in thread
From: Jacky Chou @ 2025-12-09 11:15 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Joel Stanley,
Andrew Jeffery, Potin Lai
Cc: netdev, linux-arm-kernel, linux-aspeed, linux-kernel, Jacky Chou
The Aspeed MDIO controller may return incorrect data when a read operation
follows immediately after a write. Due to a controller bug, the subsequent
read can latch stale data, causing the polling logic to terminate earlier
than expected.
To work around this hardware issue, insert a dummy read after each write
operation. This ensures that the next actual read returns the correct
data and prevents premature polling exit.
This workaround has been verified to stabilize MDIO transactions on
affected Aspeed platforms.
Fixes: f160e99462c6 ("net: phy: Add mdio-aspeed")
Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com>
---
Changes in v2:
- Updated the Fixes: tag
- Link to v1: https://lore.kernel.org/r/20251208-aspeed_mdio_add_dummy_read-v1-1-0a1861ad2161@aspeedtech.com
---
drivers/net/mdio/mdio-aspeed.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/mdio/mdio-aspeed.c b/drivers/net/mdio/mdio-aspeed.c
index e55be6dc9ae7..7d11add3c05e 100644
--- a/drivers/net/mdio/mdio-aspeed.c
+++ b/drivers/net/mdio/mdio-aspeed.c
@@ -63,6 +63,13 @@ static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad,
iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
+ /* Workaround for read-after-write issue.
+ * The controller may return stale data if a read follows immediately
+ * after a write. A dummy read forces the hardware to update its
+ * internal state, ensuring that the next real read returns correct data.
+ */
+ (void)ioread32(ctx->base + ASPEED_MDIO_CTRL);
+
return readl_poll_timeout(ctx->base + ASPEED_MDIO_CTRL, ctrl,
!(ctrl & ASPEED_MDIO_CTRL_FIRE),
ASPEED_MDIO_INTERVAL_US,
---
base-commit: 0373d5c387f24de749cc22e694a14b3a7c7eb515
change-id: 20251208-aspeed_mdio_add_dummy_read-587ab8808817
Best regards,
--
Jacky Chou <jacky_chou@aspeedtech.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: mdio: aspeed: add dummy read to avoid read-after-write issue
2025-12-09 11:15 [PATCH net v2] net: mdio: aspeed: add dummy read to avoid read-after-write issue Jacky Chou
@ 2025-12-09 11:27 ` Russell King (Oracle)
2025-12-10 2:51 ` Jacky Chou
0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2025-12-09 11:27 UTC (permalink / raw)
To: Jacky Chou
Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Joel Stanley, Andrew Jeffery,
Potin Lai, netdev, linux-arm-kernel, linux-aspeed, linux-kernel
On Tue, Dec 09, 2025 at 07:15:31PM +0800, Jacky Chou wrote:
> + /* Workaround for read-after-write issue.
> + * The controller may return stale data if a read follows immediately
> + * after a write. A dummy read forces the hardware to update its
> + * internal state, ensuring that the next real read returns correct data.
> + */
> + (void)ioread32(ctx->base + ASPEED_MDIO_CTRL);
What purpose does this cast to void achieve in an already void context?
We have plenty of functions that get called in the kernel that return a
value which the caller ignores, never assigning to a variable, none of
these warn.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net v2] net: mdio: aspeed: add dummy read to avoid read-after-write issue
2025-12-09 11:27 ` Russell King (Oracle)
@ 2025-12-10 2:51 ` Jacky Chou
0 siblings, 0 replies; 3+ messages in thread
From: Jacky Chou @ 2025-12-10 2:51 UTC (permalink / raw)
To: Russell King
Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Joel Stanley, Andrew Jeffery,
Potin Lai, netdev@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org
Hi Russell King,
> > + (void)ioread32(ctx->base + ASPEED_MDIO_CTRL);
>
> What purpose does this cast to void achieve in an already void context?
>
> We have plenty of functions that get called in the kernel that return a value
> which the caller ignores, never assigning to a variable, none of these warn.
>
Thanks for pointing this out.
On some older compilers I used to encounter warnings when ignoring a
function's return value, so adding (void) became a habitual practice.
You're right that it is unnecessary in the kernel context today.
I'll remove it in the next revision.
Thanks,
Jacky
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-10 2:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 11:15 [PATCH net v2] net: mdio: aspeed: add dummy read to avoid read-after-write issue Jacky Chou
2025-12-09 11:27 ` Russell King (Oracle)
2025-12-10 2:51 ` Jacky Chou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).