ircomm_tty.c 38 KB

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