rocket.c 98 KB

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