istallion.c 125 KB

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