stallion.c 131 KB

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