All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] can: mcan: Add support for handling dlec error on CAN FD format frame
       [not found] <CGME20221011120147epcas5p45049f7c0428a799c005b6ab77b428128@epcas5p4.samsung.com>
@ 2022-10-11 11:35 ` Vivek Yadav
  2022-10-12  7:47   ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Vivek Yadav @ 2022-10-11 11:35 UTC (permalink / raw)
  To: rcsekar, wg, mkl, davem, edumazet, kuba, pabeni, pankaj.dubey
  Cc: linux-can, netdev, linux-kernel, Vivek Yadav

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@samsung.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] can: mcan: Add support for handling dlec error on CAN FD format frame
  2022-10-11 11:35 ` [PATCH] can: mcan: Add support for handling dlec error on CAN FD format frame Vivek Yadav
@ 2022-10-12  7:47   ` Marc Kleine-Budde
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2022-10-12  7:47 UTC (permalink / raw)
  To: Vivek Yadav
  Cc: rcsekar, wg, davem, edumazet, kuba, pabeni, pankaj.dubey,
	linux-can, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2479 bytes --]

On 11.10.2022 17:05:12, 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.
> 
> Signed-off-by: Vivek Yadav <vivek.2311@samsung.com>

I've just sent patch

| https://lore.kernel.org/all/20221012074205.691384-1-mkl@pengutronix.de

to clean up the LEC error handling a bit. This makes it easier to add
DLEC support.

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

Please define a PSR_DLEC_MASK and follow the lec handling in my patch.

regards,
Marc

>  
>  /* 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) {

I think we can skip the check for CAN-FD here.

> +		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);

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 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-12  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20221011120147epcas5p45049f7c0428a799c005b6ab77b428128@epcas5p4.samsung.com>
2022-10-11 11:35 ` [PATCH] can: mcan: Add support for handling dlec error on CAN FD format frame Vivek Yadav
2022-10-12  7:47   ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.