hfcmulti.c 153 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586
  1. /*
  2. * hfcmulti.c low level driver for hfc-4s/hfc-8s/hfc-e1 based cards
  3. *
  4. * Author Andreas Eversberg (jolly@eversberg.eu)
  5. * ported to mqueue mechanism:
  6. * Peter Sprenger (sprengermoving-bytes.de)
  7. *
  8. * inspired by existing hfc-pci driver:
  9. * Copyright 1999 by Werner Cornelius (werner@isdn-development.de)
  10. * Copyright 2008 by Karsten Keil (kkeil@suse.de)
  11. * Copyright 2008 by Andreas Eversberg (jolly@eversberg.eu)
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. *
  28. * Thanks to Cologne Chip AG for this great controller!
  29. */
  30. /*
  31. * module parameters:
  32. * type:
  33. * By default (0), the card is automatically detected.
  34. * Or use the following combinations:
  35. * Bit 0-7 = 0x00001 = HFC-E1 (1 port)
  36. * or Bit 0-7 = 0x00004 = HFC-4S (4 ports)
  37. * or Bit 0-7 = 0x00008 = HFC-8S (8 ports)
  38. * Bit 8 = 0x00100 = uLaw (instead of aLaw)
  39. * Bit 9 = 0x00200 = Disable DTMF detect on all B-channels via hardware
  40. * Bit 10 = spare
  41. * Bit 11 = 0x00800 = Force PCM bus into slave mode. (otherwhise auto)
  42. * or Bit 12 = 0x01000 = Force PCM bus into master mode. (otherwhise auto)
  43. * Bit 13 = spare
  44. * Bit 14 = 0x04000 = Use external ram (128K)
  45. * Bit 15 = 0x08000 = Use external ram (512K)
  46. * Bit 16 = 0x10000 = Use 64 timeslots instead of 32
  47. * or Bit 17 = 0x20000 = Use 128 timeslots instead of anything else
  48. * Bit 18 = spare
  49. * Bit 19 = 0x80000 = Send the Watchdog a Signal (Dual E1 with Watchdog)
  50. * (all other bits are reserved and shall be 0)
  51. * example: 0x20204 one HFC-4S with dtmf detection and 128 timeslots on PCM
  52. * bus (PCM master)
  53. *
  54. * port: (optional or required for all ports on all installed cards)
  55. * HFC-4S/HFC-8S only bits:
  56. * Bit 0 = 0x001 = Use master clock for this S/T interface
  57. * (ony once per chip).
  58. * Bit 1 = 0x002 = transmitter line setup (non capacitive mode)
  59. * Don't use this unless you know what you are doing!
  60. * Bit 2 = 0x004 = Disable E-channel. (No E-channel processing)
  61. * example: 0x0001,0x0000,0x0000,0x0000 one HFC-4S with master clock
  62. * received from port 1
  63. *
  64. * HFC-E1 only bits:
  65. * Bit 0 = 0x0001 = interface: 0=copper, 1=optical
  66. * Bit 1 = 0x0002 = reserved (later for 32 B-channels transparent mode)
  67. * Bit 2 = 0x0004 = Report LOS
  68. * Bit 3 = 0x0008 = Report AIS
  69. * Bit 4 = 0x0010 = Report SLIP
  70. * Bit 5 = 0x0020 = Report RDI
  71. * Bit 8 = 0x0100 = Turn off CRC-4 Multiframe Mode, use double frame
  72. * mode instead.
  73. * Bit 9 = 0x0200 = Force get clock from interface, even in NT mode.
  74. * or Bit 10 = 0x0400 = Force put clock to interface, even in TE mode.
  75. * Bit 11 = 0x0800 = Use direct RX clock for PCM sync rather than PLL.
  76. * (E1 only)
  77. * Bit 12-13 = 0xX000 = elastic jitter buffer (1-3), Set both bits to 0
  78. * for default.
  79. * (all other bits are reserved and shall be 0)
  80. *
  81. * debug:
  82. * NOTE: only one debug value must be given for all cards
  83. * enable debugging (see hfc_multi.h for debug options)
  84. *
  85. * poll:
  86. * NOTE: only one poll value must be given for all cards
  87. * Give the number of samples for each fifo process.
  88. * By default 128 is used. Decrease to reduce delay, increase to
  89. * reduce cpu load. If unsure, don't mess with it!
  90. * Valid is 8, 16, 32, 64, 128, 256.
  91. *
  92. * pcm:
  93. * NOTE: only one pcm value must be given for every card.
  94. * The PCM bus id tells the mISDNdsp module about the connected PCM bus.
  95. * By default (0), the PCM bus id is 100 for the card that is PCM master.
  96. * If multiple cards are PCM master (because they are not interconnected),
  97. * each card with PCM master will have increasing PCM id.
  98. * All PCM busses with the same ID are expected to be connected and have
  99. * common time slots slots.
  100. * Only one chip of the PCM bus must be master, the others slave.
  101. * -1 means no support of PCM bus not even.
  102. * Omit this value, if all cards are interconnected or none is connected.
  103. * If unsure, don't give this parameter.
  104. *
  105. * dmask and bmask:
  106. * NOTE: One dmask value must be given for every HFC-E1 card.
  107. * If omitted, the E1 card has D-channel on time slot 16, which is default.
  108. * dmask is a 32 bit mask. The bit must be set for an alternate time slot.
  109. * If multiple bits are set, multiple virtual card fragments are created.
  110. * For each bit set, a bmask value must be given. Each bit on the bmask
  111. * value stands for a B-channel. The bmask may not overlap with dmask or
  112. * with other bmask values for that card.
  113. * Example: dmask=0x00020002 bmask=0x0000fffc,0xfffc0000
  114. * This will create one fragment with D-channel on slot 1 with
  115. * B-channels on slots 2..15, and a second fragment with D-channel
  116. * on slot 17 with B-channels on slot 18..31. Slot 16 is unused.
  117. * If bit 0 is set (dmask=0x00000001) the D-channel is on slot 0 and will
  118. * not function.
  119. * Example: dmask=0x00000001 bmask=0xfffffffe
  120. * This will create a port with all 31 usable timeslots as
  121. * B-channels.
  122. * If no bits are set on bmask, no B-channel is created for that fragment.
  123. * Example: dmask=0xfffffffe bmask=0,0,0,0.... (31 0-values for bmask)
  124. * This will create 31 ports with one D-channel only.
  125. * If you don't know how to use it, you don't need it!
  126. *
  127. * iomode:
  128. * NOTE: only one mode value must be given for every card.
  129. * -> See hfc_multi.h for HFC_IO_MODE_* values
  130. * By default, the IO mode is pci memory IO (MEMIO).
  131. * Some cards require specific IO mode, so it cannot be changed.
  132. * It may be useful to set IO mode to register io (REGIO) to solve
  133. * PCI bridge problems.
  134. * If unsure, don't give this parameter.
  135. *
  136. * clockdelay_nt:
  137. * NOTE: only one clockdelay_nt value must be given once for all cards.
  138. * Give the value of the clock control register (A_ST_CLK_DLY)
  139. * of the S/T interfaces in NT mode.
  140. * This register is needed for the TBR3 certification, so don't change it.
  141. *
  142. * clockdelay_te:
  143. * NOTE: only one clockdelay_te value must be given once
  144. * Give the value of the clock control register (A_ST_CLK_DLY)
  145. * of the S/T interfaces in TE mode.
  146. * This register is needed for the TBR3 certification, so don't change it.
  147. *
  148. * clock:
  149. * NOTE: only one clock value must be given once
  150. * Selects interface with clock source for mISDN and applications.
  151. * Set to card number starting with 1. Set to -1 to disable.
  152. * By default, the first card is used as clock source.
  153. *
  154. * hwid:
  155. * NOTE: only one hwid value must be given once
  156. * Enable special embedded devices with XHFC controllers.
  157. */
  158. /*
  159. * debug register access (never use this, it will flood your system log)
  160. * #define HFC_REGISTER_DEBUG
  161. */
  162. #define HFC_MULTI_VERSION "2.03"
  163. #include <linux/interrupt.h>
  164. #include <linux/module.h>
  165. #include <linux/slab.h>
  166. #include <linux/pci.h>
  167. #include <linux/delay.h>
  168. #include <linux/mISDNhw.h>
  169. #include <linux/mISDNdsp.h>
  170. /*
  171. #define IRQCOUNT_DEBUG
  172. #define IRQ_DEBUG
  173. */
  174. #include "hfc_multi.h"
  175. #ifdef ECHOPREP
  176. #include "gaintab.h"
  177. #endif
  178. #define MAX_CARDS 8
  179. #define MAX_PORTS (8 * MAX_CARDS)
  180. #define MAX_FRAGS (32 * MAX_CARDS)
  181. static LIST_HEAD(HFClist);
  182. static spinlock_t HFClock; /* global hfc list lock */
  183. static void ph_state_change(struct dchannel *);
  184. static struct hfc_multi *syncmaster;
  185. static int plxsd_master; /* if we have a master card (yet) */
  186. static spinlock_t plx_lock; /* may not acquire other lock inside */
  187. #define TYP_E1 1
  188. #define TYP_4S 4
  189. #define TYP_8S 8
  190. static int poll_timer = 6; /* default = 128 samples = 16ms */
  191. /* number of POLL_TIMER interrupts for G2 timeout (ca 1s) */
  192. static int nt_t1_count[] = { 3840, 1920, 960, 480, 240, 120, 60, 30 };
  193. #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
  194. #define CLKDEL_NT 0x6c /* CLKDEL in NT mode
  195. (0x60 MUST be included!) */
  196. #define DIP_4S 0x1 /* DIP Switches for Beronet 1S/2S/4S cards */
  197. #define DIP_8S 0x2 /* DIP Switches for Beronet 8S+ cards */
  198. #define DIP_E1 0x3 /* DIP Switches for Beronet E1 cards */
  199. /*
  200. * module stuff
  201. */
  202. static uint type[MAX_CARDS];
  203. static int pcm[MAX_CARDS];
  204. static uint dmask[MAX_CARDS];
  205. static uint bmask[MAX_FRAGS];
  206. static uint iomode[MAX_CARDS];
  207. static uint port[MAX_PORTS];
  208. static uint debug;
  209. static uint poll;
  210. static int clock;
  211. static uint timer;
  212. static uint clockdelay_te = CLKDEL_TE;
  213. static uint clockdelay_nt = CLKDEL_NT;
  214. #define HWID_NONE 0
  215. #define HWID_MINIP4 1
  216. #define HWID_MINIP8 2
  217. #define HWID_MINIP16 3
  218. static uint hwid = HWID_NONE;
  219. static int HFC_cnt, E1_cnt, bmask_cnt, Port_cnt, PCM_cnt = 99;
  220. MODULE_AUTHOR("Andreas Eversberg");
  221. MODULE_LICENSE("GPL");
  222. MODULE_VERSION(HFC_MULTI_VERSION);
  223. module_param(debug, uint, S_IRUGO | S_IWUSR);
  224. module_param(poll, uint, S_IRUGO | S_IWUSR);
  225. module_param(clock, int, S_IRUGO | S_IWUSR);
  226. module_param(timer, uint, S_IRUGO | S_IWUSR);
  227. module_param(clockdelay_te, uint, S_IRUGO | S_IWUSR);
  228. module_param(clockdelay_nt, uint, S_IRUGO | S_IWUSR);
  229. module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR);
  230. module_param_array(pcm, int, NULL, S_IRUGO | S_IWUSR);
  231. module_param_array(dmask, uint, NULL, S_IRUGO | S_IWUSR);
  232. module_param_array(bmask, uint, NULL, S_IRUGO | S_IWUSR);
  233. module_param_array(iomode, uint, NULL, S_IRUGO | S_IWUSR);
  234. module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR);
  235. module_param(hwid, uint, S_IRUGO | S_IWUSR); /* The hardware ID */
  236. #ifdef HFC_REGISTER_DEBUG
  237. #define HFC_outb(hc, reg, val) \
  238. (hc->HFC_outb(hc, reg, val, __func__, __LINE__))
  239. #define HFC_outb_nodebug(hc, reg, val) \
  240. (hc->HFC_outb_nodebug(hc, reg, val, __func__, __LINE__))
  241. #define HFC_inb(hc, reg) \
  242. (hc->HFC_inb(hc, reg, __func__, __LINE__))
  243. #define HFC_inb_nodebug(hc, reg) \
  244. (hc->HFC_inb_nodebug(hc, reg, __func__, __LINE__))
  245. #define HFC_inw(hc, reg) \
  246. (hc->HFC_inw(hc, reg, __func__, __LINE__))
  247. #define HFC_inw_nodebug(hc, reg) \
  248. (hc->HFC_inw_nodebug(hc, reg, __func__, __LINE__))
  249. #define HFC_wait(hc) \
  250. (hc->HFC_wait(hc, __func__, __LINE__))
  251. #define HFC_wait_nodebug(hc) \
  252. (hc->HFC_wait_nodebug(hc, __func__, __LINE__))
  253. #else
  254. #define HFC_outb(hc, reg, val) (hc->HFC_outb(hc, reg, val))
  255. #define HFC_outb_nodebug(hc, reg, val) (hc->HFC_outb_nodebug(hc, reg, val))
  256. #define HFC_inb(hc, reg) (hc->HFC_inb(hc, reg))
  257. #define HFC_inb_nodebug(hc, reg) (hc->HFC_inb_nodebug(hc, reg))
  258. #define HFC_inw(hc, reg) (hc->HFC_inw(hc, reg))
  259. #define HFC_inw_nodebug(hc, reg) (hc->HFC_inw_nodebug(hc, reg))
  260. #define HFC_wait(hc) (hc->HFC_wait(hc))
  261. #define HFC_wait_nodebug(hc) (hc->HFC_wait_nodebug(hc))
  262. #endif
  263. #ifdef CONFIG_MISDN_HFCMULTI_8xx
  264. #include "hfc_multi_8xx.h"
  265. #endif
  266. /* HFC_IO_MODE_PCIMEM */
  267. static void
  268. #ifdef HFC_REGISTER_DEBUG
  269. HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val,
  270. const char *function, int line)
  271. #else
  272. HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val)
  273. #endif
  274. {
  275. writeb(val, hc->pci_membase + reg);
  276. }
  277. static u_char
  278. #ifdef HFC_REGISTER_DEBUG
  279. HFC_inb_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
  280. #else
  281. HFC_inb_pcimem(struct hfc_multi *hc, u_char reg)
  282. #endif
  283. {
  284. return readb(hc->pci_membase + reg);
  285. }
  286. static u_short
  287. #ifdef HFC_REGISTER_DEBUG
  288. HFC_inw_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
  289. #else
  290. HFC_inw_pcimem(struct hfc_multi *hc, u_char reg)
  291. #endif
  292. {
  293. return readw(hc->pci_membase + reg);
  294. }
  295. static void
  296. #ifdef HFC_REGISTER_DEBUG
  297. HFC_wait_pcimem(struct hfc_multi *hc, const char *function, int line)
  298. #else
  299. HFC_wait_pcimem(struct hfc_multi *hc)
  300. #endif
  301. {
  302. while (readb(hc->pci_membase + R_STATUS) & V_BUSY)
  303. cpu_relax();
  304. }
  305. /* HFC_IO_MODE_REGIO */
  306. static void
  307. #ifdef HFC_REGISTER_DEBUG
  308. HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val,
  309. const char *function, int line)
  310. #else
  311. HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val)
  312. #endif
  313. {
  314. outb(reg, hc->pci_iobase + 4);
  315. outb(val, hc->pci_iobase);
  316. }
  317. static u_char
  318. #ifdef HFC_REGISTER_DEBUG
  319. HFC_inb_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
  320. #else
  321. HFC_inb_regio(struct hfc_multi *hc, u_char reg)
  322. #endif
  323. {
  324. outb(reg, hc->pci_iobase + 4);
  325. return inb(hc->pci_iobase);
  326. }
  327. static u_short
  328. #ifdef HFC_REGISTER_DEBUG
  329. HFC_inw_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
  330. #else
  331. HFC_inw_regio(struct hfc_multi *hc, u_char reg)
  332. #endif
  333. {
  334. outb(reg, hc->pci_iobase + 4);
  335. return inw(hc->pci_iobase);
  336. }
  337. static void
  338. #ifdef HFC_REGISTER_DEBUG
  339. HFC_wait_regio(struct hfc_multi *hc, const char *function, int line)
  340. #else
  341. HFC_wait_regio(struct hfc_multi *hc)
  342. #endif
  343. {
  344. outb(R_STATUS, hc->pci_iobase + 4);
  345. while (inb(hc->pci_iobase) & V_BUSY)
  346. cpu_relax();
  347. }
  348. #ifdef HFC_REGISTER_DEBUG
  349. static void
  350. HFC_outb_debug(struct hfc_multi *hc, u_char reg, u_char val,
  351. const char *function, int line)
  352. {
  353. char regname[256] = "", bits[9] = "xxxxxxxx";
  354. int i;
  355. i = -1;
  356. while (hfc_register_names[++i].name) {
  357. if (hfc_register_names[i].reg == reg)
  358. strcat(regname, hfc_register_names[i].name);
  359. }
  360. if (regname[0] == '\0')
  361. strcpy(regname, "register");
  362. bits[7] = '0' + (!!(val & 1));
  363. bits[6] = '0' + (!!(val & 2));
  364. bits[5] = '0' + (!!(val & 4));
  365. bits[4] = '0' + (!!(val & 8));
  366. bits[3] = '0' + (!!(val & 16));
  367. bits[2] = '0' + (!!(val & 32));
  368. bits[1] = '0' + (!!(val & 64));
  369. bits[0] = '0' + (!!(val & 128));
  370. printk(KERN_DEBUG
  371. "HFC_outb(chip %d, %02x=%s, 0x%02x=%s); in %s() line %d\n",
  372. hc->id, reg, regname, val, bits, function, line);
  373. HFC_outb_nodebug(hc, reg, val);
  374. }
  375. static u_char
  376. HFC_inb_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
  377. {
  378. char regname[256] = "", bits[9] = "xxxxxxxx";
  379. u_char val = HFC_inb_nodebug(hc, reg);
  380. int i;
  381. i = 0;
  382. while (hfc_register_names[i++].name)
  383. ;
  384. while (hfc_register_names[++i].name) {
  385. if (hfc_register_names[i].reg == reg)
  386. strcat(regname, hfc_register_names[i].name);
  387. }
  388. if (regname[0] == '\0')
  389. strcpy(regname, "register");
  390. bits[7] = '0' + (!!(val & 1));
  391. bits[6] = '0' + (!!(val & 2));
  392. bits[5] = '0' + (!!(val & 4));
  393. bits[4] = '0' + (!!(val & 8));
  394. bits[3] = '0' + (!!(val & 16));
  395. bits[2] = '0' + (!!(val & 32));
  396. bits[1] = '0' + (!!(val & 64));
  397. bits[0] = '0' + (!!(val & 128));
  398. printk(KERN_DEBUG
  399. "HFC_inb(chip %d, %02x=%s) = 0x%02x=%s; in %s() line %d\n",
  400. hc->id, reg, regname, val, bits, function, line);
  401. return val;
  402. }
  403. static u_short
  404. HFC_inw_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
  405. {
  406. char regname[256] = "";
  407. u_short val = HFC_inw_nodebug(hc, reg);
  408. int i;
  409. i = 0;
  410. while (hfc_register_names[i++].name)
  411. ;
  412. while (hfc_register_names[++i].name) {
  413. if (hfc_register_names[i].reg == reg)
  414. strcat(regname, hfc_register_names[i].name);
  415. }
  416. if (regname[0] == '\0')
  417. strcpy(regname, "register");
  418. printk(KERN_DEBUG
  419. "HFC_inw(chip %d, %02x=%s) = 0x%04x; in %s() line %d\n",
  420. hc->id, reg, regname, val, function, line);
  421. return val;
  422. }
  423. static void
  424. HFC_wait_debug(struct hfc_multi *hc, const char *function, int line)
  425. {
  426. printk(KERN_DEBUG "HFC_wait(chip %d); in %s() line %d\n",
  427. hc->id, function, line);
  428. HFC_wait_nodebug(hc);
  429. }
  430. #endif
  431. /* write fifo data (REGIO) */
  432. static void
  433. write_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
  434. {
  435. outb(A_FIFO_DATA0, (hc->pci_iobase) + 4);
  436. while (len >> 2) {
  437. outl(cpu_to_le32(*(u32 *)data), hc->pci_iobase);
  438. data += 4;
  439. len -= 4;
  440. }
  441. while (len >> 1) {
  442. outw(cpu_to_le16(*(u16 *)data), hc->pci_iobase);
  443. data += 2;
  444. len -= 2;
  445. }
  446. while (len) {
  447. outb(*data, hc->pci_iobase);
  448. data++;
  449. len--;
  450. }
  451. }
  452. /* write fifo data (PCIMEM) */
  453. static void
  454. write_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
  455. {
  456. while (len >> 2) {
  457. writel(cpu_to_le32(*(u32 *)data),
  458. hc->pci_membase + A_FIFO_DATA0);
  459. data += 4;
  460. len -= 4;
  461. }
  462. while (len >> 1) {
  463. writew(cpu_to_le16(*(u16 *)data),
  464. hc->pci_membase + A_FIFO_DATA0);
  465. data += 2;
  466. len -= 2;
  467. }
  468. while (len) {
  469. writeb(*data, hc->pci_membase + A_FIFO_DATA0);
  470. data++;
  471. len--;
  472. }
  473. }
  474. /* read fifo data (REGIO) */
  475. static void
  476. read_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
  477. {
  478. outb(A_FIFO_DATA0, (hc->pci_iobase) + 4);
  479. while (len >> 2) {
  480. *(u32 *)data = le32_to_cpu(inl(hc->pci_iobase));
  481. data += 4;
  482. len -= 4;
  483. }
  484. while (len >> 1) {
  485. *(u16 *)data = le16_to_cpu(inw(hc->pci_iobase));
  486. data += 2;
  487. len -= 2;
  488. }
  489. while (len) {
  490. *data = inb(hc->pci_iobase);
  491. data++;
  492. len--;
  493. }
  494. }
  495. /* read fifo data (PCIMEM) */
  496. static void
  497. read_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
  498. {
  499. while (len >> 2) {
  500. *(u32 *)data =
  501. le32_to_cpu(readl(hc->pci_membase + A_FIFO_DATA0));
  502. data += 4;
  503. len -= 4;
  504. }
  505. while (len >> 1) {
  506. *(u16 *)data =
  507. le16_to_cpu(readw(hc->pci_membase + A_FIFO_DATA0));
  508. data += 2;
  509. len -= 2;
  510. }
  511. while (len) {
  512. *data = readb(hc->pci_membase + A_FIFO_DATA0);
  513. data++;
  514. len--;
  515. }
  516. }
  517. static void
  518. enable_hwirq(struct hfc_multi *hc)
  519. {
  520. hc->hw.r_irq_ctrl |= V_GLOB_IRQ_EN;
  521. HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
  522. }
  523. static void
  524. disable_hwirq(struct hfc_multi *hc)
  525. {
  526. hc->hw.r_irq_ctrl &= ~((u_char)V_GLOB_IRQ_EN);
  527. HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
  528. }
  529. #define NUM_EC 2
  530. #define MAX_TDM_CHAN 32
  531. inline void
  532. enablepcibridge(struct hfc_multi *c)
  533. {
  534. HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); /* was _io before */
  535. }
  536. inline void
  537. disablepcibridge(struct hfc_multi *c)
  538. {
  539. HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x2); /* was _io before */
  540. }
  541. inline unsigned char
  542. readpcibridge(struct hfc_multi *hc, unsigned char address)
  543. {
  544. unsigned short cipv;
  545. unsigned char data;
  546. if (!hc->pci_iobase)
  547. return 0;
  548. /* slow down a PCI read access by 1 PCI clock cycle */
  549. HFC_outb(hc, R_CTRL, 0x4); /*was _io before*/
  550. if (address == 0)
  551. cipv = 0x4000;
  552. else
  553. cipv = 0x5800;
  554. /* select local bridge port address by writing to CIP port */
  555. /* data = HFC_inb(c, cipv); * was _io before */
  556. outw(cipv, hc->pci_iobase + 4);
  557. data = inb(hc->pci_iobase);
  558. /* restore R_CTRL for normal PCI read cycle speed */
  559. HFC_outb(hc, R_CTRL, 0x0); /* was _io before */
  560. return data;
  561. }
  562. inline void
  563. writepcibridge(struct hfc_multi *hc, unsigned char address, unsigned char data)
  564. {
  565. unsigned short cipv;
  566. unsigned int datav;
  567. if (!hc->pci_iobase)
  568. return;
  569. if (address == 0)
  570. cipv = 0x4000;
  571. else
  572. cipv = 0x5800;
  573. /* select local bridge port address by writing to CIP port */
  574. outw(cipv, hc->pci_iobase + 4);
  575. /* define a 32 bit dword with 4 identical bytes for write sequence */
  576. datav = data | ((__u32) data << 8) | ((__u32) data << 16) |
  577. ((__u32) data << 24);
  578. /*
  579. * write this 32 bit dword to the bridge data port
  580. * this will initiate a write sequence of up to 4 writes to the same
  581. * address on the local bus interface the number of write accesses
  582. * is undefined but >=1 and depends on the next PCI transaction
  583. * during write sequence on the local bus
  584. */
  585. outl(datav, hc->pci_iobase);
  586. }
  587. inline void
  588. cpld_set_reg(struct hfc_multi *hc, unsigned char reg)
  589. {
  590. /* Do data pin read low byte */
  591. HFC_outb(hc, R_GPIO_OUT1, reg);
  592. }
  593. inline void
  594. cpld_write_reg(struct hfc_multi *hc, unsigned char reg, unsigned char val)
  595. {
  596. cpld_set_reg(hc, reg);
  597. enablepcibridge(hc);
  598. writepcibridge(hc, 1, val);
  599. disablepcibridge(hc);
  600. return;
  601. }
  602. inline unsigned char
  603. cpld_read_reg(struct hfc_multi *hc, unsigned char reg)
  604. {
  605. unsigned char bytein;
  606. cpld_set_reg(hc, reg);
  607. /* Do data pin read low byte */
  608. HFC_outb(hc, R_GPIO_OUT1, reg);
  609. enablepcibridge(hc);
  610. bytein = readpcibridge(hc, 1);
  611. disablepcibridge(hc);
  612. return bytein;
  613. }
  614. inline void
  615. vpm_write_address(struct hfc_multi *hc, unsigned short addr)
  616. {
  617. cpld_write_reg(hc, 0, 0xff & addr);
  618. cpld_write_reg(hc, 1, 0x01 & (addr >> 8));
  619. }
  620. inline unsigned short
  621. vpm_read_address(struct hfc_multi *c)
  622. {
  623. unsigned short addr;
  624. unsigned short highbit;
  625. addr = cpld_read_reg(c, 0);
  626. highbit = cpld_read_reg(c, 1);
  627. addr = addr | (highbit << 8);
  628. return addr & 0x1ff;
  629. }
  630. inline unsigned char
  631. vpm_in(struct hfc_multi *c, int which, unsigned short addr)
  632. {
  633. unsigned char res;
  634. vpm_write_address(c, addr);
  635. if (!which)
  636. cpld_set_reg(c, 2);
  637. else
  638. cpld_set_reg(c, 3);
  639. enablepcibridge(c);
  640. res = readpcibridge(c, 1);
  641. disablepcibridge(c);
  642. cpld_set_reg(c, 0);
  643. return res;
  644. }
  645. inline void
  646. vpm_out(struct hfc_multi *c, int which, unsigned short addr,
  647. unsigned char data)
  648. {
  649. vpm_write_address(c, addr);
  650. enablepcibridge(c);
  651. if (!which)
  652. cpld_set_reg(c, 2);
  653. else
  654. cpld_set_reg(c, 3);
  655. writepcibridge(c, 1, data);
  656. cpld_set_reg(c, 0);
  657. disablepcibridge(c);
  658. {
  659. unsigned char regin;
  660. regin = vpm_in(c, which, addr);
  661. if (regin != data)
  662. printk(KERN_DEBUG "Wrote 0x%x to register 0x%x but got back "
  663. "0x%x\n", data, addr, regin);
  664. }
  665. }
  666. static void
  667. vpm_init(struct hfc_multi *wc)
  668. {
  669. unsigned char reg;
  670. unsigned int mask;
  671. unsigned int i, x, y;
  672. unsigned int ver;
  673. for (x = 0; x < NUM_EC; x++) {
  674. /* Setup GPIO's */
  675. if (!x) {
  676. ver = vpm_in(wc, x, 0x1a0);
  677. printk(KERN_DEBUG "VPM: Chip %d: ver %02x\n", x, ver);
  678. }
  679. for (y = 0; y < 4; y++) {
  680. vpm_out(wc, x, 0x1a8 + y, 0x00); /* GPIO out */
  681. vpm_out(wc, x, 0x1ac + y, 0x00); /* GPIO dir */
  682. vpm_out(wc, x, 0x1b0 + y, 0x00); /* GPIO sel */
  683. }
  684. /* Setup TDM path - sets fsync and tdm_clk as inputs */
  685. reg = vpm_in(wc, x, 0x1a3); /* misc_con */
  686. vpm_out(wc, x, 0x1a3, reg & ~2);
  687. /* Setup Echo length (256 taps) */
  688. vpm_out(wc, x, 0x022, 1);
  689. vpm_out(wc, x, 0x023, 0xff);
  690. /* Setup timeslots */
  691. vpm_out(wc, x, 0x02f, 0x00);
  692. mask = 0x02020202 << (x * 4);
  693. /* Setup the tdm channel masks for all chips */
  694. for (i = 0; i < 4; i++)
  695. vpm_out(wc, x, 0x33 - i, (mask >> (i << 3)) & 0xff);
  696. /* Setup convergence rate */
  697. printk(KERN_DEBUG "VPM: A-law mode\n");
  698. reg = 0x00 | 0x10 | 0x01;
  699. vpm_out(wc, x, 0x20, reg);
  700. printk(KERN_DEBUG "VPM reg 0x20 is %x\n", reg);
  701. /*vpm_out(wc, x, 0x20, (0x00 | 0x08 | 0x20 | 0x10)); */
  702. vpm_out(wc, x, 0x24, 0x02);
  703. reg = vpm_in(wc, x, 0x24);
  704. printk(KERN_DEBUG "NLP Thresh is set to %d (0x%x)\n", reg, reg);
  705. /* Initialize echo cans */
  706. for (i = 0; i < MAX_TDM_CHAN; i++) {
  707. if (mask & (0x00000001 << i))
  708. vpm_out(wc, x, i, 0x00);
  709. }
  710. /*
  711. * ARM arch at least disallows a udelay of
  712. * more than 2ms... it gives a fake "__bad_udelay"
  713. * reference at link-time.
  714. * long delays in kernel code are pretty sucky anyway
  715. * for now work around it using 5 x 2ms instead of 1 x 10ms
  716. */
  717. udelay(2000);
  718. udelay(2000);
  719. udelay(2000);
  720. udelay(2000);
  721. udelay(2000);
  722. /* Put in bypass mode */
  723. for (i = 0; i < MAX_TDM_CHAN; i++) {
  724. if (mask & (0x00000001 << i))
  725. vpm_out(wc, x, i, 0x01);
  726. }
  727. /* Enable bypass */
  728. for (i = 0; i < MAX_TDM_CHAN; i++) {
  729. if (mask & (0x00000001 << i))
  730. vpm_out(wc, x, 0x78 + i, 0x01);
  731. }
  732. }
  733. }
  734. #ifdef UNUSED
  735. static void
  736. vpm_check(struct hfc_multi *hctmp)
  737. {
  738. unsigned char gpi2;
  739. gpi2 = HFC_inb(hctmp, R_GPI_IN2);
  740. if ((gpi2 & 0x3) != 0x3)
  741. printk(KERN_DEBUG "Got interrupt 0x%x from VPM!\n", gpi2);
  742. }
  743. #endif /* UNUSED */
  744. /*
  745. * Interface to enable/disable the HW Echocan
  746. *
  747. * these functions are called within a spin_lock_irqsave on
  748. * the channel instance lock, so we are not disturbed by irqs
  749. *
  750. * we can later easily change the interface to make other
  751. * things configurable, for now we configure the taps
  752. *
  753. */
  754. static void
  755. vpm_echocan_on(struct hfc_multi *hc, int ch, int taps)
  756. {
  757. unsigned int timeslot;
  758. unsigned int unit;
  759. struct bchannel *bch = hc->chan[ch].bch;
  760. #ifdef TXADJ
  761. int txadj = -4;
  762. struct sk_buff *skb;
  763. #endif
  764. if (hc->chan[ch].protocol != ISDN_P_B_RAW)
  765. return;
  766. if (!bch)
  767. return;
  768. #ifdef TXADJ
  769. skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
  770. sizeof(int), &txadj, GFP_ATOMIC);
  771. if (skb)
  772. recv_Bchannel_skb(bch, skb);
  773. #endif
  774. timeslot = ((ch / 4) * 8) + ((ch % 4) * 4) + 1;
  775. unit = ch % 4;
  776. printk(KERN_NOTICE "vpm_echocan_on called taps [%d] on timeslot %d\n",
  777. taps, timeslot);
  778. vpm_out(hc, unit, timeslot, 0x7e);
  779. }
  780. static void
  781. vpm_echocan_off(struct hfc_multi *hc, int ch)
  782. {
  783. unsigned int timeslot;
  784. unsigned int unit;
  785. struct bchannel *bch = hc->chan[ch].bch;
  786. #ifdef TXADJ
  787. int txadj = 0;
  788. struct sk_buff *skb;
  789. #endif
  790. if (hc->chan[ch].protocol != ISDN_P_B_RAW)
  791. return;
  792. if (!bch)
  793. return;
  794. #ifdef TXADJ
  795. skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
  796. sizeof(int), &txadj, GFP_ATOMIC);
  797. if (skb)
  798. recv_Bchannel_skb(bch, skb);
  799. #endif
  800. timeslot = ((ch / 4) * 8) + ((ch % 4) * 4) + 1;
  801. unit = ch % 4;
  802. printk(KERN_NOTICE "vpm_echocan_off called on timeslot %d\n",
  803. timeslot);
  804. /* FILLME */
  805. vpm_out(hc, unit, timeslot, 0x01);
  806. }
  807. /*
  808. * Speech Design resync feature
  809. * NOTE: This is called sometimes outside interrupt handler.
  810. * We must lock irqsave, so no other interrupt (other card) will occur!
  811. * Also multiple interrupts may nest, so must lock each access (lists, card)!
  812. */
  813. static inline void
  814. hfcmulti_resync(struct hfc_multi *locked, struct hfc_multi *newmaster, int rm)
  815. {
  816. struct hfc_multi *hc, *next, *pcmmaster = NULL;
  817. void __iomem *plx_acc_32;
  818. u_int pv;
  819. u_long flags;
  820. spin_lock_irqsave(&HFClock, flags);
  821. spin_lock(&plx_lock); /* must be locked inside other locks */
  822. if (debug & DEBUG_HFCMULTI_PLXSD)
  823. printk(KERN_DEBUG "%s: RESYNC(syncmaster=0x%p)\n",
  824. __func__, syncmaster);
  825. /* select new master */
  826. if (newmaster) {
  827. if (debug & DEBUG_HFCMULTI_PLXSD)
  828. printk(KERN_DEBUG "using provided controller\n");
  829. } else {
  830. list_for_each_entry_safe(hc, next, &HFClist, list) {
  831. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  832. if (hc->syncronized) {
  833. newmaster = hc;
  834. break;
  835. }
  836. }
  837. }
  838. }
  839. /* Disable sync of all cards */
  840. list_for_each_entry_safe(hc, next, &HFClist, list) {
  841. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  842. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  843. pv = readl(plx_acc_32);
  844. pv &= ~PLX_SYNC_O_EN;
  845. writel(pv, plx_acc_32);
  846. if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
  847. pcmmaster = hc;
  848. if (hc->ctype == HFC_TYPE_E1) {
  849. if (debug & DEBUG_HFCMULTI_PLXSD)
  850. printk(KERN_DEBUG
  851. "Schedule SYNC_I\n");
  852. hc->e1_resync |= 1; /* get SYNC_I */
  853. }
  854. }
  855. }
  856. }
  857. if (newmaster) {
  858. hc = newmaster;
  859. if (debug & DEBUG_HFCMULTI_PLXSD)
  860. printk(KERN_DEBUG "id=%d (0x%p) = syncronized with "
  861. "interface.\n", hc->id, hc);
  862. /* Enable new sync master */
  863. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  864. pv = readl(plx_acc_32);
  865. pv |= PLX_SYNC_O_EN;
  866. writel(pv, plx_acc_32);
  867. /* switch to jatt PLL, if not disabled by RX_SYNC */
  868. if (hc->ctype == HFC_TYPE_E1
  869. && !test_bit(HFC_CHIP_RX_SYNC, &hc->chip)) {
  870. if (debug & DEBUG_HFCMULTI_PLXSD)
  871. printk(KERN_DEBUG "Schedule jatt PLL\n");
  872. hc->e1_resync |= 2; /* switch to jatt */
  873. }
  874. } else {
  875. if (pcmmaster) {
  876. hc = pcmmaster;
  877. if (debug & DEBUG_HFCMULTI_PLXSD)
  878. printk(KERN_DEBUG
  879. "id=%d (0x%p) = PCM master syncronized "
  880. "with QUARTZ\n", hc->id, hc);
  881. if (hc->ctype == HFC_TYPE_E1) {
  882. /* Use the crystal clock for the PCM
  883. master card */
  884. if (debug & DEBUG_HFCMULTI_PLXSD)
  885. printk(KERN_DEBUG
  886. "Schedule QUARTZ for HFC-E1\n");
  887. hc->e1_resync |= 4; /* switch quartz */
  888. } else {
  889. if (debug & DEBUG_HFCMULTI_PLXSD)
  890. printk(KERN_DEBUG
  891. "QUARTZ is automatically "
  892. "enabled by HFC-%dS\n", hc->ctype);
  893. }
  894. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  895. pv = readl(plx_acc_32);
  896. pv |= PLX_SYNC_O_EN;
  897. writel(pv, plx_acc_32);
  898. } else
  899. if (!rm)
  900. printk(KERN_ERR "%s no pcm master, this MUST "
  901. "not happen!\n", __func__);
  902. }
  903. syncmaster = newmaster;
  904. spin_unlock(&plx_lock);
  905. spin_unlock_irqrestore(&HFClock, flags);
  906. }
  907. /* This must be called AND hc must be locked irqsave!!! */
  908. inline void
  909. plxsd_checksync(struct hfc_multi *hc, int rm)
  910. {
  911. if (hc->syncronized) {
  912. if (syncmaster == NULL) {
  913. if (debug & DEBUG_HFCMULTI_PLXSD)
  914. printk(KERN_DEBUG "%s: GOT sync on card %d"
  915. " (id=%d)\n", __func__, hc->id + 1,
  916. hc->id);
  917. hfcmulti_resync(hc, hc, rm);
  918. }
  919. } else {
  920. if (syncmaster == hc) {
  921. if (debug & DEBUG_HFCMULTI_PLXSD)
  922. printk(KERN_DEBUG "%s: LOST sync on card %d"
  923. " (id=%d)\n", __func__, hc->id + 1,
  924. hc->id);
  925. hfcmulti_resync(hc, NULL, rm);
  926. }
  927. }
  928. }
  929. /*
  930. * free hardware resources used by driver
  931. */
  932. static void
  933. release_io_hfcmulti(struct hfc_multi *hc)
  934. {
  935. void __iomem *plx_acc_32;
  936. u_int pv;
  937. u_long plx_flags;
  938. if (debug & DEBUG_HFCMULTI_INIT)
  939. printk(KERN_DEBUG "%s: entered\n", __func__);
  940. /* soft reset also masks all interrupts */
  941. hc->hw.r_cirm |= V_SRES;
  942. HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
  943. udelay(1000);
  944. hc->hw.r_cirm &= ~V_SRES;
  945. HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
  946. udelay(1000); /* instead of 'wait' that may cause locking */
  947. /* release Speech Design card, if PLX was initialized */
  948. if (test_bit(HFC_CHIP_PLXSD, &hc->chip) && hc->plx_membase) {
  949. if (debug & DEBUG_HFCMULTI_PLXSD)
  950. printk(KERN_DEBUG "%s: release PLXSD card %d\n",
  951. __func__, hc->id + 1);
  952. spin_lock_irqsave(&plx_lock, plx_flags);
  953. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  954. writel(PLX_GPIOC_INIT, plx_acc_32);
  955. pv = readl(plx_acc_32);
  956. /* Termination off */
  957. pv &= ~PLX_TERM_ON;
  958. /* Disconnect the PCM */
  959. pv |= PLX_SLAVE_EN_N;
  960. pv &= ~PLX_MASTER_EN;
  961. pv &= ~PLX_SYNC_O_EN;
  962. /* Put the DSP in Reset */
  963. pv &= ~PLX_DSP_RES_N;
  964. writel(pv, plx_acc_32);
  965. if (debug & DEBUG_HFCMULTI_INIT)
  966. printk(KERN_DEBUG "%s: PCM off: PLX_GPIO=%x\n",
  967. __func__, pv);
  968. spin_unlock_irqrestore(&plx_lock, plx_flags);
  969. }
  970. /* disable memory mapped ports / io ports */
  971. test_and_clear_bit(HFC_CHIP_PLXSD, &hc->chip); /* prevent resync */
  972. if (hc->pci_dev)
  973. pci_write_config_word(hc->pci_dev, PCI_COMMAND, 0);
  974. if (hc->pci_membase)
  975. iounmap(hc->pci_membase);
  976. if (hc->plx_membase)
  977. iounmap(hc->plx_membase);
  978. if (hc->pci_iobase)
  979. release_region(hc->pci_iobase, 8);
  980. if (hc->xhfc_membase)
  981. iounmap((void *)hc->xhfc_membase);
  982. if (hc->pci_dev) {
  983. pci_disable_device(hc->pci_dev);
  984. pci_set_drvdata(hc->pci_dev, NULL);
  985. }
  986. if (debug & DEBUG_HFCMULTI_INIT)
  987. printk(KERN_DEBUG "%s: done\n", __func__);
  988. }
  989. /*
  990. * function called to reset the HFC chip. A complete software reset of chip
  991. * and fifos is done. All configuration of the chip is done.
  992. */
  993. static int
  994. init_chip(struct hfc_multi *hc)
  995. {
  996. u_long flags, val, val2 = 0, rev;
  997. int i, err = 0;
  998. u_char r_conf_en, rval;
  999. void __iomem *plx_acc_32;
  1000. u_int pv;
  1001. u_long plx_flags, hfc_flags;
  1002. int plx_count;
  1003. struct hfc_multi *pos, *next, *plx_last_hc;
  1004. spin_lock_irqsave(&hc->lock, flags);
  1005. /* reset all registers */
  1006. memset(&hc->hw, 0, sizeof(struct hfcm_hw));
  1007. /* revision check */
  1008. if (debug & DEBUG_HFCMULTI_INIT)
  1009. printk(KERN_DEBUG "%s: entered\n", __func__);
  1010. val = HFC_inb(hc, R_CHIP_ID);
  1011. if ((val >> 4) != 0x8 && (val >> 4) != 0xc && (val >> 4) != 0xe &&
  1012. (val >> 1) != 0x31) {
  1013. printk(KERN_INFO "HFC_multi: unknown CHIP_ID:%x\n", (u_int)val);
  1014. err = -EIO;
  1015. goto out;
  1016. }
  1017. rev = HFC_inb(hc, R_CHIP_RV);
  1018. printk(KERN_INFO
  1019. "HFC_multi: detected HFC with chip ID=0x%lx revision=%ld%s\n",
  1020. val, rev, (rev == 0 && (hc->ctype != HFC_TYPE_XHFC)) ?
  1021. " (old FIFO handling)" : "");
  1022. if (hc->ctype != HFC_TYPE_XHFC && rev == 0) {
  1023. test_and_set_bit(HFC_CHIP_REVISION0, &hc->chip);
  1024. printk(KERN_WARNING
  1025. "HFC_multi: NOTE: Your chip is revision 0, "
  1026. "ask Cologne Chip for update. Newer chips "
  1027. "have a better FIFO handling. Old chips "
  1028. "still work but may have slightly lower "
  1029. "HDLC transmit performance.\n");
  1030. }
  1031. if (rev > 1) {
  1032. printk(KERN_WARNING "HFC_multi: WARNING: This driver doesn't "
  1033. "consider chip revision = %ld. The chip / "
  1034. "bridge may not work.\n", rev);
  1035. }
  1036. /* set s-ram size */
  1037. hc->Flen = 0x10;
  1038. hc->Zmin = 0x80;
  1039. hc->Zlen = 384;
  1040. hc->DTMFbase = 0x1000;
  1041. if (test_bit(HFC_CHIP_EXRAM_128, &hc->chip)) {
  1042. if (debug & DEBUG_HFCMULTI_INIT)
  1043. printk(KERN_DEBUG "%s: changing to 128K external RAM\n",
  1044. __func__);
  1045. hc->hw.r_ctrl |= V_EXT_RAM;
  1046. hc->hw.r_ram_sz = 1;
  1047. hc->Flen = 0x20;
  1048. hc->Zmin = 0xc0;
  1049. hc->Zlen = 1856;
  1050. hc->DTMFbase = 0x2000;
  1051. }
  1052. if (test_bit(HFC_CHIP_EXRAM_512, &hc->chip)) {
  1053. if (debug & DEBUG_HFCMULTI_INIT)
  1054. printk(KERN_DEBUG "%s: changing to 512K external RAM\n",
  1055. __func__);
  1056. hc->hw.r_ctrl |= V_EXT_RAM;
  1057. hc->hw.r_ram_sz = 2;
  1058. hc->Flen = 0x20;
  1059. hc->Zmin = 0xc0;
  1060. hc->Zlen = 8000;
  1061. hc->DTMFbase = 0x2000;
  1062. }
  1063. if (hc->ctype == HFC_TYPE_XHFC) {
  1064. hc->Flen = 0x8;
  1065. hc->Zmin = 0x0;
  1066. hc->Zlen = 64;
  1067. hc->DTMFbase = 0x0;
  1068. }
  1069. hc->max_trans = poll << 1;
  1070. if (hc->max_trans > hc->Zlen)
  1071. hc->max_trans = hc->Zlen;
  1072. /* Speech Design PLX bridge */
  1073. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  1074. if (debug & DEBUG_HFCMULTI_PLXSD)
  1075. printk(KERN_DEBUG "%s: initializing PLXSD card %d\n",
  1076. __func__, hc->id + 1);
  1077. spin_lock_irqsave(&plx_lock, plx_flags);
  1078. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  1079. writel(PLX_GPIOC_INIT, plx_acc_32);
  1080. pv = readl(plx_acc_32);
  1081. /* The first and the last cards are terminating the PCM bus */
  1082. pv |= PLX_TERM_ON; /* hc is currently the last */
  1083. /* Disconnect the PCM */
  1084. pv |= PLX_SLAVE_EN_N;
  1085. pv &= ~PLX_MASTER_EN;
  1086. pv &= ~PLX_SYNC_O_EN;
  1087. /* Put the DSP in Reset */
  1088. pv &= ~PLX_DSP_RES_N;
  1089. writel(pv, plx_acc_32);
  1090. spin_unlock_irqrestore(&plx_lock, plx_flags);
  1091. if (debug & DEBUG_HFCMULTI_INIT)
  1092. printk(KERN_DEBUG "%s: slave/term: PLX_GPIO=%x\n",
  1093. __func__, pv);
  1094. /*
  1095. * If we are the 3rd PLXSD card or higher, we must turn
  1096. * termination of last PLXSD card off.
  1097. */
  1098. spin_lock_irqsave(&HFClock, hfc_flags);
  1099. plx_count = 0;
  1100. plx_last_hc = NULL;
  1101. list_for_each_entry_safe(pos, next, &HFClist, list) {
  1102. if (test_bit(HFC_CHIP_PLXSD, &pos->chip)) {
  1103. plx_count++;
  1104. if (pos != hc)
  1105. plx_last_hc = pos;
  1106. }
  1107. }
  1108. if (plx_count >= 3) {
  1109. if (debug & DEBUG_HFCMULTI_PLXSD)
  1110. printk(KERN_DEBUG "%s: card %d is between, so "
  1111. "we disable termination\n",
  1112. __func__, plx_last_hc->id + 1);
  1113. spin_lock_irqsave(&plx_lock, plx_flags);
  1114. plx_acc_32 = plx_last_hc->plx_membase + PLX_GPIOC;
  1115. pv = readl(plx_acc_32);
  1116. pv &= ~PLX_TERM_ON;
  1117. writel(pv, plx_acc_32);
  1118. spin_unlock_irqrestore(&plx_lock, plx_flags);
  1119. if (debug & DEBUG_HFCMULTI_INIT)
  1120. printk(KERN_DEBUG
  1121. "%s: term off: PLX_GPIO=%x\n",
  1122. __func__, pv);
  1123. }
  1124. spin_unlock_irqrestore(&HFClock, hfc_flags);
  1125. hc->hw.r_pcm_md0 = V_F0_LEN; /* shift clock for DSP */
  1126. }
  1127. if (test_bit(HFC_CHIP_EMBSD, &hc->chip))
  1128. hc->hw.r_pcm_md0 = V_F0_LEN; /* shift clock for DSP */
  1129. /* we only want the real Z2 read-pointer for revision > 0 */
  1130. if (!test_bit(HFC_CHIP_REVISION0, &hc->chip))
  1131. hc->hw.r_ram_sz |= V_FZ_MD;
  1132. /* select pcm mode */
  1133. if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
  1134. if (debug & DEBUG_HFCMULTI_INIT)
  1135. printk(KERN_DEBUG "%s: setting PCM into slave mode\n",
  1136. __func__);
  1137. } else
  1138. if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip) && !plxsd_master) {
  1139. if (debug & DEBUG_HFCMULTI_INIT)
  1140. printk(KERN_DEBUG "%s: setting PCM into master mode\n",
  1141. __func__);
  1142. hc->hw.r_pcm_md0 |= V_PCM_MD;
  1143. } else {
  1144. if (debug & DEBUG_HFCMULTI_INIT)
  1145. printk(KERN_DEBUG "%s: performing PCM auto detect\n",
  1146. __func__);
  1147. }
  1148. /* soft reset */
  1149. HFC_outb(hc, R_CTRL, hc->hw.r_ctrl);
  1150. if (hc->ctype == HFC_TYPE_XHFC)
  1151. HFC_outb(hc, 0x0C /* R_FIFO_THRES */,
  1152. 0x11 /* 16 Bytes TX/RX */);
  1153. else
  1154. HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
  1155. HFC_outb(hc, R_FIFO_MD, 0);
  1156. if (hc->ctype == HFC_TYPE_XHFC)
  1157. hc->hw.r_cirm = V_SRES | V_HFCRES | V_PCMRES | V_STRES;
  1158. else
  1159. hc->hw.r_cirm = V_SRES | V_HFCRES | V_PCMRES | V_STRES
  1160. | V_RLD_EPR;
  1161. HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
  1162. udelay(100);
  1163. hc->hw.r_cirm = 0;
  1164. HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
  1165. udelay(100);
  1166. if (hc->ctype != HFC_TYPE_XHFC)
  1167. HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
  1168. /* Speech Design PLX bridge pcm and sync mode */
  1169. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  1170. spin_lock_irqsave(&plx_lock, plx_flags);
  1171. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  1172. pv = readl(plx_acc_32);
  1173. /* Connect PCM */
  1174. if (hc->hw.r_pcm_md0 & V_PCM_MD) {
  1175. pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
  1176. pv |= PLX_SYNC_O_EN;
  1177. if (debug & DEBUG_HFCMULTI_INIT)
  1178. printk(KERN_DEBUG "%s: master: PLX_GPIO=%x\n",
  1179. __func__, pv);
  1180. } else {
  1181. pv &= ~(PLX_MASTER_EN | PLX_SLAVE_EN_N);
  1182. pv &= ~PLX_SYNC_O_EN;
  1183. if (debug & DEBUG_HFCMULTI_INIT)
  1184. printk(KERN_DEBUG "%s: slave: PLX_GPIO=%x\n",
  1185. __func__, pv);
  1186. }
  1187. writel(pv, plx_acc_32);
  1188. spin_unlock_irqrestore(&plx_lock, plx_flags);
  1189. }
  1190. /* PCM setup */
  1191. HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x90);
  1192. if (hc->slots == 32)
  1193. HFC_outb(hc, R_PCM_MD1, 0x00);
  1194. if (hc->slots == 64)
  1195. HFC_outb(hc, R_PCM_MD1, 0x10);
  1196. if (hc->slots == 128)
  1197. HFC_outb(hc, R_PCM_MD1, 0x20);
  1198. HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0xa0);
  1199. if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
  1200. HFC_outb(hc, R_PCM_MD2, V_SYNC_SRC); /* sync via SYNC_I / O */
  1201. else if (test_bit(HFC_CHIP_EMBSD, &hc->chip))
  1202. HFC_outb(hc, R_PCM_MD2, 0x10); /* V_C2O_EN */
  1203. else
  1204. HFC_outb(hc, R_PCM_MD2, 0x00); /* sync from interface */
  1205. HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
  1206. for (i = 0; i < 256; i++) {
  1207. HFC_outb_nodebug(hc, R_SLOT, i);
  1208. HFC_outb_nodebug(hc, A_SL_CFG, 0);
  1209. if (hc->ctype != HFC_TYPE_XHFC)
  1210. HFC_outb_nodebug(hc, A_CONF, 0);
  1211. hc->slot_owner[i] = -1;
  1212. }
  1213. /* set clock speed */
  1214. if (test_bit(HFC_CHIP_CLOCK2, &hc->chip)) {
  1215. if (debug & DEBUG_HFCMULTI_INIT)
  1216. printk(KERN_DEBUG
  1217. "%s: setting double clock\n", __func__);
  1218. HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
  1219. }
  1220. if (test_bit(HFC_CHIP_EMBSD, &hc->chip))
  1221. HFC_outb(hc, 0x02 /* R_CLK_CFG */, 0x40 /* V_CLKO_OFF */);
  1222. /* B410P GPIO */
  1223. if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
  1224. printk(KERN_NOTICE "Setting GPIOs\n");
  1225. HFC_outb(hc, R_GPIO_SEL, 0x30);
  1226. HFC_outb(hc, R_GPIO_EN1, 0x3);
  1227. udelay(1000);
  1228. printk(KERN_NOTICE "calling vpm_init\n");
  1229. vpm_init(hc);
  1230. }
  1231. /* check if R_F0_CNT counts (8 kHz frame count) */
  1232. val = HFC_inb(hc, R_F0_CNTL);
  1233. val += HFC_inb(hc, R_F0_CNTH) << 8;
  1234. if (debug & DEBUG_HFCMULTI_INIT)
  1235. printk(KERN_DEBUG
  1236. "HFC_multi F0_CNT %ld after reset\n", val);
  1237. spin_unlock_irqrestore(&hc->lock, flags);
  1238. set_current_state(TASK_UNINTERRUPTIBLE);
  1239. schedule_timeout((HZ / 100) ? : 1); /* Timeout minimum 10ms */
  1240. spin_lock_irqsave(&hc->lock, flags);
  1241. val2 = HFC_inb(hc, R_F0_CNTL);
  1242. val2 += HFC_inb(hc, R_F0_CNTH) << 8;
  1243. if (debug & DEBUG_HFCMULTI_INIT)
  1244. printk(KERN_DEBUG
  1245. "HFC_multi F0_CNT %ld after 10 ms (1st try)\n",
  1246. val2);
  1247. if (val2 >= val + 8) { /* 1 ms */
  1248. /* it counts, so we keep the pcm mode */
  1249. if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
  1250. printk(KERN_INFO "controller is PCM bus MASTER\n");
  1251. else
  1252. if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip))
  1253. printk(KERN_INFO "controller is PCM bus SLAVE\n");
  1254. else {
  1255. test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
  1256. printk(KERN_INFO "controller is PCM bus SLAVE "
  1257. "(auto detected)\n");
  1258. }
  1259. } else {
  1260. /* does not count */
  1261. if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
  1262. controller_fail:
  1263. printk(KERN_ERR "HFC_multi ERROR, getting no 125us "
  1264. "pulse. Seems that controller fails.\n");
  1265. err = -EIO;
  1266. goto out;
  1267. }
  1268. if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
  1269. printk(KERN_INFO "controller is PCM bus SLAVE "
  1270. "(ignoring missing PCM clock)\n");
  1271. } else {
  1272. /* only one pcm master */
  1273. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
  1274. && plxsd_master) {
  1275. printk(KERN_ERR "HFC_multi ERROR, no clock "
  1276. "on another Speech Design card found. "
  1277. "Please be sure to connect PCM cable.\n");
  1278. err = -EIO;
  1279. goto out;
  1280. }
  1281. /* retry with master clock */
  1282. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  1283. spin_lock_irqsave(&plx_lock, plx_flags);
  1284. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  1285. pv = readl(plx_acc_32);
  1286. pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
  1287. pv |= PLX_SYNC_O_EN;
  1288. writel(pv, plx_acc_32);
  1289. spin_unlock_irqrestore(&plx_lock, plx_flags);
  1290. if (debug & DEBUG_HFCMULTI_INIT)
  1291. printk(KERN_DEBUG "%s: master: "
  1292. "PLX_GPIO=%x\n", __func__, pv);
  1293. }
  1294. hc->hw.r_pcm_md0 |= V_PCM_MD;
  1295. HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
  1296. spin_unlock_irqrestore(&hc->lock, flags);
  1297. set_current_state(TASK_UNINTERRUPTIBLE);
  1298. schedule_timeout((HZ / 100) ?: 1); /* Timeout min. 10ms */
  1299. spin_lock_irqsave(&hc->lock, flags);
  1300. val2 = HFC_inb(hc, R_F0_CNTL);
  1301. val2 += HFC_inb(hc, R_F0_CNTH) << 8;
  1302. if (debug & DEBUG_HFCMULTI_INIT)
  1303. printk(KERN_DEBUG "HFC_multi F0_CNT %ld after "
  1304. "10 ms (2nd try)\n", val2);
  1305. if (val2 >= val + 8) { /* 1 ms */
  1306. test_and_set_bit(HFC_CHIP_PCM_MASTER,
  1307. &hc->chip);
  1308. printk(KERN_INFO "controller is PCM bus MASTER "
  1309. "(auto detected)\n");
  1310. } else
  1311. goto controller_fail;
  1312. }
  1313. }
  1314. /* Release the DSP Reset */
  1315. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  1316. if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
  1317. plxsd_master = 1;
  1318. spin_lock_irqsave(&plx_lock, plx_flags);
  1319. plx_acc_32 = hc->plx_membase + PLX_GPIOC;
  1320. pv = readl(plx_acc_32);
  1321. pv |= PLX_DSP_RES_N;
  1322. writel(pv, plx_acc_32);
  1323. spin_unlock_irqrestore(&plx_lock, plx_flags);
  1324. if (debug & DEBUG_HFCMULTI_INIT)
  1325. printk(KERN_DEBUG "%s: reset off: PLX_GPIO=%x\n",
  1326. __func__, pv);
  1327. }
  1328. /* pcm id */
  1329. if (hc->pcm)
  1330. printk(KERN_INFO "controller has given PCM BUS ID %d\n",
  1331. hc->pcm);
  1332. else {
  1333. if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)
  1334. || test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  1335. PCM_cnt++; /* SD has proprietary bridging */
  1336. }
  1337. hc->pcm = PCM_cnt;
  1338. printk(KERN_INFO "controller has PCM BUS ID %d "
  1339. "(auto selected)\n", hc->pcm);
  1340. }
  1341. /* set up timer */
  1342. HFC_outb(hc, R_TI_WD, poll_timer);
  1343. hc->hw.r_irqmsk_misc |= V_TI_IRQMSK;
  1344. /* set E1 state machine IRQ */
  1345. if (hc->ctype == HFC_TYPE_E1)
  1346. hc->hw.r_irqmsk_misc |= V_STA_IRQMSK;
  1347. /* set DTMF detection */
  1348. if (test_bit(HFC_CHIP_DTMF, &hc->chip)) {
  1349. if (debug & DEBUG_HFCMULTI_INIT)
  1350. printk(KERN_DEBUG "%s: enabling DTMF detection "
  1351. "for all B-channel\n", __func__);
  1352. hc->hw.r_dtmf = V_DTMF_EN | V_DTMF_STOP;
  1353. if (test_bit(HFC_CHIP_ULAW, &hc->chip))
  1354. hc->hw.r_dtmf |= V_ULAW_SEL;
  1355. HFC_outb(hc, R_DTMF_N, 102 - 1);
  1356. hc->hw.r_irqmsk_misc |= V_DTMF_IRQMSK;
  1357. }
  1358. /* conference engine */
  1359. if (test_bit(HFC_CHIP_ULAW, &hc->chip))
  1360. r_conf_en = V_CONF_EN | V_ULAW;
  1361. else
  1362. r_conf_en = V_CONF_EN;
  1363. if (hc->ctype != HFC_TYPE_XHFC)
  1364. HFC_outb(hc, R_CONF_EN, r_conf_en);
  1365. /* setting leds */
  1366. switch (hc->leds) {
  1367. case 1: /* HFC-E1 OEM */
  1368. if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
  1369. HFC_outb(hc, R_GPIO_SEL, 0x32);
  1370. else
  1371. HFC_outb(hc, R_GPIO_SEL, 0x30);
  1372. HFC_outb(hc, R_GPIO_EN1, 0x0f);
  1373. HFC_outb(hc, R_GPIO_OUT1, 0x00);
  1374. HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
  1375. break;
  1376. case 2: /* HFC-4S OEM */
  1377. case 3:
  1378. HFC_outb(hc, R_GPIO_SEL, 0xf0);
  1379. HFC_outb(hc, R_GPIO_EN1, 0xff);
  1380. HFC_outb(hc, R_GPIO_OUT1, 0x00);
  1381. break;
  1382. }
  1383. if (test_bit(HFC_CHIP_EMBSD, &hc->chip)) {
  1384. hc->hw.r_st_sync = 0x10; /* V_AUTO_SYNCI */
  1385. HFC_outb(hc, R_ST_SYNC, hc->hw.r_st_sync);
  1386. }
  1387. /* set master clock */
  1388. if (hc->masterclk >= 0) {
  1389. if (debug & DEBUG_HFCMULTI_INIT)
  1390. printk(KERN_DEBUG "%s: setting ST master clock "
  1391. "to port %d (0..%d)\n",
  1392. __func__, hc->masterclk, hc->ports - 1);
  1393. hc->hw.r_st_sync |= (hc->masterclk | V_AUTO_SYNC);
  1394. HFC_outb(hc, R_ST_SYNC, hc->hw.r_st_sync);
  1395. }
  1396. /* setting misc irq */
  1397. HFC_outb(hc, R_IRQMSK_MISC, hc->hw.r_irqmsk_misc);
  1398. if (debug & DEBUG_HFCMULTI_INIT)
  1399. printk(KERN_DEBUG "r_irqmsk_misc.2: 0x%x\n",
  1400. hc->hw.r_irqmsk_misc);
  1401. /* RAM access test */
  1402. HFC_outb(hc, R_RAM_ADDR0, 0);
  1403. HFC_outb(hc, R_RAM_ADDR1, 0);
  1404. HFC_outb(hc, R_RAM_ADDR2, 0);
  1405. for (i = 0; i < 256; i++) {
  1406. HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
  1407. HFC_outb_nodebug(hc, R_RAM_DATA, ((i * 3) & 0xff));
  1408. }
  1409. for (i = 0; i < 256; i++) {
  1410. HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
  1411. HFC_inb_nodebug(hc, R_RAM_DATA);
  1412. rval = HFC_inb_nodebug(hc, R_INT_DATA);
  1413. if (rval != ((i * 3) & 0xff)) {
  1414. printk(KERN_DEBUG
  1415. "addr:%x val:%x should:%x\n", i, rval,
  1416. (i * 3) & 0xff);
  1417. err++;
  1418. }
  1419. }
  1420. if (err) {
  1421. printk(KERN_DEBUG "aborting - %d RAM access errors\n", err);
  1422. err = -EIO;
  1423. goto out;
  1424. }
  1425. if (debug & DEBUG_HFCMULTI_INIT)
  1426. printk(KERN_DEBUG "%s: done\n", __func__);
  1427. out:
  1428. spin_unlock_irqrestore(&hc->lock, flags);
  1429. return err;
  1430. }
  1431. /*
  1432. * control the watchdog
  1433. */
  1434. static void
  1435. hfcmulti_watchdog(struct hfc_multi *hc)
  1436. {
  1437. hc->wdcount++;
  1438. if (hc->wdcount > 10) {
  1439. hc->wdcount = 0;
  1440. hc->wdbyte = hc->wdbyte == V_GPIO_OUT2 ?
  1441. V_GPIO_OUT3 : V_GPIO_OUT2;
  1442. /* printk("Sending Watchdog Kill %x\n",hc->wdbyte); */
  1443. HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
  1444. HFC_outb(hc, R_GPIO_OUT0, hc->wdbyte);
  1445. }
  1446. }
  1447. /*
  1448. * output leds
  1449. */
  1450. static void
  1451. hfcmulti_leds(struct hfc_multi *hc)
  1452. {
  1453. unsigned long lled;
  1454. unsigned long leddw;
  1455. int i, state, active, leds;
  1456. struct dchannel *dch;
  1457. int led[4];
  1458. switch (hc->leds) {
  1459. case 1: /* HFC-E1 OEM */
  1460. /* 2 red steady: LOS
  1461. * 1 red steady: L1 not active
  1462. * 2 green steady: L1 active
  1463. * 1st green flashing: activity on TX
  1464. * 2nd green flashing: activity on RX
  1465. */
  1466. led[0] = 0;
  1467. led[1] = 0;
  1468. led[2] = 0;
  1469. led[3] = 0;
  1470. dch = hc->chan[hc->dnum[0]].dch;
  1471. if (dch) {
  1472. if (hc->chan[hc->dnum[0]].los)
  1473. led[1] = 1;
  1474. if (hc->e1_state != 1) {
  1475. led[0] = 1;
  1476. hc->flash[2] = 0;
  1477. hc->flash[3] = 0;
  1478. } else {
  1479. led[2] = 1;
  1480. led[3] = 1;
  1481. if (!hc->flash[2] && hc->activity_tx)
  1482. hc->flash[2] = poll;
  1483. if (!hc->flash[3] && hc->activity_rx)
  1484. hc->flash[3] = poll;
  1485. if (hc->flash[2] && hc->flash[2] < 1024)
  1486. led[2] = 0;
  1487. if (hc->flash[3] && hc->flash[3] < 1024)
  1488. led[3] = 0;
  1489. if (hc->flash[2] >= 2048)
  1490. hc->flash[2] = 0;
  1491. if (hc->flash[3] >= 2048)
  1492. hc->flash[3] = 0;
  1493. if (hc->flash[2])
  1494. hc->flash[2] += poll;
  1495. if (hc->flash[3])
  1496. hc->flash[3] += poll;
  1497. }
  1498. }
  1499. leds = (led[0] | (led[1]<<2) | (led[2]<<1) | (led[3]<<3))^0xF;
  1500. /* leds are inverted */
  1501. if (leds != (int)hc->ledstate) {
  1502. HFC_outb_nodebug(hc, R_GPIO_OUT1, leds);
  1503. hc->ledstate = leds;
  1504. }
  1505. break;
  1506. case 2: /* HFC-4S OEM */
  1507. /* red steady: PH_DEACTIVATE
  1508. * green steady: PH_ACTIVATE
  1509. * green flashing: activity on TX
  1510. */
  1511. for (i = 0; i < 4; i++) {
  1512. state = 0;
  1513. active = -1;
  1514. dch = hc->chan[(i << 2) | 2].dch;
  1515. if (dch) {
  1516. state = dch->state;
  1517. if (dch->dev.D.protocol == ISDN_P_NT_S0)
  1518. active = 3;
  1519. else
  1520. active = 7;
  1521. }
  1522. if (state) {
  1523. if (state == active) {
  1524. led[i] = 1; /* led green */
  1525. hc->activity_tx |= hc->activity_rx;
  1526. if (!hc->flash[i] &&
  1527. (hc->activity_tx & (1 << i)))
  1528. hc->flash[i] = poll;
  1529. if (hc->flash[i] && hc->flash[i] < 1024)
  1530. led[i] = 0; /* led off */
  1531. if (hc->flash[i] >= 2048)
  1532. hc->flash[i] = 0;
  1533. if (hc->flash[i])
  1534. hc->flash[i] += poll;
  1535. } else {
  1536. led[i] = 2; /* led red */
  1537. hc->flash[i] = 0;
  1538. }
  1539. } else
  1540. led[i] = 0; /* led off */
  1541. }
  1542. if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
  1543. leds = 0;
  1544. for (i = 0; i < 4; i++) {
  1545. if (led[i] == 1) {
  1546. /*green*/
  1547. leds |= (0x2 << (i * 2));
  1548. } else if (led[i] == 2) {
  1549. /*red*/
  1550. leds |= (0x1 << (i * 2));
  1551. }
  1552. }
  1553. if (leds != (int)hc->ledstate) {
  1554. vpm_out(hc, 0, 0x1a8 + 3, leds);
  1555. hc->ledstate = leds;
  1556. }
  1557. } else {
  1558. leds = ((led[3] > 0) << 0) | ((led[1] > 0) << 1) |
  1559. ((led[0] > 0) << 2) | ((led[2] > 0) << 3) |
  1560. ((led[3] & 1) << 4) | ((led[1] & 1) << 5) |
  1561. ((led[0] & 1) << 6) | ((led[2] & 1) << 7);
  1562. if (leds != (int)hc->ledstate) {
  1563. HFC_outb_nodebug(hc, R_GPIO_EN1, leds & 0x0F);
  1564. HFC_outb_nodebug(hc, R_GPIO_OUT1, leds >> 4);
  1565. hc->ledstate = leds;
  1566. }
  1567. }
  1568. break;
  1569. case 3: /* HFC 1S/2S Beronet */
  1570. /* red steady: PH_DEACTIVATE
  1571. * green steady: PH_ACTIVATE
  1572. * green flashing: activity on TX
  1573. */
  1574. for (i = 0; i < 2; i++) {
  1575. state = 0;
  1576. active = -1;
  1577. dch = hc->chan[(i << 2) | 2].dch;
  1578. if (dch) {
  1579. state = dch->state;
  1580. if (dch->dev.D.protocol == ISDN_P_NT_S0)
  1581. active = 3;
  1582. else
  1583. active = 7;
  1584. }
  1585. if (state) {
  1586. if (state == active) {
  1587. led[i] = 1; /* led green */
  1588. hc->activity_tx |= hc->activity_rx;
  1589. if (!hc->flash[i] &&
  1590. (hc->activity_tx & (1 << i)))
  1591. hc->flash[i] = poll;
  1592. if (hc->flash[i] < 1024)
  1593. led[i] = 0; /* led off */
  1594. if (hc->flash[i] >= 2048)
  1595. hc->flash[i] = 0;
  1596. if (hc->flash[i])
  1597. hc->flash[i] += poll;
  1598. } else {
  1599. led[i] = 2; /* led red */
  1600. hc->flash[i] = 0;
  1601. }
  1602. } else
  1603. led[i] = 0; /* led off */
  1604. }
  1605. leds = (led[0] > 0) | ((led[1] > 0) << 1) | ((led[0]&1) << 2)
  1606. | ((led[1]&1) << 3);
  1607. if (leds != (int)hc->ledstate) {
  1608. HFC_outb_nodebug(hc, R_GPIO_EN1,
  1609. ((led[0] > 0) << 2) | ((led[1] > 0) << 3));
  1610. HFC_outb_nodebug(hc, R_GPIO_OUT1,
  1611. ((led[0] & 1) << 2) | ((led[1] & 1) << 3));
  1612. hc->ledstate = leds;
  1613. }
  1614. break;
  1615. case 8: /* HFC 8S+ Beronet */
  1616. /* off: PH_DEACTIVATE
  1617. * steady: PH_ACTIVATE
  1618. * flashing: activity on TX
  1619. */
  1620. lled = 0xff; /* leds off */
  1621. for (i = 0; i < 8; i++) {
  1622. state = 0;
  1623. active = -1;
  1624. dch = hc->chan[(i << 2) | 2].dch;
  1625. if (dch) {
  1626. state = dch->state;
  1627. if (dch->dev.D.protocol == ISDN_P_NT_S0)
  1628. active = 3;
  1629. else
  1630. active = 7;
  1631. }
  1632. if (state) {
  1633. if (state == active) {
  1634. lled &= ~(1 << i); /* led on */
  1635. hc->activity_tx |= hc->activity_rx;
  1636. if (!hc->flash[i] &&
  1637. (hc->activity_tx & (1 << i)))
  1638. hc->flash[i] = poll;
  1639. if (hc->flash[i] < 1024)
  1640. lled |= 1 << i; /* led off */
  1641. if (hc->flash[i] >= 2048)
  1642. hc->flash[i] = 0;
  1643. if (hc->flash[i])
  1644. hc->flash[i] += poll;
  1645. } else
  1646. hc->flash[i] = 0;
  1647. }
  1648. }
  1649. leddw = lled << 24 | lled << 16 | lled << 8 | lled;
  1650. if (leddw != hc->ledstate) {
  1651. /* HFC_outb(hc, R_BRG_PCM_CFG, 1);
  1652. HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); */
  1653. /* was _io before */
  1654. HFC_outb_nodebug(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
  1655. outw(0x4000, hc->pci_iobase + 4);
  1656. outl(leddw, hc->pci_iobase);
  1657. HFC_outb_nodebug(hc, R_BRG_PCM_CFG, V_PCM_CLK);
  1658. hc->ledstate = leddw;
  1659. }
  1660. break;
  1661. }
  1662. hc->activity_tx = 0;
  1663. hc->activity_rx = 0;
  1664. }
  1665. /*
  1666. * read dtmf coefficients
  1667. */
  1668. static void
  1669. hfcmulti_dtmf(struct hfc_multi *hc)
  1670. {
  1671. s32 *coeff;
  1672. u_int mantissa;
  1673. int co, ch;
  1674. struct bchannel *bch = NULL;
  1675. u8 exponent;
  1676. int dtmf = 0;
  1677. int addr;
  1678. u16 w_float;
  1679. struct sk_buff *skb;
  1680. struct mISDNhead *hh;
  1681. if (debug & DEBUG_HFCMULTI_DTMF)
  1682. printk(KERN_DEBUG "%s: dtmf detection irq\n", __func__);
  1683. for (ch = 0; ch <= 31; ch++) {
  1684. /* only process enabled B-channels */
  1685. bch = hc->chan[ch].bch;
  1686. if (!bch)
  1687. continue;
  1688. if (!hc->created[hc->chan[ch].port])
  1689. continue;
  1690. if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
  1691. continue;
  1692. if (debug & DEBUG_HFCMULTI_DTMF)
  1693. printk(KERN_DEBUG "%s: dtmf channel %d:",
  1694. __func__, ch);
  1695. coeff = &(hc->chan[ch].coeff[hc->chan[ch].coeff_count * 16]);
  1696. dtmf = 1;
  1697. for (co = 0; co < 8; co++) {
  1698. /* read W(n-1) coefficient */
  1699. addr = hc->DTMFbase + ((co << 7) | (ch << 2));
  1700. HFC_outb_nodebug(hc, R_RAM_ADDR0, addr);
  1701. HFC_outb_nodebug(hc, R_RAM_ADDR1, addr >> 8);
  1702. HFC_outb_nodebug(hc, R_RAM_ADDR2, (addr >> 16)
  1703. | V_ADDR_INC);
  1704. w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
  1705. w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
  1706. if (debug & DEBUG_HFCMULTI_DTMF)
  1707. printk(" %04x", w_float);
  1708. /* decode float (see chip doc) */
  1709. mantissa = w_float & 0x0fff;
  1710. if (w_float & 0x8000)
  1711. mantissa |= 0xfffff000;
  1712. exponent = (w_float >> 12) & 0x7;
  1713. if (exponent) {
  1714. mantissa ^= 0x1000;
  1715. mantissa <<= (exponent - 1);
  1716. }
  1717. /* store coefficient */
  1718. coeff[co << 1] = mantissa;
  1719. /* read W(n) coefficient */
  1720. w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
  1721. w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
  1722. if (debug & DEBUG_HFCMULTI_DTMF)
  1723. printk(" %04x", w_float);
  1724. /* decode float (see chip doc) */
  1725. mantissa = w_float & 0x0fff;
  1726. if (w_float & 0x8000)
  1727. mantissa |= 0xfffff000;
  1728. exponent = (w_float >> 12) & 0x7;
  1729. if (exponent) {
  1730. mantissa ^= 0x1000;
  1731. mantissa <<= (exponent - 1);
  1732. }
  1733. /* store coefficient */
  1734. coeff[(co << 1) | 1] = mantissa;
  1735. }
  1736. if (debug & DEBUG_HFCMULTI_DTMF)
  1737. printk(" DTMF ready %08x %08x %08x %08x "
  1738. "%08x %08x %08x %08x\n",
  1739. coeff[0], coeff[1], coeff[2], coeff[3],
  1740. coeff[4], coeff[5], coeff[6], coeff[7]);
  1741. hc->chan[ch].coeff_count++;
  1742. if (hc->chan[ch].coeff_count == 8) {
  1743. hc->chan[ch].coeff_count = 0;
  1744. skb = mI_alloc_skb(512, GFP_ATOMIC);
  1745. if (!skb) {
  1746. printk(KERN_DEBUG "%s: No memory for skb\n",
  1747. __func__);
  1748. continue;
  1749. }
  1750. hh = mISDN_HEAD_P(skb);
  1751. hh->prim = PH_CONTROL_IND;
  1752. hh->id = DTMF_HFC_COEF;
  1753. memcpy(skb_put(skb, 512), hc->chan[ch].coeff, 512);
  1754. recv_Bchannel_skb(bch, skb);
  1755. }
  1756. }
  1757. /* restart DTMF processing */
  1758. hc->dtmf = dtmf;
  1759. if (dtmf)
  1760. HFC_outb_nodebug(hc, R_DTMF, hc->hw.r_dtmf | V_RST_DTMF);
  1761. }
  1762. /*
  1763. * fill fifo as much as possible
  1764. */
  1765. static void
  1766. hfcmulti_tx(struct hfc_multi *hc, int ch)
  1767. {
  1768. int i, ii, temp, len = 0;
  1769. int Zspace, z1, z2; /* must be int for calculation */
  1770. int Fspace, f1, f2;
  1771. u_char *d;
  1772. int *txpending, slot_tx;
  1773. struct bchannel *bch;
  1774. struct dchannel *dch;
  1775. struct sk_buff **sp = NULL;
  1776. int *idxp;
  1777. bch = hc->chan[ch].bch;
  1778. dch = hc->chan[ch].dch;
  1779. if ((!dch) && (!bch))
  1780. return;
  1781. txpending = &hc->chan[ch].txpending;
  1782. slot_tx = hc->chan[ch].slot_tx;
  1783. if (dch) {
  1784. if (!test_bit(FLG_ACTIVE, &dch->Flags))
  1785. return;
  1786. sp = &dch->tx_skb;
  1787. idxp = &dch->tx_idx;
  1788. } else {
  1789. if (!test_bit(FLG_ACTIVE, &bch->Flags))
  1790. return;
  1791. sp = &bch->tx_skb;
  1792. idxp = &bch->tx_idx;
  1793. }
  1794. if (*sp)
  1795. len = (*sp)->len;
  1796. if ((!len) && *txpending != 1)
  1797. return; /* no data */
  1798. if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
  1799. (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
  1800. (hc->chan[ch].slot_rx < 0) &&
  1801. (hc->chan[ch].slot_tx < 0))
  1802. HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch << 1));
  1803. else
  1804. HFC_outb_nodebug(hc, R_FIFO, ch << 1);
  1805. HFC_wait_nodebug(hc);
  1806. if (*txpending == 2) {
  1807. /* reset fifo */
  1808. HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
  1809. HFC_wait_nodebug(hc);
  1810. HFC_outb(hc, A_SUBCH_CFG, 0);
  1811. *txpending = 1;
  1812. }
  1813. next_frame:
  1814. if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
  1815. f1 = HFC_inb_nodebug(hc, A_F1);
  1816. f2 = HFC_inb_nodebug(hc, A_F2);
  1817. while (f2 != (temp = HFC_inb_nodebug(hc, A_F2))) {
  1818. if (debug & DEBUG_HFCMULTI_FIFO)
  1819. printk(KERN_DEBUG
  1820. "%s(card %d): reread f2 because %d!=%d\n",
  1821. __func__, hc->id + 1, temp, f2);
  1822. f2 = temp; /* repeat until F2 is equal */
  1823. }
  1824. Fspace = f2 - f1 - 1;
  1825. if (Fspace < 0)
  1826. Fspace += hc->Flen;
  1827. /*
  1828. * Old FIFO handling doesn't give us the current Z2 read
  1829. * pointer, so we cannot send the next frame before the fifo
  1830. * is empty. It makes no difference except for a slightly
  1831. * lower performance.
  1832. */
  1833. if (test_bit(HFC_CHIP_REVISION0, &hc->chip)) {
  1834. if (f1 != f2)
  1835. Fspace = 0;
  1836. else
  1837. Fspace = 1;
  1838. }
  1839. /* one frame only for ST D-channels, to allow resending */
  1840. if (hc->ctype != HFC_TYPE_E1 && dch) {
  1841. if (f1 != f2)
  1842. Fspace = 0;
  1843. }
  1844. /* F-counter full condition */
  1845. if (Fspace == 0)
  1846. return;
  1847. }
  1848. z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
  1849. z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
  1850. while (z2 != (temp = (HFC_inw_nodebug(hc, A_Z2) - hc->Zmin))) {
  1851. if (debug & DEBUG_HFCMULTI_FIFO)
  1852. printk(KERN_DEBUG "%s(card %d): reread z2 because "
  1853. "%d!=%d\n", __func__, hc->id + 1, temp, z2);
  1854. z2 = temp; /* repeat unti Z2 is equal */
  1855. }
  1856. hc->chan[ch].Zfill = z1 - z2;
  1857. if (hc->chan[ch].Zfill < 0)
  1858. hc->chan[ch].Zfill += hc->Zlen;
  1859. Zspace = z2 - z1;
  1860. if (Zspace <= 0)
  1861. Zspace += hc->Zlen;
  1862. Zspace -= 4; /* keep not too full, so pointers will not overrun */
  1863. /* fill transparent data only to maxinum transparent load (minus 4) */
  1864. if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
  1865. Zspace = Zspace - hc->Zlen + hc->max_trans;
  1866. if (Zspace <= 0) /* no space of 4 bytes */
  1867. return;
  1868. /* if no data */
  1869. if (!len) {
  1870. if (z1 == z2) { /* empty */
  1871. /* if done with FIFO audio data during PCM connection */
  1872. if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) &&
  1873. *txpending && slot_tx >= 0) {
  1874. if (debug & DEBUG_HFCMULTI_MODE)
  1875. printk(KERN_DEBUG
  1876. "%s: reconnecting PCM due to no "
  1877. "more FIFO data: channel %d "
  1878. "slot_tx %d\n",
  1879. __func__, ch, slot_tx);
  1880. /* connect slot */
  1881. if (hc->ctype == HFC_TYPE_XHFC)
  1882. HFC_outb(hc, A_CON_HDLC, 0xc0
  1883. | 0x07 << 2 | V_HDLC_TRP | V_IFF);
  1884. /* Enable FIFO, no interrupt */
  1885. else
  1886. HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
  1887. V_HDLC_TRP | V_IFF);
  1888. HFC_outb_nodebug(hc, R_FIFO, ch << 1 | 1);
  1889. HFC_wait_nodebug(hc);
  1890. if (hc->ctype == HFC_TYPE_XHFC)
  1891. HFC_outb(hc, A_CON_HDLC, 0xc0
  1892. | 0x07 << 2 | V_HDLC_TRP | V_IFF);
  1893. /* Enable FIFO, no interrupt */
  1894. else
  1895. HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
  1896. V_HDLC_TRP | V_IFF);
  1897. HFC_outb_nodebug(hc, R_FIFO, ch << 1);
  1898. HFC_wait_nodebug(hc);
  1899. }
  1900. *txpending = 0;
  1901. }
  1902. return; /* no data */
  1903. }
  1904. /* "fill fifo if empty" feature */
  1905. if (bch && test_bit(FLG_FILLEMPTY, &bch->Flags)
  1906. && !test_bit(FLG_HDLC, &bch->Flags) && z2 == z1) {
  1907. if (debug & DEBUG_HFCMULTI_FILL)
  1908. printk(KERN_DEBUG "%s: buffer empty, so we have "
  1909. "underrun\n", __func__);
  1910. /* fill buffer, to prevent future underrun */
  1911. hc->write_fifo(hc, hc->silence_data, poll >> 1);
  1912. Zspace -= (poll >> 1);
  1913. }
  1914. /* if audio data and connected slot */
  1915. if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) && (!*txpending)
  1916. && slot_tx >= 0) {
  1917. if (debug & DEBUG_HFCMULTI_MODE)
  1918. printk(KERN_DEBUG "%s: disconnecting PCM due to "
  1919. "FIFO data: channel %d slot_tx %d\n",
  1920. __func__, ch, slot_tx);
  1921. /* disconnect slot */
  1922. if (hc->ctype == HFC_TYPE_XHFC)
  1923. HFC_outb(hc, A_CON_HDLC, 0x80
  1924. | 0x07 << 2 | V_HDLC_TRP | V_IFF);
  1925. /* Enable FIFO, no interrupt */
  1926. else
  1927. HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 |
  1928. V_HDLC_TRP | V_IFF);
  1929. HFC_outb_nodebug(hc, R_FIFO, ch << 1 | 1);
  1930. HFC_wait_nodebug(hc);
  1931. if (hc->ctype == HFC_TYPE_XHFC)
  1932. HFC_outb(hc, A_CON_HDLC, 0x80
  1933. | 0x07 << 2 | V_HDLC_TRP | V_IFF);
  1934. /* Enable FIFO, no interrupt */
  1935. else
  1936. HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 |
  1937. V_HDLC_TRP | V_IFF);
  1938. HFC_outb_nodebug(hc, R_FIFO, ch << 1);
  1939. HFC_wait_nodebug(hc);
  1940. }
  1941. *txpending = 1;
  1942. /* show activity */
  1943. if (dch)
  1944. hc->activity_tx |= 1 << hc->chan[ch].port;
  1945. /* fill fifo to what we have left */
  1946. ii = len;
  1947. if (dch || test_bit(FLG_HDLC, &bch->Flags))
  1948. temp = 1;
  1949. else
  1950. temp = 0;
  1951. i = *idxp;
  1952. d = (*sp)->data + i;
  1953. if (ii - i > Zspace)
  1954. ii = Zspace + i;
  1955. if (debug & DEBUG_HFCMULTI_FIFO)
  1956. printk(KERN_DEBUG "%s(card %d): fifo(%d) has %d bytes space "
  1957. "left (z1=%04x, z2=%04x) sending %d of %d bytes %s\n",
  1958. __func__, hc->id + 1, ch, Zspace, z1, z2, ii-i, len-i,
  1959. temp ? "HDLC" : "TRANS");
  1960. /* Have to prep the audio data */
  1961. hc->write_fifo(hc, d, ii - i);
  1962. hc->chan[ch].Zfill += ii - i;
  1963. *idxp = ii;
  1964. /* if not all data has been written */
  1965. if (ii != len) {
  1966. /* NOTE: fifo is started by the calling function */
  1967. return;
  1968. }
  1969. /* if all data has been written, terminate frame */
  1970. if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
  1971. /* increment f-counter */
  1972. HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
  1973. HFC_wait_nodebug(hc);
  1974. }
  1975. dev_kfree_skb(*sp);
  1976. /* check for next frame */
  1977. if (bch && get_next_bframe(bch)) {
  1978. len = (*sp)->len;
  1979. goto next_frame;
  1980. }
  1981. if (dch && get_next_dframe(dch)) {
  1982. len = (*sp)->len;
  1983. goto next_frame;
  1984. }
  1985. /*
  1986. * now we have no more data, so in case of transparent,
  1987. * we set the last byte in fifo to 'silence' in case we will get
  1988. * no more data at all. this prevents sending an undefined value.
  1989. */
  1990. if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
  1991. HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence);
  1992. }
  1993. /* NOTE: only called if E1 card is in active state */
  1994. static void
  1995. hfcmulti_rx(struct hfc_multi *hc, int ch)
  1996. {
  1997. int temp;
  1998. int Zsize, z1, z2 = 0; /* = 0, to make GCC happy */
  1999. int f1 = 0, f2 = 0; /* = 0, to make GCC happy */
  2000. int again = 0;
  2001. struct bchannel *bch;
  2002. struct dchannel *dch = NULL;
  2003. struct sk_buff *skb, **sp = NULL;
  2004. int maxlen;
  2005. bch = hc->chan[ch].bch;
  2006. if (bch) {
  2007. if (!test_bit(FLG_ACTIVE, &bch->Flags))
  2008. return;
  2009. } else if (hc->chan[ch].dch) {
  2010. dch = hc->chan[ch].dch;
  2011. if (!test_bit(FLG_ACTIVE, &dch->Flags))
  2012. return;
  2013. } else {
  2014. return;
  2015. }
  2016. next_frame:
  2017. /* on first AND before getting next valid frame, R_FIFO must be written
  2018. to. */
  2019. if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
  2020. (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
  2021. (hc->chan[ch].slot_rx < 0) &&
  2022. (hc->chan[ch].slot_tx < 0))
  2023. HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch << 1) | 1);
  2024. else
  2025. HFC_outb_nodebug(hc, R_FIFO, (ch << 1) | 1);
  2026. HFC_wait_nodebug(hc);
  2027. /* ignore if rx is off BUT change fifo (above) to start pending TX */
  2028. if (hc->chan[ch].rx_off) {
  2029. if (bch)
  2030. bch->dropcnt += poll; /* not exact but fair enough */
  2031. return;
  2032. }
  2033. if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
  2034. f1 = HFC_inb_nodebug(hc, A_F1);
  2035. while (f1 != (temp = HFC_inb_nodebug(hc, A_F1))) {
  2036. if (debug & DEBUG_HFCMULTI_FIFO)
  2037. printk(KERN_DEBUG
  2038. "%s(card %d): reread f1 because %d!=%d\n",
  2039. __func__, hc->id + 1, temp, f1);
  2040. f1 = temp; /* repeat until F1 is equal */
  2041. }
  2042. f2 = HFC_inb_nodebug(hc, A_F2);
  2043. }
  2044. z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
  2045. while (z1 != (temp = (HFC_inw_nodebug(hc, A_Z1) - hc->Zmin))) {
  2046. if (debug & DEBUG_HFCMULTI_FIFO)
  2047. printk(KERN_DEBUG "%s(card %d): reread z2 because "
  2048. "%d!=%d\n", __func__, hc->id + 1, temp, z2);
  2049. z1 = temp; /* repeat until Z1 is equal */
  2050. }
  2051. z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
  2052. Zsize = z1 - z2;
  2053. if ((dch || test_bit(FLG_HDLC, &bch->Flags)) && f1 != f2)
  2054. /* complete hdlc frame */
  2055. Zsize++;
  2056. if (Zsize < 0)
  2057. Zsize += hc->Zlen;
  2058. /* if buffer is empty */
  2059. if (Zsize <= 0)
  2060. return;
  2061. if (bch) {
  2062. maxlen = bchannel_get_rxbuf(bch, Zsize);
  2063. if (maxlen < 0) {
  2064. pr_warning("card%d.B%d: No bufferspace for %d bytes\n",
  2065. hc->id + 1, bch->nr, Zsize);
  2066. return;
  2067. }
  2068. sp = &bch->rx_skb;
  2069. maxlen = bch->maxlen;
  2070. } else { /* Dchannel */
  2071. sp = &dch->rx_skb;
  2072. maxlen = dch->maxlen + 3;
  2073. if (*sp == NULL) {
  2074. *sp = mI_alloc_skb(maxlen, GFP_ATOMIC);
  2075. if (*sp == NULL) {
  2076. pr_warning("card%d: No mem for dch rx_skb\n",
  2077. hc->id + 1);
  2078. return;
  2079. }
  2080. }
  2081. }
  2082. /* show activity */
  2083. if (dch)
  2084. hc->activity_rx |= 1 << hc->chan[ch].port;
  2085. /* empty fifo with what we have */
  2086. if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
  2087. if (debug & DEBUG_HFCMULTI_FIFO)
  2088. printk(KERN_DEBUG "%s(card %d): fifo(%d) reading %d "
  2089. "bytes (z1=%04x, z2=%04x) HDLC %s (f1=%d, f2=%d) "
  2090. "got=%d (again %d)\n", __func__, hc->id + 1, ch,
  2091. Zsize, z1, z2, (f1 == f2) ? "fragment" : "COMPLETE",
  2092. f1, f2, Zsize + (*sp)->len, again);
  2093. /* HDLC */
  2094. if ((Zsize + (*sp)->len) > maxlen) {
  2095. if (debug & DEBUG_HFCMULTI_FIFO)
  2096. printk(KERN_DEBUG
  2097. "%s(card %d): hdlc-frame too large.\n",
  2098. __func__, hc->id + 1);
  2099. skb_trim(*sp, 0);
  2100. HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
  2101. HFC_wait_nodebug(hc);
  2102. return;
  2103. }
  2104. hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
  2105. if (f1 != f2) {
  2106. /* increment Z2,F2-counter */
  2107. HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
  2108. HFC_wait_nodebug(hc);
  2109. /* check size */
  2110. if ((*sp)->len < 4) {
  2111. if (debug & DEBUG_HFCMULTI_FIFO)
  2112. printk(KERN_DEBUG
  2113. "%s(card %d): Frame below minimum "
  2114. "size\n", __func__, hc->id + 1);
  2115. skb_trim(*sp, 0);
  2116. goto next_frame;
  2117. }
  2118. /* there is at least one complete frame, check crc */
  2119. if ((*sp)->data[(*sp)->len - 1]) {
  2120. if (debug & DEBUG_HFCMULTI_CRC)
  2121. printk(KERN_DEBUG
  2122. "%s: CRC-error\n", __func__);
  2123. skb_trim(*sp, 0);
  2124. goto next_frame;
  2125. }
  2126. skb_trim(*sp, (*sp)->len - 3);
  2127. if ((*sp)->len < MISDN_COPY_SIZE) {
  2128. skb = *sp;
  2129. *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
  2130. if (*sp) {
  2131. memcpy(skb_put(*sp, skb->len),
  2132. skb->data, skb->len);
  2133. skb_trim(skb, 0);
  2134. } else {
  2135. printk(KERN_DEBUG "%s: No mem\n",
  2136. __func__);
  2137. *sp = skb;
  2138. skb = NULL;
  2139. }
  2140. } else {
  2141. skb = NULL;
  2142. }
  2143. if (debug & DEBUG_HFCMULTI_FIFO) {
  2144. printk(KERN_DEBUG "%s(card %d):",
  2145. __func__, hc->id + 1);
  2146. temp = 0;
  2147. while (temp < (*sp)->len)
  2148. printk(" %02x", (*sp)->data[temp++]);
  2149. printk("\n");
  2150. }
  2151. if (dch)
  2152. recv_Dchannel(dch);
  2153. else
  2154. recv_Bchannel(bch, MISDN_ID_ANY, false);
  2155. *sp = skb;
  2156. again++;
  2157. goto next_frame;
  2158. }
  2159. /* there is an incomplete frame */
  2160. } else {
  2161. /* transparent */
  2162. hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
  2163. if (debug & DEBUG_HFCMULTI_FIFO)
  2164. printk(KERN_DEBUG
  2165. "%s(card %d): fifo(%d) reading %d bytes "
  2166. "(z1=%04x, z2=%04x) TRANS\n",
  2167. __func__, hc->id + 1, ch, Zsize, z1, z2);
  2168. /* only bch is transparent */
  2169. recv_Bchannel(bch, hc->chan[ch].Zfill, false);
  2170. }
  2171. }
  2172. /*
  2173. * Interrupt handler
  2174. */
  2175. static void
  2176. signal_state_up(struct dchannel *dch, int info, char *msg)
  2177. {
  2178. struct sk_buff *skb;
  2179. int id, data = info;
  2180. if (debug & DEBUG_HFCMULTI_STATE)
  2181. printk(KERN_DEBUG "%s: %s\n", __func__, msg);
  2182. id = TEI_SAPI | (GROUP_TEI << 8); /* manager address */
  2183. skb = _alloc_mISDN_skb(MPH_INFORMATION_IND, id, sizeof(data), &data,
  2184. GFP_ATOMIC);
  2185. if (!skb)
  2186. return;
  2187. recv_Dchannel_skb(dch, skb);
  2188. }
  2189. static inline void
  2190. handle_timer_irq(struct hfc_multi *hc)
  2191. {
  2192. int ch, temp;
  2193. struct dchannel *dch;
  2194. u_long flags;
  2195. /* process queued resync jobs */
  2196. if (hc->e1_resync) {
  2197. /* lock, so e1_resync gets not changed */
  2198. spin_lock_irqsave(&HFClock, flags);
  2199. if (hc->e1_resync & 1) {
  2200. if (debug & DEBUG_HFCMULTI_PLXSD)
  2201. printk(KERN_DEBUG "Enable SYNC_I\n");
  2202. HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC);
  2203. /* disable JATT, if RX_SYNC is set */
  2204. if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
  2205. HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
  2206. }
  2207. if (hc->e1_resync & 2) {
  2208. if (debug & DEBUG_HFCMULTI_PLXSD)
  2209. printk(KERN_DEBUG "Enable jatt PLL\n");
  2210. HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
  2211. }
  2212. if (hc->e1_resync & 4) {
  2213. if (debug & DEBUG_HFCMULTI_PLXSD)
  2214. printk(KERN_DEBUG
  2215. "Enable QUARTZ for HFC-E1\n");
  2216. /* set jatt to quartz */
  2217. HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC
  2218. | V_JATT_OFF);
  2219. /* switch to JATT, in case it is not already */
  2220. HFC_outb(hc, R_SYNC_OUT, 0);
  2221. }
  2222. hc->e1_resync = 0;
  2223. spin_unlock_irqrestore(&HFClock, flags);
  2224. }
  2225. if (hc->ctype != HFC_TYPE_E1 || hc->e1_state == 1)
  2226. for (ch = 0; ch <= 31; ch++) {
  2227. if (hc->created[hc->chan[ch].port]) {
  2228. hfcmulti_tx(hc, ch);
  2229. /* fifo is started when switching to rx-fifo */
  2230. hfcmulti_rx(hc, ch);
  2231. if (hc->chan[ch].dch &&
  2232. hc->chan[ch].nt_timer > -1) {
  2233. dch = hc->chan[ch].dch;
  2234. if (!(--hc->chan[ch].nt_timer)) {
  2235. schedule_event(dch,
  2236. FLG_PHCHANGE);
  2237. if (debug &
  2238. DEBUG_HFCMULTI_STATE)
  2239. printk(KERN_DEBUG
  2240. "%s: nt_timer at "
  2241. "state %x\n",
  2242. __func__,
  2243. dch->state);
  2244. }
  2245. }
  2246. }
  2247. }
  2248. if (hc->ctype == HFC_TYPE_E1 && hc->created[0]) {
  2249. dch = hc->chan[hc->dnum[0]].dch;
  2250. /* LOS */
  2251. temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_SIG_LOS;
  2252. hc->chan[hc->dnum[0]].los = temp;
  2253. if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dnum[0]].cfg)) {
  2254. if (!temp && hc->chan[hc->dnum[0]].los)
  2255. signal_state_up(dch, L1_SIGNAL_LOS_ON,
  2256. "LOS detected");
  2257. if (temp && !hc->chan[hc->dnum[0]].los)
  2258. signal_state_up(dch, L1_SIGNAL_LOS_OFF,
  2259. "LOS gone");
  2260. }
  2261. if (test_bit(HFC_CFG_REPORT_AIS, &hc->chan[hc->dnum[0]].cfg)) {
  2262. /* AIS */
  2263. temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_AIS;
  2264. if (!temp && hc->chan[hc->dnum[0]].ais)
  2265. signal_state_up(dch, L1_SIGNAL_AIS_ON,
  2266. "AIS detected");
  2267. if (temp && !hc->chan[hc->dnum[0]].ais)
  2268. signal_state_up(dch, L1_SIGNAL_AIS_OFF,
  2269. "AIS gone");
  2270. hc->chan[hc->dnum[0]].ais = temp;
  2271. }
  2272. if (test_bit(HFC_CFG_REPORT_SLIP, &hc->chan[hc->dnum[0]].cfg)) {
  2273. /* SLIP */
  2274. temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_RX;
  2275. if (!temp && hc->chan[hc->dnum[0]].slip_rx)
  2276. signal_state_up(dch, L1_SIGNAL_SLIP_RX,
  2277. " bit SLIP detected RX");
  2278. hc->chan[hc->dnum[0]].slip_rx = temp;
  2279. temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_TX;
  2280. if (!temp && hc->chan[hc->dnum[0]].slip_tx)
  2281. signal_state_up(dch, L1_SIGNAL_SLIP_TX,
  2282. " bit SLIP detected TX");
  2283. hc->chan[hc->dnum[0]].slip_tx = temp;
  2284. }
  2285. if (test_bit(HFC_CFG_REPORT_RDI, &hc->chan[hc->dnum[0]].cfg)) {
  2286. /* RDI */
  2287. temp = HFC_inb_nodebug(hc, R_RX_SL0_0) & V_A;
  2288. if (!temp && hc->chan[hc->dnum[0]].rdi)
  2289. signal_state_up(dch, L1_SIGNAL_RDI_ON,
  2290. "RDI detected");
  2291. if (temp && !hc->chan[hc->dnum[0]].rdi)
  2292. signal_state_up(dch, L1_SIGNAL_RDI_OFF,
  2293. "RDI gone");
  2294. hc->chan[hc->dnum[0]].rdi = temp;
  2295. }
  2296. temp = HFC_inb_nodebug(hc, R_JATT_DIR);
  2297. switch (hc->chan[hc->dnum[0]].sync) {
  2298. case 0:
  2299. if ((temp & 0x60) == 0x60) {
  2300. if (debug & DEBUG_HFCMULTI_SYNC)
  2301. printk(KERN_DEBUG
  2302. "%s: (id=%d) E1 now "
  2303. "in clock sync\n",
  2304. __func__, hc->id);
  2305. HFC_outb(hc, R_RX_OFF,
  2306. hc->chan[hc->dnum[0]].jitter | V_RX_INIT);
  2307. HFC_outb(hc, R_TX_OFF,
  2308. hc->chan[hc->dnum[0]].jitter | V_RX_INIT);
  2309. hc->chan[hc->dnum[0]].sync = 1;
  2310. goto check_framesync;
  2311. }
  2312. break;
  2313. case 1:
  2314. if ((temp & 0x60) != 0x60) {
  2315. if (debug & DEBUG_HFCMULTI_SYNC)
  2316. printk(KERN_DEBUG
  2317. "%s: (id=%d) E1 "
  2318. "lost clock sync\n",
  2319. __func__, hc->id);
  2320. hc->chan[hc->dnum[0]].sync = 0;
  2321. break;
  2322. }
  2323. check_framesync:
  2324. temp = HFC_inb_nodebug(hc, R_SYNC_STA);
  2325. if (temp == 0x27) {
  2326. if (debug & DEBUG_HFCMULTI_SYNC)
  2327. printk(KERN_DEBUG
  2328. "%s: (id=%d) E1 "
  2329. "now in frame sync\n",
  2330. __func__, hc->id);
  2331. hc->chan[hc->dnum[0]].sync = 2;
  2332. }
  2333. break;
  2334. case 2:
  2335. if ((temp & 0x60) != 0x60) {
  2336. if (debug & DEBUG_HFCMULTI_SYNC)
  2337. printk(KERN_DEBUG
  2338. "%s: (id=%d) E1 lost "
  2339. "clock & frame sync\n",
  2340. __func__, hc->id);
  2341. hc->chan[hc->dnum[0]].sync = 0;
  2342. break;
  2343. }
  2344. temp = HFC_inb_nodebug(hc, R_SYNC_STA);
  2345. if (temp != 0x27) {
  2346. if (debug & DEBUG_HFCMULTI_SYNC)
  2347. printk(KERN_DEBUG
  2348. "%s: (id=%d) E1 "
  2349. "lost frame sync\n",
  2350. __func__, hc->id);
  2351. hc->chan[hc->dnum[0]].sync = 1;
  2352. }
  2353. break;
  2354. }
  2355. }
  2356. if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
  2357. hfcmulti_watchdog(hc);
  2358. if (hc->leds)
  2359. hfcmulti_leds(hc);
  2360. }
  2361. static void
  2362. ph_state_irq(struct hfc_multi *hc, u_char r_irq_statech)
  2363. {
  2364. struct dchannel *dch;
  2365. int ch;
  2366. int active;
  2367. u_char st_status, temp;
  2368. /* state machine */
  2369. for (ch = 0; ch <= 31; ch++) {
  2370. if (hc->chan[ch].dch) {
  2371. dch = hc->chan[ch].dch;
  2372. if (r_irq_statech & 1) {
  2373. HFC_outb_nodebug(hc, R_ST_SEL,
  2374. hc->chan[ch].port);
  2375. /* undocumented: delay after R_ST_SEL */
  2376. udelay(1);
  2377. /* undocumented: status changes during read */
  2378. st_status = HFC_inb_nodebug(hc, A_ST_RD_STATE);
  2379. while (st_status != (temp =
  2380. HFC_inb_nodebug(hc, A_ST_RD_STATE))) {
  2381. if (debug & DEBUG_HFCMULTI_STATE)
  2382. printk(KERN_DEBUG "%s: reread "
  2383. "STATE because %d!=%d\n",
  2384. __func__, temp,
  2385. st_status);
  2386. st_status = temp; /* repeat */
  2387. }
  2388. /* Speech Design TE-sync indication */
  2389. if (test_bit(HFC_CHIP_PLXSD, &hc->chip) &&
  2390. dch->dev.D.protocol == ISDN_P_TE_S0) {
  2391. if (st_status & V_FR_SYNC_ST)
  2392. hc->syncronized |=
  2393. (1 << hc->chan[ch].port);
  2394. else
  2395. hc->syncronized &=
  2396. ~(1 << hc->chan[ch].port);
  2397. }
  2398. dch->state = st_status & 0x0f;
  2399. if (dch->dev.D.protocol == ISDN_P_NT_S0)
  2400. active = 3;
  2401. else
  2402. active = 7;
  2403. if (dch->state == active) {
  2404. HFC_outb_nodebug(hc, R_FIFO,
  2405. (ch << 1) | 1);
  2406. HFC_wait_nodebug(hc);
  2407. HFC_outb_nodebug(hc,
  2408. R_INC_RES_FIFO, V_RES_F);
  2409. HFC_wait_nodebug(hc);
  2410. dch->tx_idx = 0;
  2411. }
  2412. schedule_event(dch, FLG_PHCHANGE);
  2413. if (debug & DEBUG_HFCMULTI_STATE)
  2414. printk(KERN_DEBUG
  2415. "%s: S/T newstate %x port %d\n",
  2416. __func__, dch->state,
  2417. hc->chan[ch].port);
  2418. }
  2419. r_irq_statech >>= 1;
  2420. }
  2421. }
  2422. if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
  2423. plxsd_checksync(hc, 0);
  2424. }
  2425. static void
  2426. fifo_irq(struct hfc_multi *hc, int block)
  2427. {
  2428. int ch, j;
  2429. struct dchannel *dch;
  2430. struct bchannel *bch;
  2431. u_char r_irq_fifo_bl;
  2432. r_irq_fifo_bl = HFC_inb_nodebug(hc, R_IRQ_FIFO_BL0 + block);
  2433. j = 0;
  2434. while (j < 8) {
  2435. ch = (block << 2) + (j >> 1);
  2436. dch = hc->chan[ch].dch;
  2437. bch = hc->chan[ch].bch;
  2438. if (((!dch) && (!bch)) || (!hc->created[hc->chan[ch].port])) {
  2439. j += 2;
  2440. continue;
  2441. }
  2442. if (dch && (r_irq_fifo_bl & (1 << j)) &&
  2443. test_bit(FLG_ACTIVE, &dch->Flags)) {
  2444. hfcmulti_tx(hc, ch);
  2445. /* start fifo */
  2446. HFC_outb_nodebug(hc, R_FIFO, 0);
  2447. HFC_wait_nodebug(hc);
  2448. }
  2449. if (bch && (r_irq_fifo_bl & (1 << j)) &&
  2450. test_bit(FLG_ACTIVE, &bch->Flags)) {
  2451. hfcmulti_tx(hc, ch);
  2452. /* start fifo */
  2453. HFC_outb_nodebug(hc, R_FIFO, 0);
  2454. HFC_wait_nodebug(hc);
  2455. }
  2456. j++;
  2457. if (dch && (r_irq_fifo_bl & (1 << j)) &&
  2458. test_bit(FLG_ACTIVE, &dch->Flags)) {
  2459. hfcmulti_rx(hc, ch);
  2460. }
  2461. if (bch && (r_irq_fifo_bl & (1 << j)) &&
  2462. test_bit(FLG_ACTIVE, &bch->Flags)) {
  2463. hfcmulti_rx(hc, ch);
  2464. }
  2465. j++;
  2466. }
  2467. }
  2468. #ifdef IRQ_DEBUG
  2469. int irqsem;
  2470. #endif
  2471. static irqreturn_t
  2472. hfcmulti_interrupt(int intno, void *dev_id)
  2473. {
  2474. #ifdef IRQCOUNT_DEBUG
  2475. static int iq1 = 0, iq2 = 0, iq3 = 0, iq4 = 0,
  2476. iq5 = 0, iq6 = 0, iqcnt = 0;
  2477. #endif
  2478. struct hfc_multi *hc = dev_id;
  2479. struct dchannel *dch;
  2480. u_char r_irq_statech, status, r_irq_misc, r_irq_oview;
  2481. int i;
  2482. void __iomem *plx_acc;
  2483. u_short wval;
  2484. u_char e1_syncsta, temp, temp2;
  2485. u_long flags;
  2486. if (!hc) {
  2487. printk(KERN_ERR "HFC-multi: Spurious interrupt!\n");
  2488. return IRQ_NONE;
  2489. }
  2490. spin_lock(&hc->lock);
  2491. #ifdef IRQ_DEBUG
  2492. if (irqsem)
  2493. printk(KERN_ERR "irq for card %d during irq from "
  2494. "card %d, this is no bug.\n", hc->id + 1, irqsem);
  2495. irqsem = hc->id + 1;
  2496. #endif
  2497. #ifdef CONFIG_MISDN_HFCMULTI_8xx
  2498. if (hc->immap->im_cpm.cp_pbdat & hc->pb_irqmsk)
  2499. goto irq_notforus;
  2500. #endif
  2501. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  2502. spin_lock_irqsave(&plx_lock, flags);
  2503. plx_acc = hc->plx_membase + PLX_INTCSR;
  2504. wval = readw(plx_acc);
  2505. spin_unlock_irqrestore(&plx_lock, flags);
  2506. if (!(wval & PLX_INTCSR_LINTI1_STATUS))
  2507. goto irq_notforus;
  2508. }
  2509. status = HFC_inb_nodebug(hc, R_STATUS);
  2510. r_irq_statech = HFC_inb_nodebug(hc, R_IRQ_STATECH);
  2511. #ifdef IRQCOUNT_DEBUG
  2512. if (r_irq_statech)
  2513. iq1++;
  2514. if (status & V_DTMF_STA)
  2515. iq2++;
  2516. if (status & V_LOST_STA)
  2517. iq3++;
  2518. if (status & V_EXT_IRQSTA)
  2519. iq4++;
  2520. if (status & V_MISC_IRQSTA)
  2521. iq5++;
  2522. if (status & V_FR_IRQSTA)
  2523. iq6++;
  2524. if (iqcnt++ > 5000) {
  2525. printk(KERN_ERR "iq1:%x iq2:%x iq3:%x iq4:%x iq5:%x iq6:%x\n",
  2526. iq1, iq2, iq3, iq4, iq5, iq6);
  2527. iqcnt = 0;
  2528. }
  2529. #endif
  2530. if (!r_irq_statech &&
  2531. !(status & (V_DTMF_STA | V_LOST_STA | V_EXT_IRQSTA |
  2532. V_MISC_IRQSTA | V_FR_IRQSTA))) {
  2533. /* irq is not for us */
  2534. goto irq_notforus;
  2535. }
  2536. hc->irqcnt++;
  2537. if (r_irq_statech) {
  2538. if (hc->ctype != HFC_TYPE_E1)
  2539. ph_state_irq(hc, r_irq_statech);
  2540. }
  2541. if (status & V_EXT_IRQSTA)
  2542. ; /* external IRQ */
  2543. if (status & V_LOST_STA) {
  2544. /* LOST IRQ */
  2545. HFC_outb(hc, R_INC_RES_FIFO, V_RES_LOST); /* clear irq! */
  2546. }
  2547. if (status & V_MISC_IRQSTA) {
  2548. /* misc IRQ */
  2549. r_irq_misc = HFC_inb_nodebug(hc, R_IRQ_MISC);
  2550. r_irq_misc &= hc->hw.r_irqmsk_misc; /* ignore disabled irqs */
  2551. if (r_irq_misc & V_STA_IRQ) {
  2552. if (hc->ctype == HFC_TYPE_E1) {
  2553. /* state machine */
  2554. dch = hc->chan[hc->dnum[0]].dch;
  2555. e1_syncsta = HFC_inb_nodebug(hc, R_SYNC_STA);
  2556. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
  2557. && hc->e1_getclock) {
  2558. if (e1_syncsta & V_FR_SYNC_E1)
  2559. hc->syncronized = 1;
  2560. else
  2561. hc->syncronized = 0;
  2562. }
  2563. /* undocumented: status changes during read */
  2564. temp = HFC_inb_nodebug(hc, R_E1_RD_STA);
  2565. while (temp != (temp2 =
  2566. HFC_inb_nodebug(hc, R_E1_RD_STA))) {
  2567. if (debug & DEBUG_HFCMULTI_STATE)
  2568. printk(KERN_DEBUG "%s: reread "
  2569. "STATE because %d!=%d\n",
  2570. __func__, temp, temp2);
  2571. temp = temp2; /* repeat */
  2572. }
  2573. /* broadcast state change to all fragments */
  2574. if (debug & DEBUG_HFCMULTI_STATE)
  2575. printk(KERN_DEBUG
  2576. "%s: E1 (id=%d) newstate %x\n",
  2577. __func__, hc->id, temp & 0x7);
  2578. for (i = 0; i < hc->ports; i++) {
  2579. dch = hc->chan[hc->dnum[i]].dch;
  2580. dch->state = temp & 0x7;
  2581. schedule_event(dch, FLG_PHCHANGE);
  2582. }
  2583. if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
  2584. plxsd_checksync(hc, 0);
  2585. }
  2586. }
  2587. if (r_irq_misc & V_TI_IRQ) {
  2588. if (hc->iclock_on)
  2589. mISDN_clock_update(hc->iclock, poll, NULL);
  2590. handle_timer_irq(hc);
  2591. }
  2592. if (r_irq_misc & V_DTMF_IRQ)
  2593. hfcmulti_dtmf(hc);
  2594. if (r_irq_misc & V_IRQ_PROC) {
  2595. static int irq_proc_cnt;
  2596. if (!irq_proc_cnt++)
  2597. printk(KERN_DEBUG "%s: got V_IRQ_PROC -"
  2598. " this should not happen\n", __func__);
  2599. }
  2600. }
  2601. if (status & V_FR_IRQSTA) {
  2602. /* FIFO IRQ */
  2603. r_irq_oview = HFC_inb_nodebug(hc, R_IRQ_OVIEW);
  2604. for (i = 0; i < 8; i++) {
  2605. if (r_irq_oview & (1 << i))
  2606. fifo_irq(hc, i);
  2607. }
  2608. }
  2609. #ifdef IRQ_DEBUG
  2610. irqsem = 0;
  2611. #endif
  2612. spin_unlock(&hc->lock);
  2613. return IRQ_HANDLED;
  2614. irq_notforus:
  2615. #ifdef IRQ_DEBUG
  2616. irqsem = 0;
  2617. #endif
  2618. spin_unlock(&hc->lock);
  2619. return IRQ_NONE;
  2620. }
  2621. /*
  2622. * timer callback for D-chan busy resolution. Currently no function
  2623. */
  2624. static void
  2625. hfcmulti_dbusy_timer(struct hfc_multi *hc)
  2626. {
  2627. }
  2628. /*
  2629. * activate/deactivate hardware for selected channels and mode
  2630. *
  2631. * configure B-channel with the given protocol
  2632. * ch eqals to the HFC-channel (0-31)
  2633. * ch is the number of channel (0-4,4-7,8-11,12-15,16-19,20-23,24-27,28-31
  2634. * for S/T, 1-31 for E1)
  2635. * the hdlc interrupts will be set/unset
  2636. */
  2637. static int
  2638. mode_hfcmulti(struct hfc_multi *hc, int ch, int protocol, int slot_tx,
  2639. int bank_tx, int slot_rx, int bank_rx)
  2640. {
  2641. int flow_tx = 0, flow_rx = 0, routing = 0;
  2642. int oslot_tx, oslot_rx;
  2643. int conf;
  2644. if (ch < 0 || ch > 31)
  2645. return -EINVAL;
  2646. oslot_tx = hc->chan[ch].slot_tx;
  2647. oslot_rx = hc->chan[ch].slot_rx;
  2648. conf = hc->chan[ch].conf;
  2649. if (debug & DEBUG_HFCMULTI_MODE)
  2650. printk(KERN_DEBUG
  2651. "%s: card %d channel %d protocol %x slot old=%d new=%d "
  2652. "bank new=%d (TX) slot old=%d new=%d bank new=%d (RX)\n",
  2653. __func__, hc->id, ch, protocol, oslot_tx, slot_tx,
  2654. bank_tx, oslot_rx, slot_rx, bank_rx);
  2655. if (oslot_tx >= 0 && slot_tx != oslot_tx) {
  2656. /* remove from slot */
  2657. if (debug & DEBUG_HFCMULTI_MODE)
  2658. printk(KERN_DEBUG "%s: remove from slot %d (TX)\n",
  2659. __func__, oslot_tx);
  2660. if (hc->slot_owner[oslot_tx << 1] == ch) {
  2661. HFC_outb(hc, R_SLOT, oslot_tx << 1);
  2662. HFC_outb(hc, A_SL_CFG, 0);
  2663. if (hc->ctype != HFC_TYPE_XHFC)
  2664. HFC_outb(hc, A_CONF, 0);
  2665. hc->slot_owner[oslot_tx << 1] = -1;
  2666. } else {
  2667. if (debug & DEBUG_HFCMULTI_MODE)
  2668. printk(KERN_DEBUG
  2669. "%s: we are not owner of this tx slot "
  2670. "anymore, channel %d is.\n",
  2671. __func__, hc->slot_owner[oslot_tx << 1]);
  2672. }
  2673. }
  2674. if (oslot_rx >= 0 && slot_rx != oslot_rx) {
  2675. /* remove from slot */
  2676. if (debug & DEBUG_HFCMULTI_MODE)
  2677. printk(KERN_DEBUG
  2678. "%s: remove from slot %d (RX)\n",
  2679. __func__, oslot_rx);
  2680. if (hc->slot_owner[(oslot_rx << 1) | 1] == ch) {
  2681. HFC_outb(hc, R_SLOT, (oslot_rx << 1) | V_SL_DIR);
  2682. HFC_outb(hc, A_SL_CFG, 0);
  2683. hc->slot_owner[(oslot_rx << 1) | 1] = -1;
  2684. } else {
  2685. if (debug & DEBUG_HFCMULTI_MODE)
  2686. printk(KERN_DEBUG
  2687. "%s: we are not owner of this rx slot "
  2688. "anymore, channel %d is.\n",
  2689. __func__,
  2690. hc->slot_owner[(oslot_rx << 1) | 1]);
  2691. }
  2692. }
  2693. if (slot_tx < 0) {
  2694. flow_tx = 0x80; /* FIFO->ST */
  2695. /* disable pcm slot */
  2696. hc->chan[ch].slot_tx = -1;
  2697. hc->chan[ch].bank_tx = 0;
  2698. } else {
  2699. /* set pcm slot */
  2700. if (hc->chan[ch].txpending)
  2701. flow_tx = 0x80; /* FIFO->ST */
  2702. else
  2703. flow_tx = 0xc0; /* PCM->ST */
  2704. /* put on slot */
  2705. routing = bank_tx ? 0xc0 : 0x80;
  2706. if (conf >= 0 || bank_tx > 1)
  2707. routing = 0x40; /* loop */
  2708. if (debug & DEBUG_HFCMULTI_MODE)
  2709. printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
  2710. " %d flow %02x routing %02x conf %d (TX)\n",
  2711. __func__, ch, slot_tx, bank_tx,
  2712. flow_tx, routing, conf);
  2713. HFC_outb(hc, R_SLOT, slot_tx << 1);
  2714. HFC_outb(hc, A_SL_CFG, (ch << 1) | routing);
  2715. if (hc->ctype != HFC_TYPE_XHFC)
  2716. HFC_outb(hc, A_CONF,
  2717. (conf < 0) ? 0 : (conf | V_CONF_SL));
  2718. hc->slot_owner[slot_tx << 1] = ch;
  2719. hc->chan[ch].slot_tx = slot_tx;
  2720. hc->chan[ch].bank_tx = bank_tx;
  2721. }
  2722. if (slot_rx < 0) {
  2723. /* disable pcm slot */
  2724. flow_rx = 0x80; /* ST->FIFO */
  2725. hc->chan[ch].slot_rx = -1;
  2726. hc->chan[ch].bank_rx = 0;
  2727. } else {
  2728. /* set pcm slot */
  2729. if (hc->chan[ch].txpending)
  2730. flow_rx = 0x80; /* ST->FIFO */
  2731. else
  2732. flow_rx = 0xc0; /* ST->(FIFO,PCM) */
  2733. /* put on slot */
  2734. routing = bank_rx ? 0x80 : 0xc0; /* reversed */
  2735. if (conf >= 0 || bank_rx > 1)
  2736. routing = 0x40; /* loop */
  2737. if (debug & DEBUG_HFCMULTI_MODE)
  2738. printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
  2739. " %d flow %02x routing %02x conf %d (RX)\n",
  2740. __func__, ch, slot_rx, bank_rx,
  2741. flow_rx, routing, conf);
  2742. HFC_outb(hc, R_SLOT, (slot_rx << 1) | V_SL_DIR);
  2743. HFC_outb(hc, A_SL_CFG, (ch << 1) | V_CH_DIR | routing);
  2744. hc->slot_owner[(slot_rx << 1) | 1] = ch;
  2745. hc->chan[ch].slot_rx = slot_rx;
  2746. hc->chan[ch].bank_rx = bank_rx;
  2747. }
  2748. switch (protocol) {
  2749. case (ISDN_P_NONE):
  2750. /* disable TX fifo */
  2751. HFC_outb(hc, R_FIFO, ch << 1);
  2752. HFC_wait(hc);
  2753. HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 | V_IFF);
  2754. HFC_outb(hc, A_SUBCH_CFG, 0);
  2755. HFC_outb(hc, A_IRQ_MSK, 0);
  2756. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2757. HFC_wait(hc);
  2758. /* disable RX fifo */
  2759. HFC_outb(hc, R_FIFO, (ch << 1) | 1);
  2760. HFC_wait(hc);
  2761. HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00);
  2762. HFC_outb(hc, A_SUBCH_CFG, 0);
  2763. HFC_outb(hc, A_IRQ_MSK, 0);
  2764. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2765. HFC_wait(hc);
  2766. if (hc->chan[ch].bch && hc->ctype != HFC_TYPE_E1) {
  2767. hc->hw.a_st_ctrl0[hc->chan[ch].port] &=
  2768. ((ch & 0x3) == 0) ? ~V_B1_EN : ~V_B2_EN;
  2769. HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
  2770. /* undocumented: delay after R_ST_SEL */
  2771. udelay(1);
  2772. HFC_outb(hc, A_ST_CTRL0,
  2773. hc->hw.a_st_ctrl0[hc->chan[ch].port]);
  2774. }
  2775. if (hc->chan[ch].bch) {
  2776. test_and_clear_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
  2777. test_and_clear_bit(FLG_TRANSPARENT,
  2778. &hc->chan[ch].bch->Flags);
  2779. }
  2780. break;
  2781. case (ISDN_P_B_RAW): /* B-channel */
  2782. if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
  2783. (hc->chan[ch].slot_rx < 0) &&
  2784. (hc->chan[ch].slot_tx < 0)) {
  2785. printk(KERN_DEBUG
  2786. "Setting B-channel %d to echo cancelable "
  2787. "state on PCM slot %d\n", ch,
  2788. ((ch / 4) * 8) + ((ch % 4) * 4) + 1);
  2789. printk(KERN_DEBUG
  2790. "Enabling pass through for channel\n");
  2791. vpm_out(hc, ch, ((ch / 4) * 8) +
  2792. ((ch % 4) * 4) + 1, 0x01);
  2793. /* rx path */
  2794. /* S/T -> PCM */
  2795. HFC_outb(hc, R_FIFO, (ch << 1));
  2796. HFC_wait(hc);
  2797. HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
  2798. HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
  2799. ((ch % 4) * 4) + 1) << 1);
  2800. HFC_outb(hc, A_SL_CFG, 0x80 | (ch << 1));
  2801. /* PCM -> FIFO */
  2802. HFC_outb(hc, R_FIFO, 0x20 | (ch << 1) | 1);
  2803. HFC_wait(hc);
  2804. HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
  2805. HFC_outb(hc, A_SUBCH_CFG, 0);
  2806. HFC_outb(hc, A_IRQ_MSK, 0);
  2807. if (hc->chan[ch].protocol != protocol) {
  2808. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2809. HFC_wait(hc);
  2810. }
  2811. HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
  2812. ((ch % 4) * 4) + 1) << 1) | 1);
  2813. HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1) | 1);
  2814. /* tx path */
  2815. /* PCM -> S/T */
  2816. HFC_outb(hc, R_FIFO, (ch << 1) | 1);
  2817. HFC_wait(hc);
  2818. HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
  2819. HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
  2820. ((ch % 4) * 4)) << 1) | 1);
  2821. HFC_outb(hc, A_SL_CFG, 0x80 | 0x40 | (ch << 1) | 1);
  2822. /* FIFO -> PCM */
  2823. HFC_outb(hc, R_FIFO, 0x20 | (ch << 1));
  2824. HFC_wait(hc);
  2825. HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
  2826. HFC_outb(hc, A_SUBCH_CFG, 0);
  2827. HFC_outb(hc, A_IRQ_MSK, 0);
  2828. if (hc->chan[ch].protocol != protocol) {
  2829. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2830. HFC_wait(hc);
  2831. }
  2832. /* tx silence */
  2833. HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence);
  2834. HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
  2835. ((ch % 4) * 4)) << 1);
  2836. HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1));
  2837. } else {
  2838. /* enable TX fifo */
  2839. HFC_outb(hc, R_FIFO, ch << 1);
  2840. HFC_wait(hc);
  2841. if (hc->ctype == HFC_TYPE_XHFC)
  2842. HFC_outb(hc, A_CON_HDLC, flow_tx | 0x07 << 2 |
  2843. V_HDLC_TRP | V_IFF);
  2844. /* Enable FIFO, no interrupt */
  2845. else
  2846. HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 |
  2847. V_HDLC_TRP | V_IFF);
  2848. HFC_outb(hc, A_SUBCH_CFG, 0);
  2849. HFC_outb(hc, A_IRQ_MSK, 0);
  2850. if (hc->chan[ch].protocol != protocol) {
  2851. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2852. HFC_wait(hc);
  2853. }
  2854. /* tx silence */
  2855. HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence);
  2856. /* enable RX fifo */
  2857. HFC_outb(hc, R_FIFO, (ch << 1) | 1);
  2858. HFC_wait(hc);
  2859. if (hc->ctype == HFC_TYPE_XHFC)
  2860. HFC_outb(hc, A_CON_HDLC, flow_rx | 0x07 << 2 |
  2861. V_HDLC_TRP);
  2862. /* Enable FIFO, no interrupt*/
  2863. else
  2864. HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00 |
  2865. V_HDLC_TRP);
  2866. HFC_outb(hc, A_SUBCH_CFG, 0);
  2867. HFC_outb(hc, A_IRQ_MSK, 0);
  2868. if (hc->chan[ch].protocol != protocol) {
  2869. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2870. HFC_wait(hc);
  2871. }
  2872. }
  2873. if (hc->ctype != HFC_TYPE_E1) {
  2874. hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
  2875. ((ch & 0x3) == 0) ? V_B1_EN : V_B2_EN;
  2876. HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
  2877. /* undocumented: delay after R_ST_SEL */
  2878. udelay(1);
  2879. HFC_outb(hc, A_ST_CTRL0,
  2880. hc->hw.a_st_ctrl0[hc->chan[ch].port]);
  2881. }
  2882. if (hc->chan[ch].bch)
  2883. test_and_set_bit(FLG_TRANSPARENT,
  2884. &hc->chan[ch].bch->Flags);
  2885. break;
  2886. case (ISDN_P_B_HDLC): /* B-channel */
  2887. case (ISDN_P_TE_S0): /* D-channel */
  2888. case (ISDN_P_NT_S0):
  2889. case (ISDN_P_TE_E1):
  2890. case (ISDN_P_NT_E1):
  2891. /* enable TX fifo */
  2892. HFC_outb(hc, R_FIFO, ch << 1);
  2893. HFC_wait(hc);
  2894. if (hc->ctype == HFC_TYPE_E1 || hc->chan[ch].bch) {
  2895. /* E1 or B-channel */
  2896. HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04);
  2897. HFC_outb(hc, A_SUBCH_CFG, 0);
  2898. } else {
  2899. /* D-Channel without HDLC fill flags */
  2900. HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04 | V_IFF);
  2901. HFC_outb(hc, A_SUBCH_CFG, 2);
  2902. }
  2903. HFC_outb(hc, A_IRQ_MSK, V_IRQ);
  2904. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2905. HFC_wait(hc);
  2906. /* enable RX fifo */
  2907. HFC_outb(hc, R_FIFO, (ch << 1) | 1);
  2908. HFC_wait(hc);
  2909. HFC_outb(hc, A_CON_HDLC, flow_rx | 0x04);
  2910. if (hc->ctype == HFC_TYPE_E1 || hc->chan[ch].bch)
  2911. HFC_outb(hc, A_SUBCH_CFG, 0); /* full 8 bits */
  2912. else
  2913. HFC_outb(hc, A_SUBCH_CFG, 2); /* 2 bits dchannel */
  2914. HFC_outb(hc, A_IRQ_MSK, V_IRQ);
  2915. HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
  2916. HFC_wait(hc);
  2917. if (hc->chan[ch].bch) {
  2918. test_and_set_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
  2919. if (hc->ctype != HFC_TYPE_E1) {
  2920. hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
  2921. ((ch & 0x3) == 0) ? V_B1_EN : V_B2_EN;
  2922. HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
  2923. /* undocumented: delay after R_ST_SEL */
  2924. udelay(1);
  2925. HFC_outb(hc, A_ST_CTRL0,
  2926. hc->hw.a_st_ctrl0[hc->chan[ch].port]);
  2927. }
  2928. }
  2929. break;
  2930. default:
  2931. printk(KERN_DEBUG "%s: protocol not known %x\n",
  2932. __func__, protocol);
  2933. hc->chan[ch].protocol = ISDN_P_NONE;
  2934. return -ENOPROTOOPT;
  2935. }
  2936. hc->chan[ch].protocol = protocol;
  2937. return 0;
  2938. }
  2939. /*
  2940. * connect/disconnect PCM
  2941. */
  2942. static void
  2943. hfcmulti_pcm(struct hfc_multi *hc, int ch, int slot_tx, int bank_tx,
  2944. int slot_rx, int bank_rx)
  2945. {
  2946. if (slot_tx < 0 || slot_rx < 0 || bank_tx < 0 || bank_rx < 0) {
  2947. /* disable PCM */
  2948. mode_hfcmulti(hc, ch, hc->chan[ch].protocol, -1, 0, -1, 0);
  2949. return;
  2950. }
  2951. /* enable pcm */
  2952. mode_hfcmulti(hc, ch, hc->chan[ch].protocol, slot_tx, bank_tx,
  2953. slot_rx, bank_rx);
  2954. }
  2955. /*
  2956. * set/disable conference
  2957. */
  2958. static void
  2959. hfcmulti_conf(struct hfc_multi *hc, int ch, int num)
  2960. {
  2961. if (num >= 0 && num <= 7)
  2962. hc->chan[ch].conf = num;
  2963. else
  2964. hc->chan[ch].conf = -1;
  2965. mode_hfcmulti(hc, ch, hc->chan[ch].protocol, hc->chan[ch].slot_tx,
  2966. hc->chan[ch].bank_tx, hc->chan[ch].slot_rx,
  2967. hc->chan[ch].bank_rx);
  2968. }
  2969. /*
  2970. * set/disable sample loop
  2971. */
  2972. /* NOTE: this function is experimental and therefore disabled */
  2973. /*
  2974. * Layer 1 callback function
  2975. */
  2976. static int
  2977. hfcm_l1callback(struct dchannel *dch, u_int cmd)
  2978. {
  2979. struct hfc_multi *hc = dch->hw;
  2980. u_long flags;
  2981. switch (cmd) {
  2982. case INFO3_P8:
  2983. case INFO3_P10:
  2984. break;
  2985. case HW_RESET_REQ:
  2986. /* start activation */
  2987. spin_lock_irqsave(&hc->lock, flags);
  2988. if (hc->ctype == HFC_TYPE_E1) {
  2989. if (debug & DEBUG_HFCMULTI_MSG)
  2990. printk(KERN_DEBUG
  2991. "%s: HW_RESET_REQ no BRI\n",
  2992. __func__);
  2993. } else {
  2994. HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
  2995. /* undocumented: delay after R_ST_SEL */
  2996. udelay(1);
  2997. HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 3); /* F3 */
  2998. udelay(6); /* wait at least 5,21us */
  2999. HFC_outb(hc, A_ST_WR_STATE, 3);
  3000. HFC_outb(hc, A_ST_WR_STATE, 3 | (V_ST_ACT * 3));
  3001. /* activate */
  3002. }
  3003. spin_unlock_irqrestore(&hc->lock, flags);
  3004. l1_event(dch->l1, HW_POWERUP_IND);
  3005. break;
  3006. case HW_DEACT_REQ:
  3007. /* start deactivation */
  3008. spin_lock_irqsave(&hc->lock, flags);
  3009. if (hc->ctype == HFC_TYPE_E1) {
  3010. if (debug & DEBUG_HFCMULTI_MSG)
  3011. printk(KERN_DEBUG
  3012. "%s: HW_DEACT_REQ no BRI\n",
  3013. __func__);
  3014. } else {
  3015. HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
  3016. /* undocumented: delay after R_ST_SEL */
  3017. udelay(1);
  3018. HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT * 2);
  3019. /* deactivate */
  3020. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  3021. hc->syncronized &=
  3022. ~(1 << hc->chan[dch->slot].port);
  3023. plxsd_checksync(hc, 0);
  3024. }
  3025. }
  3026. skb_queue_purge(&dch->squeue);
  3027. if (dch->tx_skb) {
  3028. dev_kfree_skb(dch->tx_skb);
  3029. dch->tx_skb = NULL;
  3030. }
  3031. dch->tx_idx = 0;
  3032. if (dch->rx_skb) {
  3033. dev_kfree_skb(dch->rx_skb);
  3034. dch->rx_skb = NULL;
  3035. }
  3036. test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
  3037. if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
  3038. del_timer(&dch->timer);
  3039. spin_unlock_irqrestore(&hc->lock, flags);
  3040. break;
  3041. case HW_POWERUP_REQ:
  3042. spin_lock_irqsave(&hc->lock, flags);
  3043. if (hc->ctype == HFC_TYPE_E1) {
  3044. if (debug & DEBUG_HFCMULTI_MSG)
  3045. printk(KERN_DEBUG
  3046. "%s: HW_POWERUP_REQ no BRI\n",
  3047. __func__);
  3048. } else {
  3049. HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
  3050. /* undocumented: delay after R_ST_SEL */
  3051. udelay(1);
  3052. HFC_outb(hc, A_ST_WR_STATE, 3 | 0x10); /* activate */
  3053. udelay(6); /* wait at least 5,21us */
  3054. HFC_outb(hc, A_ST_WR_STATE, 3); /* activate */
  3055. }
  3056. spin_unlock_irqrestore(&hc->lock, flags);
  3057. break;
  3058. case PH_ACTIVATE_IND:
  3059. test_and_set_bit(FLG_ACTIVE, &dch->Flags);
  3060. _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
  3061. GFP_ATOMIC);
  3062. break;
  3063. case PH_DEACTIVATE_IND:
  3064. test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
  3065. _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
  3066. GFP_ATOMIC);
  3067. break;
  3068. default:
  3069. if (dch->debug & DEBUG_HW)
  3070. printk(KERN_DEBUG "%s: unknown command %x\n",
  3071. __func__, cmd);
  3072. return -1;
  3073. }
  3074. return 0;
  3075. }
  3076. /*
  3077. * Layer2 -> Layer 1 Transfer
  3078. */
  3079. static int
  3080. handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
  3081. {
  3082. struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
  3083. struct dchannel *dch = container_of(dev, struct dchannel, dev);
  3084. struct hfc_multi *hc = dch->hw;
  3085. struct mISDNhead *hh = mISDN_HEAD_P(skb);
  3086. int ret = -EINVAL;
  3087. unsigned int id;
  3088. u_long flags;
  3089. switch (hh->prim) {
  3090. case PH_DATA_REQ:
  3091. if (skb->len < 1)
  3092. break;
  3093. spin_lock_irqsave(&hc->lock, flags);
  3094. ret = dchannel_senddata(dch, skb);
  3095. if (ret > 0) { /* direct TX */
  3096. id = hh->id; /* skb can be freed */
  3097. hfcmulti_tx(hc, dch->slot);
  3098. ret = 0;
  3099. /* start fifo */
  3100. HFC_outb(hc, R_FIFO, 0);
  3101. HFC_wait(hc);
  3102. spin_unlock_irqrestore(&hc->lock, flags);
  3103. queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
  3104. } else
  3105. spin_unlock_irqrestore(&hc->lock, flags);
  3106. return ret;
  3107. case PH_ACTIVATE_REQ:
  3108. if (dch->dev.D.protocol != ISDN_P_TE_S0) {
  3109. spin_lock_irqsave(&hc->lock, flags);
  3110. ret = 0;
  3111. if (debug & DEBUG_HFCMULTI_MSG)
  3112. printk(KERN_DEBUG
  3113. "%s: PH_ACTIVATE port %d (0..%d)\n",
  3114. __func__, hc->chan[dch->slot].port,
  3115. hc->ports - 1);
  3116. /* start activation */
  3117. if (hc->ctype == HFC_TYPE_E1) {
  3118. ph_state_change(dch);
  3119. if (debug & DEBUG_HFCMULTI_STATE)
  3120. printk(KERN_DEBUG
  3121. "%s: E1 report state %x \n",
  3122. __func__, dch->state);
  3123. } else {
  3124. HFC_outb(hc, R_ST_SEL,
  3125. hc->chan[dch->slot].port);
  3126. /* undocumented: delay after R_ST_SEL */
  3127. udelay(1);
  3128. HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 1);
  3129. /* G1 */
  3130. udelay(6); /* wait at least 5,21us */
  3131. HFC_outb(hc, A_ST_WR_STATE, 1);
  3132. HFC_outb(hc, A_ST_WR_STATE, 1 |
  3133. (V_ST_ACT * 3)); /* activate */
  3134. dch->state = 1;
  3135. }
  3136. spin_unlock_irqrestore(&hc->lock, flags);
  3137. } else
  3138. ret = l1_event(dch->l1, hh->prim);
  3139. break;
  3140. case PH_DEACTIVATE_REQ:
  3141. test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
  3142. if (dch->dev.D.protocol != ISDN_P_TE_S0) {
  3143. spin_lock_irqsave(&hc->lock, flags);
  3144. if (debug & DEBUG_HFCMULTI_MSG)
  3145. printk(KERN_DEBUG
  3146. "%s: PH_DEACTIVATE port %d (0..%d)\n",
  3147. __func__, hc->chan[dch->slot].port,
  3148. hc->ports - 1);
  3149. /* start deactivation */
  3150. if (hc->ctype == HFC_TYPE_E1) {
  3151. if (debug & DEBUG_HFCMULTI_MSG)
  3152. printk(KERN_DEBUG
  3153. "%s: PH_DEACTIVATE no BRI\n",
  3154. __func__);
  3155. } else {
  3156. HFC_outb(hc, R_ST_SEL,
  3157. hc->chan[dch->slot].port);
  3158. /* undocumented: delay after R_ST_SEL */
  3159. udelay(1);
  3160. HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT * 2);
  3161. /* deactivate */
  3162. dch->state = 1;
  3163. }
  3164. skb_queue_purge(&dch->squeue);
  3165. if (dch->tx_skb) {
  3166. dev_kfree_skb(dch->tx_skb);
  3167. dch->tx_skb = NULL;
  3168. }
  3169. dch->tx_idx = 0;
  3170. if (dch->rx_skb) {
  3171. dev_kfree_skb(dch->rx_skb);
  3172. dch->rx_skb = NULL;
  3173. }
  3174. test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
  3175. if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
  3176. del_timer(&dch->timer);
  3177. #ifdef FIXME
  3178. if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags))
  3179. dchannel_sched_event(&hc->dch, D_CLEARBUSY);
  3180. #endif
  3181. ret = 0;
  3182. spin_unlock_irqrestore(&hc->lock, flags);
  3183. } else
  3184. ret = l1_event(dch->l1, hh->prim);
  3185. break;
  3186. }
  3187. if (!ret)
  3188. dev_kfree_skb(skb);
  3189. return ret;
  3190. }
  3191. static void
  3192. deactivate_bchannel(struct bchannel *bch)
  3193. {
  3194. struct hfc_multi *hc = bch->hw;
  3195. u_long flags;
  3196. spin_lock_irqsave(&hc->lock, flags);
  3197. mISDN_clear_bchannel(bch);
  3198. hc->chan[bch->slot].coeff_count = 0;
  3199. hc->chan[bch->slot].rx_off = 0;
  3200. hc->chan[bch->slot].conf = -1;
  3201. mode_hfcmulti(hc, bch->slot, ISDN_P_NONE, -1, 0, -1, 0);
  3202. spin_unlock_irqrestore(&hc->lock, flags);
  3203. }
  3204. static int
  3205. handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
  3206. {
  3207. struct bchannel *bch = container_of(ch, struct bchannel, ch);
  3208. struct hfc_multi *hc = bch->hw;
  3209. int ret = -EINVAL;
  3210. struct mISDNhead *hh = mISDN_HEAD_P(skb);
  3211. unsigned long flags;
  3212. switch (hh->prim) {
  3213. case PH_DATA_REQ:
  3214. if (!skb->len)
  3215. break;
  3216. spin_lock_irqsave(&hc->lock, flags);
  3217. ret = bchannel_senddata(bch, skb);
  3218. if (ret > 0) { /* direct TX */
  3219. hfcmulti_tx(hc, bch->slot);
  3220. ret = 0;
  3221. /* start fifo */
  3222. HFC_outb_nodebug(hc, R_FIFO, 0);
  3223. HFC_wait_nodebug(hc);
  3224. }
  3225. spin_unlock_irqrestore(&hc->lock, flags);
  3226. return ret;
  3227. case PH_ACTIVATE_REQ:
  3228. if (debug & DEBUG_HFCMULTI_MSG)
  3229. printk(KERN_DEBUG "%s: PH_ACTIVATE ch %d (0..32)\n",
  3230. __func__, bch->slot);
  3231. spin_lock_irqsave(&hc->lock, flags);
  3232. /* activate B-channel if not already activated */
  3233. if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) {
  3234. hc->chan[bch->slot].txpending = 0;
  3235. ret = mode_hfcmulti(hc, bch->slot,
  3236. ch->protocol,
  3237. hc->chan[bch->slot].slot_tx,
  3238. hc->chan[bch->slot].bank_tx,
  3239. hc->chan[bch->slot].slot_rx,
  3240. hc->chan[bch->slot].bank_rx);
  3241. if (!ret) {
  3242. if (ch->protocol == ISDN_P_B_RAW && !hc->dtmf
  3243. && test_bit(HFC_CHIP_DTMF, &hc->chip)) {
  3244. /* start decoder */
  3245. hc->dtmf = 1;
  3246. if (debug & DEBUG_HFCMULTI_DTMF)
  3247. printk(KERN_DEBUG
  3248. "%s: start dtmf decoder\n",
  3249. __func__);
  3250. HFC_outb(hc, R_DTMF, hc->hw.r_dtmf |
  3251. V_RST_DTMF);
  3252. }
  3253. }
  3254. } else
  3255. ret = 0;
  3256. spin_unlock_irqrestore(&hc->lock, flags);
  3257. if (!ret)
  3258. _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
  3259. GFP_KERNEL);
  3260. break;
  3261. case PH_CONTROL_REQ:
  3262. spin_lock_irqsave(&hc->lock, flags);
  3263. switch (hh->id) {
  3264. case HFC_SPL_LOOP_ON: /* set sample loop */
  3265. if (debug & DEBUG_HFCMULTI_MSG)
  3266. printk(KERN_DEBUG
  3267. "%s: HFC_SPL_LOOP_ON (len = %d)\n",
  3268. __func__, skb->len);
  3269. ret = 0;
  3270. break;
  3271. case HFC_SPL_LOOP_OFF: /* set silence */
  3272. if (debug & DEBUG_HFCMULTI_MSG)
  3273. printk(KERN_DEBUG "%s: HFC_SPL_LOOP_OFF\n",
  3274. __func__);
  3275. ret = 0;
  3276. break;
  3277. default:
  3278. printk(KERN_ERR
  3279. "%s: unknown PH_CONTROL_REQ info %x\n",
  3280. __func__, hh->id);
  3281. ret = -EINVAL;
  3282. }
  3283. spin_unlock_irqrestore(&hc->lock, flags);
  3284. break;
  3285. case PH_DEACTIVATE_REQ:
  3286. deactivate_bchannel(bch); /* locked there */
  3287. _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
  3288. GFP_KERNEL);
  3289. ret = 0;
  3290. break;
  3291. }
  3292. if (!ret)
  3293. dev_kfree_skb(skb);
  3294. return ret;
  3295. }
  3296. /*
  3297. * bchannel control function
  3298. */
  3299. static int
  3300. channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
  3301. {
  3302. int ret = 0;
  3303. struct dsp_features *features =
  3304. (struct dsp_features *)(*((u_long *)&cq->p1));
  3305. struct hfc_multi *hc = bch->hw;
  3306. int slot_tx;
  3307. int bank_tx;
  3308. int slot_rx;
  3309. int bank_rx;
  3310. int num;
  3311. switch (cq->op) {
  3312. case MISDN_CTRL_GETOP:
  3313. ret = mISDN_ctrl_bchannel(bch, cq);
  3314. cq->op |= MISDN_CTRL_HFC_OP | MISDN_CTRL_HW_FEATURES_OP;
  3315. break;
  3316. case MISDN_CTRL_RX_OFF: /* turn off / on rx stream */
  3317. ret = mISDN_ctrl_bchannel(bch, cq);
  3318. hc->chan[bch->slot].rx_off = !!cq->p1;
  3319. if (!hc->chan[bch->slot].rx_off) {
  3320. /* reset fifo on rx on */
  3321. HFC_outb_nodebug(hc, R_FIFO, (bch->slot << 1) | 1);
  3322. HFC_wait_nodebug(hc);
  3323. HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
  3324. HFC_wait_nodebug(hc);
  3325. }
  3326. if (debug & DEBUG_HFCMULTI_MSG)
  3327. printk(KERN_DEBUG "%s: RX_OFF request (nr=%d off=%d)\n",
  3328. __func__, bch->nr, hc->chan[bch->slot].rx_off);
  3329. break;
  3330. case MISDN_CTRL_FILL_EMPTY:
  3331. ret = mISDN_ctrl_bchannel(bch, cq);
  3332. hc->silence = bch->fill[0];
  3333. memset(hc->silence_data, hc->silence, sizeof(hc->silence_data));
  3334. break;
  3335. case MISDN_CTRL_HW_FEATURES: /* fill features structure */
  3336. if (debug & DEBUG_HFCMULTI_MSG)
  3337. printk(KERN_DEBUG "%s: HW_FEATURE request\n",
  3338. __func__);
  3339. /* create confirm */
  3340. features->hfc_id = hc->id;
  3341. if (test_bit(HFC_CHIP_DTMF, &hc->chip))
  3342. features->hfc_dtmf = 1;
  3343. if (test_bit(HFC_CHIP_CONF, &hc->chip))
  3344. features->hfc_conf = 1;
  3345. features->hfc_loops = 0;
  3346. if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
  3347. features->hfc_echocanhw = 1;
  3348. } else {
  3349. features->pcm_id = hc->pcm;
  3350. features->pcm_slots = hc->slots;
  3351. features->pcm_banks = 2;
  3352. }
  3353. break;
  3354. case MISDN_CTRL_HFC_PCM_CONN: /* connect to pcm timeslot (0..N) */
  3355. slot_tx = cq->p1 & 0xff;
  3356. bank_tx = cq->p1 >> 8;
  3357. slot_rx = cq->p2 & 0xff;
  3358. bank_rx = cq->p2 >> 8;
  3359. if (debug & DEBUG_HFCMULTI_MSG)
  3360. printk(KERN_DEBUG
  3361. "%s: HFC_PCM_CONN slot %d bank %d (TX) "
  3362. "slot %d bank %d (RX)\n",
  3363. __func__, slot_tx, bank_tx,
  3364. slot_rx, bank_rx);
  3365. if (slot_tx < hc->slots && bank_tx <= 2 &&
  3366. slot_rx < hc->slots && bank_rx <= 2)
  3367. hfcmulti_pcm(hc, bch->slot,
  3368. slot_tx, bank_tx, slot_rx, bank_rx);
  3369. else {
  3370. printk(KERN_WARNING
  3371. "%s: HFC_PCM_CONN slot %d bank %d (TX) "
  3372. "slot %d bank %d (RX) out of range\n",
  3373. __func__, slot_tx, bank_tx,
  3374. slot_rx, bank_rx);
  3375. ret = -EINVAL;
  3376. }
  3377. break;
  3378. case MISDN_CTRL_HFC_PCM_DISC: /* release interface from pcm timeslot */
  3379. if (debug & DEBUG_HFCMULTI_MSG)
  3380. printk(KERN_DEBUG "%s: HFC_PCM_DISC\n",
  3381. __func__);
  3382. hfcmulti_pcm(hc, bch->slot, -1, 0, -1, 0);
  3383. break;
  3384. case MISDN_CTRL_HFC_CONF_JOIN: /* join conference (0..7) */
  3385. num = cq->p1 & 0xff;
  3386. if (debug & DEBUG_HFCMULTI_MSG)
  3387. printk(KERN_DEBUG "%s: HFC_CONF_JOIN conf %d\n",
  3388. __func__, num);
  3389. if (num <= 7)
  3390. hfcmulti_conf(hc, bch->slot, num);
  3391. else {
  3392. printk(KERN_WARNING
  3393. "%s: HW_CONF_JOIN conf %d out of range\n",
  3394. __func__, num);
  3395. ret = -EINVAL;
  3396. }
  3397. break;
  3398. case MISDN_CTRL_HFC_CONF_SPLIT: /* split conference */
  3399. if (debug & DEBUG_HFCMULTI_MSG)
  3400. printk(KERN_DEBUG "%s: HFC_CONF_SPLIT\n", __func__);
  3401. hfcmulti_conf(hc, bch->slot, -1);
  3402. break;
  3403. case MISDN_CTRL_HFC_ECHOCAN_ON:
  3404. if (debug & DEBUG_HFCMULTI_MSG)
  3405. printk(KERN_DEBUG "%s: HFC_ECHOCAN_ON\n", __func__);
  3406. if (test_bit(HFC_CHIP_B410P, &hc->chip))
  3407. vpm_echocan_on(hc, bch->slot, cq->p1);
  3408. else
  3409. ret = -EINVAL;
  3410. break;
  3411. case MISDN_CTRL_HFC_ECHOCAN_OFF:
  3412. if (debug & DEBUG_HFCMULTI_MSG)
  3413. printk(KERN_DEBUG "%s: HFC_ECHOCAN_OFF\n",
  3414. __func__);
  3415. if (test_bit(HFC_CHIP_B410P, &hc->chip))
  3416. vpm_echocan_off(hc, bch->slot);
  3417. else
  3418. ret = -EINVAL;
  3419. break;
  3420. default:
  3421. ret = mISDN_ctrl_bchannel(bch, cq);
  3422. break;
  3423. }
  3424. return ret;
  3425. }
  3426. static int
  3427. hfcm_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
  3428. {
  3429. struct bchannel *bch = container_of(ch, struct bchannel, ch);
  3430. struct hfc_multi *hc = bch->hw;
  3431. int err = -EINVAL;
  3432. u_long flags;
  3433. if (bch->debug & DEBUG_HW)
  3434. printk(KERN_DEBUG "%s: cmd:%x %p\n",
  3435. __func__, cmd, arg);
  3436. switch (cmd) {
  3437. case CLOSE_CHANNEL:
  3438. test_and_clear_bit(FLG_OPEN, &bch->Flags);
  3439. deactivate_bchannel(bch); /* locked there */
  3440. ch->protocol = ISDN_P_NONE;
  3441. ch->peer = NULL;
  3442. module_put(THIS_MODULE);
  3443. err = 0;
  3444. break;
  3445. case CONTROL_CHANNEL:
  3446. spin_lock_irqsave(&hc->lock, flags);
  3447. err = channel_bctrl(bch, arg);
  3448. spin_unlock_irqrestore(&hc->lock, flags);
  3449. break;
  3450. default:
  3451. printk(KERN_WARNING "%s: unknown prim(%x)\n",
  3452. __func__, cmd);
  3453. }
  3454. return err;
  3455. }
  3456. /*
  3457. * handle D-channel events
  3458. *
  3459. * handle state change event
  3460. */
  3461. static void
  3462. ph_state_change(struct dchannel *dch)
  3463. {
  3464. struct hfc_multi *hc;
  3465. int ch, i;
  3466. if (!dch) {
  3467. printk(KERN_WARNING "%s: ERROR given dch is NULL\n", __func__);
  3468. return;
  3469. }
  3470. hc = dch->hw;
  3471. ch = dch->slot;
  3472. if (hc->ctype == HFC_TYPE_E1) {
  3473. if (dch->dev.D.protocol == ISDN_P_TE_E1) {
  3474. if (debug & DEBUG_HFCMULTI_STATE)
  3475. printk(KERN_DEBUG
  3476. "%s: E1 TE (id=%d) newstate %x\n",
  3477. __func__, hc->id, dch->state);
  3478. } else {
  3479. if (debug & DEBUG_HFCMULTI_STATE)
  3480. printk(KERN_DEBUG
  3481. "%s: E1 NT (id=%d) newstate %x\n",
  3482. __func__, hc->id, dch->state);
  3483. }
  3484. switch (dch->state) {
  3485. case (1):
  3486. if (hc->e1_state != 1) {
  3487. for (i = 1; i <= 31; i++) {
  3488. /* reset fifos on e1 activation */
  3489. HFC_outb_nodebug(hc, R_FIFO,
  3490. (i << 1) | 1);
  3491. HFC_wait_nodebug(hc);
  3492. HFC_outb_nodebug(hc, R_INC_RES_FIFO,
  3493. V_RES_F);
  3494. HFC_wait_nodebug(hc);
  3495. }
  3496. }
  3497. test_and_set_bit(FLG_ACTIVE, &dch->Flags);
  3498. _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
  3499. MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
  3500. break;
  3501. default:
  3502. if (hc->e1_state != 1)
  3503. return;
  3504. test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
  3505. _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
  3506. MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
  3507. }
  3508. hc->e1_state = dch->state;
  3509. } else {
  3510. if (dch->dev.D.protocol == ISDN_P_TE_S0) {
  3511. if (debug & DEBUG_HFCMULTI_STATE)
  3512. printk(KERN_DEBUG
  3513. "%s: S/T TE newstate %x\n",
  3514. __func__, dch->state);
  3515. switch (dch->state) {
  3516. case (0):
  3517. l1_event(dch->l1, HW_RESET_IND);
  3518. break;
  3519. case (3):
  3520. l1_event(dch->l1, HW_DEACT_IND);
  3521. break;
  3522. case (5):
  3523. case (8):
  3524. l1_event(dch->l1, ANYSIGNAL);
  3525. break;
  3526. case (6):
  3527. l1_event(dch->l1, INFO2);
  3528. break;
  3529. case (7):
  3530. l1_event(dch->l1, INFO4_P8);
  3531. break;
  3532. }
  3533. } else {
  3534. if (debug & DEBUG_HFCMULTI_STATE)
  3535. printk(KERN_DEBUG "%s: S/T NT newstate %x\n",
  3536. __func__, dch->state);
  3537. switch (dch->state) {
  3538. case (2):
  3539. if (hc->chan[ch].nt_timer == 0) {
  3540. hc->chan[ch].nt_timer = -1;
  3541. HFC_outb(hc, R_ST_SEL,
  3542. hc->chan[ch].port);
  3543. /* undocumented: delay after R_ST_SEL */
  3544. udelay(1);
  3545. HFC_outb(hc, A_ST_WR_STATE, 4 |
  3546. V_ST_LD_STA); /* G4 */
  3547. udelay(6); /* wait at least 5,21us */
  3548. HFC_outb(hc, A_ST_WR_STATE, 4);
  3549. dch->state = 4;
  3550. } else {
  3551. /* one extra count for the next event */
  3552. hc->chan[ch].nt_timer =
  3553. nt_t1_count[poll_timer] + 1;
  3554. HFC_outb(hc, R_ST_SEL,
  3555. hc->chan[ch].port);
  3556. /* undocumented: delay after R_ST_SEL */
  3557. udelay(1);
  3558. /* allow G2 -> G3 transition */
  3559. HFC_outb(hc, A_ST_WR_STATE, 2 |
  3560. V_SET_G2_G3);
  3561. }
  3562. break;
  3563. case (1):
  3564. hc->chan[ch].nt_timer = -1;
  3565. test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
  3566. _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
  3567. MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
  3568. break;
  3569. case (4):
  3570. hc->chan[ch].nt_timer = -1;
  3571. break;
  3572. case (3):
  3573. hc->chan[ch].nt_timer = -1;
  3574. test_and_set_bit(FLG_ACTIVE, &dch->Flags);
  3575. _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
  3576. MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
  3577. break;
  3578. }
  3579. }
  3580. }
  3581. }
  3582. /*
  3583. * called for card mode init message
  3584. */
  3585. static void
  3586. hfcmulti_initmode(struct dchannel *dch)
  3587. {
  3588. struct hfc_multi *hc = dch->hw;
  3589. u_char a_st_wr_state, r_e1_wr_sta;
  3590. int i, pt;
  3591. if (debug & DEBUG_HFCMULTI_INIT)
  3592. printk(KERN_DEBUG "%s: entered\n", __func__);
  3593. i = dch->slot;
  3594. pt = hc->chan[i].port;
  3595. if (hc->ctype == HFC_TYPE_E1) {
  3596. /* E1 */
  3597. hc->chan[hc->dnum[pt]].slot_tx = -1;
  3598. hc->chan[hc->dnum[pt]].slot_rx = -1;
  3599. hc->chan[hc->dnum[pt]].conf = -1;
  3600. if (hc->dnum[pt]) {
  3601. mode_hfcmulti(hc, dch->slot, dch->dev.D.protocol,
  3602. -1, 0, -1, 0);
  3603. dch->timer.function = (void *) hfcmulti_dbusy_timer;
  3604. dch->timer.data = (long) dch;
  3605. init_timer(&dch->timer);
  3606. }
  3607. for (i = 1; i <= 31; i++) {
  3608. if (!((1 << i) & hc->bmask[pt])) /* skip unused chan */
  3609. continue;
  3610. hc->chan[i].slot_tx = -1;
  3611. hc->chan[i].slot_rx = -1;
  3612. hc->chan[i].conf = -1;
  3613. mode_hfcmulti(hc, i, ISDN_P_NONE, -1, 0, -1, 0);
  3614. }
  3615. }
  3616. if (hc->ctype == HFC_TYPE_E1 && pt == 0) {
  3617. /* E1, port 0 */
  3618. dch = hc->chan[hc->dnum[0]].dch;
  3619. if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dnum[0]].cfg)) {
  3620. HFC_outb(hc, R_LOS0, 255); /* 2 ms */
  3621. HFC_outb(hc, R_LOS1, 255); /* 512 ms */
  3622. }
  3623. if (test_bit(HFC_CFG_OPTICAL, &hc->chan[hc->dnum[0]].cfg)) {
  3624. HFC_outb(hc, R_RX0, 0);
  3625. hc->hw.r_tx0 = 0 | V_OUT_EN;
  3626. } else {
  3627. HFC_outb(hc, R_RX0, 1);
  3628. hc->hw.r_tx0 = 1 | V_OUT_EN;
  3629. }
  3630. hc->hw.r_tx1 = V_ATX | V_NTRI;
  3631. HFC_outb(hc, R_TX0, hc->hw.r_tx0);
  3632. HFC_outb(hc, R_TX1, hc->hw.r_tx1);
  3633. HFC_outb(hc, R_TX_FR0, 0x00);
  3634. HFC_outb(hc, R_TX_FR1, 0xf8);
  3635. if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dnum[0]].cfg))
  3636. HFC_outb(hc, R_TX_FR2, V_TX_MF | V_TX_E | V_NEG_E);
  3637. HFC_outb(hc, R_RX_FR0, V_AUTO_RESYNC | V_AUTO_RECO | 0);
  3638. if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dnum[0]].cfg))
  3639. HFC_outb(hc, R_RX_FR1, V_RX_MF | V_RX_MF_SYNC);
  3640. if (dch->dev.D.protocol == ISDN_P_NT_E1) {
  3641. if (debug & DEBUG_HFCMULTI_INIT)
  3642. printk(KERN_DEBUG "%s: E1 port is NT-mode\n",
  3643. __func__);
  3644. r_e1_wr_sta = 0; /* G0 */
  3645. hc->e1_getclock = 0;
  3646. } else {
  3647. if (debug & DEBUG_HFCMULTI_INIT)
  3648. printk(KERN_DEBUG "%s: E1 port is TE-mode\n",
  3649. __func__);
  3650. r_e1_wr_sta = 0; /* F0 */
  3651. hc->e1_getclock = 1;
  3652. }
  3653. if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
  3654. HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
  3655. else
  3656. HFC_outb(hc, R_SYNC_OUT, 0);
  3657. if (test_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip))
  3658. hc->e1_getclock = 1;
  3659. if (test_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip))
  3660. hc->e1_getclock = 0;
  3661. if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
  3662. /* SLAVE (clock master) */
  3663. if (debug & DEBUG_HFCMULTI_INIT)
  3664. printk(KERN_DEBUG
  3665. "%s: E1 port is clock master "
  3666. "(clock from PCM)\n", __func__);
  3667. HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC | V_PCM_SYNC);
  3668. } else {
  3669. if (hc->e1_getclock) {
  3670. /* MASTER (clock slave) */
  3671. if (debug & DEBUG_HFCMULTI_INIT)
  3672. printk(KERN_DEBUG
  3673. "%s: E1 port is clock slave "
  3674. "(clock to PCM)\n", __func__);
  3675. HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
  3676. } else {
  3677. /* MASTER (clock master) */
  3678. if (debug & DEBUG_HFCMULTI_INIT)
  3679. printk(KERN_DEBUG "%s: E1 port is "
  3680. "clock master "
  3681. "(clock from QUARTZ)\n",
  3682. __func__);
  3683. HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC |
  3684. V_PCM_SYNC | V_JATT_OFF);
  3685. HFC_outb(hc, R_SYNC_OUT, 0);
  3686. }
  3687. }
  3688. HFC_outb(hc, R_JATT_ATT, 0x9c); /* undoc register */
  3689. HFC_outb(hc, R_PWM_MD, V_PWM0_MD);
  3690. HFC_outb(hc, R_PWM0, 0x50);
  3691. HFC_outb(hc, R_PWM1, 0xff);
  3692. /* state machine setup */
  3693. HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta | V_E1_LD_STA);
  3694. udelay(6); /* wait at least 5,21us */
  3695. HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta);
  3696. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  3697. hc->syncronized = 0;
  3698. plxsd_checksync(hc, 0);
  3699. }
  3700. }
  3701. if (hc->ctype != HFC_TYPE_E1) {
  3702. /* ST */
  3703. hc->chan[i].slot_tx = -1;
  3704. hc->chan[i].slot_rx = -1;
  3705. hc->chan[i].conf = -1;
  3706. mode_hfcmulti(hc, i, dch->dev.D.protocol, -1, 0, -1, 0);
  3707. dch->timer.function = (void *) hfcmulti_dbusy_timer;
  3708. dch->timer.data = (long) dch;
  3709. init_timer(&dch->timer);
  3710. hc->chan[i - 2].slot_tx = -1;
  3711. hc->chan[i - 2].slot_rx = -1;
  3712. hc->chan[i - 2].conf = -1;
  3713. mode_hfcmulti(hc, i - 2, ISDN_P_NONE, -1, 0, -1, 0);
  3714. hc->chan[i - 1].slot_tx = -1;
  3715. hc->chan[i - 1].slot_rx = -1;
  3716. hc->chan[i - 1].conf = -1;
  3717. mode_hfcmulti(hc, i - 1, ISDN_P_NONE, -1, 0, -1, 0);
  3718. /* select interface */
  3719. HFC_outb(hc, R_ST_SEL, pt);
  3720. /* undocumented: delay after R_ST_SEL */
  3721. udelay(1);
  3722. if (dch->dev.D.protocol == ISDN_P_NT_S0) {
  3723. if (debug & DEBUG_HFCMULTI_INIT)
  3724. printk(KERN_DEBUG
  3725. "%s: ST port %d is NT-mode\n",
  3726. __func__, pt);
  3727. /* clock delay */
  3728. HFC_outb(hc, A_ST_CLK_DLY, clockdelay_nt);
  3729. a_st_wr_state = 1; /* G1 */
  3730. hc->hw.a_st_ctrl0[pt] = V_ST_MD;
  3731. } else {
  3732. if (debug & DEBUG_HFCMULTI_INIT)
  3733. printk(KERN_DEBUG
  3734. "%s: ST port %d is TE-mode\n",
  3735. __func__, pt);
  3736. /* clock delay */
  3737. HFC_outb(hc, A_ST_CLK_DLY, clockdelay_te);
  3738. a_st_wr_state = 2; /* F2 */
  3739. hc->hw.a_st_ctrl0[pt] = 0;
  3740. }
  3741. if (!test_bit(HFC_CFG_NONCAP_TX, &hc->chan[i].cfg))
  3742. hc->hw.a_st_ctrl0[pt] |= V_TX_LI;
  3743. if (hc->ctype == HFC_TYPE_XHFC) {
  3744. hc->hw.a_st_ctrl0[pt] |= 0x40 /* V_ST_PU_CTRL */;
  3745. HFC_outb(hc, 0x35 /* A_ST_CTRL3 */,
  3746. 0x7c << 1 /* V_ST_PULSE */);
  3747. }
  3748. /* line setup */
  3749. HFC_outb(hc, A_ST_CTRL0, hc->hw.a_st_ctrl0[pt]);
  3750. /* disable E-channel */
  3751. if ((dch->dev.D.protocol == ISDN_P_NT_S0) ||
  3752. test_bit(HFC_CFG_DIS_ECHANNEL, &hc->chan[i].cfg))
  3753. HFC_outb(hc, A_ST_CTRL1, V_E_IGNO);
  3754. else
  3755. HFC_outb(hc, A_ST_CTRL1, 0);
  3756. /* enable B-channel receive */
  3757. HFC_outb(hc, A_ST_CTRL2, V_B1_RX_EN | V_B2_RX_EN);
  3758. /* state machine setup */
  3759. HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state | V_ST_LD_STA);
  3760. udelay(6); /* wait at least 5,21us */
  3761. HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state);
  3762. hc->hw.r_sci_msk |= 1 << pt;
  3763. /* state machine interrupts */
  3764. HFC_outb(hc, R_SCI_MSK, hc->hw.r_sci_msk);
  3765. /* unset sync on port */
  3766. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  3767. hc->syncronized &=
  3768. ~(1 << hc->chan[dch->slot].port);
  3769. plxsd_checksync(hc, 0);
  3770. }
  3771. }
  3772. if (debug & DEBUG_HFCMULTI_INIT)
  3773. printk("%s: done\n", __func__);
  3774. }
  3775. static int
  3776. open_dchannel(struct hfc_multi *hc, struct dchannel *dch,
  3777. struct channel_req *rq)
  3778. {
  3779. int err = 0;
  3780. u_long flags;
  3781. if (debug & DEBUG_HW_OPEN)
  3782. printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
  3783. dch->dev.id, __builtin_return_address(0));
  3784. if (rq->protocol == ISDN_P_NONE)
  3785. return -EINVAL;
  3786. if ((dch->dev.D.protocol != ISDN_P_NONE) &&
  3787. (dch->dev.D.protocol != rq->protocol)) {
  3788. if (debug & DEBUG_HFCMULTI_MODE)
  3789. printk(KERN_DEBUG "%s: change protocol %x to %x\n",
  3790. __func__, dch->dev.D.protocol, rq->protocol);
  3791. }
  3792. if ((dch->dev.D.protocol == ISDN_P_TE_S0) &&
  3793. (rq->protocol != ISDN_P_TE_S0))
  3794. l1_event(dch->l1, CLOSE_CHANNEL);
  3795. if (dch->dev.D.protocol != rq->protocol) {
  3796. if (rq->protocol == ISDN_P_TE_S0) {
  3797. err = create_l1(dch, hfcm_l1callback);
  3798. if (err)
  3799. return err;
  3800. }
  3801. dch->dev.D.protocol = rq->protocol;
  3802. spin_lock_irqsave(&hc->lock, flags);
  3803. hfcmulti_initmode(dch);
  3804. spin_unlock_irqrestore(&hc->lock, flags);
  3805. }
  3806. if (test_bit(FLG_ACTIVE, &dch->Flags))
  3807. _queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY,
  3808. 0, NULL, GFP_KERNEL);
  3809. rq->ch = &dch->dev.D;
  3810. if (!try_module_get(THIS_MODULE))
  3811. printk(KERN_WARNING "%s:cannot get module\n", __func__);
  3812. return 0;
  3813. }
  3814. static int
  3815. open_bchannel(struct hfc_multi *hc, struct dchannel *dch,
  3816. struct channel_req *rq)
  3817. {
  3818. struct bchannel *bch;
  3819. int ch;
  3820. if (!test_channelmap(rq->adr.channel, dch->dev.channelmap))
  3821. return -EINVAL;
  3822. if (rq->protocol == ISDN_P_NONE)
  3823. return -EINVAL;
  3824. if (hc->ctype == HFC_TYPE_E1)
  3825. ch = rq->adr.channel;
  3826. else
  3827. ch = (rq->adr.channel - 1) + (dch->slot - 2);
  3828. bch = hc->chan[ch].bch;
  3829. if (!bch) {
  3830. printk(KERN_ERR "%s:internal error ch %d has no bch\n",
  3831. __func__, ch);
  3832. return -EINVAL;
  3833. }
  3834. if (test_and_set_bit(FLG_OPEN, &bch->Flags))
  3835. return -EBUSY; /* b-channel can be only open once */
  3836. bch->ch.protocol = rq->protocol;
  3837. hc->chan[ch].rx_off = 0;
  3838. rq->ch = &bch->ch;
  3839. if (!try_module_get(THIS_MODULE))
  3840. printk(KERN_WARNING "%s:cannot get module\n", __func__);
  3841. return 0;
  3842. }
  3843. /*
  3844. * device control function
  3845. */
  3846. static int
  3847. channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
  3848. {
  3849. struct hfc_multi *hc = dch->hw;
  3850. int ret = 0;
  3851. int wd_mode, wd_cnt;
  3852. switch (cq->op) {
  3853. case MISDN_CTRL_GETOP:
  3854. cq->op = MISDN_CTRL_HFC_OP | MISDN_CTRL_L1_TIMER3;
  3855. break;
  3856. case MISDN_CTRL_HFC_WD_INIT: /* init the watchdog */
  3857. wd_cnt = cq->p1 & 0xf;
  3858. wd_mode = !!(cq->p1 >> 4);
  3859. if (debug & DEBUG_HFCMULTI_MSG)
  3860. printk(KERN_DEBUG "%s: MISDN_CTRL_HFC_WD_INIT mode %s"
  3861. ", counter 0x%x\n", __func__,
  3862. wd_mode ? "AUTO" : "MANUAL", wd_cnt);
  3863. /* set the watchdog timer */
  3864. HFC_outb(hc, R_TI_WD, poll_timer | (wd_cnt << 4));
  3865. hc->hw.r_bert_wd_md = (wd_mode ? V_AUTO_WD_RES : 0);
  3866. if (hc->ctype == HFC_TYPE_XHFC)
  3867. hc->hw.r_bert_wd_md |= 0x40 /* V_WD_EN */;
  3868. /* init the watchdog register and reset the counter */
  3869. HFC_outb(hc, R_BERT_WD_MD, hc->hw.r_bert_wd_md | V_WD_RES);
  3870. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  3871. /* enable the watchdog output for Speech-Design */
  3872. HFC_outb(hc, R_GPIO_SEL, V_GPIO_SEL7);
  3873. HFC_outb(hc, R_GPIO_EN1, V_GPIO_EN15);
  3874. HFC_outb(hc, R_GPIO_OUT1, 0);
  3875. HFC_outb(hc, R_GPIO_OUT1, V_GPIO_OUT15);
  3876. }
  3877. break;
  3878. case MISDN_CTRL_HFC_WD_RESET: /* reset the watchdog counter */
  3879. if (debug & DEBUG_HFCMULTI_MSG)
  3880. printk(KERN_DEBUG "%s: MISDN_CTRL_HFC_WD_RESET\n",
  3881. __func__);
  3882. HFC_outb(hc, R_BERT_WD_MD, hc->hw.r_bert_wd_md | V_WD_RES);
  3883. break;
  3884. case MISDN_CTRL_L1_TIMER3:
  3885. ret = l1_event(dch->l1, HW_TIMER3_VALUE | (cq->p1 & 0xff));
  3886. break;
  3887. default:
  3888. printk(KERN_WARNING "%s: unknown Op %x\n",
  3889. __func__, cq->op);
  3890. ret = -EINVAL;
  3891. break;
  3892. }
  3893. return ret;
  3894. }
  3895. static int
  3896. hfcm_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
  3897. {
  3898. struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
  3899. struct dchannel *dch = container_of(dev, struct dchannel, dev);
  3900. struct hfc_multi *hc = dch->hw;
  3901. struct channel_req *rq;
  3902. int err = 0;
  3903. u_long flags;
  3904. if (dch->debug & DEBUG_HW)
  3905. printk(KERN_DEBUG "%s: cmd:%x %p\n",
  3906. __func__, cmd, arg);
  3907. switch (cmd) {
  3908. case OPEN_CHANNEL:
  3909. rq = arg;
  3910. switch (rq->protocol) {
  3911. case ISDN_P_TE_S0:
  3912. case ISDN_P_NT_S0:
  3913. if (hc->ctype == HFC_TYPE_E1) {
  3914. err = -EINVAL;
  3915. break;
  3916. }
  3917. err = open_dchannel(hc, dch, rq); /* locked there */
  3918. break;
  3919. case ISDN_P_TE_E1:
  3920. case ISDN_P_NT_E1:
  3921. if (hc->ctype != HFC_TYPE_E1) {
  3922. err = -EINVAL;
  3923. break;
  3924. }
  3925. err = open_dchannel(hc, dch, rq); /* locked there */
  3926. break;
  3927. default:
  3928. spin_lock_irqsave(&hc->lock, flags);
  3929. err = open_bchannel(hc, dch, rq);
  3930. spin_unlock_irqrestore(&hc->lock, flags);
  3931. }
  3932. break;
  3933. case CLOSE_CHANNEL:
  3934. if (debug & DEBUG_HW_OPEN)
  3935. printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
  3936. __func__, dch->dev.id,
  3937. __builtin_return_address(0));
  3938. module_put(THIS_MODULE);
  3939. break;
  3940. case CONTROL_CHANNEL:
  3941. spin_lock_irqsave(&hc->lock, flags);
  3942. err = channel_dctrl(dch, arg);
  3943. spin_unlock_irqrestore(&hc->lock, flags);
  3944. break;
  3945. default:
  3946. if (dch->debug & DEBUG_HW)
  3947. printk(KERN_DEBUG "%s: unknown command %x\n",
  3948. __func__, cmd);
  3949. err = -EINVAL;
  3950. }
  3951. return err;
  3952. }
  3953. static int
  3954. clockctl(void *priv, int enable)
  3955. {
  3956. struct hfc_multi *hc = priv;
  3957. hc->iclock_on = enable;
  3958. return 0;
  3959. }
  3960. /*
  3961. * initialize the card
  3962. */
  3963. /*
  3964. * start timer irq, wait some time and check if we have interrupts.
  3965. * if not, reset chip and try again.
  3966. */
  3967. static int
  3968. init_card(struct hfc_multi *hc)
  3969. {
  3970. int err = -EIO;
  3971. u_long flags;
  3972. void __iomem *plx_acc;
  3973. u_long plx_flags;
  3974. if (debug & DEBUG_HFCMULTI_INIT)
  3975. printk(KERN_DEBUG "%s: entered\n", __func__);
  3976. spin_lock_irqsave(&hc->lock, flags);
  3977. /* set interrupts but leave global interrupt disabled */
  3978. hc->hw.r_irq_ctrl = V_FIFO_IRQ;
  3979. disable_hwirq(hc);
  3980. spin_unlock_irqrestore(&hc->lock, flags);
  3981. if (request_irq(hc->irq, hfcmulti_interrupt, IRQF_SHARED,
  3982. "HFC-multi", hc)) {
  3983. printk(KERN_WARNING "mISDN: Could not get interrupt %d.\n",
  3984. hc->irq);
  3985. hc->irq = 0;
  3986. return -EIO;
  3987. }
  3988. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  3989. spin_lock_irqsave(&plx_lock, plx_flags);
  3990. plx_acc = hc->plx_membase + PLX_INTCSR;
  3991. writew((PLX_INTCSR_PCIINT_ENABLE | PLX_INTCSR_LINTI1_ENABLE),
  3992. plx_acc); /* enable PCI & LINT1 irq */
  3993. spin_unlock_irqrestore(&plx_lock, plx_flags);
  3994. }
  3995. if (debug & DEBUG_HFCMULTI_INIT)
  3996. printk(KERN_DEBUG "%s: IRQ %d count %d\n",
  3997. __func__, hc->irq, hc->irqcnt);
  3998. err = init_chip(hc);
  3999. if (err)
  4000. goto error;
  4001. /*
  4002. * Finally enable IRQ output
  4003. * this is only allowed, if an IRQ routine is already
  4004. * established for this HFC, so don't do that earlier
  4005. */
  4006. spin_lock_irqsave(&hc->lock, flags);
  4007. enable_hwirq(hc);
  4008. spin_unlock_irqrestore(&hc->lock, flags);
  4009. /* printk(KERN_DEBUG "no master irq set!!!\n"); */
  4010. set_current_state(TASK_UNINTERRUPTIBLE);
  4011. schedule_timeout((100 * HZ) / 1000); /* Timeout 100ms */
  4012. /* turn IRQ off until chip is completely initialized */
  4013. spin_lock_irqsave(&hc->lock, flags);
  4014. disable_hwirq(hc);
  4015. spin_unlock_irqrestore(&hc->lock, flags);
  4016. if (debug & DEBUG_HFCMULTI_INIT)
  4017. printk(KERN_DEBUG "%s: IRQ %d count %d\n",
  4018. __func__, hc->irq, hc->irqcnt);
  4019. if (hc->irqcnt) {
  4020. if (debug & DEBUG_HFCMULTI_INIT)
  4021. printk(KERN_DEBUG "%s: done\n", __func__);
  4022. return 0;
  4023. }
  4024. if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
  4025. printk(KERN_INFO "ignoring missing interrupts\n");
  4026. return 0;
  4027. }
  4028. printk(KERN_ERR "HFC PCI: IRQ(%d) getting no interrupts during init.\n",
  4029. hc->irq);
  4030. err = -EIO;
  4031. error:
  4032. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  4033. spin_lock_irqsave(&plx_lock, plx_flags);
  4034. plx_acc = hc->plx_membase + PLX_INTCSR;
  4035. writew(0x00, plx_acc); /*disable IRQs*/
  4036. spin_unlock_irqrestore(&plx_lock, plx_flags);
  4037. }
  4038. if (debug & DEBUG_HFCMULTI_INIT)
  4039. printk(KERN_DEBUG "%s: free irq %d\n", __func__, hc->irq);
  4040. if (hc->irq) {
  4041. free_irq(hc->irq, hc);
  4042. hc->irq = 0;
  4043. }
  4044. if (debug & DEBUG_HFCMULTI_INIT)
  4045. printk(KERN_DEBUG "%s: done (err=%d)\n", __func__, err);
  4046. return err;
  4047. }
  4048. /*
  4049. * find pci device and set it up
  4050. */
  4051. static int
  4052. setup_pci(struct hfc_multi *hc, struct pci_dev *pdev,
  4053. const struct pci_device_id *ent)
  4054. {
  4055. struct hm_map *m = (struct hm_map *)ent->driver_data;
  4056. printk(KERN_INFO
  4057. "HFC-multi: card manufacturer: '%s' card name: '%s' clock: %s\n",
  4058. m->vendor_name, m->card_name, m->clock2 ? "double" : "normal");
  4059. hc->pci_dev = pdev;
  4060. if (m->clock2)
  4061. test_and_set_bit(HFC_CHIP_CLOCK2, &hc->chip);
  4062. if (ent->vendor == PCI_VENDOR_ID_DIGIUM &&
  4063. ent->device == PCI_DEVICE_ID_DIGIUM_HFC4S) {
  4064. test_and_set_bit(HFC_CHIP_B410P, &hc->chip);
  4065. test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
  4066. test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
  4067. hc->slots = 32;
  4068. }
  4069. if (hc->pci_dev->irq <= 0) {
  4070. printk(KERN_WARNING "HFC-multi: No IRQ for PCI card found.\n");
  4071. return -EIO;
  4072. }
  4073. if (pci_enable_device(hc->pci_dev)) {
  4074. printk(KERN_WARNING "HFC-multi: Error enabling PCI card.\n");
  4075. return -EIO;
  4076. }
  4077. hc->leds = m->leds;
  4078. hc->ledstate = 0xAFFEAFFE;
  4079. hc->opticalsupport = m->opticalsupport;
  4080. hc->pci_iobase = 0;
  4081. hc->pci_membase = NULL;
  4082. hc->plx_membase = NULL;
  4083. /* set memory access methods */
  4084. if (m->io_mode) /* use mode from card config */
  4085. hc->io_mode = m->io_mode;
  4086. switch (hc->io_mode) {
  4087. case HFC_IO_MODE_PLXSD:
  4088. test_and_set_bit(HFC_CHIP_PLXSD, &hc->chip);
  4089. hc->slots = 128; /* required */
  4090. hc->HFC_outb = HFC_outb_pcimem;
  4091. hc->HFC_inb = HFC_inb_pcimem;
  4092. hc->HFC_inw = HFC_inw_pcimem;
  4093. hc->HFC_wait = HFC_wait_pcimem;
  4094. hc->read_fifo = read_fifo_pcimem;
  4095. hc->write_fifo = write_fifo_pcimem;
  4096. hc->plx_origmembase = hc->pci_dev->resource[0].start;
  4097. /* MEMBASE 1 is PLX PCI Bridge */
  4098. if (!hc->plx_origmembase) {
  4099. printk(KERN_WARNING
  4100. "HFC-multi: No IO-Memory for PCI PLX bridge found\n");
  4101. pci_disable_device(hc->pci_dev);
  4102. return -EIO;
  4103. }
  4104. hc->plx_membase = ioremap(hc->plx_origmembase, 0x80);
  4105. if (!hc->plx_membase) {
  4106. printk(KERN_WARNING
  4107. "HFC-multi: failed to remap plx address space. "
  4108. "(internal error)\n");
  4109. pci_disable_device(hc->pci_dev);
  4110. return -EIO;
  4111. }
  4112. printk(KERN_INFO
  4113. "HFC-multi: plx_membase:%#lx plx_origmembase:%#lx\n",
  4114. (u_long)hc->plx_membase, hc->plx_origmembase);
  4115. hc->pci_origmembase = hc->pci_dev->resource[2].start;
  4116. /* MEMBASE 1 is PLX PCI Bridge */
  4117. if (!hc->pci_origmembase) {
  4118. printk(KERN_WARNING
  4119. "HFC-multi: No IO-Memory for PCI card found\n");
  4120. pci_disable_device(hc->pci_dev);
  4121. return -EIO;
  4122. }
  4123. hc->pci_membase = ioremap(hc->pci_origmembase, 0x400);
  4124. if (!hc->pci_membase) {
  4125. printk(KERN_WARNING "HFC-multi: failed to remap io "
  4126. "address space. (internal error)\n");
  4127. pci_disable_device(hc->pci_dev);
  4128. return -EIO;
  4129. }
  4130. printk(KERN_INFO
  4131. "card %d: defined at MEMBASE %#lx (%#lx) IRQ %d HZ %d "
  4132. "leds-type %d\n",
  4133. hc->id, (u_long)hc->pci_membase, hc->pci_origmembase,
  4134. hc->pci_dev->irq, HZ, hc->leds);
  4135. pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
  4136. break;
  4137. case HFC_IO_MODE_PCIMEM:
  4138. hc->HFC_outb = HFC_outb_pcimem;
  4139. hc->HFC_inb = HFC_inb_pcimem;
  4140. hc->HFC_inw = HFC_inw_pcimem;
  4141. hc->HFC_wait = HFC_wait_pcimem;
  4142. hc->read_fifo = read_fifo_pcimem;
  4143. hc->write_fifo = write_fifo_pcimem;
  4144. hc->pci_origmembase = hc->pci_dev->resource[1].start;
  4145. if (!hc->pci_origmembase) {
  4146. printk(KERN_WARNING
  4147. "HFC-multi: No IO-Memory for PCI card found\n");
  4148. pci_disable_device(hc->pci_dev);
  4149. return -EIO;
  4150. }
  4151. hc->pci_membase = ioremap(hc->pci_origmembase, 256);
  4152. if (!hc->pci_membase) {
  4153. printk(KERN_WARNING
  4154. "HFC-multi: failed to remap io address space. "
  4155. "(internal error)\n");
  4156. pci_disable_device(hc->pci_dev);
  4157. return -EIO;
  4158. }
  4159. printk(KERN_INFO "card %d: defined at MEMBASE %#lx (%#lx) IRQ "
  4160. "%d HZ %d leds-type %d\n", hc->id, (u_long)hc->pci_membase,
  4161. hc->pci_origmembase, hc->pci_dev->irq, HZ, hc->leds);
  4162. pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
  4163. break;
  4164. case HFC_IO_MODE_REGIO:
  4165. hc->HFC_outb = HFC_outb_regio;
  4166. hc->HFC_inb = HFC_inb_regio;
  4167. hc->HFC_inw = HFC_inw_regio;
  4168. hc->HFC_wait = HFC_wait_regio;
  4169. hc->read_fifo = read_fifo_regio;
  4170. hc->write_fifo = write_fifo_regio;
  4171. hc->pci_iobase = (u_int) hc->pci_dev->resource[0].start;
  4172. if (!hc->pci_iobase) {
  4173. printk(KERN_WARNING
  4174. "HFC-multi: No IO for PCI card found\n");
  4175. pci_disable_device(hc->pci_dev);
  4176. return -EIO;
  4177. }
  4178. if (!request_region(hc->pci_iobase, 8, "hfcmulti")) {
  4179. printk(KERN_WARNING "HFC-multi: failed to request "
  4180. "address space at 0x%08lx (internal error)\n",
  4181. hc->pci_iobase);
  4182. pci_disable_device(hc->pci_dev);
  4183. return -EIO;
  4184. }
  4185. printk(KERN_INFO
  4186. "%s %s: defined at IOBASE %#x IRQ %d HZ %d leds-type %d\n",
  4187. m->vendor_name, m->card_name, (u_int) hc->pci_iobase,
  4188. hc->pci_dev->irq, HZ, hc->leds);
  4189. pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_REGIO);
  4190. break;
  4191. default:
  4192. printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");
  4193. pci_disable_device(hc->pci_dev);
  4194. return -EIO;
  4195. }
  4196. pci_set_drvdata(hc->pci_dev, hc);
  4197. /* At this point the needed PCI config is done */
  4198. /* fifos are still not enabled */
  4199. return 0;
  4200. }
  4201. /*
  4202. * remove port
  4203. */
  4204. static void
  4205. release_port(struct hfc_multi *hc, struct dchannel *dch)
  4206. {
  4207. int pt, ci, i = 0;
  4208. u_long flags;
  4209. struct bchannel *pb;
  4210. ci = dch->slot;
  4211. pt = hc->chan[ci].port;
  4212. if (debug & DEBUG_HFCMULTI_INIT)
  4213. printk(KERN_DEBUG "%s: entered for port %d\n",
  4214. __func__, pt + 1);
  4215. if (pt >= hc->ports) {
  4216. printk(KERN_WARNING "%s: ERROR port out of range (%d).\n",
  4217. __func__, pt + 1);
  4218. return;
  4219. }
  4220. if (debug & DEBUG_HFCMULTI_INIT)
  4221. printk(KERN_DEBUG "%s: releasing port=%d\n",
  4222. __func__, pt + 1);
  4223. if (dch->dev.D.protocol == ISDN_P_TE_S0)
  4224. l1_event(dch->l1, CLOSE_CHANNEL);
  4225. hc->chan[ci].dch = NULL;
  4226. if (hc->created[pt]) {
  4227. hc->created[pt] = 0;
  4228. mISDN_unregister_device(&dch->dev);
  4229. }
  4230. spin_lock_irqsave(&hc->lock, flags);
  4231. if (dch->timer.function) {
  4232. del_timer(&dch->timer);
  4233. dch->timer.function = NULL;
  4234. }
  4235. if (hc->ctype == HFC_TYPE_E1) { /* E1 */
  4236. /* remove sync */
  4237. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  4238. hc->syncronized = 0;
  4239. plxsd_checksync(hc, 1);
  4240. }
  4241. /* free channels */
  4242. for (i = 0; i <= 31; i++) {
  4243. if (!((1 << i) & hc->bmask[pt])) /* skip unused chan */
  4244. continue;
  4245. if (hc->chan[i].bch) {
  4246. if (debug & DEBUG_HFCMULTI_INIT)
  4247. printk(KERN_DEBUG
  4248. "%s: free port %d channel %d\n",
  4249. __func__, hc->chan[i].port + 1, i);
  4250. pb = hc->chan[i].bch;
  4251. hc->chan[i].bch = NULL;
  4252. spin_unlock_irqrestore(&hc->lock, flags);
  4253. mISDN_freebchannel(pb);
  4254. kfree(pb);
  4255. kfree(hc->chan[i].coeff);
  4256. spin_lock_irqsave(&hc->lock, flags);
  4257. }
  4258. }
  4259. } else {
  4260. /* remove sync */
  4261. if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
  4262. hc->syncronized &=
  4263. ~(1 << hc->chan[ci].port);
  4264. plxsd_checksync(hc, 1);
  4265. }
  4266. /* free channels */
  4267. if (hc->chan[ci - 2].bch) {
  4268. if (debug & DEBUG_HFCMULTI_INIT)
  4269. printk(KERN_DEBUG
  4270. "%s: free port %d channel %d\n",
  4271. __func__, hc->chan[ci - 2].port + 1,
  4272. ci - 2);
  4273. pb = hc->chan[ci - 2].bch;
  4274. hc->chan[ci - 2].bch = NULL;
  4275. spin_unlock_irqrestore(&hc->lock, flags);
  4276. mISDN_freebchannel(pb);
  4277. kfree(pb);
  4278. kfree(hc->chan[ci - 2].coeff);
  4279. spin_lock_irqsave(&hc->lock, flags);
  4280. }
  4281. if (hc->chan[ci - 1].bch) {
  4282. if (debug & DEBUG_HFCMULTI_INIT)
  4283. printk(KERN_DEBUG
  4284. "%s: free port %d channel %d\n",
  4285. __func__, hc->chan[ci - 1].port + 1,
  4286. ci - 1);
  4287. pb = hc->chan[ci - 1].bch;
  4288. hc->chan[ci - 1].bch = NULL;
  4289. spin_unlock_irqrestore(&hc->lock, flags);
  4290. mISDN_freebchannel(pb);
  4291. kfree(pb);
  4292. kfree(hc->chan[ci - 1].coeff);
  4293. spin_lock_irqsave(&hc->lock, flags);
  4294. }
  4295. }
  4296. spin_unlock_irqrestore(&hc->lock, flags);
  4297. if (debug & DEBUG_HFCMULTI_INIT)
  4298. printk(KERN_DEBUG "%s: free port %d channel D(%d)\n", __func__,
  4299. pt+1, ci);
  4300. mISDN_freedchannel(dch);
  4301. kfree(dch);
  4302. if (debug & DEBUG_HFCMULTI_INIT)
  4303. printk(KERN_DEBUG "%s: done!\n", __func__);
  4304. }
  4305. static void
  4306. release_card(struct hfc_multi *hc)
  4307. {
  4308. u_long flags;
  4309. int ch;
  4310. if (debug & DEBUG_HFCMULTI_INIT)
  4311. printk(KERN_DEBUG "%s: release card (%d) entered\n",
  4312. __func__, hc->id);
  4313. /* unregister clock source */
  4314. if (hc->iclock)
  4315. mISDN_unregister_clock(hc->iclock);
  4316. /* disable and free irq */
  4317. spin_lock_irqsave(&hc->lock, flags);
  4318. disable_hwirq(hc);
  4319. spin_unlock_irqrestore(&hc->lock, flags);
  4320. udelay(1000);
  4321. if (hc->irq) {
  4322. if (debug & DEBUG_HFCMULTI_INIT)
  4323. printk(KERN_DEBUG "%s: free irq %d (hc=%p)\n",
  4324. __func__, hc->irq, hc);
  4325. free_irq(hc->irq, hc);
  4326. hc->irq = 0;
  4327. }
  4328. /* disable D-channels & B-channels */
  4329. if (debug & DEBUG_HFCMULTI_INIT)
  4330. printk(KERN_DEBUG "%s: disable all channels (d and b)\n",
  4331. __func__);
  4332. for (ch = 0; ch <= 31; ch++) {
  4333. if (hc->chan[ch].dch)
  4334. release_port(hc, hc->chan[ch].dch);
  4335. }
  4336. /* dimm leds */
  4337. if (hc->leds)
  4338. hfcmulti_leds(hc);
  4339. /* release hardware */
  4340. release_io_hfcmulti(hc);
  4341. if (debug & DEBUG_HFCMULTI_INIT)
  4342. printk(KERN_DEBUG "%s: remove instance from list\n",
  4343. __func__);
  4344. list_del(&hc->list);
  4345. if (debug & DEBUG_HFCMULTI_INIT)
  4346. printk(KERN_DEBUG "%s: delete instance\n", __func__);
  4347. if (hc == syncmaster)
  4348. syncmaster = NULL;
  4349. kfree(hc);
  4350. if (debug & DEBUG_HFCMULTI_INIT)
  4351. printk(KERN_DEBUG "%s: card successfully removed\n",
  4352. __func__);
  4353. }
  4354. static void
  4355. init_e1_port_hw(struct hfc_multi *hc, struct hm_map *m)
  4356. {
  4357. /* set optical line type */
  4358. if (port[Port_cnt] & 0x001) {
  4359. if (!m->opticalsupport) {
  4360. printk(KERN_INFO
  4361. "This board has no optical "
  4362. "support\n");
  4363. } else {
  4364. if (debug & DEBUG_HFCMULTI_INIT)
  4365. printk(KERN_DEBUG
  4366. "%s: PORT set optical "
  4367. "interfacs: card(%d) "
  4368. "port(%d)\n",
  4369. __func__,
  4370. HFC_cnt + 1, 1);
  4371. test_and_set_bit(HFC_CFG_OPTICAL,
  4372. &hc->chan[hc->dnum[0]].cfg);
  4373. }
  4374. }
  4375. /* set LOS report */
  4376. if (port[Port_cnt] & 0x004) {
  4377. if (debug & DEBUG_HFCMULTI_INIT)
  4378. printk(KERN_DEBUG "%s: PORT set "
  4379. "LOS report: card(%d) port(%d)\n",
  4380. __func__, HFC_cnt + 1, 1);
  4381. test_and_set_bit(HFC_CFG_REPORT_LOS,
  4382. &hc->chan[hc->dnum[0]].cfg);
  4383. }
  4384. /* set AIS report */
  4385. if (port[Port_cnt] & 0x008) {
  4386. if (debug & DEBUG_HFCMULTI_INIT)
  4387. printk(KERN_DEBUG "%s: PORT set "
  4388. "AIS report: card(%d) port(%d)\n",
  4389. __func__, HFC_cnt + 1, 1);
  4390. test_and_set_bit(HFC_CFG_REPORT_AIS,
  4391. &hc->chan[hc->dnum[0]].cfg);
  4392. }
  4393. /* set SLIP report */
  4394. if (port[Port_cnt] & 0x010) {
  4395. if (debug & DEBUG_HFCMULTI_INIT)
  4396. printk(KERN_DEBUG
  4397. "%s: PORT set SLIP report: "
  4398. "card(%d) port(%d)\n",
  4399. __func__, HFC_cnt + 1, 1);
  4400. test_and_set_bit(HFC_CFG_REPORT_SLIP,
  4401. &hc->chan[hc->dnum[0]].cfg);
  4402. }
  4403. /* set RDI report */
  4404. if (port[Port_cnt] & 0x020) {
  4405. if (debug & DEBUG_HFCMULTI_INIT)
  4406. printk(KERN_DEBUG
  4407. "%s: PORT set RDI report: "
  4408. "card(%d) port(%d)\n",
  4409. __func__, HFC_cnt + 1, 1);
  4410. test_and_set_bit(HFC_CFG_REPORT_RDI,
  4411. &hc->chan[hc->dnum[0]].cfg);
  4412. }
  4413. /* set CRC-4 Mode */
  4414. if (!(port[Port_cnt] & 0x100)) {
  4415. if (debug & DEBUG_HFCMULTI_INIT)
  4416. printk(KERN_DEBUG "%s: PORT turn on CRC4 report:"
  4417. " card(%d) port(%d)\n",
  4418. __func__, HFC_cnt + 1, 1);
  4419. test_and_set_bit(HFC_CFG_CRC4,
  4420. &hc->chan[hc->dnum[0]].cfg);
  4421. } else {
  4422. if (debug & DEBUG_HFCMULTI_INIT)
  4423. printk(KERN_DEBUG "%s: PORT turn off CRC4"
  4424. " report: card(%d) port(%d)\n",
  4425. __func__, HFC_cnt + 1, 1);
  4426. }
  4427. /* set forced clock */
  4428. if (port[Port_cnt] & 0x0200) {
  4429. if (debug & DEBUG_HFCMULTI_INIT)
  4430. printk(KERN_DEBUG "%s: PORT force getting clock from "
  4431. "E1: card(%d) port(%d)\n",
  4432. __func__, HFC_cnt + 1, 1);
  4433. test_and_set_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip);
  4434. } else
  4435. if (port[Port_cnt] & 0x0400) {
  4436. if (debug & DEBUG_HFCMULTI_INIT)
  4437. printk(KERN_DEBUG "%s: PORT force putting clock to "
  4438. "E1: card(%d) port(%d)\n",
  4439. __func__, HFC_cnt + 1, 1);
  4440. test_and_set_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip);
  4441. }
  4442. /* set JATT PLL */
  4443. if (port[Port_cnt] & 0x0800) {
  4444. if (debug & DEBUG_HFCMULTI_INIT)
  4445. printk(KERN_DEBUG "%s: PORT disable JATT PLL on "
  4446. "E1: card(%d) port(%d)\n",
  4447. __func__, HFC_cnt + 1, 1);
  4448. test_and_set_bit(HFC_CHIP_RX_SYNC, &hc->chip);
  4449. }
  4450. /* set elastic jitter buffer */
  4451. if (port[Port_cnt] & 0x3000) {
  4452. hc->chan[hc->dnum[0]].jitter = (port[Port_cnt]>>12) & 0x3;
  4453. if (debug & DEBUG_HFCMULTI_INIT)
  4454. printk(KERN_DEBUG
  4455. "%s: PORT set elastic "
  4456. "buffer to %d: card(%d) port(%d)\n",
  4457. __func__, hc->chan[hc->dnum[0]].jitter,
  4458. HFC_cnt + 1, 1);
  4459. } else
  4460. hc->chan[hc->dnum[0]].jitter = 2; /* default */
  4461. }
  4462. static int
  4463. init_e1_port(struct hfc_multi *hc, struct hm_map *m, int pt)
  4464. {
  4465. struct dchannel *dch;
  4466. struct bchannel *bch;
  4467. int ch, ret = 0;
  4468. char name[MISDN_MAX_IDLEN];
  4469. int bcount = 0;
  4470. dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
  4471. if (!dch)
  4472. return -ENOMEM;
  4473. dch->debug = debug;
  4474. mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
  4475. dch->hw = hc;
  4476. dch->dev.Dprotocols = (1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1);
  4477. dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
  4478. (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
  4479. dch->dev.D.send = handle_dmsg;
  4480. dch->dev.D.ctrl = hfcm_dctrl;
  4481. dch->slot = hc->dnum[pt];
  4482. hc->chan[hc->dnum[pt]].dch = dch;
  4483. hc->chan[hc->dnum[pt]].port = pt;
  4484. hc->chan[hc->dnum[pt]].nt_timer = -1;
  4485. for (ch = 1; ch <= 31; ch++) {
  4486. if (!((1 << ch) & hc->bmask[pt])) /* skip unused channel */
  4487. continue;
  4488. bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
  4489. if (!bch) {
  4490. printk(KERN_ERR "%s: no memory for bchannel\n",
  4491. __func__);
  4492. ret = -ENOMEM;
  4493. goto free_chan;
  4494. }
  4495. hc->chan[ch].coeff = kzalloc(512, GFP_KERNEL);
  4496. if (!hc->chan[ch].coeff) {
  4497. printk(KERN_ERR "%s: no memory for coeffs\n",
  4498. __func__);
  4499. ret = -ENOMEM;
  4500. kfree(bch);
  4501. goto free_chan;
  4502. }
  4503. bch->nr = ch;
  4504. bch->slot = ch;
  4505. bch->debug = debug;
  4506. mISDN_initbchannel(bch, MAX_DATA_MEM, poll >> 1);
  4507. bch->hw = hc;
  4508. bch->ch.send = handle_bmsg;
  4509. bch->ch.ctrl = hfcm_bctrl;
  4510. bch->ch.nr = ch;
  4511. list_add(&bch->ch.list, &dch->dev.bchannels);
  4512. hc->chan[ch].bch = bch;
  4513. hc->chan[ch].port = pt;
  4514. set_channelmap(bch->nr, dch->dev.channelmap);
  4515. bcount++;
  4516. }
  4517. dch->dev.nrbchan = bcount;
  4518. if (pt == 0)
  4519. init_e1_port_hw(hc, m);
  4520. if (hc->ports > 1)
  4521. snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-e1.%d-%d",
  4522. HFC_cnt + 1, pt+1);
  4523. else
  4524. snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-e1.%d", HFC_cnt + 1);
  4525. ret = mISDN_register_device(&dch->dev, &hc->pci_dev->dev, name);
  4526. if (ret)
  4527. goto free_chan;
  4528. hc->created[pt] = 1;
  4529. return ret;
  4530. free_chan:
  4531. release_port(hc, dch);
  4532. return ret;
  4533. }
  4534. static int
  4535. init_multi_port(struct hfc_multi *hc, int pt)
  4536. {
  4537. struct dchannel *dch;
  4538. struct bchannel *bch;
  4539. int ch, i, ret = 0;
  4540. char name[MISDN_MAX_IDLEN];
  4541. dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
  4542. if (!dch)
  4543. return -ENOMEM;
  4544. dch->debug = debug;
  4545. mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
  4546. dch->hw = hc;
  4547. dch->dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
  4548. dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
  4549. (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
  4550. dch->dev.D.send = handle_dmsg;
  4551. dch->dev.D.ctrl = hfcm_dctrl;
  4552. dch->dev.nrbchan = 2;
  4553. i = pt << 2;
  4554. dch->slot = i + 2;
  4555. hc->chan[i + 2].dch = dch;
  4556. hc->chan[i + 2].port = pt;
  4557. hc->chan[i + 2].nt_timer = -1;
  4558. for (ch = 0; ch < dch->dev.nrbchan; ch++) {
  4559. bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
  4560. if (!bch) {
  4561. printk(KERN_ERR "%s: no memory for bchannel\n",
  4562. __func__);
  4563. ret = -ENOMEM;
  4564. goto free_chan;
  4565. }
  4566. hc->chan[i + ch].coeff = kzalloc(512, GFP_KERNEL);
  4567. if (!hc->chan[i + ch].coeff) {
  4568. printk(KERN_ERR "%s: no memory for coeffs\n",
  4569. __func__);
  4570. ret = -ENOMEM;
  4571. kfree(bch);
  4572. goto free_chan;
  4573. }
  4574. bch->nr = ch + 1;
  4575. bch->slot = i + ch;
  4576. bch->debug = debug;
  4577. mISDN_initbchannel(bch, MAX_DATA_MEM, poll >> 1);
  4578. bch->hw = hc;
  4579. bch->ch.send = handle_bmsg;
  4580. bch->ch.ctrl = hfcm_bctrl;
  4581. bch->ch.nr = ch + 1;
  4582. list_add(&bch->ch.list, &dch->dev.bchannels);
  4583. hc->chan[i + ch].bch = bch;
  4584. hc->chan[i + ch].port = pt;
  4585. set_channelmap(bch->nr, dch->dev.channelmap);
  4586. }
  4587. /* set master clock */
  4588. if (port[Port_cnt] & 0x001) {
  4589. if (debug & DEBUG_HFCMULTI_INIT)
  4590. printk(KERN_DEBUG
  4591. "%s: PROTOCOL set master clock: "
  4592. "card(%d) port(%d)\n",
  4593. __func__, HFC_cnt + 1, pt + 1);
  4594. if (dch->dev.D.protocol != ISDN_P_TE_S0) {
  4595. printk(KERN_ERR "Error: Master clock "
  4596. "for port(%d) of card(%d) is only"
  4597. " possible with TE-mode\n",
  4598. pt + 1, HFC_cnt + 1);
  4599. ret = -EINVAL;
  4600. goto free_chan;
  4601. }
  4602. if (hc->masterclk >= 0) {
  4603. printk(KERN_ERR "Error: Master clock "
  4604. "for port(%d) of card(%d) already "
  4605. "defined for port(%d)\n",
  4606. pt + 1, HFC_cnt + 1, hc->masterclk + 1);
  4607. ret = -EINVAL;
  4608. goto free_chan;
  4609. }
  4610. hc->masterclk = pt;
  4611. }
  4612. /* set transmitter line to non capacitive */
  4613. if (port[Port_cnt] & 0x002) {
  4614. if (debug & DEBUG_HFCMULTI_INIT)
  4615. printk(KERN_DEBUG
  4616. "%s: PROTOCOL set non capacitive "
  4617. "transmitter: card(%d) port(%d)\n",
  4618. __func__, HFC_cnt + 1, pt + 1);
  4619. test_and_set_bit(HFC_CFG_NONCAP_TX,
  4620. &hc->chan[i + 2].cfg);
  4621. }
  4622. /* disable E-channel */
  4623. if (port[Port_cnt] & 0x004) {
  4624. if (debug & DEBUG_HFCMULTI_INIT)
  4625. printk(KERN_DEBUG
  4626. "%s: PROTOCOL disable E-channel: "
  4627. "card(%d) port(%d)\n",
  4628. __func__, HFC_cnt + 1, pt + 1);
  4629. test_and_set_bit(HFC_CFG_DIS_ECHANNEL,
  4630. &hc->chan[i + 2].cfg);
  4631. }
  4632. if (hc->ctype == HFC_TYPE_XHFC) {
  4633. snprintf(name, MISDN_MAX_IDLEN - 1, "xhfc.%d-%d",
  4634. HFC_cnt + 1, pt + 1);
  4635. ret = mISDN_register_device(&dch->dev, NULL, name);
  4636. } else {
  4637. snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-%ds.%d-%d",
  4638. hc->ctype, HFC_cnt + 1, pt + 1);
  4639. ret = mISDN_register_device(&dch->dev, &hc->pci_dev->dev, name);
  4640. }
  4641. if (ret)
  4642. goto free_chan;
  4643. hc->created[pt] = 1;
  4644. return ret;
  4645. free_chan:
  4646. release_port(hc, dch);
  4647. return ret;
  4648. }
  4649. static int
  4650. hfcmulti_init(struct hm_map *m, struct pci_dev *pdev,
  4651. const struct pci_device_id *ent)
  4652. {
  4653. int ret_err = 0;
  4654. int pt;
  4655. struct hfc_multi *hc;
  4656. u_long flags;
  4657. u_char dips = 0, pmj = 0; /* dip settings, port mode Jumpers */
  4658. int i, ch;
  4659. u_int maskcheck;
  4660. if (HFC_cnt >= MAX_CARDS) {
  4661. printk(KERN_ERR "too many cards (max=%d).\n",
  4662. MAX_CARDS);
  4663. return -EINVAL;
  4664. }
  4665. if ((type[HFC_cnt] & 0xff) && (type[HFC_cnt] & 0xff) != m->type) {
  4666. printk(KERN_WARNING "HFC-MULTI: Card '%s:%s' type %d found but "
  4667. "type[%d] %d was supplied as module parameter\n",
  4668. m->vendor_name, m->card_name, m->type, HFC_cnt,
  4669. type[HFC_cnt] & 0xff);
  4670. printk(KERN_WARNING "HFC-MULTI: Load module without parameters "
  4671. "first, to see cards and their types.");
  4672. return -EINVAL;
  4673. }
  4674. if (debug & DEBUG_HFCMULTI_INIT)
  4675. printk(KERN_DEBUG "%s: Registering %s:%s chip type %d (0x%x)\n",
  4676. __func__, m->vendor_name, m->card_name, m->type,
  4677. type[HFC_cnt]);
  4678. /* allocate card+fifo structure */
  4679. hc = kzalloc(sizeof(struct hfc_multi), GFP_KERNEL);
  4680. if (!hc) {
  4681. printk(KERN_ERR "No kmem for HFC-Multi card\n");
  4682. return -ENOMEM;
  4683. }
  4684. spin_lock_init(&hc->lock);
  4685. hc->mtyp = m;
  4686. hc->ctype = m->type;
  4687. hc->ports = m->ports;
  4688. hc->id = HFC_cnt;
  4689. hc->pcm = pcm[HFC_cnt];
  4690. hc->io_mode = iomode[HFC_cnt];
  4691. if (hc->ctype == HFC_TYPE_E1 && dmask[E1_cnt]) {
  4692. /* fragment card */
  4693. pt = 0;
  4694. maskcheck = 0;
  4695. for (ch = 0; ch <= 31; ch++) {
  4696. if (!((1 << ch) & dmask[E1_cnt]))
  4697. continue;
  4698. hc->dnum[pt] = ch;
  4699. hc->bmask[pt] = bmask[bmask_cnt++];
  4700. if ((maskcheck & hc->bmask[pt])
  4701. || (dmask[E1_cnt] & hc->bmask[pt])) {
  4702. printk(KERN_INFO
  4703. "HFC-E1 #%d has overlapping B-channels on fragment #%d\n",
  4704. E1_cnt + 1, pt);
  4705. kfree(hc);
  4706. return -EINVAL;
  4707. }
  4708. maskcheck |= hc->bmask[pt];
  4709. printk(KERN_INFO
  4710. "HFC-E1 #%d uses D-channel on slot %d and a B-channel map of 0x%08x\n",
  4711. E1_cnt + 1, ch, hc->bmask[pt]);
  4712. pt++;
  4713. }
  4714. hc->ports = pt;
  4715. }
  4716. if (hc->ctype == HFC_TYPE_E1 && !dmask[E1_cnt]) {
  4717. /* default card layout */
  4718. hc->dnum[0] = 16;
  4719. hc->bmask[0] = 0xfffefffe;
  4720. hc->ports = 1;
  4721. }
  4722. /* set chip specific features */
  4723. hc->masterclk = -1;
  4724. if (type[HFC_cnt] & 0x100) {
  4725. test_and_set_bit(HFC_CHIP_ULAW, &hc->chip);
  4726. hc->silence = 0xff; /* ulaw silence */
  4727. } else
  4728. hc->silence = 0x2a; /* alaw silence */
  4729. if ((poll >> 1) > sizeof(hc->silence_data)) {
  4730. printk(KERN_ERR "HFCMULTI error: silence_data too small, "
  4731. "please fix\n");
  4732. kfree(hc);
  4733. return -EINVAL;
  4734. }
  4735. for (i = 0; i < (poll >> 1); i++)
  4736. hc->silence_data[i] = hc->silence;
  4737. if (hc->ctype != HFC_TYPE_XHFC) {
  4738. if (!(type[HFC_cnt] & 0x200))
  4739. test_and_set_bit(HFC_CHIP_DTMF, &hc->chip);
  4740. test_and_set_bit(HFC_CHIP_CONF, &hc->chip);
  4741. }
  4742. if (type[HFC_cnt] & 0x800)
  4743. test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
  4744. if (type[HFC_cnt] & 0x1000) {
  4745. test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
  4746. test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
  4747. }
  4748. if (type[HFC_cnt] & 0x4000)
  4749. test_and_set_bit(HFC_CHIP_EXRAM_128, &hc->chip);
  4750. if (type[HFC_cnt] & 0x8000)
  4751. test_and_set_bit(HFC_CHIP_EXRAM_512, &hc->chip);
  4752. hc->slots = 32;
  4753. if (type[HFC_cnt] & 0x10000)
  4754. hc->slots = 64;
  4755. if (type[HFC_cnt] & 0x20000)
  4756. hc->slots = 128;
  4757. if (type[HFC_cnt] & 0x80000) {
  4758. test_and_set_bit(HFC_CHIP_WATCHDOG, &hc->chip);
  4759. hc->wdcount = 0;
  4760. hc->wdbyte = V_GPIO_OUT2;
  4761. printk(KERN_NOTICE "Watchdog enabled\n");
  4762. }
  4763. if (pdev && ent)
  4764. /* setup pci, hc->slots may change due to PLXSD */
  4765. ret_err = setup_pci(hc, pdev, ent);
  4766. else
  4767. #ifdef CONFIG_MISDN_HFCMULTI_8xx
  4768. ret_err = setup_embedded(hc, m);
  4769. #else
  4770. {
  4771. printk(KERN_WARNING "Embedded IO Mode not selected\n");
  4772. ret_err = -EIO;
  4773. }
  4774. #endif
  4775. if (ret_err) {
  4776. if (hc == syncmaster)
  4777. syncmaster = NULL;
  4778. kfree(hc);
  4779. return ret_err;
  4780. }
  4781. hc->HFC_outb_nodebug = hc->HFC_outb;
  4782. hc->HFC_inb_nodebug = hc->HFC_inb;
  4783. hc->HFC_inw_nodebug = hc->HFC_inw;
  4784. hc->HFC_wait_nodebug = hc->HFC_wait;
  4785. #ifdef HFC_REGISTER_DEBUG
  4786. hc->HFC_outb = HFC_outb_debug;
  4787. hc->HFC_inb = HFC_inb_debug;
  4788. hc->HFC_inw = HFC_inw_debug;
  4789. hc->HFC_wait = HFC_wait_debug;
  4790. #endif
  4791. /* create channels */
  4792. for (pt = 0; pt < hc->ports; pt++) {
  4793. if (Port_cnt >= MAX_PORTS) {
  4794. printk(KERN_ERR "too many ports (max=%d).\n",
  4795. MAX_PORTS);
  4796. ret_err = -EINVAL;
  4797. goto free_card;
  4798. }
  4799. if (hc->ctype == HFC_TYPE_E1)
  4800. ret_err = init_e1_port(hc, m, pt);
  4801. else
  4802. ret_err = init_multi_port(hc, pt);
  4803. if (debug & DEBUG_HFCMULTI_INIT)
  4804. printk(KERN_DEBUG
  4805. "%s: Registering D-channel, card(%d) port(%d) "
  4806. "result %d\n",
  4807. __func__, HFC_cnt + 1, pt + 1, ret_err);
  4808. if (ret_err) {
  4809. while (pt) { /* release already registered ports */
  4810. pt--;
  4811. if (hc->ctype == HFC_TYPE_E1)
  4812. release_port(hc,
  4813. hc->chan[hc->dnum[pt]].dch);
  4814. else
  4815. release_port(hc,
  4816. hc->chan[(pt << 2) + 2].dch);
  4817. }
  4818. goto free_card;
  4819. }
  4820. if (hc->ctype != HFC_TYPE_E1)
  4821. Port_cnt++; /* for each S0 port */
  4822. }
  4823. if (hc->ctype == HFC_TYPE_E1) {
  4824. Port_cnt++; /* for each E1 port */
  4825. E1_cnt++;
  4826. }
  4827. /* disp switches */
  4828. switch (m->dip_type) {
  4829. case DIP_4S:
  4830. /*
  4831. * Get DIP setting for beroNet 1S/2S/4S cards
  4832. * DIP Setting: (collect GPIO 13/14/15 (R_GPIO_IN1) +
  4833. * GPI 19/23 (R_GPI_IN2))
  4834. */
  4835. dips = ((~HFC_inb(hc, R_GPIO_IN1) & 0xE0) >> 5) |
  4836. ((~HFC_inb(hc, R_GPI_IN2) & 0x80) >> 3) |
  4837. (~HFC_inb(hc, R_GPI_IN2) & 0x08);
  4838. /* Port mode (TE/NT) jumpers */
  4839. pmj = ((HFC_inb(hc, R_GPI_IN3) >> 4) & 0xf);
  4840. if (test_bit(HFC_CHIP_B410P, &hc->chip))
  4841. pmj = ~pmj & 0xf;
  4842. printk(KERN_INFO "%s: %s DIPs(0x%x) jumpers(0x%x)\n",
  4843. m->vendor_name, m->card_name, dips, pmj);
  4844. break;
  4845. case DIP_8S:
  4846. /*
  4847. * Get DIP Setting for beroNet 8S0+ cards
  4848. * Enable PCI auxbridge function
  4849. */
  4850. HFC_outb(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
  4851. /* prepare access to auxport */
  4852. outw(0x4000, hc->pci_iobase + 4);
  4853. /*
  4854. * some dummy reads are required to
  4855. * read valid DIP switch data
  4856. */
  4857. dips = inb(hc->pci_iobase);
  4858. dips = inb(hc->pci_iobase);
  4859. dips = inb(hc->pci_iobase);
  4860. dips = ~inb(hc->pci_iobase) & 0x3F;
  4861. outw(0x0, hc->pci_iobase + 4);
  4862. /* disable PCI auxbridge function */
  4863. HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
  4864. printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
  4865. m->vendor_name, m->card_name, dips);
  4866. break;
  4867. case DIP_E1:
  4868. /*
  4869. * get DIP Setting for beroNet E1 cards
  4870. * DIP Setting: collect GPI 4/5/6/7 (R_GPI_IN0)
  4871. */
  4872. dips = (~HFC_inb(hc, R_GPI_IN0) & 0xF0) >> 4;
  4873. printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
  4874. m->vendor_name, m->card_name, dips);
  4875. break;
  4876. }
  4877. /* add to list */
  4878. spin_lock_irqsave(&HFClock, flags);
  4879. list_add_tail(&hc->list, &HFClist);
  4880. spin_unlock_irqrestore(&HFClock, flags);
  4881. /* use as clock source */
  4882. if (clock == HFC_cnt + 1)
  4883. hc->iclock = mISDN_register_clock("HFCMulti", 0, clockctl, hc);
  4884. /* initialize hardware */
  4885. hc->irq = (m->irq) ? : hc->pci_dev->irq;
  4886. ret_err = init_card(hc);
  4887. if (ret_err) {
  4888. printk(KERN_ERR "init card returns %d\n", ret_err);
  4889. release_card(hc);
  4890. return ret_err;
  4891. }
  4892. /* start IRQ and return */
  4893. spin_lock_irqsave(&hc->lock, flags);
  4894. enable_hwirq(hc);
  4895. spin_unlock_irqrestore(&hc->lock, flags);
  4896. return 0;
  4897. free_card:
  4898. release_io_hfcmulti(hc);
  4899. if (hc == syncmaster)
  4900. syncmaster = NULL;
  4901. kfree(hc);
  4902. return ret_err;
  4903. }
  4904. static void hfc_remove_pci(struct pci_dev *pdev)
  4905. {
  4906. struct hfc_multi *card = pci_get_drvdata(pdev);
  4907. u_long flags;
  4908. if (debug)
  4909. printk(KERN_INFO "removing hfc_multi card vendor:%x "
  4910. "device:%x subvendor:%x subdevice:%x\n",
  4911. pdev->vendor, pdev->device,
  4912. pdev->subsystem_vendor, pdev->subsystem_device);
  4913. if (card) {
  4914. spin_lock_irqsave(&HFClock, flags);
  4915. release_card(card);
  4916. spin_unlock_irqrestore(&HFClock, flags);
  4917. } else {
  4918. if (debug)
  4919. printk(KERN_DEBUG "%s: drvdata already removed\n",
  4920. __func__);
  4921. }
  4922. }
  4923. #define VENDOR_CCD "Cologne Chip AG"
  4924. #define VENDOR_BN "beroNet GmbH"
  4925. #define VENDOR_DIG "Digium Inc."
  4926. #define VENDOR_JH "Junghanns.NET GmbH"
  4927. #define VENDOR_PRIM "PrimuX"
  4928. static const struct hm_map hfcm_map[] = {
  4929. /*0*/ {VENDOR_BN, "HFC-1S Card (mini PCI)", 4, 1, 1, 3, 0, DIP_4S, 0, 0},
  4930. /*1*/ {VENDOR_BN, "HFC-2S Card", 4, 2, 1, 3, 0, DIP_4S, 0, 0},
  4931. /*2*/ {VENDOR_BN, "HFC-2S Card (mini PCI)", 4, 2, 1, 3, 0, DIP_4S, 0, 0},
  4932. /*3*/ {VENDOR_BN, "HFC-4S Card", 4, 4, 1, 2, 0, DIP_4S, 0, 0},
  4933. /*4*/ {VENDOR_BN, "HFC-4S Card (mini PCI)", 4, 4, 1, 2, 0, 0, 0, 0},
  4934. /*5*/ {VENDOR_CCD, "HFC-4S Eval (old)", 4, 4, 0, 0, 0, 0, 0, 0},
  4935. /*6*/ {VENDOR_CCD, "HFC-4S IOB4ST", 4, 4, 1, 2, 0, DIP_4S, 0, 0},
  4936. /*7*/ {VENDOR_CCD, "HFC-4S", 4, 4, 1, 2, 0, 0, 0, 0},
  4937. /*8*/ {VENDOR_DIG, "HFC-4S Card", 4, 4, 0, 2, 0, 0, HFC_IO_MODE_REGIO, 0},
  4938. /*9*/ {VENDOR_CCD, "HFC-4S Swyx 4xS0 SX2 QuadBri", 4, 4, 1, 2, 0, 0, 0, 0},
  4939. /*10*/ {VENDOR_JH, "HFC-4S (junghanns 2.0)", 4, 4, 1, 2, 0, 0, 0, 0},
  4940. /*11*/ {VENDOR_PRIM, "HFC-2S Primux Card", 4, 2, 0, 0, 0, 0, 0, 0},
  4941. /*12*/ {VENDOR_BN, "HFC-8S Card", 8, 8, 1, 0, 0, 0, 0, 0},
  4942. /*13*/ {VENDOR_BN, "HFC-8S Card (+)", 8, 8, 1, 8, 0, DIP_8S,
  4943. HFC_IO_MODE_REGIO, 0},
  4944. /*14*/ {VENDOR_CCD, "HFC-8S Eval (old)", 8, 8, 0, 0, 0, 0, 0, 0},
  4945. /*15*/ {VENDOR_CCD, "HFC-8S IOB4ST Recording", 8, 8, 1, 0, 0, 0, 0, 0},
  4946. /*16*/ {VENDOR_CCD, "HFC-8S IOB8ST", 8, 8, 1, 0, 0, 0, 0, 0},
  4947. /*17*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0, 0},
  4948. /*18*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0, 0},
  4949. /*19*/ {VENDOR_BN, "HFC-E1 Card", 1, 1, 0, 1, 0, DIP_E1, 0, 0},
  4950. /*20*/ {VENDOR_BN, "HFC-E1 Card (mini PCI)", 1, 1, 0, 1, 0, 0, 0, 0},
  4951. /*21*/ {VENDOR_BN, "HFC-E1+ Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0, 0},
  4952. /*22*/ {VENDOR_BN, "HFC-E1 Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0, 0},
  4953. /*23*/ {VENDOR_CCD, "HFC-E1 Eval (old)", 1, 1, 0, 0, 0, 0, 0, 0},
  4954. /*24*/ {VENDOR_CCD, "HFC-E1 IOB1E1", 1, 1, 0, 1, 0, 0, 0, 0},
  4955. /*25*/ {VENDOR_CCD, "HFC-E1", 1, 1, 0, 1, 0, 0, 0, 0},
  4956. /*26*/ {VENDOR_CCD, "HFC-4S Speech Design", 4, 4, 0, 0, 0, 0,
  4957. HFC_IO_MODE_PLXSD, 0},
  4958. /*27*/ {VENDOR_CCD, "HFC-E1 Speech Design", 1, 1, 0, 0, 0, 0,
  4959. HFC_IO_MODE_PLXSD, 0},
  4960. /*28*/ {VENDOR_CCD, "HFC-4S OpenVox", 4, 4, 1, 0, 0, 0, 0, 0},
  4961. /*29*/ {VENDOR_CCD, "HFC-2S OpenVox", 4, 2, 1, 0, 0, 0, 0, 0},
  4962. /*30*/ {VENDOR_CCD, "HFC-8S OpenVox", 8, 8, 1, 0, 0, 0, 0, 0},
  4963. /*31*/ {VENDOR_CCD, "XHFC-4S Speech Design", 5, 4, 0, 0, 0, 0,
  4964. HFC_IO_MODE_EMBSD, XHFC_IRQ},
  4965. /*32*/ {VENDOR_JH, "HFC-8S (junghanns)", 8, 8, 1, 0, 0, 0, 0, 0},
  4966. /*33*/ {VENDOR_BN, "HFC-2S Beronet Card PCIe", 4, 2, 1, 3, 0, DIP_4S, 0, 0},
  4967. /*34*/ {VENDOR_BN, "HFC-4S Beronet Card PCIe", 4, 4, 1, 2, 0, DIP_4S, 0, 0},
  4968. };
  4969. #undef H
  4970. #define H(x) ((unsigned long)&hfcm_map[x])
  4971. static struct pci_device_id hfmultipci_ids[] = {
  4972. /* Cards with HFC-4S Chip */
  4973. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4974. PCI_SUBDEVICE_ID_CCD_BN1SM, 0, 0, H(0)}, /* BN1S mini PCI */
  4975. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4976. PCI_SUBDEVICE_ID_CCD_BN2S, 0, 0, H(1)}, /* BN2S */
  4977. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4978. PCI_SUBDEVICE_ID_CCD_BN2SM, 0, 0, H(2)}, /* BN2S mini PCI */
  4979. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4980. PCI_SUBDEVICE_ID_CCD_BN4S, 0, 0, H(3)}, /* BN4S */
  4981. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4982. PCI_SUBDEVICE_ID_CCD_BN4SM, 0, 0, H(4)}, /* BN4S mini PCI */
  4983. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4984. PCI_DEVICE_ID_CCD_HFC4S, 0, 0, H(5)}, /* Old Eval */
  4985. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4986. PCI_SUBDEVICE_ID_CCD_IOB4ST, 0, 0, H(6)}, /* IOB4ST */
  4987. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4988. PCI_SUBDEVICE_ID_CCD_HFC4S, 0, 0, H(7)}, /* 4S */
  4989. { PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S,
  4990. PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S, 0, 0, H(8)},
  4991. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4992. PCI_SUBDEVICE_ID_CCD_SWYX4S, 0, 0, H(9)}, /* 4S Swyx */
  4993. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4994. PCI_SUBDEVICE_ID_CCD_JH4S20, 0, 0, H(10)},
  4995. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4996. PCI_SUBDEVICE_ID_CCD_PMX2S, 0, 0, H(11)}, /* Primux */
  4997. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  4998. PCI_SUBDEVICE_ID_CCD_OV4S, 0, 0, H(28)}, /* OpenVox 4 */
  4999. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  5000. PCI_SUBDEVICE_ID_CCD_OV2S, 0, 0, H(29)}, /* OpenVox 2 */
  5001. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  5002. 0xb761, 0, 0, H(33)}, /* BN2S PCIe */
  5003. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
  5004. 0xb762, 0, 0, H(34)}, /* BN4S PCIe */
  5005. /* Cards with HFC-8S Chip */
  5006. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5007. PCI_SUBDEVICE_ID_CCD_BN8S, 0, 0, H(12)}, /* BN8S */
  5008. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5009. PCI_SUBDEVICE_ID_CCD_BN8SP, 0, 0, H(13)}, /* BN8S+ */
  5010. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5011. PCI_DEVICE_ID_CCD_HFC8S, 0, 0, H(14)}, /* old Eval */
  5012. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5013. PCI_SUBDEVICE_ID_CCD_IOB8STR, 0, 0, H(15)}, /* IOB8ST Recording */
  5014. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5015. PCI_SUBDEVICE_ID_CCD_IOB8ST, 0, 0, H(16)}, /* IOB8ST */
  5016. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5017. PCI_SUBDEVICE_ID_CCD_IOB8ST_1, 0, 0, H(17)}, /* IOB8ST */
  5018. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5019. PCI_SUBDEVICE_ID_CCD_HFC8S, 0, 0, H(18)}, /* 8S */
  5020. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5021. PCI_SUBDEVICE_ID_CCD_OV8S, 0, 0, H(30)}, /* OpenVox 8 */
  5022. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
  5023. PCI_SUBDEVICE_ID_CCD_JH8S, 0, 0, H(32)}, /* Junganns 8S */
  5024. /* Cards with HFC-E1 Chip */
  5025. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5026. PCI_SUBDEVICE_ID_CCD_BNE1, 0, 0, H(19)}, /* BNE1 */
  5027. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5028. PCI_SUBDEVICE_ID_CCD_BNE1M, 0, 0, H(20)}, /* BNE1 mini PCI */
  5029. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5030. PCI_SUBDEVICE_ID_CCD_BNE1DP, 0, 0, H(21)}, /* BNE1 + (Dual) */
  5031. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5032. PCI_SUBDEVICE_ID_CCD_BNE1D, 0, 0, H(22)}, /* BNE1 (Dual) */
  5033. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5034. PCI_DEVICE_ID_CCD_HFCE1, 0, 0, H(23)}, /* Old Eval */
  5035. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5036. PCI_SUBDEVICE_ID_CCD_IOB1E1, 0, 0, H(24)}, /* IOB1E1 */
  5037. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5038. PCI_SUBDEVICE_ID_CCD_HFCE1, 0, 0, H(25)}, /* E1 */
  5039. { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
  5040. PCI_SUBDEVICE_ID_CCD_SPD4S, 0, 0, H(26)}, /* PLX PCI Bridge */
  5041. { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
  5042. PCI_SUBDEVICE_ID_CCD_SPDE1, 0, 0, H(27)}, /* PLX PCI Bridge */
  5043. { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
  5044. PCI_SUBDEVICE_ID_CCD_JHSE1, 0, 0, H(25)}, /* Junghanns E1 */
  5045. { PCI_VDEVICE(CCD, PCI_DEVICE_ID_CCD_HFC4S), 0 },
  5046. { PCI_VDEVICE(CCD, PCI_DEVICE_ID_CCD_HFC8S), 0 },
  5047. { PCI_VDEVICE(CCD, PCI_DEVICE_ID_CCD_HFCE1), 0 },
  5048. {0, }
  5049. };
  5050. #undef H
  5051. MODULE_DEVICE_TABLE(pci, hfmultipci_ids);
  5052. static int
  5053. hfcmulti_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5054. {
  5055. struct hm_map *m = (struct hm_map *)ent->driver_data;
  5056. int ret;
  5057. if (m == NULL && ent->vendor == PCI_VENDOR_ID_CCD && (
  5058. ent->device == PCI_DEVICE_ID_CCD_HFC4S ||
  5059. ent->device == PCI_DEVICE_ID_CCD_HFC8S ||
  5060. ent->device == PCI_DEVICE_ID_CCD_HFCE1)) {
  5061. printk(KERN_ERR
  5062. "Unknown HFC multiport controller (vendor:%04x device:%04x "
  5063. "subvendor:%04x subdevice:%04x)\n", pdev->vendor,
  5064. pdev->device, pdev->subsystem_vendor,
  5065. pdev->subsystem_device);
  5066. printk(KERN_ERR
  5067. "Please contact the driver maintainer for support.\n");
  5068. return -ENODEV;
  5069. }
  5070. ret = hfcmulti_init(m, pdev, ent);
  5071. if (ret)
  5072. return ret;
  5073. HFC_cnt++;
  5074. printk(KERN_INFO "%d devices registered\n", HFC_cnt);
  5075. return 0;
  5076. }
  5077. static struct pci_driver hfcmultipci_driver = {
  5078. .name = "hfc_multi",
  5079. .probe = hfcmulti_probe,
  5080. .remove = hfc_remove_pci,
  5081. .id_table = hfmultipci_ids,
  5082. };
  5083. static void __exit
  5084. HFCmulti_cleanup(void)
  5085. {
  5086. struct hfc_multi *card, *next;
  5087. /* get rid of all devices of this driver */
  5088. list_for_each_entry_safe(card, next, &HFClist, list)
  5089. release_card(card);
  5090. pci_unregister_driver(&hfcmultipci_driver);
  5091. }
  5092. static int __init
  5093. HFCmulti_init(void)
  5094. {
  5095. int err;
  5096. int i, xhfc = 0;
  5097. struct hm_map m;
  5098. printk(KERN_INFO "mISDN: HFC-multi driver %s\n", HFC_MULTI_VERSION);
  5099. #ifdef IRQ_DEBUG
  5100. printk(KERN_DEBUG "%s: IRQ_DEBUG IS ENABLED!\n", __func__);
  5101. #endif
  5102. spin_lock_init(&HFClock);
  5103. spin_lock_init(&plx_lock);
  5104. if (debug & DEBUG_HFCMULTI_INIT)
  5105. printk(KERN_DEBUG "%s: init entered\n", __func__);
  5106. switch (poll) {
  5107. case 0:
  5108. poll_timer = 6;
  5109. poll = 128;
  5110. break;
  5111. case 8:
  5112. poll_timer = 2;
  5113. break;
  5114. case 16:
  5115. poll_timer = 3;
  5116. break;
  5117. case 32:
  5118. poll_timer = 4;
  5119. break;
  5120. case 64:
  5121. poll_timer = 5;
  5122. break;
  5123. case 128:
  5124. poll_timer = 6;
  5125. break;
  5126. case 256:
  5127. poll_timer = 7;
  5128. break;
  5129. default:
  5130. printk(KERN_ERR
  5131. "%s: Wrong poll value (%d).\n", __func__, poll);
  5132. err = -EINVAL;
  5133. return err;
  5134. }
  5135. if (!clock)
  5136. clock = 1;
  5137. /* Register the embedded devices.
  5138. * This should be done before the PCI cards registration */
  5139. switch (hwid) {
  5140. case HWID_MINIP4:
  5141. xhfc = 1;
  5142. m = hfcm_map[31];
  5143. break;
  5144. case HWID_MINIP8:
  5145. xhfc = 2;
  5146. m = hfcm_map[31];
  5147. break;
  5148. case HWID_MINIP16:
  5149. xhfc = 4;
  5150. m = hfcm_map[31];
  5151. break;
  5152. default:
  5153. xhfc = 0;
  5154. }
  5155. for (i = 0; i < xhfc; ++i) {
  5156. err = hfcmulti_init(&m, NULL, NULL);
  5157. if (err) {
  5158. printk(KERN_ERR "error registering embedded driver: "
  5159. "%x\n", err);
  5160. return err;
  5161. }
  5162. HFC_cnt++;
  5163. printk(KERN_INFO "%d devices registered\n", HFC_cnt);
  5164. }
  5165. /* Register the PCI cards */
  5166. err = pci_register_driver(&hfcmultipci_driver);
  5167. if (err < 0) {
  5168. printk(KERN_ERR "error registering pci driver: %x\n", err);
  5169. return err;
  5170. }
  5171. return 0;
  5172. }
  5173. module_init(HFCmulti_init);
  5174. module_exit(HFCmulti_cleanup);