🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
7 messages
7 total messages Started by Linmao Li Fri, 09 Oct 2026 07:16
Re: [PATCH net v2] r8152: Use BMSR to detect the link state
#1091
Author: Linmao Li
Date: Fri, 09 Oct 2026 07:16
67 lines
8867 bytes
在 2026/10/7 0:10, Andrew Lunn 写道:
> On Tue, Oct 06, 2026 at 08:28:21AM +0000, Hayes Wang wrote:
>> Linmao Li <lilinmao@kylinos.cn>
>>> Sent: Monday, October 5, 2026 6:53 PM
>> [...]
>>> r8152 detects carrier from PLA_PHYSTATUS without reading BMSR, so
>>> BMSR_LSTATUS can still be latched low when the carrier comes up.
>>> Since commit f6f2e946aa4d ("net: mii: Fix the Speed display when the network
>>> cable is not connected"), the first speed query after link up can then report
>>> SPEED_UNKNOWN, leaving NetworkManager at 0 Mb/s until the next carrier
>>> change.
>>>
>>> Use BMSR_LSTATUS in set_carrier() and rtl8152_runtime_resume(), so the
>>> driver consumes the latched link down itself. If the first read still reports link
>>> down, the next link-up notification triggers another read and brings the carrier
>>> up.
>>>
>>> Tested on an RTL8153B with a 6.6-based kernel. In 5 rebinds and 6 cable
>>> replugs, the first read returned LSTATUS=0, a second link-up notification came
>>> about 32 ms later, the second read returned
>>> LSTATUS=1 and the carrier went up; NetworkManager reported 1000 Mb/s.
>>> Runtime suspend/resume with the link up did not change the carrier.
>> I think this patch may introduce a new issue.
>>
>> Our newer ICs do not generate periodic link-status notifications. They generate a
>> notification only when the link status changes. Therefore, with your patch, BMSR
>> will not be read a second time until the next link-status change.
> But the link status in BMSR does change.
>
> You read it once and get the latched value. That clears the latch, so
> the link status changes to the current version.
>
> Now, 802.3 C22 has no support for interrupts, that is a vendor
> extension. But if you are not generating an interrupt when BMSR
> changes, i would say that is broken.
>
> 	 Andrew
Hi Hayes, Andrew,

Thanks. Since the newer ICs notify only when the link status changes,
the driver cannot rely on another link up notification after the link
has settled, so v2 can leave the carrier off when the first read
returns the latched link down.

Before sending v3, which approach would you prefer? Both fixed the
problem in my tests on an RTL8153B with v7.3-rc6:

a) Keep carrier detection on PLA_PHYSTATUS and read BMSR once before
    carrier on, only to clear the latch. This is the option I asked
    about on v1.

b) Detect carrier from BMSR and read it again when the first read
    returns link down, as genphy_update_link() does in interrupt mode.

Neither depends on another notification. Neither reports a short link
drop that recovers before the link work runs: with a) a later speed
query still sees the latched link down, with b) the latch is cleared.

Hayes, for b): is BMSR_LSTATUS reliable as the carrier source on all
chips supported by r8152?

Thanks,
Linmao

pw-bot: cr
Re: [PATCH net v2] r8152: Use BMSR to detect the link state
#1219
Author: Andrew Lunn
Date: Fri, 09 Oct 2026 12:22
38 lines
7862 bytes
> Hi Hayes, Andrew,
> 
> Thanks. Since the newer ICs notify only when the link status changes,
> the driver cannot rely on another link up notification after the link
> has settled, so v2 can leave the carrier off when the first read
> returns the latched link down.
> 
> Before sending v3, which approach would you prefer? Both fixed the
> problem in my tests on an RTL8153B with v7.3-rc6:
> 
> a) Keep carrier detection on PLA_PHYSTATUS and read BMSR once before
>    carrier on, only to clear the latch. This is the option I asked
>    about on v1.
> 
> b) Detect carrier from BMSR and read it again when the first read
>    returns link down, as genphy_update_link() does in interrupt mode.
> 
> Neither depends on another notification. Neither reports a short link
> drop that recovers before the link work runs: with a) a later speed
> query still sees the latched link down, with b) the latch is cleared.
> 
> Hayes, for b): is BMSR_LSTATUS reliable as the carrier source on all
> chips supported by r8152?

Ideally we want a list of devices which correctly do notification on
every change of link state, and which are broken.

For those that work, read the BMSR once and report the down, and then
later on the second event, report the up.

For those devices which are broken, double read the BMSR.  The danger
is, somebody who quickly unplugs and replugs the cable is not going to
get the down notification. The dhcp client will not restart, so the
old IP address will be used, for the next hour to day, and the network
is broken.

    Andrew
Re: [PATCH net v2] r8152: Use BMSR to detect the link state
#2595
Author: Linmao Li
Date: Tue, 13 Oct 2026 02:36
60 lines
8804 bytes
在 2026/10/9 20:22, Andrew Lunn 写道:
>> Hi Hayes, Andrew,
>>
>> Thanks. Since the newer ICs notify only when the link status changes,
>> the driver cannot rely on another link up notification after the link
>> has settled, so v2 can leave the carrier off when the first read
>> returns the latched link down.
>>
>> Before sending v3, which approach would you prefer? Both fixed the
>> problem in my tests on an RTL8153B with v7.3-rc6:
>>
>> a) Keep carrier detection on PLA_PHYSTATUS and read BMSR once before
>>     carrier on, only to clear the latch. This is the option I asked
>>     about on v1.
>>
>> b) Detect carrier from BMSR and read it again when the first read
>>     returns link down, as genphy_update_link() does in interrupt mode.
>>
>> Neither depends on another notification. Neither reports a short link
>> drop that recovers before the link work runs: with a) a later speed
>> query still sees the latched link down, with b) the latch is cleared.
>>
>> Hayes, for b): is BMSR_LSTATUS reliable as the carrier source on all
>> chips supported by r8152?
> Ideally we want a list of devices which correctly do notification on
> every change of link state, and which are broken.
>
> For those that work, read the BMSR once and report the down, and then
> later on the second event, report the up.
>
> For those devices which are broken, double read the BMSR.  The danger
> is, somebody who quickly unplugs and replugs the cable is not going to
> get the down notification. The dhcp client will not restart, so the
> old IP address will be used, for the next hour to day, and the network
> is broken.
>
>      Andrew
Hi Andrew,

Thanks. In tests on my RTL8153B, down and up notifications were about
3.1 s apart after a quick cable replug, and about 3.4 s apart after
ethtool -r. A double read should still report down if the link work
runs during that interval, but I have not verified this directly.
These results do not cover shorter link interruptions or other chips.

Since this fixes a regression for net and stable, would you accept a)
there, keeping PLA_PHYSTATUS and reading BMSR once before an off-to-on
carrier transition, and moving carrier detection to BMSR with per-chip
handling as a follow-up for net-next, once the chip behaviour is known?

Hayes, to build that list: which ICs notify only on link changes? And
on any of them, does reading BMSR, which clears the latched link down,
trigger another notification? The single read depends on that. Birger
tested v2 on an RTL8157 and an RTL8153A without problems, so it would
also help to know how the RTL8157 notifies.

Thanks,
Linmao
RE: [PATCH net v2] r8152: Use BMSR to detect the link state
#2667
Author: Hayes Wang
Date: Tue, 13 Oct 2026 08:04
73 lines
10015 bytes
Andrew Lunn <andrew@lunn.ch>
> Sent: Friday, October 9, 2026 8:22 PM
> To: Linmao Li <lilinmao@kylinos.cn>
> Cc: Hayes Wang <hayeswang@realtek.com>; 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>; Chih Kai Hsu <hsu.chih.kai@realtek.com>;
> nic_swsd <nic_swsd@realtek.com>; Birger Koblitz <mail@birger-koblitz.de>;
> Xiangqian Zhang <zhangxiangqian@kylinos.cn>; linux-usb@vger.kernel.org;
> netdev@vger.kernel.org; linux-kernel@vger.kernel.org; stable@vger.kernel.org
> Subject: Re: [PATCH net v2] 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.
> 
> 
> 
> > Hi Hayes, Andrew,
> >
> > Thanks. Since the newer ICs notify only when the link status changes,
> > the driver cannot rely on another link up notification after the link
> > has settled, so v2 can leave the carrier off when the first read
> > returns the latched link down.
> >
> > Before sending v3, which approach would you prefer? Both fixed the
> > problem in my tests on an RTL8153B with v7.3-rc6:
> >
> > a) Keep carrier detection on PLA_PHYSTATUS and read BMSR once before
> >    carrier on, only to clear the latch. This is the option I asked
> >    about on v1.
> >
> > b) Detect carrier from BMSR and read it again when the first read
> >    returns link down, as genphy_update_link() does in interrupt mode.
> >
> > Neither depends on another notification. Neither reports a short link
> > drop that recovers before the link work runs: with a) a later speed
> > query still sees the latched link down, with b) the latch is cleared.
> >
> > Hayes, for b): is BMSR_LSTATUS reliable as the carrier source on all
> > chips supported by r8152?
> 
> Ideally we want a list of devices which correctly do notification on every
> change of link state, and which are broken.

I think all of our ICs have the same situation.

> For those that work, read the BMSR once and report the down, and then later
> on the second event, report the up.
> 
> For those devices which are broken, double read the BMSR.  The danger is,
> somebody who quickly unplugs and replugs the cable is not going to get the
> down notification. The dhcp client will not restart, so the old IP address will be
> used, for the next hour to day, and the network is broken.

Could this actually happen? 
I think it would take several seconds for the link to go down and then come back up.
Wouldn't this issue occur only if the link transitions from up to down and back up before the driver processes the link-down event?


Best Regards,
Hayes
Re: [PATCH net v2] r8152: Use BMSR to detect the link state
#3288
Author: Andrew Lunn
Date: Wed, 14 Oct 2026 16:10
21 lines
7317 bytes
> > For those devices which are broken, double read the BMSR.  The danger is,
> > somebody who quickly unplugs and replugs the cable is not going to get the
> > down notification. The dhcp client will not restart, so the old IP address will be
> > used, for the next hour to day, and the network is broken.
> 
> Could this actually happen? 
> I think it would take several seconds for the link to go down and then come back up.
> Wouldn't this issue occur only if the link transitions from up to down and back up before the driver processes the link-down event?

802.3 thinks this can happen, otherwise why make it latch?

If i'm just going from port 7 to port 8 of my switch, it might happen.

Or i reconfigure my managed switch to change the port from one subnet
to another subnet. The RJ45 is not moved, it is just a configuration
change. The switch should do a down/up on its side to indicate
something has changed, and that needs to be reported to userspace so
dhcpcd gets a new IP address.

       Andrew
Re: [PATCH net v2] r8152: Use BMSR to detect the link state
#3872
Author: Linmao Li
Date: Fri, 16 Oct 2026 07:15
34 lines
7705 bytes
在 2026/10/15 0:10, Andrew Lunn 写道:
>>> For those devices which are broken, double read the BMSR.  The danger is,
>>> somebody who quickly unplugs and replugs the cable is not going to get the
>>> down notification. The dhcp client will not restart, so the old IP address will be
>>> used, for the next hour to day, and the network is broken.
>> Could this actually happen?
>> I think it would take several seconds for the link to go down and then come back up.
>> Wouldn't this issue occur only if the link transitions from up to down and back up before the driver processes the link-down event?
> 802.3 thinks this can happen, otherwise why make it latch?
>
> If i'm just going from port 7 to port 8 of my switch, it might happen.
>
> Or i reconfigure my managed switch to change the port from one subnet
> to another subnet. The RJ45 is not moved, it is just a configuration
> change. The switch should do a down/up on its side to indicate
> something has changed, and that needs to be reported to userspace so
> dhcpcd gets a new IP address.
>
>         Andrew
Hi Andrew,

Agreed, my replug numbers do not rule out those cases.

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.

Thanks,
Linmao
Re: [PATCH net v2] r8152: Use BMSR to detect the link state
#5491
Author: Linmao Li
Date: Tue, 20 Oct 2026 12:38
69 lines
11419 bytes
在 2026/10/19 20:12, Hayes Wang 写道:
> Linmao Li <lilinmao@kylinos.cn>
>> 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads