jsm_tty.c 20 KB

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