Don't unconditionally set in_sync on newly added device in raid5_reshape
[safe/jmp/linux-2.6] / drivers / char / synclink_gt.c
index 07aa42a..8678f0c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: synclink_gt.c,v 4.50 2007/07/25 19:29:25 paulkf Exp $
- *
  * Device driver for Microgate SyncLink GT serial adapters.
  *
  * written by Paul Fulghum for Microgate Corporation
@@ -47,7 +45,6 @@
 
 
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
@@ -63,7 +60,9 @@
 #include <linux/ptrace.h>
 #include <linux/ioport.h>
 #include <linux/mm.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/netdevice.h>
 #include <linux/vmalloc.h>
 #include <linux/init.h>
@@ -92,7 +91,6 @@
  * module identification
  */
 static char *driver_name     = "SyncLink GT";
-static char *driver_version  = "$Revision: 4.50 $";
 static char *tty_driver_name = "synclink_gt";
 static char *tty_dev_prefix  = "ttySLG";
 MODULE_LICENSE("GPL");
@@ -128,17 +126,14 @@ 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
@@ -161,11 +156,10 @@ static void tx_hold(struct tty_struct *tty);
 static void tx_release(struct tty_struct *tty);
 
 static int  ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
-static int  read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
 static int  chars_in_buffer(struct tty_struct *tty);
 static void throttle(struct tty_struct * tty);
 static void unthrottle(struct tty_struct * tty);
-static void set_break(struct tty_struct *tty, int break_state);
+static int set_break(struct tty_struct *tty, int break_state);
 
 /*
  * generic HDLC support and callbacks
@@ -214,12 +208,14 @@ struct slgt_desc
        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)
@@ -302,8 +298,10 @@ struct slgt_info {
        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;
 
        /* device status */
 
@@ -336,6 +334,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;
@@ -348,7 +348,6 @@ struct slgt_info {
        /* SPPP/Cisco HDLC device parts */
 
        int netcount;
-       int dosyncppp;
        spinlock_t netlock;
 #if SYNCLINK_GENERIC_HDLC
        struct net_device *netdev;
@@ -466,9 +465,9 @@ 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 tdma_start(struct slgt_info *info);
 static void tx_load(struct slgt_info *info, const char *buf, unsigned int count);
 
 static void get_signals(struct slgt_info *info);
@@ -513,7 +512,7 @@ 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);
@@ -723,44 +722,9 @@ static void close(struct tty_struct *tty, struct file *filp)
                return;
        DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
 
-       if (!info->port.count)
-               return;
-
-       if (tty_hung_up_p(filp))
-               goto cleanup;
-
-       if ((tty->count == 1) && (info->port.count != 1)) {
-               /*
-                * tty->count is 1 and the tty structure will be freed.
-                * info->port.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->port.count=%d\n", info->device_name, info->port.count));
-               info->port.count = 1;
-       }
-
-       info->port.count--;
-
-       /* if at least one open remaining, leave hardware active */
-       if (info->port.count)
+       if (tty_port_close_start(&info->port, tty, filp) == 0)
                goto cleanup;
 
-       info->port.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->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) {
-               DBGINFO(("%s call tty_wait_until_sent\n", info->device_name));
-               tty_wait_until_sent(tty, info->port.closing_wait);
-       }
-
        if (info->port.flags & ASYNC_INITIALIZED)
                wait_until_sent(tty, info->timeout);
        flush_buffer(tty);
@@ -768,20 +732,8 @@ static void close(struct tty_struct *tty, struct file *filp)
 
        shutdown(info);
 
-       tty->closing = 0;
+       tty_port_close_end(&info->port, tty);
        info->port.tty = NULL;
-
-       if (info->port.blocked_open) {
-               if (info->port.close_delay) {
-                       msleep_interruptible(jiffies_to_msecs(info->port.close_delay));
-               }
-               wake_up_interruptible(&info->port.open_wait);
-       }
-
-       info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
-
-       wake_up_interruptible(&info->port.close_wait);
-
 cleanup:
        DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
 }
@@ -843,12 +795,25 @@ static void set_termios(struct tty_struct *tty, struct ktermios *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)
 {
        int ret = 0;
        struct slgt_info *info = tty->driver_data;
        unsigned long flags;
+       unsigned int bufs_needed;
 
        if (sanity_check(info, tty->name, "write"))
                goto cleanup;
@@ -865,25 +830,16 @@ static int write(struct tty_struct *tty,
        if (!count)
                goto cleanup;
 
-       if (info->params.mode == MGSL_MODE_RAW ||
-           info->params.mode == MGSL_MODE_MONOSYNC ||
-           info->params.mode == MGSL_MODE_BISYNC) {
-               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)
-                       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;
-               }
+       if (!info->tx_active && info->tx_count) {
+               /* send accumulated data from send_char() */
+               tx_load(info, info->tx_buf, info->tx_count);
+               goto start;
        }
+       bufs_needed = (count/DMABUFSIZE);
+       if (count % DMABUFSIZE)
+               ++bufs_needed;
+       if (bufs_needed > free_tbuf_count(info))
+               goto cleanup;
 
        ret = info->tx_count = count;
        tx_load(info, buf, count);
@@ -894,8 +850,18 @@ start:
                spin_lock_irqsave(&info->lock,flags);
                if (!info->tx_active)
                        tx_start(info);
-               else
-                       tdma_start(info);
+               else if (!(rd_reg32(info, TDCSR) & BIT0)) {
+                       /* transmit still active but transmit DMA stopped */
+                       unsigned int i = info->tbuf_current;
+                       if (!i)
+                               i = info->tbuf_count;
+                       i--;
+                       /* if DMA buf unsent must try later after tx idle */
+                       if (desc_count(info->tbufs[i]))
+                               ret = 0;
+               }
+               if (ret > 0)
+                       update_tx_timer(info);
                spin_unlock_irqrestore(&info->lock,flags);
        }
 
@@ -1217,22 +1183,26 @@ static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *ne
                return -EFAULT;
 
        spin_lock(&info->lock);
-       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;
+       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);
 
-       change_params(info);
+       program_hw(info);
 
        return 0;
 }
@@ -1290,13 +1260,12 @@ static long slgt_compat_ioctl(struct tty_struct *tty, struct file *file,
 /*
  * 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);
 
@@ -1321,85 +1290,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;
 }
 
 /*
@@ -1452,14 +1418,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);
@@ -1470,6 +1436,7 @@ 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;
 }
 
 #if SYNCLINK_GENERIC_HDLC
@@ -1530,13 +1497,11 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  *
  * skb  socket buffer containing HDLC frame
  * dev  pointer to network device structure
- *
- * returns 0 if success, otherwise error code
  */
-static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb,
+                                     struct net_device *dev)
 {
        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));
@@ -1549,8 +1514,8 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
        tx_load(info, skb->data, skb->len);
 
        /* update network statistics */
-       stats->tx_packets++;
-       stats->tx_bytes += skb->len;
+       dev->stats.tx_packets++;
+       dev->stats.tx_bytes += skb->len;
 
        /* done with socket buffer, so free it */
        dev_kfree_skb(skb);
@@ -1558,13 +1523,12 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
        /* 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);
+       tx_start(info);
+       update_tx_timer(info);
        spin_unlock_irqrestore(&info->lock,flags);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /**
@@ -1767,13 +1731,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);
@@ -1806,28 +1769,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
@@ -1855,11 +1824,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 */
@@ -2168,6 +2134,40 @@ static void ri_change(struct slgt_info *info, unsigned short status)
        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);
@@ -2183,6 +2183,8 @@ static void isr_serial(struct slgt_info *info)
                        if (info->tx_count)
                                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 */
@@ -2199,7 +2201,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++;
@@ -2499,7 +2502,7 @@ 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 ||
@@ -2622,10 +2625,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;
 }
@@ -2682,8 +2688,35 @@ 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);
@@ -3120,6 +3153,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
  */
@@ -3131,12 +3190,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
        bool            do_clocal = false;
        bool            extra_count = false;
        unsigned long   flags;
+       int             cd;
+       struct tty_port *port = &info->port;
 
        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->port.flags |= ASYNC_NORMAL_ACTIVE;
+               port->flags |= ASYNC_NORMAL_ACTIVE;
                return 0;
        }
 
@@ -3145,46 +3206,38 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 
        /* Wait for carrier detect and the line to become
         * free (i.e., not in use by the callout).  While we are in
-        * this loop, info->port.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->port.open_wait, &wait);
+       add_wait_queue(&port->open_wait, &wait);
 
        spin_lock_irqsave(&info->lock, flags);
        if (!tty_hung_up_p(filp)) {
                extra_count = true;
-               info->port.count--;
+               port->count--;
        }
        spin_unlock_irqrestore(&info->lock, flags);
-       info->port.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->port.flags & ASYNC_INITIALIZED)){
-                       retval = (info->port.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->port.flags & ASYNC_CLOSING) &&
-                   (do_clocal || (info->signals & SerialSignal_DCD)) ) {
+               if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd ))
                        break;
-               }
 
                if (signal_pending(current)) {
                        retval = -ERESTARTSYS;
@@ -3196,14 +3249,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
        }
 
        set_current_state(TASK_RUNNING);
-       remove_wait_queue(&info->port.open_wait, &wait);
+       remove_wait_queue(&port->open_wait, &wait);
 
        if (extra_count)
-               info->port.count++;
-       info->port.blocked_open--;
+               port->count++;
+       port->blocked_open--;
 
        if (!retval)
-               info->port.flags |= ASYNC_NORMAL_ACTIVE;
+               port->flags |= ASYNC_NORMAL_ACTIVE;
 
        DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
        return retval;
@@ -3388,7 +3441,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++;
@@ -3433,6 +3485,11 @@ static void add_device(struct slgt_info *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
  */
@@ -3447,10 +3504,12 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
                        driver_name, adapter_num, port_num));
        } else {
                tty_port_init(&info->port);
+               info->port.ops = &slgt_port_ops;
                info->magic = MGSL_MAGIC;
                INIT_WORK(&info->task, bh_handler);
                info->max_frame_size = 4096;
-               info->raw_rx_size = DMABUFSIZE;
+               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);
@@ -3574,13 +3633,13 @@ static const struct tty_operations ops = {
        .send_xchar = send_xchar,
        .break_ctl = set_break,
        .wait_until_sent = wait_until_sent,
-       .read_proc = read_proc,
        .set_termios = set_termios,
        .stop = tx_hold,
        .start = tx_release,
        .hangup = hangup,
        .tiocmget = tiocmget,
        .tiocmset = tiocmset,
+       .proc_fops = &synclink_gt_proc_fops,
 };
 
 static void slgt_cleanup(void)
@@ -3589,7 +3648,7 @@ 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)
@@ -3632,7 +3691,7 @@ static int __init slgt_init(void)
 {
        int rc;
 
-       printk("%s %s\n", driver_name, driver_version);
+       printk(KERN_INFO "%s\n", driver_name);
 
        serial_driver = alloc_tty_driver(MAX_DEVICES);
        if (!serial_driver) {
@@ -3663,9 +3722,8 @@ 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) {
@@ -3798,7 +3856,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
         *
@@ -3851,15 +3909,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);
@@ -3896,58 +3966,19 @@ 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 (info->params.mode == MGSL_MODE_HDLC)
-                               mod_timer(&info->tx_timer, jiffies +
-                                               msecs_to_jiffies(5000));
                } else {
                        slgt_irq_off(info, IRQ_TXDATA);
                        slgt_irq_on(info, IRQ_TXIDLE);
                        /* clear tx idle status bit */
                        wr_reg16(info, SSR, IRQ_TXIDLE);
                }
-               tdma_start(info);
+               /* 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;
        }
 }
 
-/*
- * start transmit DMA if inactive and there are unsent buffers
- */
-static void tdma_start(struct slgt_info *info)
-{
-       unsigned int i;
-
-       if (rd_reg32(info, TDCSR) & BIT0)
-               return;
-
-       /* transmit DMA inactive, check for unsent buffers */
-       i = info->tbuf_start;
-       while (!desc_count(info->tbufs[i])) {
-               if (++i == info->tbuf_count)
-                       i = 0;
-               if (i == info->tbuf_current)
-                       return;
-       }
-       info->tbuf_start = i;
-
-       /* there are unsent buffers, start transmit DMA */
-
-       /* reset needed if previous error condition */
-       tdma_reset(info);
-
-       /* set 1st descriptor address */
-       wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
-       switch(info->params.mode) {
-       case MGSL_MODE_RAW:
-       case MGSL_MODE_MONOSYNC:
-       case MGSL_MODE_BISYNC:
-               wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
-               break;
-       default:
-               wr_reg32(info, TDCSR, BIT0); /* DMA enable */
-       }
-}
-
 static void tx_stop(struct slgt_info *info)
 {
        unsigned short val;
@@ -4110,18 +4141,27 @@ 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);
 }
@@ -4148,7 +4188,7 @@ static void sync_mode(struct slgt_info *info)
         * 01      enable
         * 00      auto-CTS enable
         */
-       val = 0;
+       val = BIT2;
 
        switch(info->params.mode) {
        case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
@@ -4421,6 +4461,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)
@@ -4459,16 +4501,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;
-               switch(info->params.mode) {
-               case MGSL_MODE_RAW:
-               case MGSL_MODE_MONOSYNC:
-               case MGSL_MODE_BISYNC:
-                       set_desc_count(info->rbufs[i], info->raw_rx_size);
-                       break;
-               default:
-                       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)
@@ -4483,6 +4516,8 @@ 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;
 }
 
 /*
@@ -4568,15 +4603,14 @@ check_again:
 
 #if SYNCLINK_GENERIC_HDLC
        if (framesize == 0) {
-               struct net_device_stats *stats = hdlc_stats(info->netdev);
-               stats->rx_errors++;
-               stats->rx_frame_errors++;
+               info->netdev->stats.rx_errors++;
+               info->netdev->stats.rx_frame_errors++;
        }
 #endif
 
        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 (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
@@ -4596,7 +4630,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;
@@ -4688,6 +4722,56 @@ static unsigned int free_tbuf_count(struct slgt_info *info)
 }
 
 /*
+ * return number of bytes in unsent transmit DMA buffers
+ * and the serial controller tx FIFO
+ */
+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 transmit DMA buffer(s) with data
  */
 static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
@@ -4725,6 +4809,7 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
                        set_desc_eof(*d, 0);
 
                set_desc_count(*d, count);
+               d->buf_count = count;
        }
 
        info->tbuf_current = i;
@@ -4908,8 +4993,7 @@ static void tx_timeout(unsigned long context)
                info->icount.txtimeout++;
        }
        spin_lock_irqsave(&info->lock,flags);
-       info->tx_active = false;
-       info->tx_count = 0;
+       tx_stop(info);
        spin_unlock_irqrestore(&info->lock,flags);
 
 #if SYNCLINK_GENERIC_HDLC