netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: phy: improve and simplify state machine
@ 2018-10-11 20:35 Heiner Kallweit
  2018-10-11 20:36 ` [PATCH net-next 1/2] net: phy: improve handling of PHY_RUNNING in " Heiner Kallweit
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Heiner Kallweit @ 2018-10-11 20:35 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller; +Cc: netdev@vger.kernel.org

Improve / simplify handling of states PHY_RUNNING and PHY_RESUMING in
phylib state machine.

Heiner Kallweit (2):
  net: phy: improve handling of PHY_RUNNING in state machine
  net: phy: simplify handling of PHY_RESUMING in state machine

 drivers/net/phy/phy.c | 72 ++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 49 deletions(-)

-- 
2.19.1

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

* [PATCH net-next 1/2] net: phy: improve handling of PHY_RUNNING in state machine
  2018-10-11 20:35 [PATCH net-next 0/2] net: phy: improve and simplify state machine Heiner Kallweit
@ 2018-10-11 20:36 ` Heiner Kallweit
  2018-10-11 20:37 ` [PATCH net-next 2/2] net: phy: simplify handling of PHY_RESUMING " Heiner Kallweit
  2018-10-16  5:07 ` [PATCH net-next 0/2] net: phy: improve and simplify " David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Heiner Kallweit @ 2018-10-11 20:36 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller; +Cc: netdev@vger.kernel.org

Handling of state PHY_RUNNING seems to be more complex than it needs
to be. If not polling, then we don't have to do anything, we'll
receive an interrupt and go to state PHY_CHANGELINK once the link
goes down. If polling and link is down, we don't have to go the
extra mile over PHY_CHANGELINK and call phy_read_status() again
but can set status PHY_NOLINK directly.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 704428211..696955d38 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -941,7 +941,6 @@ void phy_state_machine(struct work_struct *work)
 	bool needs_aneg = false, do_suspend = false;
 	enum phy_state old_state;
 	int err = 0;
-	int old_link;
 
 	mutex_lock(&phydev->lock);
 
@@ -1025,26 +1024,16 @@ void phy_state_machine(struct work_struct *work)
 		}
 		break;
 	case PHY_RUNNING:
-		/* Only register a CHANGE if we are polling and link changed
-		 * since latest checking.
-		 */
-		if (phy_polling_mode(phydev)) {
-			old_link = phydev->link;
-			err = phy_read_status(phydev);
-			if (err)
-				break;
+		if (!phy_polling_mode(phydev))
+			break;
 
-			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;
-			phydev_err(phydev, "no link in PHY_RUNNING\n");
+		err = phy_read_status(phydev);
+		if (err)
+			break;
+
+		if (!phydev->link) {
+			phydev->state = PHY_NOLINK;
+			phy_link_down(phydev, true);
 		}
 		break;
 	case PHY_CHANGELINK:
-- 
2.19.1

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

* [PATCH net-next 2/2] net: phy: simplify handling of PHY_RESUMING in state machine
  2018-10-11 20:35 [PATCH net-next 0/2] net: phy: improve and simplify state machine Heiner Kallweit
  2018-10-11 20:36 ` [PATCH net-next 1/2] net: phy: improve handling of PHY_RUNNING in " Heiner Kallweit
@ 2018-10-11 20:37 ` Heiner Kallweit
  2018-10-16  5:07 ` [PATCH net-next 0/2] net: phy: improve and simplify " David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Heiner Kallweit @ 2018-10-11 20:37 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller; +Cc: netdev@vger.kernel.org

Simplify code for handling state PHY_RESUMING, no functional change
intended.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy.c | 43 ++++++++++++++-----------------------------
 1 file changed, 14 insertions(+), 29 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 696955d38..d03bdbbd1 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1059,41 +1059,26 @@ void phy_state_machine(struct work_struct *work)
 	case PHY_RESUMING:
 		if (AUTONEG_ENABLE == phydev->autoneg) {
 			err = phy_aneg_done(phydev);
-			if (err < 0)
+			if (err < 0) {
 				break;
-
-			/* err > 0 if AN is done.
-			 * Otherwise, it's 0, and we're  still waiting for AN
-			 */
-			if (err > 0) {
-				err = phy_read_status(phydev);
-				if (err)
-					break;
-
-				if (phydev->link) {
-					phydev->state = PHY_RUNNING;
-					phy_link_up(phydev);
-				} else	{
-					phydev->state = PHY_NOLINK;
-					phy_link_down(phydev, false);
-				}
-			} else {
+			} else if (!err) {
 				phydev->state = PHY_AN;
 				phydev->link_timeout = PHY_AN_TIMEOUT;
-			}
-		} else {
-			err = phy_read_status(phydev);
-			if (err)
 				break;
-
-			if (phydev->link) {
-				phydev->state = PHY_RUNNING;
-				phy_link_up(phydev);
-			} else	{
-				phydev->state = PHY_NOLINK;
-				phy_link_down(phydev, false);
 			}
 		}
+
+		err = phy_read_status(phydev);
+		if (err)
+			break;
+
+		if (phydev->link) {
+			phydev->state = PHY_RUNNING;
+			phy_link_up(phydev);
+		} else	{
+			phydev->state = PHY_NOLINK;
+			phy_link_down(phydev, false);
+		}
 		break;
 	}
 
-- 
2.19.1

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

* Re: [PATCH net-next 0/2] net: phy: improve and simplify state machine
  2018-10-11 20:35 [PATCH net-next 0/2] net: phy: improve and simplify state machine Heiner Kallweit
  2018-10-11 20:36 ` [PATCH net-next 1/2] net: phy: improve handling of PHY_RUNNING in " Heiner Kallweit
  2018-10-11 20:37 ` [PATCH net-next 2/2] net: phy: simplify handling of PHY_RESUMING " Heiner Kallweit
@ 2018-10-16  5:07 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-10-16  5:07 UTC (permalink / raw)
  To: hkallweit1; +Cc: andrew, f.fainelli, netdev

From: Heiner Kallweit <hkallweit1@gmail.com>
Date: Thu, 11 Oct 2018 22:35:35 +0200

> Improve / simplify handling of states PHY_RUNNING and PHY_RESUMING in
> phylib state machine.

Series applied.

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

end of thread, other threads:[~2018-10-16 12:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-11 20:35 [PATCH net-next 0/2] net: phy: improve and simplify state machine Heiner Kallweit
2018-10-11 20:36 ` [PATCH net-next 1/2] net: phy: improve handling of PHY_RUNNING in " Heiner Kallweit
2018-10-11 20:37 ` [PATCH net-next 2/2] net: phy: simplify handling of PHY_RESUMING " Heiner Kallweit
2018-10-16  5:07 ` [PATCH net-next 0/2] net: phy: improve and simplify " David Miller

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