TTY: ircomm, use open counts from tty_port
[linux-3.10.git] / net / irda / ircomm / ircomm_tty.c
index 76c3057..787578f 100644 (file)
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/fs.h>
+#include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/seq_file.h>
 #include <linux/termios.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/interrupt.h>
 #include <linux/device.h>              /* for MODULE_ALIAS_CHARDEV_MAJOR */
 
@@ -72,8 +75,7 @@ static int ircomm_tty_control_indication(void *instance, void *sap,
 static void ircomm_tty_flow_indication(void *instance, void *sap,
                                       LOCAL_FLOW cmd);
 #ifdef CONFIG_PROC_FS
-static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
-                               int *eof, void *unused);
+static const struct file_operations ircomm_tty_proc_fops;
 #endif /* CONFIG_PROC_FS */
 static struct tty_driver *driver;
 
@@ -98,7 +100,7 @@ static const struct tty_operations ops = {
        .hangup          = ircomm_tty_hangup,
        .wait_until_sent = ircomm_tty_wait_until_sent,
 #ifdef CONFIG_PROC_FS
-       .read_proc       = ircomm_tty_read_proc,
+       .proc_fops       = &ircomm_tty_proc_fops,
 #endif /* CONFIG_PROC_FS */
 };
 
@@ -120,7 +122,6 @@ static int __init ircomm_tty_init(void)
                return -ENOMEM;
        }
 
-       driver->owner           = THIS_MODULE;
        driver->driver_name     = "ircomm";
        driver->name            = "ircomm";
        driver->major           = IRCOMM_TTY_MAJOR;
@@ -271,25 +272,25 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
 
        /* Wait for carrier detect and the line to become
         * free (i.e., not in use by the callout).  While we are in
-        * this loop, self->open_count is dropped by one, so that
+        * this loop, self->port.count is dropped by one, so that
         * mgsl_close() knows when to free things.  We restore it upon
         * exit, either normal or abnormal.
         */
 
        retval = 0;
-       add_wait_queue(&self->open_wait, &wait);
+       add_wait_queue(&self->port.open_wait, &wait);
 
        IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
-             __FILE__,__LINE__, tty->driver->name, self->open_count );
+             __FILE__, __LINE__, tty->driver->name, self->port.count);
 
-       /* As far as I can see, we protect open_count - Jean II */
+       /* As far as I can see, we protect port.count - Jean II */
        spin_lock_irqsave(&self->spinlock, flags);
        if (!tty_hung_up_p(filp)) {
                extra_count = 1;
-               self->open_count--;
+               self->port.count--;
        }
        spin_unlock_irqrestore(&self->spinlock, flags);
-       self->blocked_open++;
+       self->port.blocked_open++;
 
        while (1) {
                if (tty->termios->c_cflag & CBAUD) {
@@ -329,24 +330,24 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
                }
 
                IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
-                     __FILE__,__LINE__, tty->driver->name, self->open_count );
+                     __FILE__, __LINE__, tty->driver->name, self->port.count);
 
                schedule();
        }
 
        __set_current_state(TASK_RUNNING);
-       remove_wait_queue(&self->open_wait, &wait);
+       remove_wait_queue(&self->port.open_wait, &wait);
 
        if (extra_count) {
                /* ++ is not atomic, so this should be protected - Jean II */
                spin_lock_irqsave(&self->spinlock, flags);
-               self->open_count++;
+               self->port.count++;
                spin_unlock_irqrestore(&self->spinlock, flags);
        }
-       self->blocked_open--;
+       self->port.blocked_open--;
 
        IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
-             __FILE__,__LINE__, tty->driver->name, self->open_count);
+             __FILE__, __LINE__, tty->driver->name, self->port.count);
 
        if (!retval)
                self->flags |= ASYNC_NORMAL_ACTIVE;
@@ -364,17 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
 static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
 {
        struct ircomm_tty_cb *self;
-       unsigned int line;
+       unsigned int line = tty->index;
        unsigned long   flags;
        int ret;
 
        IRDA_DEBUG(2, "%s()\n", __func__ );
 
-       line = tty->index;
-       if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
-               return -ENODEV;
-       }
-
        /* Check if instance already exists */
        self = hashbin_lock_find(ircomm_tty, line, NULL);
        if (!self) {
@@ -385,6 +381,7 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
                        return -ENOMEM;
                }
 
+               tty_port_init(&self->port);
                self->magic = IRCOMM_TTY_MAGIC;
                self->flow = FLOW_STOP;
 
@@ -392,36 +389,35 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
                INIT_WORK(&self->tqueue, ircomm_tty_do_softint);
                self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED;
                self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
-               self->close_delay = 5*HZ/10;
-               self->closing_wait = 30*HZ;
 
                /* Init some important stuff */
                init_timer(&self->watchdog_timer);
-               init_waitqueue_head(&self->open_wait);
-               init_waitqueue_head(&self->close_wait);
                spin_lock_init(&self->spinlock);
 
                /*
                 * Force TTY into raw mode by default which is usually what
                 * we want for IrCOMM and IrLPT. This way applications will
                 * not have to twiddle with printcap etc.
+                *
+                * Note this is completely usafe and doesn't work properly
                 */
                tty->termios->c_iflag = 0;
                tty->termios->c_oflag = 0;
 
                /* Insert into hash */
+               /* FIXME there is a window from find to here */
                hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL);
        }
        /* ++ is not atomic, so this should be protected - Jean II */
        spin_lock_irqsave(&self->spinlock, flags);
-       self->open_count++;
+       self->port.count++;
 
        tty->driver_data = self;
        self->tty = tty;
        spin_unlock_irqrestore(&self->spinlock, flags);
 
        IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
-                  self->line, self->open_count);
+                  self->line, self->port.count);
 
        /* Not really used by us, but lets do it anyway */
        self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
@@ -440,15 +436,16 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
                 * probably better sleep uninterruptible?
                 */
 
-               if (wait_event_interruptible(self->close_wait, !test_bit(ASYNC_B_CLOSING, &self->flags))) {
+               if (wait_event_interruptible(self->port.close_wait,
+                               !test_bit(ASYNC_B_CLOSING, &self->flags))) {
                        IRDA_WARNING("%s - got signal while blocking on ASYNC_CLOSING!\n",
                                     __func__);
                        return -ERESTARTSYS;
                }
 
 #ifdef SERIAL_DO_RESTART
-               return ((self->flags & ASYNC_HUP_NOTIFY) ?
-                       -EAGAIN : -ERESTARTSYS);
+               return (self->flags & ASYNC_HUP_NOTIFY) ?
+                       -EAGAIN : -ERESTARTSYS;
 #else
                return -EAGAIN;
 #endif
@@ -495,9 +492,6 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
 
        IRDA_DEBUG(0, "%s()\n", __func__ );
 
-       if (!tty)
-               return;
-
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
 
@@ -510,7 +504,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
                return;
        }
 
-       if ((tty->count == 1) && (self->open_count != 1)) {
+       if ((tty->count == 1) && (self->port.count != 1)) {
                /*
                 * Uh, oh.  tty->count is 1, which means that the tty
                 * structure will be freed.  state->count should always
@@ -520,16 +514,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
                 */
                IRDA_DEBUG(0, "%s(), bad serial port count; "
                           "tty->count is 1, state->count is %d\n", __func__ ,
-                          self->open_count);
-               self->open_count = 1;
+                          self->port.count);
+               self->port.count = 1;
        }
 
-       if (--self->open_count < 0) {
+       if (--self->port.count < 0) {
                IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
-                          __func__, self->line, self->open_count);
-               self->open_count = 0;
+                          __func__, self->line, self->port.count);
+               self->port.count = 0;
        }
-       if (self->open_count) {
+       if (self->port.count) {
                spin_unlock_irqrestore(&self->spinlock, flags);
 
                IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
@@ -550,8 +544,8 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
         * the line discipline to only process XON/XOFF characters.
         */
        tty->closing = 1;
-       if (self->closing_wait != ASYNC_CLOSING_WAIT_NONE)
-               tty_wait_until_sent(tty, self->closing_wait);
+       if (self->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
+               tty_wait_until_sent_from_close(tty, self->port.closing_wait);
 
        ircomm_tty_shutdown(self);
 
@@ -561,14 +555,14 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
        tty->closing = 0;
        self->tty = NULL;
 
-       if (self->blocked_open) {
-               if (self->close_delay)
-                       schedule_timeout_interruptible(self->close_delay);
-               wake_up_interruptible(&self->open_wait);
+       if (self->port.blocked_open) {
+               if (self->port.close_delay)
+                       schedule_timeout_interruptible(self->port.close_delay);
+               wake_up_interruptible(&self->port.open_wait);
        }
 
        self->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
-       wake_up_interruptible(&self->close_wait);
+       wake_up_interruptible(&self->port.close_wait);
 }
 
 /*
@@ -650,12 +644,7 @@ static void ircomm_tty_do_softint(struct work_struct *work)
        }
 
        /* Check if user (still) wants to be waken up */
-       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-           tty->ldisc.write_wakeup)
-       {
-               (tty->ldisc.write_wakeup)(tty);
-       }
-       wake_up_interruptible(&tty->write_wait);
+       tty_wakeup(tty);
 }
 
 /*
@@ -1011,9 +1000,6 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
 
-       if (!tty)
-               return;
-
        /* ircomm_tty_flush_buffer(tty); */
        ircomm_tty_shutdown(self);
 
@@ -1021,10 +1007,10 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
        spin_lock_irqsave(&self->spinlock, flags);
        self->flags &= ~ASYNC_NORMAL_ACTIVE;
        self->tty = NULL;
-       self->open_count = 0;
+       self->port.count = 0;
        spin_unlock_irqrestore(&self->spinlock, flags);
 
-       wake_up_interruptible(&self->open_wait);
+       wake_up_interruptible(&self->port.open_wait);
 }
 
 /*
@@ -1097,7 +1083,7 @@ void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
                           (status & IRCOMM_CD) ? "on" : "off");
 
                if (status & IRCOMM_CD) {
-                       wake_up_interruptible(&self->open_wait);
+                       wake_up_interruptible(&self->port.open_wait);
                } else {
                        IRDA_DEBUG(2,
                                   "%s(), Doing serial hangup..\n", __func__ );
@@ -1116,7 +1102,7 @@ void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
                                tty->hw_stopped = 0;
 
                                /* Wake up processes blocked on open */
-                               wake_up_interruptible(&self->open_wait);
+                               wake_up_interruptible(&self->port.open_wait);
 
                                schedule_work(&self->tqueue);
                                return;
@@ -1169,11 +1155,11 @@ static int ircomm_tty_data_indication(void *instance, void *sap,
        }
 
        /*
-        * Just give it over to the line discipline. There is no need to
-        * involve the flip buffers, since we are not running in an interrupt
-        * handler
+        * Use flip buffer functions since the code may be called from interrupt
+        * context
         */
-       self->tty->ldisc.receive_buf(self->tty, skb->data, NULL, skb->len);
+       tty_insert_flip_string(self->tty, skb->data, skb->len);
+       tty_flip_buffer_push(self->tty);
 
        /* No need to kfree_skb - see ircomm_ttp_data_indication() */
 
@@ -1244,150 +1230,170 @@ static void ircomm_tty_flow_indication(void *instance, void *sap,
 }
 
 #ifdef CONFIG_PROC_FS
-static int ircomm_tty_line_info(struct ircomm_tty_cb *self, char *buf)
+static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
 {
-       int  ret=0;
+       char sep;
 
-       ret += sprintf(buf+ret, "State: %s\n", ircomm_tty_state[self->state]);
+       seq_printf(m, "State: %s\n", ircomm_tty_state[self->state]);
 
-       ret += sprintf(buf+ret, "Service type: ");
+       seq_puts(m, "Service type: ");
        if (self->service_type & IRCOMM_9_WIRE)
-               ret += sprintf(buf+ret, "9_WIRE");
+               seq_puts(m, "9_WIRE");
        else if (self->service_type & IRCOMM_3_WIRE)
-               ret += sprintf(buf+ret, "3_WIRE");
+               seq_puts(m, "3_WIRE");
        else if (self->service_type & IRCOMM_3_WIRE_RAW)
-               ret += sprintf(buf+ret, "3_WIRE_RAW");
+               seq_puts(m, "3_WIRE_RAW");
        else
-               ret += sprintf(buf+ret, "No common service type!\n");
-       ret += sprintf(buf+ret, "\n");
-
-       ret += sprintf(buf+ret, "Port name: %s\n", self->settings.port_name);
-
-       ret += sprintf(buf+ret, "DTE status: ");
-       if (self->settings.dte & IRCOMM_RTS)
-               ret += sprintf(buf+ret, "RTS|");
-       if (self->settings.dte & IRCOMM_DTR)
-               ret += sprintf(buf+ret, "DTR|");
-       if (self->settings.dte)
-               ret--; /* remove the last | */
-       ret += sprintf(buf+ret, "\n");
-
-       ret += sprintf(buf+ret, "DCE status: ");
-       if (self->settings.dce & IRCOMM_CTS)
-               ret += sprintf(buf+ret, "CTS|");
-       if (self->settings.dce & IRCOMM_DSR)
-               ret += sprintf(buf+ret, "DSR|");
-       if (self->settings.dce & IRCOMM_CD)
-               ret += sprintf(buf+ret, "CD|");
-       if (self->settings.dce & IRCOMM_RI)
-               ret += sprintf(buf+ret, "RI|");
-       if (self->settings.dce)
-               ret--; /* remove the last | */
-       ret += sprintf(buf+ret, "\n");
-
-       ret += sprintf(buf+ret, "Configuration: ");
+               seq_puts(m, "No common service type!\n");
+       seq_putc(m, '\n');
+
+       seq_printf(m, "Port name: %s\n", self->settings.port_name);
+
+       seq_printf(m, "DTE status:");
+       sep = ' ';
+       if (self->settings.dte & IRCOMM_RTS) {
+               seq_printf(m, "%cRTS", sep);
+               sep = '|';
+       }
+       if (self->settings.dte & IRCOMM_DTR) {
+               seq_printf(m, "%cDTR", sep);
+               sep = '|';
+       }
+       seq_putc(m, '\n');
+
+       seq_puts(m, "DCE status:");
+       sep = ' ';
+       if (self->settings.dce & IRCOMM_CTS) {
+               seq_printf(m, "%cCTS", sep);
+               sep = '|';
+       }
+       if (self->settings.dce & IRCOMM_DSR) {
+               seq_printf(m, "%cDSR", sep);
+               sep = '|';
+       }
+       if (self->settings.dce & IRCOMM_CD) {
+               seq_printf(m, "%cCD", sep);
+               sep = '|';
+       }
+       if (self->settings.dce & IRCOMM_RI) {
+               seq_printf(m, "%cRI", sep);
+               sep = '|';
+       }
+       seq_putc(m, '\n');
+
+       seq_puts(m, "Configuration: ");
        if (!self->settings.null_modem)
-               ret += sprintf(buf+ret, "DTE <-> DCE\n");
+               seq_puts(m, "DTE <-> DCE\n");
        else
-               ret += sprintf(buf+ret,
-                              "DTE <-> DTE (null modem emulation)\n");
-
-       ret += sprintf(buf+ret, "Data rate: %d\n", self->settings.data_rate);
-
-       ret += sprintf(buf+ret, "Flow control: ");
-       if (self->settings.flow_control & IRCOMM_XON_XOFF_IN)
-               ret += sprintf(buf+ret, "XON_XOFF_IN|");
-       if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT)
-               ret += sprintf(buf+ret, "XON_XOFF_OUT|");
-       if (self->settings.flow_control & IRCOMM_RTS_CTS_IN)
-               ret += sprintf(buf+ret, "RTS_CTS_IN|");
-       if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT)
-               ret += sprintf(buf+ret, "RTS_CTS_OUT|");
-       if (self->settings.flow_control & IRCOMM_DSR_DTR_IN)
-               ret += sprintf(buf+ret, "DSR_DTR_IN|");
-       if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT)
-               ret += sprintf(buf+ret, "DSR_DTR_OUT|");
-       if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN)
-               ret += sprintf(buf+ret, "ENQ_ACK_IN|");
-       if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT)
-               ret += sprintf(buf+ret, "ENQ_ACK_OUT|");
-       if (self->settings.flow_control)
-               ret--; /* remove the last | */
-       ret += sprintf(buf+ret, "\n");
-
-       ret += sprintf(buf+ret, "Flags: ");
-       if (self->flags & ASYNC_CTS_FLOW)
-               ret += sprintf(buf+ret, "ASYNC_CTS_FLOW|");
-       if (self->flags & ASYNC_CHECK_CD)
-               ret += sprintf(buf+ret, "ASYNC_CHECK_CD|");
-       if (self->flags & ASYNC_INITIALIZED)
-               ret += sprintf(buf+ret, "ASYNC_INITIALIZED|");
-       if (self->flags & ASYNC_LOW_LATENCY)
-               ret += sprintf(buf+ret, "ASYNC_LOW_LATENCY|");
-       if (self->flags & ASYNC_CLOSING)
-               ret += sprintf(buf+ret, "ASYNC_CLOSING|");
-       if (self->flags & ASYNC_NORMAL_ACTIVE)
-               ret += sprintf(buf+ret, "ASYNC_NORMAL_ACTIVE|");
-       if (self->flags)
-               ret--; /* remove the last | */
-       ret += sprintf(buf+ret, "\n");
-
-       ret += sprintf(buf+ret, "Role: %s\n", self->client ?
-                      "client" : "server");
-       ret += sprintf(buf+ret, "Open count: %d\n", self->open_count);
-       ret += sprintf(buf+ret, "Max data size: %d\n", self->max_data_size);
-       ret += sprintf(buf+ret, "Max header size: %d\n", self->max_header_size);
+               seq_puts(m, "DTE <-> DTE (null modem emulation)\n");
+
+       seq_printf(m, "Data rate: %d\n", self->settings.data_rate);
+
+       seq_puts(m, "Flow control:");
+       sep = ' ';
+       if (self->settings.flow_control & IRCOMM_XON_XOFF_IN) {
+               seq_printf(m, "%cXON_XOFF_IN", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT) {
+               seq_printf(m, "%cXON_XOFF_OUT", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_RTS_CTS_IN) {
+               seq_printf(m, "%cRTS_CTS_IN", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT) {
+               seq_printf(m, "%cRTS_CTS_OUT", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_DSR_DTR_IN) {
+               seq_printf(m, "%cDSR_DTR_IN", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT) {
+               seq_printf(m, "%cDSR_DTR_OUT", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN) {
+               seq_printf(m, "%cENQ_ACK_IN", sep);
+               sep = '|';
+       }
+       if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT) {
+               seq_printf(m, "%cENQ_ACK_OUT", sep);
+               sep = '|';
+       }
+       seq_putc(m, '\n');
+
+       seq_puts(m, "Flags:");
+       sep = ' ';
+       if (self->flags & ASYNC_CTS_FLOW) {
+               seq_printf(m, "%cASYNC_CTS_FLOW", sep);
+               sep = '|';
+       }
+       if (self->flags & ASYNC_CHECK_CD) {
+               seq_printf(m, "%cASYNC_CHECK_CD", sep);
+               sep = '|';
+       }
+       if (self->flags & ASYNC_INITIALIZED) {
+               seq_printf(m, "%cASYNC_INITIALIZED", sep);
+               sep = '|';
+       }
+       if (self->flags & ASYNC_LOW_LATENCY) {
+               seq_printf(m, "%cASYNC_LOW_LATENCY", sep);
+               sep = '|';
+       }
+       if (self->flags & ASYNC_CLOSING) {
+               seq_printf(m, "%cASYNC_CLOSING", sep);
+               sep = '|';
+       }
+       if (self->flags & ASYNC_NORMAL_ACTIVE) {
+               seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep);
+               sep = '|';
+       }
+       seq_putc(m, '\n');
+
+       seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
+       seq_printf(m, "Open count: %d\n", self->port.count);
+       seq_printf(m, "Max data size: %d\n", self->max_data_size);
+       seq_printf(m, "Max header size: %d\n", self->max_header_size);
 
        if (self->tty)
-               ret += sprintf(buf+ret, "Hardware: %s\n",
+               seq_printf(m, "Hardware: %s\n",
                               self->tty->hw_stopped ? "Stopped" : "Running");
-
-       ret += sprintf(buf+ret, "\n");
-       return ret;
 }
 
-
-/*
- * Function ircomm_tty_read_proc (buf, start, offset, len, eof, unused)
- *
- *
- *
- */
-static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
-                               int *eof, void *unused)
+static int ircomm_tty_proc_show(struct seq_file *m, void *v)
 {
        struct ircomm_tty_cb *self;
-       int count = 0, l;
-       off_t begin = 0;
        unsigned long flags;
 
        spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags);
 
        self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
-       while ((self != NULL) && (count < 4000)) {
+       while (self != NULL) {
                if (self->magic != IRCOMM_TTY_MAGIC)
                        break;
 
-               l = ircomm_tty_line_info(self, buf + count);
-               count += l;
-               if (count+begin > offset+len)
-                       goto done;
-               if (count+begin < offset) {
-                       begin += count;
-                       count = 0;
-               }
-
+               ircomm_tty_line_info(self, m);
                self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
        }
-       *eof = 1;
-done:
        spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags);
+       return 0;
+}
 
-       if (offset >= count+begin)
-               return 0;
-       *start = buf + (offset-begin);
-       return ((len < begin+count-offset) ? len : begin+count-offset);
+static int ircomm_tty_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ircomm_tty_proc_show, NULL);
 }
+
+static const struct file_operations ircomm_tty_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ircomm_tty_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif /* CONFIG_PROC_FS */
 
 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");