istallion.c 120 KB

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