From: "Markus Schneider-Pargmann" <msp@baylibre.com>
To: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Chandrasekar Ramakrishnan" <rcsekar@samsung.com>,
"Vincent Mailhol" <mailhol.vincent@wanadoo.fr>,
"Patrik Flykt" <patrik.flykt@linux.intel.com>,
"Dong Aisheng" <b29396@freescale.com>,
"Varka Bhadram" <varkabhadram@gmail.com>,
"Wu Bo" <wubo.oduw@gmail.com>,
"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: <linux-can@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<kernel@pengutronix.de>
Subject: Re: [PATCH v2 3/7] can: m_can: m_can_handle_state_errors(): fix CAN state transition to Error Active
Date: Wed, 10 Sep 2025 10:47:45 +0200 [thread overview]
Message-ID: <DCOZNFLPYZFH.2EWPVI5X452IJ@baylibre.com> (raw)
In-Reply-To: <20250909-m_can-fix-state-handling-v2-3-af9fa240b68a@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 4099 bytes --]
On Tue Sep 9, 2025 at 7:53 PM CEST, Marc Kleine-Budde wrote:
> The CAN Error State is determined by the receive and transmit error
> counters. The CAN error counters decrease when reception/transmission
> is successful, so that a status transition back to the Error Active
> status is possible. This transition is not handled by
> m_can_handle_state_errors().
>
> Add the missing detection of the Error Active state to
> m_can_handle_state_errors() and extend the handling of this state in
> m_can_handle_state_change().
>
> Fixes: e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
> Fixes: cd0d83eab2e0 ("can: m_can: m_can_handle_state_change(): fix state change")
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Reviewed-by: Markus Schneider-Pargmann <msp@baylibre.com>
> ---
> drivers/net/can/m_can/m_can.c | 55 ++++++++++++++++++++++++++-----------------
> 1 file changed, 33 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 16b38e6c3985..3edf01b098a4 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -812,6 +812,9 @@ static int m_can_handle_state_change(struct net_device *dev,
> u32 timestamp = 0;
>
> switch (new_state) {
> + case CAN_STATE_ERROR_ACTIVE:
> + cdev->can.state = CAN_STATE_ERROR_ACTIVE;
> + break;
> case CAN_STATE_ERROR_WARNING:
> /* error warning state */
> cdev->can.can_stats.error_warning++;
> @@ -841,6 +844,12 @@ static int m_can_handle_state_change(struct net_device *dev,
> __m_can_get_berr_counter(dev, &bec);
>
> switch (new_state) {
> + case CAN_STATE_ERROR_ACTIVE:
> + cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
> + cf->data[1] = CAN_ERR_CRTL_ACTIVE;
> + cf->data[6] = bec.txerr;
> + cf->data[7] = bec.rxerr;
> + break;
> case CAN_STATE_ERROR_WARNING:
> /* error warning state */
> cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
> @@ -877,30 +886,33 @@ static int m_can_handle_state_change(struct net_device *dev,
> return 1;
> }
>
> -static int m_can_handle_state_errors(struct net_device *dev, u32 psr)
> +static enum can_state
> +m_can_state_get_by_psr(struct m_can_classdev *cdev)
> +{
> + u32 reg_psr;
> +
> + reg_psr = m_can_read(cdev, M_CAN_PSR);
> +
> + if (reg_psr & PSR_BO)
> + return CAN_STATE_BUS_OFF;
> + if (reg_psr & PSR_EP)
> + return CAN_STATE_ERROR_PASSIVE;
> + if (reg_psr & PSR_EW)
> + return CAN_STATE_ERROR_WARNING;
> +
> + return CAN_STATE_ERROR_ACTIVE;
> +}
> +
> +static int m_can_handle_state_errors(struct net_device *dev)
> {
> struct m_can_classdev *cdev = netdev_priv(dev);
> - int work_done = 0;
> + enum can_state new_state;
>
> - if (psr & PSR_EW && cdev->can.state != CAN_STATE_ERROR_WARNING) {
> - netdev_dbg(dev, "entered error warning state\n");
> - work_done += m_can_handle_state_change(dev,
> - CAN_STATE_ERROR_WARNING);
> - }
> + new_state = m_can_state_get_by_psr(cdev);
> + if (new_state == cdev->can.state)
> + return 0;
>
> - if (psr & PSR_EP && cdev->can.state != CAN_STATE_ERROR_PASSIVE) {
> - netdev_dbg(dev, "entered error passive state\n");
> - work_done += m_can_handle_state_change(dev,
> - CAN_STATE_ERROR_PASSIVE);
> - }
> -
> - if (psr & PSR_BO && cdev->can.state != CAN_STATE_BUS_OFF) {
> - netdev_dbg(dev, "entered error bus off state\n");
> - work_done += m_can_handle_state_change(dev,
> - CAN_STATE_BUS_OFF);
> - }
> -
> - return work_done;
> + return m_can_handle_state_change(dev, new_state);
> }
>
> static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
> @@ -1031,8 +1043,7 @@ static int m_can_rx_handler(struct net_device *dev, int quota, u32 irqstatus)
> }
>
> if (irqstatus & IR_ERR_STATE)
> - work_done += m_can_handle_state_errors(dev,
> - m_can_read(cdev, M_CAN_PSR));
> + work_done += m_can_handle_state_errors(dev);
>
> if (irqstatus & IR_ERR_BUS_30X)
> work_done += m_can_handle_bus_errors(dev, irqstatus,
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 289 bytes --]
next prev parent reply other threads:[~2025-09-10 8:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 17:53 [PATCH v2 0/7] can: m_can: fix pm_runtime and CAN state handling Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 1/7] can: m_can: m_can_plat_remove(): add missing pm_runtime_disable() Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 2/7] can: m_can: only handle active interrupts Marc Kleine-Budde
2025-09-10 8:41 ` Markus Schneider-Pargmann
2025-09-10 14:28 ` Marc Kleine-Budde
2025-09-10 15:06 ` Marc Kleine-Budde
2025-09-10 16:04 ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 3/7] can: m_can: m_can_handle_state_errors(): fix CAN state transition to Error Active Marc Kleine-Budde
2025-09-10 8:47 ` Markus Schneider-Pargmann [this message]
2025-09-09 17:53 ` [PATCH v2 4/7] can: m_can: m_can_chip_config(): bring up interface in correct state Marc Kleine-Budde
2025-09-10 8:57 ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 5/7] can: m_can: fix CAN state in system PM Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 6/7] can: m_can: m_can_get_berr_counter(): don't wake up controller if interface is down Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 7/7] can: m_can: add optional support for reset Marc Kleine-Budde
2025-09-10 9:32 ` Markus Schneider-Pargmann
2025-09-10 14:35 ` Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DCOZNFLPYZFH.2EWPVI5X452IJ@baylibre.com \
--to=msp@baylibre.com \
--cc=b29396@freescale.com \
--cc=kernel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=p.zabel@pengutronix.de \
--cc=patrik.flykt@linux.intel.com \
--cc=rcsekar@samsung.com \
--cc=varkabhadram@gmail.com \
--cc=wubo.oduw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®