mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anthony Pighin <anthony.pighin@nokia.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Xiangqian Zhang <zhangxiangqian@kylinos.cn>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH net v2] net: mii: Accept link settings read back while the link is down
Date: Sat,  7 Nov 2026 16:02:36 -0500	[thread overview]
Message-ID: <20261107210236.721901-1-anthony.pighin@nokia.com> (raw)

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


                 reply	other threads:[~2026-11-07 21:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261107210236.721901-1-anthony.pighin@nokia.com \
    --to=anthony.pighin@nokia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=zhangxiangqian@kylinos.cn \
    /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

all inboxes | Powered by JetHome®