synclinkmp.c 147 KB

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