* Re: can: flexcan: patch
[not found] <14855451462460611@web29h.yandex.ru>
@ 2016-05-06 10:26 ` Marc Kleine-Budde
2016-05-06 13:47 ` Mikhail Kofanov
0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2016-05-06 10:26 UTC (permalink / raw)
To: Mikhail Kofanov; +Cc: linux-can
[-- 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(®s->esr) | priv->reg_esr;
> + reg_esr = flexcan_read(®s->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, ®s->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, ®s->imask1);
> flexcan_write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
> ®s->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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: can: flexcan: patch
2016-05-06 10:26 ` can: flexcan: patch Marc Kleine-Budde
@ 2016-05-06 13:47 ` Mikhail Kofanov
2016-05-06 15:56 ` Marc Kleine-Budde
0 siblings, 1 reply; 3+ messages in thread
From: Mikhail Kofanov @ 2016-05-06 13:47 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can
https://git.kernel.org/cgit/linux/kernel/git/mkl/linux-can-next.git/tree/?id=ffd461f80d536336811d573f197f3e6d9872d054
06.05.2016, 13:26, "Marc Kleine-Budde" <mkl@pengutronix.de>:
> 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(®s->esr) | priv->reg_esr;
>> + reg_esr = flexcan_read(®s->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, ®s->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, ®s->imask1);
>> flexcan_write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
>> ®s->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 |
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: can: flexcan: patch
2016-05-06 13:47 ` Mikhail Kofanov
@ 2016-05-06 15:56 ` Marc Kleine-Budde
0 siblings, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2016-05-06 15:56 UTC (permalink / raw)
To: Mikhail Kofanov; +Cc: linux-can
[-- Attachment #1.1: Type: text/plain, Size: 1115 bytes --]
On 05/06/2016 03:47 PM, Mikhail Kofanov wrote:
> https://git.kernel.org/cgit/linux/kernel/git/mkl/linux-can-next.git/tree/?id=ffd461f80d536336811d573f197f3e6d9872d054
The patch does not apply, as your mailer converted all tabs to spaces
and capped long lines....See below:
>>> /* 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
--
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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-06 15:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <14855451462460611@web29h.yandex.ru>
2016-05-06 10:26 ` can: flexcan: patch Marc Kleine-Budde
2016-05-06 13:47 ` Mikhail Kofanov
2016-05-06 15:56 ` Marc Kleine-Budde
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).