hfcmulti.c 144 KB

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