jsm_neo.c 37 KB

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