2022-10-14 12:48:37

by Vivek Yadav

[permalink] [raw]
Subject: [PATCH v3] can: mcan: Add support for handling DLEC error on CAN FD

When a frame in CAN FD format has reached the data phase, the next
CAN event (error or valid frame) will be shown in DLEC.

Utilizes the dedicated flag (Data Phase Last Error Code: DLEC flag) to
determine the type of last error that occurred in the data phase
of a CAN FD frame and handle the bus errors.

Signed-off-by: Vivek Yadav <[email protected]>
---
This patch is dependent on following patch from Marc:
[1]: https://lore.kernel.org/all/[email protected]/

drivers/net/can/m_can/m_can.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 18a138fdfa66..73ce946b5aab 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -156,6 +156,7 @@ enum m_can_reg {
#define PSR_EW BIT(6)
#define PSR_EP BIT(5)
#define PSR_LEC_MASK GENMASK(2, 0)
+#define PSR_DLEC_MASK GENMASK(8, 10)

/* Interrupt Register (IR) */
#define IR_ALL_INT 0xffffffff
@@ -878,6 +879,13 @@ static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,

if (is_lec_err(lec))
work_done += m_can_handle_lec_err(dev, lec);
+
+ u8 dlec = FIELD_GET(PSR_DLEC_MASK, psr);
+
+ if (is_lec_err(dlec)) {
+ netdev_dbg(dev, "Data phase error detected\n");
+ work_done += m_can_handle_lec_err(dev, dlec);
+ }
}

/* handle protocol errors in arbitration phase */
--
2.17.1


2022-10-14 13:18:30

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH v3] can: mcan: Add support for handling DLEC error on CAN FD

On 14.10.2022 17:16:13, Vivek Yadav wrote:
> When a frame in CAN FD format has reached the data phase, the next
> CAN event (error or valid frame) will be shown in DLEC.
>
> Utilizes the dedicated flag (Data Phase Last Error Code: DLEC flag) to
> determine the type of last error that occurred in the data phase
> of a CAN FD frame and handle the bus errors.

Can you please test your code before sending it.

| drivers/net/can/m_can/m_can.c: In function ‘m_can_handle_bus_errors’:
| include/linux/build_bug.h:16:51: error: negative width in bit-field ‘<anonymous>’
| 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
[...]
| drivers/net/can/m_can/m_can.c:883:17: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
| 883 | u8 dlec = FIELD_GET(PSR_DLEC_MASK, psr);
| | ^~

regards,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (1.16 kB)
signature.asc (499.00 B)
Download all attachments