rocket.c 94 KB

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