mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: phy: Warn about incorrect mdio_bus_phy_resume() state
@ 2022-08-01 23:34 Florian Fainelli
  2022-08-04  2:40 ` patchwork-bot+netdevbpf
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Florian Fainelli @ 2022-08-01 23:34 UTC (permalink / raw)
  To: netdev
  Cc: opendmb, Florian Fainelli, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, open list

Calling mdio_bus_phy_resume() with neither the PHY state machine set to
PHY_HALTED nor phydev->mac_managed_pm set to true is a good indication
that we can produce a race condition looking like this:

CPU0						CPU1
bcmgenet_resume
 -> phy_resume
   -> phy_init_hw
 -> phy_start
   -> phy_resume
                                                phy_start_aneg()
mdio_bus_phy_resume
 -> phy_resume
    -> phy_write(..., BMCR_RESET)
     -> usleep()                                  -> phy_read()

with the phy_resume() function triggering a PHY behavior that might have
to be worked around with (see bf8bfc4336f7 ("net: phy: broadcom: Fix
brcm_fet_config_init()") for instance) that ultimately leads to an error
reading from the PHY.

Fixes: fba863b81604 ("net: phy: make PHY PM ops a no-op if MAC driver manages PHY PM")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/phy/phy_device.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 46acddd865a7..608de5a94165 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -316,6 +316,12 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
 
 	phydev->suspended_by_mdio_bus = 0;
 
+	/* If we managed to get here with the PHY state machine in a state other
+	 * than PHY_HALTED this is an indication that something went wrong and
+	 * we should most likely be using MAC managed PM and we are not.
+	 */
+	WARN_ON(phydev->state != PHY_HALTED && !phydev->mac_managed_pm);
+
 	ret = phy_init_hw(phydev);
 	if (ret < 0)
 		return ret;
-- 
2.25.1


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

end of thread, other threads:[~2022-09-22 15:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01 23:34 [PATCH net] net: phy: Warn about incorrect mdio_bus_phy_resume() state Florian Fainelli
2022-08-04  2:40 ` patchwork-bot+netdevbpf
     [not found] ` <CGME20220812111948eucas1p2bf97e7f4558eb024f419346367a87b45@eucas1p2.samsung.com>
2022-08-12 11:19   ` Marek Szyprowski
2022-08-12 16:32     ` Florian Fainelli
2022-08-16 11:18       ` Marek Szyprowski
2022-08-16 13:20       ` Geert Uytterhoeven
2022-08-17  2:28         ` Florian Fainelli
2022-08-17  9:18           ` Geert Uytterhoeven
2022-08-17 11:32             ` Marek Szyprowski
2022-09-19 14:51         ` Geert Uytterhoeven
2022-09-22 12:31 ` Jakub Kicinski
2022-09-22 15:29   ` Florian Fainelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®