]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: phy: clear link parameters on admin link down
authorOleksij Rempel <o.rempel@pengutronix.de>
Wed, 17 Sep 2025 09:47:51 +0000 (11:47 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 18 Sep 2025 22:43:26 +0000 (15:43 -0700)
When a PHY is halted (e.g. `ip link set dev lan2 down`), several
fields in struct phy_device may still reflect the last active
connection. This leads to ethtool showing stale values even though
the link is down.

Reset selected fields in _phy_state_machine() when transitioning
to PHY_HALTED and the link was previously up:

- speed/duplex -> UNKNOWN, but only in autoneg mode (in forced mode
  these fields carry configuration, not status)
- master_slave_state -> UNKNOWN if previously supported
- mdix -> INVALID (state only, same meaning as "unknown")
- lp_advertising -> always cleared

The cleanup is skipped if the PHY is in PHY_ERROR state, so the
last values remain available for diagnostics.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20250917094751.2101285-1-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phy.c

index e046dd858f151aec132e9980049431e2d1b832b3..02da4a203ddd4c2aedf847345c819db6196bf2ad 100644 (file)
@@ -1548,6 +1548,19 @@ static enum phy_state_work _phy_state_machine(struct phy_device *phydev)
                }
                break;
        case PHY_HALTED:
+               if (phydev->link) {
+                       if (phydev->autoneg == AUTONEG_ENABLE) {
+                               phydev->speed = SPEED_UNKNOWN;
+                               phydev->duplex = DUPLEX_UNKNOWN;
+                       }
+                       if (phydev->master_slave_state !=
+                                               MASTER_SLAVE_STATE_UNSUPPORTED)
+                               phydev->master_slave_state =
+                                               MASTER_SLAVE_STATE_UNKNOWN;
+                       phydev->mdix = ETH_TP_MDI_INVALID;
+                       linkmode_zero(phydev->lp_advertising);
+               }
+               fallthrough;
        case PHY_ERROR:
                if (phydev->link) {
                        phydev->link = 0;