linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andri Yngvason <andri.yngvason@marel.com>
To: linux-can@vger.kernel.org
Subject: [PATCH 2/4] Consolidate and unify state change handling
Date: Thu, 18 Sep 2014 16:38:29 +0000	[thread overview]
Message-ID: <541B0A85.4000906@marel.com> (raw)

Signed-off-by: Andri Yngvason <andri.yngvason@marel.com>
---
  drivers/net/can/flexcan.c | 66 
+++--------------------------------------------
  1 file changed, 3 insertions(+), 63 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 2700865..96a0755 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -559,74 +559,15 @@ static int flexcan_poll_bus_err(struct net_device 
*dev, u32 reg_esr)
  static void do_state(struct net_device *dev,
               struct can_frame *cf, enum can_state new_state)
  {
-    struct flexcan_priv *priv = netdev_priv(dev);
      struct can_berr_counter bec;

      __flexcan_get_berr_counter(dev, &bec);

-    switch (priv->can.state) {
-    case CAN_STATE_ERROR_ACTIVE:
-        /*
-         * from: ERROR_ACTIVE
-         * to  : ERROR_WARNING, ERROR_PASSIVE, BUS_OFF
-         * =>  : there was a warning int
-         */
-        if (new_state >= CAN_STATE_ERROR_WARNING &&
-            new_state <= CAN_STATE_BUS_OFF) {
-            netdev_dbg(dev, "Error Warning IRQ\n");
-            priv->can.can_stats.error_warning++;
-
-            cf->can_id |= CAN_ERR_CRTL;
-            cf->data[1] = (bec.txerr > bec.rxerr) ?
-                CAN_ERR_CRTL_TX_WARNING :
-                CAN_ERR_CRTL_RX_WARNING;
-        }
-    case CAN_STATE_ERROR_WARNING:    /* fallthrough */
-        /*
-         * from: ERROR_ACTIVE, ERROR_WARNING
-         * to  : ERROR_PASSIVE, BUS_OFF
-         * =>  : error passive int
-         */
-        if (new_state >= CAN_STATE_ERROR_PASSIVE &&
-            new_state <= CAN_STATE_BUS_OFF) {
-            netdev_dbg(dev, "Error Passive IRQ\n");
-            priv->can.can_stats.error_passive++;
-
-            cf->can_id |= CAN_ERR_CRTL;
-            cf->data[1] = (bec.txerr > bec.rxerr) ?
-                CAN_ERR_CRTL_TX_PASSIVE :
-                CAN_ERR_CRTL_RX_PASSIVE;
-        }
-        break;
-    case CAN_STATE_BUS_OFF:
-        netdev_err(dev, "BUG! "
-               "hardware recovered automatically from BUS_OFF\n");
-        break;
-    default:
-        break;
-    }
+    can_change_state(dev, cf, new_state,
+             can_get_err_dir(bec.rxerr, bec.txerr));

-    /* process state changes depending on the new state */
-    switch (new_state) {
-    case CAN_STATE_ERROR_WARNING:
-        netdev_dbg(dev, "Error Warning\n");
-        cf->can_id |= CAN_ERR_CRTL;
-        cf->data[1] = (bec.txerr > bec.rxerr) ?
-            CAN_ERR_CRTL_TX_WARNING :
-            CAN_ERR_CRTL_RX_WARNING;
-        break;
-    case CAN_STATE_ERROR_ACTIVE:
-        netdev_dbg(dev, "Error Active\n");
-        cf->can_id |= CAN_ERR_PROT;
-        cf->data[2] = CAN_ERR_PROT_ACTIVE;
-        break;
-    case CAN_STATE_BUS_OFF:
-        cf->can_id |= CAN_ERR_BUSOFF;
+    if (unlikely(new_state == CAN_STATE_BUS_OFF))
          can_bus_off(dev);
-        break;
-    default:
-        break;
-    }
  }

  static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
@@ -658,7 +599,6 @@ static int flexcan_poll_state(struct net_device 
*dev, u32 reg_esr)
          return 0;

      do_state(dev, cf, new_state);
-    priv->can.state = new_state;
      netif_receive_skb(skb);

      dev->stats.rx_packets++;

             reply	other threads:[~2014-09-18 16:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18 16:38 Andri Yngvason [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-09-18 16:25 [PATCH 2/4] Consolidate and unify state change handling Andri Yngvason
2014-09-19 21:10 ` Wolfgang Grandegger
2014-09-21 14:47   ` Andri Yngvason
2014-09-21 15:30     ` Wolfgang Grandegger
2014-09-21 17:27       ` Andri Yngvason
2014-09-23 20:33         ` Wolfgang Grandegger
2014-09-23 22:31           ` Oliver Hartkopp
2014-09-24  6:28             ` Wolfgang Grandegger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=541B0A85.4000906@marel.com \
    --to=andri.yngvason@marel.com \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).