* [PATCH net-next v3 1/1] net: phy: clear link parameters on admin link down
@ 2025-09-17 9:47 Oleksij Rempel
2025-09-17 12:48 ` Andrew Lunn
2025-09-18 22:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Oleksij Rempel @ 2025-09-17 9:47 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Oleksij Rempel, kernel, linux-kernel, netdev, Russell King
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>
---
changes v3:
- rework commit message
- move cleaning sequence to PHY_HALTED case in _phy_state_machine()
changes v2:
- rebase and resned against net-next
drivers/net/phy/phy.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e046dd858f15..02da4a203ddd 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -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;
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v3 1/1] net: phy: clear link parameters on admin link down
2025-09-17 9:47 [PATCH net-next v3 1/1] net: phy: clear link parameters on admin link down Oleksij Rempel
@ 2025-09-17 12:48 ` Andrew Lunn
2025-09-18 22:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2025-09-17 12:48 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, kernel, linux-kernel, netdev, Russell King
On Wed, Sep 17, 2025 at 11:47:51AM +0200, Oleksij Rempel wrote:
> 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>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v3 1/1] net: phy: clear link parameters on admin link down
2025-09-17 9:47 [PATCH net-next v3 1/1] net: phy: clear link parameters on admin link down Oleksij Rempel
2025-09-17 12:48 ` Andrew Lunn
@ 2025-09-18 22:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-18 22:50 UTC (permalink / raw)
To: Oleksij Rempel
Cc: andrew, hkallweit1, davem, edumazet, kuba, pabeni, kernel,
linux-kernel, netdev, linux
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 17 Sep 2025 11:47:51 +0200 you wrote:
> 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:
>
> [...]
Here is the summary with links:
- [net-next,v3,1/1] net: phy: clear link parameters on admin link down
https://git.kernel.org/netdev/net-next/c/60f887b1290b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-18 22:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-17 9:47 [PATCH net-next v3 1/1] net: phy: clear link parameters on admin link down Oleksij Rempel
2025-09-17 12:48 ` Andrew Lunn
2025-09-18 22:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®