Re: [PATCH net v2] r8152: Use BMSR to detect the link state

From: Linmao Li

Date: Tue Oct 20 2026 - 08:41:22 EST



在 2026/10/19 20:12, Hayes Wang 写道:
Linmao Li <lilinmao@xxxxxxxxxx>
Sent: Friday, October 16, 2026 3:16 PM
[...]
Option a) addresses only the speed regression. It keeps the existing
PLA_PHYSTATUS carrier detection and does not improve reporting of short link
drops that recover before the link work runs.

I plan to post a) as v3 for net next week, keeping that scope explicit. Please let
me know if you see a problem with this approach.
I tested the following patch, and it works for me. It might be useful as a reference.

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index f61686433031..398d35f6fb7b 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -6979,11 +6979,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);
@@ -7009,6 +7006,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);
+ }
}
}


Best Regards,
Hayes
Hi Hayes,

Thanks. I tested your patch on an RTL8153B with a kernel based on
net/main (513444cc62e2):

- With NetworkManager running, it reported 1000 Mb/s after 3 of 3
  rebinds, where it reported an unknown speed without the patch.
- On link up, the first BMSR read returned the latched link down,
  PLA_PHYSTATUS showed link, so the work was rescheduled and the next
  read brought the carrier up. After ethtool -r there was no repeated
  rescheduling while autonegotiation was in progress.
- I also filtered intr_callback() to pass only link status changes.
  I delayed the first link check until after both down and up
  notifications from ethtool -r had arrived; the recheck ran without
  an artificial delay. In 5 of 5 runs, carrier went off and back on
  within about 8 ms, and ip monitor saw NO-CARRIER then LOWER_UP.

I will post v3 based on your patch with Suggested-by: Hayes Wang. If
you would rather be credited with Co-developed-by and your
Signed-off-by, please let me know.

Thanks,
Linmao