rocket.c 98 KB

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