hfcmulti.c 148 KB

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