Skip to content

Commit

Permalink
can: m_can: m_can_handle_bus_errors(): add support for handling DLEC …
Browse files Browse the repository at this point in the history
…error on CAN-FD frames

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.

Utilize 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@samsung.com>
Link: https://lore.kernel.org/all/20221018081934.1336690-1-mkl@pengutronix.de
Reviewed-by: Chandrasekar Ramakrishnan <rcsekar@samsung.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Vivek Yadav authored and Marc Kleine-Budde committed Oct 20, 2022
1 parent 6a8836e commit f5071d9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/net/can/m_can/m_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(10, 8)

/* Interrupt Register (IR) */
#define IR_ALL_INT 0xffffffff
Expand Down Expand Up @@ -875,9 +876,17 @@ static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
/* handle lec errors on the bus */
if (cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) {
u8 lec = FIELD_GET(PSR_LEC_MASK, psr);
u8 dlec = FIELD_GET(PSR_DLEC_MASK, psr);

if (is_lec_err(lec))
if (is_lec_err(lec)) {
netdev_dbg(dev, "Arbitration phase error detected\n");
work_done += m_can_handle_lec_err(dev, lec);
}

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 */
Expand Down

0 comments on commit f5071d9

Please sign in to comment.