istallion.c 136 KB

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