synclinkmp.c 148 KB

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