[PATCH] can: mcan: Add support for handling dlec error on CAN FD format frame
From: Vivek Yadav
Date: Tue Oct 11 2022 - 23:46:36 EST
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 <vivek.2311@xxxxxxxxxxx>
---
drivers/net/can/m_can/m_can.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 4709c012b1dc..c070580d35fb 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_SHIFT 8
/* Interrupt Register (IR) */
#define IR_ALL_INT 0xffffffff
@@ -870,6 +871,7 @@ static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
{
struct m_can_classdev *cdev = netdev_priv(dev);
int work_done = 0;
+ int dpsr = 0;
if (irqstatus & IR_RF0L)
work_done += m_can_handle_lost_msg(dev);
@@ -884,6 +886,15 @@ static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
m_can_is_protocol_err(irqstatus))
work_done += m_can_handle_protocol_error(dev, irqstatus);
+ if (cdev->can.ctrlmode & CAN_CTRLMODE_FD) {
+ dpsr = psr >> PSR_DLEC_SHIFT;
+ if ((cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) &&
+ is_lec_err(dpsr)) {
+ netdev_dbg(dev, "Data phase error detected\n");
+ work_done += m_can_handle_lec_err(dev, dpsr & LEC_UNUSED);
+ }
+ }
+
/* other unproccessed error interrupts */
m_can_handle_other_err(dev, irqstatus);
--
2.17.1