]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - kernel/2.6/drivers/net/can/slcan.c
There is no reason why the 'real' SLCAN interfaces should have a different
[socketcan-devel.git] / kernel / 2.6 / drivers / net / can / slcan.c
index 1f6c67724cf6b0c60edcc6a9825b50955ab57a2c..dd29d7d6cd7cba9775bf5174a08335fc2bc524ef 100644 (file)
@@ -57,6 +57,7 @@
 #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>
@@ -73,9 +74,9 @@
 #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[] =
@@ -123,7 +124,6 @@ module_param(debug, int, S_IRUGO);
  * 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;
@@ -301,7 +301,9 @@ static void slc_bump(struct slcan *sl)
               &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;
 }
@@ -383,9 +385,6 @@ static void slc_encaps(struct slcan *sl, struct can_frame *cf)
        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;
@@ -428,47 +427,17 @@ static void slcan_write_wakeup(struct tty_struct *tty)
        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);
 
@@ -493,7 +462,11 @@ static int slc_xmit(struct sk_buff *skb, struct net_device *dev)
 
 out:
        kfree_skb(skb);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
        return 0;
+#else
+       return NETDEV_TX_OK;
+#endif
 }
 
 
@@ -528,16 +501,42 @@ static int slc_open(struct net_device *dev)
        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;
@@ -545,10 +544,6 @@ static void slc_setup(struct net_device *dev)
 
        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;
@@ -631,8 +626,10 @@ static void slc_sync(void)
 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;
 
@@ -644,6 +641,7 @@ static struct slcan *slc_alloc(dev_t line)
                if (dev == NULL)
                        break;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
                sl = netdev_priv(dev);
                if (sl->leased) {
                        if (sl->line != line)
@@ -690,6 +688,7 @@ static struct slcan *slc_alloc(dev_t line)
                        sl->flags &= (1 << SLF_INUSE);
                        return sl;
                }
+#endif
        }
 
        /* Sorry, too many, all slots in use */
@@ -707,7 +706,7 @@ static struct slcan *slc_alloc(dev_t line)
 
        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)
@@ -815,30 +814,12 @@ err_exit:
        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)
 {
@@ -853,9 +834,23 @@ 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)
@@ -902,6 +897,9 @@ static struct tty_ldisc_ops slc_ldisc = {
        .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)
@@ -974,6 +972,8 @@ static void __exit slcan_exit(void)
                }
        } 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];