Skip to contentSkip to conversation

amd-xgbe: do not double read link status

PATCH Applied Raju Rangoju 3 participants 3 messages Jul 1, 2025 – Jul 2, 2025

Subsystems (3)
lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

PATCH v3 1/1 amd-xgbe: do not double read link status

The link status is latched low so that momentary link drops can be detected. Always double-reading the status defeats this design feature. Only double read if link was already down

This prevents unnecessary duplicate readings of the link status.

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")

---
Changes since v2:
- update the commit message
- avoid using gotos for normal function control flow

Changes since v1:
- skip double-read to detect short link drops
- refine the subject line for clarity

 drivers/net/ethernet/amd/xgbe/xgbe-mdio.c   |  4 ++++
 drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 24 +++++++++++++--------
 2 files changed, 19 insertions(+), 9 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-mdio.c +4 -0
index fb5b7eceb73f..1a37ec45e650 100644
@@ -1304,6 +1304,10 @@ static void xgbe_phy_status(struct xgbe_prv_data *pdata)
 
 	pdata->phy.link = pdata->phy_if.phy_impl.link_status(pdata,
 							     &an_restart);
+	/* bail out if the link status register read fails */
+	if (pdata->phy.link < 0)
+		return;
+
 	if (an_restart) {
 		xgbe_phy_config_aneg(pdata);
 		goto adjust_link;
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +15 -9
index 7a4dfa4e19c7..23c39e92e783 100644
@@ -2746,8 +2746,7 @@ static bool xgbe_phy_valid_speed(struct xgbe_prv_data *pdata, int speed)
 static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 {
 	struct xgbe_phy_data *phy_data = pdata->phy_data;
-	unsigned int reg;
-	int ret;
+	int reg, ret;
 
 	*an_restart = 0;
 
@@ -2781,11 +2780,20 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 			return 0;
 	}
 
-	/* 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 < 0)
+		return reg;
+
+	/* Link status is latched low so that momentary link drops
+	 * can be detected. If link was already down read again
+	 * to get the latest state.
+	 */
+
+	if (!pdata->phy.link && !(reg & MDIO_STAT1_LSTATUS)) {
+		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
+		if (reg < 0)
+			return reg;
+	}
 
 	if (pdata->en_rx_adap) {
 		/* if the link is available and adaptation is done,
@@ -2804,9 +2812,7 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
 			xgbe_phy_set_mode(pdata, phy_data->cur_mode);
 		}
 
-		/* check again for the link and adaptation status */
-		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
-		if ((reg & MDIO_STAT1_LSTATUS) && pdata->rx_adapt_done)
+		if (pdata->rx_adapt_done)
 			return 1;
 	} else if (reg & MDIO_STAT1_LSTATUS)
 		return 1;
Signature · 1 line
2.34.1
reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Raju Rangoju

The link status is latched low so that momentary link drops can be detected. Always double-reading the status defeats this design feature. Only double read if link was already down

This prevents unnecessary duplicate readings of the link status.

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")
Quoted 8 lines

---
Changes since v2:
- update the commit message
- avoid using gotos for normal function control flow

Changes since v1:
- skip double-read to detect short link drops
- refine the subject line for clarity

Thanks for the updates.
I agree this addresses Jakub's review of v2.

#2 lore raw
In reply to Raju Rangoju
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 1 Jul 2025 12:20:16 +0530 you wrote:

The link status is latched low so that momentary link drops can be detected. Always double-reading the status defeats this design feature. Only double read if link was already down

This prevents unnecessary duplicate readings of the link status.

Fixes 4f3b20bfbb75 ("amd-xgbe: add support for rx-adaptation")

[...]

Here is the summary with links:
- [net,v3] amd-xgbe: do not double read link status

    https://git.kernel.org/netdev/net/c/16ceda2ef683

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html