* [PATCH net v2] net: mii: Accept link settings read back while the link is down
@ 2026-11-07 21:02 Anthony Pighin
0 siblings, 0 replies; only message in thread
From: Anthony Pighin @ 2026-11-07 21:02 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Xiangqian Zhang, linux-kernel, stable
Since commit f6f2e946aa4d ("net: mii: Fix the Speed display when the
network cable is not connected"), mii_ethtool_get_link_ksettings()
reports SPEED_UNKNOWN whenever the link is down. ethtool changes link
settings by reading the current ones, updating only the requested
fields, and writing the result back. mii_ethtool_set_link_ksettings()
rejects the unknown speed with -EINVAL, in both autoneg and forced mode.
For example, on an ax88179_178a USB adapter while the link is down:
# ethtool -s eth0 autoneg on advertise 0x2f
Cannot set new settings: Invalid argument
not setting autoneg
# ethtool -s eth0 speed 1000 duplex full autoneg off
# ethtool -s eth0 duplex half
Cannot set new settings: Invalid argument
not setting duplex
pch_gbe_set_link_ksettings() already works around the same failure by
replacing an unknown speed with SPEED_1000 before it calls
mii_ethtool_set_link_ksettings().
In forced mode, BMCR holds the configured speed whether or not the link
is up, so report SPEED_UNKNOWN only when autoneg is enabled, as
genphy_read_status() does. In autoneg mode the speed is not used, so
accept SPEED_UNKNOWN there. All other speed and duplex checks are
unchanged.
Fixes: f6f2e946aa4d ("net: mii: Fix the Speed display when the network cable is not connected")
Cc: stable@vger.kernel.org
Signed-off-by: Anthony Pighin <anthony.pighin@nokia.com>
---
Changes in v2:
- Report SPEED_UNKNOWN only with autoneg enabled, so writing back the
settings also works in forced mode.
- With autoneg enabled, accept only SPEED_UNKNOWN and keep the other
speed and duplex checks. v1 accepted any speed and duplex there.
- New subject, since speed is still checked with autoneg enabled.
- Tested on an ax88179_178a adapter running v6.18.54, where
drivers/net/mii.c is identical to net. Both ethtool examples above now
succeed. A direct ETHTOOL_SLINKSETTINGS with autoneg enabled accepts
SPEED_UNKNOWN and still rejects an invalid speed.
v1: https://lore.kernel.org/netdev/20261106195544.4146568-1-anthony.pighin@nokia.com/
drivers/net/mii.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/mii.c b/drivers/net/mii.c
index 37bc3131d31a..225488f2438b 100644
--- a/drivers/net/mii.c
+++ b/drivers/net/mii.c
@@ -199,6 +199,9 @@ void mii_ethtool_get_link_ksettings(struct mii_if_info *mii,
cmd->base.speed = SPEED_10;
cmd->base.duplex = !!(nego & ADVERTISED_10baseT_Full);
}
+
+ if (!(bmsr & BMSR_LSTATUS))
+ cmd->base.speed = SPEED_UNKNOWN;
} else {
cmd->base.autoneg = AUTONEG_DISABLE;
@@ -213,9 +216,6 @@ void mii_ethtool_get_link_ksettings(struct mii_if_info *mii,
lp_advertising = 0;
}
- if (!(bmsr & BMSR_LSTATUS))
- cmd->base.speed = SPEED_UNKNOWN;
-
mii->full_duplex = cmd->base.duplex;
ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
@@ -333,9 +333,11 @@ int mii_ethtool_set_link_ksettings(struct mii_if_info *mii,
struct net_device *dev = mii->dev;
u32 speed = cmd->base.speed;
+ /* Autoneg ignores speed, which is SPEED_UNKNOWN while the link is down */
if (speed != SPEED_10 &&
speed != SPEED_100 &&
- speed != SPEED_1000)
+ speed != SPEED_1000 &&
+ !(cmd->base.autoneg == AUTONEG_ENABLE && speed == SPEED_UNKNOWN))
return -EINVAL;
if (cmd->base.duplex != DUPLEX_HALF && cmd->base.duplex != DUPLEX_FULL)
return -EINVAL;
base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-07 21:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 21:02 [PATCH net v2] net: mii: Accept link settings read back while the link is down Anthony Pighin
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®