Skip to contentSkip to conversation

amd-xgbe: read link status twice to avoid inconsistencies

PATCH In review Raju Rangoju 2 participants 3 messages May 14, 2025 – Jun 25, 2025

Subsystems (3)
lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

PATCH 1/1 amd-xgbe: read link status twice to avoid inconsistencies

The link status is latched low, so read the register twice to get the current status and avoid link inconsistencies.

As per IEEE 802.3 "Table 22-8 - Status register bit definitions"
1.2 Link Status 1 = link is up 0 = link is down RO/LL

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")
---
 drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +4 -0
index 268399dfcf22..d233e3faa1a9 100644
@@ -2914,6 +2914,10 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 		}
 
 		/* check again for the link and adaptation status */
+		/* Link status is latched low, so read once to clear
+		 * and then read again to get current state
+		 */
+		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;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 17 lines · Raju Rangoju

The link status is latched low, so read the register twice to get the current status and avoid link inconsistencies.

As per IEEE 802.3 "Table 22-8 - Status register bit definitions"
1.2 Link Status 1 = link is up 0 = link is down RO/LL

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")
---
 drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +0 -0
index 268399dfcf22..d233e3faa1a9 100644

drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart) · line 2920

Quoted 7 lines
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +4 -0
@@ -2914,6 +2914,10 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 		}
 
 		/* check again for the link and adaptation status */
+		/* Link status is latched low, so read once to clear
+		 * and then read again to get current state
+		 */
+		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);

Since this is not a phylib user, i don't care too much, but:

https://elixir.bootlin.com/linux/v6.14.6/source/drivers/net/phy/phy_device.c#L2514

/* The link state is latched low so that momentary link
* drops can be detected. Do not double-read the status
* in polling mode to detect such short link drops except
* the link was already down.
*/

So you don't care about short link drops? You don't want to tell user space the link went away and came back? It never happened.

Andrew

author maintainer
#2 lore raw
Quoted 31 lines · Andrew Lunn
Quoted 17 lines · Raju Rangoju

The link status is latched low, so read the register twice to get the current status and avoid link inconsistencies.

As per IEEE 802.3 "Table 22-8 - Status register bit definitions"
1.2 Link Status 1 = link is up 0 = link is down RO/LL

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")
---
  drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +0 -0
index 268399dfcf22..d233e3faa1a9 100644

drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart) · line 2920

Quoted 7 lines
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +4 -0
@@ -2914,6 +2914,10 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
  		}
 
  		/* check again for the link and adaptation status */
+		/* Link status is latched low, so read once to clear
+		 * and then read again to get current state
+		 */
+		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);

Since this is not a phylib user, i don't care too much, but:

https://elixir.bootlin.com/linux/v6.14.6/source/drivers/net/phy/phy_device.c#L2514

Quoted 8 lines

/* The link state is latched low so that momentary link
* drops can be detected. Do not double-read the status
* in polling mode to detect such short link drops except
* the link was already down.
*/

So you don't care about short link drops? You don't want to tell user space the link went away and came back? It never happened.

Thanks Andrew for point this out. I'll re-spin v2 addressing these.

Quoted 2 lines

Andrew