netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Subject: [PATCH net-next 01/17] net: sfp: move sfp sub-state machines into separate functions
Date: Sun, 10 Nov 2019 14:06:13 +0000	[thread overview]
Message-ID: <E1iTnr3-00059H-CF@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20191110140530.GA25745@shell.armlinux.org.uk>

Move the SFP sub-state machines out of the main state machine function,
in preparation for it doing a bit more with the device state.  By doing
so, we ensure that our debug after the main state machine is always
printed.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/sfp.c | 74 +++++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 31 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index e36c04c26866..f0e325324b23 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -1481,19 +1481,34 @@ static void sfp_sm_mod_remove(struct sfp *sfp)
 	dev_info(sfp->dev, "module removed\n");
 }
 
-static void sfp_sm_event(struct sfp *sfp, unsigned int event)
+/* This state machine tracks the netdev up/down state */
+static void sfp_sm_device(struct sfp *sfp, unsigned int event)
 {
-	mutex_lock(&sfp->sm_mutex);
+	switch (sfp->sm_dev_state) {
+	default:
+		if (event == SFP_E_DEV_UP)
+			sfp->sm_dev_state = SFP_DEV_UP;
+		break;
 
-	dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
-		mod_state_to_str(sfp->sm_mod_state),
-		dev_state_to_str(sfp->sm_dev_state),
-		sm_state_to_str(sfp->sm_state),
-		event_to_str(event));
+	case SFP_DEV_UP:
+		if (event == SFP_E_DEV_DOWN) {
+			/* If the module has a PHY, avoid raising TX disable
+			 * as this resets the PHY. Otherwise, raise it to
+			 * turn the laser off.
+			 */
+			if (!sfp->mod_phy)
+				sfp_module_tx_disable(sfp);
+			sfp->sm_dev_state = SFP_DEV_DOWN;
+		}
+		break;
+	}
+}
 
-	/* This state machine tracks the insert/remove state of
-	 * the module, and handles probing the on-board EEPROM.
-	 */
+/* This state machine tracks the insert/remove state of
+ * the module, and handles probing the on-board EEPROM.
+ */
+static void sfp_sm_module(struct sfp *sfp, unsigned int event)
+{
 	switch (sfp->sm_mod_state) {
 	default:
 		if (event == SFP_E_INSERT && sfp->attached) {
@@ -1533,27 +1548,10 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event)
 		}
 		break;
 	}
+}
 
-	/* This state machine tracks the netdev up/down state */
-	switch (sfp->sm_dev_state) {
-	default:
-		if (event == SFP_E_DEV_UP)
-			sfp->sm_dev_state = SFP_DEV_UP;
-		break;
-
-	case SFP_DEV_UP:
-		if (event == SFP_E_DEV_DOWN) {
-			/* If the module has a PHY, avoid raising TX disable
-			 * as this resets the PHY. Otherwise, raise it to
-			 * turn the laser off.
-			 */
-			if (!sfp->mod_phy)
-				sfp_module_tx_disable(sfp);
-			sfp->sm_dev_state = SFP_DEV_DOWN;
-		}
-		break;
-	}
-
+static void sfp_sm_main(struct sfp *sfp, unsigned int event)
+{
 	/* Some events are global */
 	if (sfp->sm_state != SFP_S_DOWN &&
 	    (sfp->sm_mod_state != SFP_MOD_PRESENT ||
@@ -1564,7 +1562,6 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event)
 		if (sfp->mod_phy)
 			sfp_sm_phy_detach(sfp);
 		sfp_sm_next(sfp, SFP_S_DOWN, 0);
-		mutex_unlock(&sfp->sm_mutex);
 		return;
 	}
 
@@ -1619,6 +1616,21 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event)
 	case SFP_S_TX_DISABLE:
 		break;
 	}
+}
+
+static void sfp_sm_event(struct sfp *sfp, unsigned int event)
+{
+	mutex_lock(&sfp->sm_mutex);
+
+	dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
+		mod_state_to_str(sfp->sm_mod_state),
+		dev_state_to_str(sfp->sm_dev_state),
+		sm_state_to_str(sfp->sm_state),
+		event_to_str(event));
+
+	sfp_sm_module(sfp, event);
+	sfp_sm_device(sfp, event);
+	sfp_sm_main(sfp, event);
 
 	dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n",
 		mod_state_to_str(sfp->sm_mod_state),
-- 
2.20.1


  reply	other threads:[~2019-11-10 14:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-10 14:05 [PATCH net-next 00/17] Allow slow to initialise GPON modules to work Russell King - ARM Linux admin
2019-11-10 14:06 ` Russell King [this message]
2019-11-10 17:56   ` [PATCH net-next 01/17] net: sfp: move sfp sub-state machines into separate functions Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 02/17] net: sfp: move tx disable on device down to main state machine Russell King
2019-11-10 18:00   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 03/17] net: sfp: rename sfp_sm_ins_next() as sfp_sm_mod_next() Russell King
2019-11-10 18:01   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 04/17] net: sfp: handle module remove outside state machine Russell King
2019-11-10 18:07   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 05/17] net: sfp: rename T_PROBE_WAIT to T_SERIAL Russell King
2019-11-10 18:08   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 06/17] net: sfp: parse SFP power requirement earlier Russell King
2019-11-10 18:10   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 07/17] net: sfp: avoid power switch on address-change modules Russell King
2019-11-10 18:12   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 08/17] net: sfp: control TX_DISABLE and phy only from main state machine Russell King
2019-11-10 18:14   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 09/17] net: sfp: split the PHY probe from sfp_sm_mod_init() Russell King
2019-11-10 18:19   ` Andrew Lunn
2019-11-10 14:06 ` [PATCH net-next 10/17] net: sfp: eliminate mdelay() from PHY probe Russell King
2019-11-10 19:37   ` Andrew Lunn
2019-11-10 19:59     ` Russell King - ARM Linux admin
2019-11-10 14:07 ` [PATCH net-next 11/17] net: sfp: allow fault processing to transition to other states Russell King
2019-11-10 14:07 ` [PATCH net-next 12/17] net: sfp: ensure TX_FAULT has deasserted before probing the PHY Russell King
2019-11-10 14:07 ` [PATCH net-next 13/17] net: sfp: track upstream's attachment state in state machine Russell King
2019-11-10 14:07 ` [PATCH net-next 14/17] net: sfp: split power mode switching from probe Russell King
2019-11-10 14:07 ` [PATCH net-next 15/17] net: sfp: move module insert reporting out of probe Russell King
2019-11-10 14:07 ` [PATCH net-next 16/17] net: sfp: allow sfp to probe slow to initialise GPON modules Russell King
2019-11-10 14:07 ` [PATCH net-next 17/17] net: sfp: allow modules with slow diagnostics to probe Russell King
2019-11-10 17:52 ` [PATCH net-next 00/17] Allow slow to initialise GPON modules to work Andrew Lunn
2019-11-10 19:47   ` Russell King - ARM Linux admin
2019-11-12  0:18 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1iTnr3-00059H-CF@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux.org.uk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).