synclinkmp.c 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670
  1. /*
  2. * $Id: synclinkmp.c,v 4.34 2005/03/04 15:07:10 paulkf Exp $
  3. *
  4. * Device driver for Microgate SyncLink Multiport
  5. * high speed multiprotocol serial adapter.
  6. *
  7. * written by Paul Fulghum for Microgate Corporation
  8. * paulkf@microgate.com
  9. *
  10. * Microgate and SyncLink are trademarks of Microgate Corporation
  11. *
  12. * Derived from serial.c written by Theodore Ts'o and Linus Torvalds
  13. * This code is released under the GNU General Public License (GPL)
  14. *
  15. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  16. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25. * OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
  28. #if defined(__i386__)
  29. # define BREAKPOINT() asm(" int $3");
  30. #else
  31. # define BREAKPOINT() { }
  32. #endif
  33. #define MAX_DEVICES 12
  34. #include <linux/config.h>
  35. #include <linux/module.h>
  36. #include <linux/errno.h>
  37. #include <linux/signal.h>
  38. #include <linux/sched.h>
  39. #include <linux/timer.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/pci.h>
  42. #include <linux/tty.h>
  43. #include <linux/tty_flip.h>
  44. #include <linux/serial.h>
  45. #include <linux/major.h>
  46. #include <linux/string.h>
  47. #include <linux/fcntl.h>
  48. #include <linux/ptrace.h>
  49. #include <linux/ioport.h>
  50. #include <linux/mm.h>
  51. #include <linux/slab.h>
  52. #include <linux/netdevice.h>
  53. #include <linux/vmalloc.h>
  54. #include <linux/init.h>
  55. #include <linux/delay.h>
  56. #include <linux/ioctl.h>
  57. #include <asm/system.h>
  58. #include <asm/io.h>
  59. #include <asm/irq.h>
  60. #include <asm/dma.h>
  61. #include <linux/bitops.h>
  62. #include <asm/types.h>
  63. #include <linux/termios.h>
  64. #include <linux/workqueue.h>
  65. #include <linux/hdlc.h>
  66. #ifdef CONFIG_HDLC_MODULE
  67. #define CONFIG_HDLC 1
  68. #endif
  69. #define GET_USER(error,value,addr) error = get_user(value,addr)
  70. #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
  71. #define PUT_USER(error,value,addr) error = put_user(value,addr)
  72. #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
  73. #include <asm/uaccess.h>
  74. #include "linux/synclink.h"
  75. static MGSL_PARAMS default_params = {
  76. MGSL_MODE_HDLC, /* unsigned long mode */
  77. 0, /* unsigned char loopback; */
  78. HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
  79. HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
  80. 0, /* unsigned long clock_speed; */
  81. 0xff, /* unsigned char addr_filter; */
  82. HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
  83. HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
  84. HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
  85. 9600, /* unsigned long data_rate; */
  86. 8, /* unsigned char data_bits; */
  87. 1, /* unsigned char stop_bits; */
  88. ASYNC_PARITY_NONE /* unsigned char parity; */
  89. };
  90. /* size in bytes of DMA data buffers */
  91. #define SCABUFSIZE 1024
  92. #define SCA_MEM_SIZE 0x40000
  93. #define SCA_BASE_SIZE 512
  94. #define SCA_REG_SIZE 16
  95. #define SCA_MAX_PORTS 4
  96. #define SCAMAXDESC 128
  97. #define BUFFERLISTSIZE 4096
  98. /* SCA-I style DMA buffer descriptor */
  99. typedef struct _SCADESC
  100. {
  101. u16 next; /* lower l6 bits of next descriptor addr */
  102. u16 buf_ptr; /* lower 16 bits of buffer addr */
  103. u8 buf_base; /* upper 8 bits of buffer addr */
  104. u8 pad1;
  105. u16 length; /* length of buffer */
  106. u8 status; /* status of buffer */
  107. u8 pad2;
  108. } SCADESC, *PSCADESC;
  109. typedef struct _SCADESC_EX
  110. {
  111. /* device driver bookkeeping section */
  112. char *virt_addr; /* virtual address of data buffer */
  113. u16 phys_entry; /* lower 16-bits of physical address of this descriptor */
  114. } SCADESC_EX, *PSCADESC_EX;
  115. /* The queue of BH actions to be performed */
  116. #define BH_RECEIVE 1
  117. #define BH_TRANSMIT 2
  118. #define BH_STATUS 4
  119. #define IO_PIN_SHUTDOWN_LIMIT 100
  120. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  121. struct _input_signal_events {
  122. int ri_up;
  123. int ri_down;
  124. int dsr_up;
  125. int dsr_down;
  126. int dcd_up;
  127. int dcd_down;
  128. int cts_up;
  129. int cts_down;
  130. };
  131. /*
  132. * Device instance data structure
  133. */
  134. typedef struct _synclinkmp_info {
  135. void *if_ptr; /* General purpose pointer (used by SPPP) */
  136. int magic;
  137. int flags;
  138. int count; /* count of opens */
  139. int line;
  140. unsigned short close_delay;
  141. unsigned short closing_wait; /* time to wait before closing */
  142. struct mgsl_icount icount;
  143. struct tty_struct *tty;
  144. int timeout;
  145. int x_char; /* xon/xoff character */
  146. int blocked_open; /* # of blocked opens */
  147. u16 read_status_mask1; /* break detection (SR1 indications) */
  148. u16 read_status_mask2; /* parity/framing/overun (SR2 indications) */
  149. unsigned char ignore_status_mask1; /* break detection (SR1 indications) */
  150. unsigned char ignore_status_mask2; /* parity/framing/overun (SR2 indications) */
  151. unsigned char *tx_buf;
  152. int tx_put;
  153. int tx_get;
  154. int tx_count;
  155. wait_queue_head_t open_wait;
  156. wait_queue_head_t close_wait;
  157. wait_queue_head_t status_event_wait_q;
  158. wait_queue_head_t event_wait_q;
  159. struct timer_list tx_timer; /* HDLC transmit timeout timer */
  160. struct _synclinkmp_info *next_device; /* device list link */
  161. struct timer_list status_timer; /* input signal status check timer */
  162. spinlock_t lock; /* spinlock for synchronizing with ISR */
  163. struct work_struct task; /* task structure for scheduling bh */
  164. u32 max_frame_size; /* as set by device config */
  165. u32 pending_bh;
  166. int bh_running; /* Protection from multiple */
  167. int isr_overflow;
  168. int bh_requested;
  169. int dcd_chkcount; /* check counts to prevent */
  170. int cts_chkcount; /* too many IRQs if a signal */
  171. int dsr_chkcount; /* is floating */
  172. int ri_chkcount;
  173. char *buffer_list; /* virtual address of Rx & Tx buffer lists */
  174. unsigned long buffer_list_phys;
  175. unsigned int rx_buf_count; /* count of total allocated Rx buffers */
  176. SCADESC *rx_buf_list; /* list of receive buffer entries */
  177. SCADESC_EX rx_buf_list_ex[SCAMAXDESC]; /* list of receive buffer entries */
  178. unsigned int current_rx_buf;
  179. unsigned int tx_buf_count; /* count of total allocated Tx buffers */
  180. SCADESC *tx_buf_list; /* list of transmit buffer entries */
  181. SCADESC_EX tx_buf_list_ex[SCAMAXDESC]; /* list of transmit buffer entries */
  182. unsigned int last_tx_buf;
  183. unsigned char *tmp_rx_buf;
  184. unsigned int tmp_rx_buf_count;
  185. int rx_enabled;
  186. int rx_overflow;
  187. int tx_enabled;
  188. int tx_active;
  189. u32 idle_mode;
  190. unsigned char ie0_value;
  191. unsigned char ie1_value;
  192. unsigned char ie2_value;
  193. unsigned char ctrlreg_value;
  194. unsigned char old_signals;
  195. char device_name[25]; /* device instance name */
  196. int port_count;
  197. int adapter_num;
  198. int port_num;
  199. struct _synclinkmp_info *port_array[SCA_MAX_PORTS];
  200. unsigned int bus_type; /* expansion bus type (ISA,EISA,PCI) */
  201. unsigned int irq_level; /* interrupt level */
  202. unsigned long irq_flags;
  203. int irq_requested; /* nonzero if IRQ requested */
  204. MGSL_PARAMS params; /* communications parameters */
  205. unsigned char serial_signals; /* current serial signal states */
  206. int irq_occurred; /* for diagnostics use */
  207. unsigned int init_error; /* Initialization startup error */
  208. u32 last_mem_alloc;
  209. unsigned char* memory_base; /* shared memory address (PCI only) */
  210. u32 phys_memory_base;
  211. int shared_mem_requested;
  212. unsigned char* sca_base; /* HD64570 SCA Memory address */
  213. u32 phys_sca_base;
  214. u32 sca_offset;
  215. int sca_base_requested;
  216. unsigned char* lcr_base; /* local config registers (PCI only) */
  217. u32 phys_lcr_base;
  218. u32 lcr_offset;
  219. int lcr_mem_requested;
  220. unsigned char* statctrl_base; /* status/control register memory */
  221. u32 phys_statctrl_base;
  222. u32 statctrl_offset;
  223. int sca_statctrl_requested;
  224. u32 misc_ctrl_value;
  225. char flag_buf[MAX_ASYNC_BUFFER_SIZE];
  226. char char_buf[MAX_ASYNC_BUFFER_SIZE];
  227. BOOLEAN drop_rts_on_tx_done;
  228. struct _input_signal_events input_signal_events;
  229. /* SPPP/Cisco HDLC device parts */
  230. int netcount;
  231. int dosyncppp;
  232. spinlock_t netlock;
  233. #ifdef CONFIG_HDLC
  234. struct net_device *netdev;
  235. #endif
  236. } SLMP_INFO;
  237. #define MGSL_MAGIC 0x5401
  238. /*
  239. * define serial signal status change macros
  240. */
  241. #define MISCSTATUS_DCD_LATCHED (SerialSignal_DCD<<8) /* indicates change in DCD */
  242. #define MISCSTATUS_RI_LATCHED (SerialSignal_RI<<8) /* indicates change in RI */
  243. #define MISCSTATUS_CTS_LATCHED (SerialSignal_CTS<<8) /* indicates change in CTS */
  244. #define MISCSTATUS_DSR_LATCHED (SerialSignal_DSR<<8) /* change in DSR */
  245. /* Common Register macros */
  246. #define LPR 0x00
  247. #define PABR0 0x02
  248. #define PABR1 0x03
  249. #define WCRL 0x04
  250. #define WCRM 0x05
  251. #define WCRH 0x06
  252. #define DPCR 0x08
  253. #define DMER 0x09
  254. #define ISR0 0x10
  255. #define ISR1 0x11
  256. #define ISR2 0x12
  257. #define IER0 0x14
  258. #define IER1 0x15
  259. #define IER2 0x16
  260. #define ITCR 0x18
  261. #define INTVR 0x1a
  262. #define IMVR 0x1c
  263. /* MSCI Register macros */
  264. #define TRB 0x20
  265. #define TRBL 0x20
  266. #define TRBH 0x21
  267. #define SR0 0x22
  268. #define SR1 0x23
  269. #define SR2 0x24
  270. #define SR3 0x25
  271. #define FST 0x26
  272. #define IE0 0x28
  273. #define IE1 0x29
  274. #define IE2 0x2a
  275. #define FIE 0x2b
  276. #define CMD 0x2c
  277. #define MD0 0x2e
  278. #define MD1 0x2f
  279. #define MD2 0x30
  280. #define CTL 0x31
  281. #define SA0 0x32
  282. #define SA1 0x33
  283. #define IDL 0x34
  284. #define TMC 0x35
  285. #define RXS 0x36
  286. #define TXS 0x37
  287. #define TRC0 0x38
  288. #define TRC1 0x39
  289. #define RRC 0x3a
  290. #define CST0 0x3c
  291. #define CST1 0x3d
  292. /* Timer Register Macros */
  293. #define TCNT 0x60
  294. #define TCNTL 0x60
  295. #define TCNTH 0x61
  296. #define TCONR 0x62
  297. #define TCONRL 0x62
  298. #define TCONRH 0x63
  299. #define TMCS 0x64
  300. #define TEPR 0x65
  301. /* DMA Controller Register macros */
  302. #define DARL 0x80
  303. #define DARH 0x81
  304. #define DARB 0x82
  305. #define BAR 0x80
  306. #define BARL 0x80
  307. #define BARH 0x81
  308. #define BARB 0x82
  309. #define SAR 0x84
  310. #define SARL 0x84
  311. #define SARH 0x85
  312. #define SARB 0x86
  313. #define CPB 0x86
  314. #define CDA 0x88
  315. #define CDAL 0x88
  316. #define CDAH 0x89
  317. #define EDA 0x8a
  318. #define EDAL 0x8a
  319. #define EDAH 0x8b
  320. #define BFL 0x8c
  321. #define BFLL 0x8c
  322. #define BFLH 0x8d
  323. #define BCR 0x8e
  324. #define BCRL 0x8e
  325. #define BCRH 0x8f
  326. #define DSR 0x90
  327. #define DMR 0x91
  328. #define FCT 0x93
  329. #define DIR 0x94
  330. #define DCMD 0x95
  331. /* combine with timer or DMA register address */
  332. #define TIMER0 0x00
  333. #define TIMER1 0x08
  334. #define TIMER2 0x10
  335. #define TIMER3 0x18
  336. #define RXDMA 0x00
  337. #define TXDMA 0x20
  338. /* SCA Command Codes */
  339. #define NOOP 0x00
  340. #define TXRESET 0x01
  341. #define TXENABLE 0x02
  342. #define TXDISABLE 0x03
  343. #define TXCRCINIT 0x04
  344. #define TXCRCEXCL 0x05
  345. #define TXEOM 0x06
  346. #define TXABORT 0x07
  347. #define MPON 0x08
  348. #define TXBUFCLR 0x09
  349. #define RXRESET 0x11
  350. #define RXENABLE 0x12
  351. #define RXDISABLE 0x13
  352. #define RXCRCINIT 0x14
  353. #define RXREJECT 0x15
  354. #define SEARCHMP 0x16
  355. #define RXCRCEXCL 0x17
  356. #define RXCRCCALC 0x18
  357. #define CHRESET 0x21
  358. #define HUNT 0x31
  359. /* DMA command codes */
  360. #define SWABORT 0x01
  361. #define FEICLEAR 0x02
  362. /* IE0 */
  363. #define TXINTE BIT7
  364. #define RXINTE BIT6
  365. #define TXRDYE BIT1
  366. #define RXRDYE BIT0
  367. /* IE1 & SR1 */
  368. #define UDRN BIT7
  369. #define IDLE BIT6
  370. #define SYNCD BIT4
  371. #define FLGD BIT4
  372. #define CCTS BIT3
  373. #define CDCD BIT2
  374. #define BRKD BIT1
  375. #define ABTD BIT1
  376. #define GAPD BIT1
  377. #define BRKE BIT0
  378. #define IDLD BIT0
  379. /* IE2 & SR2 */
  380. #define EOM BIT7
  381. #define PMP BIT6
  382. #define SHRT BIT6
  383. #define PE BIT5
  384. #define ABT BIT5
  385. #define FRME BIT4
  386. #define RBIT BIT4
  387. #define OVRN BIT3
  388. #define CRCE BIT2
  389. /*
  390. * Global linked list of SyncLink devices
  391. */
  392. static SLMP_INFO *synclinkmp_device_list = NULL;
  393. static int synclinkmp_adapter_count = -1;
  394. static int synclinkmp_device_count = 0;
  395. /*
  396. * Set this param to non-zero to load eax with the
  397. * .text section address and breakpoint on module load.
  398. * This is useful for use with gdb and add-symbol-file command.
  399. */
  400. static int break_on_load=0;
  401. /*
  402. * Driver major number, defaults to zero to get auto
  403. * assigned major number. May be forced as module parameter.
  404. */
  405. static int ttymajor=0;
  406. /*
  407. * Array of user specified options for ISA adapters.
  408. */
  409. static int debug_level = 0;
  410. static int maxframe[MAX_DEVICES] = {0,};
  411. static int dosyncppp[MAX_DEVICES] = {0,};
  412. module_param(break_on_load, bool, 0);
  413. module_param(ttymajor, int, 0);
  414. module_param(debug_level, int, 0);
  415. module_param_array(maxframe, int, NULL, 0);
  416. module_param_array(dosyncppp, int, NULL, 0);
  417. static char *driver_name = "SyncLink MultiPort driver";
  418. static char *driver_version = "$Revision: 4.34 $";
  419. static int synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent);
  420. static void synclinkmp_remove_one(struct pci_dev *dev);
  421. static struct pci_device_id synclinkmp_pci_tbl[] = {
  422. { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_SCA, PCI_ANY_ID, PCI_ANY_ID, },
  423. { 0, }, /* terminate list */
  424. };
  425. MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
  426. MODULE_LICENSE("GPL");
  427. static struct pci_driver synclinkmp_pci_driver = {
  428. .name = "synclinkmp",
  429. .id_table = synclinkmp_pci_tbl,
  430. .probe = synclinkmp_init_one,
  431. .remove = __devexit_p(synclinkmp_remove_one),
  432. };
  433. static struct tty_driver *serial_driver;
  434. /* number of characters left in xmit buffer before we ask for more */
  435. #define WAKEUP_CHARS 256
  436. /* tty callbacks */
  437. static int open(struct tty_struct *tty, struct file * filp);
  438. static void close(struct tty_struct *tty, struct file * filp);
  439. static void hangup(struct tty_struct *tty);
  440. static void set_termios(struct tty_struct *tty, struct termios *old_termios);
  441. static int write(struct tty_struct *tty, const unsigned char *buf, int count);
  442. static void put_char(struct tty_struct *tty, unsigned char ch);
  443. static void send_xchar(struct tty_struct *tty, char ch);
  444. static void wait_until_sent(struct tty_struct *tty, int timeout);
  445. static int write_room(struct tty_struct *tty);
  446. static void flush_chars(struct tty_struct *tty);
  447. static void flush_buffer(struct tty_struct *tty);
  448. static void tx_hold(struct tty_struct *tty);
  449. static void tx_release(struct tty_struct *tty);
  450. static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  451. static int read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
  452. static int chars_in_buffer(struct tty_struct *tty);
  453. static void throttle(struct tty_struct * tty);
  454. static void unthrottle(struct tty_struct * tty);
  455. static void set_break(struct tty_struct *tty, int break_state);
  456. #ifdef CONFIG_HDLC
  457. #define dev_to_port(D) (dev_to_hdlc(D)->priv)
  458. static void hdlcdev_tx_done(SLMP_INFO *info);
  459. static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size);
  460. static int hdlcdev_init(SLMP_INFO *info);
  461. static void hdlcdev_exit(SLMP_INFO *info);
  462. #endif
  463. /* ioctl handlers */
  464. static int get_stats(SLMP_INFO *info, struct mgsl_icount __user *user_icount);
  465. static int get_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
  466. static int set_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
  467. static int get_txidle(SLMP_INFO *info, int __user *idle_mode);
  468. static int set_txidle(SLMP_INFO *info, int idle_mode);
  469. static int tx_enable(SLMP_INFO *info, int enable);
  470. static int tx_abort(SLMP_INFO *info);
  471. static int rx_enable(SLMP_INFO *info, int enable);
  472. static int map_status(int signals);
  473. static int modem_input_wait(SLMP_INFO *info,int arg);
  474. static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
  475. static int tiocmget(struct tty_struct *tty, struct file *file);
  476. static int tiocmset(struct tty_struct *tty, struct file *file,
  477. unsigned int set, unsigned int clear);
  478. static void set_break(struct tty_struct *tty, int break_state);
  479. static void add_device(SLMP_INFO *info);
  480. static void device_init(int adapter_num, struct pci_dev *pdev);
  481. static int claim_resources(SLMP_INFO *info);
  482. static void release_resources(SLMP_INFO *info);
  483. static int startup(SLMP_INFO *info);
  484. static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
  485. static void shutdown(SLMP_INFO *info);
  486. static void program_hw(SLMP_INFO *info);
  487. static void change_params(SLMP_INFO *info);
  488. static int init_adapter(SLMP_INFO *info);
  489. static int register_test(SLMP_INFO *info);
  490. static int irq_test(SLMP_INFO *info);
  491. static int loopback_test(SLMP_INFO *info);
  492. static int adapter_test(SLMP_INFO *info);
  493. static int memory_test(SLMP_INFO *info);
  494. static void reset_adapter(SLMP_INFO *info);
  495. static void reset_port(SLMP_INFO *info);
  496. static void async_mode(SLMP_INFO *info);
  497. static void hdlc_mode(SLMP_INFO *info);
  498. static void rx_stop(SLMP_INFO *info);
  499. static void rx_start(SLMP_INFO *info);
  500. static void rx_reset_buffers(SLMP_INFO *info);
  501. static void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last);
  502. static int rx_get_frame(SLMP_INFO *info);
  503. static void tx_start(SLMP_INFO *info);
  504. static void tx_stop(SLMP_INFO *info);
  505. static void tx_load_fifo(SLMP_INFO *info);
  506. static void tx_set_idle(SLMP_INFO *info);
  507. static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count);
  508. static void get_signals(SLMP_INFO *info);
  509. static void set_signals(SLMP_INFO *info);
  510. static void enable_loopback(SLMP_INFO *info, int enable);
  511. static void set_rate(SLMP_INFO *info, u32 data_rate);
  512. static int bh_action(SLMP_INFO *info);
  513. static void bh_handler(void* Context);
  514. static void bh_receive(SLMP_INFO *info);
  515. static void bh_transmit(SLMP_INFO *info);
  516. static void bh_status(SLMP_INFO *info);
  517. static void isr_timer(SLMP_INFO *info);
  518. static void isr_rxint(SLMP_INFO *info);
  519. static void isr_rxrdy(SLMP_INFO *info);
  520. static void isr_txint(SLMP_INFO *info);
  521. static void isr_txrdy(SLMP_INFO *info);
  522. static void isr_rxdmaok(SLMP_INFO *info);
  523. static void isr_rxdmaerror(SLMP_INFO *info);
  524. static void isr_txdmaok(SLMP_INFO *info);
  525. static void isr_txdmaerror(SLMP_INFO *info);
  526. static void isr_io_pin(SLMP_INFO *info, u16 status);
  527. static int alloc_dma_bufs(SLMP_INFO *info);
  528. static void free_dma_bufs(SLMP_INFO *info);
  529. static int alloc_buf_list(SLMP_INFO *info);
  530. static int alloc_frame_bufs(SLMP_INFO *info, SCADESC *list, SCADESC_EX *list_ex,int count);
  531. static int alloc_tmp_rx_buf(SLMP_INFO *info);
  532. static void free_tmp_rx_buf(SLMP_INFO *info);
  533. static void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count);
  534. static void trace_block(SLMP_INFO *info, const char* data, int count, int xmit);
  535. static void tx_timeout(unsigned long context);
  536. static void status_timeout(unsigned long context);
  537. static unsigned char read_reg(SLMP_INFO *info, unsigned char addr);
  538. static void write_reg(SLMP_INFO *info, unsigned char addr, unsigned char val);
  539. static u16 read_reg16(SLMP_INFO *info, unsigned char addr);
  540. static void write_reg16(SLMP_INFO *info, unsigned char addr, u16 val);
  541. static unsigned char read_status_reg(SLMP_INFO * info);
  542. static void write_control_reg(SLMP_INFO * info);
  543. static unsigned char rx_active_fifo_level = 16; // rx request FIFO activation level in bytes
  544. static unsigned char tx_active_fifo_level = 16; // tx request FIFO activation level in bytes
  545. static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes
  546. static u32 misc_ctrl_value = 0x007e4040;
  547. static u32 lcr1_brdr_value = 0x00800029;
  548. static u32 read_ahead_count = 8;
  549. /* DPCR, DMA Priority Control
  550. *
  551. * 07..05 Not used, must be 0
  552. * 04 BRC, bus release condition: 0=all transfers complete
  553. * 1=release after 1 xfer on all channels
  554. * 03 CCC, channel change condition: 0=every cycle
  555. * 1=after each channel completes all xfers
  556. * 02..00 PR<2..0>, priority 100=round robin
  557. *
  558. * 00000100 = 0x00
  559. */
  560. static unsigned char dma_priority = 0x04;
  561. // Number of bytes that can be written to shared RAM
  562. // in a single write operation
  563. static u32 sca_pci_load_interval = 64;
  564. /*
  565. * 1st function defined in .text section. Calling this function in
  566. * init_module() followed by a breakpoint allows a remote debugger
  567. * (gdb) to get the .text address for the add-symbol-file command.
  568. * This allows remote debugging of dynamically loadable modules.
  569. */
  570. static void* synclinkmp_get_text_ptr(void);
  571. static void* synclinkmp_get_text_ptr(void) {return synclinkmp_get_text_ptr;}
  572. static inline int sanity_check(SLMP_INFO *info,
  573. char *name, const char *routine)
  574. {
  575. #ifdef SANITY_CHECK
  576. static const char *badmagic =
  577. "Warning: bad magic number for synclinkmp_struct (%s) in %s\n";
  578. static const char *badinfo =
  579. "Warning: null synclinkmp_struct for (%s) in %s\n";
  580. if (!info) {
  581. printk(badinfo, name, routine);
  582. return 1;
  583. }
  584. if (info->magic != MGSL_MAGIC) {
  585. printk(badmagic, name, routine);
  586. return 1;
  587. }
  588. #else
  589. if (!info)
  590. return 1;
  591. #endif
  592. return 0;
  593. }
  594. /**
  595. * line discipline callback wrappers
  596. *
  597. * The wrappers maintain line discipline references
  598. * while calling into the line discipline.
  599. *
  600. * ldisc_receive_buf - pass receive data to line discipline
  601. */
  602. static void ldisc_receive_buf(struct tty_struct *tty,
  603. const __u8 *data, char *flags, int count)
  604. {
  605. struct tty_ldisc *ld;
  606. if (!tty)
  607. return;
  608. ld = tty_ldisc_ref(tty);
  609. if (ld) {
  610. if (ld->receive_buf)
  611. ld->receive_buf(tty, data, flags, count);
  612. tty_ldisc_deref(ld);
  613. }
  614. }
  615. /* tty callbacks */
  616. /* Called when a port is opened. Init and enable port.
  617. */
  618. static int open(struct tty_struct *tty, struct file *filp)
  619. {
  620. SLMP_INFO *info;
  621. int retval, line;
  622. unsigned long flags;
  623. line = tty->index;
  624. if ((line < 0) || (line >= synclinkmp_device_count)) {
  625. printk("%s(%d): open with invalid line #%d.\n",
  626. __FILE__,__LINE__,line);
  627. return -ENODEV;
  628. }
  629. info = synclinkmp_device_list;
  630. while(info && info->line != line)
  631. info = info->next_device;
  632. if (sanity_check(info, tty->name, "open"))
  633. return -ENODEV;
  634. if ( info->init_error ) {
  635. printk("%s(%d):%s device is not allocated, init error=%d\n",
  636. __FILE__,__LINE__,info->device_name,info->init_error);
  637. return -ENODEV;
  638. }
  639. tty->driver_data = info;
  640. info->tty = tty;
  641. if (debug_level >= DEBUG_LEVEL_INFO)
  642. printk("%s(%d):%s open(), old ref count = %d\n",
  643. __FILE__,__LINE__,tty->driver->name, info->count);
  644. /* If port is closing, signal caller to try again */
  645. if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
  646. if (info->flags & ASYNC_CLOSING)
  647. interruptible_sleep_on(&info->close_wait);
  648. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  649. -EAGAIN : -ERESTARTSYS);
  650. goto cleanup;
  651. }
  652. info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  653. spin_lock_irqsave(&info->netlock, flags);
  654. if (info->netcount) {
  655. retval = -EBUSY;
  656. spin_unlock_irqrestore(&info->netlock, flags);
  657. goto cleanup;
  658. }
  659. info->count++;
  660. spin_unlock_irqrestore(&info->netlock, flags);
  661. if (info->count == 1) {
  662. /* 1st open on this device, init hardware */
  663. retval = startup(info);
  664. if (retval < 0)
  665. goto cleanup;
  666. }
  667. retval = block_til_ready(tty, filp, info);
  668. if (retval) {
  669. if (debug_level >= DEBUG_LEVEL_INFO)
  670. printk("%s(%d):%s block_til_ready() returned %d\n",
  671. __FILE__,__LINE__, info->device_name, retval);
  672. goto cleanup;
  673. }
  674. if (debug_level >= DEBUG_LEVEL_INFO)
  675. printk("%s(%d):%s open() success\n",
  676. __FILE__,__LINE__, info->device_name);
  677. retval = 0;
  678. cleanup:
  679. if (retval) {
  680. if (tty->count == 1)
  681. info->tty = NULL; /* tty layer will release tty struct */
  682. if(info->count)
  683. info->count--;
  684. }
  685. return retval;
  686. }
  687. /* Called when port is closed. Wait for remaining data to be
  688. * sent. Disable port and free resources.
  689. */
  690. static void close(struct tty_struct *tty, struct file *filp)
  691. {
  692. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  693. if (sanity_check(info, tty->name, "close"))
  694. return;
  695. if (debug_level >= DEBUG_LEVEL_INFO)
  696. printk("%s(%d):%s close() entry, count=%d\n",
  697. __FILE__,__LINE__, info->device_name, info->count);
  698. if (!info->count)
  699. return;
  700. if (tty_hung_up_p(filp))
  701. goto cleanup;
  702. if ((tty->count == 1) && (info->count != 1)) {
  703. /*
  704. * tty->count is 1 and the tty structure will be freed.
  705. * info->count should be one in this case.
  706. * if it's not, correct it so that the port is shutdown.
  707. */
  708. printk("%s(%d):%s close: bad refcount; tty->count is 1, "
  709. "info->count is %d\n",
  710. __FILE__,__LINE__, info->device_name, info->count);
  711. info->count = 1;
  712. }
  713. info->count--;
  714. /* if at least one open remaining, leave hardware active */
  715. if (info->count)
  716. goto cleanup;
  717. info->flags |= ASYNC_CLOSING;
  718. /* set tty->closing to notify line discipline to
  719. * only process XON/XOFF characters. Only the N_TTY
  720. * discipline appears to use this (ppp does not).
  721. */
  722. tty->closing = 1;
  723. /* wait for transmit data to clear all layers */
  724. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
  725. if (debug_level >= DEBUG_LEVEL_INFO)
  726. printk("%s(%d):%s close() calling tty_wait_until_sent\n",
  727. __FILE__,__LINE__, info->device_name );
  728. tty_wait_until_sent(tty, info->closing_wait);
  729. }
  730. if (info->flags & ASYNC_INITIALIZED)
  731. wait_until_sent(tty, info->timeout);
  732. if (tty->driver->flush_buffer)
  733. tty->driver->flush_buffer(tty);
  734. tty_ldisc_flush(tty);
  735. shutdown(info);
  736. tty->closing = 0;
  737. info->tty = NULL;
  738. if (info->blocked_open) {
  739. if (info->close_delay) {
  740. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  741. }
  742. wake_up_interruptible(&info->open_wait);
  743. }
  744. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  745. wake_up_interruptible(&info->close_wait);
  746. cleanup:
  747. if (debug_level >= DEBUG_LEVEL_INFO)
  748. printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
  749. tty->driver->name, info->count);
  750. }
  751. /* Called by tty_hangup() when a hangup is signaled.
  752. * This is the same as closing all open descriptors for the port.
  753. */
  754. static void hangup(struct tty_struct *tty)
  755. {
  756. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  757. if (debug_level >= DEBUG_LEVEL_INFO)
  758. printk("%s(%d):%s hangup()\n",
  759. __FILE__,__LINE__, info->device_name );
  760. if (sanity_check(info, tty->name, "hangup"))
  761. return;
  762. flush_buffer(tty);
  763. shutdown(info);
  764. info->count = 0;
  765. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  766. info->tty = NULL;
  767. wake_up_interruptible(&info->open_wait);
  768. }
  769. /* Set new termios settings
  770. */
  771. static void set_termios(struct tty_struct *tty, struct termios *old_termios)
  772. {
  773. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  774. unsigned long flags;
  775. if (debug_level >= DEBUG_LEVEL_INFO)
  776. printk("%s(%d):%s set_termios()\n", __FILE__,__LINE__,
  777. tty->driver->name );
  778. /* just return if nothing has changed */
  779. if ((tty->termios->c_cflag == old_termios->c_cflag)
  780. && (RELEVANT_IFLAG(tty->termios->c_iflag)
  781. == RELEVANT_IFLAG(old_termios->c_iflag)))
  782. return;
  783. change_params(info);
  784. /* Handle transition to B0 status */
  785. if (old_termios->c_cflag & CBAUD &&
  786. !(tty->termios->c_cflag & CBAUD)) {
  787. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  788. spin_lock_irqsave(&info->lock,flags);
  789. set_signals(info);
  790. spin_unlock_irqrestore(&info->lock,flags);
  791. }
  792. /* Handle transition away from B0 status */
  793. if (!(old_termios->c_cflag & CBAUD) &&
  794. tty->termios->c_cflag & CBAUD) {
  795. info->serial_signals |= SerialSignal_DTR;
  796. if (!(tty->termios->c_cflag & CRTSCTS) ||
  797. !test_bit(TTY_THROTTLED, &tty->flags)) {
  798. info->serial_signals |= SerialSignal_RTS;
  799. }
  800. spin_lock_irqsave(&info->lock,flags);
  801. set_signals(info);
  802. spin_unlock_irqrestore(&info->lock,flags);
  803. }
  804. /* Handle turning off CRTSCTS */
  805. if (old_termios->c_cflag & CRTSCTS &&
  806. !(tty->termios->c_cflag & CRTSCTS)) {
  807. tty->hw_stopped = 0;
  808. tx_release(tty);
  809. }
  810. }
  811. /* Send a block of data
  812. *
  813. * Arguments:
  814. *
  815. * tty pointer to tty information structure
  816. * buf pointer to buffer containing send data
  817. * count size of send data in bytes
  818. *
  819. * Return Value: number of characters written
  820. */
  821. static int write(struct tty_struct *tty,
  822. const unsigned char *buf, int count)
  823. {
  824. int c, ret = 0;
  825. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  826. unsigned long flags;
  827. if (debug_level >= DEBUG_LEVEL_INFO)
  828. printk("%s(%d):%s write() count=%d\n",
  829. __FILE__,__LINE__,info->device_name,count);
  830. if (sanity_check(info, tty->name, "write"))
  831. goto cleanup;
  832. if (!tty || !info->tx_buf)
  833. goto cleanup;
  834. if (info->params.mode == MGSL_MODE_HDLC) {
  835. if (count > info->max_frame_size) {
  836. ret = -EIO;
  837. goto cleanup;
  838. }
  839. if (info->tx_active)
  840. goto cleanup;
  841. if (info->tx_count) {
  842. /* send accumulated data from send_char() calls */
  843. /* as frame and wait before accepting more data. */
  844. tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
  845. goto start;
  846. }
  847. ret = info->tx_count = count;
  848. tx_load_dma_buffer(info, buf, count);
  849. goto start;
  850. }
  851. for (;;) {
  852. c = min_t(int, count,
  853. min(info->max_frame_size - info->tx_count - 1,
  854. info->max_frame_size - info->tx_put));
  855. if (c <= 0)
  856. break;
  857. memcpy(info->tx_buf + info->tx_put, buf, c);
  858. spin_lock_irqsave(&info->lock,flags);
  859. info->tx_put += c;
  860. if (info->tx_put >= info->max_frame_size)
  861. info->tx_put -= info->max_frame_size;
  862. info->tx_count += c;
  863. spin_unlock_irqrestore(&info->lock,flags);
  864. buf += c;
  865. count -= c;
  866. ret += c;
  867. }
  868. if (info->params.mode == MGSL_MODE_HDLC) {
  869. if (count) {
  870. ret = info->tx_count = 0;
  871. goto cleanup;
  872. }
  873. tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
  874. }
  875. start:
  876. if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
  877. spin_lock_irqsave(&info->lock,flags);
  878. if (!info->tx_active)
  879. tx_start(info);
  880. spin_unlock_irqrestore(&info->lock,flags);
  881. }
  882. cleanup:
  883. if (debug_level >= DEBUG_LEVEL_INFO)
  884. printk( "%s(%d):%s write() returning=%d\n",
  885. __FILE__,__LINE__,info->device_name,ret);
  886. return ret;
  887. }
  888. /* Add a character to the transmit buffer.
  889. */
  890. static void put_char(struct tty_struct *tty, unsigned char ch)
  891. {
  892. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  893. unsigned long flags;
  894. if ( debug_level >= DEBUG_LEVEL_INFO ) {
  895. printk( "%s(%d):%s put_char(%d)\n",
  896. __FILE__,__LINE__,info->device_name,ch);
  897. }
  898. if (sanity_check(info, tty->name, "put_char"))
  899. return;
  900. if (!tty || !info->tx_buf)
  901. return;
  902. spin_lock_irqsave(&info->lock,flags);
  903. if ( (info->params.mode != MGSL_MODE_HDLC) ||
  904. !info->tx_active ) {
  905. if (info->tx_count < info->max_frame_size - 1) {
  906. info->tx_buf[info->tx_put++] = ch;
  907. if (info->tx_put >= info->max_frame_size)
  908. info->tx_put -= info->max_frame_size;
  909. info->tx_count++;
  910. }
  911. }
  912. spin_unlock_irqrestore(&info->lock,flags);
  913. }
  914. /* Send a high-priority XON/XOFF character
  915. */
  916. static void send_xchar(struct tty_struct *tty, char ch)
  917. {
  918. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  919. unsigned long flags;
  920. if (debug_level >= DEBUG_LEVEL_INFO)
  921. printk("%s(%d):%s send_xchar(%d)\n",
  922. __FILE__,__LINE__, info->device_name, ch );
  923. if (sanity_check(info, tty->name, "send_xchar"))
  924. return;
  925. info->x_char = ch;
  926. if (ch) {
  927. /* Make sure transmit interrupts are on */
  928. spin_lock_irqsave(&info->lock,flags);
  929. if (!info->tx_enabled)
  930. tx_start(info);
  931. spin_unlock_irqrestore(&info->lock,flags);
  932. }
  933. }
  934. /* Wait until the transmitter is empty.
  935. */
  936. static void wait_until_sent(struct tty_struct *tty, int timeout)
  937. {
  938. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  939. unsigned long orig_jiffies, char_time;
  940. if (!info )
  941. return;
  942. if (debug_level >= DEBUG_LEVEL_INFO)
  943. printk("%s(%d):%s wait_until_sent() entry\n",
  944. __FILE__,__LINE__, info->device_name );
  945. if (sanity_check(info, tty->name, "wait_until_sent"))
  946. return;
  947. if (!(info->flags & ASYNC_INITIALIZED))
  948. goto exit;
  949. orig_jiffies = jiffies;
  950. /* Set check interval to 1/5 of estimated time to
  951. * send a character, and make it at least 1. The check
  952. * interval should also be less than the timeout.
  953. * Note: use tight timings here to satisfy the NIST-PCTS.
  954. */
  955. if ( info->params.data_rate ) {
  956. char_time = info->timeout/(32 * 5);
  957. if (!char_time)
  958. char_time++;
  959. } else
  960. char_time = 1;
  961. if (timeout)
  962. char_time = min_t(unsigned long, char_time, timeout);
  963. if ( info->params.mode == MGSL_MODE_HDLC ) {
  964. while (info->tx_active) {
  965. msleep_interruptible(jiffies_to_msecs(char_time));
  966. if (signal_pending(current))
  967. break;
  968. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  969. break;
  970. }
  971. } else {
  972. //TODO: determine if there is something similar to USC16C32
  973. // TXSTATUS_ALL_SENT status
  974. while ( info->tx_active && info->tx_enabled) {
  975. msleep_interruptible(jiffies_to_msecs(char_time));
  976. if (signal_pending(current))
  977. break;
  978. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  979. break;
  980. }
  981. }
  982. exit:
  983. if (debug_level >= DEBUG_LEVEL_INFO)
  984. printk("%s(%d):%s wait_until_sent() exit\n",
  985. __FILE__,__LINE__, info->device_name );
  986. }
  987. /* Return the count of free bytes in transmit buffer
  988. */
  989. static int write_room(struct tty_struct *tty)
  990. {
  991. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  992. int ret;
  993. if (sanity_check(info, tty->name, "write_room"))
  994. return 0;
  995. if (info->params.mode == MGSL_MODE_HDLC) {
  996. ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
  997. } else {
  998. ret = info->max_frame_size - info->tx_count - 1;
  999. if (ret < 0)
  1000. ret = 0;
  1001. }
  1002. if (debug_level >= DEBUG_LEVEL_INFO)
  1003. printk("%s(%d):%s write_room()=%d\n",
  1004. __FILE__, __LINE__, info->device_name, ret);
  1005. return ret;
  1006. }
  1007. /* enable transmitter and send remaining buffered characters
  1008. */
  1009. static void flush_chars(struct tty_struct *tty)
  1010. {
  1011. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1012. unsigned long flags;
  1013. if ( debug_level >= DEBUG_LEVEL_INFO )
  1014. printk( "%s(%d):%s flush_chars() entry tx_count=%d\n",
  1015. __FILE__,__LINE__,info->device_name,info->tx_count);
  1016. if (sanity_check(info, tty->name, "flush_chars"))
  1017. return;
  1018. if (info->tx_count <= 0 || tty->stopped || tty->hw_stopped ||
  1019. !info->tx_buf)
  1020. return;
  1021. if ( debug_level >= DEBUG_LEVEL_INFO )
  1022. printk( "%s(%d):%s flush_chars() entry, starting transmitter\n",
  1023. __FILE__,__LINE__,info->device_name );
  1024. spin_lock_irqsave(&info->lock,flags);
  1025. if (!info->tx_active) {
  1026. if ( (info->params.mode == MGSL_MODE_HDLC) &&
  1027. info->tx_count ) {
  1028. /* operating in synchronous (frame oriented) mode */
  1029. /* copy data from circular tx_buf to */
  1030. /* transmit DMA buffer. */
  1031. tx_load_dma_buffer(info,
  1032. info->tx_buf,info->tx_count);
  1033. }
  1034. tx_start(info);
  1035. }
  1036. spin_unlock_irqrestore(&info->lock,flags);
  1037. }
  1038. /* Discard all data in the send buffer
  1039. */
  1040. static void flush_buffer(struct tty_struct *tty)
  1041. {
  1042. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1043. unsigned long flags;
  1044. if (debug_level >= DEBUG_LEVEL_INFO)
  1045. printk("%s(%d):%s flush_buffer() entry\n",
  1046. __FILE__,__LINE__, info->device_name );
  1047. if (sanity_check(info, tty->name, "flush_buffer"))
  1048. return;
  1049. spin_lock_irqsave(&info->lock,flags);
  1050. info->tx_count = info->tx_put = info->tx_get = 0;
  1051. del_timer(&info->tx_timer);
  1052. spin_unlock_irqrestore(&info->lock,flags);
  1053. wake_up_interruptible(&tty->write_wait);
  1054. tty_wakeup(tty);
  1055. }
  1056. /* throttle (stop) transmitter
  1057. */
  1058. static void tx_hold(struct tty_struct *tty)
  1059. {
  1060. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1061. unsigned long flags;
  1062. if (sanity_check(info, tty->name, "tx_hold"))
  1063. return;
  1064. if ( debug_level >= DEBUG_LEVEL_INFO )
  1065. printk("%s(%d):%s tx_hold()\n",
  1066. __FILE__,__LINE__,info->device_name);
  1067. spin_lock_irqsave(&info->lock,flags);
  1068. if (info->tx_enabled)
  1069. tx_stop(info);
  1070. spin_unlock_irqrestore(&info->lock,flags);
  1071. }
  1072. /* release (start) transmitter
  1073. */
  1074. static void tx_release(struct tty_struct *tty)
  1075. {
  1076. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1077. unsigned long flags;
  1078. if (sanity_check(info, tty->name, "tx_release"))
  1079. return;
  1080. if ( debug_level >= DEBUG_LEVEL_INFO )
  1081. printk("%s(%d):%s tx_release()\n",
  1082. __FILE__,__LINE__,info->device_name);
  1083. spin_lock_irqsave(&info->lock,flags);
  1084. if (!info->tx_enabled)
  1085. tx_start(info);
  1086. spin_unlock_irqrestore(&info->lock,flags);
  1087. }
  1088. /* Service an IOCTL request
  1089. *
  1090. * Arguments:
  1091. *
  1092. * tty pointer to tty instance data
  1093. * file pointer to associated file object for device
  1094. * cmd IOCTL command code
  1095. * arg command argument/context
  1096. *
  1097. * Return Value: 0 if success, otherwise error code
  1098. */
  1099. static int ioctl(struct tty_struct *tty, struct file *file,
  1100. unsigned int cmd, unsigned long arg)
  1101. {
  1102. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1103. int error;
  1104. struct mgsl_icount cnow; /* kernel counter temps */
  1105. struct serial_icounter_struct __user *p_cuser; /* user space */
  1106. unsigned long flags;
  1107. void __user *argp = (void __user *)arg;
  1108. if (debug_level >= DEBUG_LEVEL_INFO)
  1109. printk("%s(%d):%s ioctl() cmd=%08X\n", __FILE__,__LINE__,
  1110. info->device_name, cmd );
  1111. if (sanity_check(info, tty->name, "ioctl"))
  1112. return -ENODEV;
  1113. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1114. (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
  1115. if (tty->flags & (1 << TTY_IO_ERROR))
  1116. return -EIO;
  1117. }
  1118. switch (cmd) {
  1119. case MGSL_IOCGPARAMS:
  1120. return get_params(info, argp);
  1121. case MGSL_IOCSPARAMS:
  1122. return set_params(info, argp);
  1123. case MGSL_IOCGTXIDLE:
  1124. return get_txidle(info, argp);
  1125. case MGSL_IOCSTXIDLE:
  1126. return set_txidle(info, (int)arg);
  1127. case MGSL_IOCTXENABLE:
  1128. return tx_enable(info, (int)arg);
  1129. case MGSL_IOCRXENABLE:
  1130. return rx_enable(info, (int)arg);
  1131. case MGSL_IOCTXABORT:
  1132. return tx_abort(info);
  1133. case MGSL_IOCGSTATS:
  1134. return get_stats(info, argp);
  1135. case MGSL_IOCWAITEVENT:
  1136. return wait_mgsl_event(info, argp);
  1137. case MGSL_IOCLOOPTXDONE:
  1138. return 0; // TODO: Not supported, need to document
  1139. /* Wait for modem input (DCD,RI,DSR,CTS) change
  1140. * as specified by mask in arg (TIOCM_RNG/DSR/CD/CTS)
  1141. */
  1142. case TIOCMIWAIT:
  1143. return modem_input_wait(info,(int)arg);
  1144. /*
  1145. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1146. * Return: write counters to the user passed counter struct
  1147. * NB: both 1->0 and 0->1 transitions are counted except for
  1148. * RI where only 0->1 is counted.
  1149. */
  1150. case TIOCGICOUNT:
  1151. spin_lock_irqsave(&info->lock,flags);
  1152. cnow = info->icount;
  1153. spin_unlock_irqrestore(&info->lock,flags);
  1154. p_cuser = argp;
  1155. PUT_USER(error,cnow.cts, &p_cuser->cts);
  1156. if (error) return error;
  1157. PUT_USER(error,cnow.dsr, &p_cuser->dsr);
  1158. if (error) return error;
  1159. PUT_USER(error,cnow.rng, &p_cuser->rng);
  1160. if (error) return error;
  1161. PUT_USER(error,cnow.dcd, &p_cuser->dcd);
  1162. if (error) return error;
  1163. PUT_USER(error,cnow.rx, &p_cuser->rx);
  1164. if (error) return error;
  1165. PUT_USER(error,cnow.tx, &p_cuser->tx);
  1166. if (error) return error;
  1167. PUT_USER(error,cnow.frame, &p_cuser->frame);
  1168. if (error) return error;
  1169. PUT_USER(error,cnow.overrun, &p_cuser->overrun);
  1170. if (error) return error;
  1171. PUT_USER(error,cnow.parity, &p_cuser->parity);
  1172. if (error) return error;
  1173. PUT_USER(error,cnow.brk, &p_cuser->brk);
  1174. if (error) return error;
  1175. PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
  1176. if (error) return error;
  1177. return 0;
  1178. default:
  1179. return -ENOIOCTLCMD;
  1180. }
  1181. return 0;
  1182. }
  1183. /*
  1184. * /proc fs routines....
  1185. */
  1186. static inline int line_info(char *buf, SLMP_INFO *info)
  1187. {
  1188. char stat_buf[30];
  1189. int ret;
  1190. unsigned long flags;
  1191. ret = sprintf(buf, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
  1192. "\tIRQ=%d MaxFrameSize=%u\n",
  1193. info->device_name,
  1194. info->phys_sca_base,
  1195. info->phys_memory_base,
  1196. info->phys_statctrl_base,
  1197. info->phys_lcr_base,
  1198. info->irq_level,
  1199. info->max_frame_size );
  1200. /* output current serial signal states */
  1201. spin_lock_irqsave(&info->lock,flags);
  1202. get_signals(info);
  1203. spin_unlock_irqrestore(&info->lock,flags);
  1204. stat_buf[0] = 0;
  1205. stat_buf[1] = 0;
  1206. if (info->serial_signals & SerialSignal_RTS)
  1207. strcat(stat_buf, "|RTS");
  1208. if (info->serial_signals & SerialSignal_CTS)
  1209. strcat(stat_buf, "|CTS");
  1210. if (info->serial_signals & SerialSignal_DTR)
  1211. strcat(stat_buf, "|DTR");
  1212. if (info->serial_signals & SerialSignal_DSR)
  1213. strcat(stat_buf, "|DSR");
  1214. if (info->serial_signals & SerialSignal_DCD)
  1215. strcat(stat_buf, "|CD");
  1216. if (info->serial_signals & SerialSignal_RI)
  1217. strcat(stat_buf, "|RI");
  1218. if (info->params.mode == MGSL_MODE_HDLC) {
  1219. ret += sprintf(buf+ret, "\tHDLC txok:%d rxok:%d",
  1220. info->icount.txok, info->icount.rxok);
  1221. if (info->icount.txunder)
  1222. ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
  1223. if (info->icount.txabort)
  1224. ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
  1225. if (info->icount.rxshort)
  1226. ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);
  1227. if (info->icount.rxlong)
  1228. ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
  1229. if (info->icount.rxover)
  1230. ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
  1231. if (info->icount.rxcrc)
  1232. ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxcrc);
  1233. } else {
  1234. ret += sprintf(buf+ret, "\tASYNC tx:%d rx:%d",
  1235. info->icount.tx, info->icount.rx);
  1236. if (info->icount.frame)
  1237. ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
  1238. if (info->icount.parity)
  1239. ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
  1240. if (info->icount.brk)
  1241. ret += sprintf(buf+ret, " brk:%d", info->icount.brk);
  1242. if (info->icount.overrun)
  1243. ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
  1244. }
  1245. /* Append serial signal status to end */
  1246. ret += sprintf(buf+ret, " %s\n", stat_buf+1);
  1247. ret += sprintf(buf+ret, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
  1248. info->tx_active,info->bh_requested,info->bh_running,
  1249. info->pending_bh);
  1250. return ret;
  1251. }
  1252. /* Called to print information about devices
  1253. */
  1254. int read_proc(char *page, char **start, off_t off, int count,
  1255. int *eof, void *data)
  1256. {
  1257. int len = 0, l;
  1258. off_t begin = 0;
  1259. SLMP_INFO *info;
  1260. len += sprintf(page, "synclinkmp driver:%s\n", driver_version);
  1261. info = synclinkmp_device_list;
  1262. while( info ) {
  1263. l = line_info(page + len, info);
  1264. len += l;
  1265. if (len+begin > off+count)
  1266. goto done;
  1267. if (len+begin < off) {
  1268. begin += len;
  1269. len = 0;
  1270. }
  1271. info = info->next_device;
  1272. }
  1273. *eof = 1;
  1274. done:
  1275. if (off >= len+begin)
  1276. return 0;
  1277. *start = page + (off-begin);
  1278. return ((count < begin+len-off) ? count : begin+len-off);
  1279. }
  1280. /* Return the count of bytes in transmit buffer
  1281. */
  1282. static int chars_in_buffer(struct tty_struct *tty)
  1283. {
  1284. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1285. if (sanity_check(info, tty->name, "chars_in_buffer"))
  1286. return 0;
  1287. if (debug_level >= DEBUG_LEVEL_INFO)
  1288. printk("%s(%d):%s chars_in_buffer()=%d\n",
  1289. __FILE__, __LINE__, info->device_name, info->tx_count);
  1290. return info->tx_count;
  1291. }
  1292. /* Signal remote device to throttle send data (our receive data)
  1293. */
  1294. static void throttle(struct tty_struct * tty)
  1295. {
  1296. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1297. unsigned long flags;
  1298. if (debug_level >= DEBUG_LEVEL_INFO)
  1299. printk("%s(%d):%s throttle() entry\n",
  1300. __FILE__,__LINE__, info->device_name );
  1301. if (sanity_check(info, tty->name, "throttle"))
  1302. return;
  1303. if (I_IXOFF(tty))
  1304. send_xchar(tty, STOP_CHAR(tty));
  1305. if (tty->termios->c_cflag & CRTSCTS) {
  1306. spin_lock_irqsave(&info->lock,flags);
  1307. info->serial_signals &= ~SerialSignal_RTS;
  1308. set_signals(info);
  1309. spin_unlock_irqrestore(&info->lock,flags);
  1310. }
  1311. }
  1312. /* Signal remote device to stop throttling send data (our receive data)
  1313. */
  1314. static void unthrottle(struct tty_struct * tty)
  1315. {
  1316. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1317. unsigned long flags;
  1318. if (debug_level >= DEBUG_LEVEL_INFO)
  1319. printk("%s(%d):%s unthrottle() entry\n",
  1320. __FILE__,__LINE__, info->device_name );
  1321. if (sanity_check(info, tty->name, "unthrottle"))
  1322. return;
  1323. if (I_IXOFF(tty)) {
  1324. if (info->x_char)
  1325. info->x_char = 0;
  1326. else
  1327. send_xchar(tty, START_CHAR(tty));
  1328. }
  1329. if (tty->termios->c_cflag & CRTSCTS) {
  1330. spin_lock_irqsave(&info->lock,flags);
  1331. info->serial_signals |= SerialSignal_RTS;
  1332. set_signals(info);
  1333. spin_unlock_irqrestore(&info->lock,flags);
  1334. }
  1335. }
  1336. /* set or clear transmit break condition
  1337. * break_state -1=set break condition, 0=clear
  1338. */
  1339. static void set_break(struct tty_struct *tty, int break_state)
  1340. {
  1341. unsigned char RegValue;
  1342. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  1343. unsigned long flags;
  1344. if (debug_level >= DEBUG_LEVEL_INFO)
  1345. printk("%s(%d):%s set_break(%d)\n",
  1346. __FILE__,__LINE__, info->device_name, break_state);
  1347. if (sanity_check(info, tty->name, "set_break"))
  1348. return;
  1349. spin_lock_irqsave(&info->lock,flags);
  1350. RegValue = read_reg(info, CTL);
  1351. if (break_state == -1)
  1352. RegValue |= BIT3;
  1353. else
  1354. RegValue &= ~BIT3;
  1355. write_reg(info, CTL, RegValue);
  1356. spin_unlock_irqrestore(&info->lock,flags);
  1357. }
  1358. #ifdef CONFIG_HDLC
  1359. /**
  1360. * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
  1361. * set encoding and frame check sequence (FCS) options
  1362. *
  1363. * dev pointer to network device structure
  1364. * encoding serial encoding setting
  1365. * parity FCS setting
  1366. *
  1367. * returns 0 if success, otherwise error code
  1368. */
  1369. static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  1370. unsigned short parity)
  1371. {
  1372. SLMP_INFO *info = dev_to_port(dev);
  1373. unsigned char new_encoding;
  1374. unsigned short new_crctype;
  1375. /* return error if TTY interface open */
  1376. if (info->count)
  1377. return -EBUSY;
  1378. switch (encoding)
  1379. {
  1380. case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
  1381. case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
  1382. case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
  1383. case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
  1384. case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
  1385. default: return -EINVAL;
  1386. }
  1387. switch (parity)
  1388. {
  1389. case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
  1390. case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
  1391. case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
  1392. default: return -EINVAL;
  1393. }
  1394. info->params.encoding = new_encoding;
  1395. info->params.crc_type = new_crctype;;
  1396. /* if network interface up, reprogram hardware */
  1397. if (info->netcount)
  1398. program_hw(info);
  1399. return 0;
  1400. }
  1401. /**
  1402. * called by generic HDLC layer to send frame
  1403. *
  1404. * skb socket buffer containing HDLC frame
  1405. * dev pointer to network device structure
  1406. *
  1407. * returns 0 if success, otherwise error code
  1408. */
  1409. static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
  1410. {
  1411. SLMP_INFO *info = dev_to_port(dev);
  1412. struct net_device_stats *stats = hdlc_stats(dev);
  1413. unsigned long flags;
  1414. if (debug_level >= DEBUG_LEVEL_INFO)
  1415. printk(KERN_INFO "%s:hdlc_xmit(%s)\n",__FILE__,dev->name);
  1416. /* stop sending until this frame completes */
  1417. netif_stop_queue(dev);
  1418. /* copy data to device buffers */
  1419. info->tx_count = skb->len;
  1420. tx_load_dma_buffer(info, skb->data, skb->len);
  1421. /* update network statistics */
  1422. stats->tx_packets++;
  1423. stats->tx_bytes += skb->len;
  1424. /* done with socket buffer, so free it */
  1425. dev_kfree_skb(skb);
  1426. /* save start time for transmit timeout detection */
  1427. dev->trans_start = jiffies;
  1428. /* start hardware transmitter if necessary */
  1429. spin_lock_irqsave(&info->lock,flags);
  1430. if (!info->tx_active)
  1431. tx_start(info);
  1432. spin_unlock_irqrestore(&info->lock,flags);
  1433. return 0;
  1434. }
  1435. /**
  1436. * called by network layer when interface enabled
  1437. * claim resources and initialize hardware
  1438. *
  1439. * dev pointer to network device structure
  1440. *
  1441. * returns 0 if success, otherwise error code
  1442. */
  1443. static int hdlcdev_open(struct net_device *dev)
  1444. {
  1445. SLMP_INFO *info = dev_to_port(dev);
  1446. int rc;
  1447. unsigned long flags;
  1448. if (debug_level >= DEBUG_LEVEL_INFO)
  1449. printk("%s:hdlcdev_open(%s)\n",__FILE__,dev->name);
  1450. /* generic HDLC layer open processing */
  1451. if ((rc = hdlc_open(dev)))
  1452. return rc;
  1453. /* arbitrate between network and tty opens */
  1454. spin_lock_irqsave(&info->netlock, flags);
  1455. if (info->count != 0 || info->netcount != 0) {
  1456. printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
  1457. spin_unlock_irqrestore(&info->netlock, flags);
  1458. return -EBUSY;
  1459. }
  1460. info->netcount=1;
  1461. spin_unlock_irqrestore(&info->netlock, flags);
  1462. /* claim resources and init adapter */
  1463. if ((rc = startup(info)) != 0) {
  1464. spin_lock_irqsave(&info->netlock, flags);
  1465. info->netcount=0;
  1466. spin_unlock_irqrestore(&info->netlock, flags);
  1467. return rc;
  1468. }
  1469. /* assert DTR and RTS, apply hardware settings */
  1470. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  1471. program_hw(info);
  1472. /* enable network layer transmit */
  1473. dev->trans_start = jiffies;
  1474. netif_start_queue(dev);
  1475. /* inform generic HDLC layer of current DCD status */
  1476. spin_lock_irqsave(&info->lock, flags);
  1477. get_signals(info);
  1478. spin_unlock_irqrestore(&info->lock, flags);
  1479. hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev);
  1480. return 0;
  1481. }
  1482. /**
  1483. * called by network layer when interface is disabled
  1484. * shutdown hardware and release resources
  1485. *
  1486. * dev pointer to network device structure
  1487. *
  1488. * returns 0 if success, otherwise error code
  1489. */
  1490. static int hdlcdev_close(struct net_device *dev)
  1491. {
  1492. SLMP_INFO *info = dev_to_port(dev);
  1493. unsigned long flags;
  1494. if (debug_level >= DEBUG_LEVEL_INFO)
  1495. printk("%s:hdlcdev_close(%s)\n",__FILE__,dev->name);
  1496. netif_stop_queue(dev);
  1497. /* shutdown adapter and release resources */
  1498. shutdown(info);
  1499. hdlc_close(dev);
  1500. spin_lock_irqsave(&info->netlock, flags);
  1501. info->netcount=0;
  1502. spin_unlock_irqrestore(&info->netlock, flags);
  1503. return 0;
  1504. }
  1505. /**
  1506. * called by network layer to process IOCTL call to network device
  1507. *
  1508. * dev pointer to network device structure
  1509. * ifr pointer to network interface request structure
  1510. * cmd IOCTL command code
  1511. *
  1512. * returns 0 if success, otherwise error code
  1513. */
  1514. static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1515. {
  1516. const size_t size = sizeof(sync_serial_settings);
  1517. sync_serial_settings new_line;
  1518. sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
  1519. SLMP_INFO *info = dev_to_port(dev);
  1520. unsigned int flags;
  1521. if (debug_level >= DEBUG_LEVEL_INFO)
  1522. printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
  1523. /* return error if TTY interface open */
  1524. if (info->count)
  1525. return -EBUSY;
  1526. if (cmd != SIOCWANDEV)
  1527. return hdlc_ioctl(dev, ifr, cmd);
  1528. switch(ifr->ifr_settings.type) {
  1529. case IF_GET_IFACE: /* return current sync_serial_settings */
  1530. ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL;
  1531. if (ifr->ifr_settings.size < size) {
  1532. ifr->ifr_settings.size = size; /* data size wanted */
  1533. return -ENOBUFS;
  1534. }
  1535. flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
  1536. HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
  1537. HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
  1538. HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
  1539. switch (flags){
  1540. case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
  1541. case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
  1542. case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
  1543. case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
  1544. default: new_line.clock_type = CLOCK_DEFAULT;
  1545. }
  1546. new_line.clock_rate = info->params.clock_speed;
  1547. new_line.loopback = info->params.loopback ? 1:0;
  1548. if (copy_to_user(line, &new_line, size))
  1549. return -EFAULT;
  1550. return 0;
  1551. case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
  1552. if(!capable(CAP_NET_ADMIN))
  1553. return -EPERM;
  1554. if (copy_from_user(&new_line, line, size))
  1555. return -EFAULT;
  1556. switch (new_line.clock_type)
  1557. {
  1558. case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
  1559. case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
  1560. case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
  1561. case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
  1562. case CLOCK_DEFAULT: flags = info->params.flags &
  1563. (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
  1564. HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
  1565. HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
  1566. HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
  1567. default: return -EINVAL;
  1568. }
  1569. if (new_line.loopback != 0 && new_line.loopback != 1)
  1570. return -EINVAL;
  1571. info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
  1572. HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
  1573. HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
  1574. HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
  1575. info->params.flags |= flags;
  1576. info->params.loopback = new_line.loopback;
  1577. if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
  1578. info->params.clock_speed = new_line.clock_rate;
  1579. else
  1580. info->params.clock_speed = 0;
  1581. /* if network interface up, reprogram hardware */
  1582. if (info->netcount)
  1583. program_hw(info);
  1584. return 0;
  1585. default:
  1586. return hdlc_ioctl(dev, ifr, cmd);
  1587. }
  1588. }
  1589. /**
  1590. * called by network layer when transmit timeout is detected
  1591. *
  1592. * dev pointer to network device structure
  1593. */
  1594. static void hdlcdev_tx_timeout(struct net_device *dev)
  1595. {
  1596. SLMP_INFO *info = dev_to_port(dev);
  1597. struct net_device_stats *stats = hdlc_stats(dev);
  1598. unsigned long flags;
  1599. if (debug_level >= DEBUG_LEVEL_INFO)
  1600. printk("hdlcdev_tx_timeout(%s)\n",dev->name);
  1601. stats->tx_errors++;
  1602. stats->tx_aborted_errors++;
  1603. spin_lock_irqsave(&info->lock,flags);
  1604. tx_stop(info);
  1605. spin_unlock_irqrestore(&info->lock,flags);
  1606. netif_wake_queue(dev);
  1607. }
  1608. /**
  1609. * called by device driver when transmit completes
  1610. * reenable network layer transmit if stopped
  1611. *
  1612. * info pointer to device instance information
  1613. */
  1614. static void hdlcdev_tx_done(SLMP_INFO *info)
  1615. {
  1616. if (netif_queue_stopped(info->netdev))
  1617. netif_wake_queue(info->netdev);
  1618. }
  1619. /**
  1620. * called by device driver when frame received
  1621. * pass frame to network layer
  1622. *
  1623. * info pointer to device instance information
  1624. * buf pointer to buffer contianing frame data
  1625. * size count of data bytes in buf
  1626. */
  1627. static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size)
  1628. {
  1629. struct sk_buff *skb = dev_alloc_skb(size);
  1630. struct net_device *dev = info->netdev;
  1631. struct net_device_stats *stats = hdlc_stats(dev);
  1632. if (debug_level >= DEBUG_LEVEL_INFO)
  1633. printk("hdlcdev_rx(%s)\n",dev->name);
  1634. if (skb == NULL) {
  1635. printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n", dev->name);
  1636. stats->rx_dropped++;
  1637. return;
  1638. }
  1639. memcpy(skb_put(skb, size),buf,size);
  1640. skb->protocol = hdlc_type_trans(skb, info->netdev);
  1641. stats->rx_packets++;
  1642. stats->rx_bytes += size;
  1643. netif_rx(skb);
  1644. info->netdev->last_rx = jiffies;
  1645. }
  1646. /**
  1647. * called by device driver when adding device instance
  1648. * do generic HDLC initialization
  1649. *
  1650. * info pointer to device instance information
  1651. *
  1652. * returns 0 if success, otherwise error code
  1653. */
  1654. static int hdlcdev_init(SLMP_INFO *info)
  1655. {
  1656. int rc;
  1657. struct net_device *dev;
  1658. hdlc_device *hdlc;
  1659. /* allocate and initialize network and HDLC layer objects */
  1660. if (!(dev = alloc_hdlcdev(info))) {
  1661. printk(KERN_ERR "%s:hdlc device allocation failure\n",__FILE__);
  1662. return -ENOMEM;
  1663. }
  1664. /* for network layer reporting purposes only */
  1665. dev->mem_start = info->phys_sca_base;
  1666. dev->mem_end = info->phys_sca_base + SCA_BASE_SIZE - 1;
  1667. dev->irq = info->irq_level;
  1668. /* network layer callbacks and settings */
  1669. dev->do_ioctl = hdlcdev_ioctl;
  1670. dev->open = hdlcdev_open;
  1671. dev->stop = hdlcdev_close;
  1672. dev->tx_timeout = hdlcdev_tx_timeout;
  1673. dev->watchdog_timeo = 10*HZ;
  1674. dev->tx_queue_len = 50;
  1675. /* generic HDLC layer callbacks and settings */
  1676. hdlc = dev_to_hdlc(dev);
  1677. hdlc->attach = hdlcdev_attach;
  1678. hdlc->xmit = hdlcdev_xmit;
  1679. /* register objects with HDLC layer */
  1680. if ((rc = register_hdlc_device(dev))) {
  1681. printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
  1682. free_netdev(dev);
  1683. return rc;
  1684. }
  1685. info->netdev = dev;
  1686. return 0;
  1687. }
  1688. /**
  1689. * called by device driver when removing device instance
  1690. * do generic HDLC cleanup
  1691. *
  1692. * info pointer to device instance information
  1693. */
  1694. static void hdlcdev_exit(SLMP_INFO *info)
  1695. {
  1696. unregister_hdlc_device(info->netdev);
  1697. free_netdev(info->netdev);
  1698. info->netdev = NULL;
  1699. }
  1700. #endif /* CONFIG_HDLC */
  1701. /* Return next bottom half action to perform.
  1702. * Return Value: BH action code or 0 if nothing to do.
  1703. */
  1704. int bh_action(SLMP_INFO *info)
  1705. {
  1706. unsigned long flags;
  1707. int rc = 0;
  1708. spin_lock_irqsave(&info->lock,flags);
  1709. if (info->pending_bh & BH_RECEIVE) {
  1710. info->pending_bh &= ~BH_RECEIVE;
  1711. rc = BH_RECEIVE;
  1712. } else if (info->pending_bh & BH_TRANSMIT) {
  1713. info->pending_bh &= ~BH_TRANSMIT;
  1714. rc = BH_TRANSMIT;
  1715. } else if (info->pending_bh & BH_STATUS) {
  1716. info->pending_bh &= ~BH_STATUS;
  1717. rc = BH_STATUS;
  1718. }
  1719. if (!rc) {
  1720. /* Mark BH routine as complete */
  1721. info->bh_running = 0;
  1722. info->bh_requested = 0;
  1723. }
  1724. spin_unlock_irqrestore(&info->lock,flags);
  1725. return rc;
  1726. }
  1727. /* Perform bottom half processing of work items queued by ISR.
  1728. */
  1729. void bh_handler(void* Context)
  1730. {
  1731. SLMP_INFO *info = (SLMP_INFO*)Context;
  1732. int action;
  1733. if (!info)
  1734. return;
  1735. if ( debug_level >= DEBUG_LEVEL_BH )
  1736. printk( "%s(%d):%s bh_handler() entry\n",
  1737. __FILE__,__LINE__,info->device_name);
  1738. info->bh_running = 1;
  1739. while((action = bh_action(info)) != 0) {
  1740. /* Process work item */
  1741. if ( debug_level >= DEBUG_LEVEL_BH )
  1742. printk( "%s(%d):%s bh_handler() work item action=%d\n",
  1743. __FILE__,__LINE__,info->device_name, action);
  1744. switch (action) {
  1745. case BH_RECEIVE:
  1746. bh_receive(info);
  1747. break;
  1748. case BH_TRANSMIT:
  1749. bh_transmit(info);
  1750. break;
  1751. case BH_STATUS:
  1752. bh_status(info);
  1753. break;
  1754. default:
  1755. /* unknown work item ID */
  1756. printk("%s(%d):%s Unknown work item ID=%08X!\n",
  1757. __FILE__,__LINE__,info->device_name,action);
  1758. break;
  1759. }
  1760. }
  1761. if ( debug_level >= DEBUG_LEVEL_BH )
  1762. printk( "%s(%d):%s bh_handler() exit\n",
  1763. __FILE__,__LINE__,info->device_name);
  1764. }
  1765. void bh_receive(SLMP_INFO *info)
  1766. {
  1767. if ( debug_level >= DEBUG_LEVEL_BH )
  1768. printk( "%s(%d):%s bh_receive()\n",
  1769. __FILE__,__LINE__,info->device_name);
  1770. while( rx_get_frame(info) );
  1771. }
  1772. void bh_transmit(SLMP_INFO *info)
  1773. {
  1774. struct tty_struct *tty = info->tty;
  1775. if ( debug_level >= DEBUG_LEVEL_BH )
  1776. printk( "%s(%d):%s bh_transmit() entry\n",
  1777. __FILE__,__LINE__,info->device_name);
  1778. if (tty) {
  1779. tty_wakeup(tty);
  1780. wake_up_interruptible(&tty->write_wait);
  1781. }
  1782. }
  1783. void bh_status(SLMP_INFO *info)
  1784. {
  1785. if ( debug_level >= DEBUG_LEVEL_BH )
  1786. printk( "%s(%d):%s bh_status() entry\n",
  1787. __FILE__,__LINE__,info->device_name);
  1788. info->ri_chkcount = 0;
  1789. info->dsr_chkcount = 0;
  1790. info->dcd_chkcount = 0;
  1791. info->cts_chkcount = 0;
  1792. }
  1793. void isr_timer(SLMP_INFO * info)
  1794. {
  1795. unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
  1796. /* IER2<7..4> = timer<3..0> interrupt enables (0=disabled) */
  1797. write_reg(info, IER2, 0);
  1798. /* TMCS, Timer Control/Status Register
  1799. *
  1800. * 07 CMF, Compare match flag (read only) 1=match
  1801. * 06 ECMI, CMF Interrupt Enable: 0=disabled
  1802. * 05 Reserved, must be 0
  1803. * 04 TME, Timer Enable
  1804. * 03..00 Reserved, must be 0
  1805. *
  1806. * 0000 0000
  1807. */
  1808. write_reg(info, (unsigned char)(timer + TMCS), 0);
  1809. info->irq_occurred = TRUE;
  1810. if ( debug_level >= DEBUG_LEVEL_ISR )
  1811. printk("%s(%d):%s isr_timer()\n",
  1812. __FILE__,__LINE__,info->device_name);
  1813. }
  1814. void isr_rxint(SLMP_INFO * info)
  1815. {
  1816. struct tty_struct *tty = info->tty;
  1817. struct mgsl_icount *icount = &info->icount;
  1818. unsigned char status = read_reg(info, SR1) & info->ie1_value & (FLGD + IDLD + CDCD + BRKD);
  1819. unsigned char status2 = read_reg(info, SR2) & info->ie2_value & OVRN;
  1820. /* clear status bits */
  1821. if (status)
  1822. write_reg(info, SR1, status);
  1823. if (status2)
  1824. write_reg(info, SR2, status2);
  1825. if ( debug_level >= DEBUG_LEVEL_ISR )
  1826. printk("%s(%d):%s isr_rxint status=%02X %02x\n",
  1827. __FILE__,__LINE__,info->device_name,status,status2);
  1828. if (info->params.mode == MGSL_MODE_ASYNC) {
  1829. if (status & BRKD) {
  1830. icount->brk++;
  1831. /* process break detection if tty control
  1832. * is not set to ignore it
  1833. */
  1834. if ( tty ) {
  1835. if (!(status & info->ignore_status_mask1)) {
  1836. if (info->read_status_mask1 & BRKD) {
  1837. *tty->flip.flag_buf_ptr = TTY_BREAK;
  1838. if (info->flags & ASYNC_SAK)
  1839. do_SAK(tty);
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. else {
  1846. if (status & (FLGD|IDLD)) {
  1847. if (status & FLGD)
  1848. info->icount.exithunt++;
  1849. else if (status & IDLD)
  1850. info->icount.rxidle++;
  1851. wake_up_interruptible(&info->event_wait_q);
  1852. }
  1853. }
  1854. if (status & CDCD) {
  1855. /* simulate a common modem status change interrupt
  1856. * for our handler
  1857. */
  1858. get_signals( info );
  1859. isr_io_pin(info,
  1860. MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD));
  1861. }
  1862. }
  1863. /*
  1864. * handle async rx data interrupts
  1865. */
  1866. void isr_rxrdy(SLMP_INFO * info)
  1867. {
  1868. u16 status;
  1869. unsigned char DataByte;
  1870. struct tty_struct *tty = info->tty;
  1871. struct mgsl_icount *icount = &info->icount;
  1872. if ( debug_level >= DEBUG_LEVEL_ISR )
  1873. printk("%s(%d):%s isr_rxrdy\n",
  1874. __FILE__,__LINE__,info->device_name);
  1875. while((status = read_reg(info,CST0)) & BIT0)
  1876. {
  1877. DataByte = read_reg(info,TRB);
  1878. if ( tty ) {
  1879. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  1880. continue;
  1881. *tty->flip.char_buf_ptr = DataByte;
  1882. *tty->flip.flag_buf_ptr = 0;
  1883. }
  1884. icount->rx++;
  1885. if ( status & (PE + FRME + OVRN) ) {
  1886. printk("%s(%d):%s rxerr=%04X\n",
  1887. __FILE__,__LINE__,info->device_name,status);
  1888. /* update error statistics */
  1889. if (status & PE)
  1890. icount->parity++;
  1891. else if (status & FRME)
  1892. icount->frame++;
  1893. else if (status & OVRN)
  1894. icount->overrun++;
  1895. /* discard char if tty control flags say so */
  1896. if (status & info->ignore_status_mask2)
  1897. continue;
  1898. status &= info->read_status_mask2;
  1899. if ( tty ) {
  1900. if (status & PE)
  1901. *tty->flip.flag_buf_ptr = TTY_PARITY;
  1902. else if (status & FRME)
  1903. *tty->flip.flag_buf_ptr = TTY_FRAME;
  1904. if (status & OVRN) {
  1905. /* Overrun is special, since it's
  1906. * reported immediately, and doesn't
  1907. * affect the current character
  1908. */
  1909. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  1910. tty->flip.count++;
  1911. tty->flip.flag_buf_ptr++;
  1912. tty->flip.char_buf_ptr++;
  1913. *tty->flip.flag_buf_ptr = TTY_OVERRUN;
  1914. }
  1915. }
  1916. }
  1917. } /* end of if (error) */
  1918. if ( tty ) {
  1919. tty->flip.flag_buf_ptr++;
  1920. tty->flip.char_buf_ptr++;
  1921. tty->flip.count++;
  1922. }
  1923. }
  1924. if ( debug_level >= DEBUG_LEVEL_ISR ) {
  1925. printk("%s(%d):%s isr_rxrdy() flip count=%d\n",
  1926. __FILE__,__LINE__,info->device_name,
  1927. tty ? tty->flip.count : 0);
  1928. printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
  1929. __FILE__,__LINE__,info->device_name,
  1930. icount->rx,icount->brk,icount->parity,
  1931. icount->frame,icount->overrun);
  1932. }
  1933. if ( tty && tty->flip.count )
  1934. tty_flip_buffer_push(tty);
  1935. }
  1936. static void isr_txeom(SLMP_INFO * info, unsigned char status)
  1937. {
  1938. if ( debug_level >= DEBUG_LEVEL_ISR )
  1939. printk("%s(%d):%s isr_txeom status=%02x\n",
  1940. __FILE__,__LINE__,info->device_name,status);
  1941. write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
  1942. write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
  1943. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  1944. if (status & UDRN) {
  1945. write_reg(info, CMD, TXRESET);
  1946. write_reg(info, CMD, TXENABLE);
  1947. } else
  1948. write_reg(info, CMD, TXBUFCLR);
  1949. /* disable and clear tx interrupts */
  1950. info->ie0_value &= ~TXRDYE;
  1951. info->ie1_value &= ~(IDLE + UDRN);
  1952. write_reg16(info, IE0, (unsigned short)((info->ie1_value << 8) + info->ie0_value));
  1953. write_reg(info, SR1, (unsigned char)(UDRN + IDLE));
  1954. if ( info->tx_active ) {
  1955. if (info->params.mode != MGSL_MODE_ASYNC) {
  1956. if (status & UDRN)
  1957. info->icount.txunder++;
  1958. else if (status & IDLE)
  1959. info->icount.txok++;
  1960. }
  1961. info->tx_active = 0;
  1962. info->tx_count = info->tx_put = info->tx_get = 0;
  1963. del_timer(&info->tx_timer);
  1964. if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done ) {
  1965. info->serial_signals &= ~SerialSignal_RTS;
  1966. info->drop_rts_on_tx_done = 0;
  1967. set_signals(info);
  1968. }
  1969. #ifdef CONFIG_HDLC
  1970. if (info->netcount)
  1971. hdlcdev_tx_done(info);
  1972. else
  1973. #endif
  1974. {
  1975. if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
  1976. tx_stop(info);
  1977. return;
  1978. }
  1979. info->pending_bh |= BH_TRANSMIT;
  1980. }
  1981. }
  1982. }
  1983. /*
  1984. * handle tx status interrupts
  1985. */
  1986. void isr_txint(SLMP_INFO * info)
  1987. {
  1988. unsigned char status = read_reg(info, SR1) & info->ie1_value & (UDRN + IDLE + CCTS);
  1989. /* clear status bits */
  1990. write_reg(info, SR1, status);
  1991. if ( debug_level >= DEBUG_LEVEL_ISR )
  1992. printk("%s(%d):%s isr_txint status=%02x\n",
  1993. __FILE__,__LINE__,info->device_name,status);
  1994. if (status & (UDRN + IDLE))
  1995. isr_txeom(info, status);
  1996. if (status & CCTS) {
  1997. /* simulate a common modem status change interrupt
  1998. * for our handler
  1999. */
  2000. get_signals( info );
  2001. isr_io_pin(info,
  2002. MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS));
  2003. }
  2004. }
  2005. /*
  2006. * handle async tx data interrupts
  2007. */
  2008. void isr_txrdy(SLMP_INFO * info)
  2009. {
  2010. if ( debug_level >= DEBUG_LEVEL_ISR )
  2011. printk("%s(%d):%s isr_txrdy() tx_count=%d\n",
  2012. __FILE__,__LINE__,info->device_name,info->tx_count);
  2013. if (info->params.mode != MGSL_MODE_ASYNC) {
  2014. /* disable TXRDY IRQ, enable IDLE IRQ */
  2015. info->ie0_value &= ~TXRDYE;
  2016. info->ie1_value |= IDLE;
  2017. write_reg16(info, IE0, (unsigned short)((info->ie1_value << 8) + info->ie0_value));
  2018. return;
  2019. }
  2020. if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
  2021. tx_stop(info);
  2022. return;
  2023. }
  2024. if ( info->tx_count )
  2025. tx_load_fifo( info );
  2026. else {
  2027. info->tx_active = 0;
  2028. info->ie0_value &= ~TXRDYE;
  2029. write_reg(info, IE0, info->ie0_value);
  2030. }
  2031. if (info->tx_count < WAKEUP_CHARS)
  2032. info->pending_bh |= BH_TRANSMIT;
  2033. }
  2034. void isr_rxdmaok(SLMP_INFO * info)
  2035. {
  2036. /* BIT7 = EOT (end of transfer)
  2037. * BIT6 = EOM (end of message/frame)
  2038. */
  2039. unsigned char status = read_reg(info,RXDMA + DSR) & 0xc0;
  2040. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  2041. write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
  2042. if ( debug_level >= DEBUG_LEVEL_ISR )
  2043. printk("%s(%d):%s isr_rxdmaok(), status=%02x\n",
  2044. __FILE__,__LINE__,info->device_name,status);
  2045. info->pending_bh |= BH_RECEIVE;
  2046. }
  2047. void isr_rxdmaerror(SLMP_INFO * info)
  2048. {
  2049. /* BIT5 = BOF (buffer overflow)
  2050. * BIT4 = COF (counter overflow)
  2051. */
  2052. unsigned char status = read_reg(info,RXDMA + DSR) & 0x30;
  2053. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  2054. write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
  2055. if ( debug_level >= DEBUG_LEVEL_ISR )
  2056. printk("%s(%d):%s isr_rxdmaerror(), status=%02x\n",
  2057. __FILE__,__LINE__,info->device_name,status);
  2058. info->rx_overflow = TRUE;
  2059. info->pending_bh |= BH_RECEIVE;
  2060. }
  2061. void isr_txdmaok(SLMP_INFO * info)
  2062. {
  2063. unsigned char status_reg1 = read_reg(info, SR1);
  2064. write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
  2065. write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
  2066. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  2067. if ( debug_level >= DEBUG_LEVEL_ISR )
  2068. printk("%s(%d):%s isr_txdmaok(), status=%02x\n",
  2069. __FILE__,__LINE__,info->device_name,status_reg1);
  2070. /* program TXRDY as FIFO empty flag, enable TXRDY IRQ */
  2071. write_reg16(info, TRC0, 0);
  2072. info->ie0_value |= TXRDYE;
  2073. write_reg(info, IE0, info->ie0_value);
  2074. }
  2075. void isr_txdmaerror(SLMP_INFO * info)
  2076. {
  2077. /* BIT5 = BOF (buffer overflow)
  2078. * BIT4 = COF (counter overflow)
  2079. */
  2080. unsigned char status = read_reg(info,TXDMA + DSR) & 0x30;
  2081. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  2082. write_reg(info, TXDMA + DSR, (unsigned char)(status | 1));
  2083. if ( debug_level >= DEBUG_LEVEL_ISR )
  2084. printk("%s(%d):%s isr_txdmaerror(), status=%02x\n",
  2085. __FILE__,__LINE__,info->device_name,status);
  2086. }
  2087. /* handle input serial signal changes
  2088. */
  2089. void isr_io_pin( SLMP_INFO *info, u16 status )
  2090. {
  2091. struct mgsl_icount *icount;
  2092. if ( debug_level >= DEBUG_LEVEL_ISR )
  2093. printk("%s(%d):isr_io_pin status=%04X\n",
  2094. __FILE__,__LINE__,status);
  2095. if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
  2096. MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
  2097. icount = &info->icount;
  2098. /* update input line counters */
  2099. if (status & MISCSTATUS_RI_LATCHED) {
  2100. icount->rng++;
  2101. if ( status & SerialSignal_RI )
  2102. info->input_signal_events.ri_up++;
  2103. else
  2104. info->input_signal_events.ri_down++;
  2105. }
  2106. if (status & MISCSTATUS_DSR_LATCHED) {
  2107. icount->dsr++;
  2108. if ( status & SerialSignal_DSR )
  2109. info->input_signal_events.dsr_up++;
  2110. else
  2111. info->input_signal_events.dsr_down++;
  2112. }
  2113. if (status & MISCSTATUS_DCD_LATCHED) {
  2114. if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
  2115. info->ie1_value &= ~CDCD;
  2116. write_reg(info, IE1, info->ie1_value);
  2117. }
  2118. icount->dcd++;
  2119. if (status & SerialSignal_DCD) {
  2120. info->input_signal_events.dcd_up++;
  2121. } else
  2122. info->input_signal_events.dcd_down++;
  2123. #ifdef CONFIG_HDLC
  2124. if (info->netcount)
  2125. hdlc_set_carrier(status & SerialSignal_DCD, info->netdev);
  2126. #endif
  2127. }
  2128. if (status & MISCSTATUS_CTS_LATCHED)
  2129. {
  2130. if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
  2131. info->ie1_value &= ~CCTS;
  2132. write_reg(info, IE1, info->ie1_value);
  2133. }
  2134. icount->cts++;
  2135. if ( status & SerialSignal_CTS )
  2136. info->input_signal_events.cts_up++;
  2137. else
  2138. info->input_signal_events.cts_down++;
  2139. }
  2140. wake_up_interruptible(&info->status_event_wait_q);
  2141. wake_up_interruptible(&info->event_wait_q);
  2142. if ( (info->flags & ASYNC_CHECK_CD) &&
  2143. (status & MISCSTATUS_DCD_LATCHED) ) {
  2144. if ( debug_level >= DEBUG_LEVEL_ISR )
  2145. printk("%s CD now %s...", info->device_name,
  2146. (status & SerialSignal_DCD) ? "on" : "off");
  2147. if (status & SerialSignal_DCD)
  2148. wake_up_interruptible(&info->open_wait);
  2149. else {
  2150. if ( debug_level >= DEBUG_LEVEL_ISR )
  2151. printk("doing serial hangup...");
  2152. if (info->tty)
  2153. tty_hangup(info->tty);
  2154. }
  2155. }
  2156. if ( (info->flags & ASYNC_CTS_FLOW) &&
  2157. (status & MISCSTATUS_CTS_LATCHED) ) {
  2158. if ( info->tty ) {
  2159. if (info->tty->hw_stopped) {
  2160. if (status & SerialSignal_CTS) {
  2161. if ( debug_level >= DEBUG_LEVEL_ISR )
  2162. printk("CTS tx start...");
  2163. info->tty->hw_stopped = 0;
  2164. tx_start(info);
  2165. info->pending_bh |= BH_TRANSMIT;
  2166. return;
  2167. }
  2168. } else {
  2169. if (!(status & SerialSignal_CTS)) {
  2170. if ( debug_level >= DEBUG_LEVEL_ISR )
  2171. printk("CTS tx stop...");
  2172. info->tty->hw_stopped = 1;
  2173. tx_stop(info);
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. info->pending_bh |= BH_STATUS;
  2180. }
  2181. /* Interrupt service routine entry point.
  2182. *
  2183. * Arguments:
  2184. * irq interrupt number that caused interrupt
  2185. * dev_id device ID supplied during interrupt registration
  2186. * regs interrupted processor context
  2187. */
  2188. static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
  2189. struct pt_regs *regs)
  2190. {
  2191. SLMP_INFO * info;
  2192. unsigned char status, status0, status1=0;
  2193. unsigned char dmastatus, dmastatus0, dmastatus1=0;
  2194. unsigned char timerstatus0, timerstatus1=0;
  2195. unsigned char shift;
  2196. unsigned int i;
  2197. unsigned short tmp;
  2198. if ( debug_level >= DEBUG_LEVEL_ISR )
  2199. printk("%s(%d): synclinkmp_interrupt(%d)entry.\n",
  2200. __FILE__,__LINE__,irq);
  2201. info = (SLMP_INFO *)dev_id;
  2202. if (!info)
  2203. return IRQ_NONE;
  2204. spin_lock(&info->lock);
  2205. for(;;) {
  2206. /* get status for SCA0 (ports 0-1) */
  2207. tmp = read_reg16(info, ISR0); /* get ISR0 and ISR1 in one read */
  2208. status0 = (unsigned char)tmp;
  2209. dmastatus0 = (unsigned char)(tmp>>8);
  2210. timerstatus0 = read_reg(info, ISR2);
  2211. if ( debug_level >= DEBUG_LEVEL_ISR )
  2212. printk("%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
  2213. __FILE__,__LINE__,info->device_name,
  2214. status0,dmastatus0,timerstatus0);
  2215. if (info->port_count == 4) {
  2216. /* get status for SCA1 (ports 2-3) */
  2217. tmp = read_reg16(info->port_array[2], ISR0);
  2218. status1 = (unsigned char)tmp;
  2219. dmastatus1 = (unsigned char)(tmp>>8);
  2220. timerstatus1 = read_reg(info->port_array[2], ISR2);
  2221. if ( debug_level >= DEBUG_LEVEL_ISR )
  2222. printk("%s(%d):%s status1=%02x, dmastatus1=%02x, timerstatus1=%02x\n",
  2223. __FILE__,__LINE__,info->device_name,
  2224. status1,dmastatus1,timerstatus1);
  2225. }
  2226. if (!status0 && !dmastatus0 && !timerstatus0 &&
  2227. !status1 && !dmastatus1 && !timerstatus1)
  2228. break;
  2229. for(i=0; i < info->port_count ; i++) {
  2230. if (info->port_array[i] == NULL)
  2231. continue;
  2232. if (i < 2) {
  2233. status = status0;
  2234. dmastatus = dmastatus0;
  2235. } else {
  2236. status = status1;
  2237. dmastatus = dmastatus1;
  2238. }
  2239. shift = i & 1 ? 4 :0;
  2240. if (status & BIT0 << shift)
  2241. isr_rxrdy(info->port_array[i]);
  2242. if (status & BIT1 << shift)
  2243. isr_txrdy(info->port_array[i]);
  2244. if (status & BIT2 << shift)
  2245. isr_rxint(info->port_array[i]);
  2246. if (status & BIT3 << shift)
  2247. isr_txint(info->port_array[i]);
  2248. if (dmastatus & BIT0 << shift)
  2249. isr_rxdmaerror(info->port_array[i]);
  2250. if (dmastatus & BIT1 << shift)
  2251. isr_rxdmaok(info->port_array[i]);
  2252. if (dmastatus & BIT2 << shift)
  2253. isr_txdmaerror(info->port_array[i]);
  2254. if (dmastatus & BIT3 << shift)
  2255. isr_txdmaok(info->port_array[i]);
  2256. }
  2257. if (timerstatus0 & (BIT5 | BIT4))
  2258. isr_timer(info->port_array[0]);
  2259. if (timerstatus0 & (BIT7 | BIT6))
  2260. isr_timer(info->port_array[1]);
  2261. if (timerstatus1 & (BIT5 | BIT4))
  2262. isr_timer(info->port_array[2]);
  2263. if (timerstatus1 & (BIT7 | BIT6))
  2264. isr_timer(info->port_array[3]);
  2265. }
  2266. for(i=0; i < info->port_count ; i++) {
  2267. SLMP_INFO * port = info->port_array[i];
  2268. /* Request bottom half processing if there's something
  2269. * for it to do and the bh is not already running.
  2270. *
  2271. * Note: startup adapter diags require interrupts.
  2272. * do not request bottom half processing if the
  2273. * device is not open in a normal mode.
  2274. */
  2275. if ( port && (port->count || port->netcount) &&
  2276. port->pending_bh && !port->bh_running &&
  2277. !port->bh_requested ) {
  2278. if ( debug_level >= DEBUG_LEVEL_ISR )
  2279. printk("%s(%d):%s queueing bh task.\n",
  2280. __FILE__,__LINE__,port->device_name);
  2281. schedule_work(&port->task);
  2282. port->bh_requested = 1;
  2283. }
  2284. }
  2285. spin_unlock(&info->lock);
  2286. if ( debug_level >= DEBUG_LEVEL_ISR )
  2287. printk("%s(%d):synclinkmp_interrupt(%d)exit.\n",
  2288. __FILE__,__LINE__,irq);
  2289. return IRQ_HANDLED;
  2290. }
  2291. /* Initialize and start device.
  2292. */
  2293. static int startup(SLMP_INFO * info)
  2294. {
  2295. if ( debug_level >= DEBUG_LEVEL_INFO )
  2296. printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name);
  2297. if (info->flags & ASYNC_INITIALIZED)
  2298. return 0;
  2299. if (!info->tx_buf) {
  2300. info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL);
  2301. if (!info->tx_buf) {
  2302. printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
  2303. __FILE__,__LINE__,info->device_name);
  2304. return -ENOMEM;
  2305. }
  2306. }
  2307. info->pending_bh = 0;
  2308. /* program hardware for current parameters */
  2309. reset_port(info);
  2310. change_params(info);
  2311. info->status_timer.expires = jiffies + msecs_to_jiffies(10);
  2312. add_timer(&info->status_timer);
  2313. if (info->tty)
  2314. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  2315. info->flags |= ASYNC_INITIALIZED;
  2316. return 0;
  2317. }
  2318. /* Called by close() and hangup() to shutdown hardware
  2319. */
  2320. static void shutdown(SLMP_INFO * info)
  2321. {
  2322. unsigned long flags;
  2323. if (!(info->flags & ASYNC_INITIALIZED))
  2324. return;
  2325. if (debug_level >= DEBUG_LEVEL_INFO)
  2326. printk("%s(%d):%s synclinkmp_shutdown()\n",
  2327. __FILE__,__LINE__, info->device_name );
  2328. /* clear status wait queue because status changes */
  2329. /* can't happen after shutting down the hardware */
  2330. wake_up_interruptible(&info->status_event_wait_q);
  2331. wake_up_interruptible(&info->event_wait_q);
  2332. del_timer(&info->tx_timer);
  2333. del_timer(&info->status_timer);
  2334. if (info->tx_buf) {
  2335. kfree(info->tx_buf);
  2336. info->tx_buf = NULL;
  2337. }
  2338. spin_lock_irqsave(&info->lock,flags);
  2339. reset_port(info);
  2340. if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
  2341. info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  2342. set_signals(info);
  2343. }
  2344. spin_unlock_irqrestore(&info->lock,flags);
  2345. if (info->tty)
  2346. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2347. info->flags &= ~ASYNC_INITIALIZED;
  2348. }
  2349. static void program_hw(SLMP_INFO *info)
  2350. {
  2351. unsigned long flags;
  2352. spin_lock_irqsave(&info->lock,flags);
  2353. rx_stop(info);
  2354. tx_stop(info);
  2355. info->tx_count = info->tx_put = info->tx_get = 0;
  2356. if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
  2357. hdlc_mode(info);
  2358. else
  2359. async_mode(info);
  2360. set_signals(info);
  2361. info->dcd_chkcount = 0;
  2362. info->cts_chkcount = 0;
  2363. info->ri_chkcount = 0;
  2364. info->dsr_chkcount = 0;
  2365. info->ie1_value |= (CDCD|CCTS);
  2366. write_reg(info, IE1, info->ie1_value);
  2367. get_signals(info);
  2368. if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
  2369. rx_start(info);
  2370. spin_unlock_irqrestore(&info->lock,flags);
  2371. }
  2372. /* Reconfigure adapter based on new parameters
  2373. */
  2374. static void change_params(SLMP_INFO *info)
  2375. {
  2376. unsigned cflag;
  2377. int bits_per_char;
  2378. if (!info->tty || !info->tty->termios)
  2379. return;
  2380. if (debug_level >= DEBUG_LEVEL_INFO)
  2381. printk("%s(%d):%s change_params()\n",
  2382. __FILE__,__LINE__, info->device_name );
  2383. cflag = info->tty->termios->c_cflag;
  2384. /* if B0 rate (hangup) specified then negate DTR and RTS */
  2385. /* otherwise assert DTR and RTS */
  2386. if (cflag & CBAUD)
  2387. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2388. else
  2389. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  2390. /* byte size and parity */
  2391. switch (cflag & CSIZE) {
  2392. case CS5: info->params.data_bits = 5; break;
  2393. case CS6: info->params.data_bits = 6; break;
  2394. case CS7: info->params.data_bits = 7; break;
  2395. case CS8: info->params.data_bits = 8; break;
  2396. /* Never happens, but GCC is too dumb to figure it out */
  2397. default: info->params.data_bits = 7; break;
  2398. }
  2399. if (cflag & CSTOPB)
  2400. info->params.stop_bits = 2;
  2401. else
  2402. info->params.stop_bits = 1;
  2403. info->params.parity = ASYNC_PARITY_NONE;
  2404. if (cflag & PARENB) {
  2405. if (cflag & PARODD)
  2406. info->params.parity = ASYNC_PARITY_ODD;
  2407. else
  2408. info->params.parity = ASYNC_PARITY_EVEN;
  2409. #ifdef CMSPAR
  2410. if (cflag & CMSPAR)
  2411. info->params.parity = ASYNC_PARITY_SPACE;
  2412. #endif
  2413. }
  2414. /* calculate number of jiffies to transmit a full
  2415. * FIFO (32 bytes) at specified data rate
  2416. */
  2417. bits_per_char = info->params.data_bits +
  2418. info->params.stop_bits + 1;
  2419. /* if port data rate is set to 460800 or less then
  2420. * allow tty settings to override, otherwise keep the
  2421. * current data rate.
  2422. */
  2423. if (info->params.data_rate <= 460800) {
  2424. info->params.data_rate = tty_get_baud_rate(info->tty);
  2425. }
  2426. if ( info->params.data_rate ) {
  2427. info->timeout = (32*HZ*bits_per_char) /
  2428. info->params.data_rate;
  2429. }
  2430. info->timeout += HZ/50; /* Add .02 seconds of slop */
  2431. if (cflag & CRTSCTS)
  2432. info->flags |= ASYNC_CTS_FLOW;
  2433. else
  2434. info->flags &= ~ASYNC_CTS_FLOW;
  2435. if (cflag & CLOCAL)
  2436. info->flags &= ~ASYNC_CHECK_CD;
  2437. else
  2438. info->flags |= ASYNC_CHECK_CD;
  2439. /* process tty input control flags */
  2440. info->read_status_mask2 = OVRN;
  2441. if (I_INPCK(info->tty))
  2442. info->read_status_mask2 |= PE | FRME;
  2443. if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  2444. info->read_status_mask1 |= BRKD;
  2445. if (I_IGNPAR(info->tty))
  2446. info->ignore_status_mask2 |= PE | FRME;
  2447. if (I_IGNBRK(info->tty)) {
  2448. info->ignore_status_mask1 |= BRKD;
  2449. /* If ignoring parity and break indicators, ignore
  2450. * overruns too. (For real raw support).
  2451. */
  2452. if (I_IGNPAR(info->tty))
  2453. info->ignore_status_mask2 |= OVRN;
  2454. }
  2455. program_hw(info);
  2456. }
  2457. static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
  2458. {
  2459. int err;
  2460. if (debug_level >= DEBUG_LEVEL_INFO)
  2461. printk("%s(%d):%s get_params()\n",
  2462. __FILE__,__LINE__, info->device_name);
  2463. COPY_TO_USER(err,user_icount, &info->icount, sizeof(struct mgsl_icount));
  2464. if (err) {
  2465. if ( debug_level >= DEBUG_LEVEL_INFO )
  2466. printk( "%s(%d):%s get_stats() user buffer copy failed\n",
  2467. __FILE__,__LINE__,info->device_name);
  2468. return -EFAULT;
  2469. }
  2470. return 0;
  2471. }
  2472. static int get_params(SLMP_INFO * info, MGSL_PARAMS __user *user_params)
  2473. {
  2474. int err;
  2475. if (debug_level >= DEBUG_LEVEL_INFO)
  2476. printk("%s(%d):%s get_params()\n",
  2477. __FILE__,__LINE__, info->device_name);
  2478. COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
  2479. if (err) {
  2480. if ( debug_level >= DEBUG_LEVEL_INFO )
  2481. printk( "%s(%d):%s get_params() user buffer copy failed\n",
  2482. __FILE__,__LINE__,info->device_name);
  2483. return -EFAULT;
  2484. }
  2485. return 0;
  2486. }
  2487. static int set_params(SLMP_INFO * info, MGSL_PARAMS __user *new_params)
  2488. {
  2489. unsigned long flags;
  2490. MGSL_PARAMS tmp_params;
  2491. int err;
  2492. if (debug_level >= DEBUG_LEVEL_INFO)
  2493. printk("%s(%d):%s set_params\n",
  2494. __FILE__,__LINE__,info->device_name );
  2495. COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
  2496. if (err) {
  2497. if ( debug_level >= DEBUG_LEVEL_INFO )
  2498. printk( "%s(%d):%s set_params() user buffer copy failed\n",
  2499. __FILE__,__LINE__,info->device_name);
  2500. return -EFAULT;
  2501. }
  2502. spin_lock_irqsave(&info->lock,flags);
  2503. memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
  2504. spin_unlock_irqrestore(&info->lock,flags);
  2505. change_params(info);
  2506. return 0;
  2507. }
  2508. static int get_txidle(SLMP_INFO * info, int __user *idle_mode)
  2509. {
  2510. int err;
  2511. if (debug_level >= DEBUG_LEVEL_INFO)
  2512. printk("%s(%d):%s get_txidle()=%d\n",
  2513. __FILE__,__LINE__, info->device_name, info->idle_mode);
  2514. COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
  2515. if (err) {
  2516. if ( debug_level >= DEBUG_LEVEL_INFO )
  2517. printk( "%s(%d):%s get_txidle() user buffer copy failed\n",
  2518. __FILE__,__LINE__,info->device_name);
  2519. return -EFAULT;
  2520. }
  2521. return 0;
  2522. }
  2523. static int set_txidle(SLMP_INFO * info, int idle_mode)
  2524. {
  2525. unsigned long flags;
  2526. if (debug_level >= DEBUG_LEVEL_INFO)
  2527. printk("%s(%d):%s set_txidle(%d)\n",
  2528. __FILE__,__LINE__,info->device_name, idle_mode );
  2529. spin_lock_irqsave(&info->lock,flags);
  2530. info->idle_mode = idle_mode;
  2531. tx_set_idle( info );
  2532. spin_unlock_irqrestore(&info->lock,flags);
  2533. return 0;
  2534. }
  2535. static int tx_enable(SLMP_INFO * info, int enable)
  2536. {
  2537. unsigned long flags;
  2538. if (debug_level >= DEBUG_LEVEL_INFO)
  2539. printk("%s(%d):%s tx_enable(%d)\n",
  2540. __FILE__,__LINE__,info->device_name, enable);
  2541. spin_lock_irqsave(&info->lock,flags);
  2542. if ( enable ) {
  2543. if ( !info->tx_enabled ) {
  2544. tx_start(info);
  2545. }
  2546. } else {
  2547. if ( info->tx_enabled )
  2548. tx_stop(info);
  2549. }
  2550. spin_unlock_irqrestore(&info->lock,flags);
  2551. return 0;
  2552. }
  2553. /* abort send HDLC frame
  2554. */
  2555. static int tx_abort(SLMP_INFO * info)
  2556. {
  2557. unsigned long flags;
  2558. if (debug_level >= DEBUG_LEVEL_INFO)
  2559. printk("%s(%d):%s tx_abort()\n",
  2560. __FILE__,__LINE__,info->device_name);
  2561. spin_lock_irqsave(&info->lock,flags);
  2562. if ( info->tx_active && info->params.mode == MGSL_MODE_HDLC ) {
  2563. info->ie1_value &= ~UDRN;
  2564. info->ie1_value |= IDLE;
  2565. write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
  2566. write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
  2567. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  2568. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  2569. write_reg(info, CMD, TXABORT);
  2570. }
  2571. spin_unlock_irqrestore(&info->lock,flags);
  2572. return 0;
  2573. }
  2574. static int rx_enable(SLMP_INFO * info, int enable)
  2575. {
  2576. unsigned long flags;
  2577. if (debug_level >= DEBUG_LEVEL_INFO)
  2578. printk("%s(%d):%s rx_enable(%d)\n",
  2579. __FILE__,__LINE__,info->device_name,enable);
  2580. spin_lock_irqsave(&info->lock,flags);
  2581. if ( enable ) {
  2582. if ( !info->rx_enabled )
  2583. rx_start(info);
  2584. } else {
  2585. if ( info->rx_enabled )
  2586. rx_stop(info);
  2587. }
  2588. spin_unlock_irqrestore(&info->lock,flags);
  2589. return 0;
  2590. }
  2591. static int map_status(int signals)
  2592. {
  2593. /* Map status bits to API event bits */
  2594. return ((signals & SerialSignal_DSR) ? MgslEvent_DsrActive : MgslEvent_DsrInactive) +
  2595. ((signals & SerialSignal_CTS) ? MgslEvent_CtsActive : MgslEvent_CtsInactive) +
  2596. ((signals & SerialSignal_DCD) ? MgslEvent_DcdActive : MgslEvent_DcdInactive) +
  2597. ((signals & SerialSignal_RI) ? MgslEvent_RiActive : MgslEvent_RiInactive);
  2598. }
  2599. /* wait for specified event to occur
  2600. */
  2601. static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
  2602. {
  2603. unsigned long flags;
  2604. int s;
  2605. int rc=0;
  2606. struct mgsl_icount cprev, cnow;
  2607. int events;
  2608. int mask;
  2609. struct _input_signal_events oldsigs, newsigs;
  2610. DECLARE_WAITQUEUE(wait, current);
  2611. COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
  2612. if (rc) {
  2613. return -EFAULT;
  2614. }
  2615. if (debug_level >= DEBUG_LEVEL_INFO)
  2616. printk("%s(%d):%s wait_mgsl_event(%d)\n",
  2617. __FILE__,__LINE__,info->device_name,mask);
  2618. spin_lock_irqsave(&info->lock,flags);
  2619. /* return immediately if state matches requested events */
  2620. get_signals(info);
  2621. s = map_status(info->serial_signals);
  2622. events = mask &
  2623. ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
  2624. ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
  2625. ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
  2626. ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
  2627. if (events) {
  2628. spin_unlock_irqrestore(&info->lock,flags);
  2629. goto exit;
  2630. }
  2631. /* save current irq counts */
  2632. cprev = info->icount;
  2633. oldsigs = info->input_signal_events;
  2634. /* enable hunt and idle irqs if needed */
  2635. if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
  2636. unsigned char oldval = info->ie1_value;
  2637. unsigned char newval = oldval +
  2638. (mask & MgslEvent_ExitHuntMode ? FLGD:0) +
  2639. (mask & MgslEvent_IdleReceived ? IDLD:0);
  2640. if ( oldval != newval ) {
  2641. info->ie1_value = newval;
  2642. write_reg(info, IE1, info->ie1_value);
  2643. }
  2644. }
  2645. set_current_state(TASK_INTERRUPTIBLE);
  2646. add_wait_queue(&info->event_wait_q, &wait);
  2647. spin_unlock_irqrestore(&info->lock,flags);
  2648. for(;;) {
  2649. schedule();
  2650. if (signal_pending(current)) {
  2651. rc = -ERESTARTSYS;
  2652. break;
  2653. }
  2654. /* get current irq counts */
  2655. spin_lock_irqsave(&info->lock,flags);
  2656. cnow = info->icount;
  2657. newsigs = info->input_signal_events;
  2658. set_current_state(TASK_INTERRUPTIBLE);
  2659. spin_unlock_irqrestore(&info->lock,flags);
  2660. /* if no change, wait aborted for some reason */
  2661. if (newsigs.dsr_up == oldsigs.dsr_up &&
  2662. newsigs.dsr_down == oldsigs.dsr_down &&
  2663. newsigs.dcd_up == oldsigs.dcd_up &&
  2664. newsigs.dcd_down == oldsigs.dcd_down &&
  2665. newsigs.cts_up == oldsigs.cts_up &&
  2666. newsigs.cts_down == oldsigs.cts_down &&
  2667. newsigs.ri_up == oldsigs.ri_up &&
  2668. newsigs.ri_down == oldsigs.ri_down &&
  2669. cnow.exithunt == cprev.exithunt &&
  2670. cnow.rxidle == cprev.rxidle) {
  2671. rc = -EIO;
  2672. break;
  2673. }
  2674. events = mask &
  2675. ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
  2676. (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
  2677. (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
  2678. (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
  2679. (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
  2680. (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
  2681. (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
  2682. (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
  2683. (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
  2684. (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
  2685. if (events)
  2686. break;
  2687. cprev = cnow;
  2688. oldsigs = newsigs;
  2689. }
  2690. remove_wait_queue(&info->event_wait_q, &wait);
  2691. set_current_state(TASK_RUNNING);
  2692. if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
  2693. spin_lock_irqsave(&info->lock,flags);
  2694. if (!waitqueue_active(&info->event_wait_q)) {
  2695. /* disable enable exit hunt mode/idle rcvd IRQs */
  2696. info->ie1_value &= ~(FLGD|IDLD);
  2697. write_reg(info, IE1, info->ie1_value);
  2698. }
  2699. spin_unlock_irqrestore(&info->lock,flags);
  2700. }
  2701. exit:
  2702. if ( rc == 0 )
  2703. PUT_USER(rc, events, mask_ptr);
  2704. return rc;
  2705. }
  2706. static int modem_input_wait(SLMP_INFO *info,int arg)
  2707. {
  2708. unsigned long flags;
  2709. int rc;
  2710. struct mgsl_icount cprev, cnow;
  2711. DECLARE_WAITQUEUE(wait, current);
  2712. /* save current irq counts */
  2713. spin_lock_irqsave(&info->lock,flags);
  2714. cprev = info->icount;
  2715. add_wait_queue(&info->status_event_wait_q, &wait);
  2716. set_current_state(TASK_INTERRUPTIBLE);
  2717. spin_unlock_irqrestore(&info->lock,flags);
  2718. for(;;) {
  2719. schedule();
  2720. if (signal_pending(current)) {
  2721. rc = -ERESTARTSYS;
  2722. break;
  2723. }
  2724. /* get new irq counts */
  2725. spin_lock_irqsave(&info->lock,flags);
  2726. cnow = info->icount;
  2727. set_current_state(TASK_INTERRUPTIBLE);
  2728. spin_unlock_irqrestore(&info->lock,flags);
  2729. /* if no change, wait aborted for some reason */
  2730. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  2731. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
  2732. rc = -EIO;
  2733. break;
  2734. }
  2735. /* check for change in caller specified modem input */
  2736. if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
  2737. (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
  2738. (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
  2739. (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
  2740. rc = 0;
  2741. break;
  2742. }
  2743. cprev = cnow;
  2744. }
  2745. remove_wait_queue(&info->status_event_wait_q, &wait);
  2746. set_current_state(TASK_RUNNING);
  2747. return rc;
  2748. }
  2749. /* return the state of the serial control and status signals
  2750. */
  2751. static int tiocmget(struct tty_struct *tty, struct file *file)
  2752. {
  2753. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  2754. unsigned int result;
  2755. unsigned long flags;
  2756. spin_lock_irqsave(&info->lock,flags);
  2757. get_signals(info);
  2758. spin_unlock_irqrestore(&info->lock,flags);
  2759. result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
  2760. ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
  2761. ((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
  2762. ((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
  2763. ((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
  2764. ((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
  2765. if (debug_level >= DEBUG_LEVEL_INFO)
  2766. printk("%s(%d):%s tiocmget() value=%08X\n",
  2767. __FILE__,__LINE__, info->device_name, result );
  2768. return result;
  2769. }
  2770. /* set modem control signals (DTR/RTS)
  2771. */
  2772. static int tiocmset(struct tty_struct *tty, struct file *file,
  2773. unsigned int set, unsigned int clear)
  2774. {
  2775. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  2776. unsigned long flags;
  2777. if (debug_level >= DEBUG_LEVEL_INFO)
  2778. printk("%s(%d):%s tiocmset(%x,%x)\n",
  2779. __FILE__,__LINE__,info->device_name, set, clear);
  2780. if (set & TIOCM_RTS)
  2781. info->serial_signals |= SerialSignal_RTS;
  2782. if (set & TIOCM_DTR)
  2783. info->serial_signals |= SerialSignal_DTR;
  2784. if (clear & TIOCM_RTS)
  2785. info->serial_signals &= ~SerialSignal_RTS;
  2786. if (clear & TIOCM_DTR)
  2787. info->serial_signals &= ~SerialSignal_DTR;
  2788. spin_lock_irqsave(&info->lock,flags);
  2789. set_signals(info);
  2790. spin_unlock_irqrestore(&info->lock,flags);
  2791. return 0;
  2792. }
  2793. /* Block the current process until the specified port is ready to open.
  2794. */
  2795. static int block_til_ready(struct tty_struct *tty, struct file *filp,
  2796. SLMP_INFO *info)
  2797. {
  2798. DECLARE_WAITQUEUE(wait, current);
  2799. int retval;
  2800. int do_clocal = 0, extra_count = 0;
  2801. unsigned long flags;
  2802. if (debug_level >= DEBUG_LEVEL_INFO)
  2803. printk("%s(%d):%s block_til_ready()\n",
  2804. __FILE__,__LINE__, tty->driver->name );
  2805. if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
  2806. /* nonblock mode is set or port is not enabled */
  2807. /* just verify that callout device is not active */
  2808. info->flags |= ASYNC_NORMAL_ACTIVE;
  2809. return 0;
  2810. }
  2811. if (tty->termios->c_cflag & CLOCAL)
  2812. do_clocal = 1;
  2813. /* Wait for carrier detect and the line to become
  2814. * free (i.e., not in use by the callout). While we are in
  2815. * this loop, info->count is dropped by one, so that
  2816. * close() knows when to free things. We restore it upon
  2817. * exit, either normal or abnormal.
  2818. */
  2819. retval = 0;
  2820. add_wait_queue(&info->open_wait, &wait);
  2821. if (debug_level >= DEBUG_LEVEL_INFO)
  2822. printk("%s(%d):%s block_til_ready() before block, count=%d\n",
  2823. __FILE__,__LINE__, tty->driver->name, info->count );
  2824. spin_lock_irqsave(&info->lock, flags);
  2825. if (!tty_hung_up_p(filp)) {
  2826. extra_count = 1;
  2827. info->count--;
  2828. }
  2829. spin_unlock_irqrestore(&info->lock, flags);
  2830. info->blocked_open++;
  2831. while (1) {
  2832. if ((tty->termios->c_cflag & CBAUD)) {
  2833. spin_lock_irqsave(&info->lock,flags);
  2834. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2835. set_signals(info);
  2836. spin_unlock_irqrestore(&info->lock,flags);
  2837. }
  2838. set_current_state(TASK_INTERRUPTIBLE);
  2839. if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
  2840. retval = (info->flags & ASYNC_HUP_NOTIFY) ?
  2841. -EAGAIN : -ERESTARTSYS;
  2842. break;
  2843. }
  2844. spin_lock_irqsave(&info->lock,flags);
  2845. get_signals(info);
  2846. spin_unlock_irqrestore(&info->lock,flags);
  2847. if (!(info->flags & ASYNC_CLOSING) &&
  2848. (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
  2849. break;
  2850. }
  2851. if (signal_pending(current)) {
  2852. retval = -ERESTARTSYS;
  2853. break;
  2854. }
  2855. if (debug_level >= DEBUG_LEVEL_INFO)
  2856. printk("%s(%d):%s block_til_ready() count=%d\n",
  2857. __FILE__,__LINE__, tty->driver->name, info->count );
  2858. schedule();
  2859. }
  2860. set_current_state(TASK_RUNNING);
  2861. remove_wait_queue(&info->open_wait, &wait);
  2862. if (extra_count)
  2863. info->count++;
  2864. info->blocked_open--;
  2865. if (debug_level >= DEBUG_LEVEL_INFO)
  2866. printk("%s(%d):%s block_til_ready() after, count=%d\n",
  2867. __FILE__,__LINE__, tty->driver->name, info->count );
  2868. if (!retval)
  2869. info->flags |= ASYNC_NORMAL_ACTIVE;
  2870. return retval;
  2871. }
  2872. int alloc_dma_bufs(SLMP_INFO *info)
  2873. {
  2874. unsigned short BuffersPerFrame;
  2875. unsigned short BufferCount;
  2876. // Force allocation to start at 64K boundary for each port.
  2877. // This is necessary because *all* buffer descriptors for a port
  2878. // *must* be in the same 64K block. All descriptors on a port
  2879. // share a common 'base' address (upper 8 bits of 24 bits) programmed
  2880. // into the CBP register.
  2881. info->port_array[0]->last_mem_alloc = (SCA_MEM_SIZE/4) * info->port_num;
  2882. /* Calculate the number of DMA buffers necessary to hold the */
  2883. /* largest allowable frame size. Note: If the max frame size is */
  2884. /* not an even multiple of the DMA buffer size then we need to */
  2885. /* round the buffer count per frame up one. */
  2886. BuffersPerFrame = (unsigned short)(info->max_frame_size/SCABUFSIZE);
  2887. if ( info->max_frame_size % SCABUFSIZE )
  2888. BuffersPerFrame++;
  2889. /* calculate total number of data buffers (SCABUFSIZE) possible
  2890. * in one ports memory (SCA_MEM_SIZE/4) after allocating memory
  2891. * for the descriptor list (BUFFERLISTSIZE).
  2892. */
  2893. BufferCount = (SCA_MEM_SIZE/4 - BUFFERLISTSIZE)/SCABUFSIZE;
  2894. /* limit number of buffers to maximum amount of descriptors */
  2895. if (BufferCount > BUFFERLISTSIZE/sizeof(SCADESC))
  2896. BufferCount = BUFFERLISTSIZE/sizeof(SCADESC);
  2897. /* use enough buffers to transmit one max size frame */
  2898. info->tx_buf_count = BuffersPerFrame + 1;
  2899. /* never use more than half the available buffers for transmit */
  2900. if (info->tx_buf_count > (BufferCount/2))
  2901. info->tx_buf_count = BufferCount/2;
  2902. if (info->tx_buf_count > SCAMAXDESC)
  2903. info->tx_buf_count = SCAMAXDESC;
  2904. /* use remaining buffers for receive */
  2905. info->rx_buf_count = BufferCount - info->tx_buf_count;
  2906. if (info->rx_buf_count > SCAMAXDESC)
  2907. info->rx_buf_count = SCAMAXDESC;
  2908. if ( debug_level >= DEBUG_LEVEL_INFO )
  2909. printk("%s(%d):%s Allocating %d TX and %d RX DMA buffers.\n",
  2910. __FILE__,__LINE__, info->device_name,
  2911. info->tx_buf_count,info->rx_buf_count);
  2912. if ( alloc_buf_list( info ) < 0 ||
  2913. alloc_frame_bufs(info,
  2914. info->rx_buf_list,
  2915. info->rx_buf_list_ex,
  2916. info->rx_buf_count) < 0 ||
  2917. alloc_frame_bufs(info,
  2918. info->tx_buf_list,
  2919. info->tx_buf_list_ex,
  2920. info->tx_buf_count) < 0 ||
  2921. alloc_tmp_rx_buf(info) < 0 ) {
  2922. printk("%s(%d):%s Can't allocate DMA buffer memory\n",
  2923. __FILE__,__LINE__, info->device_name);
  2924. return -ENOMEM;
  2925. }
  2926. rx_reset_buffers( info );
  2927. return 0;
  2928. }
  2929. /* Allocate DMA buffers for the transmit and receive descriptor lists.
  2930. */
  2931. int alloc_buf_list(SLMP_INFO *info)
  2932. {
  2933. unsigned int i;
  2934. /* build list in adapter shared memory */
  2935. info->buffer_list = info->memory_base + info->port_array[0]->last_mem_alloc;
  2936. info->buffer_list_phys = info->port_array[0]->last_mem_alloc;
  2937. info->port_array[0]->last_mem_alloc += BUFFERLISTSIZE;
  2938. memset(info->buffer_list, 0, BUFFERLISTSIZE);
  2939. /* Save virtual address pointers to the receive and */
  2940. /* transmit buffer lists. (Receive 1st). These pointers will */
  2941. /* be used by the processor to access the lists. */
  2942. info->rx_buf_list = (SCADESC *)info->buffer_list;
  2943. info->tx_buf_list = (SCADESC *)info->buffer_list;
  2944. info->tx_buf_list += info->rx_buf_count;
  2945. /* Build links for circular buffer entry lists (tx and rx)
  2946. *
  2947. * Note: links are physical addresses read by the SCA device
  2948. * to determine the next buffer entry to use.
  2949. */
  2950. for ( i = 0; i < info->rx_buf_count; i++ ) {
  2951. /* calculate and store physical address of this buffer entry */
  2952. info->rx_buf_list_ex[i].phys_entry =
  2953. info->buffer_list_phys + (i * sizeof(SCABUFSIZE));
  2954. /* calculate and store physical address of */
  2955. /* next entry in cirular list of entries */
  2956. info->rx_buf_list[i].next = info->buffer_list_phys;
  2957. if ( i < info->rx_buf_count - 1 )
  2958. info->rx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
  2959. info->rx_buf_list[i].length = SCABUFSIZE;
  2960. }
  2961. for ( i = 0; i < info->tx_buf_count; i++ ) {
  2962. /* calculate and store physical address of this buffer entry */
  2963. info->tx_buf_list_ex[i].phys_entry = info->buffer_list_phys +
  2964. ((info->rx_buf_count + i) * sizeof(SCADESC));
  2965. /* calculate and store physical address of */
  2966. /* next entry in cirular list of entries */
  2967. info->tx_buf_list[i].next = info->buffer_list_phys +
  2968. info->rx_buf_count * sizeof(SCADESC);
  2969. if ( i < info->tx_buf_count - 1 )
  2970. info->tx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
  2971. }
  2972. return 0;
  2973. }
  2974. /* Allocate the frame DMA buffers used by the specified buffer list.
  2975. */
  2976. int alloc_frame_bufs(SLMP_INFO *info, SCADESC *buf_list,SCADESC_EX *buf_list_ex,int count)
  2977. {
  2978. int i;
  2979. unsigned long phys_addr;
  2980. for ( i = 0; i < count; i++ ) {
  2981. buf_list_ex[i].virt_addr = info->memory_base + info->port_array[0]->last_mem_alloc;
  2982. phys_addr = info->port_array[0]->last_mem_alloc;
  2983. info->port_array[0]->last_mem_alloc += SCABUFSIZE;
  2984. buf_list[i].buf_ptr = (unsigned short)phys_addr;
  2985. buf_list[i].buf_base = (unsigned char)(phys_addr >> 16);
  2986. }
  2987. return 0;
  2988. }
  2989. void free_dma_bufs(SLMP_INFO *info)
  2990. {
  2991. info->buffer_list = NULL;
  2992. info->rx_buf_list = NULL;
  2993. info->tx_buf_list = NULL;
  2994. }
  2995. /* allocate buffer large enough to hold max_frame_size.
  2996. * This buffer is used to pass an assembled frame to the line discipline.
  2997. */
  2998. int alloc_tmp_rx_buf(SLMP_INFO *info)
  2999. {
  3000. info->tmp_rx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
  3001. if (info->tmp_rx_buf == NULL)
  3002. return -ENOMEM;
  3003. return 0;
  3004. }
  3005. void free_tmp_rx_buf(SLMP_INFO *info)
  3006. {
  3007. if (info->tmp_rx_buf)
  3008. kfree(info->tmp_rx_buf);
  3009. info->tmp_rx_buf = NULL;
  3010. }
  3011. int claim_resources(SLMP_INFO *info)
  3012. {
  3013. if (request_mem_region(info->phys_memory_base,SCA_MEM_SIZE,"synclinkmp") == NULL) {
  3014. printk( "%s(%d):%s mem addr conflict, Addr=%08X\n",
  3015. __FILE__,__LINE__,info->device_name, info->phys_memory_base);
  3016. info->init_error = DiagStatus_AddressConflict;
  3017. goto errout;
  3018. }
  3019. else
  3020. info->shared_mem_requested = 1;
  3021. if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclinkmp") == NULL) {
  3022. printk( "%s(%d):%s lcr mem addr conflict, Addr=%08X\n",
  3023. __FILE__,__LINE__,info->device_name, info->phys_lcr_base);
  3024. info->init_error = DiagStatus_AddressConflict;
  3025. goto errout;
  3026. }
  3027. else
  3028. info->lcr_mem_requested = 1;
  3029. if (request_mem_region(info->phys_sca_base + info->sca_offset,SCA_BASE_SIZE,"synclinkmp") == NULL) {
  3030. printk( "%s(%d):%s sca mem addr conflict, Addr=%08X\n",
  3031. __FILE__,__LINE__,info->device_name, info->phys_sca_base);
  3032. info->init_error = DiagStatus_AddressConflict;
  3033. goto errout;
  3034. }
  3035. else
  3036. info->sca_base_requested = 1;
  3037. if (request_mem_region(info->phys_statctrl_base + info->statctrl_offset,SCA_REG_SIZE,"synclinkmp") == NULL) {
  3038. printk( "%s(%d):%s stat/ctrl mem addr conflict, Addr=%08X\n",
  3039. __FILE__,__LINE__,info->device_name, info->phys_statctrl_base);
  3040. info->init_error = DiagStatus_AddressConflict;
  3041. goto errout;
  3042. }
  3043. else
  3044. info->sca_statctrl_requested = 1;
  3045. info->memory_base = ioremap(info->phys_memory_base,SCA_MEM_SIZE);
  3046. if (!info->memory_base) {
  3047. printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n",
  3048. __FILE__,__LINE__,info->device_name, info->phys_memory_base );
  3049. info->init_error = DiagStatus_CantAssignPciResources;
  3050. goto errout;
  3051. }
  3052. info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE);
  3053. if (!info->lcr_base) {
  3054. printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n",
  3055. __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
  3056. info->init_error = DiagStatus_CantAssignPciResources;
  3057. goto errout;
  3058. }
  3059. info->lcr_base += info->lcr_offset;
  3060. info->sca_base = ioremap(info->phys_sca_base,PAGE_SIZE);
  3061. if (!info->sca_base) {
  3062. printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n",
  3063. __FILE__,__LINE__,info->device_name, info->phys_sca_base );
  3064. info->init_error = DiagStatus_CantAssignPciResources;
  3065. goto errout;
  3066. }
  3067. info->sca_base += info->sca_offset;
  3068. info->statctrl_base = ioremap(info->phys_statctrl_base,PAGE_SIZE);
  3069. if (!info->statctrl_base) {
  3070. printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n",
  3071. __FILE__,__LINE__,info->device_name, info->phys_statctrl_base );
  3072. info->init_error = DiagStatus_CantAssignPciResources;
  3073. goto errout;
  3074. }
  3075. info->statctrl_base += info->statctrl_offset;
  3076. if ( !memory_test(info) ) {
  3077. printk( "%s(%d):Shared Memory Test failed for device %s MemAddr=%08X\n",
  3078. __FILE__,__LINE__,info->device_name, info->phys_memory_base );
  3079. info->init_error = DiagStatus_MemoryError;
  3080. goto errout;
  3081. }
  3082. return 0;
  3083. errout:
  3084. release_resources( info );
  3085. return -ENODEV;
  3086. }
  3087. void release_resources(SLMP_INFO *info)
  3088. {
  3089. if ( debug_level >= DEBUG_LEVEL_INFO )
  3090. printk( "%s(%d):%s release_resources() entry\n",
  3091. __FILE__,__LINE__,info->device_name );
  3092. if ( info->irq_requested ) {
  3093. free_irq(info->irq_level, info);
  3094. info->irq_requested = 0;
  3095. }
  3096. if ( info->shared_mem_requested ) {
  3097. release_mem_region(info->phys_memory_base,SCA_MEM_SIZE);
  3098. info->shared_mem_requested = 0;
  3099. }
  3100. if ( info->lcr_mem_requested ) {
  3101. release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
  3102. info->lcr_mem_requested = 0;
  3103. }
  3104. if ( info->sca_base_requested ) {
  3105. release_mem_region(info->phys_sca_base + info->sca_offset,SCA_BASE_SIZE);
  3106. info->sca_base_requested = 0;
  3107. }
  3108. if ( info->sca_statctrl_requested ) {
  3109. release_mem_region(info->phys_statctrl_base + info->statctrl_offset,SCA_REG_SIZE);
  3110. info->sca_statctrl_requested = 0;
  3111. }
  3112. if (info->memory_base){
  3113. iounmap(info->memory_base);
  3114. info->memory_base = NULL;
  3115. }
  3116. if (info->sca_base) {
  3117. iounmap(info->sca_base - info->sca_offset);
  3118. info->sca_base=NULL;
  3119. }
  3120. if (info->statctrl_base) {
  3121. iounmap(info->statctrl_base - info->statctrl_offset);
  3122. info->statctrl_base=NULL;
  3123. }
  3124. if (info->lcr_base){
  3125. iounmap(info->lcr_base - info->lcr_offset);
  3126. info->lcr_base = NULL;
  3127. }
  3128. if ( debug_level >= DEBUG_LEVEL_INFO )
  3129. printk( "%s(%d):%s release_resources() exit\n",
  3130. __FILE__,__LINE__,info->device_name );
  3131. }
  3132. /* Add the specified device instance data structure to the
  3133. * global linked list of devices and increment the device count.
  3134. */
  3135. void add_device(SLMP_INFO *info)
  3136. {
  3137. info->next_device = NULL;
  3138. info->line = synclinkmp_device_count;
  3139. sprintf(info->device_name,"ttySLM%dp%d",info->adapter_num,info->port_num);
  3140. if (info->line < MAX_DEVICES) {
  3141. if (maxframe[info->line])
  3142. info->max_frame_size = maxframe[info->line];
  3143. info->dosyncppp = dosyncppp[info->line];
  3144. }
  3145. synclinkmp_device_count++;
  3146. if ( !synclinkmp_device_list )
  3147. synclinkmp_device_list = info;
  3148. else {
  3149. SLMP_INFO *current_dev = synclinkmp_device_list;
  3150. while( current_dev->next_device )
  3151. current_dev = current_dev->next_device;
  3152. current_dev->next_device = info;
  3153. }
  3154. if ( info->max_frame_size < 4096 )
  3155. info->max_frame_size = 4096;
  3156. else if ( info->max_frame_size > 65535 )
  3157. info->max_frame_size = 65535;
  3158. printk( "SyncLink MultiPort %s: "
  3159. "Mem=(%08x %08X %08x %08X) IRQ=%d MaxFrameSize=%u\n",
  3160. info->device_name,
  3161. info->phys_sca_base,
  3162. info->phys_memory_base,
  3163. info->phys_statctrl_base,
  3164. info->phys_lcr_base,
  3165. info->irq_level,
  3166. info->max_frame_size );
  3167. #ifdef CONFIG_HDLC
  3168. hdlcdev_init(info);
  3169. #endif
  3170. }
  3171. /* Allocate and initialize a device instance structure
  3172. *
  3173. * Return Value: pointer to SLMP_INFO if success, otherwise NULL
  3174. */
  3175. static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
  3176. {
  3177. SLMP_INFO *info;
  3178. info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO),
  3179. GFP_KERNEL);
  3180. if (!info) {
  3181. printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
  3182. __FILE__,__LINE__, adapter_num, port_num);
  3183. } else {
  3184. memset(info, 0, sizeof(SLMP_INFO));
  3185. info->magic = MGSL_MAGIC;
  3186. INIT_WORK(&info->task, bh_handler, info);
  3187. info->max_frame_size = 4096;
  3188. info->close_delay = 5*HZ/10;
  3189. info->closing_wait = 30*HZ;
  3190. init_waitqueue_head(&info->open_wait);
  3191. init_waitqueue_head(&info->close_wait);
  3192. init_waitqueue_head(&info->status_event_wait_q);
  3193. init_waitqueue_head(&info->event_wait_q);
  3194. spin_lock_init(&info->netlock);
  3195. memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
  3196. info->idle_mode = HDLC_TXIDLE_FLAGS;
  3197. info->adapter_num = adapter_num;
  3198. info->port_num = port_num;
  3199. /* Copy configuration info to device instance data */
  3200. info->irq_level = pdev->irq;
  3201. info->phys_lcr_base = pci_resource_start(pdev,0);
  3202. info->phys_sca_base = pci_resource_start(pdev,2);
  3203. info->phys_memory_base = pci_resource_start(pdev,3);
  3204. info->phys_statctrl_base = pci_resource_start(pdev,4);
  3205. /* Because veremap only works on page boundaries we must map
  3206. * a larger area than is actually implemented for the LCR
  3207. * memory range. We map a full page starting at the page boundary.
  3208. */
  3209. info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
  3210. info->phys_lcr_base &= ~(PAGE_SIZE-1);
  3211. info->sca_offset = info->phys_sca_base & (PAGE_SIZE-1);
  3212. info->phys_sca_base &= ~(PAGE_SIZE-1);
  3213. info->statctrl_offset = info->phys_statctrl_base & (PAGE_SIZE-1);
  3214. info->phys_statctrl_base &= ~(PAGE_SIZE-1);
  3215. info->bus_type = MGSL_BUS_TYPE_PCI;
  3216. info->irq_flags = SA_SHIRQ;
  3217. init_timer(&info->tx_timer);
  3218. info->tx_timer.data = (unsigned long)info;
  3219. info->tx_timer.function = tx_timeout;
  3220. init_timer(&info->status_timer);
  3221. info->status_timer.data = (unsigned long)info;
  3222. info->status_timer.function = status_timeout;
  3223. /* Store the PCI9050 misc control register value because a flaw
  3224. * in the PCI9050 prevents LCR registers from being read if
  3225. * BIOS assigns an LCR base address with bit 7 set.
  3226. *
  3227. * Only the misc control register is accessed for which only
  3228. * write access is needed, so set an initial value and change
  3229. * bits to the device instance data as we write the value
  3230. * to the actual misc control register.
  3231. */
  3232. info->misc_ctrl_value = 0x087e4546;
  3233. /* initial port state is unknown - if startup errors
  3234. * occur, init_error will be set to indicate the
  3235. * problem. Once the port is fully initialized,
  3236. * this value will be set to 0 to indicate the
  3237. * port is available.
  3238. */
  3239. info->init_error = -1;
  3240. }
  3241. return info;
  3242. }
  3243. void device_init(int adapter_num, struct pci_dev *pdev)
  3244. {
  3245. SLMP_INFO *port_array[SCA_MAX_PORTS];
  3246. int port;
  3247. /* allocate device instances for up to SCA_MAX_PORTS devices */
  3248. for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
  3249. port_array[port] = alloc_dev(adapter_num,port,pdev);
  3250. if( port_array[port] == NULL ) {
  3251. for ( --port; port >= 0; --port )
  3252. kfree(port_array[port]);
  3253. return;
  3254. }
  3255. }
  3256. /* give copy of port_array to all ports and add to device list */
  3257. for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
  3258. memcpy(port_array[port]->port_array,port_array,sizeof(port_array));
  3259. add_device( port_array[port] );
  3260. spin_lock_init(&port_array[port]->lock);
  3261. }
  3262. /* Allocate and claim adapter resources */
  3263. if ( !claim_resources(port_array[0]) ) {
  3264. alloc_dma_bufs(port_array[0]);
  3265. /* copy resource information from first port to others */
  3266. for ( port = 1; port < SCA_MAX_PORTS; ++port ) {
  3267. port_array[port]->lock = port_array[0]->lock;
  3268. port_array[port]->irq_level = port_array[0]->irq_level;
  3269. port_array[port]->memory_base = port_array[0]->memory_base;
  3270. port_array[port]->sca_base = port_array[0]->sca_base;
  3271. port_array[port]->statctrl_base = port_array[0]->statctrl_base;
  3272. port_array[port]->lcr_base = port_array[0]->lcr_base;
  3273. alloc_dma_bufs(port_array[port]);
  3274. }
  3275. if ( request_irq(port_array[0]->irq_level,
  3276. synclinkmp_interrupt,
  3277. port_array[0]->irq_flags,
  3278. port_array[0]->device_name,
  3279. port_array[0]) < 0 ) {
  3280. printk( "%s(%d):%s Cant request interrupt, IRQ=%d\n",
  3281. __FILE__,__LINE__,
  3282. port_array[0]->device_name,
  3283. port_array[0]->irq_level );
  3284. }
  3285. else {
  3286. port_array[0]->irq_requested = 1;
  3287. adapter_test(port_array[0]);
  3288. }
  3289. }
  3290. }
  3291. static struct tty_operations ops = {
  3292. .open = open,
  3293. .close = close,
  3294. .write = write,
  3295. .put_char = put_char,
  3296. .flush_chars = flush_chars,
  3297. .write_room = write_room,
  3298. .chars_in_buffer = chars_in_buffer,
  3299. .flush_buffer = flush_buffer,
  3300. .ioctl = ioctl,
  3301. .throttle = throttle,
  3302. .unthrottle = unthrottle,
  3303. .send_xchar = send_xchar,
  3304. .break_ctl = set_break,
  3305. .wait_until_sent = wait_until_sent,
  3306. .read_proc = read_proc,
  3307. .set_termios = set_termios,
  3308. .stop = tx_hold,
  3309. .start = tx_release,
  3310. .hangup = hangup,
  3311. .tiocmget = tiocmget,
  3312. .tiocmset = tiocmset,
  3313. };
  3314. static void synclinkmp_cleanup(void)
  3315. {
  3316. int rc;
  3317. SLMP_INFO *info;
  3318. SLMP_INFO *tmp;
  3319. printk("Unloading %s %s\n", driver_name, driver_version);
  3320. if (serial_driver) {
  3321. if ((rc = tty_unregister_driver(serial_driver)))
  3322. printk("%s(%d) failed to unregister tty driver err=%d\n",
  3323. __FILE__,__LINE__,rc);
  3324. put_tty_driver(serial_driver);
  3325. }
  3326. /* reset devices */
  3327. info = synclinkmp_device_list;
  3328. while(info) {
  3329. reset_port(info);
  3330. info = info->next_device;
  3331. }
  3332. /* release devices */
  3333. info = synclinkmp_device_list;
  3334. while(info) {
  3335. #ifdef CONFIG_HDLC
  3336. hdlcdev_exit(info);
  3337. #endif
  3338. free_dma_bufs(info);
  3339. free_tmp_rx_buf(info);
  3340. if ( info->port_num == 0 ) {
  3341. if (info->sca_base)
  3342. write_reg(info, LPR, 1); /* set low power mode */
  3343. release_resources(info);
  3344. }
  3345. tmp = info;
  3346. info = info->next_device;
  3347. kfree(tmp);
  3348. }
  3349. pci_unregister_driver(&synclinkmp_pci_driver);
  3350. }
  3351. /* Driver initialization entry point.
  3352. */
  3353. static int __init synclinkmp_init(void)
  3354. {
  3355. int rc;
  3356. if (break_on_load) {
  3357. synclinkmp_get_text_ptr();
  3358. BREAKPOINT();
  3359. }
  3360. printk("%s %s\n", driver_name, driver_version);
  3361. if ((rc = pci_register_driver(&synclinkmp_pci_driver)) < 0) {
  3362. printk("%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
  3363. return rc;
  3364. }
  3365. serial_driver = alloc_tty_driver(128);
  3366. if (!serial_driver) {
  3367. rc = -ENOMEM;
  3368. goto error;
  3369. }
  3370. /* Initialize the tty_driver structure */
  3371. serial_driver->owner = THIS_MODULE;
  3372. serial_driver->driver_name = "synclinkmp";
  3373. serial_driver->name = "ttySLM";
  3374. serial_driver->major = ttymajor;
  3375. serial_driver->minor_start = 64;
  3376. serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  3377. serial_driver->subtype = SERIAL_TYPE_NORMAL;
  3378. serial_driver->init_termios = tty_std_termios;
  3379. serial_driver->init_termios.c_cflag =
  3380. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  3381. serial_driver->flags = TTY_DRIVER_REAL_RAW;
  3382. tty_set_operations(serial_driver, &ops);
  3383. if ((rc = tty_register_driver(serial_driver)) < 0) {
  3384. printk("%s(%d):Couldn't register serial driver\n",
  3385. __FILE__,__LINE__);
  3386. put_tty_driver(serial_driver);
  3387. serial_driver = NULL;
  3388. goto error;
  3389. }
  3390. printk("%s %s, tty major#%d\n",
  3391. driver_name, driver_version,
  3392. serial_driver->major);
  3393. return 0;
  3394. error:
  3395. synclinkmp_cleanup();
  3396. return rc;
  3397. }
  3398. static void __exit synclinkmp_exit(void)
  3399. {
  3400. synclinkmp_cleanup();
  3401. }
  3402. module_init(synclinkmp_init);
  3403. module_exit(synclinkmp_exit);
  3404. /* Set the port for internal loopback mode.
  3405. * The TxCLK and RxCLK signals are generated from the BRG and
  3406. * the TxD is looped back to the RxD internally.
  3407. */
  3408. void enable_loopback(SLMP_INFO *info, int enable)
  3409. {
  3410. if (enable) {
  3411. /* MD2 (Mode Register 2)
  3412. * 01..00 CNCT<1..0> Channel Connection 11=Local Loopback
  3413. */
  3414. write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) | (BIT1 + BIT0)));
  3415. /* degate external TxC clock source */
  3416. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3417. write_control_reg(info);
  3418. /* RXS/TXS (Rx/Tx clock source)
  3419. * 07 Reserved, must be 0
  3420. * 06..04 Clock Source, 100=BRG
  3421. * 03..00 Clock Divisor, 0000=1
  3422. */
  3423. write_reg(info, RXS, 0x40);
  3424. write_reg(info, TXS, 0x40);
  3425. } else {
  3426. /* MD2 (Mode Register 2)
  3427. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3428. */
  3429. write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) & ~(BIT1 + BIT0)));
  3430. /* RXS/TXS (Rx/Tx clock source)
  3431. * 07 Reserved, must be 0
  3432. * 06..04 Clock Source, 000=RxC/TxC Pin
  3433. * 03..00 Clock Divisor, 0000=1
  3434. */
  3435. write_reg(info, RXS, 0x00);
  3436. write_reg(info, TXS, 0x00);
  3437. }
  3438. /* set LinkSpeed if available, otherwise default to 2Mbps */
  3439. if (info->params.clock_speed)
  3440. set_rate(info, info->params.clock_speed);
  3441. else
  3442. set_rate(info, 3686400);
  3443. }
  3444. /* Set the baud rate register to the desired speed
  3445. *
  3446. * data_rate data rate of clock in bits per second
  3447. * A data rate of 0 disables the AUX clock.
  3448. */
  3449. void set_rate( SLMP_INFO *info, u32 data_rate )
  3450. {
  3451. u32 TMCValue;
  3452. unsigned char BRValue;
  3453. u32 Divisor=0;
  3454. /* fBRG = fCLK/(TMC * 2^BR)
  3455. */
  3456. if (data_rate != 0) {
  3457. Divisor = 14745600/data_rate;
  3458. if (!Divisor)
  3459. Divisor = 1;
  3460. TMCValue = Divisor;
  3461. BRValue = 0;
  3462. if (TMCValue != 1 && TMCValue != 2) {
  3463. /* BRValue of 0 provides 50/50 duty cycle *only* when
  3464. * TMCValue is 1 or 2. BRValue of 1 to 9 always provides
  3465. * 50/50 duty cycle.
  3466. */
  3467. BRValue = 1;
  3468. TMCValue >>= 1;
  3469. }
  3470. /* while TMCValue is too big for TMC register, divide
  3471. * by 2 and increment BR exponent.
  3472. */
  3473. for(; TMCValue > 256 && BRValue < 10; BRValue++)
  3474. TMCValue >>= 1;
  3475. write_reg(info, TXS,
  3476. (unsigned char)((read_reg(info, TXS) & 0xf0) | BRValue));
  3477. write_reg(info, RXS,
  3478. (unsigned char)((read_reg(info, RXS) & 0xf0) | BRValue));
  3479. write_reg(info, TMC, (unsigned char)TMCValue);
  3480. }
  3481. else {
  3482. write_reg(info, TXS,0);
  3483. write_reg(info, RXS,0);
  3484. write_reg(info, TMC, 0);
  3485. }
  3486. }
  3487. /* Disable receiver
  3488. */
  3489. void rx_stop(SLMP_INFO *info)
  3490. {
  3491. if (debug_level >= DEBUG_LEVEL_ISR)
  3492. printk("%s(%d):%s rx_stop()\n",
  3493. __FILE__,__LINE__, info->device_name );
  3494. write_reg(info, CMD, RXRESET);
  3495. info->ie0_value &= ~RXRDYE;
  3496. write_reg(info, IE0, info->ie0_value); /* disable Rx data interrupts */
  3497. write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
  3498. write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
  3499. write_reg(info, RXDMA + DIR, 0); /* disable Rx DMA interrupts */
  3500. info->rx_enabled = 0;
  3501. info->rx_overflow = 0;
  3502. }
  3503. /* enable the receiver
  3504. */
  3505. void rx_start(SLMP_INFO *info)
  3506. {
  3507. int i;
  3508. if (debug_level >= DEBUG_LEVEL_ISR)
  3509. printk("%s(%d):%s rx_start()\n",
  3510. __FILE__,__LINE__, info->device_name );
  3511. write_reg(info, CMD, RXRESET);
  3512. if ( info->params.mode == MGSL_MODE_HDLC ) {
  3513. /* HDLC, disabe IRQ on rxdata */
  3514. info->ie0_value &= ~RXRDYE;
  3515. write_reg(info, IE0, info->ie0_value);
  3516. /* Reset all Rx DMA buffers and program rx dma */
  3517. write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
  3518. write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
  3519. for (i = 0; i < info->rx_buf_count; i++) {
  3520. info->rx_buf_list[i].status = 0xff;
  3521. // throttle to 4 shared memory writes at a time to prevent
  3522. // hogging local bus (keep latency time for DMA requests low).
  3523. if (!(i % 4))
  3524. read_status_reg(info);
  3525. }
  3526. info->current_rx_buf = 0;
  3527. /* set current/1st descriptor address */
  3528. write_reg16(info, RXDMA + CDA,
  3529. info->rx_buf_list_ex[0].phys_entry);
  3530. /* set new last rx descriptor address */
  3531. write_reg16(info, RXDMA + EDA,
  3532. info->rx_buf_list_ex[info->rx_buf_count - 1].phys_entry);
  3533. /* set buffer length (shared by all rx dma data buffers) */
  3534. write_reg16(info, RXDMA + BFL, SCABUFSIZE);
  3535. write_reg(info, RXDMA + DIR, 0x60); /* enable Rx DMA interrupts (EOM/BOF) */
  3536. write_reg(info, RXDMA + DSR, 0xf2); /* clear Rx DMA IRQs, enable Rx DMA */
  3537. } else {
  3538. /* async, enable IRQ on rxdata */
  3539. info->ie0_value |= RXRDYE;
  3540. write_reg(info, IE0, info->ie0_value);
  3541. }
  3542. write_reg(info, CMD, RXENABLE);
  3543. info->rx_overflow = FALSE;
  3544. info->rx_enabled = 1;
  3545. }
  3546. /* Enable the transmitter and send a transmit frame if
  3547. * one is loaded in the DMA buffers.
  3548. */
  3549. void tx_start(SLMP_INFO *info)
  3550. {
  3551. if (debug_level >= DEBUG_LEVEL_ISR)
  3552. printk("%s(%d):%s tx_start() tx_count=%d\n",
  3553. __FILE__,__LINE__, info->device_name,info->tx_count );
  3554. if (!info->tx_enabled ) {
  3555. write_reg(info, CMD, TXRESET);
  3556. write_reg(info, CMD, TXENABLE);
  3557. info->tx_enabled = TRUE;
  3558. }
  3559. if ( info->tx_count ) {
  3560. /* If auto RTS enabled and RTS is inactive, then assert */
  3561. /* RTS and set a flag indicating that the driver should */
  3562. /* negate RTS when the transmission completes. */
  3563. info->drop_rts_on_tx_done = 0;
  3564. if (info->params.mode != MGSL_MODE_ASYNC) {
  3565. if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
  3566. get_signals( info );
  3567. if ( !(info->serial_signals & SerialSignal_RTS) ) {
  3568. info->serial_signals |= SerialSignal_RTS;
  3569. set_signals( info );
  3570. info->drop_rts_on_tx_done = 1;
  3571. }
  3572. }
  3573. write_reg16(info, TRC0,
  3574. (unsigned short)(((tx_negate_fifo_level-1)<<8) + tx_active_fifo_level));
  3575. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  3576. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  3577. /* set TX CDA (current descriptor address) */
  3578. write_reg16(info, TXDMA + CDA,
  3579. info->tx_buf_list_ex[0].phys_entry);
  3580. /* set TX EDA (last descriptor address) */
  3581. write_reg16(info, TXDMA + EDA,
  3582. info->tx_buf_list_ex[info->last_tx_buf].phys_entry);
  3583. /* enable underrun IRQ */
  3584. info->ie1_value &= ~IDLE;
  3585. info->ie1_value |= UDRN;
  3586. write_reg(info, IE1, info->ie1_value);
  3587. write_reg(info, SR1, (unsigned char)(IDLE + UDRN));
  3588. write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
  3589. write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
  3590. info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
  3591. add_timer(&info->tx_timer);
  3592. }
  3593. else {
  3594. tx_load_fifo(info);
  3595. /* async, enable IRQ on txdata */
  3596. info->ie0_value |= TXRDYE;
  3597. write_reg(info, IE0, info->ie0_value);
  3598. }
  3599. info->tx_active = 1;
  3600. }
  3601. }
  3602. /* stop the transmitter and DMA
  3603. */
  3604. void tx_stop( SLMP_INFO *info )
  3605. {
  3606. if (debug_level >= DEBUG_LEVEL_ISR)
  3607. printk("%s(%d):%s tx_stop()\n",
  3608. __FILE__,__LINE__, info->device_name );
  3609. del_timer(&info->tx_timer);
  3610. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  3611. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  3612. write_reg(info, CMD, TXRESET);
  3613. info->ie1_value &= ~(UDRN + IDLE);
  3614. write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
  3615. write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
  3616. info->ie0_value &= ~TXRDYE;
  3617. write_reg(info, IE0, info->ie0_value); /* disable tx data interrupts */
  3618. info->tx_enabled = 0;
  3619. info->tx_active = 0;
  3620. }
  3621. /* Fill the transmit FIFO until the FIFO is full or
  3622. * there is no more data to load.
  3623. */
  3624. void tx_load_fifo(SLMP_INFO *info)
  3625. {
  3626. u8 TwoBytes[2];
  3627. /* do nothing is now tx data available and no XON/XOFF pending */
  3628. if ( !info->tx_count && !info->x_char )
  3629. return;
  3630. /* load the Transmit FIFO until FIFOs full or all data sent */
  3631. while( info->tx_count && (read_reg(info,SR0) & BIT1) ) {
  3632. /* there is more space in the transmit FIFO and */
  3633. /* there is more data in transmit buffer */
  3634. if ( (info->tx_count > 1) && !info->x_char ) {
  3635. /* write 16-bits */
  3636. TwoBytes[0] = info->tx_buf[info->tx_get++];
  3637. if (info->tx_get >= info->max_frame_size)
  3638. info->tx_get -= info->max_frame_size;
  3639. TwoBytes[1] = info->tx_buf[info->tx_get++];
  3640. if (info->tx_get >= info->max_frame_size)
  3641. info->tx_get -= info->max_frame_size;
  3642. write_reg16(info, TRB, *((u16 *)TwoBytes));
  3643. info->tx_count -= 2;
  3644. info->icount.tx += 2;
  3645. } else {
  3646. /* only 1 byte left to transmit or 1 FIFO slot left */
  3647. if (info->x_char) {
  3648. /* transmit pending high priority char */
  3649. write_reg(info, TRB, info->x_char);
  3650. info->x_char = 0;
  3651. } else {
  3652. write_reg(info, TRB, info->tx_buf[info->tx_get++]);
  3653. if (info->tx_get >= info->max_frame_size)
  3654. info->tx_get -= info->max_frame_size;
  3655. info->tx_count--;
  3656. }
  3657. info->icount.tx++;
  3658. }
  3659. }
  3660. }
  3661. /* Reset a port to a known state
  3662. */
  3663. void reset_port(SLMP_INFO *info)
  3664. {
  3665. if (info->sca_base) {
  3666. tx_stop(info);
  3667. rx_stop(info);
  3668. info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  3669. set_signals(info);
  3670. /* disable all port interrupts */
  3671. info->ie0_value = 0;
  3672. info->ie1_value = 0;
  3673. info->ie2_value = 0;
  3674. write_reg(info, IE0, info->ie0_value);
  3675. write_reg(info, IE1, info->ie1_value);
  3676. write_reg(info, IE2, info->ie2_value);
  3677. write_reg(info, CMD, CHRESET);
  3678. }
  3679. }
  3680. /* Reset all the ports to a known state.
  3681. */
  3682. void reset_adapter(SLMP_INFO *info)
  3683. {
  3684. int i;
  3685. for ( i=0; i < SCA_MAX_PORTS; ++i) {
  3686. if (info->port_array[i])
  3687. reset_port(info->port_array[i]);
  3688. }
  3689. }
  3690. /* Program port for asynchronous communications.
  3691. */
  3692. void async_mode(SLMP_INFO *info)
  3693. {
  3694. unsigned char RegValue;
  3695. tx_stop(info);
  3696. rx_stop(info);
  3697. /* MD0, Mode Register 0
  3698. *
  3699. * 07..05 PRCTL<2..0>, Protocol Mode, 000=async
  3700. * 04 AUTO, Auto-enable (RTS/CTS/DCD)
  3701. * 03 Reserved, must be 0
  3702. * 02 CRCCC, CRC Calculation, 0=disabled
  3703. * 01..00 STOP<1..0> Stop bits (00=1,10=2)
  3704. *
  3705. * 0000 0000
  3706. */
  3707. RegValue = 0x00;
  3708. if (info->params.stop_bits != 1)
  3709. RegValue |= BIT1;
  3710. write_reg(info, MD0, RegValue);
  3711. /* MD1, Mode Register 1
  3712. *
  3713. * 07..06 BRATE<1..0>, bit rate, 00=1/1 01=1/16 10=1/32 11=1/64
  3714. * 05..04 TXCHR<1..0>, tx char size, 00=8 bits,01=7,10=6,11=5
  3715. * 03..02 RXCHR<1..0>, rx char size
  3716. * 01..00 PMPM<1..0>, Parity mode, 00=none 10=even 11=odd
  3717. *
  3718. * 0100 0000
  3719. */
  3720. RegValue = 0x40;
  3721. switch (info->params.data_bits) {
  3722. case 7: RegValue |= BIT4 + BIT2; break;
  3723. case 6: RegValue |= BIT5 + BIT3; break;
  3724. case 5: RegValue |= BIT5 + BIT4 + BIT3 + BIT2; break;
  3725. }
  3726. if (info->params.parity != ASYNC_PARITY_NONE) {
  3727. RegValue |= BIT1;
  3728. if (info->params.parity == ASYNC_PARITY_ODD)
  3729. RegValue |= BIT0;
  3730. }
  3731. write_reg(info, MD1, RegValue);
  3732. /* MD2, Mode Register 2
  3733. *
  3734. * 07..02 Reserved, must be 0
  3735. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3736. *
  3737. * 0000 0000
  3738. */
  3739. RegValue = 0x00;
  3740. write_reg(info, MD2, RegValue);
  3741. /* RXS, Receive clock source
  3742. *
  3743. * 07 Reserved, must be 0
  3744. * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
  3745. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3746. */
  3747. RegValue=BIT6;
  3748. write_reg(info, RXS, RegValue);
  3749. /* TXS, Transmit clock source
  3750. *
  3751. * 07 Reserved, must be 0
  3752. * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
  3753. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3754. */
  3755. RegValue=BIT6;
  3756. write_reg(info, TXS, RegValue);
  3757. /* Control Register
  3758. *
  3759. * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
  3760. */
  3761. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3762. write_control_reg(info);
  3763. tx_set_idle(info);
  3764. /* RRC Receive Ready Control 0
  3765. *
  3766. * 07..05 Reserved, must be 0
  3767. * 04..00 RRC<4..0> Rx FIFO trigger active 0x00 = 1 byte
  3768. */
  3769. write_reg(info, RRC, 0x00);
  3770. /* TRC0 Transmit Ready Control 0
  3771. *
  3772. * 07..05 Reserved, must be 0
  3773. * 04..00 TRC<4..0> Tx FIFO trigger active 0x10 = 16 bytes
  3774. */
  3775. write_reg(info, TRC0, 0x10);
  3776. /* TRC1 Transmit Ready Control 1
  3777. *
  3778. * 07..05 Reserved, must be 0
  3779. * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1e = 31 bytes (full-1)
  3780. */
  3781. write_reg(info, TRC1, 0x1e);
  3782. /* CTL, MSCI control register
  3783. *
  3784. * 07..06 Reserved, set to 0
  3785. * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
  3786. * 04 IDLC, idle control, 0=mark 1=idle register
  3787. * 03 BRK, break, 0=off 1 =on (async)
  3788. * 02 SYNCLD, sync char load enable (BSC) 1=enabled
  3789. * 01 GOP, go active on poll (LOOP mode) 1=enabled
  3790. * 00 RTS, RTS output control, 0=active 1=inactive
  3791. *
  3792. * 0001 0001
  3793. */
  3794. RegValue = 0x10;
  3795. if (!(info->serial_signals & SerialSignal_RTS))
  3796. RegValue |= 0x01;
  3797. write_reg(info, CTL, RegValue);
  3798. /* enable status interrupts */
  3799. info->ie0_value |= TXINTE + RXINTE;
  3800. write_reg(info, IE0, info->ie0_value);
  3801. /* enable break detect interrupt */
  3802. info->ie1_value = BRKD;
  3803. write_reg(info, IE1, info->ie1_value);
  3804. /* enable rx overrun interrupt */
  3805. info->ie2_value = OVRN;
  3806. write_reg(info, IE2, info->ie2_value);
  3807. set_rate( info, info->params.data_rate * 16 );
  3808. if (info->params.loopback)
  3809. enable_loopback(info,1);
  3810. }
  3811. /* Program the SCA for HDLC communications.
  3812. */
  3813. void hdlc_mode(SLMP_INFO *info)
  3814. {
  3815. unsigned char RegValue;
  3816. u32 DpllDivisor;
  3817. // Can't use DPLL because SCA outputs recovered clock on RxC when
  3818. // DPLL mode selected. This causes output contention with RxC receiver.
  3819. // Use of DPLL would require external hardware to disable RxC receiver
  3820. // when DPLL mode selected.
  3821. info->params.flags &= ~(HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL);
  3822. /* disable DMA interrupts */
  3823. write_reg(info, TXDMA + DIR, 0);
  3824. write_reg(info, RXDMA + DIR, 0);
  3825. /* MD0, Mode Register 0
  3826. *
  3827. * 07..05 PRCTL<2..0>, Protocol Mode, 100=HDLC
  3828. * 04 AUTO, Auto-enable (RTS/CTS/DCD)
  3829. * 03 Reserved, must be 0
  3830. * 02 CRCCC, CRC Calculation, 1=enabled
  3831. * 01 CRC1, CRC selection, 0=CRC-16,1=CRC-CCITT-16
  3832. * 00 CRC0, CRC initial value, 1 = all 1s
  3833. *
  3834. * 1000 0001
  3835. */
  3836. RegValue = 0x81;
  3837. if (info->params.flags & HDLC_FLAG_AUTO_CTS)
  3838. RegValue |= BIT4;
  3839. if (info->params.flags & HDLC_FLAG_AUTO_DCD)
  3840. RegValue |= BIT4;
  3841. if (info->params.crc_type == HDLC_CRC_16_CCITT)
  3842. RegValue |= BIT2 + BIT1;
  3843. write_reg(info, MD0, RegValue);
  3844. /* MD1, Mode Register 1
  3845. *
  3846. * 07..06 ADDRS<1..0>, Address detect, 00=no addr check
  3847. * 05..04 TXCHR<1..0>, tx char size, 00=8 bits
  3848. * 03..02 RXCHR<1..0>, rx char size, 00=8 bits
  3849. * 01..00 PMPM<1..0>, Parity mode, 00=no parity
  3850. *
  3851. * 0000 0000
  3852. */
  3853. RegValue = 0x00;
  3854. write_reg(info, MD1, RegValue);
  3855. /* MD2, Mode Register 2
  3856. *
  3857. * 07 NRZFM, 0=NRZ, 1=FM
  3858. * 06..05 CODE<1..0> Encoding, 00=NRZ
  3859. * 04..03 DRATE<1..0> DPLL Divisor, 00=8
  3860. * 02 Reserved, must be 0
  3861. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3862. *
  3863. * 0000 0000
  3864. */
  3865. RegValue = 0x00;
  3866. switch(info->params.encoding) {
  3867. case HDLC_ENCODING_NRZI: RegValue |= BIT5; break;
  3868. case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT7 + BIT5; break; /* aka FM1 */
  3869. case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT7 + BIT6; break; /* aka FM0 */
  3870. case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT7; break; /* aka Manchester */
  3871. #if 0
  3872. case HDLC_ENCODING_NRZB: /* not supported */
  3873. case HDLC_ENCODING_NRZI_MARK: /* not supported */
  3874. case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: /* not supported */
  3875. #endif
  3876. }
  3877. if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
  3878. DpllDivisor = 16;
  3879. RegValue |= BIT3;
  3880. } else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
  3881. DpllDivisor = 8;
  3882. } else {
  3883. DpllDivisor = 32;
  3884. RegValue |= BIT4;
  3885. }
  3886. write_reg(info, MD2, RegValue);
  3887. /* RXS, Receive clock source
  3888. *
  3889. * 07 Reserved, must be 0
  3890. * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
  3891. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3892. */
  3893. RegValue=0;
  3894. if (info->params.flags & HDLC_FLAG_RXC_BRG)
  3895. RegValue |= BIT6;
  3896. if (info->params.flags & HDLC_FLAG_RXC_DPLL)
  3897. RegValue |= BIT6 + BIT5;
  3898. write_reg(info, RXS, RegValue);
  3899. /* TXS, Transmit clock source
  3900. *
  3901. * 07 Reserved, must be 0
  3902. * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
  3903. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3904. */
  3905. RegValue=0;
  3906. if (info->params.flags & HDLC_FLAG_TXC_BRG)
  3907. RegValue |= BIT6;
  3908. if (info->params.flags & HDLC_FLAG_TXC_DPLL)
  3909. RegValue |= BIT6 + BIT5;
  3910. write_reg(info, TXS, RegValue);
  3911. if (info->params.flags & HDLC_FLAG_RXC_DPLL)
  3912. set_rate(info, info->params.clock_speed * DpllDivisor);
  3913. else
  3914. set_rate(info, info->params.clock_speed);
  3915. /* GPDATA (General Purpose I/O Data Register)
  3916. *
  3917. * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
  3918. */
  3919. if (info->params.flags & HDLC_FLAG_TXC_BRG)
  3920. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3921. else
  3922. info->port_array[0]->ctrlreg_value &= ~(BIT0 << (info->port_num * 2));
  3923. write_control_reg(info);
  3924. /* RRC Receive Ready Control 0
  3925. *
  3926. * 07..05 Reserved, must be 0
  3927. * 04..00 RRC<4..0> Rx FIFO trigger active
  3928. */
  3929. write_reg(info, RRC, rx_active_fifo_level);
  3930. /* TRC0 Transmit Ready Control 0
  3931. *
  3932. * 07..05 Reserved, must be 0
  3933. * 04..00 TRC<4..0> Tx FIFO trigger active
  3934. */
  3935. write_reg(info, TRC0, tx_active_fifo_level);
  3936. /* TRC1 Transmit Ready Control 1
  3937. *
  3938. * 07..05 Reserved, must be 0
  3939. * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1f = 32 bytes (full)
  3940. */
  3941. write_reg(info, TRC1, (unsigned char)(tx_negate_fifo_level - 1));
  3942. /* DMR, DMA Mode Register
  3943. *
  3944. * 07..05 Reserved, must be 0
  3945. * 04 TMOD, Transfer Mode: 1=chained-block
  3946. * 03 Reserved, must be 0
  3947. * 02 NF, Number of Frames: 1=multi-frame
  3948. * 01 CNTE, Frame End IRQ Counter enable: 0=disabled
  3949. * 00 Reserved, must be 0
  3950. *
  3951. * 0001 0100
  3952. */
  3953. write_reg(info, TXDMA + DMR, 0x14);
  3954. write_reg(info, RXDMA + DMR, 0x14);
  3955. /* Set chain pointer base (upper 8 bits of 24 bit addr) */
  3956. write_reg(info, RXDMA + CPB,
  3957. (unsigned char)(info->buffer_list_phys >> 16));
  3958. /* Set chain pointer base (upper 8 bits of 24 bit addr) */
  3959. write_reg(info, TXDMA + CPB,
  3960. (unsigned char)(info->buffer_list_phys >> 16));
  3961. /* enable status interrupts. other code enables/disables
  3962. * the individual sources for these two interrupt classes.
  3963. */
  3964. info->ie0_value |= TXINTE + RXINTE;
  3965. write_reg(info, IE0, info->ie0_value);
  3966. /* CTL, MSCI control register
  3967. *
  3968. * 07..06 Reserved, set to 0
  3969. * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
  3970. * 04 IDLC, idle control, 0=mark 1=idle register
  3971. * 03 BRK, break, 0=off 1 =on (async)
  3972. * 02 SYNCLD, sync char load enable (BSC) 1=enabled
  3973. * 01 GOP, go active on poll (LOOP mode) 1=enabled
  3974. * 00 RTS, RTS output control, 0=active 1=inactive
  3975. *
  3976. * 0001 0001
  3977. */
  3978. RegValue = 0x10;
  3979. if (!(info->serial_signals & SerialSignal_RTS))
  3980. RegValue |= 0x01;
  3981. write_reg(info, CTL, RegValue);
  3982. /* preamble not supported ! */
  3983. tx_set_idle(info);
  3984. tx_stop(info);
  3985. rx_stop(info);
  3986. set_rate(info, info->params.clock_speed);
  3987. if (info->params.loopback)
  3988. enable_loopback(info,1);
  3989. }
  3990. /* Set the transmit HDLC idle mode
  3991. */
  3992. void tx_set_idle(SLMP_INFO *info)
  3993. {
  3994. unsigned char RegValue = 0xff;
  3995. /* Map API idle mode to SCA register bits */
  3996. switch(info->idle_mode) {
  3997. case HDLC_TXIDLE_FLAGS: RegValue = 0x7e; break;
  3998. case HDLC_TXIDLE_ALT_ZEROS_ONES: RegValue = 0xaa; break;
  3999. case HDLC_TXIDLE_ZEROS: RegValue = 0x00; break;
  4000. case HDLC_TXIDLE_ONES: RegValue = 0xff; break;
  4001. case HDLC_TXIDLE_ALT_MARK_SPACE: RegValue = 0xaa; break;
  4002. case HDLC_TXIDLE_SPACE: RegValue = 0x00; break;
  4003. case HDLC_TXIDLE_MARK: RegValue = 0xff; break;
  4004. }
  4005. write_reg(info, IDL, RegValue);
  4006. }
  4007. /* Query the adapter for the state of the V24 status (input) signals.
  4008. */
  4009. void get_signals(SLMP_INFO *info)
  4010. {
  4011. u16 status = read_reg(info, SR3);
  4012. u16 gpstatus = read_status_reg(info);
  4013. u16 testbit;
  4014. /* clear all serial signals except DTR and RTS */
  4015. info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
  4016. /* set serial signal bits to reflect MISR */
  4017. if (!(status & BIT3))
  4018. info->serial_signals |= SerialSignal_CTS;
  4019. if ( !(status & BIT2))
  4020. info->serial_signals |= SerialSignal_DCD;
  4021. testbit = BIT1 << (info->port_num * 2); // Port 0..3 RI is GPDATA<1,3,5,7>
  4022. if (!(gpstatus & testbit))
  4023. info->serial_signals |= SerialSignal_RI;
  4024. testbit = BIT0 << (info->port_num * 2); // Port 0..3 DSR is GPDATA<0,2,4,6>
  4025. if (!(gpstatus & testbit))
  4026. info->serial_signals |= SerialSignal_DSR;
  4027. }
  4028. /* Set the state of DTR and RTS based on contents of
  4029. * serial_signals member of device context.
  4030. */
  4031. void set_signals(SLMP_INFO *info)
  4032. {
  4033. unsigned char RegValue;
  4034. u16 EnableBit;
  4035. RegValue = read_reg(info, CTL);
  4036. if (info->serial_signals & SerialSignal_RTS)
  4037. RegValue &= ~BIT0;
  4038. else
  4039. RegValue |= BIT0;
  4040. write_reg(info, CTL, RegValue);
  4041. // Port 0..3 DTR is ctrl reg <1,3,5,7>
  4042. EnableBit = BIT1 << (info->port_num*2);
  4043. if (info->serial_signals & SerialSignal_DTR)
  4044. info->port_array[0]->ctrlreg_value &= ~EnableBit;
  4045. else
  4046. info->port_array[0]->ctrlreg_value |= EnableBit;
  4047. write_control_reg(info);
  4048. }
  4049. /*******************/
  4050. /* DMA Buffer Code */
  4051. /*******************/
  4052. /* Set the count for all receive buffers to SCABUFSIZE
  4053. * and set the current buffer to the first buffer. This effectively
  4054. * makes all buffers free and discards any data in buffers.
  4055. */
  4056. void rx_reset_buffers(SLMP_INFO *info)
  4057. {
  4058. rx_free_frame_buffers(info, 0, info->rx_buf_count - 1);
  4059. }
  4060. /* Free the buffers used by a received frame
  4061. *
  4062. * info pointer to device instance data
  4063. * first index of 1st receive buffer of frame
  4064. * last index of last receive buffer of frame
  4065. */
  4066. void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last)
  4067. {
  4068. int done = 0;
  4069. while(!done) {
  4070. /* reset current buffer for reuse */
  4071. info->rx_buf_list[first].status = 0xff;
  4072. if (first == last) {
  4073. done = 1;
  4074. /* set new last rx descriptor address */
  4075. write_reg16(info, RXDMA + EDA, info->rx_buf_list_ex[first].phys_entry);
  4076. }
  4077. first++;
  4078. if (first == info->rx_buf_count)
  4079. first = 0;
  4080. }
  4081. /* set current buffer to next buffer after last buffer of frame */
  4082. info->current_rx_buf = first;
  4083. }
  4084. /* Return a received frame from the receive DMA buffers.
  4085. * Only frames received without errors are returned.
  4086. *
  4087. * Return Value: 1 if frame returned, otherwise 0
  4088. */
  4089. int rx_get_frame(SLMP_INFO *info)
  4090. {
  4091. unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
  4092. unsigned short status;
  4093. unsigned int framesize = 0;
  4094. int ReturnCode = 0;
  4095. unsigned long flags;
  4096. struct tty_struct *tty = info->tty;
  4097. unsigned char addr_field = 0xff;
  4098. SCADESC *desc;
  4099. SCADESC_EX *desc_ex;
  4100. CheckAgain:
  4101. /* assume no frame returned, set zero length */
  4102. framesize = 0;
  4103. addr_field = 0xff;
  4104. /*
  4105. * current_rx_buf points to the 1st buffer of the next available
  4106. * receive frame. To find the last buffer of the frame look for
  4107. * a non-zero status field in the buffer entries. (The status
  4108. * field is set by the 16C32 after completing a receive frame.
  4109. */
  4110. StartIndex = EndIndex = info->current_rx_buf;
  4111. for ( ;; ) {
  4112. desc = &info->rx_buf_list[EndIndex];
  4113. desc_ex = &info->rx_buf_list_ex[EndIndex];
  4114. if (desc->status == 0xff)
  4115. goto Cleanup; /* current desc still in use, no frames available */
  4116. if (framesize == 0 && info->params.addr_filter != 0xff)
  4117. addr_field = desc_ex->virt_addr[0];
  4118. framesize += desc->length;
  4119. /* Status != 0 means last buffer of frame */
  4120. if (desc->status)
  4121. break;
  4122. EndIndex++;
  4123. if (EndIndex == info->rx_buf_count)
  4124. EndIndex = 0;
  4125. if (EndIndex == info->current_rx_buf) {
  4126. /* all buffers have been 'used' but none mark */
  4127. /* the end of a frame. Reset buffers and receiver. */
  4128. if ( info->rx_enabled ){
  4129. spin_lock_irqsave(&info->lock,flags);
  4130. rx_start(info);
  4131. spin_unlock_irqrestore(&info->lock,flags);
  4132. }
  4133. goto Cleanup;
  4134. }
  4135. }
  4136. /* check status of receive frame */
  4137. /* frame status is byte stored after frame data
  4138. *
  4139. * 7 EOM (end of msg), 1 = last buffer of frame
  4140. * 6 Short Frame, 1 = short frame
  4141. * 5 Abort, 1 = frame aborted
  4142. * 4 Residue, 1 = last byte is partial
  4143. * 3 Overrun, 1 = overrun occurred during frame reception
  4144. * 2 CRC, 1 = CRC error detected
  4145. *
  4146. */
  4147. status = desc->status;
  4148. /* ignore CRC bit if not using CRC (bit is undefined) */
  4149. /* Note:CRC is not save to data buffer */
  4150. if (info->params.crc_type == HDLC_CRC_NONE)
  4151. status &= ~BIT2;
  4152. if (framesize == 0 ||
  4153. (addr_field != 0xff && addr_field != info->params.addr_filter)) {
  4154. /* discard 0 byte frames, this seems to occur sometime
  4155. * when remote is idling flags.
  4156. */
  4157. rx_free_frame_buffers(info, StartIndex, EndIndex);
  4158. goto CheckAgain;
  4159. }
  4160. if (framesize < 2)
  4161. status |= BIT6;
  4162. if (status & (BIT6+BIT5+BIT3+BIT2)) {
  4163. /* received frame has errors,
  4164. * update counts and mark frame size as 0
  4165. */
  4166. if (status & BIT6)
  4167. info->icount.rxshort++;
  4168. else if (status & BIT5)
  4169. info->icount.rxabort++;
  4170. else if (status & BIT3)
  4171. info->icount.rxover++;
  4172. else
  4173. info->icount.rxcrc++;
  4174. framesize = 0;
  4175. #ifdef CONFIG_HDLC
  4176. {
  4177. struct net_device_stats *stats = hdlc_stats(info->netdev);
  4178. stats->rx_errors++;
  4179. stats->rx_frame_errors++;
  4180. }
  4181. #endif
  4182. }
  4183. if ( debug_level >= DEBUG_LEVEL_BH )
  4184. printk("%s(%d):%s rx_get_frame() status=%04X size=%d\n",
  4185. __FILE__,__LINE__,info->device_name,status,framesize);
  4186. if ( debug_level >= DEBUG_LEVEL_DATA )
  4187. trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
  4188. min_t(int, framesize,SCABUFSIZE),0);
  4189. if (framesize) {
  4190. if (framesize > info->max_frame_size)
  4191. info->icount.rxlong++;
  4192. else {
  4193. /* copy dma buffer(s) to contiguous intermediate buffer */
  4194. int copy_count = framesize;
  4195. int index = StartIndex;
  4196. unsigned char *ptmp = info->tmp_rx_buf;
  4197. info->tmp_rx_buf_count = framesize;
  4198. info->icount.rxok++;
  4199. while(copy_count) {
  4200. int partial_count = min(copy_count,SCABUFSIZE);
  4201. memcpy( ptmp,
  4202. info->rx_buf_list_ex[index].virt_addr,
  4203. partial_count );
  4204. ptmp += partial_count;
  4205. copy_count -= partial_count;
  4206. if ( ++index == info->rx_buf_count )
  4207. index = 0;
  4208. }
  4209. #ifdef CONFIG_HDLC
  4210. if (info->netcount)
  4211. hdlcdev_rx(info,info->tmp_rx_buf,framesize);
  4212. else
  4213. #endif
  4214. ldisc_receive_buf(tty,info->tmp_rx_buf,
  4215. info->flag_buf, framesize);
  4216. }
  4217. }
  4218. /* Free the buffers used by this frame. */
  4219. rx_free_frame_buffers( info, StartIndex, EndIndex );
  4220. ReturnCode = 1;
  4221. Cleanup:
  4222. if ( info->rx_enabled && info->rx_overflow ) {
  4223. /* Receiver is enabled, but needs to restarted due to
  4224. * rx buffer overflow. If buffers are empty, restart receiver.
  4225. */
  4226. if (info->rx_buf_list[EndIndex].status == 0xff) {
  4227. spin_lock_irqsave(&info->lock,flags);
  4228. rx_start(info);
  4229. spin_unlock_irqrestore(&info->lock,flags);
  4230. }
  4231. }
  4232. return ReturnCode;
  4233. }
  4234. /* load the transmit DMA buffer with data
  4235. */
  4236. void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count)
  4237. {
  4238. unsigned short copy_count;
  4239. unsigned int i = 0;
  4240. SCADESC *desc;
  4241. SCADESC_EX *desc_ex;
  4242. if ( debug_level >= DEBUG_LEVEL_DATA )
  4243. trace_block(info,buf, min_t(int, count,SCABUFSIZE), 1);
  4244. /* Copy source buffer to one or more DMA buffers, starting with
  4245. * the first transmit dma buffer.
  4246. */
  4247. for(i=0;;)
  4248. {
  4249. copy_count = min_t(unsigned short,count,SCABUFSIZE);
  4250. desc = &info->tx_buf_list[i];
  4251. desc_ex = &info->tx_buf_list_ex[i];
  4252. load_pci_memory(info, desc_ex->virt_addr,buf,copy_count);
  4253. desc->length = copy_count;
  4254. desc->status = 0;
  4255. buf += copy_count;
  4256. count -= copy_count;
  4257. if (!count)
  4258. break;
  4259. i++;
  4260. if (i >= info->tx_buf_count)
  4261. i = 0;
  4262. }
  4263. info->tx_buf_list[i].status = 0x81; /* set EOM and EOT status */
  4264. info->last_tx_buf = ++i;
  4265. }
  4266. int register_test(SLMP_INFO *info)
  4267. {
  4268. static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
  4269. static unsigned int count = sizeof(testval)/sizeof(unsigned char);
  4270. unsigned int i;
  4271. int rc = TRUE;
  4272. unsigned long flags;
  4273. spin_lock_irqsave(&info->lock,flags);
  4274. reset_port(info);
  4275. /* assume failure */
  4276. info->init_error = DiagStatus_AddressFailure;
  4277. /* Write bit patterns to various registers but do it out of */
  4278. /* sync, then read back and verify values. */
  4279. for (i = 0 ; i < count ; i++) {
  4280. write_reg(info, TMC, testval[i]);
  4281. write_reg(info, IDL, testval[(i+1)%count]);
  4282. write_reg(info, SA0, testval[(i+2)%count]);
  4283. write_reg(info, SA1, testval[(i+3)%count]);
  4284. if ( (read_reg(info, TMC) != testval[i]) ||
  4285. (read_reg(info, IDL) != testval[(i+1)%count]) ||
  4286. (read_reg(info, SA0) != testval[(i+2)%count]) ||
  4287. (read_reg(info, SA1) != testval[(i+3)%count]) )
  4288. {
  4289. rc = FALSE;
  4290. break;
  4291. }
  4292. }
  4293. reset_port(info);
  4294. spin_unlock_irqrestore(&info->lock,flags);
  4295. return rc;
  4296. }
  4297. int irq_test(SLMP_INFO *info)
  4298. {
  4299. unsigned long timeout;
  4300. unsigned long flags;
  4301. unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
  4302. spin_lock_irqsave(&info->lock,flags);
  4303. reset_port(info);
  4304. /* assume failure */
  4305. info->init_error = DiagStatus_IrqFailure;
  4306. info->irq_occurred = FALSE;
  4307. /* setup timer0 on SCA0 to interrupt */
  4308. /* IER2<7..4> = timer<3..0> interrupt enables (1=enabled) */
  4309. write_reg(info, IER2, (unsigned char)((info->port_num & 1) ? BIT6 : BIT4));
  4310. write_reg(info, (unsigned char)(timer + TEPR), 0); /* timer expand prescale */
  4311. write_reg16(info, (unsigned char)(timer + TCONR), 1); /* timer constant */
  4312. /* TMCS, Timer Control/Status Register
  4313. *
  4314. * 07 CMF, Compare match flag (read only) 1=match
  4315. * 06 ECMI, CMF Interrupt Enable: 1=enabled
  4316. * 05 Reserved, must be 0
  4317. * 04 TME, Timer Enable
  4318. * 03..00 Reserved, must be 0
  4319. *
  4320. * 0101 0000
  4321. */
  4322. write_reg(info, (unsigned char)(timer + TMCS), 0x50);
  4323. spin_unlock_irqrestore(&info->lock,flags);
  4324. timeout=100;
  4325. while( timeout-- && !info->irq_occurred ) {
  4326. msleep_interruptible(10);
  4327. }
  4328. spin_lock_irqsave(&info->lock,flags);
  4329. reset_port(info);
  4330. spin_unlock_irqrestore(&info->lock,flags);
  4331. return info->irq_occurred;
  4332. }
  4333. /* initialize individual SCA device (2 ports)
  4334. */
  4335. static int sca_init(SLMP_INFO *info)
  4336. {
  4337. /* set wait controller to single mem partition (low), no wait states */
  4338. write_reg(info, PABR0, 0); /* wait controller addr boundary 0 */
  4339. write_reg(info, PABR1, 0); /* wait controller addr boundary 1 */
  4340. write_reg(info, WCRL, 0); /* wait controller low range */
  4341. write_reg(info, WCRM, 0); /* wait controller mid range */
  4342. write_reg(info, WCRH, 0); /* wait controller high range */
  4343. /* DPCR, DMA Priority Control
  4344. *
  4345. * 07..05 Not used, must be 0
  4346. * 04 BRC, bus release condition: 0=all transfers complete
  4347. * 03 CCC, channel change condition: 0=every cycle
  4348. * 02..00 PR<2..0>, priority 100=round robin
  4349. *
  4350. * 00000100 = 0x04
  4351. */
  4352. write_reg(info, DPCR, dma_priority);
  4353. /* DMA Master Enable, BIT7: 1=enable all channels */
  4354. write_reg(info, DMER, 0x80);
  4355. /* enable all interrupt classes */
  4356. write_reg(info, IER0, 0xff); /* TxRDY,RxRDY,TxINT,RxINT (ports 0-1) */
  4357. write_reg(info, IER1, 0xff); /* DMIB,DMIA (channels 0-3) */
  4358. write_reg(info, IER2, 0xf0); /* TIRQ (timers 0-3) */
  4359. /* ITCR, interrupt control register
  4360. * 07 IPC, interrupt priority, 0=MSCI->DMA
  4361. * 06..05 IAK<1..0>, Acknowledge cycle, 00=non-ack cycle
  4362. * 04 VOS, Vector Output, 0=unmodified vector
  4363. * 03..00 Reserved, must be 0
  4364. */
  4365. write_reg(info, ITCR, 0);
  4366. return TRUE;
  4367. }
  4368. /* initialize adapter hardware
  4369. */
  4370. int init_adapter(SLMP_INFO *info)
  4371. {
  4372. int i;
  4373. /* Set BIT30 of Local Control Reg 0x50 to reset SCA */
  4374. volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
  4375. u32 readval;
  4376. info->misc_ctrl_value |= BIT30;
  4377. *MiscCtrl = info->misc_ctrl_value;
  4378. /*
  4379. * Force at least 170ns delay before clearing
  4380. * reset bit. Each read from LCR takes at least
  4381. * 30ns so 10 times for 300ns to be safe.
  4382. */
  4383. for(i=0;i<10;i++)
  4384. readval = *MiscCtrl;
  4385. info->misc_ctrl_value &= ~BIT30;
  4386. *MiscCtrl = info->misc_ctrl_value;
  4387. /* init control reg (all DTRs off, all clksel=input) */
  4388. info->ctrlreg_value = 0xaa;
  4389. write_control_reg(info);
  4390. {
  4391. volatile u32 *LCR1BRDR = (u32 *)(info->lcr_base + 0x2c);
  4392. lcr1_brdr_value &= ~(BIT5 + BIT4 + BIT3);
  4393. switch(read_ahead_count)
  4394. {
  4395. case 16:
  4396. lcr1_brdr_value |= BIT5 + BIT4 + BIT3;
  4397. break;
  4398. case 8:
  4399. lcr1_brdr_value |= BIT5 + BIT4;
  4400. break;
  4401. case 4:
  4402. lcr1_brdr_value |= BIT5 + BIT3;
  4403. break;
  4404. case 0:
  4405. lcr1_brdr_value |= BIT5;
  4406. break;
  4407. }
  4408. *LCR1BRDR = lcr1_brdr_value;
  4409. *MiscCtrl = misc_ctrl_value;
  4410. }
  4411. sca_init(info->port_array[0]);
  4412. sca_init(info->port_array[2]);
  4413. return TRUE;
  4414. }
  4415. /* Loopback an HDLC frame to test the hardware
  4416. * interrupt and DMA functions.
  4417. */
  4418. int loopback_test(SLMP_INFO *info)
  4419. {
  4420. #define TESTFRAMESIZE 20
  4421. unsigned long timeout;
  4422. u16 count = TESTFRAMESIZE;
  4423. unsigned char buf[TESTFRAMESIZE];
  4424. int rc = FALSE;
  4425. unsigned long flags;
  4426. struct tty_struct *oldtty = info->tty;
  4427. u32 speed = info->params.clock_speed;
  4428. info->params.clock_speed = 3686400;
  4429. info->tty = NULL;
  4430. /* assume failure */
  4431. info->init_error = DiagStatus_DmaFailure;
  4432. /* build and send transmit frame */
  4433. for (count = 0; count < TESTFRAMESIZE;++count)
  4434. buf[count] = (unsigned char)count;
  4435. memset(info->tmp_rx_buf,0,TESTFRAMESIZE);
  4436. /* program hardware for HDLC and enabled receiver */
  4437. spin_lock_irqsave(&info->lock,flags);
  4438. hdlc_mode(info);
  4439. enable_loopback(info,1);
  4440. rx_start(info);
  4441. info->tx_count = count;
  4442. tx_load_dma_buffer(info,buf,count);
  4443. tx_start(info);
  4444. spin_unlock_irqrestore(&info->lock,flags);
  4445. /* wait for receive complete */
  4446. /* Set a timeout for waiting for interrupt. */
  4447. for ( timeout = 100; timeout; --timeout ) {
  4448. msleep_interruptible(10);
  4449. if (rx_get_frame(info)) {
  4450. rc = TRUE;
  4451. break;
  4452. }
  4453. }
  4454. /* verify received frame length and contents */
  4455. if (rc == TRUE &&
  4456. ( info->tmp_rx_buf_count != count ||
  4457. memcmp(buf, info->tmp_rx_buf,count))) {
  4458. rc = FALSE;
  4459. }
  4460. spin_lock_irqsave(&info->lock,flags);
  4461. reset_adapter(info);
  4462. spin_unlock_irqrestore(&info->lock,flags);
  4463. info->params.clock_speed = speed;
  4464. info->tty = oldtty;
  4465. return rc;
  4466. }
  4467. /* Perform diagnostics on hardware
  4468. */
  4469. int adapter_test( SLMP_INFO *info )
  4470. {
  4471. unsigned long flags;
  4472. if ( debug_level >= DEBUG_LEVEL_INFO )
  4473. printk( "%s(%d):Testing device %s\n",
  4474. __FILE__,__LINE__,info->device_name );
  4475. spin_lock_irqsave(&info->lock,flags);
  4476. init_adapter(info);
  4477. spin_unlock_irqrestore(&info->lock,flags);
  4478. info->port_array[0]->port_count = 0;
  4479. if ( register_test(info->port_array[0]) &&
  4480. register_test(info->port_array[1])) {
  4481. info->port_array[0]->port_count = 2;
  4482. if ( register_test(info->port_array[2]) &&
  4483. register_test(info->port_array[3]) )
  4484. info->port_array[0]->port_count += 2;
  4485. }
  4486. else {
  4487. printk( "%s(%d):Register test failure for device %s Addr=%08lX\n",
  4488. __FILE__,__LINE__,info->device_name, (unsigned long)(info->phys_sca_base));
  4489. return -ENODEV;
  4490. }
  4491. if ( !irq_test(info->port_array[0]) ||
  4492. !irq_test(info->port_array[1]) ||
  4493. (info->port_count == 4 && !irq_test(info->port_array[2])) ||
  4494. (info->port_count == 4 && !irq_test(info->port_array[3]))) {
  4495. printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
  4496. __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
  4497. return -ENODEV;
  4498. }
  4499. if (!loopback_test(info->port_array[0]) ||
  4500. !loopback_test(info->port_array[1]) ||
  4501. (info->port_count == 4 && !loopback_test(info->port_array[2])) ||
  4502. (info->port_count == 4 && !loopback_test(info->port_array[3]))) {
  4503. printk( "%s(%d):DMA test failure for device %s\n",
  4504. __FILE__,__LINE__,info->device_name);
  4505. return -ENODEV;
  4506. }
  4507. if ( debug_level >= DEBUG_LEVEL_INFO )
  4508. printk( "%s(%d):device %s passed diagnostics\n",
  4509. __FILE__,__LINE__,info->device_name );
  4510. info->port_array[0]->init_error = 0;
  4511. info->port_array[1]->init_error = 0;
  4512. if ( info->port_count > 2 ) {
  4513. info->port_array[2]->init_error = 0;
  4514. info->port_array[3]->init_error = 0;
  4515. }
  4516. return 0;
  4517. }
  4518. /* Test the shared memory on a PCI adapter.
  4519. */
  4520. int memory_test(SLMP_INFO *info)
  4521. {
  4522. static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
  4523. 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
  4524. unsigned long count = sizeof(testval)/sizeof(unsigned long);
  4525. unsigned long i;
  4526. unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
  4527. unsigned long * addr = (unsigned long *)info->memory_base;
  4528. /* Test data lines with test pattern at one location. */
  4529. for ( i = 0 ; i < count ; i++ ) {
  4530. *addr = testval[i];
  4531. if ( *addr != testval[i] )
  4532. return FALSE;
  4533. }
  4534. /* Test address lines with incrementing pattern over */
  4535. /* entire address range. */
  4536. for ( i = 0 ; i < limit ; i++ ) {
  4537. *addr = i * 4;
  4538. addr++;
  4539. }
  4540. addr = (unsigned long *)info->memory_base;
  4541. for ( i = 0 ; i < limit ; i++ ) {
  4542. if ( *addr != i * 4 )
  4543. return FALSE;
  4544. addr++;
  4545. }
  4546. memset( info->memory_base, 0, SCA_MEM_SIZE );
  4547. return TRUE;
  4548. }
  4549. /* Load data into PCI adapter shared memory.
  4550. *
  4551. * The PCI9050 releases control of the local bus
  4552. * after completing the current read or write operation.
  4553. *
  4554. * While the PCI9050 write FIFO not empty, the
  4555. * PCI9050 treats all of the writes as a single transaction
  4556. * and does not release the bus. This causes DMA latency problems
  4557. * at high speeds when copying large data blocks to the shared memory.
  4558. *
  4559. * This function breaks a write into multiple transations by
  4560. * interleaving a read which flushes the write FIFO and 'completes'
  4561. * the write transation. This allows any pending DMA request to gain control
  4562. * of the local bus in a timely fasion.
  4563. */
  4564. void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count)
  4565. {
  4566. /* A load interval of 16 allows for 4 32-bit writes at */
  4567. /* 136ns each for a maximum latency of 542ns on the local bus.*/
  4568. unsigned short interval = count / sca_pci_load_interval;
  4569. unsigned short i;
  4570. for ( i = 0 ; i < interval ; i++ )
  4571. {
  4572. memcpy(dest, src, sca_pci_load_interval);
  4573. read_status_reg(info);
  4574. dest += sca_pci_load_interval;
  4575. src += sca_pci_load_interval;
  4576. }
  4577. memcpy(dest, src, count % sca_pci_load_interval);
  4578. }
  4579. void trace_block(SLMP_INFO *info,const char* data, int count, int xmit)
  4580. {
  4581. int i;
  4582. int linecount;
  4583. if (xmit)
  4584. printk("%s tx data:\n",info->device_name);
  4585. else
  4586. printk("%s rx data:\n",info->device_name);
  4587. while(count) {
  4588. if (count > 16)
  4589. linecount = 16;
  4590. else
  4591. linecount = count;
  4592. for(i=0;i<linecount;i++)
  4593. printk("%02X ",(unsigned char)data[i]);
  4594. for(;i<17;i++)
  4595. printk(" ");
  4596. for(i=0;i<linecount;i++) {
  4597. if (data[i]>=040 && data[i]<=0176)
  4598. printk("%c",data[i]);
  4599. else
  4600. printk(".");
  4601. }
  4602. printk("\n");
  4603. data += linecount;
  4604. count -= linecount;
  4605. }
  4606. } /* end of trace_block() */
  4607. /* called when HDLC frame times out
  4608. * update stats and do tx completion processing
  4609. */
  4610. void tx_timeout(unsigned long context)
  4611. {
  4612. SLMP_INFO *info = (SLMP_INFO*)context;
  4613. unsigned long flags;
  4614. if ( debug_level >= DEBUG_LEVEL_INFO )
  4615. printk( "%s(%d):%s tx_timeout()\n",
  4616. __FILE__,__LINE__,info->device_name);
  4617. if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
  4618. info->icount.txtimeout++;
  4619. }
  4620. spin_lock_irqsave(&info->lock,flags);
  4621. info->tx_active = 0;
  4622. info->tx_count = info->tx_put = info->tx_get = 0;
  4623. spin_unlock_irqrestore(&info->lock,flags);
  4624. #ifdef CONFIG_HDLC
  4625. if (info->netcount)
  4626. hdlcdev_tx_done(info);
  4627. else
  4628. #endif
  4629. bh_transmit(info);
  4630. }
  4631. /* called to periodically check the DSR/RI modem signal input status
  4632. */
  4633. void status_timeout(unsigned long context)
  4634. {
  4635. u16 status = 0;
  4636. SLMP_INFO *info = (SLMP_INFO*)context;
  4637. unsigned long flags;
  4638. unsigned char delta;
  4639. spin_lock_irqsave(&info->lock,flags);
  4640. get_signals(info);
  4641. spin_unlock_irqrestore(&info->lock,flags);
  4642. /* check for DSR/RI state change */
  4643. delta = info->old_signals ^ info->serial_signals;
  4644. info->old_signals = info->serial_signals;
  4645. if (delta & SerialSignal_DSR)
  4646. status |= MISCSTATUS_DSR_LATCHED|(info->serial_signals&SerialSignal_DSR);
  4647. if (delta & SerialSignal_RI)
  4648. status |= MISCSTATUS_RI_LATCHED|(info->serial_signals&SerialSignal_RI);
  4649. if (delta & SerialSignal_DCD)
  4650. status |= MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD);
  4651. if (delta & SerialSignal_CTS)
  4652. status |= MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS);
  4653. if (status)
  4654. isr_io_pin(info,status);
  4655. info->status_timer.data = (unsigned long)info;
  4656. info->status_timer.function = status_timeout;
  4657. info->status_timer.expires = jiffies + msecs_to_jiffies(10);
  4658. add_timer(&info->status_timer);
  4659. }
  4660. /* Register Access Routines -
  4661. * All registers are memory mapped
  4662. */
  4663. #define CALC_REGADDR() \
  4664. unsigned char * RegAddr = (unsigned char*)(info->sca_base + Addr); \
  4665. if (info->port_num > 1) \
  4666. RegAddr += 256; /* port 0-1 SCA0, 2-3 SCA1 */ \
  4667. if ( info->port_num & 1) { \
  4668. if (Addr > 0x7f) \
  4669. RegAddr += 0x40; /* DMA access */ \
  4670. else if (Addr > 0x1f && Addr < 0x60) \
  4671. RegAddr += 0x20; /* MSCI access */ \
  4672. }
  4673. unsigned char read_reg(SLMP_INFO * info, unsigned char Addr)
  4674. {
  4675. CALC_REGADDR();
  4676. return *RegAddr;
  4677. }
  4678. void write_reg(SLMP_INFO * info, unsigned char Addr, unsigned char Value)
  4679. {
  4680. CALC_REGADDR();
  4681. *RegAddr = Value;
  4682. }
  4683. u16 read_reg16(SLMP_INFO * info, unsigned char Addr)
  4684. {
  4685. CALC_REGADDR();
  4686. return *((u16 *)RegAddr);
  4687. }
  4688. void write_reg16(SLMP_INFO * info, unsigned char Addr, u16 Value)
  4689. {
  4690. CALC_REGADDR();
  4691. *((u16 *)RegAddr) = Value;
  4692. }
  4693. unsigned char read_status_reg(SLMP_INFO * info)
  4694. {
  4695. unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
  4696. return *RegAddr;
  4697. }
  4698. void write_control_reg(SLMP_INFO * info)
  4699. {
  4700. unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
  4701. *RegAddr = info->port_array[0]->ctrlreg_value;
  4702. }
  4703. static int __devinit synclinkmp_init_one (struct pci_dev *dev,
  4704. const struct pci_device_id *ent)
  4705. {
  4706. if (pci_enable_device(dev)) {
  4707. printk("error enabling pci device %p\n", dev);
  4708. return -EIO;
  4709. }
  4710. device_init( ++synclinkmp_adapter_count, dev );
  4711. return 0;
  4712. }
  4713. static void __devexit synclinkmp_remove_one (struct pci_dev *dev)
  4714. {
  4715. }