jsm_tty.c 20 KB

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