16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/types.h>
23 #include <linux/fcntl.h>
25 #include <linux/ptrace.h>
26 #include <linux/string.h>
27 #include <linux/errno.h>
28 #include <linux/netdevice.h>
29 #include <linux/if_arp.h>
30 #include <linux/if_ether.h>
69 static int msgobj15_eff;
71 MODULE_PARM_DESC(msgobj15_eff,
"Extended 29-bit frames for message object 15 "
72 "(default: 11-bit standard frames)");
74 static int i82527_compat;
77 "without using additional functions");
94 .name = KBUILD_MODNAME,
105 static inline int intid2obj(
unsigned int intid)
133 "RX data, RTR, SFF and EFF\n", mo);
136 "Message object %d for RX %s %s\n",
155 if (obj_flags & CC770_OBJ_FLAG_RTR)
165 "TX data, RTR, SFF and EFF\n", mo);
177 static void disable_all_objs(
const struct cc770_priv *priv)
184 if (priv->
obj_flags[o] & CC770_OBJ_FLAG_RX) {
206 static void set_reset_mode(
struct net_device *dev)
222 disable_all_objs(priv);
225 static void set_normal_mode(
struct net_device *dev)
236 enable_all_objs(dev);
247 static void chipset_init(
struct cc770_priv *priv)
280 for (data = 0; data < 8; data++)
282 for (
id = 0;
id < 4;
id++)
297 static int cc770_probe_chip(
struct net_device *dev)
311 netdev_info(dev,
"probing @0x%p failed (reset)\n",
323 netdev_info(dev,
"probing @0x%p failed (pattern)\n",
335 static void cc770_start(
struct net_device *dev)
344 set_normal_mode(dev);
352 netif_wake_queue(dev);
362 static int cc770_set_bittiming(
struct net_device *dev)
368 btr0 = ((bt->
brp - 1) & 0x3f) | (((bt->
sjw - 1) & 0x3) << 6);
374 netdev_info(dev,
"setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
382 static int cc770_get_berr_counter(
const struct net_device *dev,
403 if (can_dropped_invalid_skb(dev, skb))
408 netdev_err(dev,
"TX register is still occupied!\n");
412 netif_stop_queue(dev);
439 for (i = 0; i < dlc; i++)
462 static void cc770_rx(
struct net_device *dev,
unsigned int mo,
u8 ctrl1)
504 for (i = 0; i < cf->
can_dlc; i++)
521 netdev_dbg(dev,
"status interrupt (%#x)\n", status);
542 if (cf->data[7] > 127) {
546 priv->
can.can_stats.error_passive++;
551 priv->
can.can_stats.error_warning++;
561 if (lec < 7 && lec > 0) {
594 static int cc770_status_interrupt(
struct net_device *dev)
603 if (status & (STAT_WARN | STAT_BOFF) ||
604 (status & STAT_LEC_MASK) != STAT_LEC_MASK) {
605 cc770_err(dev, status);
612 static void cc770_rx_interrupt(
struct net_device *dev,
unsigned int o)
642 cc770_rx(dev, mo, ctrl1);
653 static void cc770_rtr_interrupt(
struct net_device *dev,
unsigned int o)
666 cc770_rx(dev, mo, ctrl1);
677 static void cc770_tx_interrupt(
struct net_device *dev,
unsigned int o)
695 netif_wake_queue(dev);
721 if (cc770_status_interrupt(dev))
724 o = intid2obj(intid);
727 netdev_err(dev,
"Unexpected interrupt id %d\n",
733 cc770_rtr_interrupt(dev, o);
734 else if (priv->
obj_flags[o] & CC770_OBJ_FLAG_RX)
735 cc770_rx_interrupt(dev, o);
737 cc770_tx_interrupt(dev, o);
745 netdev_dbg(dev,
"%d messages handled in ISR", n);
773 netif_start_queue(dev);
778 static int cc770_close(
struct net_device *dev)
780 netif_stop_queue(dev);
799 priv = netdev_priv(dev);
802 priv->
can.bittiming_const = &cc770_bittiming_const;
803 priv->
can.do_set_bittiming = cc770_set_bittiming;
804 priv->
can.do_set_mode = cc770_set_mode;
823 .ndo_open = cc770_open,
824 .ndo_stop = cc770_close,
825 .ndo_start_xmit = cc770_start_xmit,
833 err = cc770_probe_chip(dev);
843 priv->
can.do_get_berr_counter = cc770_get_berr_counter;
845 netdev_dbg(dev,
"i82527 mode with additional functions\n");
848 netdev_dbg(dev,
"strict i82527 compatibility mode\n");
865 static __init int cc770_init(
void)
872 pr_info(
"CAN netdevice driver\n");
878 static __exit void cc770_exit(
void)