rocket.c 98 KB

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