From: Marc Kleine-Budde Date: Mon, 1 May 2023 16:14:41 +0000 (+0200) Subject: can: at91_can: at91_irq_err_line(): make use of can_state_get_by_berr_counter() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=910f179aa0de17bab654291548aec378f74db293;p=linux.git can: at91_can: at91_irq_err_line(): make use of can_state_get_by_berr_counter() 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 --- diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c index 4249a1c95769d..68b611d0fa6cf 100644 --- a/drivers/net/can/at91_can.c +++ b/drivers/net/can/at91_can.c @@ -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))