rocket.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185
  1. /*
  2. * RocketPort device driver for Linux
  3. *
  4. * Written by Theodore Ts'o, 1995, 1996, 1997, 1998, 1999, 2000.
  5. *
  6. * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2003 by Comtrol, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. /*
  23. * Kernel Synchronization:
  24. *
  25. * This driver has 2 kernel control paths - exception handlers (calls into the driver
  26. * from user mode) and the timer bottom half (tasklet). This is a polled driver, interrupts
  27. * are not used.
  28. *
  29. * Critical data:
  30. * - rp_table[], accessed through passed "info" pointers, is a global (static) array of
  31. * serial port state information and the xmit_buf circular buffer. Protected by
  32. * a per port spinlock.
  33. * - xmit_flags[], an array of ints indexed by line (port) number, indicating that there
  34. * is data to be transmitted. Protected by atomic bit operations.
  35. * - rp_num_ports, int indicating number of open ports, protected by atomic operations.
  36. *
  37. * rp_write() and rp_write_char() functions use a per port semaphore to protect against
  38. * simultaneous access to the same port by more than one process.
  39. */
  40. /****** Defines ******/
  41. #define ROCKET_PARANOIA_CHECK
  42. #define ROCKET_DISABLE_SIMUSAGE
  43. #undef ROCKET_SOFT_FLOW
  44. #undef ROCKET_DEBUG_OPEN
  45. #undef ROCKET_DEBUG_INTR
  46. #undef ROCKET_DEBUG_WRITE
  47. #undef ROCKET_DEBUG_FLOW
  48. #undef ROCKET_DEBUG_THROTTLE
  49. #undef ROCKET_DEBUG_WAIT_UNTIL_SENT
  50. #undef ROCKET_DEBUG_RECEIVE
  51. #undef ROCKET_DEBUG_HANGUP
  52. #undef REV_PCI_ORDER
  53. #undef ROCKET_DEBUG_IO
  54. #define POLL_PERIOD HZ/100 /* Polling period .01 seconds (10ms) */
  55. /****** Kernel includes ******/
  56. #include <linux/module.h>
  57. #include <linux/errno.h>
  58. #include <linux/major.h>
  59. #include <linux/kernel.h>
  60. #include <linux/signal.h>
  61. #include <linux/slab.h>
  62. #include <linux/mm.h>
  63. #include <linux/sched.h>
  64. #include <linux/timer.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/tty.h>
  67. #include <linux/tty_driver.h>
  68. #include <linux/tty_flip.h>
  69. #include <linux/serial.h>
  70. #include <linux/smp_lock.h>
  71. #include <linux/string.h>
  72. #include <linux/fcntl.h>
  73. #include <linux/ptrace.h>
  74. #include <linux/mutex.h>
  75. #include <linux/ioport.h>
  76. #include <linux/delay.h>
  77. #include <linux/completion.h>
  78. #include <linux/wait.h>
  79. #include <linux/pci.h>
  80. #include <linux/uaccess.h>
  81. #include <asm/atomic.h>
  82. #include <asm/unaligned.h>
  83. #include <linux/bitops.h>
  84. #include <linux/spinlock.h>
  85. #include <linux/init.h>
  86. /****** RocketPort includes ******/
  87. #include "rocket_int.h"
  88. #include "rocket.h"
  89. #define ROCKET_VERSION "2.09"
  90. #define ROCKET_DATE "12-June-2003"
  91. /****** RocketPort Local Variables ******/
  92. static void rp_do_poll(unsigned long dummy);
  93. static struct tty_driver *rocket_driver;
  94. static struct rocket_version driver_version = {
  95. ROCKET_VERSION, ROCKET_DATE
  96. };
  97. static struct r_port *rp_table[MAX_RP_PORTS]; /* The main repository of serial port state information. */
  98. static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */
  99. /* eg. Bit 0 indicates port 0 has xmit data, ... */
  100. static atomic_t rp_num_ports_open; /* Number of serial ports open */
  101. static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0);
  102. static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */
  103. static unsigned long board2;
  104. static unsigned long board3;
  105. static unsigned long board4;
  106. static unsigned long controller;
  107. static int support_low_speed;
  108. static unsigned long modem1;
  109. static unsigned long modem2;
  110. static unsigned long modem3;
  111. static unsigned long modem4;
  112. static unsigned long pc104_1[8];
  113. static unsigned long pc104_2[8];
  114. static unsigned long pc104_3[8];
  115. static unsigned long pc104_4[8];
  116. static unsigned long *pc104[4] = { pc104_1, pc104_2, pc104_3, pc104_4 };
  117. static int rp_baud_base[NUM_BOARDS]; /* Board config info (Someday make a per-board structure) */
  118. static unsigned long rcktpt_io_addr[NUM_BOARDS];
  119. static int rcktpt_type[NUM_BOARDS];
  120. static int is_PCI[NUM_BOARDS];
  121. static rocketModel_t rocketModel[NUM_BOARDS];
  122. static int max_board;
  123. static const struct tty_port_operations rocket_port_ops;
  124. /*
  125. * The following arrays define the interrupt bits corresponding to each AIOP.
  126. * These bits are different between the ISA and regular PCI boards and the
  127. * Universal PCI boards.
  128. */
  129. static Word_t aiop_intr_bits[AIOP_CTL_SIZE] = {
  130. AIOP_INTR_BIT_0,
  131. AIOP_INTR_BIT_1,
  132. AIOP_INTR_BIT_2,
  133. AIOP_INTR_BIT_3
  134. };
  135. static Word_t upci_aiop_intr_bits[AIOP_CTL_SIZE] = {
  136. UPCI_AIOP_INTR_BIT_0,
  137. UPCI_AIOP_INTR_BIT_1,
  138. UPCI_AIOP_INTR_BIT_2,
  139. UPCI_AIOP_INTR_BIT_3
  140. };
  141. static Byte_t RData[RDATASIZE] = {
  142. 0x00, 0x09, 0xf6, 0x82,
  143. 0x02, 0x09, 0x86, 0xfb,
  144. 0x04, 0x09, 0x00, 0x0a,
  145. 0x06, 0x09, 0x01, 0x0a,
  146. 0x08, 0x09, 0x8a, 0x13,
  147. 0x0a, 0x09, 0xc5, 0x11,
  148. 0x0c, 0x09, 0x86, 0x85,
  149. 0x0e, 0x09, 0x20, 0x0a,
  150. 0x10, 0x09, 0x21, 0x0a,
  151. 0x12, 0x09, 0x41, 0xff,
  152. 0x14, 0x09, 0x82, 0x00,
  153. 0x16, 0x09, 0x82, 0x7b,
  154. 0x18, 0x09, 0x8a, 0x7d,
  155. 0x1a, 0x09, 0x88, 0x81,
  156. 0x1c, 0x09, 0x86, 0x7a,
  157. 0x1e, 0x09, 0x84, 0x81,
  158. 0x20, 0x09, 0x82, 0x7c,
  159. 0x22, 0x09, 0x0a, 0x0a
  160. };
  161. static Byte_t RRegData[RREGDATASIZE] = {
  162. 0x00, 0x09, 0xf6, 0x82, /* 00: Stop Rx processor */
  163. 0x08, 0x09, 0x8a, 0x13, /* 04: Tx software flow control */
  164. 0x0a, 0x09, 0xc5, 0x11, /* 08: XON char */
  165. 0x0c, 0x09, 0x86, 0x85, /* 0c: XANY */
  166. 0x12, 0x09, 0x41, 0xff, /* 10: Rx mask char */
  167. 0x14, 0x09, 0x82, 0x00, /* 14: Compare/Ignore #0 */
  168. 0x16, 0x09, 0x82, 0x7b, /* 18: Compare #1 */
  169. 0x18, 0x09, 0x8a, 0x7d, /* 1c: Compare #2 */
  170. 0x1a, 0x09, 0x88, 0x81, /* 20: Interrupt #1 */
  171. 0x1c, 0x09, 0x86, 0x7a, /* 24: Ignore/Replace #1 */
  172. 0x1e, 0x09, 0x84, 0x81, /* 28: Interrupt #2 */
  173. 0x20, 0x09, 0x82, 0x7c, /* 2c: Ignore/Replace #2 */
  174. 0x22, 0x09, 0x0a, 0x0a /* 30: Rx FIFO Enable */
  175. };
  176. static CONTROLLER_T sController[CTL_SIZE] = {
  177. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  178. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  179. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  180. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  181. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  182. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  183. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  184. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}}
  185. };
  186. static Byte_t sBitMapClrTbl[8] = {
  187. 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f
  188. };
  189. static Byte_t sBitMapSetTbl[8] = {
  190. 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
  191. };
  192. static int sClockPrescale = 0x14;
  193. /*
  194. * Line number is the ttySIx number (x), the Minor number. We
  195. * assign them sequentially, starting at zero. The following
  196. * array keeps track of the line number assigned to a given board/aiop/channel.
  197. */
  198. static unsigned char lineNumbers[MAX_RP_PORTS];
  199. static unsigned long nextLineNumber;
  200. /***** RocketPort Static Prototypes *********/
  201. static int __init init_ISA(int i);
  202. static void rp_wait_until_sent(struct tty_struct *tty, int timeout);
  203. static void rp_flush_buffer(struct tty_struct *tty);
  204. static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model);
  205. static unsigned char GetLineNumber(int ctrl, int aiop, int ch);
  206. static unsigned char SetLineNumber(int ctrl, int aiop, int ch);
  207. static void rp_start(struct tty_struct *tty);
  208. static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
  209. int ChanNum);
  210. static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode);
  211. static void sFlushRxFIFO(CHANNEL_T * ChP);
  212. static void sFlushTxFIFO(CHANNEL_T * ChP);
  213. static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags);
  214. static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags);
  215. static void sModemReset(CONTROLLER_T * CtlP, int chan, int on);
  216. static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on);
  217. static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data);
  218. static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
  219. ByteIO_t * AiopIOList, int AiopIOListSize,
  220. WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
  221. int PeriodicOnly, int altChanRingIndicator,
  222. int UPCIRingInd);
  223. static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
  224. ByteIO_t * AiopIOList, int AiopIOListSize,
  225. int IRQNum, Byte_t Frequency, int PeriodicOnly);
  226. static int sReadAiopID(ByteIO_t io);
  227. static int sReadAiopNumChan(WordIO_t io);
  228. MODULE_AUTHOR("Theodore Ts'o");
  229. MODULE_DESCRIPTION("Comtrol RocketPort driver");
  230. module_param(board1, ulong, 0);
  231. MODULE_PARM_DESC(board1, "I/O port for (ISA) board #1");
  232. module_param(board2, ulong, 0);
  233. MODULE_PARM_DESC(board2, "I/O port for (ISA) board #2");
  234. module_param(board3, ulong, 0);
  235. MODULE_PARM_DESC(board3, "I/O port for (ISA) board #3");
  236. module_param(board4, ulong, 0);
  237. MODULE_PARM_DESC(board4, "I/O port for (ISA) board #4");
  238. module_param(controller, ulong, 0);
  239. MODULE_PARM_DESC(controller, "I/O port for (ISA) rocketport controller");
  240. module_param(support_low_speed, bool, 0);
  241. MODULE_PARM_DESC(support_low_speed, "1 means support 50 baud, 0 means support 460400 baud");
  242. module_param(modem1, ulong, 0);
  243. MODULE_PARM_DESC(modem1, "1 means (ISA) board #1 is a RocketModem");
  244. module_param(modem2, ulong, 0);
  245. MODULE_PARM_DESC(modem2, "1 means (ISA) board #2 is a RocketModem");
  246. module_param(modem3, ulong, 0);
  247. MODULE_PARM_DESC(modem3, "1 means (ISA) board #3 is a RocketModem");
  248. module_param(modem4, ulong, 0);
  249. MODULE_PARM_DESC(modem4, "1 means (ISA) board #4 is a RocketModem");
  250. module_param_array(pc104_1, ulong, NULL, 0);
  251. MODULE_PARM_DESC(pc104_1, "set interface types for ISA(PC104) board #1 (e.g. pc104_1=232,232,485,485,...");
  252. module_param_array(pc104_2, ulong, NULL, 0);
  253. MODULE_PARM_DESC(pc104_2, "set interface types for ISA(PC104) board #2 (e.g. pc104_2=232,232,485,485,...");
  254. module_param_array(pc104_3, ulong, NULL, 0);
  255. MODULE_PARM_DESC(pc104_3, "set interface types for ISA(PC104) board #3 (e.g. pc104_3=232,232,485,485,...");
  256. module_param_array(pc104_4, ulong, NULL, 0);
  257. MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,...");
  258. static int rp_init(void);
  259. static void rp_cleanup_module(void);
  260. module_init(rp_init);
  261. module_exit(rp_cleanup_module);
  262. MODULE_LICENSE("Dual BSD/GPL");
  263. /*************************************************************************/
  264. /* Module code starts here */
  265. static inline int rocket_paranoia_check(struct r_port *info,
  266. const char *routine)
  267. {
  268. #ifdef ROCKET_PARANOIA_CHECK
  269. if (!info)
  270. return 1;
  271. if (info->magic != RPORT_MAGIC) {
  272. printk(KERN_WARNING "Warning: bad magic number for rocketport "
  273. "struct in %s\n", routine);
  274. return 1;
  275. }
  276. #endif
  277. return 0;
  278. }
  279. /* Serial port receive data function. Called (from timer poll) when an AIOPIC signals
  280. * that receive data is present on a serial port. Pulls data from FIFO, moves it into the
  281. * tty layer.
  282. */
  283. static void rp_do_receive(struct r_port *info,
  284. struct tty_struct *tty,
  285. CHANNEL_t * cp, unsigned int ChanStatus)
  286. {
  287. unsigned int CharNStat;
  288. int ToRecv, wRecv, space;
  289. unsigned char *cbuf;
  290. ToRecv = sGetRxCnt(cp);
  291. #ifdef ROCKET_DEBUG_INTR
  292. printk(KERN_INFO "rp_do_receive(%d)...\n", ToRecv);
  293. #endif
  294. if (ToRecv == 0)
  295. return;
  296. /*
  297. * if status indicates there are errored characters in the
  298. * FIFO, then enter status mode (a word in FIFO holds
  299. * character and status).
  300. */
  301. if (ChanStatus & (RXFOVERFL | RXBREAK | RXFRAME | RXPARITY)) {
  302. if (!(ChanStatus & STATMODE)) {
  303. #ifdef ROCKET_DEBUG_RECEIVE
  304. printk(KERN_INFO "Entering STATMODE...\n");
  305. #endif
  306. ChanStatus |= STATMODE;
  307. sEnRxStatusMode(cp);
  308. }
  309. }
  310. /*
  311. * if we previously entered status mode, then read down the
  312. * FIFO one word at a time, pulling apart the character and
  313. * the status. Update error counters depending on status
  314. */
  315. if (ChanStatus & STATMODE) {
  316. #ifdef ROCKET_DEBUG_RECEIVE
  317. printk(KERN_INFO "Ignore %x, read %x...\n",
  318. info->ignore_status_mask, info->read_status_mask);
  319. #endif
  320. while (ToRecv) {
  321. char flag;
  322. CharNStat = sInW(sGetTxRxDataIO(cp));
  323. #ifdef ROCKET_DEBUG_RECEIVE
  324. printk(KERN_INFO "%x...\n", CharNStat);
  325. #endif
  326. if (CharNStat & STMBREAKH)
  327. CharNStat &= ~(STMFRAMEH | STMPARITYH);
  328. if (CharNStat & info->ignore_status_mask) {
  329. ToRecv--;
  330. continue;
  331. }
  332. CharNStat &= info->read_status_mask;
  333. if (CharNStat & STMBREAKH)
  334. flag = TTY_BREAK;
  335. else if (CharNStat & STMPARITYH)
  336. flag = TTY_PARITY;
  337. else if (CharNStat & STMFRAMEH)
  338. flag = TTY_FRAME;
  339. else if (CharNStat & STMRCVROVRH)
  340. flag = TTY_OVERRUN;
  341. else
  342. flag = TTY_NORMAL;
  343. tty_insert_flip_char(tty, CharNStat & 0xff, flag);
  344. ToRecv--;
  345. }
  346. /*
  347. * after we've emptied the FIFO in status mode, turn
  348. * status mode back off
  349. */
  350. if (sGetRxCnt(cp) == 0) {
  351. #ifdef ROCKET_DEBUG_RECEIVE
  352. printk(KERN_INFO "Status mode off.\n");
  353. #endif
  354. sDisRxStatusMode(cp);
  355. }
  356. } else {
  357. /*
  358. * we aren't in status mode, so read down the FIFO two
  359. * characters at time by doing repeated word IO
  360. * transfer.
  361. */
  362. space = tty_prepare_flip_string(tty, &cbuf, ToRecv);
  363. if (space < ToRecv) {
  364. #ifdef ROCKET_DEBUG_RECEIVE
  365. printk(KERN_INFO "rp_do_receive:insufficient space ToRecv=%d space=%d\n", ToRecv, space);
  366. #endif
  367. if (space <= 0)
  368. return;
  369. ToRecv = space;
  370. }
  371. wRecv = ToRecv >> 1;
  372. if (wRecv)
  373. sInStrW(sGetTxRxDataIO(cp), (unsigned short *) cbuf, wRecv);
  374. if (ToRecv & 1)
  375. cbuf[ToRecv - 1] = sInB(sGetTxRxDataIO(cp));
  376. }
  377. /* Push the data up to the tty layer */
  378. tty_flip_buffer_push(tty);
  379. }
  380. /*
  381. * Serial port transmit data function. Called from the timer polling loop as a
  382. * result of a bit set in xmit_flags[], indicating data (from the tty layer) is ready
  383. * to be sent out the serial port. Data is buffered in rp_table[line].xmit_buf, it is
  384. * moved to the port's xmit FIFO. *info is critical data, protected by spinlocks.
  385. */
  386. static void rp_do_transmit(struct r_port *info)
  387. {
  388. int c;
  389. CHANNEL_t *cp = &info->channel;
  390. struct tty_struct *tty;
  391. unsigned long flags;
  392. #ifdef ROCKET_DEBUG_INTR
  393. printk(KERN_DEBUG "%s\n", __func__);
  394. #endif
  395. if (!info)
  396. return;
  397. tty = tty_port_tty_get(&info->port);
  398. if (tty == NULL) {
  399. printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__);
  400. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  401. return;
  402. }
  403. spin_lock_irqsave(&info->slock, flags);
  404. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  405. /* Loop sending data to FIFO until done or FIFO full */
  406. while (1) {
  407. if (tty->stopped || tty->hw_stopped)
  408. break;
  409. c = min(info->xmit_fifo_room, info->xmit_cnt);
  410. c = min(c, XMIT_BUF_SIZE - info->xmit_tail);
  411. if (c <= 0 || info->xmit_fifo_room <= 0)
  412. break;
  413. sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) (info->xmit_buf + info->xmit_tail), c / 2);
  414. if (c & 1)
  415. sOutB(sGetTxRxDataIO(cp), info->xmit_buf[info->xmit_tail + c - 1]);
  416. info->xmit_tail += c;
  417. info->xmit_tail &= XMIT_BUF_SIZE - 1;
  418. info->xmit_cnt -= c;
  419. info->xmit_fifo_room -= c;
  420. #ifdef ROCKET_DEBUG_INTR
  421. printk(KERN_INFO "tx %d chars...\n", c);
  422. #endif
  423. }
  424. if (info->xmit_cnt == 0)
  425. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  426. if (info->xmit_cnt < WAKEUP_CHARS) {
  427. tty_wakeup(tty);
  428. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  429. wake_up_interruptible(&tty->poll_wait);
  430. #endif
  431. }
  432. spin_unlock_irqrestore(&info->slock, flags);
  433. tty_kref_put(tty);
  434. #ifdef ROCKET_DEBUG_INTR
  435. printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
  436. info->xmit_tail, info->xmit_fifo_room);
  437. #endif
  438. }
  439. /*
  440. * Called when a serial port signals it has read data in it's RX FIFO.
  441. * It checks what interrupts are pending and services them, including
  442. * receiving serial data.
  443. */
  444. static void rp_handle_port(struct r_port *info)
  445. {
  446. CHANNEL_t *cp;
  447. struct tty_struct *tty;
  448. unsigned int IntMask, ChanStatus;
  449. if (!info)
  450. return;
  451. if ((info->port.flags & ASYNC_INITIALIZED) == 0) {
  452. printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
  453. "info->flags & NOT_INIT\n");
  454. return;
  455. }
  456. tty = tty_port_tty_get(&info->port);
  457. if (!tty) {
  458. printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
  459. "tty==NULL\n");
  460. return;
  461. }
  462. cp = &info->channel;
  463. IntMask = sGetChanIntID(cp) & info->intmask;
  464. #ifdef ROCKET_DEBUG_INTR
  465. printk(KERN_INFO "rp_interrupt %02x...\n", IntMask);
  466. #endif
  467. ChanStatus = sGetChanStatus(cp);
  468. if (IntMask & RXF_TRIG) { /* Rx FIFO trigger level */
  469. rp_do_receive(info, tty, cp, ChanStatus);
  470. }
  471. if (IntMask & DELTA_CD) { /* CD change */
  472. #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_INTR) || defined(ROCKET_DEBUG_HANGUP))
  473. printk(KERN_INFO "ttyR%d CD now %s...\n", info->line,
  474. (ChanStatus & CD_ACT) ? "on" : "off");
  475. #endif
  476. if (!(ChanStatus & CD_ACT) && info->cd_status) {
  477. #ifdef ROCKET_DEBUG_HANGUP
  478. printk(KERN_INFO "CD drop, calling hangup.\n");
  479. #endif
  480. tty_hangup(tty);
  481. }
  482. info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0;
  483. wake_up_interruptible(&info->port.open_wait);
  484. }
  485. #ifdef ROCKET_DEBUG_INTR
  486. if (IntMask & DELTA_CTS) { /* CTS change */
  487. printk(KERN_INFO "CTS change...\n");
  488. }
  489. if (IntMask & DELTA_DSR) { /* DSR change */
  490. printk(KERN_INFO "DSR change...\n");
  491. }
  492. #endif
  493. tty_kref_put(tty);
  494. }
  495. /*
  496. * The top level polling routine. Repeats every 1/100 HZ (10ms).
  497. */
  498. static void rp_do_poll(unsigned long dummy)
  499. {
  500. CONTROLLER_t *ctlp;
  501. int ctrl, aiop, ch, line;
  502. unsigned int xmitmask, i;
  503. unsigned int CtlMask;
  504. unsigned char AiopMask;
  505. Word_t bit;
  506. /* Walk through all the boards (ctrl's) */
  507. for (ctrl = 0; ctrl < max_board; ctrl++) {
  508. if (rcktpt_io_addr[ctrl] <= 0)
  509. continue;
  510. /* Get a ptr to the board's control struct */
  511. ctlp = sCtlNumToCtlPtr(ctrl);
  512. /* Get the interrupt status from the board */
  513. #ifdef CONFIG_PCI
  514. if (ctlp->BusType == isPCI)
  515. CtlMask = sPCIGetControllerIntStatus(ctlp);
  516. else
  517. #endif
  518. CtlMask = sGetControllerIntStatus(ctlp);
  519. /* Check if any AIOP read bits are set */
  520. for (aiop = 0; CtlMask; aiop++) {
  521. bit = ctlp->AiopIntrBits[aiop];
  522. if (CtlMask & bit) {
  523. CtlMask &= ~bit;
  524. AiopMask = sGetAiopIntStatus(ctlp, aiop);
  525. /* Check if any port read bits are set */
  526. for (ch = 0; AiopMask; AiopMask >>= 1, ch++) {
  527. if (AiopMask & 1) {
  528. /* Get the line number (/dev/ttyRx number). */
  529. /* Read the data from the port. */
  530. line = GetLineNumber(ctrl, aiop, ch);
  531. rp_handle_port(rp_table[line]);
  532. }
  533. }
  534. }
  535. }
  536. xmitmask = xmit_flags[ctrl];
  537. /*
  538. * xmit_flags contains bit-significant flags, indicating there is data
  539. * to xmit on the port. Bit 0 is port 0 on this board, bit 1 is port
  540. * 1, ... (32 total possible). The variable i has the aiop and ch
  541. * numbers encoded in it (port 0-7 are aiop0, 8-15 are aiop1, etc).
  542. */
  543. if (xmitmask) {
  544. for (i = 0; i < rocketModel[ctrl].numPorts; i++) {
  545. if (xmitmask & (1 << i)) {
  546. aiop = (i & 0x18) >> 3;
  547. ch = i & 0x07;
  548. line = GetLineNumber(ctrl, aiop, ch);
  549. rp_do_transmit(rp_table[line]);
  550. }
  551. }
  552. }
  553. }
  554. /*
  555. * Reset the timer so we get called at the next clock tick (10ms).
  556. */
  557. if (atomic_read(&rp_num_ports_open))
  558. mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
  559. }
  560. /*
  561. * Initializes the r_port structure for a port, as well as enabling the port on
  562. * the board.
  563. * Inputs: board, aiop, chan numbers
  564. */
  565. static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
  566. {
  567. unsigned rocketMode;
  568. struct r_port *info;
  569. int line;
  570. CONTROLLER_T *ctlp;
  571. /* Get the next available line number */
  572. line = SetLineNumber(board, aiop, chan);
  573. ctlp = sCtlNumToCtlPtr(board);
  574. /* Get a r_port struct for the port, fill it in and save it globally, indexed by line number */
  575. info = kzalloc(sizeof (struct r_port), GFP_KERNEL);
  576. if (!info) {
  577. printk(KERN_ERR "Couldn't allocate info struct for line #%d\n",
  578. line);
  579. return;
  580. }
  581. info->magic = RPORT_MAGIC;
  582. info->line = line;
  583. info->ctlp = ctlp;
  584. info->board = board;
  585. info->aiop = aiop;
  586. info->chan = chan;
  587. tty_port_init(&info->port);
  588. info->port.ops = &rocket_port_ops;
  589. init_completion(&info->close_wait);
  590. info->flags &= ~ROCKET_MODE_MASK;
  591. switch (pc104[board][line]) {
  592. case 422:
  593. info->flags |= ROCKET_MODE_RS422;
  594. break;
  595. case 485:
  596. info->flags |= ROCKET_MODE_RS485;
  597. break;
  598. case 232:
  599. default:
  600. info->flags |= ROCKET_MODE_RS232;
  601. break;
  602. }
  603. info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR;
  604. if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
  605. printk(KERN_ERR "RocketPort sInitChan(%d, %d, %d) failed!\n",
  606. board, aiop, chan);
  607. kfree(info);
  608. return;
  609. }
  610. rocketMode = info->flags & ROCKET_MODE_MASK;
  611. if ((info->flags & ROCKET_RTS_TOGGLE) || (rocketMode == ROCKET_MODE_RS485))
  612. sEnRTSToggle(&info->channel);
  613. else
  614. sDisRTSToggle(&info->channel);
  615. if (ctlp->boardType == ROCKET_TYPE_PC104) {
  616. switch (rocketMode) {
  617. case ROCKET_MODE_RS485:
  618. sSetInterfaceMode(&info->channel, InterfaceModeRS485);
  619. break;
  620. case ROCKET_MODE_RS422:
  621. sSetInterfaceMode(&info->channel, InterfaceModeRS422);
  622. break;
  623. case ROCKET_MODE_RS232:
  624. default:
  625. if (info->flags & ROCKET_RTS_TOGGLE)
  626. sSetInterfaceMode(&info->channel, InterfaceModeRS232T);
  627. else
  628. sSetInterfaceMode(&info->channel, InterfaceModeRS232);
  629. break;
  630. }
  631. }
  632. spin_lock_init(&info->slock);
  633. mutex_init(&info->write_mtx);
  634. rp_table[line] = info;
  635. tty_register_device(rocket_driver, line, pci_dev ? &pci_dev->dev :
  636. NULL);
  637. }
  638. /*
  639. * Configures a rocketport port according to its termio settings. Called from
  640. * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
  641. */
  642. static void configure_r_port(struct tty_struct *tty, struct r_port *info,
  643. struct ktermios *old_termios)
  644. {
  645. unsigned cflag;
  646. unsigned long flags;
  647. unsigned rocketMode;
  648. int bits, baud, divisor;
  649. CHANNEL_t *cp;
  650. struct ktermios *t = tty->termios;
  651. cp = &info->channel;
  652. cflag = t->c_cflag;
  653. /* Byte size and parity */
  654. if ((cflag & CSIZE) == CS8) {
  655. sSetData8(cp);
  656. bits = 10;
  657. } else {
  658. sSetData7(cp);
  659. bits = 9;
  660. }
  661. if (cflag & CSTOPB) {
  662. sSetStop2(cp);
  663. bits++;
  664. } else {
  665. sSetStop1(cp);
  666. }
  667. if (cflag & PARENB) {
  668. sEnParity(cp);
  669. bits++;
  670. if (cflag & PARODD) {
  671. sSetOddParity(cp);
  672. } else {
  673. sSetEvenParity(cp);
  674. }
  675. } else {
  676. sDisParity(cp);
  677. }
  678. /* baud rate */
  679. baud = tty_get_baud_rate(tty);
  680. if (!baud)
  681. baud = 9600;
  682. divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
  683. if ((divisor >= 8192 || divisor < 0) && old_termios) {
  684. baud = tty_termios_baud_rate(old_termios);
  685. if (!baud)
  686. baud = 9600;
  687. divisor = (rp_baud_base[info->board] / baud) - 1;
  688. }
  689. if (divisor >= 8192 || divisor < 0) {
  690. baud = 9600;
  691. divisor = (rp_baud_base[info->board] / baud) - 1;
  692. }
  693. info->cps = baud / bits;
  694. sSetBaud(cp, divisor);
  695. /* FIXME: Should really back compute a baud rate from the divisor */
  696. tty_encode_baud_rate(tty, baud, baud);
  697. if (cflag & CRTSCTS) {
  698. info->intmask |= DELTA_CTS;
  699. sEnCTSFlowCtl(cp);
  700. } else {
  701. info->intmask &= ~DELTA_CTS;
  702. sDisCTSFlowCtl(cp);
  703. }
  704. if (cflag & CLOCAL) {
  705. info->intmask &= ~DELTA_CD;
  706. } else {
  707. spin_lock_irqsave(&info->slock, flags);
  708. if (sGetChanStatus(cp) & CD_ACT)
  709. info->cd_status = 1;
  710. else
  711. info->cd_status = 0;
  712. info->intmask |= DELTA_CD;
  713. spin_unlock_irqrestore(&info->slock, flags);
  714. }
  715. /*
  716. * Handle software flow control in the board
  717. */
  718. #ifdef ROCKET_SOFT_FLOW
  719. if (I_IXON(tty)) {
  720. sEnTxSoftFlowCtl(cp);
  721. if (I_IXANY(tty)) {
  722. sEnIXANY(cp);
  723. } else {
  724. sDisIXANY(cp);
  725. }
  726. sSetTxXONChar(cp, START_CHAR(tty));
  727. sSetTxXOFFChar(cp, STOP_CHAR(tty));
  728. } else {
  729. sDisTxSoftFlowCtl(cp);
  730. sDisIXANY(cp);
  731. sClrTxXOFF(cp);
  732. }
  733. #endif
  734. /*
  735. * Set up ignore/read mask words
  736. */
  737. info->read_status_mask = STMRCVROVRH | 0xFF;
  738. if (I_INPCK(tty))
  739. info->read_status_mask |= STMFRAMEH | STMPARITYH;
  740. if (I_BRKINT(tty) || I_PARMRK(tty))
  741. info->read_status_mask |= STMBREAKH;
  742. /*
  743. * Characters to ignore
  744. */
  745. info->ignore_status_mask = 0;
  746. if (I_IGNPAR(tty))
  747. info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
  748. if (I_IGNBRK(tty)) {
  749. info->ignore_status_mask |= STMBREAKH;
  750. /*
  751. * If we're ignoring parity and break indicators,
  752. * ignore overruns too. (For real raw support).
  753. */
  754. if (I_IGNPAR(tty))
  755. info->ignore_status_mask |= STMRCVROVRH;
  756. }
  757. rocketMode = info->flags & ROCKET_MODE_MASK;
  758. if ((info->flags & ROCKET_RTS_TOGGLE)
  759. || (rocketMode == ROCKET_MODE_RS485))
  760. sEnRTSToggle(cp);
  761. else
  762. sDisRTSToggle(cp);
  763. sSetRTS(&info->channel);
  764. if (cp->CtlP->boardType == ROCKET_TYPE_PC104) {
  765. switch (rocketMode) {
  766. case ROCKET_MODE_RS485:
  767. sSetInterfaceMode(cp, InterfaceModeRS485);
  768. break;
  769. case ROCKET_MODE_RS422:
  770. sSetInterfaceMode(cp, InterfaceModeRS422);
  771. break;
  772. case ROCKET_MODE_RS232:
  773. default:
  774. if (info->flags & ROCKET_RTS_TOGGLE)
  775. sSetInterfaceMode(cp, InterfaceModeRS232T);
  776. else
  777. sSetInterfaceMode(cp, InterfaceModeRS232);
  778. break;
  779. }
  780. }
  781. }
  782. static int carrier_raised(struct tty_port *port)
  783. {
  784. struct r_port *info = container_of(port, struct r_port, port);
  785. return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
  786. }
  787. static void dtr_rts(struct tty_port *port, int on)
  788. {
  789. struct r_port *info = container_of(port, struct r_port, port);
  790. if (on) {
  791. sSetDTR(&info->channel);
  792. sSetRTS(&info->channel);
  793. } else {
  794. sClrDTR(&info->channel);
  795. sClrRTS(&info->channel);
  796. }
  797. }
  798. /*
  799. * Exception handler that opens a serial port. Creates xmit_buf storage, fills in
  800. * port's r_port struct. Initializes the port hardware.
  801. */
  802. static int rp_open(struct tty_struct *tty, struct file *filp)
  803. {
  804. struct r_port *info;
  805. struct tty_port *port;
  806. int line = 0, retval;
  807. CHANNEL_t *cp;
  808. unsigned long page;
  809. line = tty->index;
  810. if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
  811. return -ENXIO;
  812. port = &info->port;
  813. page = __get_free_page(GFP_KERNEL);
  814. if (!page)
  815. return -ENOMEM;
  816. if (port->flags & ASYNC_CLOSING) {
  817. retval = wait_for_completion_interruptible(&info->close_wait);
  818. free_page(page);
  819. if (retval)
  820. return retval;
  821. return ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  822. }
  823. /*
  824. * We must not sleep from here until the port is marked fully in use.
  825. */
  826. if (info->xmit_buf)
  827. free_page(page);
  828. else
  829. info->xmit_buf = (unsigned char *) page;
  830. tty->driver_data = info;
  831. tty_port_tty_set(port, tty);
  832. if (port->count++ == 0) {
  833. atomic_inc(&rp_num_ports_open);
  834. #ifdef ROCKET_DEBUG_OPEN
  835. printk(KERN_INFO "rocket mod++ = %d...\n",
  836. atomic_read(&rp_num_ports_open));
  837. #endif
  838. }
  839. #ifdef ROCKET_DEBUG_OPEN
  840. printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
  841. #endif
  842. /*
  843. * Info->count is now 1; so it's safe to sleep now.
  844. */
  845. if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
  846. cp = &info->channel;
  847. sSetRxTrigger(cp, TRIG_1);
  848. if (sGetChanStatus(cp) & CD_ACT)
  849. info->cd_status = 1;
  850. else
  851. info->cd_status = 0;
  852. sDisRxStatusMode(cp);
  853. sFlushRxFIFO(cp);
  854. sFlushTxFIFO(cp);
  855. sEnInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  856. sSetRxTrigger(cp, TRIG_1);
  857. sGetChanStatus(cp);
  858. sDisRxStatusMode(cp);
  859. sClrTxXOFF(cp);
  860. sDisCTSFlowCtl(cp);
  861. sDisTxSoftFlowCtl(cp);
  862. sEnRxFIFO(cp);
  863. sEnTransmit(cp);
  864. set_bit(ASYNCB_INITIALIZED, &info->port.flags);
  865. /*
  866. * Set up the tty->alt_speed kludge
  867. */
  868. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
  869. tty->alt_speed = 57600;
  870. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
  871. tty->alt_speed = 115200;
  872. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
  873. tty->alt_speed = 230400;
  874. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
  875. tty->alt_speed = 460800;
  876. configure_r_port(tty, info, NULL);
  877. if (tty->termios->c_cflag & CBAUD) {
  878. sSetDTR(cp);
  879. sSetRTS(cp);
  880. }
  881. }
  882. /* Starts (or resets) the maint polling loop */
  883. mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
  884. retval = tty_port_block_til_ready(port, tty, filp);
  885. if (retval) {
  886. #ifdef ROCKET_DEBUG_OPEN
  887. printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval);
  888. #endif
  889. return retval;
  890. }
  891. return 0;
  892. }
  893. /*
  894. * Exception handler that closes a serial port. info->port.count is considered critical.
  895. */
  896. static void rp_close(struct tty_struct *tty, struct file *filp)
  897. {
  898. struct r_port *info = tty->driver_data;
  899. struct tty_port *port = &info->port;
  900. int timeout;
  901. CHANNEL_t *cp;
  902. if (rocket_paranoia_check(info, "rp_close"))
  903. return;
  904. #ifdef ROCKET_DEBUG_OPEN
  905. printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count);
  906. #endif
  907. if (tty_port_close_start(port, tty, filp) == 0)
  908. return;
  909. cp = &info->channel;
  910. /*
  911. * Before we drop DTR, make sure the UART transmitter
  912. * has completely drained; this is especially
  913. * important if there is a transmit FIFO!
  914. */
  915. timeout = (sGetTxCnt(cp) + 1) * HZ / info->cps;
  916. if (timeout == 0)
  917. timeout = 1;
  918. rp_wait_until_sent(tty, timeout);
  919. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  920. sDisTransmit(cp);
  921. sDisInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  922. sDisCTSFlowCtl(cp);
  923. sDisTxSoftFlowCtl(cp);
  924. sClrTxXOFF(cp);
  925. sFlushRxFIFO(cp);
  926. sFlushTxFIFO(cp);
  927. sClrRTS(cp);
  928. if (C_HUPCL(tty))
  929. sClrDTR(cp);
  930. rp_flush_buffer(tty);
  931. tty_ldisc_flush(tty);
  932. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  933. /* We can't yet use tty_port_close_end as the buffer handling in this
  934. driver is a bit different to the usual */
  935. if (port->blocked_open) {
  936. if (port->close_delay) {
  937. msleep_interruptible(jiffies_to_msecs(port->close_delay));
  938. }
  939. wake_up_interruptible(&port->open_wait);
  940. } else {
  941. if (info->xmit_buf) {
  942. free_page((unsigned long) info->xmit_buf);
  943. info->xmit_buf = NULL;
  944. }
  945. }
  946. info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE);
  947. tty->closing = 0;
  948. tty_port_tty_set(port, NULL);
  949. wake_up_interruptible(&port->close_wait);
  950. complete_all(&info->close_wait);
  951. atomic_dec(&rp_num_ports_open);
  952. #ifdef ROCKET_DEBUG_OPEN
  953. printk(KERN_INFO "rocket mod-- = %d...\n",
  954. atomic_read(&rp_num_ports_open));
  955. printk(KERN_INFO "rp_close ttyR%d complete shutdown\n", info->line);
  956. #endif
  957. }
  958. static void rp_set_termios(struct tty_struct *tty,
  959. struct ktermios *old_termios)
  960. {
  961. struct r_port *info = tty->driver_data;
  962. CHANNEL_t *cp;
  963. unsigned cflag;
  964. if (rocket_paranoia_check(info, "rp_set_termios"))
  965. return;
  966. cflag = tty->termios->c_cflag;
  967. /*
  968. * This driver doesn't support CS5 or CS6
  969. */
  970. if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6))
  971. tty->termios->c_cflag =
  972. ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE));
  973. /* Or CMSPAR */
  974. tty->termios->c_cflag &= ~CMSPAR;
  975. configure_r_port(tty, info, old_termios);
  976. cp = &info->channel;
  977. /* Handle transition to B0 status */
  978. if ((old_termios->c_cflag & CBAUD) && !(tty->termios->c_cflag & CBAUD)) {
  979. sClrDTR(cp);
  980. sClrRTS(cp);
  981. }
  982. /* Handle transition away from B0 status */
  983. if (!(old_termios->c_cflag & CBAUD) && (tty->termios->c_cflag & CBAUD)) {
  984. if (!tty->hw_stopped || !(tty->termios->c_cflag & CRTSCTS))
  985. sSetRTS(cp);
  986. sSetDTR(cp);
  987. }
  988. if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
  989. tty->hw_stopped = 0;
  990. rp_start(tty);
  991. }
  992. }
  993. static int rp_break(struct tty_struct *tty, int break_state)
  994. {
  995. struct r_port *info = tty->driver_data;
  996. unsigned long flags;
  997. if (rocket_paranoia_check(info, "rp_break"))
  998. return -EINVAL;
  999. spin_lock_irqsave(&info->slock, flags);
  1000. if (break_state == -1)
  1001. sSendBreak(&info->channel);
  1002. else
  1003. sClrBreak(&info->channel);
  1004. spin_unlock_irqrestore(&info->slock, flags);
  1005. return 0;
  1006. }
  1007. /*
  1008. * sGetChanRI used to be a macro in rocket_int.h. When the functionality for
  1009. * the UPCI boards was added, it was decided to make this a function because
  1010. * the macro was getting too complicated. All cases except the first one
  1011. * (UPCIRingInd) are taken directly from the original macro.
  1012. */
  1013. static int sGetChanRI(CHANNEL_T * ChP)
  1014. {
  1015. CONTROLLER_t *CtlP = ChP->CtlP;
  1016. int ChanNum = ChP->ChanNum;
  1017. int RingInd = 0;
  1018. if (CtlP->UPCIRingInd)
  1019. RingInd = !(sInB(CtlP->UPCIRingInd) & sBitMapSetTbl[ChanNum]);
  1020. else if (CtlP->AltChanRingIndicator)
  1021. RingInd = sInB((ByteIO_t) (ChP->ChanStat + 8)) & DSR_ACT;
  1022. else if (CtlP->boardType == ROCKET_TYPE_PC104)
  1023. RingInd = !(sInB(CtlP->AiopIO[3]) & sBitMapSetTbl[ChanNum]);
  1024. return RingInd;
  1025. }
  1026. /********************************************************************************************/
  1027. /* Here are the routines used by rp_ioctl. These are all called from exception handlers. */
  1028. /*
  1029. * Returns the state of the serial modem control lines. These next 2 functions
  1030. * are the way kernel versions > 2.5 handle modem control lines rather than IOCTLs.
  1031. */
  1032. static int rp_tiocmget(struct tty_struct *tty, struct file *file)
  1033. {
  1034. struct r_port *info = tty->driver_data;
  1035. unsigned int control, result, ChanStatus;
  1036. ChanStatus = sGetChanStatusLo(&info->channel);
  1037. control = info->channel.TxControl[3];
  1038. result = ((control & SET_RTS) ? TIOCM_RTS : 0) |
  1039. ((control & SET_DTR) ? TIOCM_DTR : 0) |
  1040. ((ChanStatus & CD_ACT) ? TIOCM_CAR : 0) |
  1041. (sGetChanRI(&info->channel) ? TIOCM_RNG : 0) |
  1042. ((ChanStatus & DSR_ACT) ? TIOCM_DSR : 0) |
  1043. ((ChanStatus & CTS_ACT) ? TIOCM_CTS : 0);
  1044. return result;
  1045. }
  1046. /*
  1047. * Sets the modem control lines
  1048. */
  1049. static int rp_tiocmset(struct tty_struct *tty, struct file *file,
  1050. unsigned int set, unsigned int clear)
  1051. {
  1052. struct r_port *info = tty->driver_data;
  1053. if (set & TIOCM_RTS)
  1054. info->channel.TxControl[3] |= SET_RTS;
  1055. if (set & TIOCM_DTR)
  1056. info->channel.TxControl[3] |= SET_DTR;
  1057. if (clear & TIOCM_RTS)
  1058. info->channel.TxControl[3] &= ~SET_RTS;
  1059. if (clear & TIOCM_DTR)
  1060. info->channel.TxControl[3] &= ~SET_DTR;
  1061. out32(info->channel.IndexAddr, info->channel.TxControl);
  1062. return 0;
  1063. }
  1064. static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
  1065. {
  1066. struct rocket_config tmp;
  1067. if (!retinfo)
  1068. return -EFAULT;
  1069. memset(&tmp, 0, sizeof (tmp));
  1070. tmp.line = info->line;
  1071. tmp.flags = info->flags;
  1072. tmp.close_delay = info->port.close_delay;
  1073. tmp.closing_wait = info->port.closing_wait;
  1074. tmp.port = rcktpt_io_addr[(info->line >> 5) & 3];
  1075. if (copy_to_user(retinfo, &tmp, sizeof (*retinfo)))
  1076. return -EFAULT;
  1077. return 0;
  1078. }
  1079. static int set_config(struct tty_struct *tty, struct r_port *info,
  1080. struct rocket_config __user *new_info)
  1081. {
  1082. struct rocket_config new_serial;
  1083. if (copy_from_user(&new_serial, new_info, sizeof (new_serial)))
  1084. return -EFAULT;
  1085. if (!capable(CAP_SYS_ADMIN))
  1086. {
  1087. if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
  1088. return -EPERM;
  1089. info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
  1090. configure_r_port(tty, info, NULL);
  1091. return 0;
  1092. }
  1093. info->flags = ((info->flags & ~ROCKET_FLAGS) | (new_serial.flags & ROCKET_FLAGS));
  1094. info->port.close_delay = new_serial.close_delay;
  1095. info->port.closing_wait = new_serial.closing_wait;
  1096. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
  1097. tty->alt_speed = 57600;
  1098. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
  1099. tty->alt_speed = 115200;
  1100. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
  1101. tty->alt_speed = 230400;
  1102. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
  1103. tty->alt_speed = 460800;
  1104. configure_r_port(tty, info, NULL);
  1105. return 0;
  1106. }
  1107. /*
  1108. * This function fills in a rocket_ports struct with information
  1109. * about what boards/ports are in the system. This info is passed
  1110. * to user space. See setrocket.c where the info is used to create
  1111. * the /dev/ttyRx ports.
  1112. */
  1113. static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
  1114. {
  1115. struct rocket_ports tmp;
  1116. int board;
  1117. if (!retports)
  1118. return -EFAULT;
  1119. memset(&tmp, 0, sizeof (tmp));
  1120. tmp.tty_major = rocket_driver->major;
  1121. for (board = 0; board < 4; board++) {
  1122. tmp.rocketModel[board].model = rocketModel[board].model;
  1123. strcpy(tmp.rocketModel[board].modelString, rocketModel[board].modelString);
  1124. tmp.rocketModel[board].numPorts = rocketModel[board].numPorts;
  1125. tmp.rocketModel[board].loadrm2 = rocketModel[board].loadrm2;
  1126. tmp.rocketModel[board].startingPortNumber = rocketModel[board].startingPortNumber;
  1127. }
  1128. if (copy_to_user(retports, &tmp, sizeof (*retports)))
  1129. return -EFAULT;
  1130. return 0;
  1131. }
  1132. static int reset_rm2(struct r_port *info, void __user *arg)
  1133. {
  1134. int reset;
  1135. if (!capable(CAP_SYS_ADMIN))
  1136. return -EPERM;
  1137. if (copy_from_user(&reset, arg, sizeof (int)))
  1138. return -EFAULT;
  1139. if (reset)
  1140. reset = 1;
  1141. if (rcktpt_type[info->board] != ROCKET_TYPE_MODEMII &&
  1142. rcktpt_type[info->board] != ROCKET_TYPE_MODEMIII)
  1143. return -EINVAL;
  1144. if (info->ctlp->BusType == isISA)
  1145. sModemReset(info->ctlp, info->chan, reset);
  1146. else
  1147. sPCIModemReset(info->ctlp, info->chan, reset);
  1148. return 0;
  1149. }
  1150. static int get_version(struct r_port *info, struct rocket_version __user *retvers)
  1151. {
  1152. if (copy_to_user(retvers, &driver_version, sizeof (*retvers)))
  1153. return -EFAULT;
  1154. return 0;
  1155. }
  1156. /* IOCTL call handler into the driver */
  1157. static int rp_ioctl(struct tty_struct *tty, struct file *file,
  1158. unsigned int cmd, unsigned long arg)
  1159. {
  1160. struct r_port *info = tty->driver_data;
  1161. void __user *argp = (void __user *)arg;
  1162. int ret = 0;
  1163. if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl"))
  1164. return -ENXIO;
  1165. lock_kernel();
  1166. switch (cmd) {
  1167. case RCKP_GET_STRUCT:
  1168. if (copy_to_user(argp, info, sizeof (struct r_port)))
  1169. ret = -EFAULT;
  1170. break;
  1171. case RCKP_GET_CONFIG:
  1172. ret = get_config(info, argp);
  1173. break;
  1174. case RCKP_SET_CONFIG:
  1175. ret = set_config(tty, info, argp);
  1176. break;
  1177. case RCKP_GET_PORTS:
  1178. ret = get_ports(info, argp);
  1179. break;
  1180. case RCKP_RESET_RM2:
  1181. ret = reset_rm2(info, argp);
  1182. break;
  1183. case RCKP_GET_VERSION:
  1184. ret = get_version(info, argp);
  1185. break;
  1186. default:
  1187. ret = -ENOIOCTLCMD;
  1188. }
  1189. unlock_kernel();
  1190. return ret;
  1191. }
  1192. static void rp_send_xchar(struct tty_struct *tty, char ch)
  1193. {
  1194. struct r_port *info = tty->driver_data;
  1195. CHANNEL_t *cp;
  1196. if (rocket_paranoia_check(info, "rp_send_xchar"))
  1197. return;
  1198. cp = &info->channel;
  1199. if (sGetTxCnt(cp))
  1200. sWriteTxPrioByte(cp, ch);
  1201. else
  1202. sWriteTxByte(sGetTxRxDataIO(cp), ch);
  1203. }
  1204. static void rp_throttle(struct tty_struct *tty)
  1205. {
  1206. struct r_port *info = tty->driver_data;
  1207. CHANNEL_t *cp;
  1208. #ifdef ROCKET_DEBUG_THROTTLE
  1209. printk(KERN_INFO "throttle %s: %d....\n", tty->name,
  1210. tty->ldisc.chars_in_buffer(tty));
  1211. #endif
  1212. if (rocket_paranoia_check(info, "rp_throttle"))
  1213. return;
  1214. cp = &info->channel;
  1215. if (I_IXOFF(tty))
  1216. rp_send_xchar(tty, STOP_CHAR(tty));
  1217. sClrRTS(&info->channel);
  1218. }
  1219. static void rp_unthrottle(struct tty_struct *tty)
  1220. {
  1221. struct r_port *info = tty->driver_data;
  1222. CHANNEL_t *cp;
  1223. #ifdef ROCKET_DEBUG_THROTTLE
  1224. printk(KERN_INFO "unthrottle %s: %d....\n", tty->name,
  1225. tty->ldisc.chars_in_buffer(tty));
  1226. #endif
  1227. if (rocket_paranoia_check(info, "rp_throttle"))
  1228. return;
  1229. cp = &info->channel;
  1230. if (I_IXOFF(tty))
  1231. rp_send_xchar(tty, START_CHAR(tty));
  1232. sSetRTS(&info->channel);
  1233. }
  1234. /*
  1235. * ------------------------------------------------------------
  1236. * rp_stop() and rp_start()
  1237. *
  1238. * This routines are called before setting or resetting tty->stopped.
  1239. * They enable or disable transmitter interrupts, as necessary.
  1240. * ------------------------------------------------------------
  1241. */
  1242. static void rp_stop(struct tty_struct *tty)
  1243. {
  1244. struct r_port *info = tty->driver_data;
  1245. #ifdef ROCKET_DEBUG_FLOW
  1246. printk(KERN_INFO "stop %s: %d %d....\n", tty->name,
  1247. info->xmit_cnt, info->xmit_fifo_room);
  1248. #endif
  1249. if (rocket_paranoia_check(info, "rp_stop"))
  1250. return;
  1251. if (sGetTxCnt(&info->channel))
  1252. sDisTransmit(&info->channel);
  1253. }
  1254. static void rp_start(struct tty_struct *tty)
  1255. {
  1256. struct r_port *info = tty->driver_data;
  1257. #ifdef ROCKET_DEBUG_FLOW
  1258. printk(KERN_INFO "start %s: %d %d....\n", tty->name,
  1259. info->xmit_cnt, info->xmit_fifo_room);
  1260. #endif
  1261. if (rocket_paranoia_check(info, "rp_stop"))
  1262. return;
  1263. sEnTransmit(&info->channel);
  1264. set_bit((info->aiop * 8) + info->chan,
  1265. (void *) &xmit_flags[info->board]);
  1266. }
  1267. /*
  1268. * rp_wait_until_sent() --- wait until the transmitter is empty
  1269. */
  1270. static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
  1271. {
  1272. struct r_port *info = tty->driver_data;
  1273. CHANNEL_t *cp;
  1274. unsigned long orig_jiffies;
  1275. int check_time, exit_time;
  1276. int txcnt;
  1277. if (rocket_paranoia_check(info, "rp_wait_until_sent"))
  1278. return;
  1279. cp = &info->channel;
  1280. orig_jiffies = jiffies;
  1281. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1282. printk(KERN_INFO "In RP_wait_until_sent(%d) (jiff=%lu)...\n", timeout,
  1283. jiffies);
  1284. printk(KERN_INFO "cps=%d...\n", info->cps);
  1285. #endif
  1286. lock_kernel();
  1287. while (1) {
  1288. txcnt = sGetTxCnt(cp);
  1289. if (!txcnt) {
  1290. if (sGetChanStatusLo(cp) & TXSHRMT)
  1291. break;
  1292. check_time = (HZ / info->cps) / 5;
  1293. } else {
  1294. check_time = HZ * txcnt / info->cps;
  1295. }
  1296. if (timeout) {
  1297. exit_time = orig_jiffies + timeout - jiffies;
  1298. if (exit_time <= 0)
  1299. break;
  1300. if (exit_time < check_time)
  1301. check_time = exit_time;
  1302. }
  1303. if (check_time == 0)
  1304. check_time = 1;
  1305. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1306. printk(KERN_INFO "txcnt = %d (jiff=%lu,check=%d)...\n", txcnt,
  1307. jiffies, check_time);
  1308. #endif
  1309. msleep_interruptible(jiffies_to_msecs(check_time));
  1310. if (signal_pending(current))
  1311. break;
  1312. }
  1313. __set_current_state(TASK_RUNNING);
  1314. unlock_kernel();
  1315. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1316. printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
  1317. #endif
  1318. }
  1319. /*
  1320. * rp_hangup() --- called by tty_hangup() when a hangup is signaled.
  1321. */
  1322. static void rp_hangup(struct tty_struct *tty)
  1323. {
  1324. CHANNEL_t *cp;
  1325. struct r_port *info = tty->driver_data;
  1326. if (rocket_paranoia_check(info, "rp_hangup"))
  1327. return;
  1328. #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_HANGUP))
  1329. printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
  1330. #endif
  1331. rp_flush_buffer(tty);
  1332. if (info->port.flags & ASYNC_CLOSING)
  1333. return;
  1334. if (info->port.count)
  1335. atomic_dec(&rp_num_ports_open);
  1336. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1337. tty_port_hangup(&info->port);
  1338. cp = &info->channel;
  1339. sDisRxFIFO(cp);
  1340. sDisTransmit(cp);
  1341. sDisInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  1342. sDisCTSFlowCtl(cp);
  1343. sDisTxSoftFlowCtl(cp);
  1344. sClrTxXOFF(cp);
  1345. info->port.flags &= ~ASYNC_INITIALIZED;
  1346. wake_up_interruptible(&info->port.open_wait);
  1347. }
  1348. /*
  1349. * Exception handler - write char routine. The RocketPort driver uses a
  1350. * double-buffering strategy, with the twist that if the in-memory CPU
  1351. * buffer is empty, and there's space in the transmit FIFO, the
  1352. * writing routines will write directly to transmit FIFO.
  1353. * Write buffer and counters protected by spinlocks
  1354. */
  1355. static int rp_put_char(struct tty_struct *tty, unsigned char ch)
  1356. {
  1357. struct r_port *info = tty->driver_data;
  1358. CHANNEL_t *cp;
  1359. unsigned long flags;
  1360. if (rocket_paranoia_check(info, "rp_put_char"))
  1361. return 0;
  1362. /*
  1363. * Grab the port write mutex, locking out other processes that try to
  1364. * write to this port
  1365. */
  1366. mutex_lock(&info->write_mtx);
  1367. #ifdef ROCKET_DEBUG_WRITE
  1368. printk(KERN_INFO "rp_put_char %c...\n", ch);
  1369. #endif
  1370. spin_lock_irqsave(&info->slock, flags);
  1371. cp = &info->channel;
  1372. if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room == 0)
  1373. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  1374. if (tty->stopped || tty->hw_stopped || info->xmit_fifo_room == 0 || info->xmit_cnt != 0) {
  1375. info->xmit_buf[info->xmit_head++] = ch;
  1376. info->xmit_head &= XMIT_BUF_SIZE - 1;
  1377. info->xmit_cnt++;
  1378. set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1379. } else {
  1380. sOutB(sGetTxRxDataIO(cp), ch);
  1381. info->xmit_fifo_room--;
  1382. }
  1383. spin_unlock_irqrestore(&info->slock, flags);
  1384. mutex_unlock(&info->write_mtx);
  1385. return 1;
  1386. }
  1387. /*
  1388. * Exception handler - write routine, called when user app writes to the device.
  1389. * A per port write mutex is used to protect from another process writing to
  1390. * this port at the same time. This other process could be running on the other CPU
  1391. * or get control of the CPU if the copy_from_user() blocks due to a page fault (swapped out).
  1392. * Spinlocks protect the info xmit members.
  1393. */
  1394. static int rp_write(struct tty_struct *tty,
  1395. const unsigned char *buf, int count)
  1396. {
  1397. struct r_port *info = tty->driver_data;
  1398. CHANNEL_t *cp;
  1399. const unsigned char *b;
  1400. int c, retval = 0;
  1401. unsigned long flags;
  1402. if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
  1403. return 0;
  1404. if (mutex_lock_interruptible(&info->write_mtx))
  1405. return -ERESTARTSYS;
  1406. #ifdef ROCKET_DEBUG_WRITE
  1407. printk(KERN_INFO "rp_write %d chars...\n", count);
  1408. #endif
  1409. cp = &info->channel;
  1410. if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room < count)
  1411. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  1412. /*
  1413. * If the write queue for the port is empty, and there is FIFO space, stuff bytes
  1414. * into FIFO. Use the write queue for temp storage.
  1415. */
  1416. if (!tty->stopped && !tty->hw_stopped && info->xmit_cnt == 0 && info->xmit_fifo_room > 0) {
  1417. c = min(count, info->xmit_fifo_room);
  1418. b = buf;
  1419. /* Push data into FIFO, 2 bytes at a time */
  1420. sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) b, c / 2);
  1421. /* If there is a byte remaining, write it */
  1422. if (c & 1)
  1423. sOutB(sGetTxRxDataIO(cp), b[c - 1]);
  1424. retval += c;
  1425. buf += c;
  1426. count -= c;
  1427. spin_lock_irqsave(&info->slock, flags);
  1428. info->xmit_fifo_room -= c;
  1429. spin_unlock_irqrestore(&info->slock, flags);
  1430. }
  1431. /* If count is zero, we wrote it all and are done */
  1432. if (!count)
  1433. goto end;
  1434. /* Write remaining data into the port's xmit_buf */
  1435. while (1) {
  1436. /* Hung up ? */
  1437. if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags))
  1438. goto end;
  1439. c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
  1440. c = min(c, XMIT_BUF_SIZE - info->xmit_head);
  1441. if (c <= 0)
  1442. break;
  1443. b = buf;
  1444. memcpy(info->xmit_buf + info->xmit_head, b, c);
  1445. spin_lock_irqsave(&info->slock, flags);
  1446. info->xmit_head =
  1447. (info->xmit_head + c) & (XMIT_BUF_SIZE - 1);
  1448. info->xmit_cnt += c;
  1449. spin_unlock_irqrestore(&info->slock, flags);
  1450. buf += c;
  1451. count -= c;
  1452. retval += c;
  1453. }
  1454. if ((retval > 0) && !tty->stopped && !tty->hw_stopped)
  1455. set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1456. end:
  1457. if (info->xmit_cnt < WAKEUP_CHARS) {
  1458. tty_wakeup(tty);
  1459. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  1460. wake_up_interruptible(&tty->poll_wait);
  1461. #endif
  1462. }
  1463. mutex_unlock(&info->write_mtx);
  1464. return retval;
  1465. }
  1466. /*
  1467. * Return the number of characters that can be sent. We estimate
  1468. * only using the in-memory transmit buffer only, and ignore the
  1469. * potential space in the transmit FIFO.
  1470. */
  1471. static int rp_write_room(struct tty_struct *tty)
  1472. {
  1473. struct r_port *info = tty->driver_data;
  1474. int ret;
  1475. if (rocket_paranoia_check(info, "rp_write_room"))
  1476. return 0;
  1477. ret = XMIT_BUF_SIZE - info->xmit_cnt - 1;
  1478. if (ret < 0)
  1479. ret = 0;
  1480. #ifdef ROCKET_DEBUG_WRITE
  1481. printk(KERN_INFO "rp_write_room returns %d...\n", ret);
  1482. #endif
  1483. return ret;
  1484. }
  1485. /*
  1486. * Return the number of characters in the buffer. Again, this only
  1487. * counts those characters in the in-memory transmit buffer.
  1488. */
  1489. static int rp_chars_in_buffer(struct tty_struct *tty)
  1490. {
  1491. struct r_port *info = tty->driver_data;
  1492. CHANNEL_t *cp;
  1493. if (rocket_paranoia_check(info, "rp_chars_in_buffer"))
  1494. return 0;
  1495. cp = &info->channel;
  1496. #ifdef ROCKET_DEBUG_WRITE
  1497. printk(KERN_INFO "rp_chars_in_buffer returns %d...\n", info->xmit_cnt);
  1498. #endif
  1499. return info->xmit_cnt;
  1500. }
  1501. /*
  1502. * Flushes the TX fifo for a port, deletes data in the xmit_buf stored in the
  1503. * r_port struct for the port. Note that spinlock are used to protect info members,
  1504. * do not call this function if the spinlock is already held.
  1505. */
  1506. static void rp_flush_buffer(struct tty_struct *tty)
  1507. {
  1508. struct r_port *info = tty->driver_data;
  1509. CHANNEL_t *cp;
  1510. unsigned long flags;
  1511. if (rocket_paranoia_check(info, "rp_flush_buffer"))
  1512. return;
  1513. spin_lock_irqsave(&info->slock, flags);
  1514. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1515. spin_unlock_irqrestore(&info->slock, flags);
  1516. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  1517. wake_up_interruptible(&tty->poll_wait);
  1518. #endif
  1519. tty_wakeup(tty);
  1520. cp = &info->channel;
  1521. sFlushTxFIFO(cp);
  1522. }
  1523. #ifdef CONFIG_PCI
  1524. static struct pci_device_id __devinitdata rocket_pci_ids[] = {
  1525. { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) },
  1526. { }
  1527. };
  1528. MODULE_DEVICE_TABLE(pci, rocket_pci_ids);
  1529. /*
  1530. * Called when a PCI card is found. Retrieves and stores model information,
  1531. * init's aiopic and serial port hardware.
  1532. * Inputs: i is the board number (0-n)
  1533. */
  1534. static __init int register_PCI(int i, struct pci_dev *dev)
  1535. {
  1536. int num_aiops, aiop, max_num_aiops, num_chan, chan;
  1537. unsigned int aiopio[MAX_AIOPS_PER_BOARD];
  1538. char *str, *board_type;
  1539. CONTROLLER_t *ctlp;
  1540. int fast_clock = 0;
  1541. int altChanRingIndicator = 0;
  1542. int ports_per_aiop = 8;
  1543. WordIO_t ConfigIO = 0;
  1544. ByteIO_t UPCIRingInd = 0;
  1545. if (!dev || pci_enable_device(dev))
  1546. return 0;
  1547. rcktpt_io_addr[i] = pci_resource_start(dev, 0);
  1548. rcktpt_type[i] = ROCKET_TYPE_NORMAL;
  1549. rocketModel[i].loadrm2 = 0;
  1550. rocketModel[i].startingPortNumber = nextLineNumber;
  1551. /* Depending on the model, set up some config variables */
  1552. switch (dev->device) {
  1553. case PCI_DEVICE_ID_RP4QUAD:
  1554. str = "Quadcable";
  1555. max_num_aiops = 1;
  1556. ports_per_aiop = 4;
  1557. rocketModel[i].model = MODEL_RP4QUAD;
  1558. strcpy(rocketModel[i].modelString, "RocketPort 4 port w/quad cable");
  1559. rocketModel[i].numPorts = 4;
  1560. break;
  1561. case PCI_DEVICE_ID_RP8OCTA:
  1562. str = "Octacable";
  1563. max_num_aiops = 1;
  1564. rocketModel[i].model = MODEL_RP8OCTA;
  1565. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/octa cable");
  1566. rocketModel[i].numPorts = 8;
  1567. break;
  1568. case PCI_DEVICE_ID_URP8OCTA:
  1569. str = "Octacable";
  1570. max_num_aiops = 1;
  1571. rocketModel[i].model = MODEL_UPCI_RP8OCTA;
  1572. strcpy(rocketModel[i].modelString, "RocketPort UPCI 8 port w/octa cable");
  1573. rocketModel[i].numPorts = 8;
  1574. break;
  1575. case PCI_DEVICE_ID_RP8INTF:
  1576. str = "8";
  1577. max_num_aiops = 1;
  1578. rocketModel[i].model = MODEL_RP8INTF;
  1579. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/external I/F");
  1580. rocketModel[i].numPorts = 8;
  1581. break;
  1582. case PCI_DEVICE_ID_URP8INTF:
  1583. str = "8";
  1584. max_num_aiops = 1;
  1585. rocketModel[i].model = MODEL_UPCI_RP8INTF;
  1586. strcpy(rocketModel[i].modelString, "RocketPort UPCI 8 port w/external I/F");
  1587. rocketModel[i].numPorts = 8;
  1588. break;
  1589. case PCI_DEVICE_ID_RP8J:
  1590. str = "8J";
  1591. max_num_aiops = 1;
  1592. rocketModel[i].model = MODEL_RP8J;
  1593. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/RJ11 connectors");
  1594. rocketModel[i].numPorts = 8;
  1595. break;
  1596. case PCI_DEVICE_ID_RP4J:
  1597. str = "4J";
  1598. max_num_aiops = 1;
  1599. ports_per_aiop = 4;
  1600. rocketModel[i].model = MODEL_RP4J;
  1601. strcpy(rocketModel[i].modelString, "RocketPort 4 port w/RJ45 connectors");
  1602. rocketModel[i].numPorts = 4;
  1603. break;
  1604. case PCI_DEVICE_ID_RP8SNI:
  1605. str = "8 (DB78 Custom)";
  1606. max_num_aiops = 1;
  1607. rocketModel[i].model = MODEL_RP8SNI;
  1608. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/ custom DB78");
  1609. rocketModel[i].numPorts = 8;
  1610. break;
  1611. case PCI_DEVICE_ID_RP16SNI:
  1612. str = "16 (DB78 Custom)";
  1613. max_num_aiops = 2;
  1614. rocketModel[i].model = MODEL_RP16SNI;
  1615. strcpy(rocketModel[i].modelString, "RocketPort 16 port w/ custom DB78");
  1616. rocketModel[i].numPorts = 16;
  1617. break;
  1618. case PCI_DEVICE_ID_RP16INTF:
  1619. str = "16";
  1620. max_num_aiops = 2;
  1621. rocketModel[i].model = MODEL_RP16INTF;
  1622. strcpy(rocketModel[i].modelString, "RocketPort 16 port w/external I/F");
  1623. rocketModel[i].numPorts = 16;
  1624. break;
  1625. case PCI_DEVICE_ID_URP16INTF:
  1626. str = "16";
  1627. max_num_aiops = 2;
  1628. rocketModel[i].model = MODEL_UPCI_RP16INTF;
  1629. strcpy(rocketModel[i].modelString, "RocketPort UPCI 16 port w/external I/F");
  1630. rocketModel[i].numPorts = 16;
  1631. break;
  1632. case PCI_DEVICE_ID_CRP16INTF:
  1633. str = "16";
  1634. max_num_aiops = 2;
  1635. rocketModel[i].model = MODEL_CPCI_RP16INTF;
  1636. strcpy(rocketModel[i].modelString, "RocketPort Compact PCI 16 port w/external I/F");
  1637. rocketModel[i].numPorts = 16;
  1638. break;
  1639. case PCI_DEVICE_ID_RP32INTF:
  1640. str = "32";
  1641. max_num_aiops = 4;
  1642. rocketModel[i].model = MODEL_RP32INTF;
  1643. strcpy(rocketModel[i].modelString, "RocketPort 32 port w/external I/F");
  1644. rocketModel[i].numPorts = 32;
  1645. break;
  1646. case PCI_DEVICE_ID_URP32INTF:
  1647. str = "32";
  1648. max_num_aiops = 4;
  1649. rocketModel[i].model = MODEL_UPCI_RP32INTF;
  1650. strcpy(rocketModel[i].modelString, "RocketPort UPCI 32 port w/external I/F");
  1651. rocketModel[i].numPorts = 32;
  1652. break;
  1653. case PCI_DEVICE_ID_RPP4:
  1654. str = "Plus Quadcable";
  1655. max_num_aiops = 1;
  1656. ports_per_aiop = 4;
  1657. altChanRingIndicator++;
  1658. fast_clock++;
  1659. rocketModel[i].model = MODEL_RPP4;
  1660. strcpy(rocketModel[i].modelString, "RocketPort Plus 4 port");
  1661. rocketModel[i].numPorts = 4;
  1662. break;
  1663. case PCI_DEVICE_ID_RPP8:
  1664. str = "Plus Octacable";
  1665. max_num_aiops = 2;
  1666. ports_per_aiop = 4;
  1667. altChanRingIndicator++;
  1668. fast_clock++;
  1669. rocketModel[i].model = MODEL_RPP8;
  1670. strcpy(rocketModel[i].modelString, "RocketPort Plus 8 port");
  1671. rocketModel[i].numPorts = 8;
  1672. break;
  1673. case PCI_DEVICE_ID_RP2_232:
  1674. str = "Plus 2 (RS-232)";
  1675. max_num_aiops = 1;
  1676. ports_per_aiop = 2;
  1677. altChanRingIndicator++;
  1678. fast_clock++;
  1679. rocketModel[i].model = MODEL_RP2_232;
  1680. strcpy(rocketModel[i].modelString, "RocketPort Plus 2 port RS232");
  1681. rocketModel[i].numPorts = 2;
  1682. break;
  1683. case PCI_DEVICE_ID_RP2_422:
  1684. str = "Plus 2 (RS-422)";
  1685. max_num_aiops = 1;
  1686. ports_per_aiop = 2;
  1687. altChanRingIndicator++;
  1688. fast_clock++;
  1689. rocketModel[i].model = MODEL_RP2_422;
  1690. strcpy(rocketModel[i].modelString, "RocketPort Plus 2 port RS422");
  1691. rocketModel[i].numPorts = 2;
  1692. break;
  1693. case PCI_DEVICE_ID_RP6M:
  1694. max_num_aiops = 1;
  1695. ports_per_aiop = 6;
  1696. str = "6-port";
  1697. /* If revision is 1, the rocketmodem flash must be loaded.
  1698. * If it is 2 it is a "socketed" version. */
  1699. if (dev->revision == 1) {
  1700. rcktpt_type[i] = ROCKET_TYPE_MODEMII;
  1701. rocketModel[i].loadrm2 = 1;
  1702. } else {
  1703. rcktpt_type[i] = ROCKET_TYPE_MODEM;
  1704. }
  1705. rocketModel[i].model = MODEL_RP6M;
  1706. strcpy(rocketModel[i].modelString, "RocketModem 6 port");
  1707. rocketModel[i].numPorts = 6;
  1708. break;
  1709. case PCI_DEVICE_ID_RP4M:
  1710. max_num_aiops = 1;
  1711. ports_per_aiop = 4;
  1712. str = "4-port";
  1713. if (dev->revision == 1) {
  1714. rcktpt_type[i] = ROCKET_TYPE_MODEMII;
  1715. rocketModel[i].loadrm2 = 1;
  1716. } else {
  1717. rcktpt_type[i] = ROCKET_TYPE_MODEM;
  1718. }
  1719. rocketModel[i].model = MODEL_RP4M;
  1720. strcpy(rocketModel[i].modelString, "RocketModem 4 port");
  1721. rocketModel[i].numPorts = 4;
  1722. break;
  1723. default:
  1724. str = "(unknown/unsupported)";
  1725. max_num_aiops = 0;
  1726. break;
  1727. }
  1728. /*
  1729. * Check for UPCI boards.
  1730. */
  1731. switch (dev->device) {
  1732. case PCI_DEVICE_ID_URP32INTF:
  1733. case PCI_DEVICE_ID_URP8INTF:
  1734. case PCI_DEVICE_ID_URP16INTF:
  1735. case PCI_DEVICE_ID_CRP16INTF:
  1736. case PCI_DEVICE_ID_URP8OCTA:
  1737. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1738. ConfigIO = pci_resource_start(dev, 1);
  1739. if (dev->device == PCI_DEVICE_ID_URP8OCTA) {
  1740. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1741. /*
  1742. * Check for octa or quad cable.
  1743. */
  1744. if (!
  1745. (sInW(ConfigIO + _PCI_9030_GPIO_CTRL) &
  1746. PCI_GPIO_CTRL_8PORT)) {
  1747. str = "Quadcable";
  1748. ports_per_aiop = 4;
  1749. rocketModel[i].numPorts = 4;
  1750. }
  1751. }
  1752. break;
  1753. case PCI_DEVICE_ID_UPCI_RM3_8PORT:
  1754. str = "8 ports";
  1755. max_num_aiops = 1;
  1756. rocketModel[i].model = MODEL_UPCI_RM3_8PORT;
  1757. strcpy(rocketModel[i].modelString, "RocketModem III 8 port");
  1758. rocketModel[i].numPorts = 8;
  1759. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1760. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1761. ConfigIO = pci_resource_start(dev, 1);
  1762. rcktpt_type[i] = ROCKET_TYPE_MODEMIII;
  1763. break;
  1764. case PCI_DEVICE_ID_UPCI_RM3_4PORT:
  1765. str = "4 ports";
  1766. max_num_aiops = 1;
  1767. rocketModel[i].model = MODEL_UPCI_RM3_4PORT;
  1768. strcpy(rocketModel[i].modelString, "RocketModem III 4 port");
  1769. rocketModel[i].numPorts = 4;
  1770. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1771. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1772. ConfigIO = pci_resource_start(dev, 1);
  1773. rcktpt_type[i] = ROCKET_TYPE_MODEMIII;
  1774. break;
  1775. default:
  1776. break;
  1777. }
  1778. switch (rcktpt_type[i]) {
  1779. case ROCKET_TYPE_MODEM:
  1780. board_type = "RocketModem";
  1781. break;
  1782. case ROCKET_TYPE_MODEMII:
  1783. board_type = "RocketModem II";
  1784. break;
  1785. case ROCKET_TYPE_MODEMIII:
  1786. board_type = "RocketModem III";
  1787. break;
  1788. default:
  1789. board_type = "RocketPort";
  1790. break;
  1791. }
  1792. if (fast_clock) {
  1793. sClockPrescale = 0x12; /* mod 2 (divide by 3) */
  1794. rp_baud_base[i] = 921600;
  1795. } else {
  1796. /*
  1797. * If support_low_speed is set, use the slow clock
  1798. * prescale, which supports 50 bps
  1799. */
  1800. if (support_low_speed) {
  1801. /* mod 9 (divide by 10) prescale */
  1802. sClockPrescale = 0x19;
  1803. rp_baud_base[i] = 230400;
  1804. } else {
  1805. /* mod 4 (devide by 5) prescale */
  1806. sClockPrescale = 0x14;
  1807. rp_baud_base[i] = 460800;
  1808. }
  1809. }
  1810. for (aiop = 0; aiop < max_num_aiops; aiop++)
  1811. aiopio[aiop] = rcktpt_io_addr[i] + (aiop * 0x40);
  1812. ctlp = sCtlNumToCtlPtr(i);
  1813. num_aiops = sPCIInitController(ctlp, i, aiopio, max_num_aiops, ConfigIO, 0, FREQ_DIS, 0, altChanRingIndicator, UPCIRingInd);
  1814. for (aiop = 0; aiop < max_num_aiops; aiop++)
  1815. ctlp->AiopNumChan[aiop] = ports_per_aiop;
  1816. dev_info(&dev->dev, "comtrol PCI controller #%d found at "
  1817. "address %04lx, %d AIOP(s) (%s), creating ttyR%d - %ld\n",
  1818. i, rcktpt_io_addr[i], num_aiops, rocketModel[i].modelString,
  1819. rocketModel[i].startingPortNumber,
  1820. rocketModel[i].startingPortNumber + rocketModel[i].numPorts-1);
  1821. if (num_aiops <= 0) {
  1822. rcktpt_io_addr[i] = 0;
  1823. return (0);
  1824. }
  1825. is_PCI[i] = 1;
  1826. /* Reset the AIOPIC, init the serial ports */
  1827. for (aiop = 0; aiop < num_aiops; aiop++) {
  1828. sResetAiopByNum(ctlp, aiop);
  1829. num_chan = ports_per_aiop;
  1830. for (chan = 0; chan < num_chan; chan++)
  1831. init_r_port(i, aiop, chan, dev);
  1832. }
  1833. /* Rocket modems must be reset */
  1834. if ((rcktpt_type[i] == ROCKET_TYPE_MODEM) ||
  1835. (rcktpt_type[i] == ROCKET_TYPE_MODEMII) ||
  1836. (rcktpt_type[i] == ROCKET_TYPE_MODEMIII)) {
  1837. num_chan = ports_per_aiop;
  1838. for (chan = 0; chan < num_chan; chan++)
  1839. sPCIModemReset(ctlp, chan, 1);
  1840. msleep(500);
  1841. for (chan = 0; chan < num_chan; chan++)
  1842. sPCIModemReset(ctlp, chan, 0);
  1843. msleep(500);
  1844. rmSpeakerReset(ctlp, rocketModel[i].model);
  1845. }
  1846. return (1);
  1847. }
  1848. /*
  1849. * Probes for PCI cards, inits them if found
  1850. * Input: board_found = number of ISA boards already found, or the
  1851. * starting board number
  1852. * Returns: Number of PCI boards found
  1853. */
  1854. static int __init init_PCI(int boards_found)
  1855. {
  1856. struct pci_dev *dev = NULL;
  1857. int count = 0;
  1858. /* Work through the PCI device list, pulling out ours */
  1859. while ((dev = pci_get_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
  1860. if (register_PCI(count + boards_found, dev))
  1861. count++;
  1862. }
  1863. return (count);
  1864. }
  1865. #endif /* CONFIG_PCI */
  1866. /*
  1867. * Probes for ISA cards
  1868. * Input: i = the board number to look for
  1869. * Returns: 1 if board found, 0 else
  1870. */
  1871. static int __init init_ISA(int i)
  1872. {
  1873. int num_aiops, num_chan = 0, total_num_chan = 0;
  1874. int aiop, chan;
  1875. unsigned int aiopio[MAX_AIOPS_PER_BOARD];
  1876. CONTROLLER_t *ctlp;
  1877. char *type_string;
  1878. /* If io_addr is zero, no board configured */
  1879. if (rcktpt_io_addr[i] == 0)
  1880. return (0);
  1881. /* Reserve the IO region */
  1882. if (!request_region(rcktpt_io_addr[i], 64, "Comtrol RocketPort")) {
  1883. printk(KERN_ERR "Unable to reserve IO region for configured "
  1884. "ISA RocketPort at address 0x%lx, board not "
  1885. "installed...\n", rcktpt_io_addr[i]);
  1886. rcktpt_io_addr[i] = 0;
  1887. return (0);
  1888. }
  1889. ctlp = sCtlNumToCtlPtr(i);
  1890. ctlp->boardType = rcktpt_type[i];
  1891. switch (rcktpt_type[i]) {
  1892. case ROCKET_TYPE_PC104:
  1893. type_string = "(PC104)";
  1894. break;
  1895. case ROCKET_TYPE_MODEM:
  1896. type_string = "(RocketModem)";
  1897. break;
  1898. case ROCKET_TYPE_MODEMII:
  1899. type_string = "(RocketModem II)";
  1900. break;
  1901. default:
  1902. type_string = "";
  1903. break;
  1904. }
  1905. /*
  1906. * If support_low_speed is set, use the slow clock prescale,
  1907. * which supports 50 bps
  1908. */
  1909. if (support_low_speed) {
  1910. sClockPrescale = 0x19; /* mod 9 (divide by 10) prescale */
  1911. rp_baud_base[i] = 230400;
  1912. } else {
  1913. sClockPrescale = 0x14; /* mod 4 (devide by 5) prescale */
  1914. rp_baud_base[i] = 460800;
  1915. }
  1916. for (aiop = 0; aiop < MAX_AIOPS_PER_BOARD; aiop++)
  1917. aiopio[aiop] = rcktpt_io_addr[i] + (aiop * 0x400);
  1918. num_aiops = sInitController(ctlp, i, controller + (i * 0x400), aiopio, MAX_AIOPS_PER_BOARD, 0, FREQ_DIS, 0);
  1919. if (ctlp->boardType == ROCKET_TYPE_PC104) {
  1920. sEnAiop(ctlp, 2); /* only one AIOPIC, but these */
  1921. sEnAiop(ctlp, 3); /* CSels used for other stuff */
  1922. }
  1923. /* If something went wrong initing the AIOP's release the ISA IO memory */
  1924. if (num_aiops <= 0) {
  1925. release_region(rcktpt_io_addr[i], 64);
  1926. rcktpt_io_addr[i] = 0;
  1927. return (0);
  1928. }
  1929. rocketModel[i].startingPortNumber = nextLineNumber;
  1930. for (aiop = 0; aiop < num_aiops; aiop++) {
  1931. sResetAiopByNum(ctlp, aiop);
  1932. sEnAiop(ctlp, aiop);
  1933. num_chan = sGetAiopNumChan(ctlp, aiop);
  1934. total_num_chan += num_chan;
  1935. for (chan = 0; chan < num_chan; chan++)
  1936. init_r_port(i, aiop, chan, NULL);
  1937. }
  1938. is_PCI[i] = 0;
  1939. if ((rcktpt_type[i] == ROCKET_TYPE_MODEM) || (rcktpt_type[i] == ROCKET_TYPE_MODEMII)) {
  1940. num_chan = sGetAiopNumChan(ctlp, 0);
  1941. total_num_chan = num_chan;
  1942. for (chan = 0; chan < num_chan; chan++)
  1943. sModemReset(ctlp, chan, 1);
  1944. msleep(500);
  1945. for (chan = 0; chan < num_chan; chan++)
  1946. sModemReset(ctlp, chan, 0);
  1947. msleep(500);
  1948. strcpy(rocketModel[i].modelString, "RocketModem ISA");
  1949. } else {
  1950. strcpy(rocketModel[i].modelString, "RocketPort ISA");
  1951. }
  1952. rocketModel[i].numPorts = total_num_chan;
  1953. rocketModel[i].model = MODEL_ISA;
  1954. printk(KERN_INFO "RocketPort ISA card #%d found at 0x%lx - %d AIOPs %s\n",
  1955. i, rcktpt_io_addr[i], num_aiops, type_string);
  1956. printk(KERN_INFO "Installing %s, creating /dev/ttyR%d - %ld\n",
  1957. rocketModel[i].modelString,
  1958. rocketModel[i].startingPortNumber,
  1959. rocketModel[i].startingPortNumber +
  1960. rocketModel[i].numPorts - 1);
  1961. return (1);
  1962. }
  1963. static const struct tty_operations rocket_ops = {
  1964. .open = rp_open,
  1965. .close = rp_close,
  1966. .write = rp_write,
  1967. .put_char = rp_put_char,
  1968. .write_room = rp_write_room,
  1969. .chars_in_buffer = rp_chars_in_buffer,
  1970. .flush_buffer = rp_flush_buffer,
  1971. .ioctl = rp_ioctl,
  1972. .throttle = rp_throttle,
  1973. .unthrottle = rp_unthrottle,
  1974. .set_termios = rp_set_termios,
  1975. .stop = rp_stop,
  1976. .start = rp_start,
  1977. .hangup = rp_hangup,
  1978. .break_ctl = rp_break,
  1979. .send_xchar = rp_send_xchar,
  1980. .wait_until_sent = rp_wait_until_sent,
  1981. .tiocmget = rp_tiocmget,
  1982. .tiocmset = rp_tiocmset,
  1983. };
  1984. static const struct tty_port_operations rocket_port_ops = {
  1985. .carrier_raised = carrier_raised,
  1986. .dtr_rts = dtr_rts,
  1987. };
  1988. /*
  1989. * The module "startup" routine; it's run when the module is loaded.
  1990. */
  1991. static int __init rp_init(void)
  1992. {
  1993. int ret = -ENOMEM, pci_boards_found, isa_boards_found, i;
  1994. printk(KERN_INFO "RocketPort device driver module, version %s, %s\n",
  1995. ROCKET_VERSION, ROCKET_DATE);
  1996. rocket_driver = alloc_tty_driver(MAX_RP_PORTS);
  1997. if (!rocket_driver)
  1998. goto err;
  1999. /*
  2000. * If board 1 is non-zero, there is at least one ISA configured. If controller is
  2001. * zero, use the default controller IO address of board1 + 0x40.
  2002. */
  2003. if (board1) {
  2004. if (controller == 0)
  2005. controller = board1 + 0x40;
  2006. } else {
  2007. controller = 0; /* Used as a flag, meaning no ISA boards */
  2008. }
  2009. /* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */
  2010. if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) {
  2011. printk(KERN_ERR "Unable to reserve IO region for first "
  2012. "configured ISA RocketPort controller 0x%lx. "
  2013. "Driver exiting\n", controller);
  2014. ret = -EBUSY;
  2015. goto err_tty;
  2016. }
  2017. /* Store ISA variable retrieved from command line or .conf file. */
  2018. rcktpt_io_addr[0] = board1;
  2019. rcktpt_io_addr[1] = board2;
  2020. rcktpt_io_addr[2] = board3;
  2021. rcktpt_io_addr[3] = board4;
  2022. rcktpt_type[0] = modem1 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2023. rcktpt_type[0] = pc104_1[0] ? ROCKET_TYPE_PC104 : rcktpt_type[0];
  2024. rcktpt_type[1] = modem2 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2025. rcktpt_type[1] = pc104_2[0] ? ROCKET_TYPE_PC104 : rcktpt_type[1];
  2026. rcktpt_type[2] = modem3 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2027. rcktpt_type[2] = pc104_3[0] ? ROCKET_TYPE_PC104 : rcktpt_type[2];
  2028. rcktpt_type[3] = modem4 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2029. rcktpt_type[3] = pc104_4[0] ? ROCKET_TYPE_PC104 : rcktpt_type[3];
  2030. /*
  2031. * Set up the tty driver structure and then register this
  2032. * driver with the tty layer.
  2033. */
  2034. rocket_driver->owner = THIS_MODULE;
  2035. rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV;
  2036. rocket_driver->name = "ttyR";
  2037. rocket_driver->driver_name = "Comtrol RocketPort";
  2038. rocket_driver->major = TTY_ROCKET_MAJOR;
  2039. rocket_driver->minor_start = 0;
  2040. rocket_driver->type = TTY_DRIVER_TYPE_SERIAL;
  2041. rocket_driver->subtype = SERIAL_TYPE_NORMAL;
  2042. rocket_driver->init_termios = tty_std_termios;
  2043. rocket_driver->init_termios.c_cflag =
  2044. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  2045. rocket_driver->init_termios.c_ispeed = 9600;
  2046. rocket_driver->init_termios.c_ospeed = 9600;
  2047. #ifdef ROCKET_SOFT_FLOW
  2048. rocket_driver->flags |= TTY_DRIVER_REAL_RAW;
  2049. #endif
  2050. tty_set_operations(rocket_driver, &rocket_ops);
  2051. ret = tty_register_driver(rocket_driver);
  2052. if (ret < 0) {
  2053. printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
  2054. goto err_tty;
  2055. }
  2056. #ifdef ROCKET_DEBUG_OPEN
  2057. printk(KERN_INFO "RocketPort driver is major %d\n", rocket_driver.major);
  2058. #endif
  2059. /*
  2060. * OK, let's probe each of the controllers looking for boards. Any boards found
  2061. * will be initialized here.
  2062. */
  2063. isa_boards_found = 0;
  2064. pci_boards_found = 0;
  2065. for (i = 0; i < NUM_BOARDS; i++) {
  2066. if (init_ISA(i))
  2067. isa_boards_found++;
  2068. }
  2069. #ifdef CONFIG_PCI
  2070. if (isa_boards_found < NUM_BOARDS)
  2071. pci_boards_found = init_PCI(isa_boards_found);
  2072. #endif
  2073. max_board = pci_boards_found + isa_boards_found;
  2074. if (max_board == 0) {
  2075. printk(KERN_ERR "No rocketport ports found; unloading driver\n");
  2076. ret = -ENXIO;
  2077. goto err_ttyu;
  2078. }
  2079. return 0;
  2080. err_ttyu:
  2081. tty_unregister_driver(rocket_driver);
  2082. err_tty:
  2083. put_tty_driver(rocket_driver);
  2084. err:
  2085. return ret;
  2086. }
  2087. static void rp_cleanup_module(void)
  2088. {
  2089. int retval;
  2090. int i;
  2091. del_timer_sync(&rocket_timer);
  2092. retval = tty_unregister_driver(rocket_driver);
  2093. if (retval)
  2094. printk(KERN_ERR "Error %d while trying to unregister "
  2095. "rocketport driver\n", -retval);
  2096. for (i = 0; i < MAX_RP_PORTS; i++)
  2097. if (rp_table[i]) {
  2098. tty_unregister_device(rocket_driver, i);
  2099. kfree(rp_table[i]);
  2100. }
  2101. put_tty_driver(rocket_driver);
  2102. for (i = 0; i < NUM_BOARDS; i++) {
  2103. if (rcktpt_io_addr[i] <= 0 || is_PCI[i])
  2104. continue;
  2105. release_region(rcktpt_io_addr[i], 64);
  2106. }
  2107. if (controller)
  2108. release_region(controller, 4);
  2109. }
  2110. /***************************************************************************
  2111. Function: sInitController
  2112. Purpose: Initialization of controller global registers and controller
  2113. structure.
  2114. Call: sInitController(CtlP,CtlNum,MudbacIO,AiopIOList,AiopIOListSize,
  2115. IRQNum,Frequency,PeriodicOnly)
  2116. CONTROLLER_T *CtlP; Ptr to controller structure
  2117. int CtlNum; Controller number
  2118. ByteIO_t MudbacIO; Mudbac base I/O address.
  2119. ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
  2120. This list must be in the order the AIOPs will be found on the
  2121. controller. Once an AIOP in the list is not found, it is
  2122. assumed that there are no more AIOPs on the controller.
  2123. int AiopIOListSize; Number of addresses in AiopIOList
  2124. int IRQNum; Interrupt Request number. Can be any of the following:
  2125. 0: Disable global interrupts
  2126. 3: IRQ 3
  2127. 4: IRQ 4
  2128. 5: IRQ 5
  2129. 9: IRQ 9
  2130. 10: IRQ 10
  2131. 11: IRQ 11
  2132. 12: IRQ 12
  2133. 15: IRQ 15
  2134. Byte_t Frequency: A flag identifying the frequency
  2135. of the periodic interrupt, can be any one of the following:
  2136. FREQ_DIS - periodic interrupt disabled
  2137. FREQ_137HZ - 137 Hertz
  2138. FREQ_69HZ - 69 Hertz
  2139. FREQ_34HZ - 34 Hertz
  2140. FREQ_17HZ - 17 Hertz
  2141. FREQ_9HZ - 9 Hertz
  2142. FREQ_4HZ - 4 Hertz
  2143. If IRQNum is set to 0 the Frequency parameter is
  2144. overidden, it is forced to a value of FREQ_DIS.
  2145. int PeriodicOnly: 1 if all interrupts except the periodic
  2146. interrupt are to be blocked.
  2147. 0 is both the periodic interrupt and
  2148. other channel interrupts are allowed.
  2149. If IRQNum is set to 0 the PeriodicOnly parameter is
  2150. overidden, it is forced to a value of 0.
  2151. Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
  2152. initialization failed.
  2153. Comments:
  2154. If periodic interrupts are to be disabled but AIOP interrupts
  2155. are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
  2156. If interrupts are to be completely disabled set IRQNum to 0.
  2157. Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
  2158. invalid combination.
  2159. This function performs initialization of global interrupt modes,
  2160. but it does not actually enable global interrupts. To enable
  2161. and disable global interrupts use functions sEnGlobalInt() and
  2162. sDisGlobalInt(). Enabling of global interrupts is normally not
  2163. done until all other initializations are complete.
  2164. Even if interrupts are globally enabled, they must also be
  2165. individually enabled for each channel that is to generate
  2166. interrupts.
  2167. Warnings: No range checking on any of the parameters is done.
  2168. No context switches are allowed while executing this function.
  2169. After this function all AIOPs on the controller are disabled,
  2170. they can be enabled with sEnAiop().
  2171. */
  2172. static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
  2173. ByteIO_t * AiopIOList, int AiopIOListSize,
  2174. int IRQNum, Byte_t Frequency, int PeriodicOnly)
  2175. {
  2176. int i;
  2177. ByteIO_t io;
  2178. int done;
  2179. CtlP->AiopIntrBits = aiop_intr_bits;
  2180. CtlP->AltChanRingIndicator = 0;
  2181. CtlP->CtlNum = CtlNum;
  2182. CtlP->CtlID = CTLID_0001; /* controller release 1 */
  2183. CtlP->BusType = isISA;
  2184. CtlP->MBaseIO = MudbacIO;
  2185. CtlP->MReg1IO = MudbacIO + 1;
  2186. CtlP->MReg2IO = MudbacIO + 2;
  2187. CtlP->MReg3IO = MudbacIO + 3;
  2188. #if 1
  2189. CtlP->MReg2 = 0; /* interrupt disable */
  2190. CtlP->MReg3 = 0; /* no periodic interrupts */
  2191. #else
  2192. if (sIRQMap[IRQNum] == 0) { /* interrupts globally disabled */
  2193. CtlP->MReg2 = 0; /* interrupt disable */
  2194. CtlP->MReg3 = 0; /* no periodic interrupts */
  2195. } else {
  2196. CtlP->MReg2 = sIRQMap[IRQNum]; /* set IRQ number */
  2197. CtlP->MReg3 = Frequency; /* set frequency */
  2198. if (PeriodicOnly) { /* periodic interrupt only */
  2199. CtlP->MReg3 |= PERIODIC_ONLY;
  2200. }
  2201. }
  2202. #endif
  2203. sOutB(CtlP->MReg2IO, CtlP->MReg2);
  2204. sOutB(CtlP->MReg3IO, CtlP->MReg3);
  2205. sControllerEOI(CtlP); /* clear EOI if warm init */
  2206. /* Init AIOPs */
  2207. CtlP->NumAiop = 0;
  2208. for (i = done = 0; i < AiopIOListSize; i++) {
  2209. io = AiopIOList[i];
  2210. CtlP->AiopIO[i] = (WordIO_t) io;
  2211. CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
  2212. sOutB(CtlP->MReg2IO, CtlP->MReg2 | (i & 0x03)); /* AIOP index */
  2213. sOutB(MudbacIO, (Byte_t) (io >> 6)); /* set up AIOP I/O in MUDBAC */
  2214. if (done)
  2215. continue;
  2216. sEnAiop(CtlP, i); /* enable the AIOP */
  2217. CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
  2218. if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
  2219. done = 1; /* done looking for AIOPs */
  2220. else {
  2221. CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
  2222. sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
  2223. sOutB(io + _INDX_DATA, sClockPrescale);
  2224. CtlP->NumAiop++; /* bump count of AIOPs */
  2225. }
  2226. sDisAiop(CtlP, i); /* disable AIOP */
  2227. }
  2228. if (CtlP->NumAiop == 0)
  2229. return (-1);
  2230. else
  2231. return (CtlP->NumAiop);
  2232. }
  2233. /***************************************************************************
  2234. Function: sPCIInitController
  2235. Purpose: Initialization of controller global registers and controller
  2236. structure.
  2237. Call: sPCIInitController(CtlP,CtlNum,AiopIOList,AiopIOListSize,
  2238. IRQNum,Frequency,PeriodicOnly)
  2239. CONTROLLER_T *CtlP; Ptr to controller structure
  2240. int CtlNum; Controller number
  2241. ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
  2242. This list must be in the order the AIOPs will be found on the
  2243. controller. Once an AIOP in the list is not found, it is
  2244. assumed that there are no more AIOPs on the controller.
  2245. int AiopIOListSize; Number of addresses in AiopIOList
  2246. int IRQNum; Interrupt Request number. Can be any of the following:
  2247. 0: Disable global interrupts
  2248. 3: IRQ 3
  2249. 4: IRQ 4
  2250. 5: IRQ 5
  2251. 9: IRQ 9
  2252. 10: IRQ 10
  2253. 11: IRQ 11
  2254. 12: IRQ 12
  2255. 15: IRQ 15
  2256. Byte_t Frequency: A flag identifying the frequency
  2257. of the periodic interrupt, can be any one of the following:
  2258. FREQ_DIS - periodic interrupt disabled
  2259. FREQ_137HZ - 137 Hertz
  2260. FREQ_69HZ - 69 Hertz
  2261. FREQ_34HZ - 34 Hertz
  2262. FREQ_17HZ - 17 Hertz
  2263. FREQ_9HZ - 9 Hertz
  2264. FREQ_4HZ - 4 Hertz
  2265. If IRQNum is set to 0 the Frequency parameter is
  2266. overidden, it is forced to a value of FREQ_DIS.
  2267. int PeriodicOnly: 1 if all interrupts except the periodic
  2268. interrupt are to be blocked.
  2269. 0 is both the periodic interrupt and
  2270. other channel interrupts are allowed.
  2271. If IRQNum is set to 0 the PeriodicOnly parameter is
  2272. overidden, it is forced to a value of 0.
  2273. Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
  2274. initialization failed.
  2275. Comments:
  2276. If periodic interrupts are to be disabled but AIOP interrupts
  2277. are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
  2278. If interrupts are to be completely disabled set IRQNum to 0.
  2279. Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
  2280. invalid combination.
  2281. This function performs initialization of global interrupt modes,
  2282. but it does not actually enable global interrupts. To enable
  2283. and disable global interrupts use functions sEnGlobalInt() and
  2284. sDisGlobalInt(). Enabling of global interrupts is normally not
  2285. done until all other initializations are complete.
  2286. Even if interrupts are globally enabled, they must also be
  2287. individually enabled for each channel that is to generate
  2288. interrupts.
  2289. Warnings: No range checking on any of the parameters is done.
  2290. No context switches are allowed while executing this function.
  2291. After this function all AIOPs on the controller are disabled,
  2292. they can be enabled with sEnAiop().
  2293. */
  2294. static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
  2295. ByteIO_t * AiopIOList, int AiopIOListSize,
  2296. WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
  2297. int PeriodicOnly, int altChanRingIndicator,
  2298. int UPCIRingInd)
  2299. {
  2300. int i;
  2301. ByteIO_t io;
  2302. CtlP->AltChanRingIndicator = altChanRingIndicator;
  2303. CtlP->UPCIRingInd = UPCIRingInd;
  2304. CtlP->CtlNum = CtlNum;
  2305. CtlP->CtlID = CTLID_0001; /* controller release 1 */
  2306. CtlP->BusType = isPCI; /* controller release 1 */
  2307. if (ConfigIO) {
  2308. CtlP->isUPCI = 1;
  2309. CtlP->PCIIO = ConfigIO + _PCI_9030_INT_CTRL;
  2310. CtlP->PCIIO2 = ConfigIO + _PCI_9030_GPIO_CTRL;
  2311. CtlP->AiopIntrBits = upci_aiop_intr_bits;
  2312. } else {
  2313. CtlP->isUPCI = 0;
  2314. CtlP->PCIIO =
  2315. (WordIO_t) ((ByteIO_t) AiopIOList[0] + _PCI_INT_FUNC);
  2316. CtlP->AiopIntrBits = aiop_intr_bits;
  2317. }
  2318. sPCIControllerEOI(CtlP); /* clear EOI if warm init */
  2319. /* Init AIOPs */
  2320. CtlP->NumAiop = 0;
  2321. for (i = 0; i < AiopIOListSize; i++) {
  2322. io = AiopIOList[i];
  2323. CtlP->AiopIO[i] = (WordIO_t) io;
  2324. CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
  2325. CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
  2326. if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
  2327. break; /* done looking for AIOPs */
  2328. CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
  2329. sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
  2330. sOutB(io + _INDX_DATA, sClockPrescale);
  2331. CtlP->NumAiop++; /* bump count of AIOPs */
  2332. }
  2333. if (CtlP->NumAiop == 0)
  2334. return (-1);
  2335. else
  2336. return (CtlP->NumAiop);
  2337. }
  2338. /***************************************************************************
  2339. Function: sReadAiopID
  2340. Purpose: Read the AIOP idenfication number directly from an AIOP.
  2341. Call: sReadAiopID(io)
  2342. ByteIO_t io: AIOP base I/O address
  2343. Return: int: Flag AIOPID_XXXX if a valid AIOP is found, where X
  2344. is replace by an identifying number.
  2345. Flag AIOPID_NULL if no valid AIOP is found
  2346. Warnings: No context switches are allowed while executing this function.
  2347. */
  2348. static int sReadAiopID(ByteIO_t io)
  2349. {
  2350. Byte_t AiopID; /* ID byte from AIOP */
  2351. sOutB(io + _CMD_REG, RESET_ALL); /* reset AIOP */
  2352. sOutB(io + _CMD_REG, 0x0);
  2353. AiopID = sInW(io + _CHN_STAT0) & 0x07;
  2354. if (AiopID == 0x06)
  2355. return (1);
  2356. else /* AIOP does not exist */
  2357. return (-1);
  2358. }
  2359. /***************************************************************************
  2360. Function: sReadAiopNumChan
  2361. Purpose: Read the number of channels available in an AIOP directly from
  2362. an AIOP.
  2363. Call: sReadAiopNumChan(io)
  2364. WordIO_t io: AIOP base I/O address
  2365. Return: int: The number of channels available
  2366. Comments: The number of channels is determined by write/reads from identical
  2367. offsets within the SRAM address spaces for channels 0 and 4.
  2368. If the channel 4 space is mirrored to channel 0 it is a 4 channel
  2369. AIOP, otherwise it is an 8 channel.
  2370. Warnings: No context switches are allowed while executing this function.
  2371. */
  2372. static int sReadAiopNumChan(WordIO_t io)
  2373. {
  2374. Word_t x;
  2375. static Byte_t R[4] = { 0x00, 0x00, 0x34, 0x12 };
  2376. /* write to chan 0 SRAM */
  2377. out32((DWordIO_t) io + _INDX_ADDR, R);
  2378. sOutW(io + _INDX_ADDR, 0); /* read from SRAM, chan 0 */
  2379. x = sInW(io + _INDX_DATA);
  2380. sOutW(io + _INDX_ADDR, 0x4000); /* read from SRAM, chan 4 */
  2381. if (x != sInW(io + _INDX_DATA)) /* if different must be 8 chan */
  2382. return (8);
  2383. else
  2384. return (4);
  2385. }
  2386. /***************************************************************************
  2387. Function: sInitChan
  2388. Purpose: Initialization of a channel and channel structure
  2389. Call: sInitChan(CtlP,ChP,AiopNum,ChanNum)
  2390. CONTROLLER_T *CtlP; Ptr to controller structure
  2391. CHANNEL_T *ChP; Ptr to channel structure
  2392. int AiopNum; AIOP number within controller
  2393. int ChanNum; Channel number within AIOP
  2394. Return: int: 1 if initialization succeeded, 0 if it fails because channel
  2395. number exceeds number of channels available in AIOP.
  2396. Comments: This function must be called before a channel can be used.
  2397. Warnings: No range checking on any of the parameters is done.
  2398. No context switches are allowed while executing this function.
  2399. */
  2400. static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
  2401. int ChanNum)
  2402. {
  2403. int i;
  2404. WordIO_t AiopIO;
  2405. WordIO_t ChIOOff;
  2406. Byte_t *ChR;
  2407. Word_t ChOff;
  2408. static Byte_t R[4];
  2409. int brd9600;
  2410. if (ChanNum >= CtlP->AiopNumChan[AiopNum])
  2411. return 0; /* exceeds num chans in AIOP */
  2412. /* Channel, AIOP, and controller identifiers */
  2413. ChP->CtlP = CtlP;
  2414. ChP->ChanID = CtlP->AiopID[AiopNum];
  2415. ChP->AiopNum = AiopNum;
  2416. ChP->ChanNum = ChanNum;
  2417. /* Global direct addresses */
  2418. AiopIO = CtlP->AiopIO[AiopNum];
  2419. ChP->Cmd = (ByteIO_t) AiopIO + _CMD_REG;
  2420. ChP->IntChan = (ByteIO_t) AiopIO + _INT_CHAN;
  2421. ChP->IntMask = (ByteIO_t) AiopIO + _INT_MASK;
  2422. ChP->IndexAddr = (DWordIO_t) AiopIO + _INDX_ADDR;
  2423. ChP->IndexData = AiopIO + _INDX_DATA;
  2424. /* Channel direct addresses */
  2425. ChIOOff = AiopIO + ChP->ChanNum * 2;
  2426. ChP->TxRxData = ChIOOff + _TD0;
  2427. ChP->ChanStat = ChIOOff + _CHN_STAT0;
  2428. ChP->TxRxCount = ChIOOff + _FIFO_CNT0;
  2429. ChP->IntID = (ByteIO_t) AiopIO + ChP->ChanNum + _INT_ID0;
  2430. /* Initialize the channel from the RData array */
  2431. for (i = 0; i < RDATASIZE; i += 4) {
  2432. R[0] = RData[i];
  2433. R[1] = RData[i + 1] + 0x10 * ChanNum;
  2434. R[2] = RData[i + 2];
  2435. R[3] = RData[i + 3];
  2436. out32(ChP->IndexAddr, R);
  2437. }
  2438. ChR = ChP->R;
  2439. for (i = 0; i < RREGDATASIZE; i += 4) {
  2440. ChR[i] = RRegData[i];
  2441. ChR[i + 1] = RRegData[i + 1] + 0x10 * ChanNum;
  2442. ChR[i + 2] = RRegData[i + 2];
  2443. ChR[i + 3] = RRegData[i + 3];
  2444. }
  2445. /* Indexed registers */
  2446. ChOff = (Word_t) ChanNum *0x1000;
  2447. if (sClockPrescale == 0x14)
  2448. brd9600 = 47;
  2449. else
  2450. brd9600 = 23;
  2451. ChP->BaudDiv[0] = (Byte_t) (ChOff + _BAUD);
  2452. ChP->BaudDiv[1] = (Byte_t) ((ChOff + _BAUD) >> 8);
  2453. ChP->BaudDiv[2] = (Byte_t) brd9600;
  2454. ChP->BaudDiv[3] = (Byte_t) (brd9600 >> 8);
  2455. out32(ChP->IndexAddr, ChP->BaudDiv);
  2456. ChP->TxControl[0] = (Byte_t) (ChOff + _TX_CTRL);
  2457. ChP->TxControl[1] = (Byte_t) ((ChOff + _TX_CTRL) >> 8);
  2458. ChP->TxControl[2] = 0;
  2459. ChP->TxControl[3] = 0;
  2460. out32(ChP->IndexAddr, ChP->TxControl);
  2461. ChP->RxControl[0] = (Byte_t) (ChOff + _RX_CTRL);
  2462. ChP->RxControl[1] = (Byte_t) ((ChOff + _RX_CTRL) >> 8);
  2463. ChP->RxControl[2] = 0;
  2464. ChP->RxControl[3] = 0;
  2465. out32(ChP->IndexAddr, ChP->RxControl);
  2466. ChP->TxEnables[0] = (Byte_t) (ChOff + _TX_ENBLS);
  2467. ChP->TxEnables[1] = (Byte_t) ((ChOff + _TX_ENBLS) >> 8);
  2468. ChP->TxEnables[2] = 0;
  2469. ChP->TxEnables[3] = 0;
  2470. out32(ChP->IndexAddr, ChP->TxEnables);
  2471. ChP->TxCompare[0] = (Byte_t) (ChOff + _TXCMP1);
  2472. ChP->TxCompare[1] = (Byte_t) ((ChOff + _TXCMP1) >> 8);
  2473. ChP->TxCompare[2] = 0;
  2474. ChP->TxCompare[3] = 0;
  2475. out32(ChP->IndexAddr, ChP->TxCompare);
  2476. ChP->TxReplace1[0] = (Byte_t) (ChOff + _TXREP1B1);
  2477. ChP->TxReplace1[1] = (Byte_t) ((ChOff + _TXREP1B1) >> 8);
  2478. ChP->TxReplace1[2] = 0;
  2479. ChP->TxReplace1[3] = 0;
  2480. out32(ChP->IndexAddr, ChP->TxReplace1);
  2481. ChP->TxReplace2[0] = (Byte_t) (ChOff + _TXREP2);
  2482. ChP->TxReplace2[1] = (Byte_t) ((ChOff + _TXREP2) >> 8);
  2483. ChP->TxReplace2[2] = 0;
  2484. ChP->TxReplace2[3] = 0;
  2485. out32(ChP->IndexAddr, ChP->TxReplace2);
  2486. ChP->TxFIFOPtrs = ChOff + _TXF_OUTP;
  2487. ChP->TxFIFO = ChOff + _TX_FIFO;
  2488. sOutB(ChP->Cmd, (Byte_t) ChanNum | RESTXFCNT); /* apply reset Tx FIFO count */
  2489. sOutB(ChP->Cmd, (Byte_t) ChanNum); /* remove reset Tx FIFO count */
  2490. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxFIFOPtrs); /* clear Tx in/out ptrs */
  2491. sOutW(ChP->IndexData, 0);
  2492. ChP->RxFIFOPtrs = ChOff + _RXF_OUTP;
  2493. ChP->RxFIFO = ChOff + _RX_FIFO;
  2494. sOutB(ChP->Cmd, (Byte_t) ChanNum | RESRXFCNT); /* apply reset Rx FIFO count */
  2495. sOutB(ChP->Cmd, (Byte_t) ChanNum); /* remove reset Rx FIFO count */
  2496. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs); /* clear Rx out ptr */
  2497. sOutW(ChP->IndexData, 0);
  2498. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs + 2); /* clear Rx in ptr */
  2499. sOutW(ChP->IndexData, 0);
  2500. ChP->TxPrioCnt = ChOff + _TXP_CNT;
  2501. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxPrioCnt);
  2502. sOutB(ChP->IndexData, 0);
  2503. ChP->TxPrioPtr = ChOff + _TXP_PNTR;
  2504. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxPrioPtr);
  2505. sOutB(ChP->IndexData, 0);
  2506. ChP->TxPrioBuf = ChOff + _TXP_BUF;
  2507. sEnRxProcessor(ChP); /* start the Rx processor */
  2508. return 1;
  2509. }
  2510. /***************************************************************************
  2511. Function: sStopRxProcessor
  2512. Purpose: Stop the receive processor from processing a channel.
  2513. Call: sStopRxProcessor(ChP)
  2514. CHANNEL_T *ChP; Ptr to channel structure
  2515. Comments: The receive processor can be started again with sStartRxProcessor().
  2516. This function causes the receive processor to skip over the
  2517. stopped channel. It does not stop it from processing other channels.
  2518. Warnings: No context switches are allowed while executing this function.
  2519. Do not leave the receive processor stopped for more than one
  2520. character time.
  2521. After calling this function a delay of 4 uS is required to ensure
  2522. that the receive processor is no longer processing this channel.
  2523. */
  2524. static void sStopRxProcessor(CHANNEL_T * ChP)
  2525. {
  2526. Byte_t R[4];
  2527. R[0] = ChP->R[0];
  2528. R[1] = ChP->R[1];
  2529. R[2] = 0x0a;
  2530. R[3] = ChP->R[3];
  2531. out32(ChP->IndexAddr, R);
  2532. }
  2533. /***************************************************************************
  2534. Function: sFlushRxFIFO
  2535. Purpose: Flush the Rx FIFO
  2536. Call: sFlushRxFIFO(ChP)
  2537. CHANNEL_T *ChP; Ptr to channel structure
  2538. Return: void
  2539. Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
  2540. while it is being flushed the receive processor is stopped
  2541. and the transmitter is disabled. After these operations a
  2542. 4 uS delay is done before clearing the pointers to allow
  2543. the receive processor to stop. These items are handled inside
  2544. this function.
  2545. Warnings: No context switches are allowed while executing this function.
  2546. */
  2547. static void sFlushRxFIFO(CHANNEL_T * ChP)
  2548. {
  2549. int i;
  2550. Byte_t Ch; /* channel number within AIOP */
  2551. int RxFIFOEnabled; /* 1 if Rx FIFO enabled */
  2552. if (sGetRxCnt(ChP) == 0) /* Rx FIFO empty */
  2553. return; /* don't need to flush */
  2554. RxFIFOEnabled = 0;
  2555. if (ChP->R[0x32] == 0x08) { /* Rx FIFO is enabled */
  2556. RxFIFOEnabled = 1;
  2557. sDisRxFIFO(ChP); /* disable it */
  2558. for (i = 0; i < 2000 / 200; i++) /* delay 2 uS to allow proc to disable FIFO */
  2559. sInB(ChP->IntChan); /* depends on bus i/o timing */
  2560. }
  2561. sGetChanStatus(ChP); /* clear any pending Rx errors in chan stat */
  2562. Ch = (Byte_t) sGetChanNum(ChP);
  2563. sOutB(ChP->Cmd, Ch | RESRXFCNT); /* apply reset Rx FIFO count */
  2564. sOutB(ChP->Cmd, Ch); /* remove reset Rx FIFO count */
  2565. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs); /* clear Rx out ptr */
  2566. sOutW(ChP->IndexData, 0);
  2567. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs + 2); /* clear Rx in ptr */
  2568. sOutW(ChP->IndexData, 0);
  2569. if (RxFIFOEnabled)
  2570. sEnRxFIFO(ChP); /* enable Rx FIFO */
  2571. }
  2572. /***************************************************************************
  2573. Function: sFlushTxFIFO
  2574. Purpose: Flush the Tx FIFO
  2575. Call: sFlushTxFIFO(ChP)
  2576. CHANNEL_T *ChP; Ptr to channel structure
  2577. Return: void
  2578. Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
  2579. while it is being flushed the receive processor is stopped
  2580. and the transmitter is disabled. After these operations a
  2581. 4 uS delay is done before clearing the pointers to allow
  2582. the receive processor to stop. These items are handled inside
  2583. this function.
  2584. Warnings: No context switches are allowed while executing this function.
  2585. */
  2586. static void sFlushTxFIFO(CHANNEL_T * ChP)
  2587. {
  2588. int i;
  2589. Byte_t Ch; /* channel number within AIOP */
  2590. int TxEnabled; /* 1 if transmitter enabled */
  2591. if (sGetTxCnt(ChP) == 0) /* Tx FIFO empty */
  2592. return; /* don't need to flush */
  2593. TxEnabled = 0;
  2594. if (ChP->TxControl[3] & TX_ENABLE) {
  2595. TxEnabled = 1;
  2596. sDisTransmit(ChP); /* disable transmitter */
  2597. }
  2598. sStopRxProcessor(ChP); /* stop Rx processor */
  2599. for (i = 0; i < 4000 / 200; i++) /* delay 4 uS to allow proc to stop */
  2600. sInB(ChP->IntChan); /* depends on bus i/o timing */
  2601. Ch = (Byte_t) sGetChanNum(ChP);
  2602. sOutB(ChP->Cmd, Ch | RESTXFCNT); /* apply reset Tx FIFO count */
  2603. sOutB(ChP->Cmd, Ch); /* remove reset Tx FIFO count */
  2604. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxFIFOPtrs); /* clear Tx in/out ptrs */
  2605. sOutW(ChP->IndexData, 0);
  2606. if (TxEnabled)
  2607. sEnTransmit(ChP); /* enable transmitter */
  2608. sStartRxProcessor(ChP); /* restart Rx processor */
  2609. }
  2610. /***************************************************************************
  2611. Function: sWriteTxPrioByte
  2612. Purpose: Write a byte of priority transmit data to a channel
  2613. Call: sWriteTxPrioByte(ChP,Data)
  2614. CHANNEL_T *ChP; Ptr to channel structure
  2615. Byte_t Data; The transmit data byte
  2616. Return: int: 1 if the bytes is successfully written, otherwise 0.
  2617. Comments: The priority byte is transmitted before any data in the Tx FIFO.
  2618. Warnings: No context switches are allowed while executing this function.
  2619. */
  2620. static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data)
  2621. {
  2622. Byte_t DWBuf[4]; /* buffer for double word writes */
  2623. Word_t *WordPtr; /* must be far because Win SS != DS */
  2624. register DWordIO_t IndexAddr;
  2625. if (sGetTxCnt(ChP) > 1) { /* write it to Tx priority buffer */
  2626. IndexAddr = ChP->IndexAddr;
  2627. sOutW((WordIO_t) IndexAddr, ChP->TxPrioCnt); /* get priority buffer status */
  2628. if (sInB((ByteIO_t) ChP->IndexData) & PRI_PEND) /* priority buffer busy */
  2629. return (0); /* nothing sent */
  2630. WordPtr = (Word_t *) (&DWBuf[0]);
  2631. *WordPtr = ChP->TxPrioBuf; /* data byte address */
  2632. DWBuf[2] = Data; /* data byte value */
  2633. out32(IndexAddr, DWBuf); /* write it out */
  2634. *WordPtr = ChP->TxPrioCnt; /* Tx priority count address */
  2635. DWBuf[2] = PRI_PEND + 1; /* indicate 1 byte pending */
  2636. DWBuf[3] = 0; /* priority buffer pointer */
  2637. out32(IndexAddr, DWBuf); /* write it out */
  2638. } else { /* write it to Tx FIFO */
  2639. sWriteTxByte(sGetTxRxDataIO(ChP), Data);
  2640. }
  2641. return (1); /* 1 byte sent */
  2642. }
  2643. /***************************************************************************
  2644. Function: sEnInterrupts
  2645. Purpose: Enable one or more interrupts for a channel
  2646. Call: sEnInterrupts(ChP,Flags)
  2647. CHANNEL_T *ChP; Ptr to channel structure
  2648. Word_t Flags: Interrupt enable flags, can be any combination
  2649. of the following flags:
  2650. TXINT_EN: Interrupt on Tx FIFO empty
  2651. RXINT_EN: Interrupt on Rx FIFO at trigger level (see
  2652. sSetRxTrigger())
  2653. SRCINT_EN: Interrupt on SRC (Special Rx Condition)
  2654. MCINT_EN: Interrupt on modem input change
  2655. CHANINT_EN: Allow channel interrupt signal to the AIOP's
  2656. Interrupt Channel Register.
  2657. Return: void
  2658. Comments: If an interrupt enable flag is set in Flags, that interrupt will be
  2659. enabled. If an interrupt enable flag is not set in Flags, that
  2660. interrupt will not be changed. Interrupts can be disabled with
  2661. function sDisInterrupts().
  2662. This function sets the appropriate bit for the channel in the AIOP's
  2663. Interrupt Mask Register if the CHANINT_EN flag is set. This allows
  2664. this channel's bit to be set in the AIOP's Interrupt Channel Register.
  2665. Interrupts must also be globally enabled before channel interrupts
  2666. will be passed on to the host. This is done with function
  2667. sEnGlobalInt().
  2668. In some cases it may be desirable to disable interrupts globally but
  2669. enable channel interrupts. This would allow the global interrupt
  2670. status register to be used to determine which AIOPs need service.
  2671. */
  2672. static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags)
  2673. {
  2674. Byte_t Mask; /* Interrupt Mask Register */
  2675. ChP->RxControl[2] |=
  2676. ((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
  2677. out32(ChP->IndexAddr, ChP->RxControl);
  2678. ChP->TxControl[2] |= ((Byte_t) Flags & TXINT_EN);
  2679. out32(ChP->IndexAddr, ChP->TxControl);
  2680. if (Flags & CHANINT_EN) {
  2681. Mask = sInB(ChP->IntMask) | sBitMapSetTbl[ChP->ChanNum];
  2682. sOutB(ChP->IntMask, Mask);
  2683. }
  2684. }
  2685. /***************************************************************************
  2686. Function: sDisInterrupts
  2687. Purpose: Disable one or more interrupts for a channel
  2688. Call: sDisInterrupts(ChP,Flags)
  2689. CHANNEL_T *ChP; Ptr to channel structure
  2690. Word_t Flags: Interrupt flags, can be any combination
  2691. of the following flags:
  2692. TXINT_EN: Interrupt on Tx FIFO empty
  2693. RXINT_EN: Interrupt on Rx FIFO at trigger level (see
  2694. sSetRxTrigger())
  2695. SRCINT_EN: Interrupt on SRC (Special Rx Condition)
  2696. MCINT_EN: Interrupt on modem input change
  2697. CHANINT_EN: Disable channel interrupt signal to the
  2698. AIOP's Interrupt Channel Register.
  2699. Return: void
  2700. Comments: If an interrupt flag is set in Flags, that interrupt will be
  2701. disabled. If an interrupt flag is not set in Flags, that
  2702. interrupt will not be changed. Interrupts can be enabled with
  2703. function sEnInterrupts().
  2704. This function clears the appropriate bit for the channel in the AIOP's
  2705. Interrupt Mask Register if the CHANINT_EN flag is set. This blocks
  2706. this channel's bit from being set in the AIOP's Interrupt Channel
  2707. Register.
  2708. */
  2709. static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
  2710. {
  2711. Byte_t Mask; /* Interrupt Mask Register */
  2712. ChP->RxControl[2] &=
  2713. ~((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
  2714. out32(ChP->IndexAddr, ChP->RxControl);
  2715. ChP->TxControl[2] &= ~((Byte_t) Flags & TXINT_EN);
  2716. out32(ChP->IndexAddr, ChP->TxControl);
  2717. if (Flags & CHANINT_EN) {
  2718. Mask = sInB(ChP->IntMask) & sBitMapClrTbl[ChP->ChanNum];
  2719. sOutB(ChP->IntMask, Mask);
  2720. }
  2721. }
  2722. static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode)
  2723. {
  2724. sOutB(ChP->CtlP->AiopIO[2], (mode & 0x18) | ChP->ChanNum);
  2725. }
  2726. /*
  2727. * Not an official SSCI function, but how to reset RocketModems.
  2728. * ISA bus version
  2729. */
  2730. static void sModemReset(CONTROLLER_T * CtlP, int chan, int on)
  2731. {
  2732. ByteIO_t addr;
  2733. Byte_t val;
  2734. addr = CtlP->AiopIO[0] + 0x400;
  2735. val = sInB(CtlP->MReg3IO);
  2736. /* if AIOP[1] is not enabled, enable it */
  2737. if ((val & 2) == 0) {
  2738. val = sInB(CtlP->MReg2IO);
  2739. sOutB(CtlP->MReg2IO, (val & 0xfc) | (1 & 0x03));
  2740. sOutB(CtlP->MBaseIO, (unsigned char) (addr >> 6));
  2741. }
  2742. sEnAiop(CtlP, 1);
  2743. if (!on)
  2744. addr += 8;
  2745. sOutB(addr + chan, 0); /* apply or remove reset */
  2746. sDisAiop(CtlP, 1);
  2747. }
  2748. /*
  2749. * Not an official SSCI function, but how to reset RocketModems.
  2750. * PCI bus version
  2751. */
  2752. static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on)
  2753. {
  2754. ByteIO_t addr;
  2755. addr = CtlP->AiopIO[0] + 0x40; /* 2nd AIOP */
  2756. if (!on)
  2757. addr += 8;
  2758. sOutB(addr + chan, 0); /* apply or remove reset */
  2759. }
  2760. /* Resets the speaker controller on RocketModem II and III devices */
  2761. static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model)
  2762. {
  2763. ByteIO_t addr;
  2764. /* RocketModem II speaker control is at the 8th port location of offset 0x40 */
  2765. if ((model == MODEL_RP4M) || (model == MODEL_RP6M)) {
  2766. addr = CtlP->AiopIO[0] + 0x4F;
  2767. sOutB(addr, 0);
  2768. }
  2769. /* RocketModem III speaker control is at the 1st port location of offset 0x80 */
  2770. if ((model == MODEL_UPCI_RM3_8PORT)
  2771. || (model == MODEL_UPCI_RM3_4PORT)) {
  2772. addr = CtlP->AiopIO[0] + 0x88;
  2773. sOutB(addr, 0);
  2774. }
  2775. }
  2776. /* Returns the line number given the controller (board), aiop and channel number */
  2777. static unsigned char GetLineNumber(int ctrl, int aiop, int ch)
  2778. {
  2779. return lineNumbers[(ctrl << 5) | (aiop << 3) | ch];
  2780. }
  2781. /*
  2782. * Stores the line number associated with a given controller (board), aiop
  2783. * and channel number.
  2784. * Returns: The line number assigned
  2785. */
  2786. static unsigned char SetLineNumber(int ctrl, int aiop, int ch)
  2787. {
  2788. lineNumbers[(ctrl << 5) | (aiop << 3) | ch] = nextLineNumber++;
  2789. return (nextLineNumber - 1);
  2790. }