Skip to contentSkip to conversation

amd-xgbe: read STAT1 register twice to get correct value

PATCH In review Raju Rangoju 4 participants 8 messages Sep 14, 2023 – Oct 12, 2023

Subsystems (3)
lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

PATCH 1/1 amd-xgbe: read STAT1 register twice to get correct value

Link status is latched low, so read once to clear
and then read again to get current state.

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")
---
 drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +1 -0
index 6a716337f48b..c83085285e8c 100644
@@ -2930,6 +2930,7 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 
 		/* check again for the link and adaptation status */
 		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
+		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
 		if ((reg & MDIO_STAT1_LSTATUS) && pdata->rx_adapt_done)
 			return 1;
 	} else if (reg & MDIO_STAT1_LSTATUS)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Raju Rangoju

Link status is latched low, so read once to clear
and then read again to get current state.

I don't know about your PHY implementation, but within phylib and Linux PHY drivers, this is considered wrong. You loose out on being notified of the link going down and then back up again. Or up and then down again.

But since this is not a Linux PHY driver, you are free to do whatever you want...

Also, i believe it is latched, not latched low. So i think your commit message is wrong. You should probably check with IEEE 802.3 clause 22.

Andrew

#2 lore raw
Quoted 9 lines · Andrew Lunn
Quoted 2 lines · Raju Rangoju

Link status is latched low, so read once to clear
and then read again to get current state.

I don't know about your PHY implementation, but within phylib and Linux PHY drivers, this is considered wrong. You loose out on being notified of the link going down and then back up again. Or up and then down again.

Quoted 5 lines

But since this is not a Linux PHY driver, you are free to do whatever you want...

Also, i believe it is latched, not latched low. So i think your commit message is wrong. You should probably check with IEEE 802.3 clause 22.

Granted I have an old version of IEEE 802.3, but "Table 22-8 - Status register bit definitions" has:

1.2 Link Status 1 = link is up 0 = link is down RO/LL

So latched low.

Thanks,
Tom

Quoted 3 lines

Andrew

author maintainer
#3 lore raw
Quoted 15 lines · Tom Lendacky
Quoted 12 lines · Andrew Lunn
Quoted 2 lines · Raju Rangoju

Link status is latched low, so read once to clear
and then read again to get current state.

I don't know about your PHY implementation, but within phylib and Linux PHY drivers, this is considered wrong. You loose out on being notified of the link going down and then back up again. Or up and then down again.

But since this is not a Linux PHY driver, you are free to do whatever you want...

Quoted 8 lines
Quoted 2 lines

Also, i believe it is latched, not latched low. So i think your commit message is wrong. You should probably check with IEEE 802.3 clause 22.

Granted I have an old version of IEEE 802.3, but "Table 22-8 - Status register bit definitions" has:

1.2    Link Status    1 = link is up    0 = link is down    RO/LL

So latched low.

Thanks, Tom.

The following thread (found online) has the detailed info on the IEEE 802.3 Standard that define the Link Status bit:

https://microchip.my.site.com/s/article/How-to-correctly-read-the-Ethernet-PHY-Link-Status-bit

Thanks,
Raju

Quoted 7 lines

Thanks,
Tom

Quoted 3 lines

     Andrew

#4 lore raw
Quoted 6 lines

Thanks, Tom.

The following thread (found online) has the detailed info on the IEEE 802.3 Standard that define the Link Status bit:

https://microchip.my.site.com/s/article/How-to-correctly-read-the-Ethernet-PHY-Link-Status-bit

The relevant section for me is:

Having a latched-low bit helps to ensure a link drop (no matter how short the duration before re-establishing link-up again) gets recorded and can be read from PHY register by the upper network layer (e.g., MAC processor).

By reading it twice, you are loosing the information the link went down. This could mean you don't restart dhcp to get a new IP address for a new subnet, kick of IPv6 getting the new network prefix so it can create its IPv6 address etc.

When Linux is driving the PHYs using phylib, drivers are written such that they report the latched link down. This gets report to the stack, and so up to user space etc. phylib will then ask the driver a second time to get the link status, and it might then return that the link is now up. That then gets reported to the stack and user space.

As i said, you are not using phylib, this is not a linux PHY driver, so i don't actually care what you do here. I just want to point out why what you are doing could be wrong.

Andrew

author maintainer
#5 lore raw

Hi Andrew,

Thanks for the explanation. The current approach is holding good for amd-xgbe.

Hi Jakub,

Can you please apply this patch.

Thanks,
Raju

Quoted 30 lines · Andrew Lunn
Quoted 6 lines

Thanks, Tom.

The following thread (found online) has the detailed info on the IEEE 802.3 Standard that define the Link Status bit:

https://microchip.my.site.com/s/article/How-to-correctly-read-the-Ethernet-PHY-Link-Status-bit

The relevant section for me is:

Having a latched-low bit helps to ensure a link drop (no matter how short the duration before re-establishing link-up again) gets recorded and can be read from PHY register by the upper network layer (e.g., MAC processor).

By reading it twice, you are loosing the information the link went down. This could mean you don't restart dhcp to get a new IP address for a new subnet, kick of IPv6 getting the new network prefix so it can create its IPv6 address etc.

When Linux is driving the PHYs using phylib, drivers are written such that they report the latched link down. This gets report to the stack, and so up to user space etc. phylib will then ask the driver a second time to get the link status, and it might then return that the link is now up. That then gets reported to the stack and user space.

As i said, you are not using phylib, this is not a linux PHY driver, so i don't actually care what you do here. I just want to point out why what you are doing could be wrong.

Andrew

author maintainer
#6 lore raw
In reply to Raju Rangoju

Hi Jakub,

Can you please apply this patch? Let me know if it needs to be resent.

Thanks,
Raju

Quoted 22 lines · Raju Rangoju

Link status is latched low, so read once to clear
and then read again to get current state.

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")
---
  drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +1 -0
index 6a716337f48b..c83085285e8c 100644
@@ -2930,6 +2930,7 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 
  		/* check again for the link and adaptation status */
  		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
+		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
  		if ((reg & MDIO_STAT1_LSTATUS) && pdata->rx_adapt_done)
  			return 1;
  	} else if (reg & MDIO_STAT1_LSTATUS)
maintainer
#7 lore raw
Quoted 3 lines · On Thu, 12 Oct 2023 22:59:57 +0530 Raju Rangoju wrote:

Hi Jakub,

Can you please apply this patch? Let me know if it needs to be resent.

Yes, please resend. And please put in the commit message an explanation more technically detailed than "The current approach is holding good for amd-xgbe." :(

Reminder: please don't top post on the ML.