summaryrefslogtreecommitdiff
path: root/drivers/net
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2023-05-01 18:14:41 +0200
committerMarc Kleine-Budde <mkl@pengutronix.de>2023-10-05 21:47:16 +0200
commit910f179aa0de17bab654291548aec378f74db293 (patch)
tree3166a7c28491d14122edec0a3f4aaf12eff6d9aa /drivers/net
parentefad777c3e97472fbd6aa4e5db11dcb3ef3eae90 (diff)
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 <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/can/at91_can.c51
1 files changed, 5 insertions, 46 deletions
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index 4249a1c95769..68b611d0fa6c 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))