hfcmulti.c 143 KB

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