istallion.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508
  1. /*****************************************************************************/
  2. /*
  3. * istallion.c -- stallion intelligent multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. */
  17. /*****************************************************************************/
  18. #include <linux/module.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/tty.h>
  23. #include <linux/tty_flip.h>
  24. #include <linux/serial.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/cdk.h>
  27. #include <linux/comstats.h>
  28. #include <linux/istallion.h>
  29. #include <linux/ioport.h>
  30. #include <linux/delay.h>
  31. #include <linux/init.h>
  32. #include <linux/device.h>
  33. #include <linux/wait.h>
  34. #include <linux/eisa.h>
  35. #include <linux/ctype.h>
  36. #include <asm/io.h>
  37. #include <asm/uaccess.h>
  38. #include <linux/pci.h>
  39. /*****************************************************************************/
  40. /*
  41. * Define different board types. Not all of the following board types
  42. * are supported by this driver. But I will use the standard "assigned"
  43. * board numbers. Currently supported boards are abbreviated as:
  44. * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
  45. * STAL = Stallion.
  46. */
  47. #define BRD_UNKNOWN 0
  48. #define BRD_STALLION 1
  49. #define BRD_BRUMBY4 2
  50. #define BRD_ONBOARD2 3
  51. #define BRD_ONBOARD 4
  52. #define BRD_ONBOARDE 7
  53. #define BRD_ECP 23
  54. #define BRD_ECPE 24
  55. #define BRD_ECPMC 25
  56. #define BRD_ECPPCI 29
  57. #define BRD_BRUMBY BRD_BRUMBY4
  58. /*
  59. * Define a configuration structure to hold the board configuration.
  60. * Need to set this up in the code (for now) with the boards that are
  61. * to be configured into the system. This is what needs to be modified
  62. * when adding/removing/modifying boards. Each line entry in the
  63. * stli_brdconf[] array is a board. Each line contains io/irq/memory
  64. * ranges for that board (as well as what type of board it is).
  65. * Some examples:
  66. * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
  67. * This line will configure an EasyConnection 8/64 at io address 2a0,
  68. * and shared memory address of cc000. Multiple EasyConnection 8/64
  69. * boards can share the same shared memory address space. No interrupt
  70. * is required for this board type.
  71. * Another example:
  72. * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
  73. * This line will configure an EasyConnection 8/64 EISA in slot 5 and
  74. * shared memory address of 0x80000000 (2 GByte). Multiple
  75. * EasyConnection 8/64 EISA boards can share the same shared memory
  76. * address space. No interrupt is required for this board type.
  77. * Another example:
  78. * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
  79. * This line will configure an ONboard (ISA type) at io address 240,
  80. * and shared memory address of d0000. Multiple ONboards can share
  81. * the same shared memory address space. No interrupt required.
  82. * Another example:
  83. * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
  84. * This line will configure a Brumby board (any number of ports!) at
  85. * io address 360 and shared memory address of c8000. All Brumby boards
  86. * configured into a system must have their own separate io and memory
  87. * addresses. No interrupt is required.
  88. * Another example:
  89. * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
  90. * This line will configure an original Stallion board at io address 330
  91. * and shared memory address d0000 (this would only be valid for a "V4.0"
  92. * or Rev.O Stallion board). All Stallion boards configured into the
  93. * system must have their own separate io and memory addresses. No
  94. * interrupt is required.
  95. */
  96. struct stlconf {
  97. int brdtype;
  98. int ioaddr1;
  99. int ioaddr2;
  100. unsigned long memaddr;
  101. int irq;
  102. int irqtype;
  103. };
  104. static unsigned int stli_nrbrds;
  105. /* stli_lock must NOT be taken holding brd_lock */
  106. static spinlock_t stli_lock; /* TTY logic lock */
  107. static spinlock_t brd_lock; /* Board logic lock */
  108. /*
  109. * There is some experimental EISA board detection code in this driver.
  110. * By default it is disabled, but for those that want to try it out,
  111. * then set the define below to be 1.
  112. */
  113. #define STLI_EISAPROBE 0
  114. /*****************************************************************************/
  115. /*
  116. * Define some important driver characteristics. Device major numbers
  117. * allocated as per Linux Device Registry.
  118. */
  119. #ifndef STL_SIOMEMMAJOR
  120. #define STL_SIOMEMMAJOR 28
  121. #endif
  122. #ifndef STL_SERIALMAJOR
  123. #define STL_SERIALMAJOR 24
  124. #endif
  125. #ifndef STL_CALLOUTMAJOR
  126. #define STL_CALLOUTMAJOR 25
  127. #endif
  128. /*****************************************************************************/
  129. /*
  130. * Define our local driver identity first. Set up stuff to deal with
  131. * all the local structures required by a serial tty driver.
  132. */
  133. static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
  134. static char *stli_drvname = "istallion";
  135. static char *stli_drvversion = "5.6.0";
  136. static char *stli_serialname = "ttyE";
  137. static struct tty_driver *stli_serial;
  138. static const struct tty_port_operations stli_port_ops;
  139. #define STLI_TXBUFSIZE 4096
  140. /*
  141. * Use a fast local buffer for cooked characters. Typically a whole
  142. * bunch of cooked characters come in for a port, 1 at a time. So we
  143. * save those up into a local buffer, then write out the whole lot
  144. * with a large memcpy. Just use 1 buffer for all ports, since its
  145. * use it is only need for short periods of time by each port.
  146. */
  147. static char *stli_txcookbuf;
  148. static int stli_txcooksize;
  149. static int stli_txcookrealsize;
  150. static struct tty_struct *stli_txcooktty;
  151. /*
  152. * Define a local default termios struct. All ports will be created
  153. * with this termios initially. Basically all it defines is a raw port
  154. * at 9600 baud, 8 data bits, no parity, 1 stop bit.
  155. */
  156. static struct ktermios stli_deftermios = {
  157. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  158. .c_cc = INIT_C_CC,
  159. .c_ispeed = 9600,
  160. .c_ospeed = 9600,
  161. };
  162. /*
  163. * Define global stats structures. Not used often, and can be
  164. * re-used for each stats call.
  165. */
  166. static comstats_t stli_comstats;
  167. static struct asystats stli_cdkstats;
  168. /*****************************************************************************/
  169. static DEFINE_MUTEX(stli_brdslock);
  170. static struct stlibrd *stli_brds[STL_MAXBRDS];
  171. static int stli_shared;
  172. /*
  173. * Per board state flags. Used with the state field of the board struct.
  174. * Not really much here... All we need to do is keep track of whether
  175. * the board has been detected, and whether it is actually running a slave
  176. * or not.
  177. */
  178. #define BST_FOUND 0
  179. #define BST_STARTED 1
  180. #define BST_PROBED 2
  181. /*
  182. * Define the set of port state flags. These are marked for internal
  183. * state purposes only, usually to do with the state of communications
  184. * with the slave. Most of them need to be updated atomically, so always
  185. * use the bit setting operations (unless protected by cli/sti).
  186. */
  187. #define ST_OPENING 2
  188. #define ST_CLOSING 3
  189. #define ST_CMDING 4
  190. #define ST_TXBUSY 5
  191. #define ST_RXING 6
  192. #define ST_DOFLUSHRX 7
  193. #define ST_DOFLUSHTX 8
  194. #define ST_DOSIGS 9
  195. #define ST_RXSTOP 10
  196. #define ST_GETSIGS 11
  197. /*
  198. * Define an array of board names as printable strings. Handy for
  199. * referencing boards when printing trace and stuff.
  200. */
  201. static char *stli_brdnames[] = {
  202. "Unknown",
  203. "Stallion",
  204. "Brumby",
  205. "ONboard-MC",
  206. "ONboard",
  207. "Brumby",
  208. "Brumby",
  209. "ONboard-EI",
  210. NULL,
  211. "ONboard",
  212. "ONboard-MC",
  213. "ONboard-MC",
  214. NULL,
  215. NULL,
  216. NULL,
  217. NULL,
  218. NULL,
  219. NULL,
  220. NULL,
  221. NULL,
  222. "EasyIO",
  223. "EC8/32-AT",
  224. "EC8/32-MC",
  225. "EC8/64-AT",
  226. "EC8/64-EI",
  227. "EC8/64-MC",
  228. "EC8/32-PCI",
  229. "EC8/64-PCI",
  230. "EasyIO-PCI",
  231. "EC/RA-PCI",
  232. };
  233. /*****************************************************************************/
  234. /*
  235. * Define some string labels for arguments passed from the module
  236. * load line. These allow for easy board definitions, and easy
  237. * modification of the io, memory and irq resoucres.
  238. */
  239. static char *board0[8];
  240. static char *board1[8];
  241. static char *board2[8];
  242. static char *board3[8];
  243. static char **stli_brdsp[] = {
  244. (char **) &board0,
  245. (char **) &board1,
  246. (char **) &board2,
  247. (char **) &board3
  248. };
  249. /*
  250. * Define a set of common board names, and types. This is used to
  251. * parse any module arguments.
  252. */
  253. static struct stlibrdtype {
  254. char *name;
  255. int type;
  256. } stli_brdstr[] = {
  257. { "stallion", BRD_STALLION },
  258. { "1", BRD_STALLION },
  259. { "brumby", BRD_BRUMBY },
  260. { "brumby4", BRD_BRUMBY },
  261. { "brumby/4", BRD_BRUMBY },
  262. { "brumby-4", BRD_BRUMBY },
  263. { "brumby8", BRD_BRUMBY },
  264. { "brumby/8", BRD_BRUMBY },
  265. { "brumby-8", BRD_BRUMBY },
  266. { "brumby16", BRD_BRUMBY },
  267. { "brumby/16", BRD_BRUMBY },
  268. { "brumby-16", BRD_BRUMBY },
  269. { "2", BRD_BRUMBY },
  270. { "onboard2", BRD_ONBOARD2 },
  271. { "onboard-2", BRD_ONBOARD2 },
  272. { "onboard/2", BRD_ONBOARD2 },
  273. { "onboard-mc", BRD_ONBOARD2 },
  274. { "onboard/mc", BRD_ONBOARD2 },
  275. { "onboard-mca", BRD_ONBOARD2 },
  276. { "onboard/mca", BRD_ONBOARD2 },
  277. { "3", BRD_ONBOARD2 },
  278. { "onboard", BRD_ONBOARD },
  279. { "onboardat", BRD_ONBOARD },
  280. { "4", BRD_ONBOARD },
  281. { "onboarde", BRD_ONBOARDE },
  282. { "onboard-e", BRD_ONBOARDE },
  283. { "onboard/e", BRD_ONBOARDE },
  284. { "onboard-ei", BRD_ONBOARDE },
  285. { "onboard/ei", BRD_ONBOARDE },
  286. { "7", BRD_ONBOARDE },
  287. { "ecp", BRD_ECP },
  288. { "ecpat", BRD_ECP },
  289. { "ec8/64", BRD_ECP },
  290. { "ec8/64-at", BRD_ECP },
  291. { "ec8/64-isa", BRD_ECP },
  292. { "23", BRD_ECP },
  293. { "ecpe", BRD_ECPE },
  294. { "ecpei", BRD_ECPE },
  295. { "ec8/64-e", BRD_ECPE },
  296. { "ec8/64-ei", BRD_ECPE },
  297. { "24", BRD_ECPE },
  298. { "ecpmc", BRD_ECPMC },
  299. { "ec8/64-mc", BRD_ECPMC },
  300. { "ec8/64-mca", BRD_ECPMC },
  301. { "25", BRD_ECPMC },
  302. { "ecppci", BRD_ECPPCI },
  303. { "ec/ra", BRD_ECPPCI },
  304. { "ec/ra-pc", BRD_ECPPCI },
  305. { "ec/ra-pci", BRD_ECPPCI },
  306. { "29", BRD_ECPPCI },
  307. };
  308. /*
  309. * Define the module agruments.
  310. */
  311. MODULE_AUTHOR("Greg Ungerer");
  312. MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
  313. MODULE_LICENSE("GPL");
  314. module_param_array(board0, charp, NULL, 0);
  315. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
  316. module_param_array(board1, charp, NULL, 0);
  317. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
  318. module_param_array(board2, charp, NULL, 0);
  319. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
  320. module_param_array(board3, charp, NULL, 0);
  321. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
  322. #if STLI_EISAPROBE != 0
  323. /*
  324. * Set up a default memory address table for EISA board probing.
  325. * The default addresses are all bellow 1Mbyte, which has to be the
  326. * case anyway. They should be safe, since we only read values from
  327. * them, and interrupts are disabled while we do it. If the higher
  328. * memory support is compiled in then we also try probing around
  329. * the 1Gb, 2Gb and 3Gb areas as well...
  330. */
  331. static unsigned long stli_eisamemprobeaddrs[] = {
  332. 0xc0000, 0xd0000, 0xe0000, 0xf0000,
  333. 0x80000000, 0x80010000, 0x80020000, 0x80030000,
  334. 0x40000000, 0x40010000, 0x40020000, 0x40030000,
  335. 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
  336. 0xff000000, 0xff010000, 0xff020000, 0xff030000,
  337. };
  338. static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
  339. #endif
  340. /*
  341. * Define the Stallion PCI vendor and device IDs.
  342. */
  343. #ifndef PCI_DEVICE_ID_ECRA
  344. #define PCI_DEVICE_ID_ECRA 0x0004
  345. #endif
  346. static struct pci_device_id istallion_pci_tbl[] = {
  347. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
  348. { 0 }
  349. };
  350. MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
  351. static struct pci_driver stli_pcidriver;
  352. /*****************************************************************************/
  353. /*
  354. * Hardware configuration info for ECP boards. These defines apply
  355. * to the directly accessible io ports of the ECP. There is a set of
  356. * defines for each ECP board type, ISA, EISA, MCA and PCI.
  357. */
  358. #define ECP_IOSIZE 4
  359. #define ECP_MEMSIZE (128 * 1024)
  360. #define ECP_PCIMEMSIZE (256 * 1024)
  361. #define ECP_ATPAGESIZE (4 * 1024)
  362. #define ECP_MCPAGESIZE (4 * 1024)
  363. #define ECP_EIPAGESIZE (64 * 1024)
  364. #define ECP_PCIPAGESIZE (64 * 1024)
  365. #define STL_EISAID 0x8c4e
  366. /*
  367. * Important defines for the ISA class of ECP board.
  368. */
  369. #define ECP_ATIREG 0
  370. #define ECP_ATCONFR 1
  371. #define ECP_ATMEMAR 2
  372. #define ECP_ATMEMPR 3
  373. #define ECP_ATSTOP 0x1
  374. #define ECP_ATINTENAB 0x10
  375. #define ECP_ATENABLE 0x20
  376. #define ECP_ATDISABLE 0x00
  377. #define ECP_ATADDRMASK 0x3f000
  378. #define ECP_ATADDRSHFT 12
  379. /*
  380. * Important defines for the EISA class of ECP board.
  381. */
  382. #define ECP_EIIREG 0
  383. #define ECP_EIMEMARL 1
  384. #define ECP_EICONFR 2
  385. #define ECP_EIMEMARH 3
  386. #define ECP_EIENABLE 0x1
  387. #define ECP_EIDISABLE 0x0
  388. #define ECP_EISTOP 0x4
  389. #define ECP_EIEDGE 0x00
  390. #define ECP_EILEVEL 0x80
  391. #define ECP_EIADDRMASKL 0x00ff0000
  392. #define ECP_EIADDRSHFTL 16
  393. #define ECP_EIADDRMASKH 0xff000000
  394. #define ECP_EIADDRSHFTH 24
  395. #define ECP_EIBRDENAB 0xc84
  396. #define ECP_EISAID 0x4
  397. /*
  398. * Important defines for the Micro-channel class of ECP board.
  399. * (It has a lot in common with the ISA boards.)
  400. */
  401. #define ECP_MCIREG 0
  402. #define ECP_MCCONFR 1
  403. #define ECP_MCSTOP 0x20
  404. #define ECP_MCENABLE 0x80
  405. #define ECP_MCDISABLE 0x00
  406. /*
  407. * Important defines for the PCI class of ECP board.
  408. * (It has a lot in common with the other ECP boards.)
  409. */
  410. #define ECP_PCIIREG 0
  411. #define ECP_PCICONFR 1
  412. #define ECP_PCISTOP 0x01
  413. /*
  414. * Hardware configuration info for ONboard and Brumby boards. These
  415. * defines apply to the directly accessible io ports of these boards.
  416. */
  417. #define ONB_IOSIZE 16
  418. #define ONB_MEMSIZE (64 * 1024)
  419. #define ONB_ATPAGESIZE (64 * 1024)
  420. #define ONB_MCPAGESIZE (64 * 1024)
  421. #define ONB_EIMEMSIZE (128 * 1024)
  422. #define ONB_EIPAGESIZE (64 * 1024)
  423. /*
  424. * Important defines for the ISA class of ONboard board.
  425. */
  426. #define ONB_ATIREG 0
  427. #define ONB_ATMEMAR 1
  428. #define ONB_ATCONFR 2
  429. #define ONB_ATSTOP 0x4
  430. #define ONB_ATENABLE 0x01
  431. #define ONB_ATDISABLE 0x00
  432. #define ONB_ATADDRMASK 0xff0000
  433. #define ONB_ATADDRSHFT 16
  434. #define ONB_MEMENABLO 0
  435. #define ONB_MEMENABHI 0x02
  436. /*
  437. * Important defines for the EISA class of ONboard board.
  438. */
  439. #define ONB_EIIREG 0
  440. #define ONB_EIMEMARL 1
  441. #define ONB_EICONFR 2
  442. #define ONB_EIMEMARH 3
  443. #define ONB_EIENABLE 0x1
  444. #define ONB_EIDISABLE 0x0
  445. #define ONB_EISTOP 0x4
  446. #define ONB_EIEDGE 0x00
  447. #define ONB_EILEVEL 0x80
  448. #define ONB_EIADDRMASKL 0x00ff0000
  449. #define ONB_EIADDRSHFTL 16
  450. #define ONB_EIADDRMASKH 0xff000000
  451. #define ONB_EIADDRSHFTH 24
  452. #define ONB_EIBRDENAB 0xc84
  453. #define ONB_EISAID 0x1
  454. /*
  455. * Important defines for the Brumby boards. They are pretty simple,
  456. * there is not much that is programmably configurable.
  457. */
  458. #define BBY_IOSIZE 16
  459. #define BBY_MEMSIZE (64 * 1024)
  460. #define BBY_PAGESIZE (16 * 1024)
  461. #define BBY_ATIREG 0
  462. #define BBY_ATCONFR 1
  463. #define BBY_ATSTOP 0x4
  464. /*
  465. * Important defines for the Stallion boards. They are pretty simple,
  466. * there is not much that is programmably configurable.
  467. */
  468. #define STAL_IOSIZE 16
  469. #define STAL_MEMSIZE (64 * 1024)
  470. #define STAL_PAGESIZE (64 * 1024)
  471. /*
  472. * Define the set of status register values for EasyConnection panels.
  473. * The signature will return with the status value for each panel. From
  474. * this we can determine what is attached to the board - before we have
  475. * actually down loaded any code to it.
  476. */
  477. #define ECH_PNLSTATUS 2
  478. #define ECH_PNL16PORT 0x20
  479. #define ECH_PNLIDMASK 0x07
  480. #define ECH_PNLXPID 0x40
  481. #define ECH_PNLINTRPEND 0x80
  482. /*
  483. * Define some macros to do things to the board. Even those these boards
  484. * are somewhat related there is often significantly different ways of
  485. * doing some operation on it (like enable, paging, reset, etc). So each
  486. * board class has a set of functions which do the commonly required
  487. * operations. The macros below basically just call these functions,
  488. * generally checking for a NULL function - which means that the board
  489. * needs nothing done to it to achieve this operation!
  490. */
  491. #define EBRDINIT(brdp) \
  492. if (brdp->init != NULL) \
  493. (* brdp->init)(brdp)
  494. #define EBRDENABLE(brdp) \
  495. if (brdp->enable != NULL) \
  496. (* brdp->enable)(brdp);
  497. #define EBRDDISABLE(brdp) \
  498. if (brdp->disable != NULL) \
  499. (* brdp->disable)(brdp);
  500. #define EBRDINTR(brdp) \
  501. if (brdp->intr != NULL) \
  502. (* brdp->intr)(brdp);
  503. #define EBRDRESET(brdp) \
  504. if (brdp->reset != NULL) \
  505. (* brdp->reset)(brdp);
  506. #define EBRDGETMEMPTR(brdp,offset) \
  507. (* brdp->getmemptr)(brdp, offset, __LINE__)
  508. /*
  509. * Define the maximal baud rate, and the default baud base for ports.
  510. */
  511. #define STL_MAXBAUD 460800
  512. #define STL_BAUDBASE 115200
  513. #define STL_CLOSEDELAY (5 * HZ / 10)
  514. /*****************************************************************************/
  515. /*
  516. * Define macros to extract a brd or port number from a minor number.
  517. */
  518. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  519. #define MINOR2PORT(min) ((min) & 0x3f)
  520. /*****************************************************************************/
  521. /*
  522. * Prototype all functions in this driver!
  523. */
  524. static int stli_parsebrd(struct stlconf *confp, char **argp);
  525. static int stli_open(struct tty_struct *tty, struct file *filp);
  526. static void stli_close(struct tty_struct *tty, struct file *filp);
  527. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
  528. static int stli_putchar(struct tty_struct *tty, unsigned char ch);
  529. static void stli_flushchars(struct tty_struct *tty);
  530. static int stli_writeroom(struct tty_struct *tty);
  531. static int stli_charsinbuffer(struct tty_struct *tty);
  532. static int stli_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
  533. static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
  534. static void stli_throttle(struct tty_struct *tty);
  535. static void stli_unthrottle(struct tty_struct *tty);
  536. static void stli_stop(struct tty_struct *tty);
  537. static void stli_start(struct tty_struct *tty);
  538. static void stli_flushbuffer(struct tty_struct *tty);
  539. static int stli_breakctl(struct tty_struct *tty, int state);
  540. static void stli_waituntilsent(struct tty_struct *tty, int timeout);
  541. static void stli_sendxchar(struct tty_struct *tty, char ch);
  542. static void stli_hangup(struct tty_struct *tty);
  543. static int stli_brdinit(struct stlibrd *brdp);
  544. static int stli_startbrd(struct stlibrd *brdp);
  545. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
  546. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
  547. static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg);
  548. static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
  549. static void stli_poll(unsigned long arg);
  550. static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
  551. static int stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp);
  552. static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
  553. static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
  554. static int stli_setport(struct tty_struct *tty);
  555. static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
  556. static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
  557. static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
  558. static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
  559. static void stli_mkasyport(struct tty_struct *tty, struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
  560. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
  561. static long stli_mktiocm(unsigned long sigvalue);
  562. static void stli_read(struct stlibrd *brdp, struct stliport *portp);
  563. static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
  564. static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *sp);
  565. static int stli_getbrdstats(combrd_t __user *bp);
  566. static int stli_getportstats(struct tty_struct *tty, struct stliport *portp, comstats_t __user *cp);
  567. static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp);
  568. static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
  569. static int stli_getportstruct(struct stliport __user *arg);
  570. static int stli_getbrdstruct(struct stlibrd __user *arg);
  571. static struct stlibrd *stli_allocbrd(void);
  572. static void stli_ecpinit(struct stlibrd *brdp);
  573. static void stli_ecpenable(struct stlibrd *brdp);
  574. static void stli_ecpdisable(struct stlibrd *brdp);
  575. static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  576. static void stli_ecpreset(struct stlibrd *brdp);
  577. static void stli_ecpintr(struct stlibrd *brdp);
  578. static void stli_ecpeiinit(struct stlibrd *brdp);
  579. static void stli_ecpeienable(struct stlibrd *brdp);
  580. static void stli_ecpeidisable(struct stlibrd *brdp);
  581. static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  582. static void stli_ecpeireset(struct stlibrd *brdp);
  583. static void stli_ecpmcenable(struct stlibrd *brdp);
  584. static void stli_ecpmcdisable(struct stlibrd *brdp);
  585. static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  586. static void stli_ecpmcreset(struct stlibrd *brdp);
  587. static void stli_ecppciinit(struct stlibrd *brdp);
  588. static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  589. static void stli_ecppcireset(struct stlibrd *brdp);
  590. static void stli_onbinit(struct stlibrd *brdp);
  591. static void stli_onbenable(struct stlibrd *brdp);
  592. static void stli_onbdisable(struct stlibrd *brdp);
  593. static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  594. static void stli_onbreset(struct stlibrd *brdp);
  595. static void stli_onbeinit(struct stlibrd *brdp);
  596. static void stli_onbeenable(struct stlibrd *brdp);
  597. static void stli_onbedisable(struct stlibrd *brdp);
  598. static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  599. static void stli_onbereset(struct stlibrd *brdp);
  600. static void stli_bbyinit(struct stlibrd *brdp);
  601. static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  602. static void stli_bbyreset(struct stlibrd *brdp);
  603. static void stli_stalinit(struct stlibrd *brdp);
  604. static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  605. static void stli_stalreset(struct stlibrd *brdp);
  606. static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
  607. static int stli_initecp(struct stlibrd *brdp);
  608. static int stli_initonb(struct stlibrd *brdp);
  609. #if STLI_EISAPROBE != 0
  610. static int stli_eisamemprobe(struct stlibrd *brdp);
  611. #endif
  612. static int stli_initports(struct stlibrd *brdp);
  613. /*****************************************************************************/
  614. /*
  615. * Define the driver info for a user level shared memory device. This
  616. * device will work sort of like the /dev/kmem device - except that it
  617. * will give access to the shared memory on the Stallion intelligent
  618. * board. This is also a very useful debugging tool.
  619. */
  620. static const struct file_operations stli_fsiomem = {
  621. .owner = THIS_MODULE,
  622. .read = stli_memread,
  623. .write = stli_memwrite,
  624. .unlocked_ioctl = stli_memioctl,
  625. .llseek = default_llseek,
  626. };
  627. /*****************************************************************************/
  628. /*
  629. * Define a timer_list entry for our poll routine. The slave board
  630. * is polled every so often to see if anything needs doing. This is
  631. * much cheaper on host cpu than using interrupts. It turns out to
  632. * not increase character latency by much either...
  633. */
  634. static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
  635. static int stli_timeron;
  636. /*
  637. * Define the calculation for the timeout routine.
  638. */
  639. #define STLI_TIMEOUT (jiffies + 1)
  640. /*****************************************************************************/
  641. static struct class *istallion_class;
  642. static void stli_cleanup_ports(struct stlibrd *brdp)
  643. {
  644. struct stliport *portp;
  645. unsigned int j;
  646. struct tty_struct *tty;
  647. for (j = 0; j < STL_MAXPORTS; j++) {
  648. portp = brdp->ports[j];
  649. if (portp != NULL) {
  650. tty = tty_port_tty_get(&portp->port);
  651. if (tty != NULL) {
  652. tty_hangup(tty);
  653. tty_kref_put(tty);
  654. }
  655. kfree(portp);
  656. }
  657. }
  658. }
  659. /*****************************************************************************/
  660. /*
  661. * Parse the supplied argument string, into the board conf struct.
  662. */
  663. static int stli_parsebrd(struct stlconf *confp, char **argp)
  664. {
  665. unsigned int i;
  666. char *sp;
  667. if (argp[0] == NULL || *argp[0] == 0)
  668. return 0;
  669. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  670. *sp = tolower(*sp);
  671. for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
  672. if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
  673. break;
  674. }
  675. if (i == ARRAY_SIZE(stli_brdstr)) {
  676. printk(KERN_WARNING "istallion: unknown board name, %s?\n", argp[0]);
  677. return 0;
  678. }
  679. confp->brdtype = stli_brdstr[i].type;
  680. if (argp[1] != NULL && *argp[1] != 0)
  681. confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
  682. if (argp[2] != NULL && *argp[2] != 0)
  683. confp->memaddr = simple_strtoul(argp[2], NULL, 0);
  684. return(1);
  685. }
  686. /*****************************************************************************/
  687. /*
  688. * On the first open of the device setup the port hardware, and
  689. * initialize the per port data structure. Since initializing the port
  690. * requires several commands to the board we will need to wait for any
  691. * other open that is already initializing the port.
  692. *
  693. * Locking: protected by the port mutex.
  694. */
  695. static int stli_activate(struct tty_port *port, struct tty_struct *tty)
  696. {
  697. struct stliport *portp = container_of(port, struct stliport, port);
  698. struct stlibrd *brdp = stli_brds[portp->brdnr];
  699. int rc;
  700. if ((rc = stli_initopen(tty, brdp, portp)) >= 0)
  701. clear_bit(TTY_IO_ERROR, &tty->flags);
  702. wake_up_interruptible(&portp->raw_wait);
  703. return rc;
  704. }
  705. static int stli_open(struct tty_struct *tty, struct file *filp)
  706. {
  707. struct stlibrd *brdp;
  708. struct stliport *portp;
  709. unsigned int minordev, brdnr, portnr;
  710. minordev = tty->index;
  711. brdnr = MINOR2BRD(minordev);
  712. if (brdnr >= stli_nrbrds)
  713. return -ENODEV;
  714. brdp = stli_brds[brdnr];
  715. if (brdp == NULL)
  716. return -ENODEV;
  717. if (!test_bit(BST_STARTED, &brdp->state))
  718. return -ENODEV;
  719. portnr = MINOR2PORT(minordev);
  720. if (portnr > brdp->nrports)
  721. return -ENODEV;
  722. portp = brdp->ports[portnr];
  723. if (portp == NULL)
  724. return -ENODEV;
  725. if (portp->devnr < 1)
  726. return -ENODEV;
  727. tty->driver_data = portp;
  728. return tty_port_open(&portp->port, tty, filp);
  729. }
  730. /*****************************************************************************/
  731. static void stli_shutdown(struct tty_port *port)
  732. {
  733. struct stlibrd *brdp;
  734. unsigned long ftype;
  735. unsigned long flags;
  736. struct stliport *portp = container_of(port, struct stliport, port);
  737. if (portp->brdnr >= stli_nrbrds)
  738. return;
  739. brdp = stli_brds[portp->brdnr];
  740. if (brdp == NULL)
  741. return;
  742. /*
  743. * May want to wait for data to drain before closing. The BUSY
  744. * flag keeps track of whether we are still transmitting or not.
  745. * It is updated by messages from the slave - indicating when all
  746. * chars really have drained.
  747. */
  748. if (!test_bit(ST_CLOSING, &portp->state))
  749. stli_rawclose(brdp, portp, 0, 0);
  750. spin_lock_irqsave(&stli_lock, flags);
  751. clear_bit(ST_TXBUSY, &portp->state);
  752. clear_bit(ST_RXSTOP, &portp->state);
  753. spin_unlock_irqrestore(&stli_lock, flags);
  754. ftype = FLUSHTX | FLUSHRX;
  755. stli_cmdwait(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
  756. }
  757. static void stli_close(struct tty_struct *tty, struct file *filp)
  758. {
  759. struct stliport *portp = tty->driver_data;
  760. unsigned long flags;
  761. if (portp == NULL)
  762. return;
  763. spin_lock_irqsave(&stli_lock, flags);
  764. /* Flush any internal buffering out first */
  765. if (tty == stli_txcooktty)
  766. stli_flushchars(tty);
  767. spin_unlock_irqrestore(&stli_lock, flags);
  768. tty_port_close(&portp->port, tty, filp);
  769. }
  770. /*****************************************************************************/
  771. /*
  772. * Carry out first open operations on a port. This involves a number of
  773. * commands to be sent to the slave. We need to open the port, set the
  774. * notification events, set the initial port settings, get and set the
  775. * initial signal values. We sleep and wait in between each one. But
  776. * this still all happens pretty quickly.
  777. */
  778. static int stli_initopen(struct tty_struct *tty,
  779. struct stlibrd *brdp, struct stliport *portp)
  780. {
  781. asynotify_t nt;
  782. asyport_t aport;
  783. int rc;
  784. if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
  785. return rc;
  786. memset(&nt, 0, sizeof(asynotify_t));
  787. nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
  788. nt.signal = SG_DCD;
  789. if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
  790. sizeof(asynotify_t), 0)) < 0)
  791. return rc;
  792. stli_mkasyport(tty, portp, &aport, tty->termios);
  793. if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
  794. sizeof(asyport_t), 0)) < 0)
  795. return rc;
  796. set_bit(ST_GETSIGS, &portp->state);
  797. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
  798. sizeof(asysigs_t), 1)) < 0)
  799. return rc;
  800. if (test_and_clear_bit(ST_GETSIGS, &portp->state))
  801. portp->sigs = stli_mktiocm(portp->asig.sigvalue);
  802. stli_mkasysigs(&portp->asig, 1, 1);
  803. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  804. sizeof(asysigs_t), 0)) < 0)
  805. return rc;
  806. return 0;
  807. }
  808. /*****************************************************************************/
  809. /*
  810. * Send an open message to the slave. This will sleep waiting for the
  811. * acknowledgement, so must have user context. We need to co-ordinate
  812. * with close events here, since we don't want open and close events
  813. * to overlap.
  814. */
  815. static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
  816. {
  817. cdkhdr_t __iomem *hdrp;
  818. cdkctrl_t __iomem *cp;
  819. unsigned char __iomem *bits;
  820. unsigned long flags;
  821. int rc;
  822. /*
  823. * Send a message to the slave to open this port.
  824. */
  825. /*
  826. * Slave is already closing this port. This can happen if a hangup
  827. * occurs on this port. So we must wait until it is complete. The
  828. * order of opens and closes may not be preserved across shared
  829. * memory, so we must wait until it is complete.
  830. */
  831. wait_event_interruptible_tty(portp->raw_wait,
  832. !test_bit(ST_CLOSING, &portp->state));
  833. if (signal_pending(current)) {
  834. return -ERESTARTSYS;
  835. }
  836. /*
  837. * Everything is ready now, so write the open message into shared
  838. * memory. Once the message is in set the service bits to say that
  839. * this port wants service.
  840. */
  841. spin_lock_irqsave(&brd_lock, flags);
  842. EBRDENABLE(brdp);
  843. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  844. writel(arg, &cp->openarg);
  845. writeb(1, &cp->open);
  846. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  847. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  848. portp->portidx;
  849. writeb(readb(bits) | portp->portbit, bits);
  850. EBRDDISABLE(brdp);
  851. if (wait == 0) {
  852. spin_unlock_irqrestore(&brd_lock, flags);
  853. return 0;
  854. }
  855. /*
  856. * Slave is in action, so now we must wait for the open acknowledgment
  857. * to come back.
  858. */
  859. rc = 0;
  860. set_bit(ST_OPENING, &portp->state);
  861. spin_unlock_irqrestore(&brd_lock, flags);
  862. wait_event_interruptible_tty(portp->raw_wait,
  863. !test_bit(ST_OPENING, &portp->state));
  864. if (signal_pending(current))
  865. rc = -ERESTARTSYS;
  866. if ((rc == 0) && (portp->rc != 0))
  867. rc = -EIO;
  868. return rc;
  869. }
  870. /*****************************************************************************/
  871. /*
  872. * Send a close message to the slave. Normally this will sleep waiting
  873. * for the acknowledgement, but if wait parameter is 0 it will not. If
  874. * wait is true then must have user context (to sleep).
  875. */
  876. static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
  877. {
  878. cdkhdr_t __iomem *hdrp;
  879. cdkctrl_t __iomem *cp;
  880. unsigned char __iomem *bits;
  881. unsigned long flags;
  882. int rc;
  883. /*
  884. * Slave is already closing this port. This can happen if a hangup
  885. * occurs on this port.
  886. */
  887. if (wait) {
  888. wait_event_interruptible_tty(portp->raw_wait,
  889. !test_bit(ST_CLOSING, &portp->state));
  890. if (signal_pending(current)) {
  891. return -ERESTARTSYS;
  892. }
  893. }
  894. /*
  895. * Write the close command into shared memory.
  896. */
  897. spin_lock_irqsave(&brd_lock, flags);
  898. EBRDENABLE(brdp);
  899. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  900. writel(arg, &cp->closearg);
  901. writeb(1, &cp->close);
  902. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  903. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  904. portp->portidx;
  905. writeb(readb(bits) |portp->portbit, bits);
  906. EBRDDISABLE(brdp);
  907. set_bit(ST_CLOSING, &portp->state);
  908. spin_unlock_irqrestore(&brd_lock, flags);
  909. if (wait == 0)
  910. return 0;
  911. /*
  912. * Slave is in action, so now we must wait for the open acknowledgment
  913. * to come back.
  914. */
  915. rc = 0;
  916. wait_event_interruptible_tty(portp->raw_wait,
  917. !test_bit(ST_CLOSING, &portp->state));
  918. if (signal_pending(current))
  919. rc = -ERESTARTSYS;
  920. if ((rc == 0) && (portp->rc != 0))
  921. rc = -EIO;
  922. return rc;
  923. }
  924. /*****************************************************************************/
  925. /*
  926. * Send a command to the slave and wait for the response. This must
  927. * have user context (it sleeps). This routine is generic in that it
  928. * can send any type of command. Its purpose is to wait for that command
  929. * to complete (as opposed to initiating the command then returning).
  930. */
  931. static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
  932. {
  933. /*
  934. * no need for wait_event_tty because clearing ST_CMDING cannot block
  935. * on BTM
  936. */
  937. wait_event_interruptible(portp->raw_wait,
  938. !test_bit(ST_CMDING, &portp->state));
  939. if (signal_pending(current))
  940. return -ERESTARTSYS;
  941. stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  942. wait_event_interruptible(portp->raw_wait,
  943. !test_bit(ST_CMDING, &portp->state));
  944. if (signal_pending(current))
  945. return -ERESTARTSYS;
  946. if (portp->rc != 0)
  947. return -EIO;
  948. return 0;
  949. }
  950. /*****************************************************************************/
  951. /*
  952. * Send the termios settings for this port to the slave. This sleeps
  953. * waiting for the command to complete - so must have user context.
  954. */
  955. static int stli_setport(struct tty_struct *tty)
  956. {
  957. struct stliport *portp = tty->driver_data;
  958. struct stlibrd *brdp;
  959. asyport_t aport;
  960. if (portp == NULL)
  961. return -ENODEV;
  962. if (portp->brdnr >= stli_nrbrds)
  963. return -ENODEV;
  964. brdp = stli_brds[portp->brdnr];
  965. if (brdp == NULL)
  966. return -ENODEV;
  967. stli_mkasyport(tty, portp, &aport, tty->termios);
  968. return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
  969. }
  970. /*****************************************************************************/
  971. static int stli_carrier_raised(struct tty_port *port)
  972. {
  973. struct stliport *portp = container_of(port, struct stliport, port);
  974. return (portp->sigs & TIOCM_CD) ? 1 : 0;
  975. }
  976. static void stli_dtr_rts(struct tty_port *port, int on)
  977. {
  978. struct stliport *portp = container_of(port, struct stliport, port);
  979. struct stlibrd *brdp = stli_brds[portp->brdnr];
  980. stli_mkasysigs(&portp->asig, on, on);
  981. if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  982. sizeof(asysigs_t), 0) < 0)
  983. printk(KERN_WARNING "istallion: dtr set failed.\n");
  984. }
  985. /*****************************************************************************/
  986. /*
  987. * Write routine. Take the data and put it in the shared memory ring
  988. * queue. If port is not already sending chars then need to mark the
  989. * service bits for this port.
  990. */
  991. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
  992. {
  993. cdkasy_t __iomem *ap;
  994. cdkhdr_t __iomem *hdrp;
  995. unsigned char __iomem *bits;
  996. unsigned char __iomem *shbuf;
  997. unsigned char *chbuf;
  998. struct stliport *portp;
  999. struct stlibrd *brdp;
  1000. unsigned int len, stlen, head, tail, size;
  1001. unsigned long flags;
  1002. if (tty == stli_txcooktty)
  1003. stli_flushchars(tty);
  1004. portp = tty->driver_data;
  1005. if (portp == NULL)
  1006. return 0;
  1007. if (portp->brdnr >= stli_nrbrds)
  1008. return 0;
  1009. brdp = stli_brds[portp->brdnr];
  1010. if (brdp == NULL)
  1011. return 0;
  1012. chbuf = (unsigned char *) buf;
  1013. /*
  1014. * All data is now local, shove as much as possible into shared memory.
  1015. */
  1016. spin_lock_irqsave(&brd_lock, flags);
  1017. EBRDENABLE(brdp);
  1018. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1019. head = (unsigned int) readw(&ap->txq.head);
  1020. tail = (unsigned int) readw(&ap->txq.tail);
  1021. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1022. tail = (unsigned int) readw(&ap->txq.tail);
  1023. size = portp->txsize;
  1024. if (head >= tail) {
  1025. len = size - (head - tail) - 1;
  1026. stlen = size - head;
  1027. } else {
  1028. len = tail - head - 1;
  1029. stlen = len;
  1030. }
  1031. len = min(len, (unsigned int)count);
  1032. count = 0;
  1033. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1034. while (len > 0) {
  1035. stlen = min(len, stlen);
  1036. memcpy_toio(shbuf + head, chbuf, stlen);
  1037. chbuf += stlen;
  1038. len -= stlen;
  1039. count += stlen;
  1040. head += stlen;
  1041. if (head >= size) {
  1042. head = 0;
  1043. stlen = tail;
  1044. }
  1045. }
  1046. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1047. writew(head, &ap->txq.head);
  1048. if (test_bit(ST_TXBUSY, &portp->state)) {
  1049. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1050. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1051. }
  1052. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1053. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1054. portp->portidx;
  1055. writeb(readb(bits) | portp->portbit, bits);
  1056. set_bit(ST_TXBUSY, &portp->state);
  1057. EBRDDISABLE(brdp);
  1058. spin_unlock_irqrestore(&brd_lock, flags);
  1059. return(count);
  1060. }
  1061. /*****************************************************************************/
  1062. /*
  1063. * Output a single character. We put it into a temporary local buffer
  1064. * (for speed) then write out that buffer when the flushchars routine
  1065. * is called. There is a safety catch here so that if some other port
  1066. * writes chars before the current buffer has been, then we write them
  1067. * first them do the new ports.
  1068. */
  1069. static int stli_putchar(struct tty_struct *tty, unsigned char ch)
  1070. {
  1071. if (tty != stli_txcooktty) {
  1072. if (stli_txcooktty != NULL)
  1073. stli_flushchars(stli_txcooktty);
  1074. stli_txcooktty = tty;
  1075. }
  1076. stli_txcookbuf[stli_txcooksize++] = ch;
  1077. return 0;
  1078. }
  1079. /*****************************************************************************/
  1080. /*
  1081. * Transfer characters from the local TX cooking buffer to the board.
  1082. * We sort of ignore the tty that gets passed in here. We rely on the
  1083. * info stored with the TX cook buffer to tell us which port to flush
  1084. * the data on. In any case we clean out the TX cook buffer, for re-use
  1085. * by someone else.
  1086. */
  1087. static void stli_flushchars(struct tty_struct *tty)
  1088. {
  1089. cdkhdr_t __iomem *hdrp;
  1090. unsigned char __iomem *bits;
  1091. cdkasy_t __iomem *ap;
  1092. struct tty_struct *cooktty;
  1093. struct stliport *portp;
  1094. struct stlibrd *brdp;
  1095. unsigned int len, stlen, head, tail, size, count, cooksize;
  1096. unsigned char *buf;
  1097. unsigned char __iomem *shbuf;
  1098. unsigned long flags;
  1099. cooksize = stli_txcooksize;
  1100. cooktty = stli_txcooktty;
  1101. stli_txcooksize = 0;
  1102. stli_txcookrealsize = 0;
  1103. stli_txcooktty = NULL;
  1104. if (cooktty == NULL)
  1105. return;
  1106. if (tty != cooktty)
  1107. tty = cooktty;
  1108. if (cooksize == 0)
  1109. return;
  1110. portp = tty->driver_data;
  1111. if (portp == NULL)
  1112. return;
  1113. if (portp->brdnr >= stli_nrbrds)
  1114. return;
  1115. brdp = stli_brds[portp->brdnr];
  1116. if (brdp == NULL)
  1117. return;
  1118. spin_lock_irqsave(&brd_lock, flags);
  1119. EBRDENABLE(brdp);
  1120. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1121. head = (unsigned int) readw(&ap->txq.head);
  1122. tail = (unsigned int) readw(&ap->txq.tail);
  1123. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1124. tail = (unsigned int) readw(&ap->txq.tail);
  1125. size = portp->txsize;
  1126. if (head >= tail) {
  1127. len = size - (head - tail) - 1;
  1128. stlen = size - head;
  1129. } else {
  1130. len = tail - head - 1;
  1131. stlen = len;
  1132. }
  1133. len = min(len, cooksize);
  1134. count = 0;
  1135. shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
  1136. buf = stli_txcookbuf;
  1137. while (len > 0) {
  1138. stlen = min(len, stlen);
  1139. memcpy_toio(shbuf + head, buf, stlen);
  1140. buf += stlen;
  1141. len -= stlen;
  1142. count += stlen;
  1143. head += stlen;
  1144. if (head >= size) {
  1145. head = 0;
  1146. stlen = tail;
  1147. }
  1148. }
  1149. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1150. writew(head, &ap->txq.head);
  1151. if (test_bit(ST_TXBUSY, &portp->state)) {
  1152. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1153. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1154. }
  1155. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1156. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1157. portp->portidx;
  1158. writeb(readb(bits) | portp->portbit, bits);
  1159. set_bit(ST_TXBUSY, &portp->state);
  1160. EBRDDISABLE(brdp);
  1161. spin_unlock_irqrestore(&brd_lock, flags);
  1162. }
  1163. /*****************************************************************************/
  1164. static int stli_writeroom(struct tty_struct *tty)
  1165. {
  1166. cdkasyrq_t __iomem *rp;
  1167. struct stliport *portp;
  1168. struct stlibrd *brdp;
  1169. unsigned int head, tail, len;
  1170. unsigned long flags;
  1171. if (tty == stli_txcooktty) {
  1172. if (stli_txcookrealsize != 0) {
  1173. len = stli_txcookrealsize - stli_txcooksize;
  1174. return len;
  1175. }
  1176. }
  1177. portp = tty->driver_data;
  1178. if (portp == NULL)
  1179. return 0;
  1180. if (portp->brdnr >= stli_nrbrds)
  1181. return 0;
  1182. brdp = stli_brds[portp->brdnr];
  1183. if (brdp == NULL)
  1184. return 0;
  1185. spin_lock_irqsave(&brd_lock, flags);
  1186. EBRDENABLE(brdp);
  1187. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1188. head = (unsigned int) readw(&rp->head);
  1189. tail = (unsigned int) readw(&rp->tail);
  1190. if (tail != ((unsigned int) readw(&rp->tail)))
  1191. tail = (unsigned int) readw(&rp->tail);
  1192. len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
  1193. len--;
  1194. EBRDDISABLE(brdp);
  1195. spin_unlock_irqrestore(&brd_lock, flags);
  1196. if (tty == stli_txcooktty) {
  1197. stli_txcookrealsize = len;
  1198. len -= stli_txcooksize;
  1199. }
  1200. return len;
  1201. }
  1202. /*****************************************************************************/
  1203. /*
  1204. * Return the number of characters in the transmit buffer. Normally we
  1205. * will return the number of chars in the shared memory ring queue.
  1206. * We need to kludge around the case where the shared memory buffer is
  1207. * empty but not all characters have drained yet, for this case just
  1208. * return that there is 1 character in the buffer!
  1209. */
  1210. static int stli_charsinbuffer(struct tty_struct *tty)
  1211. {
  1212. cdkasyrq_t __iomem *rp;
  1213. struct stliport *portp;
  1214. struct stlibrd *brdp;
  1215. unsigned int head, tail, len;
  1216. unsigned long flags;
  1217. if (tty == stli_txcooktty)
  1218. stli_flushchars(tty);
  1219. portp = tty->driver_data;
  1220. if (portp == NULL)
  1221. return 0;
  1222. if (portp->brdnr >= stli_nrbrds)
  1223. return 0;
  1224. brdp = stli_brds[portp->brdnr];
  1225. if (brdp == NULL)
  1226. return 0;
  1227. spin_lock_irqsave(&brd_lock, flags);
  1228. EBRDENABLE(brdp);
  1229. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1230. head = (unsigned int) readw(&rp->head);
  1231. tail = (unsigned int) readw(&rp->tail);
  1232. if (tail != ((unsigned int) readw(&rp->tail)))
  1233. tail = (unsigned int) readw(&rp->tail);
  1234. len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
  1235. if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
  1236. len = 1;
  1237. EBRDDISABLE(brdp);
  1238. spin_unlock_irqrestore(&brd_lock, flags);
  1239. return len;
  1240. }
  1241. /*****************************************************************************/
  1242. /*
  1243. * Generate the serial struct info.
  1244. */
  1245. static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
  1246. {
  1247. struct serial_struct sio;
  1248. struct stlibrd *brdp;
  1249. memset(&sio, 0, sizeof(struct serial_struct));
  1250. sio.type = PORT_UNKNOWN;
  1251. sio.line = portp->portnr;
  1252. sio.irq = 0;
  1253. sio.flags = portp->port.flags;
  1254. sio.baud_base = portp->baud_base;
  1255. sio.close_delay = portp->port.close_delay;
  1256. sio.closing_wait = portp->closing_wait;
  1257. sio.custom_divisor = portp->custom_divisor;
  1258. sio.xmit_fifo_size = 0;
  1259. sio.hub6 = 0;
  1260. brdp = stli_brds[portp->brdnr];
  1261. if (brdp != NULL)
  1262. sio.port = brdp->iobase;
  1263. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
  1264. -EFAULT : 0;
  1265. }
  1266. /*****************************************************************************/
  1267. /*
  1268. * Set port according to the serial struct info.
  1269. * At this point we do not do any auto-configure stuff, so we will
  1270. * just quietly ignore any requests to change irq, etc.
  1271. */
  1272. static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
  1273. {
  1274. struct serial_struct sio;
  1275. int rc;
  1276. struct stliport *portp = tty->driver_data;
  1277. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1278. return -EFAULT;
  1279. if (!capable(CAP_SYS_ADMIN)) {
  1280. if ((sio.baud_base != portp->baud_base) ||
  1281. (sio.close_delay != portp->port.close_delay) ||
  1282. ((sio.flags & ~ASYNC_USR_MASK) !=
  1283. (portp->port.flags & ~ASYNC_USR_MASK)))
  1284. return -EPERM;
  1285. }
  1286. portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
  1287. (sio.flags & ASYNC_USR_MASK);
  1288. portp->baud_base = sio.baud_base;
  1289. portp->port.close_delay = sio.close_delay;
  1290. portp->closing_wait = sio.closing_wait;
  1291. portp->custom_divisor = sio.custom_divisor;
  1292. if ((rc = stli_setport(tty)) < 0)
  1293. return rc;
  1294. return 0;
  1295. }
  1296. /*****************************************************************************/
  1297. static int stli_tiocmget(struct tty_struct *tty)
  1298. {
  1299. struct stliport *portp = tty->driver_data;
  1300. struct stlibrd *brdp;
  1301. int rc;
  1302. if (portp == NULL)
  1303. return -ENODEV;
  1304. if (portp->brdnr >= stli_nrbrds)
  1305. return 0;
  1306. brdp = stli_brds[portp->brdnr];
  1307. if (brdp == NULL)
  1308. return 0;
  1309. if (tty->flags & (1 << TTY_IO_ERROR))
  1310. return -EIO;
  1311. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
  1312. &portp->asig, sizeof(asysigs_t), 1)) < 0)
  1313. return rc;
  1314. return stli_mktiocm(portp->asig.sigvalue);
  1315. }
  1316. static int stli_tiocmset(struct tty_struct *tty,
  1317. unsigned int set, unsigned int clear)
  1318. {
  1319. struct stliport *portp = tty->driver_data;
  1320. struct stlibrd *brdp;
  1321. int rts = -1, dtr = -1;
  1322. if (portp == NULL)
  1323. return -ENODEV;
  1324. if (portp->brdnr >= stli_nrbrds)
  1325. return 0;
  1326. brdp = stli_brds[portp->brdnr];
  1327. if (brdp == NULL)
  1328. return 0;
  1329. if (tty->flags & (1 << TTY_IO_ERROR))
  1330. return -EIO;
  1331. if (set & TIOCM_RTS)
  1332. rts = 1;
  1333. if (set & TIOCM_DTR)
  1334. dtr = 1;
  1335. if (clear & TIOCM_RTS)
  1336. rts = 0;
  1337. if (clear & TIOCM_DTR)
  1338. dtr = 0;
  1339. stli_mkasysigs(&portp->asig, dtr, rts);
  1340. return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1341. sizeof(asysigs_t), 0);
  1342. }
  1343. static int stli_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
  1344. {
  1345. struct stliport *portp;
  1346. struct stlibrd *brdp;
  1347. int rc;
  1348. void __user *argp = (void __user *)arg;
  1349. portp = tty->driver_data;
  1350. if (portp == NULL)
  1351. return -ENODEV;
  1352. if (portp->brdnr >= stli_nrbrds)
  1353. return 0;
  1354. brdp = stli_brds[portp->brdnr];
  1355. if (brdp == NULL)
  1356. return 0;
  1357. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1358. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1359. if (tty->flags & (1 << TTY_IO_ERROR))
  1360. return -EIO;
  1361. }
  1362. rc = 0;
  1363. switch (cmd) {
  1364. case TIOCGSERIAL:
  1365. rc = stli_getserial(portp, argp);
  1366. break;
  1367. case TIOCSSERIAL:
  1368. rc = stli_setserial(tty, argp);
  1369. break;
  1370. case STL_GETPFLAG:
  1371. rc = put_user(portp->pflag, (unsigned __user *)argp);
  1372. break;
  1373. case STL_SETPFLAG:
  1374. if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
  1375. stli_setport(tty);
  1376. break;
  1377. case COM_GETPORTSTATS:
  1378. rc = stli_getportstats(tty, portp, argp);
  1379. break;
  1380. case COM_CLRPORTSTATS:
  1381. rc = stli_clrportstats(portp, argp);
  1382. break;
  1383. case TIOCSERCONFIG:
  1384. case TIOCSERGWILD:
  1385. case TIOCSERSWILD:
  1386. case TIOCSERGETLSR:
  1387. case TIOCSERGSTRUCT:
  1388. case TIOCSERGETMULTI:
  1389. case TIOCSERSETMULTI:
  1390. default:
  1391. rc = -ENOIOCTLCMD;
  1392. break;
  1393. }
  1394. return rc;
  1395. }
  1396. /*****************************************************************************/
  1397. /*
  1398. * This routine assumes that we have user context and can sleep.
  1399. * Looks like it is true for the current ttys implementation..!!
  1400. */
  1401. static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
  1402. {
  1403. struct stliport *portp;
  1404. struct stlibrd *brdp;
  1405. struct ktermios *tiosp;
  1406. asyport_t aport;
  1407. portp = tty->driver_data;
  1408. if (portp == NULL)
  1409. return;
  1410. if (portp->brdnr >= stli_nrbrds)
  1411. return;
  1412. brdp = stli_brds[portp->brdnr];
  1413. if (brdp == NULL)
  1414. return;
  1415. tiosp = tty->termios;
  1416. stli_mkasyport(tty, portp, &aport, tiosp);
  1417. stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
  1418. stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
  1419. stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1420. sizeof(asysigs_t), 0);
  1421. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
  1422. tty->hw_stopped = 0;
  1423. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1424. wake_up_interruptible(&portp->port.open_wait);
  1425. }
  1426. /*****************************************************************************/
  1427. /*
  1428. * Attempt to flow control who ever is sending us data. We won't really
  1429. * do any flow control action here. We can't directly, and even if we
  1430. * wanted to we would have to send a command to the slave. The slave
  1431. * knows how to flow control, and will do so when its buffers reach its
  1432. * internal high water marks. So what we will do is set a local state
  1433. * bit that will stop us sending any RX data up from the poll routine
  1434. * (which is the place where RX data from the slave is handled).
  1435. */
  1436. static void stli_throttle(struct tty_struct *tty)
  1437. {
  1438. struct stliport *portp = tty->driver_data;
  1439. if (portp == NULL)
  1440. return;
  1441. set_bit(ST_RXSTOP, &portp->state);
  1442. }
  1443. /*****************************************************************************/
  1444. /*
  1445. * Unflow control the device sending us data... That means that all
  1446. * we have to do is clear the RXSTOP state bit. The next poll call
  1447. * will then be able to pass the RX data back up.
  1448. */
  1449. static void stli_unthrottle(struct tty_struct *tty)
  1450. {
  1451. struct stliport *portp = tty->driver_data;
  1452. if (portp == NULL)
  1453. return;
  1454. clear_bit(ST_RXSTOP, &portp->state);
  1455. }
  1456. /*****************************************************************************/
  1457. /*
  1458. * Stop the transmitter.
  1459. */
  1460. static void stli_stop(struct tty_struct *tty)
  1461. {
  1462. }
  1463. /*****************************************************************************/
  1464. /*
  1465. * Start the transmitter again.
  1466. */
  1467. static void stli_start(struct tty_struct *tty)
  1468. {
  1469. }
  1470. /*****************************************************************************/
  1471. /*
  1472. * Hangup this port. This is pretty much like closing the port, only
  1473. * a little more brutal. No waiting for data to drain. Shutdown the
  1474. * port and maybe drop signals. This is rather tricky really. We want
  1475. * to close the port as well.
  1476. */
  1477. static void stli_hangup(struct tty_struct *tty)
  1478. {
  1479. struct stliport *portp = tty->driver_data;
  1480. tty_port_hangup(&portp->port);
  1481. }
  1482. /*****************************************************************************/
  1483. /*
  1484. * Flush characters from the lower buffer. We may not have user context
  1485. * so we cannot sleep waiting for it to complete. Also we need to check
  1486. * if there is chars for this port in the TX cook buffer, and flush them
  1487. * as well.
  1488. */
  1489. static void stli_flushbuffer(struct tty_struct *tty)
  1490. {
  1491. struct stliport *portp;
  1492. struct stlibrd *brdp;
  1493. unsigned long ftype, flags;
  1494. portp = tty->driver_data;
  1495. if (portp == NULL)
  1496. return;
  1497. if (portp->brdnr >= stli_nrbrds)
  1498. return;
  1499. brdp = stli_brds[portp->brdnr];
  1500. if (brdp == NULL)
  1501. return;
  1502. spin_lock_irqsave(&brd_lock, flags);
  1503. if (tty == stli_txcooktty) {
  1504. stli_txcooktty = NULL;
  1505. stli_txcooksize = 0;
  1506. stli_txcookrealsize = 0;
  1507. }
  1508. if (test_bit(ST_CMDING, &portp->state)) {
  1509. set_bit(ST_DOFLUSHTX, &portp->state);
  1510. } else {
  1511. ftype = FLUSHTX;
  1512. if (test_bit(ST_DOFLUSHRX, &portp->state)) {
  1513. ftype |= FLUSHRX;
  1514. clear_bit(ST_DOFLUSHRX, &portp->state);
  1515. }
  1516. __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
  1517. }
  1518. spin_unlock_irqrestore(&brd_lock, flags);
  1519. tty_wakeup(tty);
  1520. }
  1521. /*****************************************************************************/
  1522. static int stli_breakctl(struct tty_struct *tty, int state)
  1523. {
  1524. struct stlibrd *brdp;
  1525. struct stliport *portp;
  1526. long arg;
  1527. portp = tty->driver_data;
  1528. if (portp == NULL)
  1529. return -EINVAL;
  1530. if (portp->brdnr >= stli_nrbrds)
  1531. return -EINVAL;
  1532. brdp = stli_brds[portp->brdnr];
  1533. if (brdp == NULL)
  1534. return -EINVAL;
  1535. arg = (state == -1) ? BREAKON : BREAKOFF;
  1536. stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
  1537. return 0;
  1538. }
  1539. /*****************************************************************************/
  1540. static void stli_waituntilsent(struct tty_struct *tty, int timeout)
  1541. {
  1542. struct stliport *portp;
  1543. unsigned long tend;
  1544. portp = tty->driver_data;
  1545. if (portp == NULL)
  1546. return;
  1547. if (timeout == 0)
  1548. timeout = HZ;
  1549. tend = jiffies + timeout;
  1550. while (test_bit(ST_TXBUSY, &portp->state)) {
  1551. if (signal_pending(current))
  1552. break;
  1553. msleep_interruptible(20);
  1554. if (time_after_eq(jiffies, tend))
  1555. break;
  1556. }
  1557. }
  1558. /*****************************************************************************/
  1559. static void stli_sendxchar(struct tty_struct *tty, char ch)
  1560. {
  1561. struct stlibrd *brdp;
  1562. struct stliport *portp;
  1563. asyctrl_t actrl;
  1564. portp = tty->driver_data;
  1565. if (portp == NULL)
  1566. return;
  1567. if (portp->brdnr >= stli_nrbrds)
  1568. return;
  1569. brdp = stli_brds[portp->brdnr];
  1570. if (brdp == NULL)
  1571. return;
  1572. memset(&actrl, 0, sizeof(asyctrl_t));
  1573. if (ch == STOP_CHAR(tty)) {
  1574. actrl.rxctrl = CT_STOPFLOW;
  1575. } else if (ch == START_CHAR(tty)) {
  1576. actrl.rxctrl = CT_STARTFLOW;
  1577. } else {
  1578. actrl.txctrl = CT_SENDCHR;
  1579. actrl.tximdch = ch;
  1580. }
  1581. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1582. }
  1583. static void stli_portinfo(struct seq_file *m, struct stlibrd *brdp, struct stliport *portp, int portnr)
  1584. {
  1585. char *uart;
  1586. int rc;
  1587. rc = stli_portcmdstats(NULL, portp);
  1588. uart = "UNKNOWN";
  1589. if (test_bit(BST_STARTED, &brdp->state)) {
  1590. switch (stli_comstats.hwid) {
  1591. case 0: uart = "2681"; break;
  1592. case 1: uart = "SC26198"; break;
  1593. default:uart = "CD1400"; break;
  1594. }
  1595. }
  1596. seq_printf(m, "%d: uart:%s ", portnr, uart);
  1597. if (test_bit(BST_STARTED, &brdp->state) && rc >= 0) {
  1598. char sep;
  1599. seq_printf(m, "tx:%d rx:%d", (int) stli_comstats.txtotal,
  1600. (int) stli_comstats.rxtotal);
  1601. if (stli_comstats.rxframing)
  1602. seq_printf(m, " fe:%d",
  1603. (int) stli_comstats.rxframing);
  1604. if (stli_comstats.rxparity)
  1605. seq_printf(m, " pe:%d",
  1606. (int) stli_comstats.rxparity);
  1607. if (stli_comstats.rxbreaks)
  1608. seq_printf(m, " brk:%d",
  1609. (int) stli_comstats.rxbreaks);
  1610. if (stli_comstats.rxoverrun)
  1611. seq_printf(m, " oe:%d",
  1612. (int) stli_comstats.rxoverrun);
  1613. sep = ' ';
  1614. if (stli_comstats.signals & TIOCM_RTS) {
  1615. seq_printf(m, "%c%s", sep, "RTS");
  1616. sep = '|';
  1617. }
  1618. if (stli_comstats.signals & TIOCM_CTS) {
  1619. seq_printf(m, "%c%s", sep, "CTS");
  1620. sep = '|';
  1621. }
  1622. if (stli_comstats.signals & TIOCM_DTR) {
  1623. seq_printf(m, "%c%s", sep, "DTR");
  1624. sep = '|';
  1625. }
  1626. if (stli_comstats.signals & TIOCM_CD) {
  1627. seq_printf(m, "%c%s", sep, "DCD");
  1628. sep = '|';
  1629. }
  1630. if (stli_comstats.signals & TIOCM_DSR) {
  1631. seq_printf(m, "%c%s", sep, "DSR");
  1632. sep = '|';
  1633. }
  1634. }
  1635. seq_putc(m, '\n');
  1636. }
  1637. /*****************************************************************************/
  1638. /*
  1639. * Port info, read from the /proc file system.
  1640. */
  1641. static int stli_proc_show(struct seq_file *m, void *v)
  1642. {
  1643. struct stlibrd *brdp;
  1644. struct stliport *portp;
  1645. unsigned int brdnr, portnr, totalport;
  1646. totalport = 0;
  1647. seq_printf(m, "%s: version %s\n", stli_drvtitle, stli_drvversion);
  1648. /*
  1649. * We scan through for each board, panel and port. The offset is
  1650. * calculated on the fly, and irrelevant ports are skipped.
  1651. */
  1652. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  1653. brdp = stli_brds[brdnr];
  1654. if (brdp == NULL)
  1655. continue;
  1656. if (brdp->state == 0)
  1657. continue;
  1658. totalport = brdnr * STL_MAXPORTS;
  1659. for (portnr = 0; (portnr < brdp->nrports); portnr++,
  1660. totalport++) {
  1661. portp = brdp->ports[portnr];
  1662. if (portp == NULL)
  1663. continue;
  1664. stli_portinfo(m, brdp, portp, totalport);
  1665. }
  1666. }
  1667. return 0;
  1668. }
  1669. static int stli_proc_open(struct inode *inode, struct file *file)
  1670. {
  1671. return single_open(file, stli_proc_show, NULL);
  1672. }
  1673. static const struct file_operations stli_proc_fops = {
  1674. .owner = THIS_MODULE,
  1675. .open = stli_proc_open,
  1676. .read = seq_read,
  1677. .llseek = seq_lseek,
  1678. .release = single_release,
  1679. };
  1680. /*****************************************************************************/
  1681. /*
  1682. * Generic send command routine. This will send a message to the slave,
  1683. * of the specified type with the specified argument. Must be very
  1684. * careful of data that will be copied out from shared memory -
  1685. * containing command results. The command completion is all done from
  1686. * a poll routine that does not have user context. Therefore you cannot
  1687. * copy back directly into user space, or to the kernel stack of a
  1688. * process. This routine does not sleep, so can be called from anywhere.
  1689. *
  1690. * The caller must hold the brd_lock (see also stli_sendcmd the usual
  1691. * entry point)
  1692. */
  1693. static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
  1694. {
  1695. cdkhdr_t __iomem *hdrp;
  1696. cdkctrl_t __iomem *cp;
  1697. unsigned char __iomem *bits;
  1698. if (test_bit(ST_CMDING, &portp->state)) {
  1699. printk(KERN_ERR "istallion: command already busy, cmd=%x!\n",
  1700. (int) cmd);
  1701. return;
  1702. }
  1703. EBRDENABLE(brdp);
  1704. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1705. if (size > 0) {
  1706. memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
  1707. if (copyback) {
  1708. portp->argp = arg;
  1709. portp->argsize = size;
  1710. }
  1711. }
  1712. writel(0, &cp->status);
  1713. writel(cmd, &cp->cmd);
  1714. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1715. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1716. portp->portidx;
  1717. writeb(readb(bits) | portp->portbit, bits);
  1718. set_bit(ST_CMDING, &portp->state);
  1719. EBRDDISABLE(brdp);
  1720. }
  1721. static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
  1722. {
  1723. unsigned long flags;
  1724. spin_lock_irqsave(&brd_lock, flags);
  1725. __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  1726. spin_unlock_irqrestore(&brd_lock, flags);
  1727. }
  1728. /*****************************************************************************/
  1729. /*
  1730. * Read data from shared memory. This assumes that the shared memory
  1731. * is enabled and that interrupts are off. Basically we just empty out
  1732. * the shared memory buffer into the tty buffer. Must be careful to
  1733. * handle the case where we fill up the tty buffer, but still have
  1734. * more chars to unload.
  1735. */
  1736. static void stli_read(struct stlibrd *brdp, struct stliport *portp)
  1737. {
  1738. cdkasyrq_t __iomem *rp;
  1739. char __iomem *shbuf;
  1740. struct tty_struct *tty;
  1741. unsigned int head, tail, size;
  1742. unsigned int len, stlen;
  1743. if (test_bit(ST_RXSTOP, &portp->state))
  1744. return;
  1745. tty = tty_port_tty_get(&portp->port);
  1746. if (tty == NULL)
  1747. return;
  1748. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  1749. head = (unsigned int) readw(&rp->head);
  1750. if (head != ((unsigned int) readw(&rp->head)))
  1751. head = (unsigned int) readw(&rp->head);
  1752. tail = (unsigned int) readw(&rp->tail);
  1753. size = portp->rxsize;
  1754. if (head >= tail) {
  1755. len = head - tail;
  1756. stlen = len;
  1757. } else {
  1758. len = size - (tail - head);
  1759. stlen = size - tail;
  1760. }
  1761. len = tty_buffer_request_room(tty, len);
  1762. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
  1763. while (len > 0) {
  1764. unsigned char *cptr;
  1765. stlen = min(len, stlen);
  1766. tty_prepare_flip_string(tty, &cptr, stlen);
  1767. memcpy_fromio(cptr, shbuf + tail, stlen);
  1768. len -= stlen;
  1769. tail += stlen;
  1770. if (tail >= size) {
  1771. tail = 0;
  1772. stlen = head;
  1773. }
  1774. }
  1775. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  1776. writew(tail, &rp->tail);
  1777. if (head != tail)
  1778. set_bit(ST_RXING, &portp->state);
  1779. tty_schedule_flip(tty);
  1780. tty_kref_put(tty);
  1781. }
  1782. /*****************************************************************************/
  1783. /*
  1784. * Set up and carry out any delayed commands. There is only a small set
  1785. * of slave commands that can be done "off-level". So it is not too
  1786. * difficult to deal with them here.
  1787. */
  1788. static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
  1789. {
  1790. int cmd;
  1791. if (test_bit(ST_DOSIGS, &portp->state)) {
  1792. if (test_bit(ST_DOFLUSHTX, &portp->state) &&
  1793. test_bit(ST_DOFLUSHRX, &portp->state))
  1794. cmd = A_SETSIGNALSF;
  1795. else if (test_bit(ST_DOFLUSHTX, &portp->state))
  1796. cmd = A_SETSIGNALSFTX;
  1797. else if (test_bit(ST_DOFLUSHRX, &portp->state))
  1798. cmd = A_SETSIGNALSFRX;
  1799. else
  1800. cmd = A_SETSIGNALS;
  1801. clear_bit(ST_DOFLUSHTX, &portp->state);
  1802. clear_bit(ST_DOFLUSHRX, &portp->state);
  1803. clear_bit(ST_DOSIGS, &portp->state);
  1804. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
  1805. sizeof(asysigs_t));
  1806. writel(0, &cp->status);
  1807. writel(cmd, &cp->cmd);
  1808. set_bit(ST_CMDING, &portp->state);
  1809. } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
  1810. test_bit(ST_DOFLUSHRX, &portp->state)) {
  1811. cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
  1812. cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
  1813. clear_bit(ST_DOFLUSHTX, &portp->state);
  1814. clear_bit(ST_DOFLUSHRX, &portp->state);
  1815. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
  1816. writel(0, &cp->status);
  1817. writel(A_FLUSH, &cp->cmd);
  1818. set_bit(ST_CMDING, &portp->state);
  1819. }
  1820. }
  1821. /*****************************************************************************/
  1822. /*
  1823. * Host command service checking. This handles commands or messages
  1824. * coming from the slave to the host. Must have board shared memory
  1825. * enabled and interrupts off when called. Notice that by servicing the
  1826. * read data last we don't need to change the shared memory pointer
  1827. * during processing (which is a slow IO operation).
  1828. * Return value indicates if this port is still awaiting actions from
  1829. * the slave (like open, command, or even TX data being sent). If 0
  1830. * then port is still busy, otherwise no longer busy.
  1831. */
  1832. static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
  1833. {
  1834. cdkasy_t __iomem *ap;
  1835. cdkctrl_t __iomem *cp;
  1836. struct tty_struct *tty;
  1837. asynotify_t nt;
  1838. unsigned long oldsigs;
  1839. int rc, donerx;
  1840. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1841. cp = &ap->ctrl;
  1842. /*
  1843. * Check if we are waiting for an open completion message.
  1844. */
  1845. if (test_bit(ST_OPENING, &portp->state)) {
  1846. rc = readl(&cp->openarg);
  1847. if (readb(&cp->open) == 0 && rc != 0) {
  1848. if (rc > 0)
  1849. rc--;
  1850. writel(0, &cp->openarg);
  1851. portp->rc = rc;
  1852. clear_bit(ST_OPENING, &portp->state);
  1853. wake_up_interruptible(&portp->raw_wait);
  1854. }
  1855. }
  1856. /*
  1857. * Check if we are waiting for a close completion message.
  1858. */
  1859. if (test_bit(ST_CLOSING, &portp->state)) {
  1860. rc = (int) readl(&cp->closearg);
  1861. if (readb(&cp->close) == 0 && rc != 0) {
  1862. if (rc > 0)
  1863. rc--;
  1864. writel(0, &cp->closearg);
  1865. portp->rc = rc;
  1866. clear_bit(ST_CLOSING, &portp->state);
  1867. wake_up_interruptible(&portp->raw_wait);
  1868. }
  1869. }
  1870. /*
  1871. * Check if we are waiting for a command completion message. We may
  1872. * need to copy out the command results associated with this command.
  1873. */
  1874. if (test_bit(ST_CMDING, &portp->state)) {
  1875. rc = readl(&cp->status);
  1876. if (readl(&cp->cmd) == 0 && rc != 0) {
  1877. if (rc > 0)
  1878. rc--;
  1879. if (portp->argp != NULL) {
  1880. memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
  1881. portp->argsize);
  1882. portp->argp = NULL;
  1883. }
  1884. writel(0, &cp->status);
  1885. portp->rc = rc;
  1886. clear_bit(ST_CMDING, &portp->state);
  1887. stli_dodelaycmd(portp, cp);
  1888. wake_up_interruptible(&portp->raw_wait);
  1889. }
  1890. }
  1891. /*
  1892. * Check for any notification messages ready. This includes lots of
  1893. * different types of events - RX chars ready, RX break received,
  1894. * TX data low or empty in the slave, modem signals changed state.
  1895. */
  1896. donerx = 0;
  1897. if (ap->notify) {
  1898. nt = ap->changed;
  1899. ap->notify = 0;
  1900. tty = tty_port_tty_get(&portp->port);
  1901. if (nt.signal & SG_DCD) {
  1902. oldsigs = portp->sigs;
  1903. portp->sigs = stli_mktiocm(nt.sigvalue);
  1904. clear_bit(ST_GETSIGS, &portp->state);
  1905. if ((portp->sigs & TIOCM_CD) &&
  1906. ((oldsigs & TIOCM_CD) == 0))
  1907. wake_up_interruptible(&portp->port.open_wait);
  1908. if ((oldsigs & TIOCM_CD) &&
  1909. ((portp->sigs & TIOCM_CD) == 0)) {
  1910. if (portp->port.flags & ASYNC_CHECK_CD) {
  1911. if (tty)
  1912. tty_hangup(tty);
  1913. }
  1914. }
  1915. }
  1916. if (nt.data & DT_TXEMPTY)
  1917. clear_bit(ST_TXBUSY, &portp->state);
  1918. if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
  1919. if (tty != NULL) {
  1920. tty_wakeup(tty);
  1921. EBRDENABLE(brdp);
  1922. }
  1923. }
  1924. if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
  1925. if (tty != NULL) {
  1926. tty_insert_flip_char(tty, 0, TTY_BREAK);
  1927. if (portp->port.flags & ASYNC_SAK) {
  1928. do_SAK(tty);
  1929. EBRDENABLE(brdp);
  1930. }
  1931. tty_schedule_flip(tty);
  1932. }
  1933. }
  1934. tty_kref_put(tty);
  1935. if (nt.data & DT_RXBUSY) {
  1936. donerx++;
  1937. stli_read(brdp, portp);
  1938. }
  1939. }
  1940. /*
  1941. * It might seem odd that we are checking for more RX chars here.
  1942. * But, we need to handle the case where the tty buffer was previously
  1943. * filled, but we had more characters to pass up. The slave will not
  1944. * send any more RX notify messages until the RX buffer has been emptied.
  1945. * But it will leave the service bits on (since the buffer is not empty).
  1946. * So from here we can try to process more RX chars.
  1947. */
  1948. if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
  1949. clear_bit(ST_RXING, &portp->state);
  1950. stli_read(brdp, portp);
  1951. }
  1952. return((test_bit(ST_OPENING, &portp->state) ||
  1953. test_bit(ST_CLOSING, &portp->state) ||
  1954. test_bit(ST_CMDING, &portp->state) ||
  1955. test_bit(ST_TXBUSY, &portp->state) ||
  1956. test_bit(ST_RXING, &portp->state)) ? 0 : 1);
  1957. }
  1958. /*****************************************************************************/
  1959. /*
  1960. * Service all ports on a particular board. Assumes that the boards
  1961. * shared memory is enabled, and that the page pointer is pointed
  1962. * at the cdk header structure.
  1963. */
  1964. static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
  1965. {
  1966. struct stliport *portp;
  1967. unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
  1968. unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
  1969. unsigned char __iomem *slavep;
  1970. int bitpos, bitat, bitsize;
  1971. int channr, nrdevs, slavebitchange;
  1972. bitsize = brdp->bitsize;
  1973. nrdevs = brdp->nrdevs;
  1974. /*
  1975. * Check if slave wants any service. Basically we try to do as
  1976. * little work as possible here. There are 2 levels of service
  1977. * bits. So if there is nothing to do we bail early. We check
  1978. * 8 service bits at a time in the inner loop, so we can bypass
  1979. * the lot if none of them want service.
  1980. */
  1981. memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
  1982. bitsize);
  1983. memset(&slavebits[0], 0, bitsize);
  1984. slavebitchange = 0;
  1985. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  1986. if (hostbits[bitpos] == 0)
  1987. continue;
  1988. channr = bitpos * 8;
  1989. for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
  1990. if (hostbits[bitpos] & bitat) {
  1991. portp = brdp->ports[(channr - 1)];
  1992. if (stli_hostcmd(brdp, portp)) {
  1993. slavebitchange++;
  1994. slavebits[bitpos] |= bitat;
  1995. }
  1996. }
  1997. }
  1998. }
  1999. /*
  2000. * If any of the ports are no longer busy then update them in the
  2001. * slave request bits. We need to do this after, since a host port
  2002. * service may initiate more slave requests.
  2003. */
  2004. if (slavebitchange) {
  2005. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2006. slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
  2007. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2008. if (readb(slavebits + bitpos))
  2009. writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
  2010. }
  2011. }
  2012. }
  2013. /*****************************************************************************/
  2014. /*
  2015. * Driver poll routine. This routine polls the boards in use and passes
  2016. * messages back up to host when necessary. This is actually very
  2017. * CPU efficient, since we will always have the kernel poll clock, it
  2018. * adds only a few cycles when idle (since board service can be
  2019. * determined very easily), but when loaded generates no interrupts
  2020. * (with their expensive associated context change).
  2021. */
  2022. static void stli_poll(unsigned long arg)
  2023. {
  2024. cdkhdr_t __iomem *hdrp;
  2025. struct stlibrd *brdp;
  2026. unsigned int brdnr;
  2027. mod_timer(&stli_timerlist, STLI_TIMEOUT);
  2028. /*
  2029. * Check each board and do any servicing required.
  2030. */
  2031. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2032. brdp = stli_brds[brdnr];
  2033. if (brdp == NULL)
  2034. continue;
  2035. if (!test_bit(BST_STARTED, &brdp->state))
  2036. continue;
  2037. spin_lock(&brd_lock);
  2038. EBRDENABLE(brdp);
  2039. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2040. if (readb(&hdrp->hostreq))
  2041. stli_brdpoll(brdp, hdrp);
  2042. EBRDDISABLE(brdp);
  2043. spin_unlock(&brd_lock);
  2044. }
  2045. }
  2046. /*****************************************************************************/
  2047. /*
  2048. * Translate the termios settings into the port setting structure of
  2049. * the slave.
  2050. */
  2051. static void stli_mkasyport(struct tty_struct *tty, struct stliport *portp,
  2052. asyport_t *pp, struct ktermios *tiosp)
  2053. {
  2054. memset(pp, 0, sizeof(asyport_t));
  2055. /*
  2056. * Start of by setting the baud, char size, parity and stop bit info.
  2057. */
  2058. pp->baudout = tty_get_baud_rate(tty);
  2059. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2060. if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2061. pp->baudout = 57600;
  2062. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2063. pp->baudout = 115200;
  2064. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2065. pp->baudout = 230400;
  2066. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2067. pp->baudout = 460800;
  2068. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2069. pp->baudout = (portp->baud_base / portp->custom_divisor);
  2070. }
  2071. if (pp->baudout > STL_MAXBAUD)
  2072. pp->baudout = STL_MAXBAUD;
  2073. pp->baudin = pp->baudout;
  2074. switch (tiosp->c_cflag & CSIZE) {
  2075. case CS5:
  2076. pp->csize = 5;
  2077. break;
  2078. case CS6:
  2079. pp->csize = 6;
  2080. break;
  2081. case CS7:
  2082. pp->csize = 7;
  2083. break;
  2084. default:
  2085. pp->csize = 8;
  2086. break;
  2087. }
  2088. if (tiosp->c_cflag & CSTOPB)
  2089. pp->stopbs = PT_STOP2;
  2090. else
  2091. pp->stopbs = PT_STOP1;
  2092. if (tiosp->c_cflag & PARENB) {
  2093. if (tiosp->c_cflag & PARODD)
  2094. pp->parity = PT_ODDPARITY;
  2095. else
  2096. pp->parity = PT_EVENPARITY;
  2097. } else {
  2098. pp->parity = PT_NOPARITY;
  2099. }
  2100. /*
  2101. * Set up any flow control options enabled.
  2102. */
  2103. if (tiosp->c_iflag & IXON) {
  2104. pp->flow |= F_IXON;
  2105. if (tiosp->c_iflag & IXANY)
  2106. pp->flow |= F_IXANY;
  2107. }
  2108. if (tiosp->c_cflag & CRTSCTS)
  2109. pp->flow |= (F_RTSFLOW | F_CTSFLOW);
  2110. pp->startin = tiosp->c_cc[VSTART];
  2111. pp->stopin = tiosp->c_cc[VSTOP];
  2112. pp->startout = tiosp->c_cc[VSTART];
  2113. pp->stopout = tiosp->c_cc[VSTOP];
  2114. /*
  2115. * Set up the RX char marking mask with those RX error types we must
  2116. * catch. We can get the slave to help us out a little here, it will
  2117. * ignore parity errors and breaks for us, and mark parity errors in
  2118. * the data stream.
  2119. */
  2120. if (tiosp->c_iflag & IGNPAR)
  2121. pp->iflag |= FI_IGNRXERRS;
  2122. if (tiosp->c_iflag & IGNBRK)
  2123. pp->iflag |= FI_IGNBREAK;
  2124. portp->rxmarkmsk = 0;
  2125. if (tiosp->c_iflag & (INPCK | PARMRK))
  2126. pp->iflag |= FI_1MARKRXERRS;
  2127. if (tiosp->c_iflag & BRKINT)
  2128. portp->rxmarkmsk |= BRKINT;
  2129. /*
  2130. * Set up clocal processing as required.
  2131. */
  2132. if (tiosp->c_cflag & CLOCAL)
  2133. portp->port.flags &= ~ASYNC_CHECK_CD;
  2134. else
  2135. portp->port.flags |= ASYNC_CHECK_CD;
  2136. /*
  2137. * Transfer any persistent flags into the asyport structure.
  2138. */
  2139. pp->pflag = (portp->pflag & 0xffff);
  2140. pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
  2141. pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
  2142. pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
  2143. }
  2144. /*****************************************************************************/
  2145. /*
  2146. * Construct a slave signals structure for setting the DTR and RTS
  2147. * signals as specified.
  2148. */
  2149. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
  2150. {
  2151. memset(sp, 0, sizeof(asysigs_t));
  2152. if (dtr >= 0) {
  2153. sp->signal |= SG_DTR;
  2154. sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
  2155. }
  2156. if (rts >= 0) {
  2157. sp->signal |= SG_RTS;
  2158. sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
  2159. }
  2160. }
  2161. /*****************************************************************************/
  2162. /*
  2163. * Convert the signals returned from the slave into a local TIOCM type
  2164. * signals value. We keep them locally in TIOCM format.
  2165. */
  2166. static long stli_mktiocm(unsigned long sigvalue)
  2167. {
  2168. long tiocm = 0;
  2169. tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
  2170. tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
  2171. tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
  2172. tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
  2173. tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
  2174. tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
  2175. return(tiocm);
  2176. }
  2177. /*****************************************************************************/
  2178. /*
  2179. * All panels and ports actually attached have been worked out. All
  2180. * we need to do here is set up the appropriate per port data structures.
  2181. */
  2182. static int stli_initports(struct stlibrd *brdp)
  2183. {
  2184. struct stliport *portp;
  2185. unsigned int i, panelnr, panelport;
  2186. for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
  2187. portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
  2188. if (!portp) {
  2189. printk(KERN_WARNING "istallion: failed to allocate port structure\n");
  2190. continue;
  2191. }
  2192. tty_port_init(&portp->port);
  2193. portp->port.ops = &stli_port_ops;
  2194. portp->magic = STLI_PORTMAGIC;
  2195. portp->portnr = i;
  2196. portp->brdnr = brdp->brdnr;
  2197. portp->panelnr = panelnr;
  2198. portp->baud_base = STL_BAUDBASE;
  2199. portp->port.close_delay = STL_CLOSEDELAY;
  2200. portp->closing_wait = 30 * HZ;
  2201. init_waitqueue_head(&portp->port.open_wait);
  2202. init_waitqueue_head(&portp->port.close_wait);
  2203. init_waitqueue_head(&portp->raw_wait);
  2204. panelport++;
  2205. if (panelport >= brdp->panels[panelnr]) {
  2206. panelport = 0;
  2207. panelnr++;
  2208. }
  2209. brdp->ports[i] = portp;
  2210. }
  2211. return 0;
  2212. }
  2213. /*****************************************************************************/
  2214. /*
  2215. * All the following routines are board specific hardware operations.
  2216. */
  2217. static void stli_ecpinit(struct stlibrd *brdp)
  2218. {
  2219. unsigned long memconf;
  2220. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2221. udelay(10);
  2222. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2223. udelay(100);
  2224. memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
  2225. outb(memconf, (brdp->iobase + ECP_ATMEMAR));
  2226. }
  2227. /*****************************************************************************/
  2228. static void stli_ecpenable(struct stlibrd *brdp)
  2229. {
  2230. outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
  2231. }
  2232. /*****************************************************************************/
  2233. static void stli_ecpdisable(struct stlibrd *brdp)
  2234. {
  2235. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2236. }
  2237. /*****************************************************************************/
  2238. static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2239. {
  2240. void __iomem *ptr;
  2241. unsigned char val;
  2242. if (offset > brdp->memsize) {
  2243. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2244. "range at line=%d(%d), brd=%d\n",
  2245. (int) offset, line, __LINE__, brdp->brdnr);
  2246. ptr = NULL;
  2247. val = 0;
  2248. } else {
  2249. ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
  2250. val = (unsigned char) (offset / ECP_ATPAGESIZE);
  2251. }
  2252. outb(val, (brdp->iobase + ECP_ATMEMPR));
  2253. return(ptr);
  2254. }
  2255. /*****************************************************************************/
  2256. static void stli_ecpreset(struct stlibrd *brdp)
  2257. {
  2258. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2259. udelay(10);
  2260. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2261. udelay(500);
  2262. }
  2263. /*****************************************************************************/
  2264. static void stli_ecpintr(struct stlibrd *brdp)
  2265. {
  2266. outb(0x1, brdp->iobase);
  2267. }
  2268. /*****************************************************************************/
  2269. /*
  2270. * The following set of functions act on ECP EISA boards.
  2271. */
  2272. static void stli_ecpeiinit(struct stlibrd *brdp)
  2273. {
  2274. unsigned long memconf;
  2275. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2276. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2277. udelay(10);
  2278. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2279. udelay(500);
  2280. memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
  2281. outb(memconf, (brdp->iobase + ECP_EIMEMARL));
  2282. memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
  2283. outb(memconf, (brdp->iobase + ECP_EIMEMARH));
  2284. }
  2285. /*****************************************************************************/
  2286. static void stli_ecpeienable(struct stlibrd *brdp)
  2287. {
  2288. outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
  2289. }
  2290. /*****************************************************************************/
  2291. static void stli_ecpeidisable(struct stlibrd *brdp)
  2292. {
  2293. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2294. }
  2295. /*****************************************************************************/
  2296. static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2297. {
  2298. void __iomem *ptr;
  2299. unsigned char val;
  2300. if (offset > brdp->memsize) {
  2301. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2302. "range at line=%d(%d), brd=%d\n",
  2303. (int) offset, line, __LINE__, brdp->brdnr);
  2304. ptr = NULL;
  2305. val = 0;
  2306. } else {
  2307. ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
  2308. if (offset < ECP_EIPAGESIZE)
  2309. val = ECP_EIENABLE;
  2310. else
  2311. val = ECP_EIENABLE | 0x40;
  2312. }
  2313. outb(val, (brdp->iobase + ECP_EICONFR));
  2314. return(ptr);
  2315. }
  2316. /*****************************************************************************/
  2317. static void stli_ecpeireset(struct stlibrd *brdp)
  2318. {
  2319. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2320. udelay(10);
  2321. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2322. udelay(500);
  2323. }
  2324. /*****************************************************************************/
  2325. /*
  2326. * The following set of functions act on ECP MCA boards.
  2327. */
  2328. static void stli_ecpmcenable(struct stlibrd *brdp)
  2329. {
  2330. outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
  2331. }
  2332. /*****************************************************************************/
  2333. static void stli_ecpmcdisable(struct stlibrd *brdp)
  2334. {
  2335. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2336. }
  2337. /*****************************************************************************/
  2338. static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2339. {
  2340. void __iomem *ptr;
  2341. unsigned char val;
  2342. if (offset > brdp->memsize) {
  2343. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2344. "range at line=%d(%d), brd=%d\n",
  2345. (int) offset, line, __LINE__, brdp->brdnr);
  2346. ptr = NULL;
  2347. val = 0;
  2348. } else {
  2349. ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
  2350. val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
  2351. }
  2352. outb(val, (brdp->iobase + ECP_MCCONFR));
  2353. return(ptr);
  2354. }
  2355. /*****************************************************************************/
  2356. static void stli_ecpmcreset(struct stlibrd *brdp)
  2357. {
  2358. outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
  2359. udelay(10);
  2360. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2361. udelay(500);
  2362. }
  2363. /*****************************************************************************/
  2364. /*
  2365. * The following set of functions act on ECP PCI boards.
  2366. */
  2367. static void stli_ecppciinit(struct stlibrd *brdp)
  2368. {
  2369. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2370. udelay(10);
  2371. outb(0, (brdp->iobase + ECP_PCICONFR));
  2372. udelay(500);
  2373. }
  2374. /*****************************************************************************/
  2375. static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2376. {
  2377. void __iomem *ptr;
  2378. unsigned char val;
  2379. if (offset > brdp->memsize) {
  2380. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2381. "range at line=%d(%d), board=%d\n",
  2382. (int) offset, line, __LINE__, brdp->brdnr);
  2383. ptr = NULL;
  2384. val = 0;
  2385. } else {
  2386. ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
  2387. val = (offset / ECP_PCIPAGESIZE) << 1;
  2388. }
  2389. outb(val, (brdp->iobase + ECP_PCICONFR));
  2390. return(ptr);
  2391. }
  2392. /*****************************************************************************/
  2393. static void stli_ecppcireset(struct stlibrd *brdp)
  2394. {
  2395. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2396. udelay(10);
  2397. outb(0, (brdp->iobase + ECP_PCICONFR));
  2398. udelay(500);
  2399. }
  2400. /*****************************************************************************/
  2401. /*
  2402. * The following routines act on ONboards.
  2403. */
  2404. static void stli_onbinit(struct stlibrd *brdp)
  2405. {
  2406. unsigned long memconf;
  2407. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2408. udelay(10);
  2409. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2410. mdelay(1000);
  2411. memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
  2412. outb(memconf, (brdp->iobase + ONB_ATMEMAR));
  2413. outb(0x1, brdp->iobase);
  2414. mdelay(1);
  2415. }
  2416. /*****************************************************************************/
  2417. static void stli_onbenable(struct stlibrd *brdp)
  2418. {
  2419. outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
  2420. }
  2421. /*****************************************************************************/
  2422. static void stli_onbdisable(struct stlibrd *brdp)
  2423. {
  2424. outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
  2425. }
  2426. /*****************************************************************************/
  2427. static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2428. {
  2429. void __iomem *ptr;
  2430. if (offset > brdp->memsize) {
  2431. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2432. "range at line=%d(%d), brd=%d\n",
  2433. (int) offset, line, __LINE__, brdp->brdnr);
  2434. ptr = NULL;
  2435. } else {
  2436. ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
  2437. }
  2438. return(ptr);
  2439. }
  2440. /*****************************************************************************/
  2441. static void stli_onbreset(struct stlibrd *brdp)
  2442. {
  2443. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2444. udelay(10);
  2445. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2446. mdelay(1000);
  2447. }
  2448. /*****************************************************************************/
  2449. /*
  2450. * The following routines act on ONboard EISA.
  2451. */
  2452. static void stli_onbeinit(struct stlibrd *brdp)
  2453. {
  2454. unsigned long memconf;
  2455. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  2456. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2457. udelay(10);
  2458. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2459. mdelay(1000);
  2460. memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
  2461. outb(memconf, (brdp->iobase + ONB_EIMEMARL));
  2462. memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
  2463. outb(memconf, (brdp->iobase + ONB_EIMEMARH));
  2464. outb(0x1, brdp->iobase);
  2465. mdelay(1);
  2466. }
  2467. /*****************************************************************************/
  2468. static void stli_onbeenable(struct stlibrd *brdp)
  2469. {
  2470. outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
  2471. }
  2472. /*****************************************************************************/
  2473. static void stli_onbedisable(struct stlibrd *brdp)
  2474. {
  2475. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2476. }
  2477. /*****************************************************************************/
  2478. static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2479. {
  2480. void __iomem *ptr;
  2481. unsigned char val;
  2482. if (offset > brdp->memsize) {
  2483. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2484. "range at line=%d(%d), brd=%d\n",
  2485. (int) offset, line, __LINE__, brdp->brdnr);
  2486. ptr = NULL;
  2487. val = 0;
  2488. } else {
  2489. ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
  2490. if (offset < ONB_EIPAGESIZE)
  2491. val = ONB_EIENABLE;
  2492. else
  2493. val = ONB_EIENABLE | 0x40;
  2494. }
  2495. outb(val, (brdp->iobase + ONB_EICONFR));
  2496. return(ptr);
  2497. }
  2498. /*****************************************************************************/
  2499. static void stli_onbereset(struct stlibrd *brdp)
  2500. {
  2501. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2502. udelay(10);
  2503. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2504. mdelay(1000);
  2505. }
  2506. /*****************************************************************************/
  2507. /*
  2508. * The following routines act on Brumby boards.
  2509. */
  2510. static void stli_bbyinit(struct stlibrd *brdp)
  2511. {
  2512. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2513. udelay(10);
  2514. outb(0, (brdp->iobase + BBY_ATCONFR));
  2515. mdelay(1000);
  2516. outb(0x1, brdp->iobase);
  2517. mdelay(1);
  2518. }
  2519. /*****************************************************************************/
  2520. static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2521. {
  2522. void __iomem *ptr;
  2523. unsigned char val;
  2524. BUG_ON(offset > brdp->memsize);
  2525. ptr = brdp->membase + (offset % BBY_PAGESIZE);
  2526. val = (unsigned char) (offset / BBY_PAGESIZE);
  2527. outb(val, (brdp->iobase + BBY_ATCONFR));
  2528. return(ptr);
  2529. }
  2530. /*****************************************************************************/
  2531. static void stli_bbyreset(struct stlibrd *brdp)
  2532. {
  2533. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2534. udelay(10);
  2535. outb(0, (brdp->iobase + BBY_ATCONFR));
  2536. mdelay(1000);
  2537. }
  2538. /*****************************************************************************/
  2539. /*
  2540. * The following routines act on original old Stallion boards.
  2541. */
  2542. static void stli_stalinit(struct stlibrd *brdp)
  2543. {
  2544. outb(0x1, brdp->iobase);
  2545. mdelay(1000);
  2546. }
  2547. /*****************************************************************************/
  2548. static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2549. {
  2550. BUG_ON(offset > brdp->memsize);
  2551. return brdp->membase + (offset % STAL_PAGESIZE);
  2552. }
  2553. /*****************************************************************************/
  2554. static void stli_stalreset(struct stlibrd *brdp)
  2555. {
  2556. u32 __iomem *vecp;
  2557. vecp = (u32 __iomem *) (brdp->membase + 0x30);
  2558. writel(0xffff0000, vecp);
  2559. outb(0, brdp->iobase);
  2560. mdelay(1000);
  2561. }
  2562. /*****************************************************************************/
  2563. /*
  2564. * Try to find an ECP board and initialize it. This handles only ECP
  2565. * board types.
  2566. */
  2567. static int stli_initecp(struct stlibrd *brdp)
  2568. {
  2569. cdkecpsig_t sig;
  2570. cdkecpsig_t __iomem *sigsp;
  2571. unsigned int status, nxtid;
  2572. char *name;
  2573. int retval, panelnr, nrports;
  2574. if ((brdp->iobase == 0) || (brdp->memaddr == 0)) {
  2575. retval = -ENODEV;
  2576. goto err;
  2577. }
  2578. brdp->iosize = ECP_IOSIZE;
  2579. if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
  2580. retval = -EIO;
  2581. goto err;
  2582. }
  2583. /*
  2584. * Based on the specific board type setup the common vars to access
  2585. * and enable shared memory. Set all board specific information now
  2586. * as well.
  2587. */
  2588. switch (brdp->brdtype) {
  2589. case BRD_ECP:
  2590. brdp->memsize = ECP_MEMSIZE;
  2591. brdp->pagesize = ECP_ATPAGESIZE;
  2592. brdp->init = stli_ecpinit;
  2593. brdp->enable = stli_ecpenable;
  2594. brdp->reenable = stli_ecpenable;
  2595. brdp->disable = stli_ecpdisable;
  2596. brdp->getmemptr = stli_ecpgetmemptr;
  2597. brdp->intr = stli_ecpintr;
  2598. brdp->reset = stli_ecpreset;
  2599. name = "serial(EC8/64)";
  2600. break;
  2601. case BRD_ECPE:
  2602. brdp->memsize = ECP_MEMSIZE;
  2603. brdp->pagesize = ECP_EIPAGESIZE;
  2604. brdp->init = stli_ecpeiinit;
  2605. brdp->enable = stli_ecpeienable;
  2606. brdp->reenable = stli_ecpeienable;
  2607. brdp->disable = stli_ecpeidisable;
  2608. brdp->getmemptr = stli_ecpeigetmemptr;
  2609. brdp->intr = stli_ecpintr;
  2610. brdp->reset = stli_ecpeireset;
  2611. name = "serial(EC8/64-EI)";
  2612. break;
  2613. case BRD_ECPMC:
  2614. brdp->memsize = ECP_MEMSIZE;
  2615. brdp->pagesize = ECP_MCPAGESIZE;
  2616. brdp->init = NULL;
  2617. brdp->enable = stli_ecpmcenable;
  2618. brdp->reenable = stli_ecpmcenable;
  2619. brdp->disable = stli_ecpmcdisable;
  2620. brdp->getmemptr = stli_ecpmcgetmemptr;
  2621. brdp->intr = stli_ecpintr;
  2622. brdp->reset = stli_ecpmcreset;
  2623. name = "serial(EC8/64-MCA)";
  2624. break;
  2625. case BRD_ECPPCI:
  2626. brdp->memsize = ECP_PCIMEMSIZE;
  2627. brdp->pagesize = ECP_PCIPAGESIZE;
  2628. brdp->init = stli_ecppciinit;
  2629. brdp->enable = NULL;
  2630. brdp->reenable = NULL;
  2631. brdp->disable = NULL;
  2632. brdp->getmemptr = stli_ecppcigetmemptr;
  2633. brdp->intr = stli_ecpintr;
  2634. brdp->reset = stli_ecppcireset;
  2635. name = "serial(EC/RA-PCI)";
  2636. break;
  2637. default:
  2638. retval = -EINVAL;
  2639. goto err_reg;
  2640. }
  2641. /*
  2642. * The per-board operations structure is all set up, so now let's go
  2643. * and get the board operational. Firstly initialize board configuration
  2644. * registers. Set the memory mapping info so we can get at the boards
  2645. * shared memory.
  2646. */
  2647. EBRDINIT(brdp);
  2648. brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
  2649. if (brdp->membase == NULL) {
  2650. retval = -ENOMEM;
  2651. goto err_reg;
  2652. }
  2653. /*
  2654. * Now that all specific code is set up, enable the shared memory and
  2655. * look for the a signature area that will tell us exactly what board
  2656. * this is, and what it is connected to it.
  2657. */
  2658. EBRDENABLE(brdp);
  2659. sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  2660. memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
  2661. EBRDDISABLE(brdp);
  2662. if (sig.magic != cpu_to_le32(ECP_MAGIC)) {
  2663. retval = -ENODEV;
  2664. goto err_unmap;
  2665. }
  2666. /*
  2667. * Scan through the signature looking at the panels connected to the
  2668. * board. Calculate the total number of ports as we go.
  2669. */
  2670. for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  2671. status = sig.panelid[nxtid];
  2672. if ((status & ECH_PNLIDMASK) != nxtid)
  2673. break;
  2674. brdp->panelids[panelnr] = status;
  2675. nrports = (status & ECH_PNL16PORT) ? 16 : 8;
  2676. if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
  2677. nxtid++;
  2678. brdp->panels[panelnr] = nrports;
  2679. brdp->nrports += nrports;
  2680. nxtid++;
  2681. brdp->nrpanels++;
  2682. }
  2683. set_bit(BST_FOUND, &brdp->state);
  2684. return 0;
  2685. err_unmap:
  2686. iounmap(brdp->membase);
  2687. brdp->membase = NULL;
  2688. err_reg:
  2689. release_region(brdp->iobase, brdp->iosize);
  2690. err:
  2691. return retval;
  2692. }
  2693. /*****************************************************************************/
  2694. /*
  2695. * Try to find an ONboard, Brumby or Stallion board and initialize it.
  2696. * This handles only these board types.
  2697. */
  2698. static int stli_initonb(struct stlibrd *brdp)
  2699. {
  2700. cdkonbsig_t sig;
  2701. cdkonbsig_t __iomem *sigsp;
  2702. char *name;
  2703. int i, retval;
  2704. /*
  2705. * Do a basic sanity check on the IO and memory addresses.
  2706. */
  2707. if (brdp->iobase == 0 || brdp->memaddr == 0) {
  2708. retval = -ENODEV;
  2709. goto err;
  2710. }
  2711. brdp->iosize = ONB_IOSIZE;
  2712. if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
  2713. retval = -EIO;
  2714. goto err;
  2715. }
  2716. /*
  2717. * Based on the specific board type setup the common vars to access
  2718. * and enable shared memory. Set all board specific information now
  2719. * as well.
  2720. */
  2721. switch (brdp->brdtype) {
  2722. case BRD_ONBOARD:
  2723. case BRD_ONBOARD2:
  2724. brdp->memsize = ONB_MEMSIZE;
  2725. brdp->pagesize = ONB_ATPAGESIZE;
  2726. brdp->init = stli_onbinit;
  2727. brdp->enable = stli_onbenable;
  2728. brdp->reenable = stli_onbenable;
  2729. brdp->disable = stli_onbdisable;
  2730. brdp->getmemptr = stli_onbgetmemptr;
  2731. brdp->intr = stli_ecpintr;
  2732. brdp->reset = stli_onbreset;
  2733. if (brdp->memaddr > 0x100000)
  2734. brdp->enabval = ONB_MEMENABHI;
  2735. else
  2736. brdp->enabval = ONB_MEMENABLO;
  2737. name = "serial(ONBoard)";
  2738. break;
  2739. case BRD_ONBOARDE:
  2740. brdp->memsize = ONB_EIMEMSIZE;
  2741. brdp->pagesize = ONB_EIPAGESIZE;
  2742. brdp->init = stli_onbeinit;
  2743. brdp->enable = stli_onbeenable;
  2744. brdp->reenable = stli_onbeenable;
  2745. brdp->disable = stli_onbedisable;
  2746. brdp->getmemptr = stli_onbegetmemptr;
  2747. brdp->intr = stli_ecpintr;
  2748. brdp->reset = stli_onbereset;
  2749. name = "serial(ONBoard/E)";
  2750. break;
  2751. case BRD_BRUMBY4:
  2752. brdp->memsize = BBY_MEMSIZE;
  2753. brdp->pagesize = BBY_PAGESIZE;
  2754. brdp->init = stli_bbyinit;
  2755. brdp->enable = NULL;
  2756. brdp->reenable = NULL;
  2757. brdp->disable = NULL;
  2758. brdp->getmemptr = stli_bbygetmemptr;
  2759. brdp->intr = stli_ecpintr;
  2760. brdp->reset = stli_bbyreset;
  2761. name = "serial(Brumby)";
  2762. break;
  2763. case BRD_STALLION:
  2764. brdp->memsize = STAL_MEMSIZE;
  2765. brdp->pagesize = STAL_PAGESIZE;
  2766. brdp->init = stli_stalinit;
  2767. brdp->enable = NULL;
  2768. brdp->reenable = NULL;
  2769. brdp->disable = NULL;
  2770. brdp->getmemptr = stli_stalgetmemptr;
  2771. brdp->intr = stli_ecpintr;
  2772. brdp->reset = stli_stalreset;
  2773. name = "serial(Stallion)";
  2774. break;
  2775. default:
  2776. retval = -EINVAL;
  2777. goto err_reg;
  2778. }
  2779. /*
  2780. * The per-board operations structure is all set up, so now let's go
  2781. * and get the board operational. Firstly initialize board configuration
  2782. * registers. Set the memory mapping info so we can get at the boards
  2783. * shared memory.
  2784. */
  2785. EBRDINIT(brdp);
  2786. brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
  2787. if (brdp->membase == NULL) {
  2788. retval = -ENOMEM;
  2789. goto err_reg;
  2790. }
  2791. /*
  2792. * Now that all specific code is set up, enable the shared memory and
  2793. * look for the a signature area that will tell us exactly what board
  2794. * this is, and how many ports.
  2795. */
  2796. EBRDENABLE(brdp);
  2797. sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  2798. memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
  2799. EBRDDISABLE(brdp);
  2800. if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
  2801. sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
  2802. sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
  2803. sig.magic3 != cpu_to_le16(ONB_MAGIC3)) {
  2804. retval = -ENODEV;
  2805. goto err_unmap;
  2806. }
  2807. /*
  2808. * Scan through the signature alive mask and calculate how many ports
  2809. * there are on this board.
  2810. */
  2811. brdp->nrpanels = 1;
  2812. if (sig.amask1) {
  2813. brdp->nrports = 32;
  2814. } else {
  2815. for (i = 0; (i < 16); i++) {
  2816. if (((sig.amask0 << i) & 0x8000) == 0)
  2817. break;
  2818. }
  2819. brdp->nrports = i;
  2820. }
  2821. brdp->panels[0] = brdp->nrports;
  2822. set_bit(BST_FOUND, &brdp->state);
  2823. return 0;
  2824. err_unmap:
  2825. iounmap(brdp->membase);
  2826. brdp->membase = NULL;
  2827. err_reg:
  2828. release_region(brdp->iobase, brdp->iosize);
  2829. err:
  2830. return retval;
  2831. }
  2832. /*****************************************************************************/
  2833. /*
  2834. * Start up a running board. This routine is only called after the
  2835. * code has been down loaded to the board and is operational. It will
  2836. * read in the memory map, and get the show on the road...
  2837. */
  2838. static int stli_startbrd(struct stlibrd *brdp)
  2839. {
  2840. cdkhdr_t __iomem *hdrp;
  2841. cdkmem_t __iomem *memp;
  2842. cdkasy_t __iomem *ap;
  2843. unsigned long flags;
  2844. unsigned int portnr, nrdevs, i;
  2845. struct stliport *portp;
  2846. int rc = 0;
  2847. u32 memoff;
  2848. spin_lock_irqsave(&brd_lock, flags);
  2849. EBRDENABLE(brdp);
  2850. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2851. nrdevs = hdrp->nrdevs;
  2852. #if 0
  2853. printk("%s(%d): CDK version %d.%d.%d --> "
  2854. "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
  2855. __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
  2856. readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
  2857. readl(&hdrp->slavep));
  2858. #endif
  2859. if (nrdevs < (brdp->nrports + 1)) {
  2860. printk(KERN_ERR "istallion: slave failed to allocate memory for "
  2861. "all devices, devices=%d\n", nrdevs);
  2862. brdp->nrports = nrdevs - 1;
  2863. }
  2864. brdp->nrdevs = nrdevs;
  2865. brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
  2866. brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
  2867. brdp->bitsize = (nrdevs + 7) / 8;
  2868. memoff = readl(&hdrp->memp);
  2869. if (memoff > brdp->memsize) {
  2870. printk(KERN_ERR "istallion: corrupted shared memory region?\n");
  2871. rc = -EIO;
  2872. goto stli_donestartup;
  2873. }
  2874. memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
  2875. if (readw(&memp->dtype) != TYP_ASYNCTRL) {
  2876. printk(KERN_ERR "istallion: no slave control device found\n");
  2877. goto stli_donestartup;
  2878. }
  2879. memp++;
  2880. /*
  2881. * Cycle through memory allocation of each port. We are guaranteed to
  2882. * have all ports inside the first page of slave window, so no need to
  2883. * change pages while reading memory map.
  2884. */
  2885. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
  2886. if (readw(&memp->dtype) != TYP_ASYNC)
  2887. break;
  2888. portp = brdp->ports[portnr];
  2889. if (portp == NULL)
  2890. break;
  2891. portp->devnr = i;
  2892. portp->addr = readl(&memp->offset);
  2893. portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
  2894. portp->portidx = (unsigned char) (i / 8);
  2895. portp->portbit = (unsigned char) (0x1 << (i % 8));
  2896. }
  2897. writeb(0xff, &hdrp->slavereq);
  2898. /*
  2899. * For each port setup a local copy of the RX and TX buffer offsets
  2900. * and sizes. We do this separate from the above, because we need to
  2901. * move the shared memory page...
  2902. */
  2903. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
  2904. portp = brdp->ports[portnr];
  2905. if (portp == NULL)
  2906. break;
  2907. if (portp->addr == 0)
  2908. break;
  2909. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  2910. if (ap != NULL) {
  2911. portp->rxsize = readw(&ap->rxq.size);
  2912. portp->txsize = readw(&ap->txq.size);
  2913. portp->rxoffset = readl(&ap->rxq.offset);
  2914. portp->txoffset = readl(&ap->txq.offset);
  2915. }
  2916. }
  2917. stli_donestartup:
  2918. EBRDDISABLE(brdp);
  2919. spin_unlock_irqrestore(&brd_lock, flags);
  2920. if (rc == 0)
  2921. set_bit(BST_STARTED, &brdp->state);
  2922. if (! stli_timeron) {
  2923. stli_timeron++;
  2924. mod_timer(&stli_timerlist, STLI_TIMEOUT);
  2925. }
  2926. return rc;
  2927. }
  2928. /*****************************************************************************/
  2929. /*
  2930. * Probe and initialize the specified board.
  2931. */
  2932. static int __devinit stli_brdinit(struct stlibrd *brdp)
  2933. {
  2934. int retval;
  2935. switch (brdp->brdtype) {
  2936. case BRD_ECP:
  2937. case BRD_ECPE:
  2938. case BRD_ECPMC:
  2939. case BRD_ECPPCI:
  2940. retval = stli_initecp(brdp);
  2941. break;
  2942. case BRD_ONBOARD:
  2943. case BRD_ONBOARDE:
  2944. case BRD_ONBOARD2:
  2945. case BRD_BRUMBY4:
  2946. case BRD_STALLION:
  2947. retval = stli_initonb(brdp);
  2948. break;
  2949. default:
  2950. printk(KERN_ERR "istallion: board=%d is unknown board "
  2951. "type=%d\n", brdp->brdnr, brdp->brdtype);
  2952. retval = -ENODEV;
  2953. }
  2954. if (retval)
  2955. return retval;
  2956. stli_initports(brdp);
  2957. printk(KERN_INFO "istallion: %s found, board=%d io=%x mem=%x "
  2958. "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
  2959. brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
  2960. brdp->nrpanels, brdp->nrports);
  2961. return 0;
  2962. }
  2963. #if STLI_EISAPROBE != 0
  2964. /*****************************************************************************/
  2965. /*
  2966. * Probe around trying to find where the EISA boards shared memory
  2967. * might be. This is a bit if hack, but it is the best we can do.
  2968. */
  2969. static int stli_eisamemprobe(struct stlibrd *brdp)
  2970. {
  2971. cdkecpsig_t ecpsig, __iomem *ecpsigp;
  2972. cdkonbsig_t onbsig, __iomem *onbsigp;
  2973. int i, foundit;
  2974. /*
  2975. * First up we reset the board, to get it into a known state. There
  2976. * is only 2 board types here we need to worry about. Don;t use the
  2977. * standard board init routine here, it programs up the shared
  2978. * memory address, and we don't know it yet...
  2979. */
  2980. if (brdp->brdtype == BRD_ECPE) {
  2981. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2982. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2983. udelay(10);
  2984. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2985. udelay(500);
  2986. stli_ecpeienable(brdp);
  2987. } else if (brdp->brdtype == BRD_ONBOARDE) {
  2988. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  2989. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2990. udelay(10);
  2991. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2992. mdelay(100);
  2993. outb(0x1, brdp->iobase);
  2994. mdelay(1);
  2995. stli_onbeenable(brdp);
  2996. } else {
  2997. return -ENODEV;
  2998. }
  2999. foundit = 0;
  3000. brdp->memsize = ECP_MEMSIZE;
  3001. /*
  3002. * Board shared memory is enabled, so now we have a poke around and
  3003. * see if we can find it.
  3004. */
  3005. for (i = 0; (i < stli_eisamempsize); i++) {
  3006. brdp->memaddr = stli_eisamemprobeaddrs[i];
  3007. brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
  3008. if (brdp->membase == NULL)
  3009. continue;
  3010. if (brdp->brdtype == BRD_ECPE) {
  3011. ecpsigp = stli_ecpeigetmemptr(brdp,
  3012. CDK_SIGADDR, __LINE__);
  3013. memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
  3014. if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
  3015. foundit = 1;
  3016. } else {
  3017. onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
  3018. CDK_SIGADDR, __LINE__);
  3019. memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
  3020. if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
  3021. (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
  3022. (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
  3023. (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
  3024. foundit = 1;
  3025. }
  3026. iounmap(brdp->membase);
  3027. if (foundit)
  3028. break;
  3029. }
  3030. /*
  3031. * Regardless of whether we found the shared memory or not we must
  3032. * disable the region. After that return success or failure.
  3033. */
  3034. if (brdp->brdtype == BRD_ECPE)
  3035. stli_ecpeidisable(brdp);
  3036. else
  3037. stli_onbedisable(brdp);
  3038. if (! foundit) {
  3039. brdp->memaddr = 0;
  3040. brdp->membase = NULL;
  3041. printk(KERN_ERR "istallion: failed to probe shared memory "
  3042. "region for %s in EISA slot=%d\n",
  3043. stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
  3044. return -ENODEV;
  3045. }
  3046. return 0;
  3047. }
  3048. #endif
  3049. static int stli_getbrdnr(void)
  3050. {
  3051. unsigned int i;
  3052. for (i = 0; i < STL_MAXBRDS; i++) {
  3053. if (!stli_brds[i]) {
  3054. if (i >= stli_nrbrds)
  3055. stli_nrbrds = i + 1;
  3056. return i;
  3057. }
  3058. }
  3059. return -1;
  3060. }
  3061. #if STLI_EISAPROBE != 0
  3062. /*****************************************************************************/
  3063. /*
  3064. * Probe around and try to find any EISA boards in system. The biggest
  3065. * problem here is finding out what memory address is associated with
  3066. * an EISA board after it is found. The registers of the ECPE and
  3067. * ONboardE are not readable - so we can't read them from there. We
  3068. * don't have access to the EISA CMOS (or EISA BIOS) so we don't
  3069. * actually have any way to find out the real value. The best we can
  3070. * do is go probing around in the usual places hoping we can find it.
  3071. */
  3072. static int __init stli_findeisabrds(void)
  3073. {
  3074. struct stlibrd *brdp;
  3075. unsigned int iobase, eid, i;
  3076. int brdnr, found = 0;
  3077. /*
  3078. * Firstly check if this is an EISA system. If this is not an EISA system then
  3079. * don't bother going any further!
  3080. */
  3081. if (EISA_bus)
  3082. return 0;
  3083. /*
  3084. * Looks like an EISA system, so go searching for EISA boards.
  3085. */
  3086. for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
  3087. outb(0xff, (iobase + 0xc80));
  3088. eid = inb(iobase + 0xc80);
  3089. eid |= inb(iobase + 0xc81) << 8;
  3090. if (eid != STL_EISAID)
  3091. continue;
  3092. /*
  3093. * We have found a board. Need to check if this board was
  3094. * statically configured already (just in case!).
  3095. */
  3096. for (i = 0; (i < STL_MAXBRDS); i++) {
  3097. brdp = stli_brds[i];
  3098. if (brdp == NULL)
  3099. continue;
  3100. if (brdp->iobase == iobase)
  3101. break;
  3102. }
  3103. if (i < STL_MAXBRDS)
  3104. continue;
  3105. /*
  3106. * We have found a Stallion board and it is not configured already.
  3107. * Allocate a board structure and initialize it.
  3108. */
  3109. if ((brdp = stli_allocbrd()) == NULL)
  3110. return found ? : -ENOMEM;
  3111. brdnr = stli_getbrdnr();
  3112. if (brdnr < 0)
  3113. return found ? : -ENOMEM;
  3114. brdp->brdnr = (unsigned int)brdnr;
  3115. eid = inb(iobase + 0xc82);
  3116. if (eid == ECP_EISAID)
  3117. brdp->brdtype = BRD_ECPE;
  3118. else if (eid == ONB_EISAID)
  3119. brdp->brdtype = BRD_ONBOARDE;
  3120. else
  3121. brdp->brdtype = BRD_UNKNOWN;
  3122. brdp->iobase = iobase;
  3123. outb(0x1, (iobase + 0xc84));
  3124. if (stli_eisamemprobe(brdp))
  3125. outb(0, (iobase + 0xc84));
  3126. if (stli_brdinit(brdp) < 0) {
  3127. kfree(brdp);
  3128. continue;
  3129. }
  3130. stli_brds[brdp->brdnr] = brdp;
  3131. found++;
  3132. for (i = 0; i < brdp->nrports; i++)
  3133. tty_register_device(stli_serial,
  3134. brdp->brdnr * STL_MAXPORTS + i, NULL);
  3135. }
  3136. return found;
  3137. }
  3138. #else
  3139. static inline int stli_findeisabrds(void) { return 0; }
  3140. #endif
  3141. /*****************************************************************************/
  3142. /*
  3143. * Find the next available board number that is free.
  3144. */
  3145. /*****************************************************************************/
  3146. /*
  3147. * We have a Stallion board. Allocate a board structure and
  3148. * initialize it. Read its IO and MEMORY resources from PCI
  3149. * configuration space.
  3150. */
  3151. static int __devinit stli_pciprobe(struct pci_dev *pdev,
  3152. const struct pci_device_id *ent)
  3153. {
  3154. struct stlibrd *brdp;
  3155. unsigned int i;
  3156. int brdnr, retval = -EIO;
  3157. retval = pci_enable_device(pdev);
  3158. if (retval)
  3159. goto err;
  3160. brdp = stli_allocbrd();
  3161. if (brdp == NULL) {
  3162. retval = -ENOMEM;
  3163. goto err;
  3164. }
  3165. mutex_lock(&stli_brdslock);
  3166. brdnr = stli_getbrdnr();
  3167. if (brdnr < 0) {
  3168. printk(KERN_INFO "istallion: too many boards found, "
  3169. "maximum supported %d\n", STL_MAXBRDS);
  3170. mutex_unlock(&stli_brdslock);
  3171. retval = -EIO;
  3172. goto err_fr;
  3173. }
  3174. brdp->brdnr = (unsigned int)brdnr;
  3175. stli_brds[brdp->brdnr] = brdp;
  3176. mutex_unlock(&stli_brdslock);
  3177. brdp->brdtype = BRD_ECPPCI;
  3178. /*
  3179. * We have all resources from the board, so lets setup the actual
  3180. * board structure now.
  3181. */
  3182. brdp->iobase = pci_resource_start(pdev, 3);
  3183. brdp->memaddr = pci_resource_start(pdev, 2);
  3184. retval = stli_brdinit(brdp);
  3185. if (retval)
  3186. goto err_null;
  3187. set_bit(BST_PROBED, &brdp->state);
  3188. pci_set_drvdata(pdev, brdp);
  3189. EBRDENABLE(brdp);
  3190. brdp->enable = NULL;
  3191. brdp->disable = NULL;
  3192. for (i = 0; i < brdp->nrports; i++)
  3193. tty_register_device(stli_serial, brdp->brdnr * STL_MAXPORTS + i,
  3194. &pdev->dev);
  3195. return 0;
  3196. err_null:
  3197. stli_brds[brdp->brdnr] = NULL;
  3198. err_fr:
  3199. kfree(brdp);
  3200. err:
  3201. return retval;
  3202. }
  3203. static void __devexit stli_pciremove(struct pci_dev *pdev)
  3204. {
  3205. struct stlibrd *brdp = pci_get_drvdata(pdev);
  3206. stli_cleanup_ports(brdp);
  3207. iounmap(brdp->membase);
  3208. if (brdp->iosize > 0)
  3209. release_region(brdp->iobase, brdp->iosize);
  3210. stli_brds[brdp->brdnr] = NULL;
  3211. kfree(brdp);
  3212. }
  3213. static struct pci_driver stli_pcidriver = {
  3214. .name = "istallion",
  3215. .id_table = istallion_pci_tbl,
  3216. .probe = stli_pciprobe,
  3217. .remove = __devexit_p(stli_pciremove)
  3218. };
  3219. /*****************************************************************************/
  3220. /*
  3221. * Allocate a new board structure. Fill out the basic info in it.
  3222. */
  3223. static struct stlibrd *stli_allocbrd(void)
  3224. {
  3225. struct stlibrd *brdp;
  3226. brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
  3227. if (!brdp) {
  3228. printk(KERN_ERR "istallion: failed to allocate memory "
  3229. "(size=%Zd)\n", sizeof(struct stlibrd));
  3230. return NULL;
  3231. }
  3232. brdp->magic = STLI_BOARDMAGIC;
  3233. return brdp;
  3234. }
  3235. /*****************************************************************************/
  3236. /*
  3237. * Scan through all the boards in the configuration and see what we
  3238. * can find.
  3239. */
  3240. static int __init stli_initbrds(void)
  3241. {
  3242. struct stlibrd *brdp, *nxtbrdp;
  3243. struct stlconf conf;
  3244. unsigned int i, j, found = 0;
  3245. int retval;
  3246. for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
  3247. stli_nrbrds++) {
  3248. memset(&conf, 0, sizeof(conf));
  3249. if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
  3250. continue;
  3251. if ((brdp = stli_allocbrd()) == NULL)
  3252. continue;
  3253. brdp->brdnr = stli_nrbrds;
  3254. brdp->brdtype = conf.brdtype;
  3255. brdp->iobase = conf.ioaddr1;
  3256. brdp->memaddr = conf.memaddr;
  3257. if (stli_brdinit(brdp) < 0) {
  3258. kfree(brdp);
  3259. continue;
  3260. }
  3261. stli_brds[brdp->brdnr] = brdp;
  3262. found++;
  3263. for (i = 0; i < brdp->nrports; i++)
  3264. tty_register_device(stli_serial,
  3265. brdp->brdnr * STL_MAXPORTS + i, NULL);
  3266. }
  3267. retval = stli_findeisabrds();
  3268. if (retval > 0)
  3269. found += retval;
  3270. /*
  3271. * All found boards are initialized. Now for a little optimization, if
  3272. * no boards are sharing the "shared memory" regions then we can just
  3273. * leave them all enabled. This is in fact the usual case.
  3274. */
  3275. stli_shared = 0;
  3276. if (stli_nrbrds > 1) {
  3277. for (i = 0; (i < stli_nrbrds); i++) {
  3278. brdp = stli_brds[i];
  3279. if (brdp == NULL)
  3280. continue;
  3281. for (j = i + 1; (j < stli_nrbrds); j++) {
  3282. nxtbrdp = stli_brds[j];
  3283. if (nxtbrdp == NULL)
  3284. continue;
  3285. if ((brdp->membase >= nxtbrdp->membase) &&
  3286. (brdp->membase <= (nxtbrdp->membase +
  3287. nxtbrdp->memsize - 1))) {
  3288. stli_shared++;
  3289. break;
  3290. }
  3291. }
  3292. }
  3293. }
  3294. if (stli_shared == 0) {
  3295. for (i = 0; (i < stli_nrbrds); i++) {
  3296. brdp = stli_brds[i];
  3297. if (brdp == NULL)
  3298. continue;
  3299. if (test_bit(BST_FOUND, &brdp->state)) {
  3300. EBRDENABLE(brdp);
  3301. brdp->enable = NULL;
  3302. brdp->disable = NULL;
  3303. }
  3304. }
  3305. }
  3306. retval = pci_register_driver(&stli_pcidriver);
  3307. if (retval && found == 0) {
  3308. printk(KERN_ERR "Neither isa nor eisa cards found nor pci "
  3309. "driver can be registered!\n");
  3310. goto err;
  3311. }
  3312. return 0;
  3313. err:
  3314. return retval;
  3315. }
  3316. /*****************************************************************************/
  3317. /*
  3318. * Code to handle an "staliomem" read operation. This device is the
  3319. * contents of the board shared memory. It is used for down loading
  3320. * the slave image (and debugging :-)
  3321. */
  3322. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
  3323. {
  3324. unsigned long flags;
  3325. void __iomem *memptr;
  3326. struct stlibrd *brdp;
  3327. unsigned int brdnr;
  3328. int size, n;
  3329. void *p;
  3330. loff_t off = *offp;
  3331. brdnr = iminor(fp->f_path.dentry->d_inode);
  3332. if (brdnr >= stli_nrbrds)
  3333. return -ENODEV;
  3334. brdp = stli_brds[brdnr];
  3335. if (brdp == NULL)
  3336. return -ENODEV;
  3337. if (brdp->state == 0)
  3338. return -ENODEV;
  3339. if (off >= brdp->memsize || off + count < off)
  3340. return 0;
  3341. size = min(count, (size_t)(brdp->memsize - off));
  3342. /*
  3343. * Copy the data a page at a time
  3344. */
  3345. p = (void *)__get_free_page(GFP_KERNEL);
  3346. if(p == NULL)
  3347. return -ENOMEM;
  3348. while (size > 0) {
  3349. spin_lock_irqsave(&brd_lock, flags);
  3350. EBRDENABLE(brdp);
  3351. memptr = EBRDGETMEMPTR(brdp, off);
  3352. n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3353. n = min(n, (int)PAGE_SIZE);
  3354. memcpy_fromio(p, memptr, n);
  3355. EBRDDISABLE(brdp);
  3356. spin_unlock_irqrestore(&brd_lock, flags);
  3357. if (copy_to_user(buf, p, n)) {
  3358. count = -EFAULT;
  3359. goto out;
  3360. }
  3361. off += n;
  3362. buf += n;
  3363. size -= n;
  3364. }
  3365. out:
  3366. *offp = off;
  3367. free_page((unsigned long)p);
  3368. return count;
  3369. }
  3370. /*****************************************************************************/
  3371. /*
  3372. * Code to handle an "staliomem" write operation. This device is the
  3373. * contents of the board shared memory. It is used for down loading
  3374. * the slave image (and debugging :-)
  3375. *
  3376. * FIXME: copy under lock
  3377. */
  3378. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
  3379. {
  3380. unsigned long flags;
  3381. void __iomem *memptr;
  3382. struct stlibrd *brdp;
  3383. char __user *chbuf;
  3384. unsigned int brdnr;
  3385. int size, n;
  3386. void *p;
  3387. loff_t off = *offp;
  3388. brdnr = iminor(fp->f_path.dentry->d_inode);
  3389. if (brdnr >= stli_nrbrds)
  3390. return -ENODEV;
  3391. brdp = stli_brds[brdnr];
  3392. if (brdp == NULL)
  3393. return -ENODEV;
  3394. if (brdp->state == 0)
  3395. return -ENODEV;
  3396. if (off >= brdp->memsize || off + count < off)
  3397. return 0;
  3398. chbuf = (char __user *) buf;
  3399. size = min(count, (size_t)(brdp->memsize - off));
  3400. /*
  3401. * Copy the data a page at a time
  3402. */
  3403. p = (void *)__get_free_page(GFP_KERNEL);
  3404. if(p == NULL)
  3405. return -ENOMEM;
  3406. while (size > 0) {
  3407. n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3408. n = min(n, (int)PAGE_SIZE);
  3409. if (copy_from_user(p, chbuf, n)) {
  3410. if (count == 0)
  3411. count = -EFAULT;
  3412. goto out;
  3413. }
  3414. spin_lock_irqsave(&brd_lock, flags);
  3415. EBRDENABLE(brdp);
  3416. memptr = EBRDGETMEMPTR(brdp, off);
  3417. memcpy_toio(memptr, p, n);
  3418. EBRDDISABLE(brdp);
  3419. spin_unlock_irqrestore(&brd_lock, flags);
  3420. off += n;
  3421. chbuf += n;
  3422. size -= n;
  3423. }
  3424. out:
  3425. free_page((unsigned long) p);
  3426. *offp = off;
  3427. return count;
  3428. }
  3429. /*****************************************************************************/
  3430. /*
  3431. * Return the board stats structure to user app.
  3432. */
  3433. static int stli_getbrdstats(combrd_t __user *bp)
  3434. {
  3435. struct stlibrd *brdp;
  3436. unsigned int i;
  3437. combrd_t stli_brdstats;
  3438. if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
  3439. return -EFAULT;
  3440. if (stli_brdstats.brd >= STL_MAXBRDS)
  3441. return -ENODEV;
  3442. brdp = stli_brds[stli_brdstats.brd];
  3443. if (brdp == NULL)
  3444. return -ENODEV;
  3445. memset(&stli_brdstats, 0, sizeof(combrd_t));
  3446. stli_brdstats.brd = brdp->brdnr;
  3447. stli_brdstats.type = brdp->brdtype;
  3448. stli_brdstats.hwid = 0;
  3449. stli_brdstats.state = brdp->state;
  3450. stli_brdstats.ioaddr = brdp->iobase;
  3451. stli_brdstats.memaddr = brdp->memaddr;
  3452. stli_brdstats.nrpanels = brdp->nrpanels;
  3453. stli_brdstats.nrports = brdp->nrports;
  3454. for (i = 0; (i < brdp->nrpanels); i++) {
  3455. stli_brdstats.panels[i].panel = i;
  3456. stli_brdstats.panels[i].hwid = brdp->panelids[i];
  3457. stli_brdstats.panels[i].nrports = brdp->panels[i];
  3458. }
  3459. if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
  3460. return -EFAULT;
  3461. return 0;
  3462. }
  3463. /*****************************************************************************/
  3464. /*
  3465. * Resolve the referenced port number into a port struct pointer.
  3466. */
  3467. static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
  3468. unsigned int portnr)
  3469. {
  3470. struct stlibrd *brdp;
  3471. unsigned int i;
  3472. if (brdnr >= STL_MAXBRDS)
  3473. return NULL;
  3474. brdp = stli_brds[brdnr];
  3475. if (brdp == NULL)
  3476. return NULL;
  3477. for (i = 0; (i < panelnr); i++)
  3478. portnr += brdp->panels[i];
  3479. if (portnr >= brdp->nrports)
  3480. return NULL;
  3481. return brdp->ports[portnr];
  3482. }
  3483. /*****************************************************************************/
  3484. /*
  3485. * Return the port stats structure to user app. A NULL port struct
  3486. * pointer passed in means that we need to find out from the app
  3487. * what port to get stats for (used through board control device).
  3488. */
  3489. static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp)
  3490. {
  3491. unsigned long flags;
  3492. struct stlibrd *brdp;
  3493. int rc;
  3494. memset(&stli_comstats, 0, sizeof(comstats_t));
  3495. if (portp == NULL)
  3496. return -ENODEV;
  3497. brdp = stli_brds[portp->brdnr];
  3498. if (brdp == NULL)
  3499. return -ENODEV;
  3500. mutex_lock(&portp->port.mutex);
  3501. if (test_bit(BST_STARTED, &brdp->state)) {
  3502. if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
  3503. &stli_cdkstats, sizeof(asystats_t), 1)) < 0) {
  3504. mutex_unlock(&portp->port.mutex);
  3505. return rc;
  3506. }
  3507. } else {
  3508. memset(&stli_cdkstats, 0, sizeof(asystats_t));
  3509. }
  3510. stli_comstats.brd = portp->brdnr;
  3511. stli_comstats.panel = portp->panelnr;
  3512. stli_comstats.port = portp->portnr;
  3513. stli_comstats.state = portp->state;
  3514. stli_comstats.flags = portp->port.flags;
  3515. spin_lock_irqsave(&brd_lock, flags);
  3516. if (tty != NULL) {
  3517. if (portp->port.tty == tty) {
  3518. stli_comstats.ttystate = tty->flags;
  3519. stli_comstats.rxbuffered = -1;
  3520. if (tty->termios != NULL) {
  3521. stli_comstats.cflags = tty->termios->c_cflag;
  3522. stli_comstats.iflags = tty->termios->c_iflag;
  3523. stli_comstats.oflags = tty->termios->c_oflag;
  3524. stli_comstats.lflags = tty->termios->c_lflag;
  3525. }
  3526. }
  3527. }
  3528. spin_unlock_irqrestore(&brd_lock, flags);
  3529. stli_comstats.txtotal = stli_cdkstats.txchars;
  3530. stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
  3531. stli_comstats.txbuffered = stli_cdkstats.txringq;
  3532. stli_comstats.rxbuffered += stli_cdkstats.rxringq;
  3533. stli_comstats.rxoverrun = stli_cdkstats.overruns;
  3534. stli_comstats.rxparity = stli_cdkstats.parity;
  3535. stli_comstats.rxframing = stli_cdkstats.framing;
  3536. stli_comstats.rxlost = stli_cdkstats.ringover;
  3537. stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
  3538. stli_comstats.txbreaks = stli_cdkstats.txbreaks;
  3539. stli_comstats.txxon = stli_cdkstats.txstart;
  3540. stli_comstats.txxoff = stli_cdkstats.txstop;
  3541. stli_comstats.rxxon = stli_cdkstats.rxstart;
  3542. stli_comstats.rxxoff = stli_cdkstats.rxstop;
  3543. stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
  3544. stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
  3545. stli_comstats.modem = stli_cdkstats.dcdcnt;
  3546. stli_comstats.hwid = stli_cdkstats.hwid;
  3547. stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
  3548. mutex_unlock(&portp->port.mutex);
  3549. return 0;
  3550. }
  3551. /*****************************************************************************/
  3552. /*
  3553. * Return the port stats structure to user app. A NULL port struct
  3554. * pointer passed in means that we need to find out from the app
  3555. * what port to get stats for (used through board control device).
  3556. */
  3557. static int stli_getportstats(struct tty_struct *tty, struct stliport *portp,
  3558. comstats_t __user *cp)
  3559. {
  3560. struct stlibrd *brdp;
  3561. int rc;
  3562. if (!portp) {
  3563. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3564. return -EFAULT;
  3565. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3566. stli_comstats.port);
  3567. if (!portp)
  3568. return -ENODEV;
  3569. }
  3570. brdp = stli_brds[portp->brdnr];
  3571. if (!brdp)
  3572. return -ENODEV;
  3573. if ((rc = stli_portcmdstats(tty, portp)) < 0)
  3574. return rc;
  3575. return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
  3576. -EFAULT : 0;
  3577. }
  3578. /*****************************************************************************/
  3579. /*
  3580. * Clear the port stats structure. We also return it zeroed out...
  3581. */
  3582. static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
  3583. {
  3584. struct stlibrd *brdp;
  3585. int rc;
  3586. if (!portp) {
  3587. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3588. return -EFAULT;
  3589. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3590. stli_comstats.port);
  3591. if (!portp)
  3592. return -ENODEV;
  3593. }
  3594. brdp = stli_brds[portp->brdnr];
  3595. if (!brdp)
  3596. return -ENODEV;
  3597. mutex_lock(&portp->port.mutex);
  3598. if (test_bit(BST_STARTED, &brdp->state)) {
  3599. if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0) {
  3600. mutex_unlock(&portp->port.mutex);
  3601. return rc;
  3602. }
  3603. }
  3604. memset(&stli_comstats, 0, sizeof(comstats_t));
  3605. stli_comstats.brd = portp->brdnr;
  3606. stli_comstats.panel = portp->panelnr;
  3607. stli_comstats.port = portp->portnr;
  3608. mutex_unlock(&portp->port.mutex);
  3609. if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
  3610. return -EFAULT;
  3611. return 0;
  3612. }
  3613. /*****************************************************************************/
  3614. /*
  3615. * Return the entire driver ports structure to a user app.
  3616. */
  3617. static int stli_getportstruct(struct stliport __user *arg)
  3618. {
  3619. struct stliport stli_dummyport;
  3620. struct stliport *portp;
  3621. if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
  3622. return -EFAULT;
  3623. portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
  3624. stli_dummyport.portnr);
  3625. if (!portp)
  3626. return -ENODEV;
  3627. if (copy_to_user(arg, portp, sizeof(struct stliport)))
  3628. return -EFAULT;
  3629. return 0;
  3630. }
  3631. /*****************************************************************************/
  3632. /*
  3633. * Return the entire driver board structure to a user app.
  3634. */
  3635. static int stli_getbrdstruct(struct stlibrd __user *arg)
  3636. {
  3637. struct stlibrd stli_dummybrd;
  3638. struct stlibrd *brdp;
  3639. if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
  3640. return -EFAULT;
  3641. if (stli_dummybrd.brdnr >= STL_MAXBRDS)
  3642. return -ENODEV;
  3643. brdp = stli_brds[stli_dummybrd.brdnr];
  3644. if (!brdp)
  3645. return -ENODEV;
  3646. if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
  3647. return -EFAULT;
  3648. return 0;
  3649. }
  3650. /*****************************************************************************/
  3651. /*
  3652. * The "staliomem" device is also required to do some special operations on
  3653. * the board. We need to be able to send an interrupt to the board,
  3654. * reset it, and start/stop it.
  3655. */
  3656. static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
  3657. {
  3658. struct stlibrd *brdp;
  3659. int brdnr, rc, done;
  3660. void __user *argp = (void __user *)arg;
  3661. /*
  3662. * First up handle the board independent ioctls.
  3663. */
  3664. done = 0;
  3665. rc = 0;
  3666. switch (cmd) {
  3667. case COM_GETPORTSTATS:
  3668. rc = stli_getportstats(NULL, NULL, argp);
  3669. done++;
  3670. break;
  3671. case COM_CLRPORTSTATS:
  3672. rc = stli_clrportstats(NULL, argp);
  3673. done++;
  3674. break;
  3675. case COM_GETBRDSTATS:
  3676. rc = stli_getbrdstats(argp);
  3677. done++;
  3678. break;
  3679. case COM_READPORT:
  3680. rc = stli_getportstruct(argp);
  3681. done++;
  3682. break;
  3683. case COM_READBOARD:
  3684. rc = stli_getbrdstruct(argp);
  3685. done++;
  3686. break;
  3687. }
  3688. if (done)
  3689. return rc;
  3690. /*
  3691. * Now handle the board specific ioctls. These all depend on the
  3692. * minor number of the device they were called from.
  3693. */
  3694. brdnr = iminor(fp->f_dentry->d_inode);
  3695. if (brdnr >= STL_MAXBRDS)
  3696. return -ENODEV;
  3697. brdp = stli_brds[brdnr];
  3698. if (!brdp)
  3699. return -ENODEV;
  3700. if (brdp->state == 0)
  3701. return -ENODEV;
  3702. switch (cmd) {
  3703. case STL_BINTR:
  3704. EBRDINTR(brdp);
  3705. break;
  3706. case STL_BSTART:
  3707. rc = stli_startbrd(brdp);
  3708. break;
  3709. case STL_BSTOP:
  3710. clear_bit(BST_STARTED, &brdp->state);
  3711. break;
  3712. case STL_BRESET:
  3713. clear_bit(BST_STARTED, &brdp->state);
  3714. EBRDRESET(brdp);
  3715. if (stli_shared == 0) {
  3716. if (brdp->reenable != NULL)
  3717. (* brdp->reenable)(brdp);
  3718. }
  3719. break;
  3720. default:
  3721. rc = -ENOIOCTLCMD;
  3722. break;
  3723. }
  3724. return rc;
  3725. }
  3726. static const struct tty_operations stli_ops = {
  3727. .open = stli_open,
  3728. .close = stli_close,
  3729. .write = stli_write,
  3730. .put_char = stli_putchar,
  3731. .flush_chars = stli_flushchars,
  3732. .write_room = stli_writeroom,
  3733. .chars_in_buffer = stli_charsinbuffer,
  3734. .ioctl = stli_ioctl,
  3735. .set_termios = stli_settermios,
  3736. .throttle = stli_throttle,
  3737. .unthrottle = stli_unthrottle,
  3738. .stop = stli_stop,
  3739. .start = stli_start,
  3740. .hangup = stli_hangup,
  3741. .flush_buffer = stli_flushbuffer,
  3742. .break_ctl = stli_breakctl,
  3743. .wait_until_sent = stli_waituntilsent,
  3744. .send_xchar = stli_sendxchar,
  3745. .tiocmget = stli_tiocmget,
  3746. .tiocmset = stli_tiocmset,
  3747. .proc_fops = &stli_proc_fops,
  3748. };
  3749. static const struct tty_port_operations stli_port_ops = {
  3750. .carrier_raised = stli_carrier_raised,
  3751. .dtr_rts = stli_dtr_rts,
  3752. .activate = stli_activate,
  3753. .shutdown = stli_shutdown,
  3754. };
  3755. /*****************************************************************************/
  3756. /*
  3757. * Loadable module initialization stuff.
  3758. */
  3759. static void istallion_cleanup_isa(void)
  3760. {
  3761. struct stlibrd *brdp;
  3762. unsigned int j;
  3763. for (j = 0; (j < stli_nrbrds); j++) {
  3764. if ((brdp = stli_brds[j]) == NULL ||
  3765. test_bit(BST_PROBED, &brdp->state))
  3766. continue;
  3767. stli_cleanup_ports(brdp);
  3768. iounmap(brdp->membase);
  3769. if (brdp->iosize > 0)
  3770. release_region(brdp->iobase, brdp->iosize);
  3771. kfree(brdp);
  3772. stli_brds[j] = NULL;
  3773. }
  3774. }
  3775. static int __init istallion_module_init(void)
  3776. {
  3777. unsigned int i;
  3778. int retval;
  3779. printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
  3780. spin_lock_init(&stli_lock);
  3781. spin_lock_init(&brd_lock);
  3782. stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
  3783. if (!stli_txcookbuf) {
  3784. printk(KERN_ERR "istallion: failed to allocate memory "
  3785. "(size=%d)\n", STLI_TXBUFSIZE);
  3786. retval = -ENOMEM;
  3787. goto err;
  3788. }
  3789. stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  3790. if (!stli_serial) {
  3791. retval = -ENOMEM;
  3792. goto err_free;
  3793. }
  3794. stli_serial->owner = THIS_MODULE;
  3795. stli_serial->driver_name = stli_drvname;
  3796. stli_serial->name = stli_serialname;
  3797. stli_serial->major = STL_SERIALMAJOR;
  3798. stli_serial->minor_start = 0;
  3799. stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
  3800. stli_serial->subtype = SERIAL_TYPE_NORMAL;
  3801. stli_serial->init_termios = stli_deftermios;
  3802. stli_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  3803. tty_set_operations(stli_serial, &stli_ops);
  3804. retval = tty_register_driver(stli_serial);
  3805. if (retval) {
  3806. printk(KERN_ERR "istallion: failed to register serial driver\n");
  3807. goto err_ttyput;
  3808. }
  3809. retval = stli_initbrds();
  3810. if (retval)
  3811. goto err_ttyunr;
  3812. /*
  3813. * Set up a character driver for the shared memory region. We need this
  3814. * to down load the slave code image. Also it is a useful debugging tool.
  3815. */
  3816. retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem);
  3817. if (retval) {
  3818. printk(KERN_ERR "istallion: failed to register serial memory "
  3819. "device\n");
  3820. goto err_deinit;
  3821. }
  3822. istallion_class = class_create(THIS_MODULE, "staliomem");
  3823. for (i = 0; i < 4; i++)
  3824. device_create(istallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
  3825. NULL, "staliomem%d", i);
  3826. return 0;
  3827. err_deinit:
  3828. pci_unregister_driver(&stli_pcidriver);
  3829. istallion_cleanup_isa();
  3830. err_ttyunr:
  3831. tty_unregister_driver(stli_serial);
  3832. err_ttyput:
  3833. put_tty_driver(stli_serial);
  3834. err_free:
  3835. kfree(stli_txcookbuf);
  3836. err:
  3837. return retval;
  3838. }
  3839. /*****************************************************************************/
  3840. static void __exit istallion_module_exit(void)
  3841. {
  3842. unsigned int j;
  3843. printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
  3844. stli_drvversion);
  3845. if (stli_timeron) {
  3846. stli_timeron = 0;
  3847. del_timer_sync(&stli_timerlist);
  3848. }
  3849. unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
  3850. for (j = 0; j < 4; j++)
  3851. device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, j));
  3852. class_destroy(istallion_class);
  3853. pci_unregister_driver(&stli_pcidriver);
  3854. istallion_cleanup_isa();
  3855. tty_unregister_driver(stli_serial);
  3856. put_tty_driver(stli_serial);
  3857. kfree(stli_txcookbuf);
  3858. }
  3859. module_init(istallion_module_init);
  3860. module_exit(istallion_module_exit);