can: flexcan: patch
Marc Kleine-Budde
maintainerQuoted 7 lines · Mikhail Kofanov
Hello!
There is small patch for imx flexcan driver.
1. Improve state change handling
2. add tx/rx error counter to state change error frameTested on imx25 based custom board.
Against which kernel version does this patch apply?
Quoted 59 lines
drivers/net/can/flexcan.c +9
-2@@ -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); +
drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 739
Quoted 10 lines
drivers/net/can/flexcan.c +3
-1/* 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
Quoted 18 lines
drivers/net/can/flexcan.c +3
-1flexcan_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 ) {
Signature · 4 lines
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 |
06.05.2016, 13:26, "Marc Kleine-Budde" <[email protected]>:
Quoted 109 lines · Mikhail Kofanov
Quoted 7 lines
Hello!
There is small patch for imx flexcan driver.
1. Improve state change handling
2. add tx/rx error counter to state change error frameTested on imx25 based custom board.
Against which kernel version does this patch apply?
Quoted 58 lines
diff --git
a/drivers/net/can/flexcan.cb/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 intflexcan_poll_state(struct net_device *dev, u32 reg_esr)structflexcan_priv*priv =netdev_priv(dev);
structsk_buff*skb;
structcan_frame*cf;
+ structflexcan_regs__iomem*regs =priv->regs;
enumcan_statenew_state= 0,rx_state= 0,tx_state= 0;
int flt;
structcan_berr_counterbec;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 intflexcan_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 intflexcan_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 intflexcan_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 intflexcan_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 @@ staticirqreturn_tflexcan_irq(int irq, void *dev_id)if (reg_esr&FLEXCAN_ESR_ALL_INT)flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, ®s->esr);Quoted 11 lines
+
/* 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_MASThere seems to be a problem with this mail, the rest of this line is missing.
Marc
Quoted 15 lines
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;Quoted 2 lines
/* 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 |
Marc Kleine-Budde
maintainerQuoted 1 line · Mikhail Kofanov
The patch does not apply, as your mailer converted all tabs to spaces and capped long lines....See below:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
/* 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
Signature · 4 lines
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 |