hfcmulti.c 152 KB

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