ircomm_tty.c 37 KB

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