Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/devfs-2.6
[deliverable/linux.git] / net / irda / ircomm / ircomm_tty.c
1 /*********************************************************************
2 *
3 * 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
12 *
13 * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
14 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
15 *
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
19 * the License, or (at your option) any later version.
20 *
21 * 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.
25 *
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,
29 * MA 02111-1307 USA
30 *
31 ********************************************************************/
32
33 #include <linux/config.h>
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/fs.h>
37 #include <linux/sched.h>
38 #include <linux/termios.h>
39 #include <linux/tty.h>
40 #include <linux/interrupt.h>
41 #include <linux/device.h> /* for MODULE_ALIAS_CHARDEV_MAJOR */
42
43 #include <asm/uaccess.h>
44
45 #include <net/irda/irda.h>
46 #include <net/irda/irmod.h>
47
48 #include <net/irda/ircomm_core.h>
49 #include <net/irda/ircomm_param.h>
50 #include <net/irda/ircomm_tty_attach.h>
51 #include <net/irda/ircomm_tty.h>
52
53 static int ircomm_tty_open(struct tty_struct *tty, struct file *filp);
54 static void ircomm_tty_close(struct tty_struct * tty, struct file *filp);
55 static int ircomm_tty_write(struct tty_struct * tty,
56 const unsigned char *buf, int count);
57 static int ircomm_tty_write_room(struct tty_struct *tty);
58 static void ircomm_tty_throttle(struct tty_struct *tty);
59 static void ircomm_tty_unthrottle(struct tty_struct *tty);
60 static int ircomm_tty_chars_in_buffer(struct tty_struct *tty);
61 static void ircomm_tty_flush_buffer(struct tty_struct *tty);
62 static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch);
63 static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout);
64 static void ircomm_tty_hangup(struct tty_struct *tty);
65 static void ircomm_tty_do_softint(void *private_);
66 static void ircomm_tty_shutdown(struct ircomm_tty_cb *self);
67 static void ircomm_tty_stop(struct tty_struct *tty);
68
69 static int ircomm_tty_data_indication(void *instance, void *sap,
70 struct sk_buff *skb);
71 static int ircomm_tty_control_indication(void *instance, void *sap,
72 struct sk_buff *skb);
73 static void ircomm_tty_flow_indication(void *instance, void *sap,
74 LOCAL_FLOW cmd);
75 #ifdef CONFIG_PROC_FS
76 static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
77 int *eof, void *unused);
78 #endif /* CONFIG_PROC_FS */
79 static struct tty_driver *driver;
80
81 hashbin_t *ircomm_tty = NULL;
82
83 static struct tty_operations ops = {
84 .open = ircomm_tty_open,
85 .close = ircomm_tty_close,
86 .write = ircomm_tty_write,
87 .write_room = ircomm_tty_write_room,
88 .chars_in_buffer = ircomm_tty_chars_in_buffer,
89 .flush_buffer = ircomm_tty_flush_buffer,
90 .ioctl = ircomm_tty_ioctl, /* ircomm_tty_ioctl.c */
91 .tiocmget = ircomm_tty_tiocmget, /* ircomm_tty_ioctl.c */
92 .tiocmset = ircomm_tty_tiocmset, /* ircomm_tty_ioctl.c */
93 .throttle = ircomm_tty_throttle,
94 .unthrottle = ircomm_tty_unthrottle,
95 .send_xchar = ircomm_tty_send_xchar,
96 .set_termios = ircomm_tty_set_termios,
97 .stop = ircomm_tty_stop,
98 .start = ircomm_tty_start,
99 .hangup = ircomm_tty_hangup,
100 .wait_until_sent = ircomm_tty_wait_until_sent,
101 #ifdef CONFIG_PROC_FS
102 .read_proc = ircomm_tty_read_proc,
103 #endif /* CONFIG_PROC_FS */
104 };
105
106 /*
107 * Function ircomm_tty_init()
108 *
109 * Init IrCOMM TTY layer/driver
110 *
111 */
112 static int __init ircomm_tty_init(void)
113 {
114 driver = alloc_tty_driver(IRCOMM_TTY_PORTS);
115 if (!driver)
116 return -ENOMEM;
117 ircomm_tty = hashbin_new(HB_LOCK);
118 if (ircomm_tty == NULL) {
119 IRDA_ERROR("%s(), can't allocate hashbin!\n", __FUNCTION__);
120 put_tty_driver(driver);
121 return -ENOMEM;
122 }
123
124 driver->owner = THIS_MODULE;
125 driver->driver_name = "ircomm";
126 driver->name = "ircomm";
127 driver->major = IRCOMM_TTY_MAJOR;
128 driver->minor_start = IRCOMM_TTY_MINOR;
129 driver->type = TTY_DRIVER_TYPE_SERIAL;
130 driver->subtype = SERIAL_TYPE_NORMAL;
131 driver->init_termios = tty_std_termios;
132 driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
133 driver->flags = TTY_DRIVER_REAL_RAW;
134 tty_set_operations(driver, &ops);
135 if (tty_register_driver(driver)) {
136 IRDA_ERROR("%s(): Couldn't register serial driver\n",
137 __FUNCTION__);
138 put_tty_driver(driver);
139 return -1;
140 }
141 return 0;
142 }
143
144 static void __exit __ircomm_tty_cleanup(struct ircomm_tty_cb *self)
145 {
146 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
147
148 IRDA_ASSERT(self != NULL, return;);
149 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
150
151 ircomm_tty_shutdown(self);
152
153 self->magic = 0;
154 kfree(self);
155 }
156
157 /*
158 * Function ircomm_tty_cleanup ()
159 *
160 * Remove IrCOMM TTY layer/driver
161 *
162 */
163 static void __exit ircomm_tty_cleanup(void)
164 {
165 int ret;
166
167 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
168
169 ret = tty_unregister_driver(driver);
170 if (ret) {
171 IRDA_ERROR("%s(), failed to unregister driver\n",
172 __FUNCTION__);
173 return;
174 }
175
176 hashbin_delete(ircomm_tty, (FREE_FUNC) __ircomm_tty_cleanup);
177 put_tty_driver(driver);
178 }
179
180 /*
181 * Function ircomm_startup (self)
182 *
183 *
184 *
185 */
186 static int ircomm_tty_startup(struct ircomm_tty_cb *self)
187 {
188 notify_t notify;
189 int ret = -ENODEV;
190
191 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
192
193 IRDA_ASSERT(self != NULL, return -1;);
194 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
195
196 /* Check if already open */
197 if (test_and_set_bit(ASYNC_B_INITIALIZED, &self->flags)) {
198 IRDA_DEBUG(2, "%s(), already open so break out!\n", __FUNCTION__ );
199 return 0;
200 }
201
202 /* Register with IrCOMM */
203 irda_notify_init(&notify);
204 /* These callbacks we must handle ourselves */
205 notify.data_indication = ircomm_tty_data_indication;
206 notify.udata_indication = ircomm_tty_control_indication;
207 notify.flow_indication = ircomm_tty_flow_indication;
208
209 /* Use the ircomm_tty interface for these ones */
210 notify.disconnect_indication = ircomm_tty_disconnect_indication;
211 notify.connect_confirm = ircomm_tty_connect_confirm;
212 notify.connect_indication = ircomm_tty_connect_indication;
213 strlcpy(notify.name, "ircomm_tty", sizeof(notify.name));
214 notify.instance = self;
215
216 if (!self->ircomm) {
217 self->ircomm = ircomm_open(&notify, self->service_type,
218 self->line);
219 }
220 if (!self->ircomm)
221 goto err;
222
223 self->slsap_sel = self->ircomm->slsap_sel;
224
225 /* Connect IrCOMM link with remote device */
226 ret = ircomm_tty_attach_cable(self);
227 if (ret < 0) {
228 IRDA_ERROR("%s(), error attaching cable!\n", __FUNCTION__);
229 goto err;
230 }
231
232 return 0;
233 err:
234 clear_bit(ASYNC_B_INITIALIZED, &self->flags);
235 return ret;
236 }
237
238 /*
239 * Function ircomm_block_til_ready (self, filp)
240 *
241 *
242 *
243 */
244 static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
245 struct file *filp)
246 {
247 DECLARE_WAITQUEUE(wait, current);
248 int retval;
249 int do_clocal = 0, extra_count = 0;
250 unsigned long flags;
251 struct tty_struct *tty;
252
253 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
254
255 tty = self->tty;
256
257 /*
258 * If non-blocking mode is set, or the port is not enabled,
259 * then make the check up front and then exit.
260 */
261 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
262 /* nonblock mode is set or port is not enabled */
263 self->flags |= ASYNC_NORMAL_ACTIVE;
264 IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __FUNCTION__ );
265 return 0;
266 }
267
268 if (tty->termios->c_cflag & CLOCAL) {
269 IRDA_DEBUG(1, "%s(), doing CLOCAL!\n", __FUNCTION__ );
270 do_clocal = 1;
271 }
272
273 /* Wait for carrier detect and the line to become
274 * free (i.e., not in use by the callout). While we are in
275 * this loop, self->open_count is dropped by one, so that
276 * mgsl_close() knows when to free things. We restore it upon
277 * exit, either normal or abnormal.
278 */
279
280 retval = 0;
281 add_wait_queue(&self->open_wait, &wait);
282
283 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
284 __FILE__,__LINE__, tty->driver->name, self->open_count );
285
286 /* As far as I can see, we protect open_count - Jean II */
287 spin_lock_irqsave(&self->spinlock, flags);
288 if (!tty_hung_up_p(filp)) {
289 extra_count = 1;
290 self->open_count--;
291 }
292 spin_unlock_irqrestore(&self->spinlock, flags);
293 self->blocked_open++;
294
295 while (1) {
296 if (tty->termios->c_cflag & CBAUD) {
297 /* Here, we use to lock those two guys, but
298 * as ircomm_param_request() does it itself,
299 * I don't see the point (and I see the deadlock).
300 * Jean II */
301 self->settings.dte |= IRCOMM_RTS + IRCOMM_DTR;
302
303 ircomm_param_request(self, IRCOMM_DTE, TRUE);
304 }
305
306 current->state = TASK_INTERRUPTIBLE;
307
308 if (tty_hung_up_p(filp) ||
309 !test_bit(ASYNC_B_INITIALIZED, &self->flags)) {
310 retval = (self->flags & ASYNC_HUP_NOTIFY) ?
311 -EAGAIN : -ERESTARTSYS;
312 break;
313 }
314
315 /*
316 * Check if link is ready now. Even if CLOCAL is
317 * specified, we cannot return before the IrCOMM link is
318 * ready
319 */
320 if (!test_bit(ASYNC_B_CLOSING, &self->flags) &&
321 (do_clocal || (self->settings.dce & IRCOMM_CD)) &&
322 self->state == IRCOMM_TTY_READY)
323 {
324 break;
325 }
326
327 if (signal_pending(current)) {
328 retval = -ERESTARTSYS;
329 break;
330 }
331
332 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
333 __FILE__,__LINE__, tty->driver->name, self->open_count );
334
335 schedule();
336 }
337
338 __set_current_state(TASK_RUNNING);
339 remove_wait_queue(&self->open_wait, &wait);
340
341 if (extra_count) {
342 /* ++ is not atomic, so this should be protected - Jean II */
343 spin_lock_irqsave(&self->spinlock, flags);
344 self->open_count++;
345 spin_unlock_irqrestore(&self->spinlock, flags);
346 }
347 self->blocked_open--;
348
349 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
350 __FILE__,__LINE__, tty->driver->name, self->open_count);
351
352 if (!retval)
353 self->flags |= ASYNC_NORMAL_ACTIVE;
354
355 return retval;
356 }
357
358 /*
359 * Function ircomm_tty_open (tty, filp)
360 *
361 * This routine is called when a particular tty device is opened. This
362 * routine is mandatory; if this routine is not filled in, the attempted
363 * open will fail with ENODEV.
364 */
365 static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
366 {
367 struct ircomm_tty_cb *self;
368 unsigned int line;
369 unsigned long flags;
370 int ret;
371
372 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
373
374 line = tty->index;
375 if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
376 return -ENODEV;
377 }
378
379 /* Check if instance already exists */
380 self = hashbin_lock_find(ircomm_tty, line, NULL);
381 if (!self) {
382 /* No, so make new instance */
383 self = kmalloc(sizeof(struct ircomm_tty_cb), GFP_KERNEL);
384 if (self == NULL) {
385 IRDA_ERROR("%s(), kmalloc failed!\n", __FUNCTION__);
386 return -ENOMEM;
387 }
388 memset(self, 0, sizeof(struct ircomm_tty_cb));
389
390 self->magic = IRCOMM_TTY_MAGIC;
391 self->flow = FLOW_STOP;
392
393 self->line = line;
394 INIT_WORK(&self->tqueue, ircomm_tty_do_softint, self);
395 self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED;
396 self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
397 self->close_delay = 5*HZ/10;
398 self->closing_wait = 30*HZ;
399
400 /* Init some important stuff */
401 init_timer(&self->watchdog_timer);
402 init_waitqueue_head(&self->open_wait);
403 init_waitqueue_head(&self->close_wait);
404 spin_lock_init(&self->spinlock);
405
406 /*
407 * Force TTY into raw mode by default which is usually what
408 * we want for IrCOMM and IrLPT. This way applications will
409 * not have to twiddle with printcap etc.
410 */
411 tty->termios->c_iflag = 0;
412 tty->termios->c_oflag = 0;
413
414 /* Insert into hash */
415 hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL);
416 }
417 /* ++ is not atomic, so this should be protected - Jean II */
418 spin_lock_irqsave(&self->spinlock, flags);
419 self->open_count++;
420
421 tty->driver_data = self;
422 self->tty = tty;
423 spin_unlock_irqrestore(&self->spinlock, flags);
424
425 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __FUNCTION__ , tty->driver->name,
426 self->line, self->open_count);
427
428 /* Not really used by us, but lets do it anyway */
429 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
430
431 /*
432 * If the port is the middle of closing, bail out now
433 */
434 if (tty_hung_up_p(filp) ||
435 test_bit(ASYNC_B_CLOSING, &self->flags)) {
436
437 /* Hm, why are we blocking on ASYNC_CLOSING if we
438 * do return -EAGAIN/-ERESTARTSYS below anyway?
439 * IMHO it's either not needed in the first place
440 * or for some reason we need to make sure the async
441 * closing has been finished - if so, wouldn't we
442 * probably better sleep uninterruptible?
443 */
444
445 if (wait_event_interruptible(self->close_wait, !test_bit(ASYNC_B_CLOSING, &self->flags))) {
446 IRDA_WARNING("%s - got signal while blocking on ASYNC_CLOSING!\n",
447 __FUNCTION__);
448 return -ERESTARTSYS;
449 }
450
451 #ifdef SERIAL_DO_RESTART
452 return ((self->flags & ASYNC_HUP_NOTIFY) ?
453 -EAGAIN : -ERESTARTSYS);
454 #else
455 return -EAGAIN;
456 #endif
457 }
458
459 /* Check if this is a "normal" ircomm device, or an irlpt device */
460 if (line < 0x10) {
461 self->service_type = IRCOMM_3_WIRE | IRCOMM_9_WIRE;
462 self->settings.service_type = IRCOMM_9_WIRE; /* 9 wire as default */
463 /* Jan Kiszka -> add DSR/RI -> Conform to IrCOMM spec */
464 self->settings.dce = IRCOMM_CTS | IRCOMM_CD | IRCOMM_DSR | IRCOMM_RI; /* Default line settings */
465 IRDA_DEBUG(2, "%s(), IrCOMM device\n", __FUNCTION__ );
466 } else {
467 IRDA_DEBUG(2, "%s(), IrLPT device\n", __FUNCTION__ );
468 self->service_type = IRCOMM_3_WIRE_RAW;
469 self->settings.service_type = IRCOMM_3_WIRE_RAW; /* Default */
470 }
471
472 ret = ircomm_tty_startup(self);
473 if (ret)
474 return ret;
475
476 ret = ircomm_tty_block_til_ready(self, filp);
477 if (ret) {
478 IRDA_DEBUG(2,
479 "%s(), returning after block_til_ready with %d\n", __FUNCTION__ ,
480 ret);
481
482 return ret;
483 }
484 return 0;
485 }
486
487 /*
488 * Function ircomm_tty_close (tty, filp)
489 *
490 * This routine is called when a particular tty device is closed.
491 *
492 */
493 static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
494 {
495 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
496 unsigned long flags;
497
498 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
499
500 if (!tty)
501 return;
502
503 IRDA_ASSERT(self != NULL, return;);
504 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
505
506 spin_lock_irqsave(&self->spinlock, flags);
507
508 if (tty_hung_up_p(filp)) {
509 spin_unlock_irqrestore(&self->spinlock, flags);
510
511 IRDA_DEBUG(0, "%s(), returning 1\n", __FUNCTION__ );
512 return;
513 }
514
515 if ((tty->count == 1) && (self->open_count != 1)) {
516 /*
517 * Uh, oh. tty->count is 1, which means that the tty
518 * structure will be freed. state->count should always
519 * be one in these conditions. If it's greater than
520 * one, we've got real problems, since it means the
521 * serial port won't be shutdown.
522 */
523 IRDA_DEBUG(0, "%s(), bad serial port count; "
524 "tty->count is 1, state->count is %d\n", __FUNCTION__ ,
525 self->open_count);
526 self->open_count = 1;
527 }
528
529 if (--self->open_count < 0) {
530 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
531 __FUNCTION__, self->line, self->open_count);
532 self->open_count = 0;
533 }
534 if (self->open_count) {
535 spin_unlock_irqrestore(&self->spinlock, flags);
536
537 IRDA_DEBUG(0, "%s(), open count > 0\n", __FUNCTION__ );
538 return;
539 }
540
541 /* Hum... Should be test_and_set_bit ??? - Jean II */
542 set_bit(ASYNC_B_CLOSING, &self->flags);
543
544 /* We need to unlock here (we were unlocking at the end of this
545 * function), because tty_wait_until_sent() may schedule.
546 * I don't know if the rest should be protected somehow,
547 * so someone should check. - Jean II */
548 spin_unlock_irqrestore(&self->spinlock, flags);
549
550 /*
551 * Now we wait for the transmit buffer to clear; and we notify
552 * the line discipline to only process XON/XOFF characters.
553 */
554 tty->closing = 1;
555 if (self->closing_wait != ASYNC_CLOSING_WAIT_NONE)
556 tty_wait_until_sent(tty, self->closing_wait);
557
558 ircomm_tty_shutdown(self);
559
560 if (tty->driver->flush_buffer)
561 tty->driver->flush_buffer(tty);
562 if (tty->ldisc.flush_buffer)
563 tty->ldisc.flush_buffer(tty);
564
565 tty->closing = 0;
566 self->tty = NULL;
567
568 if (self->blocked_open) {
569 if (self->close_delay)
570 schedule_timeout_interruptible(self->close_delay);
571 wake_up_interruptible(&self->open_wait);
572 }
573
574 self->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
575 wake_up_interruptible(&self->close_wait);
576 }
577
578 /*
579 * Function ircomm_tty_flush_buffer (tty)
580 *
581 *
582 *
583 */
584 static void ircomm_tty_flush_buffer(struct tty_struct *tty)
585 {
586 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
587
588 IRDA_ASSERT(self != NULL, return;);
589 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
590
591 /*
592 * Let do_softint() do this to avoid race condition with
593 * do_softint() ;-)
594 */
595 schedule_work(&self->tqueue);
596 }
597
598 /*
599 * Function ircomm_tty_do_softint (private_)
600 *
601 * We use this routine to give the write wakeup to the user at at a
602 * safe time (as fast as possible after write have completed). This
603 * can be compared to the Tx interrupt.
604 */
605 static void ircomm_tty_do_softint(void *private_)
606 {
607 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) private_;
608 struct tty_struct *tty;
609 unsigned long flags;
610 struct sk_buff *skb, *ctrl_skb;
611
612 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
613
614 if (!self || self->magic != IRCOMM_TTY_MAGIC)
615 return;
616
617 tty = self->tty;
618 if (!tty)
619 return;
620
621 /* Unlink control buffer */
622 spin_lock_irqsave(&self->spinlock, flags);
623
624 ctrl_skb = self->ctrl_skb;
625 self->ctrl_skb = NULL;
626
627 spin_unlock_irqrestore(&self->spinlock, flags);
628
629 /* Flush control buffer if any */
630 if(ctrl_skb) {
631 if(self->flow == FLOW_START)
632 ircomm_control_request(self->ircomm, ctrl_skb);
633 /* Drop reference count - see ircomm_ttp_data_request(). */
634 dev_kfree_skb(ctrl_skb);
635 }
636
637 if (tty->hw_stopped)
638 return;
639
640 /* Unlink transmit buffer */
641 spin_lock_irqsave(&self->spinlock, flags);
642
643 skb = self->tx_skb;
644 self->tx_skb = NULL;
645
646 spin_unlock_irqrestore(&self->spinlock, flags);
647
648 /* Flush transmit buffer if any */
649 if (skb) {
650 ircomm_tty_do_event(self, IRCOMM_TTY_DATA_REQUEST, skb, NULL);
651 /* Drop reference count - see ircomm_ttp_data_request(). */
652 dev_kfree_skb(skb);
653 }
654
655 /* Check if user (still) wants to be waken up */
656 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
657 tty->ldisc.write_wakeup)
658 {
659 (tty->ldisc.write_wakeup)(tty);
660 }
661 wake_up_interruptible(&tty->write_wait);
662 }
663
664 /*
665 * Function ircomm_tty_write (tty, buf, count)
666 *
667 * This routine is called by the kernel to write a series of characters
668 * to the tty device. The characters may come from user space or kernel
669 * space. This routine will return the number of characters actually
670 * accepted for writing. This routine is mandatory.
671 */
672 static int ircomm_tty_write(struct tty_struct *tty,
673 const unsigned char *buf, int count)
674 {
675 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
676 unsigned long flags;
677 struct sk_buff *skb;
678 int tailroom = 0;
679 int len = 0;
680 int size;
681
682 IRDA_DEBUG(2, "%s(), count=%d, hw_stopped=%d\n", __FUNCTION__ , count,
683 tty->hw_stopped);
684
685 IRDA_ASSERT(self != NULL, return -1;);
686 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
687
688 /* We may receive packets from the TTY even before we have finished
689 * our setup. Not cool.
690 * The problem is that we don't know the final header and data size
691 * to create the proper skb, so any skb we would create would have
692 * bogus header and data size, so need care.
693 * We use a bogus header size to safely detect this condition.
694 * Another problem is that hw_stopped was set to 0 way before it
695 * should be, so we would drop this skb. It should now be fixed.
696 * One option is to not accept data until we are properly setup.
697 * But, I suspect that when it happens, the ppp line discipline
698 * just "drops" the data, which might screw up connect scripts.
699 * The second option is to create a "safe skb", with large header
700 * and small size (see ircomm_tty_open() for values).
701 * We just need to make sure that when the real values get filled,
702 * we don't mess up the original "safe skb" (see tx_data_size).
703 * Jean II */
704 if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED) {
705 IRDA_DEBUG(1, "%s() : not initialised\n", __FUNCTION__);
706 #ifdef IRCOMM_NO_TX_BEFORE_INIT
707 /* We didn't consume anything, TTY will retry */
708 return 0;
709 #endif
710 }
711
712 if (count < 1)
713 return 0;
714
715 /* Protect our manipulation of self->tx_skb and related */
716 spin_lock_irqsave(&self->spinlock, flags);
717
718 /* Fetch current transmit buffer */
719 skb = self->tx_skb;
720
721 /*
722 * Send out all the data we get, possibly as multiple fragmented
723 * frames, but this will only happen if the data is larger than the
724 * max data size. The normal case however is just the opposite, and
725 * this function may be called multiple times, and will then actually
726 * defragment the data and send it out as one packet as soon as
727 * possible, but at a safer point in time
728 */
729 while (count) {
730 size = count;
731
732 /* Adjust data size to the max data size */
733 if (size > self->max_data_size)
734 size = self->max_data_size;
735
736 /*
737 * Do we already have a buffer ready for transmit, or do
738 * we need to allocate a new frame
739 */
740 if (skb) {
741 /*
742 * Any room for more data at the end of the current
743 * transmit buffer? Cannot use skb_tailroom, since
744 * dev_alloc_skb gives us a larger skb than we
745 * requested
746 * Note : use tx_data_size, because max_data_size
747 * may have changed and we don't want to overwrite
748 * the skb. - Jean II
749 */
750 if ((tailroom = (self->tx_data_size - skb->len)) > 0) {
751 /* Adjust data to tailroom */
752 if (size > tailroom)
753 size = tailroom;
754 } else {
755 /*
756 * Current transmit frame is full, so break
757 * out, so we can send it as soon as possible
758 */
759 break;
760 }
761 } else {
762 /* Prepare a full sized frame */
763 skb = dev_alloc_skb(self->max_data_size+
764 self->max_header_size);
765 if (!skb) {
766 spin_unlock_irqrestore(&self->spinlock, flags);
767 return -ENOBUFS;
768 }
769 skb_reserve(skb, self->max_header_size);
770 self->tx_skb = skb;
771 /* Remember skb size because max_data_size may
772 * change later on - Jean II */
773 self->tx_data_size = self->max_data_size;
774 }
775
776 /* Copy data */
777 memcpy(skb_put(skb,size), buf + len, size);
778
779 count -= size;
780 len += size;
781 }
782
783 spin_unlock_irqrestore(&self->spinlock, flags);
784
785 /*
786 * Schedule a new thread which will transmit the frame as soon
787 * as possible, but at a safe point in time. We do this so the
788 * "user" can give us data multiple times, as PPP does (because of
789 * its 256 byte tx buffer). We will then defragment and send out
790 * all this data as one single packet.
791 */
792 schedule_work(&self->tqueue);
793
794 return len;
795 }
796
797 /*
798 * Function ircomm_tty_write_room (tty)
799 *
800 * This routine returns the numbers of characters the tty driver will
801 * accept for queuing to be written. This number is subject to change as
802 * output buffers get emptied, or if the output flow control is acted.
803 */
804 static int ircomm_tty_write_room(struct tty_struct *tty)
805 {
806 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
807 unsigned long flags;
808 int ret;
809
810 IRDA_ASSERT(self != NULL, return -1;);
811 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
812
813 #ifdef IRCOMM_NO_TX_BEFORE_INIT
814 /* max_header_size tells us if the channel is initialised or not. */
815 if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED)
816 /* Don't bother us yet */
817 return 0;
818 #endif
819
820 /* Check if we are allowed to transmit any data.
821 * hw_stopped is the regular flow control.
822 * Jean II */
823 if (tty->hw_stopped)
824 ret = 0;
825 else {
826 spin_lock_irqsave(&self->spinlock, flags);
827 if (self->tx_skb)
828 ret = self->tx_data_size - self->tx_skb->len;
829 else
830 ret = self->max_data_size;
831 spin_unlock_irqrestore(&self->spinlock, flags);
832 }
833 IRDA_DEBUG(2, "%s(), ret=%d\n", __FUNCTION__ , ret);
834
835 return ret;
836 }
837
838 /*
839 * Function ircomm_tty_wait_until_sent (tty, timeout)
840 *
841 * This routine waits until the device has written out all of the
842 * characters in its transmitter FIFO.
843 */
844 static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout)
845 {
846 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
847 unsigned long orig_jiffies, poll_time;
848 unsigned long flags;
849
850 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
851
852 IRDA_ASSERT(self != NULL, return;);
853 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
854
855 orig_jiffies = jiffies;
856
857 /* Set poll time to 200 ms */
858 poll_time = IRDA_MIN(timeout, msecs_to_jiffies(200));
859
860 spin_lock_irqsave(&self->spinlock, flags);
861 while (self->tx_skb && self->tx_skb->len) {
862 spin_unlock_irqrestore(&self->spinlock, flags);
863 schedule_timeout_interruptible(poll_time);
864 spin_lock_irqsave(&self->spinlock, flags);
865 if (signal_pending(current))
866 break;
867 if (timeout && time_after(jiffies, orig_jiffies + timeout))
868 break;
869 }
870 spin_unlock_irqrestore(&self->spinlock, flags);
871 current->state = TASK_RUNNING;
872 }
873
874 /*
875 * Function ircomm_tty_throttle (tty)
876 *
877 * This routine notifies the tty driver that input buffers for the line
878 * discipline are close to full, and it should somehow signal that no
879 * more characters should be sent to the tty.
880 */
881 static void ircomm_tty_throttle(struct tty_struct *tty)
882 {
883 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
884
885 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
886
887 IRDA_ASSERT(self != NULL, return;);
888 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
889
890 /* Software flow control? */
891 if (I_IXOFF(tty))
892 ircomm_tty_send_xchar(tty, STOP_CHAR(tty));
893
894 /* Hardware flow control? */
895 if (tty->termios->c_cflag & CRTSCTS) {
896 self->settings.dte &= ~IRCOMM_RTS;
897 self->settings.dte |= IRCOMM_DELTA_RTS;
898
899 ircomm_param_request(self, IRCOMM_DTE, TRUE);
900 }
901
902 ircomm_flow_request(self->ircomm, FLOW_STOP);
903 }
904
905 /*
906 * Function ircomm_tty_unthrottle (tty)
907 *
908 * This routine notifies the tty drivers that it should signals that
909 * characters can now be sent to the tty without fear of overrunning the
910 * input buffers of the line disciplines.
911 */
912 static void ircomm_tty_unthrottle(struct tty_struct *tty)
913 {
914 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
915
916 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
917
918 IRDA_ASSERT(self != NULL, return;);
919 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
920
921 /* Using software flow control? */
922 if (I_IXOFF(tty)) {
923 ircomm_tty_send_xchar(tty, START_CHAR(tty));
924 }
925
926 /* Using hardware flow control? */
927 if (tty->termios->c_cflag & CRTSCTS) {
928 self->settings.dte |= (IRCOMM_RTS|IRCOMM_DELTA_RTS);
929
930 ircomm_param_request(self, IRCOMM_DTE, TRUE);
931 IRDA_DEBUG(1, "%s(), FLOW_START\n", __FUNCTION__ );
932 }
933 ircomm_flow_request(self->ircomm, FLOW_START);
934 }
935
936 /*
937 * Function ircomm_tty_chars_in_buffer (tty)
938 *
939 * Indicates if there are any data in the buffer
940 *
941 */
942 static int ircomm_tty_chars_in_buffer(struct tty_struct *tty)
943 {
944 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
945 unsigned long flags;
946 int len = 0;
947
948 IRDA_ASSERT(self != NULL, return -1;);
949 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
950
951 spin_lock_irqsave(&self->spinlock, flags);
952
953 if (self->tx_skb)
954 len = self->tx_skb->len;
955
956 spin_unlock_irqrestore(&self->spinlock, flags);
957
958 return len;
959 }
960
961 static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
962 {
963 unsigned long flags;
964
965 IRDA_ASSERT(self != NULL, return;);
966 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
967
968 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
969
970 if (!test_and_clear_bit(ASYNC_B_INITIALIZED, &self->flags))
971 return;
972
973 ircomm_tty_detach_cable(self);
974
975 spin_lock_irqsave(&self->spinlock, flags);
976
977 del_timer(&self->watchdog_timer);
978
979 /* Free parameter buffer */
980 if (self->ctrl_skb) {
981 dev_kfree_skb(self->ctrl_skb);
982 self->ctrl_skb = NULL;
983 }
984
985 /* Free transmit buffer */
986 if (self->tx_skb) {
987 dev_kfree_skb(self->tx_skb);
988 self->tx_skb = NULL;
989 }
990
991 if (self->ircomm) {
992 ircomm_close(self->ircomm);
993 self->ircomm = NULL;
994 }
995
996 spin_unlock_irqrestore(&self->spinlock, flags);
997 }
998
999 /*
1000 * Function ircomm_tty_hangup (tty)
1001 *
1002 * This routine notifies the tty driver that it should hangup the tty
1003 * device.
1004 *
1005 */
1006 static void ircomm_tty_hangup(struct tty_struct *tty)
1007 {
1008 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
1009 unsigned long flags;
1010
1011 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
1012
1013 IRDA_ASSERT(self != NULL, return;);
1014 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1015
1016 if (!tty)
1017 return;
1018
1019 /* ircomm_tty_flush_buffer(tty); */
1020 ircomm_tty_shutdown(self);
1021
1022 /* I guess we need to lock here - Jean II */
1023 spin_lock_irqsave(&self->spinlock, flags);
1024 self->flags &= ~ASYNC_NORMAL_ACTIVE;
1025 self->tty = NULL;
1026 self->open_count = 0;
1027 spin_unlock_irqrestore(&self->spinlock, flags);
1028
1029 wake_up_interruptible(&self->open_wait);
1030 }
1031
1032 /*
1033 * Function ircomm_tty_send_xchar (tty, ch)
1034 *
1035 * This routine is used to send a high-priority XON/XOFF character to
1036 * the device.
1037 */
1038 static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch)
1039 {
1040 IRDA_DEBUG(0, "%s(), not impl\n", __FUNCTION__ );
1041 }
1042
1043 /*
1044 * Function ircomm_tty_start (tty)
1045 *
1046 * This routine notifies the tty driver that it resume sending
1047 * characters to the tty device.
1048 */
1049 void ircomm_tty_start(struct tty_struct *tty)
1050 {
1051 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
1052
1053 ircomm_flow_request(self->ircomm, FLOW_START);
1054 }
1055
1056 /*
1057 * Function ircomm_tty_stop (tty)
1058 *
1059 * This routine notifies the tty driver that it should stop outputting
1060 * characters to the tty device.
1061 */
1062 static void ircomm_tty_stop(struct tty_struct *tty)
1063 {
1064 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
1065
1066 IRDA_ASSERT(self != NULL, return;);
1067 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1068
1069 ircomm_flow_request(self->ircomm, FLOW_STOP);
1070 }
1071
1072 /*
1073 * Function ircomm_check_modem_status (self)
1074 *
1075 * Check for any changes in the DCE's line settings. This function should
1076 * be called whenever the dce parameter settings changes, to update the
1077 * flow control settings and other things
1078 */
1079 void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
1080 {
1081 struct tty_struct *tty;
1082 int status;
1083
1084 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
1085
1086 IRDA_ASSERT(self != NULL, return;);
1087 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1088
1089 tty = self->tty;
1090
1091 status = self->settings.dce;
1092
1093 if (status & IRCOMM_DCE_DELTA_ANY) {
1094 /*wake_up_interruptible(&self->delta_msr_wait);*/
1095 }
1096 if ((self->flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) {
1097 IRDA_DEBUG(2,
1098 "%s(), ircomm%d CD now %s...\n", __FUNCTION__ , self->line,
1099 (status & IRCOMM_CD) ? "on" : "off");
1100
1101 if (status & IRCOMM_CD) {
1102 wake_up_interruptible(&self->open_wait);
1103 } else {
1104 IRDA_DEBUG(2,
1105 "%s(), Doing serial hangup..\n", __FUNCTION__ );
1106 if (tty)
1107 tty_hangup(tty);
1108
1109 /* Hangup will remote the tty, so better break out */
1110 return;
1111 }
1112 }
1113 if (self->flags & ASYNC_CTS_FLOW) {
1114 if (tty->hw_stopped) {
1115 if (status & IRCOMM_CTS) {
1116 IRDA_DEBUG(2,
1117 "%s(), CTS tx start...\n", __FUNCTION__ );
1118 tty->hw_stopped = 0;
1119
1120 /* Wake up processes blocked on open */
1121 wake_up_interruptible(&self->open_wait);
1122
1123 schedule_work(&self->tqueue);
1124 return;
1125 }
1126 } else {
1127 if (!(status & IRCOMM_CTS)) {
1128 IRDA_DEBUG(2,
1129 "%s(), CTS tx stop...\n", __FUNCTION__ );
1130 tty->hw_stopped = 1;
1131 }
1132 }
1133 }
1134 }
1135
1136 /*
1137 * Function ircomm_tty_data_indication (instance, sap, skb)
1138 *
1139 * Handle incoming data, and deliver it to the line discipline
1140 *
1141 */
1142 static int ircomm_tty_data_indication(void *instance, void *sap,
1143 struct sk_buff *skb)
1144 {
1145 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
1146
1147 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
1148
1149 IRDA_ASSERT(self != NULL, return -1;);
1150 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
1151 IRDA_ASSERT(skb != NULL, return -1;);
1152
1153 if (!self->tty) {
1154 IRDA_DEBUG(0, "%s(), no tty!\n", __FUNCTION__ );
1155 return 0;
1156 }
1157
1158 /*
1159 * If we receive data when hardware is stopped then something is wrong.
1160 * We try to poll the peers line settings to check if we are up todate.
1161 * Devices like WinCE can do this, and since they don't send any
1162 * params, we can just as well declare the hardware for running.
1163 */
1164 if (self->tty->hw_stopped && (self->flow == FLOW_START)) {
1165 IRDA_DEBUG(0, "%s(), polling for line settings!\n", __FUNCTION__ );
1166 ircomm_param_request(self, IRCOMM_POLL, TRUE);
1167
1168 /* We can just as well declare the hardware for running */
1169 ircomm_tty_send_initial_parameters(self);
1170 ircomm_tty_link_established(self);
1171 }
1172
1173 /*
1174 * Just give it over to the line discipline. There is no need to
1175 * involve the flip buffers, since we are not running in an interrupt
1176 * handler
1177 */
1178 self->tty->ldisc.receive_buf(self->tty, skb->data, NULL, skb->len);
1179
1180 /* No need to kfree_skb - see ircomm_ttp_data_indication() */
1181
1182 return 0;
1183 }
1184
1185 /*
1186 * Function ircomm_tty_control_indication (instance, sap, skb)
1187 *
1188 * Parse all incoming parameters (easy!)
1189 *
1190 */
1191 static int ircomm_tty_control_indication(void *instance, void *sap,
1192 struct sk_buff *skb)
1193 {
1194 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
1195 int clen;
1196
1197 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
1198
1199 IRDA_ASSERT(self != NULL, return -1;);
1200 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
1201 IRDA_ASSERT(skb != NULL, return -1;);
1202
1203 clen = skb->data[0];
1204
1205 irda_param_extract_all(self, skb->data+1, IRDA_MIN(skb->len-1, clen),
1206 &ircomm_param_info);
1207
1208 /* No need to kfree_skb - see ircomm_control_indication() */
1209
1210 return 0;
1211 }
1212
1213 /*
1214 * Function ircomm_tty_flow_indication (instance, sap, cmd)
1215 *
1216 * This function is called by IrTTP when it wants us to slow down the
1217 * transmission of data. We just mark the hardware as stopped, and wait
1218 * for IrTTP to notify us that things are OK again.
1219 */
1220 static void ircomm_tty_flow_indication(void *instance, void *sap,
1221 LOCAL_FLOW cmd)
1222 {
1223 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
1224 struct tty_struct *tty;
1225
1226 IRDA_ASSERT(self != NULL, return;);
1227 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1228
1229 tty = self->tty;
1230
1231 switch (cmd) {
1232 case FLOW_START:
1233 IRDA_DEBUG(2, "%s(), hw start!\n", __FUNCTION__ );
1234 tty->hw_stopped = 0;
1235
1236 /* ircomm_tty_do_softint will take care of the rest */
1237 schedule_work(&self->tqueue);
1238 break;
1239 default: /* If we get here, something is very wrong, better stop */
1240 case FLOW_STOP:
1241 IRDA_DEBUG(2, "%s(), hw stopped!\n", __FUNCTION__ );
1242 tty->hw_stopped = 1;
1243 break;
1244 }
1245 self->flow = cmd;
1246 }
1247
1248 static int ircomm_tty_line_info(struct ircomm_tty_cb *self, char *buf)
1249 {
1250 int ret=0;
1251
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");
1263 ret += sprintf(buf+ret, "\n");
1264
1265 ret += sprintf(buf+ret, "Port name: %s\n", self->settings.port_name);
1266
1267 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|");
1272 if (self->settings.dte)
1273 ret--; /* remove the last | */
1274 ret += sprintf(buf+ret, "\n");
1275
1276 ret += sprintf(buf+ret, "DCE status: ");
1277 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|");
1285 if (self->settings.dce)
1286 ret--; /* remove the last | */
1287 ret += sprintf(buf+ret, "\n");
1288
1289 ret += sprintf(buf+ret, "Configuration: ");
1290 if (!self->settings.null_modem)
1291 ret += sprintf(buf+ret, "DTE <-> DCE\n");
1292 else
1293 ret += sprintf(buf+ret,
1294 "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 | */
1317 ret += sprintf(buf+ret, "\n");
1318
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
1336 ret += sprintf(buf+ret, "Role: %s\n", self->client ?
1337 "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);
1341
1342 if (self->tty)
1343 ret += sprintf(buf+ret, "Hardware: %s\n",
1344 self->tty->hw_stopped ? "Stopped" : "Running");
1345
1346 ret += sprintf(buf+ret, "\n");
1347 return ret;
1348 }
1349
1350
1351 /*
1352 * Function ircomm_tty_read_proc (buf, start, offset, len, eof, unused)
1353 *
1354 *
1355 *
1356 */
1357 #ifdef CONFIG_PROC_FS
1358 static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
1359 int *eof, void *unused)
1360 {
1361 struct ircomm_tty_cb *self;
1362 int count = 0, l;
1363 off_t begin = 0;
1364 unsigned long flags;
1365
1366 spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags);
1367
1368 self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
1369 while ((self != NULL) && (count < 4000)) {
1370 if (self->magic != IRCOMM_TTY_MAGIC)
1371 break;
1372
1373 l = ircomm_tty_line_info(self, buf + count);
1374 count += l;
1375 if (count+begin > offset+len)
1376 goto done;
1377 if (count+begin < offset) {
1378 begin += count;
1379 count = 0;
1380 }
1381
1382 self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
1383 }
1384 *eof = 1;
1385 done:
1386 spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags);
1387
1388 if (offset >= count+begin)
1389 return 0;
1390 *start = buf + (offset-begin);
1391 return ((len < begin+count-offset) ? len : begin+count-offset);
1392 }
1393 #endif /* CONFIG_PROC_FS */
1394
1395 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1396 MODULE_DESCRIPTION("IrCOMM serial TTY driver");
1397 MODULE_LICENSE("GPL");
1398 MODULE_ALIAS_CHARDEV_MAJOR(IRCOMM_TTY_MAJOR);
1399
1400 module_init(ircomm_tty_init);
1401 module_exit(ircomm_tty_cleanup);
This page took 0.126234 seconds and 6 git commands to generate.