hfcmulti.c 148 KB

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