jsm_neo.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  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. * Wendy Xiong <wendyx@us.ibm.com>
  10. *
  11. ***********************************************************************/
  12. #include <linux/delay.h> /* For udelay */
  13. #include <linux/serial_reg.h> /* For the various UART offsets */
  14. #include <linux/tty.h>
  15. #include <linux/pci.h>
  16. #include <asm/io.h>
  17. #include "jsm.h" /* Driver main header file */
  18. static u32 jsm_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
  19. /*
  20. * This function allows calls to ensure that all outstanding
  21. * PCI writes have been completed, by doing a PCI read against
  22. * a non-destructive, read-only location on the Neo card.
  23. *
  24. * In this case, we are reading the DVID (Read-only Device Identification)
  25. * value of the Neo card.
  26. */
  27. static inline void neo_pci_posting_flush(struct jsm_board *bd)
  28. {
  29. readb(bd->re_map_membase + 0x8D);
  30. }
  31. static void neo_set_cts_flow_control(struct jsm_channel *ch)
  32. {
  33. u8 ier, efr;
  34. ier = readb(&ch->ch_neo_uart->ier);
  35. efr = readb(&ch->ch_neo_uart->efr);
  36. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n");
  37. /* Turn on auto CTS flow control */
  38. ier |= (UART_17158_IER_CTSDSR);
  39. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_CTSDSR);
  40. /* Turn off auto Xon flow control */
  41. efr &= ~(UART_17158_EFR_IXON);
  42. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  43. writeb(0, &ch->ch_neo_uart->efr);
  44. /* Turn on UART enhanced bits */
  45. writeb(efr, &ch->ch_neo_uart->efr);
  46. /* Turn on table D, with 8 char hi/low watermarks */
  47. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  48. /* Feed the UART our trigger levels */
  49. writeb(8, &ch->ch_neo_uart->tfifo);
  50. ch->ch_t_tlevel = 8;
  51. writeb(ier, &ch->ch_neo_uart->ier);
  52. }
  53. static void neo_set_rts_flow_control(struct jsm_channel *ch)
  54. {
  55. u8 ier, efr;
  56. ier = readb(&ch->ch_neo_uart->ier);
  57. efr = readb(&ch->ch_neo_uart->efr);
  58. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n");
  59. /* Turn on auto RTS flow control */
  60. ier |= (UART_17158_IER_RTSDTR);
  61. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_RTSDTR);
  62. /* Turn off auto Xoff flow control */
  63. ier &= ~(UART_17158_IER_XOFF);
  64. efr &= ~(UART_17158_EFR_IXOFF);
  65. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  66. writeb(0, &ch->ch_neo_uart->efr);
  67. /* Turn on UART enhanced bits */
  68. writeb(efr, &ch->ch_neo_uart->efr);
  69. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  70. ch->ch_r_watermark = 4;
  71. writeb(56, &ch->ch_neo_uart->rfifo);
  72. ch->ch_r_tlevel = 56;
  73. writeb(ier, &ch->ch_neo_uart->ier);
  74. /*
  75. * From the Neo UART spec sheet:
  76. * The auto RTS/DTR function must be started by asserting
  77. * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
  78. * it is enabled.
  79. */
  80. ch->ch_mostat |= (UART_MCR_RTS);
  81. }
  82. static void neo_set_ixon_flow_control(struct jsm_channel *ch)
  83. {
  84. u8 ier, efr;
  85. ier = readb(&ch->ch_neo_uart->ier);
  86. efr = readb(&ch->ch_neo_uart->efr);
  87. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n");
  88. /* Turn off auto CTS flow control */
  89. ier &= ~(UART_17158_IER_CTSDSR);
  90. efr &= ~(UART_17158_EFR_CTSDSR);
  91. /* Turn on auto Xon flow control */
  92. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  93. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  94. writeb(0, &ch->ch_neo_uart->efr);
  95. /* Turn on UART enhanced bits */
  96. writeb(efr, &ch->ch_neo_uart->efr);
  97. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  98. ch->ch_r_watermark = 4;
  99. writeb(32, &ch->ch_neo_uart->rfifo);
  100. ch->ch_r_tlevel = 32;
  101. /* Tell UART what start/stop chars it should be looking for */
  102. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  103. writeb(0, &ch->ch_neo_uart->xonchar2);
  104. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  105. writeb(0, &ch->ch_neo_uart->xoffchar2);
  106. writeb(ier, &ch->ch_neo_uart->ier);
  107. }
  108. static void neo_set_ixoff_flow_control(struct jsm_channel *ch)
  109. {
  110. u8 ier, efr;
  111. ier = readb(&ch->ch_neo_uart->ier);
  112. efr = readb(&ch->ch_neo_uart->efr);
  113. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n");
  114. /* Turn off auto RTS flow control */
  115. ier &= ~(UART_17158_IER_RTSDTR);
  116. efr &= ~(UART_17158_EFR_RTSDTR);
  117. /* Turn on auto Xoff flow control */
  118. ier |= (UART_17158_IER_XOFF);
  119. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  120. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  121. writeb(0, &ch->ch_neo_uart->efr);
  122. /* Turn on UART enhanced bits */
  123. writeb(efr, &ch->ch_neo_uart->efr);
  124. /* Turn on table D, with 8 char hi/low watermarks */
  125. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  126. writeb(8, &ch->ch_neo_uart->tfifo);
  127. ch->ch_t_tlevel = 8;
  128. /* Tell UART what start/stop chars it should be looking for */
  129. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  130. writeb(0, &ch->ch_neo_uart->xonchar2);
  131. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  132. writeb(0, &ch->ch_neo_uart->xoffchar2);
  133. writeb(ier, &ch->ch_neo_uart->ier);
  134. }
  135. static void neo_set_no_input_flow_control(struct jsm_channel *ch)
  136. {
  137. u8 ier, efr;
  138. ier = readb(&ch->ch_neo_uart->ier);
  139. efr = readb(&ch->ch_neo_uart->efr);
  140. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n");
  141. /* Turn off auto RTS flow control */
  142. ier &= ~(UART_17158_IER_RTSDTR);
  143. efr &= ~(UART_17158_EFR_RTSDTR);
  144. /* Turn off auto Xoff flow control */
  145. ier &= ~(UART_17158_IER_XOFF);
  146. if (ch->ch_c_iflag & IXON)
  147. efr &= ~(UART_17158_EFR_IXOFF);
  148. else
  149. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  150. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  151. writeb(0, &ch->ch_neo_uart->efr);
  152. /* Turn on UART enhanced bits */
  153. writeb(efr, &ch->ch_neo_uart->efr);
  154. /* Turn on table D, with 8 char hi/low watermarks */
  155. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  156. ch->ch_r_watermark = 0;
  157. writeb(16, &ch->ch_neo_uart->tfifo);
  158. ch->ch_t_tlevel = 16;
  159. writeb(16, &ch->ch_neo_uart->rfifo);
  160. ch->ch_r_tlevel = 16;
  161. writeb(ier, &ch->ch_neo_uart->ier);
  162. }
  163. static void neo_set_no_output_flow_control(struct jsm_channel *ch)
  164. {
  165. u8 ier, efr;
  166. ier = readb(&ch->ch_neo_uart->ier);
  167. efr = readb(&ch->ch_neo_uart->efr);
  168. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n");
  169. /* Turn off auto CTS flow control */
  170. ier &= ~(UART_17158_IER_CTSDSR);
  171. efr &= ~(UART_17158_EFR_CTSDSR);
  172. /* Turn off auto Xon flow control */
  173. if (ch->ch_c_iflag & IXOFF)
  174. efr &= ~(UART_17158_EFR_IXON);
  175. else
  176. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  177. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  178. writeb(0, &ch->ch_neo_uart->efr);
  179. /* Turn on UART enhanced bits */
  180. writeb(efr, &ch->ch_neo_uart->efr);
  181. /* Turn on table D, with 8 char hi/low watermarks */
  182. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  183. ch->ch_r_watermark = 0;
  184. writeb(16, &ch->ch_neo_uart->tfifo);
  185. ch->ch_t_tlevel = 16;
  186. writeb(16, &ch->ch_neo_uart->rfifo);
  187. ch->ch_r_tlevel = 16;
  188. writeb(ier, &ch->ch_neo_uart->ier);
  189. }
  190. static inline void neo_set_new_start_stop_chars(struct jsm_channel *ch)
  191. {
  192. /* if hardware flow control is set, then skip this whole thing */
  193. if (ch->ch_c_cflag & CRTSCTS)
  194. return;
  195. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "start\n");
  196. /* Tell UART what start/stop chars it should be looking for */
  197. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  198. writeb(0, &ch->ch_neo_uart->xonchar2);
  199. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  200. writeb(0, &ch->ch_neo_uart->xoffchar2);
  201. }
  202. static void neo_copy_data_from_uart_to_queue(struct jsm_channel *ch)
  203. {
  204. int qleft = 0;
  205. u8 linestatus = 0;
  206. u8 error_mask = 0;
  207. int n = 0;
  208. int total = 0;
  209. u16 head;
  210. u16 tail;
  211. /* cache head and tail of queue */
  212. head = ch->ch_r_head & RQUEUEMASK;
  213. tail = ch->ch_r_tail & RQUEUEMASK;
  214. /* Get our cached LSR */
  215. linestatus = ch->ch_cached_lsr;
  216. ch->ch_cached_lsr = 0;
  217. /* Store how much space we have left in the queue */
  218. if ((qleft = tail - head - 1) < 0)
  219. qleft += RQUEUEMASK + 1;
  220. /*
  221. * If the UART is not in FIFO mode, force the FIFO copy to
  222. * NOT be run, by setting total to 0.
  223. *
  224. * On the other hand, if the UART IS in FIFO mode, then ask
  225. * the UART to give us an approximation of data it has RX'ed.
  226. */
  227. if (!(ch->ch_flags & CH_FIFO_ENABLED))
  228. total = 0;
  229. else {
  230. total = readb(&ch->ch_neo_uart->rfifo);
  231. /*
  232. * EXAR chip bug - RX FIFO COUNT - Fudge factor.
  233. *
  234. * This resolves a problem/bug with the Exar chip that sometimes
  235. * returns a bogus value in the rfifo register.
  236. * The count can be any where from 0-3 bytes "off".
  237. * Bizarre, but true.
  238. */
  239. total -= 3;
  240. }
  241. /*
  242. * Finally, bound the copy to make sure we don't overflow
  243. * our own queue...
  244. * The byte by byte copy loop below this loop this will
  245. * deal with the queue overflow possibility.
  246. */
  247. total = min(total, qleft);
  248. while (total > 0) {
  249. /*
  250. * Grab the linestatus register, we need to check
  251. * to see if there are any errors in the FIFO.
  252. */
  253. linestatus = readb(&ch->ch_neo_uart->lsr);
  254. /*
  255. * Break out if there is a FIFO error somewhere.
  256. * This will allow us to go byte by byte down below,
  257. * finding the exact location of the error.
  258. */
  259. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  260. break;
  261. /* Make sure we don't go over the end of our queue */
  262. n = min(((u32) total), (RQUEUESIZE - (u32) head));
  263. /*
  264. * Cut down n even further if needed, this is to fix
  265. * a problem with memcpy_fromio() with the Neo on the
  266. * IBM pSeries platform.
  267. * 15 bytes max appears to be the magic number.
  268. */
  269. n = min((u32) n, (u32) 12);
  270. /*
  271. * Since we are grabbing the linestatus register, which
  272. * will reset some bits after our read, we need to ensure
  273. * we don't miss our TX FIFO emptys.
  274. */
  275. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
  276. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  277. linestatus = 0;
  278. /* Copy data from uart to the queue */
  279. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
  280. /*
  281. * Since RX_FIFO_DATA_ERROR was 0, we are guaranteed
  282. * that all the data currently in the FIFO is free of
  283. * breaks and parity/frame/orun errors.
  284. */
  285. memset(ch->ch_equeue + head, 0, n);
  286. /* Add to and flip head if needed */
  287. head = (head + n) & RQUEUEMASK;
  288. total -= n;
  289. qleft -= n;
  290. ch->ch_rxcount += n;
  291. }
  292. /*
  293. * Create a mask to determine whether we should
  294. * insert the character (if any) into our queue.
  295. */
  296. if (ch->ch_c_iflag & IGNBRK)
  297. error_mask |= UART_LSR_BI;
  298. /*
  299. * Now cleanup any leftover bytes still in the UART.
  300. * Also deal with any possible queue overflow here as well.
  301. */
  302. while (1) {
  303. /*
  304. * Its possible we have a linestatus from the loop above
  305. * this, so we "OR" on any extra bits.
  306. */
  307. linestatus |= readb(&ch->ch_neo_uart->lsr);
  308. /*
  309. * If the chip tells us there is no more data pending to
  310. * be read, we can then leave.
  311. * But before we do, cache the linestatus, just in case.
  312. */
  313. if (!(linestatus & UART_LSR_DR)) {
  314. ch->ch_cached_lsr = linestatus;
  315. break;
  316. }
  317. /* No need to store this bit */
  318. linestatus &= ~UART_LSR_DR;
  319. /*
  320. * Since we are grabbing the linestatus register, which
  321. * will reset some bits after our read, we need to ensure
  322. * we don't miss our TX FIFO emptys.
  323. */
  324. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
  325. linestatus &= ~(UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR);
  326. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  327. }
  328. /*
  329. * Discard character if we are ignoring the error mask.
  330. */
  331. if (linestatus & error_mask) {
  332. u8 discard;
  333. linestatus = 0;
  334. memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
  335. continue;
  336. }
  337. /*
  338. * If our queue is full, we have no choice but to drop some data.
  339. * The assumption is that HWFLOW or SWFLOW should have stopped
  340. * things way way before we got to this point.
  341. *
  342. * I decided that I wanted to ditch the oldest data first,
  343. * I hope thats okay with everyone? Yes? Good.
  344. */
  345. while (qleft < 1) {
  346. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  347. "Queue full, dropping DATA:%x LSR:%x\n",
  348. ch->ch_rqueue[tail], ch->ch_equeue[tail]);
  349. ch->ch_r_tail = tail = (tail + 1) & RQUEUEMASK;
  350. ch->ch_err_overrun++;
  351. qleft++;
  352. }
  353. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
  354. ch->ch_equeue[head] = (u8) linestatus;
  355. jsm_dbg(READ, &ch->ch_bd->pci_dev, "DATA/LSR pair: %x %x\n",
  356. ch->ch_rqueue[head], ch->ch_equeue[head]);
  357. /* Ditch any remaining linestatus value. */
  358. linestatus = 0;
  359. /* Add to and flip head if needed */
  360. head = (head + 1) & RQUEUEMASK;
  361. qleft--;
  362. ch->ch_rxcount++;
  363. }
  364. /*
  365. * Write new final heads to channel structure.
  366. */
  367. ch->ch_r_head = head & RQUEUEMASK;
  368. ch->ch_e_head = head & EQUEUEMASK;
  369. jsm_input(ch);
  370. }
  371. static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
  372. {
  373. u16 head;
  374. u16 tail;
  375. int n;
  376. int s;
  377. int qlen;
  378. u32 len_written = 0;
  379. struct circ_buf *circ;
  380. if (!ch)
  381. return;
  382. circ = &ch->uart_port.state->xmit;
  383. /* No data to write to the UART */
  384. if (uart_circ_empty(circ))
  385. return;
  386. /* If port is "stopped", don't send any data to the UART */
  387. if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING))
  388. return;
  389. /*
  390. * If FIFOs are disabled. Send data directly to txrx register
  391. */
  392. if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
  393. u8 lsrbits = readb(&ch->ch_neo_uart->lsr);
  394. ch->ch_cached_lsr |= lsrbits;
  395. if (ch->ch_cached_lsr & UART_LSR_THRE) {
  396. ch->ch_cached_lsr &= ~(UART_LSR_THRE);
  397. writeb(circ->buf[circ->tail], &ch->ch_neo_uart->txrx);
  398. jsm_dbg(WRITE, &ch->ch_bd->pci_dev,
  399. "Tx data: %x\n", circ->buf[circ->tail]);
  400. circ->tail = (circ->tail + 1) & (UART_XMIT_SIZE - 1);
  401. ch->ch_txcount++;
  402. }
  403. return;
  404. }
  405. /*
  406. * We have to do it this way, because of the EXAR TXFIFO count bug.
  407. */
  408. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  409. return;
  410. n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
  411. /* cache head and tail of queue */
  412. head = circ->head & (UART_XMIT_SIZE - 1);
  413. tail = circ->tail & (UART_XMIT_SIZE - 1);
  414. qlen = uart_circ_chars_pending(circ);
  415. /* Find minimum of the FIFO space, versus queue length */
  416. n = min(n, qlen);
  417. while (n > 0) {
  418. s = ((head >= tail) ? head : UART_XMIT_SIZE) - tail;
  419. s = min(s, n);
  420. if (s <= 0)
  421. break;
  422. memcpy_toio(&ch->ch_neo_uart->txrxburst, circ->buf + tail, s);
  423. /* Add and flip queue if needed */
  424. tail = (tail + s) & (UART_XMIT_SIZE - 1);
  425. n -= s;
  426. ch->ch_txcount += s;
  427. len_written += s;
  428. }
  429. /* Update the final tail */
  430. circ->tail = tail & (UART_XMIT_SIZE - 1);
  431. if (len_written >= ch->ch_t_tlevel)
  432. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  433. if (uart_circ_empty(circ))
  434. uart_write_wakeup(&ch->uart_port);
  435. }
  436. static void neo_parse_modem(struct jsm_channel *ch, u8 signals)
  437. {
  438. u8 msignals = signals;
  439. jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
  440. "neo_parse_modem: port: %d msignals: %x\n",
  441. ch->ch_portnum, msignals);
  442. /* Scrub off lower bits. They signify delta's, which I don't care about */
  443. /* Keep DDCD and DDSR though */
  444. msignals &= 0xf8;
  445. if (msignals & UART_MSR_DDCD)
  446. uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
  447. if (msignals & UART_MSR_DDSR)
  448. uart_handle_cts_change(&ch->uart_port, msignals & UART_MSR_CTS);
  449. if (msignals & UART_MSR_DCD)
  450. ch->ch_mistat |= UART_MSR_DCD;
  451. else
  452. ch->ch_mistat &= ~UART_MSR_DCD;
  453. if (msignals & UART_MSR_DSR)
  454. ch->ch_mistat |= UART_MSR_DSR;
  455. else
  456. ch->ch_mistat &= ~UART_MSR_DSR;
  457. if (msignals & UART_MSR_RI)
  458. ch->ch_mistat |= UART_MSR_RI;
  459. else
  460. ch->ch_mistat &= ~UART_MSR_RI;
  461. if (msignals & UART_MSR_CTS)
  462. ch->ch_mistat |= UART_MSR_CTS;
  463. else
  464. ch->ch_mistat &= ~UART_MSR_CTS;
  465. jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
  466. "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
  467. ch->ch_portnum,
  468. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
  469. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
  470. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS),
  471. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR),
  472. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI),
  473. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD));
  474. }
  475. /* Make the UART raise any of the output signals we want up */
  476. static void neo_assert_modem_signals(struct jsm_channel *ch)
  477. {
  478. if (!ch)
  479. return;
  480. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  481. /* flush write operation */
  482. neo_pci_posting_flush(ch->ch_bd);
  483. }
  484. /*
  485. * Flush the WRITE FIFO on the Neo.
  486. *
  487. * NOTE: Channel lock MUST be held before calling this function!
  488. */
  489. static void neo_flush_uart_write(struct jsm_channel *ch)
  490. {
  491. u8 tmp = 0;
  492. int i = 0;
  493. if (!ch)
  494. return;
  495. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  496. for (i = 0; i < 10; i++) {
  497. /* Check to see if the UART feels it completely flushed the FIFO. */
  498. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  499. if (tmp & UART_FCR_CLEAR_XMIT) {
  500. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  501. "Still flushing TX UART... i: %d\n", i);
  502. udelay(10);
  503. }
  504. else
  505. break;
  506. }
  507. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  508. }
  509. /*
  510. * Flush the READ FIFO on the Neo.
  511. *
  512. * NOTE: Channel lock MUST be held before calling this function!
  513. */
  514. static void neo_flush_uart_read(struct jsm_channel *ch)
  515. {
  516. u8 tmp = 0;
  517. int i = 0;
  518. if (!ch)
  519. return;
  520. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
  521. for (i = 0; i < 10; i++) {
  522. /* Check to see if the UART feels it completely flushed the FIFO. */
  523. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  524. if (tmp & 2) {
  525. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  526. "Still flushing RX UART... i: %d\n", i);
  527. udelay(10);
  528. }
  529. else
  530. break;
  531. }
  532. }
  533. /*
  534. * No locks are assumed to be held when calling this function.
  535. */
  536. static void neo_clear_break(struct jsm_channel *ch)
  537. {
  538. unsigned long lock_flags;
  539. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  540. /* Turn break off, and unset some variables */
  541. if (ch->ch_flags & CH_BREAK_SENDING) {
  542. u8 temp = readb(&ch->ch_neo_uart->lcr);
  543. writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  544. ch->ch_flags &= ~(CH_BREAK_SENDING);
  545. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  546. "clear break Finishing UART_LCR_SBC! finished: %lx\n",
  547. jiffies);
  548. /* flush write operation */
  549. neo_pci_posting_flush(ch->ch_bd);
  550. }
  551. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  552. }
  553. /*
  554. * Parse the ISR register.
  555. */
  556. static void neo_parse_isr(struct jsm_board *brd, u32 port)
  557. {
  558. struct jsm_channel *ch;
  559. u8 isr;
  560. u8 cause;
  561. unsigned long lock_flags;
  562. if (!brd)
  563. return;
  564. if (port >= brd->maxports)
  565. return;
  566. ch = brd->channels[port];
  567. if (!ch)
  568. return;
  569. /* Here we try to figure out what caused the interrupt to happen */
  570. while (1) {
  571. isr = readb(&ch->ch_neo_uart->isr_fcr);
  572. /* Bail if no pending interrupt */
  573. if (isr & UART_IIR_NO_INT)
  574. break;
  575. /*
  576. * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
  577. */
  578. isr &= ~(UART_17158_IIR_FIFO_ENABLED);
  579. jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d isr: %x\n",
  580. __FILE__, __LINE__, isr);
  581. if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
  582. /* Read data from uart -> queue */
  583. neo_copy_data_from_uart_to_queue(ch);
  584. /* Call our tty layer to enforce queue flow control if needed. */
  585. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  586. jsm_check_queue_flow_control(ch);
  587. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  588. }
  589. if (isr & UART_IIR_THRI) {
  590. /* Transfer data (if any) from Write Queue -> UART. */
  591. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  592. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  593. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  594. neo_copy_data_from_queue_to_uart(ch);
  595. }
  596. if (isr & UART_17158_IIR_XONXOFF) {
  597. cause = readb(&ch->ch_neo_uart->xoffchar1);
  598. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  599. "Port %d. Got ISR_XONXOFF: cause:%x\n",
  600. port, cause);
  601. /*
  602. * Since the UART detected either an XON or
  603. * XOFF match, we need to figure out which
  604. * one it was, so we can suspend or resume data flow.
  605. */
  606. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  607. if (cause == UART_17158_XON_DETECT) {
  608. /* Is output stopped right now, if so, resume it */
  609. if (brd->channels[port]->ch_flags & CH_STOP) {
  610. ch->ch_flags &= ~(CH_STOP);
  611. }
  612. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  613. "Port %d. XON detected in incoming data\n",
  614. port);
  615. }
  616. else if (cause == UART_17158_XOFF_DETECT) {
  617. if (!(brd->channels[port]->ch_flags & CH_STOP)) {
  618. ch->ch_flags |= CH_STOP;
  619. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  620. "Setting CH_STOP\n");
  621. }
  622. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  623. "Port: %d. XOFF detected in incoming data\n",
  624. port);
  625. }
  626. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  627. }
  628. if (isr & UART_17158_IIR_HWFLOW_STATE_CHANGE) {
  629. /*
  630. * If we get here, this means the hardware is doing auto flow control.
  631. * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
  632. */
  633. cause = readb(&ch->ch_neo_uart->mcr);
  634. /* Which pin is doing auto flow? RTS or DTR? */
  635. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  636. if ((cause & 0x4) == 0) {
  637. if (cause & UART_MCR_RTS)
  638. ch->ch_mostat |= UART_MCR_RTS;
  639. else
  640. ch->ch_mostat &= ~(UART_MCR_RTS);
  641. } else {
  642. if (cause & UART_MCR_DTR)
  643. ch->ch_mostat |= UART_MCR_DTR;
  644. else
  645. ch->ch_mostat &= ~(UART_MCR_DTR);
  646. }
  647. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  648. }
  649. /* Parse any modem signal changes */
  650. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  651. "MOD_STAT: sending to parse_modem_sigs\n");
  652. spin_lock_irqsave(&ch->uart_port.lock, lock_flags);
  653. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  654. spin_unlock_irqrestore(&ch->uart_port.lock, lock_flags);
  655. }
  656. }
  657. static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
  658. {
  659. struct jsm_channel *ch;
  660. int linestatus;
  661. unsigned long lock_flags;
  662. if (!brd)
  663. return;
  664. if (port >= brd->maxports)
  665. return;
  666. ch = brd->channels[port];
  667. if (!ch)
  668. return;
  669. linestatus = readb(&ch->ch_neo_uart->lsr);
  670. jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d port: %d linestatus: %x\n",
  671. __FILE__, __LINE__, port, linestatus);
  672. ch->ch_cached_lsr |= linestatus;
  673. if (ch->ch_cached_lsr & UART_LSR_DR) {
  674. /* Read data from uart -> queue */
  675. neo_copy_data_from_uart_to_queue(ch);
  676. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  677. jsm_check_queue_flow_control(ch);
  678. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  679. }
  680. /*
  681. * This is a special flag. It indicates that at least 1
  682. * RX error (parity, framing, or break) has happened.
  683. * Mark this in our struct, which will tell me that I have
  684. *to do the special RX+LSR read for this FIFO load.
  685. */
  686. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  687. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  688. "%s:%d Port: %d Got an RX error, need to parse LSR\n",
  689. __FILE__, __LINE__, port);
  690. /*
  691. * The next 3 tests should *NOT* happen, as the above test
  692. * should encapsulate all 3... At least, thats what Exar says.
  693. */
  694. if (linestatus & UART_LSR_PE) {
  695. ch->ch_err_parity++;
  696. jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d Port: %d. PAR ERR!\n",
  697. __FILE__, __LINE__, port);
  698. }
  699. if (linestatus & UART_LSR_FE) {
  700. ch->ch_err_frame++;
  701. jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d Port: %d. FRM ERR!\n",
  702. __FILE__, __LINE__, port);
  703. }
  704. if (linestatus & UART_LSR_BI) {
  705. ch->ch_err_break++;
  706. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  707. "%s:%d Port: %d. BRK INTR!\n",
  708. __FILE__, __LINE__, port);
  709. }
  710. if (linestatus & UART_LSR_OE) {
  711. /*
  712. * Rx Oruns. Exar says that an orun will NOT corrupt
  713. * the FIFO. It will just replace the holding register
  714. * with this new data byte. So basically just ignore this.
  715. * Probably we should eventually have an orun stat in our driver...
  716. */
  717. ch->ch_err_overrun++;
  718. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  719. "%s:%d Port: %d. Rx Overrun!\n",
  720. __FILE__, __LINE__, port);
  721. }
  722. if (linestatus & UART_LSR_THRE) {
  723. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  724. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  725. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  726. /* Transfer data (if any) from Write Queue -> UART. */
  727. neo_copy_data_from_queue_to_uart(ch);
  728. }
  729. else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
  730. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  731. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  732. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  733. /* Transfer data (if any) from Write Queue -> UART. */
  734. neo_copy_data_from_queue_to_uart(ch);
  735. }
  736. }
  737. /*
  738. * neo_param()
  739. * Send any/all changes to the line to the UART.
  740. */
  741. static void neo_param(struct jsm_channel *ch)
  742. {
  743. u8 lcr = 0;
  744. u8 uart_lcr, ier;
  745. u32 baud;
  746. int quot;
  747. struct jsm_board *bd;
  748. bd = ch->ch_bd;
  749. if (!bd)
  750. return;
  751. /*
  752. * If baud rate is zero, flush queues, and set mval to drop DTR.
  753. */
  754. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  755. ch->ch_r_head = ch->ch_r_tail = 0;
  756. ch->ch_e_head = ch->ch_e_tail = 0;
  757. neo_flush_uart_write(ch);
  758. neo_flush_uart_read(ch);
  759. ch->ch_flags |= (CH_BAUD0);
  760. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  761. neo_assert_modem_signals(ch);
  762. return;
  763. } else {
  764. int i;
  765. unsigned int cflag;
  766. static struct {
  767. unsigned int rate;
  768. unsigned int cflag;
  769. } baud_rates[] = {
  770. { 921600, B921600 },
  771. { 460800, B460800 },
  772. { 230400, B230400 },
  773. { 115200, B115200 },
  774. { 57600, B57600 },
  775. { 38400, B38400 },
  776. { 19200, B19200 },
  777. { 9600, B9600 },
  778. { 4800, B4800 },
  779. { 2400, B2400 },
  780. { 1200, B1200 },
  781. { 600, B600 },
  782. { 300, B300 },
  783. { 200, B200 },
  784. { 150, B150 },
  785. { 134, B134 },
  786. { 110, B110 },
  787. { 75, B75 },
  788. { 50, B50 },
  789. };
  790. cflag = C_BAUD(ch->uart_port.state->port.tty);
  791. baud = 9600;
  792. for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
  793. if (baud_rates[i].cflag == cflag) {
  794. baud = baud_rates[i].rate;
  795. break;
  796. }
  797. }
  798. if (ch->ch_flags & CH_BAUD0)
  799. ch->ch_flags &= ~(CH_BAUD0);
  800. }
  801. if (ch->ch_c_cflag & PARENB)
  802. lcr |= UART_LCR_PARITY;
  803. if (!(ch->ch_c_cflag & PARODD))
  804. lcr |= UART_LCR_EPAR;
  805. /*
  806. * Not all platforms support mark/space parity,
  807. * so this will hide behind an ifdef.
  808. */
  809. #ifdef CMSPAR
  810. if (ch->ch_c_cflag & CMSPAR)
  811. lcr |= UART_LCR_SPAR;
  812. #endif
  813. if (ch->ch_c_cflag & CSTOPB)
  814. lcr |= UART_LCR_STOP;
  815. switch (ch->ch_c_cflag & CSIZE) {
  816. case CS5:
  817. lcr |= UART_LCR_WLEN5;
  818. break;
  819. case CS6:
  820. lcr |= UART_LCR_WLEN6;
  821. break;
  822. case CS7:
  823. lcr |= UART_LCR_WLEN7;
  824. break;
  825. case CS8:
  826. default:
  827. lcr |= UART_LCR_WLEN8;
  828. break;
  829. }
  830. ier = readb(&ch->ch_neo_uart->ier);
  831. uart_lcr = readb(&ch->ch_neo_uart->lcr);
  832. quot = ch->ch_bd->bd_dividend / baud;
  833. if (quot != 0) {
  834. writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
  835. writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
  836. writeb((quot >> 8), &ch->ch_neo_uart->ier);
  837. writeb(lcr, &ch->ch_neo_uart->lcr);
  838. }
  839. if (uart_lcr != lcr)
  840. writeb(lcr, &ch->ch_neo_uart->lcr);
  841. if (ch->ch_c_cflag & CREAD)
  842. ier |= (UART_IER_RDI | UART_IER_RLSI);
  843. ier |= (UART_IER_THRI | UART_IER_MSI);
  844. writeb(ier, &ch->ch_neo_uart->ier);
  845. /* Set new start/stop chars */
  846. neo_set_new_start_stop_chars(ch);
  847. if (ch->ch_c_cflag & CRTSCTS)
  848. neo_set_cts_flow_control(ch);
  849. else if (ch->ch_c_iflag & IXON) {
  850. /* If start/stop is set to disable, then we should disable flow control */
  851. if ((ch->ch_startc == __DISABLED_CHAR) || (ch->ch_stopc == __DISABLED_CHAR))
  852. neo_set_no_output_flow_control(ch);
  853. else
  854. neo_set_ixon_flow_control(ch);
  855. }
  856. else
  857. neo_set_no_output_flow_control(ch);
  858. if (ch->ch_c_cflag & CRTSCTS)
  859. neo_set_rts_flow_control(ch);
  860. else if (ch->ch_c_iflag & IXOFF) {
  861. /* If start/stop is set to disable, then we should disable flow control */
  862. if ((ch->ch_startc == __DISABLED_CHAR) || (ch->ch_stopc == __DISABLED_CHAR))
  863. neo_set_no_input_flow_control(ch);
  864. else
  865. neo_set_ixoff_flow_control(ch);
  866. }
  867. else
  868. neo_set_no_input_flow_control(ch);
  869. /*
  870. * Adjust the RX FIFO Trigger level if baud is less than 9600.
  871. * Not exactly elegant, but this is needed because of the Exar chip's
  872. * delay on firing off the RX FIFO interrupt on slower baud rates.
  873. */
  874. if (baud < 9600) {
  875. writeb(1, &ch->ch_neo_uart->rfifo);
  876. ch->ch_r_tlevel = 1;
  877. }
  878. neo_assert_modem_signals(ch);
  879. /* Get current status of the modem signals now */
  880. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  881. return;
  882. }
  883. /*
  884. * jsm_neo_intr()
  885. *
  886. * Neo specific interrupt handler.
  887. */
  888. static irqreturn_t neo_intr(int irq, void *voidbrd)
  889. {
  890. struct jsm_board *brd = voidbrd;
  891. struct jsm_channel *ch;
  892. int port = 0;
  893. int type = 0;
  894. int current_port;
  895. u32 tmp;
  896. u32 uart_poll;
  897. unsigned long lock_flags;
  898. unsigned long lock_flags2;
  899. int outofloop_count = 0;
  900. /* Lock out the slow poller from running on this board. */
  901. spin_lock_irqsave(&brd->bd_intr_lock, lock_flags);
  902. /*
  903. * Read in "extended" IRQ information from the 32bit Neo register.
  904. * Bits 0-7: What port triggered the interrupt.
  905. * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
  906. */
  907. uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
  908. jsm_dbg(INTR, &brd->pci_dev, "%s:%d uart_poll: %x\n",
  909. __FILE__, __LINE__, uart_poll);
  910. if (!uart_poll) {
  911. jsm_dbg(INTR, &brd->pci_dev,
  912. "Kernel interrupted to me, but no pending interrupts...\n");
  913. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  914. return IRQ_NONE;
  915. }
  916. /* At this point, we have at least SOMETHING to service, dig further... */
  917. current_port = 0;
  918. /* Loop on each port */
  919. while (((uart_poll & 0xff) != 0) && (outofloop_count < 0xff)){
  920. tmp = uart_poll;
  921. outofloop_count++;
  922. /* Check current port to see if it has interrupt pending */
  923. if ((tmp & jsm_offset_table[current_port]) != 0) {
  924. port = current_port;
  925. type = tmp >> (8 + (port * 3));
  926. type &= 0x7;
  927. } else {
  928. current_port++;
  929. continue;
  930. }
  931. jsm_dbg(INTR, &brd->pci_dev, "%s:%d port: %x type: %x\n",
  932. __FILE__, __LINE__, port, type);
  933. /* Remove this port + type from uart_poll */
  934. uart_poll &= ~(jsm_offset_table[port]);
  935. if (!type) {
  936. /* If no type, just ignore it, and move onto next port */
  937. jsm_dbg(INTR, &brd->pci_dev,
  938. "Interrupt with no type! port: %d\n", port);
  939. continue;
  940. }
  941. /* Switch on type of interrupt we have */
  942. switch (type) {
  943. case UART_17158_RXRDY_TIMEOUT:
  944. /*
  945. * RXRDY Time-out is cleared by reading data in the
  946. * RX FIFO until it falls below the trigger level.
  947. */
  948. /* Verify the port is in range. */
  949. if (port >= brd->nasync)
  950. continue;
  951. ch = brd->channels[port];
  952. if (!ch)
  953. continue;
  954. neo_copy_data_from_uart_to_queue(ch);
  955. /* Call our tty layer to enforce queue flow control if needed. */
  956. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  957. jsm_check_queue_flow_control(ch);
  958. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  959. continue;
  960. case UART_17158_RX_LINE_STATUS:
  961. /*
  962. * RXRDY and RX LINE Status (logic OR of LSR[4:1])
  963. */
  964. neo_parse_lsr(brd, port);
  965. continue;
  966. case UART_17158_TXRDY:
  967. /*
  968. * TXRDY interrupt clears after reading ISR register for the UART channel.
  969. */
  970. /*
  971. * Yes, this is odd...
  972. * Why would I check EVERY possibility of type of
  973. * interrupt, when we know its TXRDY???
  974. * Becuz for some reason, even tho we got triggered for TXRDY,
  975. * it seems to be occasionally wrong. Instead of TX, which
  976. * it should be, I was getting things like RXDY too. Weird.
  977. */
  978. neo_parse_isr(brd, port);
  979. continue;
  980. case UART_17158_MSR:
  981. /*
  982. * MSR or flow control was seen.
  983. */
  984. neo_parse_isr(brd, port);
  985. continue;
  986. default:
  987. /*
  988. * The UART triggered us with a bogus interrupt type.
  989. * It appears the Exar chip, when REALLY bogged down, will throw
  990. * these once and awhile.
  991. * Its harmless, just ignore it and move on.
  992. */
  993. jsm_dbg(INTR, &brd->pci_dev,
  994. "%s:%d Unknown Interrupt type: %x\n",
  995. __FILE__, __LINE__, type);
  996. continue;
  997. }
  998. }
  999. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  1000. jsm_dbg(INTR, &brd->pci_dev, "finish\n");
  1001. return IRQ_HANDLED;
  1002. }
  1003. /*
  1004. * Neo specific way of turning off the receiver.
  1005. * Used as a way to enforce queue flow control when in
  1006. * hardware flow control mode.
  1007. */
  1008. static void neo_disable_receiver(struct jsm_channel *ch)
  1009. {
  1010. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1011. tmp &= ~(UART_IER_RDI);
  1012. writeb(tmp, &ch->ch_neo_uart->ier);
  1013. /* flush write operation */
  1014. neo_pci_posting_flush(ch->ch_bd);
  1015. }
  1016. /*
  1017. * Neo specific way of turning on the receiver.
  1018. * Used as a way to un-enforce queue flow control when in
  1019. * hardware flow control mode.
  1020. */
  1021. static void neo_enable_receiver(struct jsm_channel *ch)
  1022. {
  1023. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1024. tmp |= (UART_IER_RDI);
  1025. writeb(tmp, &ch->ch_neo_uart->ier);
  1026. /* flush write operation */
  1027. neo_pci_posting_flush(ch->ch_bd);
  1028. }
  1029. static void neo_send_start_character(struct jsm_channel *ch)
  1030. {
  1031. if (!ch)
  1032. return;
  1033. if (ch->ch_startc != __DISABLED_CHAR) {
  1034. ch->ch_xon_sends++;
  1035. writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
  1036. /* flush write operation */
  1037. neo_pci_posting_flush(ch->ch_bd);
  1038. }
  1039. }
  1040. static void neo_send_stop_character(struct jsm_channel *ch)
  1041. {
  1042. if (!ch)
  1043. return;
  1044. if (ch->ch_stopc != __DISABLED_CHAR) {
  1045. ch->ch_xoff_sends++;
  1046. writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
  1047. /* flush write operation */
  1048. neo_pci_posting_flush(ch->ch_bd);
  1049. }
  1050. }
  1051. /*
  1052. * neo_uart_init
  1053. */
  1054. static void neo_uart_init(struct jsm_channel *ch)
  1055. {
  1056. writeb(0, &ch->ch_neo_uart->ier);
  1057. writeb(0, &ch->ch_neo_uart->efr);
  1058. writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
  1059. /* Clear out UART and FIFO */
  1060. readb(&ch->ch_neo_uart->txrx);
  1061. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  1062. readb(&ch->ch_neo_uart->lsr);
  1063. readb(&ch->ch_neo_uart->msr);
  1064. ch->ch_flags |= CH_FIFO_ENABLED;
  1065. /* Assert any signals we want up */
  1066. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  1067. }
  1068. /*
  1069. * Make the UART completely turn off.
  1070. */
  1071. static void neo_uart_off(struct jsm_channel *ch)
  1072. {
  1073. /* Turn off UART enhanced bits */
  1074. writeb(0, &ch->ch_neo_uart->efr);
  1075. /* Stop all interrupts from occurring. */
  1076. writeb(0, &ch->ch_neo_uart->ier);
  1077. }
  1078. static u32 neo_get_uart_bytes_left(struct jsm_channel *ch)
  1079. {
  1080. u8 left = 0;
  1081. u8 lsr = readb(&ch->ch_neo_uart->lsr);
  1082. /* We must cache the LSR as some of the bits get reset once read... */
  1083. ch->ch_cached_lsr |= lsr;
  1084. /* Determine whether the Transmitter is empty or not */
  1085. if (!(lsr & UART_LSR_TEMT))
  1086. left = 1;
  1087. else {
  1088. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1089. left = 0;
  1090. }
  1091. return left;
  1092. }
  1093. /* Channel lock MUST be held by the calling function! */
  1094. static void neo_send_break(struct jsm_channel *ch)
  1095. {
  1096. /*
  1097. * Set the time we should stop sending the break.
  1098. * If we are already sending a break, toss away the existing
  1099. * time to stop, and use this new value instead.
  1100. */
  1101. /* Tell the UART to start sending the break */
  1102. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  1103. u8 temp = readb(&ch->ch_neo_uart->lcr);
  1104. writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  1105. ch->ch_flags |= (CH_BREAK_SENDING);
  1106. /* flush write operation */
  1107. neo_pci_posting_flush(ch->ch_bd);
  1108. }
  1109. }
  1110. /*
  1111. * neo_send_immediate_char.
  1112. *
  1113. * Sends a specific character as soon as possible to the UART,
  1114. * jumping over any bytes that might be in the write queue.
  1115. *
  1116. * The channel lock MUST be held by the calling function.
  1117. */
  1118. static void neo_send_immediate_char(struct jsm_channel *ch, unsigned char c)
  1119. {
  1120. if (!ch)
  1121. return;
  1122. writeb(c, &ch->ch_neo_uart->txrx);
  1123. /* flush write operation */
  1124. neo_pci_posting_flush(ch->ch_bd);
  1125. }
  1126. struct board_ops jsm_neo_ops = {
  1127. .intr = neo_intr,
  1128. .uart_init = neo_uart_init,
  1129. .uart_off = neo_uart_off,
  1130. .param = neo_param,
  1131. .assert_modem_signals = neo_assert_modem_signals,
  1132. .flush_uart_write = neo_flush_uart_write,
  1133. .flush_uart_read = neo_flush_uart_read,
  1134. .disable_receiver = neo_disable_receiver,
  1135. .enable_receiver = neo_enable_receiver,
  1136. .send_break = neo_send_break,
  1137. .clear_break = neo_clear_break,
  1138. .send_start_character = neo_send_start_character,
  1139. .send_stop_character = neo_send_stop_character,
  1140. .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
  1141. .get_uart_bytes_left = neo_get_uart_bytes_left,
  1142. .send_immediate_char = neo_send_immediate_char
  1143. };