hfcmulti.c 148 KB

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