[v2] can: mcan: Add support for handling DLEC error on CAN FD

Message ID 20221014050332.45045-1-vivek.2311@samsung.com
State New
Headers
Series [v2] can: mcan: Add support for handling DLEC error on CAN FD |

Commit Message

Vivek Yadav Oct. 14, 2022, 5:03 a.m. UTC
  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>
---
This patch is dependent on following patch from Marc:
[1]: https://lore.kernel.org/all/20221012074205.691384-1-mkl@pengutronix.de/

 drivers/net/can/m_can/m_can.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
  

Comments

Marc Kleine-Budde Oct. 14, 2022, 7:11 a.m. UTC | #1
On 14.10.2022 10:33:32, 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>
> ---
> This patch is dependent on following patch from Marc:
> [1]: https://lore.kernel.org/all/20221012074205.691384-1-mkl@pengutronix.de/
> 
>  drivers/net/can/m_can/m_can.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 18a138fdfa66..8cff1f274aab 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
> @@ -876,8 +877,16 @@ static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
>  	if (cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) {
>  		u8 lec = FIELD_GET(PSR_LEC_MASK, psr);
>  
> -		if (is_lec_err(lec))
> +		if (is_lec_err(lec)) {
>  			work_done += m_can_handle_lec_err(dev, lec);
> +		} else {

In case of high interrupt latency there might be lec and dlec errors
pending. As this is error handling and not the hot path, please check
for both, i.e.:

                if (is_lec_err(lec))
                        work_done += m_can_handle_lec_err(dev, lec);

                if (is_lec_err(dlec))
                        work_done += m_can_handle_lec_err(dev, dlec);

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

If you add a debug, please add one for the Arbitration phase, too.

> +				work_done += m_can_handle_lec_err(dev, dlec);
> +			}
> +		}
>  	}
>  
>  	/* handle protocol errors in arbitration phase */

regards,
Marc
  
Vivek Yadav Oct. 14, 2022, 11:23 a.m. UTC | #2
> -----Original Message-----
> From: Marc Kleine-Budde [mailto:mkl@pengutronix.de]
> Sent: 14 October 2022 12:41
> To: Vivek Yadav <vivek.2311@samsung.com>
> Cc: rcsekar@samsung.com; wg@grandegger.com; davem@davemloft.net;
> edumazet@google.com; kuba@kernel.org; pabeni@redhat.com;
> pankaj.dubey@samsung.com; ravi.patel@samsung.com; linux-
> can@vger.kernel.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH v2] can: mcan: Add support for handling DLEC error on
> CAN FD
> 
> On 14.10.2022 10:33:32, 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>
> > ---
> > This patch is dependent on following patch from Marc:
> > [1]:
> > https://lore.kernel.org/all/20221012074205.691384-1-mkl@pengutronix.de
> > /
> >
> >  drivers/net/can/m_can/m_can.c | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/can/m_can/m_can.c
> > b/drivers/net/can/m_can/m_can.c index 18a138fdfa66..8cff1f274aab
> > 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
> > @@ -876,8 +877,16 @@ static int m_can_handle_bus_errors(struct
> net_device *dev, u32 irqstatus,
> >  	if (cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) {
> >  		u8 lec = FIELD_GET(PSR_LEC_MASK, psr);
> >
> > -		if (is_lec_err(lec))
> > +		if (is_lec_err(lec)) {
> >  			work_done += m_can_handle_lec_err(dev, lec);
> > +		} else {
> 
> In case of high interrupt latency there might be lec and dlec errors pending.
> As this is error handling and not the hot path, please check for both, i.e.:
Okay will do that.
> 
>                 if (is_lec_err(lec))
>                         work_done += m_can_handle_lec_err(dev, lec);
> 
>                 if (is_lec_err(dlec))
>                         work_done += m_can_handle_lec_err(dev, dlec);
> 
> > +			u8 dlec = FIELD_GET(PSR_DLEC_MASK, psr);
> > +
> > +			if (is_lec_err(dlec)) {
> > +				netdev_dbg(dev, "Data phase error
> detected\n");
> 
> If you add a debug, please add one for the Arbitration phase, too.
I have added the debug print specially for dlec (data phase). So we can differentiate lec errors (for all type of frames except FD with BRS) and Data phase errors, as we are calling same handler function for both the errors.

If I understood your comment correctly, you are asking something like below:
        /* handle protocol errors in arbitration phase */
        if ((cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) &&
-           m_can_is_protocol_err(irqstatus))
+           m_can_is_protocol_err(irqstatus)) {
+               netdev_dbg(dev, "Arbitration phase error detected\n");
                work_done += m_can_handle_protocol_error(dev, irqstatus);
+       }

If the above implementation is correct as per your review comment, I think we don't need the above changes because 
Debug print for arbitration failure are already there in " m_can_handle_protocol_error" function.

> 
> > +				work_done += m_can_handle_lec_err(dev,
> dlec);
> > +			}
> > +		}
> >  	}
> >
> >  	/* handle protocol errors in arbitration phase */
> 
> regards,
> Marc
> 
> --
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   |
> https://protect2.fireeye.com/v1/url?k=28e40100-499fab97-28e58a4f-
> 74fe4860001d-8e82bf09edd18d7c&q=1&e=47b831bd-4118-45e2-977c-
> eac4315bdf6d&u=https%3A%2F%2Fwww.pengutronix.de%2F  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
  
Marc Kleine-Budde Oct. 14, 2022, 11:36 a.m. UTC | #3
On 14.10.2022 16:53:19, Vivek Yadav wrote:
> > 
> >                 if (is_lec_err(lec))
> >                         work_done += m_can_handle_lec_err(dev, lec);
> > 
> >                 if (is_lec_err(dlec))
> >                         work_done += m_can_handle_lec_err(dev, dlec);
> > 
> > > +			u8 dlec = FIELD_GET(PSR_DLEC_MASK, psr);
> > > +
> > > +			if (is_lec_err(dlec)) {
> > > +				netdev_dbg(dev, "Data phase error
> > detected\n");
> > 
> > If you add a debug, please add one for the Arbitration phase, too.
>
> I have added the debug print specially for dlec (data phase). So we
> can differentiate lec errors (for all type of frames except FD with
> BRS) and Data phase errors, as we are calling same handler function
> for both the errors.
> 
> If I understood your comment correctly, you are asking something like below:
>         /* handle protocol errors in arbitration phase */
>         if ((cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) &&
> -           m_can_is_protocol_err(irqstatus))
> +           m_can_is_protocol_err(irqstatus)) {
> +               netdev_dbg(dev, "Arbitration phase error detected\n");
>                 work_done += m_can_handle_protocol_error(dev, irqstatus);
> +       }
> 
> If the above implementation is correct as per your review comment, I
> think we don't need the above changes because Debug print for
> arbitration failure are already there in "
> m_can_handle_protocol_error" function.

Ok

regards,
Marc
  

Patch

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 18a138fdfa66..8cff1f274aab 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
@@ -876,8 +877,16 @@  static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
 	if (cdev->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) {
 		u8 lec = FIELD_GET(PSR_LEC_MASK, psr);
 
-		if (is_lec_err(lec))
+		if (is_lec_err(lec)) {
 			work_done += m_can_handle_lec_err(dev, lec);
+		} else {
+			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 */