netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
	Andrew Lunn <andrew@lunn.ch>, Jakub Kicinski <kuba@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	hkallweit1@gmail.com, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 6.17-6.6] net: phy: clear link parameters on admin link down
Date: Sat, 25 Oct 2025 11:57:07 -0400	[thread overview]
Message-ID: <20251025160905.3857885-196-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>

From: Oleksij Rempel <o.rempel@pengutronix.de>

[ Upstream commit 60f887b1290b43a4f5a3497982a725687b193fa4 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

YES
- `_phy_state_machine()` now clears the runtime status fields (speed,
  duplex, master/slave, MDI-X, partner advertising) when transitioning a
  previously up PHY into `PHY_HALTED`, so administrative link-down stops
  reporting stale values to ethtool (`drivers/net/phy/phy.c:1551-1561`).
- These members are exactly what `phy_ethtool_ksettings_get()` surfaces
  to user space, so leaving them stale makes `ethtool link`/`ip link`
  misreport the link after an admin down; the new resets ensure the
  user-visible API reflects that the link is unknown/down
  (`drivers/net/phy/phy.c:273-296`).
- The change is careful to leave forced-mode configurations intact
  (`phydev->autoneg == AUTONEG_ENABLE` guard at
  `drivers/net/phy/phy.c:1552-1555`) and avoids touching hardware
  registers, which keeps the risk of behavioural regressions low.
- Master/slave state is only reset when the feature is supported, while
  diagnostics in `PHY_ERROR` still retain the last negotiated
  information thanks to the guarded fall-through
  (`drivers/net/phy/phy.c:1556-1569`).
- The touched fields are long-standing members of `struct phy_device`
  (`include/linux/phy.h:665-713`), so the patch is self-contained,
  architecture-neutral, and aligns with an earlier mainline fix that
  already clears EEE runtime flags on the same state transition.

 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 e046dd858f151..02da4a203ddd4 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.51.0


  parent reply	other threads:[~2025-10-25 16:18 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251025160905.3857885-1-sashal@kernel.org>
2025-10-25 15:53 ` [PATCH AUTOSEL 6.17-6.1] net: phy: fixed_phy: let fixed_phy_unregister free the phy_device Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-5.4] ipv6: np->rxpmtu race annotation Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.6] net: stmmac: Correctly handle Rx checksum offload errors Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.12] PCI/ERR: Update device error_state already after reset Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.1] selftests: net: replace sleeps in fcnal-test with waits Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-5.4] selftests/net: Replace non-standard __WORDSIZE with sizeof(long) * 8 Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-6.12] bnxt_en: Add Hyper-V VF ID Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.4] selftests/net: Ensure assert() triggers in psock_tpacket.c Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.4] net: When removing nexthops, don't call synchronize_net if it is not necessary Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17] netlink: specs: fou: change local-v6/peer-v6 check Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-6.1] smsc911x: add second read of EEPROM mac when possible corruption seen Sasha Levin
2025-10-28 12:53   ` Colin Foster
2025-11-04 13:55     ` Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.4] net: sh_eth: Disable WoL if system can not suspend Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17] bnxt_en: Add fw log trace support for 5731X/5741X chips Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.10] udp_tunnel: use netdev_warn() instead of netdev_WARN() Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] tcp: Update bind bucket state on port release Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17-6.1] net: bridge: Install FDB for bridge MAC on VLAN 0 Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] selftest: net: Fix error message if empty variable Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] net: phy: dp83640: improve phydev and driver removal handling Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] selftests: Disable dad for ipv6 in fcnal-test.sh Sasha Levin
2025-10-25 15:57 ` Sasha Levin [this message]
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17] net: Prevent RPS table overwrite of active flows Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.10] r8169: set EEE speed down ratio to 1 Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] rds: Fix endianness annotation for RDS_MPATH_HASH Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] net: stmmac: est: Drop frames causing HLBS error Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] net: ipv4: allow directed broadcast routes to use dst hint Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] net: dsa: felix: support phy-mode = "10g-qxgmii" Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] net: ipv6: fix field-spanning memcpy warning in AH output Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.12] net: dsa: microchip: Set SPI as bus interface during reset for KSZ8463 Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] net/mlx5e: Prevent entering switchdev mode with inconsistent netns Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.12] microchip: lan865x: add ndo_eth_ioctl handler to enable PHY ioctl support Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] Octeontx2-af: Broadcast XON on all channels Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] hinic3: Queue pair endianness improvements Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.12] tcp: use dst_dev_rcu() in tcp_fastopen_active_disable_ofo_check() Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17] selftests: net: lib.sh: Don't defer failed commands Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17] ptp_ocp: make ptp_ocp driver compatible with PTP_EXTTS_REQUEST2 Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.10] selftests: traceroute: Use require_command() Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.10] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.10] ipv6: Add sanity checks on ipv6_devconf.rpl_seg_enabled Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-6.1] net/mlx5e: Don't query FEC statistics when FEC is disabled Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] bng_en: make bnge_alloc_ring() self-unwind on failure Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.4] page_pool: Clamp pool size to max 16K pages Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] selftests: drv-net: hds: restore hds settings Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] selftests: traceroute: Return correct value on failure Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.4] bridge: Redirect to backup port when port is administratively down Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] net: devmem: expose tcp_recvmsg_locked errors Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] net: phy: clear EEE runtime state in PHY_HALTED/PHY_ERROR Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] selftests: mptcp: join: allow more time to send ADD_ADDR Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.10] net: phy: marvell: Fix 88e1510 downshift counter errata Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] selftests: net: make the dump test less sensitive to mem accounting Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.4] net: nfc: nci: Increase NCI_DATA_TIMEOUT to 3000 ms Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] hinic3: Fix missing napi->dev in netif_queue_set_napi Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.4] selftests: Replace sleep with slowwait Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-6.12] inet_diag: annotate data-races in inet_diag_bc_sk() Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.15] page_pool: always add GFP_NOWARN for ATOMIC allocations Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.4] net/cls_cgroup: Fix task_get_classid() during qdisc run Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.15] ptp: Limit time setting of PTP clocks Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251025160905.3857885-196-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).