jsm_tty.c 23 KB

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