synclinkmp.c 146 KB

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