[PATCH net] net: mii: Check speed and duplex only when autoneg is off
From: Anthony Pighin
Date: Fri Nov 06 2026 - 14:56:00 EST
mii_ethtool_get_link_ksettings() reports SPEED_UNKNOWN while the link is
down. ethtool reads the current settings, changes the autoneg and
advertising fields, and writes the result back. When it does this to
enable autoneg on a port without link, mii_ethtool_set_link_ksettings()
rejects the unknown speed with -EINVAL. 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
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().
The autoneg path uses only the advertising mask, so check speed and
duplex only when the link is forced.
Fixes: f6f2e946aa4d ("net: mii: Fix the Speed display when the network cable is not connected")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Anthony Pighin <anthony.pighin@xxxxxxxxx>
---
drivers/net/mii.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/mii.c b/drivers/net/mii.c
index 37bc3131d31a..439444637537 100644
--- a/drivers/net/mii.c
+++ b/drivers/net/mii.c
@@ -333,12 +333,6 @@ int mii_ethtool_set_link_ksettings(struct mii_if_info *mii,
struct net_device *dev = mii->dev;
u32 speed = cmd->base.speed;
- if (speed != SPEED_10 &&
- speed != SPEED_100 &&
- speed != SPEED_1000)
- return -EINVAL;
- if (cmd->base.duplex != DUPLEX_HALF && cmd->base.duplex != DUPLEX_FULL)
- return -EINVAL;
if (cmd->base.port != PORT_MII)
return -EINVAL;
if (cmd->base.phy_address != mii->phy_id)
@@ -346,8 +340,19 @@ int mii_ethtool_set_link_ksettings(struct mii_if_info *mii,
if (cmd->base.autoneg != AUTONEG_DISABLE &&
cmd->base.autoneg != AUTONEG_ENABLE)
return -EINVAL;
- if ((speed == SPEED_1000) && (!mii->supports_gmii))
- return -EINVAL;
+
+ /* Speed is SPEED_UNKNOWN while the link is down; autoneg ignores it */
+ if (cmd->base.autoneg == AUTONEG_DISABLE) {
+ if (speed != SPEED_10 &&
+ speed != SPEED_100 &&
+ speed != SPEED_1000)
+ return -EINVAL;
+ if (cmd->base.duplex != DUPLEX_HALF &&
+ cmd->base.duplex != DUPLEX_FULL)
+ return -EINVAL;
+ if ((speed == SPEED_1000) && (!mii->supports_gmii))
+ return -EINVAL;
+ }
/* ignore supported, maxtxpkt, maxrxpkt */
base-commit: 19a227903e65c7a9c179156485660a4e017575fe
--
2.43.0