ircomm_tty.c 38 KB

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