hfcmulti.c 142 KB

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