rocket.c 93 KB

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