[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5f6b5096-d172-4a70-874c-be6d5a457ac0@nic.cz>
Date: Wed, 27 Dec 2023 23:19:40 +0100
From: Marek Mojík <marek.mojik@....cz>
To: Asmaa Mnebhi <asmaa@...dia.com>, davem@...emloft.net,
linux@...linux.org.uk, netdev@...r.kernel.org
Cc: davthompson@...dia.com
Subject: Re: [PATCH v1 1/1] net: phy: micrel: Add workaround for incomplete
autonegotiation
On 12/26/23 15:19, Asmaa Mnebhi wrote:
> Very rarely, the KSZ9031 fails to complete autonegotiation although it was
> initiated via phy_start(). As a result, the link stays down. Restarting
> autonegotiation when in this state solves the issue.
>
> Signed-off-by: Asmaa Mnebhi <asmaa@...dia.com>
> ---
> drivers/net/phy/micrel.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> index 08e3915001c3..de8140c5907f 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -1475,6 +1475,7 @@ static int ksz9031_get_features(struct phy_device *phydev)
>
> static int ksz9031_read_status(struct phy_device *phydev)
> {
> + u8 timeout = 10;
> int err;
> int regval;
>
> @@ -1494,6 +1495,22 @@ static int ksz9031_read_status(struct phy_device *phydev)
> return genphy_config_aneg(phydev);
> }
>
> + /* KSZ9031's autonegotiation takes normally 4-5 seconds to complete.
> + * Occasionally it fails to complete autonegotiation. The workaround is
> + * to restart it.
> + */
> + if (phydev->autoneg == AUTONEG_ENABLE) {
> + while (timeout) {
> + if (phy_aneg_done(phydev))
> + break;
> + mdelay(1000);
> + timeout--;
> + };
> +
> + if (timeout == 0)
> + phy_restart_aneg(phydev);
> + }
> +
> return 0;
> }
Hi Asmaa, mdelay is busy-wait, so you're unnecessarily blocking cpu core
for 10 seconds, msleep should be used here as explained in the docs
https://kernel.org/doc/Documentation/timers/timers-howto.txt
Marek
Powered by blists - more mailing lists