blob: 086d5ef098fd0b541359c8bd8448075406ef05cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Filename: ircomm_tty.c
4 * Version: 1.0
5 * Description: IrCOMM serial TTY driver
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sun Jun 6 21:00:56 1999
9 * Modified at: Wed Feb 23 00:09:02 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 * Sources: serial.c and previous IrCOMM work by Takahide Higuchi
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
14 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090015 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * the License, or (at your option) any later version.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090020 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090025 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * MA 02111-1307 USA
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 ********************************************************************/
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/module.h>
35#include <linux/fs.h>
36#include <linux/sched.h>
37#include <linux/termios.h>
38#include <linux/tty.h>
39#include <linux/interrupt.h>
40#include <linux/device.h> /* for MODULE_ALIAS_CHARDEV_MAJOR */
41
42#include <asm/uaccess.h>
43
44#include <net/irda/irda.h>
45#include <net/irda/irmod.h>
46
47#include <net/irda/ircomm_core.h>
48#include <net/irda/ircomm_param.h>
49#include <net/irda/ircomm_tty_attach.h>
50#include <net/irda/ircomm_tty.h>
51
52static int ircomm_tty_open(struct tty_struct *tty, struct file *filp);
53static void ircomm_tty_close(struct tty_struct * tty, struct file *filp);
54static int ircomm_tty_write(struct tty_struct * tty,
55 const unsigned char *buf, int count);
56static int ircomm_tty_write_room(struct tty_struct *tty);
57static void ircomm_tty_throttle(struct tty_struct *tty);
58static void ircomm_tty_unthrottle(struct tty_struct *tty);
59static int ircomm_tty_chars_in_buffer(struct tty_struct *tty);
60static void ircomm_tty_flush_buffer(struct tty_struct *tty);
61static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch);
62static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout);
63static void ircomm_tty_hangup(struct tty_struct *tty);
David Howellsc4028952006-11-22 14:57:56 +000064static void ircomm_tty_do_softint(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static void ircomm_tty_shutdown(struct ircomm_tty_cb *self);
66static void ircomm_tty_stop(struct tty_struct *tty);
67
68static int ircomm_tty_data_indication(void *instance, void *sap,
69 struct sk_buff *skb);
70static int ircomm_tty_control_indication(void *instance, void *sap,
71 struct sk_buff *skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090072static void ircomm_tty_flow_indication(void *instance, void *sap,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 LOCAL_FLOW cmd);
74#ifdef CONFIG_PROC_FS
75static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
76 int *eof, void *unused);
77#endif /* CONFIG_PROC_FS */
78static struct tty_driver *driver;
79
Adrian Bunkd76081f2007-10-26 03:56:43 -070080static hashbin_t *ircomm_tty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Jeff Dikeb68e31d2006-10-02 02:17:18 -070082static const struct tty_operations ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 .open = ircomm_tty_open,
84 .close = ircomm_tty_close,
85 .write = ircomm_tty_write,
86 .write_room = ircomm_tty_write_room,
87 .chars_in_buffer = ircomm_tty_chars_in_buffer,
88 .flush_buffer = ircomm_tty_flush_buffer,
89 .ioctl = ircomm_tty_ioctl, /* ircomm_tty_ioctl.c */
90 .tiocmget = ircomm_tty_tiocmget, /* ircomm_tty_ioctl.c */
91 .tiocmset = ircomm_tty_tiocmset, /* ircomm_tty_ioctl.c */
92 .throttle = ircomm_tty_throttle,
93 .unthrottle = ircomm_tty_unthrottle,
94 .send_xchar = ircomm_tty_send_xchar,
95 .set_termios = ircomm_tty_set_termios,
96 .stop = ircomm_tty_stop,
97 .start = ircomm_tty_start,
98 .hangup = ircomm_tty_hangup,
99 .wait_until_sent = ircomm_tty_wait_until_sent,
100#ifdef CONFIG_PROC_FS
101 .read_proc = ircomm_tty_read_proc,
102#endif /* CONFIG_PROC_FS */
103};
104
105/*
106 * Function ircomm_tty_init()
107 *
108 * Init IrCOMM TTY layer/driver
109 *
110 */
111static int __init ircomm_tty_init(void)
112{
113 driver = alloc_tty_driver(IRCOMM_TTY_PORTS);
114 if (!driver)
115 return -ENOMEM;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900116 ircomm_tty = hashbin_new(HB_LOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (ircomm_tty == NULL) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800118 IRDA_ERROR("%s(), can't allocate hashbin!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 put_tty_driver(driver);
120 return -ENOMEM;
121 }
122
123 driver->owner = THIS_MODULE;
124 driver->driver_name = "ircomm";
125 driver->name = "ircomm";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 driver->major = IRCOMM_TTY_MAJOR;
127 driver->minor_start = IRCOMM_TTY_MINOR;
128 driver->type = TTY_DRIVER_TYPE_SERIAL;
129 driver->subtype = SERIAL_TYPE_NORMAL;
130 driver->init_termios = tty_std_termios;
131 driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
132 driver->flags = TTY_DRIVER_REAL_RAW;
133 tty_set_operations(driver, &ops);
134 if (tty_register_driver(driver)) {
135 IRDA_ERROR("%s(): Couldn't register serial driver\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800136 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 put_tty_driver(driver);
138 return -1;
139 }
140 return 0;
141}
142
143static void __exit __ircomm_tty_cleanup(struct ircomm_tty_cb *self)
144{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800145 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 IRDA_ASSERT(self != NULL, return;);
148 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
149
150 ircomm_tty_shutdown(self);
151
152 self->magic = 0;
153 kfree(self);
154}
155
156/*
157 * Function ircomm_tty_cleanup ()
158 *
159 * Remove IrCOMM TTY layer/driver
160 *
161 */
162static void __exit ircomm_tty_cleanup(void)
163{
164 int ret;
165
Harvey Harrison0dc47872008-03-05 20:47:47 -0800166 IRDA_DEBUG(4, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 ret = tty_unregister_driver(driver);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900169 if (ret) {
170 IRDA_ERROR("%s(), failed to unregister driver\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800171 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return;
173 }
174
175 hashbin_delete(ircomm_tty, (FREE_FUNC) __ircomm_tty_cleanup);
176 put_tty_driver(driver);
177}
178
179/*
180 * Function ircomm_startup (self)
181 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900182 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 *
184 */
185static int ircomm_tty_startup(struct ircomm_tty_cb *self)
186{
187 notify_t notify;
188 int ret = -ENODEV;
189
Harvey Harrison0dc47872008-03-05 20:47:47 -0800190 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 IRDA_ASSERT(self != NULL, return -1;);
193 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
194
195 /* Check if already open */
196 if (test_and_set_bit(ASYNC_B_INITIALIZED, &self->flags)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800197 IRDA_DEBUG(2, "%s(), already open so break out!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return 0;
199 }
200
201 /* Register with IrCOMM */
202 irda_notify_init(&notify);
203 /* These callbacks we must handle ourselves */
204 notify.data_indication = ircomm_tty_data_indication;
205 notify.udata_indication = ircomm_tty_control_indication;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900206 notify.flow_indication = ircomm_tty_flow_indication;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /* Use the ircomm_tty interface for these ones */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900209 notify.disconnect_indication = ircomm_tty_disconnect_indication;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 notify.connect_confirm = ircomm_tty_connect_confirm;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900211 notify.connect_indication = ircomm_tty_connect_indication;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 strlcpy(notify.name, "ircomm_tty", sizeof(notify.name));
213 notify.instance = self;
214
215 if (!self->ircomm) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900216 self->ircomm = ircomm_open(&notify, self->service_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 self->line);
218 }
219 if (!self->ircomm)
220 goto err;
221
222 self->slsap_sel = self->ircomm->slsap_sel;
223
224 /* Connect IrCOMM link with remote device */
225 ret = ircomm_tty_attach_cable(self);
226 if (ret < 0) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800227 IRDA_ERROR("%s(), error attaching cable!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 goto err;
229 }
230
231 return 0;
232err:
233 clear_bit(ASYNC_B_INITIALIZED, &self->flags);
234 return ret;
235}
236
237/*
238 * Function ircomm_block_til_ready (self, filp)
239 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900240 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 *
242 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900243static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 struct file *filp)
245{
246 DECLARE_WAITQUEUE(wait, current);
247 int retval;
248 int do_clocal = 0, extra_count = 0;
249 unsigned long flags;
250 struct tty_struct *tty;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900251
Harvey Harrison0dc47872008-03-05 20:47:47 -0800252 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 tty = self->tty;
255
256 /*
257 * If non-blocking mode is set, or the port is not enabled,
258 * then make the check up front and then exit.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900259 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
261 /* nonblock mode is set or port is not enabled */
262 self->flags |= ASYNC_NORMAL_ACTIVE;
Harvey Harrison0dc47872008-03-05 20:47:47 -0800263 IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return 0;
265 }
266
267 if (tty->termios->c_cflag & CLOCAL) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800268 IRDA_DEBUG(1, "%s(), doing CLOCAL!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 do_clocal = 1;
270 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /* Wait for carrier detect and the line to become
273 * free (i.e., not in use by the callout). While we are in
274 * this loop, self->open_count is dropped by one, so that
275 * mgsl_close() knows when to free things. We restore it upon
276 * exit, either normal or abnormal.
277 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 retval = 0;
280 add_wait_queue(&self->open_wait, &wait);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
283 __FILE__,__LINE__, tty->driver->name, self->open_count );
284
285 /* As far as I can see, we protect open_count - Jean II */
286 spin_lock_irqsave(&self->spinlock, flags);
287 if (!tty_hung_up_p(filp)) {
288 extra_count = 1;
289 self->open_count--;
290 }
291 spin_unlock_irqrestore(&self->spinlock, flags);
292 self->blocked_open++;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 while (1) {
295 if (tty->termios->c_cflag & CBAUD) {
296 /* Here, we use to lock those two guys, but
297 * as ircomm_param_request() does it itself,
298 * I don't see the point (and I see the deadlock).
299 * Jean II */
300 self->settings.dte |= IRCOMM_RTS + IRCOMM_DTR;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 ircomm_param_request(self, IRCOMM_DTE, TRUE);
303 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 current->state = TASK_INTERRUPTIBLE;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (tty_hung_up_p(filp) ||
308 !test_bit(ASYNC_B_INITIALIZED, &self->flags)) {
309 retval = (self->flags & ASYNC_HUP_NOTIFY) ?
310 -EAGAIN : -ERESTARTSYS;
311 break;
312 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900313
314 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 * Check if link is ready now. Even if CLOCAL is
316 * specified, we cannot return before the IrCOMM link is
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900317 * ready
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900319 if (!test_bit(ASYNC_B_CLOSING, &self->flags) &&
320 (do_clocal || (self->settings.dce & IRCOMM_CD)) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 self->state == IRCOMM_TTY_READY)
322 {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900323 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if (signal_pending(current)) {
327 retval = -ERESTARTSYS;
328 break;
329 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
332 __FILE__,__LINE__, tty->driver->name, self->open_count );
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 schedule();
335 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 __set_current_state(TASK_RUNNING);
338 remove_wait_queue(&self->open_wait, &wait);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (extra_count) {
341 /* ++ is not atomic, so this should be protected - Jean II */
342 spin_lock_irqsave(&self->spinlock, flags);
343 self->open_count++;
344 spin_unlock_irqrestore(&self->spinlock, flags);
345 }
346 self->blocked_open--;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
349 __FILE__,__LINE__, tty->driver->name, self->open_count);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (!retval)
352 self->flags |= ASYNC_NORMAL_ACTIVE;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900353
354 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
357/*
358 * Function ircomm_tty_open (tty, filp)
359 *
360 * This routine is called when a particular tty device is opened. This
361 * routine is mandatory; if this routine is not filled in, the attempted
362 * open will fail with ENODEV.
363 */
364static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
365{
366 struct ircomm_tty_cb *self;
367 unsigned int line;
368 unsigned long flags;
369 int ret;
370
Harvey Harrison0dc47872008-03-05 20:47:47 -0800371 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 line = tty->index;
Alan Coxad36b882009-01-02 13:50:20 +0000374 if (line >= IRCOMM_TTY_PORTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 /* Check if instance already exists */
378 self = hashbin_lock_find(ircomm_tty, line, NULL);
379 if (!self) {
380 /* No, so make new instance */
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700381 self = kzalloc(sizeof(struct ircomm_tty_cb), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (self == NULL) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800383 IRDA_ERROR("%s(), kmalloc failed!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return -ENOMEM;
385 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 self->magic = IRCOMM_TTY_MAGIC;
388 self->flow = FLOW_STOP;
389
390 self->line = line;
David Howellsc4028952006-11-22 14:57:56 +0000391 INIT_WORK(&self->tqueue, ircomm_tty_do_softint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED;
393 self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
394 self->close_delay = 5*HZ/10;
395 self->closing_wait = 30*HZ;
396
397 /* Init some important stuff */
398 init_timer(&self->watchdog_timer);
399 init_waitqueue_head(&self->open_wait);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900400 init_waitqueue_head(&self->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 spin_lock_init(&self->spinlock);
402
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900403 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 * Force TTY into raw mode by default which is usually what
405 * we want for IrCOMM and IrLPT. This way applications will
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900406 * not have to twiddle with printcap etc.
Alan Coxad36b882009-01-02 13:50:20 +0000407 *
408 * Note this is completely usafe and doesn't work properly
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 */
410 tty->termios->c_iflag = 0;
411 tty->termios->c_oflag = 0;
412
413 /* Insert into hash */
414 hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL);
415 }
416 /* ++ is not atomic, so this should be protected - Jean II */
417 spin_lock_irqsave(&self->spinlock, flags);
418 self->open_count++;
419
420 tty->driver_data = self;
421 self->tty = tty;
422 spin_unlock_irqrestore(&self->spinlock, flags);
423
Harvey Harrison0dc47872008-03-05 20:47:47 -0800424 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 self->line, self->open_count);
426
427 /* Not really used by us, but lets do it anyway */
428 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
429
430 /*
431 * If the port is the middle of closing, bail out now
432 */
433 if (tty_hung_up_p(filp) ||
434 test_bit(ASYNC_B_CLOSING, &self->flags)) {
435
436 /* Hm, why are we blocking on ASYNC_CLOSING if we
437 * do return -EAGAIN/-ERESTARTSYS below anyway?
438 * IMHO it's either not needed in the first place
439 * or for some reason we need to make sure the async
440 * closing has been finished - if so, wouldn't we
441 * probably better sleep uninterruptible?
442 */
443
444 if (wait_event_interruptible(self->close_wait, !test_bit(ASYNC_B_CLOSING, &self->flags))) {
445 IRDA_WARNING("%s - got signal while blocking on ASYNC_CLOSING!\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800446 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 return -ERESTARTSYS;
448 }
449
450#ifdef SERIAL_DO_RESTART
451 return ((self->flags & ASYNC_HUP_NOTIFY) ?
452 -EAGAIN : -ERESTARTSYS);
453#else
454 return -EAGAIN;
455#endif
456 }
457
458 /* Check if this is a "normal" ircomm device, or an irlpt device */
459 if (line < 0x10) {
460 self->service_type = IRCOMM_3_WIRE | IRCOMM_9_WIRE;
461 self->settings.service_type = IRCOMM_9_WIRE; /* 9 wire as default */
462 /* Jan Kiszka -> add DSR/RI -> Conform to IrCOMM spec */
463 self->settings.dce = IRCOMM_CTS | IRCOMM_CD | IRCOMM_DSR | IRCOMM_RI; /* Default line settings */
Harvey Harrison0dc47872008-03-05 20:47:47 -0800464 IRDA_DEBUG(2, "%s(), IrCOMM device\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 } else {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800466 IRDA_DEBUG(2, "%s(), IrLPT device\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 self->service_type = IRCOMM_3_WIRE_RAW;
468 self->settings.service_type = IRCOMM_3_WIRE_RAW; /* Default */
469 }
470
471 ret = ircomm_tty_startup(self);
472 if (ret)
473 return ret;
474
475 ret = ircomm_tty_block_til_ready(self, filp);
476 if (ret) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900477 IRDA_DEBUG(2,
Harvey Harrison0dc47872008-03-05 20:47:47 -0800478 "%s(), returning after block_til_ready with %d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 ret);
480
481 return ret;
482 }
483 return 0;
484}
485
486/*
487 * Function ircomm_tty_close (tty, filp)
488 *
489 * This routine is called when a particular tty device is closed.
490 *
491 */
492static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
493{
494 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
495 unsigned long flags;
496
Harvey Harrison0dc47872008-03-05 20:47:47 -0800497 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 if (!tty)
500 return;
501
502 IRDA_ASSERT(self != NULL, return;);
503 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
504
505 spin_lock_irqsave(&self->spinlock, flags);
506
507 if (tty_hung_up_p(filp)) {
508 spin_unlock_irqrestore(&self->spinlock, flags);
509
Harvey Harrison0dc47872008-03-05 20:47:47 -0800510 IRDA_DEBUG(0, "%s(), returning 1\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 return;
512 }
513
514 if ((tty->count == 1) && (self->open_count != 1)) {
515 /*
516 * Uh, oh. tty->count is 1, which means that the tty
517 * structure will be freed. state->count should always
518 * be one in these conditions. If it's greater than
519 * one, we've got real problems, since it means the
520 * serial port won't be shutdown.
521 */
522 IRDA_DEBUG(0, "%s(), bad serial port count; "
Harvey Harrison0dc47872008-03-05 20:47:47 -0800523 "tty->count is 1, state->count is %d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 self->open_count);
525 self->open_count = 1;
526 }
527
528 if (--self->open_count < 0) {
529 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800530 __func__, self->line, self->open_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 self->open_count = 0;
532 }
533 if (self->open_count) {
534 spin_unlock_irqrestore(&self->spinlock, flags);
535
Harvey Harrison0dc47872008-03-05 20:47:47 -0800536 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return;
538 }
539
540 /* Hum... Should be test_and_set_bit ??? - Jean II */
541 set_bit(ASYNC_B_CLOSING, &self->flags);
542
543 /* We need to unlock here (we were unlocking at the end of this
544 * function), because tty_wait_until_sent() may schedule.
545 * I don't know if the rest should be protected somehow,
546 * so someone should check. - Jean II */
547 spin_unlock_irqrestore(&self->spinlock, flags);
548
549 /*
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900550 * Now we wait for the transmit buffer to clear; and we notify
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 * the line discipline to only process XON/XOFF characters.
552 */
553 tty->closing = 1;
554 if (self->closing_wait != ASYNC_CLOSING_WAIT_NONE)
555 tty_wait_until_sent(tty, self->closing_wait);
556
557 ircomm_tty_shutdown(self);
558
Alan Coxf34d7a52008-04-30 00:54:13 -0700559 tty_driver_flush_buffer(tty);
560 tty_ldisc_flush(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 tty->closing = 0;
563 self->tty = NULL;
564
565 if (self->blocked_open) {
Nishanth Aravamudan121caf52005-09-12 14:15:34 -0700566 if (self->close_delay)
567 schedule_timeout_interruptible(self->close_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 wake_up_interruptible(&self->open_wait);
569 }
570
571 self->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
572 wake_up_interruptible(&self->close_wait);
573}
574
575/*
576 * Function ircomm_tty_flush_buffer (tty)
577 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900578 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 *
580 */
581static void ircomm_tty_flush_buffer(struct tty_struct *tty)
582{
583 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
584
585 IRDA_ASSERT(self != NULL, return;);
586 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
587
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900588 /*
589 * Let do_softint() do this to avoid race condition with
590 * do_softint() ;-)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 */
592 schedule_work(&self->tqueue);
593}
594
595/*
David Howellsc4028952006-11-22 14:57:56 +0000596 * Function ircomm_tty_do_softint (work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 *
598 * We use this routine to give the write wakeup to the user at at a
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900599 * safe time (as fast as possible after write have completed). This
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 * can be compared to the Tx interrupt.
601 */
David Howellsc4028952006-11-22 14:57:56 +0000602static void ircomm_tty_do_softint(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
David Howellsc4028952006-11-22 14:57:56 +0000604 struct ircomm_tty_cb *self =
605 container_of(work, struct ircomm_tty_cb, tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 struct tty_struct *tty;
607 unsigned long flags;
608 struct sk_buff *skb, *ctrl_skb;
609
Harvey Harrison0dc47872008-03-05 20:47:47 -0800610 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 if (!self || self->magic != IRCOMM_TTY_MAGIC)
613 return;
614
615 tty = self->tty;
616 if (!tty)
617 return;
618
619 /* Unlink control buffer */
620 spin_lock_irqsave(&self->spinlock, flags);
621
622 ctrl_skb = self->ctrl_skb;
623 self->ctrl_skb = NULL;
624
625 spin_unlock_irqrestore(&self->spinlock, flags);
626
627 /* Flush control buffer if any */
628 if(ctrl_skb) {
629 if(self->flow == FLOW_START)
630 ircomm_control_request(self->ircomm, ctrl_skb);
631 /* Drop reference count - see ircomm_ttp_data_request(). */
632 dev_kfree_skb(ctrl_skb);
633 }
634
635 if (tty->hw_stopped)
636 return;
637
638 /* Unlink transmit buffer */
639 spin_lock_irqsave(&self->spinlock, flags);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 skb = self->tx_skb;
642 self->tx_skb = NULL;
643
644 spin_unlock_irqrestore(&self->spinlock, flags);
645
646 /* Flush transmit buffer if any */
647 if (skb) {
648 ircomm_tty_do_event(self, IRCOMM_TTY_DATA_REQUEST, skb, NULL);
649 /* Drop reference count - see ircomm_ttp_data_request(). */
650 dev_kfree_skb(skb);
651 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* Check if user (still) wants to be waken up */
Alan Coxa352def2008-07-16 21:53:12 +0100654 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657/*
658 * Function ircomm_tty_write (tty, buf, count)
659 *
660 * This routine is called by the kernel to write a series of characters
661 * to the tty device. The characters may come from user space or kernel
662 * space. This routine will return the number of characters actually
663 * accepted for writing. This routine is mandatory.
664 */
665static int ircomm_tty_write(struct tty_struct *tty,
666 const unsigned char *buf, int count)
667{
668 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
669 unsigned long flags;
670 struct sk_buff *skb;
671 int tailroom = 0;
672 int len = 0;
673 int size;
674
Harvey Harrison0dc47872008-03-05 20:47:47 -0800675 IRDA_DEBUG(2, "%s(), count=%d, hw_stopped=%d\n", __func__ , count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 tty->hw_stopped);
677
678 IRDA_ASSERT(self != NULL, return -1;);
679 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
680
681 /* We may receive packets from the TTY even before we have finished
682 * our setup. Not cool.
683 * The problem is that we don't know the final header and data size
684 * to create the proper skb, so any skb we would create would have
685 * bogus header and data size, so need care.
686 * We use a bogus header size to safely detect this condition.
687 * Another problem is that hw_stopped was set to 0 way before it
688 * should be, so we would drop this skb. It should now be fixed.
689 * One option is to not accept data until we are properly setup.
690 * But, I suspect that when it happens, the ppp line discipline
691 * just "drops" the data, which might screw up connect scripts.
692 * The second option is to create a "safe skb", with large header
693 * and small size (see ircomm_tty_open() for values).
694 * We just need to make sure that when the real values get filled,
695 * we don't mess up the original "safe skb" (see tx_data_size).
696 * Jean II */
697 if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800698 IRDA_DEBUG(1, "%s() : not initialised\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#ifdef IRCOMM_NO_TX_BEFORE_INIT
700 /* We didn't consume anything, TTY will retry */
701 return 0;
702#endif
703 }
704
705 if (count < 1)
706 return 0;
707
708 /* Protect our manipulation of self->tx_skb and related */
709 spin_lock_irqsave(&self->spinlock, flags);
710
711 /* Fetch current transmit buffer */
712 skb = self->tx_skb;
713
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900714 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 * Send out all the data we get, possibly as multiple fragmented
716 * frames, but this will only happen if the data is larger than the
717 * max data size. The normal case however is just the opposite, and
718 * this function may be called multiple times, and will then actually
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900719 * defragment the data and send it out as one packet as soon as
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 * possible, but at a safer point in time
721 */
722 while (count) {
723 size = count;
724
725 /* Adjust data size to the max data size */
726 if (size > self->max_data_size)
727 size = self->max_data_size;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900728
729 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 * Do we already have a buffer ready for transmit, or do
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900731 * we need to allocate a new frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900733 if (skb) {
734 /*
735 * Any room for more data at the end of the current
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 * transmit buffer? Cannot use skb_tailroom, since
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900737 * dev_alloc_skb gives us a larger skb than we
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 * requested
739 * Note : use tx_data_size, because max_data_size
740 * may have changed and we don't want to overwrite
741 * the skb. - Jean II
742 */
743 if ((tailroom = (self->tx_data_size - skb->len)) > 0) {
744 /* Adjust data to tailroom */
745 if (size > tailroom)
746 size = tailroom;
747 } else {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900748 /*
749 * Current transmit frame is full, so break
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 * out, so we can send it as soon as possible
751 */
752 break;
753 }
754 } else {
755 /* Prepare a full sized frame */
Samuel Ortiz485fb2c2006-07-21 14:50:41 -0700756 skb = alloc_skb(self->max_data_size+
757 self->max_header_size,
758 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 if (!skb) {
760 spin_unlock_irqrestore(&self->spinlock, flags);
761 return -ENOBUFS;
762 }
763 skb_reserve(skb, self->max_header_size);
764 self->tx_skb = skb;
765 /* Remember skb size because max_data_size may
766 * change later on - Jean II */
767 self->tx_data_size = self->max_data_size;
768 }
769
770 /* Copy data */
771 memcpy(skb_put(skb,size), buf + len, size);
772
773 count -= size;
774 len += size;
775 }
776
777 spin_unlock_irqrestore(&self->spinlock, flags);
778
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900779 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 * Schedule a new thread which will transmit the frame as soon
781 * as possible, but at a safe point in time. We do this so the
782 * "user" can give us data multiple times, as PPP does (because of
783 * its 256 byte tx buffer). We will then defragment and send out
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900784 * all this data as one single packet.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 */
786 schedule_work(&self->tqueue);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 return len;
789}
790
791/*
792 * Function ircomm_tty_write_room (tty)
793 *
794 * This routine returns the numbers of characters the tty driver will
795 * accept for queuing to be written. This number is subject to change as
796 * output buffers get emptied, or if the output flow control is acted.
797 */
798static int ircomm_tty_write_room(struct tty_struct *tty)
799{
800 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
801 unsigned long flags;
802 int ret;
803
804 IRDA_ASSERT(self != NULL, return -1;);
805 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
806
807#ifdef IRCOMM_NO_TX_BEFORE_INIT
808 /* max_header_size tells us if the channel is initialised or not. */
809 if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED)
810 /* Don't bother us yet */
811 return 0;
812#endif
813
814 /* Check if we are allowed to transmit any data.
815 * hw_stopped is the regular flow control.
816 * Jean II */
817 if (tty->hw_stopped)
818 ret = 0;
819 else {
820 spin_lock_irqsave(&self->spinlock, flags);
821 if (self->tx_skb)
822 ret = self->tx_data_size - self->tx_skb->len;
823 else
824 ret = self->max_data_size;
825 spin_unlock_irqrestore(&self->spinlock, flags);
826 }
Harvey Harrison0dc47872008-03-05 20:47:47 -0800827 IRDA_DEBUG(2, "%s(), ret=%d\n", __func__ , ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 return ret;
830}
831
832/*
833 * Function ircomm_tty_wait_until_sent (tty, timeout)
834 *
835 * This routine waits until the device has written out all of the
836 * characters in its transmitter FIFO.
837 */
838static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout)
839{
840 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
841 unsigned long orig_jiffies, poll_time;
842 unsigned long flags;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900843
Harvey Harrison0dc47872008-03-05 20:47:47 -0800844 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846 IRDA_ASSERT(self != NULL, return;);
847 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
848
849 orig_jiffies = jiffies;
850
851 /* Set poll time to 200 ms */
852 poll_time = IRDA_MIN(timeout, msecs_to_jiffies(200));
853
854 spin_lock_irqsave(&self->spinlock, flags);
855 while (self->tx_skb && self->tx_skb->len) {
856 spin_unlock_irqrestore(&self->spinlock, flags);
Nishanth Aravamudan121caf52005-09-12 14:15:34 -0700857 schedule_timeout_interruptible(poll_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 spin_lock_irqsave(&self->spinlock, flags);
859 if (signal_pending(current))
860 break;
861 if (timeout && time_after(jiffies, orig_jiffies + timeout))
862 break;
863 }
864 spin_unlock_irqrestore(&self->spinlock, flags);
865 current->state = TASK_RUNNING;
866}
867
868/*
869 * Function ircomm_tty_throttle (tty)
870 *
871 * This routine notifies the tty driver that input buffers for the line
872 * discipline are close to full, and it should somehow signal that no
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900873 * more characters should be sent to the tty.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 */
875static void ircomm_tty_throttle(struct tty_struct *tty)
876{
877 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
878
Harvey Harrison0dc47872008-03-05 20:47:47 -0800879 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 IRDA_ASSERT(self != NULL, return;);
882 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
883
884 /* Software flow control? */
885 if (I_IXOFF(tty))
886 ircomm_tty_send_xchar(tty, STOP_CHAR(tty));
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 /* Hardware flow control? */
889 if (tty->termios->c_cflag & CRTSCTS) {
890 self->settings.dte &= ~IRCOMM_RTS;
891 self->settings.dte |= IRCOMM_DELTA_RTS;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 ircomm_param_request(self, IRCOMM_DTE, TRUE);
894 }
895
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900896 ircomm_flow_request(self->ircomm, FLOW_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897}
898
899/*
900 * Function ircomm_tty_unthrottle (tty)
901 *
902 * This routine notifies the tty drivers that it should signals that
903 * characters can now be sent to the tty without fear of overrunning the
904 * input buffers of the line disciplines.
905 */
906static void ircomm_tty_unthrottle(struct tty_struct *tty)
907{
908 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
909
Harvey Harrison0dc47872008-03-05 20:47:47 -0800910 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 IRDA_ASSERT(self != NULL, return;);
913 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
914
915 /* Using software flow control? */
916 if (I_IXOFF(tty)) {
917 ircomm_tty_send_xchar(tty, START_CHAR(tty));
918 }
919
920 /* Using hardware flow control? */
921 if (tty->termios->c_cflag & CRTSCTS) {
922 self->settings.dte |= (IRCOMM_RTS|IRCOMM_DELTA_RTS);
923
924 ircomm_param_request(self, IRCOMM_DTE, TRUE);
Harvey Harrison0dc47872008-03-05 20:47:47 -0800925 IRDA_DEBUG(1, "%s(), FLOW_START\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900927 ircomm_flow_request(self->ircomm, FLOW_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928}
929
930/*
931 * Function ircomm_tty_chars_in_buffer (tty)
932 *
933 * Indicates if there are any data in the buffer
934 *
935 */
936static int ircomm_tty_chars_in_buffer(struct tty_struct *tty)
937{
938 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
939 unsigned long flags;
940 int len = 0;
941
942 IRDA_ASSERT(self != NULL, return -1;);
943 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
944
945 spin_lock_irqsave(&self->spinlock, flags);
946
947 if (self->tx_skb)
948 len = self->tx_skb->len;
949
950 spin_unlock_irqrestore(&self->spinlock, flags);
951
952 return len;
953}
954
955static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
956{
957 unsigned long flags;
958
959 IRDA_ASSERT(self != NULL, return;);
960 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
961
Harvey Harrison0dc47872008-03-05 20:47:47 -0800962 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 if (!test_and_clear_bit(ASYNC_B_INITIALIZED, &self->flags))
965 return;
966
967 ircomm_tty_detach_cable(self);
968
969 spin_lock_irqsave(&self->spinlock, flags);
970
971 del_timer(&self->watchdog_timer);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 /* Free parameter buffer */
974 if (self->ctrl_skb) {
975 dev_kfree_skb(self->ctrl_skb);
976 self->ctrl_skb = NULL;
977 }
978
979 /* Free transmit buffer */
980 if (self->tx_skb) {
981 dev_kfree_skb(self->tx_skb);
982 self->tx_skb = NULL;
983 }
984
985 if (self->ircomm) {
986 ircomm_close(self->ircomm);
987 self->ircomm = NULL;
988 }
989
990 spin_unlock_irqrestore(&self->spinlock, flags);
991}
992
993/*
994 * Function ircomm_tty_hangup (tty)
995 *
996 * This routine notifies the tty driver that it should hangup the tty
997 * device.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900998 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 */
1000static void ircomm_tty_hangup(struct tty_struct *tty)
1001{
1002 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
1003 unsigned long flags;
1004
Harvey Harrison0dc47872008-03-05 20:47:47 -08001005 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 IRDA_ASSERT(self != NULL, return;);
1008 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1009
1010 if (!tty)
1011 return;
1012
1013 /* ircomm_tty_flush_buffer(tty); */
1014 ircomm_tty_shutdown(self);
1015
1016 /* I guess we need to lock here - Jean II */
1017 spin_lock_irqsave(&self->spinlock, flags);
1018 self->flags &= ~ASYNC_NORMAL_ACTIVE;
1019 self->tty = NULL;
1020 self->open_count = 0;
1021 spin_unlock_irqrestore(&self->spinlock, flags);
1022
1023 wake_up_interruptible(&self->open_wait);
1024}
1025
1026/*
1027 * Function ircomm_tty_send_xchar (tty, ch)
1028 *
1029 * This routine is used to send a high-priority XON/XOFF character to
1030 * the device.
1031 */
1032static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch)
1033{
Harvey Harrison0dc47872008-03-05 20:47:47 -08001034 IRDA_DEBUG(0, "%s(), not impl\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035}
1036
1037/*
1038 * Function ircomm_tty_start (tty)
1039 *
1040 * This routine notifies the tty driver that it resume sending
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001041 * characters to the tty device.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 */
1043void ircomm_tty_start(struct tty_struct *tty)
1044{
1045 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
1046
1047 ircomm_flow_request(self->ircomm, FLOW_START);
1048}
1049
1050/*
1051 * Function ircomm_tty_stop (tty)
1052 *
1053 * This routine notifies the tty driver that it should stop outputting
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001054 * characters to the tty device.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001056static void ircomm_tty_stop(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
1058 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
1059
1060 IRDA_ASSERT(self != NULL, return;);
1061 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1062
1063 ircomm_flow_request(self->ircomm, FLOW_STOP);
1064}
1065
1066/*
1067 * Function ircomm_check_modem_status (self)
1068 *
1069 * Check for any changes in the DCE's line settings. This function should
1070 * be called whenever the dce parameter settings changes, to update the
1071 * flow control settings and other things
1072 */
1073void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
1074{
1075 struct tty_struct *tty;
1076 int status;
1077
Harvey Harrison0dc47872008-03-05 20:47:47 -08001078 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 IRDA_ASSERT(self != NULL, return;);
1081 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1082
1083 tty = self->tty;
1084
1085 status = self->settings.dce;
1086
1087 if (status & IRCOMM_DCE_DELTA_ANY) {
1088 /*wake_up_interruptible(&self->delta_msr_wait);*/
1089 }
1090 if ((self->flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001091 IRDA_DEBUG(2,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001092 "%s(), ircomm%d CD now %s...\n", __func__ , self->line,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 (status & IRCOMM_CD) ? "on" : "off");
1094
1095 if (status & IRCOMM_CD) {
1096 wake_up_interruptible(&self->open_wait);
1097 } else {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001098 IRDA_DEBUG(2,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001099 "%s(), Doing serial hangup..\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (tty)
1101 tty_hangup(tty);
1102
1103 /* Hangup will remote the tty, so better break out */
1104 return;
1105 }
1106 }
1107 if (self->flags & ASYNC_CTS_FLOW) {
1108 if (tty->hw_stopped) {
1109 if (status & IRCOMM_CTS) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001110 IRDA_DEBUG(2,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001111 "%s(), CTS tx start...\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 tty->hw_stopped = 0;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 /* Wake up processes blocked on open */
1115 wake_up_interruptible(&self->open_wait);
1116
1117 schedule_work(&self->tqueue);
1118 return;
1119 }
1120 } else {
1121 if (!(status & IRCOMM_CTS)) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001122 IRDA_DEBUG(2,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001123 "%s(), CTS tx stop...\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 tty->hw_stopped = 1;
1125 }
1126 }
1127 }
1128}
1129
1130/*
1131 * Function ircomm_tty_data_indication (instance, sap, skb)
1132 *
1133 * Handle incoming data, and deliver it to the line discipline
1134 *
1135 */
1136static int ircomm_tty_data_indication(void *instance, void *sap,
1137 struct sk_buff *skb)
1138{
1139 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
Alan Coxa352def2008-07-16 21:53:12 +01001140 struct tty_ldisc *ld;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Harvey Harrison0dc47872008-03-05 20:47:47 -08001142 IRDA_DEBUG(2, "%s()\n", __func__ );
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 IRDA_ASSERT(self != NULL, return -1;);
1145 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
1146 IRDA_ASSERT(skb != NULL, return -1;);
1147
1148 if (!self->tty) {
Harvey Harrison0dc47872008-03-05 20:47:47 -08001149 IRDA_DEBUG(0, "%s(), no tty!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 return 0;
1151 }
1152
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001153 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 * If we receive data when hardware is stopped then something is wrong.
1155 * We try to poll the peers line settings to check if we are up todate.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001156 * Devices like WinCE can do this, and since they don't send any
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 * params, we can just as well declare the hardware for running.
1158 */
1159 if (self->tty->hw_stopped && (self->flow == FLOW_START)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -08001160 IRDA_DEBUG(0, "%s(), polling for line settings!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 ircomm_param_request(self, IRCOMM_POLL, TRUE);
1162
1163 /* We can just as well declare the hardware for running */
1164 ircomm_tty_send_initial_parameters(self);
1165 ircomm_tty_link_established(self);
1166 }
1167
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001168 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 * Just give it over to the line discipline. There is no need to
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001170 * involve the flip buffers, since we are not running in an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 * handler
1172 */
Alan Coxa352def2008-07-16 21:53:12 +01001173
1174 ld = tty_ldisc_ref(self->tty);
1175 if (ld)
1176 ld->ops->receive_buf(self->tty, skb->data, NULL, skb->len);
1177 tty_ldisc_deref(ld);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
1179 /* No need to kfree_skb - see ircomm_ttp_data_indication() */
1180
1181 return 0;
1182}
1183
1184/*
1185 * Function ircomm_tty_control_indication (instance, sap, skb)
1186 *
1187 * Parse all incoming parameters (easy!)
1188 *
1189 */
1190static int ircomm_tty_control_indication(void *instance, void *sap,
1191 struct sk_buff *skb)
1192{
1193 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
1194 int clen;
1195
Harvey Harrison0dc47872008-03-05 20:47:47 -08001196 IRDA_DEBUG(4, "%s()\n", __func__ );
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 IRDA_ASSERT(self != NULL, return -1;);
1199 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
1200 IRDA_ASSERT(skb != NULL, return -1;);
1201
1202 clen = skb->data[0];
1203
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001204 irda_param_extract_all(self, skb->data+1, IRDA_MIN(skb->len-1, clen),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 &ircomm_param_info);
1206
1207 /* No need to kfree_skb - see ircomm_control_indication() */
1208
1209 return 0;
1210}
1211
1212/*
1213 * Function ircomm_tty_flow_indication (instance, sap, cmd)
1214 *
1215 * This function is called by IrTTP when it wants us to slow down the
1216 * transmission of data. We just mark the hardware as stopped, and wait
1217 * for IrTTP to notify us that things are OK again.
1218 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001219static void ircomm_tty_flow_indication(void *instance, void *sap,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 LOCAL_FLOW cmd)
1221{
1222 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
1223 struct tty_struct *tty;
1224
1225 IRDA_ASSERT(self != NULL, return;);
1226 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1227
1228 tty = self->tty;
1229
1230 switch (cmd) {
1231 case FLOW_START:
Harvey Harrison0dc47872008-03-05 20:47:47 -08001232 IRDA_DEBUG(2, "%s(), hw start!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 tty->hw_stopped = 0;
1234
1235 /* ircomm_tty_do_softint will take care of the rest */
1236 schedule_work(&self->tqueue);
1237 break;
1238 default: /* If we get here, something is very wrong, better stop */
1239 case FLOW_STOP:
Harvey Harrison0dc47872008-03-05 20:47:47 -08001240 IRDA_DEBUG(2, "%s(), hw stopped!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 tty->hw_stopped = 1;
1242 break;
1243 }
1244 self->flow = cmd;
1245}
1246
Pavel Emelyanov92b05e132007-12-05 02:18:48 -08001247#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248static int ircomm_tty_line_info(struct ircomm_tty_cb *self, char *buf)
1249{
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001250 int ret=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
1252 ret += sprintf(buf+ret, "State: %s\n", ircomm_tty_state[self->state]);
1253
1254 ret += sprintf(buf+ret, "Service type: ");
1255 if (self->service_type & IRCOMM_9_WIRE)
1256 ret += sprintf(buf+ret, "9_WIRE");
1257 else if (self->service_type & IRCOMM_3_WIRE)
1258 ret += sprintf(buf+ret, "3_WIRE");
1259 else if (self->service_type & IRCOMM_3_WIRE_RAW)
1260 ret += sprintf(buf+ret, "3_WIRE_RAW");
1261 else
1262 ret += sprintf(buf+ret, "No common service type!\n");
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001263 ret += sprintf(buf+ret, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 ret += sprintf(buf+ret, "Port name: %s\n", self->settings.port_name);
1266
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001267 ret += sprintf(buf+ret, "DTE status: ");
1268 if (self->settings.dte & IRCOMM_RTS)
1269 ret += sprintf(buf+ret, "RTS|");
1270 if (self->settings.dte & IRCOMM_DTR)
1271 ret += sprintf(buf+ret, "DTR|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if (self->settings.dte)
1273 ret--; /* remove the last | */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001274 ret += sprintf(buf+ret, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 ret += sprintf(buf+ret, "DCE status: ");
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001277 if (self->settings.dce & IRCOMM_CTS)
1278 ret += sprintf(buf+ret, "CTS|");
1279 if (self->settings.dce & IRCOMM_DSR)
1280 ret += sprintf(buf+ret, "DSR|");
1281 if (self->settings.dce & IRCOMM_CD)
1282 ret += sprintf(buf+ret, "CD|");
1283 if (self->settings.dce & IRCOMM_RI)
1284 ret += sprintf(buf+ret, "RI|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 if (self->settings.dce)
1286 ret--; /* remove the last | */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001287 ret += sprintf(buf+ret, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 ret += sprintf(buf+ret, "Configuration: ");
1290 if (!self->settings.null_modem)
1291 ret += sprintf(buf+ret, "DTE <-> DCE\n");
1292 else
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001293 ret += sprintf(buf+ret,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 "DTE <-> DTE (null modem emulation)\n");
1295
1296 ret += sprintf(buf+ret, "Data rate: %d\n", self->settings.data_rate);
1297
1298 ret += sprintf(buf+ret, "Flow control: ");
1299 if (self->settings.flow_control & IRCOMM_XON_XOFF_IN)
1300 ret += sprintf(buf+ret, "XON_XOFF_IN|");
1301 if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT)
1302 ret += sprintf(buf+ret, "XON_XOFF_OUT|");
1303 if (self->settings.flow_control & IRCOMM_RTS_CTS_IN)
1304 ret += sprintf(buf+ret, "RTS_CTS_IN|");
1305 if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT)
1306 ret += sprintf(buf+ret, "RTS_CTS_OUT|");
1307 if (self->settings.flow_control & IRCOMM_DSR_DTR_IN)
1308 ret += sprintf(buf+ret, "DSR_DTR_IN|");
1309 if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT)
1310 ret += sprintf(buf+ret, "DSR_DTR_OUT|");
1311 if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN)
1312 ret += sprintf(buf+ret, "ENQ_ACK_IN|");
1313 if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT)
1314 ret += sprintf(buf+ret, "ENQ_ACK_OUT|");
1315 if (self->settings.flow_control)
1316 ret--; /* remove the last | */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001317 ret += sprintf(buf+ret, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 ret += sprintf(buf+ret, "Flags: ");
1320 if (self->flags & ASYNC_CTS_FLOW)
1321 ret += sprintf(buf+ret, "ASYNC_CTS_FLOW|");
1322 if (self->flags & ASYNC_CHECK_CD)
1323 ret += sprintf(buf+ret, "ASYNC_CHECK_CD|");
1324 if (self->flags & ASYNC_INITIALIZED)
1325 ret += sprintf(buf+ret, "ASYNC_INITIALIZED|");
1326 if (self->flags & ASYNC_LOW_LATENCY)
1327 ret += sprintf(buf+ret, "ASYNC_LOW_LATENCY|");
1328 if (self->flags & ASYNC_CLOSING)
1329 ret += sprintf(buf+ret, "ASYNC_CLOSING|");
1330 if (self->flags & ASYNC_NORMAL_ACTIVE)
1331 ret += sprintf(buf+ret, "ASYNC_NORMAL_ACTIVE|");
1332 if (self->flags)
1333 ret--; /* remove the last | */
1334 ret += sprintf(buf+ret, "\n");
1335
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001336 ret += sprintf(buf+ret, "Role: %s\n", self->client ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 "client" : "server");
1338 ret += sprintf(buf+ret, "Open count: %d\n", self->open_count);
1339 ret += sprintf(buf+ret, "Max data size: %d\n", self->max_data_size);
1340 ret += sprintf(buf+ret, "Max header size: %d\n", self->max_header_size);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 if (self->tty)
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001343 ret += sprintf(buf+ret, "Hardware: %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 self->tty->hw_stopped ? "Stopped" : "Running");
1345
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001346 ret += sprintf(buf+ret, "\n");
1347 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348}
1349
1350
1351/*
1352 * Function ircomm_tty_read_proc (buf, start, offset, len, eof, unused)
1353 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001354 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 *
1356 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
1358 int *eof, void *unused)
1359{
1360 struct ircomm_tty_cb *self;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001361 int count = 0, l;
1362 off_t begin = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 unsigned long flags;
1364
1365 spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags);
1366
1367 self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
1368 while ((self != NULL) && (count < 4000)) {
1369 if (self->magic != IRCOMM_TTY_MAGIC)
1370 break;
1371
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001372 l = ircomm_tty_line_info(self, buf + count);
1373 count += l;
1374 if (count+begin > offset+len)
1375 goto done;
1376 if (count+begin < offset) {
1377 begin += count;
1378 count = 0;
1379 }
1380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001382 }
1383 *eof = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384done:
1385 spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags);
1386
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09001387 if (offset >= count+begin)
1388 return 0;
1389 *start = buf + (offset-begin);
1390 return ((len < begin+count-offset) ? len : begin+count-offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391}
1392#endif /* CONFIG_PROC_FS */
1393
1394MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1395MODULE_DESCRIPTION("IrCOMM serial TTY driver");
1396MODULE_LICENSE("GPL");
1397MODULE_ALIAS_CHARDEV_MAJOR(IRCOMM_TTY_MAJOR);
1398
1399module_init(ircomm_tty_init);
1400module_exit(ircomm_tty_cleanup);