23 #include <linux/kernel.h>
24 #include <linux/module.h>
27 #include <linux/netdevice.h>
28 #include <linux/if_arp.h>
29 #include <linux/if_ether.h>
30 #include <linux/list.h>
80 setbits8(®s->
canctl0, MSCAN_SLPRQ);
97 if (i >= MSCAN_SET_MODE_RETRIES)
99 "device failed to enter sleep mode. "
100 "We proceed anyhow.\n");
106 setbits8(®s->
canctl0, MSCAN_INITRQ);
111 if (i >= MSCAN_SET_MODE_RETRIES)
118 setbits8(®s->
canctl0, MSCAN_CSWAI);
122 if (canctl1 & (MSCAN_SLPAK | MSCAN_INITAK)) {
123 clrbits8(®s->
canctl0, MSCAN_SLPRQ | MSCAN_INITRQ);
126 if (!(canctl1 & (MSCAN_INITAK | MSCAN_SLPAK)))
129 if (i >= MSCAN_SET_MODE_RETRIES)
138 static int mscan_start(
struct net_device *dev)
147 INIT_LIST_HEAD(&priv->
tx_head);
176 static int mscan_restart(
struct net_device *dev)
185 "bus-off state expected\n");
192 return mscan_start(dev);
206 if (can_dropped_invalid_skb(dev, skb))
215 netif_stop_queue(dev);
216 netdev_err(dev,
"Tx Ring full when queue awake!\n");
223 netif_stop_queue(dev);
225 if (buf_id < priv->prev_buf_id) {
229 netif_stop_queue(dev);
250 can_id = (can_id & 0x7) | ((can_id << 2) & 0xffe0)
315 if (can_id & (1 << 3)) {
317 can_id = ((can_id << 16) |
in_be16(®s->
rx.idr3_2));
318 can_id = ((can_id & 0xffe00000) |
319 ((can_id & 0x7ffff) << 2)) >> 2;
325 frame->
can_id |= can_id >> 1;
333 u16 *payload = (
u16 *)frame->data;
355 netdev_dbg(dev,
"error interrupt (canrflg=%#x)\n", canrflg);
367 old_state = check_set_state(dev, canrflg);
369 if (old_state != priv->
can.state) {
370 switch (priv->
can.state) {
373 priv->
can.can_stats.error_warning++;
383 priv->
can.can_stats.error_passive++;
397 MSCAN_SLPRQ | MSCAN_INITRQ);
422 while (npackets < quota) {
429 if (printk_ratelimit())
430 netdev_notice(dev,
"packet dropped\n");
437 mscan_get_rx_frame(dev, frame);
439 mscan_get_err_frame(dev, frame, canrflg);
463 u8 cantier, cantflg, canrflg;
469 if (cantier && cantflg) {
477 if (!(cantflg & mask))
488 if (list_empty(&priv->
tx_head)) {
497 netif_wake_queue(dev);
504 if ((canrflg & ~MSCAN_STAT_MSK) &&
506 if (canrflg & ~MSCAN_STAT_MSK) {
509 napi_schedule(&priv->
napi);
528 ret = mscan_restart(dev);
531 if (netif_queue_stopped(dev))
532 netif_wake_queue(dev);
542 static int mscan_do_set_bittiming(
struct net_device *dev)
554 netdev_info(dev,
"setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
562 static int mscan_get_berr_counter(
const struct net_device *dev,
585 napi_enable(&priv->
napi);
589 netdev_err(dev,
"failed to attach interrupt\n");
590 goto exit_napi_disable;
600 ret = mscan_start(dev);
604 netif_start_queue(dev);
612 napi_disable(&priv->
napi);
617 static int mscan_close(
struct net_device *dev)
622 netif_stop_queue(dev);
623 napi_disable(&priv->
napi);
636 .ndo_open = mscan_open,
637 .ndo_stop = mscan_close,
638 .ndo_start_xmit = mscan_start_xmit,
654 priv->
can.do_get_berr_counter = mscan_get_berr_counter;
698 priv = netdev_priv(dev);
706 priv->
can.bittiming_const = &mscan_bittiming_const;
707 priv->
can.do_set_bittiming = mscan_do_set_bittiming;
708 priv->
can.do_set_mode = mscan_do_set_mode;