[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190517023652.19285-1-qiangqing.zhang@nxp.com>
Date: Fri, 17 May 2019 02:39:10 +0000
From: Joakim Zhang <qiangqing.zhang@....com>
To: "mkl@...gutronix.de" <mkl@...gutronix.de>,
"linux-can@...r.kernel.org" <linux-can@...r.kernel.org>
CC: dl-linux-imx <linux-imx@....com>,
"wg@...ndegger.com" <wg@...ndegger.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Joakim Zhang <qiangqing.zhang@....com>
Subject: [PATCH] can: flexcan: fix deadlock when using self wakeup
As reproted by Sean Nyekjaer bellow:
When suspending, when there is still can traffic on the
interfaces the flexcan immediately wakes the platform again.
As it should :-)
But it throws this error msg:
[ 3169.378661] PM: noirq suspend of devices failed
On the way down to suspend the interface that throws the error
message does call flexcan_suspend but fails to call
flexcan_noirq_suspend.
That means the flexcan_enter_stop_mode is called, but on the way
out of suspend the driver only calls flexcan_resume and skips
flexcan_noirq_resume, thus it doesn't call flexcan_exit_stop_mode.
This leaves the flexcan in stop mode, and with the current driver
it can't recover from this even with a soft reboot, it requires a
hard reboot.
Fixes: de3578c198c6 ("can: flexcan: add self wakeup support")
This patch intends to fix the issue, and also add comment to explain the
wakeup flow.
Signed-off-by: Joakim Zhang <qiangqing.zhang@....com>
---
drivers/net/can/flexcan.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index e35083ff31ee..6fbce473a8c7 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -286,6 +286,7 @@ struct flexcan_priv {
const struct flexcan_devtype_data *devtype_data;
struct regulator *reg_xceiver;
struct flexcan_stop_mode stm;
+ bool in_stop_mode;
/* Read and Write APIs */
u32 (*read)(void __iomem *addr);
@@ -1653,6 +1654,7 @@ static int __maybe_unused flexcan_suspend(struct device *device)
if (device_may_wakeup(device)) {
enable_irq_wake(dev->irq);
flexcan_enter_stop_mode(priv);
+ priv->in_stop_mode = true;
} else {
err = flexcan_chip_disable(priv);
if (err)
@@ -1679,6 +1681,11 @@ static int __maybe_unused flexcan_resume(struct device *device)
netif_device_attach(dev);
netif_start_queue(dev);
if (device_may_wakeup(device)) {
+ if (priv->in_stop_mode) {
+ flexcan_enable_wakeup_irq(priv, false);
+ flexcan_exit_stop_mode(priv);
+ priv->in_stop_mode = false;
+ }
disable_irq_wake(dev->irq);
} else {
err = pm_runtime_force_resume(device);
@@ -1715,6 +1722,11 @@ static int __maybe_unused flexcan_noirq_suspend(struct device *device)
struct net_device *dev = dev_get_drvdata(device);
struct flexcan_priv *priv = netdev_priv(dev);
+ /* Need enable wakeup interrupt in noirq suspend stage. Otherwise,
+ * it will trigger continuously wakeup interrupt if the wakeup event
+ * comes before noirq suspend stage, and simultaneously in has enter
+ * the stop mode.
+ */
if (netif_running(dev) && device_may_wakeup(device))
flexcan_enable_wakeup_irq(priv, true);
@@ -1726,9 +1738,14 @@ static int __maybe_unused flexcan_noirq_resume(struct device *device)
struct net_device *dev = dev_get_drvdata(device);
struct flexcan_priv *priv = netdev_priv(dev);
+ /* Need exit stop mode in noirq resume stage. Otherwise, it will
+ * trigger continuously wakeup interrupt if the wakeup event comes,
+ * and simultaneously it has still in stop mode.
+ */
if (netif_running(dev) && device_may_wakeup(device)) {
flexcan_enable_wakeup_irq(priv, false);
flexcan_exit_stop_mode(priv);
+ priv->in_stop_mode = false;
}
return 0;
--
2.17.1
Powered by blists - more mailing lists