pcmcia: introduce autoconfiguration feature
[linux-2.6.git] / drivers / char / pcmcia / synclink_cs.c
index d3ea53a..c701434 100644 (file)
@@ -35,7 +35,6 @@
 
 #define MAX_DEVICE_COUNT 4
 
-#include <linux/config.h>      
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
@@ -43,7 +42,6 @@
 #include <linux/timer.h>
 #include <linux/time.h>
 #include <linux/interrupt.h>
-#include <linux/pci.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/serial.h>
 #include <linux/ptrace.h>
 #include <linux/ioport.h>
 #include <linux/mm.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/netdevice.h>
 #include <linux/vmalloc.h>
 #include <linux/init.h>
-#include <asm/serial.h>
 #include <linux/delay.h>
 #include <linux/ioctl.h>
+#include <linux/synclink.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
 #include <linux/workqueue.h>
 #include <linux/hdlc.h>
 
-#include <pcmcia/cs_types.h>
-#include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
 
-#ifdef CONFIG_HDLC_MODULE
-#define CONFIG_HDLC 1
+#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_CS_MODULE))
+#define SYNCLINK_GENERIC_HDLC 1
+#else
+#define SYNCLINK_GENERIC_HDLC 0
 #endif
 
 #define GET_USER(error,value,addr) error = get_user(value,addr)
@@ -88,8 +87,6 @@
 
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
 static MGSL_PARAMS default_params = {
        MGSL_MODE_HDLC,                 /* unsigned long mode */
        0,                              /* unsigned char loopback; */
@@ -124,7 +121,7 @@ typedef struct
 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
 
 struct _input_signal_events {
-       int     ri_up;  
+       int     ri_up;
        int     ri_down;
        int     dsr_up;
        int     dsr_down;
@@ -138,24 +135,19 @@ struct _input_signal_events {
 /*
  * Device instance data structure
  */
+
 typedef struct _mgslpc_info {
+       struct tty_port         port;
        void *if_ptr;   /* General purpose pointer (used by SPPP) */
        int                     magic;
-       int                     flags;
-       int                     count;          /* count of opens */
        int                     line;
-       unsigned short          close_delay;
-       unsigned short          closing_wait;   /* time to wait before closing */
-       
+
        struct mgsl_icount      icount;
-       
-       struct tty_struct       *tty;
+
        int                     timeout;
        int                     x_char;         /* xon/xoff character */
-       int                     blocked_open;   /* # of blocked opens */
        unsigned char           read_status_mask;
-       unsigned char           ignore_status_mask;     
+       unsigned char           ignore_status_mask;
 
        unsigned char *tx_buf;
        int            tx_put;
@@ -171,10 +163,7 @@ typedef struct _mgslpc_info {
        int            rx_buf_size;    /* size in bytes of single rx buffer */
        int            rx_buf_count;   /* total number of rx buffers */
        int            rx_frame_count; /* number of full rx buffers */
-       
-       wait_queue_head_t       open_wait;
-       wait_queue_head_t       close_wait;
-       
+
        wait_queue_head_t       status_event_wait_q;
        wait_queue_head_t       event_wait_q;
        struct timer_list       tx_timer;       /* HDLC transmit timeout timer */
@@ -191,20 +180,20 @@ typedef struct _mgslpc_info {
 
        u32 pending_bh;
 
-       int bh_running;
-       int bh_requested;
-       
+       bool bh_running;
+       bool bh_requested;
+
        int dcd_chkcount; /* check counts to prevent */
        int cts_chkcount; /* too many IRQs if a signal */
        int dsr_chkcount; /* is floating */
        int ri_chkcount;
 
-       int rx_enabled;
-       int rx_overflow;
+       bool rx_enabled;
+       bool rx_overflow;
 
-       int tx_enabled;
-       int tx_active;
-       int tx_aborting;
+       bool tx_enabled;
+       bool tx_active;
+       bool tx_aborting;
        u32 idle_mode;
 
        int if_mode; /* serial interface selection (RS-232, v.35 etc) */
@@ -213,31 +202,29 @@ typedef struct _mgslpc_info {
 
        unsigned int io_base;   /* base I/O address of adapter */
        unsigned int irq_level;
-       
+
        MGSL_PARAMS params;             /* communications parameters */
 
        unsigned char serial_signals;   /* current serial signal states */
 
-       char irq_occurred;              /* for diagnostics use */
+       bool irq_occurred;              /* for diagnostics use */
        char testing_irq;
        unsigned int init_error;        /* startup error (DIAGS)        */
 
        char flag_buf[MAX_ASYNC_BUFFER_SIZE];
-       BOOLEAN drop_rts_on_tx_done;
+       bool drop_rts_on_tx_done;
 
        struct  _input_signal_events    input_signal_events;
 
        /* PCMCIA support */
-       dev_link_t            link;
-       dev_node_t            node;
+       struct pcmcia_device    *p_dev;
        int                   stop;
 
        /* SPPP/Cisco HDLC device parts */
        int netcount;
-       int dosyncppp;
        spinlock_t netlock;
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        struct net_device *netdev;
 #endif
 
@@ -250,7 +237,7 @@ typedef struct _mgslpc_info {
  */
 #define TXBUFSIZE 4096
 
-    
+
 #define CHA     0x00   /* channel A offset */
 #define CHB     0x40   /* channel B offset */
 
@@ -299,9 +286,9 @@ typedef struct _mgslpc_info {
 #define PIM     0x3d
 #define PCR     0x3e
 #define CCR4    0x3f
-    
+
 // IMR/ISR
-    
+
 #define IRQ_BREAK_ON    BIT15   // rx break detected
 #define IRQ_DATAOVERRUN BIT14  // receive data overflow
 #define IRQ_ALLSENT     BIT13  // all sent
@@ -316,13 +303,13 @@ typedef struct _mgslpc_info {
 #define IRQ_DCD         BIT2   // carrier detect status change
 #define IRQ_OVERRUN     BIT1   // receive frame overflow
 #define IRQ_RXFIFO      BIT0   // receive pool full
-    
+
 // STAR
-    
+
 #define XFW   BIT6             // transmit FIFO write enable
 #define CEC   BIT2             // command executing
 #define CTS   BIT1             // CTS state
-    
+
 #define PVR_DTR      BIT0
 #define PVR_DSR      BIT1
 #define PVR_RI       BIT2
@@ -330,25 +317,25 @@ typedef struct _mgslpc_info {
 #define PVR_RS232    0x20   /* 0010b */
 #define PVR_V35      0xe0   /* 1110b */
 #define PVR_RS422    0x40   /* 0100b */
-    
-/* Register access functions */ 
-    
+
+/* Register access functions */
+
 #define write_reg(info, reg, val) outb((val),(info)->io_base + (reg))
 #define read_reg(info, reg) inb((info)->io_base + (reg))
 
-#define read_reg16(info, reg) inw((info)->io_base + (reg))  
+#define read_reg16(info, reg) inw((info)->io_base + (reg))
 #define write_reg16(info, reg, val) outw((val), (info)->io_base + (reg))
-    
+
 #define set_reg_bits(info, reg, mask) \
     write_reg(info, (reg), \
-                (unsigned char) (read_reg(info, (reg)) | (mask)))  
+                (unsigned char) (read_reg(info, (reg)) | (mask)))
 #define clear_reg_bits(info, reg, mask) \
     write_reg(info, (reg), \
-                (unsigned char) (read_reg(info, (reg)) & ~(mask)))  
+                (unsigned char) (read_reg(info, (reg)) & ~(mask)))
 /*
  * interrupt enable/disable routines
- */ 
-static void irq_disable(MGSLPC_INFO *info, unsigned char channel, unsigned short mask) 
+ */
+static void irq_disable(MGSLPC_INFO *info, unsigned char channel, unsigned short mask)
 {
        if (channel == CHA) {
                info->imra_value |= mask;
@@ -358,7 +345,7 @@ static void irq_disable(MGSLPC_INFO *info, unsigned char channel, unsigned short
                write_reg16(info, CHB + IMR, info->imrb_value);
        }
 }
-static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short mask) 
+static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short mask)
 {
        if (channel == CHA) {
                info->imra_value &= ~mask;
@@ -378,7 +365,7 @@ static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short
 static void rx_start(MGSLPC_INFO *info);
 static void rx_stop(MGSLPC_INFO *info);
 
-static void tx_start(MGSLPC_INFO *info);
+static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty);
 static void tx_stop(MGSLPC_INFO *info);
 static void tx_set_idle(MGSLPC_INFO *info);
 
@@ -392,9 +379,10 @@ static void async_mode(MGSLPC_INFO *info);
 
 static void tx_timeout(unsigned long context);
 
-static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg);
+static int carrier_raised(struct tty_port *port);
+static void dtr_rts(struct tty_port *port, int onoff);
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
 static void hdlcdev_tx_done(MGSLPC_INFO *info);
 static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size);
@@ -404,8 +392,8 @@ static void hdlcdev_exit(MGSLPC_INFO *info);
 
 static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit);
 
-static BOOLEAN register_test(MGSLPC_INFO *info);
-static BOOLEAN irq_test(MGSLPC_INFO *info);
+static bool register_test(MGSLPC_INFO *info);
+static bool irq_test(MGSLPC_INFO *info);
 static int adapter_test(MGSLPC_INFO *info);
 
 static int claim_resources(MGSLPC_INFO *info);
@@ -413,18 +401,18 @@ static void release_resources(MGSLPC_INFO *info);
 static void mgslpc_add_device(MGSLPC_INFO *info);
 static void mgslpc_remove_device(MGSLPC_INFO *info);
 
-static int  rx_get_frame(MGSLPC_INFO *info);
+static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty);
 static void rx_reset_buffers(MGSLPC_INFO *info);
 static int  rx_alloc_buffers(MGSLPC_INFO *info);
 static void rx_free_buffers(MGSLPC_INFO *info);
 
-static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs);
+static irqreturn_t mgslpc_isr(int irq, void *dev_id);
 
 /*
  * Bottom half interrupt handlers
  */
-static void bh_handler(void* Context);
-static void bh_transmit(MGSLPC_INFO *info);
+static void bh_handler(struct work_struct *work);
+static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty);
 static void bh_status(MGSLPC_INFO *info);
 
 /*
@@ -435,10 +423,10 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
                    unsigned int set, unsigned int clear);
 static int get_stats(MGSLPC_INFO *info, struct mgsl_icount __user *user_icount);
 static int get_params(MGSLPC_INFO *info, MGSL_PARAMS __user *user_params);
-static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params);
+static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params, struct tty_struct *tty);
 static int get_txidle(MGSLPC_INFO *info, int __user *idle_mode);
 static int set_txidle(MGSLPC_INFO *info, int idle_mode);
-static int set_txenable(MGSLPC_INFO *info, int enable);
+static int set_txenable(MGSLPC_INFO *info, int enable, struct tty_struct *tty);
 static int tx_abort(MGSLPC_INFO *info);
 static int set_rxenable(MGSLPC_INFO *info, int enable);
 static int wait_events(MGSLPC_INFO *info, int __user *mask);
@@ -461,13 +449,11 @@ static int ttymajor=0;
 
 static int debug_level = 0;
 static int maxframe[MAX_DEVICE_COUNT] = {0,};
-static int dosyncppp[MAX_DEVICE_COUNT] = {1,1,1,1};
 
 module_param(break_on_load, bool, 0);
 module_param(ttymajor, int, 0);
 module_param(debug_level, int, 0);
 module_param_array(maxframe, int, NULL, 0);
-module_param_array(dosyncppp, int, NULL, 0);
 
 MODULE_LICENSE("GPL");
 
@@ -479,12 +465,12 @@ static struct tty_driver *serial_driver;
 /* number of characters left in xmit buffer before we ask for more */
 #define WAKEUP_CHARS 256
 
-static void mgslpc_change_params(MGSLPC_INFO *info);
+static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty);
 static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
 
 /* PCMCIA prototypes */
 
-static void mgslpc_config(dev_link_t *link);
+static int mgslpc_config(struct pcmcia_device *link);
 static void mgslpc_release(u_long arg);
 static void mgslpc_detach(struct pcmcia_device *p_dev);
 
@@ -505,20 +491,9 @@ static void* mgslpc_get_text_ptr(void)
  * The wrappers maintain line discipline references
  * while calling into the line discipline.
  *
- * ldisc_flush_buffer - flush line discipline receive buffers
  * ldisc_receive_buf  - pass receive data to line discipline
  */
 
-static void ldisc_flush_buffer(struct tty_struct *tty)
-{
-       struct tty_ldisc *ld = tty_ldisc_ref(tty);
-       if (ld) {
-               if (ld->flush_buffer)
-                       ld->flush_buffer(tty);
-               tty_ldisc_deref(ld);
-       }
-}
-
 static void ldisc_receive_buf(struct tty_struct *tty,
                              const __u8 *data, char *flags, int count)
 {
@@ -527,63 +502,56 @@ static void ldisc_receive_buf(struct tty_struct *tty,
                return;
        ld = tty_ldisc_ref(tty);
        if (ld) {
-               if (ld->receive_buf)
-                       ld->receive_buf(tty, data, flags, count);
+               if (ld->ops->receive_buf)
+                       ld->ops->receive_buf(tty, data, flags, count);
                tty_ldisc_deref(ld);
        }
 }
 
-static int mgslpc_attach(struct pcmcia_device *p_dev)
+static const struct tty_port_operations mgslpc_port_ops = {
+       .carrier_raised = carrier_raised,
+       .dtr_rts = dtr_rts
+};
+
+static int mgslpc_probe(struct pcmcia_device *link)
 {
     MGSLPC_INFO *info;
-    dev_link_t *link;
-    
+    int ret;
+
     if (debug_level >= DEBUG_LEVEL_INFO)
            printk("mgslpc_attach\n");
-       
-    info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
+
+    info = kzalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
     if (!info) {
            printk("Error can't allocate device instance data\n");
            return -ENOMEM;
     }
 
-    memset(info, 0, sizeof(MGSLPC_INFO));
     info->magic = MGSLPC_MAGIC;
-    INIT_WORK(&info->task, bh_handler, info);
+    tty_port_init(&info->port);
+    info->port.ops = &mgslpc_port_ops;
+    INIT_WORK(&info->task, bh_handler);
     info->max_frame_size = 4096;
-    info->close_delay = 5*HZ/10;
-    info->closing_wait = 30*HZ;
-    init_waitqueue_head(&info->open_wait);
-    init_waitqueue_head(&info->close_wait);
+    info->port.close_delay = 5*HZ/10;
+    info->port.closing_wait = 30*HZ;
     init_waitqueue_head(&info->status_event_wait_q);
     init_waitqueue_head(&info->event_wait_q);
     spin_lock_init(&info->lock);
     spin_lock_init(&info->netlock);
     memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
-    info->idle_mode = HDLC_TXIDLE_FLAGS;               
+    info->idle_mode = HDLC_TXIDLE_FLAGS;
     info->imra_value = 0xffff;
     info->imrb_value = 0xffff;
     info->pim_value = 0xff;
 
-    link = &info->link;
+    info->p_dev = link;
     link->priv = info;
-    
-    /* Initialize the dev_link_t structure */
-
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-    link->irq.IRQInfo1   = IRQ_LEVEL_ID;
-    link->irq.Handler = NULL;
-    
-    link->conf.Attributes = 0;
-    link->conf.Vcc = 50;
-    link->conf.IntType = INT_MEMORY_AND_IO;
 
-    link->handle = p_dev;
-    p_dev->instance = link;
+    /* Initialize the struct pcmcia_device structure */
 
-    link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-    mgslpc_config(link);
+    ret = mgslpc_config(link);
+    if (ret)
+           return ret;
 
     mgslpc_add_device(info);
 
@@ -593,110 +561,59 @@ static int mgslpc_attach(struct pcmcia_device *p_dev)
 /* Card has been inserted.
  */
 
-#define CS_CHECK(fn, ret) \
-do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
+static int mgslpc_ioprobe(struct pcmcia_device *p_dev,
+                         cistpl_cftable_entry_t *cfg,
+                         cistpl_cftable_entry_t *dflt,
+                         void *priv_data)
+{
+       if (!cfg->io.nwin)
+               return -ENODEV;
+
+       p_dev->resource[0]->start = cfg->io.win[0].base;
+       p_dev->resource[0]->end = cfg->io.win[0].len;
+       p_dev->resource[0]->flags |= pcmcia_io_cfg_data_width(cfg->io.flags);
+       p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
 
-static void mgslpc_config(dev_link_t *link)
+       return pcmcia_request_io(p_dev);
+}
+
+static int mgslpc_config(struct pcmcia_device *link)
 {
-    client_handle_t handle = link->handle;
     MGSLPC_INFO *info = link->priv;
-    tuple_t tuple;
-    cisparse_t parse;
-    int last_fn, last_ret;
-    u_char buf[64];
-    config_info_t conf;
-    cistpl_cftable_entry_t dflt = { 0 };
-    cistpl_cftable_entry_t *cfg;
-    
+    int ret;
+
     if (debug_level >= DEBUG_LEVEL_INFO)
            printk("mgslpc_config(0x%p)\n", link);
 
-    /* read CONFIG tuple to find its configuration registers */
-    tuple.DesiredTuple = CISTPL_CONFIG;
-    tuple.Attributes = 0;
-    tuple.TupleData = buf;
-    tuple.TupleDataMax = sizeof(buf);
-    tuple.TupleOffset = 0;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
-    CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
-    CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
-    link->conf.ConfigBase = parse.config.base;
-    link->conf.Present = parse.config.rmask[0];
-    
-    /* Configure card */
-    link->state |= DEV_CONFIG;
-
-    /* Look up the current Vcc */
-    CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
-    link->conf.Vcc = conf.Vcc;
-
-    /* get CIS configuration entry */
-
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
-
-    cfg = &(parse.cftable_entry);
-    CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
-    CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
-
-    if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
-    if (cfg->index == 0)
-           goto cs_failed;
-
-    link->conf.ConfigIndex = cfg->index;
-    link->conf.Attributes |= CONF_ENABLE_IRQ;
-       
-    /* IO window settings */
-    link->io.NumPorts1 = 0;
-    if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-           cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-           link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-           if (!(io->flags & CISTPL_IO_8BIT))
-                   link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-           if (!(io->flags & CISTPL_IO_16BIT))
-                   link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-           link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-           link->io.BasePort1 = io->win[0].base;
-           link->io.NumPorts1 = io->win[0].len;
-           CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io));
-    }
-
-    link->conf.Attributes = CONF_ENABLE_IRQ;
-    link->conf.Vcc = 50;
-    link->conf.IntType = INT_MEMORY_AND_IO;
-    link->conf.ConfigIndex = 8;
-    link->conf.Present = PRESENT_OPTION;
-    
-    link->irq.Attributes |= IRQ_HANDLE_PRESENT;
-    link->irq.Handler     = mgslpc_isr;
-    link->irq.Instance    = info;
-    CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
-
-    CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
-
-    info->io_base = link->io.BasePort1;
-    info->irq_level = link->irq.AssignedIRQ;
-
-    /* add to linked list of devices */
-    sprintf(info->node.dev_name, "mgslpc0");
-    info->node.major = info->node.minor = 0;
-    link->dev = &info->node;
-
-    printk(KERN_INFO "%s: index 0x%02x:",
-          info->node.dev_name, link->conf.ConfigIndex);
-    if (link->conf.Attributes & CONF_ENABLE_IRQ)
-           printk(", irq %d", link->irq.AssignedIRQ);
-    if (link->io.NumPorts1)
-           printk(", io 0x%04x-0x%04x", link->io.BasePort1,
-                  link->io.BasePort1+link->io.NumPorts1-1);
+    ret = pcmcia_loop_config(link, mgslpc_ioprobe, NULL);
+    if (ret != 0)
+           goto failed;
+
+    link->config_flags |= CONF_ENABLE_IRQ;
+    link->config_index = 8;
+    link->config_regs = PRESENT_OPTION;
+
+    ret = pcmcia_request_irq(link, mgslpc_isr);
+    if (ret)
+           goto failed;
+    ret = pcmcia_enable_device(link);
+    if (ret)
+           goto failed;
+
+    info->io_base = link->resource[0]->start;
+    info->irq_level = link->irq;
+
+    dev_info(&link->dev, "index 0x%02x:",
+           link->config_index);
+    printk(", irq %d", link->irq);
+    if (link->resource[0])
+           printk(", io %pR", link->resource[0]);
     printk("\n");
-    
-    link->state &= ~DEV_CONFIG_PENDING;
-    return;
+    return 0;
 
-cs_failed:
-    cs_error(link->handle, last_fn, last_ret);
+failed:
     mgslpc_release((u_long)link);
+    return -ENODEV;
 }
 
 /* Card has been removed.
@@ -705,32 +622,27 @@ cs_failed:
  */
 static void mgslpc_release(u_long arg)
 {
-    dev_link_t *link = (dev_link_t *)arg;
+       struct pcmcia_device *link = (struct pcmcia_device *)arg;
 
-    if (debug_level >= DEBUG_LEVEL_INFO)
-           printk("mgslpc_release(0x%p)\n", link);
+       if (debug_level >= DEBUG_LEVEL_INFO)
+               printk("mgslpc_release(0x%p)\n", link);
 
-    pcmcia_disable_device(link->handle);
+       pcmcia_disable_device(link);
 }
 
-static void mgslpc_detach(struct pcmcia_device *p_dev)
+static void mgslpc_detach(struct pcmcia_device *link)
 {
-    dev_link_t *link = dev_to_instance(p_dev);
-
-    if (debug_level >= DEBUG_LEVEL_INFO)
-           printk("mgslpc_detach(0x%p)\n", link);
+       if (debug_level >= DEBUG_LEVEL_INFO)
+               printk("mgslpc_detach(0x%p)\n", link);
 
-    if (link->state & DEV_CONFIG) {
-           ((MGSLPC_INFO *)link->priv)->stop = 1;
-           mgslpc_release((u_long)link);
-    }
+       ((MGSLPC_INFO *)link->priv)->stop = 1;
+       mgslpc_release((u_long)link);
 
-    mgslpc_remove_device((MGSLPC_INFO *)link->priv);
+       mgslpc_remove_device((MGSLPC_INFO *)link->priv);
 }
 
-static int mgslpc_suspend(struct pcmcia_device *dev)
+static int mgslpc_suspend(struct pcmcia_device *link)
 {
-       dev_link_t *link = dev_to_instance(dev);
        MGSLPC_INFO *info = link->priv;
 
        info->stop = 1;
@@ -738,9 +650,8 @@ static int mgslpc_suspend(struct pcmcia_device *dev)
        return 0;
 }
 
-static int mgslpc_resume(struct pcmcia_device *dev)
+static int mgslpc_resume(struct pcmcia_device *link)
 {
-       dev_link_t *link = dev_to_instance(dev);
        MGSLPC_INFO *info = link->priv;
 
        info->stop = 0;
@@ -749,7 +660,7 @@ static int mgslpc_resume(struct pcmcia_device *dev)
 }
 
 
-static inline int mgslpc_paranoia_check(MGSLPC_INFO *info,
+static inline bool mgslpc_paranoia_check(MGSLPC_INFO *info,
                                        char *name, const char *routine)
 {
 #ifdef MGSLPC_PARANOIA_CHECK
@@ -760,17 +671,17 @@ static inline int mgslpc_paranoia_check(MGSLPC_INFO *info,
 
        if (!info) {
                printk(badinfo, name, routine);
-               return 1;
+               return true;
        }
        if (info->magic != MGSLPC_MAGIC) {
                printk(badmagic, name, routine);
-               return 1;
+               return true;
        }
 #else
        if (!info)
-               return 1;
+               return true;
 #endif
-       return 0;
+       return false;
 }
 
 
@@ -782,19 +693,19 @@ static inline int mgslpc_paranoia_check(MGSLPC_INFO *info,
 #define CMD_TXEOM       BIT1   // transmit end message
 #define CMD_TXRESET     BIT0   // transmit reset
 
-static BOOLEAN wait_command_complete(MGSLPC_INFO *info, unsigned char channel) 
+static bool wait_command_complete(MGSLPC_INFO *info, unsigned char channel)
 {
        int i = 0;
-       /* wait for command completion */ 
+       /* wait for command completion */
        while (read_reg(info, (unsigned char)(channel+STAR)) & BIT2) {
                udelay(1);
                if (i++ == 1000)
-                       return FALSE;
+                       return false;
        }
-       return TRUE;
+       return true;
 }
 
-static void issue_command(MGSLPC_INFO *info, unsigned char channel, unsigned char cmd) 
+static void issue_command(MGSLPC_INFO *info, unsigned char channel, unsigned char cmd)
 {
        wait_command_complete(info, channel);
        write_reg(info, (unsigned char) (channel + CMDR), cmd);
@@ -804,12 +715,12 @@ static void tx_pause(struct tty_struct *tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (mgslpc_paranoia_check(info, tty->name, "tx_pause"))
                return;
        if (debug_level >= DEBUG_LEVEL_INFO)
-               printk("tx_pause(%s)\n",info->device_name);     
-               
+               printk("tx_pause(%s)\n",info->device_name);
+
        spin_lock_irqsave(&info->lock,flags);
        if (info->tx_enabled)
                tx_stop(info);
@@ -820,15 +731,15 @@ static void tx_release(struct tty_struct *tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (mgslpc_paranoia_check(info, tty->name, "tx_release"))
                return;
        if (debug_level >= DEBUG_LEVEL_INFO)
-               printk("tx_release(%s)\n",info->device_name);   
-               
+               printk("tx_release(%s)\n",info->device_name);
+
        spin_lock_irqsave(&info->lock,flags);
        if (!info->tx_enabled)
-               tx_start(info);
+               tx_start(info, tty);
        spin_unlock_irqrestore(&info->lock,flags);
 }
 
@@ -839,7 +750,7 @@ static int bh_action(MGSLPC_INFO *info)
 {
        unsigned long flags;
        int rc = 0;
-       
+
        spin_lock_irqsave(&info->lock,flags);
 
        if (info->pending_bh & BH_RECEIVE) {
@@ -855,43 +766,45 @@ static int bh_action(MGSLPC_INFO *info)
 
        if (!rc) {
                /* Mark BH routine as complete */
-               info->bh_running   = 0;
-               info->bh_requested = 0;
+               info->bh_running = false;
+               info->bh_requested = false;
        }
-       
+
        spin_unlock_irqrestore(&info->lock,flags);
-       
+
        return rc;
 }
 
-void bh_handler(void* Context)
+static void bh_handler(struct work_struct *work)
 {
-       MGSLPC_INFO *info = (MGSLPC_INFO*)Context;
+       MGSLPC_INFO *info = container_of(work, MGSLPC_INFO, task);
+       struct tty_struct *tty;
        int action;
 
        if (!info)
                return;
-               
+
        if (debug_level >= DEBUG_LEVEL_BH)
                printk( "%s(%d):bh_handler(%s) entry\n",
                        __FILE__,__LINE__,info->device_name);
-       
-       info->bh_running = 1;
+
+       info->bh_running = true;
+       tty = tty_port_tty_get(&info->port);
 
        while((action = bh_action(info)) != 0) {
-       
+
                /* Process work item */
                if ( debug_level >= DEBUG_LEVEL_BH )
                        printk( "%s(%d):bh_handler() work item action=%d\n",
                                __FILE__,__LINE__,action);
 
                switch (action) {
-               
+
                case BH_RECEIVE:
-                       while(rx_get_frame(info));
+                       while(rx_get_frame(info, tty));
                        break;
                case BH_TRANSMIT:
-                       bh_transmit(info);
+                       bh_transmit(info, tty);
                        break;
                case BH_STATUS:
                        bh_status(info);
@@ -903,24 +816,22 @@ void bh_handler(void* Context)
                }
        }
 
+       tty_kref_put(tty);
        if (debug_level >= DEBUG_LEVEL_BH)
                printk( "%s(%d):bh_handler(%s) exit\n",
                        __FILE__,__LINE__,info->device_name);
 }
 
-void bh_transmit(MGSLPC_INFO *info)
+static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty)
 {
-       struct tty_struct *tty = info->tty;
        if (debug_level >= DEBUG_LEVEL_BH)
                printk("bh_transmit() entry on %s\n", info->device_name);
 
-       if (tty) {
+       if (tty)
                tty_wakeup(tty);
-               wake_up_interruptible(&tty->write_wait);
-       }
 }
 
-void bh_status(MGSLPC_INFO *info)
+static void bh_status(MGSLPC_INFO *info)
 {
        info->ri_chkcount = 0;
        info->dsr_chkcount = 0;
@@ -928,7 +839,7 @@ void bh_status(MGSLPC_INFO *info)
        info->cts_chkcount = 0;
 }
 
-/* eom: non-zero = end of frame */ 
+/* eom: non-zero = end of frame */
 static void rx_ready_hdlc(MGSLPC_INFO *info, int eom)
 {
        unsigned char data[2];
@@ -937,7 +848,7 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom)
 
        if (debug_level >= DEBUG_LEVEL_ISR)
                printk("%s(%d):rx_ready_hdlc(eom=%d)\n",__FILE__,__LINE__,eom);
-       
+
        if (!info->rx_enabled)
                return;
 
@@ -945,18 +856,18 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom)
                /* no more free buffers */
                issue_command(info, CHA, CMD_RXRESET);
                info->pending_bh |= BH_RECEIVE;
-               info->rx_overflow = 1;
+               info->rx_overflow = true;
                info->icount.buf_overrun++;
                return;
        }
 
        if (eom) {
-               /* end of frame, get FIFO count from RBCL register */ 
+               /* end of frame, get FIFO count from RBCL register */
                if (!(fifo_count = (unsigned char)(read_reg(info, CHA+RBCL) & 0x1f)))
                        fifo_count = 32;
        } else
                fifo_count = 32;
-       
+
        do {
                if (fifo_count == 1) {
                        read_count = 1;
@@ -991,16 +902,15 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom)
        issue_command(info, CHA, CMD_RXFIFO);
 }
 
-static void rx_ready_async(MGSLPC_INFO *info, int tcd)
+static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty)
 {
        unsigned char data, status, flag;
        int fifo_count;
        int work = 0;
-       struct tty_struct *tty = info->tty;
        struct mgsl_icount *icount = &info->icount;
 
        if (tcd) {
-               /* early termination, get FIFO count from RBCL register */ 
+               /* early termination, get FIFO count from RBCL register */
                fifo_count = (unsigned char)(read_reg(info, CHA+RBCL) & 0x1f);
 
                /* Zero fifo count could mean 0 or 32 bytes available.
@@ -1012,7 +922,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd)
                fifo_count = 32;
 
        tty_buffer_request_room(tty, fifo_count);
-       /* Flush received async data to receive data buffer. */ 
+       /* Flush received async data to receive data buffer. */
        while (fifo_count) {
                data   = read_reg(info, CHA + RXFIFO);
                status = read_reg(info, CHA + RXFIFO);
@@ -1026,7 +936,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd)
                // BIT6:framing error
 
                if (status & (BIT7 + BIT6)) {
-                       if (status & BIT7) 
+                       if (status & BIT7)
                                icount->parity++;
                        else
                                icount->frame++;
@@ -1034,7 +944,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd)
                        /* discard char if tty control flags say so */
                        if (status & info->ignore_status_mask)
                                continue;
-                               
+
                        status &= info->read_status_mask;
 
                        if (status & BIT7)
@@ -1053,42 +963,42 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd)
                        __FILE__,__LINE__,icount->rx,icount->brk,
                        icount->parity,icount->frame,icount->overrun);
        }
-                       
+
        if (work)
                tty_flip_buffer_push(tty);
 }
 
 
-static void tx_done(MGSLPC_INFO *info)
+static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        if (!info->tx_active)
                return;
-                       
-       info->tx_active = 0;
-       info->tx_aborting = 0;
+
+       info->tx_active = false;
+       info->tx_aborting = false;
 
        if (info->params.mode == MGSL_MODE_ASYNC)
                return;
 
        info->tx_count = info->tx_put = info->tx_get = 0;
-       del_timer(&info->tx_timer);     
-       
+       del_timer(&info->tx_timer);
+
        if (info->drop_rts_on_tx_done) {
                get_signals(info);
                if (info->serial_signals & SerialSignal_RTS) {
                        info->serial_signals &= ~SerialSignal_RTS;
                        set_signals(info);
                }
-               info->drop_rts_on_tx_done = 0;
+               info->drop_rts_on_tx_done = false;
        }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        if (info->netcount)
                hdlcdev_tx_done(info);
-       else 
+       else
 #endif
        {
-               if (info->tty->stopped || info->tty->hw_stopped) {
+               if (tty->stopped || tty->hw_stopped) {
                        tx_stop(info);
                        return;
                }
@@ -1096,7 +1006,7 @@ static void tx_done(MGSLPC_INFO *info)
        }
 }
 
-static void tx_ready(MGSLPC_INFO *info)
+static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        unsigned char fifo_count = 32;
        int c;
@@ -1108,12 +1018,12 @@ static void tx_ready(MGSLPC_INFO *info)
                if (!info->tx_active)
                        return;
        } else {
-               if (info->tty->stopped || info->tty->hw_stopped) {
+               if (tty->stopped || tty->hw_stopped) {
                        tx_stop(info);
                        return;
                }
                if (!info->tx_count)
-                       info->tx_active = 0;
+                       info->tx_active = false;
        }
 
        if (!info->tx_count)
@@ -1121,7 +1031,7 @@ static void tx_ready(MGSLPC_INFO *info)
 
        while (info->tx_count && fifo_count) {
                c = min(2, min_t(int, fifo_count, min(info->tx_count, TXBUFSIZE - info->tx_get)));
-               
+
                if (c == 1) {
                        write_reg(info, CHA + TXFIFO, *(info->tx_buf + info->tx_get));
                } else {
@@ -1145,7 +1055,7 @@ static void tx_ready(MGSLPC_INFO *info)
        }
 }
 
-static void cts_change(MGSLPC_INFO *info)
+static void cts_change(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        get_signals(info);
        if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
@@ -1158,14 +1068,14 @@ static void cts_change(MGSLPC_INFO *info)
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
 
-       if (info->flags & ASYNC_CTS_FLOW) {
-               if (info->tty->hw_stopped) {
+       if (info->port.flags & ASYNC_CTS_FLOW) {
+               if (tty->hw_stopped) {
                        if (info->serial_signals & SerialSignal_CTS) {
                                if (debug_level >= DEBUG_LEVEL_ISR)
                                        printk("CTS tx start...");
-                               if (info->tty)
-                                       info->tty->hw_stopped = 0;
-                               tx_start(info);
+                               if (tty)
+                                       tty->hw_stopped = 0;
+                               tx_start(info, tty);
                                info->pending_bh |= BH_TRANSMIT;
                                return;
                        }
@@ -1173,8 +1083,8 @@ static void cts_change(MGSLPC_INFO *info)
                        if (!(info->serial_signals & SerialSignal_CTS)) {
                                if (debug_level >= DEBUG_LEVEL_ISR)
                                        printk("CTS tx stop...");
-                               if (info->tty)
-                                       info->tty->hw_stopped = 1;
+                               if (tty)
+                                       tty->hw_stopped = 1;
                                tx_stop(info);
                        }
                }
@@ -1182,7 +1092,7 @@ static void cts_change(MGSLPC_INFO *info)
        info->pending_bh |= BH_STATUS;
 }
 
-static void dcd_change(MGSLPC_INFO *info)
+static void dcd_change(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        get_signals(info);
        if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
@@ -1193,24 +1103,28 @@ static void dcd_change(MGSLPC_INFO *info)
        }
        else
                info->input_signal_events.dcd_down++;
-#ifdef CONFIG_HDLC
-       if (info->netcount)
-               hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, info->netdev);
+#if SYNCLINK_GENERIC_HDLC
+       if (info->netcount) {
+               if (info->serial_signals & SerialSignal_DCD)
+                       netif_carrier_on(info->netdev);
+               else
+                       netif_carrier_off(info->netdev);
+       }
 #endif
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
 
-       if (info->flags & ASYNC_CHECK_CD) {
+       if (info->port.flags & ASYNC_CHECK_CD) {
                if (debug_level >= DEBUG_LEVEL_ISR)
                        printk("%s CD now %s...", info->device_name,
                               (info->serial_signals & SerialSignal_DCD) ? "on" : "off");
                if (info->serial_signals & SerialSignal_DCD)
-                       wake_up_interruptible(&info->open_wait);
+                       wake_up_interruptible(&info->port.open_wait);
                else {
                        if (debug_level >= DEBUG_LEVEL_ISR)
                                printk("doing serial hangup...");
-                       if (info->tty)
-                               tty_hangup(info->tty);
+                       if (tty)
+                               tty_hangup(tty);
                }
        }
        info->pending_bh |= BH_STATUS;
@@ -1247,32 +1161,32 @@ static void ri_change(MGSLPC_INFO *info)
 }
 
 /* Interrupt service routine entry point.
- *     
+ *
  * Arguments:
- * 
+ *
  * irq     interrupt number that caused interrupt
  * dev_id  device ID supplied during interrupt registration
- * regs    interrupted processor context
  */
-static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs)
+static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
 {
-       MGSLPC_INFO * info = (MGSLPC_INFO *)dev_id;
+       MGSLPC_INFO *info = dev_id;
+       struct tty_struct *tty;
        unsigned short isr;
        unsigned char gis, pis;
        int count=0;
 
-       if (debug_level >= DEBUG_LEVEL_ISR)     
-               printk("mgslpc_isr(%d) entry.\n", irq);
-       if (!info)
-               return IRQ_NONE;
-               
-       if (!(info->link.state & DEV_CONFIG))
+       if (debug_level >= DEBUG_LEVEL_ISR)
+               printk("mgslpc_isr(%d) entry.\n", info->irq_level);
+
+       if (!(info->p_dev->_locked))
                return IRQ_HANDLED;
 
+       tty = tty_port_tty_get(&info->port);
+
        spin_lock(&info->lock);
 
        while ((gis = read_reg(info, CHA + GIS))) {
-               if (debug_level >= DEBUG_LEVEL_ISR)     
+               if (debug_level >= DEBUG_LEVEL_ISR)
                        printk("mgslpc_isr %s gis=%04X\n", info->device_name,gis);
 
                if ((gis & 0x70) || count > 1000) {
@@ -1284,52 +1198,52 @@ static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs)
                if (gis & (BIT1 + BIT0)) {
                        isr = read_reg16(info, CHB + ISR);
                        if (isr & IRQ_DCD)
-                               dcd_change(info);
+                               dcd_change(info, tty);
                        if (isr & IRQ_CTS)
-                               cts_change(info);
+                               cts_change(info, tty);
                }
                if (gis & (BIT3 + BIT2))
                {
                        isr = read_reg16(info, CHA + ISR);
                        if (isr & IRQ_TIMER) {
-                               info->irq_occurred = 1;
+                               info->irq_occurred = true;
                                irq_disable(info, CHA, IRQ_TIMER);
                        }
 
-                       /* receive IRQs */ 
+                       /* receive IRQs */
                        if (isr & IRQ_EXITHUNT) {
                                info->icount.exithunt++;
                                wake_up_interruptible(&info->event_wait_q);
                        }
                        if (isr & IRQ_BREAK_ON) {
                                info->icount.brk++;
-                               if (info->flags & ASYNC_SAK)
-                                       do_SAK(info->tty);
+                               if (info->port.flags & ASYNC_SAK)
+                                       do_SAK(tty);
                        }
                        if (isr & IRQ_RXTIME) {
                                issue_command(info, CHA, CMD_RXFIFO_READ);
                        }
                        if (isr & (IRQ_RXEOM + IRQ_RXFIFO)) {
                                if (info->params.mode == MGSL_MODE_HDLC)
-                                       rx_ready_hdlc(info, isr & IRQ_RXEOM); 
+                                       rx_ready_hdlc(info, isr & IRQ_RXEOM);
                                else
-                                       rx_ready_async(info, isr & IRQ_RXEOM);
+                                       rx_ready_async(info, isr & IRQ_RXEOM, tty);
                        }
 
-                       /* transmit IRQs */ 
+                       /* transmit IRQs */
                        if (isr & IRQ_UNDERRUN) {
                                if (info->tx_aborting)
                                        info->icount.txabort++;
                                else
                                        info->icount.txunder++;
-                               tx_done(info);
+                               tx_done(info, tty);
                        }
                        else if (isr & IRQ_ALLSENT) {
                                info->icount.txok++;
-                               tx_done(info);
+                               tx_done(info, tty);
                        }
                        else if (isr & IRQ_TXFIFO)
-                               tx_ready(info);
+                               tx_ready(info, tty);
                }
                if (gis & BIT7) {
                        pis = read_reg(info, CHA + PIS);
@@ -1339,40 +1253,41 @@ static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs)
                                ri_change(info);
                }
        }
-       
-       /* Request bottom half processing if there's something 
+
+       /* Request bottom half processing if there's something
         * for it to do and the bh is not already running
         */
 
        if (info->pending_bh && !info->bh_running && !info->bh_requested) {
-               if ( debug_level >= DEBUG_LEVEL_ISR )   
+               if ( debug_level >= DEBUG_LEVEL_ISR )
                        printk("%s(%d):%s queueing bh task.\n",
                                __FILE__,__LINE__,info->device_name);
                schedule_work(&info->task);
-               info->bh_requested = 1;
+               info->bh_requested = true;
        }
 
        spin_unlock(&info->lock);
-       
-       if (debug_level >= DEBUG_LEVEL_ISR)     
+       tty_kref_put(tty);
+
+       if (debug_level >= DEBUG_LEVEL_ISR)
                printk("%s(%d):mgslpc_isr(%d)exit.\n",
-                      __FILE__,__LINE__,irq);
+                      __FILE__, __LINE__, info->irq_level);
 
        return IRQ_HANDLED;
 }
 
 /* Initialize and start device.
  */
-static int startup(MGSLPC_INFO * info)
+static int startup(MGSLPC_INFO * info, struct tty_struct *tty)
 {
        int retval = 0;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):startup(%s)\n",__FILE__,__LINE__,info->device_name);
-               
-       if (info->flags & ASYNC_INITIALIZED)
+
+       if (info->port.flags & ASYNC_INITIALIZED)
                return 0;
-       
+
        if (!info->tx_buf) {
                /* allocate a page of memory for a transmit buffer */
                info->tx_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
@@ -1384,45 +1299,43 @@ static int startup(MGSLPC_INFO * info)
        }
 
        info->pending_bh = 0;
-       
+
        memset(&info->icount, 0, sizeof(info->icount));
 
-       init_timer(&info->tx_timer);
-       info->tx_timer.data = (unsigned long)info;
-       info->tx_timer.function = tx_timeout;
+       setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
 
        /* Allocate and claim adapter resources */
        retval = claim_resources(info);
-       
+
        /* perform existance check and diagnostics */
        if ( !retval )
                retval = adapter_test(info);
-               
+
        if ( retval ) {
-               if (capable(CAP_SYS_ADMIN) && info->tty)
-                       set_bit(TTY_IO_ERROR, &info->tty->flags);
+               if (capable(CAP_SYS_ADMIN) && tty)
+                       set_bit(TTY_IO_ERROR, &tty->flags);
                release_resources(info);
                return retval;
        }
 
        /* program hardware for current parameters */
-       mgslpc_change_params(info);
-       
-       if (info->tty)
-               clear_bit(TTY_IO_ERROR, &info->tty->flags);
+       mgslpc_change_params(info, tty);
+
+       if (tty)
+               clear_bit(TTY_IO_ERROR, &tty->flags);
+
+       info->port.flags |= ASYNC_INITIALIZED;
 
-       info->flags |= ASYNC_INITIALIZED;
-       
        return 0;
 }
 
 /* Called by mgslpc_close() and mgslpc_hangup() to shutdown hardware
  */
-static void shutdown(MGSLPC_INFO * info)
+static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty)
 {
        unsigned long flags;
-       
-       if (!(info->flags & ASYNC_INITIALIZED))
+
+       if (!(info->port.flags & ASYNC_INITIALIZED))
                return;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1434,7 +1347,7 @@ static void shutdown(MGSLPC_INFO * info)
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
 
-       del_timer(&info->tx_timer);     
+       del_timer_sync(&info->tx_timer);
 
        if (info->tx_buf) {
                free_page((unsigned long) info->tx_buf);
@@ -1448,39 +1361,39 @@ static void shutdown(MGSLPC_INFO * info)
 
        /* TODO:disable interrupts instead of reset to preserve signal states */
        reset_device(info);
-       
-       if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
+
+       if (!tty || tty->termios->c_cflag & HUPCL) {
                info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
                set_signals(info);
        }
-       
+
        spin_unlock_irqrestore(&info->lock,flags);
 
-       release_resources(info);        
-       
-       if (info->tty)
-               set_bit(TTY_IO_ERROR, &info->tty->flags);
+       release_resources(info);
 
-       info->flags &= ~ASYNC_INITIALIZED;
+       if (tty)
+               set_bit(TTY_IO_ERROR, &tty->flags);
+
+       info->port.flags &= ~ASYNC_INITIALIZED;
 }
 
-static void mgslpc_program_hw(MGSLPC_INFO *info)
+static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        unsigned long flags;
 
        spin_lock_irqsave(&info->lock,flags);
-       
+
        rx_stop(info);
        tx_stop(info);
        info->tx_count = info->tx_put = info->tx_get = 0;
-       
+
        if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
                hdlc_mode(info);
        else
                async_mode(info);
-               
+
        set_signals(info);
-       
+
        info->dcd_chkcount = 0;
        info->cts_chkcount = 0;
        info->ri_chkcount = 0;
@@ -1489,28 +1402,28 @@ static void mgslpc_program_hw(MGSLPC_INFO *info)
        irq_enable(info, CHB, IRQ_DCD | IRQ_CTS);
        port_irq_enable(info, (unsigned char) PVR_DSR | PVR_RI);
        get_signals(info);
-               
-       if (info->netcount || info->tty->termios->c_cflag & CREAD)
+
+       if (info->netcount || (tty && (tty->termios->c_cflag & CREAD)))
                rx_start(info);
-               
+
        spin_unlock_irqrestore(&info->lock,flags);
 }
 
 /* Reconfigure adapter based on new parameters
  */
-static void mgslpc_change_params(MGSLPC_INFO *info)
+static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        unsigned cflag;
        int bits_per_char;
 
-       if (!info->tty || !info->tty->termios)
+       if (!tty || !tty->termios)
                return;
-               
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_change_params(%s)\n",
                         __FILE__,__LINE__, info->device_name );
-                        
-       cflag = info->tty->termios->c_cflag;
+
+       cflag = tty->termios->c_cflag;
 
        /* if B0 rate (hangup) specified then negate DTR and RTS */
        /* otherwise assert DTR and RTS */
@@ -1518,9 +1431,9 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
                info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
        else
                info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
-       
+
        /* byte size and parity */
-       
+
        switch (cflag & CSIZE) {
        case CS5: info->params.data_bits = 5; break;
        case CS6: info->params.data_bits = 6; break;
@@ -1528,7 +1441,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
        case CS8: info->params.data_bits = 8; break;
        default:  info->params.data_bits = 7; break;
        }
-             
+
        if (cflag & CSTOPB)
                info->params.stop_bits = 2;
        else
@@ -1549,7 +1462,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
        /* calculate number of jiffies to transmit a full
         * FIFO (32 bytes) at specified data rate
         */
-       bits_per_char = info->params.data_bits + 
+       bits_per_char = info->params.data_bits +
                        info->params.stop_bits + 1;
 
        /* if port data rate is set to 460800 or less then
@@ -1557,39 +1470,39 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
         * current data rate.
         */
        if (info->params.data_rate <= 460800) {
-               info->params.data_rate = tty_get_baud_rate(info->tty);
+               info->params.data_rate = tty_get_baud_rate(tty);
        }
-       
+
        if ( info->params.data_rate ) {
-               info->timeout = (32*HZ*bits_per_char) / 
+               info->timeout = (32*HZ*bits_per_char) /
                                info->params.data_rate;
        }
        info->timeout += HZ/50;         /* Add .02 seconds of slop */
 
        if (cflag & CRTSCTS)
-               info->flags |= ASYNC_CTS_FLOW;
+               info->port.flags |= ASYNC_CTS_FLOW;
        else
-               info->flags &= ~ASYNC_CTS_FLOW;
-               
+               info->port.flags &= ~ASYNC_CTS_FLOW;
+
        if (cflag & CLOCAL)
-               info->flags &= ~ASYNC_CHECK_CD;
+               info->port.flags &= ~ASYNC_CHECK_CD;
        else
-               info->flags |= ASYNC_CHECK_CD;
+               info->port.flags |= ASYNC_CHECK_CD;
 
        /* process tty input control flags */
-       
+
        info->read_status_mask = 0;
-       if (I_INPCK(info->tty))
+       if (I_INPCK(tty))
                info->read_status_mask |= BIT7 | BIT6;
-       if (I_IGNPAR(info->tty))
+       if (I_IGNPAR(tty))
                info->ignore_status_mask |= BIT7 | BIT6;
 
-       mgslpc_program_hw(info);
+       mgslpc_program_hw(info, tty);
 }
 
 /* Add a character to the transmit buffer
  */
-static void mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
+static int mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
@@ -1600,13 +1513,13 @@ static void mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
        }
 
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_put_char"))
-               return;
+               return 0;
 
-       if (!tty || !info->tx_buf)
-               return;
+       if (!info->tx_buf)
+               return 0;
 
        spin_lock_irqsave(&info->lock,flags);
-       
+
        if (info->params.mode == MGSL_MODE_ASYNC || !info->tx_active) {
                if (info->tx_count < TXBUFSIZE - 1) {
                        info->tx_buf[info->tx_put++] = ch;
@@ -1614,8 +1527,9 @@ static void mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
                        info->tx_count++;
                }
        }
-       
+
        spin_unlock_irqrestore(&info->lock,flags);
+       return 1;
 }
 
 /* Enable transmitter so remaining characters in the
@@ -1625,11 +1539,11 @@ static void mgslpc_flush_chars(struct tty_struct *tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-                               
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk( "%s(%d):mgslpc_flush_chars() entry on %s tx_count=%d\n",
                        __FILE__,__LINE__,info->device_name,info->tx_count);
-       
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_chars"))
                return;
 
@@ -1643,18 +1557,18 @@ static void mgslpc_flush_chars(struct tty_struct *tty)
 
        spin_lock_irqsave(&info->lock,flags);
        if (!info->tx_active)
-               tx_start(info);
+               tx_start(info, tty);
        spin_unlock_irqrestore(&info->lock,flags);
 }
 
 /* Send a block of data
- *     
+ *
  * Arguments:
- * 
+ *
  * tty        pointer to tty information structure
  * buf       pointer to buffer containing send data
  * count      size of send data in bytes
- *     
+ *
  * Returns: number of characters written
  */
 static int mgslpc_write(struct tty_struct * tty,
@@ -1663,13 +1577,13 @@ static int mgslpc_write(struct tty_struct * tty,
        int c, ret = 0;
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk( "%s(%d):mgslpc_write(%s) count=%d\n",
                        __FILE__,__LINE__,info->device_name,count);
-       
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_write") ||
-           !tty || !info->tx_buf)
+               !info->tx_buf)
                goto cleanup;
 
        if (info->params.mode == MGSL_MODE_HDLC) {
@@ -1689,7 +1603,7 @@ static int mgslpc_write(struct tty_struct * tty,
                            TXBUFSIZE - info->tx_put));
                if (c <= 0)
                        break;
-                       
+
                memcpy(info->tx_buf + info->tx_put, buf, c);
 
                spin_lock_irqsave(&info->lock,flags);
@@ -1705,10 +1619,10 @@ start:
        if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
                spin_lock_irqsave(&info->lock,flags);
                if (!info->tx_active)
-                       tx_start(info);
+                       tx_start(info, tty);
                spin_unlock_irqrestore(&info->lock,flags);
        }
-cleanup:       
+cleanup:
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk( "%s(%d):mgslpc_write(%s) returning=%d\n",
                        __FILE__,__LINE__,info->device_name,ret);
@@ -1721,7 +1635,7 @@ static int mgslpc_write_room(struct tty_struct *tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        int ret;
-                               
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_write_room"))
                return 0;
 
@@ -1736,7 +1650,7 @@ static int mgslpc_write_room(struct tty_struct *tty)
                if (ret < 0)
                        ret = 0;
        }
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_write_room(%s)=%d\n",
                         __FILE__,__LINE__, info->device_name, ret);
@@ -1749,14 +1663,14 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        int rc;
-                
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_chars_in_buffer(%s)\n",
                         __FILE__,__LINE__, info->device_name );
-                        
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_chars_in_buffer"))
                return 0;
-               
+
        if (info->params.mode == MGSL_MODE_HDLC)
                rc = info->tx_active ? info->max_frame_size : 0;
        else
@@ -1765,7 +1679,7 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty)
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n",
                         __FILE__,__LINE__, info->device_name, rc);
-                        
+
        return rc;
 }
 
@@ -1775,17 +1689,17 @@ static void mgslpc_flush_buffer(struct tty_struct *tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_flush_buffer(%s) entry\n",
                         __FILE__,__LINE__, info->device_name );
-       
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_buffer"))
                return;
-               
-       spin_lock_irqsave(&info->lock,flags); 
+
+       spin_lock_irqsave(&info->lock,flags);
        info->tx_count = info->tx_put = info->tx_get = 0;
-       del_timer(&info->tx_timer);     
+       del_timer(&info->tx_timer);
        spin_unlock_irqrestore(&info->lock,flags);
 
        wake_up_interruptible(&tty->write_wait);
@@ -1802,7 +1716,7 @@ static void mgslpc_send_xchar(struct tty_struct *tty, char ch)
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_send_xchar(%s,%d)\n",
                         __FILE__,__LINE__, info->device_name, ch );
-                        
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_send_xchar"))
                return;
 
@@ -1810,7 +1724,7 @@ static void mgslpc_send_xchar(struct tty_struct *tty, char ch)
        if (ch) {
                spin_lock_irqsave(&info->lock,flags);
                if (!info->tx_enabled)
-                       tx_start(info);
+                       tx_start(info, tty);
                spin_unlock_irqrestore(&info->lock,flags);
        }
 }
@@ -1821,17 +1735,17 @@ static void mgslpc_throttle(struct tty_struct * tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_throttle(%s) entry\n",
                         __FILE__,__LINE__, info->device_name );
 
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_throttle"))
                return;
-       
+
        if (I_IXOFF(tty))
                mgslpc_send_xchar(tty, STOP_CHAR(tty));
+
        if (tty->termios->c_cflag & CRTSCTS) {
                spin_lock_irqsave(&info->lock,flags);
                info->serial_signals &= ~SerialSignal_RTS;
@@ -1846,21 +1760,21 @@ static void mgslpc_unthrottle(struct tty_struct * tty)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_unthrottle(%s) entry\n",
                         __FILE__,__LINE__, info->device_name );
 
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_unthrottle"))
                return;
-       
+
        if (I_IXOFF(tty)) {
                if (info->x_char)
                        info->x_char = 0;
                else
                        mgslpc_send_xchar(tty, START_CHAR(tty));
        }
-       
+
        if (tty->termios->c_cflag & CRTSCTS) {
                spin_lock_irqsave(&info->lock,flags);
                info->serial_signals |= SerialSignal_RTS;
@@ -1900,20 +1814,20 @@ static int get_params(MGSLPC_INFO * info, MGSL_PARAMS __user *user_params)
 }
 
 /* set the serial parameters
- *     
+ *
  * Arguments:
- * 
+ *
  *     info            pointer to device instance data
  *     new_params      user buffer containing new serial params
  *
  * Returns:    0 if success, otherwise error code
  */
-static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params)
+static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, struct tty_struct *tty)
 {
        unsigned long flags;
        MGSL_PARAMS tmp_params;
        int err;
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):set_params %s\n", __FILE__,__LINE__,
                        info->device_name );
@@ -1924,13 +1838,13 @@ static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params)
                                __FILE__,__LINE__,info->device_name);
                return -EFAULT;
        }
-       
+
        spin_lock_irqsave(&info->lock,flags);
        memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
        spin_unlock_irqrestore(&info->lock,flags);
-       
-       mgslpc_change_params(info);
-       
+
+       mgslpc_change_params(info, tty);
+
        return 0;
 }
 
@@ -1990,17 +1904,17 @@ static int set_interface(MGSLPC_INFO * info, int if_mode)
        return 0;
 }
 
-static int set_txenable(MGSLPC_INFO * info, int enable)
+static int set_txenable(MGSLPC_INFO * info, int enable, struct tty_struct *tty)
 {
        unsigned long flags;
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("set_txenable(%s,%d)\n", info->device_name, enable);
-                       
+
        spin_lock_irqsave(&info->lock,flags);
        if (enable) {
                if (!info->tx_enabled)
-                       tx_start(info);
+                       tx_start(info, tty);
        } else {
                if (info->tx_enabled)
                        tx_stop(info);
@@ -2012,10 +1926,10 @@ static int set_txenable(MGSLPC_INFO * info, int enable)
 static int tx_abort(MGSLPC_INFO * info)
 {
        unsigned long flags;
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("tx_abort(%s)\n", info->device_name);
-                       
+
        spin_lock_irqsave(&info->lock,flags);
        if (info->tx_active && info->tx_count &&
            info->params.mode == MGSL_MODE_HDLC) {
@@ -2023,7 +1937,7 @@ static int tx_abort(MGSLPC_INFO * info)
                 * This results in underrun and abort transmission.
                 */
                info->tx_count = info->tx_put = info->tx_get = 0;
-               info->tx_aborting = TRUE;
+               info->tx_aborting = true;
        }
        spin_unlock_irqrestore(&info->lock,flags);
        return 0;
@@ -2032,10 +1946,10 @@ static int tx_abort(MGSLPC_INFO * info)
 static int set_rxenable(MGSLPC_INFO * info, int enable)
 {
        unsigned long flags;
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("set_rxenable(%s,%d)\n", info->device_name, enable);
-                       
+
        spin_lock_irqsave(&info->lock,flags);
        if (enable) {
                if (!info->rx_enabled)
@@ -2049,7 +1963,7 @@ static int set_rxenable(MGSLPC_INFO * info, int enable)
 }
 
 /* wait for specified event to occur
- *     
+ *
  * Arguments:          info    pointer to device instance data
  *                     mask    pointer to bitmask of events to wait for
  * Return Value:       0       if successful and bit mask updated with
@@ -2070,7 +1984,7 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr)
        COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
        if (rc)
                return  -EFAULT;
-                
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("wait_events(%s,%d)\n", info->device_name, mask);
 
@@ -2092,24 +2006,24 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr)
        /* save current irq counts */
        cprev = info->icount;
        oldsigs = info->input_signal_events;
-       
+
        if ((info->params.mode == MGSL_MODE_HDLC) &&
            (mask & MgslEvent_ExitHuntMode))
                irq_enable(info, CHA, IRQ_EXITHUNT);
-       
+
        set_current_state(TASK_INTERRUPTIBLE);
        add_wait_queue(&info->event_wait_q, &wait);
-       
+
        spin_unlock_irqrestore(&info->lock,flags);
-       
-       
+
+
        for(;;) {
                schedule();
                if (signal_pending(current)) {
                        rc = -ERESTARTSYS;
                        break;
                }
-                       
+
                /* get current irq counts */
                spin_lock_irqsave(&info->lock,flags);
                cnow = info->icount;
@@ -2145,11 +2059,11 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr)
                          (cnow.rxidle      != cprev.rxidle     ? MgslEvent_IdleReceived:0) );
                if (events)
                        break;
-               
+
                cprev = cnow;
                oldsigs = newsigs;
        }
-       
+
        remove_wait_queue(&info->event_wait_q, &wait);
        set_current_state(TASK_RUNNING);
 
@@ -2273,46 +2187,52 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
  * Arguments:          tty             pointer to tty instance data
  *                     break_state     -1=set break condition, 0=clear
  */
-static void mgslpc_break(struct tty_struct *tty, int break_state)
+static int mgslpc_break(struct tty_struct *tty, int break_state)
 {
        MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_break(%s,%d)\n",
                         __FILE__,__LINE__, info->device_name, break_state);
-                        
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break"))
-               return;
+               return -EINVAL;
 
        spin_lock_irqsave(&info->lock,flags);
        if (break_state == -1)
                set_reg_bits(info, CHA+DAFO, BIT6);
-       else 
+       else
                clear_reg_bits(info, CHA+DAFO, BIT6);
        spin_unlock_irqrestore(&info->lock,flags);
+       return 0;
 }
 
 /* Service an IOCTL request
- *     
+ *
  * Arguments:
- * 
+ *
  *     tty     pointer to tty instance data
  *     file    pointer to associated file object for device
  *     cmd     IOCTL command code
  *     arg     command argument/context
- *     
+ *
  * Return Value:       0 if success, otherwise error code
  */
 static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
                        unsigned int cmd, unsigned long arg)
 {
        MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
-       
+       int error;
+       struct mgsl_icount cnow;        /* kernel counter temps */
+       struct serial_icounter_struct __user *p_cuser;  /* user space */
+       void __user *argp = (void __user *)arg;
+       unsigned long flags;
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
                        info->device_name, cmd );
-       
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_ioctl"))
                return -ENODEV;
 
@@ -2322,22 +2242,11 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
                    return -EIO;
        }
 
-       return ioctl_common(info, cmd, arg);
-}
-
-int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
-{
-       int error;
-       struct mgsl_icount cnow;        /* kernel counter temps */
-       struct serial_icounter_struct __user *p_cuser;  /* user space */
-       void __user *argp = (void __user *)arg;
-       unsigned long flags;
-       
        switch (cmd) {
        case MGSL_IOCGPARAMS:
                return get_params(info, argp);
        case MGSL_IOCSPARAMS:
-               return set_params(info, argp);
+               return set_params(info, argp, tty);
        case MGSL_IOCGTXIDLE:
                return get_txidle(info, argp);
        case MGSL_IOCSTXIDLE:
@@ -2347,7 +2256,7 @@ int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
        case MGSL_IOCSIF:
                return set_interface(info,(int)arg);
        case MGSL_IOCTXENABLE:
-               return set_txenable(info,(int)arg);
+               return set_txenable(info,(int)arg, tty);
        case MGSL_IOCRXENABLE:
                return set_rxenable(info,(int)arg);
        case MGSL_IOCTXABORT:
@@ -2393,28 +2302,28 @@ int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
 }
 
 /* Set new termios settings
- *     
+ *
  * Arguments:
- * 
+ *
  *     tty             pointer to tty structure
  *     termios         pointer to buffer to hold returned old termios
  */
-static void mgslpc_set_termios(struct tty_struct *tty, struct termios *old_termios)
+static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
        unsigned long flags;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_set_termios %s\n", __FILE__,__LINE__,
                        tty->driver->name );
-       
+
        /* just return if nothing has changed */
        if ((tty->termios->c_cflag == old_termios->c_cflag)
-           && (RELEVANT_IFLAG(tty->termios->c_iflag) 
+           && (RELEVANT_IFLAG(tty->termios->c_iflag)
                == RELEVANT_IFLAG(old_termios->c_iflag)))
          return;
 
-       mgslpc_change_params(info);
+       mgslpc_change_params(info, tty);
 
        /* Handle transition to B0 status */
        if (old_termios->c_cflag & CBAUD &&
@@ -2424,12 +2333,12 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct termios *old_termi
                set_signals(info);
                spin_unlock_irqrestore(&info->lock,flags);
        }
-       
+
        /* Handle transition away from B0 status */
        if (!(old_termios->c_cflag & CBAUD) &&
            tty->termios->c_cflag & CBAUD) {
                info->serial_signals |= SerialSignal_DTR;
-               if (!(tty->termios->c_cflag & CRTSCTS) || 
+               if (!(tty->termios->c_cflag & CRTSCTS) ||
                    !test_bit(TTY_THROTTLED, &tty->flags)) {
                        info->serial_signals |= SerialSignal_RTS;
                }
@@ -2437,7 +2346,7 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct termios *old_termi
                set_signals(info);
                spin_unlock_irqrestore(&info->lock,flags);
        }
-       
+
        /* Handle turning off CRTSCTS */
        if (old_termios->c_cflag & CRTSCTS &&
            !(tty->termios->c_cflag & CRTSCTS)) {
@@ -2449,82 +2358,34 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct termios *old_termi
 static void mgslpc_close(struct tty_struct *tty, struct file * filp)
 {
        MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
+       struct tty_port *port = &info->port;
 
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_close"))
                return;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
-                        __FILE__,__LINE__, info->device_name, info->count);
-                        
-       if (!info->count)
-               return;
+                        __FILE__,__LINE__, info->device_name, port->count);
 
-       if (tty_hung_up_p(filp))
-               goto cleanup;
-                       
-       if ((tty->count == 1) && (info->count != 1)) {
-               /*
-                * tty->count is 1 and the tty structure will be freed.
-                * info->count should be one in this case.
-                * if it's not, correct it so that the port is shutdown.
-                */
-               printk("mgslpc_close: bad refcount; tty->count is 1, "
-                      "info->count is %d\n", info->count);
-               info->count = 1;
-       }
-       
-       info->count--;
-       
-       /* if at least one open remaining, leave hardware active */
-       if (info->count)
+       WARN_ON(!port->count);
+
+       if (tty_port_close_start(port, tty, filp) == 0)
                goto cleanup;
-       
-       info->flags |= ASYNC_CLOSING;
-       
-       /* set tty->closing to notify line discipline to 
-        * only process XON/XOFF characters. Only the N_TTY
-        * discipline appears to use this (ppp does not).
-        */
-       tty->closing = 1;
-       
-       /* wait for transmit data to clear all layers */
-       
-       if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
-               if (debug_level >= DEBUG_LEVEL_INFO)
-                       printk("%s(%d):mgslpc_close(%s) calling tty_wait_until_sent\n",
-                                __FILE__,__LINE__, info->device_name );
-               tty_wait_until_sent(tty, info->closing_wait);
-       }
-               
-       if (info->flags & ASYNC_INITIALIZED)
+
+       if (port->flags & ASYNC_INITIALIZED)
                mgslpc_wait_until_sent(tty, info->timeout);
 
-       if (tty->driver->flush_buffer)
-               tty->driver->flush_buffer(tty);
+       mgslpc_flush_buffer(tty);
 
-       ldisc_flush_buffer(tty);
-               
-       shutdown(info);
+       tty_ldisc_flush(tty);
+       shutdown(info, tty);
        
-       tty->closing = 0;
-       info->tty = NULL;
-       
-       if (info->blocked_open) {
-               if (info->close_delay) {
-                       msleep_interruptible(jiffies_to_msecs(info->close_delay));
-               }
-               wake_up_interruptible(&info->open_wait);
-       }
-       
-       info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
-                        
-       wake_up_interruptible(&info->close_wait);
-       
-cleanup:                       
+       tty_port_close_end(port, tty);
+       tty_port_tty_set(port, NULL);
+cleanup:
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
-                       tty->driver->name, info->count);
+                       tty->driver->name, port->count);
 }
 
 /* Wait until the transmitter is empty.
@@ -2540,31 +2401,31 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout)
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_wait_until_sent(%s) entry\n",
                         __FILE__,__LINE__, info->device_name );
-      
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent"))
                return;
 
-       if (!(info->flags & ASYNC_INITIALIZED))
+       if (!(info->port.flags & ASYNC_INITIALIZED))
                goto exit;
-        
+
        orig_jiffies = jiffies;
-      
+
        /* Set check interval to 1/5 of estimated time to
         * send a character, and make it at least 1. The check
         * interval should also be less than the timeout.
         * Note: use tight timings here to satisfy the NIST-PCTS.
-        */ 
-       
+        */
+
        if ( info->params.data_rate ) {
                char_time = info->timeout/(32 * 5);
                if (!char_time)
                        char_time++;
        } else
                char_time = 1;
-               
+
        if (timeout)
                char_time = min_t(unsigned long, char_time, timeout);
-               
+
        if (info->params.mode == MGSL_MODE_HDLC) {
                while (info->tx_active) {
                        msleep_interruptible(jiffies_to_msecs(char_time));
@@ -2583,7 +2444,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout)
                                break;
                }
        }
-      
+
 exit:
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_wait_until_sent(%s) exit\n",
@@ -2596,132 +2457,56 @@ exit:
 static void mgslpc_hangup(struct tty_struct *tty)
 {
        MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
-       
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_hangup(%s)\n",
                         __FILE__,__LINE__, info->device_name );
-                        
+
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_hangup"))
                return;
 
        mgslpc_flush_buffer(tty);
-       shutdown(info);
-       
-       info->count = 0;        
-       info->flags &= ~ASYNC_NORMAL_ACTIVE;
-       info->tty = NULL;
-
-       wake_up_interruptible(&info->open_wait);
+       shutdown(info, tty);
+       tty_port_hangup(&info->port);
 }
 
-/* Block the current process until the specified port
- * is ready to be opened.
- */
-static int block_til_ready(struct tty_struct *tty, struct file *filp,
-                          MGSLPC_INFO *info)
+static int carrier_raised(struct tty_port *port)
 {
-       DECLARE_WAITQUEUE(wait, current);
-       int             retval;
-       int             do_clocal = 0, extra_count = 0;
-       unsigned long   flags;
-       
-       if (debug_level >= DEBUG_LEVEL_INFO)
-               printk("%s(%d):block_til_ready on %s\n",
-                        __FILE__,__LINE__, tty->driver->name );
+       MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
+       unsigned long flags;
 
-       if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
-               /* nonblock mode is set or port is not enabled */
-               /* just verify that callout device is not active */
-               info->flags |= ASYNC_NORMAL_ACTIVE;
-               return 0;
-       }
+       spin_lock_irqsave(&info->lock,flags);
+       get_signals(info);
+       spin_unlock_irqrestore(&info->lock,flags);
 
-       if (tty->termios->c_cflag & CLOCAL)
-               do_clocal = 1;
+       if (info->serial_signals & SerialSignal_DCD)
+               return 1;
+       return 0;
+}
 
-       /* Wait for carrier detect and the line to become
-        * free (i.e., not in use by the callout).  While we are in
-        * this loop, info->count is dropped by one, so that
-        * mgslpc_close() knows when to free things.  We restore it upon
-        * exit, either normal or abnormal.
-        */
-        
-       retval = 0;
-       add_wait_queue(&info->open_wait, &wait);
-       
-       if (debug_level >= DEBUG_LEVEL_INFO)
-               printk("%s(%d):block_til_ready before block on %s count=%d\n",
-                        __FILE__,__LINE__, tty->driver->name, info->count );
+static void dtr_rts(struct tty_port *port, int onoff)
+{
+       MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
+       unsigned long flags;
 
-       spin_lock_irqsave(&info->lock, flags);
-       if (!tty_hung_up_p(filp)) {
-               extra_count = 1;
-               info->count--;
-       }
-       spin_unlock_irqrestore(&info->lock, flags);
-       info->blocked_open++;
-       
-       while (1) {
-               if ((tty->termios->c_cflag & CBAUD)) {
-                       spin_lock_irqsave(&info->lock,flags);
-                       info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
-                       set_signals(info);
-                       spin_unlock_irqrestore(&info->lock,flags);
-               }
-               
-               set_current_state(TASK_INTERRUPTIBLE);
-               
-               if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
-                       retval = (info->flags & ASYNC_HUP_NOTIFY) ?
-                                       -EAGAIN : -ERESTARTSYS;
-                       break;
-               }
-               
-               spin_lock_irqsave(&info->lock,flags);
-               get_signals(info);
-               spin_unlock_irqrestore(&info->lock,flags);
-               
-               if (!(info->flags & ASYNC_CLOSING) &&
-                   (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
-                       break;
-               }
-                       
-               if (signal_pending(current)) {
-                       retval = -ERESTARTSYS;
-                       break;
-               }
-               
-               if (debug_level >= DEBUG_LEVEL_INFO)
-                       printk("%s(%d):block_til_ready blocking on %s count=%d\n",
-                                __FILE__,__LINE__, tty->driver->name, info->count );
-                                
-               schedule();
-       }
-       
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&info->open_wait, &wait);
-       
-       if (extra_count)
-               info->count++;
-       info->blocked_open--;
-       
-       if (debug_level >= DEBUG_LEVEL_INFO)
-               printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
-                        __FILE__,__LINE__, tty->driver->name, info->count );
-                        
-       if (!retval)
-               info->flags |= ASYNC_NORMAL_ACTIVE;
-               
-       return retval;
+       spin_lock_irqsave(&info->lock,flags);
+       if (onoff)
+               info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
+       else
+               info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR;
+       set_signals(info);
+       spin_unlock_irqrestore(&info->lock,flags);
 }
 
+
 static int mgslpc_open(struct tty_struct *tty, struct file * filp)
 {
        MGSLPC_INFO     *info;
+       struct tty_port *port;
        int                     retval, line;
        unsigned long flags;
 
-       /* verify range of specified line number */     
+       /* verify range of specified line number */
        line = tty->index;
        if ((line < 0) || (line >= mgslpc_device_count)) {
                printk("%s(%d):mgslpc_open with invalid line #%d.\n",
@@ -2735,24 +2520,25 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
                info = info->next_device;
        if (mgslpc_paranoia_check(info, tty->name, "mgslpc_open"))
                return -ENODEV;
-       
+
+       port = &info->port;
        tty->driver_data = info;
-       info->tty = tty;
-               
+       tty_port_tty_set(port, tty);
+
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
-                        __FILE__,__LINE__,tty->driver->name, info->count);
+                        __FILE__,__LINE__,tty->driver->name, port->count);
 
        /* If port is closing, signal caller to try again */
-       if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
-               if (info->flags & ASYNC_CLOSING)
-                       interruptible_sleep_on(&info->close_wait);
-               retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
+       if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
+               if (port->flags & ASYNC_CLOSING)
+                       interruptible_sleep_on(&port->close_wait);
+               retval = ((port->flags & ASYNC_HUP_NOTIFY) ?
                        -EAGAIN : -ERESTARTSYS);
                goto cleanup;
        }
-       
-       info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
+
+       tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
 
        spin_lock_irqsave(&info->netlock, flags);
        if (info->netcount) {
@@ -2760,17 +2546,19 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
                spin_unlock_irqrestore(&info->netlock, flags);
                goto cleanup;
        }
-       info->count++;
+       spin_lock(&port->lock);
+       port->count++;
+       spin_unlock(&port->lock);
        spin_unlock_irqrestore(&info->netlock, flags);
 
-       if (info->count == 1) {
+       if (port->count == 1) {
                /* 1st open on this device, init hardware */
-               retval = startup(info);
+               retval = startup(info, tty);
                if (retval < 0)
                        goto cleanup;
        }
 
-       retval = block_til_ready(tty, filp, info);
+       retval = tty_port_block_til_ready(&info->port, tty, filp);
        if (retval) {
                if (debug_level >= DEBUG_LEVEL_INFO)
                        printk("%s(%d):block_til_ready(%s) returned %d\n",
@@ -2782,15 +2570,8 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
                printk("%s(%d):mgslpc_open(%s) success\n",
                         __FILE__,__LINE__, info->device_name);
        retval = 0;
-       
-cleanup:                       
-       if (retval) {
-               if (tty->count == 1)
-                       info->tty = NULL; /* tty layer will release tty struct */
-               if(info->count)
-                       info->count--;
-       }
-       
+
+cleanup:
        return retval;
 }
 
@@ -2798,20 +2579,19 @@ cleanup:
  * /proc fs routines....
  */
 
-static inline int line_info(char *buf, MGSLPC_INFO *info)
+static inline void line_info(struct seq_file *m, MGSLPC_INFO *info)
 {
        char    stat_buf[30];
-       int     ret;
        unsigned long flags;
 
-       ret = sprintf(buf, "%s:io:%04X irq:%d",
+       seq_printf(m, "%s:io:%04X irq:%d",
                      info->device_name, info->io_base, info->irq_level);
 
        /* output current serial signal states */
        spin_lock_irqsave(&info->lock,flags);
        get_signals(info);
        spin_unlock_irqrestore(&info->lock,flags);
-       
+
        stat_buf[0] = 0;
        stat_buf[1] = 0;
        if (info->serial_signals & SerialSignal_RTS)
@@ -2828,76 +2608,71 @@ static inline int line_info(char *buf, MGSLPC_INFO *info)
                strcat(stat_buf, "|RI");
 
        if (info->params.mode == MGSL_MODE_HDLC) {
-               ret += sprintf(buf+ret, " HDLC txok:%d rxok:%d",
+               seq_printf(m, " HDLC txok:%d rxok:%d",
                              info->icount.txok, info->icount.rxok);
                if (info->icount.txunder)
-                       ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
+                       seq_printf(m, " txunder:%d", info->icount.txunder);
                if (info->icount.txabort)
-                       ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
+                       seq_printf(m, " txabort:%d", info->icount.txabort);
                if (info->icount.rxshort)
-                       ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);   
+                       seq_printf(m, " rxshort:%d", info->icount.rxshort);
                if (info->icount.rxlong)
-                       ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
+                       seq_printf(m, " rxlong:%d", info->icount.rxlong);
                if (info->icount.rxover)
-                       ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
+                       seq_printf(m, " rxover:%d", info->icount.rxover);
                if (info->icount.rxcrc)
-                       ret += sprintf(buf+ret, " rxcrc:%d", info->icount.rxcrc);
+                       seq_printf(m, " rxcrc:%d", info->icount.rxcrc);
        } else {
-               ret += sprintf(buf+ret, " ASYNC tx:%d rx:%d",
+               seq_printf(m, " ASYNC tx:%d rx:%d",
                              info->icount.tx, info->icount.rx);
                if (info->icount.frame)
-                       ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
+                       seq_printf(m, " fe:%d", info->icount.frame);
                if (info->icount.parity)
-                       ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
+                       seq_printf(m, " pe:%d", info->icount.parity);
                if (info->icount.brk)
-                       ret += sprintf(buf+ret, " brk:%d", info->icount.brk);   
+                       seq_printf(m, " brk:%d", info->icount.brk);
                if (info->icount.overrun)
-                       ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
+                       seq_printf(m, " oe:%d", info->icount.overrun);
        }
-       
+
        /* Append serial signal status to end */
-       ret += sprintf(buf+ret, " %s\n", stat_buf+1);
-       
-       ret += sprintf(buf+ret, "txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
+       seq_printf(m, " %s\n", stat_buf+1);
+
+       seq_printf(m, "txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
                       info->tx_active,info->bh_requested,info->bh_running,
                       info->pending_bh);
-       
-       return ret;
 }
 
 /* Called to print information about devices
  */
-static int mgslpc_read_proc(char *page, char **start, off_t off, int count,
-                int *eof, void *data)
+static int mgslpc_proc_show(struct seq_file *m, void *v)
 {
-       int len = 0, l;
-       off_t   begin = 0;
        MGSLPC_INFO *info;
-       
-       len += sprintf(page, "synclink driver:%s\n", driver_version);
-       
+
+       seq_printf(m, "synclink driver:%s\n", driver_version);
+
        info = mgslpc_device_list;
        while( info ) {
-               l = line_info(page + len, info);
-               len += l;
-               if (len+begin > off+count)
-                       goto done;
-               if (len+begin < off) {
-                       begin += len;
-                       len = 0;
-               }
+               line_info(m, info);
                info = info->next_device;
        }
+       return 0;
+}
 
-       *eof = 1;
-done:
-       if (off >= len+begin)
-               return 0;
-       *start = page + (off-begin);
-       return ((count < begin+len-off) ? count : begin+len-off);
+static int mgslpc_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mgslpc_proc_show, NULL);
 }
 
-int rx_alloc_buffers(MGSLPC_INFO *info)
+static const struct file_operations mgslpc_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mgslpc_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int rx_alloc_buffers(MGSLPC_INFO *info)
 {
        /* each buffer has header and data */
        info->rx_buf_size = sizeof(RXBUF) + info->max_frame_size;
@@ -2920,23 +2695,23 @@ int rx_alloc_buffers(MGSLPC_INFO *info)
        return 0;
 }
 
-void rx_free_buffers(MGSLPC_INFO *info)
+static void rx_free_buffers(MGSLPC_INFO *info)
 {
        kfree(info->rx_buf);
        info->rx_buf = NULL;
 }
 
-int claim_resources(MGSLPC_INFO *info)
+static int claim_resources(MGSLPC_INFO *info)
 {
        if (rx_alloc_buffers(info) < 0 ) {
                printk( "Cant allocate rx buffer %s\n", info->device_name);
                release_resources(info);
                return -ENODEV;
-       }       
+       }
        return 0;
 }
 
-void release_resources(MGSLPC_INFO *info)
+static void release_resources(MGSLPC_INFO *info)
 {
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("release_resources(%s)\n", info->device_name);
@@ -2945,46 +2720,45 @@ void release_resources(MGSLPC_INFO *info)
 
 /* Add the specified device instance data structure to the
  * global linked list of devices and increment the device count.
- *     
+ *
  * Arguments:          info    pointer to device instance data
  */
-void mgslpc_add_device(MGSLPC_INFO *info)
+static void mgslpc_add_device(MGSLPC_INFO *info)
 {
        info->next_device = NULL;
        info->line = mgslpc_device_count;
        sprintf(info->device_name,"ttySLP%d",info->line);
-       
+
        if (info->line < MAX_DEVICE_COUNT) {
                if (maxframe[info->line])
                        info->max_frame_size = maxframe[info->line];
-               info->dosyncppp = dosyncppp[info->line];
        }
 
        mgslpc_device_count++;
-       
+
        if (!mgslpc_device_list)
                mgslpc_device_list = info;
-       else {  
+       else {
                MGSLPC_INFO *current_dev = mgslpc_device_list;
                while( current_dev->next_device )
                        current_dev = current_dev->next_device;
                current_dev->next_device = info;
        }
-       
+
        if (info->max_frame_size < 4096)
                info->max_frame_size = 4096;
        else if (info->max_frame_size > 65535)
                info->max_frame_size = 65535;
-       
+
        printk( "SyncLink PC Card %s:IO=%04X IRQ=%d\n",
                info->device_name, info->io_base, info->irq_level);
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        hdlcdev_init(info);
 #endif
 }
 
-void mgslpc_remove_device(MGSLPC_INFO *remove_info)
+static void mgslpc_remove_device(MGSLPC_INFO *remove_info)
 {
        MGSLPC_INFO *info = mgslpc_device_list;
        MGSLPC_INFO *last = NULL;
@@ -2995,7 +2769,7 @@ void mgslpc_remove_device(MGSLPC_INFO *remove_info)
                                last->next_device = info->next_device;
                        else
                                mgslpc_device_list = info->next_device;
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                        hdlcdev_exit(info);
 #endif
                        release_resources(info);
@@ -3019,14 +2793,14 @@ static struct pcmcia_driver mgslpc_driver = {
        .drv            = {
                .name   = "synclink_cs",
        },
-       .probe          = mgslpc_attach,
+       .probe          = mgslpc_probe,
        .remove         = mgslpc_detach,
        .id_table       = mgslpc_ids,
        .suspend        = mgslpc_suspend,
        .resume         = mgslpc_resume,
 };
 
-static struct tty_operations mgslpc_ops = {
+static const struct tty_operations mgslpc_ops = {
        .open = mgslpc_open,
        .close = mgslpc_close,
        .write = mgslpc_write,
@@ -3041,13 +2815,13 @@ static struct tty_operations mgslpc_ops = {
        .send_xchar = mgslpc_send_xchar,
        .break_ctl = mgslpc_break,
        .wait_until_sent = mgslpc_wait_until_sent,
-       .read_proc = mgslpc_read_proc,
        .set_termios = mgslpc_set_termios,
        .stop = tx_pause,
        .start = tx_release,
        .hangup = mgslpc_hangup,
        .tiocmget = tiocmget,
        .tiocmset = tiocmset,
+       .proc_fops = &mgslpc_proc_fops,
 };
 
 static void synclink_cs_cleanup(void)
@@ -3090,7 +2864,7 @@ static int __init synclink_cs_init(void)
     }
 
     /* Initialize the tty_driver structure */
-       
+
     serial_driver->owner = THIS_MODULE;
     serial_driver->driver_name = "synclink_cs";
     serial_driver->name = "ttySLP";
@@ -3111,11 +2885,11 @@ static int __init synclink_cs_init(void)
            serial_driver = NULL;
            goto error;
     }
-                       
+
     printk("%s %s, tty major#%d\n",
           driver_name, driver_version,
           serial_driver->major);
-       
+
     return 0;
 
 error:
@@ -3123,7 +2897,7 @@ error:
     return rc;
 }
 
-static void __exit synclink_cs_exit(void) 
+static void __exit synclink_cs_exit(void)
 {
        synclink_cs_cleanup();
 }
@@ -3136,8 +2910,8 @@ static void mgslpc_set_rate(MGSLPC_INFO *info, unsigned char channel, unsigned i
        unsigned int M, N;
        unsigned char val;
 
-       /* note:standard BRG mode is broken in V3.2 chip 
-        * so enhanced mode is always used 
+       /* note:standard BRG mode is broken in V3.2 chip
+        * so enhanced mode is always used
         */
 
        if (rate) {
@@ -3156,7 +2930,7 @@ static void mgslpc_set_rate(MGSLPC_INFO *info, unsigned char channel, unsigned i
                 * divisor = (N+1)*2^M
                 *
                 * Note: M *must* not be zero (causes asymetric duty cycle)
-                */ 
+                */
                write_reg(info, (unsigned char) (channel + BGR),
                                  (unsigned char) ((M << 6) + N));
                val = read_reg(info, (unsigned char) (channel + CCR2)) & 0x3f;
@@ -3170,7 +2944,7 @@ static void mgslpc_set_rate(MGSLPC_INFO *info, unsigned char channel, unsigned i
 static void enable_auxclk(MGSLPC_INFO *info)
 {
        unsigned char val;
-       
+
        /* MODE
         *
         * 07..06  MDS[1..0] 10 = transparent HDLC mode
@@ -3182,14 +2956,14 @@ static void enable_auxclk(MGSLPC_INFO *info)
         * 00      TLP Test Loop, 0 = no loop
         *
         * 1000 0010
-        */ 
+        */
        val = 0x82;
-       
-       /* channel B RTS is used to enable AUXCLK driver on SP505 */ 
+
+       /* channel B RTS is used to enable AUXCLK driver on SP505 */
        if (info->params.mode == MGSL_MODE_HDLC && info->params.clock_speed)
                val |= BIT2;
        write_reg(info, CHB + MODE, val);
-       
+
        /* CCR0
         *
         * 07      PU Power Up, 1=active, 0=power down
@@ -3199,9 +2973,9 @@ static void enable_auxclk(MGSLPC_INFO *info)
         * 01..00  SM[1..0] Serial Mode, 00=HDLC
         *
         * 11000000
-        */ 
+        */
        write_reg(info, CHB + CCR0, 0xc0);
-       
+
        /* CCR1
         *
         * 07      SFLG Shared Flag, 0 = disable shared flags
@@ -3212,9 +2986,9 @@ static void enable_auxclk(MGSLPC_INFO *info)
         * 02..00  CM[2..0] Clock Mode
         *
         * 0001 0111
-        */ 
+        */
        write_reg(info, CHB + CCR1, 0x17);
-       
+
        /* CCR2 (Channel B)
         *
         * 07..06  BGR[9..8] Baud rate bits 9..8
@@ -3226,12 +3000,12 @@ static void enable_auxclk(MGSLPC_INFO *info)
         * 00      DIV, data inversion 0=disabled, 1=enabled
         *
         * 0011 1000
-        */ 
+        */
        if (info->params.mode == MGSL_MODE_HDLC && info->params.clock_speed)
                write_reg(info, CHB + CCR2, 0x38);
        else
                write_reg(info, CHB + CCR2, 0x30);
-       
+
        /* CCR4
         *
         * 07      MCK4 Master Clock Divide by 4, 1=enabled
@@ -3242,76 +3016,76 @@ static void enable_auxclk(MGSLPC_INFO *info)
         * 01..00  RFT[1..0] RxFIFO Threshold 00=32 bytes
         *
         * 0101 0000
-        */ 
+        */
        write_reg(info, CHB + CCR4, 0x50);
-       
+
        /* if auxclk not enabled, set internal BRG so
         * CTS transitions can be detected (requires TxC)
-        */ 
+        */
        if (info->params.mode == MGSL_MODE_HDLC && info->params.clock_speed)
                mgslpc_set_rate(info, CHB, info->params.clock_speed);
        else
                mgslpc_set_rate(info, CHB, 921600);
 }
 
-static void loopback_enable(MGSLPC_INFO *info) 
+static void loopback_enable(MGSLPC_INFO *info)
 {
        unsigned char val;
-       
-       /* CCR1:02..00  CM[2..0] Clock Mode = 111 (clock mode 7) */ 
+
+       /* CCR1:02..00  CM[2..0] Clock Mode = 111 (clock mode 7) */
        val = read_reg(info, CHA + CCR1) | (BIT2 + BIT1 + BIT0);
        write_reg(info, CHA + CCR1, val);
-       
-       /* CCR2:04 SSEL Clock source select, 1=submode b */ 
+
+       /* CCR2:04 SSEL Clock source select, 1=submode b */
        val = read_reg(info, CHA + CCR2) | (BIT4 + BIT5);
        write_reg(info, CHA + CCR2, val);
-       
-       /* set LinkSpeed if available, otherwise default to 2Mbps */ 
+
+       /* set LinkSpeed if available, otherwise default to 2Mbps */
        if (info->params.clock_speed)
                mgslpc_set_rate(info, CHA, info->params.clock_speed);
        else
                mgslpc_set_rate(info, CHA, 1843200);
-       
-       /* MODE:00 TLP Test Loop, 1=loopback enabled */ 
+
+       /* MODE:00 TLP Test Loop, 1=loopback enabled */
        val = read_reg(info, CHA + MODE) | BIT0;
        write_reg(info, CHA + MODE, val);
 }
 
-void hdlc_mode(MGSLPC_INFO *info)
+static void hdlc_mode(MGSLPC_INFO *info)
 {
        unsigned char val;
        unsigned char clkmode, clksubmode;
 
-       /* disable all interrupts */ 
+       /* disable all interrupts */
        irq_disable(info, CHA, 0xffff);
        irq_disable(info, CHB, 0xffff);
        port_irq_disable(info, 0xff);
-       
-       /* assume clock mode 0a, rcv=RxC xmt=TxC */ 
+
+       /* assume clock mode 0a, rcv=RxC xmt=TxC */
        clkmode = clksubmode = 0;
        if (info->params.flags & HDLC_FLAG_RXC_DPLL
            && info->params.flags & HDLC_FLAG_TXC_DPLL) {
-               /* clock mode 7a, rcv = DPLL, xmt = DPLL */ 
+               /* clock mode 7a, rcv = DPLL, xmt = DPLL */
                clkmode = 7;
        } else if (info->params.flags & HDLC_FLAG_RXC_BRG
                 && info->params.flags & HDLC_FLAG_TXC_BRG) {
-               /* clock mode 7b, rcv = BRG, xmt = BRG */ 
+               /* clock mode 7b, rcv = BRG, xmt = BRG */
                clkmode = 7;
                clksubmode = 1;
        } else if (info->params.flags & HDLC_FLAG_RXC_DPLL) {
                if (info->params.flags & HDLC_FLAG_TXC_BRG) {
-                       /* clock mode 6b, rcv = DPLL, xmt = BRG/16 */ 
+                       /* clock mode 6b, rcv = DPLL, xmt = BRG/16 */
                        clkmode = 6;
                        clksubmode = 1;
                } else {
-                       /* clock mode 6a, rcv = DPLL, xmt = TxC */ 
+                       /* clock mode 6a, rcv = DPLL, xmt = TxC */
                        clkmode = 6;
                }
        } else if (info->params.flags & HDLC_FLAG_TXC_BRG) {
-               /* clock mode 0b, rcv = RxC, xmt = BRG */ 
+               /* clock mode 0b, rcv = RxC, xmt = BRG */
                clksubmode = 1;
        }
-       
+
        /* MODE
         *
         * 07..06  MDS[1..0] 10 = transparent HDLC mode
@@ -3323,16 +3097,16 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 00      TLP Test Loop, 0 = no loop
         *
         * 1000 0010
-        */ 
+        */
        val = 0x82;
        if (info->params.loopback)
                val |= BIT0;
-       
-       /* preserve RTS state */ 
+
+       /* preserve RTS state */
        if (info->serial_signals & SerialSignal_RTS)
                val |= BIT2;
        write_reg(info, CHA + MODE, val);
-       
+
        /* CCR0
         *
         * 07      PU Power Up, 1=active, 0=power down
@@ -3342,7 +3116,7 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 01..00  SM[1..0] Serial Mode, 00=HDLC
         *
         * 11000000
-        */ 
+        */
        val = 0xc0;
        switch (info->params.encoding)
        {
@@ -3360,7 +3134,7 @@ void hdlc_mode(MGSLPC_INFO *info)
                break;          // Manchester
        }
        write_reg(info, CHA + CCR0, val);
-       
+
        /* CCR1
         *
         * 07      SFLG Shared Flag, 0 = disable shared flags
@@ -3371,10 +3145,10 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 02..00  CM[2..0] Clock Mode
         *
         * 0001 0000
-        */ 
+        */
        val = 0x10 + clkmode;
        write_reg(info, CHA + CCR1, val);
-       
+
        /* CCR2
         *
         * 07..06  BGR[9..8] Baud rate bits 9..8
@@ -3386,7 +3160,7 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 00      DIV, data inversion 0=disabled, 1=enabled
         *
         * 0000 0000
-        */ 
+        */
        val = 0x00;
        if (clkmode == 2 || clkmode == 3 || clkmode == 6
            || clkmode == 7 || (clkmode == 0 && clksubmode == 1))
@@ -3398,7 +3172,7 @@ void hdlc_mode(MGSLPC_INFO *info)
        if (info->params.encoding == HDLC_ENCODING_NRZB)
                val |= BIT0;
        write_reg(info, CHA + CCR2, val);
-       
+
        /* CCR3
         *
         * 07..06  PRE[1..0] Preamble count 00=1, 01=2, 10=4, 11=8
@@ -3410,7 +3184,7 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 00      PSD DPLL Phase Shift Disable
         *
         * 0000 0000
-        */ 
+        */
        val = 0x00;
        if (info->params.crc_type == HDLC_CRC_NONE)
                val |= BIT2 + BIT1;
@@ -3429,8 +3203,8 @@ void hdlc_mode(MGSLPC_INFO *info)
                break;
        }
        write_reg(info, CHA + CCR3, val);
-       
-       /* PRE - Preamble pattern */ 
+
+       /* PRE - Preamble pattern */
        val = 0;
        switch (info->params.preamble)
        {
@@ -3440,7 +3214,7 @@ void hdlc_mode(MGSLPC_INFO *info)
        case HDLC_PREAMBLE_PATTERN_ONES:  val = 0xff; break;
        }
        write_reg(info, CHA + PRE, val);
-       
+
        /* CCR4
         *
         * 07      MCK4 Master Clock Divide by 4, 1=enabled
@@ -3451,21 +3225,21 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 01..00  RFT[1..0] RxFIFO Threshold 00=32 bytes
         *
         * 0101 0000
-        */ 
+        */
        val = 0x50;
        write_reg(info, CHA + CCR4, val);
        if (info->params.flags & HDLC_FLAG_RXC_DPLL)
                mgslpc_set_rate(info, CHA, info->params.clock_speed * 16);
        else
                mgslpc_set_rate(info, CHA, info->params.clock_speed);
-       
+
        /* RLCR Receive length check register
         *
         * 7     1=enable receive length check
         * 6..0  Max frame length = (RL + 1) * 32
-        */ 
+        */
        write_reg(info, CHA + RLCR, 0);
-       
+
        /* XBCH Transmit Byte Count High
         *
         * 07      DMA mode, 0 = interrupt driven
@@ -3475,7 +3249,7 @@ void hdlc_mode(MGSLPC_INFO *info)
         * 03..00  XBC[10..8] Transmit byte count bits 10..8
         *
         * 0000 0000
-        */ 
+        */
        val = 0x00;
        if (info->params.flags & HDLC_FLAG_AUTO_DCD)
                val |= BIT5;
@@ -3486,7 +3260,7 @@ void hdlc_mode(MGSLPC_INFO *info)
        if (info->params.flags & HDLC_FLAG_AUTO_CTS)
        {
                irq_enable(info, CHB, IRQ_CTS);
-               /* PVR[3] 1=AUTO CTS active */ 
+               /* PVR[3] 1=AUTO CTS active */
                set_reg_bits(info, CHA + PVR, BIT3);
        } else
                clear_reg_bits(info, CHA + PVR, BIT3);
@@ -3497,7 +3271,7 @@ void hdlc_mode(MGSLPC_INFO *info)
        issue_command(info, CHA, CMD_TXRESET + CMD_RXRESET);
        wait_command_complete(info, CHA);
        read_reg16(info, CHA + ISR);    /* clear pending IRQs */
-       
+
        /* Master clock mode enabled above to allow reset commands
         * to complete even if no data clocks are present.
         *
@@ -3507,7 +3281,7 @@ void hdlc_mode(MGSLPC_INFO *info)
         *
         * Leave master clock mode enabled for IRQ test because the
         * timer IRQ used by the test can only happen in master clock mode.
-        */ 
+        */
        if (!info->testing_irq)
                clear_reg_bits(info, CHA + CCR0, BIT6);
 
@@ -3517,100 +3291,100 @@ void hdlc_mode(MGSLPC_INFO *info)
        rx_stop(info);
 }
 
-void rx_stop(MGSLPC_INFO *info)
+static void rx_stop(MGSLPC_INFO *info)
 {
        if (debug_level >= DEBUG_LEVEL_ISR)
                printk("%s(%d):rx_stop(%s)\n",
                         __FILE__,__LINE__, info->device_name );
-                        
-       /* MODE:03 RAC Receiver Active, 0=inactive */ 
+
+       /* MODE:03 RAC Receiver Active, 0=inactive */
        clear_reg_bits(info, CHA + MODE, BIT3);
 
-       info->rx_enabled = 0;
-       info->rx_overflow = 0;
+       info->rx_enabled = false;
+       info->rx_overflow = false;
 }
 
-void rx_start(MGSLPC_INFO *info)
+static void rx_start(MGSLPC_INFO *info)
 {
        if (debug_level >= DEBUG_LEVEL_ISR)
                printk("%s(%d):rx_start(%s)\n",
                         __FILE__,__LINE__, info->device_name );
 
        rx_reset_buffers(info);
-       info->rx_enabled = 0;
-       info->rx_overflow = 0;
+       info->rx_enabled = false;
+       info->rx_overflow = false;
 
-       /* MODE:03 RAC Receiver Active, 1=active */ 
+       /* MODE:03 RAC Receiver Active, 1=active */
        set_reg_bits(info, CHA + MODE, BIT3);
 
-       info->rx_enabled = 1;
+       info->rx_enabled = true;
 }
 
-void tx_start(MGSLPC_INFO *info)
+static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        if (debug_level >= DEBUG_LEVEL_ISR)
                printk("%s(%d):tx_start(%s)\n",
                         __FILE__,__LINE__, info->device_name );
-                        
+
        if (info->tx_count) {
                /* If auto RTS enabled and RTS is inactive, then assert */
                /* RTS and set a flag indicating that the driver should */
                /* negate RTS when the transmission completes. */
-               info->drop_rts_on_tx_done = 0;
+               info->drop_rts_on_tx_done = false;
 
                if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
                        get_signals(info);
                        if (!(info->serial_signals & SerialSignal_RTS)) {
                                info->serial_signals |= SerialSignal_RTS;
                                set_signals(info);
-                               info->drop_rts_on_tx_done = 1;
+                               info->drop_rts_on_tx_done = true;
                        }
                }
 
                if (info->params.mode == MGSL_MODE_ASYNC) {
                        if (!info->tx_active) {
-                               info->tx_active = 1;
-                               tx_ready(info);
+                               info->tx_active = true;
+                               tx_ready(info, tty);
                        }
                } else {
-                       info->tx_active = 1;
-                       tx_ready(info);
-                       info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
-                       add_timer(&info->tx_timer);     
+                       info->tx_active = true;
+                       tx_ready(info, tty);
+                       mod_timer(&info->tx_timer, jiffies +
+                                       msecs_to_jiffies(5000));
                }
        }
 
        if (!info->tx_enabled)
-               info->tx_enabled = 1;
+               info->tx_enabled = true;
 }
 
-void tx_stop(MGSLPC_INFO *info)
+static void tx_stop(MGSLPC_INFO *info)
 {
        if (debug_level >= DEBUG_LEVEL_ISR)
                printk("%s(%d):tx_stop(%s)\n",
                         __FILE__,__LINE__, info->device_name );
-                        
-       del_timer(&info->tx_timer);     
 
-       info->tx_enabled = 0;
-       info->tx_active  = 0;
+       del_timer(&info->tx_timer);
+
+       info->tx_enabled = false;
+       info->tx_active = false;
 }
 
 /* Reset the adapter to a known state and prepare it for further use.
  */
-void reset_device(MGSLPC_INFO *info)
+static void reset_device(MGSLPC_INFO *info)
 {
-       /* power up both channels (set BIT7) */ 
+       /* power up both channels (set BIT7) */
        write_reg(info, CHA + CCR0, 0x80);
        write_reg(info, CHB + CCR0, 0x80);
        write_reg(info, CHA + MODE, 0);
        write_reg(info, CHB + MODE, 0);
-       
-       /* disable all interrupts */ 
+
+       /* disable all interrupts */
        irq_disable(info, CHA, 0xffff);
        irq_disable(info, CHB, 0xffff);
        port_irq_disable(info, 0xff);
-       
+
        /* PCR Port Configuration Register
         *
         * 07..04  DEC[3..0] Serial I/F select outputs
@@ -3620,9 +3394,9 @@ void reset_device(MGSLPC_INFO *info)
         * 00      DTR output 0=active
         *
         * 0000 0110
-        */ 
+        */
        write_reg(info, PCR, 0x06);
-       
+
        /* PVR Port Value Register
         *
         * 07..04  DEC[3..0] Serial I/F select (0000=disabled)
@@ -3634,7 +3408,7 @@ void reset_device(MGSLPC_INFO *info)
         * 0000 0001
         */
 //     write_reg(info, PVR, PVR_DTR);
-       
+
        /* IPC Interrupt Port Configuration
         *
         * 07      VIS 1=Masked interrupts visible
@@ -3644,19 +3418,19 @@ void reset_device(MGSLPC_INFO *info)
         * 01..00  IC[1..0] Interrupt Config, 01=push-pull output, active low
         *
         * 0000 0101
-        */ 
+        */
        write_reg(info, IPC, 0x05);
 }
 
-void async_mode(MGSLPC_INFO *info)
+static void async_mode(MGSLPC_INFO *info)
 {
        unsigned char val;
 
-       /* disable all interrupts */ 
+       /* disable all interrupts */
        irq_disable(info, CHA, 0xffff);
        irq_disable(info, CHB, 0xffff);
        port_irq_disable(info, 0xff);
-       
+
        /* MODE
         *
         * 07      Reserved, 0
@@ -3669,16 +3443,16 @@ void async_mode(MGSLPC_INFO *info)
         * 00      TLP Test Loop, 0 = no loop
         *
         * 0000 0110
-        */ 
+        */
        val = 0x06;
        if (info->params.loopback)
                val |= BIT0;
-       
-       /* preserve RTS state */ 
+
+       /* preserve RTS state */
        if (!(info->serial_signals & SerialSignal_RTS))
                val |= BIT6;
        write_reg(info, CHA + MODE, val);
-       
+
        /* CCR0
         *
         * 07      PU Power Up, 1=active, 0=power down
@@ -3688,9 +3462,9 @@ void async_mode(MGSLPC_INFO *info)
         * 01..00  SM[1..0] Serial Mode, 11=Async
         *
         * 1000 0011
-        */ 
+        */
        write_reg(info, CHA + CCR0, 0x83);
-       
+
        /* CCR1
         *
         * 07..05  Reserved, 0
@@ -3699,9 +3473,9 @@ void async_mode(MGSLPC_INFO *info)
         * 02..00  CM[2..0] Clock Mode, 111=BRG
         *
         * 0001 1111
-        */ 
+        */
        write_reg(info, CHA + CCR1, 0x1f);
-       
+
        /* CCR2 (channel A)
         *
         * 07..06  BGR[9..8] Baud rate bits 9..8
@@ -3713,18 +3487,18 @@ void async_mode(MGSLPC_INFO *info)
         * 00      DIV, data inversion 0=disabled, 1=enabled
         *
         * 0001 0000
-        */ 
+        */
        write_reg(info, CHA + CCR2, 0x10);
-       
+
        /* CCR3
         *
         * 07..01  Reserved, 0
         * 00      PSD DPLL Phase Shift Disable
         *
         * 0000 0000
-        */ 
+        */
        write_reg(info, CHA + CCR3, 0);
-       
+
        /* CCR4
         *
         * 07      MCK4 Master Clock Divide by 4, 1=enabled
@@ -3734,10 +3508,10 @@ void async_mode(MGSLPC_INFO *info)
         * 03..00  Reserved, must be 0
         *
         * 0101 0000
-        */ 
+        */
        write_reg(info, CHA + CCR4, 0x50);
        mgslpc_set_rate(info, CHA, info->params.data_rate * 16);
-       
+
        /* DAFO Data Format
         *
         * 07      Reserved, 0
@@ -3747,7 +3521,7 @@ void async_mode(MGSLPC_INFO *info)
         * 02      PAREN Parity Enable
         * 01..00  CHL[1..0] Character Length (00=8, 01=7)
         *
-        */ 
+        */
        val = 0x00;
        if (info->params.data_bits != 8)
                val |= BIT0;    /* 7 bits */
@@ -3762,7 +3536,7 @@ void async_mode(MGSLPC_INFO *info)
                        val |= BIT4;
        }
        write_reg(info, CHA + DAFO, val);
-       
+
        /* RFC Rx FIFO Control
         *
         * 07      Reserved, 0
@@ -3774,15 +3548,15 @@ void async_mode(MGSLPC_INFO *info)
         * 00      TCDE Terminate Char Detect Enable, 0=disabled
         *
         * 0101 1100
-        */ 
+        */
        write_reg(info, CHA + RFC, 0x5c);
-       
+
        /* RLCR Receive length check register
         *
         * Max frame length = (RL + 1) * 32
-        */ 
+        */
        write_reg(info, CHA + RLCR, 0);
-       
+
        /* XBCH Transmit Byte Count High
         *
         * 07      DMA mode, 0 = interrupt driven
@@ -3792,20 +3566,20 @@ void async_mode(MGSLPC_INFO *info)
         * 03..00  XBC[10..8] Transmit byte count bits 10..8
         *
         * 0000 0000
-        */ 
+        */
        val = 0x00;
        if (info->params.flags & HDLC_FLAG_AUTO_DCD)
                val |= BIT5;
        write_reg(info, CHA + XBCH, val);
        if (info->params.flags & HDLC_FLAG_AUTO_CTS)
                irq_enable(info, CHA, IRQ_CTS);
-       
-       /* MODE:03 RAC Receiver Active, 1=active */ 
+
+       /* MODE:03 RAC Receiver Active, 1=active */
        set_reg_bits(info, CHA + MODE, BIT3);
        enable_auxclk(info);
        if (info->params.flags & HDLC_FLAG_AUTO_CTS) {
                irq_enable(info, CHB, IRQ_CTS);
-               /* PVR[3] 1=AUTO CTS active */ 
+               /* PVR[3] 1=AUTO CTS active */
                set_reg_bits(info, CHA + PVR, BIT3);
        } else
                clear_reg_bits(info, CHA + PVR, BIT3);
@@ -3819,9 +3593,9 @@ void async_mode(MGSLPC_INFO *info)
 
 /* Set the HDLC idle mode for the transmitter.
  */
-void tx_set_idle(MGSLPC_INFO *info)
+static void tx_set_idle(MGSLPC_INFO *info)
 {
-       /* Note: ESCC2 only supports flags and one idle modes */ 
+       /* Note: ESCC2 only supports flags and one idle modes */
        if (info->idle_mode == HDLC_TXIDLE_FLAGS)
                set_reg_bits(info, CHA + CCR1, BIT3);
        else
@@ -3830,11 +3604,11 @@ void tx_set_idle(MGSLPC_INFO *info)
 
 /* get state of the V24 status (input) signals.
  */
-void get_signals(MGSLPC_INFO *info)
+static void get_signals(MGSLPC_INFO *info)
 {
        unsigned char status = 0;
-       
-       /* preserve DTR and RTS */ 
+
+       /* preserve DTR and RTS */
        info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
 
        if (read_reg(info, CHB + VSTR) & BIT7)
@@ -3852,7 +3626,7 @@ void get_signals(MGSLPC_INFO *info)
 /* Set the state of DTR and RTS based on contents of
  * serial_signals member of device extension.
  */
-void set_signals(MGSLPC_INFO *info)
+static void set_signals(MGSLPC_INFO *info)
 {
        unsigned char val;
 
@@ -3876,7 +3650,7 @@ void set_signals(MGSLPC_INFO *info)
                set_reg_bits(info, CHA + PVR, PVR_DTR);
 }
 
-void rx_reset_buffers(MGSLPC_INFO *info)
+static void rx_reset_buffers(MGSLPC_INFO *info)
 {
        RXBUF *buf;
        int i;
@@ -3893,19 +3667,18 @@ void rx_reset_buffers(MGSLPC_INFO *info)
 /* Attempt to return a received HDLC frame
  * Only frames received without errors are returned.
  *
- * Returns 1 if frame returned, otherwise 0
+ * Returns true if frame returned, otherwise false
  */
-int rx_get_frame(MGSLPC_INFO *info)
+static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty)
 {
        unsigned short status;
        RXBUF *buf;
        unsigned int framesize = 0;
        unsigned long flags;
-       struct tty_struct *tty = info->tty;
-       int return_frame = 0;
-       
+       bool return_frame = false;
+
        if (info->rx_frame_count == 0)
-               return 0;
+               return false;
 
        buf = (RXBUF*)(info->rx_buf + (info->rx_get * info->rx_buf_size));
 
@@ -3924,18 +3697,17 @@ int rx_get_frame(MGSLPC_INFO *info)
                else if (!(status & BIT5)) {
                        info->icount.rxcrc++;
                        if (info->params.crc_type & HDLC_CRC_RETURN_EX)
-                               return_frame = 1;
+                               return_frame = true;
                }
                framesize = 0;
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                {
-                       struct net_device_stats *stats = hdlc_stats(info->netdev);
-                       stats->rx_errors++;
-                       stats->rx_frame_errors++;
+                       info->netdev->stats.rx_errors++;
+                       info->netdev->stats.rx_frame_errors++;
                }
 #endif
        } else
-               return_frame = 1;
+               return_frame = true;
 
        if (return_frame)
                framesize = buf->count;
@@ -3943,10 +3715,10 @@ int rx_get_frame(MGSLPC_INFO *info)
        if (debug_level >= DEBUG_LEVEL_BH)
                printk("%s(%d):rx_get_frame(%s) status=%04X size=%d\n",
                        __FILE__,__LINE__,info->device_name,status,framesize);
-                       
+
        if (debug_level >= DEBUG_LEVEL_DATA)
-               trace_block(info, buf->data, framesize, 0);     
-               
+               trace_block(info, buf->data, framesize, 0);
+
        if (framesize) {
                if ((info->params.crc_type & HDLC_CRC_RETURN_EX &&
                      framesize+1 > info->max_frame_size) ||
@@ -3961,7 +3733,7 @@ int rx_get_frame(MGSLPC_INFO *info)
                                ++framesize;
                        }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                        if (info->netcount)
                                hdlcdev_rx(info, buf->data, framesize);
                        else
@@ -3978,16 +3750,16 @@ int rx_get_frame(MGSLPC_INFO *info)
                info->rx_get = 0;
        spin_unlock_irqrestore(&info->lock,flags);
 
-       return 1;
+       return true;
 }
 
-BOOLEAN register_test(MGSLPC_INFO *info)
+static bool register_test(MGSLPC_INFO *info)
 {
-       static unsigned char patterns[] = 
+       static unsigned char patterns[] =
            { 0x00, 0xff, 0xaa, 0x55, 0x69, 0x96, 0x0f };
        static unsigned int count = ARRAY_SIZE(patterns);
        unsigned int i;
-       BOOLEAN rc = TRUE;
+       bool rc = true;
        unsigned long flags;
 
        spin_lock_irqsave(&info->lock,flags);
@@ -3998,7 +3770,7 @@ BOOLEAN register_test(MGSLPC_INFO *info)
                write_reg(info, XAD2, patterns[(i + 1) % count]);
                if ((read_reg(info, XAD1) != patterns[i]) ||
                    (read_reg(info, XAD2) != patterns[(i + 1) % count])) {
-                       rc = FALSE;
+                       rc = false;
                        break;
                }
        }
@@ -4007,7 +3779,7 @@ BOOLEAN register_test(MGSLPC_INFO *info)
        return rc;
 }
 
-BOOLEAN irq_test(MGSLPC_INFO *info)
+static bool irq_test(MGSLPC_INFO *info)
 {
        unsigned long end_time;
        unsigned long flags;
@@ -4015,10 +3787,10 @@ BOOLEAN irq_test(MGSLPC_INFO *info)
        spin_lock_irqsave(&info->lock,flags);
        reset_device(info);
 
-       info->testing_irq = TRUE;
+       info->testing_irq = true;
        hdlc_mode(info);
 
-       info->irq_occurred = FALSE;
+       info->irq_occurred = false;
 
        /* init hdlc mode */
 
@@ -4032,17 +3804,17 @@ BOOLEAN irq_test(MGSLPC_INFO *info)
        while(end_time-- && !info->irq_occurred) {
                msleep_interruptible(10);
        }
-       
-       info->testing_irq = FALSE;
+
+       info->testing_irq = false;
 
        spin_lock_irqsave(&info->lock,flags);
        reset_device(info);
        spin_unlock_irqrestore(&info->lock,flags);
-       
-       return info->irq_occurred ? TRUE : FALSE;
+
+       return info->irq_occurred;
 }
 
-int adapter_test(MGSLPC_INFO *info)
+static int adapter_test(MGSLPC_INFO *info)
 {
        if (!register_test(info)) {
                info->init_error = DiagStatus_AddressFailure;
@@ -4064,7 +3836,7 @@ int adapter_test(MGSLPC_INFO *info)
        return 0;
 }
 
-void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit)
+static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit)
 {
        int i;
        int linecount;
@@ -4072,13 +3844,13 @@ void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit)
                printk("%s tx data:\n",info->device_name);
        else
                printk("%s rx data:\n",info->device_name);
-               
+
        while(count) {
                if (count > 16)
                        linecount = 16;
                else
                        linecount = count;
-                       
+
                for(i=0;i<linecount;i++)
                        printk("%02X ",(unsigned char)data[i]);
                for(;i<17;i++)
@@ -4090,7 +3862,7 @@ void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit)
                                printk(".");
                }
                printk("\n");
-               
+
                data  += linecount;
                count -= linecount;
        }
@@ -4099,11 +3871,11 @@ void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit)
 /* HDLC frame time out
  * update stats and do tx completion processing
  */
-void tx_timeout(unsigned long context)
+static void tx_timeout(unsigned long context)
 {
        MGSLPC_INFO *info = (MGSLPC_INFO*)context;
        unsigned long flags;
-       
+
        if ( debug_level >= DEBUG_LEVEL_INFO )
                printk( "%s(%d):tx_timeout(%s)\n",
                        __FILE__,__LINE__,info->device_name);
@@ -4112,20 +3884,24 @@ void tx_timeout(unsigned long context)
                info->icount.txtimeout++;
        }
        spin_lock_irqsave(&info->lock,flags);
-       info->tx_active = 0;
+       info->tx_active = false;
        info->tx_count = info->tx_put = info->tx_get = 0;
 
        spin_unlock_irqrestore(&info->lock,flags);
-       
-#ifdef CONFIG_HDLC
+
+#if SYNCLINK_GENERIC_HDLC
        if (info->netcount)
                hdlcdev_tx_done(info);
        else
 #endif
-               bh_transmit(info);
+       {
+               struct tty_struct *tty = tty_port_tty_get(&info->port);
+               bh_transmit(info, tty);
+               tty_kref_put(tty);
+       }
 }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
 
 /**
  * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
@@ -4141,11 +3917,12 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
                          unsigned short parity)
 {
        MGSLPC_INFO *info = dev_to_port(dev);
+       struct tty_struct *tty;
        unsigned char  new_encoding;
        unsigned short new_crctype;
 
        /* return error if TTY interface open */
-       if (info->count)
+       if (info->port.count)
                return -EBUSY;
 
        switch (encoding)
@@ -4170,8 +3947,11 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
        info->params.crc_type = new_crctype;
 
        /* if network interface up, reprogram hardware */
-       if (info->netcount)
-               mgslpc_program_hw(info);
+       if (info->netcount) {
+               tty = tty_port_tty_get(&info->port);
+               mgslpc_program_hw(info, tty);
+               tty_kref_put(tty);
+       }
 
        return 0;
 }
@@ -4181,13 +3961,11 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  *
  * skb  socket buffer containing HDLC frame
  * dev  pointer to network device structure
- *
- * returns 0 if success, otherwise error code
  */
-static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb,
+                                     struct net_device *dev)
 {
        MGSLPC_INFO *info = dev_to_port(dev);
-       struct net_device_stats *stats = hdlc_stats(dev);
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -4197,13 +3975,13 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
        netif_stop_queue(dev);
 
        /* copy data to device buffers */
-       memcpy(info->tx_buf, skb->data, skb->len);
+       skb_copy_from_linear_data(skb, info->tx_buf, skb->len);
        info->tx_get = 0;
        info->tx_put = info->tx_count = skb->len;
 
        /* update network statistics */
-       stats->tx_packets++;
-       stats->tx_bytes += skb->len;
+       dev->stats.tx_packets++;
+       dev->stats.tx_bytes += skb->len;
 
        /* done with socket buffer, so free it */
        dev_kfree_skb(skb);
@@ -4213,11 +3991,14 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
 
        /* start hardware transmitter if necessary */
        spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active)
-               tx_start(info);
+       if (!info->tx_active) {
+               struct tty_struct *tty = tty_port_tty_get(&info->port);
+               tx_start(info, tty);
+               tty_kref_put(tty);
+       }
        spin_unlock_irqrestore(&info->lock,flags);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /**
@@ -4231,6 +4012,7 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
 static int hdlcdev_open(struct net_device *dev)
 {
        MGSLPC_INFO *info = dev_to_port(dev);
+       struct tty_struct *tty;
        int rc;
        unsigned long flags;
 
@@ -4243,7 +4025,7 @@ static int hdlcdev_open(struct net_device *dev)
 
        /* arbitrate between network and tty opens */
        spin_lock_irqsave(&info->netlock, flags);
-       if (info->count != 0 || info->netcount != 0) {
+       if (info->port.count != 0 || info->netcount != 0) {
                printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
                spin_unlock_irqrestore(&info->netlock, flags);
                return -EBUSY;
@@ -4251,17 +4033,19 @@ static int hdlcdev_open(struct net_device *dev)
        info->netcount=1;
        spin_unlock_irqrestore(&info->netlock, flags);
 
+       tty = tty_port_tty_get(&info->port);
        /* claim resources and init adapter */
-       if ((rc = startup(info)) != 0) {
+       if ((rc = startup(info, tty)) != 0) {
+               tty_kref_put(tty);
                spin_lock_irqsave(&info->netlock, flags);
                info->netcount=0;
                spin_unlock_irqrestore(&info->netlock, flags);
                return rc;
        }
-
        /* assert DTR and RTS, apply hardware settings */
        info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
-       mgslpc_program_hw(info);
+       mgslpc_program_hw(info, tty);
+       tty_kref_put(tty);
 
        /* enable network layer transmit */
        dev->trans_start = jiffies;
@@ -4271,8 +4055,10 @@ static int hdlcdev_open(struct net_device *dev)
        spin_lock_irqsave(&info->lock, flags);
        get_signals(info);
        spin_unlock_irqrestore(&info->lock, flags);
-       hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev);
-
+       if (info->serial_signals & SerialSignal_DCD)
+               netif_carrier_on(dev);
+       else
+               netif_carrier_off(dev);
        return 0;
 }
 
@@ -4287,6 +4073,7 @@ static int hdlcdev_open(struct net_device *dev)
 static int hdlcdev_close(struct net_device *dev)
 {
        MGSLPC_INFO *info = dev_to_port(dev);
+       struct tty_struct *tty = tty_port_tty_get(&info->port);
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -4295,8 +4082,8 @@ static int hdlcdev_close(struct net_device *dev)
        netif_stop_queue(dev);
 
        /* shutdown adapter and release resources */
-       shutdown(info);
-
+       shutdown(info, tty);
+       tty_kref_put(tty);
        hdlc_close(dev);
 
        spin_lock_irqsave(&info->netlock, flags);
@@ -4327,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
 
        /* return error if TTY interface open */
-       if (info->count)
+       if (info->port.count)
                return -EBUSY;
 
        if (cmd != SIOCWANDEV)
@@ -4400,8 +4187,11 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                        info->params.clock_speed = 0;
 
                /* if network interface up, reprogram hardware */
-               if (info->netcount)
-                       mgslpc_program_hw(info);
+               if (info->netcount) {
+                       struct tty_struct *tty = tty_port_tty_get(&info->port);
+                       mgslpc_program_hw(info, tty);
+                       tty_kref_put(tty);
+               }
                return 0;
 
        default:
@@ -4417,14 +4207,13 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 static void hdlcdev_tx_timeout(struct net_device *dev)
 {
        MGSLPC_INFO *info = dev_to_port(dev);
-       struct net_device_stats *stats = hdlc_stats(dev);
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("hdlcdev_tx_timeout(%s)\n",dev->name);
 
-       stats->tx_errors++;
-       stats->tx_aborted_errors++;
+       dev->stats.tx_errors++;
+       dev->stats.tx_aborted_errors++;
 
        spin_lock_irqsave(&info->lock,flags);
        tx_stop(info);
@@ -4457,29 +4246,35 @@ static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size)
 {
        struct sk_buff *skb = dev_alloc_skb(size);
        struct net_device *dev = info->netdev;
-       struct net_device_stats *stats = hdlc_stats(dev);
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("hdlcdev_rx(%s)\n",dev->name);
 
        if (skb == NULL) {
                printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n", dev->name);
-               stats->rx_dropped++;
+               dev->stats.rx_dropped++;
                return;
        }
 
-       memcpy(skb_put(skb, size),buf,size);
+       memcpy(skb_put(skb, size), buf, size);
 
-       skb->protocol = hdlc_type_trans(skb, info->netdev);
+       skb->protocol = hdlc_type_trans(skb, dev);
 
-       stats->rx_packets++;
-       stats->rx_bytes += size;
+       dev->stats.rx_packets++;
+       dev->stats.rx_bytes += size;
 
        netif_rx(skb);
-
-       info->netdev->last_rx = jiffies;
 }
 
+static const struct net_device_ops hdlcdev_ops = {
+       .ndo_open       = hdlcdev_open,
+       .ndo_stop       = hdlcdev_close,
+       .ndo_change_mtu = hdlc_change_mtu,
+       .ndo_start_xmit = hdlc_start_xmit,
+       .ndo_do_ioctl   = hdlcdev_ioctl,
+       .ndo_tx_timeout = hdlcdev_tx_timeout,
+};
+
 /**
  * called by device driver when adding device instance
  * do generic HDLC initialization
@@ -4506,11 +4301,8 @@ static int hdlcdev_init(MGSLPC_INFO *info)
        dev->irq       = info->irq_level;
 
        /* network layer callbacks and settings */
-       dev->do_ioctl       = hdlcdev_ioctl;
-       dev->open           = hdlcdev_open;
-       dev->stop           = hdlcdev_close;
-       dev->tx_timeout     = hdlcdev_tx_timeout;
-       dev->watchdog_timeo = 10*HZ;
+       dev->netdev_ops     = &hdlcdev_ops;
+       dev->watchdog_timeo = 10 * HZ;
        dev->tx_queue_len   = 50;
 
        /* generic HDLC layer callbacks and settings */