netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Hancock <hancock@sedsystems.ca>
To: netdev@vger.kernel.org
Cc: linux@armlinux.org.uk, andrew@lunn.ch, f.fainelli@gmail.com,
	hkallweit1@gmail.com, Robert Hancock <hancock@sedsystems.ca>
Subject: [PATCH net-next] net: sfp: Stop SFP polling and interrupt handling during shutdown
Date: Thu,  6 Jun 2019 12:06:17 -0600	[thread overview]
Message-ID: <1559844377-17188-1-git-send-email-hancock@sedsystems.ca> (raw)

SFP device polling can cause problems during the shutdown process if the
parent devices of the network controller have been shut down already.
This problem was seen on the iMX6 platform with PCIe devices, where
accessing the device after the bus is shut down causes a hang.

Stop all delayed work in the SFP driver during the shutdown process, and
set a flag which causes any further state checks or state machine events
(possibly triggered by previous GPIO IRQs) to be skipped.

Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
---

This is an updated version of a previous patch "net: sfp: Stop SFP polling
during shutdown" with the addition of stopping handling of GPIO-triggered
interrupts as well, as pointed out by Russell King.

 drivers/net/phy/sfp.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 554acc8..5fdf573 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -191,6 +191,7 @@ struct sfp {
 	struct delayed_work poll;
 	struct delayed_work timeout;
 	struct mutex sm_mutex;
+	bool shutdown;
 	unsigned char sm_mod_state;
 	unsigned char sm_dev_state;
 	unsigned short sm_state;
@@ -1466,6 +1467,11 @@ static void sfp_sm_mod_remove(struct sfp *sfp)
 static void sfp_sm_event(struct sfp *sfp, unsigned int event)
 {
 	mutex_lock(&sfp->sm_mutex);
+	if (unlikely(sfp->shutdown)) {
+		/* Do not handle any more state machine events. */
+		mutex_unlock(&sfp->sm_mutex);
+		return;
+	}
 
 	dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
 		mod_state_to_str(sfp->sm_mod_state),
@@ -1704,6 +1710,13 @@ static void sfp_check_state(struct sfp *sfp)
 {
 	unsigned int state, i, changed;
 
+	mutex_lock(&sfp->sm_mutex);
+	if (unlikely(sfp->shutdown)) {
+		/* No more state checks */
+		mutex_unlock(&sfp->sm_mutex);
+		return;
+	}
+
 	state = sfp_get_state(sfp);
 	changed = state ^ sfp->state;
 	changed &= SFP_F_PRESENT | SFP_F_LOS | SFP_F_TX_FAULT;
@@ -1715,6 +1728,7 @@ static void sfp_check_state(struct sfp *sfp)
 
 	state |= sfp->state & (SFP_F_TX_DISABLE | SFP_F_RATE_SELECT);
 	sfp->state = state;
+	mutex_unlock(&sfp->sm_mutex);
 
 	rtnl_lock();
 	if (changed & SFP_F_PRESENT)
@@ -1928,9 +1942,22 @@ static int sfp_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void sfp_shutdown(struct platform_device *pdev)
+{
+	struct sfp *sfp = platform_get_drvdata(pdev);
+
+	mutex_lock(&sfp->sm_mutex);
+	sfp->shutdown = true;
+	mutex_unlock(&sfp->sm_mutex);
+
+	cancel_delayed_work_sync(&sfp->poll);
+	cancel_delayed_work_sync(&sfp->timeout);
+}
+
 static struct platform_driver sfp_driver = {
 	.probe = sfp_probe,
 	.remove = sfp_remove,
+	.shutdown = sfp_shutdown,
 	.driver = {
 		.name = "sfp",
 		.of_match_table = sfp_of_match,
-- 
1.8.3.1


             reply	other threads:[~2019-06-06 18:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-06 18:06 Robert Hancock [this message]
2019-06-06 18:09 ` [PATCH net-next] net: sfp: Stop SFP polling and interrupt handling during shutdown Russell King - ARM Linux admin
2019-06-06 20:57   ` Robert Hancock
2019-06-07  3:21     ` Florian Fainelli
2019-06-07 10:26     ` Russell King - ARM Linux admin
2019-06-07 10:42     ` Russell King - ARM Linux admin
2019-06-07 16:08       ` Robert Hancock

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=1559844377-17188-1-git-send-email-hancock@sedsystems.ca \
    --to=hancock@sedsystems.ca \
    --cc=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux@armlinux.org.uk \
    --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).