]> git.itanic.dy.fi Git - linux-stable/commitdiff
can: at91_can: at91_irq_err_line(): make use of can_state_get_by_berr_counter()
authorMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 1 May 2023 16:14:41 +0000 (18:14 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 5 Oct 2023 19:47:16 +0000 (21:47 +0200)
On the sam9263 the SR bits for bus off, error passive, warning limit,
and error active are not latched and reflect the current status of the
controller. On the sam9x5 and newer SoCs these bits are latched.

To simplify the code, use can_state_get_by_berr_counter() to get the
state of the controller regardless of the SoC version.

Link: https://lore.kernel.org/all/20231005-at91_can-rx_offload-v2-22-9987d53600e0@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/at91_can.c

index 4249a1c95769d9d7c7f8599019c9e2e1fa60d57b..68b611d0fa6cf8d3e78be78c7522df8c4c596813 100644 (file)
@@ -932,58 +932,17 @@ static void at91_irq_err_state(struct net_device *dev,
        at91_write(priv, AT91_IER, reg_ier);
 }
 
-static int at91_get_state_by_bec(const struct net_device *dev,
-                                enum can_state *state)
-{
-       struct can_berr_counter bec;
-       int err;
-
-       err = at91_get_berr_counter(dev, &bec);
-       if (err)
-               return err;
-
-       if (bec.txerr < 96 && bec.rxerr < 96)
-               *state = CAN_STATE_ERROR_ACTIVE;
-       else if (bec.txerr < 128 && bec.rxerr < 128)
-               *state = CAN_STATE_ERROR_WARNING;
-       else if (bec.txerr < 256 && bec.rxerr < 256)
-               *state = CAN_STATE_ERROR_PASSIVE;
-       else
-               *state = CAN_STATE_BUS_OFF;
-
-       return 0;
-}
-
 static void at91_irq_err_line(struct net_device *dev)
 {
+       enum can_state new_state, rx_state, tx_state;
        struct at91_priv *priv = netdev_priv(dev);
+       struct can_berr_counter bec;
        struct sk_buff *skb;
        struct can_frame *cf;
-       enum can_state new_state;
-       u32 reg_sr;
-       int err;
 
-       if (at91_is_sam9263(priv)) {
-               reg_sr = at91_read(priv, AT91_SR);
-
-               /* we need to look at the unmasked reg_sr */
-               if (unlikely(reg_sr & AT91_IRQ_BOFF)) {
-                       new_state = CAN_STATE_BUS_OFF;
-               } else if (unlikely(reg_sr & AT91_IRQ_ERRP)) {
-                       new_state = CAN_STATE_ERROR_PASSIVE;
-               } else if (unlikely(reg_sr & AT91_IRQ_WARN)) {
-                       new_state = CAN_STATE_ERROR_WARNING;
-               } else if (likely(reg_sr & AT91_IRQ_ERRA)) {
-                       new_state = CAN_STATE_ERROR_ACTIVE;
-               } else {
-                       netdev_err(dev, "BUG! hardware in undefined state\n");
-                       return;
-               }
-       } else {
-               err = at91_get_state_by_bec(dev, &new_state);
-               if (err)
-                       return;
-       }
+       at91_get_berr_counter(dev, &bec);
+       can_state_get_by_berr_counter(dev, &bec, &tx_state, &rx_state);
+       new_state = max(tx_state, rx_state);
 
        /* state hasn't changed */
        if (likely(new_state == priv->can.state))