linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Mikhail Kofanov <c5r@yandex.ru>
Cc: linux-can <linux-can@vger.kernel.org>
Subject: Re: can: flexcan: patch
Date: Fri, 6 May 2016 12:26:17 +0200	[thread overview]
Message-ID: <572C7149.6040307@pengutronix.de> (raw)
In-Reply-To: <14855451462460611@web29h.yandex.ru>


[-- Attachment #1.1: Type: text/plain, Size: 4865 bytes --]

On 05/05/2016 05:03 PM, Mikhail Kofanov wrote:
> Hello!
> 
> There is small patch for imx flexcan driver.
> 1. Improve state change handling
> 2. add tx/rx error counter to state change error frame
> 
> Tested on imx25 based custom board.

Against which kernel version does this patch apply?

> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index e2d7ded..84d1fd8 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -581,11 +581,14 @@ static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
>         struct flexcan_priv *priv = netdev_priv(dev);
>         struct sk_buff *skb;
>         struct can_frame *cf;
> +       struct flexcan_regs __iomem *regs = priv->regs;
>         enum can_state new_state = 0, rx_state = 0, tx_state = 0;
>         int flt;
>         struct can_berr_counter bec;
>  
>         flt = reg_esr & FLEXCAN_ESR_FLT_CONF_MASK;
> +       /* always send error counters in error frame */
> +       __flexcan_get_berr_counter(dev, &bec);
>         if (likely(flt == FLEXCAN_ESR_FLT_CONF_ACTIVE)) {
>                 tx_state = unlikely(reg_esr & FLEXCAN_ESR_TX_WRN) ?
>                         CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
> @@ -593,7 +596,6 @@ static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
>                         CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
>                 new_state = max(tx_state, rx_state);
>         } else {
> -               __flexcan_get_berr_counter(dev, &bec);
>                 new_state = flt == FLEXCAN_ESR_FLT_CONF_PASSIVE ?
>                         CAN_STATE_ERROR_PASSIVE : CAN_STATE_BUS_OFF;
>                 rx_state = bec.rxerr >= bec.txerr ? new_state : 0;
> @@ -603,6 +605,8 @@ static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
>         /* state hasn't changed */
>         if (likely(new_state == priv->can.state))
>                 return 0;
> +       netdev_dbg(dev, "reg_esr=0x%x flt=0x%x ctrl=0x%08x new_state=%d\n", reg_esr, flt, flex
> +                        new_state);
>  
>         skb = alloc_can_err_skb(dev, &cf);
>         if (unlikely(!skb))
> @@ -613,6 +617,8 @@ static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
>         if (unlikely(new_state == CAN_STATE_BUS_OFF))
>                 can_bus_off(dev);
>  
> +       cf->data[6] = bec.txerr;
> +       cf->data[7] = bec.rxerr;
>         dev->stats.rx_packets++;
>         dev->stats.rx_bytes += cf->can_dlc;
>         netif_receive_skb(skb);
> @@ -679,7 +685,7 @@ static int flexcan_poll(struct napi_struct *napi, int quota)
>         /* The error bits are cleared on read,
>          * use saved value from irq handler.
>          */
> -       reg_esr = flexcan_read(&regs->esr) | priv->reg_esr;
> +       reg_esr = flexcan_read(&regs->esr) | (priv->reg_esr & FLEXCAN_ESR_ERR_BUS);
>  
>         /* handle state changes */
>         work_done += flexcan_poll_state(dev, reg_esr);
> @@ -721,24 +727,29 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
>         if (reg_esr & FLEXCAN_ESR_ALL_INT)
>                 flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, &regs->esr);
>  
> +
>         /* schedule NAPI in case of:
>          * - rx IRQ
> -        * - state change IRQ
> +        * - tx/rx warning or bus-off
> +        * - any state change
>          * - bus error IRQ and bus error reporting is activated
>          */
>         if ((reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) ||
>             (reg_esr & FLEXCAN_ESR_ERR_STATE) ||
> +           ((reg_esr & FLEXCAN_ESR_FLT_CONF_MASK) != (priv->reg_esr & FLEXCAN_ESR_FLT_CONF_MAS

There seems to be a problem with this mail, the rest of this line is
missing.

Marc

>             flexcan_has_and_handle_berr(priv, reg_esr)) {
>                 /* The error bits are cleared on read,
>                  * save them for later use.
>                  */
> -               priv->reg_esr = reg_esr & FLEXCAN_ESR_ERR_BUS;
> +               priv->reg_esr = reg_esr;
>                 flexcan_write(FLEXCAN_IFLAG_DEFAULT &
>                               ~FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, &regs->imask1);
>                 flexcan_write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
>                               &regs->ctrl);
>                 napi_schedule(&priv->napi);
>         }
> +       else
> +               priv->reg_esr = reg_esr;
>  
>         /* FIFO overflow */
>         if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_OVERFLOW) {
> 


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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

       reply	other threads:[~2016-05-06 10:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <14855451462460611@web29h.yandex.ru>
2016-05-06 10:26 ` Marc Kleine-Budde [this message]
2016-05-06 13:47   ` can: flexcan: patch Mikhail Kofanov
2016-05-06 15:56     ` Marc Kleine-Budde

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=572C7149.6040307@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=c5r@yandex.ru \
    --cc=linux-can@vger.kernel.org \
    /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).