rocket.c 97 KB

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