hfcmulti.c 142 KB

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