Skip to content

Commit 602de7e

Browse files
committed
Merge tag 'linux-can-next-for-3.19-20141207' of git://gitorious.org/linux-can/linux-can-next
Marc Kleine-Budde says: ==================== pull-request: can-next 2014-12-07 this is a pull request of 8 patches for net-next/master. Andri Yngvason contributes 4 patches in which the CAN state change handling is consolidated and unified among the sja1000, mscan and flexcan driver. The three patches by Jeremiah Mahler fix spelling mistakes and eliminate the banner[] variable in various parts. And a patch by me that switches on sparse endianess checking by default. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 605ad7f + 71a3aed commit 602de7e

File tree

14 files changed

+154
-174
lines changed

14 files changed

+154
-174
lines changed

drivers/net/can/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ obj-$(CONFIG_CAN_GRCAN) += grcan.o
2929
obj-$(CONFIG_CAN_RCAR) += rcar_can.o
3030
obj-$(CONFIG_CAN_XILINXCAN) += xilinx_can.o
3131

32-
subdir-ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
32+
subdir-ccflags-y += -D__CHECK_ENDIAN__
33+
subdir-ccflags-$(CONFIG_CAN_DEBUG_DEVICES) += -DDEBUG

drivers/net/can/cc770/cc770.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ MODULE_DESCRIPTION(KBUILD_MODNAME "CAN netdevice driver");
6060
*
6161
* The message objects 1..14 can be used for TX and RX while the message
6262
* objects 15 is optimized for RX. It has a shadow register for reliable
63-
* data receiption under heavy bus load. Therefore it makes sense to use
63+
* data reception under heavy bus load. Therefore it makes sense to use
6464
* this message object for the needed use case. The frame type (EFF/SFF)
6565
* for the message object 15 can be defined via kernel module parameter
6666
* "msgobj15_eff". If not equal 0, it will receive 29-bit EFF frames,

drivers/net/can/dev.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,84 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
273273
return err;
274274
}
275275

276+
static void can_update_state_error_stats(struct net_device *dev,
277+
enum can_state new_state)
278+
{
279+
struct can_priv *priv = netdev_priv(dev);
280+
281+
if (new_state <= priv->state)
282+
return;
283+
284+
switch (new_state) {
285+
case CAN_STATE_ERROR_WARNING:
286+
priv->can_stats.error_warning++;
287+
break;
288+
case CAN_STATE_ERROR_PASSIVE:
289+
priv->can_stats.error_passive++;
290+
break;
291+
case CAN_STATE_BUS_OFF:
292+
default:
293+
break;
294+
};
295+
}
296+
297+
static int can_tx_state_to_frame(struct net_device *dev, enum can_state state)
298+
{
299+
switch (state) {
300+
case CAN_STATE_ERROR_ACTIVE:
301+
return CAN_ERR_CRTL_ACTIVE;
302+
case CAN_STATE_ERROR_WARNING:
303+
return CAN_ERR_CRTL_TX_WARNING;
304+
case CAN_STATE_ERROR_PASSIVE:
305+
return CAN_ERR_CRTL_TX_PASSIVE;
306+
default:
307+
return 0;
308+
}
309+
}
310+
311+
static int can_rx_state_to_frame(struct net_device *dev, enum can_state state)
312+
{
313+
switch (state) {
314+
case CAN_STATE_ERROR_ACTIVE:
315+
return CAN_ERR_CRTL_ACTIVE;
316+
case CAN_STATE_ERROR_WARNING:
317+
return CAN_ERR_CRTL_RX_WARNING;
318+
case CAN_STATE_ERROR_PASSIVE:
319+
return CAN_ERR_CRTL_RX_PASSIVE;
320+
default:
321+
return 0;
322+
}
323+
}
324+
325+
void can_change_state(struct net_device *dev, struct can_frame *cf,
326+
enum can_state tx_state, enum can_state rx_state)
327+
{
328+
struct can_priv *priv = netdev_priv(dev);
329+
enum can_state new_state = max(tx_state, rx_state);
330+
331+
if (unlikely(new_state == priv->state)) {
332+
netdev_warn(dev, "%s: oops, state did not change", __func__);
333+
return;
334+
}
335+
336+
netdev_dbg(dev, "New error state: %d\n", new_state);
337+
338+
can_update_state_error_stats(dev, new_state);
339+
priv->state = new_state;
340+
341+
if (unlikely(new_state == CAN_STATE_BUS_OFF)) {
342+
cf->can_id |= CAN_ERR_BUSOFF;
343+
return;
344+
}
345+
346+
cf->can_id |= CAN_ERR_CRTL;
347+
cf->data[1] |= tx_state >= rx_state ?
348+
can_tx_state_to_frame(dev, tx_state) : 0;
349+
cf->data[1] |= tx_state <= rx_state ?
350+
can_rx_state_to_frame(dev, rx_state) : 0;
351+
}
352+
EXPORT_SYMBOL_GPL(can_change_state);
353+
276354
/*
277355
* Local echo of CAN messages
278356
*

drivers/net/can/flexcan.c

Lines changed: 18 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -577,98 +577,30 @@ static int flexcan_poll_bus_err(struct net_device *dev, u32 reg_esr)
577577
return 1;
578578
}
579579

580-
static void do_state(struct net_device *dev,
581-
struct can_frame *cf, enum can_state new_state)
582-
{
583-
struct flexcan_priv *priv = netdev_priv(dev);
584-
struct can_berr_counter bec;
585-
586-
__flexcan_get_berr_counter(dev, &bec);
587-
588-
switch (priv->can.state) {
589-
case CAN_STATE_ERROR_ACTIVE:
590-
/*
591-
* from: ERROR_ACTIVE
592-
* to : ERROR_WARNING, ERROR_PASSIVE, BUS_OFF
593-
* => : there was a warning int
594-
*/
595-
if (new_state >= CAN_STATE_ERROR_WARNING &&
596-
new_state <= CAN_STATE_BUS_OFF) {
597-
netdev_dbg(dev, "Error Warning IRQ\n");
598-
priv->can.can_stats.error_warning++;
599-
600-
cf->can_id |= CAN_ERR_CRTL;
601-
cf->data[1] = (bec.txerr > bec.rxerr) ?
602-
CAN_ERR_CRTL_TX_WARNING :
603-
CAN_ERR_CRTL_RX_WARNING;
604-
}
605-
case CAN_STATE_ERROR_WARNING: /* fallthrough */
606-
/*
607-
* from: ERROR_ACTIVE, ERROR_WARNING
608-
* to : ERROR_PASSIVE, BUS_OFF
609-
* => : error passive int
610-
*/
611-
if (new_state >= CAN_STATE_ERROR_PASSIVE &&
612-
new_state <= CAN_STATE_BUS_OFF) {
613-
netdev_dbg(dev, "Error Passive IRQ\n");
614-
priv->can.can_stats.error_passive++;
615-
616-
cf->can_id |= CAN_ERR_CRTL;
617-
cf->data[1] = (bec.txerr > bec.rxerr) ?
618-
CAN_ERR_CRTL_TX_PASSIVE :
619-
CAN_ERR_CRTL_RX_PASSIVE;
620-
}
621-
break;
622-
case CAN_STATE_BUS_OFF:
623-
netdev_err(dev, "BUG! "
624-
"hardware recovered automatically from BUS_OFF\n");
625-
break;
626-
default:
627-
break;
628-
}
629-
630-
/* process state changes depending on the new state */
631-
switch (new_state) {
632-
case CAN_STATE_ERROR_WARNING:
633-
netdev_dbg(dev, "Error Warning\n");
634-
cf->can_id |= CAN_ERR_CRTL;
635-
cf->data[1] = (bec.txerr > bec.rxerr) ?
636-
CAN_ERR_CRTL_TX_WARNING :
637-
CAN_ERR_CRTL_RX_WARNING;
638-
break;
639-
case CAN_STATE_ERROR_ACTIVE:
640-
netdev_dbg(dev, "Error Active\n");
641-
cf->can_id |= CAN_ERR_PROT;
642-
cf->data[2] = CAN_ERR_PROT_ACTIVE;
643-
break;
644-
case CAN_STATE_BUS_OFF:
645-
cf->can_id |= CAN_ERR_BUSOFF;
646-
can_bus_off(dev);
647-
break;
648-
default:
649-
break;
650-
}
651-
}
652-
653580
static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
654581
{
655582
struct flexcan_priv *priv = netdev_priv(dev);
656583
struct sk_buff *skb;
657584
struct can_frame *cf;
658-
enum can_state new_state;
585+
enum can_state new_state = 0, rx_state = 0, tx_state = 0;
659586
int flt;
587+
struct can_berr_counter bec;
660588

661589
flt = reg_esr & FLEXCAN_ESR_FLT_CONF_MASK;
662590
if (likely(flt == FLEXCAN_ESR_FLT_CONF_ACTIVE)) {
663-
if (likely(!(reg_esr & (FLEXCAN_ESR_TX_WRN |
664-
FLEXCAN_ESR_RX_WRN))))
665-
new_state = CAN_STATE_ERROR_ACTIVE;
666-
else
667-
new_state = CAN_STATE_ERROR_WARNING;
668-
} else if (unlikely(flt == FLEXCAN_ESR_FLT_CONF_PASSIVE))
591+
tx_state = unlikely(reg_esr & FLEXCAN_ESR_TX_WRN) ?
592+
CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
593+
rx_state = unlikely(reg_esr & FLEXCAN_ESR_RX_WRN) ?
594+
CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
595+
new_state = max(tx_state, rx_state);
596+
} else if (unlikely(flt == FLEXCAN_ESR_FLT_CONF_PASSIVE)) {
597+
__flexcan_get_berr_counter(dev, &bec);
669598
new_state = CAN_STATE_ERROR_PASSIVE;
670-
else
599+
rx_state = bec.rxerr >= bec.txerr ? new_state : 0;
600+
tx_state = bec.rxerr <= bec.txerr ? new_state : 0;
601+
} else {
671602
new_state = CAN_STATE_BUS_OFF;
603+
}
672604

673605
/* state hasn't changed */
674606
if (likely(new_state == priv->can.state))
@@ -678,8 +610,11 @@ static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
678610
if (unlikely(!skb))
679611
return 0;
680612

681-
do_state(dev, cf, new_state);
682-
priv->can.state = new_state;
613+
can_change_state(dev, cf, tx_state, rx_state);
614+
615+
if (unlikely(new_state == CAN_STATE_BUS_OFF))
616+
can_bus_off(dev);
617+
683618
netif_receive_skb(skb);
684619

685620
dev->stats.rx_packets++;

drivers/net/can/mscan/mscan.c

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,15 @@ static netdev_tx_t mscan_start_xmit(struct sk_buff *skb, struct net_device *dev)
289289
return NETDEV_TX_OK;
290290
}
291291

292-
/* This function returns the old state to see where we came from */
293-
static enum can_state check_set_state(struct net_device *dev, u8 canrflg)
292+
static enum can_state get_new_state(struct net_device *dev, u8 canrflg)
294293
{
295294
struct mscan_priv *priv = netdev_priv(dev);
296-
enum can_state state, old_state = priv->can.state;
297295

298-
if (canrflg & MSCAN_CSCIF && old_state <= CAN_STATE_BUS_OFF) {
299-
state = state_map[max(MSCAN_STATE_RX(canrflg),
300-
MSCAN_STATE_TX(canrflg))];
301-
priv->can.state = state;
302-
}
303-
return old_state;
296+
if (unlikely(canrflg & MSCAN_CSCIF))
297+
return state_map[max(MSCAN_STATE_RX(canrflg),
298+
MSCAN_STATE_TX(canrflg))];
299+
300+
return priv->can.state;
304301
}
305302

306303
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,
349346
struct mscan_priv *priv = netdev_priv(dev);
350347
struct mscan_regs __iomem *regs = priv->reg_base;
351348
struct net_device_stats *stats = &dev->stats;
352-
enum can_state old_state;
349+
enum can_state new_state;
353350

354351
netdev_dbg(dev, "error interrupt (canrflg=%#x)\n", canrflg);
355352
frame->can_id = CAN_ERR_FLAG;
@@ -363,27 +360,13 @@ static void mscan_get_err_frame(struct net_device *dev, struct can_frame *frame,
363360
frame->data[1] = 0;
364361
}
365362

366-
old_state = check_set_state(dev, canrflg);
367-
/* State changed */
368-
if (old_state != priv->can.state) {
369-
switch (priv->can.state) {
370-
case CAN_STATE_ERROR_WARNING:
371-
frame->can_id |= CAN_ERR_CRTL;
372-
priv->can.can_stats.error_warning++;
373-
if ((priv->shadow_statflg & MSCAN_RSTAT_MSK) <
374-
(canrflg & MSCAN_RSTAT_MSK))
375-
frame->data[1] |= CAN_ERR_CRTL_RX_WARNING;
376-
if ((priv->shadow_statflg & MSCAN_TSTAT_MSK) <
377-
(canrflg & MSCAN_TSTAT_MSK))
378-
frame->data[1] |= CAN_ERR_CRTL_TX_WARNING;
379-
break;
380-
case CAN_STATE_ERROR_PASSIVE:
381-
frame->can_id |= CAN_ERR_CRTL;
382-
priv->can.can_stats.error_passive++;
383-
frame->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
384-
break;
385-
case CAN_STATE_BUS_OFF:
386-
frame->can_id |= CAN_ERR_BUSOFF;
363+
new_state = get_new_state(dev, canrflg);
364+
if (new_state != priv->can.state) {
365+
can_change_state(dev, frame,
366+
state_map[MSCAN_STATE_TX(canrflg)],
367+
state_map[MSCAN_STATE_RX(canrflg)]);
368+
369+
if (priv->can.state == CAN_STATE_BUS_OFF) {
387370
/*
388371
* The MSCAN on the MPC5200 does recover from bus-off
389372
* 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,
396379
MSCAN_SLPRQ | MSCAN_INITRQ);
397380
}
398381
can_bus_off(dev);
399-
break;
400-
default:
401-
break;
402382
}
403383
}
404384
priv->shadow_statflg = canrflg & MSCAN_STAT_MSK;

drivers/net/can/sja1000/sja1000.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,20 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
392392
struct can_frame *cf;
393393
struct sk_buff *skb;
394394
enum can_state state = priv->can.state;
395+
enum can_state rx_state, tx_state;
396+
unsigned int rxerr, txerr;
395397
uint8_t ecc, alc;
396398

397399
skb = alloc_can_err_skb(dev, &cf);
398400
if (skb == NULL)
399401
return -ENOMEM;
400402

403+
txerr = priv->read_reg(priv, SJA1000_TXERR);
404+
rxerr = priv->read_reg(priv, SJA1000_RXERR);
405+
406+
cf->data[6] = txerr;
407+
cf->data[7] = rxerr;
408+
401409
if (isrc & IRQ_DOI) {
402410
/* data overrun interrupt */
403411
netdev_dbg(dev, "data overrun interrupt\n");
@@ -412,13 +420,11 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
412420
/* error warning interrupt */
413421
netdev_dbg(dev, "error warning interrupt\n");
414422

415-
if (status & SR_BS) {
423+
if (status & SR_BS)
416424
state = CAN_STATE_BUS_OFF;
417-
cf->can_id |= CAN_ERR_BUSOFF;
418-
can_bus_off(dev);
419-
} else if (status & SR_ES) {
425+
else if (status & SR_ES)
420426
state = CAN_STATE_ERROR_WARNING;
421-
} else
427+
else
422428
state = CAN_STATE_ERROR_ACTIVE;
423429
}
424430
if (isrc & IRQ_BEI) {
@@ -452,10 +458,11 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
452458
if (isrc & IRQ_EPI) {
453459
/* error passive interrupt */
454460
netdev_dbg(dev, "error passive interrupt\n");
455-
if (status & SR_ES)
456-
state = CAN_STATE_ERROR_PASSIVE;
461+
462+
if (state == CAN_STATE_ERROR_PASSIVE)
463+
state = CAN_STATE_ERROR_WARNING;
457464
else
458-
state = CAN_STATE_ERROR_ACTIVE;
465+
state = CAN_STATE_ERROR_PASSIVE;
459466
}
460467
if (isrc & IRQ_ALI) {
461468
/* arbitration lost interrupt */
@@ -467,27 +474,15 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
467474
cf->data[0] = alc & 0x1f;
468475
}
469476

470-
if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
471-
state == CAN_STATE_ERROR_PASSIVE)) {
472-
uint8_t rxerr = priv->read_reg(priv, SJA1000_RXERR);
473-
uint8_t txerr = priv->read_reg(priv, SJA1000_TXERR);
474-
cf->can_id |= CAN_ERR_CRTL;
475-
if (state == CAN_STATE_ERROR_WARNING) {
476-
priv->can.can_stats.error_warning++;
477-
cf->data[1] = (txerr > rxerr) ?
478-
CAN_ERR_CRTL_TX_WARNING :
479-
CAN_ERR_CRTL_RX_WARNING;
480-
} else {
481-
priv->can.can_stats.error_passive++;
482-
cf->data[1] = (txerr > rxerr) ?
483-
CAN_ERR_CRTL_TX_PASSIVE :
484-
CAN_ERR_CRTL_RX_PASSIVE;
485-
}
486-
cf->data[6] = txerr;
487-
cf->data[7] = rxerr;
488-
}
477+
if (state != priv->can.state) {
478+
tx_state = txerr >= rxerr ? state : 0;
479+
rx_state = txerr <= rxerr ? state : 0;
489480

490-
priv->can.state = state;
481+
can_change_state(dev, cf, tx_state, rx_state);
482+
483+
if(state == CAN_STATE_BUS_OFF)
484+
can_bus_off(dev);
485+
}
491486

492487
netif_rx(skb);
493488

0 commit comments

Comments
 (0)