r8152: Use BMSR to detect the link state

Started by Linmao Li on Oct 26, 2026 · 4 messages from 4 authors · Last reply Oct 29, 2026

Subsystems (3)

Maintainers (6)

Show 2 more
COLD22d LANDED

Status: Landed in mainline as 85b4bc79dde7 on 2026-10-29.

open the first message on its own page

Message details and related content
r8152 detects carrier from PLA_PHYSTATUS without reading BMSR, so
BMSR_LSTATUS can remain latched low after link up. Since
commit f6f2e946aa4d ("net: mii: Fix the Speed display when the network
cable is not connected"), the first speed query can then report
SPEED_UNKNOWN, which applications such as NetworkManager may cache
until the next carrier change.

Use BMSR_LSTATUS in set_carrier() so a latched link down can turn
carrier off after the link has recovered. If BMSR reports down but
PLA_PHYSTATUS reports up, reschedule the link work to read the current
state without waiting for another notification.

Tested on an RTL8153B: NetworkManager reported 1000 Mb/s after 3 of 3
rebinds, instead of an unknown speed.

Fixes: f6f2e946aa4d ("net: mii: Fix the Speed display when the network cable is not connected")
Cc: <redacted>
Suggested-by: Hayes Wang <redacted>
Signed-off-by: Linmao Li <redacted>
---
v3:
- Use Hayes's approach: detect carrier from a single BMSR read, so a
  latched link down can turn carrier off even after the link has
  recovered (Andrew), and reschedule the link work while
  PLA_PHYSTATUS still reports up, so carrier up does not depend on
  another notification (Hayes).
- Drop the runtime resume change.
- Tested on a net/main based kernel instead of a 6.6-based one. With
  intr_callback() filtered to pass only link status changes, and the
  first link check delayed until after the down and up notifications
  from ethtool -r, 5 of 5 runs showed NO-CARRIER then LOWER_UP about
  8 ms apart. With the PHY powered down for 10 s, the carrier stayed
  off and the speed was unknown.

v2: https://lore.kernel.org/netdev/20261005105249.1281648-1-lilinmao@kylinos.cn/
v1: https://lore.kernel.org/netdev/20260930113842.2640928-1-lilinmao@kylinos.cn/

 drivers/net/usb/r8152.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index af3d7dcb2f14..ae861eb6d9a9 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -6958,11 +6958,8 @@ static void set_carrier(struct r8152 *tp)
 {
 	struct net_device *netdev = tp->netdev;
 	struct napi_struct *napi = &tp->napi;
-	u16 speed;
-
-	speed = rtl8152_get_speed(tp);
 
-	if (speed & LINK_STATUS) {
+	if (r8152_mdio_read(tp, MII_BMSR) & BMSR_LSTATUS) {
 		if (!netif_carrier_ok(netdev)) {
 			tp->rtl_ops.enable(tp);
 			netif_stop_queue(netdev);
@@ -6988,6 +6985,11 @@ static void set_carrier(struct r8152 *tp)
 			tasklet_enable(&tp->tx_tl);
 			netif_info(tp, link, netdev, "carrier off\n");
 		}
+
+		if (rtl8152_get_speed(tp) & LINK_STATUS) {
+			set_bit(RTL8152_LINK_CHG, &tp->flags);
+			schedule_delayed_work(&tp->schedule, 0);
+		}
 	}
 }
 
-- 
2.25.1
Message details and related content
r8152 detects carrier from PLA_PHYSTATUS without reading BMSR, so
BMSR_LSTATUS can remain latched low after link up. Since
commit f6f2e946aa4d ("net: mii: Fix the Speed display when the network
cable is not connected"), the first speed query can then report
SPEED_UNKNOWN, which applications such as NetworkManager may cache
until the next carrier change.

Use BMSR_LSTATUS in set_carrier() so a latched link down can turn
carrier off after the link has recovered. If BMSR reports down but
PLA_PHYSTATUS reports up, reschedule the link work to read the current
state without waiting for another notification.

Tested on an RTL8153B: NetworkManager reported 1000 Mb/s after 3 of 3
rebinds, instead of an unknown speed.

Fixes: f6f2e946aa4d ("net: mii: Fix the Speed display when the network cable is not connected")
Cc: <redacted>
Suggested-by: Hayes Wang <redacted>
Signed-off-by: Linmao Li <redacted>
Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261026012345.1902285-1-lilinmao@kylinos.cn?part=1
Message details and related content
Linmao Li [off-list ref]
Sent: Monday, October 26, 2026 9:24 AM
To: andrew+netdev@lunn.ch; davem@davemloft.net; edumazet@kernel.org;
kuba@kernel.org; pabeni@redhat.com
Cc: Hayes Wang <redacted>; nic_swsd
[off-list ref]; Chih Kai Hsu [off-list ref];
mail@birger-koblitz.de; zhangxiangqian@kylinos.cn; linux-usb@vger.kernel.org;
netdev@vger.kernel.org; linux-kernel@vger.kernel.org; stable@vger.kernel.org;
Linmao Li [off-list ref]
Subject: [PATCH net v3] r8152: Use BMSR to detect the link state


External mail : This email originated from outside the organization. Do not
reply, click links, or open attachments unless you recognize the sender and
know the content is safe.



r8152 detects carrier from PLA_PHYSTATUS without reading BMSR, so
BMSR_LSTATUS can remain latched low after link up. Since
commit f6f2e946aa4d ("net: mii: Fix the Speed display when the network
cable is not connected"), the first speed query can then report
SPEED_UNKNOWN, which applications such as NetworkManager may cache
until the next carrier change.

Use BMSR_LSTATUS in set_carrier() so a latched link down can turn
carrier off after the link has recovered. If BMSR reports down but
PLA_PHYSTATUS reports up, reschedule the link work to read the current
state without waiting for another notification.

Tested on an RTL8153B: NetworkManager reported 1000 Mb/s after 3 of 3
rebinds, instead of an unknown speed.

Fixes: f6f2e946aa4d ("net: mii: Fix the Speed display when the network cable is
not connected")
Cc: <redacted>
Suggested-by: Hayes Wang <redacted>
Signed-off-by: Linmao Li <redacted>
Reviewed-by: Hayes Wang <redacted>

Best Regards,
Hayes
Message details and related content
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni [off-list ref]:

On Mon, 26 Oct 2026 09:23:45 +0800 you wrote:
r8152 detects carrier from PLA_PHYSTATUS without reading BMSR, so
BMSR_LSTATUS can remain latched low after link up. Since
commit f6f2e946aa4d ("net: mii: Fix the Speed display when the network
cable is not connected"), the first speed query can then report
SPEED_UNKNOWN, which applications such as NetworkManager may cache
until the next carrier change.

[...]
Here is the summary with links:
  - [net,v3] r8152: Use BMSR to detect the link state
    https://git.kernel.org/netdev/net/c/85b4bc79dde7

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help