hfcmulti.c 153 KB

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