#include <asm/uaccess.h>
#endif
#include <linux/bitops.h>
+#include <linux/sched.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/init.h>
-#include <linux/can.h>
+#include <socketcan/can.h>
-#include <linux/can/version.h> /* for RCSID. Removed by mkpatch script */
+#include <socketcan/can/version.h> /* for RCSID. Removed by mkpatch script */
RCSID("$Id$");
static __initdata const char banner[] =
* to use the slcan driver with an existing kernel.
*/
-#define SLC_CHECK_TRANSMIT
#define SLCAN_MAGIC 0x53CA
static int maxdev = 10; /* MAX number of SLCAN channels;
&cf, sizeof(struct can_frame));
netif_rx(skb);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
sl->dev->last_rx = jiffies;
+#endif
stats->rx_packets++;
stats->rx_bytes += cf.can_dlc;
}
actual = sl->tty->driver->write(sl->tty, sl->xbuff, strlen(sl->xbuff));
#else
actual = sl->tty->ops->write(sl->tty, sl->xbuff, strlen(sl->xbuff));
-#endif
-#ifdef SLC_CHECK_TRANSMIT
- sl->dev->trans_start = jiffies;
#endif
sl->xleft = strlen(sl->xbuff) - actual;
sl->xhead = sl->xbuff + actual;
sl->xhead += actual;
}
-static void slc_tx_timeout(struct net_device *dev)
-{
- struct slcan *sl = netdev_priv(dev);
-
- spin_lock(&sl->lock);
-
- if (netif_queue_stopped(dev)) {
- if (!netif_running(dev))
- goto out;
-
- /* May be we must check transmitter timeout here ?
- * 14 Oct 1994 Dmitry Gorodchanin.
- */
-#ifdef SLC_CHECK_TRANSMIT
- if (time_before(jiffies, dev->trans_start + 20 * HZ)) {
- /* 20 sec timeout not reached */
- goto out;
- }
- printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
- (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft)
-#else
- (tty_chars_in_buffer(sl->tty) || sl->xleft)
-#endif
- ? "bad line quality" : "driver error");
- sl->xleft = 0;
- sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
- netif_wake_queue(sl->dev);
-#endif
- }
-out:
- spin_unlock(&sl->lock);
-}
-
/******************************************
* Routines looking at netdevice side.
******************************************/
/* Send a can_frame to a TTY queue. */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
static int slc_xmit(struct sk_buff *skb, struct net_device *dev)
+#else
+static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev)
+#endif
{
struct slcan *sl = netdev_priv(dev);
out:
kfree_skb(skb);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
return 0;
+#else
+ return NETDEV_TX_OK;
+#endif
}
return 0;
}
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
+/* Hook the destructor so we can free slcan devs at the right point in time */
+static void slc_free_netdev(struct net_device *dev)
+{
+ int i = dev->base_addr;
+ free_netdev(dev);
+ slcan_devs[i] = NULL;
+}
+#endif
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,28)
+static const struct net_device_ops slc_netdev_ops = {
+ .ndo_open = slc_open,
+ .ndo_stop = slc_close,
+ .ndo_start_xmit = slc_xmit,
+};
+#endif
+
/* Netdevice register callback */
static void slc_setup(struct net_device *dev)
{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,28)
+ dev->netdev_ops = &slc_netdev_ops;
+#else
dev->open = slc_open;
- dev->destructor = free_netdev;
dev->stop = slc_close;
+ dev->hard_start_xmit = slc_xmit;
+#endif
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
+ dev->destructor = slc_free_netdev;
+#else
+ dev->destructor = free_netdev;
+#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
dev->get_stats = slc_get_stats;
#endif
- dev->hard_start_xmit = slc_xmit;
dev->hard_header_len = 0;
dev->addr_len = 0;
dev->mtu = sizeof(struct can_frame);
dev->type = ARPHRD_CAN;
-#ifdef SLC_CHECK_TRANSMIT
- dev->tx_timeout = slc_tx_timeout;
- dev->watchdog_timeo = 20*HZ;
-#endif
/* New-style flags. */
dev->flags = IFF_NOARP;
static struct slcan *slc_alloc(dev_t line)
{
int i;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
int sel = -1;
int score = -1;
+#endif
struct net_device *dev = NULL;
struct slcan *sl;
if (dev == NULL)
break;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
sl = netdev_priv(dev);
if (sl->leased) {
if (sl->line != line)
sl->flags &= (1 << SLF_INUSE);
return sl;
}
+#endif
}
/* Sorry, too many, all slots in use */
if (!dev) {
char name[IFNAMSIZ];
- sprintf(name, "slc%d", i);
+ sprintf(name, "can%d", i);
dev = alloc_netdev(sizeof(*sl), name, slc_setup);
if (!dev)
return err;
}
-/*
-
- FIXME: 1,2 are fixed 3 was never true anyway.
-
- Let me to blame a bit.
- 1. TTY module calls this funstion on soft interrupt.
- 2. TTY module calls this function WITH MASKED INTERRUPTS!
- 3. TTY module does not notify us about line discipline
- shutdown,
-
- Seems, now it is clean. The solution is to consider netdevice and
- line discipline sides as two independent threads.
-
- By-product (not desired): slc? does not feel hangups and remains open.
- It is supposed, that user level program (dip, diald, slattach...)
- will catch SIGHUP and make the rest of work.
-
- I see no way to make more with current tty code. --ANK
- */
-
/*
* Close down a SLCAN channel.
* This means flushing out any pending queues, and then returning. This
* call is serialized against other ldisc functions.
+ *
+ * We also use this method for a hangup event.
*/
static void slcan_close(struct tty_struct *tty)
{
if (!sl->leased)
sl->line = 0;
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
+ /* Flush network side */
+ unregister_netdev(sl->dev);
+ /* This will complete via sl_free_netdev */
+#else
/* Count references from TTY module */
+#endif
}
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
+static int slcan_hangup(struct tty_struct *tty)
+{
+ slcan_close(tty);
+ return 0;
+}
+#endif
+
/* Perform I/O control on an active SLCAN channel. */
static int slcan_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
.name = "slcan",
.open = slcan_open,
.close = slcan_close,
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
+ .hangup = slcan_hangup,
+#endif
.ioctl = slcan_ioctl,
.receive_buf = slcan_receive_buf,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
}
} while (busy && time_before(jiffies, timeout));
+ /* FIXME (2.6.32+): hangup is async so we should wait when doing
+ this second phase */
for (i = 0; i < maxdev; i++) {
dev = slcan_devs[i];