can: rcar_can: Fix suspend/resume

Started by Yoshihiro Shimoda on Sep 21, 2021 · 5 messages from 4 authors · Last reply Sep 24, 2021

Subsystems (2)

Maintainers (3)

STALE1887d REVIEWED · 1 review, 0 by maintainers

Status: Reviewed.

1 review trailer.

open the first message on its own page

Message details and related content
If the driver was not opened, rcar_can_suspend() should not call
clk_disable() because the clock was not enabled.

Fixes: fd1159318e55 ("can: add Renesas R-Car CAN driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Ayumi Nakamichi <redacted>
---
 drivers/net/can/rcar/rcar_can.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
index 00e4533c8bdd..6b4eefb03044 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
@@ -846,10 +846,12 @@ static int __maybe_unused rcar_can_suspend(struct device *dev)
 	struct rcar_can_priv *priv = netdev_priv(ndev);
 	u16 ctlr;
 
-	if (netif_running(ndev)) {
-		netif_stop_queue(ndev);
-		netif_device_detach(ndev);
-	}
+	if (!netif_running(ndev))
+		return 0;
+
+	netif_stop_queue(ndev);
+	netif_device_detach(ndev);
+
 	ctlr = readw(&priv->regs->ctlr);
 	ctlr |= RCAR_CAN_CTLR_CANM_HALT;
 	writew(ctlr, &priv->regs->ctlr);
@@ -858,6 +860,7 @@ static int __maybe_unused rcar_can_suspend(struct device *dev)
 	priv->can.state = CAN_STATE_SLEEPING;
 
 	clk_disable(priv->clk);
+
 	return 0;
 }
 
@@ -868,6 +871,9 @@ static int __maybe_unused rcar_can_resume(struct device *dev)
 	u16 ctlr;
 	int err;
 
+	if (!netif_running(ndev))
+		return 0;
+
 	err = clk_enable(priv->clk);
 	if (err) {
 		netdev_err(ndev, "clk_enable() failed, error %d\n", err);
@@ -881,10 +887,9 @@ static int __maybe_unused rcar_can_resume(struct device *dev)
 	writew(ctlr, &priv->regs->ctlr);
 	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
-	if (netif_running(ndev)) {
-		netif_device_attach(ndev);
-		netif_start_queue(ndev);
-	}
+	netif_device_attach(ndev);
+	netif_start_queue(ndev);
+
 	return 0;
 }
 
-- 
2.25.1
Message details and related content
quoted hunk
On 09/21/2021 7:19 AM Yoshihiro Shimoda [off-list ref] wrote:

 
If the driver was not opened, rcar_can_suspend() should not call
clk_disable() because the clock was not enabled.

Fixes: fd1159318e55 ("can: add Renesas R-Car CAN driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Ayumi Nakamichi <redacted>
---
 drivers/net/can/rcar/rcar_can.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
index 00e4533c8bdd..6b4eefb03044 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
@@ -846,10 +846,12 @@ static int __maybe_unused rcar_can_suspend(struct device *dev)
 	struct rcar_can_priv *priv = netdev_priv(ndev);
 	u16 ctlr;
 
-	if (netif_running(ndev)) {
-		netif_stop_queue(ndev);
-		netif_device_detach(ndev);
-	}
+	if (!netif_running(ndev))
+		return 0;
+
+	netif_stop_queue(ndev);
+	netif_device_detach(ndev);
+
 	ctlr = readw(&priv->regs->ctlr);
 	ctlr |= RCAR_CAN_CTLR_CANM_HALT;
 	writew(ctlr, &priv->regs->ctlr);
@@ -858,6 +860,7 @@ static int __maybe_unused rcar_can_suspend(struct device *dev)
 	priv->can.state = CAN_STATE_SLEEPING;
 
 	clk_disable(priv->clk);
+
 	return 0;

28 more quoted lines

Reviewed-by: Ulrich Hecht <redacted>

CU
Uli
Message details and related content
On Tue, Sep 21, 2021 at 12:38:13PM +0200, Ulrich Hecht wrote:
quoted
On 09/21/2021 7:19 AM Yoshihiro Shimoda [off-list ref] wrote:

 
If the driver was not opened, rcar_can_suspend() should not call
clk_disable() because the clock was not enabled.

Fixes: fd1159318e55 ("can: add Renesas R-Car CAN driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Ayumi Nakamichi <redacted>
---
 drivers/net/can/rcar/rcar_can.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
index 00e4533c8bdd..6b4eefb03044 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
...
quoted
@@ -858,6 +860,7 @@ static int __maybe_unused rcar_can_suspend(struct device *dev)
 	priv->can.state = CAN_STATE_SLEEPING;
 
 	clk_disable(priv->clk);
+
 	return 0;
 }
 
nit: this hunk seems unrelated to the rest of the patch

...
Message details and related content
Hi Shimoda-San,

Thanks for the patch. I have tested Wake on LAN(Magic packet) on Hihope RZ/G2M board
and this patches fixes the warning messages reported by kernel during suspend.

Tested-by: Biju Das <biju.das.jz@bp.renesas.com>


Before applying patch
------------------------
root@hihope-rzg2m:~# ethtool -s eth0 wol g
root@hihope-rzg2m:~# echo mem > /sys/power/state
[   92.220742] PM: suspend entry (s2idle)
[   92.228123] Filesystems sync: 0.003 seconds
[   92.248521] Freezing user space processes ... (elapsed 0.007 seconds) done.
[   92.263935] OOM killer disabled.
[   92.267265] Freezing remaining freezable tasks ... (elapsed 0.004 seconds) done.
[   92.279787] printk: Suspending console(s) (use no_console_suspend to debug)
[   92.310223] wl1271_sdio mmc2:0001:2: no wilink module was probed
[   92.541847] ------------[ cut here ]------------
[   92.541885] can-if1 already disabled
[   92.541932] WARNING: CPU: 0 PID: 480 at drivers/clk/clk.c:952 clk_core_disable+0x250/0x288
[   92.541962] CPU: 0 PID: 480 Comm: sh Not tainted 5.15.0-rc1-arm64-renesas-00402-gf0c16ee77cf1 #297
[   92.541973] Hardware name: HopeRun HiHope RZ/G2M with sub board (DT)
[   92.541981] pstate: 800000c5 (Nzcv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[   92.541990] pc : clk_core_disable+0x250/0x288
[   92.542000] lr : clk_core_disable+0x250/0x288
[   92.542008] sp : ffff80001263b980
[   92.542014] x29: ffff80001263b980 x28: ffff8000114ea508 x27: 0000000000000000
[   92.542037] x26: ffff8000113b0b48 x25: ffff80001115f000 x24: ffff8000114ea518
[   92.542057] x23: ffff0005c0b5f010 x22: ffff8000113b0b48 x21: 0000000000000000
[   92.542077] x20: ffff0005c0d09800 x19: ffff0005c0d09800 x18: 000000000000b948
[   92.542096] x17: 0000000000000000 x16: 000000000000b94e x15: ffff8000115c5e68
[   92.542116] x14: fffffffffffc63d7 x13: 0000000000000003 x12: ffff8000113d3e58
[   92.542135] x11: 0000000000000001 x10: 00000000000000f0 x9 : ffff8000111619e4
[   92.542154] x8 : ffff0005c67a4380 x7 : 0000000000000002 x6 : 0000000000000000
[   92.542173] x5 : ffff00063f727bf0 x4 : 0000000000000000 x3 : 0000000000000027
[   92.542192] x2 : 0000000000000023 x1 : 2b864f21865f9400 x0 : 0000000000000000
[   92.542212] Call trace:
[   92.542218]  clk_core_disable+0x250/0x288

114 more lines

quoted hunk
-----Original Message-----
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Sent: 21 September 2021 06:20
To: <redacted>; mkl@pengutronix.de
Cc: davem@davemloft.net; kuba@kernel.org; <redacted>;
netdev@vger.kernel.org; linux-renesas-soc@vger.kernel.org; Yoshihiro
Shimoda [off-list ref]; Ayumi Nakamichi
[off-list ref]
Subject: [PATCH] can: rcar_can: Fix suspend/resume

If the driver was not opened, rcar_can_suspend() should not call
clk_disable() because the clock was not enabled.

Fixes: fd1159318e55 ("can: add Renesas R-Car CAN driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Ayumi Nakamichi <redacted>
---
 drivers/net/can/rcar/rcar_can.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_can.c
b/drivers/net/can/rcar/rcar_can.c index 00e4533c8bdd..6b4eefb03044 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
@@ -846,10 +846,12 @@ static int __maybe_unused rcar_can_suspend(struct
device *dev)
 	struct rcar_can_priv *priv = netdev_priv(ndev);
 	u16 ctlr;

-	if (netif_running(ndev)) {
-		netif_stop_queue(ndev);
-		netif_device_detach(ndev);
-	}
+	if (!netif_running(ndev))
+		return 0;
+
+	netif_stop_queue(ndev);
+	netif_device_detach(ndev);
+
 	ctlr = readw(&priv->regs->ctlr);

39 more quoted lines

Message details and related content
Hi Simon-san,
From: Simon Horman, Sent: Thursday, September 23, 2021 12:24 AM

On Tue, Sep 21, 2021 at 12:38:13PM +0200, Ulrich Hecht wrote:
quoted
quoted
On 09/21/2021 7:19 AM Yoshihiro Shimoda [off-list ref] wrote:


If the driver was not opened, rcar_can_suspend() should not call
clk_disable() because the clock was not enabled.

Fixes: fd1159318e55 ("can: add Renesas R-Car CAN driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Ayumi Nakamichi <redacted>
---
 drivers/net/can/rcar/rcar_can.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
index 00e4533c8bdd..6b4eefb03044 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
...
quoted
quoted
@@ -858,6 +860,7 @@ static int __maybe_unused rcar_can_suspend(struct device *dev)
 	priv->can.state = CAN_STATE_SLEEPING;

 	clk_disable(priv->clk);
+
 	return 0;
 }
nit: this hunk seems unrelated to the rest of the patch
Thank you for your comment! I'll remove this.

Best regards,
Yoshihiro Shimda
...
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help