netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	David Miller <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net] net: phy: ensure PHY is powered up when reading ID registers
Date: Sat, 5 Jan 2019 18:33:47 +0100	[thread overview]
Message-ID: <20190105173347.GA30438@lunn.ch> (raw)
In-Reply-To: <68d8022b-493a-1c9a-72c2-2f16df835fab@gmail.com>

On Sat, Jan 05, 2019 at 02:21:03PM +0100, Heiner Kallweit wrote:
> During a bug analysis we came across the fact that there's no guarantee
> that reading from the ID registers returns a valid value if PHY is
> powered down. When reading invalid values we may load no or the wrong
> PHY driver. Therefore let's play safe and power up the PHY before
> reading the ID registers in case PHY is powered down.
> 
> Suggested-by: Florian Fainelli <f.fainelli@gmail.com>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/phy_device.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 9560a2b84..d4702313d 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -754,19 +754,22 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id,
>  	if (is_c45)
>  		return get_phy_c45_ids(bus, addr, phy_id, c45_ids);

Hi Heiner

>  
> +	phy_reg = mdiobus_read(bus, addr, MII_BMCR);
> +	if (phy_reg < 0)
> +		/* returning -ENODEV allows to continue bus-scanning */
> +		return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO;

It would be better to copy the code verbatim. I know we have had
issues with scanning depending on the return value. So changing the
return value should be in a separate patch. I would also not make it a
fix, but something for net-next, so it gets more testing.

> +
> +	/* PHY may be powered down and ID registers invalid */
> +	if (phy_reg & BMCR_PDOWN) {
> +		mdiobus_write(bus, addr, MII_BMCR, phy_reg & ~BMCR_PDOWN);
> +		/* give the PHY some time to resume */
> +		msleep(100);
> +	}
> +

Is this potentially slowing the scan down to 100ms * 32, if the read
of MII_BMCR always returns 0xffff?

Thanks
	Andrew

  parent reply	other threads:[~2019-01-05 17:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-05 13:21 [PATCH net] net: phy: ensure PHY is powered up when reading ID registers Heiner Kallweit
2019-01-05 13:37 ` Heiner Kallweit
2019-01-05 17:33 ` Andrew Lunn [this message]
2019-01-05 21:07   ` Heiner Kallweit
2019-01-05 21:47     ` David Miller
2019-01-05 22:04     ` Andrew Lunn
2019-01-05 22:06       ` David Miller
2019-01-06  0:12 ` Florian Fainelli
2019-01-06 12:03   ` Heiner Kallweit
2019-01-07 15:18 ` David Miller

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=20190105173347.GA30438@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).