netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: sfp: Stop SFP polling and interrupt handling during shutdown
@ 2019-06-06 18:06 Robert Hancock
  2019-06-06 18:09 ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Hancock @ 2019-06-06 18:06 UTC (permalink / raw)
  To: netdev; +Cc: linux, andrew, f.fainelli, hkallweit1, Robert Hancock

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


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

end of thread, other threads:[~2019-06-07 16:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-06 18:06 [PATCH net-next] net: sfp: Stop SFP polling and interrupt handling during shutdown Robert Hancock
2019-06-06 18:09 ` 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

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