netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: phy: broadcom: Fix brcm_fet_config_init()
@ 2022-03-24 21:54 Florian Fainelli
  2022-03-24 22:31 ` Florian Fainelli
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Fainelli @ 2022-03-24 21:54 UTC (permalink / raw)
  To: netdev
  Cc: opendmb, Florian Fainelli, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Michael Chan, Matt Carlson, Benjamin Li,
	open list:BROADCOM ETHERNET PHY DRIVERS, open list

A Broadcom AC201 PHY (same entry as 5241) would be flagged by the
Broadcom UniMAC MDIO controller as not completing the turn around
properly since the PHY expects 65 MDC clock cycles to complete a write
cycle, and the MDIO controller was only sending 64 MDC clock cycles as
determined by looking at a scope shot.

This would make the subsequent read fail with the UniMAC MDIO controller
command field having MDIO_READ_FAIL set and we would abort the
brcm_fet_config_init() function and thus not probe the PHY at all.

After issuing a software reset, wait for at least 1ms which is well
above the 1us reset delay advertised by the datasheet and issue a dummy
read to let the PHY turn around the line properly. This read
specifically ignores -EIO which would be returned by MDIO controllers
checking for the line being turned around.

If we have a genuine read failure, the next read of the interrupt
status register would pick it up anyway.

Fixes: d7a2ed9248a3 ("broadcom: Add AC131 phy support")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/phy/broadcom.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
index 3c683e0e40e9..ae6abe146236 100644
--- a/drivers/net/phy/broadcom.c
+++ b/drivers/net/phy/broadcom.c
@@ -602,6 +602,26 @@ static int brcm_fet_config_init(struct phy_device *phydev)
 	if (err < 0)
 		return err;
 
+	/* The datasheet indicates the PHY needs up to 1us to complete a reset,
+	 * build some slack here.
+	 */
+	usleep_range(1000, 2000);
+
+	/* The PHY requires 65 MDC clock cycles to complete a write operation
+	 * and turnaround the line properly.
+	 *
+	 * We ignore -EIO here as the MDIO controller (e.g.: mdio-bcm-unimac)
+	 * may flag the lack of turn-around as a read failure. This is
+	 * particularly true with this combination since the MDIO controller
+	 * only used 64 MDC cycles. This is not a critical failure in this
+	 * specific case and it has no functional impact otherwise, so we let
+	 * that one go through. If there is a genuine bus error, the next read
+	 * of MII_BRCM_FET_INTREG will error out.
+	 */
+	err = phy_read(phydev, MII_BMCR);
+	if (err < 0 && err != -EIO)
+		return err;
+
 	reg = phy_read(phydev, MII_BRCM_FET_INTREG);
 	if (reg < 0)
 		return reg;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: phy: broadcom: Fix brcm_fet_config_init()
  2022-03-24 21:54 [PATCH net] net: phy: broadcom: Fix brcm_fet_config_init() Florian Fainelli
@ 2022-03-24 22:31 ` Florian Fainelli
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Fainelli @ 2022-03-24 22:31 UTC (permalink / raw)
  To: netdev, David S. Miller, Jakub Kicinski
  Cc: opendmb, Andrew Lunn, Heiner Kallweit, Russell King, Paolo Abeni,
	open list:BROADCOM ETHERNET PHY DRIVERS, open list

On 3/24/22 14:54, Florian Fainelli wrote:
> A Broadcom AC201 PHY (same entry as 5241) would be flagged by the
> Broadcom UniMAC MDIO controller as not completing the turn around
> properly since the PHY expects 65 MDC clock cycles to complete a write
> cycle, and the MDIO controller was only sending 64 MDC clock cycles as
> determined by looking at a scope shot.
> 
> This would make the subsequent read fail with the UniMAC MDIO controller
> command field having MDIO_READ_FAIL set and we would abort the
> brcm_fet_config_init() function and thus not probe the PHY at all.
> 
> After issuing a software reset, wait for at least 1ms which is well
> above the 1us reset delay advertised by the datasheet and issue a dummy
> read to let the PHY turn around the line properly. This read
> specifically ignores -EIO which would be returned by MDIO controllers
> checking for the line being turned around.
> 
> If we have a genuine read failure, the next read of the interrupt
> status register would pick it up anyway.
> 
> Fixes: d7a2ed9248a3 ("broadcom: Add AC131 phy support")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---

I will make this a v2 which explicitly includes delay.h to have a 
definition for usleep_range9) so this commit would apply cleanly to 
earlier kernels as well. Please do not apply just yet. Thanks!
-- 
Florian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-24 22:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 21:54 [PATCH net] net: phy: broadcom: Fix brcm_fet_config_init() Florian Fainelli
2022-03-24 22:31 ` Florian Fainelli

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).