istallion.c 123 KB

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