hfcmulti.c 142 KB

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