jsm_neo.c 36 KB

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