Skip to contentSkip to conversation

net: mdio: aspeed: Add dummy read for fire control

PATCH In review Jacky Chou 4 participants 8 messages Nov 19, 2024 – Nov 21, 2024

Subsystems (4)
lore
Share & tools
lore

Jacky Chou

author
#0 lore raw

PATCH v2 1/1 net: mdio: aspeed: Add dummy read for fire control

When the command bus is sometimes busy, it may cause the command is not arrived to MDIO controller immediately. On software, the driver issues a write command to the command bus does not wait for command complete and it returned back to code immediately. But a read command will wait for the data back, once a read command was back indicates the previous write command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Fixes a9770eac511a ("net: mdio: Move MDIO drivers into a new subdirectory")
---
 drivers/net/mdio/mdio-aspeed.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/mdio/mdio-aspeed.c +2 -0
index c2170650415c..373902d33b96 100644
@@ -62,6 +62,8 @@ static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad,
 		| FIELD_PREP(ASPEED_MDIO_DATA_MIIRDATA, data);
 
 	iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
+	/* Add dummy read to ensure triggering mdio controller */
+	(void)ioread32(ctx->base + ASPEED_MDIO_CTRL);
 
 	return readl_poll_timeout(ctx->base + ASPEED_MDIO_CTRL, ctrl,
 				!(ctrl & ASPEED_MDIO_CTRL_FIRE),
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 8 lines · Jacky Chou

When the command bus is sometimes busy, it may cause the command is not arrived to MDIO controller immediately. On software, the driver issues a write command to the command bus does not wait for command complete and it returned back to code immediately. But a read command will wait for the data back, once a read command was back indicates the previous write command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Please have another attempt at writing the commit message.

Quoted 11 lines
Fixes a9770eac511a ("net: mdio: Move MDIO drivers into a new subdirectory")
---
 drivers/net/mdio/mdio-aspeed.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/mdio/mdio-aspeed.c +0 -0
index c2170650415c..373902d33b96 100644

drivers/net/mdio/mdio-aspeed.c static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad, · line 66

Quoted 5 lines
drivers/net/mdio/mdio-aspeed.c +2 -0
@@ -62,6 +62,8 @@ static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad,
 		| FIELD_PREP(ASPEED_MDIO_DATA_MIIRDATA, data);
 
 	iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
+	/* Add dummy read to ensure triggering mdio controller */
+	(void)ioread32(ctx->base + ASPEED_MDIO_CTRL);

Maybe: /* Dummy read to flush previous write to controller */

Andrew

---
pw-bot: cr

author
#2 lore raw

Hi Andrew Lunn,

Thank you for your reply.

Quoted 25 lines
Quoted 8 lines

When the command bus is sometimes busy, it may cause the command is not arrived to MDIO controller immediately. On software, the driver issues a write command to the command bus does not wait for command complete and it returned back to code immediately. But a read command will wait for the data back, once a read command was back indicates the previous write command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Please have another attempt at writing the commit message.

drivers/net/mdio/mdio-aspeed.c static int aspeed_mdio_op(struct mii_bus *bus, u8 st,

Quoted 13 lines
Fixes a9770eac511a ("net: mdio: Move MDIO drivers into a new

subdirectory")

---
 drivers/net/mdio/mdio-aspeed.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/net/mdio/mdio-aspeed.c index c2170650415c..373902d33b96 100644

drivers/net/mdio/mdio-aspeed.c +0 -0
@@ -62,6 +62,8 @@ static int aspeed_mdio_op(struct mii_bus *bus, u8 st,

u8 op, u8 phyad, u8 regad,

Quoted 7 lines

drivers/net/mdio/mdio-aspeed.c static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad, · line 66

Quoted 5 lines
drivers/net/mdio/mdio-aspeed.c +2 -0
 		| FIELD_PREP(ASPEED_MDIO_DATA_MIIRDATA, data);
 
 	iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
+	/* Add dummy read to ensure triggering mdio controller */
+	(void)ioread32(ctx->base + ASPEED_MDIO_CTRL);

Maybe: /* Dummy read to flush previous write to controller */

Agree. I will change the title in next version.

Thanks,
Jacky

maintainer
#3 lore raw
In reply to Jacky Chou
Quoted 6 lines · Jacky Chou

When the command bus is sometimes busy, it may cause the command is not
arrived to MDIO controller immediately. On software, the driver issues a
write command to the command bus does not wait for command complete and

Quoted 8 lines

it returned back to code immediately. But a read command will wait for
the data back, once a read command was back indicates the previous write
command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Why use the explicit dummy read rather than adjust the poll interval or duration? I still don't think that's been adequately explained given the hardware-clear of the fire bit on completion, which is what we're polling for.

Andrew

author
#4 lore raw

Hi Andrew Jeffery,

Thank you for your reply.

Quoted 10 lines
Quoted 9 lines

When the command bus is sometimes busy, it may cause the command is not arrived to MDIO controller immediately. On software, the driver issues a write command to the command bus does not wait for command complete and it returned back to code immediately. But a read command will wait for the data back, once a read command was back indicates the previous write command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Quoted 3 lines

Why use the explicit dummy read rather than adjust the poll interval or duration? I still don't think that's been adequately explained given the hardware-clear of the fire bit on completion, which is what we're polling for.

We cannot know exactly what the timeout value of polling should be set to. Because no one could know when the write command has arrived MDIO controller.

A dummy read can ensure the previous write command had arrived MDIO controller Therefore, we chose to use a dummy read instead of increasing the timeout value.

Thanks,
Jacky

maintainer
#5 lore raw
In reply to Andrew Jeffery
Quoted 16 lines · Andrew Jeffery
Quoted 6 lines · Jacky Chou

When the command bus is sometimes busy, it may cause the command is not
arrived to MDIO controller immediately. On software, the driver issues a
write command to the command bus does not wait for command complete and

Quoted 8 lines

it returned back to code immediately. But a read command will wait for
the data back, once a read command was back indicates the previous write
command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Quoted 4 lines

Why use the explicit dummy read rather than adjust the poll interval or duration? I still don't think that's been adequately explained given the hardware-clear of the fire bit on completion, which is what we're polling for.

I'm guessing here, but if the hardware has not received the write, the read could return an indication that the hardware is idle, and so the poll exits immediately. The returned value of the first read need to be ignored. It is simpler and more reliable to do that with an explicit read, rather than try to play with the poll timing.

AS i said, a guess. We need a good commit message explaining the reality of what is happening here.

Andrew

maintainer
#6 lore raw
Quoted 37 lines · Andrew Lunn
Quoted 21 lines · Andrew Jeffery
Quoted 11 lines · Jacky Chou

When the command bus is sometimes busy, it may cause the command is
not
arrived to MDIO controller immediately. On software, the driver issues a
write command to the command bus does not wait for command complete
and
it returned back to code immediately. But a read command will wait
for

Quoted 8 lines

the data back, once a read command was back indicates the previous
write
command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting
polling the status of mdio controller to avoid polling unexpected timeout.

Quoted 7 lines

Why use the explicit dummy read rather than adjust the poll interval or
duration? I still don't think that's been adequately explained given
the hardware-clear of the fire bit on completion, which is what we're
polling for.

I'm guessing here, but if the hardware has not received the write, the
read could return an indication that the hardware is idle, and so the poll exits immediately. The returned value of the first read need to be ignored. It is simpler and more reliable to do that with an explicit read, rather than try to play with the poll timing.

Quoted 2 lines

AS i said, a guess. We need a good commit message explaining the reality of what is happening here.

I agree, the commit message needs to be more precise about the interactions and effects.

Andrew

#7 lore raw
In reply to Jacky Chou
Quoted 20 lines · Jacky Chou

When the command bus is sometimes busy, it may cause the command is not arrived to MDIO controller immediately. On software, the driver issues a write command to the command bus does not wait for command complete and it returned back to code immediately. But a read command will wait for the data back, once a read command was back indicates the previous write command had arrived to controller.
Add a dummy read to ensure triggering mdio controller before starting polling the status of mdio controller to avoid polling unexpected timeout.

Fixes a9770eac511a ("net: mdio: Move MDIO drivers into a new subdirectory")
---
 drivers/net/mdio/mdio-aspeed.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/mdio/mdio-aspeed.c +0 -0
index c2170650415c..373902d33b96 100644

drivers/net/mdio/mdio-aspeed.c static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad, · line 66

Quoted 5 lines
drivers/net/mdio/mdio-aspeed.c +2 -0
@@ -62,6 +62,8 @@ static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad,
 		| FIELD_PREP(ASPEED_MDIO_DATA_MIIRDATA, data);
 
 	iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
+	/* Add dummy read to ensure triggering mdio controller */
+	(void)ioread32(ctx->base + ASPEED_MDIO_CTRL);

I'd change that comment to:

	/* The above write could be posted, causing the timeout below to
	 * be inaccurate. Ensure the controller starts before we start the
	 * timeout.
	 */
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!