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