istallion.c 119 KB

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