ircomm_tty.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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 (C_BAUD(tty))
  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 (C_CLOCAL(tty)) {
  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 ((do_clocal || tty_port_carrier_raised(port)) &&
  298. self->state == IRCOMM_TTY_READY)
  299. {
  300. break;
  301. }
  302. if (signal_pending(current)) {
  303. retval = -ERESTARTSYS;
  304. break;
  305. }
  306. pr_debug("%s(%d):block_til_ready blocking on %s open_count=%d\n",
  307. __FILE__, __LINE__, tty->driver->name, port->count);
  308. schedule();
  309. }
  310. __set_current_state(TASK_RUNNING);
  311. remove_wait_queue(&port->open_wait, &wait);
  312. spin_lock_irqsave(&port->lock, flags);
  313. if (!tty_hung_up_p(filp))
  314. port->count++;
  315. port->blocked_open--;
  316. spin_unlock_irqrestore(&port->lock, flags);
  317. pr_debug("%s(%d):block_til_ready after blocking on %s open_count=%d\n",
  318. __FILE__, __LINE__, tty->driver->name, port->count);
  319. if (!retval)
  320. port->flags |= ASYNC_NORMAL_ACTIVE;
  321. return retval;
  322. }
  323. static int ircomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
  324. {
  325. struct ircomm_tty_cb *self;
  326. unsigned int line = tty->index;
  327. /* Check if instance already exists */
  328. self = hashbin_lock_find(ircomm_tty, line, NULL);
  329. if (!self) {
  330. /* No, so make new instance */
  331. self = kzalloc(sizeof(struct ircomm_tty_cb), GFP_KERNEL);
  332. if (self == NULL)
  333. return -ENOMEM;
  334. tty_port_init(&self->port);
  335. self->port.ops = &ircomm_port_ops;
  336. self->magic = IRCOMM_TTY_MAGIC;
  337. self->flow = FLOW_STOP;
  338. self->line = line;
  339. INIT_WORK(&self->tqueue, ircomm_tty_do_softint);
  340. self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED;
  341. self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
  342. /* Init some important stuff */
  343. init_timer(&self->watchdog_timer);
  344. spin_lock_init(&self->spinlock);
  345. /*
  346. * Force TTY into raw mode by default which is usually what
  347. * we want for IrCOMM and IrLPT. This way applications will
  348. * not have to twiddle with printcap etc.
  349. *
  350. * Note this is completely usafe and doesn't work properly
  351. */
  352. tty->termios.c_iflag = 0;
  353. tty->termios.c_oflag = 0;
  354. /* Insert into hash */
  355. hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL);
  356. }
  357. tty->driver_data = self;
  358. return tty_port_install(&self->port, driver, tty);
  359. }
  360. /*
  361. * Function ircomm_tty_open (tty, filp)
  362. *
  363. * This routine is called when a particular tty device is opened. This
  364. * routine is mandatory; if this routine is not filled in, the attempted
  365. * open will fail with ENODEV.
  366. */
  367. static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
  368. {
  369. struct ircomm_tty_cb *self = tty->driver_data;
  370. unsigned long flags;
  371. int ret;
  372. /* ++ is not atomic, so this should be protected - Jean II */
  373. spin_lock_irqsave(&self->port.lock, flags);
  374. self->port.count++;
  375. spin_unlock_irqrestore(&self->port.lock, flags);
  376. tty_port_tty_set(&self->port, tty);
  377. pr_debug("%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
  378. self->line, self->port.count);
  379. /* Not really used by us, but lets do it anyway */
  380. self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  381. /* Check if this is a "normal" ircomm device, or an irlpt device */
  382. if (self->line < 0x10) {
  383. self->service_type = IRCOMM_3_WIRE | IRCOMM_9_WIRE;
  384. self->settings.service_type = IRCOMM_9_WIRE; /* 9 wire as default */
  385. /* Jan Kiszka -> add DSR/RI -> Conform to IrCOMM spec */
  386. self->settings.dce = IRCOMM_CTS | IRCOMM_CD | IRCOMM_DSR | IRCOMM_RI; /* Default line settings */
  387. pr_debug("%s(), IrCOMM device\n", __func__);
  388. } else {
  389. pr_debug("%s(), IrLPT device\n", __func__);
  390. self->service_type = IRCOMM_3_WIRE_RAW;
  391. self->settings.service_type = IRCOMM_3_WIRE_RAW; /* Default */
  392. }
  393. ret = ircomm_tty_startup(self);
  394. if (ret)
  395. return ret;
  396. ret = ircomm_tty_block_til_ready(self, tty, filp);
  397. if (ret) {
  398. pr_debug("%s(), returning after block_til_ready with %d\n",
  399. __func__, ret);
  400. return ret;
  401. }
  402. return 0;
  403. }
  404. /*
  405. * Function ircomm_tty_close (tty, filp)
  406. *
  407. * This routine is called when a particular tty device is closed.
  408. *
  409. */
  410. static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
  411. {
  412. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  413. struct tty_port *port = &self->port;
  414. IRDA_ASSERT(self != NULL, return;);
  415. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  416. if (tty_port_close_start(port, tty, filp) == 0)
  417. return;
  418. ircomm_tty_shutdown(self);
  419. tty_driver_flush_buffer(tty);
  420. tty_port_close_end(port, tty);
  421. tty_port_tty_set(port, NULL);
  422. }
  423. /*
  424. * Function ircomm_tty_flush_buffer (tty)
  425. *
  426. *
  427. *
  428. */
  429. static void ircomm_tty_flush_buffer(struct tty_struct *tty)
  430. {
  431. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  432. IRDA_ASSERT(self != NULL, return;);
  433. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  434. /*
  435. * Let do_softint() do this to avoid race condition with
  436. * do_softint() ;-)
  437. */
  438. schedule_work(&self->tqueue);
  439. }
  440. /*
  441. * Function ircomm_tty_do_softint (work)
  442. *
  443. * We use this routine to give the write wakeup to the user at at a
  444. * safe time (as fast as possible after write have completed). This
  445. * can be compared to the Tx interrupt.
  446. */
  447. static void ircomm_tty_do_softint(struct work_struct *work)
  448. {
  449. struct ircomm_tty_cb *self =
  450. container_of(work, struct ircomm_tty_cb, tqueue);
  451. struct tty_struct *tty;
  452. unsigned long flags;
  453. struct sk_buff *skb, *ctrl_skb;
  454. if (!self || self->magic != IRCOMM_TTY_MAGIC)
  455. return;
  456. tty = tty_port_tty_get(&self->port);
  457. if (!tty)
  458. return;
  459. /* Unlink control buffer */
  460. spin_lock_irqsave(&self->spinlock, flags);
  461. ctrl_skb = self->ctrl_skb;
  462. self->ctrl_skb = NULL;
  463. spin_unlock_irqrestore(&self->spinlock, flags);
  464. /* Flush control buffer if any */
  465. if(ctrl_skb) {
  466. if(self->flow == FLOW_START)
  467. ircomm_control_request(self->ircomm, ctrl_skb);
  468. /* Drop reference count - see ircomm_ttp_data_request(). */
  469. dev_kfree_skb(ctrl_skb);
  470. }
  471. if (tty->hw_stopped)
  472. goto put;
  473. /* Unlink transmit buffer */
  474. spin_lock_irqsave(&self->spinlock, flags);
  475. skb = self->tx_skb;
  476. self->tx_skb = NULL;
  477. spin_unlock_irqrestore(&self->spinlock, flags);
  478. /* Flush transmit buffer if any */
  479. if (skb) {
  480. ircomm_tty_do_event(self, IRCOMM_TTY_DATA_REQUEST, skb, NULL);
  481. /* Drop reference count - see ircomm_ttp_data_request(). */
  482. dev_kfree_skb(skb);
  483. }
  484. /* Check if user (still) wants to be waken up */
  485. tty_wakeup(tty);
  486. put:
  487. tty_kref_put(tty);
  488. }
  489. /*
  490. * Function ircomm_tty_write (tty, buf, count)
  491. *
  492. * This routine is called by the kernel to write a series of characters
  493. * to the tty device. The characters may come from user space or kernel
  494. * space. This routine will return the number of characters actually
  495. * accepted for writing. This routine is mandatory.
  496. */
  497. static int ircomm_tty_write(struct tty_struct *tty,
  498. const unsigned char *buf, int count)
  499. {
  500. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  501. unsigned long flags;
  502. struct sk_buff *skb;
  503. int tailroom = 0;
  504. int len = 0;
  505. int size;
  506. pr_debug("%s(), count=%d, hw_stopped=%d\n", __func__ , count,
  507. tty->hw_stopped);
  508. IRDA_ASSERT(self != NULL, return -1;);
  509. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
  510. /* We may receive packets from the TTY even before we have finished
  511. * our setup. Not cool.
  512. * The problem is that we don't know the final header and data size
  513. * to create the proper skb, so any skb we would create would have
  514. * bogus header and data size, so need care.
  515. * We use a bogus header size to safely detect this condition.
  516. * Another problem is that hw_stopped was set to 0 way before it
  517. * should be, so we would drop this skb. It should now be fixed.
  518. * One option is to not accept data until we are properly setup.
  519. * But, I suspect that when it happens, the ppp line discipline
  520. * just "drops" the data, which might screw up connect scripts.
  521. * The second option is to create a "safe skb", with large header
  522. * and small size (see ircomm_tty_open() for values).
  523. * We just need to make sure that when the real values get filled,
  524. * we don't mess up the original "safe skb" (see tx_data_size).
  525. * Jean II */
  526. if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED) {
  527. pr_debug("%s() : not initialised\n", __func__);
  528. #ifdef IRCOMM_NO_TX_BEFORE_INIT
  529. /* We didn't consume anything, TTY will retry */
  530. return 0;
  531. #endif
  532. }
  533. if (count < 1)
  534. return 0;
  535. /* Protect our manipulation of self->tx_skb and related */
  536. spin_lock_irqsave(&self->spinlock, flags);
  537. /* Fetch current transmit buffer */
  538. skb = self->tx_skb;
  539. /*
  540. * Send out all the data we get, possibly as multiple fragmented
  541. * frames, but this will only happen if the data is larger than the
  542. * max data size. The normal case however is just the opposite, and
  543. * this function may be called multiple times, and will then actually
  544. * defragment the data and send it out as one packet as soon as
  545. * possible, but at a safer point in time
  546. */
  547. while (count) {
  548. size = count;
  549. /* Adjust data size to the max data size */
  550. if (size > self->max_data_size)
  551. size = self->max_data_size;
  552. /*
  553. * Do we already have a buffer ready for transmit, or do
  554. * we need to allocate a new frame
  555. */
  556. if (skb) {
  557. /*
  558. * Any room for more data at the end of the current
  559. * transmit buffer? Cannot use skb_tailroom, since
  560. * dev_alloc_skb gives us a larger skb than we
  561. * requested
  562. * Note : use tx_data_size, because max_data_size
  563. * may have changed and we don't want to overwrite
  564. * the skb. - Jean II
  565. */
  566. if ((tailroom = (self->tx_data_size - skb->len)) > 0) {
  567. /* Adjust data to tailroom */
  568. if (size > tailroom)
  569. size = tailroom;
  570. } else {
  571. /*
  572. * Current transmit frame is full, so break
  573. * out, so we can send it as soon as possible
  574. */
  575. break;
  576. }
  577. } else {
  578. /* Prepare a full sized frame */
  579. skb = alloc_skb(self->max_data_size+
  580. self->max_header_size,
  581. GFP_ATOMIC);
  582. if (!skb) {
  583. spin_unlock_irqrestore(&self->spinlock, flags);
  584. return -ENOBUFS;
  585. }
  586. skb_reserve(skb, self->max_header_size);
  587. self->tx_skb = skb;
  588. /* Remember skb size because max_data_size may
  589. * change later on - Jean II */
  590. self->tx_data_size = self->max_data_size;
  591. }
  592. /* Copy data */
  593. memcpy(skb_put(skb,size), buf + len, size);
  594. count -= size;
  595. len += size;
  596. }
  597. spin_unlock_irqrestore(&self->spinlock, flags);
  598. /*
  599. * Schedule a new thread which will transmit the frame as soon
  600. * as possible, but at a safe point in time. We do this so the
  601. * "user" can give us data multiple times, as PPP does (because of
  602. * its 256 byte tx buffer). We will then defragment and send out
  603. * all this data as one single packet.
  604. */
  605. schedule_work(&self->tqueue);
  606. return len;
  607. }
  608. /*
  609. * Function ircomm_tty_write_room (tty)
  610. *
  611. * This routine returns the numbers of characters the tty driver will
  612. * accept for queuing to be written. This number is subject to change as
  613. * output buffers get emptied, or if the output flow control is acted.
  614. */
  615. static int ircomm_tty_write_room(struct tty_struct *tty)
  616. {
  617. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  618. unsigned long flags;
  619. int ret;
  620. IRDA_ASSERT(self != NULL, return -1;);
  621. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
  622. #ifdef IRCOMM_NO_TX_BEFORE_INIT
  623. /* max_header_size tells us if the channel is initialised or not. */
  624. if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED)
  625. /* Don't bother us yet */
  626. return 0;
  627. #endif
  628. /* Check if we are allowed to transmit any data.
  629. * hw_stopped is the regular flow control.
  630. * Jean II */
  631. if (tty->hw_stopped)
  632. ret = 0;
  633. else {
  634. spin_lock_irqsave(&self->spinlock, flags);
  635. if (self->tx_skb)
  636. ret = self->tx_data_size - self->tx_skb->len;
  637. else
  638. ret = self->max_data_size;
  639. spin_unlock_irqrestore(&self->spinlock, flags);
  640. }
  641. pr_debug("%s(), ret=%d\n", __func__ , ret);
  642. return ret;
  643. }
  644. /*
  645. * Function ircomm_tty_wait_until_sent (tty, timeout)
  646. *
  647. * This routine waits until the device has written out all of the
  648. * characters in its transmitter FIFO.
  649. */
  650. static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout)
  651. {
  652. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  653. unsigned long orig_jiffies, poll_time;
  654. unsigned long flags;
  655. IRDA_ASSERT(self != NULL, return;);
  656. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  657. orig_jiffies = jiffies;
  658. /* Set poll time to 200 ms */
  659. poll_time = msecs_to_jiffies(200);
  660. if (timeout)
  661. poll_time = min_t(unsigned long, timeout, poll_time);
  662. spin_lock_irqsave(&self->spinlock, flags);
  663. while (self->tx_skb && self->tx_skb->len) {
  664. spin_unlock_irqrestore(&self->spinlock, flags);
  665. schedule_timeout_interruptible(poll_time);
  666. spin_lock_irqsave(&self->spinlock, flags);
  667. if (signal_pending(current))
  668. break;
  669. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  670. break;
  671. }
  672. spin_unlock_irqrestore(&self->spinlock, flags);
  673. __set_current_state(TASK_RUNNING);
  674. }
  675. /*
  676. * Function ircomm_tty_throttle (tty)
  677. *
  678. * This routine notifies the tty driver that input buffers for the line
  679. * discipline are close to full, and it should somehow signal that no
  680. * more characters should be sent to the tty.
  681. */
  682. static void ircomm_tty_throttle(struct tty_struct *tty)
  683. {
  684. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  685. IRDA_ASSERT(self != NULL, return;);
  686. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  687. /* Software flow control? */
  688. if (I_IXOFF(tty))
  689. ircomm_tty_send_xchar(tty, STOP_CHAR(tty));
  690. /* Hardware flow control? */
  691. if (C_CRTSCTS(tty)) {
  692. self->settings.dte &= ~IRCOMM_RTS;
  693. self->settings.dte |= IRCOMM_DELTA_RTS;
  694. ircomm_param_request(self, IRCOMM_DTE, TRUE);
  695. }
  696. ircomm_flow_request(self->ircomm, FLOW_STOP);
  697. }
  698. /*
  699. * Function ircomm_tty_unthrottle (tty)
  700. *
  701. * This routine notifies the tty drivers that it should signals that
  702. * characters can now be sent to the tty without fear of overrunning the
  703. * input buffers of the line disciplines.
  704. */
  705. static void ircomm_tty_unthrottle(struct tty_struct *tty)
  706. {
  707. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  708. IRDA_ASSERT(self != NULL, return;);
  709. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  710. /* Using software flow control? */
  711. if (I_IXOFF(tty))
  712. ircomm_tty_send_xchar(tty, START_CHAR(tty));
  713. /* Using hardware flow control? */
  714. if (C_CRTSCTS(tty)) {
  715. self->settings.dte |= (IRCOMM_RTS|IRCOMM_DELTA_RTS);
  716. ircomm_param_request(self, IRCOMM_DTE, TRUE);
  717. pr_debug("%s(), FLOW_START\n", __func__);
  718. }
  719. ircomm_flow_request(self->ircomm, FLOW_START);
  720. }
  721. /*
  722. * Function ircomm_tty_chars_in_buffer (tty)
  723. *
  724. * Indicates if there are any data in the buffer
  725. *
  726. */
  727. static int ircomm_tty_chars_in_buffer(struct tty_struct *tty)
  728. {
  729. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  730. unsigned long flags;
  731. int len = 0;
  732. IRDA_ASSERT(self != NULL, return -1;);
  733. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
  734. spin_lock_irqsave(&self->spinlock, flags);
  735. if (self->tx_skb)
  736. len = self->tx_skb->len;
  737. spin_unlock_irqrestore(&self->spinlock, flags);
  738. return len;
  739. }
  740. static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
  741. {
  742. unsigned long flags;
  743. IRDA_ASSERT(self != NULL, return;);
  744. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  745. if (!test_and_clear_bit(ASYNCB_INITIALIZED, &self->port.flags))
  746. return;
  747. ircomm_tty_detach_cable(self);
  748. spin_lock_irqsave(&self->spinlock, flags);
  749. del_timer(&self->watchdog_timer);
  750. /* Free parameter buffer */
  751. if (self->ctrl_skb) {
  752. dev_kfree_skb(self->ctrl_skb);
  753. self->ctrl_skb = NULL;
  754. }
  755. /* Free transmit buffer */
  756. if (self->tx_skb) {
  757. dev_kfree_skb(self->tx_skb);
  758. self->tx_skb = NULL;
  759. }
  760. if (self->ircomm) {
  761. ircomm_close(self->ircomm);
  762. self->ircomm = NULL;
  763. }
  764. spin_unlock_irqrestore(&self->spinlock, flags);
  765. }
  766. /*
  767. * Function ircomm_tty_hangup (tty)
  768. *
  769. * This routine notifies the tty driver that it should hangup the tty
  770. * device.
  771. *
  772. */
  773. static void ircomm_tty_hangup(struct tty_struct *tty)
  774. {
  775. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  776. struct tty_port *port = &self->port;
  777. unsigned long flags;
  778. IRDA_ASSERT(self != NULL, return;);
  779. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  780. /* ircomm_tty_flush_buffer(tty); */
  781. ircomm_tty_shutdown(self);
  782. spin_lock_irqsave(&port->lock, flags);
  783. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  784. if (port->tty) {
  785. set_bit(TTY_IO_ERROR, &port->tty->flags);
  786. tty_kref_put(port->tty);
  787. }
  788. port->tty = NULL;
  789. port->count = 0;
  790. spin_unlock_irqrestore(&port->lock, flags);
  791. wake_up_interruptible(&port->open_wait);
  792. }
  793. /*
  794. * Function ircomm_tty_send_xchar (tty, ch)
  795. *
  796. * This routine is used to send a high-priority XON/XOFF character to
  797. * the device.
  798. */
  799. static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch)
  800. {
  801. pr_debug("%s(), not impl\n", __func__);
  802. }
  803. /*
  804. * Function ircomm_tty_start (tty)
  805. *
  806. * This routine notifies the tty driver that it resume sending
  807. * characters to the tty device.
  808. */
  809. void ircomm_tty_start(struct tty_struct *tty)
  810. {
  811. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  812. ircomm_flow_request(self->ircomm, FLOW_START);
  813. }
  814. /*
  815. * Function ircomm_tty_stop (tty)
  816. *
  817. * This routine notifies the tty driver that it should stop outputting
  818. * characters to the tty device.
  819. */
  820. static void ircomm_tty_stop(struct tty_struct *tty)
  821. {
  822. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
  823. IRDA_ASSERT(self != NULL, return;);
  824. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  825. ircomm_flow_request(self->ircomm, FLOW_STOP);
  826. }
  827. /*
  828. * Function ircomm_check_modem_status (self)
  829. *
  830. * Check for any changes in the DCE's line settings. This function should
  831. * be called whenever the dce parameter settings changes, to update the
  832. * flow control settings and other things
  833. */
  834. void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
  835. {
  836. struct tty_struct *tty;
  837. int status;
  838. IRDA_ASSERT(self != NULL, return;);
  839. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  840. tty = tty_port_tty_get(&self->port);
  841. status = self->settings.dce;
  842. if (status & IRCOMM_DCE_DELTA_ANY) {
  843. /*wake_up_interruptible(&self->delta_msr_wait);*/
  844. }
  845. if ((self->port.flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) {
  846. pr_debug("%s(), ircomm%d CD now %s...\n", __func__ , self->line,
  847. (status & IRCOMM_CD) ? "on" : "off");
  848. if (status & IRCOMM_CD) {
  849. wake_up_interruptible(&self->port.open_wait);
  850. } else {
  851. pr_debug("%s(), Doing serial hangup..\n", __func__);
  852. if (tty)
  853. tty_hangup(tty);
  854. /* Hangup will remote the tty, so better break out */
  855. goto put;
  856. }
  857. }
  858. if (tty && tty_port_cts_enabled(&self->port)) {
  859. if (tty->hw_stopped) {
  860. if (status & IRCOMM_CTS) {
  861. pr_debug("%s(), CTS tx start...\n", __func__);
  862. tty->hw_stopped = 0;
  863. /* Wake up processes blocked on open */
  864. wake_up_interruptible(&self->port.open_wait);
  865. schedule_work(&self->tqueue);
  866. goto put;
  867. }
  868. } else {
  869. if (!(status & IRCOMM_CTS)) {
  870. pr_debug("%s(), CTS tx stop...\n", __func__);
  871. tty->hw_stopped = 1;
  872. }
  873. }
  874. }
  875. put:
  876. tty_kref_put(tty);
  877. }
  878. /*
  879. * Function ircomm_tty_data_indication (instance, sap, skb)
  880. *
  881. * Handle incoming data, and deliver it to the line discipline
  882. *
  883. */
  884. static int ircomm_tty_data_indication(void *instance, void *sap,
  885. struct sk_buff *skb)
  886. {
  887. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
  888. struct tty_struct *tty;
  889. IRDA_ASSERT(self != NULL, return -1;);
  890. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
  891. IRDA_ASSERT(skb != NULL, return -1;);
  892. tty = tty_port_tty_get(&self->port);
  893. if (!tty) {
  894. pr_debug("%s(), no tty!\n", __func__);
  895. return 0;
  896. }
  897. /*
  898. * If we receive data when hardware is stopped then something is wrong.
  899. * We try to poll the peers line settings to check if we are up todate.
  900. * Devices like WinCE can do this, and since they don't send any
  901. * params, we can just as well declare the hardware for running.
  902. */
  903. if (tty->hw_stopped && (self->flow == FLOW_START)) {
  904. pr_debug("%s(), polling for line settings!\n", __func__);
  905. ircomm_param_request(self, IRCOMM_POLL, TRUE);
  906. /* We can just as well declare the hardware for running */
  907. ircomm_tty_send_initial_parameters(self);
  908. ircomm_tty_link_established(self);
  909. }
  910. tty_kref_put(tty);
  911. /*
  912. * Use flip buffer functions since the code may be called from interrupt
  913. * context
  914. */
  915. tty_insert_flip_string(&self->port, skb->data, skb->len);
  916. tty_flip_buffer_push(&self->port);
  917. /* No need to kfree_skb - see ircomm_ttp_data_indication() */
  918. return 0;
  919. }
  920. /*
  921. * Function ircomm_tty_control_indication (instance, sap, skb)
  922. *
  923. * Parse all incoming parameters (easy!)
  924. *
  925. */
  926. static int ircomm_tty_control_indication(void *instance, void *sap,
  927. struct sk_buff *skb)
  928. {
  929. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
  930. int clen;
  931. IRDA_ASSERT(self != NULL, return -1;);
  932. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
  933. IRDA_ASSERT(skb != NULL, return -1;);
  934. clen = skb->data[0];
  935. irda_param_extract_all(self, skb->data+1, IRDA_MIN(skb->len-1, clen),
  936. &ircomm_param_info);
  937. /* No need to kfree_skb - see ircomm_control_indication() */
  938. return 0;
  939. }
  940. /*
  941. * Function ircomm_tty_flow_indication (instance, sap, cmd)
  942. *
  943. * This function is called by IrTTP when it wants us to slow down the
  944. * transmission of data. We just mark the hardware as stopped, and wait
  945. * for IrTTP to notify us that things are OK again.
  946. */
  947. static void ircomm_tty_flow_indication(void *instance, void *sap,
  948. LOCAL_FLOW cmd)
  949. {
  950. struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
  951. struct tty_struct *tty;
  952. IRDA_ASSERT(self != NULL, return;);
  953. IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
  954. tty = tty_port_tty_get(&self->port);
  955. switch (cmd) {
  956. case FLOW_START:
  957. pr_debug("%s(), hw start!\n", __func__);
  958. if (tty)
  959. tty->hw_stopped = 0;
  960. /* ircomm_tty_do_softint will take care of the rest */
  961. schedule_work(&self->tqueue);
  962. break;
  963. default: /* If we get here, something is very wrong, better stop */
  964. case FLOW_STOP:
  965. pr_debug("%s(), hw stopped!\n", __func__);
  966. if (tty)
  967. tty->hw_stopped = 1;
  968. break;
  969. }
  970. tty_kref_put(tty);
  971. self->flow = cmd;
  972. }
  973. #ifdef CONFIG_PROC_FS
  974. static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
  975. {
  976. struct tty_struct *tty;
  977. char sep;
  978. seq_printf(m, "State: %s\n", ircomm_tty_state[self->state]);
  979. seq_puts(m, "Service type: ");
  980. if (self->service_type & IRCOMM_9_WIRE)
  981. seq_puts(m, "9_WIRE");
  982. else if (self->service_type & IRCOMM_3_WIRE)
  983. seq_puts(m, "3_WIRE");
  984. else if (self->service_type & IRCOMM_3_WIRE_RAW)
  985. seq_puts(m, "3_WIRE_RAW");
  986. else
  987. seq_puts(m, "No common service type!\n");
  988. seq_putc(m, '\n');
  989. seq_printf(m, "Port name: %s\n", self->settings.port_name);
  990. seq_printf(m, "DTE status:");
  991. sep = ' ';
  992. if (self->settings.dte & IRCOMM_RTS) {
  993. seq_printf(m, "%cRTS", sep);
  994. sep = '|';
  995. }
  996. if (self->settings.dte & IRCOMM_DTR) {
  997. seq_printf(m, "%cDTR", sep);
  998. sep = '|';
  999. }
  1000. seq_putc(m, '\n');
  1001. seq_puts(m, "DCE status:");
  1002. sep = ' ';
  1003. if (self->settings.dce & IRCOMM_CTS) {
  1004. seq_printf(m, "%cCTS", sep);
  1005. sep = '|';
  1006. }
  1007. if (self->settings.dce & IRCOMM_DSR) {
  1008. seq_printf(m, "%cDSR", sep);
  1009. sep = '|';
  1010. }
  1011. if (self->settings.dce & IRCOMM_CD) {
  1012. seq_printf(m, "%cCD", sep);
  1013. sep = '|';
  1014. }
  1015. if (self->settings.dce & IRCOMM_RI) {
  1016. seq_printf(m, "%cRI", sep);
  1017. sep = '|';
  1018. }
  1019. seq_putc(m, '\n');
  1020. seq_puts(m, "Configuration: ");
  1021. if (!self->settings.null_modem)
  1022. seq_puts(m, "DTE <-> DCE\n");
  1023. else
  1024. seq_puts(m, "DTE <-> DTE (null modem emulation)\n");
  1025. seq_printf(m, "Data rate: %d\n", self->settings.data_rate);
  1026. seq_puts(m, "Flow control:");
  1027. sep = ' ';
  1028. if (self->settings.flow_control & IRCOMM_XON_XOFF_IN) {
  1029. seq_printf(m, "%cXON_XOFF_IN", sep);
  1030. sep = '|';
  1031. }
  1032. if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT) {
  1033. seq_printf(m, "%cXON_XOFF_OUT", sep);
  1034. sep = '|';
  1035. }
  1036. if (self->settings.flow_control & IRCOMM_RTS_CTS_IN) {
  1037. seq_printf(m, "%cRTS_CTS_IN", sep);
  1038. sep = '|';
  1039. }
  1040. if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT) {
  1041. seq_printf(m, "%cRTS_CTS_OUT", sep);
  1042. sep = '|';
  1043. }
  1044. if (self->settings.flow_control & IRCOMM_DSR_DTR_IN) {
  1045. seq_printf(m, "%cDSR_DTR_IN", sep);
  1046. sep = '|';
  1047. }
  1048. if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT) {
  1049. seq_printf(m, "%cDSR_DTR_OUT", sep);
  1050. sep = '|';
  1051. }
  1052. if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN) {
  1053. seq_printf(m, "%cENQ_ACK_IN", sep);
  1054. sep = '|';
  1055. }
  1056. if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT) {
  1057. seq_printf(m, "%cENQ_ACK_OUT", sep);
  1058. sep = '|';
  1059. }
  1060. seq_putc(m, '\n');
  1061. seq_puts(m, "Flags:");
  1062. sep = ' ';
  1063. if (tty_port_cts_enabled(&self->port)) {
  1064. seq_printf(m, "%cASYNC_CTS_FLOW", sep);
  1065. sep = '|';
  1066. }
  1067. if (self->port.flags & ASYNC_CHECK_CD) {
  1068. seq_printf(m, "%cASYNC_CHECK_CD", sep);
  1069. sep = '|';
  1070. }
  1071. if (self->port.flags & ASYNC_INITIALIZED) {
  1072. seq_printf(m, "%cASYNC_INITIALIZED", sep);
  1073. sep = '|';
  1074. }
  1075. if (self->port.flags & ASYNC_LOW_LATENCY) {
  1076. seq_printf(m, "%cASYNC_LOW_LATENCY", sep);
  1077. sep = '|';
  1078. }
  1079. if (self->port.flags & ASYNC_NORMAL_ACTIVE) {
  1080. seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep);
  1081. sep = '|';
  1082. }
  1083. seq_putc(m, '\n');
  1084. seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
  1085. seq_printf(m, "Open count: %d\n", self->port.count);
  1086. seq_printf(m, "Max data size: %d\n", self->max_data_size);
  1087. seq_printf(m, "Max header size: %d\n", self->max_header_size);
  1088. tty = tty_port_tty_get(&self->port);
  1089. if (tty) {
  1090. seq_printf(m, "Hardware: %s\n",
  1091. tty->hw_stopped ? "Stopped" : "Running");
  1092. tty_kref_put(tty);
  1093. }
  1094. }
  1095. static int ircomm_tty_proc_show(struct seq_file *m, void *v)
  1096. {
  1097. struct ircomm_tty_cb *self;
  1098. unsigned long flags;
  1099. spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags);
  1100. self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
  1101. while (self != NULL) {
  1102. if (self->magic != IRCOMM_TTY_MAGIC)
  1103. break;
  1104. ircomm_tty_line_info(self, m);
  1105. self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
  1106. }
  1107. spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags);
  1108. return 0;
  1109. }
  1110. static int ircomm_tty_proc_open(struct inode *inode, struct file *file)
  1111. {
  1112. return single_open(file, ircomm_tty_proc_show, NULL);
  1113. }
  1114. static const struct file_operations ircomm_tty_proc_fops = {
  1115. .owner = THIS_MODULE,
  1116. .open = ircomm_tty_proc_open,
  1117. .read = seq_read,
  1118. .llseek = seq_lseek,
  1119. .release = single_release,
  1120. };
  1121. #endif /* CONFIG_PROC_FS */
  1122. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  1123. MODULE_DESCRIPTION("IrCOMM serial TTY driver");
  1124. MODULE_LICENSE("GPL");
  1125. MODULE_ALIAS_CHARDEV_MAJOR(IRCOMM_TTY_MAJOR);
  1126. module_init(ircomm_tty_init);
  1127. module_exit(ircomm_tty_cleanup);