Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / drivers / char / mxser.c
index 19bacae..0fb2fb9 100644 (file)
@@ -38,7 +38,6 @@
 
 #include <linux/config.h>
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/autoconf.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
@@ -63,7 +62,6 @@
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/irq.h>
-#include <asm/segment.h>
 #include <asm/bitops.h>
 #include <asm/uaccess.h>
 
@@ -179,7 +177,7 @@ static int mxser_numports[] = {
 
 #define UART_TYPE_NUM  2
 
-unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
+static const unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
        MOXA_MUST_MU150_HWID,
        MOXA_MUST_MU860_HWID
 };
@@ -197,7 +195,7 @@ struct mxpciuart_info {
        long max_baud;
 };
 
-struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
+static const struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
        {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
        {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
        {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
@@ -245,10 +243,10 @@ static int verbose = 0;
 
 MODULE_AUTHOR("Casper Yang");
 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
-MODULE_PARM(ioaddr, "1-4i");
-MODULE_PARM(ttymajor, "i");
-MODULE_PARM(calloutmajor, "i");
-MODULE_PARM(verbose, "i");
+module_param_array(ioaddr, int, NULL, 0);
+module_param(ttymajor, int, 0);
+module_param(calloutmajor, int, 0);
+module_param(verbose, bool, 0);
 MODULE_LICENSE("GPL");
 
 struct mxser_log {
@@ -471,6 +469,8 @@ static struct tty_operations mxser_ops = {
        .stop = mxser_stop,
        .start = mxser_start,
        .hangup = mxser_hangup,
+       .break_ctl = mxser_rs_break,
+       .wait_until_sent = mxser_wait_until_sent,
        .tiocmget = mxser_tiocmget,
        .tiocmset = mxser_tiocmset,
 };
@@ -493,14 +493,18 @@ static int __init mxser_module_init(void)
 
 static void __exit mxser_module_exit(void)
 {
-       int i, err = 0;
+       int i, err;
 
        if (verbose)
                printk(KERN_DEBUG "Unloading module mxser ...\n");
 
-       if ((err |= tty_unregister_driver(mxvar_sdriver)))
+       err = tty_unregister_driver(mxvar_sdriver);
+       if (!err)
+               put_tty_driver(mxvar_sdriver);
+       else
                printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
 
+
        for (i = 0; i < MXSER_BOARDS; i++) {
                struct pci_dev *pdev;
 
@@ -548,7 +552,6 @@ static void process_txrx_fifo(struct mxser_struct *info)
 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
 {
        struct mxser_struct *info;
-       unsigned long flags;
        int retval;
        int i, n;
 
@@ -556,7 +559,7 @@ static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
        info = &mxvar_table[n];
        /*if (verbose) */  {
                printk(KERN_DEBUG "        ttyM%d - ttyM%d ", n, n + hwconf->ports - 1);
-               printk(KERN_DEBUG " max. baud rate = %d bps.\n", hwconf->MaxCanSetBaudRate[0]);
+               printk(" max. baud rate = %d bps.\n", hwconf->MaxCanSetBaudRate[0]);
        }
 
        for (i = 0; i < hwconf->ports; i++, n++, info++) {
@@ -609,18 +612,12 @@ static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
        n = board * MXSER_PORTS_PER_BOARD;
        info = &mxvar_table[n];
 
-       spin_lock_irqsave(&info->slock, flags);
        retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info), "mxser", info);
        if (retval) {
-               spin_unlock_irqrestore(&info->slock, flags);
                printk(KERN_ERR "Board %d: %s", board, mxser_brdname[hwconf->board_type - 1]);
                printk("  Request irq fail,IRQ (%d) may be conflit with another device.\n", info->irq);
                return retval;
        }
-
-       spin_unlock_irqrestore(&info->slock, flags);
-
-
        return 0;
 }
 
@@ -696,7 +693,6 @@ static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxs
 static int mxser_init(void)
 {
        int i, m, retval, b, n;
-       int ret1;
        struct pci_dev *pdev = NULL;
        int index;
        unsigned char busnum, devnum;
@@ -730,24 +726,6 @@ static int mxser_init(void)
        mxvar_sdriver->termios = mxvar_termios;
        mxvar_sdriver->termios_locked = mxvar_termios_locked;
 
-       mxvar_sdriver->open = mxser_open;
-       mxvar_sdriver->close = mxser_close;
-       mxvar_sdriver->write = mxser_write;
-       mxvar_sdriver->put_char = mxser_put_char;
-       mxvar_sdriver->flush_chars = mxser_flush_chars;
-       mxvar_sdriver->write_room = mxser_write_room;
-       mxvar_sdriver->chars_in_buffer = mxser_chars_in_buffer;
-       mxvar_sdriver->flush_buffer = mxser_flush_buffer;
-       mxvar_sdriver->ioctl = mxser_ioctl;
-       mxvar_sdriver->throttle = mxser_throttle;
-       mxvar_sdriver->unthrottle = mxser_unthrottle;
-       mxvar_sdriver->set_termios = mxser_set_termios;
-       mxvar_sdriver->stop = mxser_stop;
-       mxvar_sdriver->start = mxser_start;
-       mxvar_sdriver->hangup = mxser_hangup;
-       mxvar_sdriver->break_ctl = mxser_rs_break;
-       mxvar_sdriver->wait_until_sent = mxser_wait_until_sent;
-
        mxvar_diagflag = 0;
        memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
        memset(&mxvar_log, 0, sizeof(struct mxser_log));
@@ -835,7 +813,7 @@ static int mxser_init(void)
 
        /* start finding PCI board here */
 #ifdef CONFIG_PCI
-       n = (sizeof(mxser_pcibrds) / sizeof(mxser_pcibrds[0])) - 1;
+       n = ARRAY_SIZE(mxser_pcibrds) - 1;
        index = 0;
        b = 0;
        while (b < n) {
@@ -878,14 +856,11 @@ static int mxser_init(void)
        }
 #endif
 
-       ret1 = 0;
-       if (!(ret1 = tty_register_driver(mxvar_sdriver))) {
-               return 0;
-       } else
+       retval = tty_register_driver(mxvar_sdriver);
+       if (retval) {
                printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n");
+               put_tty_driver(mxvar_sdriver);
 
-
-       if (ret1) {
                for (i = 0; i < MXSER_BOARDS; i++) {
                        if (mxsercfg[i].board_type == -1)
                                continue;
@@ -894,10 +869,10 @@ static int mxser_init(void)
                                //todo: release io, vector
                        }
                }
-               return -1;
+               return retval;
        }
 
-       return (0);
+       return 0;
 }
 
 static void mxser_do_softint(void *private_)
@@ -941,6 +916,9 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
        struct mxser_struct *info;
        int retval, line;
 
+       /* initialize driver_data in case something fails */
+       tty->driver_data = NULL;
+
        line = tty->index;
        if (line == MXSER_PORTS)
                return 0;
@@ -1003,7 +981,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
        if (tty->index == MXSER_PORTS)
                return;
        if (!info)
-               BUG();
+               return;
 
        spin_lock_irqsave(&info->slock, flags);
 
@@ -1066,8 +1044,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
                 */
                timeout = jiffies + HZ;
                while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       schedule_timeout(5);
+                       schedule_timeout_interruptible(5);
                        if (time_after(jiffies, timeout))
                                break;
                }
@@ -1088,10 +1065,8 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
        info->event = 0;
        info->tty = NULL;
        if (info->blocked_open) {
-               if (info->close_delay) {
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       schedule_timeout(info->close_delay);
-               }
+               if (info->close_delay)
+                       schedule_timeout_interruptible(info->close_delay);
                wake_up_interruptible(&info->open_wait);
        }
 
@@ -1809,8 +1784,7 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
                printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
 #endif
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(char_time);
+               schedule_timeout_interruptible(char_time);
                if (signal_pending(current))
                        break;
                if (timeout && time_after(jiffies, orig_jiffies + timeout))
@@ -2002,26 +1976,19 @@ static void mxser_receive_chars(struct mxser_struct *info, int *status)
        unsigned char ch, gdl;
        int ignored = 0;
        int cnt = 0;
-       unsigned char *cp;
-       char *fp;
-       int count;
        int recv_room;
        int max = 256;
        unsigned long flags;
 
        spin_lock_irqsave(&info->slock, flags);
 
-       recv_room = tty->ldisc.receive_room(tty);
+       recv_room = tty->receive_room;
        if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
                //mxser_throttle(tty);
                mxser_stoprx(tty);
                //return;
        }
 
-       cp = tty->flip.char_buf;
-       fp = tty->flip.flag_buf;
-       count = 0;
-
        // following add by Victor Yu. 09-02-2002
        if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
 
@@ -2048,12 +2015,10 @@ static void mxser_receive_chars(struct mxser_struct *info, int *status)
                }
                while (gdl--) {
                        ch = inb(info->base + UART_RX);
-                       count++;
-                       *cp++ = ch;
-                       *fp++ = 0;
+                       tty_insert_flip_char(tty, ch, 0);
                        cnt++;
                        /*
-                          if((count>=HI_WATER) && (info->stop_rx==0)){
+                          if((cnt>=HI_WATER) && (info->stop_rx==0)){
                           mxser_stoprx(tty);
                           info->stop_rx=1;
                           break;
@@ -2068,7 +2033,7 @@ intr_old:
                if (max-- < 0)
                        break;
                /*
-                  if((count>=HI_WATER) && (info->stop_rx==0)){
+                  if((cnt>=HI_WATER) && (info->stop_rx==0)){
                   mxser_stoprx(tty);
                   info->stop_rx=1;
                   break;
@@ -2085,36 +2050,33 @@ intr_old:
                        if (++ignored > 100)
                                break;
                } else {
-                       count++;
+                       char flag = 0;
                        if (*status & UART_LSR_SPECIAL) {
                                if (*status & UART_LSR_BI) {
-                                       *fp++ = TTY_BREAK;
+                                       flag = TTY_BREAK;
 /* added by casper 1/11/2000 */
                                        info->icount.brk++;
-
 /* */
                                        if (info->flags & ASYNC_SAK)
                                                do_SAK(tty);
                                } else if (*status & UART_LSR_PE) {
-                                       *fp++ = TTY_PARITY;
+                                       flag = TTY_PARITY;
 /* added by casper 1/11/2000 */
                                        info->icount.parity++;
 /* */
                                } else if (*status & UART_LSR_FE) {
-                                       *fp++ = TTY_FRAME;
+                                       flag = TTY_FRAME;
 /* added by casper 1/11/2000 */
                                        info->icount.frame++;
 /* */
                                } else if (*status & UART_LSR_OE) {
-                                       *fp++ = TTY_OVERRUN;
+                                       flag = TTY_OVERRUN;
 /* added by casper 1/11/2000 */
                                        info->icount.overrun++;
 /* */
-                               } else
-                                       *fp++ = 0;
-                       } else
-                               *fp++ = 0;
-                       *cp++ = ch;
+                               }
+                       }
+                       tty_insert_flip_char(tty, ch, flag);
                        cnt++;
                        if (cnt >= recv_room) {
                                if (!info->ldisc_stop_rx) {
@@ -2139,15 +2101,14 @@ intr_old:
                // above add by Victor Yu. 09-02-2002
        } while (*status & UART_LSR_DR);
 
-      end_intr:                // add by Victor Yu. 09-02-2002
+end_intr:              // add by Victor Yu. 09-02-2002
 
        mxvar_log.rxcnt[info->port] += cnt;
        info->mon_data.rxcnt += cnt;
        info->mon_data.up_rxcnt += cnt;
-
-       tty->ldisc.receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
        spin_unlock_irqrestore(&info->slock, flags);
 
+       tty_flip_buffer_push(tty);
 }
 
 static void mxser_transmit_chars(struct mxser_struct *info)
@@ -3174,22 +3135,5 @@ static void mxser_normal_mode(int port)
        outb(0x00, port + 4);
 }
 
-// added by James 03-05-2004.
-// for secure device server:
-// stat = 1, the port8 DTR is set to ON.
-// stat = 0, the port8 DTR is set to OFF.
-void SDS_PORT8_DTR(int stat)
-{
-       int _sds_oldmcr;
-       _sds_oldmcr = inb(mxvar_table[7].base + UART_MCR);      // get old MCR
-       if (stat == 1) {
-               outb(_sds_oldmcr | 0x01, mxvar_table[7].base + UART_MCR);       // set DTR ON
-       }
-       if (stat == 0) {
-               outb(_sds_oldmcr & 0xfe, mxvar_table[7].base + UART_MCR);       // set DTR OFF
-       }
-       return;
-}
-
 module_init(mxser_module_init);
 module_exit(mxser_module_exit);