rocket.c 93 KB

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