netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] net: phy: add state PERM_FAIL
@ 2019-06-10 17:37 Heiner Kallweit
  2019-06-10 17:41 ` Florian Fainelli
  0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2019-06-10 17:37 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Russell King - ARM Linux,
	David Miller
  Cc: netdev@vger.kernel.org

This RFC patch is a follow-up to discussion [0]. In cases like missing
PHY firmware we may want to keep the PHY from being brought up, but
still allow MDIO access. Setting state PERM_FAIL in the probe or
config_init callback allows to achieve this.

[0] https://marc.info/?t=155973142200002&r=1&w=2

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy.c | 10 ++++++++--
 include/linux/phy.h   |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d91507650..889437512 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -44,6 +44,7 @@ static const char *phy_state_to_str(enum phy_state st)
 	PHY_STATE_STR(RUNNING)
 	PHY_STATE_STR(NOLINK)
 	PHY_STATE_STR(HALTED)
+	PHY_STATE_STR(PERM_FAIL)
 	}
 
 	return NULL;
@@ -744,7 +745,8 @@ static void phy_error(struct phy_device *phydev)
 	WARN_ON(1);
 
 	mutex_lock(&phydev->lock);
-	phydev->state = PHY_HALTED;
+	if (phydev->state != PHY_PERM_FAIL)
+		phydev->state = PHY_HALTED;
 	mutex_unlock(&phydev->lock);
 
 	phy_trigger_machine(phydev);
@@ -897,7 +899,10 @@ void phy_start(struct phy_device *phydev)
 {
 	mutex_lock(&phydev->lock);
 
-	if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) {
+	if (phydev->state == PHY_PERM_FAIL) {
+		phydev_warn(phydev, "Can't start PHY because it's in state PERM_FAIL\n");
+		goto out;
+	} else if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) {
 		WARN(1, "called from state %s\n",
 		     phy_state_to_str(phydev->state));
 		goto out;
@@ -934,6 +939,7 @@ void phy_state_machine(struct work_struct *work)
 	switch (phydev->state) {
 	case PHY_DOWN:
 	case PHY_READY:
+	case PHY_PERM_FAIL:
 		break;
 	case PHY_UP:
 		needs_aneg = true;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index d0af7d37f..7f47b6605 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -300,11 +300,16 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
  * HALTED: PHY is up, but no polling or interrupts are done. Or
  * PHY is in an error state.
  * - phy_start moves to UP
+ *
+ * PERM_FAIL: A permanent failure was detected and PHY isn't allowed to be
+ * brought up. Still we don't want to fail in probe to allow MDIO access
+ * to the PHY, e.g. to load missing firmware.
  */
 enum phy_state {
 	PHY_DOWN = 0,
 	PHY_READY,
 	PHY_HALTED,
+	PHY_PERM_FAIL,
 	PHY_UP,
 	PHY_RUNNING,
 	PHY_NOLINK,
-- 
2.21.0


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

end of thread, other threads:[~2019-06-10 21:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-10 17:37 [PATCH RFC] net: phy: add state PERM_FAIL Heiner Kallweit
2019-06-10 17:41 ` Florian Fainelli
2019-06-10 18:51   ` Andrew Lunn
2019-06-10 19:06     ` Florian Fainelli
2019-06-10 21:27       ` Andrew Lunn
2019-06-10 21:44         ` 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).