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