netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "pankj.sharma" <pankj.sharma@samsung.com>
To: "'Marc Kleine-Budde'" <mkl@pengutronix.de>
Cc: <wg@grandegger.com>, <davem@davemloft.net>,
	<eugen.hristev@microchip.com>, <ludovic.desroches@microchip.com>,
	<pankaj.dubey@samsung.com>, <rcsekar@samsung.com>,
	"'Sriram Dash'" <sriram.dash@samsung.com>,
	<linux-can@vger.kernel.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] can: m_can: add support for handling arbitration error
Date: Thu, 17 Oct 2019 17:21:36 +0530	[thread overview]
Message-ID: <000e01d584e1$3cb91c10$b62b5430$@samsung.com> (raw)
In-Reply-To: <00c5c5b7-cc90-ff6c-0c49-77fe0481dac1@pengutronix.de>

> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Subject: Re: [PATCH] can: m_can: add support for handling arbitration error
> 
> On 10/14/19 1:34 PM, Pankaj Sharma wrote:
> > The Bosch MCAN hardware (3.1.0 and above) supports interrupt flag to
> > detect Protocol error in arbitration phase.
> >
> > Transmit error statistics is currently not updated from the MCAN driver.
> > Protocol error in arbitration phase is a TX error and the network
> > statistics should be updated accordingly.
> >
> > The member "tx_error" of "struct net_device_stats" should be
> > incremented as arbitration is a transmit protocol error. Also
> > "arbitration_lost" of "struct can_device_stats" should be incremented
> > to report arbitration lost.
> >
> > Signed-off-by: Pankaj Sharma <pankj.sharma@samsung.com>
> > Signed-off-by: Sriram Dash <sriram.dash@samsung.com>
> > ---
> >  drivers/net/can/m_can/m_can.c | 38
> > +++++++++++++++++++++++++++++++++++
> >  1 file changed, 38 insertions(+)
> >
> > diff --git a/drivers/net/can/m_can/m_can.c
> > b/drivers/net/can/m_can/m_can.c index b95b382eb308..7efafee0eec8
> > 100644
> > --- a/drivers/net/can/m_can/m_can.c
> > +++ b/drivers/net/can/m_can/m_can.c
> > @@ -778,6 +778,39 @@ static inline bool is_lec_err(u32 psr)
> >  	return psr && (psr != LEC_UNUSED);
> >  }
> >
> > +static inline bool is_protocol_err(u32 irqstatus)
> 
> please add the comon m_can_ prefix

Alright. Will change the name "is_protocol_err" to "m_can_ is_protocol_err"

> 
> > +{
> > +	if (irqstatus & IR_ERR_LEC_31X)
> > +		return 1;
> > +	else
> > +		return 0;
> > +}
> > +
> > +static int m_can_handle_protocol_error(struct net_device *dev, u32
> > +irqstatus) {
> > +	struct net_device_stats *stats = &dev->stats;
> > +	struct m_can_priv *priv = netdev_priv(dev);
> > +	struct can_frame *cf;
> > +	struct sk_buff *skb;
> > +
> > +	/* propagate the error condition to the CAN stack */
> > +	skb = alloc_can_err_skb(dev, &cf);
> > +	if (unlikely(!skb))
> > +		return 0;
> 
> please handle the stats, even if the allocation of the skb fails.

Alright. Will do as follows
+       if (unlikely(!skb)) {
+               netdev_dbg(dev, "allocation of skb failed\n");
+               stats->tx_errors++;
+               return 0;
+       }

> 
> > +
> > +	if (priv->version >= 31 && (irqstatus & IR_PEA)) {
> > +		netdev_dbg(dev, "Protocol error in Arbitration fail\n");
> > +		stats->tx_errors++;
> > +		priv->can.can_stats.arbitration_lost++;
> > +		cf->can_id |= CAN_ERR_LOSTARB;
> > +		cf->data[0] |= CAN_ERR_LOSTARB_UNSPEC;
> > +	}
> > +
> > +	netif_receive_skb(skb);
> > +
> > +	return 1;
> > +}
> > +
> >  static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
> >  				   u32 psr)
> >  {
> > @@ -792,6 +825,11 @@ static int m_can_handle_bus_errors(struct
> net_device *dev, u32 irqstatus,
> >  	    is_lec_err(psr))
> >  		work_done += m_can_handle_lec_err(dev, psr & LEC_UNUSED);
> >
> > +	/* handle protocol errors in arbitration phase */
> > +	if ((priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) &&
> > +	    is_protocol_err(irqstatus))
> > +		work_done += m_can_handle_protocol_error(dev, irqstatus);
> > +
> >  	/* other unproccessed error interrupts */
> >  	m_can_handle_other_err(dev, irqstatus);
> >
> >
> 
> Marc
> 
> --
> Pengutronix e.K.                  | Marc Kleine-Budde           |
> Industrial Linux Solutions        | Phone: +49-231-2826-924     |
> Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
> Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



  reply	other threads:[~2019-10-17 11:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20191014113437epcas5p2143d7e85d5a50dad79a4a60a9d666fe4@epcas5p2.samsung.com>
2019-10-14 11:34 ` [PATCH] can: m_can: add support for handling arbitration error Pankaj Sharma
2019-10-14 12:31   ` Marc Kleine-Budde
2019-10-17 11:51     ` pankj.sharma [this message]
2019-10-14 13:04   ` kbuild test robot
2019-10-14 15:04   ` kbuild test robot
2019-10-14 15:04   ` [PATCH] can: m_can: fix boolreturn.cocci warnings kbuild test robot
2019-10-15  5:57     ` Simon Horman
2019-10-15  6:37       ` Jeroen Hofstee
2019-10-15  7:13         ` Simon Horman
2019-10-15  8:32           ` Jeroen Hofstee
2019-10-17 11:54             ` pankj.sharma
2019-10-14 16:20   ` [PATCH] can: m_can: add support for handling arbitration error kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000e01d584e1$3cb91c10$b62b5430$@samsung.com' \
    --to=pankj.sharma@samsung.com \
    --cc=davem@davemloft.net \
    --cc=eugen.hristev@microchip.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pankaj.dubey@samsung.com \
    --cc=rcsekar@samsung.com \
    --cc=sriram.dash@samsung.com \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).