]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/synclink_gt.c
[ARM] Fix SMP booting with non-zero PHYS_OFFSET
[linux-2.6-omap-h63xx.git] / drivers / char / synclink_gt.c
index 3c89266c8255fedeb8b5114abeb28a7998691e22..3e9058993e41805c0b2cd699ad836c76844fe398 100644 (file)
@@ -117,7 +117,7 @@ static struct pci_driver pci_driver = {
        .remove         = __devexit_p(remove_one),
 };
 
-static int pci_registered;
+static bool pci_registered;
 
 /*
  * module configuration and status
@@ -151,7 +151,7 @@ static void hangup(struct tty_struct *tty);
 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);
@@ -165,7 +165,7 @@ static int  read_proc(char *page, char **start, off_t off, int count,int *eof, v
 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,6 +214,7 @@ 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))
@@ -244,11 +245,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;
@@ -260,23 +261,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;
@@ -289,12 +282,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 */
 
@@ -304,22 +297,22 @@ 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 if_mode;
 
        /* 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 */
@@ -329,7 +322,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 */
@@ -467,13 +460,14 @@ 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 tdma_start(struct slgt_info *info);
@@ -521,7 +515,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);
@@ -641,8 +635,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);
        }
 }
@@ -672,20 +666,20 @@ 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;
+       info->port.tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
 
        spin_lock_irqsave(&info->netlock, flags);
        if (info->netcount) {
@@ -693,10 +687,10 @@ static int open(struct tty_struct *tty, struct file *filp)
                spin_unlock_irqrestore(&info->netlock, flags);
                goto cleanup;
        }
-       info->count++;
+       info->port.count++;
        spin_unlock_irqrestore(&info->netlock, flags);
 
-       if (info->count == 1) {
+       if (info->port.count == 1) {
                /* 1st open on this device, init hardware */
                retval = startup(info);
                if (retval < 0)
@@ -714,9 +708,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));
@@ -729,32 +723,32 @@ 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));
+       DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
 
-       if (!info->count)
+       if (!info->port.count)
                return;
 
        if (tty_hung_up_p(filp))
                goto cleanup;
 
-       if ((tty->count == 1) && (info->count != 1)) {
+       if ((tty->count == 1) && (info->port.count != 1)) {
                /*
                 * tty->count is 1 and the tty structure will be freed.
-                * info->count should be one in this case.
+                * 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->count=%d\n", info->device_name, info->count));
-               info->count = 1;
+                      "info->port.count=%d\n", info->device_name, info->port.count));
+               info->port.count = 1;
        }
 
-       info->count--;
+       info->port.count--;
 
        /* if at least one open remaining, leave hardware active */
-       if (info->count)
+       if (info->port.count)
                goto cleanup;
 
-       info->flags |= ASYNC_CLOSING;
+       info->port.flags |= ASYNC_CLOSING;
 
        /* set tty->closing to notify line discipline to
         * only process XON/XOFF characters. Only the N_TTY
@@ -764,35 +758,34 @@ static void close(struct tty_struct *tty, struct file *filp)
 
        /* wait for transmit data to clear all layers */
 
-       if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
+       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->closing_wait);
+               tty_wait_until_sent(tty, info->port.closing_wait);
        }
 
-       if (info->flags & ASYNC_INITIALIZED)
+       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);
 
        tty->closing = 0;
-       info->tty = NULL;
+       info->port.tty = NULL;
 
-       if (info->blocked_open) {
-               if (info->close_delay) {
-                       msleep_interruptible(jiffies_to_msecs(info->close_delay));
+       if (info->port.blocked_open) {
+               if (info->port.close_delay) {
+                       msleep_interruptible(jiffies_to_msecs(info->port.close_delay));
                }
-               wake_up_interruptible(&info->open_wait);
+               wake_up_interruptible(&info->port.open_wait);
        }
 
-       info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
+       info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
 
-       wake_up_interruptible(&info->close_wait);
+       wake_up_interruptible(&info->port.close_wait);
 
 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)
@@ -806,11 +799,11 @@ static void hangup(struct tty_struct *tty)
        flush_buffer(tty);
        shutdown(info);
 
-       info->count = 0;
-       info->flags &= ~ASYNC_NORMAL_ACTIVE;
-       info->tty = NULL;
+       info->port.count = 0;
+       info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
+       info->port.tty = NULL;
 
-       wake_up_interruptible(&info->open_wait);
+       wake_up_interruptible(&info->port.open_wait);
 }
 
 static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
@@ -858,6 +851,7 @@ static int write(struct tty_struct *tty,
        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;
@@ -874,25 +868,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);
@@ -913,20 +898,24 @@ cleanup:
        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 (!info->tx_buf)
-               return;
+               return 0;
        spin_lock_irqsave(&info->lock,flags);
-       if (!info->tx_active && (info->tx_count < info->max_frame_size))
+       if (!info->tx_active && (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)
@@ -956,7 +945,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;
@@ -967,6 +956,8 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
         * Note: use tight timings here to satisfy the NIST-PCTS.
         */
 
+       lock_kernel();
+
        if (info->params.data_rate) {
                char_time = info->timeout/(32 * 5);
                if (!char_time)
@@ -984,6 +975,7 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
                if (timeout && time_after(jiffies, orig_jiffies + timeout))
                        break;
        }
+       unlock_kernel();
 
 exit:
        DBGINFO(("%s wait_until_sent exit\n", info->device_name));
@@ -1097,6 +1089,7 @@ static int ioctl(struct tty_struct *tty, struct file *file,
        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;
@@ -1108,37 +1101,54 @@ static int ioctl(struct tty_struct *tty, struct file *file,
                    return -EIO;
        }
 
+       lock_kernel();
+
        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);
+               ret = get_stats(info, argp);
+               break;
        case MGSL_IOCWAITEVENT:
-               return wait_mgsl_event(info, argp);
+               ret = wait_mgsl_event(info, argp);
+               break;
        case TIOCMIWAIT:
-               return modem_input_wait(info,(int)arg);
+               ret = modem_input_wait(info,(int)arg);
+               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;
        case MGSL_IOCSGPIO:
-               return set_gpio(info, argp);
+               ret = set_gpio(info, argp);
+               break;
        case MGSL_IOCGGPIO:
-               return get_gpio(info, argp);
+               ret = get_gpio(info, argp);
+               break;
        case MGSL_IOCWAITGPIO:
-               return wait_gpio(info, argp);
+               ret = wait_gpio(info, argp);
+               break;
        case TIOCGICOUNT:
                spin_lock_irqsave(&info->lock,flags);
                cnow = info->icount;
@@ -1155,12 +1165,14 @@ static int ioctl(struct tty_struct *tty, struct file *file,
                    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;
+                       ret = -EFAULT;
+               ret = 0;
+               break;
        default:
-               return -ENOIOCTLCMD;
+               ret = -ENOIOCTLCMD;
        }
-       return 0;
+       unlock_kernel();
+       return ret;
 }
 
 /*
@@ -1378,10 +1390,12 @@ done:
 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;
 }
 
 /*
@@ -1434,14 +1448,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);
@@ -1452,6 +1466,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
@@ -1474,7 +1489,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));
@@ -1518,7 +1533,6 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
 static int 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));
@@ -1531,8 +1545,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);
@@ -1574,7 +1588,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;
@@ -1659,7 +1673,7 @@ 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)
@@ -1749,13 +1763,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);
@@ -1788,26 +1801,25 @@ 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;
+       dev->last_rx = jiffies;
 }
 
 /**
@@ -1880,7 +1892,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;
@@ -1968,8 +1980,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;
        }
 
@@ -1988,7 +2000,7 @@ static void bh_handler(struct work_struct *work)
 
        if (!info)
                return;
-       info->bh_running = 1;
+       info->bh_running = true;
 
        while((action = bh_action(info))) {
                switch (action) {
@@ -2031,7 +2043,7 @@ static void bh_handler(struct work_struct *work)
 
 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)
@@ -2077,17 +2089,17 @@ static void cts_change(struct slgt_info *info, unsigned short status)
        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;
                        }
                }
        }
@@ -2120,12 +2132,12 @@ static void dcd_change(struct slgt_info *info, unsigned short status)
        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);
                }
        }
 }
@@ -2158,7 +2170,7 @@ 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) {
@@ -2168,12 +2180,12 @@ static void isr_serial(struct slgt_info *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);
                                        }
                                }
                        }
@@ -2225,7 +2237,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;
 }
@@ -2276,14 +2288,14 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
                                info->icount.txok++;
                }
 
-               info->tx_active = 0;
+               info->tx_active = false;
                info->tx_count = 0;
 
                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);
                }
 
@@ -2293,7 +2305,7 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
                else
 #endif
                {
-                       if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
+                       if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) {
                                tx_stop(info);
                                return;
                        }
@@ -2337,7 +2349,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
 
        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;
@@ -2369,12 +2381,12 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
        for(i=0; i < info->port_count ; i++) {
                struct slgt_info *port = info->port_array[i];
 
-               if (port && (port->count || port->netcount) &&
+               if (port && (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;
                }
        }
 
@@ -2388,7 +2400,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) {
@@ -2406,10 +2418,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;
 }
@@ -2421,7 +2433,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));
@@ -2444,7 +2456,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);
        }
@@ -2453,10 +2465,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)
@@ -2485,7 +2497,7 @@ static void program_hw(struct slgt_info *info)
        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);
@@ -2499,11 +2511,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 */
@@ -2535,7 +2547,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) /
@@ -2544,30 +2556,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;
        }
 
@@ -2664,8 +2676,31 @@ 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;
+               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);
@@ -3110,37 +3145,38 @@ 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;
 
        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;
+               info->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, info->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(&info->port.open_wait, &wait);
 
        spin_lock_irqsave(&info->lock, flags);
        if (!tty_hung_up_p(filp)) {
-               extra_count = 1;
-               info->count--;
+               extra_count = true;
+               info->port.count--;
        }
        spin_unlock_irqrestore(&info->lock, flags);
-       info->blocked_open++;
+       info->port.blocked_open++;
 
        while (1) {
                if ((tty->termios->c_cflag & CBAUD)) {
@@ -3152,8 +3188,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 
                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) || !(info->port.flags & ASYNC_INITIALIZED)){
+                       retval = (info->port.flags & ASYNC_HUP_NOTIFY) ?
                                        -EAGAIN : -ERESTARTSYS;
                        break;
                }
@@ -3162,7 +3198,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
                get_signals(info);
                spin_unlock_irqrestore(&info->lock,flags);
 
-               if (!(info->flags & ASYNC_CLOSING) &&
+               if (!(info->port.flags & ASYNC_CLOSING) &&
                    (do_clocal || (info->signals & SerialSignal_DCD)) ) {
                        break;
                }
@@ -3177,14 +3213,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
        }
 
        set_current_state(TASK_RUNNING);
-       remove_wait_queue(&info->open_wait, &wait);
+       remove_wait_queue(&info->port.open_wait, &wait);
 
        if (extra_count)
-               info->count++;
-       info->blocked_open--;
+               info->port.count++;
+       info->port.blocked_open--;
 
        if (!retval)
-               info->flags |= ASYNC_NORMAL_ACTIVE;
+               info->port.flags |= ASYNC_NORMAL_ACTIVE;
 
        DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
        return retval;
@@ -3321,9 +3357,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));
@@ -3341,12 +3377,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) {
@@ -3427,14 +3463,13 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
                DBGERR(("%s device alloc failed adapter=%d port=%d\n",
                        driver_name, adapter_num, port_num));
        } else {
+               tty_port_init(&info->port);
                info->magic = MGSL_MAGIC;
                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->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);
@@ -3511,7 +3546,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;
@@ -3654,7 +3689,7 @@ static int __init slgt_init(void)
                printk("%s pci_register_driver error=%d\n", driver_name, rc);
                goto error;
        }
-       pci_registered = 1;
+       pci_registered = true;
 
        if (!slgt_device_list)
                printk("%s no devices found\n",driver_name);
@@ -3812,8 +3847,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)
@@ -3849,8 +3884,8 @@ 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)
@@ -3858,11 +3893,11 @@ static void tx_start(struct slgt_info *info)
        if (!info->tx_enabled) {
                wr_reg16(info, TCR,
                         (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
-               info->tx_enabled = TRUE;
+               info->tx_enabled = true;
        }
 
        if (info->tx_count) {
-               info->drop_rts_on_tx_done = 0;
+               info->drop_rts_on_tx_done = false;
 
                if (info->params.mode != MGSL_MODE_ASYNC) {
                        if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
@@ -3870,7 +3905,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;
                                }
                        }
 
@@ -3888,7 +3923,7 @@ static void tx_start(struct slgt_info *info)
                        wr_reg16(info, SSR, IRQ_TXIDLE);
                }
                tdma_start(info);
-               info->tx_active = 1;
+               info->tx_active = true;
        }
 }
 
@@ -3919,15 +3954,7 @@ static void tdma_start(struct slgt_info *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 */
-       }
+       wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
 }
 
 static void tx_stop(struct slgt_info *info)
@@ -3949,8 +3976,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)
@@ -4130,7 +4157,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;
@@ -4403,6 +4430,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)
@@ -4441,16 +4470,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)
@@ -4470,16 +4490,15 @@ static void reset_rbufs(struct slgt_info *info)
 /*
  * 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;
 
@@ -4551,15 +4570,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)) {
@@ -4579,7 +4597,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;
@@ -4601,23 +4619,23 @@ 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;
+               return false;
        count = desc_count(info->rbufs[i]);
        switch(info->params.mode) {
        case MGSL_MODE_MONOSYNC:
@@ -4630,10 +4648,10 @@ static int rx_get_buf(struct slgt_info *info)
        DBGDATA(info, info->rbufs[i].buf, count, "rx");
        DBGINFO(("rx_get_buf size=%d\n", count));
        if (count)
-               ldisc_receive_buf(info->tty, info->rbufs[i].buf,
+               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)
@@ -4670,6 +4688,56 @@ static unsigned int free_tbuf_count(struct slgt_info *info)
        return count;
 }
 
+/*
+ * 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
  */
@@ -4708,6 +4776,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;
@@ -4739,11 +4808,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);
@@ -4758,7 +4827,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);
 
@@ -4771,7 +4840,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;
@@ -4811,7 +4880,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));
@@ -4819,7 +4888,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)
@@ -4857,7 +4926,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;
@@ -4891,7 +4960,7 @@ static void tx_timeout(unsigned long context)
                info->icount.txtimeout++;
        }
        spin_lock_irqsave(&info->lock,flags);
-       info->tx_active = 0;
+       info->tx_active = false;
        info->tx_count = 0;
        spin_unlock_irqrestore(&info->lock,flags);