Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH v3 1/2] can: flexcan: only change CAN state when link up in system PM
@ 2025-03-14 11:01 haibo.chen
  2025-03-14 11:01 ` [PATCH v3 2/2] can: flexcan: disable transceiver during " haibo.chen
  2025-03-14 12:27 ` [PATCH v3 1/2] can: flexcan: only change CAN state when link up in " Marc Kleine-Budde
  0 siblings, 2 replies; 3+ messages in thread
From: haibo.chen @ 2025-03-14 11:01 UTC (permalink / raw)
  To: mkl, mailhol.vincent
  Cc: haibo.chen, ciprianmarian.costea, u.kleine-koenig, fabio.estevam,
	festevam, linux-can, linux-kernel, stable, imx, han.xu

From: Haibo Chen <haibo.chen@nxp.com>

After a suspend/resume cycle on a down interface, it will come up as
ERROR-ACTIVE.

$ ip -details -s -s a s dev flexcan0
3: flexcan0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN group default qlen 10
    link/can  promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
    can state STOPPED (berr-counter tx 0 rx 0) restart-ms 1000

$ sudo systemctl suspend

$ ip -details -s -s a s dev flexcan0
3: flexcan0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN group default qlen 10
    link/can  promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 1000

And only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process
has no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.

Fixes: 4de349e786a3 ("can: flexcan: fix resume function")
Cc: stable@vger.kernel.org
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
Changes for v3:
 - only handle priv->can.state when netif_running(dev) return true in PM.
---
 drivers/net/can/flexcan/flexcan-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index b347a1c93536..d4d342d8f490 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -2299,8 +2299,8 @@ static int __maybe_unused flexcan_suspend(struct device *device)
 		}
 		netif_stop_queue(dev);
 		netif_device_detach(dev);
+		priv->can.state = CAN_STATE_SLEEPING;
 	}
-	priv->can.state = CAN_STATE_SLEEPING;
 
 	return 0;
 }
@@ -2311,7 +2311,6 @@ static int __maybe_unused flexcan_resume(struct device *device)
 	struct flexcan_priv *priv = netdev_priv(dev);
 	int err;
 
-	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 	if (netif_running(dev)) {
 		netif_device_attach(dev);
 		netif_start_queue(dev);
@@ -2331,6 +2330,7 @@ static int __maybe_unused flexcan_resume(struct device *device)
 
 			flexcan_chip_interrupts_enable(dev);
 		}
+		priv->can.state = CAN_STATE_ERROR_ACTIVE;
 	}
 
 	return 0;
-- 
2.34.1


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

* [PATCH v3 2/2] can: flexcan: disable transceiver during system PM
  2025-03-14 11:01 [PATCH v3 1/2] can: flexcan: only change CAN state when link up in system PM haibo.chen
@ 2025-03-14 11:01 ` haibo.chen
  2025-03-14 12:27 ` [PATCH v3 1/2] can: flexcan: only change CAN state when link up in " Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: haibo.chen @ 2025-03-14 11:01 UTC (permalink / raw)
  To: mkl, mailhol.vincent
  Cc: haibo.chen, ciprianmarian.costea, u.kleine-koenig, fabio.estevam,
	festevam, linux-can, linux-kernel, stable, imx, han.xu

From: Haibo Chen <haibo.chen@nxp.com>

During system PM, if no wakeup requirement, disable transceiver to
save power.

Fixes: 4de349e786a3 ("can: flexcan: fix resume function")
Cc: stable@vger.kernel.org
Reviewed-by: Frank Li <frank.li@nxp.com>
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
Changes for V3:
 N/A

Changes for V2:
 - add return check for flexcan_transceiver_disable
 - disable transceiver if flexcan_chip_start() failed

---
 drivers/net/can/flexcan/flexcan-core.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index d4d342d8f490..491f9548c7ae 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -2292,6 +2292,9 @@ static int __maybe_unused flexcan_suspend(struct device *device)
 				return err;
 
 			flexcan_chip_interrupts_disable(dev);
+			err = flexcan_transceiver_disable(priv);
+			if (err)
+				return err;
 
 			err = pinctrl_pm_select_sleep_state(device);
 			if (err)
@@ -2324,10 +2327,16 @@ static int __maybe_unused flexcan_resume(struct device *device)
 			if (err)
 				return err;
 
-			err = flexcan_chip_start(dev);
+			err = flexcan_transceiver_enable(priv);
 			if (err)
 				return err;
 
+			err = flexcan_chip_start(dev);
+			if (err) {
+				flexcan_transceiver_disable(priv);
+				return err;
+			}
+
 			flexcan_chip_interrupts_enable(dev);
 		}
 		priv->can.state = CAN_STATE_ERROR_ACTIVE;
-- 
2.34.1


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

* Re: [PATCH v3 1/2] can: flexcan: only change CAN state when link up in system PM
  2025-03-14 11:01 [PATCH v3 1/2] can: flexcan: only change CAN state when link up in system PM haibo.chen
  2025-03-14 11:01 ` [PATCH v3 2/2] can: flexcan: disable transceiver during " haibo.chen
@ 2025-03-14 12:27 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2025-03-14 12:27 UTC (permalink / raw)
  To: haibo.chen
  Cc: mailhol.vincent, ciprianmarian.costea, u.kleine-koenig,
	fabio.estevam, festevam, linux-can, linux-kernel, stable, imx,
	han.xu

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

On 14.03.2025 19:01:44, haibo.chen@nxp.com wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
> 
> After a suspend/resume cycle on a down interface, it will come up as
> ERROR-ACTIVE.
> 
> $ ip -details -s -s a s dev flexcan0
> 3: flexcan0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN group default qlen 10
>     link/can  promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
>     can state STOPPED (berr-counter tx 0 rx 0) restart-ms 1000
> 
> $ sudo systemctl suspend
> 
> $ ip -details -s -s a s dev flexcan0
> 3: flexcan0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN group default qlen 10
>     link/can  promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 1000
> 
> And only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process
> has no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.
> 
> Fixes: 4de349e786a3 ("can: flexcan: fix resume function")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Applied to linux-can.

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2025-03-14 12:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-14 11:01 [PATCH v3 1/2] can: flexcan: only change CAN state when link up in system PM haibo.chen
2025-03-14 11:01 ` [PATCH v3 2/2] can: flexcan: disable transceiver during " haibo.chen
2025-03-14 12:27 ` [PATCH v3 1/2] can: flexcan: only change CAN state when link up in " Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox