rocket.c 97 KB

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