All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] phy state machine: failsafe leave invalid RUNNING state
@ 2017-01-04 15:04 Zefir Kurtisi
  2017-01-04 15:13 ` Florian Fainelli
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Zefir Kurtisi @ 2017-01-04 15:04 UTC (permalink / raw)
  To: netdev; +Cc: f.fainelli, andrew

While in RUNNING state, phy_state_machine() checks for link changes by
comparing phydev->link before and after calling phy_read_status().
This works as long as it is guaranteed that phydev->link is never
changed outside the phy_state_machine().

If in some setups this happens, it causes the state machine to miss
a link loss and remain RUNNING despite phydev->link being 0.

This has been observed running a dsa setup with a process continuously
polling the link states over ethtool each second (SNMPD RFC-1213
agent). Disconnecting the link on a phy followed by a ETHTOOL_GSET
causes dsa_slave_get_settings() / dsa_slave_get_link_ksettings() to
call phy_read_status() and with that modify the link status - and
with that bricking the phy state machine.

This patch adds a fail-safe check while in RUNNING, which causes to
move to CHANGELINK when the link is gone and we are still RUNNING.

Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>
---
 drivers/net/phy/phy.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 28548af..0f9a61e 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -966,6 +966,15 @@ void phy_state_machine(struct work_struct *work)
 			if (old_link != phydev->link)
 				phydev->state = PHY_CHANGELINK;
 		}
+		/*
+		 * Failsafe: check that nobody set phydev->link=0 between two
+		 * poll cycles, otherwise we won't leave RUNNING state as long
+		 * as link remains down.
+		 */
+		if (!phydev->link && phydev->state == PHY_RUNNING) {
+			phydev->state = PHY_CHANGELINK;
+			dev_warn(&phydev->dev, "no link in PHY_RUNNING\n");
+		}
 		break;
 	case PHY_CHANGELINK:
 		err = phy_read_status(phydev);
-- 
2.7.4

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

end of thread, other threads:[~2017-01-09 20:38 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-04 15:04 [PATCH] phy state machine: failsafe leave invalid RUNNING state Zefir Kurtisi
2017-01-04 15:13 ` Florian Fainelli
2017-01-04 15:27   ` Zefir Kurtisi
2017-01-04 15:30     ` Florian Fainelli
2017-01-04 16:10       ` Zefir Kurtisi
2017-01-04 16:16         ` Andrew Lunn
2017-01-04 16:24           ` [SIDE DISCUSSION] " Matthias May
2017-01-04 21:44         ` Florian Fainelli
2017-01-05  9:23           ` Zefir Kurtisi
2017-01-05 19:39             ` Florian Fainelli
2017-01-04 20:07 ` kbuild test robot
2017-01-04 20:23 ` kbuild test robot
2017-01-06 11:14 ` [PATCH v2] " Zefir Kurtisi
2017-01-08 23:16   ` David Miller
2017-01-09  1:24   ` Florian Fainelli
2017-01-09 20:38   ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.