tty: Add carrier processing on close to the tty_port core
[safe/jmp/linux-2.6] / drivers / char / synclinkmp.c
index 10241ed..6f727e3 100644 (file)
@@ -50,6 +50,7 @@
 #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>
@@ -151,18 +152,15 @@ struct    _input_signal_events {
 typedef struct _synclinkmp_info {
        void *if_ptr;                           /* General purpose pointer (used by SPPP) */
        int                     magic;
-       int                     flags;
-       int                     count;          /* count of opens */
+       struct tty_port         port;
        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 */
        u16                     read_status_mask1;  /* break detection (SR1 indications) */
        u16                     read_status_mask2;  /* parity/framing/overun (SR2 indications) */
        unsigned char           ignore_status_mask1;  /* break detection (SR1 indications) */
@@ -172,9 +170,6 @@ typedef struct _synclinkmp_info {
        int                     tx_get;
        int                     tx_count;
 
-       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 */
@@ -276,7 +271,6 @@ typedef struct _synclinkmp_info {
 
        /* SPPP/Cisco HDLC device parts */
        int netcount;
-       int dosyncppp;
        spinlock_t netlock;
 
 #if SYNCLINK_GENERIC_HDLC
@@ -462,26 +456,24 @@ static int synclinkmp_device_count = 0;
  * .text section address and breakpoint on module load.
  * This is useful for use with gdb and add-symbol-file command.
  */
-static int break_on_load=0;
+static int break_on_load = 0;
 
 /*
  * Driver major number, defaults to zero to get auto
  * assigned major number. May be forced as module parameter.
  */
-static int ttymajor=0;
+static int ttymajor = 0;
 
 /*
  * Array of user specified options for ISA adapters.
  */
 static int debug_level = 0;
 static int maxframe[MAX_DEVICES] = {0,};
-static int dosyncppp[MAX_DEVICES] = {0,};
 
 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);
 
 static char *driver_name = "SyncLink MultiPort driver";
 static char *driver_version = "$Revision: 4.38 $";
@@ -529,11 +521,10 @@ static void tx_hold(struct tty_struct *tty);
 static void tx_release(struct tty_struct *tty);
 
 static int  ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
-static int  read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
 static int  chars_in_buffer(struct tty_struct *tty);
 static void throttle(struct tty_struct * tty);
 static void unthrottle(struct tty_struct * tty);
-static void set_break(struct tty_struct *tty, int break_state);
+static int set_break(struct tty_struct *tty, int break_state);
 
 #if SYNCLINK_GENERIC_HDLC
 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
@@ -558,7 +549,7 @@ static int  wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
 static int  tiocmget(struct tty_struct *tty, struct file *file);
 static int  tiocmset(struct tty_struct *tty, struct file *file,
                     unsigned int set, unsigned int clear);
-static void set_break(struct tty_struct *tty, int break_state);
+static int  set_break(struct tty_struct *tty, int break_state);
 
 static void add_device(SLMP_INFO *info);
 static void device_init(int adapter_num, struct pci_dev *pdev);
@@ -567,6 +558,7 @@ static void release_resources(SLMP_INFO *info);
 
 static int  startup(SLMP_INFO *info);
 static int  block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
+static int carrier_raised(struct tty_port *port);
 static void shutdown(SLMP_INFO *info);
 static void program_hw(SLMP_INFO *info);
 static void change_params(SLMP_INFO *info);
@@ -712,8 +704,8 @@ 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);
        }
 }
@@ -747,22 +739,22 @@ static int open(struct tty_struct *tty, struct file *filp)
        }
 
        tty->driver_data = info;
-       info->tty = tty;
+       info->port.tty = tty;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s open(), old ref count = %d\n",
-                        __FILE__,__LINE__,tty->driver->name, info->count);
+                        __FILE__,__LINE__,tty->driver->name, info->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) || info->port.flags & ASYNC_CLOSING){
+               if (info->port.flags & ASYNC_CLOSING)
+                       interruptible_sleep_on(&info->port.close_wait);
+               retval = ((info->port.flags & ASYNC_HUP_NOTIFY) ?
                        -EAGAIN : -ERESTARTSYS);
                goto cleanup;
        }
 
-       info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
+       info->port.tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
 
        spin_lock_irqsave(&info->netlock, flags);
        if (info->netcount) {
@@ -770,10 +762,10 @@ static int open(struct tty_struct *tty, struct file *filp)
                spin_unlock_irqrestore(&info->netlock, flags);
                goto cleanup;
        }
-       info->count++;
+       info->port.count++;
        spin_unlock_irqrestore(&info->netlock, flags);
 
-       if (info->count == 1) {
+       if (info->port.count == 1) {
                /* 1st open on this device, init hardware */
                retval = startup(info);
                if (retval < 0)
@@ -796,9 +788,9 @@ static int open(struct tty_struct *tty, struct file *filp)
 cleanup:
        if (retval) {
                if (tty->count == 1)
-                       info->tty = NULL; /* tty layer will release tty struct */
-               if(info->count)
-                       info->count--;
+                       info->port.tty = NULL; /* tty layer will release tty struct */
+               if(info->port.count)
+                       info->port.count--;
        }
 
        return retval;
@@ -809,83 +801,31 @@ cleanup:
  */
 static void close(struct tty_struct *tty, struct file *filp)
 {
-       SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO * info = tty->driver_data;
 
        if (sanity_check(info, tty->name, "close"))
                return;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s close() entry, count=%d\n",
-                        __FILE__,__LINE__, info->device_name, info->count);
-
-       if (!info->count)
-               return;
+                        __FILE__,__LINE__, info->device_name, info->port.count);
 
-       if (tty_hung_up_p(filp))
+       if (tty_port_close_start(&info->port, tty, filp) == 0)
                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("%s(%d):%s close: bad refcount; tty->count is 1, "
-                      "info->count is %d\n",
-                        __FILE__,__LINE__, info->device_name, info->count);
-               info->count = 1;
-       }
-
-       info->count--;
-
-       /* if at least one open remaining, leave hardware active */
-       if (info->count)
-               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):%s close() 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 (info->port.flags & ASYNC_INITIALIZED)
                wait_until_sent(tty, info->timeout);
 
        flush_buffer(tty);
-
        tty_ldisc_flush(tty);
-
        shutdown(info);
 
-       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);
-
+       tty_port_close_end(&info->port, tty);
+       info->port.tty = NULL;
 cleanup:
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
-                       tty->driver->name, info->count);
+                       tty->driver->name, info->port.count);
 }
 
 /* Called by tty_hangup() when a hangup is signaled.
@@ -893,7 +833,7 @@ cleanup:
  */
 static void hangup(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s hangup()\n",
@@ -905,18 +845,18 @@ static void hangup(struct tty_struct *tty)
        flush_buffer(tty);
        shutdown(info);
 
-       info->count = 0;
-       info->flags &= ~ASYNC_NORMAL_ACTIVE;
-       info->tty = NULL;
+       info->port.count = 0;
+       info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
+       info->port.tty = NULL;
 
-       wake_up_interruptible(&info->open_wait);
+       wake_up_interruptible(&info->port.open_wait);
 }
 
 /* Set new termios settings
  */
 static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -969,7 +909,7 @@ static int write(struct tty_struct *tty,
                 const unsigned char *buf, int count)
 {
        int     c, ret = 0;
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1047,7 +987,7 @@ cleanup:
  */
 static int put_char(struct tty_struct *tty, unsigned char ch)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
        int ret = 0;
 
@@ -1084,7 +1024,7 @@ static int put_char(struct tty_struct *tty, unsigned char ch)
  */
 static void send_xchar(struct tty_struct *tty, char ch)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1108,7 +1048,7 @@ static void send_xchar(struct tty_struct *tty, char ch)
  */
 static void wait_until_sent(struct tty_struct *tty, int timeout)
 {
-       SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO * info = tty->driver_data;
        unsigned long orig_jiffies, char_time;
 
        if (!info )
@@ -1123,7 +1063,7 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
 
        lock_kernel();
 
-       if (!(info->flags & ASYNC_INITIALIZED))
+       if (!(info->port.flags & ASYNC_INITIALIZED))
                goto exit;
 
        orig_jiffies = jiffies;
@@ -1175,7 +1115,7 @@ exit:
  */
 static int write_room(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        int ret;
 
        if (sanity_check(info, tty->name, "write_room"))
@@ -1202,7 +1142,7 @@ static int write_room(struct tty_struct *tty)
  */
 static void flush_chars(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if ( debug_level >= DEBUG_LEVEL_INFO )
@@ -1241,7 +1181,7 @@ static void flush_chars(struct tty_struct *tty)
  */
 static void flush_buffer(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1263,7 +1203,7 @@ static void flush_buffer(struct tty_struct *tty)
  */
 static void tx_hold(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (sanity_check(info, tty->name, "tx_hold"))
@@ -1283,7 +1223,7 @@ static void tx_hold(struct tty_struct *tty)
  */
 static void tx_release(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (sanity_check(info, tty->name, "tx_release"))
@@ -1313,7 +1253,7 @@ static void tx_release(struct tty_struct *tty)
 static int do_ioctl(struct tty_struct *tty, struct file *file,
                 unsigned int cmd, unsigned long arg)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        int error;
        struct mgsl_icount cnow;        /* kernel counter temps */
        struct serial_icounter_struct __user *p_cuser;  /* user space */
@@ -1414,13 +1354,12 @@ static int ioctl(struct tty_struct *tty, struct file *file,
  * /proc fs routines....
  */
 
-static inline int line_info(char *buf, SLMP_INFO *info)
+static inline void line_info(struct seq_file *m, SLMP_INFO *info)
 {
        char    stat_buf[30];
-       int     ret;
        unsigned long flags;
 
-       ret = sprintf(buf, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
+       seq_printf(m, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
                       "\tIRQ=%d MaxFrameSize=%u\n",
                info->device_name,
                info->phys_sca_base,
@@ -1451,80 +1390,75 @@ static inline int line_info(char *buf, SLMP_INFO *info)
                strcat(stat_buf, "|RI");
 
        if (info->params.mode == MGSL_MODE_HDLC) {
-               ret += sprintf(buf+ret, "\tHDLC txok:%d rxok:%d",
+               seq_printf(m, "\tHDLC 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, " rxlong:%d", info->icount.rxcrc);
+                       seq_printf(m, " rxlong:%d", info->icount.rxcrc);
        } else {
-               ret += sprintf(buf+ret, "\tASYNC tx:%d rx:%d",
+               seq_printf(m, "\tASYNC 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);
+       seq_printf(m, " %s\n", stat_buf+1);
 
-       ret += sprintf(buf+ret, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
+       seq_printf(m, "\ttxactive=%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 read_proc(char *page, char **start, off_t off, int count,
-             int *eof, void *data)
+static int synclinkmp_proc_show(struct seq_file *m, void *v)
 {
-       int len = 0, l;
-       off_t   begin = 0;
        SLMP_INFO *info;
 
-       len += sprintf(page, "synclinkmp driver:%s\n", driver_version);
+       seq_printf(m, "synclinkmp driver:%s\n", driver_version);
 
        info = synclinkmp_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 synclinkmp_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, synclinkmp_proc_show, NULL);
 }
 
+static const struct file_operations synclinkmp_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = synclinkmp_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 /* Return the count of bytes in transmit buffer
  */
 static int chars_in_buffer(struct tty_struct *tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
 
        if (sanity_check(info, tty->name, "chars_in_buffer"))
                return 0;
@@ -1540,7 +1474,7 @@ static int chars_in_buffer(struct tty_struct *tty)
  */
 static void throttle(struct tty_struct * tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1565,7 +1499,7 @@ static void throttle(struct tty_struct * tty)
  */
 static void unthrottle(struct tty_struct * tty)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1593,10 +1527,10 @@ static void unthrottle(struct tty_struct * tty)
 /* set or clear transmit break condition
  * break_state -1=set break condition, 0=clear
  */
-static void set_break(struct tty_struct *tty, int break_state)
+static int set_break(struct tty_struct *tty, int break_state)
 {
        unsigned char RegValue;
-       SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO * info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1604,7 +1538,7 @@ static void set_break(struct tty_struct *tty, int break_state)
                         __FILE__,__LINE__, info->device_name, break_state);
 
        if (sanity_check(info, tty->name, "set_break"))
-               return;
+               return -EINVAL;
 
        spin_lock_irqsave(&info->lock,flags);
        RegValue = read_reg(info, CTL);
@@ -1614,6 +1548,7 @@ static void set_break(struct tty_struct *tty, int break_state)
                RegValue &= ~BIT3;
        write_reg(info, CTL, RegValue);
        spin_unlock_irqrestore(&info->lock,flags);
+       return 0;
 }
 
 #if SYNCLINK_GENERIC_HDLC
@@ -1636,7 +1571,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
        unsigned short new_crctype;
 
        /* return error if TTY interface open */
-       if (info->count)
+       if (info->port.count)
                return -EBUSY;
 
        switch (encoding)
@@ -1732,7 +1667,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;
@@ -1818,7 +1753,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)
@@ -1966,10 +1901,17 @@ static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size)
        dev->stats.rx_bytes += size;
 
        netif_rx(skb);
-
-       dev->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
@@ -1997,11 +1939,8 @@ static int hdlcdev_init(SLMP_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 */
@@ -2126,7 +2065,7 @@ static void bh_receive(SLMP_INFO *info)
 
 static void bh_transmit(SLMP_INFO *info)
 {
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
 
        if ( debug_level >= DEBUG_LEVEL_BH )
                printk( "%s(%d):%s bh_transmit() entry\n",
@@ -2176,7 +2115,7 @@ static void isr_timer(SLMP_INFO * info)
 
 static void isr_rxint(SLMP_INFO * info)
 {
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
        struct  mgsl_icount *icount = &info->icount;
        unsigned char status = read_reg(info, SR1) & info->ie1_value & (FLGD + IDLD + CDCD + BRKD);
        unsigned char status2 = read_reg(info, SR2) & info->ie2_value & OVRN;
@@ -2203,7 +2142,7 @@ static void isr_rxint(SLMP_INFO * info)
                                if (!(status & info->ignore_status_mask1)) {
                                        if (info->read_status_mask1 & BRKD) {
                                                tty_insert_flip_char(tty, 0, TTY_BREAK);
-                                               if (info->flags & ASYNC_SAK)
+                                               if (info->port.flags & ASYNC_SAK)
                                                        do_SAK(tty);
                                        }
                                }
@@ -2237,7 +2176,7 @@ static void isr_rxrdy(SLMP_INFO * info)
 {
        u16 status;
        unsigned char DataByte;
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
        struct  mgsl_icount *icount = &info->icount;
 
        if ( debug_level >= DEBUG_LEVEL_ISR )
@@ -2350,7 +2289,7 @@ static void isr_txeom(SLMP_INFO * info, unsigned char status)
                else
 #endif
                {
-                       if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
+                       if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) {
                                tx_stop(info);
                                return;
                        }
@@ -2405,7 +2344,7 @@ static void isr_txrdy(SLMP_INFO * info)
                return;
        }
 
-       if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
+       if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) {
                tx_stop(info);
                return;
        }
@@ -2552,29 +2491,29 @@ static void isr_io_pin( SLMP_INFO *info, u16 status )
                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) &&
                     (status & MISCSTATUS_DCD_LATCHED) ) {
                        if ( debug_level >= DEBUG_LEVEL_ISR )
                                printk("%s CD now %s...", info->device_name,
                                       (status & SerialSignal_DCD) ? "on" : "off");
                        if (status & 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 (info->port.tty)
+                                       tty_hangup(info->port.tty);
                        }
                }
 
-               if ( (info->flags & ASYNC_CTS_FLOW) &&
+               if ( (info->port.flags & ASYNC_CTS_FLOW) &&
                     (status & MISCSTATUS_CTS_LATCHED) ) {
-                       if ( info->tty ) {
-                               if (info->tty->hw_stopped) {
+                       if ( info->port.tty ) {
+                               if (info->port.tty->hw_stopped) {
                                        if (status & SerialSignal_CTS) {
                                                if ( debug_level >= DEBUG_LEVEL_ISR )
                                                        printk("CTS tx start...");
-                                               info->tty->hw_stopped = 0;
+                                               info->port.tty->hw_stopped = 0;
                                                tx_start(info);
                                                info->pending_bh |= BH_TRANSMIT;
                                                return;
@@ -2583,7 +2522,7 @@ static void isr_io_pin( SLMP_INFO *info, u16 status )
                                        if (!(status & SerialSignal_CTS)) {
                                                if ( debug_level >= DEBUG_LEVEL_ISR )
                                                        printk("CTS tx stop...");
-                                               info->tty->hw_stopped = 1;
+                                               info->port.tty->hw_stopped = 1;
                                                tx_stop(info);
                                        }
                                }
@@ -2699,7 +2638,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
                 * do not request bottom half processing if the
                 * device is not open in a normal mode.
                 */
-               if ( port && (port->count || port->netcount) &&
+               if ( port && (port->port.count || port->netcount) &&
                     port->pending_bh && !port->bh_running &&
                     !port->bh_requested ) {
                        if ( debug_level >= DEBUG_LEVEL_ISR )
@@ -2725,7 +2664,7 @@ static int startup(SLMP_INFO * info)
        if ( debug_level >= DEBUG_LEVEL_INFO )
                printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name);
 
-       if (info->flags & ASYNC_INITIALIZED)
+       if (info->port.flags & ASYNC_INITIALIZED)
                return 0;
 
        if (!info->tx_buf) {
@@ -2748,10 +2687,10 @@ static int startup(SLMP_INFO * info)
 
        mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
 
-       if (info->tty)
-               clear_bit(TTY_IO_ERROR, &info->tty->flags);
+       if (info->port.tty)
+               clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
 
-       info->flags |= ASYNC_INITIALIZED;
+       info->port.flags |= ASYNC_INITIALIZED;
 
        return 0;
 }
@@ -2762,7 +2701,7 @@ static void shutdown(SLMP_INFO * info)
 {
        unsigned long flags;
 
-       if (!(info->flags & ASYNC_INITIALIZED))
+       if (!(info->port.flags & ASYNC_INITIALIZED))
                return;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2784,17 +2723,17 @@ static void shutdown(SLMP_INFO * info)
 
        reset_port(info);
 
-       if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
+       if (!info->port.tty || info->port.tty->termios->c_cflag & HUPCL) {
                info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
                set_signals(info);
        }
 
        spin_unlock_irqrestore(&info->lock,flags);
 
-       if (info->tty)
-               set_bit(TTY_IO_ERROR, &info->tty->flags);
+       if (info->port.tty)
+               set_bit(TTY_IO_ERROR, &info->port.tty->flags);
 
-       info->flags &= ~ASYNC_INITIALIZED;
+       info->port.flags &= ~ASYNC_INITIALIZED;
 }
 
 static void program_hw(SLMP_INFO *info)
@@ -2825,7 +2764,7 @@ static void program_hw(SLMP_INFO *info)
 
        get_signals(info);
 
-       if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
+       if (info->netcount || (info->port.tty && info->port.tty->termios->c_cflag & CREAD) )
                rx_start(info);
 
        spin_unlock_irqrestore(&info->lock,flags);
@@ -2838,14 +2777,14 @@ static void change_params(SLMP_INFO *info)
        unsigned cflag;
        int bits_per_char;
 
-       if (!info->tty || !info->tty->termios)
+       if (!info->port.tty || !info->port.tty->termios)
                return;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s change_params()\n",
                         __FILE__,__LINE__, info->device_name );
 
-       cflag = info->tty->termios->c_cflag;
+       cflag = info->port.tty->termios->c_cflag;
 
        /* if B0 rate (hangup) specified then negate DTR and RTS */
        /* otherwise assert DTR and RTS */
@@ -2893,7 +2832,7 @@ static void change_params(SLMP_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(info->port.tty);
        }
 
        if ( info->params.data_rate ) {
@@ -2903,30 +2842,30 @@ static void change_params(SLMP_INFO *info)
        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_mask2 = OVRN;
-       if (I_INPCK(info->tty))
+       if (I_INPCK(info->port.tty))
                info->read_status_mask2 |= PE | FRME;
-       if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
+       if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
                info->read_status_mask1 |= BRKD;
-       if (I_IGNPAR(info->tty))
+       if (I_IGNPAR(info->port.tty))
                info->ignore_status_mask2 |= PE | FRME;
-       if (I_IGNBRK(info->tty)) {
+       if (I_IGNBRK(info->port.tty)) {
                info->ignore_status_mask1 |= BRKD;
                /* If ignoring parity and break indicators, ignore
                 * overruns too.  (For real raw support).
                 */
-               if (I_IGNPAR(info->tty))
+               if (I_IGNPAR(info->port.tty))
                        info->ignore_status_mask2 |= OVRN;
        }
 
@@ -3277,7 +3216,7 @@ static int modem_input_wait(SLMP_INFO *info,int arg)
  */
 static int tiocmget(struct tty_struct *tty, struct file *file)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned int result;
        unsigned long flags;
 
@@ -3303,7 +3242,7 @@ static int tiocmget(struct tty_struct *tty, struct file *file)
 static int tiocmset(struct tty_struct *tty, struct file *file,
                    unsigned int set, unsigned int clear)
 {
-       SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
+       SLMP_INFO *info = tty->driver_data;
        unsigned long flags;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
@@ -3326,7 +3265,31 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
        return 0;
 }
 
+static int carrier_raised(struct tty_port *port)
+{
+       SLMP_INFO *info = container_of(port, SLMP_INFO, port);
+       unsigned long flags;
+
+       spin_lock_irqsave(&info->lock,flags);
+       get_signals(info);
+       spin_unlock_irqrestore(&info->lock,flags);
+
+       return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
+}
+
+static void dtr_rts(struct tty_port *port, int on)
+{
+       SLMP_INFO *info = container_of(port, SLMP_INFO, port);
+       unsigned long flags;
 
+       spin_lock_irqsave(&info->lock,flags);
+       if (on)
+               info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
+       else
+               info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
+       set_signals(info);
+       spin_unlock_irqrestore(&info->lock,flags);
+}
 
 /* Block the current process until the specified port is ready to open.
  */
@@ -3338,6 +3301,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
        bool            do_clocal = false;
        bool            extra_count = false;
        unsigned long   flags;
+       int             cd;
+       struct tty_port *port = &info->port;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s block_til_ready()\n",
@@ -3346,7 +3311,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
        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;
+               port->flags |= ASYNC_NORMAL_ACTIVE;
                return 0;
        }
 
@@ -3355,50 +3320,42 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 
        /* 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
+        * this loop, port->count is dropped by one, so that
         * close() knows when to free things.  We restore it upon
         * exit, either normal or abnormal.
         */
 
        retval = 0;
-       add_wait_queue(&info->open_wait, &wait);
+       add_wait_queue(&port->open_wait, &wait);
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s block_til_ready() before block, count=%d\n",
-                        __FILE__,__LINE__, tty->driver->name, info->count );
+                        __FILE__,__LINE__, tty->driver->name, port->count );
 
        spin_lock_irqsave(&info->lock, flags);
        if (!tty_hung_up_p(filp)) {
                extra_count = true;
-               info->count--;
+               port->count--;
        }
        spin_unlock_irqrestore(&info->lock, flags);
-       info->blocked_open++;
+       port->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);
-               }
+               if (tty->termios->c_cflag & CBAUD)
+                       tty_port_raise_dtr_rts(port);
 
                set_current_state(TASK_INTERRUPTIBLE);
 
-               if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
-                       retval = (info->flags & ASYNC_HUP_NOTIFY) ?
+               if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){
+                       retval = (port->flags & ASYNC_HUP_NOTIFY) ?
                                        -EAGAIN : -ERESTARTSYS;
                        break;
                }
 
-               spin_lock_irqsave(&info->lock,flags);
-               get_signals(info);
-               spin_unlock_irqrestore(&info->lock,flags);
+               cd = tty_port_carrier_raised(port);
 
-               if (!(info->flags & ASYNC_CLOSING) &&
-                   (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
+               if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd))
                        break;
-               }
 
                if (signal_pending(current)) {
                        retval = -ERESTARTSYS;
@@ -3407,24 +3364,24 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 
                if (debug_level >= DEBUG_LEVEL_INFO)
                        printk("%s(%d):%s block_til_ready() count=%d\n",
-                                __FILE__,__LINE__, tty->driver->name, info->count );
+                                __FILE__,__LINE__, tty->driver->name, port->count );
 
                schedule();
        }
 
        set_current_state(TASK_RUNNING);
-       remove_wait_queue(&info->open_wait, &wait);
+       remove_wait_queue(&port->open_wait, &wait);
 
        if (extra_count)
-               info->count++;
-       info->blocked_open--;
+               port->count++;
+       port->blocked_open--;
 
        if (debug_level >= DEBUG_LEVEL_INFO)
                printk("%s(%d):%s block_til_ready() after, count=%d\n",
-                        __FILE__,__LINE__, tty->driver->name, info->count );
+                        __FILE__,__LINE__, tty->driver->name, port->count );
 
        if (!retval)
-               info->flags |= ASYNC_NORMAL_ACTIVE;
+               port->flags |= ASYNC_NORMAL_ACTIVE;
 
        return retval;
 }
@@ -3757,7 +3714,6 @@ static void add_device(SLMP_INFO *info)
        if (info->line < MAX_DEVICES) {
                if (maxframe[info->line])
                        info->max_frame_size = maxframe[info->line];
-               info->dosyncppp = dosyncppp[info->line];
        }
 
        synclinkmp_device_count++;
@@ -3791,6 +3747,11 @@ static void add_device(SLMP_INFO *info)
 #endif
 }
 
+static const struct tty_port_operations port_ops = {
+       .carrier_raised = carrier_raised,
+       .dtr_rts = dtr_rts,
+};
+
 /* Allocate and initialize a device instance structure
  *
  * Return Value:       pointer to SLMP_INFO if success, otherwise NULL
@@ -3806,13 +3767,13 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
                printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
                        __FILE__,__LINE__, adapter_num, port_num);
        } else {
+               tty_port_init(&info->port);
+               info->port.ops = &port_ops;
                info->magic = MGSL_MAGIC;
                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->netlock);
@@ -3941,15 +3902,16 @@ static const struct tty_operations ops = {
        .send_xchar = send_xchar,
        .break_ctl = set_break,
        .wait_until_sent = wait_until_sent,
-       .read_proc = read_proc,
        .set_termios = set_termios,
        .stop = tx_hold,
        .start = tx_release,
        .hangup = hangup,
        .tiocmget = tiocmget,
        .tiocmset = tiocmset,
+       .proc_fops = &synclinkmp_proc_fops,
 };
 
+
 static void synclinkmp_cleanup(void)
 {
        int rc;
@@ -4883,7 +4845,7 @@ static bool rx_get_frame(SLMP_INFO *info)
        unsigned int framesize = 0;
        bool ReturnCode = false;
        unsigned long flags;
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
        unsigned char addr_field = 0xff;
        SCADESC *desc;
        SCADESC_EX *desc_ex;
@@ -5290,11 +5252,11 @@ static bool loopback_test(SLMP_INFO *info)
        bool rc = false;
        unsigned long flags;
 
-       struct tty_struct *oldtty = info->tty;
+       struct tty_struct *oldtty = info->port.tty;
        u32 speed = info->params.clock_speed;
 
        info->params.clock_speed = 3686400;
-       info->tty = NULL;
+       info->port.tty = NULL;
 
        /* assume failure */
        info->init_error = DiagStatus_DmaFailure;
@@ -5338,7 +5300,7 @@ static bool loopback_test(SLMP_INFO *info)
        spin_unlock_irqrestore(&info->lock,flags);
 
        info->params.clock_speed = speed;
-       info->tty = oldtty;
+       info->port.tty = oldtty;
 
        return rc;
 }