synclinkmp.c 148 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658
  1. /*
  2. * $Id: synclinkmp.c,v 4.38 2005/07/15 13:29:44 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.38 $";
  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. .owner = THIS_MODULE,
  429. .name = "synclinkmp",
  430. .id_table = synclinkmp_pci_tbl,
  431. .probe = synclinkmp_init_one,
  432. .remove = __devexit_p(synclinkmp_remove_one),
  433. };
  434. static struct tty_driver *serial_driver;
  435. /* number of characters left in xmit buffer before we ask for more */
  436. #define WAKEUP_CHARS 256
  437. /* tty callbacks */
  438. static int open(struct tty_struct *tty, struct file * filp);
  439. static void close(struct tty_struct *tty, struct file * filp);
  440. static void hangup(struct tty_struct *tty);
  441. static void set_termios(struct tty_struct *tty, struct termios *old_termios);
  442. static int write(struct tty_struct *tty, const unsigned char *buf, int count);
  443. static void put_char(struct tty_struct *tty, unsigned char ch);
  444. static void send_xchar(struct tty_struct *tty, char ch);
  445. static void wait_until_sent(struct tty_struct *tty, int timeout);
  446. static int write_room(struct tty_struct *tty);
  447. static void flush_chars(struct tty_struct *tty);
  448. static void flush_buffer(struct tty_struct *tty);
  449. static void tx_hold(struct tty_struct *tty);
  450. static void tx_release(struct tty_struct *tty);
  451. static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  452. static int read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
  453. static int chars_in_buffer(struct tty_struct *tty);
  454. static void throttle(struct tty_struct * tty);
  455. static void unthrottle(struct tty_struct * tty);
  456. static void set_break(struct tty_struct *tty, int break_state);
  457. #ifdef CONFIG_HDLC
  458. #define dev_to_port(D) (dev_to_hdlc(D)->priv)
  459. static void hdlcdev_tx_done(SLMP_INFO *info);
  460. static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size);
  461. static int hdlcdev_init(SLMP_INFO *info);
  462. static void hdlcdev_exit(SLMP_INFO *info);
  463. #endif
  464. /* ioctl handlers */
  465. static int get_stats(SLMP_INFO *info, struct mgsl_icount __user *user_icount);
  466. static int get_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
  467. static int set_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
  468. static int get_txidle(SLMP_INFO *info, int __user *idle_mode);
  469. static int set_txidle(SLMP_INFO *info, int idle_mode);
  470. static int tx_enable(SLMP_INFO *info, int enable);
  471. static int tx_abort(SLMP_INFO *info);
  472. static int rx_enable(SLMP_INFO *info, int enable);
  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 = 0x00800028;
  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. memset(&info->icount, 0, sizeof(info->icount));
  2309. /* program hardware for current parameters */
  2310. reset_port(info);
  2311. change_params(info);
  2312. info->status_timer.expires = jiffies + msecs_to_jiffies(10);
  2313. add_timer(&info->status_timer);
  2314. if (info->tty)
  2315. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  2316. info->flags |= ASYNC_INITIALIZED;
  2317. return 0;
  2318. }
  2319. /* Called by close() and hangup() to shutdown hardware
  2320. */
  2321. static void shutdown(SLMP_INFO * info)
  2322. {
  2323. unsigned long flags;
  2324. if (!(info->flags & ASYNC_INITIALIZED))
  2325. return;
  2326. if (debug_level >= DEBUG_LEVEL_INFO)
  2327. printk("%s(%d):%s synclinkmp_shutdown()\n",
  2328. __FILE__,__LINE__, info->device_name );
  2329. /* clear status wait queue because status changes */
  2330. /* can't happen after shutting down the hardware */
  2331. wake_up_interruptible(&info->status_event_wait_q);
  2332. wake_up_interruptible(&info->event_wait_q);
  2333. del_timer(&info->tx_timer);
  2334. del_timer(&info->status_timer);
  2335. kfree(info->tx_buf);
  2336. info->tx_buf = NULL;
  2337. spin_lock_irqsave(&info->lock,flags);
  2338. reset_port(info);
  2339. if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
  2340. info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  2341. set_signals(info);
  2342. }
  2343. spin_unlock_irqrestore(&info->lock,flags);
  2344. if (info->tty)
  2345. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2346. info->flags &= ~ASYNC_INITIALIZED;
  2347. }
  2348. static void program_hw(SLMP_INFO *info)
  2349. {
  2350. unsigned long flags;
  2351. spin_lock_irqsave(&info->lock,flags);
  2352. rx_stop(info);
  2353. tx_stop(info);
  2354. info->tx_count = info->tx_put = info->tx_get = 0;
  2355. if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
  2356. hdlc_mode(info);
  2357. else
  2358. async_mode(info);
  2359. set_signals(info);
  2360. info->dcd_chkcount = 0;
  2361. info->cts_chkcount = 0;
  2362. info->ri_chkcount = 0;
  2363. info->dsr_chkcount = 0;
  2364. info->ie1_value |= (CDCD|CCTS);
  2365. write_reg(info, IE1, info->ie1_value);
  2366. get_signals(info);
  2367. if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
  2368. rx_start(info);
  2369. spin_unlock_irqrestore(&info->lock,flags);
  2370. }
  2371. /* Reconfigure adapter based on new parameters
  2372. */
  2373. static void change_params(SLMP_INFO *info)
  2374. {
  2375. unsigned cflag;
  2376. int bits_per_char;
  2377. if (!info->tty || !info->tty->termios)
  2378. return;
  2379. if (debug_level >= DEBUG_LEVEL_INFO)
  2380. printk("%s(%d):%s change_params()\n",
  2381. __FILE__,__LINE__, info->device_name );
  2382. cflag = info->tty->termios->c_cflag;
  2383. /* if B0 rate (hangup) specified then negate DTR and RTS */
  2384. /* otherwise assert DTR and RTS */
  2385. if (cflag & CBAUD)
  2386. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2387. else
  2388. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  2389. /* byte size and parity */
  2390. switch (cflag & CSIZE) {
  2391. case CS5: info->params.data_bits = 5; break;
  2392. case CS6: info->params.data_bits = 6; break;
  2393. case CS7: info->params.data_bits = 7; break;
  2394. case CS8: info->params.data_bits = 8; break;
  2395. /* Never happens, but GCC is too dumb to figure it out */
  2396. default: info->params.data_bits = 7; break;
  2397. }
  2398. if (cflag & CSTOPB)
  2399. info->params.stop_bits = 2;
  2400. else
  2401. info->params.stop_bits = 1;
  2402. info->params.parity = ASYNC_PARITY_NONE;
  2403. if (cflag & PARENB) {
  2404. if (cflag & PARODD)
  2405. info->params.parity = ASYNC_PARITY_ODD;
  2406. else
  2407. info->params.parity = ASYNC_PARITY_EVEN;
  2408. #ifdef CMSPAR
  2409. if (cflag & CMSPAR)
  2410. info->params.parity = ASYNC_PARITY_SPACE;
  2411. #endif
  2412. }
  2413. /* calculate number of jiffies to transmit a full
  2414. * FIFO (32 bytes) at specified data rate
  2415. */
  2416. bits_per_char = info->params.data_bits +
  2417. info->params.stop_bits + 1;
  2418. /* if port data rate is set to 460800 or less then
  2419. * allow tty settings to override, otherwise keep the
  2420. * current data rate.
  2421. */
  2422. if (info->params.data_rate <= 460800) {
  2423. info->params.data_rate = tty_get_baud_rate(info->tty);
  2424. }
  2425. if ( info->params.data_rate ) {
  2426. info->timeout = (32*HZ*bits_per_char) /
  2427. info->params.data_rate;
  2428. }
  2429. info->timeout += HZ/50; /* Add .02 seconds of slop */
  2430. if (cflag & CRTSCTS)
  2431. info->flags |= ASYNC_CTS_FLOW;
  2432. else
  2433. info->flags &= ~ASYNC_CTS_FLOW;
  2434. if (cflag & CLOCAL)
  2435. info->flags &= ~ASYNC_CHECK_CD;
  2436. else
  2437. info->flags |= ASYNC_CHECK_CD;
  2438. /* process tty input control flags */
  2439. info->read_status_mask2 = OVRN;
  2440. if (I_INPCK(info->tty))
  2441. info->read_status_mask2 |= PE | FRME;
  2442. if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  2443. info->read_status_mask1 |= BRKD;
  2444. if (I_IGNPAR(info->tty))
  2445. info->ignore_status_mask2 |= PE | FRME;
  2446. if (I_IGNBRK(info->tty)) {
  2447. info->ignore_status_mask1 |= BRKD;
  2448. /* If ignoring parity and break indicators, ignore
  2449. * overruns too. (For real raw support).
  2450. */
  2451. if (I_IGNPAR(info->tty))
  2452. info->ignore_status_mask2 |= OVRN;
  2453. }
  2454. program_hw(info);
  2455. }
  2456. static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
  2457. {
  2458. int err;
  2459. if (debug_level >= DEBUG_LEVEL_INFO)
  2460. printk("%s(%d):%s get_params()\n",
  2461. __FILE__,__LINE__, info->device_name);
  2462. if (!user_icount) {
  2463. memset(&info->icount, 0, sizeof(info->icount));
  2464. } else {
  2465. COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
  2466. if (err)
  2467. return -EFAULT;
  2468. }
  2469. return 0;
  2470. }
  2471. static int get_params(SLMP_INFO * info, MGSL_PARAMS __user *user_params)
  2472. {
  2473. int err;
  2474. if (debug_level >= DEBUG_LEVEL_INFO)
  2475. printk("%s(%d):%s get_params()\n",
  2476. __FILE__,__LINE__, info->device_name);
  2477. COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
  2478. if (err) {
  2479. if ( debug_level >= DEBUG_LEVEL_INFO )
  2480. printk( "%s(%d):%s get_params() user buffer copy failed\n",
  2481. __FILE__,__LINE__,info->device_name);
  2482. return -EFAULT;
  2483. }
  2484. return 0;
  2485. }
  2486. static int set_params(SLMP_INFO * info, MGSL_PARAMS __user *new_params)
  2487. {
  2488. unsigned long flags;
  2489. MGSL_PARAMS tmp_params;
  2490. int err;
  2491. if (debug_level >= DEBUG_LEVEL_INFO)
  2492. printk("%s(%d):%s set_params\n",
  2493. __FILE__,__LINE__,info->device_name );
  2494. COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
  2495. if (err) {
  2496. if ( debug_level >= DEBUG_LEVEL_INFO )
  2497. printk( "%s(%d):%s set_params() user buffer copy failed\n",
  2498. __FILE__,__LINE__,info->device_name);
  2499. return -EFAULT;
  2500. }
  2501. spin_lock_irqsave(&info->lock,flags);
  2502. memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
  2503. spin_unlock_irqrestore(&info->lock,flags);
  2504. change_params(info);
  2505. return 0;
  2506. }
  2507. static int get_txidle(SLMP_INFO * info, int __user *idle_mode)
  2508. {
  2509. int err;
  2510. if (debug_level >= DEBUG_LEVEL_INFO)
  2511. printk("%s(%d):%s get_txidle()=%d\n",
  2512. __FILE__,__LINE__, info->device_name, info->idle_mode);
  2513. COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
  2514. if (err) {
  2515. if ( debug_level >= DEBUG_LEVEL_INFO )
  2516. printk( "%s(%d):%s get_txidle() user buffer copy failed\n",
  2517. __FILE__,__LINE__,info->device_name);
  2518. return -EFAULT;
  2519. }
  2520. return 0;
  2521. }
  2522. static int set_txidle(SLMP_INFO * info, int idle_mode)
  2523. {
  2524. unsigned long flags;
  2525. if (debug_level >= DEBUG_LEVEL_INFO)
  2526. printk("%s(%d):%s set_txidle(%d)\n",
  2527. __FILE__,__LINE__,info->device_name, idle_mode );
  2528. spin_lock_irqsave(&info->lock,flags);
  2529. info->idle_mode = idle_mode;
  2530. tx_set_idle( info );
  2531. spin_unlock_irqrestore(&info->lock,flags);
  2532. return 0;
  2533. }
  2534. static int tx_enable(SLMP_INFO * info, int enable)
  2535. {
  2536. unsigned long flags;
  2537. if (debug_level >= DEBUG_LEVEL_INFO)
  2538. printk("%s(%d):%s tx_enable(%d)\n",
  2539. __FILE__,__LINE__,info->device_name, enable);
  2540. spin_lock_irqsave(&info->lock,flags);
  2541. if ( enable ) {
  2542. if ( !info->tx_enabled ) {
  2543. tx_start(info);
  2544. }
  2545. } else {
  2546. if ( info->tx_enabled )
  2547. tx_stop(info);
  2548. }
  2549. spin_unlock_irqrestore(&info->lock,flags);
  2550. return 0;
  2551. }
  2552. /* abort send HDLC frame
  2553. */
  2554. static int tx_abort(SLMP_INFO * info)
  2555. {
  2556. unsigned long flags;
  2557. if (debug_level >= DEBUG_LEVEL_INFO)
  2558. printk("%s(%d):%s tx_abort()\n",
  2559. __FILE__,__LINE__,info->device_name);
  2560. spin_lock_irqsave(&info->lock,flags);
  2561. if ( info->tx_active && info->params.mode == MGSL_MODE_HDLC ) {
  2562. info->ie1_value &= ~UDRN;
  2563. info->ie1_value |= IDLE;
  2564. write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
  2565. write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
  2566. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  2567. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  2568. write_reg(info, CMD, TXABORT);
  2569. }
  2570. spin_unlock_irqrestore(&info->lock,flags);
  2571. return 0;
  2572. }
  2573. static int rx_enable(SLMP_INFO * info, int enable)
  2574. {
  2575. unsigned long flags;
  2576. if (debug_level >= DEBUG_LEVEL_INFO)
  2577. printk("%s(%d):%s rx_enable(%d)\n",
  2578. __FILE__,__LINE__,info->device_name,enable);
  2579. spin_lock_irqsave(&info->lock,flags);
  2580. if ( enable ) {
  2581. if ( !info->rx_enabled )
  2582. rx_start(info);
  2583. } else {
  2584. if ( info->rx_enabled )
  2585. rx_stop(info);
  2586. }
  2587. spin_unlock_irqrestore(&info->lock,flags);
  2588. return 0;
  2589. }
  2590. /* wait for specified event to occur
  2591. */
  2592. static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
  2593. {
  2594. unsigned long flags;
  2595. int s;
  2596. int rc=0;
  2597. struct mgsl_icount cprev, cnow;
  2598. int events;
  2599. int mask;
  2600. struct _input_signal_events oldsigs, newsigs;
  2601. DECLARE_WAITQUEUE(wait, current);
  2602. COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
  2603. if (rc) {
  2604. return -EFAULT;
  2605. }
  2606. if (debug_level >= DEBUG_LEVEL_INFO)
  2607. printk("%s(%d):%s wait_mgsl_event(%d)\n",
  2608. __FILE__,__LINE__,info->device_name,mask);
  2609. spin_lock_irqsave(&info->lock,flags);
  2610. /* return immediately if state matches requested events */
  2611. get_signals(info);
  2612. s = info->serial_signals;
  2613. events = mask &
  2614. ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
  2615. ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
  2616. ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
  2617. ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
  2618. if (events) {
  2619. spin_unlock_irqrestore(&info->lock,flags);
  2620. goto exit;
  2621. }
  2622. /* save current irq counts */
  2623. cprev = info->icount;
  2624. oldsigs = info->input_signal_events;
  2625. /* enable hunt and idle irqs if needed */
  2626. if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
  2627. unsigned char oldval = info->ie1_value;
  2628. unsigned char newval = oldval +
  2629. (mask & MgslEvent_ExitHuntMode ? FLGD:0) +
  2630. (mask & MgslEvent_IdleReceived ? IDLD:0);
  2631. if ( oldval != newval ) {
  2632. info->ie1_value = newval;
  2633. write_reg(info, IE1, info->ie1_value);
  2634. }
  2635. }
  2636. set_current_state(TASK_INTERRUPTIBLE);
  2637. add_wait_queue(&info->event_wait_q, &wait);
  2638. spin_unlock_irqrestore(&info->lock,flags);
  2639. for(;;) {
  2640. schedule();
  2641. if (signal_pending(current)) {
  2642. rc = -ERESTARTSYS;
  2643. break;
  2644. }
  2645. /* get current irq counts */
  2646. spin_lock_irqsave(&info->lock,flags);
  2647. cnow = info->icount;
  2648. newsigs = info->input_signal_events;
  2649. set_current_state(TASK_INTERRUPTIBLE);
  2650. spin_unlock_irqrestore(&info->lock,flags);
  2651. /* if no change, wait aborted for some reason */
  2652. if (newsigs.dsr_up == oldsigs.dsr_up &&
  2653. newsigs.dsr_down == oldsigs.dsr_down &&
  2654. newsigs.dcd_up == oldsigs.dcd_up &&
  2655. newsigs.dcd_down == oldsigs.dcd_down &&
  2656. newsigs.cts_up == oldsigs.cts_up &&
  2657. newsigs.cts_down == oldsigs.cts_down &&
  2658. newsigs.ri_up == oldsigs.ri_up &&
  2659. newsigs.ri_down == oldsigs.ri_down &&
  2660. cnow.exithunt == cprev.exithunt &&
  2661. cnow.rxidle == cprev.rxidle) {
  2662. rc = -EIO;
  2663. break;
  2664. }
  2665. events = mask &
  2666. ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
  2667. (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
  2668. (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
  2669. (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
  2670. (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
  2671. (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
  2672. (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
  2673. (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
  2674. (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
  2675. (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
  2676. if (events)
  2677. break;
  2678. cprev = cnow;
  2679. oldsigs = newsigs;
  2680. }
  2681. remove_wait_queue(&info->event_wait_q, &wait);
  2682. set_current_state(TASK_RUNNING);
  2683. if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
  2684. spin_lock_irqsave(&info->lock,flags);
  2685. if (!waitqueue_active(&info->event_wait_q)) {
  2686. /* disable enable exit hunt mode/idle rcvd IRQs */
  2687. info->ie1_value &= ~(FLGD|IDLD);
  2688. write_reg(info, IE1, info->ie1_value);
  2689. }
  2690. spin_unlock_irqrestore(&info->lock,flags);
  2691. }
  2692. exit:
  2693. if ( rc == 0 )
  2694. PUT_USER(rc, events, mask_ptr);
  2695. return rc;
  2696. }
  2697. static int modem_input_wait(SLMP_INFO *info,int arg)
  2698. {
  2699. unsigned long flags;
  2700. int rc;
  2701. struct mgsl_icount cprev, cnow;
  2702. DECLARE_WAITQUEUE(wait, current);
  2703. /* save current irq counts */
  2704. spin_lock_irqsave(&info->lock,flags);
  2705. cprev = info->icount;
  2706. add_wait_queue(&info->status_event_wait_q, &wait);
  2707. set_current_state(TASK_INTERRUPTIBLE);
  2708. spin_unlock_irqrestore(&info->lock,flags);
  2709. for(;;) {
  2710. schedule();
  2711. if (signal_pending(current)) {
  2712. rc = -ERESTARTSYS;
  2713. break;
  2714. }
  2715. /* get new irq counts */
  2716. spin_lock_irqsave(&info->lock,flags);
  2717. cnow = info->icount;
  2718. set_current_state(TASK_INTERRUPTIBLE);
  2719. spin_unlock_irqrestore(&info->lock,flags);
  2720. /* if no change, wait aborted for some reason */
  2721. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  2722. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
  2723. rc = -EIO;
  2724. break;
  2725. }
  2726. /* check for change in caller specified modem input */
  2727. if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
  2728. (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
  2729. (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
  2730. (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
  2731. rc = 0;
  2732. break;
  2733. }
  2734. cprev = cnow;
  2735. }
  2736. remove_wait_queue(&info->status_event_wait_q, &wait);
  2737. set_current_state(TASK_RUNNING);
  2738. return rc;
  2739. }
  2740. /* return the state of the serial control and status signals
  2741. */
  2742. static int tiocmget(struct tty_struct *tty, struct file *file)
  2743. {
  2744. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  2745. unsigned int result;
  2746. unsigned long flags;
  2747. spin_lock_irqsave(&info->lock,flags);
  2748. get_signals(info);
  2749. spin_unlock_irqrestore(&info->lock,flags);
  2750. result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
  2751. ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
  2752. ((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
  2753. ((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
  2754. ((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
  2755. ((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
  2756. if (debug_level >= DEBUG_LEVEL_INFO)
  2757. printk("%s(%d):%s tiocmget() value=%08X\n",
  2758. __FILE__,__LINE__, info->device_name, result );
  2759. return result;
  2760. }
  2761. /* set modem control signals (DTR/RTS)
  2762. */
  2763. static int tiocmset(struct tty_struct *tty, struct file *file,
  2764. unsigned int set, unsigned int clear)
  2765. {
  2766. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  2767. unsigned long flags;
  2768. if (debug_level >= DEBUG_LEVEL_INFO)
  2769. printk("%s(%d):%s tiocmset(%x,%x)\n",
  2770. __FILE__,__LINE__,info->device_name, set, clear);
  2771. if (set & TIOCM_RTS)
  2772. info->serial_signals |= SerialSignal_RTS;
  2773. if (set & TIOCM_DTR)
  2774. info->serial_signals |= SerialSignal_DTR;
  2775. if (clear & TIOCM_RTS)
  2776. info->serial_signals &= ~SerialSignal_RTS;
  2777. if (clear & TIOCM_DTR)
  2778. info->serial_signals &= ~SerialSignal_DTR;
  2779. spin_lock_irqsave(&info->lock,flags);
  2780. set_signals(info);
  2781. spin_unlock_irqrestore(&info->lock,flags);
  2782. return 0;
  2783. }
  2784. /* Block the current process until the specified port is ready to open.
  2785. */
  2786. static int block_til_ready(struct tty_struct *tty, struct file *filp,
  2787. SLMP_INFO *info)
  2788. {
  2789. DECLARE_WAITQUEUE(wait, current);
  2790. int retval;
  2791. int do_clocal = 0, extra_count = 0;
  2792. unsigned long flags;
  2793. if (debug_level >= DEBUG_LEVEL_INFO)
  2794. printk("%s(%d):%s block_til_ready()\n",
  2795. __FILE__,__LINE__, tty->driver->name );
  2796. if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
  2797. /* nonblock mode is set or port is not enabled */
  2798. /* just verify that callout device is not active */
  2799. info->flags |= ASYNC_NORMAL_ACTIVE;
  2800. return 0;
  2801. }
  2802. if (tty->termios->c_cflag & CLOCAL)
  2803. do_clocal = 1;
  2804. /* Wait for carrier detect and the line to become
  2805. * free (i.e., not in use by the callout). While we are in
  2806. * this loop, info->count is dropped by one, so that
  2807. * close() knows when to free things. We restore it upon
  2808. * exit, either normal or abnormal.
  2809. */
  2810. retval = 0;
  2811. add_wait_queue(&info->open_wait, &wait);
  2812. if (debug_level >= DEBUG_LEVEL_INFO)
  2813. printk("%s(%d):%s block_til_ready() before block, count=%d\n",
  2814. __FILE__,__LINE__, tty->driver->name, info->count );
  2815. spin_lock_irqsave(&info->lock, flags);
  2816. if (!tty_hung_up_p(filp)) {
  2817. extra_count = 1;
  2818. info->count--;
  2819. }
  2820. spin_unlock_irqrestore(&info->lock, flags);
  2821. info->blocked_open++;
  2822. while (1) {
  2823. if ((tty->termios->c_cflag & CBAUD)) {
  2824. spin_lock_irqsave(&info->lock,flags);
  2825. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2826. set_signals(info);
  2827. spin_unlock_irqrestore(&info->lock,flags);
  2828. }
  2829. set_current_state(TASK_INTERRUPTIBLE);
  2830. if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
  2831. retval = (info->flags & ASYNC_HUP_NOTIFY) ?
  2832. -EAGAIN : -ERESTARTSYS;
  2833. break;
  2834. }
  2835. spin_lock_irqsave(&info->lock,flags);
  2836. get_signals(info);
  2837. spin_unlock_irqrestore(&info->lock,flags);
  2838. if (!(info->flags & ASYNC_CLOSING) &&
  2839. (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
  2840. break;
  2841. }
  2842. if (signal_pending(current)) {
  2843. retval = -ERESTARTSYS;
  2844. break;
  2845. }
  2846. if (debug_level >= DEBUG_LEVEL_INFO)
  2847. printk("%s(%d):%s block_til_ready() count=%d\n",
  2848. __FILE__,__LINE__, tty->driver->name, info->count );
  2849. schedule();
  2850. }
  2851. set_current_state(TASK_RUNNING);
  2852. remove_wait_queue(&info->open_wait, &wait);
  2853. if (extra_count)
  2854. info->count++;
  2855. info->blocked_open--;
  2856. if (debug_level >= DEBUG_LEVEL_INFO)
  2857. printk("%s(%d):%s block_til_ready() after, count=%d\n",
  2858. __FILE__,__LINE__, tty->driver->name, info->count );
  2859. if (!retval)
  2860. info->flags |= ASYNC_NORMAL_ACTIVE;
  2861. return retval;
  2862. }
  2863. int alloc_dma_bufs(SLMP_INFO *info)
  2864. {
  2865. unsigned short BuffersPerFrame;
  2866. unsigned short BufferCount;
  2867. // Force allocation to start at 64K boundary for each port.
  2868. // This is necessary because *all* buffer descriptors for a port
  2869. // *must* be in the same 64K block. All descriptors on a port
  2870. // share a common 'base' address (upper 8 bits of 24 bits) programmed
  2871. // into the CBP register.
  2872. info->port_array[0]->last_mem_alloc = (SCA_MEM_SIZE/4) * info->port_num;
  2873. /* Calculate the number of DMA buffers necessary to hold the */
  2874. /* largest allowable frame size. Note: If the max frame size is */
  2875. /* not an even multiple of the DMA buffer size then we need to */
  2876. /* round the buffer count per frame up one. */
  2877. BuffersPerFrame = (unsigned short)(info->max_frame_size/SCABUFSIZE);
  2878. if ( info->max_frame_size % SCABUFSIZE )
  2879. BuffersPerFrame++;
  2880. /* calculate total number of data buffers (SCABUFSIZE) possible
  2881. * in one ports memory (SCA_MEM_SIZE/4) after allocating memory
  2882. * for the descriptor list (BUFFERLISTSIZE).
  2883. */
  2884. BufferCount = (SCA_MEM_SIZE/4 - BUFFERLISTSIZE)/SCABUFSIZE;
  2885. /* limit number of buffers to maximum amount of descriptors */
  2886. if (BufferCount > BUFFERLISTSIZE/sizeof(SCADESC))
  2887. BufferCount = BUFFERLISTSIZE/sizeof(SCADESC);
  2888. /* use enough buffers to transmit one max size frame */
  2889. info->tx_buf_count = BuffersPerFrame + 1;
  2890. /* never use more than half the available buffers for transmit */
  2891. if (info->tx_buf_count > (BufferCount/2))
  2892. info->tx_buf_count = BufferCount/2;
  2893. if (info->tx_buf_count > SCAMAXDESC)
  2894. info->tx_buf_count = SCAMAXDESC;
  2895. /* use remaining buffers for receive */
  2896. info->rx_buf_count = BufferCount - info->tx_buf_count;
  2897. if (info->rx_buf_count > SCAMAXDESC)
  2898. info->rx_buf_count = SCAMAXDESC;
  2899. if ( debug_level >= DEBUG_LEVEL_INFO )
  2900. printk("%s(%d):%s Allocating %d TX and %d RX DMA buffers.\n",
  2901. __FILE__,__LINE__, info->device_name,
  2902. info->tx_buf_count,info->rx_buf_count);
  2903. if ( alloc_buf_list( info ) < 0 ||
  2904. alloc_frame_bufs(info,
  2905. info->rx_buf_list,
  2906. info->rx_buf_list_ex,
  2907. info->rx_buf_count) < 0 ||
  2908. alloc_frame_bufs(info,
  2909. info->tx_buf_list,
  2910. info->tx_buf_list_ex,
  2911. info->tx_buf_count) < 0 ||
  2912. alloc_tmp_rx_buf(info) < 0 ) {
  2913. printk("%s(%d):%s Can't allocate DMA buffer memory\n",
  2914. __FILE__,__LINE__, info->device_name);
  2915. return -ENOMEM;
  2916. }
  2917. rx_reset_buffers( info );
  2918. return 0;
  2919. }
  2920. /* Allocate DMA buffers for the transmit and receive descriptor lists.
  2921. */
  2922. int alloc_buf_list(SLMP_INFO *info)
  2923. {
  2924. unsigned int i;
  2925. /* build list in adapter shared memory */
  2926. info->buffer_list = info->memory_base + info->port_array[0]->last_mem_alloc;
  2927. info->buffer_list_phys = info->port_array[0]->last_mem_alloc;
  2928. info->port_array[0]->last_mem_alloc += BUFFERLISTSIZE;
  2929. memset(info->buffer_list, 0, BUFFERLISTSIZE);
  2930. /* Save virtual address pointers to the receive and */
  2931. /* transmit buffer lists. (Receive 1st). These pointers will */
  2932. /* be used by the processor to access the lists. */
  2933. info->rx_buf_list = (SCADESC *)info->buffer_list;
  2934. info->tx_buf_list = (SCADESC *)info->buffer_list;
  2935. info->tx_buf_list += info->rx_buf_count;
  2936. /* Build links for circular buffer entry lists (tx and rx)
  2937. *
  2938. * Note: links are physical addresses read by the SCA device
  2939. * to determine the next buffer entry to use.
  2940. */
  2941. for ( i = 0; i < info->rx_buf_count; i++ ) {
  2942. /* calculate and store physical address of this buffer entry */
  2943. info->rx_buf_list_ex[i].phys_entry =
  2944. info->buffer_list_phys + (i * sizeof(SCABUFSIZE));
  2945. /* calculate and store physical address of */
  2946. /* next entry in cirular list of entries */
  2947. info->rx_buf_list[i].next = info->buffer_list_phys;
  2948. if ( i < info->rx_buf_count - 1 )
  2949. info->rx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
  2950. info->rx_buf_list[i].length = SCABUFSIZE;
  2951. }
  2952. for ( i = 0; i < info->tx_buf_count; i++ ) {
  2953. /* calculate and store physical address of this buffer entry */
  2954. info->tx_buf_list_ex[i].phys_entry = info->buffer_list_phys +
  2955. ((info->rx_buf_count + i) * sizeof(SCADESC));
  2956. /* calculate and store physical address of */
  2957. /* next entry in cirular list of entries */
  2958. info->tx_buf_list[i].next = info->buffer_list_phys +
  2959. info->rx_buf_count * sizeof(SCADESC);
  2960. if ( i < info->tx_buf_count - 1 )
  2961. info->tx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
  2962. }
  2963. return 0;
  2964. }
  2965. /* Allocate the frame DMA buffers used by the specified buffer list.
  2966. */
  2967. int alloc_frame_bufs(SLMP_INFO *info, SCADESC *buf_list,SCADESC_EX *buf_list_ex,int count)
  2968. {
  2969. int i;
  2970. unsigned long phys_addr;
  2971. for ( i = 0; i < count; i++ ) {
  2972. buf_list_ex[i].virt_addr = info->memory_base + info->port_array[0]->last_mem_alloc;
  2973. phys_addr = info->port_array[0]->last_mem_alloc;
  2974. info->port_array[0]->last_mem_alloc += SCABUFSIZE;
  2975. buf_list[i].buf_ptr = (unsigned short)phys_addr;
  2976. buf_list[i].buf_base = (unsigned char)(phys_addr >> 16);
  2977. }
  2978. return 0;
  2979. }
  2980. void free_dma_bufs(SLMP_INFO *info)
  2981. {
  2982. info->buffer_list = NULL;
  2983. info->rx_buf_list = NULL;
  2984. info->tx_buf_list = NULL;
  2985. }
  2986. /* allocate buffer large enough to hold max_frame_size.
  2987. * This buffer is used to pass an assembled frame to the line discipline.
  2988. */
  2989. int alloc_tmp_rx_buf(SLMP_INFO *info)
  2990. {
  2991. info->tmp_rx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
  2992. if (info->tmp_rx_buf == NULL)
  2993. return -ENOMEM;
  2994. return 0;
  2995. }
  2996. void free_tmp_rx_buf(SLMP_INFO *info)
  2997. {
  2998. kfree(info->tmp_rx_buf);
  2999. info->tmp_rx_buf = NULL;
  3000. }
  3001. int claim_resources(SLMP_INFO *info)
  3002. {
  3003. if (request_mem_region(info->phys_memory_base,SCA_MEM_SIZE,"synclinkmp") == NULL) {
  3004. printk( "%s(%d):%s mem addr conflict, Addr=%08X\n",
  3005. __FILE__,__LINE__,info->device_name, info->phys_memory_base);
  3006. info->init_error = DiagStatus_AddressConflict;
  3007. goto errout;
  3008. }
  3009. else
  3010. info->shared_mem_requested = 1;
  3011. if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclinkmp") == NULL) {
  3012. printk( "%s(%d):%s lcr mem addr conflict, Addr=%08X\n",
  3013. __FILE__,__LINE__,info->device_name, info->phys_lcr_base);
  3014. info->init_error = DiagStatus_AddressConflict;
  3015. goto errout;
  3016. }
  3017. else
  3018. info->lcr_mem_requested = 1;
  3019. if (request_mem_region(info->phys_sca_base + info->sca_offset,SCA_BASE_SIZE,"synclinkmp") == NULL) {
  3020. printk( "%s(%d):%s sca mem addr conflict, Addr=%08X\n",
  3021. __FILE__,__LINE__,info->device_name, info->phys_sca_base);
  3022. info->init_error = DiagStatus_AddressConflict;
  3023. goto errout;
  3024. }
  3025. else
  3026. info->sca_base_requested = 1;
  3027. if (request_mem_region(info->phys_statctrl_base + info->statctrl_offset,SCA_REG_SIZE,"synclinkmp") == NULL) {
  3028. printk( "%s(%d):%s stat/ctrl mem addr conflict, Addr=%08X\n",
  3029. __FILE__,__LINE__,info->device_name, info->phys_statctrl_base);
  3030. info->init_error = DiagStatus_AddressConflict;
  3031. goto errout;
  3032. }
  3033. else
  3034. info->sca_statctrl_requested = 1;
  3035. info->memory_base = ioremap(info->phys_memory_base,SCA_MEM_SIZE);
  3036. if (!info->memory_base) {
  3037. printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n",
  3038. __FILE__,__LINE__,info->device_name, info->phys_memory_base );
  3039. info->init_error = DiagStatus_CantAssignPciResources;
  3040. goto errout;
  3041. }
  3042. info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE);
  3043. if (!info->lcr_base) {
  3044. printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n",
  3045. __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
  3046. info->init_error = DiagStatus_CantAssignPciResources;
  3047. goto errout;
  3048. }
  3049. info->lcr_base += info->lcr_offset;
  3050. info->sca_base = ioremap(info->phys_sca_base,PAGE_SIZE);
  3051. if (!info->sca_base) {
  3052. printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n",
  3053. __FILE__,__LINE__,info->device_name, info->phys_sca_base );
  3054. info->init_error = DiagStatus_CantAssignPciResources;
  3055. goto errout;
  3056. }
  3057. info->sca_base += info->sca_offset;
  3058. info->statctrl_base = ioremap(info->phys_statctrl_base,PAGE_SIZE);
  3059. if (!info->statctrl_base) {
  3060. printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n",
  3061. __FILE__,__LINE__,info->device_name, info->phys_statctrl_base );
  3062. info->init_error = DiagStatus_CantAssignPciResources;
  3063. goto errout;
  3064. }
  3065. info->statctrl_base += info->statctrl_offset;
  3066. if ( !memory_test(info) ) {
  3067. printk( "%s(%d):Shared Memory Test failed for device %s MemAddr=%08X\n",
  3068. __FILE__,__LINE__,info->device_name, info->phys_memory_base );
  3069. info->init_error = DiagStatus_MemoryError;
  3070. goto errout;
  3071. }
  3072. return 0;
  3073. errout:
  3074. release_resources( info );
  3075. return -ENODEV;
  3076. }
  3077. void release_resources(SLMP_INFO *info)
  3078. {
  3079. if ( debug_level >= DEBUG_LEVEL_INFO )
  3080. printk( "%s(%d):%s release_resources() entry\n",
  3081. __FILE__,__LINE__,info->device_name );
  3082. if ( info->irq_requested ) {
  3083. free_irq(info->irq_level, info);
  3084. info->irq_requested = 0;
  3085. }
  3086. if ( info->shared_mem_requested ) {
  3087. release_mem_region(info->phys_memory_base,SCA_MEM_SIZE);
  3088. info->shared_mem_requested = 0;
  3089. }
  3090. if ( info->lcr_mem_requested ) {
  3091. release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
  3092. info->lcr_mem_requested = 0;
  3093. }
  3094. if ( info->sca_base_requested ) {
  3095. release_mem_region(info->phys_sca_base + info->sca_offset,SCA_BASE_SIZE);
  3096. info->sca_base_requested = 0;
  3097. }
  3098. if ( info->sca_statctrl_requested ) {
  3099. release_mem_region(info->phys_statctrl_base + info->statctrl_offset,SCA_REG_SIZE);
  3100. info->sca_statctrl_requested = 0;
  3101. }
  3102. if (info->memory_base){
  3103. iounmap(info->memory_base);
  3104. info->memory_base = NULL;
  3105. }
  3106. if (info->sca_base) {
  3107. iounmap(info->sca_base - info->sca_offset);
  3108. info->sca_base=NULL;
  3109. }
  3110. if (info->statctrl_base) {
  3111. iounmap(info->statctrl_base - info->statctrl_offset);
  3112. info->statctrl_base=NULL;
  3113. }
  3114. if (info->lcr_base){
  3115. iounmap(info->lcr_base - info->lcr_offset);
  3116. info->lcr_base = NULL;
  3117. }
  3118. if ( debug_level >= DEBUG_LEVEL_INFO )
  3119. printk( "%s(%d):%s release_resources() exit\n",
  3120. __FILE__,__LINE__,info->device_name );
  3121. }
  3122. /* Add the specified device instance data structure to the
  3123. * global linked list of devices and increment the device count.
  3124. */
  3125. void add_device(SLMP_INFO *info)
  3126. {
  3127. info->next_device = NULL;
  3128. info->line = synclinkmp_device_count;
  3129. sprintf(info->device_name,"ttySLM%dp%d",info->adapter_num,info->port_num);
  3130. if (info->line < MAX_DEVICES) {
  3131. if (maxframe[info->line])
  3132. info->max_frame_size = maxframe[info->line];
  3133. info->dosyncppp = dosyncppp[info->line];
  3134. }
  3135. synclinkmp_device_count++;
  3136. if ( !synclinkmp_device_list )
  3137. synclinkmp_device_list = info;
  3138. else {
  3139. SLMP_INFO *current_dev = synclinkmp_device_list;
  3140. while( current_dev->next_device )
  3141. current_dev = current_dev->next_device;
  3142. current_dev->next_device = info;
  3143. }
  3144. if ( info->max_frame_size < 4096 )
  3145. info->max_frame_size = 4096;
  3146. else if ( info->max_frame_size > 65535 )
  3147. info->max_frame_size = 65535;
  3148. printk( "SyncLink MultiPort %s: "
  3149. "Mem=(%08x %08X %08x %08X) IRQ=%d MaxFrameSize=%u\n",
  3150. info->device_name,
  3151. info->phys_sca_base,
  3152. info->phys_memory_base,
  3153. info->phys_statctrl_base,
  3154. info->phys_lcr_base,
  3155. info->irq_level,
  3156. info->max_frame_size );
  3157. #ifdef CONFIG_HDLC
  3158. hdlcdev_init(info);
  3159. #endif
  3160. }
  3161. /* Allocate and initialize a device instance structure
  3162. *
  3163. * Return Value: pointer to SLMP_INFO if success, otherwise NULL
  3164. */
  3165. static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
  3166. {
  3167. SLMP_INFO *info;
  3168. info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO),
  3169. GFP_KERNEL);
  3170. if (!info) {
  3171. printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
  3172. __FILE__,__LINE__, adapter_num, port_num);
  3173. } else {
  3174. memset(info, 0, sizeof(SLMP_INFO));
  3175. info->magic = MGSL_MAGIC;
  3176. INIT_WORK(&info->task, bh_handler, info);
  3177. info->max_frame_size = 4096;
  3178. info->close_delay = 5*HZ/10;
  3179. info->closing_wait = 30*HZ;
  3180. init_waitqueue_head(&info->open_wait);
  3181. init_waitqueue_head(&info->close_wait);
  3182. init_waitqueue_head(&info->status_event_wait_q);
  3183. init_waitqueue_head(&info->event_wait_q);
  3184. spin_lock_init(&info->netlock);
  3185. memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
  3186. info->idle_mode = HDLC_TXIDLE_FLAGS;
  3187. info->adapter_num = adapter_num;
  3188. info->port_num = port_num;
  3189. /* Copy configuration info to device instance data */
  3190. info->irq_level = pdev->irq;
  3191. info->phys_lcr_base = pci_resource_start(pdev,0);
  3192. info->phys_sca_base = pci_resource_start(pdev,2);
  3193. info->phys_memory_base = pci_resource_start(pdev,3);
  3194. info->phys_statctrl_base = pci_resource_start(pdev,4);
  3195. /* Because veremap only works on page boundaries we must map
  3196. * a larger area than is actually implemented for the LCR
  3197. * memory range. We map a full page starting at the page boundary.
  3198. */
  3199. info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
  3200. info->phys_lcr_base &= ~(PAGE_SIZE-1);
  3201. info->sca_offset = info->phys_sca_base & (PAGE_SIZE-1);
  3202. info->phys_sca_base &= ~(PAGE_SIZE-1);
  3203. info->statctrl_offset = info->phys_statctrl_base & (PAGE_SIZE-1);
  3204. info->phys_statctrl_base &= ~(PAGE_SIZE-1);
  3205. info->bus_type = MGSL_BUS_TYPE_PCI;
  3206. info->irq_flags = SA_SHIRQ;
  3207. init_timer(&info->tx_timer);
  3208. info->tx_timer.data = (unsigned long)info;
  3209. info->tx_timer.function = tx_timeout;
  3210. init_timer(&info->status_timer);
  3211. info->status_timer.data = (unsigned long)info;
  3212. info->status_timer.function = status_timeout;
  3213. /* Store the PCI9050 misc control register value because a flaw
  3214. * in the PCI9050 prevents LCR registers from being read if
  3215. * BIOS assigns an LCR base address with bit 7 set.
  3216. *
  3217. * Only the misc control register is accessed for which only
  3218. * write access is needed, so set an initial value and change
  3219. * bits to the device instance data as we write the value
  3220. * to the actual misc control register.
  3221. */
  3222. info->misc_ctrl_value = 0x087e4546;
  3223. /* initial port state is unknown - if startup errors
  3224. * occur, init_error will be set to indicate the
  3225. * problem. Once the port is fully initialized,
  3226. * this value will be set to 0 to indicate the
  3227. * port is available.
  3228. */
  3229. info->init_error = -1;
  3230. }
  3231. return info;
  3232. }
  3233. void device_init(int adapter_num, struct pci_dev *pdev)
  3234. {
  3235. SLMP_INFO *port_array[SCA_MAX_PORTS];
  3236. int port;
  3237. /* allocate device instances for up to SCA_MAX_PORTS devices */
  3238. for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
  3239. port_array[port] = alloc_dev(adapter_num,port,pdev);
  3240. if( port_array[port] == NULL ) {
  3241. for ( --port; port >= 0; --port )
  3242. kfree(port_array[port]);
  3243. return;
  3244. }
  3245. }
  3246. /* give copy of port_array to all ports and add to device list */
  3247. for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
  3248. memcpy(port_array[port]->port_array,port_array,sizeof(port_array));
  3249. add_device( port_array[port] );
  3250. spin_lock_init(&port_array[port]->lock);
  3251. }
  3252. /* Allocate and claim adapter resources */
  3253. if ( !claim_resources(port_array[0]) ) {
  3254. alloc_dma_bufs(port_array[0]);
  3255. /* copy resource information from first port to others */
  3256. for ( port = 1; port < SCA_MAX_PORTS; ++port ) {
  3257. port_array[port]->lock = port_array[0]->lock;
  3258. port_array[port]->irq_level = port_array[0]->irq_level;
  3259. port_array[port]->memory_base = port_array[0]->memory_base;
  3260. port_array[port]->sca_base = port_array[0]->sca_base;
  3261. port_array[port]->statctrl_base = port_array[0]->statctrl_base;
  3262. port_array[port]->lcr_base = port_array[0]->lcr_base;
  3263. alloc_dma_bufs(port_array[port]);
  3264. }
  3265. if ( request_irq(port_array[0]->irq_level,
  3266. synclinkmp_interrupt,
  3267. port_array[0]->irq_flags,
  3268. port_array[0]->device_name,
  3269. port_array[0]) < 0 ) {
  3270. printk( "%s(%d):%s Cant request interrupt, IRQ=%d\n",
  3271. __FILE__,__LINE__,
  3272. port_array[0]->device_name,
  3273. port_array[0]->irq_level );
  3274. }
  3275. else {
  3276. port_array[0]->irq_requested = 1;
  3277. adapter_test(port_array[0]);
  3278. }
  3279. }
  3280. }
  3281. static struct tty_operations ops = {
  3282. .open = open,
  3283. .close = close,
  3284. .write = write,
  3285. .put_char = put_char,
  3286. .flush_chars = flush_chars,
  3287. .write_room = write_room,
  3288. .chars_in_buffer = chars_in_buffer,
  3289. .flush_buffer = flush_buffer,
  3290. .ioctl = ioctl,
  3291. .throttle = throttle,
  3292. .unthrottle = unthrottle,
  3293. .send_xchar = send_xchar,
  3294. .break_ctl = set_break,
  3295. .wait_until_sent = wait_until_sent,
  3296. .read_proc = read_proc,
  3297. .set_termios = set_termios,
  3298. .stop = tx_hold,
  3299. .start = tx_release,
  3300. .hangup = hangup,
  3301. .tiocmget = tiocmget,
  3302. .tiocmset = tiocmset,
  3303. };
  3304. static void synclinkmp_cleanup(void)
  3305. {
  3306. int rc;
  3307. SLMP_INFO *info;
  3308. SLMP_INFO *tmp;
  3309. printk("Unloading %s %s\n", driver_name, driver_version);
  3310. if (serial_driver) {
  3311. if ((rc = tty_unregister_driver(serial_driver)))
  3312. printk("%s(%d) failed to unregister tty driver err=%d\n",
  3313. __FILE__,__LINE__,rc);
  3314. put_tty_driver(serial_driver);
  3315. }
  3316. /* reset devices */
  3317. info = synclinkmp_device_list;
  3318. while(info) {
  3319. reset_port(info);
  3320. info = info->next_device;
  3321. }
  3322. /* release devices */
  3323. info = synclinkmp_device_list;
  3324. while(info) {
  3325. #ifdef CONFIG_HDLC
  3326. hdlcdev_exit(info);
  3327. #endif
  3328. free_dma_bufs(info);
  3329. free_tmp_rx_buf(info);
  3330. if ( info->port_num == 0 ) {
  3331. if (info->sca_base)
  3332. write_reg(info, LPR, 1); /* set low power mode */
  3333. release_resources(info);
  3334. }
  3335. tmp = info;
  3336. info = info->next_device;
  3337. kfree(tmp);
  3338. }
  3339. pci_unregister_driver(&synclinkmp_pci_driver);
  3340. }
  3341. /* Driver initialization entry point.
  3342. */
  3343. static int __init synclinkmp_init(void)
  3344. {
  3345. int rc;
  3346. if (break_on_load) {
  3347. synclinkmp_get_text_ptr();
  3348. BREAKPOINT();
  3349. }
  3350. printk("%s %s\n", driver_name, driver_version);
  3351. if ((rc = pci_register_driver(&synclinkmp_pci_driver)) < 0) {
  3352. printk("%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
  3353. return rc;
  3354. }
  3355. serial_driver = alloc_tty_driver(128);
  3356. if (!serial_driver) {
  3357. rc = -ENOMEM;
  3358. goto error;
  3359. }
  3360. /* Initialize the tty_driver structure */
  3361. serial_driver->owner = THIS_MODULE;
  3362. serial_driver->driver_name = "synclinkmp";
  3363. serial_driver->name = "ttySLM";
  3364. serial_driver->major = ttymajor;
  3365. serial_driver->minor_start = 64;
  3366. serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  3367. serial_driver->subtype = SERIAL_TYPE_NORMAL;
  3368. serial_driver->init_termios = tty_std_termios;
  3369. serial_driver->init_termios.c_cflag =
  3370. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  3371. serial_driver->flags = TTY_DRIVER_REAL_RAW;
  3372. tty_set_operations(serial_driver, &ops);
  3373. if ((rc = tty_register_driver(serial_driver)) < 0) {
  3374. printk("%s(%d):Couldn't register serial driver\n",
  3375. __FILE__,__LINE__);
  3376. put_tty_driver(serial_driver);
  3377. serial_driver = NULL;
  3378. goto error;
  3379. }
  3380. printk("%s %s, tty major#%d\n",
  3381. driver_name, driver_version,
  3382. serial_driver->major);
  3383. return 0;
  3384. error:
  3385. synclinkmp_cleanup();
  3386. return rc;
  3387. }
  3388. static void __exit synclinkmp_exit(void)
  3389. {
  3390. synclinkmp_cleanup();
  3391. }
  3392. module_init(synclinkmp_init);
  3393. module_exit(synclinkmp_exit);
  3394. /* Set the port for internal loopback mode.
  3395. * The TxCLK and RxCLK signals are generated from the BRG and
  3396. * the TxD is looped back to the RxD internally.
  3397. */
  3398. void enable_loopback(SLMP_INFO *info, int enable)
  3399. {
  3400. if (enable) {
  3401. /* MD2 (Mode Register 2)
  3402. * 01..00 CNCT<1..0> Channel Connection 11=Local Loopback
  3403. */
  3404. write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) | (BIT1 + BIT0)));
  3405. /* degate external TxC clock source */
  3406. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3407. write_control_reg(info);
  3408. /* RXS/TXS (Rx/Tx clock source)
  3409. * 07 Reserved, must be 0
  3410. * 06..04 Clock Source, 100=BRG
  3411. * 03..00 Clock Divisor, 0000=1
  3412. */
  3413. write_reg(info, RXS, 0x40);
  3414. write_reg(info, TXS, 0x40);
  3415. } else {
  3416. /* MD2 (Mode Register 2)
  3417. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3418. */
  3419. write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) & ~(BIT1 + BIT0)));
  3420. /* RXS/TXS (Rx/Tx clock source)
  3421. * 07 Reserved, must be 0
  3422. * 06..04 Clock Source, 000=RxC/TxC Pin
  3423. * 03..00 Clock Divisor, 0000=1
  3424. */
  3425. write_reg(info, RXS, 0x00);
  3426. write_reg(info, TXS, 0x00);
  3427. }
  3428. /* set LinkSpeed if available, otherwise default to 2Mbps */
  3429. if (info->params.clock_speed)
  3430. set_rate(info, info->params.clock_speed);
  3431. else
  3432. set_rate(info, 3686400);
  3433. }
  3434. /* Set the baud rate register to the desired speed
  3435. *
  3436. * data_rate data rate of clock in bits per second
  3437. * A data rate of 0 disables the AUX clock.
  3438. */
  3439. void set_rate( SLMP_INFO *info, u32 data_rate )
  3440. {
  3441. u32 TMCValue;
  3442. unsigned char BRValue;
  3443. u32 Divisor=0;
  3444. /* fBRG = fCLK/(TMC * 2^BR)
  3445. */
  3446. if (data_rate != 0) {
  3447. Divisor = 14745600/data_rate;
  3448. if (!Divisor)
  3449. Divisor = 1;
  3450. TMCValue = Divisor;
  3451. BRValue = 0;
  3452. if (TMCValue != 1 && TMCValue != 2) {
  3453. /* BRValue of 0 provides 50/50 duty cycle *only* when
  3454. * TMCValue is 1 or 2. BRValue of 1 to 9 always provides
  3455. * 50/50 duty cycle.
  3456. */
  3457. BRValue = 1;
  3458. TMCValue >>= 1;
  3459. }
  3460. /* while TMCValue is too big for TMC register, divide
  3461. * by 2 and increment BR exponent.
  3462. */
  3463. for(; TMCValue > 256 && BRValue < 10; BRValue++)
  3464. TMCValue >>= 1;
  3465. write_reg(info, TXS,
  3466. (unsigned char)((read_reg(info, TXS) & 0xf0) | BRValue));
  3467. write_reg(info, RXS,
  3468. (unsigned char)((read_reg(info, RXS) & 0xf0) | BRValue));
  3469. write_reg(info, TMC, (unsigned char)TMCValue);
  3470. }
  3471. else {
  3472. write_reg(info, TXS,0);
  3473. write_reg(info, RXS,0);
  3474. write_reg(info, TMC, 0);
  3475. }
  3476. }
  3477. /* Disable receiver
  3478. */
  3479. void rx_stop(SLMP_INFO *info)
  3480. {
  3481. if (debug_level >= DEBUG_LEVEL_ISR)
  3482. printk("%s(%d):%s rx_stop()\n",
  3483. __FILE__,__LINE__, info->device_name );
  3484. write_reg(info, CMD, RXRESET);
  3485. info->ie0_value &= ~RXRDYE;
  3486. write_reg(info, IE0, info->ie0_value); /* disable Rx data interrupts */
  3487. write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
  3488. write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
  3489. write_reg(info, RXDMA + DIR, 0); /* disable Rx DMA interrupts */
  3490. info->rx_enabled = 0;
  3491. info->rx_overflow = 0;
  3492. }
  3493. /* enable the receiver
  3494. */
  3495. void rx_start(SLMP_INFO *info)
  3496. {
  3497. int i;
  3498. if (debug_level >= DEBUG_LEVEL_ISR)
  3499. printk("%s(%d):%s rx_start()\n",
  3500. __FILE__,__LINE__, info->device_name );
  3501. write_reg(info, CMD, RXRESET);
  3502. if ( info->params.mode == MGSL_MODE_HDLC ) {
  3503. /* HDLC, disabe IRQ on rxdata */
  3504. info->ie0_value &= ~RXRDYE;
  3505. write_reg(info, IE0, info->ie0_value);
  3506. /* Reset all Rx DMA buffers and program rx dma */
  3507. write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
  3508. write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
  3509. for (i = 0; i < info->rx_buf_count; i++) {
  3510. info->rx_buf_list[i].status = 0xff;
  3511. // throttle to 4 shared memory writes at a time to prevent
  3512. // hogging local bus (keep latency time for DMA requests low).
  3513. if (!(i % 4))
  3514. read_status_reg(info);
  3515. }
  3516. info->current_rx_buf = 0;
  3517. /* set current/1st descriptor address */
  3518. write_reg16(info, RXDMA + CDA,
  3519. info->rx_buf_list_ex[0].phys_entry);
  3520. /* set new last rx descriptor address */
  3521. write_reg16(info, RXDMA + EDA,
  3522. info->rx_buf_list_ex[info->rx_buf_count - 1].phys_entry);
  3523. /* set buffer length (shared by all rx dma data buffers) */
  3524. write_reg16(info, RXDMA + BFL, SCABUFSIZE);
  3525. write_reg(info, RXDMA + DIR, 0x60); /* enable Rx DMA interrupts (EOM/BOF) */
  3526. write_reg(info, RXDMA + DSR, 0xf2); /* clear Rx DMA IRQs, enable Rx DMA */
  3527. } else {
  3528. /* async, enable IRQ on rxdata */
  3529. info->ie0_value |= RXRDYE;
  3530. write_reg(info, IE0, info->ie0_value);
  3531. }
  3532. write_reg(info, CMD, RXENABLE);
  3533. info->rx_overflow = FALSE;
  3534. info->rx_enabled = 1;
  3535. }
  3536. /* Enable the transmitter and send a transmit frame if
  3537. * one is loaded in the DMA buffers.
  3538. */
  3539. void tx_start(SLMP_INFO *info)
  3540. {
  3541. if (debug_level >= DEBUG_LEVEL_ISR)
  3542. printk("%s(%d):%s tx_start() tx_count=%d\n",
  3543. __FILE__,__LINE__, info->device_name,info->tx_count );
  3544. if (!info->tx_enabled ) {
  3545. write_reg(info, CMD, TXRESET);
  3546. write_reg(info, CMD, TXENABLE);
  3547. info->tx_enabled = TRUE;
  3548. }
  3549. if ( info->tx_count ) {
  3550. /* If auto RTS enabled and RTS is inactive, then assert */
  3551. /* RTS and set a flag indicating that the driver should */
  3552. /* negate RTS when the transmission completes. */
  3553. info->drop_rts_on_tx_done = 0;
  3554. if (info->params.mode != MGSL_MODE_ASYNC) {
  3555. if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
  3556. get_signals( info );
  3557. if ( !(info->serial_signals & SerialSignal_RTS) ) {
  3558. info->serial_signals |= SerialSignal_RTS;
  3559. set_signals( info );
  3560. info->drop_rts_on_tx_done = 1;
  3561. }
  3562. }
  3563. write_reg16(info, TRC0,
  3564. (unsigned short)(((tx_negate_fifo_level-1)<<8) + tx_active_fifo_level));
  3565. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  3566. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  3567. /* set TX CDA (current descriptor address) */
  3568. write_reg16(info, TXDMA + CDA,
  3569. info->tx_buf_list_ex[0].phys_entry);
  3570. /* set TX EDA (last descriptor address) */
  3571. write_reg16(info, TXDMA + EDA,
  3572. info->tx_buf_list_ex[info->last_tx_buf].phys_entry);
  3573. /* enable underrun IRQ */
  3574. info->ie1_value &= ~IDLE;
  3575. info->ie1_value |= UDRN;
  3576. write_reg(info, IE1, info->ie1_value);
  3577. write_reg(info, SR1, (unsigned char)(IDLE + UDRN));
  3578. write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
  3579. write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
  3580. info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
  3581. add_timer(&info->tx_timer);
  3582. }
  3583. else {
  3584. tx_load_fifo(info);
  3585. /* async, enable IRQ on txdata */
  3586. info->ie0_value |= TXRDYE;
  3587. write_reg(info, IE0, info->ie0_value);
  3588. }
  3589. info->tx_active = 1;
  3590. }
  3591. }
  3592. /* stop the transmitter and DMA
  3593. */
  3594. void tx_stop( SLMP_INFO *info )
  3595. {
  3596. if (debug_level >= DEBUG_LEVEL_ISR)
  3597. printk("%s(%d):%s tx_stop()\n",
  3598. __FILE__,__LINE__, info->device_name );
  3599. del_timer(&info->tx_timer);
  3600. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  3601. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  3602. write_reg(info, CMD, TXRESET);
  3603. info->ie1_value &= ~(UDRN + IDLE);
  3604. write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
  3605. write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
  3606. info->ie0_value &= ~TXRDYE;
  3607. write_reg(info, IE0, info->ie0_value); /* disable tx data interrupts */
  3608. info->tx_enabled = 0;
  3609. info->tx_active = 0;
  3610. }
  3611. /* Fill the transmit FIFO until the FIFO is full or
  3612. * there is no more data to load.
  3613. */
  3614. void tx_load_fifo(SLMP_INFO *info)
  3615. {
  3616. u8 TwoBytes[2];
  3617. /* do nothing is now tx data available and no XON/XOFF pending */
  3618. if ( !info->tx_count && !info->x_char )
  3619. return;
  3620. /* load the Transmit FIFO until FIFOs full or all data sent */
  3621. while( info->tx_count && (read_reg(info,SR0) & BIT1) ) {
  3622. /* there is more space in the transmit FIFO and */
  3623. /* there is more data in transmit buffer */
  3624. if ( (info->tx_count > 1) && !info->x_char ) {
  3625. /* write 16-bits */
  3626. TwoBytes[0] = info->tx_buf[info->tx_get++];
  3627. if (info->tx_get >= info->max_frame_size)
  3628. info->tx_get -= info->max_frame_size;
  3629. TwoBytes[1] = info->tx_buf[info->tx_get++];
  3630. if (info->tx_get >= info->max_frame_size)
  3631. info->tx_get -= info->max_frame_size;
  3632. write_reg16(info, TRB, *((u16 *)TwoBytes));
  3633. info->tx_count -= 2;
  3634. info->icount.tx += 2;
  3635. } else {
  3636. /* only 1 byte left to transmit or 1 FIFO slot left */
  3637. if (info->x_char) {
  3638. /* transmit pending high priority char */
  3639. write_reg(info, TRB, info->x_char);
  3640. info->x_char = 0;
  3641. } else {
  3642. write_reg(info, TRB, info->tx_buf[info->tx_get++]);
  3643. if (info->tx_get >= info->max_frame_size)
  3644. info->tx_get -= info->max_frame_size;
  3645. info->tx_count--;
  3646. }
  3647. info->icount.tx++;
  3648. }
  3649. }
  3650. }
  3651. /* Reset a port to a known state
  3652. */
  3653. void reset_port(SLMP_INFO *info)
  3654. {
  3655. if (info->sca_base) {
  3656. tx_stop(info);
  3657. rx_stop(info);
  3658. info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  3659. set_signals(info);
  3660. /* disable all port interrupts */
  3661. info->ie0_value = 0;
  3662. info->ie1_value = 0;
  3663. info->ie2_value = 0;
  3664. write_reg(info, IE0, info->ie0_value);
  3665. write_reg(info, IE1, info->ie1_value);
  3666. write_reg(info, IE2, info->ie2_value);
  3667. write_reg(info, CMD, CHRESET);
  3668. }
  3669. }
  3670. /* Reset all the ports to a known state.
  3671. */
  3672. void reset_adapter(SLMP_INFO *info)
  3673. {
  3674. int i;
  3675. for ( i=0; i < SCA_MAX_PORTS; ++i) {
  3676. if (info->port_array[i])
  3677. reset_port(info->port_array[i]);
  3678. }
  3679. }
  3680. /* Program port for asynchronous communications.
  3681. */
  3682. void async_mode(SLMP_INFO *info)
  3683. {
  3684. unsigned char RegValue;
  3685. tx_stop(info);
  3686. rx_stop(info);
  3687. /* MD0, Mode Register 0
  3688. *
  3689. * 07..05 PRCTL<2..0>, Protocol Mode, 000=async
  3690. * 04 AUTO, Auto-enable (RTS/CTS/DCD)
  3691. * 03 Reserved, must be 0
  3692. * 02 CRCCC, CRC Calculation, 0=disabled
  3693. * 01..00 STOP<1..0> Stop bits (00=1,10=2)
  3694. *
  3695. * 0000 0000
  3696. */
  3697. RegValue = 0x00;
  3698. if (info->params.stop_bits != 1)
  3699. RegValue |= BIT1;
  3700. write_reg(info, MD0, RegValue);
  3701. /* MD1, Mode Register 1
  3702. *
  3703. * 07..06 BRATE<1..0>, bit rate, 00=1/1 01=1/16 10=1/32 11=1/64
  3704. * 05..04 TXCHR<1..0>, tx char size, 00=8 bits,01=7,10=6,11=5
  3705. * 03..02 RXCHR<1..0>, rx char size
  3706. * 01..00 PMPM<1..0>, Parity mode, 00=none 10=even 11=odd
  3707. *
  3708. * 0100 0000
  3709. */
  3710. RegValue = 0x40;
  3711. switch (info->params.data_bits) {
  3712. case 7: RegValue |= BIT4 + BIT2; break;
  3713. case 6: RegValue |= BIT5 + BIT3; break;
  3714. case 5: RegValue |= BIT5 + BIT4 + BIT3 + BIT2; break;
  3715. }
  3716. if (info->params.parity != ASYNC_PARITY_NONE) {
  3717. RegValue |= BIT1;
  3718. if (info->params.parity == ASYNC_PARITY_ODD)
  3719. RegValue |= BIT0;
  3720. }
  3721. write_reg(info, MD1, RegValue);
  3722. /* MD2, Mode Register 2
  3723. *
  3724. * 07..02 Reserved, must be 0
  3725. * 01..00 CNCT<1..0> Channel connection, 00=normal 11=local loopback
  3726. *
  3727. * 0000 0000
  3728. */
  3729. RegValue = 0x00;
  3730. if (info->params.loopback)
  3731. RegValue |= (BIT1 + BIT0);
  3732. write_reg(info, MD2, RegValue);
  3733. /* RXS, Receive clock source
  3734. *
  3735. * 07 Reserved, must be 0
  3736. * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
  3737. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3738. */
  3739. RegValue=BIT6;
  3740. write_reg(info, RXS, RegValue);
  3741. /* TXS, Transmit clock source
  3742. *
  3743. * 07 Reserved, must be 0
  3744. * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
  3745. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3746. */
  3747. RegValue=BIT6;
  3748. write_reg(info, TXS, RegValue);
  3749. /* Control Register
  3750. *
  3751. * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
  3752. */
  3753. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3754. write_control_reg(info);
  3755. tx_set_idle(info);
  3756. /* RRC Receive Ready Control 0
  3757. *
  3758. * 07..05 Reserved, must be 0
  3759. * 04..00 RRC<4..0> Rx FIFO trigger active 0x00 = 1 byte
  3760. */
  3761. write_reg(info, RRC, 0x00);
  3762. /* TRC0 Transmit Ready Control 0
  3763. *
  3764. * 07..05 Reserved, must be 0
  3765. * 04..00 TRC<4..0> Tx FIFO trigger active 0x10 = 16 bytes
  3766. */
  3767. write_reg(info, TRC0, 0x10);
  3768. /* TRC1 Transmit Ready Control 1
  3769. *
  3770. * 07..05 Reserved, must be 0
  3771. * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1e = 31 bytes (full-1)
  3772. */
  3773. write_reg(info, TRC1, 0x1e);
  3774. /* CTL, MSCI control register
  3775. *
  3776. * 07..06 Reserved, set to 0
  3777. * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
  3778. * 04 IDLC, idle control, 0=mark 1=idle register
  3779. * 03 BRK, break, 0=off 1 =on (async)
  3780. * 02 SYNCLD, sync char load enable (BSC) 1=enabled
  3781. * 01 GOP, go active on poll (LOOP mode) 1=enabled
  3782. * 00 RTS, RTS output control, 0=active 1=inactive
  3783. *
  3784. * 0001 0001
  3785. */
  3786. RegValue = 0x10;
  3787. if (!(info->serial_signals & SerialSignal_RTS))
  3788. RegValue |= 0x01;
  3789. write_reg(info, CTL, RegValue);
  3790. /* enable status interrupts */
  3791. info->ie0_value |= TXINTE + RXINTE;
  3792. write_reg(info, IE0, info->ie0_value);
  3793. /* enable break detect interrupt */
  3794. info->ie1_value = BRKD;
  3795. write_reg(info, IE1, info->ie1_value);
  3796. /* enable rx overrun interrupt */
  3797. info->ie2_value = OVRN;
  3798. write_reg(info, IE2, info->ie2_value);
  3799. set_rate( info, info->params.data_rate * 16 );
  3800. }
  3801. /* Program the SCA for HDLC communications.
  3802. */
  3803. void hdlc_mode(SLMP_INFO *info)
  3804. {
  3805. unsigned char RegValue;
  3806. u32 DpllDivisor;
  3807. // Can't use DPLL because SCA outputs recovered clock on RxC when
  3808. // DPLL mode selected. This causes output contention with RxC receiver.
  3809. // Use of DPLL would require external hardware to disable RxC receiver
  3810. // when DPLL mode selected.
  3811. info->params.flags &= ~(HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL);
  3812. /* disable DMA interrupts */
  3813. write_reg(info, TXDMA + DIR, 0);
  3814. write_reg(info, RXDMA + DIR, 0);
  3815. /* MD0, Mode Register 0
  3816. *
  3817. * 07..05 PRCTL<2..0>, Protocol Mode, 100=HDLC
  3818. * 04 AUTO, Auto-enable (RTS/CTS/DCD)
  3819. * 03 Reserved, must be 0
  3820. * 02 CRCCC, CRC Calculation, 1=enabled
  3821. * 01 CRC1, CRC selection, 0=CRC-16,1=CRC-CCITT-16
  3822. * 00 CRC0, CRC initial value, 1 = all 1s
  3823. *
  3824. * 1000 0001
  3825. */
  3826. RegValue = 0x81;
  3827. if (info->params.flags & HDLC_FLAG_AUTO_CTS)
  3828. RegValue |= BIT4;
  3829. if (info->params.flags & HDLC_FLAG_AUTO_DCD)
  3830. RegValue |= BIT4;
  3831. if (info->params.crc_type == HDLC_CRC_16_CCITT)
  3832. RegValue |= BIT2 + BIT1;
  3833. write_reg(info, MD0, RegValue);
  3834. /* MD1, Mode Register 1
  3835. *
  3836. * 07..06 ADDRS<1..0>, Address detect, 00=no addr check
  3837. * 05..04 TXCHR<1..0>, tx char size, 00=8 bits
  3838. * 03..02 RXCHR<1..0>, rx char size, 00=8 bits
  3839. * 01..00 PMPM<1..0>, Parity mode, 00=no parity
  3840. *
  3841. * 0000 0000
  3842. */
  3843. RegValue = 0x00;
  3844. write_reg(info, MD1, RegValue);
  3845. /* MD2, Mode Register 2
  3846. *
  3847. * 07 NRZFM, 0=NRZ, 1=FM
  3848. * 06..05 CODE<1..0> Encoding, 00=NRZ
  3849. * 04..03 DRATE<1..0> DPLL Divisor, 00=8
  3850. * 02 Reserved, must be 0
  3851. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3852. *
  3853. * 0000 0000
  3854. */
  3855. RegValue = 0x00;
  3856. switch(info->params.encoding) {
  3857. case HDLC_ENCODING_NRZI: RegValue |= BIT5; break;
  3858. case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT7 + BIT5; break; /* aka FM1 */
  3859. case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT7 + BIT6; break; /* aka FM0 */
  3860. case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT7; break; /* aka Manchester */
  3861. #if 0
  3862. case HDLC_ENCODING_NRZB: /* not supported */
  3863. case HDLC_ENCODING_NRZI_MARK: /* not supported */
  3864. case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: /* not supported */
  3865. #endif
  3866. }
  3867. if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
  3868. DpllDivisor = 16;
  3869. RegValue |= BIT3;
  3870. } else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
  3871. DpllDivisor = 8;
  3872. } else {
  3873. DpllDivisor = 32;
  3874. RegValue |= BIT4;
  3875. }
  3876. write_reg(info, MD2, RegValue);
  3877. /* RXS, Receive clock source
  3878. *
  3879. * 07 Reserved, must be 0
  3880. * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
  3881. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3882. */
  3883. RegValue=0;
  3884. if (info->params.flags & HDLC_FLAG_RXC_BRG)
  3885. RegValue |= BIT6;
  3886. if (info->params.flags & HDLC_FLAG_RXC_DPLL)
  3887. RegValue |= BIT6 + BIT5;
  3888. write_reg(info, RXS, RegValue);
  3889. /* TXS, Transmit clock source
  3890. *
  3891. * 07 Reserved, must be 0
  3892. * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
  3893. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3894. */
  3895. RegValue=0;
  3896. if (info->params.flags & HDLC_FLAG_TXC_BRG)
  3897. RegValue |= BIT6;
  3898. if (info->params.flags & HDLC_FLAG_TXC_DPLL)
  3899. RegValue |= BIT6 + BIT5;
  3900. write_reg(info, TXS, RegValue);
  3901. if (info->params.flags & HDLC_FLAG_RXC_DPLL)
  3902. set_rate(info, info->params.clock_speed * DpllDivisor);
  3903. else
  3904. set_rate(info, info->params.clock_speed);
  3905. /* GPDATA (General Purpose I/O Data Register)
  3906. *
  3907. * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
  3908. */
  3909. if (info->params.flags & HDLC_FLAG_TXC_BRG)
  3910. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3911. else
  3912. info->port_array[0]->ctrlreg_value &= ~(BIT0 << (info->port_num * 2));
  3913. write_control_reg(info);
  3914. /* RRC Receive Ready Control 0
  3915. *
  3916. * 07..05 Reserved, must be 0
  3917. * 04..00 RRC<4..0> Rx FIFO trigger active
  3918. */
  3919. write_reg(info, RRC, rx_active_fifo_level);
  3920. /* TRC0 Transmit Ready Control 0
  3921. *
  3922. * 07..05 Reserved, must be 0
  3923. * 04..00 TRC<4..0> Tx FIFO trigger active
  3924. */
  3925. write_reg(info, TRC0, tx_active_fifo_level);
  3926. /* TRC1 Transmit Ready Control 1
  3927. *
  3928. * 07..05 Reserved, must be 0
  3929. * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1f = 32 bytes (full)
  3930. */
  3931. write_reg(info, TRC1, (unsigned char)(tx_negate_fifo_level - 1));
  3932. /* DMR, DMA Mode Register
  3933. *
  3934. * 07..05 Reserved, must be 0
  3935. * 04 TMOD, Transfer Mode: 1=chained-block
  3936. * 03 Reserved, must be 0
  3937. * 02 NF, Number of Frames: 1=multi-frame
  3938. * 01 CNTE, Frame End IRQ Counter enable: 0=disabled
  3939. * 00 Reserved, must be 0
  3940. *
  3941. * 0001 0100
  3942. */
  3943. write_reg(info, TXDMA + DMR, 0x14);
  3944. write_reg(info, RXDMA + DMR, 0x14);
  3945. /* Set chain pointer base (upper 8 bits of 24 bit addr) */
  3946. write_reg(info, RXDMA + CPB,
  3947. (unsigned char)(info->buffer_list_phys >> 16));
  3948. /* Set chain pointer base (upper 8 bits of 24 bit addr) */
  3949. write_reg(info, TXDMA + CPB,
  3950. (unsigned char)(info->buffer_list_phys >> 16));
  3951. /* enable status interrupts. other code enables/disables
  3952. * the individual sources for these two interrupt classes.
  3953. */
  3954. info->ie0_value |= TXINTE + RXINTE;
  3955. write_reg(info, IE0, info->ie0_value);
  3956. /* CTL, MSCI control register
  3957. *
  3958. * 07..06 Reserved, set to 0
  3959. * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
  3960. * 04 IDLC, idle control, 0=mark 1=idle register
  3961. * 03 BRK, break, 0=off 1 =on (async)
  3962. * 02 SYNCLD, sync char load enable (BSC) 1=enabled
  3963. * 01 GOP, go active on poll (LOOP mode) 1=enabled
  3964. * 00 RTS, RTS output control, 0=active 1=inactive
  3965. *
  3966. * 0001 0001
  3967. */
  3968. RegValue = 0x10;
  3969. if (!(info->serial_signals & SerialSignal_RTS))
  3970. RegValue |= 0x01;
  3971. write_reg(info, CTL, RegValue);
  3972. /* preamble not supported ! */
  3973. tx_set_idle(info);
  3974. tx_stop(info);
  3975. rx_stop(info);
  3976. set_rate(info, info->params.clock_speed);
  3977. if (info->params.loopback)
  3978. enable_loopback(info,1);
  3979. }
  3980. /* Set the transmit HDLC idle mode
  3981. */
  3982. void tx_set_idle(SLMP_INFO *info)
  3983. {
  3984. unsigned char RegValue = 0xff;
  3985. /* Map API idle mode to SCA register bits */
  3986. switch(info->idle_mode) {
  3987. case HDLC_TXIDLE_FLAGS: RegValue = 0x7e; break;
  3988. case HDLC_TXIDLE_ALT_ZEROS_ONES: RegValue = 0xaa; break;
  3989. case HDLC_TXIDLE_ZEROS: RegValue = 0x00; break;
  3990. case HDLC_TXIDLE_ONES: RegValue = 0xff; break;
  3991. case HDLC_TXIDLE_ALT_MARK_SPACE: RegValue = 0xaa; break;
  3992. case HDLC_TXIDLE_SPACE: RegValue = 0x00; break;
  3993. case HDLC_TXIDLE_MARK: RegValue = 0xff; break;
  3994. }
  3995. write_reg(info, IDL, RegValue);
  3996. }
  3997. /* Query the adapter for the state of the V24 status (input) signals.
  3998. */
  3999. void get_signals(SLMP_INFO *info)
  4000. {
  4001. u16 status = read_reg(info, SR3);
  4002. u16 gpstatus = read_status_reg(info);
  4003. u16 testbit;
  4004. /* clear all serial signals except DTR and RTS */
  4005. info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
  4006. /* set serial signal bits to reflect MISR */
  4007. if (!(status & BIT3))
  4008. info->serial_signals |= SerialSignal_CTS;
  4009. if ( !(status & BIT2))
  4010. info->serial_signals |= SerialSignal_DCD;
  4011. testbit = BIT1 << (info->port_num * 2); // Port 0..3 RI is GPDATA<1,3,5,7>
  4012. if (!(gpstatus & testbit))
  4013. info->serial_signals |= SerialSignal_RI;
  4014. testbit = BIT0 << (info->port_num * 2); // Port 0..3 DSR is GPDATA<0,2,4,6>
  4015. if (!(gpstatus & testbit))
  4016. info->serial_signals |= SerialSignal_DSR;
  4017. }
  4018. /* Set the state of DTR and RTS based on contents of
  4019. * serial_signals member of device context.
  4020. */
  4021. void set_signals(SLMP_INFO *info)
  4022. {
  4023. unsigned char RegValue;
  4024. u16 EnableBit;
  4025. RegValue = read_reg(info, CTL);
  4026. if (info->serial_signals & SerialSignal_RTS)
  4027. RegValue &= ~BIT0;
  4028. else
  4029. RegValue |= BIT0;
  4030. write_reg(info, CTL, RegValue);
  4031. // Port 0..3 DTR is ctrl reg <1,3,5,7>
  4032. EnableBit = BIT1 << (info->port_num*2);
  4033. if (info->serial_signals & SerialSignal_DTR)
  4034. info->port_array[0]->ctrlreg_value &= ~EnableBit;
  4035. else
  4036. info->port_array[0]->ctrlreg_value |= EnableBit;
  4037. write_control_reg(info);
  4038. }
  4039. /*******************/
  4040. /* DMA Buffer Code */
  4041. /*******************/
  4042. /* Set the count for all receive buffers to SCABUFSIZE
  4043. * and set the current buffer to the first buffer. This effectively
  4044. * makes all buffers free and discards any data in buffers.
  4045. */
  4046. void rx_reset_buffers(SLMP_INFO *info)
  4047. {
  4048. rx_free_frame_buffers(info, 0, info->rx_buf_count - 1);
  4049. }
  4050. /* Free the buffers used by a received frame
  4051. *
  4052. * info pointer to device instance data
  4053. * first index of 1st receive buffer of frame
  4054. * last index of last receive buffer of frame
  4055. */
  4056. void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last)
  4057. {
  4058. int done = 0;
  4059. while(!done) {
  4060. /* reset current buffer for reuse */
  4061. info->rx_buf_list[first].status = 0xff;
  4062. if (first == last) {
  4063. done = 1;
  4064. /* set new last rx descriptor address */
  4065. write_reg16(info, RXDMA + EDA, info->rx_buf_list_ex[first].phys_entry);
  4066. }
  4067. first++;
  4068. if (first == info->rx_buf_count)
  4069. first = 0;
  4070. }
  4071. /* set current buffer to next buffer after last buffer of frame */
  4072. info->current_rx_buf = first;
  4073. }
  4074. /* Return a received frame from the receive DMA buffers.
  4075. * Only frames received without errors are returned.
  4076. *
  4077. * Return Value: 1 if frame returned, otherwise 0
  4078. */
  4079. int rx_get_frame(SLMP_INFO *info)
  4080. {
  4081. unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
  4082. unsigned short status;
  4083. unsigned int framesize = 0;
  4084. int ReturnCode = 0;
  4085. unsigned long flags;
  4086. struct tty_struct *tty = info->tty;
  4087. unsigned char addr_field = 0xff;
  4088. SCADESC *desc;
  4089. SCADESC_EX *desc_ex;
  4090. CheckAgain:
  4091. /* assume no frame returned, set zero length */
  4092. framesize = 0;
  4093. addr_field = 0xff;
  4094. /*
  4095. * current_rx_buf points to the 1st buffer of the next available
  4096. * receive frame. To find the last buffer of the frame look for
  4097. * a non-zero status field in the buffer entries. (The status
  4098. * field is set by the 16C32 after completing a receive frame.
  4099. */
  4100. StartIndex = EndIndex = info->current_rx_buf;
  4101. for ( ;; ) {
  4102. desc = &info->rx_buf_list[EndIndex];
  4103. desc_ex = &info->rx_buf_list_ex[EndIndex];
  4104. if (desc->status == 0xff)
  4105. goto Cleanup; /* current desc still in use, no frames available */
  4106. if (framesize == 0 && info->params.addr_filter != 0xff)
  4107. addr_field = desc_ex->virt_addr[0];
  4108. framesize += desc->length;
  4109. /* Status != 0 means last buffer of frame */
  4110. if (desc->status)
  4111. break;
  4112. EndIndex++;
  4113. if (EndIndex == info->rx_buf_count)
  4114. EndIndex = 0;
  4115. if (EndIndex == info->current_rx_buf) {
  4116. /* all buffers have been 'used' but none mark */
  4117. /* the end of a frame. Reset buffers and receiver. */
  4118. if ( info->rx_enabled ){
  4119. spin_lock_irqsave(&info->lock,flags);
  4120. rx_start(info);
  4121. spin_unlock_irqrestore(&info->lock,flags);
  4122. }
  4123. goto Cleanup;
  4124. }
  4125. }
  4126. /* check status of receive frame */
  4127. /* frame status is byte stored after frame data
  4128. *
  4129. * 7 EOM (end of msg), 1 = last buffer of frame
  4130. * 6 Short Frame, 1 = short frame
  4131. * 5 Abort, 1 = frame aborted
  4132. * 4 Residue, 1 = last byte is partial
  4133. * 3 Overrun, 1 = overrun occurred during frame reception
  4134. * 2 CRC, 1 = CRC error detected
  4135. *
  4136. */
  4137. status = desc->status;
  4138. /* ignore CRC bit if not using CRC (bit is undefined) */
  4139. /* Note:CRC is not save to data buffer */
  4140. if (info->params.crc_type == HDLC_CRC_NONE)
  4141. status &= ~BIT2;
  4142. if (framesize == 0 ||
  4143. (addr_field != 0xff && addr_field != info->params.addr_filter)) {
  4144. /* discard 0 byte frames, this seems to occur sometime
  4145. * when remote is idling flags.
  4146. */
  4147. rx_free_frame_buffers(info, StartIndex, EndIndex);
  4148. goto CheckAgain;
  4149. }
  4150. if (framesize < 2)
  4151. status |= BIT6;
  4152. if (status & (BIT6+BIT5+BIT3+BIT2)) {
  4153. /* received frame has errors,
  4154. * update counts and mark frame size as 0
  4155. */
  4156. if (status & BIT6)
  4157. info->icount.rxshort++;
  4158. else if (status & BIT5)
  4159. info->icount.rxabort++;
  4160. else if (status & BIT3)
  4161. info->icount.rxover++;
  4162. else
  4163. info->icount.rxcrc++;
  4164. framesize = 0;
  4165. #ifdef CONFIG_HDLC
  4166. {
  4167. struct net_device_stats *stats = hdlc_stats(info->netdev);
  4168. stats->rx_errors++;
  4169. stats->rx_frame_errors++;
  4170. }
  4171. #endif
  4172. }
  4173. if ( debug_level >= DEBUG_LEVEL_BH )
  4174. printk("%s(%d):%s rx_get_frame() status=%04X size=%d\n",
  4175. __FILE__,__LINE__,info->device_name,status,framesize);
  4176. if ( debug_level >= DEBUG_LEVEL_DATA )
  4177. trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
  4178. min_t(int, framesize,SCABUFSIZE),0);
  4179. if (framesize) {
  4180. if (framesize > info->max_frame_size)
  4181. info->icount.rxlong++;
  4182. else {
  4183. /* copy dma buffer(s) to contiguous intermediate buffer */
  4184. int copy_count = framesize;
  4185. int index = StartIndex;
  4186. unsigned char *ptmp = info->tmp_rx_buf;
  4187. info->tmp_rx_buf_count = framesize;
  4188. info->icount.rxok++;
  4189. while(copy_count) {
  4190. int partial_count = min(copy_count,SCABUFSIZE);
  4191. memcpy( ptmp,
  4192. info->rx_buf_list_ex[index].virt_addr,
  4193. partial_count );
  4194. ptmp += partial_count;
  4195. copy_count -= partial_count;
  4196. if ( ++index == info->rx_buf_count )
  4197. index = 0;
  4198. }
  4199. #ifdef CONFIG_HDLC
  4200. if (info->netcount)
  4201. hdlcdev_rx(info,info->tmp_rx_buf,framesize);
  4202. else
  4203. #endif
  4204. ldisc_receive_buf(tty,info->tmp_rx_buf,
  4205. info->flag_buf, framesize);
  4206. }
  4207. }
  4208. /* Free the buffers used by this frame. */
  4209. rx_free_frame_buffers( info, StartIndex, EndIndex );
  4210. ReturnCode = 1;
  4211. Cleanup:
  4212. if ( info->rx_enabled && info->rx_overflow ) {
  4213. /* Receiver is enabled, but needs to restarted due to
  4214. * rx buffer overflow. If buffers are empty, restart receiver.
  4215. */
  4216. if (info->rx_buf_list[EndIndex].status == 0xff) {
  4217. spin_lock_irqsave(&info->lock,flags);
  4218. rx_start(info);
  4219. spin_unlock_irqrestore(&info->lock,flags);
  4220. }
  4221. }
  4222. return ReturnCode;
  4223. }
  4224. /* load the transmit DMA buffer with data
  4225. */
  4226. void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count)
  4227. {
  4228. unsigned short copy_count;
  4229. unsigned int i = 0;
  4230. SCADESC *desc;
  4231. SCADESC_EX *desc_ex;
  4232. if ( debug_level >= DEBUG_LEVEL_DATA )
  4233. trace_block(info,buf, min_t(int, count,SCABUFSIZE), 1);
  4234. /* Copy source buffer to one or more DMA buffers, starting with
  4235. * the first transmit dma buffer.
  4236. */
  4237. for(i=0;;)
  4238. {
  4239. copy_count = min_t(unsigned short,count,SCABUFSIZE);
  4240. desc = &info->tx_buf_list[i];
  4241. desc_ex = &info->tx_buf_list_ex[i];
  4242. load_pci_memory(info, desc_ex->virt_addr,buf,copy_count);
  4243. desc->length = copy_count;
  4244. desc->status = 0;
  4245. buf += copy_count;
  4246. count -= copy_count;
  4247. if (!count)
  4248. break;
  4249. i++;
  4250. if (i >= info->tx_buf_count)
  4251. i = 0;
  4252. }
  4253. info->tx_buf_list[i].status = 0x81; /* set EOM and EOT status */
  4254. info->last_tx_buf = ++i;
  4255. }
  4256. int register_test(SLMP_INFO *info)
  4257. {
  4258. static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
  4259. static unsigned int count = sizeof(testval)/sizeof(unsigned char);
  4260. unsigned int i;
  4261. int rc = TRUE;
  4262. unsigned long flags;
  4263. spin_lock_irqsave(&info->lock,flags);
  4264. reset_port(info);
  4265. /* assume failure */
  4266. info->init_error = DiagStatus_AddressFailure;
  4267. /* Write bit patterns to various registers but do it out of */
  4268. /* sync, then read back and verify values. */
  4269. for (i = 0 ; i < count ; i++) {
  4270. write_reg(info, TMC, testval[i]);
  4271. write_reg(info, IDL, testval[(i+1)%count]);
  4272. write_reg(info, SA0, testval[(i+2)%count]);
  4273. write_reg(info, SA1, testval[(i+3)%count]);
  4274. if ( (read_reg(info, TMC) != testval[i]) ||
  4275. (read_reg(info, IDL) != testval[(i+1)%count]) ||
  4276. (read_reg(info, SA0) != testval[(i+2)%count]) ||
  4277. (read_reg(info, SA1) != testval[(i+3)%count]) )
  4278. {
  4279. rc = FALSE;
  4280. break;
  4281. }
  4282. }
  4283. reset_port(info);
  4284. spin_unlock_irqrestore(&info->lock,flags);
  4285. return rc;
  4286. }
  4287. int irq_test(SLMP_INFO *info)
  4288. {
  4289. unsigned long timeout;
  4290. unsigned long flags;
  4291. unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
  4292. spin_lock_irqsave(&info->lock,flags);
  4293. reset_port(info);
  4294. /* assume failure */
  4295. info->init_error = DiagStatus_IrqFailure;
  4296. info->irq_occurred = FALSE;
  4297. /* setup timer0 on SCA0 to interrupt */
  4298. /* IER2<7..4> = timer<3..0> interrupt enables (1=enabled) */
  4299. write_reg(info, IER2, (unsigned char)((info->port_num & 1) ? BIT6 : BIT4));
  4300. write_reg(info, (unsigned char)(timer + TEPR), 0); /* timer expand prescale */
  4301. write_reg16(info, (unsigned char)(timer + TCONR), 1); /* timer constant */
  4302. /* TMCS, Timer Control/Status Register
  4303. *
  4304. * 07 CMF, Compare match flag (read only) 1=match
  4305. * 06 ECMI, CMF Interrupt Enable: 1=enabled
  4306. * 05 Reserved, must be 0
  4307. * 04 TME, Timer Enable
  4308. * 03..00 Reserved, must be 0
  4309. *
  4310. * 0101 0000
  4311. */
  4312. write_reg(info, (unsigned char)(timer + TMCS), 0x50);
  4313. spin_unlock_irqrestore(&info->lock,flags);
  4314. timeout=100;
  4315. while( timeout-- && !info->irq_occurred ) {
  4316. msleep_interruptible(10);
  4317. }
  4318. spin_lock_irqsave(&info->lock,flags);
  4319. reset_port(info);
  4320. spin_unlock_irqrestore(&info->lock,flags);
  4321. return info->irq_occurred;
  4322. }
  4323. /* initialize individual SCA device (2 ports)
  4324. */
  4325. static int sca_init(SLMP_INFO *info)
  4326. {
  4327. /* set wait controller to single mem partition (low), no wait states */
  4328. write_reg(info, PABR0, 0); /* wait controller addr boundary 0 */
  4329. write_reg(info, PABR1, 0); /* wait controller addr boundary 1 */
  4330. write_reg(info, WCRL, 0); /* wait controller low range */
  4331. write_reg(info, WCRM, 0); /* wait controller mid range */
  4332. write_reg(info, WCRH, 0); /* wait controller high range */
  4333. /* DPCR, DMA Priority Control
  4334. *
  4335. * 07..05 Not used, must be 0
  4336. * 04 BRC, bus release condition: 0=all transfers complete
  4337. * 03 CCC, channel change condition: 0=every cycle
  4338. * 02..00 PR<2..0>, priority 100=round robin
  4339. *
  4340. * 00000100 = 0x04
  4341. */
  4342. write_reg(info, DPCR, dma_priority);
  4343. /* DMA Master Enable, BIT7: 1=enable all channels */
  4344. write_reg(info, DMER, 0x80);
  4345. /* enable all interrupt classes */
  4346. write_reg(info, IER0, 0xff); /* TxRDY,RxRDY,TxINT,RxINT (ports 0-1) */
  4347. write_reg(info, IER1, 0xff); /* DMIB,DMIA (channels 0-3) */
  4348. write_reg(info, IER2, 0xf0); /* TIRQ (timers 0-3) */
  4349. /* ITCR, interrupt control register
  4350. * 07 IPC, interrupt priority, 0=MSCI->DMA
  4351. * 06..05 IAK<1..0>, Acknowledge cycle, 00=non-ack cycle
  4352. * 04 VOS, Vector Output, 0=unmodified vector
  4353. * 03..00 Reserved, must be 0
  4354. */
  4355. write_reg(info, ITCR, 0);
  4356. return TRUE;
  4357. }
  4358. /* initialize adapter hardware
  4359. */
  4360. int init_adapter(SLMP_INFO *info)
  4361. {
  4362. int i;
  4363. /* Set BIT30 of Local Control Reg 0x50 to reset SCA */
  4364. volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
  4365. u32 readval;
  4366. info->misc_ctrl_value |= BIT30;
  4367. *MiscCtrl = info->misc_ctrl_value;
  4368. /*
  4369. * Force at least 170ns delay before clearing
  4370. * reset bit. Each read from LCR takes at least
  4371. * 30ns so 10 times for 300ns to be safe.
  4372. */
  4373. for(i=0;i<10;i++)
  4374. readval = *MiscCtrl;
  4375. info->misc_ctrl_value &= ~BIT30;
  4376. *MiscCtrl = info->misc_ctrl_value;
  4377. /* init control reg (all DTRs off, all clksel=input) */
  4378. info->ctrlreg_value = 0xaa;
  4379. write_control_reg(info);
  4380. {
  4381. volatile u32 *LCR1BRDR = (u32 *)(info->lcr_base + 0x2c);
  4382. lcr1_brdr_value &= ~(BIT5 + BIT4 + BIT3);
  4383. switch(read_ahead_count)
  4384. {
  4385. case 16:
  4386. lcr1_brdr_value |= BIT5 + BIT4 + BIT3;
  4387. break;
  4388. case 8:
  4389. lcr1_brdr_value |= BIT5 + BIT4;
  4390. break;
  4391. case 4:
  4392. lcr1_brdr_value |= BIT5 + BIT3;
  4393. break;
  4394. case 0:
  4395. lcr1_brdr_value |= BIT5;
  4396. break;
  4397. }
  4398. *LCR1BRDR = lcr1_brdr_value;
  4399. *MiscCtrl = misc_ctrl_value;
  4400. }
  4401. sca_init(info->port_array[0]);
  4402. sca_init(info->port_array[2]);
  4403. return TRUE;
  4404. }
  4405. /* Loopback an HDLC frame to test the hardware
  4406. * interrupt and DMA functions.
  4407. */
  4408. int loopback_test(SLMP_INFO *info)
  4409. {
  4410. #define TESTFRAMESIZE 20
  4411. unsigned long timeout;
  4412. u16 count = TESTFRAMESIZE;
  4413. unsigned char buf[TESTFRAMESIZE];
  4414. int rc = FALSE;
  4415. unsigned long flags;
  4416. struct tty_struct *oldtty = info->tty;
  4417. u32 speed = info->params.clock_speed;
  4418. info->params.clock_speed = 3686400;
  4419. info->tty = NULL;
  4420. /* assume failure */
  4421. info->init_error = DiagStatus_DmaFailure;
  4422. /* build and send transmit frame */
  4423. for (count = 0; count < TESTFRAMESIZE;++count)
  4424. buf[count] = (unsigned char)count;
  4425. memset(info->tmp_rx_buf,0,TESTFRAMESIZE);
  4426. /* program hardware for HDLC and enabled receiver */
  4427. spin_lock_irqsave(&info->lock,flags);
  4428. hdlc_mode(info);
  4429. enable_loopback(info,1);
  4430. rx_start(info);
  4431. info->tx_count = count;
  4432. tx_load_dma_buffer(info,buf,count);
  4433. tx_start(info);
  4434. spin_unlock_irqrestore(&info->lock,flags);
  4435. /* wait for receive complete */
  4436. /* Set a timeout for waiting for interrupt. */
  4437. for ( timeout = 100; timeout; --timeout ) {
  4438. msleep_interruptible(10);
  4439. if (rx_get_frame(info)) {
  4440. rc = TRUE;
  4441. break;
  4442. }
  4443. }
  4444. /* verify received frame length and contents */
  4445. if (rc == TRUE &&
  4446. ( info->tmp_rx_buf_count != count ||
  4447. memcmp(buf, info->tmp_rx_buf,count))) {
  4448. rc = FALSE;
  4449. }
  4450. spin_lock_irqsave(&info->lock,flags);
  4451. reset_adapter(info);
  4452. spin_unlock_irqrestore(&info->lock,flags);
  4453. info->params.clock_speed = speed;
  4454. info->tty = oldtty;
  4455. return rc;
  4456. }
  4457. /* Perform diagnostics on hardware
  4458. */
  4459. int adapter_test( SLMP_INFO *info )
  4460. {
  4461. unsigned long flags;
  4462. if ( debug_level >= DEBUG_LEVEL_INFO )
  4463. printk( "%s(%d):Testing device %s\n",
  4464. __FILE__,__LINE__,info->device_name );
  4465. spin_lock_irqsave(&info->lock,flags);
  4466. init_adapter(info);
  4467. spin_unlock_irqrestore(&info->lock,flags);
  4468. info->port_array[0]->port_count = 0;
  4469. if ( register_test(info->port_array[0]) &&
  4470. register_test(info->port_array[1])) {
  4471. info->port_array[0]->port_count = 2;
  4472. if ( register_test(info->port_array[2]) &&
  4473. register_test(info->port_array[3]) )
  4474. info->port_array[0]->port_count += 2;
  4475. }
  4476. else {
  4477. printk( "%s(%d):Register test failure for device %s Addr=%08lX\n",
  4478. __FILE__,__LINE__,info->device_name, (unsigned long)(info->phys_sca_base));
  4479. return -ENODEV;
  4480. }
  4481. if ( !irq_test(info->port_array[0]) ||
  4482. !irq_test(info->port_array[1]) ||
  4483. (info->port_count == 4 && !irq_test(info->port_array[2])) ||
  4484. (info->port_count == 4 && !irq_test(info->port_array[3]))) {
  4485. printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
  4486. __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
  4487. return -ENODEV;
  4488. }
  4489. if (!loopback_test(info->port_array[0]) ||
  4490. !loopback_test(info->port_array[1]) ||
  4491. (info->port_count == 4 && !loopback_test(info->port_array[2])) ||
  4492. (info->port_count == 4 && !loopback_test(info->port_array[3]))) {
  4493. printk( "%s(%d):DMA test failure for device %s\n",
  4494. __FILE__,__LINE__,info->device_name);
  4495. return -ENODEV;
  4496. }
  4497. if ( debug_level >= DEBUG_LEVEL_INFO )
  4498. printk( "%s(%d):device %s passed diagnostics\n",
  4499. __FILE__,__LINE__,info->device_name );
  4500. info->port_array[0]->init_error = 0;
  4501. info->port_array[1]->init_error = 0;
  4502. if ( info->port_count > 2 ) {
  4503. info->port_array[2]->init_error = 0;
  4504. info->port_array[3]->init_error = 0;
  4505. }
  4506. return 0;
  4507. }
  4508. /* Test the shared memory on a PCI adapter.
  4509. */
  4510. int memory_test(SLMP_INFO *info)
  4511. {
  4512. static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
  4513. 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
  4514. unsigned long count = sizeof(testval)/sizeof(unsigned long);
  4515. unsigned long i;
  4516. unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
  4517. unsigned long * addr = (unsigned long *)info->memory_base;
  4518. /* Test data lines with test pattern at one location. */
  4519. for ( i = 0 ; i < count ; i++ ) {
  4520. *addr = testval[i];
  4521. if ( *addr != testval[i] )
  4522. return FALSE;
  4523. }
  4524. /* Test address lines with incrementing pattern over */
  4525. /* entire address range. */
  4526. for ( i = 0 ; i < limit ; i++ ) {
  4527. *addr = i * 4;
  4528. addr++;
  4529. }
  4530. addr = (unsigned long *)info->memory_base;
  4531. for ( i = 0 ; i < limit ; i++ ) {
  4532. if ( *addr != i * 4 )
  4533. return FALSE;
  4534. addr++;
  4535. }
  4536. memset( info->memory_base, 0, SCA_MEM_SIZE );
  4537. return TRUE;
  4538. }
  4539. /* Load data into PCI adapter shared memory.
  4540. *
  4541. * The PCI9050 releases control of the local bus
  4542. * after completing the current read or write operation.
  4543. *
  4544. * While the PCI9050 write FIFO not empty, the
  4545. * PCI9050 treats all of the writes as a single transaction
  4546. * and does not release the bus. This causes DMA latency problems
  4547. * at high speeds when copying large data blocks to the shared memory.
  4548. *
  4549. * This function breaks a write into multiple transations by
  4550. * interleaving a read which flushes the write FIFO and 'completes'
  4551. * the write transation. This allows any pending DMA request to gain control
  4552. * of the local bus in a timely fasion.
  4553. */
  4554. void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count)
  4555. {
  4556. /* A load interval of 16 allows for 4 32-bit writes at */
  4557. /* 136ns each for a maximum latency of 542ns on the local bus.*/
  4558. unsigned short interval = count / sca_pci_load_interval;
  4559. unsigned short i;
  4560. for ( i = 0 ; i < interval ; i++ )
  4561. {
  4562. memcpy(dest, src, sca_pci_load_interval);
  4563. read_status_reg(info);
  4564. dest += sca_pci_load_interval;
  4565. src += sca_pci_load_interval;
  4566. }
  4567. memcpy(dest, src, count % sca_pci_load_interval);
  4568. }
  4569. void trace_block(SLMP_INFO *info,const char* data, int count, int xmit)
  4570. {
  4571. int i;
  4572. int linecount;
  4573. if (xmit)
  4574. printk("%s tx data:\n",info->device_name);
  4575. else
  4576. printk("%s rx data:\n",info->device_name);
  4577. while(count) {
  4578. if (count > 16)
  4579. linecount = 16;
  4580. else
  4581. linecount = count;
  4582. for(i=0;i<linecount;i++)
  4583. printk("%02X ",(unsigned char)data[i]);
  4584. for(;i<17;i++)
  4585. printk(" ");
  4586. for(i=0;i<linecount;i++) {
  4587. if (data[i]>=040 && data[i]<=0176)
  4588. printk("%c",data[i]);
  4589. else
  4590. printk(".");
  4591. }
  4592. printk("\n");
  4593. data += linecount;
  4594. count -= linecount;
  4595. }
  4596. } /* end of trace_block() */
  4597. /* called when HDLC frame times out
  4598. * update stats and do tx completion processing
  4599. */
  4600. void tx_timeout(unsigned long context)
  4601. {
  4602. SLMP_INFO *info = (SLMP_INFO*)context;
  4603. unsigned long flags;
  4604. if ( debug_level >= DEBUG_LEVEL_INFO )
  4605. printk( "%s(%d):%s tx_timeout()\n",
  4606. __FILE__,__LINE__,info->device_name);
  4607. if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
  4608. info->icount.txtimeout++;
  4609. }
  4610. spin_lock_irqsave(&info->lock,flags);
  4611. info->tx_active = 0;
  4612. info->tx_count = info->tx_put = info->tx_get = 0;
  4613. spin_unlock_irqrestore(&info->lock,flags);
  4614. #ifdef CONFIG_HDLC
  4615. if (info->netcount)
  4616. hdlcdev_tx_done(info);
  4617. else
  4618. #endif
  4619. bh_transmit(info);
  4620. }
  4621. /* called to periodically check the DSR/RI modem signal input status
  4622. */
  4623. void status_timeout(unsigned long context)
  4624. {
  4625. u16 status = 0;
  4626. SLMP_INFO *info = (SLMP_INFO*)context;
  4627. unsigned long flags;
  4628. unsigned char delta;
  4629. spin_lock_irqsave(&info->lock,flags);
  4630. get_signals(info);
  4631. spin_unlock_irqrestore(&info->lock,flags);
  4632. /* check for DSR/RI state change */
  4633. delta = info->old_signals ^ info->serial_signals;
  4634. info->old_signals = info->serial_signals;
  4635. if (delta & SerialSignal_DSR)
  4636. status |= MISCSTATUS_DSR_LATCHED|(info->serial_signals&SerialSignal_DSR);
  4637. if (delta & SerialSignal_RI)
  4638. status |= MISCSTATUS_RI_LATCHED|(info->serial_signals&SerialSignal_RI);
  4639. if (delta & SerialSignal_DCD)
  4640. status |= MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD);
  4641. if (delta & SerialSignal_CTS)
  4642. status |= MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS);
  4643. if (status)
  4644. isr_io_pin(info,status);
  4645. info->status_timer.data = (unsigned long)info;
  4646. info->status_timer.function = status_timeout;
  4647. info->status_timer.expires = jiffies + msecs_to_jiffies(10);
  4648. add_timer(&info->status_timer);
  4649. }
  4650. /* Register Access Routines -
  4651. * All registers are memory mapped
  4652. */
  4653. #define CALC_REGADDR() \
  4654. unsigned char * RegAddr = (unsigned char*)(info->sca_base + Addr); \
  4655. if (info->port_num > 1) \
  4656. RegAddr += 256; /* port 0-1 SCA0, 2-3 SCA1 */ \
  4657. if ( info->port_num & 1) { \
  4658. if (Addr > 0x7f) \
  4659. RegAddr += 0x40; /* DMA access */ \
  4660. else if (Addr > 0x1f && Addr < 0x60) \
  4661. RegAddr += 0x20; /* MSCI access */ \
  4662. }
  4663. unsigned char read_reg(SLMP_INFO * info, unsigned char Addr)
  4664. {
  4665. CALC_REGADDR();
  4666. return *RegAddr;
  4667. }
  4668. void write_reg(SLMP_INFO * info, unsigned char Addr, unsigned char Value)
  4669. {
  4670. CALC_REGADDR();
  4671. *RegAddr = Value;
  4672. }
  4673. u16 read_reg16(SLMP_INFO * info, unsigned char Addr)
  4674. {
  4675. CALC_REGADDR();
  4676. return *((u16 *)RegAddr);
  4677. }
  4678. void write_reg16(SLMP_INFO * info, unsigned char Addr, u16 Value)
  4679. {
  4680. CALC_REGADDR();
  4681. *((u16 *)RegAddr) = Value;
  4682. }
  4683. unsigned char read_status_reg(SLMP_INFO * info)
  4684. {
  4685. unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
  4686. return *RegAddr;
  4687. }
  4688. void write_control_reg(SLMP_INFO * info)
  4689. {
  4690. unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
  4691. *RegAddr = info->port_array[0]->ctrlreg_value;
  4692. }
  4693. static int __devinit synclinkmp_init_one (struct pci_dev *dev,
  4694. const struct pci_device_id *ent)
  4695. {
  4696. if (pci_enable_device(dev)) {
  4697. printk("error enabling pci device %p\n", dev);
  4698. return -EIO;
  4699. }
  4700. device_init( ++synclinkmp_adapter_count, dev );
  4701. return 0;
  4702. }
  4703. static void __devexit synclinkmp_remove_one (struct pci_dev *dev)
  4704. {
  4705. }