istallion.c 119 KB

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