]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/char/synclink_gt.c
Merge branch 'drm-intel-fixes' of ssh://master.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6.git] / drivers / char / synclink_gt.c
index 8818042bad7cdc1703a950d9e4e6f4a55a44a48d..d01fffeac95171f53cf8d4e7f52eb239989c27ea 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: synclink_gt.c,v 4.25 2006/02/06 21:20:33 paulkf Exp $
- *
  * Device driver for Microgate SyncLink GT serial adapters.
  *
  * written by Paul Fulghum for Microgate Corporation
 #define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt
 #define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt
 #define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label))
-//#define DBGTBUF(info) dump_tbufs(info)
-//#define DBGRBUF(info) dump_rbufs(info)
+/*#define DBGTBUF(info) dump_tbufs(info)*/
+/*#define DBGRBUF(info) dump_rbufs(info)*/
 
 
-#include <linux/config.h>
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
@@ -64,6 +60,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>
@@ -74,6 +71,7 @@
 #include <linux/bitops.h>
 #include <linux/workqueue.h>
 #include <linux/hdlc.h>
+#include <linux/synclink.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/types.h>
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
-#ifdef CONFIG_HDLC_MODULE
-#define CONFIG_HDLC 1
+#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
+#define SYNCLINK_GENERIC_HDLC 1
+#else
+#define SYNCLINK_GENERIC_HDLC 0
 #endif
 
 /*
  * module identification
  */
 static char *driver_name     = "SyncLink GT";
-static char *driver_version  = "$Revision: 4.25 $";
 static char *tty_driver_name = "synclink_gt";
 static char *tty_dev_prefix  = "ttySLG";
 MODULE_LICENSE("GPL");
 #define MGSL_MAGIC 0x5401
-#define MAX_DEVICES 12
+#define MAX_DEVICES 32
 
 static struct pci_device_id pci_table[] = {
        {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
+       {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT2_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
        {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT4_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
        {PCI_VENDOR_ID_MICROGATE, SYNCLINK_AC_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
        {0,}, /* terminate list */
@@ -116,7 +114,7 @@ static struct pci_driver pci_driver = {
        .remove         = __devexit_p(remove_one),
 };
 
-static int pci_registered;
+static bool pci_registered;
 
 /*
  * module configuration and status
@@ -127,32 +125,27 @@ static int slgt_device_count;
 static int ttymajor;
 static int debug_level;
 static int maxframe[MAX_DEVICES];
-static int dosyncppp[MAX_DEVICES];
 
 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_PARM_DESC(ttymajor, "TTY major device number override: 0=auto assigned");
 MODULE_PARM_DESC(debug_level, "Debug syslog output: 0=disabled, 1 to 5=increasing detail");
 MODULE_PARM_DESC(maxframe, "Maximum frame size used by device (4096 to 65535)");
-MODULE_PARM_DESC(dosyncppp, "Enable synchronous net device, 0=disable 1=enable");
 
 /*
  * tty support and callbacks
  */
-#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
-
 static struct tty_driver *serial_driver;
 
 static int  open(struct tty_struct *tty, struct file * filp);
 static void close(struct tty_struct *tty, struct file * filp);
 static void hangup(struct tty_struct *tty);
-static void set_termios(struct tty_struct *tty, struct termios *old_termios);
+static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
 
 static int  write(struct tty_struct *tty, const unsigned char *buf, int count);
-static void put_char(struct tty_struct *tty, unsigned char ch);
+static int put_char(struct tty_struct *tty, unsigned char ch);
 static void send_xchar(struct tty_struct *tty, char ch);
 static void wait_until_sent(struct tty_struct *tty, int timeout);
 static int  write_room(struct tty_struct *tty);
@@ -162,16 +155,15 @@ 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);
 
 /*
  * generic HDLC support and callbacks
  */
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
 static void hdlcdev_tx_done(struct slgt_info *info);
 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size);
@@ -206,21 +198,23 @@ static void flush_cond_wait(struct cond_wait **head);
  */
 struct slgt_desc
 {
-       unsigned short count;
-       unsigned short status;
-       unsigned int pbuf;  /* physical address of data buffer */
-       unsigned int next;  /* physical address of next descriptor */
+       __le16 count;
+       __le16 status;
+       __le32 pbuf;  /* physical address of data buffer */
+       __le32 next;  /* physical address of next descriptor */
 
        /* driver book keeping */
        char *buf;          /* virtual  address of data buffer */
        unsigned int pdesc; /* physical address of this descriptor */
        dma_addr_t buf_dma_addr;
+       unsigned short buf_count;
 };
 
 #define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
 #define set_desc_next(a,b) (a).next   = cpu_to_le32((unsigned int)(b))
 #define set_desc_count(a,b)(a).count  = cpu_to_le16((unsigned short)(b))
 #define set_desc_eof(a,b)  (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
+#define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
 #define desc_count(a)      (le16_to_cpu((a).count))
 #define desc_status(a)     (le16_to_cpu((a).status))
 #define desc_complete(a)   (le16_to_cpu((a).status) & BIT15)
@@ -245,11 +239,11 @@ struct _input_signal_events {
  */
 struct slgt_info {
        void *if_ptr;           /* General purpose pointer (used by SPPP) */
+       struct tty_port port;
 
        struct slgt_info *next_device;  /* device list link */
 
        int magic;
-       int flags;
 
        char device_name[25];
        struct pci_dev *pdev;
@@ -261,23 +255,15 @@ struct slgt_info {
        /* array of pointers to port contexts on this adapter */
        struct slgt_info *port_array[SLGT_MAX_PORTS];
 
-       int                     count;          /* count of opens */
        int                     line;           /* tty line instance number */
-       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 int            read_status_mask;
        unsigned int            ignore_status_mask;
 
-       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;
@@ -290,12 +276,12 @@ struct slgt_info {
 
        struct work_struct task;
        u32 pending_bh;
-       int bh_requested;
-       int bh_running;
+       bool bh_requested;
+       bool bh_running;
 
        int isr_overflow;
-       int irq_requested;      /* nonzero if IRQ requested */
-       int irq_occurred;       /* for diagnostics use */
+       bool irq_requested;     /* true if IRQ requested */
+       bool irq_occurred;      /* for diagnostics use */
 
        /* device configuration */
 
@@ -305,22 +291,26 @@ struct slgt_info {
 
        unsigned char __iomem * reg_addr;  /* memory mapped registers address */
        u32 phys_reg_addr;
-       int reg_addr_requested;
+       bool reg_addr_requested;
 
        MGSL_PARAMS params;       /* communications parameters */
        u32 idle_mode;
        u32 max_frame_size;       /* as set by device config */
 
-       unsigned int raw_rx_size;
+       unsigned int rbuf_fill_level;
+       unsigned int rx_pio;
        unsigned int if_mode;
+       unsigned int base_clock;
+       unsigned int xsync;
+       unsigned int xctrl;
 
        /* device status */
 
-       int rx_enabled;
-       int rx_restart;
+       bool rx_enabled;
+       bool rx_restart;
 
-       int tx_enabled;
-       int tx_active;
+       bool tx_enabled;
+       bool tx_active;
 
        unsigned char signals;    /* serial signal states */
        int init_error;  /* initialization error */
@@ -330,7 +320,7 @@ struct slgt_info {
 
        char flag_buf[MAX_ASYNC_BUFFER_SIZE];
        char char_buf[MAX_ASYNC_BUFFER_SIZE];
-       BOOLEAN drop_rts_on_tx_done;
+       bool drop_rts_on_tx_done;
        struct  _input_signal_events    input_signal_events;
 
        int dcd_chkcount;       /* check counts to prevent */
@@ -345,6 +335,8 @@ struct slgt_info {
        struct slgt_desc *rbufs;
        unsigned int rbuf_current;
        unsigned int rbuf_index;
+       unsigned int rbuf_fill_index;
+       unsigned short rbuf_fill_count;
 
        unsigned int tbuf_count;
        struct slgt_desc *tbufs;
@@ -357,9 +349,8 @@ struct slgt_info {
        /* SPPP/Cisco HDLC device parts */
 
        int netcount;
-       int dosyncppp;
        spinlock_t netlock;
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        struct net_device *netdev;
 #endif
 
@@ -391,8 +382,8 @@ static MGSL_PARAMS default_params = {
 #define DESC_LIST_SIZE 4096
 
 #define MASK_PARITY  BIT1
-#define MASK_FRAMING BIT2
-#define MASK_BREAK   BIT3
+#define MASK_FRAMING BIT0
+#define MASK_BREAK   BIT14
 #define MASK_OVERRUN BIT4
 
 #define GSR   0x00 /* global status */
@@ -416,6 +407,8 @@ static MGSL_PARAMS default_params = {
 #define TDCSR 0x94 /* tx DMA control/status */
 #define RDDAR 0x98 /* rx DMA descriptor address */
 #define TDDAR 0x9c /* tx DMA descriptor address */
+#define XSR   0x40 /* extended sync pattern */
+#define XCR   0x44 /* extended control */
 
 #define RXIDLE      BIT14
 #define RXBREAK     BIT14
@@ -461,23 +454,24 @@ static int  adapter_test(struct slgt_info *info);
 static void reset_adapter(struct slgt_info *info);
 static void reset_port(struct slgt_info *info);
 static void async_mode(struct slgt_info *info);
-static void hdlc_mode(struct slgt_info *info);
+static void sync_mode(struct slgt_info *info);
 
 static void rx_stop(struct slgt_info *info);
 static void rx_start(struct slgt_info *info);
 static void reset_rbufs(struct slgt_info *info);
 static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
 static void rdma_reset(struct slgt_info *info);
-static int  rx_get_frame(struct slgt_info *info);
-static int  rx_get_buf(struct slgt_info *info);
+static bool rx_get_frame(struct slgt_info *info);
+static bool rx_get_buf(struct slgt_info *info);
 
 static void tx_start(struct slgt_info *info);
 static void tx_stop(struct slgt_info *info);
 static void tx_set_idle(struct slgt_info *info);
 static unsigned int free_tbuf_count(struct slgt_info *info);
+static unsigned int tbuf_bytes(struct slgt_info *info);
 static void reset_tbufs(struct slgt_info *info);
 static void tdma_reset(struct slgt_info *info);
-static void tx_load(struct slgt_info *info, const char *buf, unsigned int count);
+static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
 
 static void get_signals(struct slgt_info *info);
 static void set_signals(struct slgt_info *info);
@@ -485,13 +479,12 @@ static void enable_loopback(struct slgt_info *info);
 static void set_rate(struct slgt_info *info, u32 data_rate);
 
 static int  bh_action(struct slgt_info *info);
-static void bh_handler(void* context);
+static void bh_handler(struct work_struct *work);
 static void bh_transmit(struct slgt_info *info);
 static void isr_serial(struct slgt_info *info);
 static void isr_rdma(struct slgt_info *info);
 static void isr_txeom(struct slgt_info *info, unsigned short status);
 static void isr_tdma(struct slgt_info *info);
-static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs);
 
 static int  alloc_dma_bufs(struct slgt_info *info);
 static void free_dma_bufs(struct slgt_info *info);
@@ -522,12 +515,16 @@ static int  wait_mgsl_event(struct slgt_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 int  get_interface(struct slgt_info *info, int __user *if_mode);
 static int  set_interface(struct slgt_info *info, int if_mode);
 static int  set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
 static int  get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
 static int  wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
+static int  get_xsync(struct slgt_info *info, int __user *if_mode);
+static int  set_xsync(struct slgt_info *info, int if_mode);
+static int  get_xctrl(struct slgt_info *info, int __user *if_mode);
+static int  set_xctrl(struct slgt_info *info, int if_mode);
 
 /*
  * driver functions
@@ -642,8 +639,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);
        }
 }
@@ -673,37 +670,41 @@ static int open(struct tty_struct *tty, struct file *filp)
        }
 
        tty->driver_data = info;
-       info->tty = tty;
+       info->port.tty = tty;
 
-       DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->count));
+       DBGINFO(("%s open, old ref count = %d\n", info->device_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;
+       mutex_lock(&info->port.mutex);
+       info->port.tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
 
        spin_lock_irqsave(&info->netlock, flags);
        if (info->netcount) {
                retval = -EBUSY;
                spin_unlock_irqrestore(&info->netlock, flags);
+               mutex_unlock(&info->port.mutex);
                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)
+               if (retval < 0) {
+                       mutex_unlock(&info->port.mutex);
                        goto cleanup;
+               }
        }
-
+       mutex_unlock(&info->port.mutex);
        retval = block_til_ready(tty, filp, info);
        if (retval) {
                DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval));
@@ -715,9 +716,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--;
        }
 
        DBGINFO(("%s open rc=%d\n", info->device_name, retval));
@@ -730,103 +731,57 @@ static void close(struct tty_struct *tty, struct file *filp)
 
        if (sanity_check(info, tty->name, "close"))
                return;
-       DBGINFO(("%s close entry, count=%d\n", info->device_name, info->count));
-
-       if (!info->count)
-               return;
-
-       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.
-                */
-               DBGERR(("%s close: bad refcount; tty->count=1, "
-                      "info->count=%d\n", info->device_name, info->count));
-               info->count = 1;
-       }
-
-       info->count--;
+       DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
 
-       /* if at least one open remaining, leave hardware active */
-       if (info->count)
+       if (tty_port_close_start(&info->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) {
-               DBGINFO(("%s call tty_wait_until_sent\n", info->device_name));
-               tty_wait_until_sent(tty, info->closing_wait);
-       }
-
-       if (info->flags & ASYNC_INITIALIZED)
+       mutex_lock(&info->port.mutex);
+       if (info->port.flags & ASYNC_INITIALIZED)
                wait_until_sent(tty, info->timeout);
-       if (tty->driver->flush_buffer)
-               tty->driver->flush_buffer(tty);
+       flush_buffer(tty);
        tty_ldisc_flush(tty);
 
        shutdown(info);
+       mutex_unlock(&info->port.mutex);
 
-       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:
-       DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->count));
+       DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
 }
 
 static void hangup(struct tty_struct *tty)
 {
        struct slgt_info *info = tty->driver_data;
+       unsigned long flags;
 
        if (sanity_check(info, tty->name, "hangup"))
                return;
        DBGINFO(("%s hangup\n", info->device_name));
 
        flush_buffer(tty);
+
+       mutex_lock(&info->port.mutex);
        shutdown(info);
 
-       info->count = 0;
-       info->flags &= ~ASYNC_NORMAL_ACTIVE;
-       info->tty = NULL;
+       spin_lock_irqsave(&info->port.lock, flags);
+       info->port.count = 0;
+       info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
+       info->port.tty = NULL;
+       spin_unlock_irqrestore(&info->port.lock, flags);
+       mutex_unlock(&info->port.mutex);
 
-       wake_up_interruptible(&info->open_wait);
+       wake_up_interruptible(&info->port.open_wait);
 }
 
-static void set_termios(struct tty_struct *tty, struct termios *old_termios)
+static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
 {
        struct slgt_info *info = tty->driver_data;
        unsigned long flags;
 
        DBGINFO(("%s set_termios\n", 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(old_termios->c_iflag)))
-               return;
-
        change_params(info);
 
        /* Handle transition to B0 status */
@@ -859,6 +814,18 @@ static void set_termios(struct tty_struct *tty, struct termios *old_termios)
        }
 }
 
+static void update_tx_timer(struct slgt_info *info)
+{
+       /*
+        * use worst case speed of 1200bps to calculate transmit timeout
+        * based on data in buffers (tbuf_bytes) and FIFO (128 bytes)
+        */
+       if (info->params.mode == MGSL_MODE_HDLC) {
+               int timeout  = (tbuf_bytes(info) * 7) + 1000;
+               mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout));
+       }
+}
+
 static int write(struct tty_struct *tty,
                 const unsigned char *buf, int count)
 {
@@ -867,69 +834,52 @@ static int write(struct tty_struct *tty,
        unsigned long flags;
 
        if (sanity_check(info, tty->name, "write"))
-               goto cleanup;
+               return -EIO;
+
        DBGINFO(("%s write count=%d\n", info->device_name, count));
 
-       if (!tty || !info->tx_buf)
-               goto cleanup;
+       if (!info->tx_buf || (count > info->max_frame_size))
+               return -EIO;
 
-       if (count > info->max_frame_size) {
-               ret = -EIO;
-               goto cleanup;
-       }
+       if (!count || tty->stopped || tty->hw_stopped)
+               return 0;
 
-       if (!count)
-               goto cleanup;
+       spin_lock_irqsave(&info->lock, flags);
 
-       if (info->params.mode == MGSL_MODE_RAW) {
-               unsigned int bufs_needed = (count/DMABUFSIZE);
-               unsigned int bufs_free = free_tbuf_count(info);
-               if (count % DMABUFSIZE)
-                       ++bufs_needed;
-               if (bufs_needed > bufs_free)
-                       goto cleanup;
-       } else {
-               if (info->tx_active)
+       if (info->tx_count) {
+               /* send accumulated data from send_char() */
+               if (!tx_load(info, info->tx_buf, info->tx_count))
                        goto cleanup;
-               if (info->tx_count) {
-                       /* send accumulated data from send_char() calls */
-                       /* as frame and wait before accepting more data. */
-                       tx_load(info, info->tx_buf, info->tx_count);
-                       goto start;
-               }
+               info->tx_count = 0;
        }
 
-       ret = info->tx_count = count;
-       tx_load(info, buf, count);
-       goto start;
-
-start:
-       if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
-               spin_lock_irqsave(&info->lock,flags);
-               if (!info->tx_active)
-                       tx_start(info);
-               spin_unlock_irqrestore(&info->lock,flags);
-       }
+       if (tx_load(info, buf, count))
+               ret = count;
 
 cleanup:
+       spin_unlock_irqrestore(&info->lock, flags);
        DBGINFO(("%s write rc=%d\n", info->device_name, ret));
        return ret;
 }
 
-static void put_char(struct tty_struct *tty, unsigned char ch)
+static int put_char(struct tty_struct *tty, unsigned char ch)
 {
        struct slgt_info *info = tty->driver_data;
        unsigned long flags;
+       int ret = 0;
 
        if (sanity_check(info, tty->name, "put_char"))
-               return;
+               return 0;
        DBGINFO(("%s put_char(%d)\n", info->device_name, ch));
-       if (!tty || !info->tx_buf)
-               return;
+       if (!info->tx_buf)
+               return 0;
        spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active && (info->tx_count < info->max_frame_size))
+       if (info->tx_count < info->max_frame_size) {
                info->tx_buf[info->tx_count++] = ch;
+               ret = 1;
+       }
        spin_unlock_irqrestore(&info->lock,flags);
+       return ret;
 }
 
 static void send_xchar(struct tty_struct *tty, char ch)
@@ -959,7 +909,7 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
        if (sanity_check(info, tty->name, "wait_until_sent"))
                return;
        DBGINFO(("%s wait_until_sent entry\n", info->device_name));
-       if (!(info->flags & ASYNC_INITIALIZED))
+       if (!(info->port.flags & ASYNC_INITIALIZED))
                goto exit;
 
        orig_jiffies = jiffies;
@@ -987,7 +937,6 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
                if (timeout && time_after(jiffies, orig_jiffies + timeout))
                        break;
        }
-
 exit:
        DBGINFO(("%s wait_until_sent exit\n", info->device_name));
 }
@@ -1020,10 +969,8 @@ static void flush_chars(struct tty_struct *tty)
        DBGINFO(("%s flush_chars start transmit\n", info->device_name));
 
        spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active && info->tx_count) {
-               tx_load(info, info->tx_buf,info->tx_count);
-               tx_start(info);
-       }
+       if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
+               info->tx_count = 0;
        spin_unlock_irqrestore(&info->lock,flags);
 }
 
@@ -1036,12 +983,10 @@ static void flush_buffer(struct tty_struct *tty)
                return;
        DBGINFO(("%s flush_buffer\n", info->device_name));
 
-       spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active)
-               info->tx_count = 0;
-       spin_unlock_irqrestore(&info->lock,flags);
+       spin_lock_irqsave(&info->lock, flags);
+       info->tx_count = 0;
+       spin_unlock_irqrestore(&info->lock, flags);
 
-       wake_up_interruptible(&tty->write_wait);
        tty_wakeup(tty);
 }
 
@@ -1073,12 +1018,10 @@ static void tx_release(struct tty_struct *tty)
        if (sanity_check(info, tty->name, "tx_release"))
                return;
        DBGINFO(("%s tx_release\n", info->device_name));
-       spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active && info->tx_count) {
-               tx_load(info, info->tx_buf, info->tx_count);
-               tx_start(info);
-       }
-       spin_unlock_irqrestore(&info->lock,flags);
+       spin_lock_irqsave(&info->lock, flags);
+       if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
+               info->tx_count = 0;
+       spin_unlock_irqrestore(&info->lock, flags);
 }
 
 /*
@@ -1097,86 +1040,225 @@ static int ioctl(struct tty_struct *tty, struct file *file,
                 unsigned int cmd, unsigned long arg)
 {
        struct slgt_info *info = tty->driver_data;
-       struct mgsl_icount cnow;        /* kernel counter temps */
-       struct serial_icounter_struct __user *p_cuser;  /* user space */
-       unsigned long flags;
        void __user *argp = (void __user *)arg;
+       int ret;
 
        if (sanity_check(info, tty->name, "ioctl"))
                return -ENODEV;
        DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd));
 
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
-           (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
+           (cmd != TIOCMIWAIT)) {
                if (tty->flags & (1 << TTY_IO_ERROR))
                    return -EIO;
        }
 
+       switch (cmd) {
+       case MGSL_IOCWAITEVENT:
+               return wait_mgsl_event(info, argp);
+       case TIOCMIWAIT:
+               return modem_input_wait(info,(int)arg);
+       case MGSL_IOCSGPIO:
+               return set_gpio(info, argp);
+       case MGSL_IOCGGPIO:
+               return get_gpio(info, argp);
+       case MGSL_IOCWAITGPIO:
+               return wait_gpio(info, argp);
+       case MGSL_IOCGXSYNC:
+               return get_xsync(info, argp);
+       case MGSL_IOCSXSYNC:
+               return set_xsync(info, (int)arg);
+       case MGSL_IOCGXCTRL:
+               return get_xctrl(info, argp);
+       case MGSL_IOCSXCTRL:
+               return set_xctrl(info, (int)arg);
+       }
+       mutex_lock(&info->port.mutex);
        switch (cmd) {
        case MGSL_IOCGPARAMS:
-               return get_params(info, argp);
+               ret = get_params(info, argp);
+               break;
        case MGSL_IOCSPARAMS:
-               return set_params(info, argp);
+               ret = set_params(info, argp);
+               break;
        case MGSL_IOCGTXIDLE:
-               return get_txidle(info, argp);
+               ret = get_txidle(info, argp);
+               break;
        case MGSL_IOCSTXIDLE:
-               return set_txidle(info, (int)arg);
+               ret = set_txidle(info, (int)arg);
+               break;
        case MGSL_IOCTXENABLE:
-               return tx_enable(info, (int)arg);
+               ret = tx_enable(info, (int)arg);
+               break;
        case MGSL_IOCRXENABLE:
-               return rx_enable(info, (int)arg);
+               ret = rx_enable(info, (int)arg);
+               break;
        case MGSL_IOCTXABORT:
-               return tx_abort(info);
+               ret = tx_abort(info);
+               break;
        case MGSL_IOCGSTATS:
-               return get_stats(info, argp);
-       case MGSL_IOCWAITEVENT:
-               return wait_mgsl_event(info, argp);
-       case TIOCMIWAIT:
-               return modem_input_wait(info,(int)arg);
+               ret = get_stats(info, argp);
+               break;
        case MGSL_IOCGIF:
-               return get_interface(info, argp);
+               ret = get_interface(info, argp);
+               break;
        case MGSL_IOCSIF:
-               return set_interface(info,(int)arg);
+               ret = set_interface(info,(int)arg);
+               break;
+       default:
+               ret = -ENOIOCTLCMD;
+       }
+       mutex_unlock(&info->port.mutex);
+       return ret;
+}
+
+static int get_icount(struct tty_struct *tty,
+                               struct serial_icounter_struct *icount)
+
+{
+       struct slgt_info *info = tty->driver_data;
+       struct mgsl_icount cnow;        /* kernel counter temps */
+       unsigned long flags;
+
+       spin_lock_irqsave(&info->lock,flags);
+       cnow = info->icount;
+       spin_unlock_irqrestore(&info->lock,flags);
+
+       icount->cts = cnow.cts;
+       icount->dsr = cnow.dsr;
+       icount->rng = cnow.rng;
+       icount->dcd = cnow.dcd;
+       icount->rx = cnow.rx;
+       icount->tx = cnow.tx;
+       icount->frame = cnow.frame;
+       icount->overrun = cnow.overrun;
+       icount->parity = cnow.parity;
+       icount->brk = cnow.brk;
+       icount->buf_overrun = cnow.buf_overrun;
+
+       return 0;
+}
+
+/*
+ * support for 32 bit ioctl calls on 64 bit systems
+ */
+#ifdef CONFIG_COMPAT
+static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params)
+{
+       struct MGSL_PARAMS32 tmp_params;
+
+       DBGINFO(("%s get_params32\n", info->device_name));
+       memset(&tmp_params, 0, sizeof(tmp_params));
+       tmp_params.mode            = (compat_ulong_t)info->params.mode;
+       tmp_params.loopback        = info->params.loopback;
+       tmp_params.flags           = info->params.flags;
+       tmp_params.encoding        = info->params.encoding;
+       tmp_params.clock_speed     = (compat_ulong_t)info->params.clock_speed;
+       tmp_params.addr_filter     = info->params.addr_filter;
+       tmp_params.crc_type        = info->params.crc_type;
+       tmp_params.preamble_length = info->params.preamble_length;
+       tmp_params.preamble        = info->params.preamble;
+       tmp_params.data_rate       = (compat_ulong_t)info->params.data_rate;
+       tmp_params.data_bits       = info->params.data_bits;
+       tmp_params.stop_bits       = info->params.stop_bits;
+       tmp_params.parity          = info->params.parity;
+       if (copy_to_user(user_params, &tmp_params, sizeof(struct MGSL_PARAMS32)))
+               return -EFAULT;
+       return 0;
+}
+
+static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params)
+{
+       struct MGSL_PARAMS32 tmp_params;
+
+       DBGINFO(("%s set_params32\n", info->device_name));
+       if (copy_from_user(&tmp_params, new_params, sizeof(struct MGSL_PARAMS32)))
+               return -EFAULT;
+
+       spin_lock(&info->lock);
+       if (tmp_params.mode == MGSL_MODE_BASE_CLOCK) {
+               info->base_clock = tmp_params.clock_speed;
+       } else {
+               info->params.mode            = tmp_params.mode;
+               info->params.loopback        = tmp_params.loopback;
+               info->params.flags           = tmp_params.flags;
+               info->params.encoding        = tmp_params.encoding;
+               info->params.clock_speed     = tmp_params.clock_speed;
+               info->params.addr_filter     = tmp_params.addr_filter;
+               info->params.crc_type        = tmp_params.crc_type;
+               info->params.preamble_length = tmp_params.preamble_length;
+               info->params.preamble        = tmp_params.preamble;
+               info->params.data_rate       = tmp_params.data_rate;
+               info->params.data_bits       = tmp_params.data_bits;
+               info->params.stop_bits       = tmp_params.stop_bits;
+               info->params.parity          = tmp_params.parity;
+       }
+       spin_unlock(&info->lock);
+
+       program_hw(info);
+
+       return 0;
+}
+
+static long slgt_compat_ioctl(struct tty_struct *tty, struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       struct slgt_info *info = tty->driver_data;
+       int rc = -ENOIOCTLCMD;
+
+       if (sanity_check(info, tty->name, "compat_ioctl"))
+               return -ENODEV;
+       DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd));
+
+       switch (cmd) {
+
+       case MGSL_IOCSPARAMS32:
+               rc = set_params32(info, compat_ptr(arg));
+               break;
+
+       case MGSL_IOCGPARAMS32:
+               rc = get_params32(info, compat_ptr(arg));
+               break;
+
+       case MGSL_IOCGPARAMS:
+       case MGSL_IOCSPARAMS:
+       case MGSL_IOCGTXIDLE:
+       case MGSL_IOCGSTATS:
+       case MGSL_IOCWAITEVENT:
+       case MGSL_IOCGIF:
        case MGSL_IOCSGPIO:
-               return set_gpio(info, argp);
        case MGSL_IOCGGPIO:
-               return get_gpio(info, argp);
        case MGSL_IOCWAITGPIO:
-               return wait_gpio(info, argp);
-       case TIOCGICOUNT:
-               spin_lock_irqsave(&info->lock,flags);
-               cnow = info->icount;
-               spin_unlock_irqrestore(&info->lock,flags);
-               p_cuser = argp;
-               if (put_user(cnow.cts, &p_cuser->cts) ||
-                   put_user(cnow.dsr, &p_cuser->dsr) ||
-                   put_user(cnow.rng, &p_cuser->rng) ||
-                   put_user(cnow.dcd, &p_cuser->dcd) ||
-                   put_user(cnow.rx, &p_cuser->rx) ||
-                   put_user(cnow.tx, &p_cuser->tx) ||
-                   put_user(cnow.frame, &p_cuser->frame) ||
-                   put_user(cnow.overrun, &p_cuser->overrun) ||
-                   put_user(cnow.parity, &p_cuser->parity) ||
-                   put_user(cnow.brk, &p_cuser->brk) ||
-                   put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
-                       return -EFAULT;
-               return 0;
-       default:
-               return -ENOIOCTLCMD;
+       case MGSL_IOCGXSYNC:
+       case MGSL_IOCGXCTRL:
+       case MGSL_IOCSTXIDLE:
+       case MGSL_IOCTXENABLE:
+       case MGSL_IOCRXENABLE:
+       case MGSL_IOCTXABORT:
+       case TIOCMIWAIT:
+       case MGSL_IOCSIF:
+       case MGSL_IOCSXSYNC:
+       case MGSL_IOCSXCTRL:
+               rc = ioctl(tty, file, cmd, arg);
+               break;
        }
-       return 0;
+
+       DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc));
+       return rc;
 }
+#else
+#define slgt_compat_ioctl NULL
+#endif /* ifdef CONFIG_COMPAT */
 
 /*
  * proc fs support
  */
-static inline int line_info(char *buf, struct slgt_info *info)
+static inline void line_info(struct seq_file *m, struct slgt_info *info)
 {
        char stat_buf[30];
-       int ret;
        unsigned long flags;
 
-       ret = sprintf(buf, "%s: IO=%08X IRQ=%d MaxFrameSize=%u\n",
+       seq_printf(m, "%s: IO=%08X IRQ=%d MaxFrameSize=%u\n",
                      info->device_name, info->phys_reg_addr,
                      info->irq_level, info->max_frame_size);
 
@@ -1201,85 +1283,82 @@ static inline int line_info(char *buf, struct slgt_info *info)
                strcat(stat_buf, "|RI");
 
        if (info->params.mode != MGSL_MODE_ASYNC) {
-               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, " rxcrc:%d", info->icount.rxcrc);
+                       seq_printf(m, " rxcrc:%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 synclink_gt_proc_show(struct seq_file *m, void *v)
 {
-       int len = 0, l;
-       off_t   begin = 0;
        struct slgt_info *info;
 
-       len += sprintf(page, "synclink_gt driver:%s\n", driver_version);
+       seq_puts(m, "synclink_gt driver\n");
 
        info = slgt_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 synclink_gt_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, synclink_gt_proc_show, NULL);
 }
 
+static const struct file_operations synclink_gt_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = synclink_gt_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 /*
  * return count of bytes in transmit buffer
  */
 static int chars_in_buffer(struct tty_struct *tty)
 {
        struct slgt_info *info = tty->driver_data;
+       int count;
        if (sanity_check(info, tty->name, "chars_in_buffer"))
                return 0;
-       DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, info->tx_count));
-       return info->tx_count;
+       count = tbuf_bytes(info);
+       DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count));
+       return count;
 }
 
 /*
@@ -1332,14 +1411,14 @@ 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)
 {
        struct slgt_info *info = tty->driver_data;
        unsigned short value;
        unsigned long flags;
 
        if (sanity_check(info, tty->name, "set_break"))
-               return;
+               return -EINVAL;
        DBGINFO(("%s set_break(%d)\n", info->device_name, break_state));
 
        spin_lock_irqsave(&info->lock,flags);
@@ -1350,9 +1429,10 @@ static void set_break(struct tty_struct *tty, int break_state)
                value &= ~BIT6;
        wr_reg16(info, TCR, value);
        spin_unlock_irqrestore(&info->lock,flags);
+       return 0;
 }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
 
 /**
  * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
@@ -1372,7 +1452,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;
 
        DBGINFO(("%s hdlcdev_attach\n", info->device_name));
@@ -1410,41 +1490,36 @@ 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)
 {
        struct slgt_info *info = dev_to_port(dev);
-       struct net_device_stats *stats = hdlc_stats(dev);
        unsigned long flags;
 
        DBGINFO(("%s hdlc_xmit\n", dev->name));
 
+       if (!skb->len)
+               return NETDEV_TX_OK;
+
        /* stop sending until this frame completes */
        netif_stop_queue(dev);
 
-       /* copy data to device buffers */
-       info->tx_count = skb->len;
-       tx_load(info, skb->data, skb->len);
-
        /* update network statistics */
-       stats->tx_packets++;
-       stats->tx_bytes += skb->len;
-
-       /* done with socket buffer, so free it */
-       dev_kfree_skb(skb);
+       dev->stats.tx_packets++;
+       dev->stats.tx_bytes += skb->len;
 
        /* save start time for transmit timeout detection */
        dev->trans_start = jiffies;
 
-       /* start hardware transmitter if necessary */
-       spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active)
-               tx_start(info);
-       spin_unlock_irqrestore(&info->lock,flags);
+       spin_lock_irqsave(&info->lock, flags);
+       tx_load(info, skb->data, skb->len);
+       spin_unlock_irqrestore(&info->lock, flags);
 
-       return 0;
+       /* done with socket buffer, so free it */
+       dev_kfree_skb(skb);
+
+       return NETDEV_TX_OK;
 }
 
 /**
@@ -1461,6 +1536,9 @@ static int hdlcdev_open(struct net_device *dev)
        int rc;
        unsigned long flags;
 
+       if (!try_module_get(THIS_MODULE))
+               return -EBUSY;
+
        DBGINFO(("%s hdlcdev_open\n", dev->name));
 
        /* generic HDLC layer open processing */
@@ -1469,7 +1547,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) {
                DBGINFO(("%s hdlc_open busy\n", dev->name));
                spin_unlock_irqrestore(&info->netlock, flags);
                return -EBUSY;
@@ -1497,8 +1575,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->signals & SerialSignal_DCD, dev);
-
+       if (info->signals & SerialSignal_DCD)
+               netif_carrier_on(dev);
+       else
+               netif_carrier_off(dev);
        return 0;
 }
 
@@ -1528,6 +1608,7 @@ static int hdlcdev_close(struct net_device *dev)
        info->netcount=0;
        spin_unlock_irqrestore(&info->netlock, flags);
 
+       module_put(THIS_MODULE);
        return 0;
 }
 
@@ -1551,12 +1632,14 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
 
        /* return error if TTY interface open */
-       if (info->count)
+       if (info->port.count)
                return -EBUSY;
 
        if (cmd != SIOCWANDEV)
                return hdlc_ioctl(dev, ifr, cmd);
 
+       memset(&new_line, 0, sizeof(new_line));
+
        switch(ifr->ifr_settings.type) {
        case IF_GET_IFACE: /* return current sync_serial_settings */
 
@@ -1641,13 +1724,12 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 static void hdlcdev_tx_timeout(struct net_device *dev)
 {
        struct slgt_info *info = dev_to_port(dev);
-       struct net_device_stats *stats = hdlc_stats(dev);
        unsigned long flags;
 
        DBGINFO(("%s hdlcdev_tx_timeout\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);
@@ -1680,28 +1762,34 @@ static void hdlcdev_rx(struct slgt_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);
 
        DBGINFO(("%s hdlcdev_rx\n", dev->name));
 
        if (skb == NULL) {
                DBGERR(("%s: can't alloc skb, drop 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
@@ -1729,11 +1817,8 @@ static int hdlcdev_init(struct slgt_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 */
@@ -1772,7 +1857,7 @@ static void hdlcdev_exit(struct slgt_info *info)
  */
 static void rx_async(struct slgt_info *info)
 {
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
        struct mgsl_icount *icount = &info->icount;
        unsigned int start, end;
        unsigned char *p;
@@ -1793,26 +1878,22 @@ static void rx_async(struct slgt_info *info)
                DBGDATA(info, p, count, "rx");
 
                for(i=0 ; i < count; i+=2, p+=2) {
-                       if (tty && chars) {
-                               tty_flip_buffer_push(tty);
-                               chars = 0;
-                       }
                        ch = *p;
                        icount->rx++;
 
                        stat = 0;
 
-                       if ((status = *(p+1) & (BIT9 + BIT8))) {
-                               if (status & BIT9)
+                       if ((status = *(p+1) & (BIT1 + BIT0))) {
+                               if (status & BIT1)
                                        icount->parity++;
-                               else if (status & BIT8)
+                               else if (status & BIT0)
                                        icount->frame++;
                                /* discard char if tty control flags say so */
                                if (status & info->ignore_status_mask)
                                        continue;
-                               if (status & BIT9)
+                               if (status & BIT1)
                                        stat = TTY_PARITY;
-                               else if (status & BIT8)
+                               else if (status & BIT0)
                                        stat = TTY_FRAME;
                        }
                        if (tty) {
@@ -1824,8 +1905,7 @@ static void rx_async(struct slgt_info *info)
                if (i < count) {
                        /* receive buffer not completed */
                        info->rbuf_index += i;
-                       info->rx_timer.expires = jiffies + 1;
-                       add_timer(&info->rx_timer);
+                       mod_timer(&info->rx_timer, jiffies + 1);
                        break;
                }
 
@@ -1865,8 +1945,8 @@ static int bh_action(struct slgt_info *info)
                rc = BH_STATUS;
        } else {
                /* Mark BH routine as complete */
-               info->bh_running   = 0;
-               info->bh_requested = 0;
+               info->bh_running = false;
+               info->bh_requested = false;
                rc = 0;
        }
 
@@ -1878,14 +1958,14 @@ static int bh_action(struct slgt_info *info)
 /*
  * perform bottom half processing
  */
-static void bh_handler(void* context)
+static void bh_handler(struct work_struct *work)
 {
-       struct slgt_info *info = context;
+       struct slgt_info *info = container_of(work, struct slgt_info, task);
        int action;
 
        if (!info)
                return;
-       info->bh_running = 1;
+       info->bh_running = true;
 
        while((action = bh_action(info))) {
                switch (action) {
@@ -1899,6 +1979,9 @@ static void bh_handler(void* context)
                                while(rx_get_frame(info));
                                break;
                        case MGSL_MODE_RAW:
+                       case MGSL_MODE_MONOSYNC:
+                       case MGSL_MODE_BISYNC:
+                       case MGSL_MODE_XSYNC:
                                while(rx_get_buf(info));
                                break;
                        }
@@ -1926,117 +2009,159 @@ static void bh_handler(void* context)
 
 static void bh_transmit(struct slgt_info *info)
 {
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
 
        DBGBH(("%s bh_transmit\n", info->device_name));
-       if (tty) {
+       if (tty)
                tty_wakeup(tty);
-               wake_up_interruptible(&tty->write_wait);
-       }
 }
 
-static void dsr_change(struct slgt_info *info)
+static void dsr_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT3) {
+               info->signals |= SerialSignal_DSR;
+               info->input_signal_events.dsr_up++;
+       } else {
+               info->signals &= ~SerialSignal_DSR;
+               info->input_signal_events.dsr_down++;
+       }
        DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_DSR);
                return;
        }
        info->icount.dsr++;
-       if (info->signals & SerialSignal_DSR)
-               info->input_signal_events.dsr_up++;
-       else
-               info->input_signal_events.dsr_down++;
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
 }
 
-static void cts_change(struct slgt_info *info)
+static void cts_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT2) {
+               info->signals |= SerialSignal_CTS;
+               info->input_signal_events.cts_up++;
+       } else {
+               info->signals &= ~SerialSignal_CTS;
+               info->input_signal_events.cts_down++;
+       }
        DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_CTS);
                return;
        }
        info->icount.cts++;
-       if (info->signals & SerialSignal_CTS)
-               info->input_signal_events.cts_up++;
-       else
-               info->input_signal_events.cts_down++;
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
 
-       if (info->flags & ASYNC_CTS_FLOW) {
-               if (info->tty) {
-                       if (info->tty->hw_stopped) {
+       if (info->port.flags & ASYNC_CTS_FLOW) {
+               if (info->port.tty) {
+                       if (info->port.tty->hw_stopped) {
                                if (info->signals & SerialSignal_CTS) {
-                                       info->tty->hw_stopped = 0;
+                                       info->port.tty->hw_stopped = 0;
                                        info->pending_bh |= BH_TRANSMIT;
                                        return;
                                }
                        } else {
                                if (!(info->signals & SerialSignal_CTS))
-                                       info->tty->hw_stopped = 1;
+                                       info->port.tty->hw_stopped = 1;
                        }
                }
        }
 }
 
-static void dcd_change(struct slgt_info *info)
+static void dcd_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT1) {
+               info->signals |= SerialSignal_DCD;
+               info->input_signal_events.dcd_up++;
+       } else {
+               info->signals &= ~SerialSignal_DCD;
+               info->input_signal_events.dcd_down++;
+       }
        DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_DCD);
                return;
        }
        info->icount.dcd++;
-       if (info->signals & SerialSignal_DCD) {
-               info->input_signal_events.dcd_up++;
-       } else {
-               info->input_signal_events.dcd_down++;
+#if SYNCLINK_GENERIC_HDLC
+       if (info->netcount) {
+               if (info->signals & SerialSignal_DCD)
+                       netif_carrier_on(info->netdev);
+               else
+                       netif_carrier_off(info->netdev);
        }
-#ifdef CONFIG_HDLC
-       if (info->netcount)
-               hdlc_set_carrier(info->signals & SerialSignal_DCD, info->netdev);
 #endif
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
 
-       if (info->flags & ASYNC_CHECK_CD) {
+       if (info->port.flags & ASYNC_CHECK_CD) {
                if (info->signals & SerialSignal_DCD)
-                       wake_up_interruptible(&info->open_wait);
+                       wake_up_interruptible(&info->port.open_wait);
                else {
-                       if (info->tty)
-                               tty_hangup(info->tty);
+                       if (info->port.tty)
+                               tty_hangup(info->port.tty);
                }
        }
 }
 
-static void ri_change(struct slgt_info *info)
+static void ri_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT0) {
+               info->signals |= SerialSignal_RI;
+               info->input_signal_events.ri_up++;
+       } else {
+               info->signals &= ~SerialSignal_RI;
+               info->input_signal_events.ri_down++;
+       }
        DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_RI);
                return;
        }
-       info->icount.dcd++;
-       if (info->signals & SerialSignal_RI) {
-               info->input_signal_events.ri_up++;
-       } else {
-               info->input_signal_events.ri_down++;
-       }
+       info->icount.rng++;
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
 }
 
+static void isr_rxdata(struct slgt_info *info)
+{
+       unsigned int count = info->rbuf_fill_count;
+       unsigned int i = info->rbuf_fill_index;
+       unsigned short reg;
+
+       while (rd_reg16(info, SSR) & IRQ_RXDATA) {
+               reg = rd_reg16(info, RDR);
+               DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg));
+               if (desc_complete(info->rbufs[i])) {
+                       /* all buffers full */
+                       rx_stop(info);
+                       info->rx_restart = 1;
+                       continue;
+               }
+               info->rbufs[i].buf[count++] = (unsigned char)reg;
+               /* async mode saves status byte to buffer for each data byte */
+               if (info->params.mode == MGSL_MODE_ASYNC)
+                       info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8);
+               if (count == info->rbuf_fill_level || (reg & BIT10)) {
+                       /* buffer full or end of frame */
+                       set_desc_count(info->rbufs[i], count);
+                       set_desc_status(info->rbufs[i], BIT15 | (reg >> 8));
+                       info->rbuf_fill_count = count = 0;
+                       if (++i == info->rbuf_count)
+                               i = 0;
+                       info->pending_bh |= BH_RECEIVE;
+               }
+       }
+
+       info->rbuf_fill_index = i;
+       info->rbuf_fill_count = count;
+}
+
 static void isr_serial(struct slgt_info *info)
 {
        unsigned short status = rd_reg16(info, SSR);
@@ -2045,22 +2170,24 @@ static void isr_serial(struct slgt_info *info)
 
        wr_reg16(info, SSR, status); /* clear pending */
 
-       info->irq_occurred = 1;
+       info->irq_occurred = true;
 
        if (info->params.mode == MGSL_MODE_ASYNC) {
                if (status & IRQ_TXIDLE) {
-                       if (info->tx_count)
+                       if (info->tx_active)
                                isr_txeom(info, status);
                }
+               if (info->rx_pio && (status & IRQ_RXDATA))
+                       isr_rxdata(info);
                if ((status & IRQ_RXBREAK) && (status & RXBREAK)) {
                        info->icount.brk++;
                        /* process break detection if tty control allows */
-                       if (info->tty) {
+                       if (info->port.tty) {
                                if (!(status & info->ignore_status_mask)) {
                                        if (info->read_status_mask & MASK_BREAK) {
-                                               tty_insert_flip_char(info->tty, 0, TTY_BREAK);
-                                               if (info->flags & ASYNC_SAK)
-                                                       do_SAK(info->tty);
+                                               tty_insert_flip_char(info->port.tty, 0, TTY_BREAK);
+                                               if (info->port.flags & ASYNC_SAK)
+                                                       do_SAK(info->port.tty);
                                        }
                                }
                        }
@@ -2068,7 +2195,8 @@ static void isr_serial(struct slgt_info *info)
        } else {
                if (status & (IRQ_TXIDLE + IRQ_TXUNDER))
                        isr_txeom(info, status);
-
+               if (info->rx_pio && (status & IRQ_RXDATA))
+                       isr_rxdata(info);
                if (status & IRQ_RXIDLE) {
                        if (status & RXIDLE)
                                info->icount.rxidle++;
@@ -2082,13 +2210,13 @@ static void isr_serial(struct slgt_info *info)
        }
 
        if (status & IRQ_DSR)
-               dsr_change(info);
+               dsr_change(info, status);
        if (status & IRQ_CTS)
-               cts_change(info);
+               cts_change(info, status);
        if (status & IRQ_DCD)
-               dcd_change(info);
+               dcd_change(info, status);
        if (status & IRQ_RI)
-               ri_change(info);
+               ri_change(info, status);
 }
 
 static void isr_rdma(struct slgt_info *info)
@@ -2112,7 +2240,7 @@ static void isr_rdma(struct slgt_info *info)
 
        if (status & (BIT5 + BIT4)) {
                DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name));
-               info->rx_restart = 1;
+               info->rx_restart = true;
        }
        info->pending_bh |= BH_RECEIVE;
 }
@@ -2142,13 +2270,42 @@ static void isr_tdma(struct slgt_info *info)
        }
 }
 
+/*
+ * return true if there are unsent tx DMA buffers, otherwise false
+ *
+ * if there are unsent buffers then info->tbuf_start
+ * is set to index of first unsent buffer
+ */
+static bool unsent_tbufs(struct slgt_info *info)
+{
+       unsigned int i = info->tbuf_current;
+       bool rc = false;
+
+       /*
+        * search backwards from last loaded buffer (precedes tbuf_current)
+        * for first unsent buffer (desc_count > 0)
+        */
+
+       do {
+               if (i)
+                       i--;
+               else
+                       i = info->tbuf_count - 1;
+               if (!desc_count(info->tbufs[i]))
+                       break;
+               info->tbuf_start = i;
+               rc = true;
+       } while (i != info->tbuf_current);
+
+       return rc;
+}
+
 static void isr_txeom(struct slgt_info *info, unsigned short status)
 {
        DBGISR(("%s txeom status=%04x\n", info->device_name, status));
 
        slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
        tdma_reset(info);
-       reset_tbufs(info);
        if (status & IRQ_TXUNDER) {
                unsigned short val = rd_reg16(info, TCR);
                wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
@@ -2163,24 +2320,28 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
                                info->icount.txok++;
                }
 
-               info->tx_active = 0;
-               info->tx_count = 0;
+               if (unsent_tbufs(info)) {
+                       tx_start(info);
+                       update_tx_timer(info);
+                       return;
+               }
+               info->tx_active = false;
 
                del_timer(&info->tx_timer);
 
                if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) {
                        info->signals &= ~SerialSignal_RTS;
-                       info->drop_rts_on_tx_done = 0;
+                       info->drop_rts_on_tx_done = false;
                        set_signals(info);
                }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                if (info->netcount)
                        hdlcdev_tx_done(info);
                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;
                        }
@@ -2211,40 +2372,36 @@ static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int
  *
  *     irq     interrupt number
  *     dev_id  device ID supplied during interrupt registration
- *     regs    interrupted processor context
  */
-static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs)
+static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
 {
-       struct slgt_info *info;
+       struct slgt_info *info = dev_id;
        unsigned int gsr;
        unsigned int i;
 
-       DBGISR(("slgt_interrupt irq=%d entry\n", irq));
-
-       info = dev_id;
-       if (!info)
-               return IRQ_NONE;
-
-       spin_lock(&info->lock);
+       DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level));
 
        while((gsr = rd_reg32(info, GSR) & 0xffffff00)) {
                DBGISR(("%s gsr=%08x\n", info->device_name, gsr));
-               info->irq_occurred = 1;
+               info->irq_occurred = true;
                for(i=0; i < info->port_count ; i++) {
                        if (info->port_array[i] == NULL)
                                continue;
+                       spin_lock(&info->port_array[i]->lock);
                        if (gsr & (BIT8 << i))
                                isr_serial(info->port_array[i]);
                        if (gsr & (BIT16 << (i*2)))
                                isr_rdma(info->port_array[i]);
                        if (gsr & (BIT17 << (i*2)))
                                isr_tdma(info->port_array[i]);
+                       spin_unlock(&info->port_array[i]->lock);
                }
        }
 
        if (info->gpio_present) {
                unsigned int state;
                unsigned int changed;
+               spin_lock(&info->lock);
                while ((changed = rd_reg32(info, IOSR)) != 0) {
                        DBGISR(("%s iosr=%08x\n", info->device_name, changed));
                        /* read latched state of GPIO signals */
@@ -2256,23 +2413,25 @@ static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs)
                                        isr_gpio(info->port_array[i], changed, state);
                        }
                }
+               spin_unlock(&info->lock);
        }
 
        for(i=0; i < info->port_count ; i++) {
                struct slgt_info *port = info->port_array[i];
-
-               if (port && (port->count || port->netcount) &&
+               if (port == NULL)
+                       continue;
+               spin_lock(&port->lock);
+               if ((port->port.count || port->netcount) &&
                    port->pending_bh && !port->bh_running &&
                    !port->bh_requested) {
                        DBGISR(("%s bh queued\n", port->device_name));
                        schedule_work(&port->task);
-                       port->bh_requested = 1;
+                       port->bh_requested = true;
                }
+               spin_unlock(&port->lock);
        }
 
-       spin_unlock(&info->lock);
-
-       DBGISR(("slgt_interrupt irq=%d exit\n", irq));
+       DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level));
        return IRQ_HANDLED;
 }
 
@@ -2280,7 +2439,7 @@ static int startup(struct slgt_info *info)
 {
        DBGINFO(("%s startup\n", info->device_name));
 
-       if (info->flags & ASYNC_INITIALIZED)
+       if (info->port.flags & ASYNC_INITIALIZED)
                return 0;
 
        if (!info->tx_buf) {
@@ -2298,10 +2457,10 @@ static int startup(struct slgt_info *info)
        /* program hardware for current parameters */
        change_params(info);
 
-       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;
 }
@@ -2313,7 +2472,7 @@ static void shutdown(struct slgt_info *info)
 {
        unsigned long flags;
 
-       if (!(info->flags & ASYNC_INITIALIZED))
+       if (!(info->port.flags & ASYNC_INITIALIZED))
                return;
 
        DBGINFO(("%s shutdown\n", info->device_name));
@@ -2336,7 +2495,7 @@ static void shutdown(struct slgt_info *info)
 
        slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
 
-       if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
+       if (!info->port.tty || info->port.tty->termios->c_cflag & HUPCL) {
                info->signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
                set_signals(info);
        }
@@ -2345,10 +2504,10 @@ static void shutdown(struct slgt_info *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(struct slgt_info *info)
@@ -2360,10 +2519,9 @@ static void program_hw(struct slgt_info *info)
        rx_stop(info);
        tx_stop(info);
 
-       if (info->params.mode == MGSL_MODE_HDLC ||
-           info->params.mode == MGSL_MODE_RAW ||
+       if (info->params.mode != MGSL_MODE_ASYNC ||
            info->netcount)
-               hdlc_mode(info);
+               sync_mode(info);
        else
                async_mode(info);
 
@@ -2374,11 +2532,11 @@ static void program_hw(struct slgt_info *info)
        info->ri_chkcount = 0;
        info->dsr_chkcount = 0;
 
-       slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR);
+       slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI);
        get_signals(info);
 
        if (info->netcount ||
-           (info->tty && info->tty->termios->c_cflag & CREAD))
+           (info->port.tty && info->port.tty->termios->c_cflag & CREAD))
                rx_start(info);
 
        spin_unlock_irqrestore(&info->lock,flags);
@@ -2392,11 +2550,11 @@ static void change_params(struct slgt_info *info)
        unsigned cflag;
        int bits_per_char;
 
-       if (!info->tty || !info->tty->termios)
+       if (!info->port.tty || !info->port.tty->termios)
                return;
        DBGINFO(("%s change_params\n", 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 */
@@ -2428,7 +2586,7 @@ static void change_params(struct slgt_info *info)
        bits_per_char = info->params.data_bits +
                        info->params.stop_bits + 1;
 
-       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) {
                info->timeout = (32*HZ*bits_per_char) /
@@ -2437,30 +2595,30 @@ static void change_params(struct slgt_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_mask = IRQ_RXOVER;
-       if (I_INPCK(info->tty))
+       if (I_INPCK(info->port.tty))
                info->read_status_mask |= MASK_PARITY | MASK_FRAMING;
-       if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
+       if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
                info->read_status_mask |= MASK_BREAK;
-       if (I_IGNPAR(info->tty))
+       if (I_IGNPAR(info->port.tty))
                info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING;
-       if (I_IGNBRK(info->tty)) {
+       if (I_IGNBRK(info->port.tty)) {
                info->ignore_status_mask |= MASK_BREAK;
                /* 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_mask |= MASK_OVERRUN;
        }
 
@@ -2497,10 +2655,13 @@ static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params)
                return -EFAULT;
 
        spin_lock_irqsave(&info->lock, flags);
-       memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS));
+       if (tmp_params.mode == MGSL_MODE_BASE_CLOCK)
+               info->base_clock = tmp_params.clock_speed;
+       else
+               memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS));
        spin_unlock_irqrestore(&info->lock, flags);
 
-       change_params(info);
+       program_hw(info);
 
        return 0;
 }
@@ -2519,7 +2680,8 @@ static int set_txidle(struct slgt_info *info, int idle_mode)
        DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode));
        spin_lock_irqsave(&info->lock,flags);
        info->idle_mode = idle_mode;
-       tx_set_idle(info);
+       if (info->params.mode != MGSL_MODE_ASYNC)
+               tx_set_idle(info);
        spin_unlock_irqrestore(&info->lock,flags);
        return 0;
 }
@@ -2556,11 +2718,42 @@ static int tx_abort(struct slgt_info *info)
 static int rx_enable(struct slgt_info *info, int enable)
 {
        unsigned long flags;
-       DBGINFO(("%s rx_enable(%d)\n", info->device_name, enable));
+       unsigned int rbuf_fill_level;
+       DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable));
        spin_lock_irqsave(&info->lock,flags);
+       /*
+        * enable[31..16] = receive DMA buffer fill level
+        * 0 = noop (leave fill level unchanged)
+        * fill level must be multiple of 4 and <= buffer size
+        */
+       rbuf_fill_level = ((unsigned int)enable) >> 16;
+       if (rbuf_fill_level) {
+               if ((rbuf_fill_level > DMABUFSIZE) || (rbuf_fill_level % 4)) {
+                       spin_unlock_irqrestore(&info->lock, flags);
+                       return -EINVAL;
+               }
+               info->rbuf_fill_level = rbuf_fill_level;
+               if (rbuf_fill_level < 128)
+                       info->rx_pio = 1; /* PIO mode */
+               else
+                       info->rx_pio = 0; /* DMA mode */
+               rx_stop(info); /* restart receiver to use new fill level */
+       }
+
+       /*
+        * enable[1..0] = receiver enable command
+        * 0 = disable
+        * 1 = enable
+        * 2 = enable or force hunt mode if already enabled
+        */
+       enable &= 3;
        if (enable) {
                if (!info->rx_enabled)
                        rx_start(info);
+               else if (enable == 2) {
+                       /* force hunt mode (write 1 to RCR[3]) */
+                       wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3);
+               }
        } else {
                if (info->rx_enabled)
                        rx_stop(info);
@@ -2717,6 +2910,69 @@ static int set_interface(struct slgt_info *info, int if_mode)
        return 0;
 }
 
+static int get_xsync(struct slgt_info *info, int __user *xsync)
+{
+       DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync));
+       if (put_user(info->xsync, xsync))
+               return -EFAULT;
+       return 0;
+}
+
+/*
+ * set extended sync pattern (1 to 4 bytes) for extended sync mode
+ *
+ * sync pattern is contained in least significant bytes of value
+ * most significant byte of sync pattern is oldest (1st sent/detected)
+ */
+static int set_xsync(struct slgt_info *info, int xsync)
+{
+       unsigned long flags;
+
+       DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync));
+       spin_lock_irqsave(&info->lock, flags);
+       info->xsync = xsync;
+       wr_reg32(info, XSR, xsync);
+       spin_unlock_irqrestore(&info->lock, flags);
+       return 0;
+}
+
+static int get_xctrl(struct slgt_info *info, int __user *xctrl)
+{
+       DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl));
+       if (put_user(info->xctrl, xctrl))
+               return -EFAULT;
+       return 0;
+}
+
+/*
+ * set extended control options
+ *
+ * xctrl[31:19] reserved, must be zero
+ * xctrl[18:17] extended sync pattern length in bytes
+ *              00 = 1 byte  in xsr[7:0]
+ *              01 = 2 bytes in xsr[15:0]
+ *              10 = 3 bytes in xsr[23:0]
+ *              11 = 4 bytes in xsr[31:0]
+ * xctrl[16]    1 = enable terminal count, 0=disabled
+ * xctrl[15:0]  receive terminal count for fixed length packets
+ *              value is count minus one (0 = 1 byte packet)
+ *              when terminal count is reached, receiver
+ *              automatically returns to hunt mode and receive
+ *              FIFO contents are flushed to DMA buffers with
+ *              end of frame (EOF) status
+ */
+static int set_xctrl(struct slgt_info *info, int xctrl)
+{
+       unsigned long flags;
+
+       DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl));
+       spin_lock_irqsave(&info->lock, flags);
+       info->xctrl = xctrl;
+       wr_reg32(info, XCR, xctrl);
+       spin_unlock_irqrestore(&info->lock, flags);
+       return 0;
+}
+
 /*
  * set general purpose IO pin state and direction
  *
@@ -2740,7 +2996,7 @@ static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
                 info->device_name, gpio.state, gpio.smask,
                 gpio.dir, gpio.dmask));
 
-       spin_lock_irqsave(&info->lock,flags);
+       spin_lock_irqsave(&info->port_array[0]->lock, flags);
        if (gpio.dmask) {
                data = rd_reg32(info, IODR);
                data |= gpio.dmask & gpio.dir;
@@ -2753,7 +3009,7 @@ static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
                data &= ~(gpio.smask & ~gpio.state);
                wr_reg32(info, IOVR, data);
        }
-       spin_unlock_irqrestore(&info->lock,flags);
+       spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
 
        return 0;
 }
@@ -2854,7 +3110,7 @@ static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
                return -EINVAL;
        init_cond_wait(&wait, gpio.smask);
 
-       spin_lock_irqsave(&info->lock, flags);
+       spin_lock_irqsave(&info->port_array[0]->lock, flags);
        /* enable interrupts for watched pins */
        wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
        /* get current pin states */
@@ -2866,20 +3122,20 @@ static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
        } else {
                /* wait for target state */
                add_cond_wait(&info->gpio_wait_q, &wait);
-               spin_unlock_irqrestore(&info->lock, flags);
+               spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
                schedule();
                if (signal_pending(current))
                        rc = -ERESTARTSYS;
                else
                        gpio.state = wait.data;
-               spin_lock_irqsave(&info->lock, flags);
+               spin_lock_irqsave(&info->port_array[0]->lock, flags);
                remove_cond_wait(&info->gpio_wait_q, &wait);
        }
 
        /* disable all GPIO interrupts if no waiting processes */
        if (info->gpio_wait_q == NULL)
                wr_reg32(info, IOER, 0);
-       spin_unlock_irqrestore(&info->lock,flags);
+       spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
 
        if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
                rc = -EFAULT;
@@ -2990,6 +3246,32 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
        return 0;
 }
 
+static int carrier_raised(struct tty_port *port)
+{
+       unsigned long flags;
+       struct slgt_info *info = container_of(port, struct slgt_info, port);
+
+       spin_lock_irqsave(&info->lock,flags);
+       get_signals(info);
+       spin_unlock_irqrestore(&info->lock,flags);
+       return (info->signals & SerialSignal_DCD) ? 1 : 0;
+}
+
+static void dtr_rts(struct tty_port *port, int on)
+{
+       unsigned long flags;
+       struct slgt_info *info = container_of(port, struct slgt_info, port);
+
+       spin_lock_irqsave(&info->lock,flags);
+       if (on)
+               info->signals |= SerialSignal_RTS + SerialSignal_DTR;
+       else
+               info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
+       set_signals(info);
+       spin_unlock_irqrestore(&info->lock,flags);
+}
+
+
 /*
  *  block current process until the device is ready to open
  */
@@ -2998,62 +3280,57 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 {
        DECLARE_WAITQUEUE(wait, current);
        int             retval;
-       int             do_clocal = 0, extra_count = 0;
+       bool            do_clocal = false;
+       bool            extra_count = false;
        unsigned long   flags;
+       int             cd;
+       struct tty_port *port = &info->port;
 
        DBGINFO(("%s block_til_ready\n", tty->driver->name));
 
        if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
                /* nonblock mode is set or port is not enabled */
-               info->flags |= ASYNC_NORMAL_ACTIVE;
+               port->flags |= ASYNC_NORMAL_ACTIVE;
                return 0;
        }
 
        if (tty->termios->c_cflag & CLOCAL)
-               do_clocal = 1;
+               do_clocal = true;
 
        /* 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);
 
        spin_lock_irqsave(&info->lock, flags);
        if (!tty_hung_up_p(filp)) {
-               extra_count = 1;
-               info->count--;
+               extra_count = true;
+               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->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->signals & SerialSignal_DCD)) ) {
+               if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd ))
                        break;
-               }
 
                if (signal_pending(current)) {
                        retval = -ERESTARTSYS;
@@ -3061,18 +3338,20 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
                }
 
                DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
+               tty_unlock();
                schedule();
+               tty_lock();
        }
 
        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 (!retval)
-               info->flags |= ASYNC_NORMAL_ACTIVE;
+               port->flags |= ASYNC_NORMAL_ACTIVE;
 
        DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
        return retval;
@@ -3080,7 +3359,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 
 static int alloc_tmp_rbuf(struct slgt_info *info)
 {
-       info->tmp_rbuf = kmalloc(info->max_frame_size, GFP_KERNEL);
+       info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL);
        if (info->tmp_rbuf == NULL)
                return -ENOMEM;
        return 0;
@@ -3209,9 +3488,9 @@ static int claim_resources(struct slgt_info *info)
                goto errout;
        }
        else
-               info->reg_addr_requested = 1;
+               info->reg_addr_requested = true;
 
-       info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE);
+       info->reg_addr = ioremap_nocache(info->phys_reg_addr, SLGT_REG_SIZE);
        if (!info->reg_addr) {
                DBGERR(("%s cant map device registers, addr=%08X\n",
                        info->device_name, info->phys_reg_addr));
@@ -3229,12 +3508,12 @@ static void release_resources(struct slgt_info *info)
 {
        if (info->irq_requested) {
                free_irq(info->irq_level, info);
-               info->irq_requested = 0;
+               info->irq_requested = false;
        }
 
        if (info->reg_addr_requested) {
                release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE);
-               info->reg_addr_requested = 0;
+               info->reg_addr_requested = false;
        }
 
        if (info->reg_addr) {
@@ -3257,7 +3536,6 @@ static void add_device(struct slgt_info *info)
        if (info->line < MAX_DEVICES) {
                if (maxframe[info->line])
                        info->max_frame_size = maxframe[info->line];
-               info->dosyncppp = dosyncppp[info->line];
        }
 
        slgt_device_count++;
@@ -3280,6 +3558,9 @@ static void add_device(struct slgt_info *info)
        case SYNCLINK_GT_DEVICE_ID:
                devstr = "GT";
                break;
+       case SYNCLINK_GT2_DEVICE_ID:
+               devstr = "GT2";
+               break;
        case SYNCLINK_GT4_DEVICE_ID:
                devstr = "GT4";
                break;
@@ -3294,11 +3575,16 @@ static void add_device(struct slgt_info *info)
                devstr, info->device_name, info->phys_reg_addr,
                info->irq_level, info->max_frame_size);
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        hdlcdev_init(info);
 #endif
 }
 
+static const struct tty_port_operations slgt_port_ops = {
+       .carrier_raised = carrier_raised,
+       .dtr_rts = dtr_rts,
+};
+
 /*
  *  allocate device instance structure, return NULL on failure
  */
@@ -3306,21 +3592,21 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
 {
        struct slgt_info *info;
 
-       info = kmalloc(sizeof(struct slgt_info), GFP_KERNEL);
+       info = kzalloc(sizeof(struct slgt_info), GFP_KERNEL);
 
        if (!info) {
                DBGERR(("%s device alloc failed adapter=%d port=%d\n",
                        driver_name, adapter_num, port_num));
        } else {
-               memset(info, 0, sizeof(struct slgt_info));
+               tty_port_init(&info->port);
+               info->port.ops = &slgt_port_ops;
                info->magic = MGSL_MAGIC;
-               INIT_WORK(&info->task, bh_handler, info);
+               INIT_WORK(&info->task, bh_handler);
                info->max_frame_size = 4096;
-               info->raw_rx_size = DMABUFSIZE;
-               info->close_delay = 5*HZ/10;
-               info->closing_wait = 30*HZ;
-               init_waitqueue_head(&info->open_wait);
-               init_waitqueue_head(&info->close_wait);
+               info->base_clock = 14745600;
+               info->rbuf_fill_level = DMABUFSIZE;
+               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);
@@ -3329,13 +3615,8 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
                info->adapter_num = adapter_num;
                info->port_num = port_num;
 
-               init_timer(&info->tx_timer);
-               info->tx_timer.data = (unsigned long)info;
-               info->tx_timer.function = tx_timeout;
-
-               init_timer(&info->rx_timer);
-               info->rx_timer.data = (unsigned long)info;
-               info->rx_timer.function = rx_timeout;
+               setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
+               setup_timer(&info->rx_timer, rx_timeout, (unsigned long)info);
 
                /* Copy configuration info to device instance data */
                info->pdev = pdev;
@@ -3343,7 +3624,7 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
                info->phys_reg_addr = pci_resource_start(pdev,0);
 
                info->bus_type = MGSL_BUS_TYPE_PCI;
-               info->irq_flags = SA_SHIRQ;
+               info->irq_flags = IRQF_SHARED;
 
                info->init_error = -1; /* assume error, set to 0 on successful init */
        }
@@ -3357,7 +3638,9 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
        int i;
        int port_count = 1;
 
-       if (pdev->device == SYNCLINK_GT4_DEVICE_ID)
+       if (pdev->device == SYNCLINK_GT2_DEVICE_ID)
+               port_count = 2;
+       else if (pdev->device == SYNCLINK_GT4_DEVICE_ID)
                port_count = 4;
 
        /* allocate device instances for all ports */
@@ -3385,7 +3668,6 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
 
                /* copy resource information from first port to others */
                for (i = 1; i < port_count; ++i) {
-                       port_array[i]->lock      = port_array[0]->lock;
                        port_array[i]->irq_level = port_array[0]->irq_level;
                        port_array[i]->reg_addr  = port_array[0]->reg_addr;
                        alloc_dma_bufs(port_array[i]);
@@ -3400,7 +3682,7 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
                                port_array[0]->device_name,
                                port_array[0]->irq_level));
                } else {
-                       port_array[0]->irq_requested = 1;
+                       port_array[0]->irq_requested = true;
                        adapter_test(port_array[0]);
                        for (i=1 ; i < port_count ; i++) {
                                port_array[i]->init_error = port_array[0]->init_error;
@@ -3408,6 +3690,9 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
                        }
                }
        }
+
+       for (i=0; i < port_count; ++i)
+               tty_register_device(serial_driver, port_array[i]->line, &(port_array[i]->pdev->dev));
 }
 
 static int __devinit init_one(struct pci_dev *dev,
@@ -3426,7 +3711,7 @@ static void __devexit remove_one(struct pci_dev *dev)
 {
 }
 
-static struct tty_operations ops = {
+static const struct tty_operations ops = {
        .open = open,
        .close = close,
        .write = write,
@@ -3436,18 +3721,20 @@ static struct tty_operations ops = {
        .chars_in_buffer = chars_in_buffer,
        .flush_buffer = flush_buffer,
        .ioctl = ioctl,
+       .compat_ioctl = slgt_compat_ioctl,
        .throttle = throttle,
        .unthrottle = unthrottle,
        .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,
+       .get_icount = get_icount,
+       .proc_fops = &synclink_gt_proc_fops,
 };
 
 static void slgt_cleanup(void)
@@ -3456,9 +3743,11 @@ static void slgt_cleanup(void)
        struct slgt_info *info;
        struct slgt_info *tmp;
 
-       printk("unload %s %s\n", driver_name, driver_version);
+       printk(KERN_INFO "unload %s\n", driver_name);
 
        if (serial_driver) {
+               for (info=slgt_device_list ; info != NULL ; info=info->next_device)
+                       tty_unregister_device(serial_driver, info->line);
                if ((rc = tty_unregister_driver(serial_driver)))
                        DBGERR(("tty_unregister_driver error=%d\n", rc));
                put_tty_driver(serial_driver);
@@ -3474,7 +3763,7 @@ static void slgt_cleanup(void)
        /* release devices */
        info = slgt_device_list;
        while(info) {
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                hdlcdev_exit(info);
 #endif
                free_dma_bufs(info);
@@ -3497,24 +3786,12 @@ static int __init slgt_init(void)
 {
        int rc;
 
-       printk("%s %s\n", driver_name, driver_version);
-
-       slgt_device_count = 0;
-       if ((rc = pci_register_driver(&pci_driver)) < 0) {
-               printk("%s pci_register_driver error=%d\n", driver_name, rc);
-               return rc;
-       }
-       pci_registered = 1;
-
-       if (!slgt_device_list) {
-               printk("%s no devices found\n",driver_name);
-               return -ENODEV;
-       }
+       printk(KERN_INFO "%s\n", driver_name);
 
        serial_driver = alloc_tty_driver(MAX_DEVICES);
        if (!serial_driver) {
-               rc = -ENOMEM;
-               goto error;
+               printk("%s can't allocate tty driver\n", driver_name);
+               return -ENOMEM;
        }
 
        /* Initialize the tty_driver structure */
@@ -3529,7 +3806,9 @@ static int __init slgt_init(void)
        serial_driver->init_termios = tty_std_termios;
        serial_driver->init_termios.c_cflag =
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
-       serial_driver->flags = TTY_DRIVER_REAL_RAW;
+       serial_driver->init_termios.c_ispeed = 9600;
+       serial_driver->init_termios.c_ospeed = 9600;
+       serial_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
        tty_set_operations(serial_driver, &ops);
        if ((rc = tty_register_driver(serial_driver)) < 0) {
                DBGERR(("%s can't register serial driver\n", driver_name));
@@ -3538,9 +3817,18 @@ static int __init slgt_init(void)
                goto error;
        }
 
-       printk("%s %s, tty major#%d\n",
-               driver_name, driver_version,
-               serial_driver->major);
+       printk(KERN_INFO "%s, tty major#%d\n",
+              driver_name, serial_driver->major);
+
+       slgt_device_count = 0;
+       if ((rc = pci_register_driver(&pci_driver)) < 0) {
+               printk("%s pci_register_driver error=%d\n", driver_name, rc);
+               goto error;
+       }
+       pci_registered = true;
+
+       if (!slgt_device_list)
+               printk("%s no devices found\n",driver_name);
 
        return 0;
 
@@ -3564,7 +3852,9 @@ module_exit(slgt_exit);
 #define CALC_REGADDR() \
        unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
        if (addr >= 0x80) \
-               reg_addr += (info->port_num) * 32;
+               reg_addr += (info->port_num) * 32; \
+       else if (addr >= 0x40)  \
+               reg_addr += (info->port_num) * 16;
 
 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr)
 {
@@ -3663,7 +3953,7 @@ static void enable_loopback(struct slgt_info *info)
 static void set_rate(struct slgt_info *info, u32 rate)
 {
        unsigned int div;
-       static unsigned int osc = 14745600;
+       unsigned int osc = info->base_clock;
 
        /* div = osc/rate - 1
         *
@@ -3695,8 +3985,8 @@ static void rx_stop(struct slgt_info *info)
 
        rdma_reset(info);
 
-       info->rx_enabled = 0;
-       info->rx_restart = 0;
+       info->rx_enabled = false;
+       info->rx_restart = false;
 }
 
 static void rx_start(struct slgt_info *info)
@@ -3716,15 +4006,27 @@ static void rx_start(struct slgt_info *info)
        rdma_reset(info);
        reset_rbufs(info);
 
-       /* set 1st descriptor address */
-       wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
-
-       if (info->params.mode != MGSL_MODE_ASYNC) {
-               /* enable rx DMA and DMA interrupt */
-               wr_reg32(info, RDCSR, (BIT2 + BIT0));
+       if (info->rx_pio) {
+               /* rx request when rx FIFO not empty */
+               wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14));
+               slgt_irq_on(info, IRQ_RXDATA);
+               if (info->params.mode == MGSL_MODE_ASYNC) {
+                       /* enable saving of rx status */
+                       wr_reg32(info, RDCSR, BIT6);
+               }
        } else {
-               /* enable saving of rx status, rx DMA and DMA interrupt */
-               wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
+               /* rx request when rx FIFO half full */
+               wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14));
+               /* set 1st descriptor address */
+               wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
+
+               if (info->params.mode != MGSL_MODE_ASYNC) {
+                       /* enable rx DMA and DMA interrupt */
+                       wr_reg32(info, RDCSR, (BIT2 + BIT0));
+               } else {
+                       /* enable saving of rx status, rx DMA and DMA interrupt */
+                       wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
+               }
        }
 
        slgt_irq_on(info, IRQ_RXOVER);
@@ -3732,20 +4034,20 @@ static void rx_start(struct slgt_info *info)
        /* enable receiver */
        wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1));
 
-       info->rx_restart = 0;
-       info->rx_enabled = 1;
+       info->rx_restart = false;
+       info->rx_enabled = true;
 }
 
 static void tx_start(struct slgt_info *info)
 {
        if (!info->tx_enabled) {
                wr_reg16(info, TCR,
-                       (unsigned short)(rd_reg16(info, TCR) | BIT1));
-               info->tx_enabled = TRUE;
+                        (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
+               info->tx_enabled = true;
        }
 
-       if (info->tx_count) {
-               info->drop_rts_on_tx_done = 0;
+       if (desc_count(info->tbufs[info->tbuf_start])) {
+               info->drop_rts_on_tx_done = false;
 
                if (info->params.mode != MGSL_MODE_ASYNC) {
                        if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
@@ -3753,7 +4055,7 @@ static void tx_start(struct slgt_info *info)
                                if (!(info->signals & SerialSignal_RTS)) {
                                        info->signals |= SerialSignal_RTS;
                                        set_signals(info);
-                                       info->drop_rts_on_tx_done = 1;
+                                       info->drop_rts_on_tx_done = true;
                                }
                        }
 
@@ -3761,37 +4063,16 @@ static void tx_start(struct slgt_info *info)
                        slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE);
                        /* clear tx idle and underrun status bits */
                        wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
-
-                       if (!(rd_reg32(info, TDCSR) & BIT0)) {
-                               /* tx DMA stopped, restart tx DMA */
-                               tdma_reset(info);
-                               /* set 1st descriptor address */
-                               wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
-                               if (info->params.mode == MGSL_MODE_RAW)
-                                       wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
-                               else
-                                       wr_reg32(info, TDCSR, BIT0); /* DMA enable */
-                       }
-
-                       if (info->params.mode != MGSL_MODE_RAW) {
-                               info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
-                               add_timer(&info->tx_timer);
-                       }
                } else {
-                       tdma_reset(info);
-                       /* set 1st descriptor address */
-                       wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
-
                        slgt_irq_off(info, IRQ_TXDATA);
                        slgt_irq_on(info, IRQ_TXIDLE);
                        /* clear tx idle status bit */
                        wr_reg16(info, SSR, IRQ_TXIDLE);
-
-                       /* enable tx DMA */
-                       wr_reg32(info, TDCSR, BIT0);
                }
-
-               info->tx_active = 1;
+               /* set 1st descriptor address and start DMA */
+               wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
+               wr_reg32(info, TDCSR, BIT2 + BIT0);
+               info->tx_active = true;
        }
 }
 
@@ -3806,7 +4087,6 @@ static void tx_stop(struct slgt_info *info)
        /* reset and disable transmitter */
        val = rd_reg16(info, TCR) & ~BIT1;          /* clear enable bit */
        wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
-       wr_reg16(info, TCR, val);                  /* clear reset */
 
        slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
 
@@ -3815,8 +4095,8 @@ static void tx_stop(struct slgt_info *info)
 
        reset_tbufs(info);
 
-       info->tx_enabled = 0;
-       info->tx_active  = 0;
+       info->tx_enabled = false;
+       info->tx_active = false;
 }
 
 static void reset_port(struct slgt_info *info)
@@ -3944,8 +4224,6 @@ static void async_mode(struct slgt_info *info)
 
        msc_set_vcr(info);
 
-       tx_set_idle(info);
-
        /* SCR (serial control)
         *
         * 15  1=tx req on FIFO half empty
@@ -3960,23 +4238,32 @@ static void async_mode(struct slgt_info *info)
         * 06  CTS      IRQ enable
         * 05  DCD      IRQ enable
         * 04  RI       IRQ enable
-        * 03  reserved, must be zero
+        * 03  0=16x sampling, 1=8x sampling
         * 02  1=txd->rxd internal loopback enable
         * 01  reserved, must be zero
         * 00  1=master IRQ enable
         */
        val = BIT15 + BIT14 + BIT0;
+       /* JCR[8] : 1 = x8 async mode feature available */
+       if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate &&
+           ((info->base_clock < (info->params.data_rate * 16)) ||
+            (info->base_clock % (info->params.data_rate * 16)))) {
+               /* use 8x sampling */
+               val |= BIT3;
+               set_rate(info, info->params.data_rate * 8);
+       } else {
+               /* use 16x sampling */
+               set_rate(info, info->params.data_rate * 16);
+       }
        wr_reg16(info, SCR, val);
 
        slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER);
 
-       set_rate(info, info->params.data_rate * 16);
-
        if (info->params.loopback)
                enable_loopback(info);
 }
 
-static void hdlc_mode(struct slgt_info *info)
+static void sync_mode(struct slgt_info *info)
 {
        unsigned short val;
 
@@ -3986,7 +4273,13 @@ static void hdlc_mode(struct slgt_info *info)
 
        /* TCR (tx control)
         *
-        * 15..13  mode, 000=HDLC 001=raw sync
+        * 15..13  mode
+        *         000=HDLC/SDLC
+        *         001=raw bit synchronous
+        *         010=asynchronous/isochronous
+        *         011=monosync byte synchronous
+        *         100=bisync byte synchronous
+        *         101=xsync byte synchronous
         * 12..10  encoding
         * 09      CRC enable
         * 08      CRC32
@@ -3998,10 +4291,16 @@ static void hdlc_mode(struct slgt_info *info)
         * 01      enable
         * 00      auto-CTS enable
         */
-       val = 0;
+       val = BIT2;
 
-       if (info->params.mode == MGSL_MODE_RAW)
-               val |= BIT13;
+       switch(info->params.mode) {
+       case MGSL_MODE_XSYNC:
+               val |= BIT15 + BIT13;
+               break;
+       case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
+       case MGSL_MODE_BISYNC:   val |= BIT15; break;
+       case MGSL_MODE_RAW:      val |= BIT13; break;
+       }
        if (info->if_mode & MGSL_INTERFACE_RTS_EN)
                val |= BIT7;
 
@@ -4016,7 +4315,7 @@ static void hdlc_mode(struct slgt_info *info)
        case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
        }
 
-       switch (info->params.crc_type)
+       switch (info->params.crc_type & HDLC_CRC_MASK)
        {
        case HDLC_CRC_16_CCITT: val |= BIT9; break;
        case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
@@ -4052,7 +4351,13 @@ static void hdlc_mode(struct slgt_info *info)
 
        /* RCR (rx control)
         *
-        * 15..13  mode, 000=HDLC 001=raw sync
+        * 15..13  mode
+        *         000=HDLC/SDLC
+        *         001=raw bit synchronous
+        *         010=asynchronous/isochronous
+        *         011=monosync byte synchronous
+        *         100=bisync byte synchronous
+        *         101=xsync byte synchronous
         * 12..10  encoding
         * 09      CRC enable
         * 08      CRC32
@@ -4063,8 +4368,14 @@ static void hdlc_mode(struct slgt_info *info)
         */
        val = 0;
 
-       if (info->params.mode == MGSL_MODE_RAW)
-               val |= BIT13;
+       switch(info->params.mode) {
+       case MGSL_MODE_XSYNC:
+               val |= BIT15 + BIT13;
+               break;
+       case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
+       case MGSL_MODE_BISYNC:   val |= BIT15; break;
+       case MGSL_MODE_RAW:      val |= BIT13; break;
+       }
 
        switch(info->params.encoding)
        {
@@ -4077,7 +4388,7 @@ static void hdlc_mode(struct slgt_info *info)
        case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
        }
 
-       switch (info->params.crc_type)
+       switch (info->params.crc_type & HDLC_CRC_MASK)
        {
        case HDLC_CRC_16_CCITT: val |= BIT9; break;
        case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
@@ -4179,17 +4490,38 @@ static void hdlc_mode(struct slgt_info *info)
  */
 static void tx_set_idle(struct slgt_info *info)
 {
-       unsigned char val = 0xff;
+       unsigned char val;
+       unsigned short tcr;
 
-       switch(info->idle_mode)
-       {
-       case HDLC_TXIDLE_FLAGS:          val = 0x7e; break;
-       case HDLC_TXIDLE_ALT_ZEROS_ONES: val = 0xaa; break;
-       case HDLC_TXIDLE_ZEROS:          val = 0x00; break;
-       case HDLC_TXIDLE_ONES:           val = 0xff; break;
-       case HDLC_TXIDLE_ALT_MARK_SPACE: val = 0xaa; break;
-       case HDLC_TXIDLE_SPACE:          val = 0x00; break;
-       case HDLC_TXIDLE_MARK:           val = 0xff; break;
+       /* if preamble enabled (tcr[6] == 1) then tx idle size = 8 bits
+        * else tcr[5:4] = tx idle size: 00 = 8 bits, 01 = 16 bits
+        */
+       tcr = rd_reg16(info, TCR);
+       if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) {
+               /* disable preamble, set idle size to 16 bits */
+               tcr = (tcr & ~(BIT6 + BIT5)) | BIT4;
+               /* MSB of 16 bit idle specified in tx preamble register (TPR) */
+               wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff));
+       } else if (!(tcr & BIT6)) {
+               /* preamble is disabled, set idle size to 8 bits */
+               tcr &= ~(BIT5 + BIT4);
+       }
+       wr_reg16(info, TCR, tcr);
+
+       if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) {
+               /* LSB of custom tx idle specified in tx idle register */
+               val = (unsigned char)(info->idle_mode & 0xff);
+       } else {
+               /* standard 8 bit idle patterns */
+               switch(info->idle_mode)
+               {
+               case HDLC_TXIDLE_FLAGS:          val = 0x7e; break;
+               case HDLC_TXIDLE_ALT_ZEROS_ONES:
+               case HDLC_TXIDLE_ALT_MARK_SPACE: val = 0xaa; break;
+               case HDLC_TXIDLE_ZEROS:
+               case HDLC_TXIDLE_SPACE:          val = 0x00; break;
+               default:                         val = 0xff;
+               }
        }
 
        wr_reg8(info, TIR, val);
@@ -4244,6 +4576,8 @@ static void msc_set_vcr(struct slgt_info *info)
                break;
        }
 
+       if (info->if_mode & MGSL_INTERFACE_MSB_FIRST)
+               val |= BIT4;
        if (info->signals & SerialSignal_DTR)
                val |= BIT3;
        if (info->signals & SerialSignal_RTS)
@@ -4282,11 +4616,7 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
        while(!done) {
                /* reset current buffer for reuse */
                info->rbufs[i].status = 0;
-               if (info->params.mode == MGSL_MODE_RAW)
-                       set_desc_count(info->rbufs[i], info->raw_rx_size);
-               else
-                       set_desc_count(info->rbufs[i], DMABUFSIZE);
-
+               set_desc_count(info->rbufs[i], info->rbuf_fill_level);
                if (i == last)
                        done = 1;
                if (++i == info->rbuf_count)
@@ -4301,22 +4631,29 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
 static void reset_rbufs(struct slgt_info *info)
 {
        free_rbufs(info, 0, info->rbuf_count - 1);
+       info->rbuf_fill_index = 0;
+       info->rbuf_fill_count = 0;
 }
 
 /*
  * pass receive HDLC frame to upper layer
  *
- * return 1 if frame available, otherwise 0
+ * return true if frame available, otherwise false
  */
-static int rx_get_frame(struct slgt_info *info)
+static bool rx_get_frame(struct slgt_info *info)
 {
        unsigned int start, end;
        unsigned short status;
        unsigned int framesize = 0;
-       int rc = 0;
        unsigned long flags;
-       struct tty_struct *tty = info->tty;
+       struct tty_struct *tty = info->port.tty;
        unsigned char addr_field = 0xff;
+       unsigned int crc_size = 0;
+
+       switch (info->params.crc_type & HDLC_CRC_MASK) {
+       case HDLC_CRC_16_CCITT: crc_size = 2; break;
+       case HDLC_CRC_32_CCITT: crc_size = 4; break;
+       }
 
 check_again:
 
@@ -4361,7 +4698,7 @@ check_again:
        status = desc_status(info->rbufs[end]);
 
        /* ignore CRC bit if not using CRC (bit is undefined) */
-       if (info->params.crc_type == HDLC_CRC_NONE)
+       if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE)
                status &= ~BIT1;
 
        if (framesize == 0 ||
@@ -4370,34 +4707,33 @@ check_again:
                goto check_again;
        }
 
-       if (framesize < 2 || status & (BIT1+BIT0)) {
-               if (framesize < 2 || (status & BIT0))
-                       info->icount.rxshort++;
-               else
-                       info->icount.rxcrc++;
+       if (framesize < (2 + crc_size) || status & BIT0) {
+               info->icount.rxshort++;
                framesize = 0;
+       } else if (status & BIT1) {
+               info->icount.rxcrc++;
+               if (!(info->params.crc_type & HDLC_CRC_RETURN_EX))
+                       framesize = 0;
+       }
 
-#ifdef CONFIG_HDLC
-               {
-                       struct net_device_stats *stats = hdlc_stats(info->netdev);
-                       stats->rx_errors++;
-                       stats->rx_frame_errors++;
-               }
-#endif
-       } else {
-               /* adjust frame size for CRC, if any */
-               if (info->params.crc_type == HDLC_CRC_16_CCITT)
-                       framesize -= 2;
-               else if (info->params.crc_type == HDLC_CRC_32_CCITT)
-                       framesize -= 4;
+#if SYNCLINK_GENERIC_HDLC
+       if (framesize == 0) {
+               info->netdev->stats.rx_errors++;
+               info->netdev->stats.rx_frame_errors++;
        }
+#endif
 
        DBGBH(("%s rx frame status=%04X size=%d\n",
                info->device_name, status, framesize));
-       DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, DMABUFSIZE), "rx");
+       DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx");
 
        if (framesize) {
-               if (framesize > info->max_frame_size)
+               if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
+                       framesize -= crc_size;
+                       crc_size = 0;
+               }
+
+               if (framesize > info->max_frame_size + crc_size)
                        info->icount.rxlong++;
                else {
                        /* copy dma buffer(s) to contiguous temp buffer */
@@ -4409,7 +4745,7 @@ check_again:
                        info->icount.rxok++;
 
                        while(copy_count) {
-                               int partial_count = min(copy_count, DMABUFSIZE);
+                               int partial_count = min_t(int, copy_count, info->rbuf_fill_level);
                                memcpy(p, info->rbufs[i].buf, partial_count);
                                p += partial_count;
                                copy_count -= partial_count;
@@ -4417,7 +4753,12 @@ check_again:
                                        i = 0;
                        }
 
-#ifdef CONFIG_HDLC
+                       if (info->params.crc_type & HDLC_CRC_RETURN_EX) {
+                               *p = (status & BIT1) ? RX_CRC_ERROR : RX_OK;
+                               framesize++;
+                       }
+
+#if SYNCLINK_GENERIC_HDLC
                        if (info->netcount)
                                hdlcdev_rx(info,info->tmp_rbuf, framesize);
                        else
@@ -4426,28 +4767,40 @@ check_again:
                }
        }
        free_rbufs(info, start, end);
-       rc = 1;
+       return true;
 
 cleanup:
-       return rc;
+       return false;
 }
 
 /*
  * pass receive buffer (RAW synchronous mode) to tty layer
- * return 1 if buffer available, otherwise 0
+ * return true if buffer available, otherwise false
  */
-static int rx_get_buf(struct slgt_info *info)
+static bool rx_get_buf(struct slgt_info *info)
 {
        unsigned int i = info->rbuf_current;
+       unsigned int count;
 
        if (!desc_complete(info->rbufs[i]))
-               return 0;
-       DBGDATA(info, info->rbufs[i].buf, desc_count(info->rbufs[i]), "rx");
-       DBGINFO(("rx_get_buf size=%d\n", desc_count(info->rbufs[i])));
-       ldisc_receive_buf(info->tty, info->rbufs[i].buf,
-                         info->flag_buf, desc_count(info->rbufs[i]));
+               return false;
+       count = desc_count(info->rbufs[i]);
+       switch(info->params.mode) {
+       case MGSL_MODE_MONOSYNC:
+       case MGSL_MODE_BISYNC:
+       case MGSL_MODE_XSYNC:
+               /* ignore residue in byte synchronous modes */
+               if (desc_residue(info->rbufs[i]))
+                       count--;
+               break;
+       }
+       DBGDATA(info, info->rbufs[i].buf, count, "rx");
+       DBGINFO(("rx_get_buf size=%d\n", count));
+       if (count)
+               ldisc_receive_buf(info->port.tty, info->rbufs[i].buf,
+                                 info->flag_buf, count);
        free_rbufs(info, i, i);
-       return 1;
+       return true;
 }
 
 static void reset_tbufs(struct slgt_info *info)
@@ -4477,33 +4830,94 @@ static unsigned int free_tbuf_count(struct slgt_info *info)
                        i=0;
        } while (i != info->tbuf_current);
 
-       /* last buffer with zero count may be in use, assume it is */
-       if (count)
+       /* if tx DMA active, last zero count buffer is in use */
+       if (count && (rd_reg32(info, TDCSR) & BIT0))
                --count;
 
        return count;
 }
 
 /*
- * load transmit DMA buffer(s) with data
+ * return number of bytes in unsent transmit DMA buffers
+ * and the serial controller tx FIFO
  */
-static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
+static unsigned int tbuf_bytes(struct slgt_info *info)
+{
+       unsigned int total_count = 0;
+       unsigned int i = info->tbuf_current;
+       unsigned int reg_value;
+       unsigned int count;
+       unsigned int active_buf_count = 0;
+
+       /*
+        * Add descriptor counts for all tx DMA buffers.
+        * If count is zero (cleared by DMA controller after read),
+        * the buffer is complete or is actively being read from.
+        *
+        * Record buf_count of last buffer with zero count starting
+        * from current ring position. buf_count is mirror
+        * copy of count and is not cleared by serial controller.
+        * If DMA controller is active, that buffer is actively
+        * being read so add to total.
+        */
+       do {
+               count = desc_count(info->tbufs[i]);
+               if (count)
+                       total_count += count;
+               else if (!total_count)
+                       active_buf_count = info->tbufs[i].buf_count;
+               if (++i == info->tbuf_count)
+                       i = 0;
+       } while (i != info->tbuf_current);
+
+       /* read tx DMA status register */
+       reg_value = rd_reg32(info, TDCSR);
+
+       /* if tx DMA active, last zero count buffer is in use */
+       if (reg_value & BIT0)
+               total_count += active_buf_count;
+
+       /* add tx FIFO count = reg_value[15..8] */
+       total_count += (reg_value >> 8) & 0xff;
+
+       /* if transmitter active add one byte for shift register */
+       if (info->tx_active)
+               total_count++;
+
+       return total_count;
+}
+
+/*
+ * load data into transmit DMA buffer ring and start transmitter if needed
+ * return true if data accepted, otherwise false (buffers full)
+ */
+static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size)
 {
        unsigned short count;
        unsigned int i;
        struct slgt_desc *d;
 
-       if (size == 0)
-               return;
+       /* check required buffer space */
+       if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info))
+               return false;
 
        DBGDATA(info, buf, size, "tx");
 
+       /*
+        * copy data to one or more DMA buffers in circular ring
+        * tbuf_start   = first buffer for this data
+        * tbuf_current = next free buffer
+        *
+        * Copy all data before making data visible to DMA controller by
+        * setting descriptor count of the first buffer.
+        * This prevents an active DMA controller from reading the first DMA
+        * buffers of a frame and stopping before the final buffers are filled.
+        */
+
        info->tbuf_start = i = info->tbuf_current;
 
        while (size) {
                d = &info->tbufs[i];
-               if (++i == info->tbuf_count)
-                       i = 0;
 
                count = (unsigned short)((size > DMABUFSIZE) ? DMABUFSIZE : size);
                memcpy(d->buf, buf, count);
@@ -4511,22 +4925,44 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
                size -= count;
                buf  += count;
 
-               if (!size && info->params.mode != MGSL_MODE_RAW)
-                       set_desc_eof(*d, 1); /* HDLC: set EOF of last desc */
+               /*
+                * set EOF bit for last buffer of HDLC frame or
+                * for every buffer in raw mode
+                */
+               if ((!size && info->params.mode == MGSL_MODE_HDLC) ||
+                   info->params.mode == MGSL_MODE_RAW)
+                       set_desc_eof(*d, 1);
                else
                        set_desc_eof(*d, 0);
 
-               set_desc_count(*d, count);
+               /* set descriptor count for all but first buffer */
+               if (i != info->tbuf_start)
+                       set_desc_count(*d, count);
+               d->buf_count = count;
+
+               if (++i == info->tbuf_count)
+                       i = 0;
        }
 
        info->tbuf_current = i;
+
+       /* set first buffer count to make new data visible to DMA controller */
+       d = &info->tbufs[info->tbuf_start];
+       set_desc_count(*d, d->buf_count);
+
+       /* start transmitter if needed and update transmit timeout */
+       if (!info->tx_active)
+               tx_start(info);
+       update_tx_timer(info);
+
+       return true;
 }
 
 static int register_test(struct slgt_info *info)
 {
        static unsigned short patterns[] =
                {0x0000, 0xffff, 0xaaaa, 0x5555, 0x6969, 0x9696};
-       static unsigned int count = sizeof(patterns)/sizeof(patterns[0]);
+       static unsigned int count = ARRAY_SIZE(patterns);
        unsigned int i;
        int rc = 0;
 
@@ -4548,11 +4984,11 @@ static int irq_test(struct slgt_info *info)
 {
        unsigned long timeout;
        unsigned long flags;
-       struct tty_struct *oldtty = info->tty;
+       struct tty_struct *oldtty = info->port.tty;
        u32 speed = info->params.data_rate;
 
        info->params.data_rate = 921600;
-       info->tty = NULL;
+       info->port.tty = NULL;
 
        spin_lock_irqsave(&info->lock, flags);
        async_mode(info);
@@ -4567,7 +5003,7 @@ static int irq_test(struct slgt_info *info)
 
        /* assume failure */
        info->init_error = DiagStatus_IrqFailure;
-       info->irq_occurred = FALSE;
+       info->irq_occurred = false;
 
        spin_unlock_irqrestore(&info->lock, flags);
 
@@ -4580,7 +5016,7 @@ static int irq_test(struct slgt_info *info)
        spin_unlock_irqrestore(&info->lock,flags);
 
        info->params.data_rate = speed;
-       info->tty = oldtty;
+       info->port.tty = oldtty;
 
        info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure;
        return info->irq_occurred ? 0 : -ENODEV;
@@ -4620,7 +5056,7 @@ static int loopback_test(struct slgt_info *info)
        int rc = -ENODEV;
        unsigned long flags;
 
-       struct tty_struct *oldtty = info->tty;
+       struct tty_struct *oldtty = info->port.tty;
        MGSL_PARAMS params;
 
        memcpy(&params, &info->params, sizeof(params));
@@ -4628,7 +5064,7 @@ static int loopback_test(struct slgt_info *info)
        info->params.mode = MGSL_MODE_ASYNC;
        info->params.data_rate = 921600;
        info->params.loopback = 1;
-       info->tty = NULL;
+       info->port.tty = NULL;
 
        /* build and send transmit frame */
        for (count = 0; count < TESTFRAMESIZE; ++count)
@@ -4641,9 +5077,7 @@ static int loopback_test(struct slgt_info *info)
        spin_lock_irqsave(&info->lock,flags);
        async_mode(info);
        rx_start(info);
-       info->tx_count = count;
        tx_load(info, buf, count);
-       tx_start(info);
        spin_unlock_irqrestore(&info->lock, flags);
 
        /* wait for receive complete */
@@ -4666,7 +5100,7 @@ static int loopback_test(struct slgt_info *info)
        spin_unlock_irqrestore(&info->lock,flags);
 
        memcpy(&info->params, &params, sizeof(info->params));
-       info->tty = oldtty;
+       info->port.tty = oldtty;
 
        info->init_error = rc ? DiagStatus_DmaFailure : 0;
        return rc;
@@ -4675,13 +5109,13 @@ static int loopback_test(struct slgt_info *info)
 static int adapter_test(struct slgt_info *info)
 {
        DBGINFO(("testing %s\n", info->device_name));
-       if ((info->init_error = register_test(info)) < 0) {
+       if (register_test(info) < 0) {
                printk("register test failure %s addr=%08X\n",
                        info->device_name, info->phys_reg_addr);
-       } else if ((info->init_error = irq_test(info)) < 0) {
+       } else if (irq_test(info) < 0) {
                printk("IRQ test failure %s IRQ=%d\n",
                        info->device_name, info->irq_level);
-       } else if ((info->init_error = loopback_test(info)) < 0) {
+       } else if (loopback_test(info) < 0) {
                printk("loopback test failure %s\n", info->device_name);
        }
        return info->init_error;
@@ -4700,11 +5134,10 @@ static void tx_timeout(unsigned long context)
                info->icount.txtimeout++;
        }
        spin_lock_irqsave(&info->lock,flags);
-       info->tx_active = 0;
-       info->tx_count = 0;
+       tx_stop(info);
        spin_unlock_irqrestore(&info->lock,flags);
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        if (info->netcount)
                hdlcdev_tx_done(info);
        else
@@ -4724,6 +5157,6 @@ static void rx_timeout(unsigned long context)
        spin_lock_irqsave(&info->lock, flags);
        info->pending_bh |= BH_RECEIVE;
        spin_unlock_irqrestore(&info->lock, flags);
-       bh_handler(info);
+       bh_handler(&info->task);
 }