istallion.c 120 KB

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