ircomm_tty.c 37 KB

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