jsm_tty.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. /************************************************************************
  2. * Copyright 2003 Digi International (www.digi.com)
  3. *
  4. * Copyright (C) 2004 IBM Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  13. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. * PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
  19. * MA 02111-1307, USA.
  20. *
  21. * Contact Information:
  22. * Scott H Kilau <Scott_Kilau@digi.com>
  23. * Ananda Venkatarman <mansarov@us.ibm.com>
  24. * Modifications:
  25. * 01/19/06: changed jsm_input routine to use the dynamically allocated
  26. * tty_buffer changes. Contributors: Scott Kilau and Ananda V.
  27. ***********************************************************************/
  28. #include <linux/tty.h>
  29. #include <linux/tty_flip.h>
  30. #include <linux/serial_reg.h>
  31. #include <linux/delay.h> /* For udelay */
  32. #include <linux/pci.h>
  33. #include <linux/slab.h>
  34. #include "jsm.h"
  35. static DECLARE_BITMAP(linemap, MAXLINES);
  36. static void jsm_carrier(struct jsm_channel *ch);
  37. static inline int jsm_get_mstat(struct jsm_channel *ch)
  38. {
  39. unsigned char mstat;
  40. unsigned result;
  41. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, "start\n");
  42. mstat = (ch->ch_mostat | ch->ch_mistat);
  43. result = 0;
  44. if (mstat & UART_MCR_DTR)
  45. result |= TIOCM_DTR;
  46. if (mstat & UART_MCR_RTS)
  47. result |= TIOCM_RTS;
  48. if (mstat & UART_MSR_CTS)
  49. result |= TIOCM_CTS;
  50. if (mstat & UART_MSR_DSR)
  51. result |= TIOCM_DSR;
  52. if (mstat & UART_MSR_RI)
  53. result |= TIOCM_RI;
  54. if (mstat & UART_MSR_DCD)
  55. result |= TIOCM_CD;
  56. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, "finish\n");
  57. return result;
  58. }
  59. static unsigned int jsm_tty_tx_empty(struct uart_port *port)
  60. {
  61. return TIOCSER_TEMT;
  62. }
  63. /*
  64. * Return modem signals to ld.
  65. */
  66. static unsigned int jsm_tty_get_mctrl(struct uart_port *port)
  67. {
  68. int result;
  69. struct jsm_channel *channel = (struct jsm_channel *)port;
  70. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
  71. result = jsm_get_mstat(channel);
  72. if (result < 0)
  73. return -ENXIO;
  74. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n");
  75. return result;
  76. }
  77. /*
  78. * jsm_set_modem_info()
  79. *
  80. * Set modem signals, called by ld.
  81. */
  82. static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl)
  83. {
  84. struct jsm_channel *channel = (struct jsm_channel *)port;
  85. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
  86. if (mctrl & TIOCM_RTS)
  87. channel->ch_mostat |= UART_MCR_RTS;
  88. else
  89. channel->ch_mostat &= ~UART_MCR_RTS;
  90. if (mctrl & TIOCM_DTR)
  91. channel->ch_mostat |= UART_MCR_DTR;
  92. else
  93. channel->ch_mostat &= ~UART_MCR_DTR;
  94. channel->ch_bd->bd_ops->assert_modem_signals(channel);
  95. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n");
  96. udelay(10);
  97. }
  98. /*
  99. * jsm_tty_write()
  100. *
  101. * Take data from the user or kernel and send it out to the FEP.
  102. * In here exists all the Transparent Print magic as well.
  103. */
  104. static void jsm_tty_write(struct uart_port *port)
  105. {
  106. struct jsm_channel *channel;
  107. channel = container_of(port, struct jsm_channel, uart_port);
  108. channel->ch_bd->bd_ops->copy_data_from_queue_to_uart(channel);
  109. }
  110. static void jsm_tty_start_tx(struct uart_port *port)
  111. {
  112. struct jsm_channel *channel = (struct jsm_channel *)port;
  113. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
  114. channel->ch_flags &= ~(CH_STOP);
  115. jsm_tty_write(port);
  116. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n");
  117. }
  118. static void jsm_tty_stop_tx(struct uart_port *port)
  119. {
  120. struct jsm_channel *channel = (struct jsm_channel *)port;
  121. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
  122. channel->ch_flags |= (CH_STOP);
  123. jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n");
  124. }
  125. static void jsm_tty_send_xchar(struct uart_port *port, char ch)
  126. {
  127. unsigned long lock_flags;
  128. struct jsm_channel *channel = (struct jsm_channel *)port;
  129. struct ktermios *termios;
  130. spin_lock_irqsave(&port->lock, lock_flags);
  131. termios = &port->state->port.tty->termios;
  132. if (ch == termios->c_cc[VSTART])
  133. channel->ch_bd->bd_ops->send_start_character(channel);
  134. if (ch == termios->c_cc[VSTOP])
  135. channel->ch_bd->bd_ops->send_stop_character(channel);
  136. spin_unlock_irqrestore(&port->lock, lock_flags);
  137. }
  138. static void jsm_tty_stop_rx(struct uart_port *port)
  139. {
  140. struct jsm_channel *channel = (struct jsm_channel *)port;
  141. channel->ch_bd->bd_ops->disable_receiver(channel);
  142. }
  143. static void jsm_tty_enable_ms(struct uart_port *port)
  144. {
  145. /* Nothing needed */
  146. }
  147. static void jsm_tty_break(struct uart_port *port, int break_state)
  148. {
  149. unsigned long lock_flags;
  150. struct jsm_channel *channel = (struct jsm_channel *)port;
  151. spin_lock_irqsave(&port->lock, lock_flags);
  152. if (break_state == -1)
  153. channel->ch_bd->bd_ops->send_break(channel);
  154. else
  155. channel->ch_bd->bd_ops->clear_break(channel, 0);
  156. spin_unlock_irqrestore(&port->lock, lock_flags);
  157. }
  158. static int jsm_tty_open(struct uart_port *port)
  159. {
  160. struct jsm_board *brd;
  161. struct jsm_channel *channel = (struct jsm_channel *)port;
  162. struct ktermios *termios;
  163. /* Get board pointer from our array of majors we have allocated */
  164. brd = channel->ch_bd;
  165. /*
  166. * Allocate channel buffers for read/write/error.
  167. * Set flag, so we don't get trounced on.
  168. */
  169. channel->ch_flags |= (CH_OPENING);
  170. /* Drop locks, as malloc with GFP_KERNEL can sleep */
  171. if (!channel->ch_rqueue) {
  172. channel->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
  173. if (!channel->ch_rqueue) {
  174. jsm_dbg(INIT, &channel->ch_bd->pci_dev,
  175. "unable to allocate read queue buf\n");
  176. return -ENOMEM;
  177. }
  178. }
  179. if (!channel->ch_equeue) {
  180. channel->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
  181. if (!channel->ch_equeue) {
  182. jsm_dbg(INIT, &channel->ch_bd->pci_dev,
  183. "unable to allocate error queue buf\n");
  184. return -ENOMEM;
  185. }
  186. }
  187. channel->ch_flags &= ~(CH_OPENING);
  188. /*
  189. * Initialize if neither terminal is open.
  190. */
  191. jsm_dbg(OPEN, &channel->ch_bd->pci_dev,
  192. "jsm_open: initializing channel in open...\n");
  193. /*
  194. * Flush input queues.
  195. */
  196. channel->ch_r_head = channel->ch_r_tail = 0;
  197. channel->ch_e_head = channel->ch_e_tail = 0;
  198. brd->bd_ops->flush_uart_write(channel);
  199. brd->bd_ops->flush_uart_read(channel);
  200. channel->ch_flags = 0;
  201. channel->ch_cached_lsr = 0;
  202. channel->ch_stops_sent = 0;
  203. termios = &port->state->port.tty->termios;
  204. channel->ch_c_cflag = termios->c_cflag;
  205. channel->ch_c_iflag = termios->c_iflag;
  206. channel->ch_c_oflag = termios->c_oflag;
  207. channel->ch_c_lflag = termios->c_lflag;
  208. channel->ch_startc = termios->c_cc[VSTART];
  209. channel->ch_stopc = termios->c_cc[VSTOP];
  210. /* Tell UART to init itself */
  211. brd->bd_ops->uart_init(channel);
  212. /*
  213. * Run param in case we changed anything
  214. */
  215. brd->bd_ops->param(channel);
  216. jsm_carrier(channel);
  217. channel->ch_open_count++;
  218. jsm_dbg(OPEN, &channel->ch_bd->pci_dev, "finish\n");
  219. return 0;
  220. }
  221. static void jsm_tty_close(struct uart_port *port)
  222. {
  223. struct jsm_board *bd;
  224. struct ktermios *ts;
  225. struct jsm_channel *channel = (struct jsm_channel *)port;
  226. jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, "start\n");
  227. bd = channel->ch_bd;
  228. ts = &port->state->port.tty->termios;
  229. channel->ch_flags &= ~(CH_STOPI);
  230. channel->ch_open_count--;
  231. /*
  232. * If we have HUPCL set, lower DTR and RTS
  233. */
  234. if (channel->ch_c_cflag & HUPCL) {
  235. jsm_dbg(CLOSE, &channel->ch_bd->pci_dev,
  236. "Close. HUPCL set, dropping DTR/RTS\n");
  237. /* Drop RTS/DTR */
  238. channel->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
  239. bd->bd_ops->assert_modem_signals(channel);
  240. }
  241. /* Turn off UART interrupts for this port */
  242. channel->ch_bd->bd_ops->uart_off(channel);
  243. jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, "finish\n");
  244. }
  245. static void jsm_tty_set_termios(struct uart_port *port,
  246. struct ktermios *termios,
  247. struct ktermios *old_termios)
  248. {
  249. unsigned long lock_flags;
  250. struct jsm_channel *channel = (struct jsm_channel *)port;
  251. spin_lock_irqsave(&port->lock, lock_flags);
  252. channel->ch_c_cflag = termios->c_cflag;
  253. channel->ch_c_iflag = termios->c_iflag;
  254. channel->ch_c_oflag = termios->c_oflag;
  255. channel->ch_c_lflag = termios->c_lflag;
  256. channel->ch_startc = termios->c_cc[VSTART];
  257. channel->ch_stopc = termios->c_cc[VSTOP];
  258. channel->ch_bd->bd_ops->param(channel);
  259. jsm_carrier(channel);
  260. spin_unlock_irqrestore(&port->lock, lock_flags);
  261. }
  262. static const char *jsm_tty_type(struct uart_port *port)
  263. {
  264. return "jsm";
  265. }
  266. static void jsm_tty_release_port(struct uart_port *port)
  267. {
  268. }
  269. static int jsm_tty_request_port(struct uart_port *port)
  270. {
  271. return 0;
  272. }
  273. static void jsm_config_port(struct uart_port *port, int flags)
  274. {
  275. port->type = PORT_JSM;
  276. }
  277. static struct uart_ops jsm_ops = {
  278. .tx_empty = jsm_tty_tx_empty,
  279. .set_mctrl = jsm_tty_set_mctrl,
  280. .get_mctrl = jsm_tty_get_mctrl,
  281. .stop_tx = jsm_tty_stop_tx,
  282. .start_tx = jsm_tty_start_tx,
  283. .send_xchar = jsm_tty_send_xchar,
  284. .stop_rx = jsm_tty_stop_rx,
  285. .enable_ms = jsm_tty_enable_ms,
  286. .break_ctl = jsm_tty_break,
  287. .startup = jsm_tty_open,
  288. .shutdown = jsm_tty_close,
  289. .set_termios = jsm_tty_set_termios,
  290. .type = jsm_tty_type,
  291. .release_port = jsm_tty_release_port,
  292. .request_port = jsm_tty_request_port,
  293. .config_port = jsm_config_port,
  294. };
  295. /*
  296. * jsm_tty_init()
  297. *
  298. * Init the tty subsystem. Called once per board after board has been
  299. * downloaded and init'ed.
  300. */
  301. int jsm_tty_init(struct jsm_board *brd)
  302. {
  303. int i;
  304. void __iomem *vaddr;
  305. struct jsm_channel *ch;
  306. if (!brd)
  307. return -ENXIO;
  308. jsm_dbg(INIT, &brd->pci_dev, "start\n");
  309. /*
  310. * Initialize board structure elements.
  311. */
  312. brd->nasync = brd->maxports;
  313. /*
  314. * Allocate channel memory that might not have been allocated
  315. * when the driver was first loaded.
  316. */
  317. for (i = 0; i < brd->nasync; i++) {
  318. if (!brd->channels[i]) {
  319. /*
  320. * Okay to malloc with GFP_KERNEL, we are not at
  321. * interrupt context, and there are no locks held.
  322. */
  323. brd->channels[i] = kzalloc(sizeof(struct jsm_channel), GFP_KERNEL);
  324. if (!brd->channels[i]) {
  325. jsm_dbg(CORE, &brd->pci_dev,
  326. "%s:%d Unable to allocate memory for channel struct\n",
  327. __FILE__, __LINE__);
  328. }
  329. }
  330. }
  331. ch = brd->channels[0];
  332. vaddr = brd->re_map_membase;
  333. /* Set up channel variables */
  334. for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
  335. if (!brd->channels[i])
  336. continue;
  337. spin_lock_init(&ch->ch_lock);
  338. if (brd->bd_uart_offset == 0x200)
  339. ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
  340. ch->ch_bd = brd;
  341. ch->ch_portnum = i;
  342. /* .25 second delay */
  343. ch->ch_close_delay = 250;
  344. init_waitqueue_head(&ch->ch_flags_wait);
  345. }
  346. jsm_dbg(INIT, &brd->pci_dev, "finish\n");
  347. return 0;
  348. }
  349. int jsm_uart_port_init(struct jsm_board *brd)
  350. {
  351. int i, rc;
  352. unsigned int line;
  353. struct jsm_channel *ch;
  354. if (!brd)
  355. return -ENXIO;
  356. jsm_dbg(INIT, &brd->pci_dev, "start\n");
  357. /*
  358. * Initialize board structure elements.
  359. */
  360. brd->nasync = brd->maxports;
  361. /* Set up channel variables */
  362. for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
  363. if (!brd->channels[i])
  364. continue;
  365. brd->channels[i]->uart_port.irq = brd->irq;
  366. brd->channels[i]->uart_port.uartclk = 14745600;
  367. brd->channels[i]->uart_port.type = PORT_JSM;
  368. brd->channels[i]->uart_port.iotype = UPIO_MEM;
  369. brd->channels[i]->uart_port.membase = brd->re_map_membase;
  370. brd->channels[i]->uart_port.fifosize = 16;
  371. brd->channels[i]->uart_port.ops = &jsm_ops;
  372. line = find_first_zero_bit(linemap, MAXLINES);
  373. if (line >= MAXLINES) {
  374. printk(KERN_INFO "jsm: linemap is full, added device failed\n");
  375. continue;
  376. } else
  377. set_bit(line, linemap);
  378. brd->channels[i]->uart_port.line = line;
  379. rc = uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port);
  380. if (rc){
  381. printk(KERN_INFO "jsm: Port %d failed. Aborting...\n", i);
  382. return rc;
  383. }
  384. else
  385. printk(KERN_INFO "jsm: Port %d added\n", i);
  386. }
  387. jsm_dbg(INIT, &brd->pci_dev, "finish\n");
  388. return 0;
  389. }
  390. int jsm_remove_uart_port(struct jsm_board *brd)
  391. {
  392. int i;
  393. struct jsm_channel *ch;
  394. if (!brd)
  395. return -ENXIO;
  396. jsm_dbg(INIT, &brd->pci_dev, "start\n");
  397. /*
  398. * Initialize board structure elements.
  399. */
  400. brd->nasync = brd->maxports;
  401. /* Set up channel variables */
  402. for (i = 0; i < brd->nasync; i++) {
  403. if (!brd->channels[i])
  404. continue;
  405. ch = brd->channels[i];
  406. clear_bit(ch->uart_port.line, linemap);
  407. uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port);
  408. }
  409. jsm_dbg(INIT, &brd->pci_dev, "finish\n");
  410. return 0;
  411. }
  412. void jsm_input(struct jsm_channel *ch)
  413. {
  414. struct jsm_board *bd;
  415. struct tty_struct *tp;
  416. struct tty_port *port;
  417. u32 rmask;
  418. u16 head;
  419. u16 tail;
  420. int data_len;
  421. unsigned long lock_flags;
  422. int len = 0;
  423. int n = 0;
  424. int s = 0;
  425. int i = 0;
  426. jsm_dbg(READ, &ch->ch_bd->pci_dev, "start\n");
  427. if (!ch)
  428. return;
  429. port = &ch->uart_port.state->port;
  430. tp = port->tty;
  431. bd = ch->ch_bd;
  432. if(!bd)
  433. return;
  434. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  435. /*
  436. *Figure the number of characters in the buffer.
  437. *Exit immediately if none.
  438. */
  439. rmask = RQUEUEMASK;
  440. head = ch->ch_r_head & rmask;
  441. tail = ch->ch_r_tail & rmask;
  442. data_len = (head - tail) & rmask;
  443. if (data_len == 0) {
  444. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  445. return;
  446. }
  447. jsm_dbg(READ, &ch->ch_bd->pci_dev, "start\n");
  448. /*
  449. *If the device is not open, or CREAD is off, flush
  450. *input data and return immediately.
  451. */
  452. if (!tp ||
  453. !(tp->termios.c_cflag & CREAD) ) {
  454. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  455. "input. dropping %d bytes on port %d...\n",
  456. data_len, ch->ch_portnum);
  457. ch->ch_r_head = tail;
  458. /* Force queue flow control to be released, if needed */
  459. jsm_check_queue_flow_control(ch);
  460. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  461. return;
  462. }
  463. /*
  464. * If we are throttled, simply don't read any data.
  465. */
  466. if (ch->ch_flags & CH_STOPI) {
  467. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  468. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  469. "Port %d throttled, not reading any data. head: %x tail: %x\n",
  470. ch->ch_portnum, head, tail);
  471. return;
  472. }
  473. jsm_dbg(READ, &ch->ch_bd->pci_dev, "start 2\n");
  474. if (data_len <= 0) {
  475. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  476. jsm_dbg(READ, &ch->ch_bd->pci_dev, "jsm_input 1\n");
  477. return;
  478. }
  479. len = tty_buffer_request_room(port, data_len);
  480. n = len;
  481. /*
  482. * n now contains the most amount of data we can copy,
  483. * bounded either by the flip buffer size or the amount
  484. * of data the card actually has pending...
  485. */
  486. while (n) {
  487. s = ((head >= tail) ? head : RQUEUESIZE) - tail;
  488. s = min(s, n);
  489. if (s <= 0)
  490. break;
  491. /*
  492. * If conditions are such that ld needs to see all
  493. * UART errors, we will have to walk each character
  494. * and error byte and send them to the buffer one at
  495. * a time.
  496. */
  497. if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
  498. for (i = 0; i < s; i++) {
  499. /*
  500. * Give the Linux ld the flags in the
  501. * format it likes.
  502. */
  503. if (*(ch->ch_equeue +tail +i) & UART_LSR_BI)
  504. tty_insert_flip_char(port, *(ch->ch_rqueue +tail +i), TTY_BREAK);
  505. else if (*(ch->ch_equeue +tail +i) & UART_LSR_PE)
  506. tty_insert_flip_char(port, *(ch->ch_rqueue +tail +i), TTY_PARITY);
  507. else if (*(ch->ch_equeue +tail +i) & UART_LSR_FE)
  508. tty_insert_flip_char(port, *(ch->ch_rqueue +tail +i), TTY_FRAME);
  509. else
  510. tty_insert_flip_char(port, *(ch->ch_rqueue +tail +i), TTY_NORMAL);
  511. }
  512. } else {
  513. tty_insert_flip_string(port, ch->ch_rqueue + tail, s);
  514. }
  515. tail += s;
  516. n -= s;
  517. /* Flip queue if needed */
  518. tail &= rmask;
  519. }
  520. ch->ch_r_tail = tail & rmask;
  521. ch->ch_e_tail = tail & rmask;
  522. jsm_check_queue_flow_control(ch);
  523. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  524. /* Tell the tty layer its okay to "eat" the data now */
  525. tty_flip_buffer_push(port);
  526. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, "finish\n");
  527. }
  528. static void jsm_carrier(struct jsm_channel *ch)
  529. {
  530. struct jsm_board *bd;
  531. int virt_carrier = 0;
  532. int phys_carrier = 0;
  533. jsm_dbg(CARR, &ch->ch_bd->pci_dev, "start\n");
  534. if (!ch)
  535. return;
  536. bd = ch->ch_bd;
  537. if (!bd)
  538. return;
  539. if (ch->ch_mistat & UART_MSR_DCD) {
  540. jsm_dbg(CARR, &ch->ch_bd->pci_dev, "mistat: %x D_CD: %x\n",
  541. ch->ch_mistat, ch->ch_mistat & UART_MSR_DCD);
  542. phys_carrier = 1;
  543. }
  544. if (ch->ch_c_cflag & CLOCAL)
  545. virt_carrier = 1;
  546. jsm_dbg(CARR, &ch->ch_bd->pci_dev, "DCD: physical: %d virt: %d\n",
  547. phys_carrier, virt_carrier);
  548. /*
  549. * Test for a VIRTUAL carrier transition to HIGH.
  550. */
  551. if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
  552. /*
  553. * When carrier rises, wake any threads waiting
  554. * for carrier in the open routine.
  555. */
  556. jsm_dbg(CARR, &ch->ch_bd->pci_dev, "carrier: virt DCD rose\n");
  557. if (waitqueue_active(&(ch->ch_flags_wait)))
  558. wake_up_interruptible(&ch->ch_flags_wait);
  559. }
  560. /*
  561. * Test for a PHYSICAL carrier transition to HIGH.
  562. */
  563. if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
  564. /*
  565. * When carrier rises, wake any threads waiting
  566. * for carrier in the open routine.
  567. */
  568. jsm_dbg(CARR, &ch->ch_bd->pci_dev,
  569. "carrier: physical DCD rose\n");
  570. if (waitqueue_active(&(ch->ch_flags_wait)))
  571. wake_up_interruptible(&ch->ch_flags_wait);
  572. }
  573. /*
  574. * Test for a PHYSICAL transition to low, so long as we aren't
  575. * currently ignoring physical transitions (which is what "virtual
  576. * carrier" indicates).
  577. *
  578. * The transition of the virtual carrier to low really doesn't
  579. * matter... it really only means "ignore carrier state", not
  580. * "make pretend that carrier is there".
  581. */
  582. if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0)
  583. && (phys_carrier == 0)) {
  584. /*
  585. * When carrier drops:
  586. *
  587. * Drop carrier on all open units.
  588. *
  589. * Flush queues, waking up any task waiting in the
  590. * line discipline.
  591. *
  592. * Send a hangup to the control terminal.
  593. *
  594. * Enable all select calls.
  595. */
  596. if (waitqueue_active(&(ch->ch_flags_wait)))
  597. wake_up_interruptible(&ch->ch_flags_wait);
  598. }
  599. /*
  600. * Make sure that our cached values reflect the current reality.
  601. */
  602. if (virt_carrier == 1)
  603. ch->ch_flags |= CH_FCAR;
  604. else
  605. ch->ch_flags &= ~CH_FCAR;
  606. if (phys_carrier == 1)
  607. ch->ch_flags |= CH_CD;
  608. else
  609. ch->ch_flags &= ~CH_CD;
  610. }
  611. void jsm_check_queue_flow_control(struct jsm_channel *ch)
  612. {
  613. struct board_ops *bd_ops = ch->ch_bd->bd_ops;
  614. int qleft;
  615. /* Store how much space we have left in the queue */
  616. if ((qleft = ch->ch_r_tail - ch->ch_r_head - 1) < 0)
  617. qleft += RQUEUEMASK + 1;
  618. /*
  619. * Check to see if we should enforce flow control on our queue because
  620. * the ld (or user) isn't reading data out of our queue fast enuf.
  621. *
  622. * NOTE: This is done based on what the current flow control of the
  623. * port is set for.
  624. *
  625. * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
  626. * This will cause the UART's FIFO to back up, and force
  627. * the RTS signal to be dropped.
  628. * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
  629. * the other side, in hopes it will stop sending data to us.
  630. * 3) NONE - Nothing we can do. We will simply drop any extra data
  631. * that gets sent into us when the queue fills up.
  632. */
  633. if (qleft < 256) {
  634. /* HWFLOW */
  635. if (ch->ch_c_cflag & CRTSCTS) {
  636. if(!(ch->ch_flags & CH_RECEIVER_OFF)) {
  637. bd_ops->disable_receiver(ch);
  638. ch->ch_flags |= (CH_RECEIVER_OFF);
  639. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  640. "Internal queue hit hilevel mark (%d)! Turning off interrupts\n",
  641. qleft);
  642. }
  643. }
  644. /* SWFLOW */
  645. else if (ch->ch_c_iflag & IXOFF) {
  646. if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
  647. bd_ops->send_stop_character(ch);
  648. ch->ch_stops_sent++;
  649. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  650. "Sending stop char! Times sent: %x\n",
  651. ch->ch_stops_sent);
  652. }
  653. }
  654. }
  655. /*
  656. * Check to see if we should unenforce flow control because
  657. * ld (or user) finally read enuf data out of our queue.
  658. *
  659. * NOTE: This is done based on what the current flow control of the
  660. * port is set for.
  661. *
  662. * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
  663. * This will cause the UART's FIFO to raise RTS back up,
  664. * which will allow the other side to start sending data again.
  665. * 2) SWFLOW (IXOFF) - Send a start character to
  666. * the other side, so it will start sending data to us again.
  667. * 3) NONE - Do nothing. Since we didn't do anything to turn off the
  668. * other side, we don't need to do anything now.
  669. */
  670. if (qleft > (RQUEUESIZE / 2)) {
  671. /* HWFLOW */
  672. if (ch->ch_c_cflag & CRTSCTS) {
  673. if (ch->ch_flags & CH_RECEIVER_OFF) {
  674. bd_ops->enable_receiver(ch);
  675. ch->ch_flags &= ~(CH_RECEIVER_OFF);
  676. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  677. "Internal queue hit lowlevel mark (%d)! Turning on interrupts\n",
  678. qleft);
  679. }
  680. }
  681. /* SWFLOW */
  682. else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
  683. ch->ch_stops_sent = 0;
  684. bd_ops->send_start_character(ch);
  685. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  686. "Sending start char!\n");
  687. }
  688. }
  689. }