tty: Ldisc revamp
[safe/jmp/linux-2.6] / drivers / net / hamradio / mkiss.c
index 3ebbbe5..c6ca475 100644 (file)
@@ -16,7 +16,6 @@
  * Copyright (C) 2004, 05 Ralf Baechle DL5RB <ralf@linux-mips.org>
  * Copyright (C) 2004, 05 Thomas Osterried DL9SAU <thomas@x-berg.in-berlin.de>
  */
-#include <linux/config.h>
 #include <linux/module.h>
 #include <asm/system.h>
 #include <linux/bitops.h>
@@ -290,7 +289,6 @@ static void ax_bump(struct mkiss *ax)
                        *ax->rbuff &= ~0x20;
                }
        }
-       spin_unlock_bh(&ax->buflock);
 
        count = ax->rcount;
 
@@ -298,17 +296,17 @@ static void ax_bump(struct mkiss *ax)
                printk(KERN_ERR "mkiss: %s: memory squeeze, dropping packet.\n",
                       ax->dev->name);
                ax->stats.rx_dropped++;
+               spin_unlock_bh(&ax->buflock);
                return;
        }
 
-       spin_lock_bh(&ax->buflock);
        memcpy(skb_put(skb,count), ax->rbuff, count);
-       spin_unlock_bh(&ax->buflock);
        skb->protocol = ax25_type_trans(skb, ax->dev);
        netif_rx(skb);
        ax->dev->last_rx = jiffies;
        ax->stats.rx_packets++;
        ax->stats.rx_bytes += count;
+       spin_unlock_bh(&ax->buflock);
 }
 
 static void kiss_unesc(struct mkiss *ax, unsigned char s)
@@ -518,7 +516,7 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len)
        spin_unlock_bh(&ax->buflock);
 
        set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags);
-       actual = ax->tty->driver->write(ax->tty, ax->xbuff, count);
+       actual = ax->tty->ops->write(ax->tty, ax->xbuff, count);
        ax->stats.tx_packets++;
        ax->stats.tx_bytes += actual;
 
@@ -548,7 +546,7 @@ static int ax_xmit(struct sk_buff *skb, struct net_device *dev)
                }
 
                printk(KERN_ERR "mkiss: %s: transmit timed out, %s?\n", dev->name,
-                      (ax->tty->driver->chars_in_buffer(ax->tty) || ax->xleft) ?
+                      (ax->tty->ops->chars_in_buffer(ax->tty) || ax->xleft) ?
                       "bad line quality" : "driver error");
 
                ax->xleft = 0;
@@ -579,11 +577,12 @@ static int ax_open_dev(struct net_device *dev)
 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
 
 /* Return the frame type ID */
-static int ax_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
-         void *daddr, void *saddr, unsigned len)
+static int ax_header(struct sk_buff *skb, struct net_device *dev,
+                    unsigned short type, const void *daddr,
+                    const void *saddr, unsigned len)
 {
 #ifdef CONFIG_INET
-       if (type != htons(ETH_P_AX25))
+       if (type != ETH_P_AX25)
                return ax25_hard_header(skb, dev, type, daddr, saddr, len);
 #endif
        return 0;
@@ -671,13 +670,13 @@ static struct net_device_stats *ax_get_stats(struct net_device *dev)
        return &ax->stats;
 }
 
+static const struct header_ops ax_header_ops = {
+       .create    = ax_header,
+       .rebuild   = ax_rebuild_header,
+};
+
 static void ax_setup(struct net_device *dev)
 {
-       static char ax25_bcast[AX25_ADDR_LEN] =
-               {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
-       static char ax25_test[AX25_ADDR_LEN] =
-               {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
-
        /* Finish setting up the DEVICE info. */
        dev->mtu             = AX_MTU;
        dev->hard_start_xmit = ax_xmit;
@@ -689,11 +688,11 @@ static void ax_setup(struct net_device *dev)
        dev->addr_len        = 0;
        dev->type            = ARPHRD_AX25;
        dev->tx_queue_len    = 10;
-       dev->hard_header     = ax_header;
-       dev->rebuild_header  = ax_rebuild_header;
+       dev->header_ops      = &ax_header_ops;
 
-       memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN);
-       memcpy(dev->dev_addr,  ax25_test,  AX25_ADDR_LEN);
+
+       memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
+       memcpy(dev->dev_addr,  &ax25_defaddr,  AX25_ADDR_LEN);
 
        dev->flags      = IFF_BROADCAST | IFF_MULTICAST;
 }
@@ -737,6 +736,8 @@ static int mkiss_open(struct tty_struct *tty)
 
        if (!capable(CAP_NET_ADMIN))
                return -EPERM;
+       if (tty->ops->write == NULL)
+               return -EOPNOTSUPP;
 
        dev = alloc_netdev(sizeof(struct mkiss), "ax%d", ax_setup);
        if (!dev) {
@@ -755,8 +756,7 @@ static int mkiss_open(struct tty_struct *tty)
        tty->disc_data = ax;
        tty->receive_room = 65535;
 
-       if (tty->driver->flush_buffer)
-               tty->driver->flush_buffer(tty);
+       tty_driver_flush_buffer(tty);
 
        /* Restore default settings */
        dev->type = ARPHRD_AX25;
@@ -821,7 +821,7 @@ static void mkiss_close(struct tty_struct *tty)
        tty->disc_data = NULL;
        write_unlock(&disc_data_lock);
 
-       if (ax == 0)
+       if (!ax)
                return;
 
        /*
@@ -936,9 +936,7 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
        }
 
        mkiss_put(ax);
-       if (test_and_clear_bit(TTY_THROTTLED, &tty->flags)
-           && tty->driver->unthrottle)
-               tty->driver->unthrottle(tty);
+       tty_unthrottle(tty);
 }
 
 /*
@@ -963,7 +961,7 @@ static void mkiss_write_wakeup(struct tty_struct *tty)
                goto out;
        }
 
-       actual = tty->driver->write(tty, ax->xhead, ax->xleft);
+       actual = tty->ops->write(tty, ax->xhead, ax->xleft);
        ax->xleft -= actual;
        ax->xhead += actual;
 
@@ -971,7 +969,7 @@ out:
        mkiss_put(ax);
 }
 
-static struct tty_ldisc ax_ldisc = {
+static struct tty_ldisc_ops ax_ldisc = {
        .owner          = THIS_MODULE,
        .magic          = TTY_LDISC_MAGIC,
        .name           = "mkiss",