stallion.c 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115
  1. /*****************************************************************************/
  2. /*
  3. * stallion.c -- stallion multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*****************************************************************************/
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/tty.h>
  30. #include <linux/tty_flip.h>
  31. #include <linux/serial.h>
  32. #include <linux/cd1400.h>
  33. #include <linux/sc26198.h>
  34. #include <linux/comstats.h>
  35. #include <linux/stallion.h>
  36. #include <linux/ioport.h>
  37. #include <linux/init.h>
  38. #include <linux/smp_lock.h>
  39. #include <linux/device.h>
  40. #include <linux/delay.h>
  41. #include <asm/io.h>
  42. #include <asm/uaccess.h>
  43. #ifdef CONFIG_PCI
  44. #include <linux/pci.h>
  45. #endif
  46. /*****************************************************************************/
  47. /*
  48. * Define different board types. Use the standard Stallion "assigned"
  49. * board numbers. Boards supported in this driver are abbreviated as
  50. * EIO = EasyIO and ECH = EasyConnection 8/32.
  51. */
  52. #define BRD_EASYIO 20
  53. #define BRD_ECH 21
  54. #define BRD_ECHMC 22
  55. #define BRD_ECHPCI 26
  56. #define BRD_ECH64PCI 27
  57. #define BRD_EASYIOPCI 28
  58. /*
  59. * Define a configuration structure to hold the board configuration.
  60. * Need to set this up in the code (for now) with the boards that are
  61. * to be configured into the system. This is what needs to be modified
  62. * when adding/removing/modifying boards. Each line entry in the
  63. * stl_brdconf[] array is a board. Each line contains io/irq/memory
  64. * ranges for that board (as well as what type of board it is).
  65. * Some examples:
  66. * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
  67. * This line would configure an EasyIO board (4 or 8, no difference),
  68. * at io address 2a0 and irq 10.
  69. * Another example:
  70. * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
  71. * This line will configure an EasyConnection 8/32 board at primary io
  72. * address 2a8, secondary io address 280 and irq 12.
  73. * Enter as many lines into this array as you want (only the first 4
  74. * will actually be used!). Any combination of EasyIO and EasyConnection
  75. * boards can be specified. EasyConnection 8/32 boards can share their
  76. * secondary io addresses between each other.
  77. *
  78. * NOTE: there is no need to put any entries in this table for PCI
  79. * boards. They will be found automatically by the driver - provided
  80. * PCI BIOS32 support is compiled into the kernel.
  81. */
  82. typedef struct {
  83. int brdtype;
  84. int ioaddr1;
  85. int ioaddr2;
  86. unsigned long memaddr;
  87. int irq;
  88. int irqtype;
  89. } stlconf_t;
  90. static stlconf_t stl_brdconf[] = {
  91. /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
  92. };
  93. static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
  94. /*****************************************************************************/
  95. /*
  96. * Define some important driver characteristics. Device major numbers
  97. * allocated as per Linux Device Registry.
  98. */
  99. #ifndef STL_SIOMEMMAJOR
  100. #define STL_SIOMEMMAJOR 28
  101. #endif
  102. #ifndef STL_SERIALMAJOR
  103. #define STL_SERIALMAJOR 24
  104. #endif
  105. #ifndef STL_CALLOUTMAJOR
  106. #define STL_CALLOUTMAJOR 25
  107. #endif
  108. /*
  109. * Set the TX buffer size. Bigger is better, but we don't want
  110. * to chew too much memory with buffers!
  111. */
  112. #define STL_TXBUFLOW 512
  113. #define STL_TXBUFSIZE 4096
  114. /*****************************************************************************/
  115. /*
  116. * Define our local driver identity first. Set up stuff to deal with
  117. * all the local structures required by a serial tty driver.
  118. */
  119. static char *stl_drvtitle = "Stallion Multiport Serial Driver";
  120. static char *stl_drvname = "stallion";
  121. static char *stl_drvversion = "5.6.0";
  122. static struct tty_driver *stl_serial;
  123. /*
  124. * Define a local default termios struct. All ports will be created
  125. * with this termios initially. Basically all it defines is a raw port
  126. * at 9600, 8 data bits, 1 stop bit.
  127. */
  128. static struct termios stl_deftermios = {
  129. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  130. .c_cc = INIT_C_CC,
  131. };
  132. /*
  133. * Define global stats structures. Not used often, and can be
  134. * re-used for each stats call.
  135. */
  136. static comstats_t stl_comstats;
  137. static combrd_t stl_brdstats;
  138. static stlbrd_t stl_dummybrd;
  139. static stlport_t stl_dummyport;
  140. /*
  141. * Define global place to put buffer overflow characters.
  142. */
  143. static char stl_unwanted[SC26198_RXFIFOSIZE];
  144. /*****************************************************************************/
  145. static stlbrd_t *stl_brds[STL_MAXBRDS];
  146. /*
  147. * Per board state flags. Used with the state field of the board struct.
  148. * Not really much here!
  149. */
  150. #define BRD_FOUND 0x1
  151. /*
  152. * Define the port structure istate flags. These set of flags are
  153. * modified at interrupt time - so setting and reseting them needs
  154. * to be atomic. Use the bit clear/setting routines for this.
  155. */
  156. #define ASYI_TXBUSY 1
  157. #define ASYI_TXLOW 2
  158. #define ASYI_DCDCHANGE 3
  159. #define ASYI_TXFLOWED 4
  160. /*
  161. * Define an array of board names as printable strings. Handy for
  162. * referencing boards when printing trace and stuff.
  163. */
  164. static char *stl_brdnames[] = {
  165. (char *) NULL,
  166. (char *) NULL,
  167. (char *) NULL,
  168. (char *) NULL,
  169. (char *) NULL,
  170. (char *) NULL,
  171. (char *) NULL,
  172. (char *) NULL,
  173. (char *) NULL,
  174. (char *) NULL,
  175. (char *) NULL,
  176. (char *) NULL,
  177. (char *) NULL,
  178. (char *) NULL,
  179. (char *) NULL,
  180. (char *) NULL,
  181. (char *) NULL,
  182. (char *) NULL,
  183. (char *) NULL,
  184. (char *) NULL,
  185. "EasyIO",
  186. "EC8/32-AT",
  187. "EC8/32-MC",
  188. (char *) NULL,
  189. (char *) NULL,
  190. (char *) NULL,
  191. "EC8/32-PCI",
  192. "EC8/64-PCI",
  193. "EasyIO-PCI",
  194. };
  195. /*****************************************************************************/
  196. /*
  197. * Define some string labels for arguments passed from the module
  198. * load line. These allow for easy board definitions, and easy
  199. * modification of the io, memory and irq resoucres.
  200. */
  201. static int stl_nargs = 0;
  202. static char *board0[4];
  203. static char *board1[4];
  204. static char *board2[4];
  205. static char *board3[4];
  206. static char **stl_brdsp[] = {
  207. (char **) &board0,
  208. (char **) &board1,
  209. (char **) &board2,
  210. (char **) &board3
  211. };
  212. /*
  213. * Define a set of common board names, and types. This is used to
  214. * parse any module arguments.
  215. */
  216. typedef struct stlbrdtype {
  217. char *name;
  218. int type;
  219. } stlbrdtype_t;
  220. static stlbrdtype_t stl_brdstr[] = {
  221. { "easyio", BRD_EASYIO },
  222. { "eio", BRD_EASYIO },
  223. { "20", BRD_EASYIO },
  224. { "ec8/32", BRD_ECH },
  225. { "ec8/32-at", BRD_ECH },
  226. { "ec8/32-isa", BRD_ECH },
  227. { "ech", BRD_ECH },
  228. { "echat", BRD_ECH },
  229. { "21", BRD_ECH },
  230. { "ec8/32-mc", BRD_ECHMC },
  231. { "ec8/32-mca", BRD_ECHMC },
  232. { "echmc", BRD_ECHMC },
  233. { "echmca", BRD_ECHMC },
  234. { "22", BRD_ECHMC },
  235. { "ec8/32-pc", BRD_ECHPCI },
  236. { "ec8/32-pci", BRD_ECHPCI },
  237. { "26", BRD_ECHPCI },
  238. { "ec8/64-pc", BRD_ECH64PCI },
  239. { "ec8/64-pci", BRD_ECH64PCI },
  240. { "ech-pci", BRD_ECH64PCI },
  241. { "echpci", BRD_ECH64PCI },
  242. { "echpc", BRD_ECH64PCI },
  243. { "27", BRD_ECH64PCI },
  244. { "easyio-pc", BRD_EASYIOPCI },
  245. { "easyio-pci", BRD_EASYIOPCI },
  246. { "eio-pci", BRD_EASYIOPCI },
  247. { "eiopci", BRD_EASYIOPCI },
  248. { "28", BRD_EASYIOPCI },
  249. };
  250. /*
  251. * Define the module agruments.
  252. */
  253. MODULE_AUTHOR("Greg Ungerer");
  254. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  255. MODULE_LICENSE("GPL");
  256. module_param_array(board0, charp, &stl_nargs, 0);
  257. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  258. module_param_array(board1, charp, &stl_nargs, 0);
  259. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  260. module_param_array(board2, charp, &stl_nargs, 0);
  261. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  262. module_param_array(board3, charp, &stl_nargs, 0);
  263. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  264. /*****************************************************************************/
  265. /*
  266. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  267. * to the directly accessible io ports of these boards (not the uarts -
  268. * they are in cd1400.h and sc26198.h).
  269. */
  270. #define EIO_8PORTRS 0x04
  271. #define EIO_4PORTRS 0x05
  272. #define EIO_8PORTDI 0x00
  273. #define EIO_8PORTM 0x06
  274. #define EIO_MK3 0x03
  275. #define EIO_IDBITMASK 0x07
  276. #define EIO_BRDMASK 0xf0
  277. #define ID_BRD4 0x10
  278. #define ID_BRD8 0x20
  279. #define ID_BRD16 0x30
  280. #define EIO_INTRPEND 0x08
  281. #define EIO_INTEDGE 0x00
  282. #define EIO_INTLEVEL 0x08
  283. #define EIO_0WS 0x10
  284. #define ECH_ID 0xa0
  285. #define ECH_IDBITMASK 0xe0
  286. #define ECH_BRDENABLE 0x08
  287. #define ECH_BRDDISABLE 0x00
  288. #define ECH_INTENABLE 0x01
  289. #define ECH_INTDISABLE 0x00
  290. #define ECH_INTLEVEL 0x02
  291. #define ECH_INTEDGE 0x00
  292. #define ECH_INTRPEND 0x01
  293. #define ECH_BRDRESET 0x01
  294. #define ECHMC_INTENABLE 0x01
  295. #define ECHMC_BRDRESET 0x02
  296. #define ECH_PNLSTATUS 2
  297. #define ECH_PNL16PORT 0x20
  298. #define ECH_PNLIDMASK 0x07
  299. #define ECH_PNLXPID 0x40
  300. #define ECH_PNLINTRPEND 0x80
  301. #define ECH_ADDR2MASK 0x1e0
  302. /*
  303. * Define the vector mapping bits for the programmable interrupt board
  304. * hardware. These bits encode the interrupt for the board to use - it
  305. * is software selectable (except the EIO-8M).
  306. */
  307. static unsigned char stl_vecmap[] = {
  308. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  309. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  310. };
  311. /*
  312. * Lock ordering is that you may not take stallion_lock holding
  313. * brd_lock.
  314. */
  315. static spinlock_t brd_lock; /* Guard the board mapping */
  316. static spinlock_t stallion_lock; /* Guard the tty driver */
  317. /*
  318. * Set up enable and disable macros for the ECH boards. They require
  319. * the secondary io address space to be activated and deactivated.
  320. * This way all ECH boards can share their secondary io region.
  321. * If this is an ECH-PCI board then also need to set the page pointer
  322. * to point to the correct page.
  323. */
  324. #define BRDENABLE(brdnr,pagenr) \
  325. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  326. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  327. stl_brds[(brdnr)]->ioctrl); \
  328. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  329. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  330. #define BRDDISABLE(brdnr) \
  331. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  332. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  333. stl_brds[(brdnr)]->ioctrl);
  334. #define STL_CD1400MAXBAUD 230400
  335. #define STL_SC26198MAXBAUD 460800
  336. #define STL_BAUDBASE 115200
  337. #define STL_CLOSEDELAY (5 * HZ / 10)
  338. /*****************************************************************************/
  339. #ifdef CONFIG_PCI
  340. /*
  341. * Define the Stallion PCI vendor and device IDs.
  342. */
  343. #ifndef PCI_VENDOR_ID_STALLION
  344. #define PCI_VENDOR_ID_STALLION 0x124d
  345. #endif
  346. #ifndef PCI_DEVICE_ID_ECHPCI832
  347. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  348. #endif
  349. #ifndef PCI_DEVICE_ID_ECHPCI864
  350. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  351. #endif
  352. #ifndef PCI_DEVICE_ID_EIOPCI
  353. #define PCI_DEVICE_ID_EIOPCI 0x0003
  354. #endif
  355. /*
  356. * Define structure to hold all Stallion PCI boards.
  357. */
  358. typedef struct stlpcibrd {
  359. unsigned short vendid;
  360. unsigned short devid;
  361. int brdtype;
  362. } stlpcibrd_t;
  363. static stlpcibrd_t stl_pcibrds[] = {
  364. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
  365. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
  366. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
  367. { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
  368. };
  369. static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
  370. #endif
  371. /*****************************************************************************/
  372. /*
  373. * Define macros to extract a brd/port number from a minor number.
  374. */
  375. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  376. #define MINOR2PORT(min) ((min) & 0x3f)
  377. /*
  378. * Define a baud rate table that converts termios baud rate selector
  379. * into the actual baud rate value. All baud rate calculations are
  380. * based on the actual baud rate required.
  381. */
  382. static unsigned int stl_baudrates[] = {
  383. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  384. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  385. };
  386. /*
  387. * Define some handy local macros...
  388. */
  389. #undef MIN
  390. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  391. #undef TOLOWER
  392. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  393. /*****************************************************************************/
  394. /*
  395. * Declare all those functions in this driver!
  396. */
  397. static void stl_argbrds(void);
  398. static int stl_parsebrd(stlconf_t *confp, char **argp);
  399. static unsigned long stl_atol(char *str);
  400. static int stl_init(void);
  401. static int stl_open(struct tty_struct *tty, struct file *filp);
  402. static void stl_close(struct tty_struct *tty, struct file *filp);
  403. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
  404. static void stl_putchar(struct tty_struct *tty, unsigned char ch);
  405. static void stl_flushchars(struct tty_struct *tty);
  406. static int stl_writeroom(struct tty_struct *tty);
  407. static int stl_charsinbuffer(struct tty_struct *tty);
  408. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  409. static void stl_settermios(struct tty_struct *tty, struct termios *old);
  410. static void stl_throttle(struct tty_struct *tty);
  411. static void stl_unthrottle(struct tty_struct *tty);
  412. static void stl_stop(struct tty_struct *tty);
  413. static void stl_start(struct tty_struct *tty);
  414. static void stl_flushbuffer(struct tty_struct *tty);
  415. static void stl_breakctl(struct tty_struct *tty, int state);
  416. static void stl_waituntilsent(struct tty_struct *tty, int timeout);
  417. static void stl_sendxchar(struct tty_struct *tty, char ch);
  418. static void stl_hangup(struct tty_struct *tty);
  419. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  420. static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
  421. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
  422. static int stl_brdinit(stlbrd_t *brdp);
  423. static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
  424. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
  425. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
  426. static int stl_getbrdstats(combrd_t __user *bp);
  427. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
  428. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
  429. static int stl_getportstruct(stlport_t __user *arg);
  430. static int stl_getbrdstruct(stlbrd_t __user *arg);
  431. static int stl_waitcarrier(stlport_t *portp, struct file *filp);
  432. static int stl_eiointr(stlbrd_t *brdp);
  433. static int stl_echatintr(stlbrd_t *brdp);
  434. static int stl_echmcaintr(stlbrd_t *brdp);
  435. static int stl_echpciintr(stlbrd_t *brdp);
  436. static int stl_echpci64intr(stlbrd_t *brdp);
  437. static void stl_offintr(void *private);
  438. static stlbrd_t *stl_allocbrd(void);
  439. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
  440. static inline int stl_initbrds(void);
  441. static inline int stl_initeio(stlbrd_t *brdp);
  442. static inline int stl_initech(stlbrd_t *brdp);
  443. static inline int stl_getbrdnr(void);
  444. #ifdef CONFIG_PCI
  445. static inline int stl_findpcibrds(void);
  446. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
  447. #endif
  448. /*
  449. * CD1400 uart specific handling functions.
  450. */
  451. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
  452. static int stl_cd1400getreg(stlport_t *portp, int regnr);
  453. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
  454. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  455. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  456. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
  457. static int stl_cd1400getsignals(stlport_t *portp);
  458. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
  459. static void stl_cd1400ccrwait(stlport_t *portp);
  460. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
  461. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
  462. static void stl_cd1400disableintrs(stlport_t *portp);
  463. static void stl_cd1400sendbreak(stlport_t *portp, int len);
  464. static void stl_cd1400flowctrl(stlport_t *portp, int state);
  465. static void stl_cd1400sendflow(stlport_t *portp, int state);
  466. static void stl_cd1400flush(stlport_t *portp);
  467. static int stl_cd1400datastate(stlport_t *portp);
  468. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
  469. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
  470. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
  471. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
  472. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
  473. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
  474. /*
  475. * SC26198 uart specific handling functions.
  476. */
  477. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
  478. static int stl_sc26198getreg(stlport_t *portp, int regnr);
  479. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
  480. static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
  481. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  482. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  483. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
  484. static int stl_sc26198getsignals(stlport_t *portp);
  485. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
  486. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
  487. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
  488. static void stl_sc26198disableintrs(stlport_t *portp);
  489. static void stl_sc26198sendbreak(stlport_t *portp, int len);
  490. static void stl_sc26198flowctrl(stlport_t *portp, int state);
  491. static void stl_sc26198sendflow(stlport_t *portp, int state);
  492. static void stl_sc26198flush(stlport_t *portp);
  493. static int stl_sc26198datastate(stlport_t *portp);
  494. static void stl_sc26198wait(stlport_t *portp);
  495. static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
  496. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
  497. static void stl_sc26198txisr(stlport_t *port);
  498. static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
  499. static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
  500. static void stl_sc26198rxbadchars(stlport_t *portp);
  501. static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
  502. /*****************************************************************************/
  503. /*
  504. * Generic UART support structure.
  505. */
  506. typedef struct uart {
  507. int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
  508. void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  509. void (*setport)(stlport_t *portp, struct termios *tiosp);
  510. int (*getsignals)(stlport_t *portp);
  511. void (*setsignals)(stlport_t *portp, int dtr, int rts);
  512. void (*enablerxtx)(stlport_t *portp, int rx, int tx);
  513. void (*startrxtx)(stlport_t *portp, int rx, int tx);
  514. void (*disableintrs)(stlport_t *portp);
  515. void (*sendbreak)(stlport_t *portp, int len);
  516. void (*flowctrl)(stlport_t *portp, int state);
  517. void (*sendflow)(stlport_t *portp, int state);
  518. void (*flush)(stlport_t *portp);
  519. int (*datastate)(stlport_t *portp);
  520. void (*intr)(stlpanel_t *panelp, unsigned int iobase);
  521. } uart_t;
  522. /*
  523. * Define some macros to make calling these functions nice and clean.
  524. */
  525. #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
  526. #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
  527. #define stl_setport (* ((uart_t *) portp->uartp)->setport)
  528. #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
  529. #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
  530. #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
  531. #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
  532. #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
  533. #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
  534. #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
  535. #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
  536. #define stl_flush (* ((uart_t *) portp->uartp)->flush)
  537. #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
  538. /*****************************************************************************/
  539. /*
  540. * CD1400 UART specific data initialization.
  541. */
  542. static uart_t stl_cd1400uart = {
  543. stl_cd1400panelinit,
  544. stl_cd1400portinit,
  545. stl_cd1400setport,
  546. stl_cd1400getsignals,
  547. stl_cd1400setsignals,
  548. stl_cd1400enablerxtx,
  549. stl_cd1400startrxtx,
  550. stl_cd1400disableintrs,
  551. stl_cd1400sendbreak,
  552. stl_cd1400flowctrl,
  553. stl_cd1400sendflow,
  554. stl_cd1400flush,
  555. stl_cd1400datastate,
  556. stl_cd1400eiointr
  557. };
  558. /*
  559. * Define the offsets within the register bank of a cd1400 based panel.
  560. * These io address offsets are common to the EasyIO board as well.
  561. */
  562. #define EREG_ADDR 0
  563. #define EREG_DATA 4
  564. #define EREG_RXACK 5
  565. #define EREG_TXACK 6
  566. #define EREG_MDACK 7
  567. #define EREG_BANKSIZE 8
  568. #define CD1400_CLK 25000000
  569. #define CD1400_CLK8M 20000000
  570. /*
  571. * Define the cd1400 baud rate clocks. These are used when calculating
  572. * what clock and divisor to use for the required baud rate. Also
  573. * define the maximum baud rate allowed, and the default base baud.
  574. */
  575. static int stl_cd1400clkdivs[] = {
  576. CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
  577. };
  578. /*****************************************************************************/
  579. /*
  580. * SC26198 UART specific data initization.
  581. */
  582. static uart_t stl_sc26198uart = {
  583. stl_sc26198panelinit,
  584. stl_sc26198portinit,
  585. stl_sc26198setport,
  586. stl_sc26198getsignals,
  587. stl_sc26198setsignals,
  588. stl_sc26198enablerxtx,
  589. stl_sc26198startrxtx,
  590. stl_sc26198disableintrs,
  591. stl_sc26198sendbreak,
  592. stl_sc26198flowctrl,
  593. stl_sc26198sendflow,
  594. stl_sc26198flush,
  595. stl_sc26198datastate,
  596. stl_sc26198intr
  597. };
  598. /*
  599. * Define the offsets within the register bank of a sc26198 based panel.
  600. */
  601. #define XP_DATA 0
  602. #define XP_ADDR 1
  603. #define XP_MODID 2
  604. #define XP_STATUS 2
  605. #define XP_IACK 3
  606. #define XP_BANKSIZE 4
  607. /*
  608. * Define the sc26198 baud rate table. Offsets within the table
  609. * represent the actual baud rate selector of sc26198 registers.
  610. */
  611. static unsigned int sc26198_baudtable[] = {
  612. 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
  613. 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
  614. 230400, 460800, 921600
  615. };
  616. #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
  617. /*****************************************************************************/
  618. /*
  619. * Define the driver info for a user level control device. Used mainly
  620. * to get at port stats - only not using the port device itself.
  621. */
  622. static const struct file_operations stl_fsiomem = {
  623. .owner = THIS_MODULE,
  624. .ioctl = stl_memioctl,
  625. };
  626. /*****************************************************************************/
  627. static struct class *stallion_class;
  628. /*
  629. * Loadable module initialization stuff.
  630. */
  631. static int __init stallion_module_init(void)
  632. {
  633. stl_init();
  634. return 0;
  635. }
  636. /*****************************************************************************/
  637. static void __exit stallion_module_exit(void)
  638. {
  639. stlbrd_t *brdp;
  640. stlpanel_t *panelp;
  641. stlport_t *portp;
  642. int i, j, k;
  643. #ifdef DEBUG
  644. printk("cleanup_module()\n");
  645. #endif
  646. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  647. stl_drvversion);
  648. /*
  649. * Free up all allocated resources used by the ports. This includes
  650. * memory and interrupts. As part of this process we will also do
  651. * a hangup on every open port - to try to flush out any processes
  652. * hanging onto ports.
  653. */
  654. i = tty_unregister_driver(stl_serial);
  655. put_tty_driver(stl_serial);
  656. if (i) {
  657. printk("STALLION: failed to un-register tty driver, "
  658. "errno=%d\n", -i);
  659. return;
  660. }
  661. for (i = 0; i < 4; i++)
  662. class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  663. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  664. printk("STALLION: failed to un-register serial memory device, "
  665. "errno=%d\n", -i);
  666. class_destroy(stallion_class);
  667. for (i = 0; (i < stl_nrbrds); i++) {
  668. if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
  669. continue;
  670. free_irq(brdp->irq, brdp);
  671. for (j = 0; (j < STL_MAXPANELS); j++) {
  672. panelp = brdp->panels[j];
  673. if (panelp == (stlpanel_t *) NULL)
  674. continue;
  675. for (k = 0; (k < STL_PORTSPERPANEL); k++) {
  676. portp = panelp->ports[k];
  677. if (portp == (stlport_t *) NULL)
  678. continue;
  679. if (portp->tty != (struct tty_struct *) NULL)
  680. stl_hangup(portp->tty);
  681. kfree(portp->tx.buf);
  682. kfree(portp);
  683. }
  684. kfree(panelp);
  685. }
  686. release_region(brdp->ioaddr1, brdp->iosize1);
  687. if (brdp->iosize2 > 0)
  688. release_region(brdp->ioaddr2, brdp->iosize2);
  689. kfree(brdp);
  690. stl_brds[i] = (stlbrd_t *) NULL;
  691. }
  692. }
  693. module_init(stallion_module_init);
  694. module_exit(stallion_module_exit);
  695. /*****************************************************************************/
  696. /*
  697. * Check for any arguments passed in on the module load command line.
  698. */
  699. static void stl_argbrds(void)
  700. {
  701. stlconf_t conf;
  702. stlbrd_t *brdp;
  703. int i;
  704. #ifdef DEBUG
  705. printk("stl_argbrds()\n");
  706. #endif
  707. for (i = stl_nrbrds; (i < stl_nargs); i++) {
  708. memset(&conf, 0, sizeof(conf));
  709. if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
  710. continue;
  711. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  712. continue;
  713. stl_nrbrds = i + 1;
  714. brdp->brdnr = i;
  715. brdp->brdtype = conf.brdtype;
  716. brdp->ioaddr1 = conf.ioaddr1;
  717. brdp->ioaddr2 = conf.ioaddr2;
  718. brdp->irq = conf.irq;
  719. brdp->irqtype = conf.irqtype;
  720. stl_brdinit(brdp);
  721. }
  722. }
  723. /*****************************************************************************/
  724. /*
  725. * Convert an ascii string number into an unsigned long.
  726. */
  727. static unsigned long stl_atol(char *str)
  728. {
  729. unsigned long val;
  730. int base, c;
  731. char *sp;
  732. val = 0;
  733. sp = str;
  734. if ((*sp == '0') && (*(sp+1) == 'x')) {
  735. base = 16;
  736. sp += 2;
  737. } else if (*sp == '0') {
  738. base = 8;
  739. sp++;
  740. } else {
  741. base = 10;
  742. }
  743. for (; (*sp != 0); sp++) {
  744. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  745. if ((c < 0) || (c >= base)) {
  746. printk("STALLION: invalid argument %s\n", str);
  747. val = 0;
  748. break;
  749. }
  750. val = (val * base) + c;
  751. }
  752. return val;
  753. }
  754. /*****************************************************************************/
  755. /*
  756. * Parse the supplied argument string, into the board conf struct.
  757. */
  758. static int stl_parsebrd(stlconf_t *confp, char **argp)
  759. {
  760. char *sp;
  761. int i;
  762. #ifdef DEBUG
  763. printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
  764. #endif
  765. if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
  766. return 0;
  767. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  768. *sp = TOLOWER(*sp);
  769. for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
  770. if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
  771. break;
  772. }
  773. if (i == ARRAY_SIZE(stl_brdstr)) {
  774. printk("STALLION: unknown board name, %s?\n", argp[0]);
  775. return 0;
  776. }
  777. confp->brdtype = stl_brdstr[i].type;
  778. i = 1;
  779. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  780. confp->ioaddr1 = stl_atol(argp[i]);
  781. i++;
  782. if (confp->brdtype == BRD_ECH) {
  783. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  784. confp->ioaddr2 = stl_atol(argp[i]);
  785. i++;
  786. }
  787. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  788. confp->irq = stl_atol(argp[i]);
  789. return 1;
  790. }
  791. /*****************************************************************************/
  792. /*
  793. * Allocate a new board structure. Fill out the basic info in it.
  794. */
  795. static stlbrd_t *stl_allocbrd(void)
  796. {
  797. stlbrd_t *brdp;
  798. brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
  799. if (!brdp) {
  800. printk("STALLION: failed to allocate memory (size=%Zd)\n",
  801. sizeof(stlbrd_t));
  802. return NULL;
  803. }
  804. brdp->magic = STL_BOARDMAGIC;
  805. return brdp;
  806. }
  807. /*****************************************************************************/
  808. static int stl_open(struct tty_struct *tty, struct file *filp)
  809. {
  810. stlport_t *portp;
  811. stlbrd_t *brdp;
  812. unsigned int minordev;
  813. int brdnr, panelnr, portnr, rc;
  814. #ifdef DEBUG
  815. printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
  816. (int) filp, tty->name);
  817. #endif
  818. minordev = tty->index;
  819. brdnr = MINOR2BRD(minordev);
  820. if (brdnr >= stl_nrbrds)
  821. return -ENODEV;
  822. brdp = stl_brds[brdnr];
  823. if (brdp == (stlbrd_t *) NULL)
  824. return -ENODEV;
  825. minordev = MINOR2PORT(minordev);
  826. for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  827. if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
  828. break;
  829. if (minordev < brdp->panels[panelnr]->nrports) {
  830. portnr = minordev;
  831. break;
  832. }
  833. minordev -= brdp->panels[panelnr]->nrports;
  834. }
  835. if (portnr < 0)
  836. return -ENODEV;
  837. portp = brdp->panels[panelnr]->ports[portnr];
  838. if (portp == (stlport_t *) NULL)
  839. return -ENODEV;
  840. /*
  841. * On the first open of the device setup the port hardware, and
  842. * initialize the per port data structure.
  843. */
  844. portp->tty = tty;
  845. tty->driver_data = portp;
  846. portp->refcount++;
  847. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  848. if (!portp->tx.buf) {
  849. portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
  850. if (!portp->tx.buf)
  851. return -ENOMEM;
  852. portp->tx.head = portp->tx.buf;
  853. portp->tx.tail = portp->tx.buf;
  854. }
  855. stl_setport(portp, tty->termios);
  856. portp->sigs = stl_getsignals(portp);
  857. stl_setsignals(portp, 1, 1);
  858. stl_enablerxtx(portp, 1, 1);
  859. stl_startrxtx(portp, 1, 0);
  860. clear_bit(TTY_IO_ERROR, &tty->flags);
  861. portp->flags |= ASYNC_INITIALIZED;
  862. }
  863. /*
  864. * Check if this port is in the middle of closing. If so then wait
  865. * until it is closed then return error status, based on flag settings.
  866. * The sleep here does not need interrupt protection since the wakeup
  867. * for it is done with the same context.
  868. */
  869. if (portp->flags & ASYNC_CLOSING) {
  870. interruptible_sleep_on(&portp->close_wait);
  871. if (portp->flags & ASYNC_HUP_NOTIFY)
  872. return -EAGAIN;
  873. return -ERESTARTSYS;
  874. }
  875. /*
  876. * Based on type of open being done check if it can overlap with any
  877. * previous opens still in effect. If we are a normal serial device
  878. * then also we might have to wait for carrier.
  879. */
  880. if (!(filp->f_flags & O_NONBLOCK)) {
  881. if ((rc = stl_waitcarrier(portp, filp)) != 0)
  882. return rc;
  883. }
  884. portp->flags |= ASYNC_NORMAL_ACTIVE;
  885. return 0;
  886. }
  887. /*****************************************************************************/
  888. /*
  889. * Possibly need to wait for carrier (DCD signal) to come high. Say
  890. * maybe because if we are clocal then we don't need to wait...
  891. */
  892. static int stl_waitcarrier(stlport_t *portp, struct file *filp)
  893. {
  894. unsigned long flags;
  895. int rc, doclocal;
  896. #ifdef DEBUG
  897. printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
  898. #endif
  899. rc = 0;
  900. doclocal = 0;
  901. spin_lock_irqsave(&stallion_lock, flags);
  902. if (portp->tty->termios->c_cflag & CLOCAL)
  903. doclocal++;
  904. portp->openwaitcnt++;
  905. if (! tty_hung_up_p(filp))
  906. portp->refcount--;
  907. for (;;) {
  908. /* Takes brd_lock internally */
  909. stl_setsignals(portp, 1, 1);
  910. if (tty_hung_up_p(filp) ||
  911. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  912. if (portp->flags & ASYNC_HUP_NOTIFY)
  913. rc = -EBUSY;
  914. else
  915. rc = -ERESTARTSYS;
  916. break;
  917. }
  918. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  919. (doclocal || (portp->sigs & TIOCM_CD))) {
  920. break;
  921. }
  922. if (signal_pending(current)) {
  923. rc = -ERESTARTSYS;
  924. break;
  925. }
  926. /* FIXME */
  927. interruptible_sleep_on(&portp->open_wait);
  928. }
  929. if (! tty_hung_up_p(filp))
  930. portp->refcount++;
  931. portp->openwaitcnt--;
  932. spin_unlock_irqrestore(&stallion_lock, flags);
  933. return rc;
  934. }
  935. /*****************************************************************************/
  936. static void stl_close(struct tty_struct *tty, struct file *filp)
  937. {
  938. stlport_t *portp;
  939. unsigned long flags;
  940. #ifdef DEBUG
  941. printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
  942. #endif
  943. portp = tty->driver_data;
  944. if (portp == (stlport_t *) NULL)
  945. return;
  946. spin_lock_irqsave(&stallion_lock, flags);
  947. if (tty_hung_up_p(filp)) {
  948. spin_unlock_irqrestore(&stallion_lock, flags);
  949. return;
  950. }
  951. if ((tty->count == 1) && (portp->refcount != 1))
  952. portp->refcount = 1;
  953. if (portp->refcount-- > 1) {
  954. spin_unlock_irqrestore(&stallion_lock, flags);
  955. return;
  956. }
  957. portp->refcount = 0;
  958. portp->flags |= ASYNC_CLOSING;
  959. /*
  960. * May want to wait for any data to drain before closing. The BUSY
  961. * flag keeps track of whether we are still sending or not - it is
  962. * very accurate for the cd1400, not quite so for the sc26198.
  963. * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
  964. */
  965. tty->closing = 1;
  966. spin_unlock_irqrestore(&stallion_lock, flags);
  967. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  968. tty_wait_until_sent(tty, portp->closing_wait);
  969. stl_waituntilsent(tty, (HZ / 2));
  970. spin_lock_irqsave(&stallion_lock, flags);
  971. portp->flags &= ~ASYNC_INITIALIZED;
  972. spin_unlock_irqrestore(&stallion_lock, flags);
  973. stl_disableintrs(portp);
  974. if (tty->termios->c_cflag & HUPCL)
  975. stl_setsignals(portp, 0, 0);
  976. stl_enablerxtx(portp, 0, 0);
  977. stl_flushbuffer(tty);
  978. portp->istate = 0;
  979. if (portp->tx.buf != (char *) NULL) {
  980. kfree(portp->tx.buf);
  981. portp->tx.buf = (char *) NULL;
  982. portp->tx.head = (char *) NULL;
  983. portp->tx.tail = (char *) NULL;
  984. }
  985. set_bit(TTY_IO_ERROR, &tty->flags);
  986. tty_ldisc_flush(tty);
  987. tty->closing = 0;
  988. portp->tty = (struct tty_struct *) NULL;
  989. if (portp->openwaitcnt) {
  990. if (portp->close_delay)
  991. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  992. wake_up_interruptible(&portp->open_wait);
  993. }
  994. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  995. wake_up_interruptible(&portp->close_wait);
  996. }
  997. /*****************************************************************************/
  998. /*
  999. * Write routine. Take data and stuff it in to the TX ring queue.
  1000. * If transmit interrupts are not running then start them.
  1001. */
  1002. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1003. {
  1004. stlport_t *portp;
  1005. unsigned int len, stlen;
  1006. unsigned char *chbuf;
  1007. char *head, *tail;
  1008. #ifdef DEBUG
  1009. printk("stl_write(tty=%x,buf=%x,count=%d)\n",
  1010. (int) tty, (int) buf, count);
  1011. #endif
  1012. portp = tty->driver_data;
  1013. if (portp == (stlport_t *) NULL)
  1014. return 0;
  1015. if (portp->tx.buf == (char *) NULL)
  1016. return 0;
  1017. /*
  1018. * If copying direct from user space we must cater for page faults,
  1019. * causing us to "sleep" here for a while. To handle this copy in all
  1020. * the data we need now, into a local buffer. Then when we got it all
  1021. * copy it into the TX buffer.
  1022. */
  1023. chbuf = (unsigned char *) buf;
  1024. head = portp->tx.head;
  1025. tail = portp->tx.tail;
  1026. if (head >= tail) {
  1027. len = STL_TXBUFSIZE - (head - tail) - 1;
  1028. stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
  1029. } else {
  1030. len = tail - head - 1;
  1031. stlen = len;
  1032. }
  1033. len = MIN(len, count);
  1034. count = 0;
  1035. while (len > 0) {
  1036. stlen = MIN(len, stlen);
  1037. memcpy(head, chbuf, stlen);
  1038. len -= stlen;
  1039. chbuf += stlen;
  1040. count += stlen;
  1041. head += stlen;
  1042. if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
  1043. head = portp->tx.buf;
  1044. stlen = tail - head;
  1045. }
  1046. }
  1047. portp->tx.head = head;
  1048. clear_bit(ASYI_TXLOW, &portp->istate);
  1049. stl_startrxtx(portp, -1, 1);
  1050. return count;
  1051. }
  1052. /*****************************************************************************/
  1053. static void stl_putchar(struct tty_struct *tty, unsigned char ch)
  1054. {
  1055. stlport_t *portp;
  1056. unsigned int len;
  1057. char *head, *tail;
  1058. #ifdef DEBUG
  1059. printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
  1060. #endif
  1061. if (tty == (struct tty_struct *) NULL)
  1062. return;
  1063. portp = tty->driver_data;
  1064. if (portp == (stlport_t *) NULL)
  1065. return;
  1066. if (portp->tx.buf == (char *) NULL)
  1067. return;
  1068. head = portp->tx.head;
  1069. tail = portp->tx.tail;
  1070. len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
  1071. len--;
  1072. if (len > 0) {
  1073. *head++ = ch;
  1074. if (head >= (portp->tx.buf + STL_TXBUFSIZE))
  1075. head = portp->tx.buf;
  1076. }
  1077. portp->tx.head = head;
  1078. }
  1079. /*****************************************************************************/
  1080. /*
  1081. * If there are any characters in the buffer then make sure that TX
  1082. * interrupts are on and get'em out. Normally used after the putchar
  1083. * routine has been called.
  1084. */
  1085. static void stl_flushchars(struct tty_struct *tty)
  1086. {
  1087. stlport_t *portp;
  1088. #ifdef DEBUG
  1089. printk("stl_flushchars(tty=%x)\n", (int) tty);
  1090. #endif
  1091. if (tty == (struct tty_struct *) NULL)
  1092. return;
  1093. portp = tty->driver_data;
  1094. if (portp == (stlport_t *) NULL)
  1095. return;
  1096. if (portp->tx.buf == (char *) NULL)
  1097. return;
  1098. stl_startrxtx(portp, -1, 1);
  1099. }
  1100. /*****************************************************************************/
  1101. static int stl_writeroom(struct tty_struct *tty)
  1102. {
  1103. stlport_t *portp;
  1104. char *head, *tail;
  1105. #ifdef DEBUG
  1106. printk("stl_writeroom(tty=%x)\n", (int) tty);
  1107. #endif
  1108. if (tty == (struct tty_struct *) NULL)
  1109. return 0;
  1110. portp = tty->driver_data;
  1111. if (portp == (stlport_t *) NULL)
  1112. return 0;
  1113. if (portp->tx.buf == (char *) NULL)
  1114. return 0;
  1115. head = portp->tx.head;
  1116. tail = portp->tx.tail;
  1117. return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
  1118. }
  1119. /*****************************************************************************/
  1120. /*
  1121. * Return number of chars in the TX buffer. Normally we would just
  1122. * calculate the number of chars in the buffer and return that, but if
  1123. * the buffer is empty and TX interrupts are still on then we return
  1124. * that the buffer still has 1 char in it. This way whoever called us
  1125. * will not think that ALL chars have drained - since the UART still
  1126. * must have some chars in it (we are busy after all).
  1127. */
  1128. static int stl_charsinbuffer(struct tty_struct *tty)
  1129. {
  1130. stlport_t *portp;
  1131. unsigned int size;
  1132. char *head, *tail;
  1133. #ifdef DEBUG
  1134. printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
  1135. #endif
  1136. if (tty == (struct tty_struct *) NULL)
  1137. return 0;
  1138. portp = tty->driver_data;
  1139. if (portp == (stlport_t *) NULL)
  1140. return 0;
  1141. if (portp->tx.buf == (char *) NULL)
  1142. return 0;
  1143. head = portp->tx.head;
  1144. tail = portp->tx.tail;
  1145. size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  1146. if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
  1147. size = 1;
  1148. return size;
  1149. }
  1150. /*****************************************************************************/
  1151. /*
  1152. * Generate the serial struct info.
  1153. */
  1154. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
  1155. {
  1156. struct serial_struct sio;
  1157. stlbrd_t *brdp;
  1158. #ifdef DEBUG
  1159. printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1160. #endif
  1161. memset(&sio, 0, sizeof(struct serial_struct));
  1162. sio.line = portp->portnr;
  1163. sio.port = portp->ioaddr;
  1164. sio.flags = portp->flags;
  1165. sio.baud_base = portp->baud_base;
  1166. sio.close_delay = portp->close_delay;
  1167. sio.closing_wait = portp->closing_wait;
  1168. sio.custom_divisor = portp->custom_divisor;
  1169. sio.hub6 = 0;
  1170. if (portp->uartp == &stl_cd1400uart) {
  1171. sio.type = PORT_CIRRUS;
  1172. sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
  1173. } else {
  1174. sio.type = PORT_UNKNOWN;
  1175. sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
  1176. }
  1177. brdp = stl_brds[portp->brdnr];
  1178. if (brdp != (stlbrd_t *) NULL)
  1179. sio.irq = brdp->irq;
  1180. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
  1181. }
  1182. /*****************************************************************************/
  1183. /*
  1184. * Set port according to the serial struct info.
  1185. * At this point we do not do any auto-configure stuff, so we will
  1186. * just quietly ignore any requests to change irq, etc.
  1187. */
  1188. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
  1189. {
  1190. struct serial_struct sio;
  1191. #ifdef DEBUG
  1192. printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1193. #endif
  1194. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1195. return -EFAULT;
  1196. if (!capable(CAP_SYS_ADMIN)) {
  1197. if ((sio.baud_base != portp->baud_base) ||
  1198. (sio.close_delay != portp->close_delay) ||
  1199. ((sio.flags & ~ASYNC_USR_MASK) !=
  1200. (portp->flags & ~ASYNC_USR_MASK)))
  1201. return -EPERM;
  1202. }
  1203. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1204. (sio.flags & ASYNC_USR_MASK);
  1205. portp->baud_base = sio.baud_base;
  1206. portp->close_delay = sio.close_delay;
  1207. portp->closing_wait = sio.closing_wait;
  1208. portp->custom_divisor = sio.custom_divisor;
  1209. stl_setport(portp, portp->tty->termios);
  1210. return 0;
  1211. }
  1212. /*****************************************************************************/
  1213. static int stl_tiocmget(struct tty_struct *tty, struct file *file)
  1214. {
  1215. stlport_t *portp;
  1216. if (tty == (struct tty_struct *) NULL)
  1217. return -ENODEV;
  1218. portp = tty->driver_data;
  1219. if (portp == (stlport_t *) NULL)
  1220. return -ENODEV;
  1221. if (tty->flags & (1 << TTY_IO_ERROR))
  1222. return -EIO;
  1223. return stl_getsignals(portp);
  1224. }
  1225. static int stl_tiocmset(struct tty_struct *tty, struct file *file,
  1226. unsigned int set, unsigned int clear)
  1227. {
  1228. stlport_t *portp;
  1229. int rts = -1, dtr = -1;
  1230. if (tty == (struct tty_struct *) NULL)
  1231. return -ENODEV;
  1232. portp = tty->driver_data;
  1233. if (portp == (stlport_t *) NULL)
  1234. return -ENODEV;
  1235. if (tty->flags & (1 << TTY_IO_ERROR))
  1236. return -EIO;
  1237. if (set & TIOCM_RTS)
  1238. rts = 1;
  1239. if (set & TIOCM_DTR)
  1240. dtr = 1;
  1241. if (clear & TIOCM_RTS)
  1242. rts = 0;
  1243. if (clear & TIOCM_DTR)
  1244. dtr = 0;
  1245. stl_setsignals(portp, dtr, rts);
  1246. return 0;
  1247. }
  1248. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1249. {
  1250. stlport_t *portp;
  1251. unsigned int ival;
  1252. int rc;
  1253. void __user *argp = (void __user *)arg;
  1254. #ifdef DEBUG
  1255. printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
  1256. (int) tty, (int) file, cmd, (int) arg);
  1257. #endif
  1258. if (tty == (struct tty_struct *) NULL)
  1259. return -ENODEV;
  1260. portp = tty->driver_data;
  1261. if (portp == (stlport_t *) NULL)
  1262. return -ENODEV;
  1263. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1264. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1265. if (tty->flags & (1 << TTY_IO_ERROR))
  1266. return -EIO;
  1267. }
  1268. rc = 0;
  1269. switch (cmd) {
  1270. case TIOCGSOFTCAR:
  1271. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1272. (unsigned __user *) argp);
  1273. break;
  1274. case TIOCSSOFTCAR:
  1275. if (get_user(ival, (unsigned int __user *) arg))
  1276. return -EFAULT;
  1277. tty->termios->c_cflag =
  1278. (tty->termios->c_cflag & ~CLOCAL) |
  1279. (ival ? CLOCAL : 0);
  1280. break;
  1281. case TIOCGSERIAL:
  1282. rc = stl_getserial(portp, argp);
  1283. break;
  1284. case TIOCSSERIAL:
  1285. rc = stl_setserial(portp, argp);
  1286. break;
  1287. case COM_GETPORTSTATS:
  1288. rc = stl_getportstats(portp, argp);
  1289. break;
  1290. case COM_CLRPORTSTATS:
  1291. rc = stl_clrportstats(portp, argp);
  1292. break;
  1293. case TIOCSERCONFIG:
  1294. case TIOCSERGWILD:
  1295. case TIOCSERSWILD:
  1296. case TIOCSERGETLSR:
  1297. case TIOCSERGSTRUCT:
  1298. case TIOCSERGETMULTI:
  1299. case TIOCSERSETMULTI:
  1300. default:
  1301. rc = -ENOIOCTLCMD;
  1302. break;
  1303. }
  1304. return rc;
  1305. }
  1306. /*****************************************************************************/
  1307. static void stl_settermios(struct tty_struct *tty, struct termios *old)
  1308. {
  1309. stlport_t *portp;
  1310. struct termios *tiosp;
  1311. #ifdef DEBUG
  1312. printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
  1313. #endif
  1314. if (tty == (struct tty_struct *) NULL)
  1315. return;
  1316. portp = tty->driver_data;
  1317. if (portp == (stlport_t *) NULL)
  1318. return;
  1319. tiosp = tty->termios;
  1320. if ((tiosp->c_cflag == old->c_cflag) &&
  1321. (tiosp->c_iflag == old->c_iflag))
  1322. return;
  1323. stl_setport(portp, tiosp);
  1324. stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
  1325. -1);
  1326. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
  1327. tty->hw_stopped = 0;
  1328. stl_start(tty);
  1329. }
  1330. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1331. wake_up_interruptible(&portp->open_wait);
  1332. }
  1333. /*****************************************************************************/
  1334. /*
  1335. * Attempt to flow control who ever is sending us data. Based on termios
  1336. * settings use software or/and hardware flow control.
  1337. */
  1338. static void stl_throttle(struct tty_struct *tty)
  1339. {
  1340. stlport_t *portp;
  1341. #ifdef DEBUG
  1342. printk("stl_throttle(tty=%x)\n", (int) tty);
  1343. #endif
  1344. if (tty == (struct tty_struct *) NULL)
  1345. return;
  1346. portp = tty->driver_data;
  1347. if (portp == (stlport_t *) NULL)
  1348. return;
  1349. stl_flowctrl(portp, 0);
  1350. }
  1351. /*****************************************************************************/
  1352. /*
  1353. * Unflow control the device sending us data...
  1354. */
  1355. static void stl_unthrottle(struct tty_struct *tty)
  1356. {
  1357. stlport_t *portp;
  1358. #ifdef DEBUG
  1359. printk("stl_unthrottle(tty=%x)\n", (int) tty);
  1360. #endif
  1361. if (tty == (struct tty_struct *) NULL)
  1362. return;
  1363. portp = tty->driver_data;
  1364. if (portp == (stlport_t *) NULL)
  1365. return;
  1366. stl_flowctrl(portp, 1);
  1367. }
  1368. /*****************************************************************************/
  1369. /*
  1370. * Stop the transmitter. Basically to do this we will just turn TX
  1371. * interrupts off.
  1372. */
  1373. static void stl_stop(struct tty_struct *tty)
  1374. {
  1375. stlport_t *portp;
  1376. #ifdef DEBUG
  1377. printk("stl_stop(tty=%x)\n", (int) tty);
  1378. #endif
  1379. if (tty == (struct tty_struct *) NULL)
  1380. return;
  1381. portp = tty->driver_data;
  1382. if (portp == (stlport_t *) NULL)
  1383. return;
  1384. stl_startrxtx(portp, -1, 0);
  1385. }
  1386. /*****************************************************************************/
  1387. /*
  1388. * Start the transmitter again. Just turn TX interrupts back on.
  1389. */
  1390. static void stl_start(struct tty_struct *tty)
  1391. {
  1392. stlport_t *portp;
  1393. #ifdef DEBUG
  1394. printk("stl_start(tty=%x)\n", (int) tty);
  1395. #endif
  1396. if (tty == (struct tty_struct *) NULL)
  1397. return;
  1398. portp = tty->driver_data;
  1399. if (portp == (stlport_t *) NULL)
  1400. return;
  1401. stl_startrxtx(portp, -1, 1);
  1402. }
  1403. /*****************************************************************************/
  1404. /*
  1405. * Hangup this port. This is pretty much like closing the port, only
  1406. * a little more brutal. No waiting for data to drain. Shutdown the
  1407. * port and maybe drop signals.
  1408. */
  1409. static void stl_hangup(struct tty_struct *tty)
  1410. {
  1411. stlport_t *portp;
  1412. #ifdef DEBUG
  1413. printk("stl_hangup(tty=%x)\n", (int) tty);
  1414. #endif
  1415. if (tty == (struct tty_struct *) NULL)
  1416. return;
  1417. portp = tty->driver_data;
  1418. if (portp == (stlport_t *) NULL)
  1419. return;
  1420. portp->flags &= ~ASYNC_INITIALIZED;
  1421. stl_disableintrs(portp);
  1422. if (tty->termios->c_cflag & HUPCL)
  1423. stl_setsignals(portp, 0, 0);
  1424. stl_enablerxtx(portp, 0, 0);
  1425. stl_flushbuffer(tty);
  1426. portp->istate = 0;
  1427. set_bit(TTY_IO_ERROR, &tty->flags);
  1428. if (portp->tx.buf != (char *) NULL) {
  1429. kfree(portp->tx.buf);
  1430. portp->tx.buf = (char *) NULL;
  1431. portp->tx.head = (char *) NULL;
  1432. portp->tx.tail = (char *) NULL;
  1433. }
  1434. portp->tty = (struct tty_struct *) NULL;
  1435. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1436. portp->refcount = 0;
  1437. wake_up_interruptible(&portp->open_wait);
  1438. }
  1439. /*****************************************************************************/
  1440. static void stl_flushbuffer(struct tty_struct *tty)
  1441. {
  1442. stlport_t *portp;
  1443. #ifdef DEBUG
  1444. printk("stl_flushbuffer(tty=%x)\n", (int) tty);
  1445. #endif
  1446. if (tty == (struct tty_struct *) NULL)
  1447. return;
  1448. portp = tty->driver_data;
  1449. if (portp == (stlport_t *) NULL)
  1450. return;
  1451. stl_flush(portp);
  1452. tty_wakeup(tty);
  1453. }
  1454. /*****************************************************************************/
  1455. static void stl_breakctl(struct tty_struct *tty, int state)
  1456. {
  1457. stlport_t *portp;
  1458. #ifdef DEBUG
  1459. printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
  1460. #endif
  1461. if (tty == (struct tty_struct *) NULL)
  1462. return;
  1463. portp = tty->driver_data;
  1464. if (portp == (stlport_t *) NULL)
  1465. return;
  1466. stl_sendbreak(portp, ((state == -1) ? 1 : 2));
  1467. }
  1468. /*****************************************************************************/
  1469. static void stl_waituntilsent(struct tty_struct *tty, int timeout)
  1470. {
  1471. stlport_t *portp;
  1472. unsigned long tend;
  1473. #ifdef DEBUG
  1474. printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
  1475. #endif
  1476. if (tty == (struct tty_struct *) NULL)
  1477. return;
  1478. portp = tty->driver_data;
  1479. if (portp == (stlport_t *) NULL)
  1480. return;
  1481. if (timeout == 0)
  1482. timeout = HZ;
  1483. tend = jiffies + timeout;
  1484. while (stl_datastate(portp)) {
  1485. if (signal_pending(current))
  1486. break;
  1487. msleep_interruptible(20);
  1488. if (time_after_eq(jiffies, tend))
  1489. break;
  1490. }
  1491. }
  1492. /*****************************************************************************/
  1493. static void stl_sendxchar(struct tty_struct *tty, char ch)
  1494. {
  1495. stlport_t *portp;
  1496. #ifdef DEBUG
  1497. printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
  1498. #endif
  1499. if (tty == (struct tty_struct *) NULL)
  1500. return;
  1501. portp = tty->driver_data;
  1502. if (portp == (stlport_t *) NULL)
  1503. return;
  1504. if (ch == STOP_CHAR(tty))
  1505. stl_sendflow(portp, 0);
  1506. else if (ch == START_CHAR(tty))
  1507. stl_sendflow(portp, 1);
  1508. else
  1509. stl_putchar(tty, ch);
  1510. }
  1511. /*****************************************************************************/
  1512. #define MAXLINE 80
  1513. /*
  1514. * Format info for a specified port. The line is deliberately limited
  1515. * to 80 characters. (If it is too long it will be truncated, if too
  1516. * short then padded with spaces).
  1517. */
  1518. static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
  1519. {
  1520. char *sp;
  1521. int sigs, cnt;
  1522. sp = pos;
  1523. sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
  1524. portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
  1525. (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
  1526. if (portp->stats.rxframing)
  1527. sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
  1528. if (portp->stats.rxparity)
  1529. sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
  1530. if (portp->stats.rxbreaks)
  1531. sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
  1532. if (portp->stats.rxoverrun)
  1533. sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
  1534. sigs = stl_getsignals(portp);
  1535. cnt = sprintf(sp, "%s%s%s%s%s ",
  1536. (sigs & TIOCM_RTS) ? "|RTS" : "",
  1537. (sigs & TIOCM_CTS) ? "|CTS" : "",
  1538. (sigs & TIOCM_DTR) ? "|DTR" : "",
  1539. (sigs & TIOCM_CD) ? "|DCD" : "",
  1540. (sigs & TIOCM_DSR) ? "|DSR" : "");
  1541. *sp = ' ';
  1542. sp += cnt;
  1543. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1544. *sp++ = ' ';
  1545. if (cnt >= MAXLINE)
  1546. pos[(MAXLINE - 2)] = '+';
  1547. pos[(MAXLINE - 1)] = '\n';
  1548. return MAXLINE;
  1549. }
  1550. /*****************************************************************************/
  1551. /*
  1552. * Port info, read from the /proc file system.
  1553. */
  1554. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1555. {
  1556. stlbrd_t *brdp;
  1557. stlpanel_t *panelp;
  1558. stlport_t *portp;
  1559. int brdnr, panelnr, portnr, totalport;
  1560. int curoff, maxoff;
  1561. char *pos;
  1562. #ifdef DEBUG
  1563. printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
  1564. "data=%x\n", (int) page, (int) start, (int) off, count,
  1565. (int) eof, (int) data);
  1566. #endif
  1567. pos = page;
  1568. totalport = 0;
  1569. curoff = 0;
  1570. if (off == 0) {
  1571. pos += sprintf(pos, "%s: version %s", stl_drvtitle,
  1572. stl_drvversion);
  1573. while (pos < (page + MAXLINE - 1))
  1574. *pos++ = ' ';
  1575. *pos++ = '\n';
  1576. }
  1577. curoff = MAXLINE;
  1578. /*
  1579. * We scan through for each board, panel and port. The offset is
  1580. * calculated on the fly, and irrelevant ports are skipped.
  1581. */
  1582. for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
  1583. brdp = stl_brds[brdnr];
  1584. if (brdp == (stlbrd_t *) NULL)
  1585. continue;
  1586. if (brdp->state == 0)
  1587. continue;
  1588. maxoff = curoff + (brdp->nrports * MAXLINE);
  1589. if (off >= maxoff) {
  1590. curoff = maxoff;
  1591. continue;
  1592. }
  1593. totalport = brdnr * STL_MAXPORTS;
  1594. for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
  1595. panelp = brdp->panels[panelnr];
  1596. if (panelp == (stlpanel_t *) NULL)
  1597. continue;
  1598. maxoff = curoff + (panelp->nrports * MAXLINE);
  1599. if (off >= maxoff) {
  1600. curoff = maxoff;
  1601. totalport += panelp->nrports;
  1602. continue;
  1603. }
  1604. for (portnr = 0; (portnr < panelp->nrports); portnr++,
  1605. totalport++) {
  1606. portp = panelp->ports[portnr];
  1607. if (portp == (stlport_t *) NULL)
  1608. continue;
  1609. if (off >= (curoff += MAXLINE))
  1610. continue;
  1611. if ((pos - page + MAXLINE) > count)
  1612. goto stl_readdone;
  1613. pos += stl_portinfo(portp, totalport, pos);
  1614. }
  1615. }
  1616. }
  1617. *eof = 1;
  1618. stl_readdone:
  1619. *start = page;
  1620. return (pos - page);
  1621. }
  1622. /*****************************************************************************/
  1623. /*
  1624. * All board interrupts are vectored through here first. This code then
  1625. * calls off to the approrpriate board interrupt handlers.
  1626. */
  1627. static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
  1628. {
  1629. stlbrd_t *brdp = (stlbrd_t *) dev_id;
  1630. #ifdef DEBUG
  1631. printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
  1632. (int) regs);
  1633. #endif
  1634. return IRQ_RETVAL((* brdp->isr)(brdp));
  1635. }
  1636. /*****************************************************************************/
  1637. /*
  1638. * Interrupt service routine for EasyIO board types.
  1639. */
  1640. static int stl_eiointr(stlbrd_t *brdp)
  1641. {
  1642. stlpanel_t *panelp;
  1643. unsigned int iobase;
  1644. int handled = 0;
  1645. spin_lock(&brd_lock);
  1646. panelp = brdp->panels[0];
  1647. iobase = panelp->iobase;
  1648. while (inb(brdp->iostatus) & EIO_INTRPEND) {
  1649. handled = 1;
  1650. (* panelp->isr)(panelp, iobase);
  1651. }
  1652. spin_unlock(&brd_lock);
  1653. return handled;
  1654. }
  1655. /*****************************************************************************/
  1656. /*
  1657. * Interrupt service routine for ECH-AT board types.
  1658. */
  1659. static int stl_echatintr(stlbrd_t *brdp)
  1660. {
  1661. stlpanel_t *panelp;
  1662. unsigned int ioaddr;
  1663. int bnknr;
  1664. int handled = 0;
  1665. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1666. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1667. handled = 1;
  1668. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1669. ioaddr = brdp->bnkstataddr[bnknr];
  1670. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1671. panelp = brdp->bnk2panel[bnknr];
  1672. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1673. }
  1674. }
  1675. }
  1676. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1677. return handled;
  1678. }
  1679. /*****************************************************************************/
  1680. /*
  1681. * Interrupt service routine for ECH-MCA board types.
  1682. */
  1683. static int stl_echmcaintr(stlbrd_t *brdp)
  1684. {
  1685. stlpanel_t *panelp;
  1686. unsigned int ioaddr;
  1687. int bnknr;
  1688. int handled = 0;
  1689. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1690. handled = 1;
  1691. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1692. ioaddr = brdp->bnkstataddr[bnknr];
  1693. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1694. panelp = brdp->bnk2panel[bnknr];
  1695. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1696. }
  1697. }
  1698. }
  1699. return handled;
  1700. }
  1701. /*****************************************************************************/
  1702. /*
  1703. * Interrupt service routine for ECH-PCI board types.
  1704. */
  1705. static int stl_echpciintr(stlbrd_t *brdp)
  1706. {
  1707. stlpanel_t *panelp;
  1708. unsigned int ioaddr;
  1709. int bnknr, recheck;
  1710. int handled = 0;
  1711. while (1) {
  1712. recheck = 0;
  1713. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1714. outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
  1715. ioaddr = brdp->bnkstataddr[bnknr];
  1716. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1717. panelp = brdp->bnk2panel[bnknr];
  1718. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1719. recheck++;
  1720. handled = 1;
  1721. }
  1722. }
  1723. if (! recheck)
  1724. break;
  1725. }
  1726. return handled;
  1727. }
  1728. /*****************************************************************************/
  1729. /*
  1730. * Interrupt service routine for ECH-8/64-PCI board types.
  1731. */
  1732. static int stl_echpci64intr(stlbrd_t *brdp)
  1733. {
  1734. stlpanel_t *panelp;
  1735. unsigned int ioaddr;
  1736. int bnknr;
  1737. int handled = 0;
  1738. while (inb(brdp->ioctrl) & 0x1) {
  1739. handled = 1;
  1740. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1741. ioaddr = brdp->bnkstataddr[bnknr];
  1742. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1743. panelp = brdp->bnk2panel[bnknr];
  1744. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1745. }
  1746. }
  1747. }
  1748. return handled;
  1749. }
  1750. /*****************************************************************************/
  1751. /*
  1752. * Service an off-level request for some channel.
  1753. */
  1754. static void stl_offintr(void *private)
  1755. {
  1756. stlport_t *portp;
  1757. struct tty_struct *tty;
  1758. unsigned int oldsigs;
  1759. portp = private;
  1760. #ifdef DEBUG
  1761. printk("stl_offintr(portp=%x)\n", (int) portp);
  1762. #endif
  1763. if (portp == (stlport_t *) NULL)
  1764. return;
  1765. tty = portp->tty;
  1766. if (tty == (struct tty_struct *) NULL)
  1767. return;
  1768. lock_kernel();
  1769. if (test_bit(ASYI_TXLOW, &portp->istate)) {
  1770. tty_wakeup(tty);
  1771. }
  1772. if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
  1773. clear_bit(ASYI_DCDCHANGE, &portp->istate);
  1774. oldsigs = portp->sigs;
  1775. portp->sigs = stl_getsignals(portp);
  1776. if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
  1777. wake_up_interruptible(&portp->open_wait);
  1778. if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
  1779. if (portp->flags & ASYNC_CHECK_CD)
  1780. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  1781. }
  1782. }
  1783. unlock_kernel();
  1784. }
  1785. /*****************************************************************************/
  1786. /*
  1787. * Initialize all the ports on a panel.
  1788. */
  1789. static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
  1790. {
  1791. stlport_t *portp;
  1792. int chipmask, i;
  1793. #ifdef DEBUG
  1794. printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  1795. #endif
  1796. chipmask = stl_panelinit(brdp, panelp);
  1797. /*
  1798. * All UART's are initialized (if found!). Now go through and setup
  1799. * each ports data structures.
  1800. */
  1801. for (i = 0; (i < panelp->nrports); i++) {
  1802. portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
  1803. if (!portp) {
  1804. printk("STALLION: failed to allocate memory "
  1805. "(size=%Zd)\n", sizeof(stlport_t));
  1806. break;
  1807. }
  1808. portp->magic = STL_PORTMAGIC;
  1809. portp->portnr = i;
  1810. portp->brdnr = panelp->brdnr;
  1811. portp->panelnr = panelp->panelnr;
  1812. portp->uartp = panelp->uartp;
  1813. portp->clk = brdp->clk;
  1814. portp->baud_base = STL_BAUDBASE;
  1815. portp->close_delay = STL_CLOSEDELAY;
  1816. portp->closing_wait = 30 * HZ;
  1817. INIT_WORK(&portp->tqueue, stl_offintr, portp);
  1818. init_waitqueue_head(&portp->open_wait);
  1819. init_waitqueue_head(&portp->close_wait);
  1820. portp->stats.brd = portp->brdnr;
  1821. portp->stats.panel = portp->panelnr;
  1822. portp->stats.port = portp->portnr;
  1823. panelp->ports[i] = portp;
  1824. stl_portinit(brdp, panelp, portp);
  1825. }
  1826. return(0);
  1827. }
  1828. /*****************************************************************************/
  1829. /*
  1830. * Try to find and initialize an EasyIO board.
  1831. */
  1832. static inline int stl_initeio(stlbrd_t *brdp)
  1833. {
  1834. stlpanel_t *panelp;
  1835. unsigned int status;
  1836. char *name;
  1837. int rc;
  1838. #ifdef DEBUG
  1839. printk("stl_initeio(brdp=%x)\n", (int) brdp);
  1840. #endif
  1841. brdp->ioctrl = brdp->ioaddr1 + 1;
  1842. brdp->iostatus = brdp->ioaddr1 + 2;
  1843. status = inb(brdp->iostatus);
  1844. if ((status & EIO_IDBITMASK) == EIO_MK3)
  1845. brdp->ioctrl++;
  1846. /*
  1847. * Handle board specific stuff now. The real difference is PCI
  1848. * or not PCI.
  1849. */
  1850. if (brdp->brdtype == BRD_EASYIOPCI) {
  1851. brdp->iosize1 = 0x80;
  1852. brdp->iosize2 = 0x80;
  1853. name = "serial(EIO-PCI)";
  1854. outb(0x41, (brdp->ioaddr2 + 0x4c));
  1855. } else {
  1856. brdp->iosize1 = 8;
  1857. name = "serial(EIO)";
  1858. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1859. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1860. printk("STALLION: invalid irq=%d for brd=%d\n",
  1861. brdp->irq, brdp->brdnr);
  1862. return(-EINVAL);
  1863. }
  1864. outb((stl_vecmap[brdp->irq] | EIO_0WS |
  1865. ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
  1866. brdp->ioctrl);
  1867. }
  1868. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1869. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1870. "%x conflicts with another device\n", brdp->brdnr,
  1871. brdp->ioaddr1);
  1872. return(-EBUSY);
  1873. }
  1874. if (brdp->iosize2 > 0)
  1875. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1876. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1877. "address %x conflicts with another device\n",
  1878. brdp->brdnr, brdp->ioaddr2);
  1879. printk(KERN_WARNING "STALLION: Warning, also "
  1880. "releasing board %d I/O address %x \n",
  1881. brdp->brdnr, brdp->ioaddr1);
  1882. release_region(brdp->ioaddr1, brdp->iosize1);
  1883. return(-EBUSY);
  1884. }
  1885. /*
  1886. * Everything looks OK, so let's go ahead and probe for the hardware.
  1887. */
  1888. brdp->clk = CD1400_CLK;
  1889. brdp->isr = stl_eiointr;
  1890. switch (status & EIO_IDBITMASK) {
  1891. case EIO_8PORTM:
  1892. brdp->clk = CD1400_CLK8M;
  1893. /* fall thru */
  1894. case EIO_8PORTRS:
  1895. case EIO_8PORTDI:
  1896. brdp->nrports = 8;
  1897. break;
  1898. case EIO_4PORTRS:
  1899. brdp->nrports = 4;
  1900. break;
  1901. case EIO_MK3:
  1902. switch (status & EIO_BRDMASK) {
  1903. case ID_BRD4:
  1904. brdp->nrports = 4;
  1905. break;
  1906. case ID_BRD8:
  1907. brdp->nrports = 8;
  1908. break;
  1909. case ID_BRD16:
  1910. brdp->nrports = 16;
  1911. break;
  1912. default:
  1913. return(-ENODEV);
  1914. }
  1915. break;
  1916. default:
  1917. return(-ENODEV);
  1918. }
  1919. /*
  1920. * We have verified that the board is actually present, so now we
  1921. * can complete the setup.
  1922. */
  1923. panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
  1924. if (!panelp) {
  1925. printk(KERN_WARNING "STALLION: failed to allocate memory "
  1926. "(size=%Zd)\n", sizeof(stlpanel_t));
  1927. return -ENOMEM;
  1928. }
  1929. panelp->magic = STL_PANELMAGIC;
  1930. panelp->brdnr = brdp->brdnr;
  1931. panelp->panelnr = 0;
  1932. panelp->nrports = brdp->nrports;
  1933. panelp->iobase = brdp->ioaddr1;
  1934. panelp->hwid = status;
  1935. if ((status & EIO_IDBITMASK) == EIO_MK3) {
  1936. panelp->uartp = (void *) &stl_sc26198uart;
  1937. panelp->isr = stl_sc26198intr;
  1938. } else {
  1939. panelp->uartp = (void *) &stl_cd1400uart;
  1940. panelp->isr = stl_cd1400eiointr;
  1941. }
  1942. brdp->panels[0] = panelp;
  1943. brdp->nrpanels = 1;
  1944. brdp->state |= BRD_FOUND;
  1945. brdp->hwid = status;
  1946. if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
  1947. printk("STALLION: failed to register interrupt "
  1948. "routine for %s irq=%d\n", name, brdp->irq);
  1949. rc = -ENODEV;
  1950. } else {
  1951. rc = 0;
  1952. }
  1953. return rc;
  1954. }
  1955. /*****************************************************************************/
  1956. /*
  1957. * Try to find an ECH board and initialize it. This code is capable of
  1958. * dealing with all types of ECH board.
  1959. */
  1960. static inline int stl_initech(stlbrd_t *brdp)
  1961. {
  1962. stlpanel_t *panelp;
  1963. unsigned int status, nxtid, ioaddr, conflict;
  1964. int panelnr, banknr, i;
  1965. char *name;
  1966. #ifdef DEBUG
  1967. printk("stl_initech(brdp=%x)\n", (int) brdp);
  1968. #endif
  1969. status = 0;
  1970. conflict = 0;
  1971. /*
  1972. * Set up the initial board register contents for boards. This varies a
  1973. * bit between the different board types. So we need to handle each
  1974. * separately. Also do a check that the supplied IRQ is good.
  1975. */
  1976. switch (brdp->brdtype) {
  1977. case BRD_ECH:
  1978. brdp->isr = stl_echatintr;
  1979. brdp->ioctrl = brdp->ioaddr1 + 1;
  1980. brdp->iostatus = brdp->ioaddr1 + 1;
  1981. status = inb(brdp->iostatus);
  1982. if ((status & ECH_IDBITMASK) != ECH_ID)
  1983. return(-ENODEV);
  1984. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1985. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1986. printk("STALLION: invalid irq=%d for brd=%d\n",
  1987. brdp->irq, brdp->brdnr);
  1988. return(-EINVAL);
  1989. }
  1990. status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
  1991. status |= (stl_vecmap[brdp->irq] << 1);
  1992. outb((status | ECH_BRDRESET), brdp->ioaddr1);
  1993. brdp->ioctrlval = ECH_INTENABLE |
  1994. ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
  1995. for (i = 0; (i < 10); i++)
  1996. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1997. brdp->iosize1 = 2;
  1998. brdp->iosize2 = 32;
  1999. name = "serial(EC8/32)";
  2000. outb(status, brdp->ioaddr1);
  2001. break;
  2002. case BRD_ECHMC:
  2003. brdp->isr = stl_echmcaintr;
  2004. brdp->ioctrl = brdp->ioaddr1 + 0x20;
  2005. brdp->iostatus = brdp->ioctrl;
  2006. status = inb(brdp->iostatus);
  2007. if ((status & ECH_IDBITMASK) != ECH_ID)
  2008. return(-ENODEV);
  2009. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  2010. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  2011. printk("STALLION: invalid irq=%d for brd=%d\n",
  2012. brdp->irq, brdp->brdnr);
  2013. return(-EINVAL);
  2014. }
  2015. outb(ECHMC_BRDRESET, brdp->ioctrl);
  2016. outb(ECHMC_INTENABLE, brdp->ioctrl);
  2017. brdp->iosize1 = 64;
  2018. name = "serial(EC8/32-MC)";
  2019. break;
  2020. case BRD_ECHPCI:
  2021. brdp->isr = stl_echpciintr;
  2022. brdp->ioctrl = brdp->ioaddr1 + 2;
  2023. brdp->iosize1 = 4;
  2024. brdp->iosize2 = 8;
  2025. name = "serial(EC8/32-PCI)";
  2026. break;
  2027. case BRD_ECH64PCI:
  2028. brdp->isr = stl_echpci64intr;
  2029. brdp->ioctrl = brdp->ioaddr2 + 0x40;
  2030. outb(0x43, (brdp->ioaddr1 + 0x4c));
  2031. brdp->iosize1 = 0x80;
  2032. brdp->iosize2 = 0x80;
  2033. name = "serial(EC8/64-PCI)";
  2034. break;
  2035. default:
  2036. printk("STALLION: unknown board type=%d\n", brdp->brdtype);
  2037. return(-EINVAL);
  2038. break;
  2039. }
  2040. /*
  2041. * Check boards for possible IO address conflicts and return fail status
  2042. * if an IO conflict found.
  2043. */
  2044. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  2045. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  2046. "%x conflicts with another device\n", brdp->brdnr,
  2047. brdp->ioaddr1);
  2048. return(-EBUSY);
  2049. }
  2050. if (brdp->iosize2 > 0)
  2051. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  2052. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  2053. "address %x conflicts with another device\n",
  2054. brdp->brdnr, brdp->ioaddr2);
  2055. printk(KERN_WARNING "STALLION: Warning, also "
  2056. "releasing board %d I/O address %x \n",
  2057. brdp->brdnr, brdp->ioaddr1);
  2058. release_region(brdp->ioaddr1, brdp->iosize1);
  2059. return(-EBUSY);
  2060. }
  2061. /*
  2062. * Scan through the secondary io address space looking for panels.
  2063. * As we find'em allocate and initialize panel structures for each.
  2064. */
  2065. brdp->clk = CD1400_CLK;
  2066. brdp->hwid = status;
  2067. ioaddr = brdp->ioaddr2;
  2068. banknr = 0;
  2069. panelnr = 0;
  2070. nxtid = 0;
  2071. for (i = 0; (i < STL_MAXPANELS); i++) {
  2072. if (brdp->brdtype == BRD_ECHPCI) {
  2073. outb(nxtid, brdp->ioctrl);
  2074. ioaddr = brdp->ioaddr2;
  2075. }
  2076. status = inb(ioaddr + ECH_PNLSTATUS);
  2077. if ((status & ECH_PNLIDMASK) != nxtid)
  2078. break;
  2079. panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
  2080. if (!panelp) {
  2081. printk("STALLION: failed to allocate memory "
  2082. "(size=%Zd)\n", sizeof(stlpanel_t));
  2083. break;
  2084. }
  2085. panelp->magic = STL_PANELMAGIC;
  2086. panelp->brdnr = brdp->brdnr;
  2087. panelp->panelnr = panelnr;
  2088. panelp->iobase = ioaddr;
  2089. panelp->pagenr = nxtid;
  2090. panelp->hwid = status;
  2091. brdp->bnk2panel[banknr] = panelp;
  2092. brdp->bnkpageaddr[banknr] = nxtid;
  2093. brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
  2094. if (status & ECH_PNLXPID) {
  2095. panelp->uartp = (void *) &stl_sc26198uart;
  2096. panelp->isr = stl_sc26198intr;
  2097. if (status & ECH_PNL16PORT) {
  2098. panelp->nrports = 16;
  2099. brdp->bnk2panel[banknr] = panelp;
  2100. brdp->bnkpageaddr[banknr] = nxtid;
  2101. brdp->bnkstataddr[banknr++] = ioaddr + 4 +
  2102. ECH_PNLSTATUS;
  2103. } else {
  2104. panelp->nrports = 8;
  2105. }
  2106. } else {
  2107. panelp->uartp = (void *) &stl_cd1400uart;
  2108. panelp->isr = stl_cd1400echintr;
  2109. if (status & ECH_PNL16PORT) {
  2110. panelp->nrports = 16;
  2111. panelp->ackmask = 0x80;
  2112. if (brdp->brdtype != BRD_ECHPCI)
  2113. ioaddr += EREG_BANKSIZE;
  2114. brdp->bnk2panel[banknr] = panelp;
  2115. brdp->bnkpageaddr[banknr] = ++nxtid;
  2116. brdp->bnkstataddr[banknr++] = ioaddr +
  2117. ECH_PNLSTATUS;
  2118. } else {
  2119. panelp->nrports = 8;
  2120. panelp->ackmask = 0xc0;
  2121. }
  2122. }
  2123. nxtid++;
  2124. ioaddr += EREG_BANKSIZE;
  2125. brdp->nrports += panelp->nrports;
  2126. brdp->panels[panelnr++] = panelp;
  2127. if ((brdp->brdtype != BRD_ECHPCI) &&
  2128. (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
  2129. break;
  2130. }
  2131. brdp->nrpanels = panelnr;
  2132. brdp->nrbnks = banknr;
  2133. if (brdp->brdtype == BRD_ECH)
  2134. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  2135. brdp->state |= BRD_FOUND;
  2136. if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
  2137. printk("STALLION: failed to register interrupt "
  2138. "routine for %s irq=%d\n", name, brdp->irq);
  2139. i = -ENODEV;
  2140. } else {
  2141. i = 0;
  2142. }
  2143. return(i);
  2144. }
  2145. /*****************************************************************************/
  2146. /*
  2147. * Initialize and configure the specified board.
  2148. * Scan through all the boards in the configuration and see what we
  2149. * can find. Handle EIO and the ECH boards a little differently here
  2150. * since the initial search and setup is very different.
  2151. */
  2152. static int __init stl_brdinit(stlbrd_t *brdp)
  2153. {
  2154. int i;
  2155. #ifdef DEBUG
  2156. printk("stl_brdinit(brdp=%x)\n", (int) brdp);
  2157. #endif
  2158. switch (brdp->brdtype) {
  2159. case BRD_EASYIO:
  2160. case BRD_EASYIOPCI:
  2161. stl_initeio(brdp);
  2162. break;
  2163. case BRD_ECH:
  2164. case BRD_ECHMC:
  2165. case BRD_ECHPCI:
  2166. case BRD_ECH64PCI:
  2167. stl_initech(brdp);
  2168. break;
  2169. default:
  2170. printk("STALLION: board=%d is unknown board type=%d\n",
  2171. brdp->brdnr, brdp->brdtype);
  2172. return(ENODEV);
  2173. }
  2174. stl_brds[brdp->brdnr] = brdp;
  2175. if ((brdp->state & BRD_FOUND) == 0) {
  2176. printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
  2177. stl_brdnames[brdp->brdtype], brdp->brdnr,
  2178. brdp->ioaddr1, brdp->irq);
  2179. return(ENODEV);
  2180. }
  2181. for (i = 0; (i < STL_MAXPANELS); i++)
  2182. if (brdp->panels[i] != (stlpanel_t *) NULL)
  2183. stl_initports(brdp, brdp->panels[i]);
  2184. printk("STALLION: %s found, board=%d io=%x irq=%d "
  2185. "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
  2186. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  2187. brdp->nrports);
  2188. return(0);
  2189. }
  2190. /*****************************************************************************/
  2191. /*
  2192. * Find the next available board number that is free.
  2193. */
  2194. static inline int stl_getbrdnr(void)
  2195. {
  2196. int i;
  2197. for (i = 0; (i < STL_MAXBRDS); i++) {
  2198. if (stl_brds[i] == (stlbrd_t *) NULL) {
  2199. if (i >= stl_nrbrds)
  2200. stl_nrbrds = i + 1;
  2201. return(i);
  2202. }
  2203. }
  2204. return(-1);
  2205. }
  2206. /*****************************************************************************/
  2207. #ifdef CONFIG_PCI
  2208. /*
  2209. * We have a Stallion board. Allocate a board structure and
  2210. * initialize it. Read its IO and IRQ resources from PCI
  2211. * configuration space.
  2212. */
  2213. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  2214. {
  2215. stlbrd_t *brdp;
  2216. #ifdef DEBUG
  2217. printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
  2218. devp->bus->number, devp->devfn);
  2219. #endif
  2220. if (pci_enable_device(devp))
  2221. return(-EIO);
  2222. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2223. return(-ENOMEM);
  2224. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  2225. printk("STALLION: too many boards found, "
  2226. "maximum supported %d\n", STL_MAXBRDS);
  2227. return(0);
  2228. }
  2229. brdp->brdtype = brdtype;
  2230. /*
  2231. * Different Stallion boards use the BAR registers in different ways,
  2232. * so set up io addresses based on board type.
  2233. */
  2234. #ifdef DEBUG
  2235. printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
  2236. pci_resource_start(devp, 0), pci_resource_start(devp, 1),
  2237. pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
  2238. #endif
  2239. /*
  2240. * We have all resources from the board, so let's setup the actual
  2241. * board structure now.
  2242. */
  2243. switch (brdtype) {
  2244. case BRD_ECHPCI:
  2245. brdp->ioaddr2 = pci_resource_start(devp, 0);
  2246. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2247. break;
  2248. case BRD_ECH64PCI:
  2249. brdp->ioaddr2 = pci_resource_start(devp, 2);
  2250. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2251. break;
  2252. case BRD_EASYIOPCI:
  2253. brdp->ioaddr1 = pci_resource_start(devp, 2);
  2254. brdp->ioaddr2 = pci_resource_start(devp, 1);
  2255. break;
  2256. default:
  2257. printk("STALLION: unknown PCI board type=%d\n", brdtype);
  2258. break;
  2259. }
  2260. brdp->irq = devp->irq;
  2261. stl_brdinit(brdp);
  2262. return(0);
  2263. }
  2264. /*****************************************************************************/
  2265. /*
  2266. * Find all Stallion PCI boards that might be installed. Initialize each
  2267. * one as it is found.
  2268. */
  2269. static inline int stl_findpcibrds(void)
  2270. {
  2271. struct pci_dev *dev = NULL;
  2272. int i, rc;
  2273. #ifdef DEBUG
  2274. printk("stl_findpcibrds()\n");
  2275. #endif
  2276. for (i = 0; (i < stl_nrpcibrds); i++)
  2277. while ((dev = pci_find_device(stl_pcibrds[i].vendid,
  2278. stl_pcibrds[i].devid, dev))) {
  2279. /*
  2280. * Found a device on the PCI bus that has our vendor and
  2281. * device ID. Need to check now that it is really us.
  2282. */
  2283. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  2284. continue;
  2285. rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
  2286. if (rc)
  2287. return(rc);
  2288. }
  2289. return(0);
  2290. }
  2291. #endif
  2292. /*****************************************************************************/
  2293. /*
  2294. * Scan through all the boards in the configuration and see what we
  2295. * can find. Handle EIO and the ECH boards a little differently here
  2296. * since the initial search and setup is too different.
  2297. */
  2298. static inline int stl_initbrds(void)
  2299. {
  2300. stlbrd_t *brdp;
  2301. stlconf_t *confp;
  2302. int i;
  2303. #ifdef DEBUG
  2304. printk("stl_initbrds()\n");
  2305. #endif
  2306. if (stl_nrbrds > STL_MAXBRDS) {
  2307. printk("STALLION: too many boards in configuration table, "
  2308. "truncating to %d\n", STL_MAXBRDS);
  2309. stl_nrbrds = STL_MAXBRDS;
  2310. }
  2311. /*
  2312. * Firstly scan the list of static boards configured. Allocate
  2313. * resources and initialize the boards as found.
  2314. */
  2315. for (i = 0; (i < stl_nrbrds); i++) {
  2316. confp = &stl_brdconf[i];
  2317. stl_parsebrd(confp, stl_brdsp[i]);
  2318. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2319. return(-ENOMEM);
  2320. brdp->brdnr = i;
  2321. brdp->brdtype = confp->brdtype;
  2322. brdp->ioaddr1 = confp->ioaddr1;
  2323. brdp->ioaddr2 = confp->ioaddr2;
  2324. brdp->irq = confp->irq;
  2325. brdp->irqtype = confp->irqtype;
  2326. stl_brdinit(brdp);
  2327. }
  2328. /*
  2329. * Find any dynamically supported boards. That is via module load
  2330. * line options or auto-detected on the PCI bus.
  2331. */
  2332. stl_argbrds();
  2333. #ifdef CONFIG_PCI
  2334. stl_findpcibrds();
  2335. #endif
  2336. return(0);
  2337. }
  2338. /*****************************************************************************/
  2339. /*
  2340. * Return the board stats structure to user app.
  2341. */
  2342. static int stl_getbrdstats(combrd_t __user *bp)
  2343. {
  2344. stlbrd_t *brdp;
  2345. stlpanel_t *panelp;
  2346. int i;
  2347. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2348. return -EFAULT;
  2349. if (stl_brdstats.brd >= STL_MAXBRDS)
  2350. return(-ENODEV);
  2351. brdp = stl_brds[stl_brdstats.brd];
  2352. if (brdp == (stlbrd_t *) NULL)
  2353. return(-ENODEV);
  2354. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2355. stl_brdstats.brd = brdp->brdnr;
  2356. stl_brdstats.type = brdp->brdtype;
  2357. stl_brdstats.hwid = brdp->hwid;
  2358. stl_brdstats.state = brdp->state;
  2359. stl_brdstats.ioaddr = brdp->ioaddr1;
  2360. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2361. stl_brdstats.irq = brdp->irq;
  2362. stl_brdstats.nrpanels = brdp->nrpanels;
  2363. stl_brdstats.nrports = brdp->nrports;
  2364. for (i = 0; (i < brdp->nrpanels); i++) {
  2365. panelp = brdp->panels[i];
  2366. stl_brdstats.panels[i].panel = i;
  2367. stl_brdstats.panels[i].hwid = panelp->hwid;
  2368. stl_brdstats.panels[i].nrports = panelp->nrports;
  2369. }
  2370. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2371. }
  2372. /*****************************************************************************/
  2373. /*
  2374. * Resolve the referenced port number into a port struct pointer.
  2375. */
  2376. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
  2377. {
  2378. stlbrd_t *brdp;
  2379. stlpanel_t *panelp;
  2380. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  2381. return((stlport_t *) NULL);
  2382. brdp = stl_brds[brdnr];
  2383. if (brdp == (stlbrd_t *) NULL)
  2384. return((stlport_t *) NULL);
  2385. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  2386. return((stlport_t *) NULL);
  2387. panelp = brdp->panels[panelnr];
  2388. if (panelp == (stlpanel_t *) NULL)
  2389. return((stlport_t *) NULL);
  2390. if ((portnr < 0) || (portnr >= panelp->nrports))
  2391. return((stlport_t *) NULL);
  2392. return(panelp->ports[portnr]);
  2393. }
  2394. /*****************************************************************************/
  2395. /*
  2396. * Return the port stats structure to user app. A NULL port struct
  2397. * pointer passed in means that we need to find out from the app
  2398. * what port to get stats for (used through board control device).
  2399. */
  2400. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
  2401. {
  2402. unsigned char *head, *tail;
  2403. unsigned long flags;
  2404. if (!portp) {
  2405. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2406. return -EFAULT;
  2407. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2408. stl_comstats.port);
  2409. if (portp == (stlport_t *) NULL)
  2410. return(-ENODEV);
  2411. }
  2412. portp->stats.state = portp->istate;
  2413. portp->stats.flags = portp->flags;
  2414. portp->stats.hwid = portp->hwid;
  2415. portp->stats.ttystate = 0;
  2416. portp->stats.cflags = 0;
  2417. portp->stats.iflags = 0;
  2418. portp->stats.oflags = 0;
  2419. portp->stats.lflags = 0;
  2420. portp->stats.rxbuffered = 0;
  2421. spin_lock_irqsave(&stallion_lock, flags);
  2422. if (portp->tty != (struct tty_struct *) NULL) {
  2423. if (portp->tty->driver_data == portp) {
  2424. portp->stats.ttystate = portp->tty->flags;
  2425. /* No longer available as a statistic */
  2426. portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
  2427. if (portp->tty->termios != (struct termios *) NULL) {
  2428. portp->stats.cflags = portp->tty->termios->c_cflag;
  2429. portp->stats.iflags = portp->tty->termios->c_iflag;
  2430. portp->stats.oflags = portp->tty->termios->c_oflag;
  2431. portp->stats.lflags = portp->tty->termios->c_lflag;
  2432. }
  2433. }
  2434. }
  2435. spin_unlock_irqrestore(&stallion_lock, flags);
  2436. head = portp->tx.head;
  2437. tail = portp->tx.tail;
  2438. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  2439. (STL_TXBUFSIZE - (tail - head)));
  2440. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2441. return copy_to_user(cp, &portp->stats,
  2442. sizeof(comstats_t)) ? -EFAULT : 0;
  2443. }
  2444. /*****************************************************************************/
  2445. /*
  2446. * Clear the port stats structure. We also return it zeroed out...
  2447. */
  2448. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
  2449. {
  2450. if (!portp) {
  2451. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2452. return -EFAULT;
  2453. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2454. stl_comstats.port);
  2455. if (portp == (stlport_t *) NULL)
  2456. return(-ENODEV);
  2457. }
  2458. memset(&portp->stats, 0, sizeof(comstats_t));
  2459. portp->stats.brd = portp->brdnr;
  2460. portp->stats.panel = portp->panelnr;
  2461. portp->stats.port = portp->portnr;
  2462. return copy_to_user(cp, &portp->stats,
  2463. sizeof(comstats_t)) ? -EFAULT : 0;
  2464. }
  2465. /*****************************************************************************/
  2466. /*
  2467. * Return the entire driver ports structure to a user app.
  2468. */
  2469. static int stl_getportstruct(stlport_t __user *arg)
  2470. {
  2471. stlport_t *portp;
  2472. if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
  2473. return -EFAULT;
  2474. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2475. stl_dummyport.portnr);
  2476. if (!portp)
  2477. return -ENODEV;
  2478. return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
  2479. }
  2480. /*****************************************************************************/
  2481. /*
  2482. * Return the entire driver board structure to a user app.
  2483. */
  2484. static int stl_getbrdstruct(stlbrd_t __user *arg)
  2485. {
  2486. stlbrd_t *brdp;
  2487. if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
  2488. return -EFAULT;
  2489. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  2490. return -ENODEV;
  2491. brdp = stl_brds[stl_dummybrd.brdnr];
  2492. if (!brdp)
  2493. return(-ENODEV);
  2494. return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
  2495. }
  2496. /*****************************************************************************/
  2497. /*
  2498. * The "staliomem" device is also required to do some special operations
  2499. * on the board and/or ports. In this driver it is mostly used for stats
  2500. * collection.
  2501. */
  2502. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2503. {
  2504. int brdnr, rc;
  2505. void __user *argp = (void __user *)arg;
  2506. #ifdef DEBUG
  2507. printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
  2508. (int) fp, cmd, (int) arg);
  2509. #endif
  2510. brdnr = iminor(ip);
  2511. if (brdnr >= STL_MAXBRDS)
  2512. return(-ENODEV);
  2513. rc = 0;
  2514. switch (cmd) {
  2515. case COM_GETPORTSTATS:
  2516. rc = stl_getportstats(NULL, argp);
  2517. break;
  2518. case COM_CLRPORTSTATS:
  2519. rc = stl_clrportstats(NULL, argp);
  2520. break;
  2521. case COM_GETBRDSTATS:
  2522. rc = stl_getbrdstats(argp);
  2523. break;
  2524. case COM_READPORT:
  2525. rc = stl_getportstruct(argp);
  2526. break;
  2527. case COM_READBOARD:
  2528. rc = stl_getbrdstruct(argp);
  2529. break;
  2530. default:
  2531. rc = -ENOIOCTLCMD;
  2532. break;
  2533. }
  2534. return(rc);
  2535. }
  2536. static struct tty_operations stl_ops = {
  2537. .open = stl_open,
  2538. .close = stl_close,
  2539. .write = stl_write,
  2540. .put_char = stl_putchar,
  2541. .flush_chars = stl_flushchars,
  2542. .write_room = stl_writeroom,
  2543. .chars_in_buffer = stl_charsinbuffer,
  2544. .ioctl = stl_ioctl,
  2545. .set_termios = stl_settermios,
  2546. .throttle = stl_throttle,
  2547. .unthrottle = stl_unthrottle,
  2548. .stop = stl_stop,
  2549. .start = stl_start,
  2550. .hangup = stl_hangup,
  2551. .flush_buffer = stl_flushbuffer,
  2552. .break_ctl = stl_breakctl,
  2553. .wait_until_sent = stl_waituntilsent,
  2554. .send_xchar = stl_sendxchar,
  2555. .read_proc = stl_readproc,
  2556. .tiocmget = stl_tiocmget,
  2557. .tiocmset = stl_tiocmset,
  2558. };
  2559. /*****************************************************************************/
  2560. static int __init stl_init(void)
  2561. {
  2562. int i;
  2563. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  2564. spin_lock_init(&stallion_lock);
  2565. spin_lock_init(&brd_lock);
  2566. stl_initbrds();
  2567. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  2568. if (!stl_serial)
  2569. return -1;
  2570. /*
  2571. * Set up a character driver for per board stuff. This is mainly used
  2572. * to do stats ioctls on the ports.
  2573. */
  2574. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  2575. printk("STALLION: failed to register serial board device\n");
  2576. stallion_class = class_create(THIS_MODULE, "staliomem");
  2577. for (i = 0; i < 4; i++)
  2578. class_device_create(stallion_class, NULL,
  2579. MKDEV(STL_SIOMEMMAJOR, i), NULL,
  2580. "staliomem%d", i);
  2581. stl_serial->owner = THIS_MODULE;
  2582. stl_serial->driver_name = stl_drvname;
  2583. stl_serial->name = "ttyE";
  2584. stl_serial->major = STL_SERIALMAJOR;
  2585. stl_serial->minor_start = 0;
  2586. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  2587. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  2588. stl_serial->init_termios = stl_deftermios;
  2589. stl_serial->flags = TTY_DRIVER_REAL_RAW;
  2590. tty_set_operations(stl_serial, &stl_ops);
  2591. if (tty_register_driver(stl_serial)) {
  2592. put_tty_driver(stl_serial);
  2593. printk("STALLION: failed to register serial driver\n");
  2594. return -1;
  2595. }
  2596. return 0;
  2597. }
  2598. /*****************************************************************************/
  2599. /* CD1400 HARDWARE FUNCTIONS */
  2600. /*****************************************************************************/
  2601. /*
  2602. * These functions get/set/update the registers of the cd1400 UARTs.
  2603. * Access to the cd1400 registers is via an address/data io port pair.
  2604. * (Maybe should make this inline...)
  2605. */
  2606. static int stl_cd1400getreg(stlport_t *portp, int regnr)
  2607. {
  2608. outb((regnr + portp->uartaddr), portp->ioaddr);
  2609. return inb(portp->ioaddr + EREG_DATA);
  2610. }
  2611. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
  2612. {
  2613. outb((regnr + portp->uartaddr), portp->ioaddr);
  2614. outb(value, portp->ioaddr + EREG_DATA);
  2615. }
  2616. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
  2617. {
  2618. outb((regnr + portp->uartaddr), portp->ioaddr);
  2619. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2620. outb(value, portp->ioaddr + EREG_DATA);
  2621. return 1;
  2622. }
  2623. return 0;
  2624. }
  2625. /*****************************************************************************/
  2626. /*
  2627. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2628. * these ports are on - since the port io registers are almost
  2629. * identical when dealing with ports.
  2630. */
  2631. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  2632. {
  2633. unsigned int gfrcr;
  2634. int chipmask, i, j;
  2635. int nrchips, uartaddr, ioaddr;
  2636. unsigned long flags;
  2637. #ifdef DEBUG
  2638. printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  2639. #endif
  2640. spin_lock_irqsave(&brd_lock, flags);
  2641. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2642. /*
  2643. * Check that each chip is present and started up OK.
  2644. */
  2645. chipmask = 0;
  2646. nrchips = panelp->nrports / CD1400_PORTS;
  2647. for (i = 0; (i < nrchips); i++) {
  2648. if (brdp->brdtype == BRD_ECHPCI) {
  2649. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2650. ioaddr = panelp->iobase;
  2651. } else {
  2652. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2653. }
  2654. uartaddr = (i & 0x01) ? 0x080 : 0;
  2655. outb((GFRCR + uartaddr), ioaddr);
  2656. outb(0, (ioaddr + EREG_DATA));
  2657. outb((CCR + uartaddr), ioaddr);
  2658. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2659. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2660. outb((GFRCR + uartaddr), ioaddr);
  2661. for (j = 0; (j < CCR_MAXWAIT); j++) {
  2662. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2663. break;
  2664. }
  2665. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2666. printk("STALLION: cd1400 not responding, "
  2667. "brd=%d panel=%d chip=%d\n",
  2668. panelp->brdnr, panelp->panelnr, i);
  2669. continue;
  2670. }
  2671. chipmask |= (0x1 << i);
  2672. outb((PPR + uartaddr), ioaddr);
  2673. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2674. }
  2675. BRDDISABLE(panelp->brdnr);
  2676. spin_unlock_irqrestore(&brd_lock, flags);
  2677. return chipmask;
  2678. }
  2679. /*****************************************************************************/
  2680. /*
  2681. * Initialize hardware specific port registers.
  2682. */
  2683. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  2684. {
  2685. unsigned long flags;
  2686. #ifdef DEBUG
  2687. printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
  2688. (int) brdp, (int) panelp, (int) portp);
  2689. #endif
  2690. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  2691. (portp == (stlport_t *) NULL))
  2692. return;
  2693. spin_lock_irqsave(&brd_lock, flags);
  2694. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2695. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2696. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2697. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2698. BRDENABLE(portp->brdnr, portp->pagenr);
  2699. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2700. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2701. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2702. BRDDISABLE(portp->brdnr);
  2703. spin_unlock_irqrestore(&brd_lock, flags);
  2704. }
  2705. /*****************************************************************************/
  2706. /*
  2707. * Wait for the command register to be ready. We will poll this,
  2708. * since it won't usually take too long to be ready.
  2709. */
  2710. static void stl_cd1400ccrwait(stlport_t *portp)
  2711. {
  2712. int i;
  2713. for (i = 0; (i < CCR_MAXWAIT); i++) {
  2714. if (stl_cd1400getreg(portp, CCR) == 0) {
  2715. return;
  2716. }
  2717. }
  2718. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2719. portp->portnr, portp->panelnr, portp->brdnr);
  2720. }
  2721. /*****************************************************************************/
  2722. /*
  2723. * Set up the cd1400 registers for a port based on the termios port
  2724. * settings.
  2725. */
  2726. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
  2727. {
  2728. stlbrd_t *brdp;
  2729. unsigned long flags;
  2730. unsigned int clkdiv, baudrate;
  2731. unsigned char cor1, cor2, cor3;
  2732. unsigned char cor4, cor5, ccr;
  2733. unsigned char srer, sreron, sreroff;
  2734. unsigned char mcor1, mcor2, rtpr;
  2735. unsigned char clk, div;
  2736. cor1 = 0;
  2737. cor2 = 0;
  2738. cor3 = 0;
  2739. cor4 = 0;
  2740. cor5 = 0;
  2741. ccr = 0;
  2742. rtpr = 0;
  2743. clk = 0;
  2744. div = 0;
  2745. mcor1 = 0;
  2746. mcor2 = 0;
  2747. sreron = 0;
  2748. sreroff = 0;
  2749. brdp = stl_brds[portp->brdnr];
  2750. if (brdp == (stlbrd_t *) NULL)
  2751. return;
  2752. /*
  2753. * Set up the RX char ignore mask with those RX error types we
  2754. * can ignore. We can get the cd1400 to help us out a little here,
  2755. * it will ignore parity errors and breaks for us.
  2756. */
  2757. portp->rxignoremsk = 0;
  2758. if (tiosp->c_iflag & IGNPAR) {
  2759. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2760. cor1 |= COR1_PARIGNORE;
  2761. }
  2762. if (tiosp->c_iflag & IGNBRK) {
  2763. portp->rxignoremsk |= ST_BREAK;
  2764. cor4 |= COR4_IGNBRK;
  2765. }
  2766. portp->rxmarkmsk = ST_OVERRUN;
  2767. if (tiosp->c_iflag & (INPCK | PARMRK))
  2768. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2769. if (tiosp->c_iflag & BRKINT)
  2770. portp->rxmarkmsk |= ST_BREAK;
  2771. /*
  2772. * Go through the char size, parity and stop bits and set all the
  2773. * option register appropriately.
  2774. */
  2775. switch (tiosp->c_cflag & CSIZE) {
  2776. case CS5:
  2777. cor1 |= COR1_CHL5;
  2778. break;
  2779. case CS6:
  2780. cor1 |= COR1_CHL6;
  2781. break;
  2782. case CS7:
  2783. cor1 |= COR1_CHL7;
  2784. break;
  2785. default:
  2786. cor1 |= COR1_CHL8;
  2787. break;
  2788. }
  2789. if (tiosp->c_cflag & CSTOPB)
  2790. cor1 |= COR1_STOP2;
  2791. else
  2792. cor1 |= COR1_STOP1;
  2793. if (tiosp->c_cflag & PARENB) {
  2794. if (tiosp->c_cflag & PARODD)
  2795. cor1 |= (COR1_PARENB | COR1_PARODD);
  2796. else
  2797. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2798. } else {
  2799. cor1 |= COR1_PARNONE;
  2800. }
  2801. /*
  2802. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2803. * space for hardware flow control and the like. This should be set to
  2804. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2805. * really be based on VTIME.
  2806. */
  2807. cor3 |= FIFO_RXTHRESHOLD;
  2808. rtpr = 2;
  2809. /*
  2810. * Calculate the baud rate timers. For now we will just assume that
  2811. * the input and output baud are the same. Could have used a baud
  2812. * table here, but this way we can generate virtually any baud rate
  2813. * we like!
  2814. */
  2815. baudrate = tiosp->c_cflag & CBAUD;
  2816. if (baudrate & CBAUDEX) {
  2817. baudrate &= ~CBAUDEX;
  2818. if ((baudrate < 1) || (baudrate > 4))
  2819. tiosp->c_cflag &= ~CBAUDEX;
  2820. else
  2821. baudrate += 15;
  2822. }
  2823. baudrate = stl_baudrates[baudrate];
  2824. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2825. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2826. baudrate = 57600;
  2827. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2828. baudrate = 115200;
  2829. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2830. baudrate = 230400;
  2831. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2832. baudrate = 460800;
  2833. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2834. baudrate = (portp->baud_base / portp->custom_divisor);
  2835. }
  2836. if (baudrate > STL_CD1400MAXBAUD)
  2837. baudrate = STL_CD1400MAXBAUD;
  2838. if (baudrate > 0) {
  2839. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  2840. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  2841. if (clkdiv < 0x100)
  2842. break;
  2843. }
  2844. div = (unsigned char) clkdiv;
  2845. }
  2846. /*
  2847. * Check what form of modem signaling is required and set it up.
  2848. */
  2849. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2850. mcor1 |= MCOR1_DCD;
  2851. mcor2 |= MCOR2_DCD;
  2852. sreron |= SRER_MODEM;
  2853. portp->flags |= ASYNC_CHECK_CD;
  2854. } else {
  2855. portp->flags &= ~ASYNC_CHECK_CD;
  2856. }
  2857. /*
  2858. * Setup cd1400 enhanced modes if we can. In particular we want to
  2859. * handle as much of the flow control as possible automatically. As
  2860. * well as saving a few CPU cycles it will also greatly improve flow
  2861. * control reliability.
  2862. */
  2863. if (tiosp->c_iflag & IXON) {
  2864. cor2 |= COR2_TXIBE;
  2865. cor3 |= COR3_SCD12;
  2866. if (tiosp->c_iflag & IXANY)
  2867. cor2 |= COR2_IXM;
  2868. }
  2869. if (tiosp->c_cflag & CRTSCTS) {
  2870. cor2 |= COR2_CTSAE;
  2871. mcor1 |= FIFO_RTSTHRESHOLD;
  2872. }
  2873. /*
  2874. * All cd1400 register values calculated so go through and set
  2875. * them all up.
  2876. */
  2877. #ifdef DEBUG
  2878. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2879. portp->portnr, portp->panelnr, portp->brdnr);
  2880. printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2881. cor1, cor2, cor3, cor4, cor5);
  2882. printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2883. mcor1, mcor2, rtpr, sreron, sreroff);
  2884. printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2885. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2886. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2887. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2888. #endif
  2889. spin_lock_irqsave(&brd_lock, flags);
  2890. BRDENABLE(portp->brdnr, portp->pagenr);
  2891. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2892. srer = stl_cd1400getreg(portp, SRER);
  2893. stl_cd1400setreg(portp, SRER, 0);
  2894. if (stl_cd1400updatereg(portp, COR1, cor1))
  2895. ccr = 1;
  2896. if (stl_cd1400updatereg(portp, COR2, cor2))
  2897. ccr = 1;
  2898. if (stl_cd1400updatereg(portp, COR3, cor3))
  2899. ccr = 1;
  2900. if (ccr) {
  2901. stl_cd1400ccrwait(portp);
  2902. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2903. }
  2904. stl_cd1400setreg(portp, COR4, cor4);
  2905. stl_cd1400setreg(portp, COR5, cor5);
  2906. stl_cd1400setreg(portp, MCOR1, mcor1);
  2907. stl_cd1400setreg(portp, MCOR2, mcor2);
  2908. if (baudrate > 0) {
  2909. stl_cd1400setreg(portp, TCOR, clk);
  2910. stl_cd1400setreg(portp, TBPR, div);
  2911. stl_cd1400setreg(portp, RCOR, clk);
  2912. stl_cd1400setreg(portp, RBPR, div);
  2913. }
  2914. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2915. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2916. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2917. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2918. stl_cd1400setreg(portp, RTPR, rtpr);
  2919. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2920. if (mcor1 & MSVR1_DCD)
  2921. portp->sigs |= TIOCM_CD;
  2922. else
  2923. portp->sigs &= ~TIOCM_CD;
  2924. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2925. BRDDISABLE(portp->brdnr);
  2926. spin_unlock_irqrestore(&brd_lock, flags);
  2927. }
  2928. /*****************************************************************************/
  2929. /*
  2930. * Set the state of the DTR and RTS signals.
  2931. */
  2932. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
  2933. {
  2934. unsigned char msvr1, msvr2;
  2935. unsigned long flags;
  2936. #ifdef DEBUG
  2937. printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
  2938. (int) portp, dtr, rts);
  2939. #endif
  2940. msvr1 = 0;
  2941. msvr2 = 0;
  2942. if (dtr > 0)
  2943. msvr1 = MSVR1_DTR;
  2944. if (rts > 0)
  2945. msvr2 = MSVR2_RTS;
  2946. spin_lock_irqsave(&brd_lock, flags);
  2947. BRDENABLE(portp->brdnr, portp->pagenr);
  2948. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2949. if (rts >= 0)
  2950. stl_cd1400setreg(portp, MSVR2, msvr2);
  2951. if (dtr >= 0)
  2952. stl_cd1400setreg(portp, MSVR1, msvr1);
  2953. BRDDISABLE(portp->brdnr);
  2954. spin_unlock_irqrestore(&brd_lock, flags);
  2955. }
  2956. /*****************************************************************************/
  2957. /*
  2958. * Return the state of the signals.
  2959. */
  2960. static int stl_cd1400getsignals(stlport_t *portp)
  2961. {
  2962. unsigned char msvr1, msvr2;
  2963. unsigned long flags;
  2964. int sigs;
  2965. #ifdef DEBUG
  2966. printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
  2967. #endif
  2968. spin_lock_irqsave(&brd_lock, flags);
  2969. BRDENABLE(portp->brdnr, portp->pagenr);
  2970. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2971. msvr1 = stl_cd1400getreg(portp, MSVR1);
  2972. msvr2 = stl_cd1400getreg(portp, MSVR2);
  2973. BRDDISABLE(portp->brdnr);
  2974. spin_unlock_irqrestore(&brd_lock, flags);
  2975. sigs = 0;
  2976. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  2977. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  2978. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  2979. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  2980. #if 0
  2981. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  2982. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  2983. #else
  2984. sigs |= TIOCM_DSR;
  2985. #endif
  2986. return sigs;
  2987. }
  2988. /*****************************************************************************/
  2989. /*
  2990. * Enable/Disable the Transmitter and/or Receiver.
  2991. */
  2992. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
  2993. {
  2994. unsigned char ccr;
  2995. unsigned long flags;
  2996. #ifdef DEBUG
  2997. printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  2998. (int) portp, rx, tx);
  2999. #endif
  3000. ccr = 0;
  3001. if (tx == 0)
  3002. ccr |= CCR_TXDISABLE;
  3003. else if (tx > 0)
  3004. ccr |= CCR_TXENABLE;
  3005. if (rx == 0)
  3006. ccr |= CCR_RXDISABLE;
  3007. else if (rx > 0)
  3008. ccr |= CCR_RXENABLE;
  3009. spin_lock_irqsave(&brd_lock, flags);
  3010. BRDENABLE(portp->brdnr, portp->pagenr);
  3011. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3012. stl_cd1400ccrwait(portp);
  3013. stl_cd1400setreg(portp, CCR, ccr);
  3014. stl_cd1400ccrwait(portp);
  3015. BRDDISABLE(portp->brdnr);
  3016. spin_unlock_irqrestore(&brd_lock, flags);
  3017. }
  3018. /*****************************************************************************/
  3019. /*
  3020. * Start/stop the Transmitter and/or Receiver.
  3021. */
  3022. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
  3023. {
  3024. unsigned char sreron, sreroff;
  3025. unsigned long flags;
  3026. #ifdef DEBUG
  3027. printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3028. (int) portp, rx, tx);
  3029. #endif
  3030. sreron = 0;
  3031. sreroff = 0;
  3032. if (tx == 0)
  3033. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  3034. else if (tx == 1)
  3035. sreron |= SRER_TXDATA;
  3036. else if (tx >= 2)
  3037. sreron |= SRER_TXEMPTY;
  3038. if (rx == 0)
  3039. sreroff |= SRER_RXDATA;
  3040. else if (rx > 0)
  3041. sreron |= SRER_RXDATA;
  3042. spin_lock_irqsave(&brd_lock, flags);
  3043. BRDENABLE(portp->brdnr, portp->pagenr);
  3044. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3045. stl_cd1400setreg(portp, SRER,
  3046. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  3047. BRDDISABLE(portp->brdnr);
  3048. if (tx > 0)
  3049. set_bit(ASYI_TXBUSY, &portp->istate);
  3050. spin_unlock_irqrestore(&brd_lock, flags);
  3051. }
  3052. /*****************************************************************************/
  3053. /*
  3054. * Disable all interrupts from this port.
  3055. */
  3056. static void stl_cd1400disableintrs(stlport_t *portp)
  3057. {
  3058. unsigned long flags;
  3059. #ifdef DEBUG
  3060. printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
  3061. #endif
  3062. spin_lock_irqsave(&brd_lock, flags);
  3063. BRDENABLE(portp->brdnr, portp->pagenr);
  3064. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3065. stl_cd1400setreg(portp, SRER, 0);
  3066. BRDDISABLE(portp->brdnr);
  3067. spin_unlock_irqrestore(&brd_lock, flags);
  3068. }
  3069. /*****************************************************************************/
  3070. static void stl_cd1400sendbreak(stlport_t *portp, int len)
  3071. {
  3072. unsigned long flags;
  3073. #ifdef DEBUG
  3074. printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3075. #endif
  3076. spin_lock_irqsave(&brd_lock, flags);
  3077. BRDENABLE(portp->brdnr, portp->pagenr);
  3078. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3079. stl_cd1400setreg(portp, SRER,
  3080. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  3081. SRER_TXEMPTY));
  3082. BRDDISABLE(portp->brdnr);
  3083. portp->brklen = len;
  3084. if (len == 1)
  3085. portp->stats.txbreaks++;
  3086. spin_unlock_irqrestore(&brd_lock, flags);
  3087. }
  3088. /*****************************************************************************/
  3089. /*
  3090. * Take flow control actions...
  3091. */
  3092. static void stl_cd1400flowctrl(stlport_t *portp, int state)
  3093. {
  3094. struct tty_struct *tty;
  3095. unsigned long flags;
  3096. #ifdef DEBUG
  3097. printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3098. #endif
  3099. if (portp == (stlport_t *) NULL)
  3100. return;
  3101. tty = portp->tty;
  3102. if (tty == (struct tty_struct *) NULL)
  3103. return;
  3104. spin_lock_irqsave(&brd_lock, flags);
  3105. BRDENABLE(portp->brdnr, portp->pagenr);
  3106. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3107. if (state) {
  3108. if (tty->termios->c_iflag & IXOFF) {
  3109. stl_cd1400ccrwait(portp);
  3110. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3111. portp->stats.rxxon++;
  3112. stl_cd1400ccrwait(portp);
  3113. }
  3114. /*
  3115. * Question: should we return RTS to what it was before? It may
  3116. * have been set by an ioctl... Suppose not, since if you have
  3117. * hardware flow control set then it is pretty silly to go and
  3118. * set the RTS line by hand.
  3119. */
  3120. if (tty->termios->c_cflag & CRTSCTS) {
  3121. stl_cd1400setreg(portp, MCOR1,
  3122. (stl_cd1400getreg(portp, MCOR1) |
  3123. FIFO_RTSTHRESHOLD));
  3124. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  3125. portp->stats.rxrtson++;
  3126. }
  3127. } else {
  3128. if (tty->termios->c_iflag & IXOFF) {
  3129. stl_cd1400ccrwait(portp);
  3130. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3131. portp->stats.rxxoff++;
  3132. stl_cd1400ccrwait(portp);
  3133. }
  3134. if (tty->termios->c_cflag & CRTSCTS) {
  3135. stl_cd1400setreg(portp, MCOR1,
  3136. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  3137. stl_cd1400setreg(portp, MSVR2, 0);
  3138. portp->stats.rxrtsoff++;
  3139. }
  3140. }
  3141. BRDDISABLE(portp->brdnr);
  3142. spin_unlock_irqrestore(&brd_lock, flags);
  3143. }
  3144. /*****************************************************************************/
  3145. /*
  3146. * Send a flow control character...
  3147. */
  3148. static void stl_cd1400sendflow(stlport_t *portp, int state)
  3149. {
  3150. struct tty_struct *tty;
  3151. unsigned long flags;
  3152. #ifdef DEBUG
  3153. printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
  3154. #endif
  3155. if (portp == (stlport_t *) NULL)
  3156. return;
  3157. tty = portp->tty;
  3158. if (tty == (struct tty_struct *) NULL)
  3159. return;
  3160. spin_lock_irqsave(&brd_lock, flags);
  3161. BRDENABLE(portp->brdnr, portp->pagenr);
  3162. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3163. if (state) {
  3164. stl_cd1400ccrwait(portp);
  3165. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3166. portp->stats.rxxon++;
  3167. stl_cd1400ccrwait(portp);
  3168. } else {
  3169. stl_cd1400ccrwait(portp);
  3170. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3171. portp->stats.rxxoff++;
  3172. stl_cd1400ccrwait(portp);
  3173. }
  3174. BRDDISABLE(portp->brdnr);
  3175. spin_unlock_irqrestore(&brd_lock, flags);
  3176. }
  3177. /*****************************************************************************/
  3178. static void stl_cd1400flush(stlport_t *portp)
  3179. {
  3180. unsigned long flags;
  3181. #ifdef DEBUG
  3182. printk("stl_cd1400flush(portp=%x)\n", (int) portp);
  3183. #endif
  3184. if (portp == (stlport_t *) NULL)
  3185. return;
  3186. spin_lock_irqsave(&brd_lock, flags);
  3187. BRDENABLE(portp->brdnr, portp->pagenr);
  3188. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3189. stl_cd1400ccrwait(portp);
  3190. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  3191. stl_cd1400ccrwait(portp);
  3192. portp->tx.tail = portp->tx.head;
  3193. BRDDISABLE(portp->brdnr);
  3194. spin_unlock_irqrestore(&brd_lock, flags);
  3195. }
  3196. /*****************************************************************************/
  3197. /*
  3198. * Return the current state of data flow on this port. This is only
  3199. * really interresting when determining if data has fully completed
  3200. * transmission or not... This is easy for the cd1400, it accurately
  3201. * maintains the busy port flag.
  3202. */
  3203. static int stl_cd1400datastate(stlport_t *portp)
  3204. {
  3205. #ifdef DEBUG
  3206. printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
  3207. #endif
  3208. if (portp == (stlport_t *) NULL)
  3209. return 0;
  3210. return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
  3211. }
  3212. /*****************************************************************************/
  3213. /*
  3214. * Interrupt service routine for cd1400 EasyIO boards.
  3215. */
  3216. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
  3217. {
  3218. unsigned char svrtype;
  3219. #ifdef DEBUG
  3220. printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
  3221. (int) panelp, iobase);
  3222. #endif
  3223. spin_lock(&brd_lock);
  3224. outb(SVRR, iobase);
  3225. svrtype = inb(iobase + EREG_DATA);
  3226. if (panelp->nrports > 4) {
  3227. outb((SVRR + 0x80), iobase);
  3228. svrtype |= inb(iobase + EREG_DATA);
  3229. }
  3230. if (svrtype & SVRR_RX)
  3231. stl_cd1400rxisr(panelp, iobase);
  3232. else if (svrtype & SVRR_TX)
  3233. stl_cd1400txisr(panelp, iobase);
  3234. else if (svrtype & SVRR_MDM)
  3235. stl_cd1400mdmisr(panelp, iobase);
  3236. spin_unlock(&brd_lock);
  3237. }
  3238. /*****************************************************************************/
  3239. /*
  3240. * Interrupt service routine for cd1400 panels.
  3241. */
  3242. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
  3243. {
  3244. unsigned char svrtype;
  3245. #ifdef DEBUG
  3246. printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
  3247. iobase);
  3248. #endif
  3249. outb(SVRR, iobase);
  3250. svrtype = inb(iobase + EREG_DATA);
  3251. outb((SVRR + 0x80), iobase);
  3252. svrtype |= inb(iobase + EREG_DATA);
  3253. if (svrtype & SVRR_RX)
  3254. stl_cd1400rxisr(panelp, iobase);
  3255. else if (svrtype & SVRR_TX)
  3256. stl_cd1400txisr(panelp, iobase);
  3257. else if (svrtype & SVRR_MDM)
  3258. stl_cd1400mdmisr(panelp, iobase);
  3259. }
  3260. /*****************************************************************************/
  3261. /*
  3262. * Unfortunately we need to handle breaks in the TX data stream, since
  3263. * this is the only way to generate them on the cd1400.
  3264. */
  3265. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
  3266. {
  3267. if (portp->brklen == 1) {
  3268. outb((COR2 + portp->uartaddr), ioaddr);
  3269. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  3270. (ioaddr + EREG_DATA));
  3271. outb((TDR + portp->uartaddr), ioaddr);
  3272. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3273. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  3274. outb((SRER + portp->uartaddr), ioaddr);
  3275. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  3276. (ioaddr + EREG_DATA));
  3277. return 1;
  3278. } else if (portp->brklen > 1) {
  3279. outb((TDR + portp->uartaddr), ioaddr);
  3280. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3281. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  3282. portp->brklen = -1;
  3283. return 1;
  3284. } else {
  3285. outb((COR2 + portp->uartaddr), ioaddr);
  3286. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  3287. (ioaddr + EREG_DATA));
  3288. portp->brklen = 0;
  3289. }
  3290. return 0;
  3291. }
  3292. /*****************************************************************************/
  3293. /*
  3294. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3295. * chars is pretty simple, stuff as many as possible from the TX buffer
  3296. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  3297. * are embedded as commands in the data stream. Oh no, had to use a goto!
  3298. * This could be optimized more, will do when I get time...
  3299. * In practice it is possible that interrupts are enabled but that the
  3300. * port has been hung up. Need to handle not having any TX buffer here,
  3301. * this is done by using the side effect that head and tail will also
  3302. * be NULL if the buffer has been freed.
  3303. */
  3304. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
  3305. {
  3306. stlport_t *portp;
  3307. int len, stlen;
  3308. char *head, *tail;
  3309. unsigned char ioack, srer;
  3310. #ifdef DEBUG
  3311. printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3312. #endif
  3313. ioack = inb(ioaddr + EREG_TXACK);
  3314. if (((ioack & panelp->ackmask) != 0) ||
  3315. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  3316. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  3317. return;
  3318. }
  3319. portp = panelp->ports[(ioack >> 3)];
  3320. /*
  3321. * Unfortunately we need to handle breaks in the data stream, since
  3322. * this is the only way to generate them on the cd1400. Do it now if
  3323. * a break is to be sent.
  3324. */
  3325. if (portp->brklen != 0)
  3326. if (stl_cd1400breakisr(portp, ioaddr))
  3327. goto stl_txalldone;
  3328. head = portp->tx.head;
  3329. tail = portp->tx.tail;
  3330. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3331. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3332. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3333. set_bit(ASYI_TXLOW, &portp->istate);
  3334. schedule_work(&portp->tqueue);
  3335. }
  3336. if (len == 0) {
  3337. outb((SRER + portp->uartaddr), ioaddr);
  3338. srer = inb(ioaddr + EREG_DATA);
  3339. if (srer & SRER_TXDATA) {
  3340. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  3341. } else {
  3342. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  3343. clear_bit(ASYI_TXBUSY, &portp->istate);
  3344. }
  3345. outb(srer, (ioaddr + EREG_DATA));
  3346. } else {
  3347. len = MIN(len, CD1400_TXFIFOSIZE);
  3348. portp->stats.txtotal += len;
  3349. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3350. outb((TDR + portp->uartaddr), ioaddr);
  3351. outsb((ioaddr + EREG_DATA), tail, stlen);
  3352. len -= stlen;
  3353. tail += stlen;
  3354. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3355. tail = portp->tx.buf;
  3356. if (len > 0) {
  3357. outsb((ioaddr + EREG_DATA), tail, len);
  3358. tail += len;
  3359. }
  3360. portp->tx.tail = tail;
  3361. }
  3362. stl_txalldone:
  3363. outb((EOSRR + portp->uartaddr), ioaddr);
  3364. outb(0, (ioaddr + EREG_DATA));
  3365. }
  3366. /*****************************************************************************/
  3367. /*
  3368. * Receive character interrupt handler. Determine if we have good chars
  3369. * or bad chars and then process appropriately. Good chars are easy
  3370. * just shove the lot into the RX buffer and set all status byte to 0.
  3371. * If a bad RX char then process as required. This routine needs to be
  3372. * fast! In practice it is possible that we get an interrupt on a port
  3373. * that is closed. This can happen on hangups - since they completely
  3374. * shutdown a port not in user context. Need to handle this case.
  3375. */
  3376. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
  3377. {
  3378. stlport_t *portp;
  3379. struct tty_struct *tty;
  3380. unsigned int ioack, len, buflen;
  3381. unsigned char status;
  3382. char ch;
  3383. #ifdef DEBUG
  3384. printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3385. #endif
  3386. ioack = inb(ioaddr + EREG_RXACK);
  3387. if ((ioack & panelp->ackmask) != 0) {
  3388. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3389. return;
  3390. }
  3391. portp = panelp->ports[(ioack >> 3)];
  3392. tty = portp->tty;
  3393. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3394. outb((RDCR + portp->uartaddr), ioaddr);
  3395. len = inb(ioaddr + EREG_DATA);
  3396. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3397. len = MIN(len, sizeof(stl_unwanted));
  3398. outb((RDSR + portp->uartaddr), ioaddr);
  3399. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3400. portp->stats.rxlost += len;
  3401. portp->stats.rxtotal += len;
  3402. } else {
  3403. len = MIN(len, buflen);
  3404. if (len > 0) {
  3405. unsigned char *ptr;
  3406. outb((RDSR + portp->uartaddr), ioaddr);
  3407. tty_prepare_flip_string(tty, &ptr, len);
  3408. insb((ioaddr + EREG_DATA), ptr, len);
  3409. tty_schedule_flip(tty);
  3410. portp->stats.rxtotal += len;
  3411. }
  3412. }
  3413. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3414. outb((RDSR + portp->uartaddr), ioaddr);
  3415. status = inb(ioaddr + EREG_DATA);
  3416. ch = inb(ioaddr + EREG_DATA);
  3417. if (status & ST_PARITY)
  3418. portp->stats.rxparity++;
  3419. if (status & ST_FRAMING)
  3420. portp->stats.rxframing++;
  3421. if (status & ST_OVERRUN)
  3422. portp->stats.rxoverrun++;
  3423. if (status & ST_BREAK)
  3424. portp->stats.rxbreaks++;
  3425. if (status & ST_SCHARMASK) {
  3426. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3427. portp->stats.txxon++;
  3428. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3429. portp->stats.txxoff++;
  3430. goto stl_rxalldone;
  3431. }
  3432. if (tty != NULL && (portp->rxignoremsk & status) == 0) {
  3433. if (portp->rxmarkmsk & status) {
  3434. if (status & ST_BREAK) {
  3435. status = TTY_BREAK;
  3436. if (portp->flags & ASYNC_SAK) {
  3437. do_SAK(tty);
  3438. BRDENABLE(portp->brdnr, portp->pagenr);
  3439. }
  3440. } else if (status & ST_PARITY) {
  3441. status = TTY_PARITY;
  3442. } else if (status & ST_FRAMING) {
  3443. status = TTY_FRAME;
  3444. } else if(status & ST_OVERRUN) {
  3445. status = TTY_OVERRUN;
  3446. } else {
  3447. status = 0;
  3448. }
  3449. } else {
  3450. status = 0;
  3451. }
  3452. tty_insert_flip_char(tty, ch, status);
  3453. tty_schedule_flip(tty);
  3454. }
  3455. } else {
  3456. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3457. return;
  3458. }
  3459. stl_rxalldone:
  3460. outb((EOSRR + portp->uartaddr), ioaddr);
  3461. outb(0, (ioaddr + EREG_DATA));
  3462. }
  3463. /*****************************************************************************/
  3464. /*
  3465. * Modem interrupt handler. The is called when the modem signal line
  3466. * (DCD) has changed state. Leave most of the work to the off-level
  3467. * processing routine.
  3468. */
  3469. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
  3470. {
  3471. stlport_t *portp;
  3472. unsigned int ioack;
  3473. unsigned char misr;
  3474. #ifdef DEBUG
  3475. printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
  3476. #endif
  3477. ioack = inb(ioaddr + EREG_MDACK);
  3478. if (((ioack & panelp->ackmask) != 0) ||
  3479. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3480. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3481. return;
  3482. }
  3483. portp = panelp->ports[(ioack >> 3)];
  3484. outb((MISR + portp->uartaddr), ioaddr);
  3485. misr = inb(ioaddr + EREG_DATA);
  3486. if (misr & MISR_DCD) {
  3487. set_bit(ASYI_DCDCHANGE, &portp->istate);
  3488. schedule_work(&portp->tqueue);
  3489. portp->stats.modem++;
  3490. }
  3491. outb((EOSRR + portp->uartaddr), ioaddr);
  3492. outb(0, (ioaddr + EREG_DATA));
  3493. }
  3494. /*****************************************************************************/
  3495. /* SC26198 HARDWARE FUNCTIONS */
  3496. /*****************************************************************************/
  3497. /*
  3498. * These functions get/set/update the registers of the sc26198 UARTs.
  3499. * Access to the sc26198 registers is via an address/data io port pair.
  3500. * (Maybe should make this inline...)
  3501. */
  3502. static int stl_sc26198getreg(stlport_t *portp, int regnr)
  3503. {
  3504. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3505. return inb(portp->ioaddr + XP_DATA);
  3506. }
  3507. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
  3508. {
  3509. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3510. outb(value, (portp->ioaddr + XP_DATA));
  3511. }
  3512. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
  3513. {
  3514. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3515. if (inb(portp->ioaddr + XP_DATA) != value) {
  3516. outb(value, (portp->ioaddr + XP_DATA));
  3517. return 1;
  3518. }
  3519. return 0;
  3520. }
  3521. /*****************************************************************************/
  3522. /*
  3523. * Functions to get and set the sc26198 global registers.
  3524. */
  3525. static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
  3526. {
  3527. outb(regnr, (portp->ioaddr + XP_ADDR));
  3528. return inb(portp->ioaddr + XP_DATA);
  3529. }
  3530. #if 0
  3531. static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
  3532. {
  3533. outb(regnr, (portp->ioaddr + XP_ADDR));
  3534. outb(value, (portp->ioaddr + XP_DATA));
  3535. }
  3536. #endif
  3537. /*****************************************************************************/
  3538. /*
  3539. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3540. * these ports are on - since the port io registers are almost
  3541. * identical when dealing with ports.
  3542. */
  3543. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  3544. {
  3545. int chipmask, i;
  3546. int nrchips, ioaddr;
  3547. #ifdef DEBUG
  3548. printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
  3549. (int) brdp, (int) panelp);
  3550. #endif
  3551. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3552. /*
  3553. * Check that each chip is present and started up OK.
  3554. */
  3555. chipmask = 0;
  3556. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3557. if (brdp->brdtype == BRD_ECHPCI)
  3558. outb(panelp->pagenr, brdp->ioctrl);
  3559. for (i = 0; (i < nrchips); i++) {
  3560. ioaddr = panelp->iobase + (i * 4);
  3561. outb(SCCR, (ioaddr + XP_ADDR));
  3562. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3563. outb(TSTR, (ioaddr + XP_ADDR));
  3564. if (inb(ioaddr + XP_DATA) != 0) {
  3565. printk("STALLION: sc26198 not responding, "
  3566. "brd=%d panel=%d chip=%d\n",
  3567. panelp->brdnr, panelp->panelnr, i);
  3568. continue;
  3569. }
  3570. chipmask |= (0x1 << i);
  3571. outb(GCCR, (ioaddr + XP_ADDR));
  3572. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3573. outb(WDTRCR, (ioaddr + XP_ADDR));
  3574. outb(0xff, (ioaddr + XP_DATA));
  3575. }
  3576. BRDDISABLE(panelp->brdnr);
  3577. return chipmask;
  3578. }
  3579. /*****************************************************************************/
  3580. /*
  3581. * Initialize hardware specific port registers.
  3582. */
  3583. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  3584. {
  3585. #ifdef DEBUG
  3586. printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
  3587. (int) brdp, (int) panelp, (int) portp);
  3588. #endif
  3589. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  3590. (portp == (stlport_t *) NULL))
  3591. return;
  3592. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3593. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3594. portp->pagenr = panelp->pagenr;
  3595. portp->hwid = 0x1;
  3596. BRDENABLE(portp->brdnr, portp->pagenr);
  3597. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3598. BRDDISABLE(portp->brdnr);
  3599. }
  3600. /*****************************************************************************/
  3601. /*
  3602. * Set up the sc26198 registers for a port based on the termios port
  3603. * settings.
  3604. */
  3605. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
  3606. {
  3607. stlbrd_t *brdp;
  3608. unsigned long flags;
  3609. unsigned int baudrate;
  3610. unsigned char mr0, mr1, mr2, clk;
  3611. unsigned char imron, imroff, iopr, ipr;
  3612. mr0 = 0;
  3613. mr1 = 0;
  3614. mr2 = 0;
  3615. clk = 0;
  3616. iopr = 0;
  3617. imron = 0;
  3618. imroff = 0;
  3619. brdp = stl_brds[portp->brdnr];
  3620. if (brdp == (stlbrd_t *) NULL)
  3621. return;
  3622. /*
  3623. * Set up the RX char ignore mask with those RX error types we
  3624. * can ignore.
  3625. */
  3626. portp->rxignoremsk = 0;
  3627. if (tiosp->c_iflag & IGNPAR)
  3628. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3629. SR_RXOVERRUN);
  3630. if (tiosp->c_iflag & IGNBRK)
  3631. portp->rxignoremsk |= SR_RXBREAK;
  3632. portp->rxmarkmsk = SR_RXOVERRUN;
  3633. if (tiosp->c_iflag & (INPCK | PARMRK))
  3634. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3635. if (tiosp->c_iflag & BRKINT)
  3636. portp->rxmarkmsk |= SR_RXBREAK;
  3637. /*
  3638. * Go through the char size, parity and stop bits and set all the
  3639. * option register appropriately.
  3640. */
  3641. switch (tiosp->c_cflag & CSIZE) {
  3642. case CS5:
  3643. mr1 |= MR1_CS5;
  3644. break;
  3645. case CS6:
  3646. mr1 |= MR1_CS6;
  3647. break;
  3648. case CS7:
  3649. mr1 |= MR1_CS7;
  3650. break;
  3651. default:
  3652. mr1 |= MR1_CS8;
  3653. break;
  3654. }
  3655. if (tiosp->c_cflag & CSTOPB)
  3656. mr2 |= MR2_STOP2;
  3657. else
  3658. mr2 |= MR2_STOP1;
  3659. if (tiosp->c_cflag & PARENB) {
  3660. if (tiosp->c_cflag & PARODD)
  3661. mr1 |= (MR1_PARENB | MR1_PARODD);
  3662. else
  3663. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3664. } else {
  3665. mr1 |= MR1_PARNONE;
  3666. }
  3667. mr1 |= MR1_ERRBLOCK;
  3668. /*
  3669. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3670. * space for hardware flow control and the like. This should be set to
  3671. * VMIN.
  3672. */
  3673. mr2 |= MR2_RXFIFOHALF;
  3674. /*
  3675. * Calculate the baud rate timers. For now we will just assume that
  3676. * the input and output baud are the same. The sc26198 has a fixed
  3677. * baud rate table, so only discrete baud rates possible.
  3678. */
  3679. baudrate = tiosp->c_cflag & CBAUD;
  3680. if (baudrate & CBAUDEX) {
  3681. baudrate &= ~CBAUDEX;
  3682. if ((baudrate < 1) || (baudrate > 4))
  3683. tiosp->c_cflag &= ~CBAUDEX;
  3684. else
  3685. baudrate += 15;
  3686. }
  3687. baudrate = stl_baudrates[baudrate];
  3688. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3689. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3690. baudrate = 57600;
  3691. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3692. baudrate = 115200;
  3693. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3694. baudrate = 230400;
  3695. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3696. baudrate = 460800;
  3697. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3698. baudrate = (portp->baud_base / portp->custom_divisor);
  3699. }
  3700. if (baudrate > STL_SC26198MAXBAUD)
  3701. baudrate = STL_SC26198MAXBAUD;
  3702. if (baudrate > 0) {
  3703. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  3704. if (baudrate <= sc26198_baudtable[clk])
  3705. break;
  3706. }
  3707. }
  3708. /*
  3709. * Check what form of modem signaling is required and set it up.
  3710. */
  3711. if (tiosp->c_cflag & CLOCAL) {
  3712. portp->flags &= ~ASYNC_CHECK_CD;
  3713. } else {
  3714. iopr |= IOPR_DCDCOS;
  3715. imron |= IR_IOPORT;
  3716. portp->flags |= ASYNC_CHECK_CD;
  3717. }
  3718. /*
  3719. * Setup sc26198 enhanced modes if we can. In particular we want to
  3720. * handle as much of the flow control as possible automatically. As
  3721. * well as saving a few CPU cycles it will also greatly improve flow
  3722. * control reliability.
  3723. */
  3724. if (tiosp->c_iflag & IXON) {
  3725. mr0 |= MR0_SWFTX | MR0_SWFT;
  3726. imron |= IR_XONXOFF;
  3727. } else {
  3728. imroff |= IR_XONXOFF;
  3729. }
  3730. if (tiosp->c_iflag & IXOFF)
  3731. mr0 |= MR0_SWFRX;
  3732. if (tiosp->c_cflag & CRTSCTS) {
  3733. mr2 |= MR2_AUTOCTS;
  3734. mr1 |= MR1_AUTORTS;
  3735. }
  3736. /*
  3737. * All sc26198 register values calculated so go through and set
  3738. * them all up.
  3739. */
  3740. #ifdef DEBUG
  3741. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3742. portp->portnr, portp->panelnr, portp->brdnr);
  3743. printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3744. printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3745. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3746. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3747. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3748. #endif
  3749. spin_lock_irqsave(&brd_lock, flags);
  3750. BRDENABLE(portp->brdnr, portp->pagenr);
  3751. stl_sc26198setreg(portp, IMR, 0);
  3752. stl_sc26198updatereg(portp, MR0, mr0);
  3753. stl_sc26198updatereg(portp, MR1, mr1);
  3754. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3755. stl_sc26198updatereg(portp, MR2, mr2);
  3756. stl_sc26198updatereg(portp, IOPIOR,
  3757. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3758. if (baudrate > 0) {
  3759. stl_sc26198setreg(portp, TXCSR, clk);
  3760. stl_sc26198setreg(portp, RXCSR, clk);
  3761. }
  3762. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3763. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3764. ipr = stl_sc26198getreg(portp, IPR);
  3765. if (ipr & IPR_DCD)
  3766. portp->sigs &= ~TIOCM_CD;
  3767. else
  3768. portp->sigs |= TIOCM_CD;
  3769. portp->imr = (portp->imr & ~imroff) | imron;
  3770. stl_sc26198setreg(portp, IMR, portp->imr);
  3771. BRDDISABLE(portp->brdnr);
  3772. spin_unlock_irqrestore(&brd_lock, flags);
  3773. }
  3774. /*****************************************************************************/
  3775. /*
  3776. * Set the state of the DTR and RTS signals.
  3777. */
  3778. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
  3779. {
  3780. unsigned char iopioron, iopioroff;
  3781. unsigned long flags;
  3782. #ifdef DEBUG
  3783. printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
  3784. (int) portp, dtr, rts);
  3785. #endif
  3786. iopioron = 0;
  3787. iopioroff = 0;
  3788. if (dtr == 0)
  3789. iopioroff |= IPR_DTR;
  3790. else if (dtr > 0)
  3791. iopioron |= IPR_DTR;
  3792. if (rts == 0)
  3793. iopioroff |= IPR_RTS;
  3794. else if (rts > 0)
  3795. iopioron |= IPR_RTS;
  3796. spin_lock_irqsave(&brd_lock, flags);
  3797. BRDENABLE(portp->brdnr, portp->pagenr);
  3798. stl_sc26198setreg(portp, IOPIOR,
  3799. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3800. BRDDISABLE(portp->brdnr);
  3801. spin_unlock_irqrestore(&brd_lock, flags);
  3802. }
  3803. /*****************************************************************************/
  3804. /*
  3805. * Return the state of the signals.
  3806. */
  3807. static int stl_sc26198getsignals(stlport_t *portp)
  3808. {
  3809. unsigned char ipr;
  3810. unsigned long flags;
  3811. int sigs;
  3812. #ifdef DEBUG
  3813. printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
  3814. #endif
  3815. spin_lock_irqsave(&brd_lock, flags);
  3816. BRDENABLE(portp->brdnr, portp->pagenr);
  3817. ipr = stl_sc26198getreg(portp, IPR);
  3818. BRDDISABLE(portp->brdnr);
  3819. spin_unlock_irqrestore(&brd_lock, flags);
  3820. sigs = 0;
  3821. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3822. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3823. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3824. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3825. sigs |= TIOCM_DSR;
  3826. return sigs;
  3827. }
  3828. /*****************************************************************************/
  3829. /*
  3830. * Enable/Disable the Transmitter and/or Receiver.
  3831. */
  3832. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
  3833. {
  3834. unsigned char ccr;
  3835. unsigned long flags;
  3836. #ifdef DEBUG
  3837. printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  3838. (int) portp, rx, tx);
  3839. #endif
  3840. ccr = portp->crenable;
  3841. if (tx == 0)
  3842. ccr &= ~CR_TXENABLE;
  3843. else if (tx > 0)
  3844. ccr |= CR_TXENABLE;
  3845. if (rx == 0)
  3846. ccr &= ~CR_RXENABLE;
  3847. else if (rx > 0)
  3848. ccr |= CR_RXENABLE;
  3849. spin_lock_irqsave(&brd_lock, flags);
  3850. BRDENABLE(portp->brdnr, portp->pagenr);
  3851. stl_sc26198setreg(portp, SCCR, ccr);
  3852. BRDDISABLE(portp->brdnr);
  3853. portp->crenable = ccr;
  3854. spin_unlock_irqrestore(&brd_lock, flags);
  3855. }
  3856. /*****************************************************************************/
  3857. /*
  3858. * Start/stop the Transmitter and/or Receiver.
  3859. */
  3860. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
  3861. {
  3862. unsigned char imr;
  3863. unsigned long flags;
  3864. #ifdef DEBUG
  3865. printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3866. (int) portp, rx, tx);
  3867. #endif
  3868. imr = portp->imr;
  3869. if (tx == 0)
  3870. imr &= ~IR_TXRDY;
  3871. else if (tx == 1)
  3872. imr |= IR_TXRDY;
  3873. if (rx == 0)
  3874. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3875. else if (rx > 0)
  3876. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3877. spin_lock_irqsave(&brd_lock, flags);
  3878. BRDENABLE(portp->brdnr, portp->pagenr);
  3879. stl_sc26198setreg(portp, IMR, imr);
  3880. BRDDISABLE(portp->brdnr);
  3881. portp->imr = imr;
  3882. if (tx > 0)
  3883. set_bit(ASYI_TXBUSY, &portp->istate);
  3884. spin_unlock_irqrestore(&brd_lock, flags);
  3885. }
  3886. /*****************************************************************************/
  3887. /*
  3888. * Disable all interrupts from this port.
  3889. */
  3890. static void stl_sc26198disableintrs(stlport_t *portp)
  3891. {
  3892. unsigned long flags;
  3893. #ifdef DEBUG
  3894. printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
  3895. #endif
  3896. spin_lock_irqsave(&brd_lock, flags);
  3897. BRDENABLE(portp->brdnr, portp->pagenr);
  3898. portp->imr = 0;
  3899. stl_sc26198setreg(portp, IMR, 0);
  3900. BRDDISABLE(portp->brdnr);
  3901. spin_unlock_irqrestore(&brd_lock, flags);
  3902. }
  3903. /*****************************************************************************/
  3904. static void stl_sc26198sendbreak(stlport_t *portp, int len)
  3905. {
  3906. unsigned long flags;
  3907. #ifdef DEBUG
  3908. printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3909. #endif
  3910. spin_lock_irqsave(&brd_lock, flags);
  3911. BRDENABLE(portp->brdnr, portp->pagenr);
  3912. if (len == 1) {
  3913. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3914. portp->stats.txbreaks++;
  3915. } else {
  3916. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3917. }
  3918. BRDDISABLE(portp->brdnr);
  3919. spin_unlock_irqrestore(&brd_lock, flags);
  3920. }
  3921. /*****************************************************************************/
  3922. /*
  3923. * Take flow control actions...
  3924. */
  3925. static void stl_sc26198flowctrl(stlport_t *portp, int state)
  3926. {
  3927. struct tty_struct *tty;
  3928. unsigned long flags;
  3929. unsigned char mr0;
  3930. #ifdef DEBUG
  3931. printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3932. #endif
  3933. if (portp == (stlport_t *) NULL)
  3934. return;
  3935. tty = portp->tty;
  3936. if (tty == (struct tty_struct *) NULL)
  3937. return;
  3938. spin_lock_irqsave(&brd_lock, flags);
  3939. BRDENABLE(portp->brdnr, portp->pagenr);
  3940. if (state) {
  3941. if (tty->termios->c_iflag & IXOFF) {
  3942. mr0 = stl_sc26198getreg(portp, MR0);
  3943. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3944. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3945. mr0 |= MR0_SWFRX;
  3946. portp->stats.rxxon++;
  3947. stl_sc26198wait(portp);
  3948. stl_sc26198setreg(portp, MR0, mr0);
  3949. }
  3950. /*
  3951. * Question: should we return RTS to what it was before? It may
  3952. * have been set by an ioctl... Suppose not, since if you have
  3953. * hardware flow control set then it is pretty silly to go and
  3954. * set the RTS line by hand.
  3955. */
  3956. if (tty->termios->c_cflag & CRTSCTS) {
  3957. stl_sc26198setreg(portp, MR1,
  3958. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  3959. stl_sc26198setreg(portp, IOPIOR,
  3960. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  3961. portp->stats.rxrtson++;
  3962. }
  3963. } else {
  3964. if (tty->termios->c_iflag & IXOFF) {
  3965. mr0 = stl_sc26198getreg(portp, MR0);
  3966. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3967. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3968. mr0 &= ~MR0_SWFRX;
  3969. portp->stats.rxxoff++;
  3970. stl_sc26198wait(portp);
  3971. stl_sc26198setreg(portp, MR0, mr0);
  3972. }
  3973. if (tty->termios->c_cflag & CRTSCTS) {
  3974. stl_sc26198setreg(portp, MR1,
  3975. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  3976. stl_sc26198setreg(portp, IOPIOR,
  3977. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  3978. portp->stats.rxrtsoff++;
  3979. }
  3980. }
  3981. BRDDISABLE(portp->brdnr);
  3982. spin_unlock_irqrestore(&brd_lock, flags);
  3983. }
  3984. /*****************************************************************************/
  3985. /*
  3986. * Send a flow control character.
  3987. */
  3988. static void stl_sc26198sendflow(stlport_t *portp, int state)
  3989. {
  3990. struct tty_struct *tty;
  3991. unsigned long flags;
  3992. unsigned char mr0;
  3993. #ifdef DEBUG
  3994. printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
  3995. #endif
  3996. if (portp == (stlport_t *) NULL)
  3997. return;
  3998. tty = portp->tty;
  3999. if (tty == (struct tty_struct *) NULL)
  4000. return;
  4001. spin_lock_irqsave(&brd_lock, flags);
  4002. BRDENABLE(portp->brdnr, portp->pagenr);
  4003. if (state) {
  4004. mr0 = stl_sc26198getreg(portp, MR0);
  4005. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4006. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  4007. mr0 |= MR0_SWFRX;
  4008. portp->stats.rxxon++;
  4009. stl_sc26198wait(portp);
  4010. stl_sc26198setreg(portp, MR0, mr0);
  4011. } else {
  4012. mr0 = stl_sc26198getreg(portp, MR0);
  4013. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4014. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  4015. mr0 &= ~MR0_SWFRX;
  4016. portp->stats.rxxoff++;
  4017. stl_sc26198wait(portp);
  4018. stl_sc26198setreg(portp, MR0, mr0);
  4019. }
  4020. BRDDISABLE(portp->brdnr);
  4021. spin_unlock_irqrestore(&brd_lock, flags);
  4022. }
  4023. /*****************************************************************************/
  4024. static void stl_sc26198flush(stlport_t *portp)
  4025. {
  4026. unsigned long flags;
  4027. #ifdef DEBUG
  4028. printk("stl_sc26198flush(portp=%x)\n", (int) portp);
  4029. #endif
  4030. if (portp == (stlport_t *) NULL)
  4031. return;
  4032. spin_lock_irqsave(&brd_lock, flags);
  4033. BRDENABLE(portp->brdnr, portp->pagenr);
  4034. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  4035. stl_sc26198setreg(portp, SCCR, portp->crenable);
  4036. BRDDISABLE(portp->brdnr);
  4037. portp->tx.tail = portp->tx.head;
  4038. spin_unlock_irqrestore(&brd_lock, flags);
  4039. }
  4040. /*****************************************************************************/
  4041. /*
  4042. * Return the current state of data flow on this port. This is only
  4043. * really interresting when determining if data has fully completed
  4044. * transmission or not... The sc26198 interrupt scheme cannot
  4045. * determine when all data has actually drained, so we need to
  4046. * check the port statusy register to be sure.
  4047. */
  4048. static int stl_sc26198datastate(stlport_t *portp)
  4049. {
  4050. unsigned long flags;
  4051. unsigned char sr;
  4052. #ifdef DEBUG
  4053. printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
  4054. #endif
  4055. if (portp == (stlport_t *) NULL)
  4056. return 0;
  4057. if (test_bit(ASYI_TXBUSY, &portp->istate))
  4058. return 1;
  4059. spin_lock_irqsave(&brd_lock, flags);
  4060. BRDENABLE(portp->brdnr, portp->pagenr);
  4061. sr = stl_sc26198getreg(portp, SR);
  4062. BRDDISABLE(portp->brdnr);
  4063. spin_unlock_irqrestore(&brd_lock, flags);
  4064. return (sr & SR_TXEMPTY) ? 0 : 1;
  4065. }
  4066. /*****************************************************************************/
  4067. /*
  4068. * Delay for a small amount of time, to give the sc26198 a chance
  4069. * to process a command...
  4070. */
  4071. static void stl_sc26198wait(stlport_t *portp)
  4072. {
  4073. int i;
  4074. #ifdef DEBUG
  4075. printk("stl_sc26198wait(portp=%x)\n", (int) portp);
  4076. #endif
  4077. if (portp == (stlport_t *) NULL)
  4078. return;
  4079. for (i = 0; (i < 20); i++)
  4080. stl_sc26198getglobreg(portp, TSTR);
  4081. }
  4082. /*****************************************************************************/
  4083. /*
  4084. * If we are TX flow controlled and in IXANY mode then we may
  4085. * need to unflow control here. We gotta do this because of the
  4086. * automatic flow control modes of the sc26198.
  4087. */
  4088. static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
  4089. {
  4090. unsigned char mr0;
  4091. mr0 = stl_sc26198getreg(portp, MR0);
  4092. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4093. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  4094. stl_sc26198wait(portp);
  4095. stl_sc26198setreg(portp, MR0, mr0);
  4096. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4097. }
  4098. /*****************************************************************************/
  4099. /*
  4100. * Interrupt service routine for sc26198 panels.
  4101. */
  4102. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
  4103. {
  4104. stlport_t *portp;
  4105. unsigned int iack;
  4106. spin_lock(&brd_lock);
  4107. /*
  4108. * Work around bug in sc26198 chip... Cannot have A6 address
  4109. * line of UART high, else iack will be returned as 0.
  4110. */
  4111. outb(0, (iobase + 1));
  4112. iack = inb(iobase + XP_IACK);
  4113. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  4114. if (iack & IVR_RXDATA)
  4115. stl_sc26198rxisr(portp, iack);
  4116. else if (iack & IVR_TXDATA)
  4117. stl_sc26198txisr(portp);
  4118. else
  4119. stl_sc26198otherisr(portp, iack);
  4120. spin_unlock(&brd_lock);
  4121. }
  4122. /*****************************************************************************/
  4123. /*
  4124. * Transmit interrupt handler. This has gotta be fast! Handling TX
  4125. * chars is pretty simple, stuff as many as possible from the TX buffer
  4126. * into the sc26198 FIFO.
  4127. * In practice it is possible that interrupts are enabled but that the
  4128. * port has been hung up. Need to handle not having any TX buffer here,
  4129. * this is done by using the side effect that head and tail will also
  4130. * be NULL if the buffer has been freed.
  4131. */
  4132. static void stl_sc26198txisr(stlport_t *portp)
  4133. {
  4134. unsigned int ioaddr;
  4135. unsigned char mr0;
  4136. int len, stlen;
  4137. char *head, *tail;
  4138. #ifdef DEBUG
  4139. printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
  4140. #endif
  4141. ioaddr = portp->ioaddr;
  4142. head = portp->tx.head;
  4143. tail = portp->tx.tail;
  4144. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  4145. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  4146. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  4147. set_bit(ASYI_TXLOW, &portp->istate);
  4148. schedule_work(&portp->tqueue);
  4149. }
  4150. if (len == 0) {
  4151. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  4152. mr0 = inb(ioaddr + XP_DATA);
  4153. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  4154. portp->imr &= ~IR_TXRDY;
  4155. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  4156. outb(portp->imr, (ioaddr + XP_DATA));
  4157. clear_bit(ASYI_TXBUSY, &portp->istate);
  4158. } else {
  4159. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  4160. outb(mr0, (ioaddr + XP_DATA));
  4161. }
  4162. } else {
  4163. len = MIN(len, SC26198_TXFIFOSIZE);
  4164. portp->stats.txtotal += len;
  4165. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  4166. outb(GTXFIFO, (ioaddr + XP_ADDR));
  4167. outsb((ioaddr + XP_DATA), tail, stlen);
  4168. len -= stlen;
  4169. tail += stlen;
  4170. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  4171. tail = portp->tx.buf;
  4172. if (len > 0) {
  4173. outsb((ioaddr + XP_DATA), tail, len);
  4174. tail += len;
  4175. }
  4176. portp->tx.tail = tail;
  4177. }
  4178. }
  4179. /*****************************************************************************/
  4180. /*
  4181. * Receive character interrupt handler. Determine if we have good chars
  4182. * or bad chars and then process appropriately. Good chars are easy
  4183. * just shove the lot into the RX buffer and set all status byte to 0.
  4184. * If a bad RX char then process as required. This routine needs to be
  4185. * fast! In practice it is possible that we get an interrupt on a port
  4186. * that is closed. This can happen on hangups - since they completely
  4187. * shutdown a port not in user context. Need to handle this case.
  4188. */
  4189. static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
  4190. {
  4191. struct tty_struct *tty;
  4192. unsigned int len, buflen, ioaddr;
  4193. #ifdef DEBUG
  4194. printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4195. #endif
  4196. tty = portp->tty;
  4197. ioaddr = portp->ioaddr;
  4198. outb(GIBCR, (ioaddr + XP_ADDR));
  4199. len = inb(ioaddr + XP_DATA) + 1;
  4200. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  4201. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  4202. len = MIN(len, sizeof(stl_unwanted));
  4203. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4204. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  4205. portp->stats.rxlost += len;
  4206. portp->stats.rxtotal += len;
  4207. } else {
  4208. len = MIN(len, buflen);
  4209. if (len > 0) {
  4210. unsigned char *ptr;
  4211. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4212. tty_prepare_flip_string(tty, &ptr, len);
  4213. insb((ioaddr + XP_DATA), ptr, len);
  4214. tty_schedule_flip(tty);
  4215. portp->stats.rxtotal += len;
  4216. }
  4217. }
  4218. } else {
  4219. stl_sc26198rxbadchars(portp);
  4220. }
  4221. /*
  4222. * If we are TX flow controlled and in IXANY mode then we may need
  4223. * to unflow control here. We gotta do this because of the automatic
  4224. * flow control modes of the sc26198.
  4225. */
  4226. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  4227. if ((tty != (struct tty_struct *) NULL) &&
  4228. (tty->termios != (struct termios *) NULL) &&
  4229. (tty->termios->c_iflag & IXANY)) {
  4230. stl_sc26198txunflow(portp, tty);
  4231. }
  4232. }
  4233. }
  4234. /*****************************************************************************/
  4235. /*
  4236. * Process an RX bad character.
  4237. */
  4238. static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
  4239. {
  4240. struct tty_struct *tty;
  4241. unsigned int ioaddr;
  4242. tty = portp->tty;
  4243. ioaddr = portp->ioaddr;
  4244. if (status & SR_RXPARITY)
  4245. portp->stats.rxparity++;
  4246. if (status & SR_RXFRAMING)
  4247. portp->stats.rxframing++;
  4248. if (status & SR_RXOVERRUN)
  4249. portp->stats.rxoverrun++;
  4250. if (status & SR_RXBREAK)
  4251. portp->stats.rxbreaks++;
  4252. if ((tty != (struct tty_struct *) NULL) &&
  4253. ((portp->rxignoremsk & status) == 0)) {
  4254. if (portp->rxmarkmsk & status) {
  4255. if (status & SR_RXBREAK) {
  4256. status = TTY_BREAK;
  4257. if (portp->flags & ASYNC_SAK) {
  4258. do_SAK(tty);
  4259. BRDENABLE(portp->brdnr, portp->pagenr);
  4260. }
  4261. } else if (status & SR_RXPARITY) {
  4262. status = TTY_PARITY;
  4263. } else if (status & SR_RXFRAMING) {
  4264. status = TTY_FRAME;
  4265. } else if(status & SR_RXOVERRUN) {
  4266. status = TTY_OVERRUN;
  4267. } else {
  4268. status = 0;
  4269. }
  4270. } else {
  4271. status = 0;
  4272. }
  4273. tty_insert_flip_char(tty, ch, status);
  4274. tty_schedule_flip(tty);
  4275. if (status == 0)
  4276. portp->stats.rxtotal++;
  4277. }
  4278. }
  4279. /*****************************************************************************/
  4280. /*
  4281. * Process all characters in the RX FIFO of the UART. Check all char
  4282. * status bytes as well, and process as required. We need to check
  4283. * all bytes in the FIFO, in case some more enter the FIFO while we
  4284. * are here. To get the exact character error type we need to switch
  4285. * into CHAR error mode (that is why we need to make sure we empty
  4286. * the FIFO).
  4287. */
  4288. static void stl_sc26198rxbadchars(stlport_t *portp)
  4289. {
  4290. unsigned char status, mr1;
  4291. char ch;
  4292. /*
  4293. * To get the precise error type for each character we must switch
  4294. * back into CHAR error mode.
  4295. */
  4296. mr1 = stl_sc26198getreg(portp, MR1);
  4297. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  4298. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  4299. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  4300. ch = stl_sc26198getreg(portp, RXFIFO);
  4301. stl_sc26198rxbadch(portp, status, ch);
  4302. }
  4303. /*
  4304. * To get correct interrupt class we must switch back into BLOCK
  4305. * error mode.
  4306. */
  4307. stl_sc26198setreg(portp, MR1, mr1);
  4308. }
  4309. /*****************************************************************************/
  4310. /*
  4311. * Other interrupt handler. This includes modem signals, flow
  4312. * control actions, etc. Most stuff is left to off-level interrupt
  4313. * processing time.
  4314. */
  4315. static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
  4316. {
  4317. unsigned char cir, ipr, xisr;
  4318. #ifdef DEBUG
  4319. printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4320. #endif
  4321. cir = stl_sc26198getglobreg(portp, CIR);
  4322. switch (cir & CIR_SUBTYPEMASK) {
  4323. case CIR_SUBCOS:
  4324. ipr = stl_sc26198getreg(portp, IPR);
  4325. if (ipr & IPR_DCDCHANGE) {
  4326. set_bit(ASYI_DCDCHANGE, &portp->istate);
  4327. schedule_work(&portp->tqueue);
  4328. portp->stats.modem++;
  4329. }
  4330. break;
  4331. case CIR_SUBXONXOFF:
  4332. xisr = stl_sc26198getreg(portp, XISR);
  4333. if (xisr & XISR_RXXONGOT) {
  4334. set_bit(ASYI_TXFLOWED, &portp->istate);
  4335. portp->stats.txxoff++;
  4336. }
  4337. if (xisr & XISR_RXXOFFGOT) {
  4338. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4339. portp->stats.txxon++;
  4340. }
  4341. break;
  4342. case CIR_SUBBREAK:
  4343. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  4344. stl_sc26198rxbadchars(portp);
  4345. break;
  4346. default:
  4347. break;
  4348. }
  4349. }
  4350. /*****************************************************************************/