hfcmulti.c 150 KB

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