hfcmulti.c 142 KB

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