can: mscan: Consolidate and unify state change handling
Replacing error state change handling with the new mechanism. Signed-off-by: Andri Yngvason <andri.yngvason@marel.com> Acked-by: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
parent
215db1856e
commit
b12a43e6dd
|
@ -289,18 +289,15 @@ static netdev_tx_t mscan_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function returns the old state to see where we came from */
|
static enum can_state get_new_state(struct net_device *dev, u8 canrflg)
|
||||||
static enum can_state check_set_state(struct net_device *dev, u8 canrflg)
|
|
||||||
{
|
{
|
||||||
struct mscan_priv *priv = netdev_priv(dev);
|
struct mscan_priv *priv = netdev_priv(dev);
|
||||||
enum can_state state, old_state = priv->can.state;
|
|
||||||
|
|
||||||
if (canrflg & MSCAN_CSCIF && old_state <= CAN_STATE_BUS_OFF) {
|
if (unlikely(canrflg & MSCAN_CSCIF))
|
||||||
state = state_map[max(MSCAN_STATE_RX(canrflg),
|
return state_map[max(MSCAN_STATE_RX(canrflg),
|
||||||
MSCAN_STATE_TX(canrflg))];
|
MSCAN_STATE_TX(canrflg))];
|
||||||
priv->can.state = state;
|
|
||||||
}
|
return priv->can.state;
|
||||||
return old_state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame)
|
static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame)
|
||||||
|
@ -349,7 +346,7 @@ static void mscan_get_err_frame(struct net_device *dev, struct can_frame *frame,
|
||||||
struct mscan_priv *priv = netdev_priv(dev);
|
struct mscan_priv *priv = netdev_priv(dev);
|
||||||
struct mscan_regs __iomem *regs = priv->reg_base;
|
struct mscan_regs __iomem *regs = priv->reg_base;
|
||||||
struct net_device_stats *stats = &dev->stats;
|
struct net_device_stats *stats = &dev->stats;
|
||||||
enum can_state old_state;
|
enum can_state new_state;
|
||||||
|
|
||||||
netdev_dbg(dev, "error interrupt (canrflg=%#x)\n", canrflg);
|
netdev_dbg(dev, "error interrupt (canrflg=%#x)\n", canrflg);
|
||||||
frame->can_id = CAN_ERR_FLAG;
|
frame->can_id = CAN_ERR_FLAG;
|
||||||
|
@ -363,27 +360,13 @@ static void mscan_get_err_frame(struct net_device *dev, struct can_frame *frame,
|
||||||
frame->data[1] = 0;
|
frame->data[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_state = check_set_state(dev, canrflg);
|
new_state = get_new_state(dev, canrflg);
|
||||||
/* State changed */
|
if (new_state != priv->can.state) {
|
||||||
if (old_state != priv->can.state) {
|
can_change_state(dev, frame,
|
||||||
switch (priv->can.state) {
|
state_map[MSCAN_STATE_TX(canrflg)],
|
||||||
case CAN_STATE_ERROR_WARNING:
|
state_map[MSCAN_STATE_RX(canrflg)]);
|
||||||
frame->can_id |= CAN_ERR_CRTL;
|
|
||||||
priv->can.can_stats.error_warning++;
|
if (priv->can.state == CAN_STATE_BUS_OFF) {
|
||||||
if ((priv->shadow_statflg & MSCAN_RSTAT_MSK) <
|
|
||||||
(canrflg & MSCAN_RSTAT_MSK))
|
|
||||||
frame->data[1] |= CAN_ERR_CRTL_RX_WARNING;
|
|
||||||
if ((priv->shadow_statflg & MSCAN_TSTAT_MSK) <
|
|
||||||
(canrflg & MSCAN_TSTAT_MSK))
|
|
||||||
frame->data[1] |= CAN_ERR_CRTL_TX_WARNING;
|
|
||||||
break;
|
|
||||||
case CAN_STATE_ERROR_PASSIVE:
|
|
||||||
frame->can_id |= CAN_ERR_CRTL;
|
|
||||||
priv->can.can_stats.error_passive++;
|
|
||||||
frame->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
|
|
||||||
break;
|
|
||||||
case CAN_STATE_BUS_OFF:
|
|
||||||
frame->can_id |= CAN_ERR_BUSOFF;
|
|
||||||
/*
|
/*
|
||||||
* The MSCAN on the MPC5200 does recover from bus-off
|
* The MSCAN on the MPC5200 does recover from bus-off
|
||||||
* automatically. To avoid that we stop the chip doing
|
* automatically. To avoid that we stop the chip doing
|
||||||
|
@ -396,9 +379,6 @@ static void mscan_get_err_frame(struct net_device *dev, struct can_frame *frame,
|
||||||
MSCAN_SLPRQ | MSCAN_INITRQ);
|
MSCAN_SLPRQ | MSCAN_INITRQ);
|
||||||
}
|
}
|
||||||
can_bus_off(dev);
|
can_bus_off(dev);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
priv->shadow_statflg = canrflg & MSCAN_STAT_MSK;
|
priv->shadow_statflg = canrflg & MSCAN_STAT_MSK;
|
||||||
|
|
Loading…
Reference in New Issue