dgnc_neo.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  1. /*
  2. * Copyright 2003 Digi International (www.digi.com)
  3. * Scott H Kilau <Scott_Kilau at digi dot com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  12. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. * PURPOSE. See the GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/sched.h> /* For jiffies, task states */
  17. #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
  18. #include <linux/delay.h> /* For udelay */
  19. #include <linux/io.h> /* For read[bwl]/write[bwl] */
  20. #include <linux/serial.h> /* For struct async_serial */
  21. #include <linux/serial_reg.h> /* For the various UART offsets */
  22. #include "dgnc_driver.h" /* Driver main header file */
  23. #include "dgnc_neo.h" /* Our header file */
  24. #include "dgnc_tty.h"
  25. static inline void neo_parse_lsr(struct dgnc_board *brd, uint port);
  26. static inline void neo_parse_isr(struct dgnc_board *brd, uint port);
  27. static void neo_copy_data_from_uart_to_queue(struct channel_t *ch);
  28. static inline void neo_clear_break(struct channel_t *ch, int force);
  29. static inline void neo_set_cts_flow_control(struct channel_t *ch);
  30. static inline void neo_set_rts_flow_control(struct channel_t *ch);
  31. static inline void neo_set_ixon_flow_control(struct channel_t *ch);
  32. static inline void neo_set_ixoff_flow_control(struct channel_t *ch);
  33. static inline void neo_set_no_output_flow_control(struct channel_t *ch);
  34. static inline void neo_set_no_input_flow_control(struct channel_t *ch);
  35. static inline void neo_set_new_start_stop_chars(struct channel_t *ch);
  36. static void neo_parse_modem(struct channel_t *ch, unsigned char signals);
  37. static void neo_tasklet(unsigned long data);
  38. static void neo_vpd(struct dgnc_board *brd);
  39. static void neo_uart_init(struct channel_t *ch);
  40. static void neo_uart_off(struct channel_t *ch);
  41. static int neo_drain(struct tty_struct *tty, uint seconds);
  42. static void neo_param(struct tty_struct *tty);
  43. static void neo_assert_modem_signals(struct channel_t *ch);
  44. static void neo_flush_uart_write(struct channel_t *ch);
  45. static void neo_flush_uart_read(struct channel_t *ch);
  46. static void neo_disable_receiver(struct channel_t *ch);
  47. static void neo_enable_receiver(struct channel_t *ch);
  48. static void neo_send_break(struct channel_t *ch, int msecs);
  49. static void neo_send_start_character(struct channel_t *ch);
  50. static void neo_send_stop_character(struct channel_t *ch);
  51. static void neo_copy_data_from_queue_to_uart(struct channel_t *ch);
  52. static uint neo_get_uart_bytes_left(struct channel_t *ch);
  53. static void neo_send_immediate_char(struct channel_t *ch, unsigned char c);
  54. static irqreturn_t neo_intr(int irq, void *voidbrd);
  55. struct board_ops dgnc_neo_ops = {
  56. .tasklet = neo_tasklet,
  57. .intr = neo_intr,
  58. .uart_init = neo_uart_init,
  59. .uart_off = neo_uart_off,
  60. .drain = neo_drain,
  61. .param = neo_param,
  62. .vpd = neo_vpd,
  63. .assert_modem_signals = neo_assert_modem_signals,
  64. .flush_uart_write = neo_flush_uart_write,
  65. .flush_uart_read = neo_flush_uart_read,
  66. .disable_receiver = neo_disable_receiver,
  67. .enable_receiver = neo_enable_receiver,
  68. .send_break = neo_send_break,
  69. .send_start_character = neo_send_start_character,
  70. .send_stop_character = neo_send_stop_character,
  71. .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
  72. .get_uart_bytes_left = neo_get_uart_bytes_left,
  73. .send_immediate_char = neo_send_immediate_char
  74. };
  75. static uint dgnc_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
  76. /*
  77. * This function allows calls to ensure that all outstanding
  78. * PCI writes have been completed, by doing a PCI read against
  79. * a non-destructive, read-only location on the Neo card.
  80. *
  81. * In this case, we are reading the DVID (Read-only Device Identification)
  82. * value of the Neo card.
  83. */
  84. static inline void neo_pci_posting_flush(struct dgnc_board *bd)
  85. {
  86. readb(bd->re_map_membase + 0x8D);
  87. }
  88. static inline void neo_set_cts_flow_control(struct channel_t *ch)
  89. {
  90. unsigned char ier = readb(&ch->ch_neo_uart->ier);
  91. unsigned char efr = readb(&ch->ch_neo_uart->efr);
  92. /* Turn on auto CTS flow control */
  93. #if 1
  94. ier |= UART_17158_IER_CTSDSR;
  95. #else
  96. ier &= ~(UART_17158_IER_CTSDSR);
  97. #endif
  98. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_CTSDSR);
  99. /* Turn off auto Xon flow control */
  100. efr &= ~UART_17158_EFR_IXON;
  101. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  102. writeb(0, &ch->ch_neo_uart->efr);
  103. /* Turn on UART enhanced bits */
  104. writeb(efr, &ch->ch_neo_uart->efr);
  105. /* Turn on table D, with 8 char hi/low watermarks */
  106. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  107. /* Feed the UART our trigger levels */
  108. writeb(8, &ch->ch_neo_uart->tfifo);
  109. ch->ch_t_tlevel = 8;
  110. writeb(ier, &ch->ch_neo_uart->ier);
  111. neo_pci_posting_flush(ch->ch_bd);
  112. }
  113. static inline void neo_set_rts_flow_control(struct channel_t *ch)
  114. {
  115. unsigned char ier = readb(&ch->ch_neo_uart->ier);
  116. unsigned char efr = readb(&ch->ch_neo_uart->efr);
  117. /* Turn on auto RTS flow control */
  118. #if 1
  119. ier |= UART_17158_IER_RTSDTR;
  120. #else
  121. ier &= ~(UART_17158_IER_RTSDTR);
  122. #endif
  123. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_RTSDTR);
  124. /* Turn off auto Xoff flow control */
  125. ier &= ~UART_17158_IER_XOFF;
  126. efr &= ~UART_17158_EFR_IXOFF;
  127. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  128. writeb(0, &ch->ch_neo_uart->efr);
  129. /* Turn on UART enhanced bits */
  130. writeb(efr, &ch->ch_neo_uart->efr);
  131. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  132. ch->ch_r_watermark = 4;
  133. writeb(32, &ch->ch_neo_uart->rfifo);
  134. ch->ch_r_tlevel = 32;
  135. writeb(ier, &ch->ch_neo_uart->ier);
  136. /*
  137. * From the Neo UART spec sheet:
  138. * The auto RTS/DTR function must be started by asserting
  139. * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
  140. * it is enabled.
  141. */
  142. ch->ch_mostat |= UART_MCR_RTS;
  143. neo_pci_posting_flush(ch->ch_bd);
  144. }
  145. static inline void neo_set_ixon_flow_control(struct channel_t *ch)
  146. {
  147. unsigned char ier = readb(&ch->ch_neo_uart->ier);
  148. unsigned char efr = readb(&ch->ch_neo_uart->efr);
  149. /* Turn off auto CTS flow control */
  150. ier &= ~UART_17158_IER_CTSDSR;
  151. efr &= ~UART_17158_EFR_CTSDSR;
  152. /* Turn on auto Xon flow control */
  153. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  154. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  155. writeb(0, &ch->ch_neo_uart->efr);
  156. /* Turn on UART enhanced bits */
  157. writeb(efr, &ch->ch_neo_uart->efr);
  158. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  159. ch->ch_r_watermark = 4;
  160. writeb(32, &ch->ch_neo_uart->rfifo);
  161. ch->ch_r_tlevel = 32;
  162. /* Tell UART what start/stop chars it should be looking for */
  163. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  164. writeb(0, &ch->ch_neo_uart->xonchar2);
  165. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  166. writeb(0, &ch->ch_neo_uart->xoffchar2);
  167. writeb(ier, &ch->ch_neo_uart->ier);
  168. neo_pci_posting_flush(ch->ch_bd);
  169. }
  170. static inline void neo_set_ixoff_flow_control(struct channel_t *ch)
  171. {
  172. unsigned char ier = readb(&ch->ch_neo_uart->ier);
  173. unsigned char efr = readb(&ch->ch_neo_uart->efr);
  174. /* Turn off auto RTS flow control */
  175. ier &= ~UART_17158_IER_RTSDTR;
  176. efr &= ~UART_17158_EFR_RTSDTR;
  177. /* Turn on auto Xoff flow control */
  178. ier |= UART_17158_IER_XOFF;
  179. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  180. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  181. writeb(0, &ch->ch_neo_uart->efr);
  182. /* Turn on UART enhanced bits */
  183. writeb(efr, &ch->ch_neo_uart->efr);
  184. /* Turn on table D, with 8 char hi/low watermarks */
  185. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  186. writeb(8, &ch->ch_neo_uart->tfifo);
  187. ch->ch_t_tlevel = 8;
  188. /* Tell UART what start/stop chars it should be looking for */
  189. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  190. writeb(0, &ch->ch_neo_uart->xonchar2);
  191. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  192. writeb(0, &ch->ch_neo_uart->xoffchar2);
  193. writeb(ier, &ch->ch_neo_uart->ier);
  194. neo_pci_posting_flush(ch->ch_bd);
  195. }
  196. static inline void neo_set_no_input_flow_control(struct channel_t *ch)
  197. {
  198. unsigned char ier = readb(&ch->ch_neo_uart->ier);
  199. unsigned char efr = readb(&ch->ch_neo_uart->efr);
  200. /* Turn off auto RTS flow control */
  201. ier &= ~UART_17158_IER_RTSDTR;
  202. efr &= ~UART_17158_EFR_RTSDTR;
  203. /* Turn off auto Xoff flow control */
  204. ier &= ~UART_17158_IER_XOFF;
  205. if (ch->ch_c_iflag & IXON)
  206. efr &= ~(UART_17158_EFR_IXOFF);
  207. else
  208. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  209. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  210. writeb(0, &ch->ch_neo_uart->efr);
  211. /* Turn on UART enhanced bits */
  212. writeb(efr, &ch->ch_neo_uart->efr);
  213. /* Turn on table D, with 8 char hi/low watermarks */
  214. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  215. ch->ch_r_watermark = 0;
  216. writeb(16, &ch->ch_neo_uart->tfifo);
  217. ch->ch_t_tlevel = 16;
  218. writeb(16, &ch->ch_neo_uart->rfifo);
  219. ch->ch_r_tlevel = 16;
  220. writeb(ier, &ch->ch_neo_uart->ier);
  221. neo_pci_posting_flush(ch->ch_bd);
  222. }
  223. static inline void neo_set_no_output_flow_control(struct channel_t *ch)
  224. {
  225. unsigned char ier = readb(&ch->ch_neo_uart->ier);
  226. unsigned char efr = readb(&ch->ch_neo_uart->efr);
  227. /* Turn off auto CTS flow control */
  228. ier &= ~UART_17158_IER_CTSDSR;
  229. efr &= ~UART_17158_EFR_CTSDSR;
  230. /* Turn off auto Xon flow control */
  231. if (ch->ch_c_iflag & IXOFF)
  232. efr &= ~UART_17158_EFR_IXON;
  233. else
  234. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  235. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  236. writeb(0, &ch->ch_neo_uart->efr);
  237. /* Turn on UART enhanced bits */
  238. writeb(efr, &ch->ch_neo_uart->efr);
  239. /* Turn on table D, with 8 char hi/low watermarks */
  240. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  241. ch->ch_r_watermark = 0;
  242. writeb(16, &ch->ch_neo_uart->tfifo);
  243. ch->ch_t_tlevel = 16;
  244. writeb(16, &ch->ch_neo_uart->rfifo);
  245. ch->ch_r_tlevel = 16;
  246. writeb(ier, &ch->ch_neo_uart->ier);
  247. neo_pci_posting_flush(ch->ch_bd);
  248. }
  249. /* change UARTs start/stop chars */
  250. static inline void neo_set_new_start_stop_chars(struct channel_t *ch)
  251. {
  252. /* if hardware flow control is set, then skip this whole thing */
  253. if (ch->ch_digi.digi_flags & (CTSPACE | RTSPACE) || ch->ch_c_cflag & CRTSCTS)
  254. return;
  255. /* Tell UART what start/stop chars it should be looking for */
  256. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  257. writeb(0, &ch->ch_neo_uart->xonchar2);
  258. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  259. writeb(0, &ch->ch_neo_uart->xoffchar2);
  260. neo_pci_posting_flush(ch->ch_bd);
  261. }
  262. /*
  263. * No locks are assumed to be held when calling this function.
  264. */
  265. static inline void neo_clear_break(struct channel_t *ch, int force)
  266. {
  267. unsigned long flags;
  268. spin_lock_irqsave(&ch->ch_lock, flags);
  269. /* Bail if we aren't currently sending a break. */
  270. if (!ch->ch_stop_sending_break) {
  271. spin_unlock_irqrestore(&ch->ch_lock, flags);
  272. return;
  273. }
  274. /* Turn break off, and unset some variables */
  275. if (ch->ch_flags & CH_BREAK_SENDING) {
  276. if (time_after_eq(jiffies, ch->ch_stop_sending_break)
  277. || force) {
  278. unsigned char temp = readb(&ch->ch_neo_uart->lcr);
  279. writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  280. neo_pci_posting_flush(ch->ch_bd);
  281. ch->ch_flags &= ~(CH_BREAK_SENDING);
  282. ch->ch_stop_sending_break = 0;
  283. }
  284. }
  285. spin_unlock_irqrestore(&ch->ch_lock, flags);
  286. }
  287. /*
  288. * Parse the ISR register.
  289. */
  290. static inline void neo_parse_isr(struct dgnc_board *brd, uint port)
  291. {
  292. struct channel_t *ch;
  293. unsigned char isr;
  294. unsigned char cause;
  295. unsigned long flags;
  296. if (!brd || brd->magic != DGNC_BOARD_MAGIC)
  297. return;
  298. if (port >= brd->maxports)
  299. return;
  300. ch = brd->channels[port];
  301. if (ch->magic != DGNC_CHANNEL_MAGIC)
  302. return;
  303. /* Here we try to figure out what caused the interrupt to happen */
  304. while (1) {
  305. isr = readb(&ch->ch_neo_uart->isr_fcr);
  306. /* Bail if no pending interrupt */
  307. if (isr & UART_IIR_NO_INT)
  308. break;
  309. /*
  310. * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
  311. */
  312. isr &= ~(UART_17158_IIR_FIFO_ENABLED);
  313. if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
  314. /* Read data from uart -> queue */
  315. brd->intr_rx++;
  316. ch->ch_intr_rx++;
  317. neo_copy_data_from_uart_to_queue(ch);
  318. /* Call our tty layer to enforce queue flow control if needed. */
  319. spin_lock_irqsave(&ch->ch_lock, flags);
  320. dgnc_check_queue_flow_control(ch);
  321. spin_unlock_irqrestore(&ch->ch_lock, flags);
  322. }
  323. if (isr & UART_IIR_THRI) {
  324. brd->intr_tx++;
  325. ch->ch_intr_tx++;
  326. /* Transfer data (if any) from Write Queue -> UART. */
  327. spin_lock_irqsave(&ch->ch_lock, flags);
  328. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  329. spin_unlock_irqrestore(&ch->ch_lock, flags);
  330. neo_copy_data_from_queue_to_uart(ch);
  331. }
  332. if (isr & UART_17158_IIR_XONXOFF) {
  333. cause = readb(&ch->ch_neo_uart->xoffchar1);
  334. /*
  335. * Since the UART detected either an XON or
  336. * XOFF match, we need to figure out which
  337. * one it was, so we can suspend or resume data flow.
  338. */
  339. if (cause == UART_17158_XON_DETECT) {
  340. /* Is output stopped right now, if so, resume it */
  341. if (brd->channels[port]->ch_flags & CH_STOP) {
  342. spin_lock_irqsave(&ch->ch_lock,
  343. flags);
  344. ch->ch_flags &= ~(CH_STOP);
  345. spin_unlock_irqrestore(&ch->ch_lock,
  346. flags);
  347. }
  348. } else if (cause == UART_17158_XOFF_DETECT) {
  349. if (!(brd->channels[port]->ch_flags & CH_STOP)) {
  350. spin_lock_irqsave(&ch->ch_lock,
  351. flags);
  352. ch->ch_flags |= CH_STOP;
  353. spin_unlock_irqrestore(&ch->ch_lock,
  354. flags);
  355. }
  356. }
  357. }
  358. if (isr & UART_17158_IIR_HWFLOW_STATE_CHANGE) {
  359. /*
  360. * If we get here, this means the hardware is doing auto flow control.
  361. * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
  362. */
  363. brd->intr_modem++;
  364. ch->ch_intr_modem++;
  365. cause = readb(&ch->ch_neo_uart->mcr);
  366. /* Which pin is doing auto flow? RTS or DTR? */
  367. if ((cause & 0x4) == 0) {
  368. if (cause & UART_MCR_RTS) {
  369. spin_lock_irqsave(&ch->ch_lock,
  370. flags);
  371. ch->ch_mostat |= UART_MCR_RTS;
  372. spin_unlock_irqrestore(&ch->ch_lock,
  373. flags);
  374. } else {
  375. spin_lock_irqsave(&ch->ch_lock,
  376. flags);
  377. ch->ch_mostat &= ~(UART_MCR_RTS);
  378. spin_unlock_irqrestore(&ch->ch_lock,
  379. flags);
  380. }
  381. } else {
  382. if (cause & UART_MCR_DTR) {
  383. spin_lock_irqsave(&ch->ch_lock,
  384. flags);
  385. ch->ch_mostat |= UART_MCR_DTR;
  386. spin_unlock_irqrestore(&ch->ch_lock,
  387. flags);
  388. } else {
  389. spin_lock_irqsave(&ch->ch_lock,
  390. flags);
  391. ch->ch_mostat &= ~(UART_MCR_DTR);
  392. spin_unlock_irqrestore(&ch->ch_lock,
  393. flags);
  394. }
  395. }
  396. }
  397. /* Parse any modem signal changes */
  398. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  399. }
  400. }
  401. static inline void neo_parse_lsr(struct dgnc_board *brd, uint port)
  402. {
  403. struct channel_t *ch;
  404. int linestatus;
  405. unsigned long flags;
  406. /*
  407. * Check to make sure it didn't receive interrupt with a null board
  408. * associated or a board pointer that wasn't ours.
  409. */
  410. if (!brd || brd->magic != DGNC_BOARD_MAGIC)
  411. return;
  412. if (port >= brd->maxports)
  413. return;
  414. ch = brd->channels[port];
  415. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  416. return;
  417. linestatus = readb(&ch->ch_neo_uart->lsr);
  418. ch->ch_cached_lsr |= linestatus;
  419. if (ch->ch_cached_lsr & UART_LSR_DR) {
  420. brd->intr_rx++;
  421. ch->ch_intr_rx++;
  422. /* Read data from uart -> queue */
  423. neo_copy_data_from_uart_to_queue(ch);
  424. spin_lock_irqsave(&ch->ch_lock, flags);
  425. dgnc_check_queue_flow_control(ch);
  426. spin_unlock_irqrestore(&ch->ch_lock, flags);
  427. }
  428. /*
  429. * The next 3 tests should *NOT* happen, as the above test
  430. * should encapsulate all 3... At least, thats what Exar says.
  431. */
  432. if (linestatus & UART_LSR_PE)
  433. ch->ch_err_parity++;
  434. if (linestatus & UART_LSR_FE)
  435. ch->ch_err_frame++;
  436. if (linestatus & UART_LSR_BI)
  437. ch->ch_err_break++;
  438. if (linestatus & UART_LSR_OE) {
  439. /*
  440. * Rx Oruns. Exar says that an orun will NOT corrupt
  441. * the FIFO. It will just replace the holding register
  442. * with this new data byte. So basically just ignore this.
  443. * Probably we should eventually have an orun stat in our driver...
  444. */
  445. ch->ch_err_overrun++;
  446. }
  447. if (linestatus & UART_LSR_THRE) {
  448. brd->intr_tx++;
  449. ch->ch_intr_tx++;
  450. spin_lock_irqsave(&ch->ch_lock, flags);
  451. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  452. spin_unlock_irqrestore(&ch->ch_lock, flags);
  453. /* Transfer data (if any) from Write Queue -> UART. */
  454. neo_copy_data_from_queue_to_uart(ch);
  455. } else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
  456. brd->intr_tx++;
  457. ch->ch_intr_tx++;
  458. spin_lock_irqsave(&ch->ch_lock, flags);
  459. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  460. spin_unlock_irqrestore(&ch->ch_lock, flags);
  461. /* Transfer data (if any) from Write Queue -> UART. */
  462. neo_copy_data_from_queue_to_uart(ch);
  463. }
  464. }
  465. /*
  466. * neo_param()
  467. * Send any/all changes to the line to the UART.
  468. */
  469. static void neo_param(struct tty_struct *tty)
  470. {
  471. unsigned char lcr = 0;
  472. unsigned char uart_lcr = 0;
  473. unsigned char ier = 0;
  474. unsigned char uart_ier = 0;
  475. uint baud = 9600;
  476. int quot = 0;
  477. struct dgnc_board *bd;
  478. struct channel_t *ch;
  479. struct un_t *un;
  480. if (!tty || tty->magic != TTY_MAGIC)
  481. return;
  482. un = (struct un_t *)tty->driver_data;
  483. if (!un || un->magic != DGNC_UNIT_MAGIC)
  484. return;
  485. ch = un->un_ch;
  486. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  487. return;
  488. bd = ch->ch_bd;
  489. if (!bd || bd->magic != DGNC_BOARD_MAGIC)
  490. return;
  491. /*
  492. * If baud rate is zero, flush queues, and set mval to drop DTR.
  493. */
  494. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  495. ch->ch_r_head = 0;
  496. ch->ch_r_tail = 0;
  497. ch->ch_e_head = 0;
  498. ch->ch_e_tail = 0;
  499. ch->ch_w_head = 0;
  500. ch->ch_w_tail = 0;
  501. neo_flush_uart_write(ch);
  502. neo_flush_uart_read(ch);
  503. /* The baudrate is B0 so all modem lines are to be dropped. */
  504. ch->ch_flags |= (CH_BAUD0);
  505. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  506. neo_assert_modem_signals(ch);
  507. ch->ch_old_baud = 0;
  508. return;
  509. } else if (ch->ch_custom_speed) {
  510. baud = ch->ch_custom_speed;
  511. /* Handle transition from B0 */
  512. if (ch->ch_flags & CH_BAUD0) {
  513. ch->ch_flags &= ~(CH_BAUD0);
  514. /*
  515. * Bring back up RTS and DTR...
  516. * Also handle RTS or DTR toggle if set.
  517. */
  518. if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
  519. ch->ch_mostat |= (UART_MCR_RTS);
  520. if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
  521. ch->ch_mostat |= (UART_MCR_DTR);
  522. }
  523. } else {
  524. int iindex = 0;
  525. int jindex = 0;
  526. ulong bauds[4][16] = {
  527. { /* slowbaud */
  528. 0, 50, 75, 110,
  529. 134, 150, 200, 300,
  530. 600, 1200, 1800, 2400,
  531. 4800, 9600, 19200, 38400 },
  532. { /* slowbaud & CBAUDEX */
  533. 0, 57600, 115200, 230400,
  534. 460800, 150, 200, 921600,
  535. 600, 1200, 1800, 2400,
  536. 4800, 9600, 19200, 38400 },
  537. { /* fastbaud */
  538. 0, 57600, 76800, 115200,
  539. 131657, 153600, 230400, 460800,
  540. 921600, 1200, 1800, 2400,
  541. 4800, 9600, 19200, 38400 },
  542. { /* fastbaud & CBAUDEX */
  543. 0, 57600, 115200, 230400,
  544. 460800, 150, 200, 921600,
  545. 600, 1200, 1800, 2400,
  546. 4800, 9600, 19200, 38400 }
  547. };
  548. /* Only use the TXPrint baud rate if the terminal unit is NOT open */
  549. if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGNC_PRINT))
  550. baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
  551. else
  552. baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
  553. if (ch->ch_c_cflag & CBAUDEX)
  554. iindex = 1;
  555. if (ch->ch_digi.digi_flags & DIGI_FAST)
  556. iindex += 2;
  557. jindex = baud;
  558. if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16))
  559. baud = bauds[iindex][jindex];
  560. else
  561. baud = 0;
  562. if (baud == 0)
  563. baud = 9600;
  564. /* Handle transition from B0 */
  565. if (ch->ch_flags & CH_BAUD0) {
  566. ch->ch_flags &= ~(CH_BAUD0);
  567. /*
  568. * Bring back up RTS and DTR...
  569. * Also handle RTS or DTR toggle if set.
  570. */
  571. if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
  572. ch->ch_mostat |= (UART_MCR_RTS);
  573. if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
  574. ch->ch_mostat |= (UART_MCR_DTR);
  575. }
  576. }
  577. if (ch->ch_c_cflag & PARENB)
  578. lcr |= UART_LCR_PARITY;
  579. if (!(ch->ch_c_cflag & PARODD))
  580. lcr |= UART_LCR_EPAR;
  581. /*
  582. * Not all platforms support mark/space parity,
  583. * so this will hide behind an ifdef.
  584. */
  585. #ifdef CMSPAR
  586. if (ch->ch_c_cflag & CMSPAR)
  587. lcr |= UART_LCR_SPAR;
  588. #endif
  589. if (ch->ch_c_cflag & CSTOPB)
  590. lcr |= UART_LCR_STOP;
  591. switch (ch->ch_c_cflag & CSIZE) {
  592. case CS5:
  593. lcr |= UART_LCR_WLEN5;
  594. break;
  595. case CS6:
  596. lcr |= UART_LCR_WLEN6;
  597. break;
  598. case CS7:
  599. lcr |= UART_LCR_WLEN7;
  600. break;
  601. case CS8:
  602. default:
  603. lcr |= UART_LCR_WLEN8;
  604. break;
  605. }
  606. uart_ier = readb(&ch->ch_neo_uart->ier);
  607. ier = uart_ier;
  608. uart_lcr = readb(&ch->ch_neo_uart->lcr);
  609. if (baud == 0)
  610. baud = 9600;
  611. quot = ch->ch_bd->bd_dividend / baud;
  612. if (quot != 0 && ch->ch_old_baud != baud) {
  613. ch->ch_old_baud = baud;
  614. writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
  615. writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
  616. writeb((quot >> 8), &ch->ch_neo_uart->ier);
  617. writeb(lcr, &ch->ch_neo_uart->lcr);
  618. }
  619. if (uart_lcr != lcr)
  620. writeb(lcr, &ch->ch_neo_uart->lcr);
  621. if (ch->ch_c_cflag & CREAD)
  622. ier |= (UART_IER_RDI | UART_IER_RLSI);
  623. else
  624. ier &= ~(UART_IER_RDI | UART_IER_RLSI);
  625. /*
  626. * Have the UART interrupt on modem signal changes ONLY when
  627. * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
  628. */
  629. if ((ch->ch_digi.digi_flags & CTSPACE) ||
  630. (ch->ch_digi.digi_flags & RTSPACE) ||
  631. (ch->ch_c_cflag & CRTSCTS) ||
  632. !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
  633. !(ch->ch_c_cflag & CLOCAL))
  634. ier |= UART_IER_MSI;
  635. else
  636. ier &= ~UART_IER_MSI;
  637. ier |= UART_IER_THRI;
  638. if (ier != uart_ier)
  639. writeb(ier, &ch->ch_neo_uart->ier);
  640. /* Set new start/stop chars */
  641. neo_set_new_start_stop_chars(ch);
  642. if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
  643. neo_set_cts_flow_control(ch);
  644. } else if (ch->ch_c_iflag & IXON) {
  645. /* If start/stop is set to disable, then we should disable flow control */
  646. if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE))
  647. neo_set_no_output_flow_control(ch);
  648. else
  649. neo_set_ixon_flow_control(ch);
  650. } else {
  651. neo_set_no_output_flow_control(ch);
  652. }
  653. if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
  654. neo_set_rts_flow_control(ch);
  655. } else if (ch->ch_c_iflag & IXOFF) {
  656. /* If start/stop is set to disable, then we should disable flow control */
  657. if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE))
  658. neo_set_no_input_flow_control(ch);
  659. else
  660. neo_set_ixoff_flow_control(ch);
  661. } else {
  662. neo_set_no_input_flow_control(ch);
  663. }
  664. /*
  665. * Adjust the RX FIFO Trigger level if baud is less than 9600.
  666. * Not exactly elegant, but this is needed because of the Exar chip's
  667. * delay on firing off the RX FIFO interrupt on slower baud rates.
  668. */
  669. if (baud < 9600) {
  670. writeb(1, &ch->ch_neo_uart->rfifo);
  671. ch->ch_r_tlevel = 1;
  672. }
  673. neo_assert_modem_signals(ch);
  674. /* Get current status of the modem signals now */
  675. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  676. }
  677. /*
  678. * Our board poller function.
  679. */
  680. static void neo_tasklet(unsigned long data)
  681. {
  682. struct dgnc_board *bd = (struct dgnc_board *)data;
  683. struct channel_t *ch;
  684. unsigned long flags;
  685. int i;
  686. int state = 0;
  687. int ports = 0;
  688. if (!bd || bd->magic != DGNC_BOARD_MAGIC)
  689. return;
  690. /* Cache a couple board values */
  691. spin_lock_irqsave(&bd->bd_lock, flags);
  692. state = bd->state;
  693. ports = bd->nasync;
  694. spin_unlock_irqrestore(&bd->bd_lock, flags);
  695. /*
  696. * Do NOT allow the interrupt routine to read the intr registers
  697. * Until we release this lock.
  698. */
  699. spin_lock_irqsave(&bd->bd_intr_lock, flags);
  700. /*
  701. * If board is ready, parse deeper to see if there is anything to do.
  702. */
  703. if ((state == BOARD_READY) && (ports > 0)) {
  704. /* Loop on each port */
  705. for (i = 0; i < ports; i++) {
  706. ch = bd->channels[i];
  707. /* Just being careful... */
  708. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  709. continue;
  710. /*
  711. * NOTE: Remember you CANNOT hold any channel
  712. * locks when calling the input routine.
  713. *
  714. * During input processing, its possible we
  715. * will call the Linux ld, which might in turn,
  716. * do a callback right back into us, resulting
  717. * in us trying to grab the channel lock twice!
  718. */
  719. dgnc_input(ch);
  720. /*
  721. * Channel lock is grabbed and then released
  722. * inside both of these routines, but neither
  723. * call anything else that could call back into us.
  724. */
  725. neo_copy_data_from_queue_to_uart(ch);
  726. dgnc_wakeup_writes(ch);
  727. /*
  728. * Call carrier carrier function, in case something
  729. * has changed.
  730. */
  731. dgnc_carrier(ch);
  732. /*
  733. * Check to see if we need to turn off a sending break.
  734. * The timing check is done inside clear_break()
  735. */
  736. if (ch->ch_stop_sending_break)
  737. neo_clear_break(ch, 0);
  738. }
  739. }
  740. /* Allow interrupt routine to access the interrupt register again */
  741. spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
  742. }
  743. /*
  744. * dgnc_neo_intr()
  745. *
  746. * Neo specific interrupt handler.
  747. */
  748. static irqreturn_t neo_intr(int irq, void *voidbrd)
  749. {
  750. struct dgnc_board *brd = voidbrd;
  751. struct channel_t *ch;
  752. int port = 0;
  753. int type = 0;
  754. int current_port;
  755. u32 tmp;
  756. u32 uart_poll;
  757. unsigned long flags;
  758. unsigned long flags2;
  759. /*
  760. * Check to make sure it didn't receive interrupt with a null board
  761. * associated or a board pointer that wasn't ours.
  762. */
  763. if (!brd || brd->magic != DGNC_BOARD_MAGIC)
  764. return IRQ_NONE;
  765. brd->intr_count++;
  766. /* Lock out the slow poller from running on this board. */
  767. spin_lock_irqsave(&brd->bd_intr_lock, flags);
  768. /*
  769. * Read in "extended" IRQ information from the 32bit Neo register.
  770. * Bits 0-7: What port triggered the interrupt.
  771. * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
  772. */
  773. uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
  774. /*
  775. * If 0, no interrupts pending.
  776. * This can happen if the IRQ is shared among a couple Neo/Classic boards.
  777. */
  778. if (!uart_poll) {
  779. spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
  780. return IRQ_NONE;
  781. }
  782. /* At this point, we have at least SOMETHING to service, dig further... */
  783. current_port = 0;
  784. /* Loop on each port */
  785. while ((uart_poll & 0xff) != 0) {
  786. tmp = uart_poll;
  787. /* Check current port to see if it has interrupt pending */
  788. if ((tmp & dgnc_offset_table[current_port]) != 0) {
  789. port = current_port;
  790. type = tmp >> (8 + (port * 3));
  791. type &= 0x7;
  792. } else {
  793. current_port++;
  794. continue;
  795. }
  796. /* Remove this port + type from uart_poll */
  797. uart_poll &= ~(dgnc_offset_table[port]);
  798. if (!type) {
  799. /* If no type, just ignore it, and move onto next port */
  800. continue;
  801. }
  802. /* Switch on type of interrupt we have */
  803. switch (type) {
  804. case UART_17158_RXRDY_TIMEOUT:
  805. /*
  806. * RXRDY Time-out is cleared by reading data in the
  807. * RX FIFO until it falls below the trigger level.
  808. */
  809. /* Verify the port is in range. */
  810. if (port >= brd->nasync)
  811. continue;
  812. ch = brd->channels[port];
  813. neo_copy_data_from_uart_to_queue(ch);
  814. /* Call our tty layer to enforce queue flow control if needed. */
  815. spin_lock_irqsave(&ch->ch_lock, flags2);
  816. dgnc_check_queue_flow_control(ch);
  817. spin_unlock_irqrestore(&ch->ch_lock, flags2);
  818. continue;
  819. case UART_17158_RX_LINE_STATUS:
  820. /*
  821. * RXRDY and RX LINE Status (logic OR of LSR[4:1])
  822. */
  823. neo_parse_lsr(brd, port);
  824. continue;
  825. case UART_17158_TXRDY:
  826. /*
  827. * TXRDY interrupt clears after reading ISR register for the UART channel.
  828. */
  829. /*
  830. * Yes, this is odd...
  831. * Why would I check EVERY possibility of type of
  832. * interrupt, when we know its TXRDY???
  833. * Becuz for some reason, even tho we got triggered for TXRDY,
  834. * it seems to be occasionally wrong. Instead of TX, which
  835. * it should be, I was getting things like RXDY too. Weird.
  836. */
  837. neo_parse_isr(brd, port);
  838. continue;
  839. case UART_17158_MSR:
  840. /*
  841. * MSR or flow control was seen.
  842. */
  843. neo_parse_isr(brd, port);
  844. continue;
  845. default:
  846. /*
  847. * The UART triggered us with a bogus interrupt type.
  848. * It appears the Exar chip, when REALLY bogged down, will throw
  849. * these once and awhile.
  850. * Its harmless, just ignore it and move on.
  851. */
  852. continue;
  853. }
  854. }
  855. /*
  856. * Schedule tasklet to more in-depth servicing at a better time.
  857. */
  858. tasklet_schedule(&brd->helper_tasklet);
  859. spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
  860. return IRQ_HANDLED;
  861. }
  862. /*
  863. * Neo specific way of turning off the receiver.
  864. * Used as a way to enforce queue flow control when in
  865. * hardware flow control mode.
  866. */
  867. static void neo_disable_receiver(struct channel_t *ch)
  868. {
  869. unsigned char tmp = readb(&ch->ch_neo_uart->ier);
  870. tmp &= ~(UART_IER_RDI);
  871. writeb(tmp, &ch->ch_neo_uart->ier);
  872. neo_pci_posting_flush(ch->ch_bd);
  873. }
  874. /*
  875. * Neo specific way of turning on the receiver.
  876. * Used as a way to un-enforce queue flow control when in
  877. * hardware flow control mode.
  878. */
  879. static void neo_enable_receiver(struct channel_t *ch)
  880. {
  881. unsigned char tmp = readb(&ch->ch_neo_uart->ier);
  882. tmp |= (UART_IER_RDI);
  883. writeb(tmp, &ch->ch_neo_uart->ier);
  884. neo_pci_posting_flush(ch->ch_bd);
  885. }
  886. static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
  887. {
  888. int qleft = 0;
  889. unsigned char linestatus = 0;
  890. unsigned char error_mask = 0;
  891. int n = 0;
  892. int total = 0;
  893. ushort head;
  894. ushort tail;
  895. unsigned long flags;
  896. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  897. return;
  898. spin_lock_irqsave(&ch->ch_lock, flags);
  899. /* cache head and tail of queue */
  900. head = ch->ch_r_head & RQUEUEMASK;
  901. tail = ch->ch_r_tail & RQUEUEMASK;
  902. /* Get our cached LSR */
  903. linestatus = ch->ch_cached_lsr;
  904. ch->ch_cached_lsr = 0;
  905. /* Store how much space we have left in the queue */
  906. qleft = tail - head - 1;
  907. if (qleft < 0)
  908. qleft += RQUEUEMASK + 1;
  909. /*
  910. * If the UART is not in FIFO mode, force the FIFO copy to
  911. * NOT be run, by setting total to 0.
  912. *
  913. * On the other hand, if the UART IS in FIFO mode, then ask
  914. * the UART to give us an approximation of data it has RX'ed.
  915. */
  916. if (!(ch->ch_flags & CH_FIFO_ENABLED))
  917. total = 0;
  918. else {
  919. total = readb(&ch->ch_neo_uart->rfifo);
  920. /*
  921. * EXAR chip bug - RX FIFO COUNT - Fudge factor.
  922. *
  923. * This resolves a problem/bug with the Exar chip that sometimes
  924. * returns a bogus value in the rfifo register.
  925. * The count can be any where from 0-3 bytes "off".
  926. * Bizarre, but true.
  927. */
  928. if ((ch->ch_bd->dvid & 0xf0) >= UART_XR17E158_DVID)
  929. total -= 1;
  930. else
  931. total -= 3;
  932. }
  933. /*
  934. * Finally, bound the copy to make sure we don't overflow
  935. * our own queue...
  936. * The byte by byte copy loop below this loop this will
  937. * deal with the queue overflow possibility.
  938. */
  939. total = min(total, qleft);
  940. while (total > 0) {
  941. /*
  942. * Grab the linestatus register, we need to check
  943. * to see if there are any errors in the FIFO.
  944. */
  945. linestatus = readb(&ch->ch_neo_uart->lsr);
  946. /*
  947. * Break out if there is a FIFO error somewhere.
  948. * This will allow us to go byte by byte down below,
  949. * finding the exact location of the error.
  950. */
  951. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  952. break;
  953. /* Make sure we don't go over the end of our queue */
  954. n = min(((uint)total), (RQUEUESIZE - (uint)head));
  955. /*
  956. * Cut down n even further if needed, this is to fix
  957. * a problem with memcpy_fromio() with the Neo on the
  958. * IBM pSeries platform.
  959. * 15 bytes max appears to be the magic number.
  960. */
  961. n = min_t(uint, n, 12);
  962. /*
  963. * Since we are grabbing the linestatus register, which
  964. * will reset some bits after our read, we need to ensure
  965. * we don't miss our TX FIFO emptys.
  966. */
  967. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
  968. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  969. linestatus = 0;
  970. /* Copy data from uart to the queue */
  971. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
  972. /*
  973. * Since RX_FIFO_DATA_ERROR was 0, we are guaranteed
  974. * that all the data currently in the FIFO is free of
  975. * breaks and parity/frame/orun errors.
  976. */
  977. memset(ch->ch_equeue + head, 0, n);
  978. /* Add to and flip head if needed */
  979. head = (head + n) & RQUEUEMASK;
  980. total -= n;
  981. qleft -= n;
  982. ch->ch_rxcount += n;
  983. }
  984. /*
  985. * Create a mask to determine whether we should
  986. * insert the character (if any) into our queue.
  987. */
  988. if (ch->ch_c_iflag & IGNBRK)
  989. error_mask |= UART_LSR_BI;
  990. /*
  991. * Now cleanup any leftover bytes still in the UART.
  992. * Also deal with any possible queue overflow here as well.
  993. */
  994. while (1) {
  995. /*
  996. * Its possible we have a linestatus from the loop above
  997. * this, so we "OR" on any extra bits.
  998. */
  999. linestatus |= readb(&ch->ch_neo_uart->lsr);
  1000. /*
  1001. * If the chip tells us there is no more data pending to
  1002. * be read, we can then leave.
  1003. * But before we do, cache the linestatus, just in case.
  1004. */
  1005. if (!(linestatus & UART_LSR_DR)) {
  1006. ch->ch_cached_lsr = linestatus;
  1007. break;
  1008. }
  1009. /* No need to store this bit */
  1010. linestatus &= ~UART_LSR_DR;
  1011. /*
  1012. * Since we are grabbing the linestatus register, which
  1013. * will reset some bits after our read, we need to ensure
  1014. * we don't miss our TX FIFO emptys.
  1015. */
  1016. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
  1017. linestatus &= ~(UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR);
  1018. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1019. }
  1020. /*
  1021. * Discard character if we are ignoring the error mask.
  1022. */
  1023. if (linestatus & error_mask) {
  1024. unsigned char discard;
  1025. linestatus = 0;
  1026. memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
  1027. continue;
  1028. }
  1029. /*
  1030. * If our queue is full, we have no choice but to drop some data.
  1031. * The assumption is that HWFLOW or SWFLOW should have stopped
  1032. * things way way before we got to this point.
  1033. *
  1034. * I decided that I wanted to ditch the oldest data first,
  1035. * I hope thats okay with everyone? Yes? Good.
  1036. */
  1037. while (qleft < 1) {
  1038. tail = (tail + 1) & RQUEUEMASK;
  1039. ch->ch_r_tail = tail;
  1040. ch->ch_err_overrun++;
  1041. qleft++;
  1042. }
  1043. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
  1044. ch->ch_equeue[head] = (unsigned char)linestatus;
  1045. /* Ditch any remaining linestatus value. */
  1046. linestatus = 0;
  1047. /* Add to and flip head if needed */
  1048. head = (head + 1) & RQUEUEMASK;
  1049. qleft--;
  1050. ch->ch_rxcount++;
  1051. }
  1052. /*
  1053. * Write new final heads to channel structure.
  1054. */
  1055. ch->ch_r_head = head & RQUEUEMASK;
  1056. ch->ch_e_head = head & EQUEUEMASK;
  1057. spin_unlock_irqrestore(&ch->ch_lock, flags);
  1058. }
  1059. /*
  1060. * This function basically goes to sleep for secs, or until
  1061. * it gets signalled that the port has fully drained.
  1062. */
  1063. static int neo_drain(struct tty_struct *tty, uint seconds)
  1064. {
  1065. unsigned long flags;
  1066. struct channel_t *ch;
  1067. struct un_t *un;
  1068. int rc = 0;
  1069. if (!tty || tty->magic != TTY_MAGIC)
  1070. return -ENXIO;
  1071. un = (struct un_t *)tty->driver_data;
  1072. if (!un || un->magic != DGNC_UNIT_MAGIC)
  1073. return -ENXIO;
  1074. ch = un->un_ch;
  1075. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1076. return -ENXIO;
  1077. spin_lock_irqsave(&ch->ch_lock, flags);
  1078. un->un_flags |= UN_EMPTY;
  1079. spin_unlock_irqrestore(&ch->ch_lock, flags);
  1080. /*
  1081. * Go to sleep waiting for the tty layer to wake me back up when
  1082. * the empty flag goes away.
  1083. *
  1084. * NOTE: TODO: Do something with time passed in.
  1085. */
  1086. rc = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
  1087. /* If ret is non-zero, user ctrl-c'ed us */
  1088. return rc;
  1089. }
  1090. /*
  1091. * Flush the WRITE FIFO on the Neo.
  1092. *
  1093. * NOTE: Channel lock MUST be held before calling this function!
  1094. */
  1095. static void neo_flush_uart_write(struct channel_t *ch)
  1096. {
  1097. unsigned char tmp = 0;
  1098. int i = 0;
  1099. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1100. return;
  1101. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  1102. neo_pci_posting_flush(ch->ch_bd);
  1103. for (i = 0; i < 10; i++) {
  1104. /* Check to see if the UART feels it completely flushed the FIFO. */
  1105. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  1106. if (tmp & 4)
  1107. udelay(10);
  1108. else
  1109. break;
  1110. }
  1111. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1112. }
  1113. /*
  1114. * Flush the READ FIFO on the Neo.
  1115. *
  1116. * NOTE: Channel lock MUST be held before calling this function!
  1117. */
  1118. static void neo_flush_uart_read(struct channel_t *ch)
  1119. {
  1120. unsigned char tmp = 0;
  1121. int i = 0;
  1122. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1123. return;
  1124. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
  1125. neo_pci_posting_flush(ch->ch_bd);
  1126. for (i = 0; i < 10; i++) {
  1127. /* Check to see if the UART feels it completely flushed the FIFO. */
  1128. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  1129. if (tmp & 2)
  1130. udelay(10);
  1131. else
  1132. break;
  1133. }
  1134. }
  1135. static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
  1136. {
  1137. ushort head;
  1138. ushort tail;
  1139. int n;
  1140. int s;
  1141. int qlen;
  1142. uint len_written = 0;
  1143. unsigned long flags;
  1144. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1145. return;
  1146. spin_lock_irqsave(&ch->ch_lock, flags);
  1147. /* No data to write to the UART */
  1148. if (ch->ch_w_tail == ch->ch_w_head)
  1149. goto exit_unlock;
  1150. /* If port is "stopped", don't send any data to the UART */
  1151. if ((ch->ch_flags & CH_FORCED_STOP) ||
  1152. (ch->ch_flags & CH_BREAK_SENDING))
  1153. goto exit_unlock;
  1154. /*
  1155. * If FIFOs are disabled. Send data directly to txrx register
  1156. */
  1157. if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
  1158. unsigned char lsrbits = readb(&ch->ch_neo_uart->lsr);
  1159. /* Cache the LSR bits for later parsing */
  1160. ch->ch_cached_lsr |= lsrbits;
  1161. if (ch->ch_cached_lsr & UART_LSR_THRE) {
  1162. ch->ch_cached_lsr &= ~(UART_LSR_THRE);
  1163. /*
  1164. * If RTS Toggle mode is on, turn on RTS now if not already set,
  1165. * and make sure we get an event when the data transfer has completed.
  1166. */
  1167. if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
  1168. if (!(ch->ch_mostat & UART_MCR_RTS)) {
  1169. ch->ch_mostat |= (UART_MCR_RTS);
  1170. neo_assert_modem_signals(ch);
  1171. }
  1172. ch->ch_tun.un_flags |= (UN_EMPTY);
  1173. }
  1174. /*
  1175. * If DTR Toggle mode is on, turn on DTR now if not already set,
  1176. * and make sure we get an event when the data transfer has completed.
  1177. */
  1178. if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
  1179. if (!(ch->ch_mostat & UART_MCR_DTR)) {
  1180. ch->ch_mostat |= (UART_MCR_DTR);
  1181. neo_assert_modem_signals(ch);
  1182. }
  1183. ch->ch_tun.un_flags |= (UN_EMPTY);
  1184. }
  1185. writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_neo_uart->txrx);
  1186. ch->ch_w_tail++;
  1187. ch->ch_w_tail &= WQUEUEMASK;
  1188. ch->ch_txcount++;
  1189. }
  1190. goto exit_unlock;
  1191. }
  1192. /*
  1193. * We have to do it this way, because of the EXAR TXFIFO count bug.
  1194. */
  1195. if ((ch->ch_bd->dvid & 0xf0) < UART_XR17E158_DVID) {
  1196. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  1197. goto exit_unlock;
  1198. len_written = 0;
  1199. n = readb(&ch->ch_neo_uart->tfifo);
  1200. if ((unsigned int)n > ch->ch_t_tlevel)
  1201. goto exit_unlock;
  1202. n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
  1203. } else {
  1204. n = UART_17158_TX_FIFOSIZE - readb(&ch->ch_neo_uart->tfifo);
  1205. }
  1206. /* cache head and tail of queue */
  1207. head = ch->ch_w_head & WQUEUEMASK;
  1208. tail = ch->ch_w_tail & WQUEUEMASK;
  1209. qlen = (head - tail) & WQUEUEMASK;
  1210. /* Find minimum of the FIFO space, versus queue length */
  1211. n = min(n, qlen);
  1212. while (n > 0) {
  1213. s = ((head >= tail) ? head : WQUEUESIZE) - tail;
  1214. s = min(s, n);
  1215. if (s <= 0)
  1216. break;
  1217. /*
  1218. * If RTS Toggle mode is on, turn on RTS now if not already set,
  1219. * and make sure we get an event when the data transfer has completed.
  1220. */
  1221. if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
  1222. if (!(ch->ch_mostat & UART_MCR_RTS)) {
  1223. ch->ch_mostat |= (UART_MCR_RTS);
  1224. neo_assert_modem_signals(ch);
  1225. }
  1226. ch->ch_tun.un_flags |= (UN_EMPTY);
  1227. }
  1228. /*
  1229. * If DTR Toggle mode is on, turn on DTR now if not already set,
  1230. * and make sure we get an event when the data transfer has completed.
  1231. */
  1232. if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
  1233. if (!(ch->ch_mostat & UART_MCR_DTR)) {
  1234. ch->ch_mostat |= (UART_MCR_DTR);
  1235. neo_assert_modem_signals(ch);
  1236. }
  1237. ch->ch_tun.un_flags |= (UN_EMPTY);
  1238. }
  1239. memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
  1240. /* Add and flip queue if needed */
  1241. tail = (tail + s) & WQUEUEMASK;
  1242. n -= s;
  1243. ch->ch_txcount += s;
  1244. len_written += s;
  1245. }
  1246. /* Update the final tail */
  1247. ch->ch_w_tail = tail & WQUEUEMASK;
  1248. if (len_written > 0) {
  1249. neo_pci_posting_flush(ch->ch_bd);
  1250. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1251. }
  1252. exit_unlock:
  1253. spin_unlock_irqrestore(&ch->ch_lock, flags);
  1254. }
  1255. static void neo_parse_modem(struct channel_t *ch, unsigned char signals)
  1256. {
  1257. unsigned char msignals = signals;
  1258. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1259. return;
  1260. /*
  1261. * Do altpin switching. Altpin switches DCD and DSR.
  1262. * This prolly breaks DSRPACE, so we should be more clever here.
  1263. */
  1264. if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
  1265. unsigned char mswap = msignals;
  1266. if (mswap & UART_MSR_DDCD) {
  1267. msignals &= ~UART_MSR_DDCD;
  1268. msignals |= UART_MSR_DDSR;
  1269. }
  1270. if (mswap & UART_MSR_DDSR) {
  1271. msignals &= ~UART_MSR_DDSR;
  1272. msignals |= UART_MSR_DDCD;
  1273. }
  1274. if (mswap & UART_MSR_DCD) {
  1275. msignals &= ~UART_MSR_DCD;
  1276. msignals |= UART_MSR_DSR;
  1277. }
  1278. if (mswap & UART_MSR_DSR) {
  1279. msignals &= ~UART_MSR_DSR;
  1280. msignals |= UART_MSR_DCD;
  1281. }
  1282. }
  1283. /* Scrub off lower bits. They signify delta's, which I don't care about */
  1284. msignals &= 0xf0;
  1285. if (msignals & UART_MSR_DCD)
  1286. ch->ch_mistat |= UART_MSR_DCD;
  1287. else
  1288. ch->ch_mistat &= ~UART_MSR_DCD;
  1289. if (msignals & UART_MSR_DSR)
  1290. ch->ch_mistat |= UART_MSR_DSR;
  1291. else
  1292. ch->ch_mistat &= ~UART_MSR_DSR;
  1293. if (msignals & UART_MSR_RI)
  1294. ch->ch_mistat |= UART_MSR_RI;
  1295. else
  1296. ch->ch_mistat &= ~UART_MSR_RI;
  1297. if (msignals & UART_MSR_CTS)
  1298. ch->ch_mistat |= UART_MSR_CTS;
  1299. else
  1300. ch->ch_mistat &= ~UART_MSR_CTS;
  1301. }
  1302. /* Make the UART raise any of the output signals we want up */
  1303. static void neo_assert_modem_signals(struct channel_t *ch)
  1304. {
  1305. unsigned char out;
  1306. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1307. return;
  1308. out = ch->ch_mostat;
  1309. if (ch->ch_flags & CH_LOOPBACK)
  1310. out |= UART_MCR_LOOP;
  1311. writeb(out, &ch->ch_neo_uart->mcr);
  1312. neo_pci_posting_flush(ch->ch_bd);
  1313. /* Give time for the UART to actually raise/drop the signals */
  1314. udelay(10);
  1315. }
  1316. static void neo_send_start_character(struct channel_t *ch)
  1317. {
  1318. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1319. return;
  1320. if (ch->ch_startc != _POSIX_VDISABLE) {
  1321. ch->ch_xon_sends++;
  1322. writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
  1323. neo_pci_posting_flush(ch->ch_bd);
  1324. udelay(10);
  1325. }
  1326. }
  1327. static void neo_send_stop_character(struct channel_t *ch)
  1328. {
  1329. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1330. return;
  1331. if (ch->ch_stopc != _POSIX_VDISABLE) {
  1332. ch->ch_xoff_sends++;
  1333. writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
  1334. neo_pci_posting_flush(ch->ch_bd);
  1335. udelay(10);
  1336. }
  1337. }
  1338. /*
  1339. * neo_uart_init
  1340. */
  1341. static void neo_uart_init(struct channel_t *ch)
  1342. {
  1343. writeb(0, &ch->ch_neo_uart->ier);
  1344. writeb(0, &ch->ch_neo_uart->efr);
  1345. writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
  1346. /* Clear out UART and FIFO */
  1347. readb(&ch->ch_neo_uart->txrx);
  1348. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  1349. readb(&ch->ch_neo_uart->lsr);
  1350. readb(&ch->ch_neo_uart->msr);
  1351. ch->ch_flags |= CH_FIFO_ENABLED;
  1352. /* Assert any signals we want up */
  1353. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  1354. neo_pci_posting_flush(ch->ch_bd);
  1355. }
  1356. /*
  1357. * Make the UART completely turn off.
  1358. */
  1359. static void neo_uart_off(struct channel_t *ch)
  1360. {
  1361. /* Turn off UART enhanced bits */
  1362. writeb(0, &ch->ch_neo_uart->efr);
  1363. /* Stop all interrupts from occurring. */
  1364. writeb(0, &ch->ch_neo_uart->ier);
  1365. neo_pci_posting_flush(ch->ch_bd);
  1366. }
  1367. static uint neo_get_uart_bytes_left(struct channel_t *ch)
  1368. {
  1369. unsigned char left = 0;
  1370. unsigned char lsr = readb(&ch->ch_neo_uart->lsr);
  1371. /* We must cache the LSR as some of the bits get reset once read... */
  1372. ch->ch_cached_lsr |= lsr;
  1373. /* Determine whether the Transmitter is empty or not */
  1374. if (!(lsr & UART_LSR_TEMT)) {
  1375. if (ch->ch_flags & CH_TX_FIFO_EMPTY)
  1376. tasklet_schedule(&ch->ch_bd->helper_tasklet);
  1377. left = 1;
  1378. } else {
  1379. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1380. left = 0;
  1381. }
  1382. return left;
  1383. }
  1384. /* Channel lock MUST be held by the calling function! */
  1385. static void neo_send_break(struct channel_t *ch, int msecs)
  1386. {
  1387. /*
  1388. * If we receive a time of 0, this means turn off the break.
  1389. */
  1390. if (msecs == 0) {
  1391. if (ch->ch_flags & CH_BREAK_SENDING) {
  1392. unsigned char temp = readb(&ch->ch_neo_uart->lcr);
  1393. writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  1394. neo_pci_posting_flush(ch->ch_bd);
  1395. ch->ch_flags &= ~(CH_BREAK_SENDING);
  1396. ch->ch_stop_sending_break = 0;
  1397. }
  1398. return;
  1399. }
  1400. /*
  1401. * Set the time we should stop sending the break.
  1402. * If we are already sending a break, toss away the existing
  1403. * time to stop, and use this new value instead.
  1404. */
  1405. ch->ch_stop_sending_break = jiffies + dgnc_jiffies_from_ms(msecs);
  1406. /* Tell the UART to start sending the break */
  1407. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  1408. unsigned char temp = readb(&ch->ch_neo_uart->lcr);
  1409. writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  1410. neo_pci_posting_flush(ch->ch_bd);
  1411. ch->ch_flags |= (CH_BREAK_SENDING);
  1412. }
  1413. }
  1414. /*
  1415. * neo_send_immediate_char.
  1416. *
  1417. * Sends a specific character as soon as possible to the UART,
  1418. * jumping over any bytes that might be in the write queue.
  1419. *
  1420. * The channel lock MUST be held by the calling function.
  1421. */
  1422. static void neo_send_immediate_char(struct channel_t *ch, unsigned char c)
  1423. {
  1424. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1425. return;
  1426. writeb(c, &ch->ch_neo_uart->txrx);
  1427. neo_pci_posting_flush(ch->ch_bd);
  1428. }
  1429. static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int address)
  1430. {
  1431. unsigned int enable;
  1432. unsigned int bits;
  1433. unsigned int databit;
  1434. unsigned int val;
  1435. /* enable chip select */
  1436. writeb(NEO_EECS, base + NEO_EEREG);
  1437. /* READ */
  1438. enable = (address | 0x180);
  1439. for (bits = 9; bits--; ) {
  1440. databit = (enable & (1 << bits)) ? NEO_EEDI : 0;
  1441. /* Set read address */
  1442. writeb(databit | NEO_EECS, base + NEO_EEREG);
  1443. writeb(databit | NEO_EECS | NEO_EECK, base + NEO_EEREG);
  1444. }
  1445. val = 0;
  1446. for (bits = 17; bits--; ) {
  1447. /* clock to EEPROM */
  1448. writeb(NEO_EECS, base + NEO_EEREG);
  1449. writeb(NEO_EECS | NEO_EECK, base + NEO_EEREG);
  1450. val <<= 1;
  1451. /* read EEPROM */
  1452. if (readb(base + NEO_EEREG) & NEO_EEDO)
  1453. val |= 1;
  1454. }
  1455. /* clock falling edge */
  1456. writeb(NEO_EECS, base + NEO_EEREG);
  1457. /* drop chip select */
  1458. writeb(0x00, base + NEO_EEREG);
  1459. return val;
  1460. }
  1461. static void neo_vpd(struct dgnc_board *brd)
  1462. {
  1463. unsigned int i = 0;
  1464. unsigned int a;
  1465. if (!brd || brd->magic != DGNC_BOARD_MAGIC)
  1466. return;
  1467. if (!brd->re_map_membase)
  1468. return;
  1469. /* Store the VPD into our buffer */
  1470. for (i = 0; i < NEO_VPD_IMAGESIZE; i++) {
  1471. a = neo_read_eeprom(brd->re_map_membase, i);
  1472. brd->vpd[i*2] = a & 0xff;
  1473. brd->vpd[(i*2)+1] = (a >> 8) & 0xff;
  1474. }
  1475. if (((brd->vpd[0x08] != 0x82) /* long resource name tag */
  1476. && (brd->vpd[0x10] != 0x82)) /* long resource name tag (PCI-66 files)*/
  1477. || (brd->vpd[0x7F] != 0x78)) { /* small resource end tag */
  1478. memset(brd->vpd, '\0', NEO_VPD_IMAGESIZE);
  1479. } else {
  1480. /* Search for the serial number */
  1481. for (i = 0; i < NEO_VPD_IMAGEBYTES - 3; i++)
  1482. if (brd->vpd[i] == 'S' && brd->vpd[i + 1] == 'N')
  1483. strncpy(brd->serial_num, &brd->vpd[i + 3], 9);
  1484. }
  1485. }