rocket.c 97 KB

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