Skip to contentSkip to conversation

can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue

PATCH In review [email protected] 4 participants 10 messages Mar 6, 2025 – Mar 14, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue

From: Haibo Chen <[email protected]>

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

---
 drivers/net/can/flexcan/flexcan-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/flexcan/flexcan-core.c +1 -1
index b347a1c93536..8415ef71f1b1 100644
@@ -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;
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 can: flexcan: disable transceiver during system PM

From: Haibo Chen <[email protected]>

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

---
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(-)
drivers/net/can/flexcan/flexcan-core.c +10 -1
index 8415ef71f1b1..6c59c2cfcf05 100644
@@ -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);
 		}
 	}
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] can: flexcan: disable transceiver during system PM

Quoted 6 lines · On Thu. 6 Mar 2025 at 15:58, <[email protected]> wrote:

From: Haibo Chen <[email protected]>

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

For this series, I guess you want to add [email protected] in CC. Power saving seems worth a backport to me :)
Marc, maybe you can take care of this when applying?

Yours sincerely,
Vincent Mailhol

maintainer Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] can: flexcan: disable transceiver during system PM

In reply to [email protected]
Quoted 6 lines · On Thu, Mar 06, 2025 at 02:59:21PM +0800, [email protected] wrote:

From: Haibo Chen <[email protected]>

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

Quoted 43 lines

---
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(-)
drivers/net/can/flexcan/flexcan-core.c +10 -2
index 8415ef71f1b1..6c59c2cfcf05 100644
@@ -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

maintainer Reviewed-by on v1 1/2
#5 lore raw
In reply to [email protected]
Quoted 6 lines · On Thu, Mar 06, 2025 at 02:59:20PM +0800, [email protected] wrote:

From: Haibo Chen <[email protected]>

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

Quoted 27 lines
---
 drivers/net/can/flexcan/flexcan-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/flexcan/flexcan-core.c +1 -2
index b347a1c93536..8415ef71f1b1 100644
@@ -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

#6 lore raw
In reply to [email protected]
Quoted 4 lines · On 06.03.2025 14:59:20, [email protected] wrote:

From: Haibo Chen <[email protected]>

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

Signature · 4 lines
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   |
#7 lore raw
Quoted 10 lines · Marc Kleine-Budde
Quoted 4 lines · On 06.03.2025 14:59:20, [email protected] wrote:

From: Haibo Chen <[email protected]>

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

Signature · 4 lines
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   |
author
#8 lore raw
Quoted 18 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2025年3月14日 17:43
To: Bough Chen <[email protected]>
Cc: [email protected]; Ciprian Marian Costea (OSS) <[email protected]>; Han Xu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] can: flexcan: only set CAN_STATE_ERROR_ACTIVE when resume has no issue

Quoted 6 lines · Marc Kleine-Budde
Quoted 4 lines · On 06.03.2025 14:59:20, [email protected] wrote:

From: Haibo Chen <[email protected]>

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

Quoted 7 lines
Quoted 4 lines

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

Quoted 23 lines

| $ 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 |

#9 lore raw
Quoted 6 lines · Bough Chen
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

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.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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

Signature · 4 lines
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   |