Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / char / stallion.c
index bbaafd8..a9c5a72 100644 (file)
@@ -3,7 +3,7 @@
 /*
  *     stallion.c  -- stallion multiport serial driver.
  *
- *     Copyright (C) 1996-1999  Stallion Technologies (support@stallion.oz.au).
+ *     Copyright (C) 1996-1999  Stallion Technologies
  *     Copyright (C) 1994-1996  Greg Ungerer.
  *
  *     This code is loosely based on the Linux serial driver, written by
@@ -42,6 +42,7 @@
 #include <linux/smp_lock.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/device.h>
+#include <linux/delay.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -102,7 +103,7 @@ static stlconf_t    stl_brdconf[] = {
        /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
 };
 
-static int     stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
+static int     stl_nrbrds = ARRAY_SIZE(stl_brdconf);
 
 /*****************************************************************************/
 
@@ -147,7 +148,6 @@ static struct tty_driver    *stl_serial;
  *     is already swapping a shared buffer won't make things any worse.
  */
 static char                    *stl_tmpwritebuf;
-static DECLARE_MUTEX(stl_tmpwritesem);
 
 /*
  *     Define a local default termios struct. All ports will be created
@@ -173,14 +173,6 @@ static stlport_t   stl_dummyport;
  */
 static char            stl_unwanted[SC26198_RXFIFOSIZE];
 
-/*
- *     Keep track of what interrupts we have requested for us.
- *     We don't need to request an interrupt twice if it is being
- *     shared with another Stallion board.
- */
-static int     stl_gotintrs[STL_MAXBRDS];
-static int     stl_numintrs;
-
 /*****************************************************************************/
 
 static stlbrd_t                *stl_brds[STL_MAXBRDS];
@@ -239,13 +231,12 @@ static char       *stl_brdnames[] = {
 
 /*****************************************************************************/
 
-#ifdef MODULE
 /*
  *     Define some string labels for arguments passed from the module
  *     load line. These allow for easy board definitions, and easy
  *     modification of the io, memory and irq resoucres.
  */
-
+static int     stl_nargs = 0;
 static char    *board0[4];
 static char    *board1[4];
 static char    *board2[4];
@@ -306,17 +297,15 @@ MODULE_AUTHOR("Greg Ungerer");
 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
 MODULE_LICENSE("GPL");
 
-MODULE_PARM(board0, "1-4s");
+module_param_array(board0, charp, &stl_nargs, 0);
 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
-MODULE_PARM(board1, "1-4s");
+module_param_array(board1, charp, &stl_nargs, 0);
 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
-MODULE_PARM(board2, "1-4s");
+module_param_array(board2, charp, &stl_nargs, 0);
 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
-MODULE_PARM(board3, "1-4s");
+module_param_array(board3, charp, &stl_nargs, 0);
 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
 
-#endif
-
 /*****************************************************************************/
 
 /*
@@ -434,7 +423,7 @@ static stlpcibrd_t  stl_pcibrds[] = {
        { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
 };
 
-static int     stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
+static int     stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
 
 #endif
 
@@ -471,17 +460,15 @@ static unsigned int       stl_baudrates[] = {
  *     Declare all those functions in this driver!
  */
 
-#ifdef MODULE
 static void    stl_argbrds(void);
 static int     stl_parsebrd(stlconf_t *confp, char **argp);
 
 static unsigned long stl_atol(char *str);
-#endif
 
-int            stl_init(void);
+static int     stl_init(void);
 static int     stl_open(struct tty_struct *tty, struct file *filp);
 static void    stl_close(struct tty_struct *tty, struct file *filp);
-static int     stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
+static int     stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
 static void    stl_putchar(struct tty_struct *tty, unsigned char ch);
 static void    stl_flushchars(struct tty_struct *tty);
 static int     stl_writeroom(struct tty_struct *tty);
@@ -503,23 +490,20 @@ static int        stl_readproc(char *page, char **start, off_t off, int count, int *eof
 
 static int     stl_brdinit(stlbrd_t *brdp);
 static int     stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
-static int     stl_mapirq(int irq, char *name);
-static int     stl_getserial(stlport_t *portp, struct serial_struct *sp);
-static int     stl_setserial(stlport_t *portp, struct serial_struct *sp);
-static int     stl_getbrdstats(combrd_t *bp);
-static int     stl_getportstats(stlport_t *portp, comstats_t *cp);
-static int     stl_clrportstats(stlport_t *portp, comstats_t *cp);
-static int     stl_getportstruct(unsigned long arg);
-static int     stl_getbrdstruct(unsigned long arg);
+static int     stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
+static int     stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
+static int     stl_getbrdstats(combrd_t __user *bp);
+static int     stl_getportstats(stlport_t *portp, comstats_t __user *cp);
+static int     stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
+static int     stl_getportstruct(stlport_t __user *arg);
+static int     stl_getbrdstruct(stlbrd_t __user *arg);
 static int     stl_waitcarrier(stlport_t *portp, struct file *filp);
-static void    stl_delay(int len);
-static void    stl_eiointr(stlbrd_t *brdp);
-static void    stl_echatintr(stlbrd_t *brdp);
-static void    stl_echmcaintr(stlbrd_t *brdp);
-static void    stl_echpciintr(stlbrd_t *brdp);
-static void    stl_echpci64intr(stlbrd_t *brdp);
+static int     stl_eiointr(stlbrd_t *brdp);
+static int     stl_echatintr(stlbrd_t *brdp);
+static int     stl_echmcaintr(stlbrd_t *brdp);
+static int     stl_echpciintr(stlbrd_t *brdp);
+static int     stl_echpci64intr(stlbrd_t *brdp);
 static void    stl_offintr(void *private);
-static void    *stl_memalloc(int len);
 static stlbrd_t *stl_allocbrd(void);
 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
 
@@ -718,7 +702,7 @@ static unsigned int sc26198_baudtable[] = {
        230400, 460800, 921600
 };
 
-#define        SC26198_NRBAUDS         (sizeof(sc26198_baudtable) / sizeof(unsigned int))
+#define        SC26198_NRBAUDS         ARRAY_SIZE(sc26198_baudtable)
 
 /*****************************************************************************/
 
@@ -733,9 +717,7 @@ static struct file_operations       stl_fsiomem = {
 
 /*****************************************************************************/
 
-static struct class_simple *stallion_class;
-
-#ifdef MODULE
+static struct class *stallion_class;
 
 /*
  *     Loadable module initialization stuff.
@@ -745,7 +727,7 @@ static int __init stallion_module_init(void)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("init_module()\n");
 #endif
 
@@ -754,7 +736,7 @@ static int __init stallion_module_init(void)
        stl_init();
        restore_flags(flags);
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -767,7 +749,7 @@ static void __exit stallion_module_exit(void)
        unsigned long   flags;
        int             i, j, k;
 
-#if DEBUG
+#ifdef DEBUG
        printk("cleanup_module()\n");
 #endif
 
@@ -793,20 +775,22 @@ static void __exit stallion_module_exit(void)
        }
        for (i = 0; i < 4; i++) {
                devfs_remove("staliomem/%d", i);
-               class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
+               class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
        }
        devfs_remove("staliomem");
        if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
                printk("STALLION: failed to un-register serial memory device, "
                        "errno=%d\n", -i);
-       class_simple_destroy(stallion_class);
+       class_destroy(stallion_class);
 
-       if (stl_tmpwritebuf != (char *) NULL)
-               kfree(stl_tmpwritebuf);
+       kfree(stl_tmpwritebuf);
 
        for (i = 0; (i < stl_nrbrds); i++) {
                if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
                        continue;
+
+               free_irq(brdp->irq, brdp);
+
                for (j = 0; (j < STL_MAXPANELS); j++) {
                        panelp = brdp->panels[j];
                        if (panelp == (stlpanel_t *) NULL)
@@ -817,8 +801,7 @@ static void __exit stallion_module_exit(void)
                                        continue;
                                if (portp->tty != (struct tty_struct *) NULL)
                                        stl_hangup(portp->tty);
-                               if (portp->tx.buf != (char *) NULL)
-                                       kfree(portp->tx.buf);
+                               kfree(portp->tx.buf);
                                kfree(portp);
                        }
                        kfree(panelp);
@@ -832,9 +815,6 @@ static void __exit stallion_module_exit(void)
                stl_brds[i] = (stlbrd_t *) NULL;
        }
 
-       for (i = 0; (i < stl_numintrs); i++)
-               free_irq(stl_gotintrs[i], NULL);
-
        restore_flags(flags);
 }
 
@@ -847,19 +827,17 @@ module_exit(stallion_module_exit);
  *     Check for any arguments passed in on the module load command line.
  */
 
-static void stl_argbrds()
+static void stl_argbrds(void)
 {
        stlconf_t       conf;
        stlbrd_t        *brdp;
-       int             nrargs, i;
+       int             i;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_argbrds()\n");
 #endif
 
-       nrargs = sizeof(stl_brdsp) / sizeof(char **);
-
-       for (i = stl_nrbrds; (i < nrargs); i++) {
+       for (i = stl_nrbrds; (i < stl_nargs); i++) {
                memset(&conf, 0, sizeof(conf));
                if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
                        continue;
@@ -909,7 +887,7 @@ static unsigned long stl_atol(char *str)
                }
                val = (val * base) + c;
        }
-       return(val);
+       return val;
 }
 
 /*****************************************************************************/
@@ -921,26 +899,25 @@ static unsigned long stl_atol(char *str)
 static int stl_parsebrd(stlconf_t *confp, char **argp)
 {
        char    *sp;
-       int     nrbrdnames, i;
+       int     i;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
 #endif
 
        if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
-               return(0);
+               return 0;
 
        for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
                *sp = TOLOWER(*sp);
 
-       nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
-       for (i = 0; (i < nrbrdnames); i++) {
+       for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
                if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
                        break;
        }
-       if (i >= nrbrdnames) {
+       if (i == ARRAY_SIZE(stl_brdstr)) {
                printk("STALLION: unknown board name, %s?\n", argp[0]);
-               return(0);
+               return 0;
        }
 
        confp->brdtype = stl_brdstr[i].type;
@@ -956,20 +933,7 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
        }
        if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
                confp->irq = stl_atol(argp[i]);
-       return(1);
-}
-
-#endif
-
-/*****************************************************************************/
-
-/*
- *     Local driver kernel memory allocation routine.
- */
-
-static void *stl_memalloc(int len)
-{
-       return((void *) kmalloc(len, GFP_KERNEL));
+       return 1;
 }
 
 /*****************************************************************************/
@@ -978,20 +942,19 @@ static void *stl_memalloc(int len)
  *     Allocate a new board structure. Fill out the basic info in it.
  */
 
-static stlbrd_t *stl_allocbrd()
+static stlbrd_t *stl_allocbrd(void)
 {
        stlbrd_t        *brdp;
 
-       brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
-       if (brdp == (stlbrd_t *) NULL) {
+       brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
+       if (!brdp) {
                printk("STALLION: failed to allocate memory (size=%d)\n",
                        sizeof(stlbrd_t));
-               return((stlbrd_t *) NULL);
+               return NULL;
        }
 
-       memset(brdp, 0, sizeof(stlbrd_t));
        brdp->magic = STL_BOARDMAGIC;
-       return(brdp);
+       return brdp;
 }
 
 /*****************************************************************************/
@@ -1003,7 +966,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
        unsigned int    minordev;
        int             brdnr, panelnr, portnr, rc;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
                (int) filp, tty->name);
 #endif
@@ -1011,10 +974,10 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
        minordev = tty->index;
        brdnr = MINOR2BRD(minordev);
        if (brdnr >= stl_nrbrds)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stl_brds[brdnr];
        if (brdp == (stlbrd_t *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
        minordev = MINOR2PORT(minordev);
        for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
                if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
@@ -1026,11 +989,11 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
                minordev -= brdp->panels[panelnr]->nrports;
        }
        if (portnr < 0)
-               return(-ENODEV);
+               return -ENODEV;
 
        portp = brdp->panels[panelnr]->ports[portnr];
        if (portp == (stlport_t *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
 
 /*
  *     On the first open of the device setup the port hardware, and
@@ -1041,10 +1004,10 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
        portp->refcount++;
 
        if ((portp->flags & ASYNC_INITIALIZED) == 0) {
-               if (portp->tx.buf == (char *) NULL) {
-                       portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
-                       if (portp->tx.buf == (char *) NULL)
-                               return(-ENOMEM);
+               if (!portp->tx.buf) {
+                       portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
+                       if (!portp->tx.buf)
+                               return -ENOMEM;
                        portp->tx.head = portp->tx.buf;
                        portp->tx.tail = portp->tx.buf;
                }
@@ -1066,8 +1029,8 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
        if (portp->flags & ASYNC_CLOSING) {
                interruptible_sleep_on(&portp->close_wait);
                if (portp->flags & ASYNC_HUP_NOTIFY)
-                       return(-EAGAIN);
-               return(-ERESTARTSYS);
+                       return -EAGAIN;
+               return -ERESTARTSYS;
        }
 
 /*
@@ -1077,11 +1040,11 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
  */
        if (!(filp->f_flags & O_NONBLOCK)) {
                if ((rc = stl_waitcarrier(portp, filp)) != 0)
-                       return(rc);
+                       return rc;
        }
        portp->flags |= ASYNC_NORMAL_ACTIVE;
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -1096,7 +1059,7 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
        unsigned long   flags;
        int             rc, doclocal;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
 #endif
 
@@ -1138,7 +1101,7 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
        portp->openwaitcnt--;
        restore_flags(flags);
 
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -1148,7 +1111,7 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
        stlport_t       *portp;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
 #endif
 
@@ -1197,15 +1160,14 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
                portp->tx.tail = (char *) NULL;
        }
        set_bit(TTY_IO_ERROR, &tty->flags);
-       if (tty->ldisc.flush_buffer)
-               (tty->ldisc.flush_buffer)(tty);
+       tty_ldisc_flush(tty);
 
        tty->closing = 0;
        portp->tty = (struct tty_struct *) NULL;
 
        if (portp->openwaitcnt) {
                if (portp->close_delay)
-                       stl_delay(portp->close_delay);
+                       msleep_interruptible(jiffies_to_msecs(portp->close_delay));
                wake_up_interruptible(&portp->open_wait);
        }
 
@@ -1216,50 +1178,31 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
 
 /*****************************************************************************/
 
-/*
- *     Wait for a specified delay period, this is not a busy-loop. It will
- *     give up the processor while waiting. Unfortunately this has some
- *     rather intimate knowledge of the process management stuff.
- */
-
-static void stl_delay(int len)
-{
-#if DEBUG
-       printk("stl_delay(len=%d)\n", len);
-#endif
-       if (len > 0) {
-               current->state = TASK_INTERRUPTIBLE;
-               schedule_timeout(len);
-       }
-}
-
-/*****************************************************************************/
-
 /*
  *     Write routine. Take data and stuff it in to the TX ring queue.
  *     If transmit interrupts are not running then start them.
  */
 
-static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
+static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
 {
        stlport_t       *portp;
        unsigned int    len, stlen;
        unsigned char   *chbuf;
        char            *head, *tail;
 
-#if DEBUG
-       printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
-               (int) tty, from_user, (int) buf, count);
+#ifdef DEBUG
+       printk("stl_write(tty=%x,buf=%x,count=%d)\n",
+               (int) tty, (int) buf, count);
 #endif
 
        if ((tty == (struct tty_struct *) NULL) ||
            (stl_tmpwritebuf == (char *) NULL))
-               return(0);
+               return 0;
        portp = tty->driver_data;
        if (portp == (stlport_t *) NULL)
-               return(0);
+               return 0;
        if (portp->tx.buf == (char *) NULL)
-               return(0);
+               return 0;
 
 /*
  *     If copying direct from user space we must cater for page faults,
@@ -1268,18 +1211,6 @@ static int stl_write(struct tty_struct *tty, int from_user, const unsigned char
  *     copy it into the TX buffer.
  */
        chbuf = (unsigned char *) buf;
-       if (from_user) {
-               head = portp->tx.head;
-               tail = portp->tx.tail;
-               len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
-                       (tail - head - 1);
-               count = MIN(len, count);
-               
-               down(&stl_tmpwritesem);
-               if (copy_from_user(stl_tmpwritebuf, chbuf, count)) 
-                       return -EFAULT;
-               chbuf = &stl_tmpwritebuf[0];
-       }
 
        head = portp->tx.head;
        tail = portp->tx.tail;
@@ -1310,10 +1241,7 @@ static int stl_write(struct tty_struct *tty, int from_user, const unsigned char
        clear_bit(ASYI_TXLOW, &portp->istate);
        stl_startrxtx(portp, -1, 1);
 
-       if (from_user)
-               up(&stl_tmpwritesem);
-
-       return(count);
+       return count;
 }
 
 /*****************************************************************************/
@@ -1324,7 +1252,7 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
        unsigned int    len;
        char            *head, *tail;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
 #endif
 
@@ -1362,7 +1290,7 @@ static void stl_flushchars(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_flushchars(tty=%x)\n", (int) tty);
 #endif
 
@@ -1389,21 +1317,21 @@ static int stl_writeroom(struct tty_struct *tty)
        stlport_t       *portp;
        char            *head, *tail;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_writeroom(tty=%x)\n", (int) tty);
 #endif
 
        if (tty == (struct tty_struct *) NULL)
-               return(0);
+               return 0;
        portp = tty->driver_data;
        if (portp == (stlport_t *) NULL)
-               return(0);
+               return 0;
        if (portp->tx.buf == (char *) NULL)
-               return(0);
+               return 0;
 
        head = portp->tx.head;
        tail = portp->tx.tail;
-       return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
+       return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
 }
 
 /*****************************************************************************/
@@ -1423,24 +1351,24 @@ static int stl_charsinbuffer(struct tty_struct *tty)
        unsigned int    size;
        char            *head, *tail;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
 #endif
 
        if (tty == (struct tty_struct *) NULL)
-               return(0);
+               return 0;
        portp = tty->driver_data;
        if (portp == (stlport_t *) NULL)
-               return(0);
+               return 0;
        if (portp->tx.buf == (char *) NULL)
-               return(0);
+               return 0;
 
        head = portp->tx.head;
        tail = portp->tx.tail;
        size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
        if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
                size = 1;
-       return(size);
+       return size;
 }
 
 /*****************************************************************************/
@@ -1449,12 +1377,12 @@ static int stl_charsinbuffer(struct tty_struct *tty)
  *     Generate the serial struct info.
  */
 
-static int stl_getserial(stlport_t *portp, struct serial_struct *sp)
+static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
 {
        struct serial_struct    sio;
        stlbrd_t                *brdp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
 #endif
 
@@ -1490,11 +1418,11 @@ static int stl_getserial(stlport_t *portp, struct serial_struct *sp)
  *     just quietly ignore any requests to change irq, etc.
  */
 
-static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
+static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
 {
        struct serial_struct    sio;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
 #endif
 
@@ -1505,7 +1433,7 @@ static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
                    (sio.close_delay != portp->close_delay) ||
                    ((sio.flags & ~ASYNC_USR_MASK) !=
                    (portp->flags & ~ASYNC_USR_MASK)))
-                       return(-EPERM);
+                       return -EPERM;
        } 
 
        portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
@@ -1515,7 +1443,7 @@ static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
        portp->closing_wait = sio.closing_wait;
        portp->custom_divisor = sio.custom_divisor;
        stl_setport(portp, portp->tty->termios);
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -1525,12 +1453,12 @@ static int stl_tiocmget(struct tty_struct *tty, struct file *file)
        stlport_t       *portp;
 
        if (tty == (struct tty_struct *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
        portp = tty->driver_data;
        if (portp == (stlport_t *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
        if (tty->flags & (1 << TTY_IO_ERROR))
-               return(-EIO);
+               return -EIO;
 
        return stl_getsignals(portp);
 }
@@ -1542,12 +1470,12 @@ static int stl_tiocmset(struct tty_struct *tty, struct file *file,
        int rts = -1, dtr = -1;
 
        if (tty == (struct tty_struct *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
        portp = tty->driver_data;
        if (portp == (stlport_t *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
        if (tty->flags & (1 << TTY_IO_ERROR))
-               return(-EIO);
+               return -EIO;
 
        if (set & TIOCM_RTS)
                rts = 1;
@@ -1567,22 +1495,23 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
        stlport_t       *portp;
        unsigned int    ival;
        int             rc;
+       void __user *argp = (void __user *)arg;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
                (int) tty, (int) file, cmd, (int) arg);
 #endif
 
        if (tty == (struct tty_struct *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
        portp = tty->driver_data;
        if (portp == (stlport_t *) NULL)
-               return(-ENODEV);
+               return -ENODEV;
 
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
            (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
                if (tty->flags & (1 << TTY_IO_ERROR))
-                       return(-EIO);
+                       return -EIO;
        }
 
        rc = 0;
@@ -1590,36 +1519,26 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
        switch (cmd) {
        case TIOCGSOFTCAR:
                rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
-                       (unsigned int *) arg);
+                       (unsigned __user *) argp);
                break;
        case TIOCSSOFTCAR:
-               if ((rc = verify_area(VERIFY_READ, (void *) arg,
-                   sizeof(int))) == 0) {
-                       get_user(ival, (unsigned int *) arg);
-                       tty->termios->c_cflag =
+               if (get_user(ival, (unsigned int __user *) arg))
+                       return -EFAULT;
+               tty->termios->c_cflag =
                                (tty->termios->c_cflag & ~CLOCAL) |
                                (ival ? CLOCAL : 0);
-               }
                break;
        case TIOCGSERIAL:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(struct serial_struct))) == 0)
-                       rc = stl_getserial(portp, (struct serial_struct *) arg);
+               rc = stl_getserial(portp, argp);
                break;
        case TIOCSSERIAL:
-               if ((rc = verify_area(VERIFY_READ, (void *) arg,
-                   sizeof(struct serial_struct))) == 0)
-                       rc = stl_setserial(portp, (struct serial_struct *) arg);
+               rc = stl_setserial(portp, argp);
                break;
        case COM_GETPORTSTATS:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(comstats_t))) == 0)
-                       rc = stl_getportstats(portp, (comstats_t *) arg);
+               rc = stl_getportstats(portp, argp);
                break;
        case COM_CLRPORTSTATS:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(comstats_t))) == 0)
-                       rc = stl_clrportstats(portp, (comstats_t *) arg);
+               rc = stl_clrportstats(portp, argp);
                break;
        case TIOCSERCONFIG:
        case TIOCSERGWILD:
@@ -1633,7 +1552,7 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
                break;
        }
 
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -1643,7 +1562,7 @@ static void stl_settermios(struct tty_struct *tty, struct termios *old)
        stlport_t       *portp;
        struct termios  *tiosp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
 #endif
 
@@ -1680,7 +1599,7 @@ static void stl_throttle(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_throttle(tty=%x)\n", (int) tty);
 #endif
 
@@ -1702,7 +1621,7 @@ static void stl_unthrottle(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_unthrottle(tty=%x)\n", (int) tty);
 #endif
 
@@ -1725,7 +1644,7 @@ static void stl_stop(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_stop(tty=%x)\n", (int) tty);
 #endif
 
@@ -1747,7 +1666,7 @@ static void stl_start(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_start(tty=%x)\n", (int) tty);
 #endif
 
@@ -1771,7 +1690,7 @@ static void stl_hangup(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_hangup(tty=%x)\n", (int) tty);
 #endif
 
@@ -1807,7 +1726,7 @@ static void stl_flushbuffer(struct tty_struct *tty)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_flushbuffer(tty=%x)\n", (int) tty);
 #endif
 
@@ -1818,10 +1737,7 @@ static void stl_flushbuffer(struct tty_struct *tty)
                return;
 
        stl_flush(portp);
-       wake_up_interruptible(&tty->write_wait);
-       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-           tty->ldisc.write_wakeup)
-               (tty->ldisc.write_wakeup)(tty);
+       tty_wakeup(tty);
 }
 
 /*****************************************************************************/
@@ -1830,7 +1746,7 @@ static void stl_breakctl(struct tty_struct *tty, int state)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
 #endif
 
@@ -1850,7 +1766,7 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
        stlport_t       *portp;
        unsigned long   tend;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
 #endif
 
@@ -1867,7 +1783,7 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
        while (stl_datastate(portp)) {
                if (signal_pending(current))
                        break;
-               stl_delay(2);
+               msleep_interruptible(20);
                if (time_after_eq(jiffies, tend))
                        break;
        }
@@ -1879,7 +1795,7 @@ static void stl_sendxchar(struct tty_struct *tty, char ch)
 {
        stlport_t       *portp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
 #endif
 
@@ -1942,7 +1858,7 @@ static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
                pos[(MAXLINE - 2)] = '+';
        pos[(MAXLINE - 1)] = '\n';
 
-       return(MAXLINE);
+       return MAXLINE;
 }
 
 /*****************************************************************************/
@@ -1960,7 +1876,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
        int             curoff, maxoff;
        char            *pos;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
                "data=%x\n", (int) page, (int) start, (int) off, count,
                (int) eof, (int) data);
@@ -2027,7 +1943,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
 
 stl_readdone:
        *start = page;
-       return(pos - page);
+       return (pos - page);
 }
 
 /*****************************************************************************/
@@ -2039,23 +1955,14 @@ stl_readdone:
 
 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
 {
-       stlbrd_t        *brdp;
-       int             i;
-       int handled = 0;
+       stlbrd_t        *brdp = (stlbrd_t *) dev_id;
 
-#if DEBUG
-       printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
+#ifdef DEBUG
+       printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
+           (int) regs);
 #endif
 
-       for (i = 0; (i < stl_nrbrds); i++) {
-               if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
-                       continue;
-               if (brdp->state == 0)
-                       continue;
-               handled = 1;
-               (* brdp->isr)(brdp);
-       }
-       return IRQ_RETVAL(handled);
+       return IRQ_RETVAL((* brdp->isr)(brdp));
 }
 
 /*****************************************************************************/
@@ -2064,15 +1971,19 @@ static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
  *     Interrupt service routine for EasyIO board types.
  */
 
-static void stl_eiointr(stlbrd_t *brdp)
+static int stl_eiointr(stlbrd_t *brdp)
 {
        stlpanel_t      *panelp;
        unsigned int    iobase;
+       int             handled = 0;
 
        panelp = brdp->panels[0];
        iobase = panelp->iobase;
-       while (inb(brdp->iostatus) & EIO_INTRPEND)
+       while (inb(brdp->iostatus) & EIO_INTRPEND) {
+               handled = 1;
                (* panelp->isr)(panelp, iobase);
+       }
+       return handled;
 }
 
 /*****************************************************************************/
@@ -2081,15 +1992,17 @@ static void stl_eiointr(stlbrd_t *brdp)
  *     Interrupt service routine for ECH-AT board types.
  */
 
-static void stl_echatintr(stlbrd_t *brdp)
+static int stl_echatintr(stlbrd_t *brdp)
 {
        stlpanel_t      *panelp;
        unsigned int    ioaddr;
        int             bnknr;
+       int             handled = 0;
 
        outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
 
        while (inb(brdp->iostatus) & ECH_INTRPEND) {
+               handled = 1;
                for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
@@ -2100,6 +2013,8 @@ static void stl_echatintr(stlbrd_t *brdp)
        }
 
        outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
+
+       return handled;
 }
 
 /*****************************************************************************/
@@ -2108,13 +2023,15 @@ static void stl_echatintr(stlbrd_t *brdp)
  *     Interrupt service routine for ECH-MCA board types.
  */
 
-static void stl_echmcaintr(stlbrd_t *brdp)
+static int stl_echmcaintr(stlbrd_t *brdp)
 {
        stlpanel_t      *panelp;
        unsigned int    ioaddr;
        int             bnknr;
+       int             handled = 0;
 
        while (inb(brdp->iostatus) & ECH_INTRPEND) {
+               handled = 1;
                for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
@@ -2123,6 +2040,7 @@ static void stl_echmcaintr(stlbrd_t *brdp)
                        }
                }
        }
+       return handled;
 }
 
 /*****************************************************************************/
@@ -2131,11 +2049,12 @@ static void stl_echmcaintr(stlbrd_t *brdp)
  *     Interrupt service routine for ECH-PCI board types.
  */
 
-static void stl_echpciintr(stlbrd_t *brdp)
+static int stl_echpciintr(stlbrd_t *brdp)
 {
        stlpanel_t      *panelp;
        unsigned int    ioaddr;
        int             bnknr, recheck;
+       int             handled = 0;
 
        while (1) {
                recheck = 0;
@@ -2146,11 +2065,13 @@ static void stl_echpciintr(stlbrd_t *brdp)
                                panelp = brdp->bnk2panel[bnknr];
                                (* panelp->isr)(panelp, (ioaddr & 0xfffc));
                                recheck++;
+                               handled = 1;
                        }
                }
                if (! recheck)
                        break;
        }
+       return handled;
 }
 
 /*****************************************************************************/
@@ -2159,13 +2080,15 @@ static void stl_echpciintr(stlbrd_t *brdp)
  *     Interrupt service routine for ECH-8/64-PCI board types.
  */
 
-static void stl_echpci64intr(stlbrd_t *brdp)
+static int stl_echpci64intr(stlbrd_t *brdp)
 {
        stlpanel_t      *panelp;
        unsigned int    ioaddr;
        int             bnknr;
+       int             handled = 0;
 
        while (inb(brdp->ioctrl) & 0x1) {
+               handled = 1;
                for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
@@ -2174,6 +2097,8 @@ static void stl_echpci64intr(stlbrd_t *brdp)
                        }
                }
        }
+
+       return handled;
 }
 
 /*****************************************************************************/
@@ -2189,7 +2114,7 @@ static void stl_offintr(void *private)
 
        portp = private;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_offintr(portp=%x)\n", (int) portp);
 #endif
 
@@ -2202,10 +2127,7 @@ static void stl_offintr(void *private)
 
        lock_kernel();
        if (test_bit(ASYI_TXLOW, &portp->istate)) {
-               if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-                   tty->ldisc.write_wakeup)
-                       (tty->ldisc.write_wakeup)(tty);
-               wake_up_interruptible(&tty->write_wait);
+               tty_wakeup(tty);
        }
        if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
                clear_bit(ASYI_DCDCHANGE, &portp->istate);
@@ -2223,39 +2145,6 @@ static void stl_offintr(void *private)
 
 /*****************************************************************************/
 
-/*
- *     Map in interrupt vector to this driver. Check that we don't
- *     already have this vector mapped, we might be sharing this
- *     interrupt across multiple boards.
- */
-
-static int __init stl_mapirq(int irq, char *name)
-{
-       int     rc, i;
-
-#if DEBUG
-       printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
-#endif
-
-       rc = 0;
-       for (i = 0; (i < stl_numintrs); i++) {
-               if (stl_gotintrs[i] == irq)
-                       break;
-       }
-       if (i >= stl_numintrs) {
-               if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
-                       printk("STALLION: failed to register interrupt "
-                               "routine for %s irq=%d\n", name, irq);
-                       rc = -ENODEV;
-               } else {
-                       stl_gotintrs[stl_numintrs++] = irq;
-               }
-       }
-       return(rc);
-}
-
-/*****************************************************************************/
-
 /*
  *     Initialize all the ports on a panel.
  */
@@ -2265,7 +2154,7 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
        stlport_t       *portp;
        int             chipmask, i;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
 #endif
 
@@ -2276,13 +2165,12 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
  *     each ports data structures.
  */
        for (i = 0; (i < panelp->nrports); i++) {
-               portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
-               if (portp == (stlport_t *) NULL) {
+               portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
+               if (!portp) {
                        printk("STALLION: failed to allocate memory "
                                "(size=%d)\n", sizeof(stlport_t));
                        break;
                }
-               memset(portp, 0, sizeof(stlport_t));
 
                portp->magic = STL_PORTMAGIC;
                portp->portnr = i;
@@ -2319,7 +2207,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
        char            *name;
        int             rc;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_initeio(brdp=%x)\n", (int) brdp);
 #endif
 
@@ -2413,13 +2301,12 @@ static inline int stl_initeio(stlbrd_t *brdp)
  *     can complete the setup.
  */
 
-       panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
-       if (panelp == (stlpanel_t *) NULL) {
+       panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
+       if (!panelp) {
                printk(KERN_WARNING "STALLION: failed to allocate memory "
                        "(size=%d)\n", sizeof(stlpanel_t));
-               return(-ENOMEM);
+               return -ENOMEM;
        }
-       memset(panelp, 0, sizeof(stlpanel_t));
 
        panelp->magic = STL_PANELMAGIC;
        panelp->brdnr = brdp->brdnr;
@@ -2439,8 +2326,14 @@ static inline int stl_initeio(stlbrd_t *brdp)
        brdp->nrpanels = 1;
        brdp->state |= BRD_FOUND;
        brdp->hwid = status;
-       rc = stl_mapirq(brdp->irq, name);
-       return(rc);
+       if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
+               printk("STALLION: failed to register interrupt "
+                   "routine for %s irq=%d\n", name, brdp->irq);
+               rc = -ENODEV;
+       } else {
+               rc = 0;
+       }
+       return rc;
 }
 
 /*****************************************************************************/
@@ -2457,7 +2350,7 @@ static inline int stl_initech(stlbrd_t *brdp)
        int             panelnr, banknr, i;
        char            *name;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_initech(brdp=%x)\n", (int) brdp);
 #endif
 
@@ -2582,13 +2475,12 @@ static inline int stl_initech(stlbrd_t *brdp)
                status = inb(ioaddr + ECH_PNLSTATUS);
                if ((status & ECH_PNLIDMASK) != nxtid)
                        break;
-               panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
-               if (panelp == (stlpanel_t *) NULL) {
+               panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
+               if (!panelp) {
                        printk("STALLION: failed to allocate memory "
                                "(size=%d)\n", sizeof(stlpanel_t));
                        break;
                }
-               memset(panelp, 0, sizeof(stlpanel_t));
                panelp->magic = STL_PANELMAGIC;
                panelp->brdnr = brdp->brdnr;
                panelp->panelnr = panelnr;
@@ -2644,7 +2536,14 @@ static inline int stl_initech(stlbrd_t *brdp)
                outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
 
        brdp->state |= BRD_FOUND;
-       i = stl_mapirq(brdp->irq, name);
+       if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
+               printk("STALLION: failed to register interrupt "
+                   "routine for %s irq=%d\n", name, brdp->irq);
+               i = -ENODEV;
+       } else {
+               i = 0;
+       }
+
        return(i);
 }
 
@@ -2661,7 +2560,7 @@ static int __init stl_brdinit(stlbrd_t *brdp)
 {
        int     i;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_brdinit(brdp=%x)\n", (int) brdp);
 #endif
 
@@ -2707,7 +2606,7 @@ static int __init stl_brdinit(stlbrd_t *brdp)
  *     Find the next available board number that is free.
  */
 
-static inline int stl_getbrdnr()
+static inline int stl_getbrdnr(void)
 {
        int     i;
 
@@ -2735,7 +2634,7 @@ static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
 {
        stlbrd_t        *brdp;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
                devp->bus->number, devp->devfn);
 #endif
@@ -2755,7 +2654,7 @@ static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  *     Different Stallion boards use the BAR registers in different ways,
  *     so set up io addresses based on board type.
  */
-#if DEBUG
+#ifdef DEBUG
        printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
                pci_resource_start(devp, 0), pci_resource_start(devp, 1),
                pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
@@ -2797,12 +2696,12 @@ static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  */
 
 
-static inline int stl_findpcibrds()
+static inline int stl_findpcibrds(void)
 {
        struct pci_dev  *dev = NULL;
        int             i, rc;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_findpcibrds()\n");
 #endif
 
@@ -2835,13 +2734,13 @@ static inline int stl_findpcibrds()
  *     since the initial search and setup is too different.
  */
 
-static inline int stl_initbrds()
+static inline int stl_initbrds(void)
 {
        stlbrd_t        *brdp;
        stlconf_t       *confp;
        int             i;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_initbrds()\n");
 #endif
 
@@ -2857,9 +2756,7 @@ static inline int stl_initbrds()
  */
        for (i = 0; (i < stl_nrbrds); i++) {
                confp = &stl_brdconf[i];
-#ifdef MODULE
                stl_parsebrd(confp, stl_brdsp[i]);
-#endif
                if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
                        return(-ENOMEM);
                brdp->brdnr = i;
@@ -2875,9 +2772,7 @@ static inline int stl_initbrds()
  *     Find any dynamically supported boards. That is via module load
  *     line options or auto-detected on the PCI bus.
  */
-#ifdef MODULE
        stl_argbrds();
-#endif
 #ifdef CONFIG_PCI
        stl_findpcibrds();
 #endif
@@ -2891,7 +2786,7 @@ static inline int stl_initbrds()
  *     Return the board stats structure to user app.
  */
 
-static int stl_getbrdstats(combrd_t *bp)
+static int stl_getbrdstats(combrd_t __user *bp)
 {
        stlbrd_t        *brdp;
        stlpanel_t      *panelp;
@@ -2959,12 +2854,12 @@ static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
  *     what port to get stats for (used through board control device).
  */
 
-static int stl_getportstats(stlport_t *portp, comstats_t *cp)
+static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
 {
        unsigned char   *head, *tail;
        unsigned long   flags;
 
-       if (portp == (stlport_t *) NULL) {
+       if (!portp) {
                if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
                        return -EFAULT;
                portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
@@ -2989,7 +2884,8 @@ static int stl_getportstats(stlport_t *portp, comstats_t *cp)
        if (portp->tty != (struct tty_struct *) NULL) {
                if (portp->tty->driver_data == portp) {
                        portp->stats.ttystate = portp->tty->flags;
-                       portp->stats.rxbuffered = portp->tty->flip.count;
+                       /* No longer available as a statistic */
+                       portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
                        if (portp->tty->termios != (struct termios *) NULL) {
                                portp->stats.cflags = portp->tty->termios->c_cflag;
                                portp->stats.iflags = portp->tty->termios->c_iflag;
@@ -3017,9 +2913,9 @@ static int stl_getportstats(stlport_t *portp, comstats_t *cp)
  *     Clear the port stats structure. We also return it zeroed out...
  */
 
-static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
+static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
 {
-       if (portp == (stlport_t *) NULL) {
+       if (!portp) {
                if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
                        return -EFAULT;
                portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
@@ -3042,18 +2938,17 @@ static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
  *     Return the entire driver ports structure to a user app.
  */
 
-static int stl_getportstruct(unsigned long arg)
+static int stl_getportstruct(stlport_t __user *arg)
 {
        stlport_t       *portp;
 
-       if (copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t)))
+       if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
                return -EFAULT;
        portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
                 stl_dummyport.portnr);
-       if (portp == (stlport_t *) NULL)
-               return(-ENODEV);
-       return copy_to_user((void *)arg, portp,
-                           sizeof(stlport_t)) ? -EFAULT : 0;
+       if (!portp)
+               return -ENODEV;
+       return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
@@ -3062,18 +2957,18 @@ static int stl_getportstruct(unsigned long arg)
  *     Return the entire driver board structure to a user app.
  */
 
-static int stl_getbrdstruct(unsigned long arg)
+static int stl_getbrdstruct(stlbrd_t __user *arg)
 {
        stlbrd_t        *brdp;
 
-       if (copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t)))
+       if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
                return -EFAULT;
        if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stl_brds[stl_dummybrd.brdnr];
-       if (brdp == (stlbrd_t *) NULL)
+       if (!brdp)
                return(-ENODEV);
-       return copy_to_user((void *)arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
+       return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
@@ -3087,8 +2982,9 @@ static int stl_getbrdstruct(unsigned long arg)
 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
 {
        int     brdnr, rc;
+       void __user *argp = (void __user *)arg;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
                (int) fp, cmd, (int) arg);
 #endif
@@ -3100,31 +2996,19 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
 
        switch (cmd) {
        case COM_GETPORTSTATS:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(comstats_t))) == 0)
-                       rc = stl_getportstats((stlport_t *) NULL,
-                               (comstats_t *) arg);
+               rc = stl_getportstats(NULL, argp);
                break;
        case COM_CLRPORTSTATS:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(comstats_t))) == 0)
-                       rc = stl_clrportstats((stlport_t *) NULL,
-                               (comstats_t *) arg);
+               rc = stl_clrportstats(NULL, argp);
                break;
        case COM_GETBRDSTATS:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(combrd_t))) == 0)
-                       rc = stl_getbrdstats((combrd_t *) arg);
+               rc = stl_getbrdstats(argp);
                break;
        case COM_READPORT:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(stlport_t))) == 0)
-                       rc = stl_getportstruct(arg);
+               rc = stl_getportstruct(argp);
                break;
        case COM_READBOARD:
-               if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
-                   sizeof(stlbrd_t))) == 0)
-                       rc = stl_getbrdstruct(arg);
+               rc = stl_getbrdstruct(argp);
                break;
        default:
                rc = -ENOIOCTLCMD;
@@ -3160,7 +3044,7 @@ static struct tty_operations stl_ops = {
 
 /*****************************************************************************/
 
-int __init stl_init(void)
+static int __init stl_init(void)
 {
        int i;
        printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
@@ -3174,8 +3058,8 @@ int __init stl_init(void)
 /*
  *     Allocate a temporary write buffer.
  */
-       stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
-       if (stl_tmpwritebuf == (char *) NULL)
+       stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
+       if (!stl_tmpwritebuf)
                printk("STALLION: failed to allocate memory (size=%d)\n",
                        STL_TXBUFSIZE);
 
@@ -3187,12 +3071,14 @@ int __init stl_init(void)
                printk("STALLION: failed to register serial board device\n");
        devfs_mk_dir("staliomem");
 
-       stallion_class = class_simple_create(THIS_MODULE, "staliomem");
+       stallion_class = class_create(THIS_MODULE, "staliomem");
        for (i = 0; i < 4; i++) {
                devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
                                S_IFCHR|S_IRUSR|S_IWUSR,
                                "staliomem/%d", i);
-               class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
+               class_device_create(stallion_class, NULL,
+                                   MKDEV(STL_SIOMEMMAJOR, i), NULL,
+                                   "staliomem%d", i);
        }
 
        stl_serial->owner = THIS_MODULE;
@@ -3213,7 +3099,7 @@ int __init stl_init(void)
                return -1;
        }
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -3229,7 +3115,7 @@ int __init stl_init(void)
 static int stl_cd1400getreg(stlport_t *portp, int regnr)
 {
        outb((regnr + portp->uartaddr), portp->ioaddr);
-       return(inb(portp->ioaddr + EREG_DATA));
+       return inb(portp->ioaddr + EREG_DATA);
 }
 
 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
@@ -3243,9 +3129,9 @@ static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
        outb((regnr + portp->uartaddr), portp->ioaddr);
        if (inb(portp->ioaddr + EREG_DATA) != value) {
                outb(value, portp->ioaddr + EREG_DATA);
-               return(1);
+               return 1;
        }
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -3262,7 +3148,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
        int             chipmask, i, j;
        int             nrchips, uartaddr, ioaddr;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
 #endif
 
@@ -3303,7 +3189,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
        }
 
        BRDDISABLE(panelp->brdnr);
-       return(chipmask);
+       return chipmask;
 }
 
 /*****************************************************************************/
@@ -3314,7 +3200,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
 
 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
 {
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
                (int) brdp, (int) panelp, (int) portp);
 #endif
@@ -3529,7 +3415,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
  *     them all up.
  */
 
-#if DEBUG
+#ifdef DEBUG
        printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
                portp->portnr, portp->panelnr, portp->brdnr);
        printk("    cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
@@ -3594,7 +3480,7 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
        unsigned char   msvr1, msvr2;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
                (int) portp, dtr, rts);
 #endif
@@ -3630,7 +3516,7 @@ static int stl_cd1400getsignals(stlport_t *portp)
        unsigned long   flags;
        int             sigs;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
 #endif
 
@@ -3654,7 +3540,7 @@ static int stl_cd1400getsignals(stlport_t *portp)
 #else
        sigs |= TIOCM_DSR;
 #endif
-       return(sigs);
+       return sigs;
 }
 
 /*****************************************************************************/
@@ -3668,7 +3554,7 @@ static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
        unsigned char   ccr;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
                (int) portp, rx, tx);
 #endif
@@ -3705,7 +3591,7 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
        unsigned char   sreron, sreroff;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
                (int) portp, rx, tx);
 #endif
@@ -3745,7 +3631,7 @@ static void stl_cd1400disableintrs(stlport_t *portp)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
 #endif
        save_flags(flags);
@@ -3763,7 +3649,7 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
 #endif
 
@@ -3792,7 +3678,7 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
        struct tty_struct       *tty;
        unsigned long           flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
 #endif
 
@@ -3857,7 +3743,7 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
        struct tty_struct       *tty;
        unsigned long           flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
 #endif
 
@@ -3892,7 +3778,7 @@ static void stl_cd1400flush(stlport_t *portp)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400flush(portp=%x)\n", (int) portp);
 #endif
 
@@ -3922,14 +3808,14 @@ static void stl_cd1400flush(stlport_t *portp)
 
 static int stl_cd1400datastate(stlport_t *portp)
 {
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
 #endif
 
        if (portp == (stlport_t *) NULL)
-               return(0);
+               return 0;
 
-       return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
+       return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
 }
 
 /*****************************************************************************/
@@ -3942,7 +3828,7 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
 {
        unsigned char   svrtype;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
                (int) panelp, iobase);
 #endif
@@ -3972,7 +3858,7 @@ static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
 {
        unsigned char   svrtype;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
                iobase);
 #endif
@@ -4009,20 +3895,20 @@ static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
                outb((SRER + portp->uartaddr), ioaddr);
                outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
                        (ioaddr + EREG_DATA));
-               return(1);
+               return 1;
        } else if (portp->brklen > 1) {
                outb((TDR + portp->uartaddr), ioaddr);
                outb(ETC_CMD, (ioaddr + EREG_DATA));
                outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
                portp->brklen = -1;
-               return(1);
+               return 1;
        } else {
                outb((COR2 + portp->uartaddr), ioaddr);
                outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
                        (ioaddr + EREG_DATA));
                portp->brklen = 0;
        }
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4046,7 +3932,7 @@ static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
        char            *head, *tail;
        unsigned char   ioack, srer;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
 #endif
 
@@ -4128,7 +4014,7 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
        unsigned char           status;
        char                    ch;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
 #endif
 
@@ -4143,9 +4029,7 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
        if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
                outb((RDCR + portp->uartaddr), ioaddr);
                len = inb(ioaddr + EREG_DATA);
-               if ((tty == (struct tty_struct *) NULL) ||
-                   (tty->flip.char_buf_ptr == (char *) NULL) ||
-                   ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
+               if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
                        len = MIN(len, sizeof(stl_unwanted));
                        outb((RDSR + portp->uartaddr), ioaddr);
                        insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
@@ -4154,12 +4038,10 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
                } else {
                        len = MIN(len, buflen);
                        if (len > 0) {
+                               unsigned char *ptr;
                                outb((RDSR + portp->uartaddr), ioaddr);
-                               insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
-                               memset(tty->flip.flag_buf_ptr, 0, len);
-                               tty->flip.flag_buf_ptr += len;
-                               tty->flip.char_buf_ptr += len;
-                               tty->flip.count += len;
+                               tty_prepare_flip_string(tty, &ptr, len);
+                               insb((ioaddr + EREG_DATA), ptr, len);
                                tty_schedule_flip(tty);
                                portp->stats.rxtotal += len;
                        }
@@ -4183,8 +4065,7 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
                                portp->stats.txxoff++;
                        goto stl_rxalldone;
                }
-               if ((tty != (struct tty_struct *) NULL) &&
-                   ((portp->rxignoremsk & status) == 0)) {
+               if (tty != NULL && (portp->rxignoremsk & status) == 0) {
                        if (portp->rxmarkmsk & status) {
                                if (status & ST_BREAK) {
                                        status = TTY_BREAK;
@@ -4204,14 +4085,8 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
                        } else {
                                status = 0;
                        }
-                       if (tty->flip.char_buf_ptr != (char *) NULL) {
-                               if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-                                       *tty->flip.flag_buf_ptr++ = status;
-                                       *tty->flip.char_buf_ptr++ = ch;
-                                       tty->flip.count++;
-                               }
-                               tty_schedule_flip(tty);
-                       }
+                       tty_insert_flip_char(tty, ch, status);
+                       tty_schedule_flip(tty);
                }
        } else {
                printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
@@ -4237,7 +4112,7 @@ static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
        unsigned int    ioack;
        unsigned char   misr;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
 #endif
 
@@ -4274,7 +4149,7 @@ static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
 static int stl_sc26198getreg(stlport_t *portp, int regnr)
 {
        outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
-       return(inb(portp->ioaddr + XP_DATA));
+       return inb(portp->ioaddr + XP_DATA);
 }
 
 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
@@ -4288,9 +4163,9 @@ static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
        outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
        if (inb(portp->ioaddr + XP_DATA) != value) {
                outb(value, (portp->ioaddr + XP_DATA));
-               return(1);
+               return 1;
        }
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4302,7 +4177,7 @@ static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
 {
        outb(regnr, (portp->ioaddr + XP_ADDR));
-       return(inb(portp->ioaddr + XP_DATA));
+       return inb(portp->ioaddr + XP_DATA);
 }
 
 #if 0
@@ -4326,7 +4201,7 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
        int     chipmask, i;
        int     nrchips, ioaddr;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
                (int) brdp, (int) panelp);
 #endif
@@ -4360,7 +4235,7 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
        }
 
        BRDDISABLE(panelp->brdnr);
-       return(chipmask);
+       return chipmask;
 }
 
 /*****************************************************************************/
@@ -4371,7 +4246,7 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
 
 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
 {
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
                (int) brdp, (int) panelp, (int) portp);
 #endif
@@ -4548,7 +4423,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
  *     them all up.
  */
 
-#if DEBUG
+#ifdef DEBUG
        printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
                portp->portnr, portp->panelnr, portp->brdnr);
        printk("    mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
@@ -4600,7 +4475,7 @@ static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
        unsigned char   iopioron, iopioroff;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
                (int) portp, dtr, rts);
 #endif
@@ -4637,7 +4512,7 @@ static int stl_sc26198getsignals(stlport_t *portp)
        unsigned long   flags;
        int             sigs;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
 #endif
 
@@ -4654,7 +4529,7 @@ static int stl_sc26198getsignals(stlport_t *portp)
        sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
        sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
        sigs |= TIOCM_DSR;
-       return(sigs);
+       return sigs;
 }
 
 /*****************************************************************************/
@@ -4668,7 +4543,7 @@ static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
        unsigned char   ccr;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
                (int) portp, rx, tx);
 #endif
@@ -4703,7 +4578,7 @@ static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
        unsigned char   imr;
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
                (int) portp, rx, tx);
 #endif
@@ -4739,7 +4614,7 @@ static void stl_sc26198disableintrs(stlport_t *portp)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
 #endif
 
@@ -4758,7 +4633,7 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
 #endif
 
@@ -4787,7 +4662,7 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
        unsigned long           flags;
        unsigned char           mr0;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
 #endif
 
@@ -4859,7 +4734,7 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
        unsigned long           flags;
        unsigned char           mr0;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
 #endif
 
@@ -4899,7 +4774,7 @@ static void stl_sc26198flush(stlport_t *portp)
 {
        unsigned long   flags;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198flush(portp=%x)\n", (int) portp);
 #endif
 
@@ -4931,14 +4806,14 @@ static int stl_sc26198datastate(stlport_t *portp)
        unsigned long   flags;
        unsigned char   sr;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
 #endif
 
        if (portp == (stlport_t *) NULL)
-               return(0);
+               return 0;
        if (test_bit(ASYI_TXBUSY, &portp->istate))
-               return(1);
+               return 1;
 
        save_flags(flags);
        cli();
@@ -4947,7 +4822,7 @@ static int stl_sc26198datastate(stlport_t *portp)
        BRDDISABLE(portp->brdnr);
        restore_flags(flags);
 
-       return((sr & SR_TXEMPTY) ? 0 : 1);
+       return (sr & SR_TXEMPTY) ? 0 : 1;
 }
 
 /*****************************************************************************/
@@ -4961,7 +4836,7 @@ static void stl_sc26198wait(stlport_t *portp)
 {
        int     i;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198wait(portp=%x)\n", (int) portp);
 #endif
 
@@ -5039,7 +4914,7 @@ static void stl_sc26198txisr(stlport_t *portp)
        int             len, stlen;
        char            *head, *tail;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
 #endif
 
@@ -5100,7 +4975,7 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
        struct tty_struct       *tty;
        unsigned int            len, buflen, ioaddr;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
 #endif
 
@@ -5110,9 +4985,7 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
        len = inb(ioaddr + XP_DATA) + 1;
 
        if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
-               if ((tty == (struct tty_struct *) NULL) ||
-                   (tty->flip.char_buf_ptr == (char *) NULL) ||
-                   ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
+               if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
                        len = MIN(len, sizeof(stl_unwanted));
                        outb(GRXFIFO, (ioaddr + XP_ADDR));
                        insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
@@ -5121,12 +4994,10 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
                } else {
                        len = MIN(len, buflen);
                        if (len > 0) {
+                               unsigned char *ptr;
                                outb(GRXFIFO, (ioaddr + XP_ADDR));
-                               insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
-                               memset(tty->flip.flag_buf_ptr, 0, len);
-                               tty->flip.flag_buf_ptr += len;
-                               tty->flip.char_buf_ptr += len;
-                               tty->flip.count += len;
+                               tty_prepare_flip_string(tty, &ptr, len);
+                               insb((ioaddr + XP_DATA), ptr, len);
                                tty_schedule_flip(tty);
                                portp->stats.rxtotal += len;
                        }
@@ -5194,14 +5065,8 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
                        status = 0;
                }
 
-               if (tty->flip.char_buf_ptr != (char *) NULL) {
-                       if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-                               *tty->flip.flag_buf_ptr++ = status;
-                               *tty->flip.char_buf_ptr++ = ch;
-                               tty->flip.count++;
-                       }
-                       tty_schedule_flip(tty);
-               }
+               tty_insert_flip_char(tty, ch, status);
+               tty_schedule_flip(tty);
 
                if (status == 0)
                        portp->stats.rxtotal++;
@@ -5256,7 +5121,7 @@ static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
 {
        unsigned char   cir, ipr, xisr;
 
-#if DEBUG
+#ifdef DEBUG
        printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
 #endif