]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - kernel/2.6/drivers/net/can/slcan.c
Reverted the removal of dev->get_stats = can_get_stats for kernels < 2.6.23
[socketcan-devel.git] / kernel / 2.6 / drivers / net / can / slcan.c
index 75f3afc1d737097bbb8634bb743cd354af714bfb..53f15b3f6550651260031b2229bca37dd498a9fe 100644 (file)
 #include <linux/moduleparam.h>
 
 #include <asm/system.h>
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)
+#include <linux/uaccess.h>
+#else
 #include <asm/uaccess.h>
+#endif
 #include <linux/bitops.h>
 #include <linux/string.h>
 #include <linux/mm.h>
@@ -158,6 +162,17 @@ struct slcan {
 
 static struct net_device **slcan_devs;
 
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+/* Netdevice get statistics request */
+static struct net_device_stats *slc_get_stats(struct net_device *dev)
+{
+       struct slcan *sl = netdev_priv(dev);
+
+       return &sl->stats;
+}
+#endif
+
  /************************************************************************
   *                    SLCAN ENCAPSULATION FORMAT                       *
   ************************************************************************/
@@ -215,7 +230,11 @@ static int asc2nibble(char c)
 /* Send one completely decapsulated can_frame to the network layer */
 static void slc_bump(struct slcan *sl)
 {
-       struct net_device_stats *stats = sl->dev->get_stats(sl->dev);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+       struct net_device_stats *stats = slc_get_stats(sl->dev);
+#else
+       struct net_device_stats *stats = &sl->dev->stats;
+#endif
        struct sk_buff *skb;
        struct can_frame cf;
        int i, dlc_pos, tmp;
@@ -235,7 +254,13 @@ static void slc_bump(struct slcan *sl)
        cf.can_dlc = sl->rbuff[dlc_pos] & 0x0F; /* get can_dlc */
 
        sl->rbuff[dlc_pos] = 0; /* terminate can_id string */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
        cf.can_id = simple_strtoul(sl->rbuff+1, NULL, 16);
+#else
+       if (strict_strtoul(sl->rbuff+1, 16, (unsigned long *) &cf.can_id))
+               return;
+#endif
 
        if (!(cmd & 0x20)) /* NO tiny chars => extended frame format */
                cf.can_id |= CAN_EFF_FLAG;
@@ -278,7 +303,11 @@ static void slc_bump(struct slcan *sl)
 /* parse tty input stream */
 static void slcan_unesc(struct slcan *sl, unsigned char s)
 {
-       struct net_device_stats *stats = sl->dev->get_stats(sl->dev);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+       struct net_device_stats *stats = slc_get_stats(sl->dev);
+#else
+       struct net_device_stats *stats = &sl->dev->stats;
+#endif
 
        if ((s == '\r') || (s == '\a')) { /* CR or BEL ends the pdu */
                if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
@@ -306,7 +335,11 @@ static void slcan_unesc(struct slcan *sl, unsigned char s)
 /* Encapsulate one can_frame and stuff into a TTY queue. */
 static void slc_encaps(struct slcan *sl, struct can_frame *cf)
 {
-       struct net_device_stats *stats = sl->dev->get_stats(sl->dev);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+       struct net_device_stats *stats = slc_get_stats(sl->dev);
+#else
+       struct net_device_stats *stats = &sl->dev->stats;
+#endif
        int actual, idx, i;
        char cmd;
 
@@ -340,7 +373,11 @@ static void slc_encaps(struct slcan *sl, struct can_frame *cf)
         *       14 Oct 1994  Dmitry Gorodchanin.
         */
        sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
        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
@@ -357,7 +394,11 @@ static void slcan_write_wakeup(struct tty_struct *tty)
 {
        int actual;
        struct slcan *sl = (struct slcan *) tty->disc_data;
-       struct net_device_stats *stats = sl->dev->get_stats(sl->dev);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+       struct net_device_stats *stats = slc_get_stats(sl->dev);
+#else
+       struct net_device_stats *stats = &sl->dev->stats;
+#endif
 
        /* First make sure we're connected. */
        if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev))
@@ -372,7 +413,11 @@ static void slcan_write_wakeup(struct tty_struct *tty)
                return;
        }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
        actual = tty->driver->write(tty, sl->xhead, sl->xleft);
+#else
+       actual = tty->ops->write(tty, sl->xhead, sl->xleft);
+#endif
        sl->xleft -= actual;
        sl->xhead += actual;
 }
@@ -396,7 +441,11 @@ static void slc_tx_timeout(struct net_device *dev)
                        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);
@@ -473,16 +522,6 @@ static int slc_open(struct net_device *dev)
        return 0;
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
-/* Netdevice get statistics request */
-static struct net_device_stats *slc_get_stats(struct net_device *dev)
-{
-       struct slcan *sl = netdev_priv(dev);
-
-       return (&sl->stats);
-}
-#endif
-
 /* Netdevice register callback */
 static void slc_setup(struct net_device *dev)
 {
@@ -490,7 +529,7 @@ static void slc_setup(struct net_device *dev)
        dev->destructor         = free_netdev;
        dev->stop               = slc_close;
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
-       dev->get_stats          = slc_get_stats;
+       dev->get_stats          = slc_get_stats;
 #endif
        dev->hard_start_xmit    = slc_xmit;
 
@@ -534,7 +573,11 @@ static void slcan_receive_buf(struct tty_struct *tty,
                              const unsigned char *cp, char *fp, int count)
 {
        struct slcan *sl = (struct slcan *) tty->disc_data;
-       struct net_device_stats *stats = sl->dev->get_stats(sl->dev);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+       struct net_device_stats *stats = slc_get_stats(sl->dev);
+#else
+       struct net_device_stats *stats = &sl->dev->stats;
+#endif
 
        if (!sl || sl->magic != SLCAN_MAGIC ||
            !netif_running(sl->dev))
@@ -696,6 +739,11 @@ static int slcan_open(struct tty_struct *tty)
        if (!capable(CAP_NET_ADMIN))
                return -EPERM;
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
+       if (tty->ops->write == NULL)
+               return -EOPNOTSUPP;
+#endif
+
        /* RTnetlink lock is misused here to serialize concurrent
           opens of slcan channels. There are better ways, but it is
           the simplest one.
@@ -824,7 +872,7 @@ static int slcan_ioctl(struct tty_struct *tty, struct file *file,
        case SIOCSIFHWADDR:
                return -EINVAL;
 
-
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
        /* Allow stty to read, but not set, the serial port */
        case TCGETS:
        case TCGETA:
@@ -832,10 +880,18 @@ static int slcan_ioctl(struct tty_struct *tty, struct file *file,
 
        default:
                return -ENOIOCTLCMD;
+#else
+       default:
+               return tty_mode_ioctl(tty, file, cmd, arg);
+#endif
        }
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
 static struct tty_ldisc        slc_ldisc = {
+#else
+static struct tty_ldisc_ops slc_ldisc = {
+#endif
        .owner          = THIS_MODULE,
        .magic          = TTY_LDISC_MAGIC,
        .name           = "slcan",