hfcmulti.c 142 KB

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