From: Florian Fainelli Subject: Re: [PATCH net] net: phy: ensure PHY is powered up when reading ID registers Date: Sat, 05 Jan 2019 16:12:37 -0800 Message-ID: <152B6387-650F-4E3D-A9A4-2FDADE49C6FB@gmail.com> References: <68d8022b-493a-1c9a-72c2-2f16df835fab@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: "netdev@vger.kernel.org" To: Heiner Kallweit , Andrew Lunn , David Miller Return-path: Received: from mail-pf1-f194.google.com ([209.85.210.194]:35591 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfAFAMr (ORCPT ); Sat, 5 Jan 2019 19:12:47 -0500 Received: by mail-pf1-f194.google.com with SMTP id z9so20034693pfi.2 for ; Sat, 05 Jan 2019 16:12:45 -0800 (PST) In-Reply-To: <68d8022b-493a-1c9a-72c2-2f16df835fab@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: On January 5, 2019 5:21:03 AM PST, 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=2E When reading invalid values we may load no or the wrong >PHY driver=2E Therefore let's play safe and power up the PHY before >reading the ID registers in case PHY is powered down=2E > >Suggested-by: Florian Fainelli >Signed-off-by: Heiner Kallweit >--- > drivers/net/phy/phy_device=2Ec | 23 +++++++++++++---------- > 1 file changed, 13 insertions(+), 10 deletions(-) > >diff --git a/drivers/net/phy/phy_device=2Ec >b/drivers/net/phy/phy_device=2Ec >index 9560a2b84=2E=2Ed4702313d 100644 >--- a/drivers/net/phy/phy_device=2Ec >+++ b/drivers/net/phy/phy_device=2Ec >@@ -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); >=20 In premise this would also apply to C45 PHYs though not sure whether this = would be on a per-package basis or global=2E >+ phy_reg =3D mdiobus_read(bus, addr, MII_BMCR); >+ if (phy_reg < 0) >+ /* returning -ENODEV allows to continue bus-scanning */ >+ return (phy_reg =3D=3D -EIO || phy_reg =3D=3D -ENODEV) ? -ENODEV : -EI= O; >+ >+ /* 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); >+ } We should check the 802=2E3 spec and see if we can reference an upper boun= d being defined there, if not, I suppose 100ms is as good as any other dela= y=2E There is one potential concern here which is that if the PHY device is pro= bed but never used subsequently or the connect()/attach() operation is done= much much longer, there is a missed opportunity for keeping the PHY in a l= ow power mode=2E I would take the PHY out of power down, read its ID, then = put it back to power down? Then the state machine takes care of taking it o= ut of power down again=2E Another thing to possibly watch out for is what the mii_bus::reset callbac= k might have done to the PHY=2E >+ > /* Grab the bits from PHYIR1, and put them in the upper half */ Typo here: MII_PHYSID1? --=20 Florian