can: move can_stats.bus_off++ from can_bus_off into can_change_state
authorAndri Yngvason <andri.yngvason@marel.com>
Fri, 16 Jan 2015 14:30:28 +0000 (14:30 +0000)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 20 Jan 2015 12:56:53 +0000 (13:56 +0100)
In order to be able to move the stats increment from can_bus_off() into
can_change_state(), the increment had to be moved back into code that was using
can_bus_off() but not can_change_state().

As a side-effect, this patch fixes the following bugs:
 * Redundant call to can_bus_off() in c_can.
 * Bus-off counted twice in xilinx_can.

Signed-off-by: Andri Yngvason <andri.yngvason@marel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
16 files changed:
drivers/net/can/bfin_can.c
drivers/net/can/c_can/c_can.c
drivers/net/can/cc770/cc770.c
drivers/net/can/dev.c
drivers/net/can/janz-ican3.c
drivers/net/can/m_can/m_can.c
drivers/net/can/pch_can.c
drivers/net/can/rcar_can.c
drivers/net/can/softing/softing_main.c
drivers/net/can/spi/mcp251x.c
drivers/net/can/ti_hecc.c
drivers/net/can/usb/ems_usb.c
drivers/net/can/usb/esd_usb2.c
drivers/net/can/usb/peak_usb/pcan_usb.c
drivers/net/can/usb/peak_usb/pcan_usb_pro.c
drivers/net/can/usb/usb_8dev.c

index 417d50998e314f8c440c401b20383af03ece00e2..e7a6363e736b6f2b35256dfd8fb957cf62abdbe0 100644 (file)
@@ -352,6 +352,7 @@ static int bfin_can_err(struct net_device *dev, u16 isrc, u16 status)
                netdev_dbg(dev, "bus-off mode interrupt\n");
                state = CAN_STATE_BUS_OFF;
                cf->can_id |= CAN_ERR_BUSOFF;
+               priv->can.can_stats.bus_off++;
                can_bus_off(dev);
        }
 
index f94a9fa60488ed8e23523f5f8c3665133f039dbb..70f77e96d409ea13c87ce9a280b4f73103a6c361 100644 (file)
@@ -866,7 +866,7 @@ static int c_can_handle_state_change(struct net_device *dev,
        case C_CAN_BUS_OFF:
                /* bus-off state */
                priv->can.state = CAN_STATE_BUS_OFF;
-               can_bus_off(dev);
+               priv->can.can_stats.bus_off++;
                break;
        default:
                break;
index c486fe510f370957944f9082e1712cfa3cb7aa8f..c11d4498403617e4dddcea42d085e08355c9a5d2 100644 (file)
@@ -535,6 +535,7 @@ static int cc770_err(struct net_device *dev, u8 status)
                cc770_write_reg(priv, control, CTRL_INI);
                cf->can_id |= CAN_ERR_BUSOFF;
                priv->can.state = CAN_STATE_BUS_OFF;
+               priv->can.can_stats.bus_off++;
                can_bus_off(dev);
        } else if (status & STAT_WARN) {
                cf->can_id |= CAN_ERR_CRTL;
index 3ec8f6f25e5f979e16838930295fe4cd66b2841c..e54dbc1a76ba0ddc12f9a4e1de110758fa868f0f 100644 (file)
@@ -289,6 +289,8 @@ static void can_update_state_error_stats(struct net_device *dev,
                priv->can_stats.error_passive++;
                break;
        case CAN_STATE_BUS_OFF:
+               priv->can_stats.bus_off++;
+               break;
        default:
                break;
        };
@@ -544,7 +546,6 @@ void can_bus_off(struct net_device *dev)
        netdev_dbg(dev, "bus-off\n");
 
        netif_carrier_off(dev);
-       priv->can_stats.bus_off++;
 
        if (priv->restart_ms)
                mod_timer(&priv->restart_timer,
index 1b118394907f0ef46c20e24b778bc9ce56e40b7b..0eb4d181ae4d2e50a6790e138e8dae2a60739b8e 100644 (file)
@@ -1008,6 +1008,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)
                if (status & SR_BS) {
                        state = CAN_STATE_BUS_OFF;
                        cf->can_id |= CAN_ERR_BUSOFF;
+                       mod->can.can_stats.bus_off++;
                        can_bus_off(dev);
                } else if (status & SR_ES) {
                        if (rxerr >= 128 || txerr >= 128)
index d7bc462aafdc27a26774aa6cb6cadb0e0d8547a3..b2ecb6c5e94b8b0a8251e5a6c10d528c579be6be 100644 (file)
@@ -589,6 +589,7 @@ static int m_can_handle_state_change(struct net_device *dev,
                /* bus-off state */
                priv->can.state = CAN_STATE_BUS_OFF;
                m_can_disable_all_interrupts(priv);
+               priv->can.can_stats.bus_off++;
                can_bus_off(dev);
                break;
        default:
index a67eb01f3028fee64837fae7878a6b78c2728d6c..e187ca783da0946def7585ff8d85ac76ea201e05 100644 (file)
@@ -505,6 +505,7 @@ static void pch_can_error(struct net_device *ndev, u32 status)
                pch_can_set_rx_all(priv, 0);
                state = CAN_STATE_BUS_OFF;
                cf->can_id |= CAN_ERR_BUSOFF;
+               priv->can.can_stats.bus_off++;
                can_bus_off(ndev);
        }
 
index 91cd48ca0efcf59c768155aa7ac517998eabbee4..7deb80dcbe8c09b669f15e3f5dfb3af3fc72598e 100644 (file)
@@ -331,6 +331,7 @@ static void rcar_can_error(struct net_device *ndev)
                priv->can.state = CAN_STATE_BUS_OFF;
                /* Clear interrupt condition */
                writeb(~RCAR_CAN_EIFR_BOEIF, &priv->regs->eifr);
+               priv->can.can_stats.bus_off++;
                can_bus_off(ndev);
                if (skb)
                        cf->can_id |= CAN_ERR_BUSOFF;
index 2bf98d862302eba41eaa6c4495c787d24451814c..7621f91a8a209e9de74d55de14fbb31947c449ee 100644 (file)
@@ -261,6 +261,7 @@ static int softing_handle_1(struct softing *card)
                                ++priv->can.can_stats.error_passive;
                        else if (can_state == CAN_STATE_BUS_OFF) {
                                /* this calls can_close_cleanup() */
+                               ++priv->can.can_stats.bus_off;
                                can_bus_off(netdev);
                                netif_stop_queue(netdev);
                        }
index c66d699640a9c1478026da5df023264a7b1ff973..bf63fee4e743a4c63c59de2445ef1ad651baa7c2 100644 (file)
@@ -905,6 +905,7 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
                if (priv->can.state == CAN_STATE_BUS_OFF) {
                        if (priv->can.restart_ms == 0) {
                                priv->force_quit = 1;
+                               priv->can.can_stats.bus_off++;
                                can_bus_off(net);
                                mcp251x_hw_sleep(spi);
                                break;
index 9a07eafe554b146135505aa50ca15361bac85921..e95a9e1a889f19c4673d9735e5e932eb83340767 100644 (file)
@@ -715,6 +715,7 @@ static int ti_hecc_error(struct net_device *ndev, int int_status,
                hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
                /* Disable all interrupts in bus-off to avoid int hog */
                hecc_write(priv, HECC_CANGIM, 0);
+               ++priv->can.can_stats.bus_off;
                can_bus_off(ndev);
        }
 
index 29d3f0938eb836b4da53a0898f574ebf42721ae2..9376f5e5b94ed2956c85808c5642ccbdb34036bd 100644 (file)
@@ -347,6 +347,7 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
                        dev->can.state = CAN_STATE_BUS_OFF;
                        cf->can_id |= CAN_ERR_BUSOFF;
 
+                       dev->can.can_stats.bus_off++;
                        can_bus_off(dev->netdev);
                } else if (state & SJA1000_SR_ES) {
                        dev->can.state = CAN_STATE_ERROR_WARNING;
index c063a54ab8dd8a598f36e5a7e712722bb5931df1..bacca0bd89c1ffc515bb352b73d4801de30c9f4a 100644 (file)
@@ -250,6 +250,7 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv,
                        case ESD_BUSSTATE_BUSOFF:
                                priv->can.state = CAN_STATE_BUS_OFF;
                                cf->can_id |= CAN_ERR_BUSOFF;
+                               priv->can.can_stats.bus_off++;
                                can_bus_off(priv->netdev);
                                break;
                        case ESD_BUSSTATE_WARN:
index 4e1659d07979b77e231040509608b043dba4841b..2a1c9ce53fae083b34fb6d14fda73636dd3a1f57 100644 (file)
@@ -488,6 +488,7 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
        switch (new_state) {
        case CAN_STATE_BUS_OFF:
                cf->can_id |= CAN_ERR_BUSOFF;
+               mc->pdev->dev.can.can_stats.bus_off++;
                can_bus_off(mc->netdev);
                break;
 
index 4cfa3b8605b19f08ecdeed869f2874e72957d5b7..145fa87c31b9721238a0a4ebb74efa6ebe626b03 100644 (file)
@@ -634,6 +634,7 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if,
        switch (new_state) {
        case CAN_STATE_BUS_OFF:
                can_frame->can_id |= CAN_ERR_BUSOFF;
+               dev->can.can_stats.bus_off++;
                can_bus_off(netdev);
                break;
 
index ef674ecb82f8e64ef3b57de77626ff31c67e1ba5..dd52c7a4c80d9f26faa74ece8d109ee21045ba47 100644 (file)
@@ -377,6 +377,7 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,
        case USB_8DEV_STATUSMSG_BUSOFF:
                priv->can.state = CAN_STATE_BUS_OFF;
                cf->can_id |= CAN_ERR_BUSOFF;
+               priv->can.can_stats.bus_off++;
                can_bus_off(priv->netdev);
                break;
        case USB_8DEV_STATUSMSG_OVERRUN: