mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
@ 2025-03-06  6:59 haibo.chen
  2025-03-06  6:59 ` [PATCH v2 2/2] can: flexcan: disable transceiver during system PM haibo.chen
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: haibo.chen @ 2025-03-06  6:59 UTC (permalink / raw)
  To: mkl, mailhol.vincent
  Cc: haibo.chen, ciprianmarian.costea, han.xu, u.kleine-koenig,
	linux-can, linux-kernel, imx

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

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

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/net/can/flexcan/flexcan-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index b347a1c93536..8415ef71f1b1 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -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);
@@ -2332,6 +2331,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	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] can: flexcan: disable transceiver during system PM
  2025-03-06  6:59 [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue haibo.chen
@ 2025-03-06  6:59 ` haibo.chen
  2025-03-06  7:15   ` Vincent Mailhol
  2025-03-06 15:04   ` Frank Li
  2025-03-06  7:15 ` [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue Vincent Mailhol
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: haibo.chen @ 2025-03-06  6:59 UTC (permalink / raw)
  To: mkl, mailhol.vincent
  Cc: haibo.chen, ciprianmarian.costea, han.xu, u.kleine-koenig,
	linux-can, linux-kernel, imx

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

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

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
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 8415ef71f1b1..6c59c2cfcf05 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);
 		}
 	}
-- 
2.34.1


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

* Re: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
  2025-03-06  6:59 [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue haibo.chen
  2025-03-06  6:59 ` [PATCH v2 2/2] can: flexcan: disable transceiver during system PM haibo.chen
@ 2025-03-06  7:15 ` Vincent Mailhol
  2025-03-06 15:03 ` Frank Li
  2025-03-14  9:13 ` Marc Kleine-Budde
  3 siblings, 0 replies; 10+ messages in thread
From: Vincent Mailhol @ 2025-03-06  7:15 UTC (permalink / raw)
  To: haibo.chen
  Cc: mkl, ciprianmarian.costea, han.xu, u.kleine-koenig, linux-can,
	linux-kernel, imx

On Thu. 6 Mar 2025 at 15:58, <haibo.chen@nxp.com> wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
>
> Only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process has
> no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.
>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

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

* Re: [PATCH v2 2/2] can: flexcan: disable transceiver during system PM
  2025-03-06  6:59 ` [PATCH v2 2/2] can: flexcan: disable transceiver during system PM haibo.chen
@ 2025-03-06  7:15   ` Vincent Mailhol
  2025-03-06 15:04   ` Frank Li
  1 sibling, 0 replies; 10+ messages in thread
From: Vincent Mailhol @ 2025-03-06  7:15 UTC (permalink / raw)
  To: haibo.chen
  Cc: mkl, ciprianmarian.costea, han.xu, u.kleine-koenig, linux-can,
	linux-kernel, imx

On Thu. 6 Mar 2025 at 15:58, <haibo.chen@nxp.com> wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
>
> During system PM, if no wakeup requirement, disable transceiver to
> save power.
>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

For this series, I guess you want to add stable@vger.kernel.org in CC.
Power saving seems worth a backport to me :)
Marc, maybe you can take care of this when applying?

Yours sincerely,
Vincent Mailhol

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

* Re: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
  2025-03-06  6:59 [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue haibo.chen
  2025-03-06  6:59 ` [PATCH v2 2/2] can: flexcan: disable transceiver during system PM haibo.chen
  2025-03-06  7:15 ` [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue Vincent Mailhol
@ 2025-03-06 15:03 ` Frank Li
  2025-03-14  9:13 ` Marc Kleine-Budde
  3 siblings, 0 replies; 10+ messages in thread
From: Frank Li @ 2025-03-06 15:03 UTC (permalink / raw)
  To: haibo.chen
  Cc: mkl, mailhol.vincent, ciprianmarian.costea, han.xu,
	u.kleine-koenig, linux-can, linux-kernel, imx

On Thu, Mar 06, 2025 at 02:59:20PM +0800, haibo.chen@nxp.com wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
>
> Only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process has
> no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.
>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>  drivers/net/can/flexcan/flexcan-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
> index b347a1c93536..8415ef71f1b1 100644
> --- a/drivers/net/can/flexcan/flexcan-core.c
> +++ b/drivers/net/can/flexcan/flexcan-core.c
> @@ -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);
> @@ -2332,6 +2331,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	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] can: flexcan: disable transceiver during system PM
  2025-03-06  6:59 ` [PATCH v2 2/2] can: flexcan: disable transceiver during system PM haibo.chen
  2025-03-06  7:15   ` Vincent Mailhol
@ 2025-03-06 15:04   ` Frank Li
  1 sibling, 0 replies; 10+ messages in thread
From: Frank Li @ 2025-03-06 15:04 UTC (permalink / raw)
  To: haibo.chen
  Cc: mkl, mailhol.vincent, ciprianmarian.costea, han.xu,
	u.kleine-koenig, linux-can, linux-kernel, imx

On Thu, Mar 06, 2025 at 02:59:21PM +0800, haibo.chen@nxp.com wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
>
> During system PM, if no wakeup requirement, disable transceiver to
> save power.
>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
> 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 8415ef71f1b1..6c59c2cfcf05 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);
>  		}
>  	}
> --
> 2.34.1
>

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

* Re: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
  2025-03-06  6:59 [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue haibo.chen
                   ` (2 preceding siblings ...)
  2025-03-06 15:03 ` Frank Li
@ 2025-03-14  9:13 ` Marc Kleine-Budde
  2025-03-14  9:42   ` Marc Kleine-Budde
  3 siblings, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2025-03-14  9:13 UTC (permalink / raw)
  To: haibo.chen
  Cc: mailhol.vincent, ciprianmarian.costea, han.xu, u.kleine-koenig,
	linux-can, linux-kernel, imx

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

On 06.03.2025 14:59:20, haibo.chen@nxp.com wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
> 
> Only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process has
> no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.

When looking at the code, it makes no sense to set the can.state to
CAN_STATE_ERROR_ACTIVE, if the device isn't up.

The suspend function doesn't look correct, either. I'll send a v3.

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] 10+ messages in thread

* Re: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
  2025-03-14  9:13 ` Marc Kleine-Budde
@ 2025-03-14  9:42   ` Marc Kleine-Budde
  2025-03-14  9:48     ` Bough Chen
  0 siblings, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2025-03-14  9:42 UTC (permalink / raw)
  To: haibo.chen
  Cc: mailhol.vincent, ciprianmarian.costea, han.xu, u.kleine-koenig,
	linux-can, linux-kernel, imx

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

On 14.03.2025 10:13:08, Marc Kleine-Budde wrote:
> On 06.03.2025 14:59:20, haibo.chen@nxp.com wrote:
> > From: Haibo Chen <haibo.chen@nxp.com>
> >
> > Only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process has
> > no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.
>
> When looking at the code, it makes no sense to set the can.state to
> CAN_STATE_ERROR_ACTIVE, if the device isn't up.
>
> The suspend function doesn't look correct, either. I'll send a v3.

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

regards,
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] 10+ messages in thread

* RE: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
  2025-03-14  9:42   ` Marc Kleine-Budde
@ 2025-03-14  9:48     ` Bough Chen
  2025-03-14  9:53       ` Marc Kleine-Budde
  0 siblings, 1 reply; 10+ messages in thread
From: Bough Chen @ 2025-03-14  9:48 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: mailhol.vincent, Ciprian Marian Costea (OSS),
	Han Xu, u.kleine-koenig, linux-can, linux-kernel, imx

> -----Original Message-----
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Sent: 2025年3月14日 17:43
> To: Bough Chen <haibo.chen@nxp.com>
> Cc: mailhol.vincent@wanadoo.fr; Ciprian Marian Costea (OSS)
> <ciprianmarian.costea@oss.nxp.com>; Han Xu <han.xu@nxp.com>;
> u.kleine-koenig@baylibre.com; linux-can@vger.kernel.org;
> linux-kernel@vger.kernel.org; imx@lists.linux.dev
> Subject: Re: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE
> when resume has no issue
> 
> On 14.03.2025 10:13:08, Marc Kleine-Budde wrote:
> > On 06.03.2025 14:59:20, haibo.chen@nxp.com wrote:
> > > From: Haibo Chen <haibo.chen@nxp.com>
> > >
> > > Only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process has
> > > no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.
> >
> > When looking at the code, it makes no sense to set the can.state to
> > CAN_STATE_ERROR_ACTIVE, if the device isn't up.
> >
> > The suspend function doesn't look correct, either. I'll send a v3.
> 
> After a suspend/resume cycle on a down interface, it will come up as
> ERROR-ACTIVE.

Seems only need to handle the priv->can.state when netif_running(dev) return true in PM.

Regards
Haibo Chen
> 
> | $ 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
> 
> regards,
> 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   |

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

* Re: RE: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue
  2025-03-14  9:48     ` Bough Chen
@ 2025-03-14  9:53       ` Marc Kleine-Budde
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2025-03-14  9:53 UTC (permalink / raw)
  To: Bough Chen
  Cc: mailhol.vincent, Ciprian Marian Costea (OSS),
	Han Xu, u.kleine-koenig, linux-can, linux-kernel, imx

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

On 14.03.2025 09:48:06, Bough Chen wrote:
> > > > Only set CAN state to CAN_STATE_ERROR_ACTIVE when resume process has
> > > > no issue, otherwise keep in CAN_STATE_SLEEPING as suspend did.
> > >
> > > When looking at the code, it makes no sense to set the can.state to
> > > CAN_STATE_ERROR_ACTIVE, if the device isn't up.
> > >
> > > The suspend function doesn't look correct, either. I'll send a v3.
> > 
> > After a suspend/resume cycle on a down interface, it will come up as
> > ERROR-ACTIVE.
> 
> Seems only need to handle the priv->can.state when netif_running(dev) return true in PM.

ACK - in both the suspend and the resume function.

regards,
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] 10+ messages in thread

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-06  6:59 [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue haibo.chen
2025-03-06  6:59 ` [PATCH v2 2/2] can: flexcan: disable transceiver during system PM haibo.chen
2025-03-06  7:15   ` Vincent Mailhol
2025-03-06 15:04   ` Frank Li
2025-03-06  7:15 ` [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue Vincent Mailhol
2025-03-06 15:03 ` Frank Li
2025-03-14  9:13 ` Marc Kleine-Budde
2025-03-14  9:42   ` Marc Kleine-Budde
2025-03-14  9:48     ` Bough Chen
2025-03-14  9:53       ` 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

all inboxes | Powered by JetHome®