rocket.c 93 KB

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