[PATCH net] net: mdio: aspeed: add dummy read to avoid read-after-write issue

Jacky Chou posted 1 patch 1 week, 4 days ago
There is a newer version of this series
drivers/net/mdio/mdio-aspeed.c | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH net] net: mdio: aspeed: add dummy read to avoid read-after-write issue
Posted by Jacky Chou 1 week, 4 days ago
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: 737ca352569e ("net: mdio: aspeed: move reg accessing part into separate functions")
Signed-off-by: Jacky Chou <jacky_chou@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>
Re: [PATCH net] net: mdio: aspeed: add dummy read to avoid read-after-write issue
Posted by Andrew Lunn 1 week, 3 days ago
On Mon, Dec 08, 2025 at 02:49:56PM +0800, Jacky Chou wrote:
> 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: 737ca352569e ("net: mdio: aspeed: move reg accessing part into separate functions")

That seems like an odd Fixes: tag. That is just moving code around,
but the write followed by a read existed before that. Why not:

commit f160e99462c68ab5b9e2b9097a4867459730b49a
Author: Andrew Jeffery <andrew@aj.id.au>
Date:   Wed Jul 31 15:09:57 2019 +0930

    net: phy: Add mdio-aspeed
    
    The AST2600 design separates the MDIO controllers from the MAC, which is
    where they were placed in the AST2400 and AST2500. Further, the register
    interface is reworked again, so now we have three possible different
    interface implementations, however this driver only supports the
    interface provided by the AST2600. The AST2400 and AST2500 will continue
    to be supported by the MDIO support embedded in the FTGMAC100 driver.
    
    The hardware supports both C22 and C45 mode, but for the moment only C22
    support is implemented.
    
    Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Signed-off-by: David S. Miller <davem@davemloft.net>


    Andrew

---
pw-bot: cr