istallion.c 121 KB

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