btusb.c 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * Generic Bluetooth USB driver
  5. *
  6. * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
  7. */
  8. #include <linux/dmi.h>
  9. #include <linux/module.h>
  10. #include <linux/usb.h>
  11. #include <linux/usb/quirks.h>
  12. #include <linux/firmware.h>
  13. #include <linux/iopoll.h>
  14. #include <linux/of_device.h>
  15. #include <linux/of_irq.h>
  16. #include <linux/suspend.h>
  17. #include <linux/gpio/consumer.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/unaligned.h>
  20. #include <net/bluetooth/bluetooth.h>
  21. #include <net/bluetooth/hci_core.h>
  22. #include "btintel.h"
  23. #include "btbcm.h"
  24. #include "btrtl.h"
  25. #include "btmtk.h"
  26. #define VERSION "0.8"
  27. static bool disable_scofix;
  28. static bool force_scofix;
  29. static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND);
  30. static bool enable_poll_sync = IS_ENABLED(CONFIG_BT_HCIBTUSB_POLL_SYNC);
  31. static bool reset = true;
  32. static struct usb_driver btusb_driver;
  33. #define BTUSB_IGNORE BIT(0)
  34. #define BTUSB_DIGIANSWER BIT(1)
  35. #define BTUSB_CSR BIT(2)
  36. #define BTUSB_SNIFFER BIT(3)
  37. #define BTUSB_BCM92035 BIT(4)
  38. #define BTUSB_BROKEN_ISOC BIT(5)
  39. #define BTUSB_WRONG_SCO_MTU BIT(6)
  40. #define BTUSB_ATH3012 BIT(7)
  41. #define BTUSB_INTEL_COMBINED BIT(8)
  42. #define BTUSB_INTEL_BOOT BIT(9)
  43. #define BTUSB_BCM_PATCHRAM BIT(10)
  44. #define BTUSB_MARVELL BIT(11)
  45. #define BTUSB_SWAVE BIT(12)
  46. #define BTUSB_AMP BIT(13)
  47. #define BTUSB_QCA_ROME BIT(14)
  48. #define BTUSB_BCM_APPLE BIT(15)
  49. #define BTUSB_REALTEK BIT(16)
  50. #define BTUSB_BCM2045 BIT(17)
  51. #define BTUSB_IFNUM_2 BIT(18)
  52. #define BTUSB_CW6622 BIT(19)
  53. #define BTUSB_MEDIATEK BIT(20)
  54. #define BTUSB_WIDEBAND_SPEECH BIT(21)
  55. #define BTUSB_INVALID_LE_STATES BIT(22)
  56. #define BTUSB_QCA_WCN6855 BIT(23)
  57. #define BTUSB_INTEL_BROKEN_SHUTDOWN_LED BIT(24)
  58. #define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25)
  59. #define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26)
  60. #define BTUSB_ACTIONS_SEMI BIT(27)
  61. static const struct usb_device_id btusb_table[] = {
  62. /* Generic Bluetooth USB device */
  63. { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
  64. /* Generic Bluetooth AMP device */
  65. { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP },
  66. /* Generic Bluetooth USB interface */
  67. { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) },
  68. /* Apple-specific (Broadcom) devices */
  69. { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01),
  70. .driver_info = BTUSB_BCM_APPLE | BTUSB_IFNUM_2 },
  71. /* MediaTek MT76x0E */
  72. { USB_DEVICE(0x0e8d, 0x763f) },
  73. /* Broadcom SoftSailing reporting vendor specific */
  74. { USB_DEVICE(0x0a5c, 0x21e1) },
  75. /* Apple MacBookPro 7,1 */
  76. { USB_DEVICE(0x05ac, 0x8213) },
  77. /* Apple iMac11,1 */
  78. { USB_DEVICE(0x05ac, 0x8215) },
  79. /* Apple MacBookPro6,2 */
  80. { USB_DEVICE(0x05ac, 0x8218) },
  81. /* Apple MacBookAir3,1, MacBookAir3,2 */
  82. { USB_DEVICE(0x05ac, 0x821b) },
  83. /* Apple MacBookAir4,1 */
  84. { USB_DEVICE(0x05ac, 0x821f) },
  85. /* Apple MacBookPro8,2 */
  86. { USB_DEVICE(0x05ac, 0x821a) },
  87. /* Apple MacMini5,1 */
  88. { USB_DEVICE(0x05ac, 0x8281) },
  89. /* AVM BlueFRITZ! USB v2.0 */
  90. { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE },
  91. /* Bluetooth Ultraport Module from IBM */
  92. { USB_DEVICE(0x04bf, 0x030a) },
  93. /* ALPS Modules with non-standard id */
  94. { USB_DEVICE(0x044e, 0x3001) },
  95. { USB_DEVICE(0x044e, 0x3002) },
  96. /* Ericsson with non-standard id */
  97. { USB_DEVICE(0x0bdb, 0x1002) },
  98. /* Canyon CN-BTU1 with HID interfaces */
  99. { USB_DEVICE(0x0c10, 0x0000) },
  100. /* Broadcom BCM20702B0 (Dynex/Insignia) */
  101. { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM },
  102. /* Broadcom BCM43142A0 (Foxconn/Lenovo) */
  103. { USB_VENDOR_AND_INTERFACE_INFO(0x105b, 0xff, 0x01, 0x01),
  104. .driver_info = BTUSB_BCM_PATCHRAM },
  105. /* Broadcom BCM920703 (HTC Vive) */
  106. { USB_VENDOR_AND_INTERFACE_INFO(0x0bb4, 0xff, 0x01, 0x01),
  107. .driver_info = BTUSB_BCM_PATCHRAM },
  108. /* Foxconn - Hon Hai */
  109. { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
  110. .driver_info = BTUSB_BCM_PATCHRAM },
  111. /* Lite-On Technology - Broadcom based */
  112. { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
  113. .driver_info = BTUSB_BCM_PATCHRAM },
  114. /* Broadcom devices with vendor specific id */
  115. { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
  116. .driver_info = BTUSB_BCM_PATCHRAM },
  117. /* ASUSTek Computer - Broadcom based */
  118. { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
  119. .driver_info = BTUSB_BCM_PATCHRAM },
  120. /* Belkin F8065bf - Broadcom based */
  121. { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01),
  122. .driver_info = BTUSB_BCM_PATCHRAM },
  123. /* IMC Networks - Broadcom based */
  124. { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01),
  125. .driver_info = BTUSB_BCM_PATCHRAM },
  126. /* Dell Computer - Broadcom based */
  127. { USB_VENDOR_AND_INTERFACE_INFO(0x413c, 0xff, 0x01, 0x01),
  128. .driver_info = BTUSB_BCM_PATCHRAM },
  129. /* Toshiba Corp - Broadcom based */
  130. { USB_VENDOR_AND_INTERFACE_INFO(0x0930, 0xff, 0x01, 0x01),
  131. .driver_info = BTUSB_BCM_PATCHRAM },
  132. /* Intel Bluetooth USB Bootloader (RAM module) */
  133. { USB_DEVICE(0x8087, 0x0a5a),
  134. .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC },
  135. { } /* Terminating entry */
  136. };
  137. MODULE_DEVICE_TABLE(usb, btusb_table);
  138. static const struct usb_device_id quirks_table[] = {
  139. /* CSR BlueCore devices */
  140. { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
  141. /* Broadcom BCM2033 without firmware */
  142. { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
  143. /* Broadcom BCM2045 devices */
  144. { USB_DEVICE(0x0a5c, 0x2045), .driver_info = BTUSB_BCM2045 },
  145. /* Atheros 3011 with sflash firmware */
  146. { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
  147. { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
  148. { USB_DEVICE(0x04f2, 0xaff1), .driver_info = BTUSB_IGNORE },
  149. { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
  150. { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
  151. { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
  152. { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
  153. /* Atheros AR9285 Malbec with sflash firmware */
  154. { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
  155. /* Atheros 3012 with sflash firmware */
  156. { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
  157. { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
  158. { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
  159. { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
  160. { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
  161. { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 },
  162. { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
  163. { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 },
  164. { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
  165. { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
  166. { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
  167. { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
  168. { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
  169. { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
  170. { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
  171. { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 },
  172. { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
  173. { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
  174. { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 },
  175. { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 },
  176. { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
  177. { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 },
  178. { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
  179. { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
  180. { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
  181. { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
  182. { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
  183. { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
  184. { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
  185. { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
  186. { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 },
  187. { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
  188. { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
  189. { USB_DEVICE(0x0cf3, 0x817b), .driver_info = BTUSB_ATH3012 },
  190. { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
  191. { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
  192. { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
  193. { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
  194. { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
  195. { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
  196. { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
  197. { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 },
  198. { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
  199. { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
  200. { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
  201. { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
  202. { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 },
  203. { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 },
  204. { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 },
  205. { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 },
  206. /* Atheros AR5BBU12 with sflash firmware */
  207. { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
  208. /* Atheros AR5BBU12 with sflash firmware */
  209. { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
  210. { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
  211. /* QCA ROME chipset */
  212. { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME |
  213. BTUSB_WIDEBAND_SPEECH },
  214. { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME |
  215. BTUSB_WIDEBAND_SPEECH },
  216. { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME |
  217. BTUSB_WIDEBAND_SPEECH },
  218. { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME |
  219. BTUSB_WIDEBAND_SPEECH },
  220. { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME |
  221. BTUSB_WIDEBAND_SPEECH },
  222. { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME |
  223. BTUSB_WIDEBAND_SPEECH },
  224. { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME |
  225. BTUSB_WIDEBAND_SPEECH },
  226. { USB_DEVICE(0x0cf3, 0xe500), .driver_info = BTUSB_QCA_ROME |
  227. BTUSB_WIDEBAND_SPEECH },
  228. { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME |
  229. BTUSB_WIDEBAND_SPEECH },
  230. { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME |
  231. BTUSB_WIDEBAND_SPEECH },
  232. { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME |
  233. BTUSB_WIDEBAND_SPEECH },
  234. { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME |
  235. BTUSB_WIDEBAND_SPEECH },
  236. { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME |
  237. BTUSB_WIDEBAND_SPEECH },
  238. { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME |
  239. BTUSB_WIDEBAND_SPEECH },
  240. { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME |
  241. BTUSB_WIDEBAND_SPEECH },
  242. { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME |
  243. BTUSB_WIDEBAND_SPEECH },
  244. { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME |
  245. BTUSB_WIDEBAND_SPEECH },
  246. { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME |
  247. BTUSB_WIDEBAND_SPEECH },
  248. { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME |
  249. BTUSB_WIDEBAND_SPEECH },
  250. /* QCA WCN6855 chipset */
  251. { USB_DEVICE(0x0cf3, 0xe600), .driver_info = BTUSB_QCA_WCN6855 |
  252. BTUSB_WIDEBAND_SPEECH },
  253. { USB_DEVICE(0x0489, 0xe0cc), .driver_info = BTUSB_QCA_WCN6855 |
  254. BTUSB_WIDEBAND_SPEECH },
  255. { USB_DEVICE(0x0489, 0xe0d6), .driver_info = BTUSB_QCA_WCN6855 |
  256. BTUSB_WIDEBAND_SPEECH },
  257. { USB_DEVICE(0x0489, 0xe0e3), .driver_info = BTUSB_QCA_WCN6855 |
  258. BTUSB_WIDEBAND_SPEECH },
  259. { USB_DEVICE(0x10ab, 0x9309), .driver_info = BTUSB_QCA_WCN6855 |
  260. BTUSB_WIDEBAND_SPEECH },
  261. { USB_DEVICE(0x10ab, 0x9409), .driver_info = BTUSB_QCA_WCN6855 |
  262. BTUSB_WIDEBAND_SPEECH },
  263. { USB_DEVICE(0x0489, 0xe0d0), .driver_info = BTUSB_QCA_WCN6855 |
  264. BTUSB_WIDEBAND_SPEECH },
  265. { USB_DEVICE(0x10ab, 0x9108), .driver_info = BTUSB_QCA_WCN6855 |
  266. BTUSB_WIDEBAND_SPEECH },
  267. { USB_DEVICE(0x10ab, 0x9109), .driver_info = BTUSB_QCA_WCN6855 |
  268. BTUSB_WIDEBAND_SPEECH },
  269. { USB_DEVICE(0x10ab, 0x9208), .driver_info = BTUSB_QCA_WCN6855 |
  270. BTUSB_WIDEBAND_SPEECH },
  271. { USB_DEVICE(0x10ab, 0x9209), .driver_info = BTUSB_QCA_WCN6855 |
  272. BTUSB_WIDEBAND_SPEECH },
  273. { USB_DEVICE(0x10ab, 0x9308), .driver_info = BTUSB_QCA_WCN6855 |
  274. BTUSB_WIDEBAND_SPEECH },
  275. { USB_DEVICE(0x10ab, 0x9408), .driver_info = BTUSB_QCA_WCN6855 |
  276. BTUSB_WIDEBAND_SPEECH },
  277. { USB_DEVICE(0x10ab, 0x9508), .driver_info = BTUSB_QCA_WCN6855 |
  278. BTUSB_WIDEBAND_SPEECH },
  279. { USB_DEVICE(0x10ab, 0x9509), .driver_info = BTUSB_QCA_WCN6855 |
  280. BTUSB_WIDEBAND_SPEECH },
  281. { USB_DEVICE(0x10ab, 0x9608), .driver_info = BTUSB_QCA_WCN6855 |
  282. BTUSB_WIDEBAND_SPEECH },
  283. { USB_DEVICE(0x10ab, 0x9609), .driver_info = BTUSB_QCA_WCN6855 |
  284. BTUSB_WIDEBAND_SPEECH },
  285. { USB_DEVICE(0x10ab, 0x9f09), .driver_info = BTUSB_QCA_WCN6855 |
  286. BTUSB_WIDEBAND_SPEECH },
  287. { USB_DEVICE(0x04ca, 0x3022), .driver_info = BTUSB_QCA_WCN6855 |
  288. BTUSB_WIDEBAND_SPEECH },
  289. { USB_DEVICE(0x0489, 0xe0c7), .driver_info = BTUSB_QCA_WCN6855 |
  290. BTUSB_WIDEBAND_SPEECH },
  291. { USB_DEVICE(0x0489, 0xe0c9), .driver_info = BTUSB_QCA_WCN6855 |
  292. BTUSB_WIDEBAND_SPEECH },
  293. { USB_DEVICE(0x0489, 0xe0ca), .driver_info = BTUSB_QCA_WCN6855 |
  294. BTUSB_WIDEBAND_SPEECH },
  295. { USB_DEVICE(0x0489, 0xe0cb), .driver_info = BTUSB_QCA_WCN6855 |
  296. BTUSB_WIDEBAND_SPEECH },
  297. { USB_DEVICE(0x0489, 0xe0ce), .driver_info = BTUSB_QCA_WCN6855 |
  298. BTUSB_WIDEBAND_SPEECH },
  299. { USB_DEVICE(0x0489, 0xe0de), .driver_info = BTUSB_QCA_WCN6855 |
  300. BTUSB_WIDEBAND_SPEECH },
  301. { USB_DEVICE(0x0489, 0xe0df), .driver_info = BTUSB_QCA_WCN6855 |
  302. BTUSB_WIDEBAND_SPEECH },
  303. { USB_DEVICE(0x0489, 0xe0e1), .driver_info = BTUSB_QCA_WCN6855 |
  304. BTUSB_WIDEBAND_SPEECH },
  305. { USB_DEVICE(0x0489, 0xe0ea), .driver_info = BTUSB_QCA_WCN6855 |
  306. BTUSB_WIDEBAND_SPEECH },
  307. { USB_DEVICE(0x0489, 0xe0ec), .driver_info = BTUSB_QCA_WCN6855 |
  308. BTUSB_WIDEBAND_SPEECH },
  309. { USB_DEVICE(0x04ca, 0x3023), .driver_info = BTUSB_QCA_WCN6855 |
  310. BTUSB_WIDEBAND_SPEECH },
  311. { USB_DEVICE(0x04ca, 0x3024), .driver_info = BTUSB_QCA_WCN6855 |
  312. BTUSB_WIDEBAND_SPEECH },
  313. { USB_DEVICE(0x04ca, 0x3a22), .driver_info = BTUSB_QCA_WCN6855 |
  314. BTUSB_WIDEBAND_SPEECH },
  315. { USB_DEVICE(0x04ca, 0x3a24), .driver_info = BTUSB_QCA_WCN6855 |
  316. BTUSB_WIDEBAND_SPEECH },
  317. { USB_DEVICE(0x04ca, 0x3a26), .driver_info = BTUSB_QCA_WCN6855 |
  318. BTUSB_WIDEBAND_SPEECH },
  319. { USB_DEVICE(0x04ca, 0x3a27), .driver_info = BTUSB_QCA_WCN6855 |
  320. BTUSB_WIDEBAND_SPEECH },
  321. /* QCA WCN785x chipset */
  322. { USB_DEVICE(0x0cf3, 0xe700), .driver_info = BTUSB_QCA_WCN6855 |
  323. BTUSB_WIDEBAND_SPEECH },
  324. { USB_DEVICE(0x0489, 0xe0fc), .driver_info = BTUSB_QCA_WCN6855 |
  325. BTUSB_WIDEBAND_SPEECH },
  326. { USB_DEVICE(0x0489, 0xe0f3), .driver_info = BTUSB_QCA_WCN6855 |
  327. BTUSB_WIDEBAND_SPEECH },
  328. { USB_DEVICE(0x0489, 0xe100), .driver_info = BTUSB_QCA_WCN6855 |
  329. BTUSB_WIDEBAND_SPEECH },
  330. { USB_DEVICE(0x0489, 0xe103), .driver_info = BTUSB_QCA_WCN6855 |
  331. BTUSB_WIDEBAND_SPEECH },
  332. { USB_DEVICE(0x0489, 0xe10a), .driver_info = BTUSB_QCA_WCN6855 |
  333. BTUSB_WIDEBAND_SPEECH },
  334. { USB_DEVICE(0x0489, 0xe10d), .driver_info = BTUSB_QCA_WCN6855 |
  335. BTUSB_WIDEBAND_SPEECH },
  336. { USB_DEVICE(0x0489, 0xe11b), .driver_info = BTUSB_QCA_WCN6855 |
  337. BTUSB_WIDEBAND_SPEECH },
  338. { USB_DEVICE(0x0489, 0xe11c), .driver_info = BTUSB_QCA_WCN6855 |
  339. BTUSB_WIDEBAND_SPEECH },
  340. { USB_DEVICE(0x0489, 0xe11f), .driver_info = BTUSB_QCA_WCN6855 |
  341. BTUSB_WIDEBAND_SPEECH },
  342. { USB_DEVICE(0x0489, 0xe141), .driver_info = BTUSB_QCA_WCN6855 |
  343. BTUSB_WIDEBAND_SPEECH },
  344. { USB_DEVICE(0x0489, 0xe14a), .driver_info = BTUSB_QCA_WCN6855 |
  345. BTUSB_WIDEBAND_SPEECH },
  346. { USB_DEVICE(0x0489, 0xe14b), .driver_info = BTUSB_QCA_WCN6855 |
  347. BTUSB_WIDEBAND_SPEECH },
  348. { USB_DEVICE(0x0489, 0xe14d), .driver_info = BTUSB_QCA_WCN6855 |
  349. BTUSB_WIDEBAND_SPEECH },
  350. { USB_DEVICE(0x13d3, 0x3623), .driver_info = BTUSB_QCA_WCN6855 |
  351. BTUSB_WIDEBAND_SPEECH },
  352. { USB_DEVICE(0x13d3, 0x3624), .driver_info = BTUSB_QCA_WCN6855 |
  353. BTUSB_WIDEBAND_SPEECH },
  354. { USB_DEVICE(0x2c7c, 0x0130), .driver_info = BTUSB_QCA_WCN6855 |
  355. BTUSB_WIDEBAND_SPEECH },
  356. { USB_DEVICE(0x2c7c, 0x0131), .driver_info = BTUSB_QCA_WCN6855 |
  357. BTUSB_WIDEBAND_SPEECH },
  358. { USB_DEVICE(0x2c7c, 0x0132), .driver_info = BTUSB_QCA_WCN6855 |
  359. BTUSB_WIDEBAND_SPEECH },
  360. /* Broadcom BCM2035 */
  361. { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
  362. { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
  363. { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
  364. /* Broadcom BCM2045 */
  365. { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
  366. { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
  367. /* IBM/Lenovo ThinkPad with Broadcom chip */
  368. { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
  369. { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
  370. /* HP laptop with Broadcom chip */
  371. { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
  372. /* Dell laptop with Broadcom chip */
  373. { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
  374. /* Dell Wireless 370 and 410 devices */
  375. { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
  376. { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
  377. /* Belkin F8T012 and F8T013 devices */
  378. { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
  379. { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
  380. /* Asus WL-BTD202 device */
  381. { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
  382. /* Kensington Bluetooth USB adapter */
  383. { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
  384. /* RTX Telecom based adapters with buggy SCO support */
  385. { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
  386. { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
  387. /* CONWISE Technology based adapters with buggy SCO support */
  388. { USB_DEVICE(0x0e5e, 0x6622),
  389. .driver_info = BTUSB_BROKEN_ISOC | BTUSB_CW6622},
  390. /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
  391. { USB_DEVICE(0x1310, 0x0001), .driver_info = BTUSB_SWAVE },
  392. /* Digianswer devices */
  393. { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
  394. { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
  395. /* CSR BlueCore Bluetooth Sniffer */
  396. { USB_DEVICE(0x0a12, 0x0002),
  397. .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
  398. /* Frontline ComProbe Bluetooth Sniffer */
  399. { USB_DEVICE(0x16d3, 0x0002),
  400. .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
  401. /* Marvell Bluetooth devices */
  402. { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL },
  403. { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL },
  404. { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL },
  405. /* Intel Bluetooth devices */
  406. { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_COMBINED },
  407. { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_COMBINED },
  408. { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_COMBINED },
  409. { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_COMBINED },
  410. { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_COMBINED },
  411. { USB_DEVICE(0x8087, 0x0035), .driver_info = BTUSB_INTEL_COMBINED },
  412. { USB_DEVICE(0x8087, 0x0036), .driver_info = BTUSB_INTEL_COMBINED },
  413. { USB_DEVICE(0x8087, 0x0037), .driver_info = BTUSB_INTEL_COMBINED },
  414. { USB_DEVICE(0x8087, 0x0038), .driver_info = BTUSB_INTEL_COMBINED },
  415. { USB_DEVICE(0x8087, 0x0039), .driver_info = BTUSB_INTEL_COMBINED },
  416. { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR },
  417. { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED |
  418. BTUSB_INTEL_NO_WBS_SUPPORT |
  419. BTUSB_INTEL_BROKEN_INITIAL_NCMD |
  420. BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
  421. { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED |
  422. BTUSB_INTEL_NO_WBS_SUPPORT |
  423. BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
  424. { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_COMBINED },
  425. { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL_COMBINED |
  426. BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
  427. { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_COMBINED },
  428. /* Other Intel Bluetooth devices */
  429. { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
  430. .driver_info = BTUSB_IGNORE },
  431. /* Realtek 8821CE Bluetooth devices */
  432. { USB_DEVICE(0x13d3, 0x3529), .driver_info = BTUSB_REALTEK |
  433. BTUSB_WIDEBAND_SPEECH },
  434. /* Realtek 8822CE Bluetooth devices */
  435. { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK |
  436. BTUSB_WIDEBAND_SPEECH },
  437. { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK |
  438. BTUSB_WIDEBAND_SPEECH },
  439. /* Realtek 8822CU Bluetooth devices */
  440. { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK |
  441. BTUSB_WIDEBAND_SPEECH },
  442. /* Realtek 8851BU Bluetooth devices */
  443. { USB_DEVICE(0x3625, 0x010b), .driver_info = BTUSB_REALTEK |
  444. BTUSB_WIDEBAND_SPEECH },
  445. { USB_DEVICE(0x2001, 0x332a), .driver_info = BTUSB_REALTEK |
  446. BTUSB_WIDEBAND_SPEECH },
  447. /* Realtek 8852AE Bluetooth devices */
  448. { USB_DEVICE(0x0bda, 0x2852), .driver_info = BTUSB_REALTEK |
  449. BTUSB_WIDEBAND_SPEECH },
  450. { USB_DEVICE(0x0bda, 0xc852), .driver_info = BTUSB_REALTEK |
  451. BTUSB_WIDEBAND_SPEECH },
  452. { USB_DEVICE(0x0bda, 0x385a), .driver_info = BTUSB_REALTEK |
  453. BTUSB_WIDEBAND_SPEECH },
  454. { USB_DEVICE(0x0bda, 0x4852), .driver_info = BTUSB_REALTEK |
  455. BTUSB_WIDEBAND_SPEECH },
  456. { USB_DEVICE(0x04c5, 0x165c), .driver_info = BTUSB_REALTEK |
  457. BTUSB_WIDEBAND_SPEECH },
  458. { USB_DEVICE(0x04ca, 0x4006), .driver_info = BTUSB_REALTEK |
  459. BTUSB_WIDEBAND_SPEECH },
  460. { USB_DEVICE(0x0cb8, 0xc549), .driver_info = BTUSB_REALTEK |
  461. BTUSB_WIDEBAND_SPEECH },
  462. /* Realtek 8852CE Bluetooth devices */
  463. { USB_DEVICE(0x04ca, 0x4007), .driver_info = BTUSB_REALTEK |
  464. BTUSB_WIDEBAND_SPEECH },
  465. { USB_DEVICE(0x04c5, 0x1675), .driver_info = BTUSB_REALTEK |
  466. BTUSB_WIDEBAND_SPEECH },
  467. { USB_DEVICE(0x0cb8, 0xc558), .driver_info = BTUSB_REALTEK |
  468. BTUSB_WIDEBAND_SPEECH },
  469. { USB_DEVICE(0x13d3, 0x3587), .driver_info = BTUSB_REALTEK |
  470. BTUSB_WIDEBAND_SPEECH },
  471. { USB_DEVICE(0x13d3, 0x3586), .driver_info = BTUSB_REALTEK |
  472. BTUSB_WIDEBAND_SPEECH },
  473. { USB_DEVICE(0x13d3, 0x3592), .driver_info = BTUSB_REALTEK |
  474. BTUSB_WIDEBAND_SPEECH },
  475. { USB_DEVICE(0x0489, 0xe122), .driver_info = BTUSB_REALTEK |
  476. BTUSB_WIDEBAND_SPEECH },
  477. /* Realtek 8852BE Bluetooth devices */
  478. { USB_DEVICE(0x0cb8, 0xc559), .driver_info = BTUSB_REALTEK |
  479. BTUSB_WIDEBAND_SPEECH },
  480. { USB_DEVICE(0x0bda, 0x4853), .driver_info = BTUSB_REALTEK |
  481. BTUSB_WIDEBAND_SPEECH },
  482. { USB_DEVICE(0x0bda, 0x887b), .driver_info = BTUSB_REALTEK |
  483. BTUSB_WIDEBAND_SPEECH },
  484. { USB_DEVICE(0x0bda, 0xb85b), .driver_info = BTUSB_REALTEK |
  485. BTUSB_WIDEBAND_SPEECH },
  486. { USB_DEVICE(0x13d3, 0x3570), .driver_info = BTUSB_REALTEK |
  487. BTUSB_WIDEBAND_SPEECH },
  488. { USB_DEVICE(0x13d3, 0x3571), .driver_info = BTUSB_REALTEK |
  489. BTUSB_WIDEBAND_SPEECH },
  490. { USB_DEVICE(0x13d3, 0x3572), .driver_info = BTUSB_REALTEK |
  491. BTUSB_WIDEBAND_SPEECH },
  492. { USB_DEVICE(0x13d3, 0x3591), .driver_info = BTUSB_REALTEK |
  493. BTUSB_WIDEBAND_SPEECH },
  494. { USB_DEVICE(0x0489, 0xe123), .driver_info = BTUSB_REALTEK |
  495. BTUSB_WIDEBAND_SPEECH },
  496. { USB_DEVICE(0x0489, 0xe125), .driver_info = BTUSB_REALTEK |
  497. BTUSB_WIDEBAND_SPEECH },
  498. /* Realtek 8852BT/8852BE-VT Bluetooth devices */
  499. { USB_DEVICE(0x0bda, 0x8520), .driver_info = BTUSB_REALTEK |
  500. BTUSB_WIDEBAND_SPEECH },
  501. /* Realtek 8922AE Bluetooth devices */
  502. { USB_DEVICE(0x0bda, 0x8922), .driver_info = BTUSB_REALTEK |
  503. BTUSB_WIDEBAND_SPEECH },
  504. { USB_DEVICE(0x13d3, 0x3617), .driver_info = BTUSB_REALTEK |
  505. BTUSB_WIDEBAND_SPEECH },
  506. { USB_DEVICE(0x13d3, 0x3616), .driver_info = BTUSB_REALTEK |
  507. BTUSB_WIDEBAND_SPEECH },
  508. { USB_DEVICE(0x0489, 0xe130), .driver_info = BTUSB_REALTEK |
  509. BTUSB_WIDEBAND_SPEECH },
  510. /* Realtek Bluetooth devices */
  511. { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
  512. .driver_info = BTUSB_REALTEK },
  513. /* MediaTek Bluetooth devices */
  514. { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01),
  515. .driver_info = BTUSB_MEDIATEK |
  516. BTUSB_WIDEBAND_SPEECH },
  517. /* Additional MediaTek MT7615E Bluetooth devices */
  518. { USB_DEVICE(0x13d3, 0x3560), .driver_info = BTUSB_MEDIATEK},
  519. /* Additional MediaTek MT7663 Bluetooth devices */
  520. { USB_DEVICE(0x043e, 0x310c), .driver_info = BTUSB_MEDIATEK |
  521. BTUSB_WIDEBAND_SPEECH },
  522. { USB_DEVICE(0x04ca, 0x3801), .driver_info = BTUSB_MEDIATEK |
  523. BTUSB_WIDEBAND_SPEECH },
  524. /* Additional MediaTek MT7668 Bluetooth devices */
  525. { USB_DEVICE(0x043e, 0x3109), .driver_info = BTUSB_MEDIATEK |
  526. BTUSB_WIDEBAND_SPEECH },
  527. /* Additional MediaTek MT7920 Bluetooth devices */
  528. { USB_DEVICE(0x0489, 0xe134), .driver_info = BTUSB_MEDIATEK |
  529. BTUSB_WIDEBAND_SPEECH },
  530. { USB_DEVICE(0x13d3, 0x3620), .driver_info = BTUSB_MEDIATEK |
  531. BTUSB_WIDEBAND_SPEECH },
  532. { USB_DEVICE(0x13d3, 0x3621), .driver_info = BTUSB_MEDIATEK |
  533. BTUSB_WIDEBAND_SPEECH },
  534. { USB_DEVICE(0x13d3, 0x3622), .driver_info = BTUSB_MEDIATEK |
  535. BTUSB_WIDEBAND_SPEECH },
  536. /* Additional MediaTek MT7921 Bluetooth devices */
  537. { USB_DEVICE(0x0489, 0xe0c8), .driver_info = BTUSB_MEDIATEK |
  538. BTUSB_WIDEBAND_SPEECH },
  539. { USB_DEVICE(0x0489, 0xe0cd), .driver_info = BTUSB_MEDIATEK |
  540. BTUSB_WIDEBAND_SPEECH },
  541. { USB_DEVICE(0x0489, 0xe0e0), .driver_info = BTUSB_MEDIATEK |
  542. BTUSB_WIDEBAND_SPEECH },
  543. { USB_DEVICE(0x0489, 0xe0f2), .driver_info = BTUSB_MEDIATEK |
  544. BTUSB_WIDEBAND_SPEECH },
  545. { USB_DEVICE(0x04ca, 0x3802), .driver_info = BTUSB_MEDIATEK |
  546. BTUSB_WIDEBAND_SPEECH },
  547. { USB_DEVICE(0x0e8d, 0x0608), .driver_info = BTUSB_MEDIATEK |
  548. BTUSB_WIDEBAND_SPEECH },
  549. { USB_DEVICE(0x13d3, 0x3563), .driver_info = BTUSB_MEDIATEK |
  550. BTUSB_WIDEBAND_SPEECH },
  551. { USB_DEVICE(0x13d3, 0x3564), .driver_info = BTUSB_MEDIATEK |
  552. BTUSB_WIDEBAND_SPEECH },
  553. { USB_DEVICE(0x13d3, 0x3567), .driver_info = BTUSB_MEDIATEK |
  554. BTUSB_WIDEBAND_SPEECH },
  555. { USB_DEVICE(0x13d3, 0x3578), .driver_info = BTUSB_MEDIATEK |
  556. BTUSB_WIDEBAND_SPEECH },
  557. { USB_DEVICE(0x13d3, 0x3583), .driver_info = BTUSB_MEDIATEK |
  558. BTUSB_WIDEBAND_SPEECH },
  559. { USB_DEVICE(0x13d3, 0x3606), .driver_info = BTUSB_MEDIATEK |
  560. BTUSB_WIDEBAND_SPEECH },
  561. /* MediaTek MT7922 Bluetooth devices */
  562. { USB_DEVICE(0x13d3, 0x3585), .driver_info = BTUSB_MEDIATEK |
  563. BTUSB_WIDEBAND_SPEECH },
  564. { USB_DEVICE(0x13d3, 0x3610), .driver_info = BTUSB_MEDIATEK |
  565. BTUSB_WIDEBAND_SPEECH },
  566. /* MediaTek MT7922A Bluetooth devices */
  567. { USB_DEVICE(0x0489, 0xe0d8), .driver_info = BTUSB_MEDIATEK |
  568. BTUSB_WIDEBAND_SPEECH },
  569. { USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK |
  570. BTUSB_WIDEBAND_SPEECH },
  571. { USB_DEVICE(0x0489, 0xe0e2), .driver_info = BTUSB_MEDIATEK |
  572. BTUSB_WIDEBAND_SPEECH },
  573. { USB_DEVICE(0x0489, 0xe0e4), .driver_info = BTUSB_MEDIATEK |
  574. BTUSB_WIDEBAND_SPEECH },
  575. { USB_DEVICE(0x0489, 0xe0f1), .driver_info = BTUSB_MEDIATEK |
  576. BTUSB_WIDEBAND_SPEECH },
  577. { USB_DEVICE(0x0489, 0xe0f2), .driver_info = BTUSB_MEDIATEK |
  578. BTUSB_WIDEBAND_SPEECH },
  579. { USB_DEVICE(0x0489, 0xe0f5), .driver_info = BTUSB_MEDIATEK |
  580. BTUSB_WIDEBAND_SPEECH },
  581. { USB_DEVICE(0x0489, 0xe0f6), .driver_info = BTUSB_MEDIATEK |
  582. BTUSB_WIDEBAND_SPEECH },
  583. { USB_DEVICE(0x0489, 0xe102), .driver_info = BTUSB_MEDIATEK |
  584. BTUSB_WIDEBAND_SPEECH },
  585. { USB_DEVICE(0x0489, 0xe152), .driver_info = BTUSB_MEDIATEK |
  586. BTUSB_WIDEBAND_SPEECH },
  587. { USB_DEVICE(0x0489, 0xe153), .driver_info = BTUSB_MEDIATEK |
  588. BTUSB_WIDEBAND_SPEECH },
  589. { USB_DEVICE(0x04ca, 0x3804), .driver_info = BTUSB_MEDIATEK |
  590. BTUSB_WIDEBAND_SPEECH },
  591. { USB_DEVICE(0x04ca, 0x38e4), .driver_info = BTUSB_MEDIATEK |
  592. BTUSB_WIDEBAND_SPEECH },
  593. { USB_DEVICE(0x13d3, 0x3568), .driver_info = BTUSB_MEDIATEK |
  594. BTUSB_WIDEBAND_SPEECH },
  595. { USB_DEVICE(0x13d3, 0x3584), .driver_info = BTUSB_MEDIATEK |
  596. BTUSB_WIDEBAND_SPEECH },
  597. { USB_DEVICE(0x13d3, 0x3605), .driver_info = BTUSB_MEDIATEK |
  598. BTUSB_WIDEBAND_SPEECH },
  599. { USB_DEVICE(0x13d3, 0x3607), .driver_info = BTUSB_MEDIATEK |
  600. BTUSB_WIDEBAND_SPEECH },
  601. { USB_DEVICE(0x13d3, 0x3614), .driver_info = BTUSB_MEDIATEK |
  602. BTUSB_WIDEBAND_SPEECH },
  603. { USB_DEVICE(0x13d3, 0x3615), .driver_info = BTUSB_MEDIATEK |
  604. BTUSB_WIDEBAND_SPEECH },
  605. { USB_DEVICE(0x35f5, 0x7922), .driver_info = BTUSB_MEDIATEK |
  606. BTUSB_WIDEBAND_SPEECH },
  607. /* Additional MediaTek MT7925 Bluetooth devices */
  608. { USB_DEVICE(0x0489, 0xe111), .driver_info = BTUSB_MEDIATEK |
  609. BTUSB_WIDEBAND_SPEECH },
  610. { USB_DEVICE(0x0489, 0xe113), .driver_info = BTUSB_MEDIATEK |
  611. BTUSB_WIDEBAND_SPEECH },
  612. { USB_DEVICE(0x0489, 0xe118), .driver_info = BTUSB_MEDIATEK |
  613. BTUSB_WIDEBAND_SPEECH },
  614. { USB_DEVICE(0x0489, 0xe11e), .driver_info = BTUSB_MEDIATEK |
  615. BTUSB_WIDEBAND_SPEECH },
  616. { USB_DEVICE(0x0489, 0xe124), .driver_info = BTUSB_MEDIATEK |
  617. BTUSB_WIDEBAND_SPEECH },
  618. { USB_DEVICE(0x0489, 0xe139), .driver_info = BTUSB_MEDIATEK |
  619. BTUSB_WIDEBAND_SPEECH },
  620. { USB_DEVICE(0x0489, 0xe14e), .driver_info = BTUSB_MEDIATEK |
  621. BTUSB_WIDEBAND_SPEECH },
  622. { USB_DEVICE(0x0489, 0xe14f), .driver_info = BTUSB_MEDIATEK |
  623. BTUSB_WIDEBAND_SPEECH },
  624. { USB_DEVICE(0x0489, 0xe150), .driver_info = BTUSB_MEDIATEK |
  625. BTUSB_WIDEBAND_SPEECH },
  626. { USB_DEVICE(0x0489, 0xe151), .driver_info = BTUSB_MEDIATEK |
  627. BTUSB_WIDEBAND_SPEECH },
  628. { USB_DEVICE(0x13d3, 0x3602), .driver_info = BTUSB_MEDIATEK |
  629. BTUSB_WIDEBAND_SPEECH },
  630. { USB_DEVICE(0x13d3, 0x3603), .driver_info = BTUSB_MEDIATEK |
  631. BTUSB_WIDEBAND_SPEECH },
  632. { USB_DEVICE(0x13d3, 0x3604), .driver_info = BTUSB_MEDIATEK |
  633. BTUSB_WIDEBAND_SPEECH },
  634. { USB_DEVICE(0x13d3, 0x3608), .driver_info = BTUSB_MEDIATEK |
  635. BTUSB_WIDEBAND_SPEECH },
  636. { USB_DEVICE(0x13d3, 0x3628), .driver_info = BTUSB_MEDIATEK |
  637. BTUSB_WIDEBAND_SPEECH },
  638. { USB_DEVICE(0x13d3, 0x3630), .driver_info = BTUSB_MEDIATEK |
  639. BTUSB_WIDEBAND_SPEECH },
  640. /* Additional Realtek 8723AE Bluetooth devices */
  641. { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK },
  642. { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK },
  643. /* Additional Realtek 8723BE Bluetooth devices */
  644. { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK },
  645. { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK },
  646. { USB_DEVICE(0x04f2, 0xb49f), .driver_info = BTUSB_REALTEK },
  647. { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK },
  648. { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK },
  649. { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK },
  650. { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK },
  651. /* Additional Realtek 8723BU Bluetooth devices */
  652. { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK },
  653. /* Additional Realtek 8723DE Bluetooth devices */
  654. { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK },
  655. { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK },
  656. /* Additional Realtek 8761BUV Bluetooth devices */
  657. { USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK |
  658. BTUSB_WIDEBAND_SPEECH },
  659. { USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK |
  660. BTUSB_WIDEBAND_SPEECH },
  661. { USB_DEVICE(0x2550, 0x8761), .driver_info = BTUSB_REALTEK |
  662. BTUSB_WIDEBAND_SPEECH },
  663. { USB_DEVICE(0x0bda, 0x8771), .driver_info = BTUSB_REALTEK |
  664. BTUSB_WIDEBAND_SPEECH },
  665. { USB_DEVICE(0x6655, 0x8771), .driver_info = BTUSB_REALTEK |
  666. BTUSB_WIDEBAND_SPEECH },
  667. { USB_DEVICE(0x7392, 0xc611), .driver_info = BTUSB_REALTEK |
  668. BTUSB_WIDEBAND_SPEECH },
  669. { USB_DEVICE(0x2b89, 0x8761), .driver_info = BTUSB_REALTEK |
  670. BTUSB_WIDEBAND_SPEECH },
  671. /* Additional Realtek 8821AE Bluetooth devices */
  672. { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK },
  673. { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK },
  674. { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK },
  675. { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK },
  676. { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK },
  677. /* Additional Realtek 8822BE Bluetooth devices */
  678. { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK },
  679. { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK },
  680. /* Additional Realtek 8822CE Bluetooth devices */
  681. { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK |
  682. BTUSB_WIDEBAND_SPEECH },
  683. { USB_DEVICE(0x04c5, 0x161f), .driver_info = BTUSB_REALTEK |
  684. BTUSB_WIDEBAND_SPEECH },
  685. { USB_DEVICE(0x0b05, 0x18ef), .driver_info = BTUSB_REALTEK |
  686. BTUSB_WIDEBAND_SPEECH },
  687. { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK |
  688. BTUSB_WIDEBAND_SPEECH },
  689. { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK |
  690. BTUSB_WIDEBAND_SPEECH },
  691. { USB_DEVICE(0x13d3, 0x3553), .driver_info = BTUSB_REALTEK |
  692. BTUSB_WIDEBAND_SPEECH },
  693. { USB_DEVICE(0x13d3, 0x3555), .driver_info = BTUSB_REALTEK |
  694. BTUSB_WIDEBAND_SPEECH },
  695. { USB_DEVICE(0x2ff8, 0x3051), .driver_info = BTUSB_REALTEK |
  696. BTUSB_WIDEBAND_SPEECH },
  697. { USB_DEVICE(0x1358, 0xc123), .driver_info = BTUSB_REALTEK |
  698. BTUSB_WIDEBAND_SPEECH },
  699. { USB_DEVICE(0x0bda, 0xc123), .driver_info = BTUSB_REALTEK |
  700. BTUSB_WIDEBAND_SPEECH },
  701. { USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK |
  702. BTUSB_WIDEBAND_SPEECH },
  703. /* Actions Semiconductor ATS2851 based devices */
  704. { USB_DEVICE(0x10d7, 0xb012), .driver_info = BTUSB_ACTIONS_SEMI },
  705. /* Silicon Wave based devices */
  706. { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE },
  707. { } /* Terminating entry */
  708. };
  709. /* The Bluetooth USB module build into some devices needs to be reset on resume,
  710. * this is a problem with the platform (likely shutting off all power) not with
  711. * the module itself. So we use a DMI list to match known broken platforms.
  712. */
  713. static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
  714. {
  715. /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */
  716. .matches = {
  717. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  718. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"),
  719. },
  720. },
  721. {
  722. /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */
  723. .matches = {
  724. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  725. DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"),
  726. },
  727. },
  728. {
  729. /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */
  730. .matches = {
  731. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  732. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"),
  733. },
  734. },
  735. {}
  736. };
  737. struct qca_dump_info {
  738. /* fields for dump collection */
  739. u16 id_vendor;
  740. u16 id_product;
  741. u32 fw_version;
  742. u32 controller_id;
  743. u32 ram_dump_size;
  744. u16 ram_dump_seqno;
  745. };
  746. #define BTUSB_MAX_ISOC_FRAMES 10
  747. #define BTUSB_INTR_RUNNING 0
  748. #define BTUSB_BULK_RUNNING 1
  749. #define BTUSB_ISOC_RUNNING 2
  750. #define BTUSB_SUSPENDING 3
  751. #define BTUSB_DID_ISO_RESUME 4
  752. #define BTUSB_BOOTLOADER 5
  753. #define BTUSB_DOWNLOADING 6
  754. #define BTUSB_FIRMWARE_LOADED 7
  755. #define BTUSB_FIRMWARE_FAILED 8
  756. #define BTUSB_BOOTING 9
  757. #define BTUSB_DIAG_RUNNING 10
  758. #define BTUSB_OOB_WAKE_ENABLED 11
  759. #define BTUSB_HW_RESET_ACTIVE 12
  760. #define BTUSB_TX_WAIT_VND_EVT 13
  761. #define BTUSB_WAKEUP_AUTOSUSPEND 14
  762. #define BTUSB_USE_ALT3_FOR_WBS 15
  763. #define BTUSB_ALT6_CONTINUOUS_TX 16
  764. #define BTUSB_HW_SSR_ACTIVE 17
  765. struct btusb_data {
  766. struct hci_dev *hdev;
  767. struct usb_device *udev;
  768. struct usb_interface *intf;
  769. struct usb_interface *isoc;
  770. struct usb_interface *diag;
  771. unsigned isoc_ifnum;
  772. unsigned long flags;
  773. bool poll_sync;
  774. int intr_interval;
  775. struct work_struct work;
  776. struct work_struct waker;
  777. struct delayed_work rx_work;
  778. struct sk_buff_head acl_q;
  779. struct usb_anchor deferred;
  780. struct usb_anchor tx_anchor;
  781. int tx_in_flight;
  782. spinlock_t txlock;
  783. struct usb_anchor intr_anchor;
  784. struct usb_anchor bulk_anchor;
  785. struct usb_anchor isoc_anchor;
  786. struct usb_anchor diag_anchor;
  787. struct usb_anchor ctrl_anchor;
  788. spinlock_t rxlock;
  789. struct sk_buff *evt_skb;
  790. struct sk_buff *acl_skb;
  791. struct sk_buff *sco_skb;
  792. struct usb_endpoint_descriptor *intr_ep;
  793. struct usb_endpoint_descriptor *bulk_tx_ep;
  794. struct usb_endpoint_descriptor *bulk_rx_ep;
  795. struct usb_endpoint_descriptor *isoc_tx_ep;
  796. struct usb_endpoint_descriptor *isoc_rx_ep;
  797. struct usb_endpoint_descriptor *diag_tx_ep;
  798. struct usb_endpoint_descriptor *diag_rx_ep;
  799. struct gpio_desc *reset_gpio;
  800. __u8 cmdreq_type;
  801. __u8 cmdreq;
  802. unsigned int sco_num;
  803. unsigned int air_mode;
  804. bool usb_alt6_packet_flow;
  805. int isoc_altsetting;
  806. int suspend_count;
  807. int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
  808. int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb);
  809. int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
  810. int (*setup_on_usb)(struct hci_dev *hdev);
  811. int (*suspend)(struct hci_dev *hdev);
  812. int (*resume)(struct hci_dev *hdev);
  813. int (*disconnect)(struct hci_dev *hdev);
  814. int oob_wake_irq; /* irq for out-of-band wake-on-bt */
  815. unsigned cmd_timeout_cnt;
  816. struct qca_dump_info qca_dump;
  817. };
  818. static void btusb_reset(struct hci_dev *hdev)
  819. {
  820. struct btusb_data *data;
  821. int err;
  822. if (hdev->reset) {
  823. hdev->reset(hdev);
  824. return;
  825. }
  826. data = hci_get_drvdata(hdev);
  827. /* This is not an unbalanced PM reference since the device will reset */
  828. err = usb_autopm_get_interface(data->intf);
  829. if (err) {
  830. bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err);
  831. return;
  832. }
  833. bt_dev_err(hdev, "Resetting usb device.");
  834. usb_queue_reset_device(data->intf);
  835. }
  836. static void btusb_intel_cmd_timeout(struct hci_dev *hdev)
  837. {
  838. struct btusb_data *data = hci_get_drvdata(hdev);
  839. struct gpio_desc *reset_gpio = data->reset_gpio;
  840. struct btintel_data *intel_data = hci_get_priv(hdev);
  841. if (++data->cmd_timeout_cnt < 5)
  842. return;
  843. if (intel_data->acpi_reset_method) {
  844. if (test_and_set_bit(INTEL_ACPI_RESET_ACTIVE, intel_data->flags)) {
  845. bt_dev_err(hdev, "acpi: last reset failed ? Not resetting again");
  846. return;
  847. }
  848. bt_dev_err(hdev, "Initiating acpi reset method");
  849. /* If ACPI reset method fails, lets try with legacy GPIO
  850. * toggling
  851. */
  852. if (!intel_data->acpi_reset_method(hdev)) {
  853. return;
  854. }
  855. }
  856. if (!reset_gpio) {
  857. btusb_reset(hdev);
  858. return;
  859. }
  860. /*
  861. * Toggle the hard reset line if the platform provides one. The reset
  862. * is going to yank the device off the USB and then replug. So doing
  863. * once is enough. The cleanup is handled correctly on the way out
  864. * (standard USB disconnect), and the new device is detected cleanly
  865. * and bound to the driver again like it should be.
  866. */
  867. if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
  868. bt_dev_err(hdev, "last reset failed? Not resetting again");
  869. return;
  870. }
  871. bt_dev_err(hdev, "Initiating HW reset via gpio");
  872. gpiod_set_value_cansleep(reset_gpio, 1);
  873. msleep(100);
  874. gpiod_set_value_cansleep(reset_gpio, 0);
  875. }
  876. #define RTK_DEVCOREDUMP_CODE_MEMDUMP 0x01
  877. #define RTK_DEVCOREDUMP_CODE_HW_ERR 0x02
  878. #define RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT 0x03
  879. #define RTK_SUB_EVENT_CODE_COREDUMP 0x34
  880. struct rtk_dev_coredump_hdr {
  881. u8 type;
  882. u8 code;
  883. u8 reserved[2];
  884. } __packed;
  885. static inline void btusb_rtl_alloc_devcoredump(struct hci_dev *hdev,
  886. struct rtk_dev_coredump_hdr *hdr, u8 *buf, u32 len)
  887. {
  888. struct sk_buff *skb;
  889. skb = alloc_skb(len + sizeof(*hdr), GFP_ATOMIC);
  890. if (!skb)
  891. return;
  892. skb_put_data(skb, hdr, sizeof(*hdr));
  893. if (len)
  894. skb_put_data(skb, buf, len);
  895. if (!hci_devcd_init(hdev, skb->len)) {
  896. hci_devcd_append(hdev, skb);
  897. hci_devcd_complete(hdev);
  898. } else {
  899. bt_dev_err(hdev, "RTL: Failed to generate devcoredump");
  900. kfree_skb(skb);
  901. }
  902. }
  903. static void btusb_rtl_cmd_timeout(struct hci_dev *hdev)
  904. {
  905. struct btusb_data *data = hci_get_drvdata(hdev);
  906. struct gpio_desc *reset_gpio = data->reset_gpio;
  907. struct rtk_dev_coredump_hdr hdr = {
  908. .type = RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT,
  909. };
  910. btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0);
  911. if (++data->cmd_timeout_cnt < 5)
  912. return;
  913. if (!reset_gpio) {
  914. btusb_reset(hdev);
  915. return;
  916. }
  917. /* Toggle the hard reset line. The Realtek device is going to
  918. * yank itself off the USB and then replug. The cleanup is handled
  919. * correctly on the way out (standard USB disconnect), and the new
  920. * device is detected cleanly and bound to the driver again like
  921. * it should be.
  922. */
  923. if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
  924. bt_dev_err(hdev, "last reset failed? Not resetting again");
  925. return;
  926. }
  927. bt_dev_err(hdev, "Reset Realtek device via gpio");
  928. gpiod_set_value_cansleep(reset_gpio, 1);
  929. msleep(200);
  930. gpiod_set_value_cansleep(reset_gpio, 0);
  931. }
  932. static void btusb_rtl_hw_error(struct hci_dev *hdev, u8 code)
  933. {
  934. struct rtk_dev_coredump_hdr hdr = {
  935. .type = RTK_DEVCOREDUMP_CODE_HW_ERR,
  936. .code = code,
  937. };
  938. bt_dev_err(hdev, "RTL: hw err, trigger devcoredump (%d)", code);
  939. btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0);
  940. }
  941. static void btusb_qca_cmd_timeout(struct hci_dev *hdev)
  942. {
  943. struct btusb_data *data = hci_get_drvdata(hdev);
  944. struct gpio_desc *reset_gpio = data->reset_gpio;
  945. if (test_bit(BTUSB_HW_SSR_ACTIVE, &data->flags)) {
  946. bt_dev_info(hdev, "Ramdump in progress, defer cmd_timeout");
  947. return;
  948. }
  949. if (++data->cmd_timeout_cnt < 5)
  950. return;
  951. if (reset_gpio) {
  952. bt_dev_err(hdev, "Reset qca device via bt_en gpio");
  953. /* Toggle the hard reset line. The qca bt device is going to
  954. * yank itself off the USB and then replug. The cleanup is handled
  955. * correctly on the way out (standard USB disconnect), and the new
  956. * device is detected cleanly and bound to the driver again like
  957. * it should be.
  958. */
  959. if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
  960. bt_dev_err(hdev, "last reset failed? Not resetting again");
  961. return;
  962. }
  963. gpiod_set_value_cansleep(reset_gpio, 0);
  964. msleep(200);
  965. gpiod_set_value_cansleep(reset_gpio, 1);
  966. return;
  967. }
  968. btusb_reset(hdev);
  969. }
  970. static inline void btusb_free_frags(struct btusb_data *data)
  971. {
  972. unsigned long flags;
  973. spin_lock_irqsave(&data->rxlock, flags);
  974. dev_kfree_skb_irq(data->evt_skb);
  975. data->evt_skb = NULL;
  976. dev_kfree_skb_irq(data->acl_skb);
  977. data->acl_skb = NULL;
  978. dev_kfree_skb_irq(data->sco_skb);
  979. data->sco_skb = NULL;
  980. spin_unlock_irqrestore(&data->rxlock, flags);
  981. }
  982. static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
  983. {
  984. if (data->intr_interval) {
  985. /* Trigger dequeue immediatelly if an event is received */
  986. schedule_delayed_work(&data->rx_work, 0);
  987. }
  988. return data->recv_event(data->hdev, skb);
  989. }
  990. static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
  991. {
  992. struct sk_buff *skb;
  993. unsigned long flags;
  994. int err = 0;
  995. spin_lock_irqsave(&data->rxlock, flags);
  996. skb = data->evt_skb;
  997. while (count) {
  998. int len;
  999. if (!skb) {
  1000. skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC);
  1001. if (!skb) {
  1002. err = -ENOMEM;
  1003. break;
  1004. }
  1005. hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
  1006. hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE;
  1007. }
  1008. len = min_t(uint, hci_skb_expect(skb), count);
  1009. skb_put_data(skb, buffer, len);
  1010. count -= len;
  1011. buffer += len;
  1012. hci_skb_expect(skb) -= len;
  1013. if (skb->len == HCI_EVENT_HDR_SIZE) {
  1014. /* Complete event header */
  1015. hci_skb_expect(skb) = hci_event_hdr(skb)->plen;
  1016. if (skb_tailroom(skb) < hci_skb_expect(skb)) {
  1017. kfree_skb(skb);
  1018. skb = NULL;
  1019. err = -EILSEQ;
  1020. break;
  1021. }
  1022. }
  1023. if (!hci_skb_expect(skb)) {
  1024. /* Complete frame */
  1025. btusb_recv_event(data, skb);
  1026. skb = NULL;
  1027. }
  1028. }
  1029. data->evt_skb = skb;
  1030. spin_unlock_irqrestore(&data->rxlock, flags);
  1031. return err;
  1032. }
  1033. static int btusb_recv_acl(struct btusb_data *data, struct sk_buff *skb)
  1034. {
  1035. /* Only queue ACL packet if intr_interval is set as it means
  1036. * force_poll_sync has been enabled.
  1037. */
  1038. if (!data->intr_interval)
  1039. return data->recv_acl(data->hdev, skb);
  1040. skb_queue_tail(&data->acl_q, skb);
  1041. schedule_delayed_work(&data->rx_work, data->intr_interval);
  1042. return 0;
  1043. }
  1044. static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
  1045. {
  1046. struct sk_buff *skb;
  1047. unsigned long flags;
  1048. int err = 0;
  1049. spin_lock_irqsave(&data->rxlock, flags);
  1050. skb = data->acl_skb;
  1051. while (count) {
  1052. int len;
  1053. if (!skb) {
  1054. skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
  1055. if (!skb) {
  1056. err = -ENOMEM;
  1057. break;
  1058. }
  1059. hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT;
  1060. hci_skb_expect(skb) = HCI_ACL_HDR_SIZE;
  1061. }
  1062. len = min_t(uint, hci_skb_expect(skb), count);
  1063. skb_put_data(skb, buffer, len);
  1064. count -= len;
  1065. buffer += len;
  1066. hci_skb_expect(skb) -= len;
  1067. if (skb->len == HCI_ACL_HDR_SIZE) {
  1068. __le16 dlen = hci_acl_hdr(skb)->dlen;
  1069. /* Complete ACL header */
  1070. hci_skb_expect(skb) = __le16_to_cpu(dlen);
  1071. if (skb_tailroom(skb) < hci_skb_expect(skb)) {
  1072. kfree_skb(skb);
  1073. skb = NULL;
  1074. err = -EILSEQ;
  1075. break;
  1076. }
  1077. }
  1078. if (!hci_skb_expect(skb)) {
  1079. /* Complete frame */
  1080. btusb_recv_acl(data, skb);
  1081. skb = NULL;
  1082. }
  1083. }
  1084. data->acl_skb = skb;
  1085. spin_unlock_irqrestore(&data->rxlock, flags);
  1086. return err;
  1087. }
  1088. static bool btusb_validate_sco_handle(struct hci_dev *hdev,
  1089. struct hci_sco_hdr *hdr)
  1090. {
  1091. __u16 handle;
  1092. if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL))
  1093. // Can't validate, userspace controls everything.
  1094. return true;
  1095. /*
  1096. * USB isochronous transfers are not designed to be reliable and may
  1097. * lose fragments. When this happens, the next first fragment
  1098. * encountered might actually be a continuation fragment.
  1099. * Validate the handle to detect it and drop it, or else the upper
  1100. * layer will get garbage for a while.
  1101. */
  1102. handle = hci_handle(__le16_to_cpu(hdr->handle));
  1103. switch (hci_conn_lookup_type(hdev, handle)) {
  1104. case SCO_LINK:
  1105. case ESCO_LINK:
  1106. return true;
  1107. default:
  1108. return false;
  1109. }
  1110. }
  1111. static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count)
  1112. {
  1113. struct sk_buff *skb;
  1114. unsigned long flags;
  1115. int err = 0;
  1116. spin_lock_irqsave(&data->rxlock, flags);
  1117. skb = data->sco_skb;
  1118. while (count) {
  1119. int len;
  1120. if (!skb) {
  1121. skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC);
  1122. if (!skb) {
  1123. err = -ENOMEM;
  1124. break;
  1125. }
  1126. hci_skb_pkt_type(skb) = HCI_SCODATA_PKT;
  1127. hci_skb_expect(skb) = HCI_SCO_HDR_SIZE;
  1128. }
  1129. len = min_t(uint, hci_skb_expect(skb), count);
  1130. skb_put_data(skb, buffer, len);
  1131. count -= len;
  1132. buffer += len;
  1133. hci_skb_expect(skb) -= len;
  1134. if (skb->len == HCI_SCO_HDR_SIZE) {
  1135. /* Complete SCO header */
  1136. struct hci_sco_hdr *hdr = hci_sco_hdr(skb);
  1137. hci_skb_expect(skb) = hdr->dlen;
  1138. if (skb_tailroom(skb) < hci_skb_expect(skb) ||
  1139. !btusb_validate_sco_handle(data->hdev, hdr)) {
  1140. kfree_skb(skb);
  1141. skb = NULL;
  1142. err = -EILSEQ;
  1143. break;
  1144. }
  1145. }
  1146. if (!hci_skb_expect(skb)) {
  1147. /* Complete frame */
  1148. hci_recv_frame(data->hdev, skb);
  1149. skb = NULL;
  1150. }
  1151. }
  1152. data->sco_skb = skb;
  1153. spin_unlock_irqrestore(&data->rxlock, flags);
  1154. return err;
  1155. }
  1156. static void btusb_intr_complete(struct urb *urb)
  1157. {
  1158. struct hci_dev *hdev = urb->context;
  1159. struct btusb_data *data = hci_get_drvdata(hdev);
  1160. int err;
  1161. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  1162. urb->actual_length);
  1163. if (!test_bit(HCI_RUNNING, &hdev->flags))
  1164. return;
  1165. if (urb->status == 0) {
  1166. hdev->stat.byte_rx += urb->actual_length;
  1167. if (btusb_recv_intr(data, urb->transfer_buffer,
  1168. urb->actual_length) < 0) {
  1169. bt_dev_err(hdev, "corrupted event packet");
  1170. hdev->stat.err_rx++;
  1171. }
  1172. } else if (urb->status == -ENOENT) {
  1173. /* Avoid suspend failed when usb_kill_urb */
  1174. return;
  1175. }
  1176. if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
  1177. return;
  1178. usb_mark_last_busy(data->udev);
  1179. usb_anchor_urb(urb, &data->intr_anchor);
  1180. err = usb_submit_urb(urb, GFP_ATOMIC);
  1181. if (err < 0) {
  1182. /* -EPERM: urb is being killed;
  1183. * -ENODEV: device got disconnected
  1184. */
  1185. if (err != -EPERM && err != -ENODEV)
  1186. bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
  1187. urb, -err);
  1188. if (err != -EPERM)
  1189. hci_cmd_sync_cancel(hdev, -err);
  1190. usb_unanchor_urb(urb);
  1191. }
  1192. }
  1193. static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
  1194. {
  1195. struct btusb_data *data = hci_get_drvdata(hdev);
  1196. struct urb *urb;
  1197. unsigned char *buf;
  1198. unsigned int pipe;
  1199. int err, size;
  1200. BT_DBG("%s", hdev->name);
  1201. if (!data->intr_ep)
  1202. return -ENODEV;
  1203. urb = usb_alloc_urb(0, mem_flags);
  1204. if (!urb)
  1205. return -ENOMEM;
  1206. if (le16_to_cpu(data->udev->descriptor.idVendor) == 0x0a12 &&
  1207. le16_to_cpu(data->udev->descriptor.idProduct) == 0x0001)
  1208. /* Fake CSR devices don't seem to support sort-transter */
  1209. size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
  1210. else
  1211. /* Use maximum HCI Event size so the USB stack handles
  1212. * ZPL/short-transfer automatically.
  1213. */
  1214. size = HCI_MAX_EVENT_SIZE;
  1215. buf = kmalloc(size, mem_flags);
  1216. if (!buf) {
  1217. usb_free_urb(urb);
  1218. return -ENOMEM;
  1219. }
  1220. pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
  1221. usb_fill_int_urb(urb, data->udev, pipe, buf, size,
  1222. btusb_intr_complete, hdev, data->intr_ep->bInterval);
  1223. urb->transfer_flags |= URB_FREE_BUFFER;
  1224. usb_anchor_urb(urb, &data->intr_anchor);
  1225. err = usb_submit_urb(urb, mem_flags);
  1226. if (err < 0) {
  1227. if (err != -EPERM && err != -ENODEV)
  1228. bt_dev_err(hdev, "urb %p submission failed (%d)",
  1229. urb, -err);
  1230. if (err != -EPERM)
  1231. hci_cmd_sync_cancel(hdev, -err);
  1232. usb_unanchor_urb(urb);
  1233. }
  1234. /* Only initialize intr_interval if URB poll sync is enabled */
  1235. if (!data->poll_sync)
  1236. goto done;
  1237. /* The units are frames (milliseconds) for full and low speed devices,
  1238. * and microframes (1/8 millisecond) for highspeed and SuperSpeed
  1239. * devices.
  1240. *
  1241. * This is done once on open/resume so it shouldn't change even if
  1242. * force_poll_sync changes.
  1243. */
  1244. switch (urb->dev->speed) {
  1245. case USB_SPEED_SUPER_PLUS:
  1246. case USB_SPEED_SUPER: /* units are 125us */
  1247. data->intr_interval = usecs_to_jiffies(urb->interval * 125);
  1248. break;
  1249. default:
  1250. data->intr_interval = msecs_to_jiffies(urb->interval);
  1251. break;
  1252. }
  1253. done:
  1254. usb_free_urb(urb);
  1255. return err;
  1256. }
  1257. static void btusb_bulk_complete(struct urb *urb)
  1258. {
  1259. struct hci_dev *hdev = urb->context;
  1260. struct btusb_data *data = hci_get_drvdata(hdev);
  1261. int err;
  1262. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  1263. urb->actual_length);
  1264. if (!test_bit(HCI_RUNNING, &hdev->flags))
  1265. return;
  1266. if (urb->status == 0) {
  1267. hdev->stat.byte_rx += urb->actual_length;
  1268. if (data->recv_bulk(data, urb->transfer_buffer,
  1269. urb->actual_length) < 0) {
  1270. bt_dev_err(hdev, "corrupted ACL packet");
  1271. hdev->stat.err_rx++;
  1272. }
  1273. } else if (urb->status == -ENOENT) {
  1274. /* Avoid suspend failed when usb_kill_urb */
  1275. return;
  1276. }
  1277. if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
  1278. return;
  1279. usb_anchor_urb(urb, &data->bulk_anchor);
  1280. usb_mark_last_busy(data->udev);
  1281. err = usb_submit_urb(urb, GFP_ATOMIC);
  1282. if (err < 0) {
  1283. /* -EPERM: urb is being killed;
  1284. * -ENODEV: device got disconnected
  1285. */
  1286. if (err != -EPERM && err != -ENODEV)
  1287. bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
  1288. urb, -err);
  1289. usb_unanchor_urb(urb);
  1290. }
  1291. }
  1292. static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
  1293. {
  1294. struct btusb_data *data = hci_get_drvdata(hdev);
  1295. struct urb *urb;
  1296. unsigned char *buf;
  1297. unsigned int pipe;
  1298. int err, size = HCI_MAX_FRAME_SIZE;
  1299. BT_DBG("%s", hdev->name);
  1300. if (!data->bulk_rx_ep)
  1301. return -ENODEV;
  1302. urb = usb_alloc_urb(0, mem_flags);
  1303. if (!urb)
  1304. return -ENOMEM;
  1305. buf = kmalloc(size, mem_flags);
  1306. if (!buf) {
  1307. usb_free_urb(urb);
  1308. return -ENOMEM;
  1309. }
  1310. pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
  1311. usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
  1312. btusb_bulk_complete, hdev);
  1313. urb->transfer_flags |= URB_FREE_BUFFER;
  1314. usb_mark_last_busy(data->udev);
  1315. usb_anchor_urb(urb, &data->bulk_anchor);
  1316. err = usb_submit_urb(urb, mem_flags);
  1317. if (err < 0) {
  1318. if (err != -EPERM && err != -ENODEV)
  1319. bt_dev_err(hdev, "urb %p submission failed (%d)",
  1320. urb, -err);
  1321. usb_unanchor_urb(urb);
  1322. }
  1323. usb_free_urb(urb);
  1324. return err;
  1325. }
  1326. static void btusb_isoc_complete(struct urb *urb)
  1327. {
  1328. struct hci_dev *hdev = urb->context;
  1329. struct btusb_data *data = hci_get_drvdata(hdev);
  1330. int i, err;
  1331. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  1332. urb->actual_length);
  1333. if (!test_bit(HCI_RUNNING, &hdev->flags))
  1334. return;
  1335. if (urb->status == 0) {
  1336. for (i = 0; i < urb->number_of_packets; i++) {
  1337. unsigned int offset = urb->iso_frame_desc[i].offset;
  1338. unsigned int length = urb->iso_frame_desc[i].actual_length;
  1339. if (urb->iso_frame_desc[i].status)
  1340. continue;
  1341. hdev->stat.byte_rx += length;
  1342. if (btusb_recv_isoc(data, urb->transfer_buffer + offset,
  1343. length) < 0) {
  1344. bt_dev_err(hdev, "corrupted SCO packet");
  1345. hdev->stat.err_rx++;
  1346. }
  1347. }
  1348. } else if (urb->status == -ENOENT) {
  1349. /* Avoid suspend failed when usb_kill_urb */
  1350. return;
  1351. }
  1352. if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
  1353. return;
  1354. usb_anchor_urb(urb, &data->isoc_anchor);
  1355. err = usb_submit_urb(urb, GFP_ATOMIC);
  1356. if (err < 0) {
  1357. /* -EPERM: urb is being killed;
  1358. * -ENODEV: device got disconnected
  1359. */
  1360. if (err != -EPERM && err != -ENODEV)
  1361. bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
  1362. urb, -err);
  1363. usb_unanchor_urb(urb);
  1364. }
  1365. }
  1366. static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len,
  1367. int mtu, struct btusb_data *data)
  1368. {
  1369. int i = 0, offset = 0;
  1370. unsigned int interval;
  1371. BT_DBG("len %d mtu %d", len, mtu);
  1372. /* For mSBC ALT 6 settings some chips need to transmit the data
  1373. * continuously without the zero length of USB packets.
  1374. */
  1375. if (test_bit(BTUSB_ALT6_CONTINUOUS_TX, &data->flags))
  1376. goto ignore_usb_alt6_packet_flow;
  1377. /* For mSBC ALT 6 setting the host will send the packet at continuous
  1378. * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting
  1379. * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets.
  1380. * To maintain the rate we send 63bytes of usb packets alternatively for
  1381. * 7ms and 8ms to maintain the rate as 7.5ms.
  1382. */
  1383. if (data->usb_alt6_packet_flow) {
  1384. interval = 7;
  1385. data->usb_alt6_packet_flow = false;
  1386. } else {
  1387. interval = 6;
  1388. data->usb_alt6_packet_flow = true;
  1389. }
  1390. for (i = 0; i < interval; i++) {
  1391. urb->iso_frame_desc[i].offset = offset;
  1392. urb->iso_frame_desc[i].length = offset;
  1393. }
  1394. ignore_usb_alt6_packet_flow:
  1395. if (len && i < BTUSB_MAX_ISOC_FRAMES) {
  1396. urb->iso_frame_desc[i].offset = offset;
  1397. urb->iso_frame_desc[i].length = len;
  1398. i++;
  1399. }
  1400. urb->number_of_packets = i;
  1401. }
  1402. static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
  1403. {
  1404. int i, offset = 0;
  1405. BT_DBG("len %d mtu %d", len, mtu);
  1406. for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
  1407. i++, offset += mtu, len -= mtu) {
  1408. urb->iso_frame_desc[i].offset = offset;
  1409. urb->iso_frame_desc[i].length = mtu;
  1410. }
  1411. if (len && i < BTUSB_MAX_ISOC_FRAMES) {
  1412. urb->iso_frame_desc[i].offset = offset;
  1413. urb->iso_frame_desc[i].length = len;
  1414. i++;
  1415. }
  1416. urb->number_of_packets = i;
  1417. }
  1418. static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
  1419. {
  1420. struct btusb_data *data = hci_get_drvdata(hdev);
  1421. struct urb *urb;
  1422. unsigned char *buf;
  1423. unsigned int pipe;
  1424. int err, size;
  1425. BT_DBG("%s", hdev->name);
  1426. if (!data->isoc_rx_ep)
  1427. return -ENODEV;
  1428. urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
  1429. if (!urb)
  1430. return -ENOMEM;
  1431. size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
  1432. BTUSB_MAX_ISOC_FRAMES;
  1433. buf = kmalloc(size, mem_flags);
  1434. if (!buf) {
  1435. usb_free_urb(urb);
  1436. return -ENOMEM;
  1437. }
  1438. pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
  1439. usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
  1440. hdev, data->isoc_rx_ep->bInterval);
  1441. urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
  1442. __fill_isoc_descriptor(urb, size,
  1443. le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
  1444. usb_anchor_urb(urb, &data->isoc_anchor);
  1445. err = usb_submit_urb(urb, mem_flags);
  1446. if (err < 0) {
  1447. if (err != -EPERM && err != -ENODEV)
  1448. bt_dev_err(hdev, "urb %p submission failed (%d)",
  1449. urb, -err);
  1450. usb_unanchor_urb(urb);
  1451. }
  1452. usb_free_urb(urb);
  1453. return err;
  1454. }
  1455. static void btusb_diag_complete(struct urb *urb)
  1456. {
  1457. struct hci_dev *hdev = urb->context;
  1458. struct btusb_data *data = hci_get_drvdata(hdev);
  1459. int err;
  1460. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  1461. urb->actual_length);
  1462. if (urb->status == 0) {
  1463. struct sk_buff *skb;
  1464. skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC);
  1465. if (skb) {
  1466. skb_put_data(skb, urb->transfer_buffer,
  1467. urb->actual_length);
  1468. hci_recv_diag(hdev, skb);
  1469. }
  1470. } else if (urb->status == -ENOENT) {
  1471. /* Avoid suspend failed when usb_kill_urb */
  1472. return;
  1473. }
  1474. if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags))
  1475. return;
  1476. usb_anchor_urb(urb, &data->diag_anchor);
  1477. usb_mark_last_busy(data->udev);
  1478. err = usb_submit_urb(urb, GFP_ATOMIC);
  1479. if (err < 0) {
  1480. /* -EPERM: urb is being killed;
  1481. * -ENODEV: device got disconnected
  1482. */
  1483. if (err != -EPERM && err != -ENODEV)
  1484. bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
  1485. urb, -err);
  1486. usb_unanchor_urb(urb);
  1487. }
  1488. }
  1489. static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags)
  1490. {
  1491. struct btusb_data *data = hci_get_drvdata(hdev);
  1492. struct urb *urb;
  1493. unsigned char *buf;
  1494. unsigned int pipe;
  1495. int err, size = HCI_MAX_FRAME_SIZE;
  1496. BT_DBG("%s", hdev->name);
  1497. if (!data->diag_rx_ep)
  1498. return -ENODEV;
  1499. urb = usb_alloc_urb(0, mem_flags);
  1500. if (!urb)
  1501. return -ENOMEM;
  1502. buf = kmalloc(size, mem_flags);
  1503. if (!buf) {
  1504. usb_free_urb(urb);
  1505. return -ENOMEM;
  1506. }
  1507. pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress);
  1508. usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
  1509. btusb_diag_complete, hdev);
  1510. urb->transfer_flags |= URB_FREE_BUFFER;
  1511. usb_mark_last_busy(data->udev);
  1512. usb_anchor_urb(urb, &data->diag_anchor);
  1513. err = usb_submit_urb(urb, mem_flags);
  1514. if (err < 0) {
  1515. if (err != -EPERM && err != -ENODEV)
  1516. bt_dev_err(hdev, "urb %p submission failed (%d)",
  1517. urb, -err);
  1518. usb_unanchor_urb(urb);
  1519. }
  1520. usb_free_urb(urb);
  1521. return err;
  1522. }
  1523. static void btusb_tx_complete(struct urb *urb)
  1524. {
  1525. struct sk_buff *skb = urb->context;
  1526. struct hci_dev *hdev = (struct hci_dev *)skb->dev;
  1527. struct btusb_data *data = hci_get_drvdata(hdev);
  1528. unsigned long flags;
  1529. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  1530. urb->actual_length);
  1531. if (!test_bit(HCI_RUNNING, &hdev->flags))
  1532. goto done;
  1533. if (!urb->status) {
  1534. hdev->stat.byte_tx += urb->transfer_buffer_length;
  1535. } else {
  1536. if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT)
  1537. hci_cmd_sync_cancel(hdev, -urb->status);
  1538. hdev->stat.err_tx++;
  1539. }
  1540. done:
  1541. spin_lock_irqsave(&data->txlock, flags);
  1542. data->tx_in_flight--;
  1543. spin_unlock_irqrestore(&data->txlock, flags);
  1544. kfree(urb->setup_packet);
  1545. kfree_skb(skb);
  1546. }
  1547. static void btusb_isoc_tx_complete(struct urb *urb)
  1548. {
  1549. struct sk_buff *skb = urb->context;
  1550. struct hci_dev *hdev = (struct hci_dev *)skb->dev;
  1551. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  1552. urb->actual_length);
  1553. if (!test_bit(HCI_RUNNING, &hdev->flags))
  1554. goto done;
  1555. if (!urb->status)
  1556. hdev->stat.byte_tx += urb->transfer_buffer_length;
  1557. else
  1558. hdev->stat.err_tx++;
  1559. done:
  1560. kfree(urb->setup_packet);
  1561. kfree_skb(skb);
  1562. }
  1563. static int btusb_open(struct hci_dev *hdev)
  1564. {
  1565. struct btusb_data *data = hci_get_drvdata(hdev);
  1566. int err;
  1567. BT_DBG("%s", hdev->name);
  1568. err = usb_autopm_get_interface(data->intf);
  1569. if (err < 0)
  1570. return err;
  1571. /* Patching USB firmware files prior to starting any URBs of HCI path
  1572. * It is more safe to use USB bulk channel for downloading USB patch
  1573. */
  1574. if (data->setup_on_usb) {
  1575. err = data->setup_on_usb(hdev);
  1576. if (err < 0)
  1577. goto setup_fail;
  1578. }
  1579. data->intf->needs_remote_wakeup = 1;
  1580. if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
  1581. goto done;
  1582. err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
  1583. if (err < 0)
  1584. goto failed;
  1585. err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
  1586. if (err < 0) {
  1587. usb_kill_anchored_urbs(&data->intr_anchor);
  1588. goto failed;
  1589. }
  1590. set_bit(BTUSB_BULK_RUNNING, &data->flags);
  1591. btusb_submit_bulk_urb(hdev, GFP_KERNEL);
  1592. if (data->diag) {
  1593. if (!btusb_submit_diag_urb(hdev, GFP_KERNEL))
  1594. set_bit(BTUSB_DIAG_RUNNING, &data->flags);
  1595. }
  1596. done:
  1597. usb_autopm_put_interface(data->intf);
  1598. return 0;
  1599. failed:
  1600. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  1601. setup_fail:
  1602. usb_autopm_put_interface(data->intf);
  1603. return err;
  1604. }
  1605. static void btusb_stop_traffic(struct btusb_data *data)
  1606. {
  1607. usb_kill_anchored_urbs(&data->intr_anchor);
  1608. usb_kill_anchored_urbs(&data->bulk_anchor);
  1609. usb_kill_anchored_urbs(&data->isoc_anchor);
  1610. usb_kill_anchored_urbs(&data->diag_anchor);
  1611. usb_kill_anchored_urbs(&data->ctrl_anchor);
  1612. }
  1613. static int btusb_close(struct hci_dev *hdev)
  1614. {
  1615. struct btusb_data *data = hci_get_drvdata(hdev);
  1616. int err;
  1617. BT_DBG("%s", hdev->name);
  1618. cancel_delayed_work(&data->rx_work);
  1619. cancel_work_sync(&data->work);
  1620. cancel_work_sync(&data->waker);
  1621. skb_queue_purge(&data->acl_q);
  1622. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  1623. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  1624. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  1625. clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
  1626. btusb_stop_traffic(data);
  1627. btusb_free_frags(data);
  1628. err = usb_autopm_get_interface(data->intf);
  1629. if (err < 0)
  1630. goto failed;
  1631. data->intf->needs_remote_wakeup = 0;
  1632. /* Enable remote wake up for auto-suspend */
  1633. if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags))
  1634. data->intf->needs_remote_wakeup = 1;
  1635. usb_autopm_put_interface(data->intf);
  1636. failed:
  1637. usb_scuttle_anchored_urbs(&data->deferred);
  1638. return 0;
  1639. }
  1640. static int btusb_flush(struct hci_dev *hdev)
  1641. {
  1642. struct btusb_data *data = hci_get_drvdata(hdev);
  1643. BT_DBG("%s", hdev->name);
  1644. cancel_delayed_work(&data->rx_work);
  1645. skb_queue_purge(&data->acl_q);
  1646. usb_kill_anchored_urbs(&data->tx_anchor);
  1647. btusb_free_frags(data);
  1648. return 0;
  1649. }
  1650. static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
  1651. {
  1652. struct btusb_data *data = hci_get_drvdata(hdev);
  1653. struct usb_ctrlrequest *dr;
  1654. struct urb *urb;
  1655. unsigned int pipe;
  1656. urb = usb_alloc_urb(0, GFP_KERNEL);
  1657. if (!urb)
  1658. return ERR_PTR(-ENOMEM);
  1659. dr = kmalloc(sizeof(*dr), GFP_KERNEL);
  1660. if (!dr) {
  1661. usb_free_urb(urb);
  1662. return ERR_PTR(-ENOMEM);
  1663. }
  1664. dr->bRequestType = data->cmdreq_type;
  1665. dr->bRequest = data->cmdreq;
  1666. dr->wIndex = 0;
  1667. dr->wValue = 0;
  1668. dr->wLength = __cpu_to_le16(skb->len);
  1669. pipe = usb_sndctrlpipe(data->udev, 0x00);
  1670. usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
  1671. skb->data, skb->len, btusb_tx_complete, skb);
  1672. skb->dev = (void *)hdev;
  1673. return urb;
  1674. }
  1675. static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
  1676. {
  1677. struct btusb_data *data = hci_get_drvdata(hdev);
  1678. struct urb *urb;
  1679. unsigned int pipe;
  1680. if (!data->bulk_tx_ep)
  1681. return ERR_PTR(-ENODEV);
  1682. urb = usb_alloc_urb(0, GFP_KERNEL);
  1683. if (!urb)
  1684. return ERR_PTR(-ENOMEM);
  1685. pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
  1686. usb_fill_bulk_urb(urb, data->udev, pipe,
  1687. skb->data, skb->len, btusb_tx_complete, skb);
  1688. skb->dev = (void *)hdev;
  1689. return urb;
  1690. }
  1691. static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
  1692. {
  1693. struct btusb_data *data = hci_get_drvdata(hdev);
  1694. struct urb *urb;
  1695. unsigned int pipe;
  1696. if (!data->isoc_tx_ep)
  1697. return ERR_PTR(-ENODEV);
  1698. urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
  1699. if (!urb)
  1700. return ERR_PTR(-ENOMEM);
  1701. pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
  1702. usb_fill_int_urb(urb, data->udev, pipe,
  1703. skb->data, skb->len, btusb_isoc_tx_complete,
  1704. skb, data->isoc_tx_ep->bInterval);
  1705. urb->transfer_flags = URB_ISO_ASAP;
  1706. if (data->isoc_altsetting == 6)
  1707. __fill_isoc_descriptor_msbc(urb, skb->len,
  1708. le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize),
  1709. data);
  1710. else
  1711. __fill_isoc_descriptor(urb, skb->len,
  1712. le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
  1713. skb->dev = (void *)hdev;
  1714. return urb;
  1715. }
  1716. static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb)
  1717. {
  1718. struct btusb_data *data = hci_get_drvdata(hdev);
  1719. int err;
  1720. usb_anchor_urb(urb, &data->tx_anchor);
  1721. err = usb_submit_urb(urb, GFP_KERNEL);
  1722. if (err < 0) {
  1723. if (err != -EPERM && err != -ENODEV)
  1724. bt_dev_err(hdev, "urb %p submission failed (%d)",
  1725. urb, -err);
  1726. kfree(urb->setup_packet);
  1727. usb_unanchor_urb(urb);
  1728. } else {
  1729. usb_mark_last_busy(data->udev);
  1730. }
  1731. usb_free_urb(urb);
  1732. return err;
  1733. }
  1734. static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb)
  1735. {
  1736. struct btusb_data *data = hci_get_drvdata(hdev);
  1737. unsigned long flags;
  1738. bool suspending;
  1739. spin_lock_irqsave(&data->txlock, flags);
  1740. suspending = test_bit(BTUSB_SUSPENDING, &data->flags);
  1741. if (!suspending)
  1742. data->tx_in_flight++;
  1743. spin_unlock_irqrestore(&data->txlock, flags);
  1744. if (!suspending)
  1745. return submit_tx_urb(hdev, urb);
  1746. usb_anchor_urb(urb, &data->deferred);
  1747. schedule_work(&data->waker);
  1748. usb_free_urb(urb);
  1749. return 0;
  1750. }
  1751. static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
  1752. {
  1753. struct urb *urb;
  1754. BT_DBG("%s", hdev->name);
  1755. switch (hci_skb_pkt_type(skb)) {
  1756. case HCI_COMMAND_PKT:
  1757. urb = alloc_ctrl_urb(hdev, skb);
  1758. if (IS_ERR(urb))
  1759. return PTR_ERR(urb);
  1760. hdev->stat.cmd_tx++;
  1761. return submit_or_queue_tx_urb(hdev, urb);
  1762. case HCI_ACLDATA_PKT:
  1763. urb = alloc_bulk_urb(hdev, skb);
  1764. if (IS_ERR(urb))
  1765. return PTR_ERR(urb);
  1766. hdev->stat.acl_tx++;
  1767. return submit_or_queue_tx_urb(hdev, urb);
  1768. case HCI_SCODATA_PKT:
  1769. if (hci_conn_num(hdev, SCO_LINK) < 1)
  1770. return -ENODEV;
  1771. urb = alloc_isoc_urb(hdev, skb);
  1772. if (IS_ERR(urb))
  1773. return PTR_ERR(urb);
  1774. hdev->stat.sco_tx++;
  1775. return submit_tx_urb(hdev, urb);
  1776. case HCI_ISODATA_PKT:
  1777. urb = alloc_bulk_urb(hdev, skb);
  1778. if (IS_ERR(urb))
  1779. return PTR_ERR(urb);
  1780. return submit_or_queue_tx_urb(hdev, urb);
  1781. }
  1782. return -EILSEQ;
  1783. }
  1784. static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
  1785. {
  1786. struct btusb_data *data = hci_get_drvdata(hdev);
  1787. BT_DBG("%s evt %d", hdev->name, evt);
  1788. if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) {
  1789. data->sco_num = hci_conn_num(hdev, SCO_LINK);
  1790. data->air_mode = evt;
  1791. schedule_work(&data->work);
  1792. }
  1793. }
  1794. static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
  1795. {
  1796. struct btusb_data *data = hci_get_drvdata(hdev);
  1797. struct usb_interface *intf = data->isoc;
  1798. struct usb_endpoint_descriptor *ep_desc;
  1799. int i, err;
  1800. if (!data->isoc)
  1801. return -ENODEV;
  1802. err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting);
  1803. if (err < 0) {
  1804. bt_dev_err(hdev, "setting interface failed (%d)", -err);
  1805. return err;
  1806. }
  1807. data->isoc_altsetting = altsetting;
  1808. data->isoc_tx_ep = NULL;
  1809. data->isoc_rx_ep = NULL;
  1810. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  1811. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  1812. if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
  1813. data->isoc_tx_ep = ep_desc;
  1814. continue;
  1815. }
  1816. if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
  1817. data->isoc_rx_ep = ep_desc;
  1818. continue;
  1819. }
  1820. }
  1821. if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
  1822. bt_dev_err(hdev, "invalid SCO descriptors");
  1823. return -ENODEV;
  1824. }
  1825. return 0;
  1826. }
  1827. static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts)
  1828. {
  1829. struct btusb_data *data = hci_get_drvdata(hdev);
  1830. int err;
  1831. if (data->isoc_altsetting != new_alts) {
  1832. unsigned long flags;
  1833. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  1834. usb_kill_anchored_urbs(&data->isoc_anchor);
  1835. /* When isochronous alternate setting needs to be
  1836. * changed, because SCO connection has been added
  1837. * or removed, a packet fragment may be left in the
  1838. * reassembling state. This could lead to wrongly
  1839. * assembled fragments.
  1840. *
  1841. * Clear outstanding fragment when selecting a new
  1842. * alternate setting.
  1843. */
  1844. spin_lock_irqsave(&data->rxlock, flags);
  1845. dev_kfree_skb_irq(data->sco_skb);
  1846. data->sco_skb = NULL;
  1847. spin_unlock_irqrestore(&data->rxlock, flags);
  1848. err = __set_isoc_interface(hdev, new_alts);
  1849. if (err < 0)
  1850. return err;
  1851. }
  1852. if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
  1853. if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
  1854. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  1855. else
  1856. btusb_submit_isoc_urb(hdev, GFP_KERNEL);
  1857. }
  1858. return 0;
  1859. }
  1860. static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data,
  1861. int alt)
  1862. {
  1863. struct usb_interface *intf = data->isoc;
  1864. int i;
  1865. BT_DBG("Looking for Alt no :%d", alt);
  1866. if (!intf)
  1867. return NULL;
  1868. for (i = 0; i < intf->num_altsetting; i++) {
  1869. if (intf->altsetting[i].desc.bAlternateSetting == alt)
  1870. return &intf->altsetting[i];
  1871. }
  1872. return NULL;
  1873. }
  1874. static void btusb_work(struct work_struct *work)
  1875. {
  1876. struct btusb_data *data = container_of(work, struct btusb_data, work);
  1877. struct hci_dev *hdev = data->hdev;
  1878. int new_alts = 0;
  1879. int err;
  1880. if (data->sco_num > 0) {
  1881. if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
  1882. err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
  1883. if (err < 0) {
  1884. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  1885. usb_kill_anchored_urbs(&data->isoc_anchor);
  1886. return;
  1887. }
  1888. set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
  1889. }
  1890. if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) {
  1891. if (hdev->voice_setting & 0x0020) {
  1892. static const int alts[3] = { 2, 4, 5 };
  1893. new_alts = alts[data->sco_num - 1];
  1894. } else {
  1895. new_alts = data->sco_num;
  1896. }
  1897. } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) {
  1898. /* Bluetooth USB spec recommends alt 6 (63 bytes), but
  1899. * many adapters do not support it. Alt 1 appears to
  1900. * work for all adapters that do not have alt 6, and
  1901. * which work with WBS at all. Some devices prefer
  1902. * alt 3 (HCI payload >= 60 Bytes let air packet
  1903. * data satisfy 60 bytes), requiring
  1904. * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
  1905. * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
  1906. */
  1907. if (btusb_find_altsetting(data, 6))
  1908. new_alts = 6;
  1909. else if (btusb_find_altsetting(data, 3) &&
  1910. hdev->sco_mtu >= 72 &&
  1911. test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags))
  1912. new_alts = 3;
  1913. else
  1914. new_alts = 1;
  1915. }
  1916. if (btusb_switch_alt_setting(hdev, new_alts) < 0)
  1917. bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts);
  1918. } else {
  1919. usb_kill_anchored_urbs(&data->isoc_anchor);
  1920. if (test_and_clear_bit(BTUSB_ISOC_RUNNING, &data->flags))
  1921. __set_isoc_interface(hdev, 0);
  1922. if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
  1923. usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
  1924. }
  1925. }
  1926. static void btusb_waker(struct work_struct *work)
  1927. {
  1928. struct btusb_data *data = container_of(work, struct btusb_data, waker);
  1929. int err;
  1930. err = usb_autopm_get_interface(data->intf);
  1931. if (err < 0)
  1932. return;
  1933. usb_autopm_put_interface(data->intf);
  1934. }
  1935. static void btusb_rx_work(struct work_struct *work)
  1936. {
  1937. struct btusb_data *data = container_of(work, struct btusb_data,
  1938. rx_work.work);
  1939. struct sk_buff *skb;
  1940. /* Dequeue ACL data received during the interval */
  1941. while ((skb = skb_dequeue(&data->acl_q)))
  1942. data->recv_acl(data->hdev, skb);
  1943. }
  1944. static int btusb_setup_bcm92035(struct hci_dev *hdev)
  1945. {
  1946. struct sk_buff *skb;
  1947. u8 val = 0x00;
  1948. BT_DBG("%s", hdev->name);
  1949. skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT);
  1950. if (IS_ERR(skb))
  1951. bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb));
  1952. else
  1953. kfree_skb(skb);
  1954. return 0;
  1955. }
  1956. static int btusb_setup_csr(struct hci_dev *hdev)
  1957. {
  1958. struct btusb_data *data = hci_get_drvdata(hdev);
  1959. u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice);
  1960. struct hci_rp_read_local_version *rp;
  1961. struct sk_buff *skb;
  1962. bool is_fake = false;
  1963. int ret;
  1964. BT_DBG("%s", hdev->name);
  1965. skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
  1966. HCI_INIT_TIMEOUT);
  1967. if (IS_ERR(skb)) {
  1968. int err = PTR_ERR(skb);
  1969. bt_dev_err(hdev, "CSR: Local version failed (%d)", err);
  1970. return err;
  1971. }
  1972. rp = skb_pull_data(skb, sizeof(*rp));
  1973. if (!rp) {
  1974. bt_dev_err(hdev, "CSR: Local version length mismatch");
  1975. kfree_skb(skb);
  1976. return -EIO;
  1977. }
  1978. bt_dev_info(hdev, "CSR: Setting up dongle with HCI ver=%u rev=%04x",
  1979. rp->hci_ver, le16_to_cpu(rp->hci_rev));
  1980. bt_dev_info(hdev, "LMP ver=%u subver=%04x; manufacturer=%u",
  1981. rp->lmp_ver, le16_to_cpu(rp->lmp_subver),
  1982. le16_to_cpu(rp->manufacturer));
  1983. /* Detect a wide host of Chinese controllers that aren't CSR.
  1984. *
  1985. * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891
  1986. *
  1987. * The main thing they have in common is that these are really popular low-cost
  1988. * options that support newer Bluetooth versions but rely on heavy VID/PID
  1989. * squatting of this poor old Bluetooth 1.1 device. Even sold as such.
  1990. *
  1991. * We detect actual CSR devices by checking that the HCI manufacturer code
  1992. * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and
  1993. * HCI rev values always match. As they both store the firmware number.
  1994. */
  1995. if (le16_to_cpu(rp->manufacturer) != 10 ||
  1996. le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver))
  1997. is_fake = true;
  1998. /* Known legit CSR firmware build numbers and their supported BT versions:
  1999. * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e
  2000. * - 1.2 (0x2) -> 0x04d9, 0x0529
  2001. * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c
  2002. * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External)
  2003. * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb
  2004. *
  2005. * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that
  2006. * support BT 1.1 only; so it's a dead giveaway when some
  2007. * third-party BT 4.0 dongle reuses it.
  2008. */
  2009. else if (le16_to_cpu(rp->lmp_subver) <= 0x034e &&
  2010. rp->hci_ver > BLUETOOTH_VER_1_1)
  2011. is_fake = true;
  2012. else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 &&
  2013. rp->hci_ver > BLUETOOTH_VER_1_2)
  2014. is_fake = true;
  2015. else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c &&
  2016. rp->hci_ver > BLUETOOTH_VER_2_0)
  2017. is_fake = true;
  2018. else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 &&
  2019. rp->hci_ver > BLUETOOTH_VER_2_1)
  2020. is_fake = true;
  2021. else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb &&
  2022. rp->hci_ver > BLUETOOTH_VER_4_0)
  2023. is_fake = true;
  2024. /* Other clones which beat all the above checks */
  2025. else if (bcdDevice == 0x0134 &&
  2026. le16_to_cpu(rp->lmp_subver) == 0x0c5c &&
  2027. rp->hci_ver == BLUETOOTH_VER_2_0)
  2028. is_fake = true;
  2029. if (is_fake) {
  2030. bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once...");
  2031. /* Generally these clones have big discrepancies between
  2032. * advertised features and what's actually supported.
  2033. * Probably will need to be expanded in the future;
  2034. * without these the controller will lock up.
  2035. */
  2036. set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
  2037. set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
  2038. set_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks);
  2039. set_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks);
  2040. /* Clear the reset quirk since this is not an actual
  2041. * early Bluetooth 1.1 device from CSR.
  2042. */
  2043. clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  2044. clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
  2045. /*
  2046. * Special workaround for these BT 4.0 chip clones, and potentially more:
  2047. *
  2048. * - 0x0134: a Barrot 8041a02 (HCI rev: 0x0810 sub: 0x1012)
  2049. * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709)
  2050. *
  2051. * These controllers are really messed-up.
  2052. *
  2053. * 1. Their bulk RX endpoint will never report any data unless
  2054. * the device was suspended at least once (yes, really).
  2055. * 2. They will not wakeup when autosuspended and receiving data
  2056. * on their bulk RX endpoint from e.g. a keyboard or mouse
  2057. * (IOW remote-wakeup support is broken for the bulk endpoint).
  2058. *
  2059. * To fix 1. enable runtime-suspend, force-suspend the
  2060. * HCI and then wake-it up by disabling runtime-suspend.
  2061. *
  2062. * To fix 2. clear the HCI's can_wake flag, this way the HCI
  2063. * will still be autosuspended when it is not open.
  2064. *
  2065. * --
  2066. *
  2067. * Because these are widespread problems we prefer generic solutions; so
  2068. * apply this initialization quirk to every controller that gets here,
  2069. * it should be harmless. The alternative is to not work at all.
  2070. */
  2071. pm_runtime_allow(&data->udev->dev);
  2072. ret = pm_runtime_suspend(&data->udev->dev);
  2073. if (ret >= 0)
  2074. msleep(200);
  2075. else
  2076. bt_dev_warn(hdev, "CSR: Couldn't suspend the device for our Barrot 8041a02 receive-issue workaround");
  2077. pm_runtime_forbid(&data->udev->dev);
  2078. device_set_wakeup_capable(&data->udev->dev, false);
  2079. /* Re-enable autosuspend if this was requested */
  2080. if (enable_autosuspend)
  2081. usb_enable_autosuspend(data->udev);
  2082. }
  2083. kfree_skb(skb);
  2084. return 0;
  2085. }
  2086. static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
  2087. {
  2088. struct sk_buff *skb;
  2089. struct hci_event_hdr *hdr;
  2090. struct hci_ev_cmd_complete *evt;
  2091. skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL);
  2092. if (!skb)
  2093. return -ENOMEM;
  2094. hdr = skb_put(skb, sizeof(*hdr));
  2095. hdr->evt = HCI_EV_CMD_COMPLETE;
  2096. hdr->plen = sizeof(*evt) + 1;
  2097. evt = skb_put(skb, sizeof(*evt));
  2098. evt->ncmd = 0x01;
  2099. evt->opcode = cpu_to_le16(opcode);
  2100. skb_put_u8(skb, 0x00);
  2101. hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
  2102. return hci_recv_frame(hdev, skb);
  2103. }
  2104. static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer,
  2105. int count)
  2106. {
  2107. struct hci_dev *hdev = data->hdev;
  2108. /* When the device is in bootloader mode, then it can send
  2109. * events via the bulk endpoint. These events are treated the
  2110. * same way as the ones received from the interrupt endpoint.
  2111. */
  2112. if (btintel_test_flag(hdev, INTEL_BOOTLOADER))
  2113. return btusb_recv_intr(data, buffer, count);
  2114. return btusb_recv_bulk(data, buffer, count);
  2115. }
  2116. static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
  2117. {
  2118. struct urb *urb;
  2119. BT_DBG("%s", hdev->name);
  2120. switch (hci_skb_pkt_type(skb)) {
  2121. case HCI_COMMAND_PKT:
  2122. if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
  2123. struct hci_command_hdr *cmd = (void *)skb->data;
  2124. __u16 opcode = le16_to_cpu(cmd->opcode);
  2125. /* When in bootloader mode and the command 0xfc09
  2126. * is received, it needs to be send down the
  2127. * bulk endpoint. So allocate a bulk URB instead.
  2128. */
  2129. if (opcode == 0xfc09)
  2130. urb = alloc_bulk_urb(hdev, skb);
  2131. else
  2132. urb = alloc_ctrl_urb(hdev, skb);
  2133. /* When the 0xfc01 command is issued to boot into
  2134. * the operational firmware, it will actually not
  2135. * send a command complete event. To keep the flow
  2136. * control working inject that event here.
  2137. */
  2138. if (opcode == 0xfc01)
  2139. inject_cmd_complete(hdev, opcode);
  2140. } else {
  2141. urb = alloc_ctrl_urb(hdev, skb);
  2142. }
  2143. if (IS_ERR(urb))
  2144. return PTR_ERR(urb);
  2145. hdev->stat.cmd_tx++;
  2146. return submit_or_queue_tx_urb(hdev, urb);
  2147. case HCI_ACLDATA_PKT:
  2148. urb = alloc_bulk_urb(hdev, skb);
  2149. if (IS_ERR(urb))
  2150. return PTR_ERR(urb);
  2151. hdev->stat.acl_tx++;
  2152. return submit_or_queue_tx_urb(hdev, urb);
  2153. case HCI_SCODATA_PKT:
  2154. if (hci_conn_num(hdev, SCO_LINK) < 1)
  2155. return -ENODEV;
  2156. urb = alloc_isoc_urb(hdev, skb);
  2157. if (IS_ERR(urb))
  2158. return PTR_ERR(urb);
  2159. hdev->stat.sco_tx++;
  2160. return submit_tx_urb(hdev, urb);
  2161. case HCI_ISODATA_PKT:
  2162. urb = alloc_bulk_urb(hdev, skb);
  2163. if (IS_ERR(urb))
  2164. return PTR_ERR(urb);
  2165. return submit_or_queue_tx_urb(hdev, urb);
  2166. }
  2167. return -EILSEQ;
  2168. }
  2169. static int btusb_setup_realtek(struct hci_dev *hdev)
  2170. {
  2171. struct btusb_data *data = hci_get_drvdata(hdev);
  2172. int ret;
  2173. ret = btrtl_setup_realtek(hdev);
  2174. if (btrealtek_test_flag(data->hdev, REALTEK_ALT6_CONTINUOUS_TX_CHIP))
  2175. set_bit(BTUSB_ALT6_CONTINUOUS_TX, &data->flags);
  2176. return ret;
  2177. }
  2178. static int btusb_recv_event_realtek(struct hci_dev *hdev, struct sk_buff *skb)
  2179. {
  2180. if (skb->data[0] == HCI_VENDOR_PKT && skb->data[2] == RTK_SUB_EVENT_CODE_COREDUMP) {
  2181. struct rtk_dev_coredump_hdr hdr = {
  2182. .code = RTK_DEVCOREDUMP_CODE_MEMDUMP,
  2183. };
  2184. bt_dev_dbg(hdev, "RTL: received coredump vendor evt, len %u",
  2185. skb->len);
  2186. btusb_rtl_alloc_devcoredump(hdev, &hdr, skb->data, skb->len);
  2187. kfree_skb(skb);
  2188. return 0;
  2189. }
  2190. return hci_recv_frame(hdev, skb);
  2191. }
  2192. static void btusb_mtk_claim_iso_intf(struct btusb_data *data)
  2193. {
  2194. struct btmtk_data *btmtk_data = hci_get_priv(data->hdev);
  2195. int err;
  2196. /*
  2197. * The function usb_driver_claim_interface() is documented to need
  2198. * locks held if it's not called from a probe routine. The code here
  2199. * is called from the hci_power_on workqueue, so grab the lock.
  2200. */
  2201. device_lock(&btmtk_data->isopkt_intf->dev);
  2202. err = usb_driver_claim_interface(&btusb_driver,
  2203. btmtk_data->isopkt_intf, data);
  2204. device_unlock(&btmtk_data->isopkt_intf->dev);
  2205. if (err < 0) {
  2206. btmtk_data->isopkt_intf = NULL;
  2207. bt_dev_err(data->hdev, "Failed to claim iso interface");
  2208. return;
  2209. }
  2210. set_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
  2211. init_usb_anchor(&btmtk_data->isopkt_anchor);
  2212. }
  2213. static void btusb_mtk_release_iso_intf(struct hci_dev *hdev)
  2214. {
  2215. struct btmtk_data *btmtk_data = hci_get_priv(hdev);
  2216. if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
  2217. usb_kill_anchored_urbs(&btmtk_data->isopkt_anchor);
  2218. clear_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags);
  2219. dev_kfree_skb_irq(btmtk_data->isopkt_skb);
  2220. btmtk_data->isopkt_skb = NULL;
  2221. usb_set_intfdata(btmtk_data->isopkt_intf, NULL);
  2222. usb_driver_release_interface(&btusb_driver,
  2223. btmtk_data->isopkt_intf);
  2224. }
  2225. clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
  2226. }
  2227. static int btusb_mtk_disconnect(struct hci_dev *hdev)
  2228. {
  2229. /* This function describes the specific additional steps taken by MediaTek
  2230. * when Bluetooth usb driver's resume function is called.
  2231. */
  2232. btusb_mtk_release_iso_intf(hdev);
  2233. return 0;
  2234. }
  2235. static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
  2236. {
  2237. struct btusb_data *data = hci_get_drvdata(hdev);
  2238. struct btmtk_data *btmtk_data = hci_get_priv(hdev);
  2239. int err;
  2240. /* It's MediaTek specific bluetooth reset mechanism via USB */
  2241. if (test_and_set_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags)) {
  2242. bt_dev_err(hdev, "last reset failed? Not resetting again");
  2243. return -EBUSY;
  2244. }
  2245. err = usb_autopm_get_interface(data->intf);
  2246. if (err < 0)
  2247. return err;
  2248. /* Release MediaTek ISO data interface */
  2249. btusb_mtk_release_iso_intf(hdev);
  2250. btusb_stop_traffic(data);
  2251. usb_kill_anchored_urbs(&data->tx_anchor);
  2252. err = btmtk_usb_subsys_reset(hdev, btmtk_data->dev_id);
  2253. usb_queue_reset_device(data->intf);
  2254. clear_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags);
  2255. return err;
  2256. }
  2257. static int btusb_send_frame_mtk(struct hci_dev *hdev, struct sk_buff *skb)
  2258. {
  2259. struct urb *urb;
  2260. BT_DBG("%s", hdev->name);
  2261. if (hci_skb_pkt_type(skb) == HCI_ISODATA_PKT) {
  2262. urb = alloc_mtk_intr_urb(hdev, skb, btusb_tx_complete);
  2263. if (IS_ERR(urb))
  2264. return PTR_ERR(urb);
  2265. return submit_or_queue_tx_urb(hdev, urb);
  2266. } else {
  2267. return btusb_send_frame(hdev, skb);
  2268. }
  2269. }
  2270. static int btusb_mtk_setup(struct hci_dev *hdev)
  2271. {
  2272. struct btusb_data *data = hci_get_drvdata(hdev);
  2273. struct btmtk_data *btmtk_data = hci_get_priv(hdev);
  2274. /* MediaTek WMT vendor cmd requiring below USB resources to
  2275. * complete the handshake.
  2276. */
  2277. btmtk_data->drv_name = btusb_driver.name;
  2278. btmtk_data->intf = data->intf;
  2279. btmtk_data->udev = data->udev;
  2280. btmtk_data->ctrl_anchor = &data->ctrl_anchor;
  2281. btmtk_data->reset_sync = btusb_mtk_reset;
  2282. /* Claim ISO data interface and endpoint */
  2283. if (!test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
  2284. btmtk_data->isopkt_intf = usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM);
  2285. btusb_mtk_claim_iso_intf(data);
  2286. }
  2287. return btmtk_usb_setup(hdev);
  2288. }
  2289. static int btusb_mtk_shutdown(struct hci_dev *hdev)
  2290. {
  2291. int ret;
  2292. ret = btmtk_usb_shutdown(hdev);
  2293. /* Release MediaTek iso interface after shutdown */
  2294. btusb_mtk_release_iso_intf(hdev);
  2295. return ret;
  2296. }
  2297. #ifdef CONFIG_PM
  2298. /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */
  2299. static int marvell_config_oob_wake(struct hci_dev *hdev)
  2300. {
  2301. struct sk_buff *skb;
  2302. struct btusb_data *data = hci_get_drvdata(hdev);
  2303. struct device *dev = &data->udev->dev;
  2304. u16 pin, gap, opcode;
  2305. int ret;
  2306. u8 cmd[5];
  2307. /* Move on if no wakeup pin specified */
  2308. if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) ||
  2309. of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap))
  2310. return 0;
  2311. /* Vendor specific command to configure a GPIO as wake-up pin */
  2312. opcode = hci_opcode_pack(0x3F, 0x59);
  2313. cmd[0] = opcode & 0xFF;
  2314. cmd[1] = opcode >> 8;
  2315. cmd[2] = 2; /* length of parameters that follow */
  2316. cmd[3] = pin;
  2317. cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */
  2318. skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
  2319. if (!skb) {
  2320. bt_dev_err(hdev, "%s: No memory", __func__);
  2321. return -ENOMEM;
  2322. }
  2323. skb_put_data(skb, cmd, sizeof(cmd));
  2324. hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
  2325. ret = btusb_send_frame(hdev, skb);
  2326. if (ret) {
  2327. bt_dev_err(hdev, "%s: configuration failed", __func__);
  2328. kfree_skb(skb);
  2329. return ret;
  2330. }
  2331. return 0;
  2332. }
  2333. #endif
  2334. static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
  2335. const bdaddr_t *bdaddr)
  2336. {
  2337. struct sk_buff *skb;
  2338. u8 buf[8];
  2339. long ret;
  2340. buf[0] = 0xfe;
  2341. buf[1] = sizeof(bdaddr_t);
  2342. memcpy(buf + 2, bdaddr, sizeof(bdaddr_t));
  2343. skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT);
  2344. if (IS_ERR(skb)) {
  2345. ret = PTR_ERR(skb);
  2346. bt_dev_err(hdev, "changing Marvell device address failed (%ld)",
  2347. ret);
  2348. return ret;
  2349. }
  2350. kfree_skb(skb);
  2351. return 0;
  2352. }
  2353. static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
  2354. const bdaddr_t *bdaddr)
  2355. {
  2356. struct sk_buff *skb;
  2357. u8 buf[10];
  2358. long ret;
  2359. buf[0] = 0x01;
  2360. buf[1] = 0x01;
  2361. buf[2] = 0x00;
  2362. buf[3] = sizeof(bdaddr_t);
  2363. memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
  2364. skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
  2365. if (IS_ERR(skb)) {
  2366. ret = PTR_ERR(skb);
  2367. bt_dev_err(hdev, "Change address command failed (%ld)", ret);
  2368. return ret;
  2369. }
  2370. kfree_skb(skb);
  2371. return 0;
  2372. }
  2373. static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev,
  2374. const bdaddr_t *bdaddr)
  2375. {
  2376. struct sk_buff *skb;
  2377. u8 buf[6];
  2378. long ret;
  2379. memcpy(buf, bdaddr, sizeof(bdaddr_t));
  2380. skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf,
  2381. HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
  2382. if (IS_ERR(skb)) {
  2383. ret = PTR_ERR(skb);
  2384. bt_dev_err(hdev, "Change address command failed (%ld)", ret);
  2385. return ret;
  2386. }
  2387. kfree_skb(skb);
  2388. return 0;
  2389. }
  2390. #define QCA_MEMDUMP_ACL_HANDLE 0x2EDD
  2391. #define QCA_MEMDUMP_SIZE_MAX 0x100000
  2392. #define QCA_MEMDUMP_VSE_CLASS 0x01
  2393. #define QCA_MEMDUMP_MSG_TYPE 0x08
  2394. #define QCA_MEMDUMP_PKT_SIZE 248
  2395. #define QCA_LAST_SEQUENCE_NUM 0xffff
  2396. struct qca_dump_hdr {
  2397. u8 vse_class;
  2398. u8 msg_type;
  2399. __le16 seqno;
  2400. u8 reserved;
  2401. union {
  2402. u8 data[0];
  2403. struct {
  2404. __le32 ram_dump_size;
  2405. u8 data0[0];
  2406. } __packed;
  2407. };
  2408. } __packed;
  2409. static void btusb_dump_hdr_qca(struct hci_dev *hdev, struct sk_buff *skb)
  2410. {
  2411. char buf[128];
  2412. struct btusb_data *btdata = hci_get_drvdata(hdev);
  2413. snprintf(buf, sizeof(buf), "Controller Name: 0x%x\n",
  2414. btdata->qca_dump.controller_id);
  2415. skb_put_data(skb, buf, strlen(buf));
  2416. snprintf(buf, sizeof(buf), "Firmware Version: 0x%x\n",
  2417. btdata->qca_dump.fw_version);
  2418. skb_put_data(skb, buf, strlen(buf));
  2419. snprintf(buf, sizeof(buf), "Driver: %s\nVendor: qca\n",
  2420. btusb_driver.name);
  2421. skb_put_data(skb, buf, strlen(buf));
  2422. snprintf(buf, sizeof(buf), "VID: 0x%x\nPID:0x%x\n",
  2423. btdata->qca_dump.id_vendor, btdata->qca_dump.id_product);
  2424. skb_put_data(skb, buf, strlen(buf));
  2425. snprintf(buf, sizeof(buf), "Lmp Subversion: 0x%x\n",
  2426. hdev->lmp_subver);
  2427. skb_put_data(skb, buf, strlen(buf));
  2428. }
  2429. static void btusb_coredump_qca(struct hci_dev *hdev)
  2430. {
  2431. int err;
  2432. static const u8 param[] = { 0x26 };
  2433. err = __hci_cmd_send(hdev, 0xfc0c, 1, param);
  2434. if (err < 0)
  2435. bt_dev_err(hdev, "%s: triggle crash failed (%d)", __func__, err);
  2436. }
  2437. /* Return: 0 on success, negative errno on failure. */
  2438. static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
  2439. {
  2440. int ret = 0;
  2441. unsigned int skip = 0;
  2442. u8 pkt_type;
  2443. u16 seqno;
  2444. u32 dump_size;
  2445. struct qca_dump_hdr *dump_hdr;
  2446. struct btusb_data *btdata = hci_get_drvdata(hdev);
  2447. struct usb_device *udev = btdata->udev;
  2448. pkt_type = hci_skb_pkt_type(skb);
  2449. skip = sizeof(struct hci_event_hdr);
  2450. if (pkt_type == HCI_ACLDATA_PKT)
  2451. skip += sizeof(struct hci_acl_hdr);
  2452. skb_pull(skb, skip);
  2453. dump_hdr = (struct qca_dump_hdr *)skb->data;
  2454. seqno = le16_to_cpu(dump_hdr->seqno);
  2455. if (seqno == 0) {
  2456. set_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags);
  2457. dump_size = le32_to_cpu(dump_hdr->ram_dump_size);
  2458. if (!dump_size || (dump_size > QCA_MEMDUMP_SIZE_MAX)) {
  2459. ret = -EILSEQ;
  2460. bt_dev_err(hdev, "Invalid memdump size(%u)",
  2461. dump_size);
  2462. goto out;
  2463. }
  2464. ret = hci_devcd_init(hdev, dump_size);
  2465. if (ret < 0) {
  2466. bt_dev_err(hdev, "memdump init error(%d)", ret);
  2467. goto out;
  2468. }
  2469. btdata->qca_dump.ram_dump_size = dump_size;
  2470. btdata->qca_dump.ram_dump_seqno = 0;
  2471. skb_pull(skb, offsetof(struct qca_dump_hdr, data0));
  2472. usb_disable_autosuspend(udev);
  2473. bt_dev_info(hdev, "%s memdump size(%u)\n",
  2474. (pkt_type == HCI_ACLDATA_PKT) ? "ACL" : "event",
  2475. dump_size);
  2476. } else {
  2477. skb_pull(skb, offsetof(struct qca_dump_hdr, data));
  2478. }
  2479. if (!btdata->qca_dump.ram_dump_size) {
  2480. ret = -EINVAL;
  2481. bt_dev_err(hdev, "memdump is not active");
  2482. goto out;
  2483. }
  2484. if ((seqno > btdata->qca_dump.ram_dump_seqno + 1) && (seqno != QCA_LAST_SEQUENCE_NUM)) {
  2485. dump_size = QCA_MEMDUMP_PKT_SIZE * (seqno - btdata->qca_dump.ram_dump_seqno - 1);
  2486. hci_devcd_append_pattern(hdev, 0x0, dump_size);
  2487. bt_dev_err(hdev,
  2488. "expected memdump seqno(%u) is not received(%u)\n",
  2489. btdata->qca_dump.ram_dump_seqno, seqno);
  2490. btdata->qca_dump.ram_dump_seqno = seqno;
  2491. kfree_skb(skb);
  2492. return ret;
  2493. }
  2494. hci_devcd_append(hdev, skb);
  2495. btdata->qca_dump.ram_dump_seqno++;
  2496. if (seqno == QCA_LAST_SEQUENCE_NUM) {
  2497. bt_dev_info(hdev,
  2498. "memdump done: pkts(%u), total(%u)\n",
  2499. btdata->qca_dump.ram_dump_seqno, btdata->qca_dump.ram_dump_size);
  2500. hci_devcd_complete(hdev);
  2501. goto out;
  2502. }
  2503. return ret;
  2504. out:
  2505. if (btdata->qca_dump.ram_dump_size)
  2506. usb_enable_autosuspend(udev);
  2507. btdata->qca_dump.ram_dump_size = 0;
  2508. btdata->qca_dump.ram_dump_seqno = 0;
  2509. clear_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags);
  2510. if (ret < 0)
  2511. kfree_skb(skb);
  2512. return ret;
  2513. }
  2514. /* Return: true if the ACL packet is a dump packet, false otherwise. */
  2515. static bool acl_pkt_is_dump_qca(struct hci_dev *hdev, struct sk_buff *skb)
  2516. {
  2517. struct hci_event_hdr *event_hdr;
  2518. struct hci_acl_hdr *acl_hdr;
  2519. struct qca_dump_hdr *dump_hdr;
  2520. struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
  2521. bool is_dump = false;
  2522. if (!clone)
  2523. return false;
  2524. acl_hdr = skb_pull_data(clone, sizeof(*acl_hdr));
  2525. if (!acl_hdr || (le16_to_cpu(acl_hdr->handle) != QCA_MEMDUMP_ACL_HANDLE))
  2526. goto out;
  2527. event_hdr = skb_pull_data(clone, sizeof(*event_hdr));
  2528. if (!event_hdr || (event_hdr->evt != HCI_VENDOR_PKT))
  2529. goto out;
  2530. dump_hdr = skb_pull_data(clone, sizeof(*dump_hdr));
  2531. if (!dump_hdr || (dump_hdr->vse_class != QCA_MEMDUMP_VSE_CLASS) ||
  2532. (dump_hdr->msg_type != QCA_MEMDUMP_MSG_TYPE))
  2533. goto out;
  2534. is_dump = true;
  2535. out:
  2536. consume_skb(clone);
  2537. return is_dump;
  2538. }
  2539. /* Return: true if the event packet is a dump packet, false otherwise. */
  2540. static bool evt_pkt_is_dump_qca(struct hci_dev *hdev, struct sk_buff *skb)
  2541. {
  2542. struct hci_event_hdr *event_hdr;
  2543. struct qca_dump_hdr *dump_hdr;
  2544. struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
  2545. bool is_dump = false;
  2546. if (!clone)
  2547. return false;
  2548. event_hdr = skb_pull_data(clone, sizeof(*event_hdr));
  2549. if (!event_hdr || (event_hdr->evt != HCI_VENDOR_PKT))
  2550. goto out;
  2551. dump_hdr = skb_pull_data(clone, sizeof(*dump_hdr));
  2552. if (!dump_hdr || (dump_hdr->vse_class != QCA_MEMDUMP_VSE_CLASS) ||
  2553. (dump_hdr->msg_type != QCA_MEMDUMP_MSG_TYPE))
  2554. goto out;
  2555. is_dump = true;
  2556. out:
  2557. consume_skb(clone);
  2558. return is_dump;
  2559. }
  2560. static int btusb_recv_acl_qca(struct hci_dev *hdev, struct sk_buff *skb)
  2561. {
  2562. if (acl_pkt_is_dump_qca(hdev, skb))
  2563. return handle_dump_pkt_qca(hdev, skb);
  2564. return hci_recv_frame(hdev, skb);
  2565. }
  2566. static int btusb_recv_evt_qca(struct hci_dev *hdev, struct sk_buff *skb)
  2567. {
  2568. if (evt_pkt_is_dump_qca(hdev, skb))
  2569. return handle_dump_pkt_qca(hdev, skb);
  2570. return hci_recv_frame(hdev, skb);
  2571. }
  2572. #define QCA_DFU_PACKET_LEN 4096
  2573. #define QCA_GET_TARGET_VERSION 0x09
  2574. #define QCA_CHECK_STATUS 0x05
  2575. #define QCA_DFU_DOWNLOAD 0x01
  2576. #define QCA_SYSCFG_UPDATED 0x40
  2577. #define QCA_PATCH_UPDATED 0x80
  2578. #define QCA_DFU_TIMEOUT 3000
  2579. #define QCA_FLAG_MULTI_NVM 0x80
  2580. #define QCA_BT_RESET_WAIT_MS 100
  2581. #define WCN6855_2_0_RAM_VERSION_GF 0x400c1200
  2582. #define WCN6855_2_1_RAM_VERSION_GF 0x400c1211
  2583. struct qca_version {
  2584. __le32 rom_version;
  2585. __le32 patch_version;
  2586. __le32 ram_version;
  2587. __u8 chip_id;
  2588. __u8 platform_id;
  2589. __le16 flag;
  2590. __u8 reserved[4];
  2591. } __packed;
  2592. struct qca_rampatch_version {
  2593. __le16 rom_version_high;
  2594. __le16 rom_version_low;
  2595. __le16 patch_version;
  2596. } __packed;
  2597. struct qca_device_info {
  2598. u32 rom_version;
  2599. u8 rampatch_hdr; /* length of header in rampatch */
  2600. u8 nvm_hdr; /* length of header in NVM */
  2601. u8 ver_offset; /* offset of version structure in rampatch */
  2602. };
  2603. static const struct qca_device_info qca_devices_table[] = {
  2604. { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */
  2605. { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */
  2606. { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */
  2607. { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */
  2608. { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */
  2609. { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */
  2610. { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */
  2611. { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */
  2612. { 0x00130201, 40, 4, 16 }, /* WCN6855 2.1 */
  2613. { 0x00190200, 40, 4, 16 }, /* WCN785x 2.0 */
  2614. };
  2615. static u16 qca_extract_board_id(const struct qca_version *ver)
  2616. {
  2617. u16 flag = le16_to_cpu(ver->flag);
  2618. u16 board_id = 0;
  2619. if (((flag >> 8) & 0xff) == QCA_FLAG_MULTI_NVM) {
  2620. /* The board_id should be split into two bytes
  2621. * The 1st byte is chip ID, and the 2nd byte is platform ID
  2622. * For example, board ID 0x010A, 0x01 is platform ID. 0x0A is chip ID
  2623. * we have several platforms, and platform IDs are continuously added
  2624. * Platform ID:
  2625. * 0x00 is for Mobile
  2626. * 0x01 is for X86
  2627. * 0x02 is for Automotive
  2628. * 0x03 is for Consumer electronic
  2629. */
  2630. board_id = (ver->chip_id << 8) + ver->platform_id;
  2631. }
  2632. /* Take 0xffff as invalid board ID */
  2633. if (board_id == 0xffff)
  2634. board_id = 0;
  2635. return board_id;
  2636. }
  2637. static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request,
  2638. void *data, u16 size)
  2639. {
  2640. int pipe, err;
  2641. u8 *buf;
  2642. buf = kmalloc(size, GFP_KERNEL);
  2643. if (!buf)
  2644. return -ENOMEM;
  2645. /* Found some of USB hosts have IOT issues with ours so that we should
  2646. * not wait until HCI layer is ready.
  2647. */
  2648. pipe = usb_rcvctrlpipe(udev, 0);
  2649. err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN,
  2650. 0, 0, buf, size, USB_CTRL_GET_TIMEOUT);
  2651. if (err < 0) {
  2652. dev_err(&udev->dev, "Failed to access otp area (%d)", err);
  2653. goto done;
  2654. }
  2655. memcpy(data, buf, size);
  2656. done:
  2657. kfree(buf);
  2658. return err;
  2659. }
  2660. static int btusb_setup_qca_download_fw(struct hci_dev *hdev,
  2661. const struct firmware *firmware,
  2662. size_t hdr_size)
  2663. {
  2664. struct btusb_data *btdata = hci_get_drvdata(hdev);
  2665. struct usb_device *udev = btdata->udev;
  2666. size_t count, size, sent = 0;
  2667. int pipe, len, err;
  2668. u8 *buf;
  2669. buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL);
  2670. if (!buf)
  2671. return -ENOMEM;
  2672. count = firmware->size;
  2673. size = min_t(size_t, count, hdr_size);
  2674. memcpy(buf, firmware->data, size);
  2675. /* USB patches should go down to controller through USB path
  2676. * because binary format fits to go down through USB channel.
  2677. * USB control path is for patching headers and USB bulk is for
  2678. * patch body.
  2679. */
  2680. pipe = usb_sndctrlpipe(udev, 0);
  2681. err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR,
  2682. 0, 0, buf, size, USB_CTRL_SET_TIMEOUT);
  2683. if (err < 0) {
  2684. bt_dev_err(hdev, "Failed to send headers (%d)", err);
  2685. goto done;
  2686. }
  2687. sent += size;
  2688. count -= size;
  2689. /* ep2 need time to switch from function acl to function dfu,
  2690. * so we add 20ms delay here.
  2691. */
  2692. msleep(20);
  2693. while (count) {
  2694. size = min_t(size_t, count, QCA_DFU_PACKET_LEN);
  2695. memcpy(buf, firmware->data + sent, size);
  2696. pipe = usb_sndbulkpipe(udev, 0x02);
  2697. err = usb_bulk_msg(udev, pipe, buf, size, &len,
  2698. QCA_DFU_TIMEOUT);
  2699. if (err < 0) {
  2700. bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)",
  2701. sent, firmware->size, err);
  2702. break;
  2703. }
  2704. if (size != len) {
  2705. bt_dev_err(hdev, "Failed to get bulk buffer");
  2706. err = -EILSEQ;
  2707. break;
  2708. }
  2709. sent += size;
  2710. count -= size;
  2711. }
  2712. done:
  2713. kfree(buf);
  2714. return err;
  2715. }
  2716. static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev,
  2717. struct qca_version *ver,
  2718. const struct qca_device_info *info)
  2719. {
  2720. struct qca_rampatch_version *rver;
  2721. const struct firmware *fw;
  2722. u32 ver_rom, ver_patch, rver_rom;
  2723. u16 rver_rom_low, rver_rom_high, rver_patch;
  2724. char fwname[64];
  2725. int err;
  2726. ver_rom = le32_to_cpu(ver->rom_version);
  2727. ver_patch = le32_to_cpu(ver->patch_version);
  2728. snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin", ver_rom);
  2729. err = request_firmware(&fw, fwname, &hdev->dev);
  2730. if (err) {
  2731. bt_dev_err(hdev, "failed to request rampatch file: %s (%d)",
  2732. fwname, err);
  2733. return err;
  2734. }
  2735. bt_dev_info(hdev, "using rampatch file: %s", fwname);
  2736. rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset);
  2737. rver_rom_low = le16_to_cpu(rver->rom_version_low);
  2738. rver_patch = le16_to_cpu(rver->patch_version);
  2739. if (ver_rom & ~0xffffU) {
  2740. rver_rom_high = le16_to_cpu(rver->rom_version_high);
  2741. rver_rom = rver_rom_high << 16 | rver_rom_low;
  2742. } else {
  2743. rver_rom = rver_rom_low;
  2744. }
  2745. bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, "
  2746. "firmware rome 0x%x build 0x%x",
  2747. rver_rom, rver_patch, ver_rom, ver_patch);
  2748. if (rver_rom != ver_rom || rver_patch <= ver_patch) {
  2749. bt_dev_err(hdev, "rampatch file version did not match with firmware");
  2750. err = -EINVAL;
  2751. goto done;
  2752. }
  2753. err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr);
  2754. done:
  2755. release_firmware(fw);
  2756. return err;
  2757. }
  2758. static void btusb_generate_qca_nvm_name(char *fwname, size_t max_size,
  2759. const struct qca_version *ver)
  2760. {
  2761. u32 rom_version = le32_to_cpu(ver->rom_version);
  2762. const char *variant;
  2763. int len;
  2764. u16 board_id;
  2765. board_id = qca_extract_board_id(ver);
  2766. switch (le32_to_cpu(ver->ram_version)) {
  2767. case WCN6855_2_0_RAM_VERSION_GF:
  2768. case WCN6855_2_1_RAM_VERSION_GF:
  2769. variant = "_gf";
  2770. break;
  2771. default:
  2772. variant = NULL;
  2773. break;
  2774. }
  2775. len = snprintf(fwname, max_size, "qca/nvm_usb_%08x", rom_version);
  2776. if (variant)
  2777. len += snprintf(fwname + len, max_size - len, "%s", variant);
  2778. if (board_id)
  2779. len += snprintf(fwname + len, max_size - len, "_%04x", board_id);
  2780. len += snprintf(fwname + len, max_size - len, ".bin");
  2781. }
  2782. static int btusb_setup_qca_load_nvm(struct hci_dev *hdev,
  2783. struct qca_version *ver,
  2784. const struct qca_device_info *info)
  2785. {
  2786. const struct firmware *fw;
  2787. char fwname[64];
  2788. int err;
  2789. btusb_generate_qca_nvm_name(fwname, sizeof(fwname), ver);
  2790. err = request_firmware(&fw, fwname, &hdev->dev);
  2791. if (err) {
  2792. bt_dev_err(hdev, "failed to request NVM file: %s (%d)",
  2793. fwname, err);
  2794. return err;
  2795. }
  2796. bt_dev_info(hdev, "using NVM file: %s", fwname);
  2797. err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr);
  2798. release_firmware(fw);
  2799. return err;
  2800. }
  2801. /* identify the ROM version and check whether patches are needed */
  2802. static bool btusb_qca_need_patch(struct usb_device *udev)
  2803. {
  2804. struct qca_version ver;
  2805. if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
  2806. sizeof(ver)) < 0)
  2807. return false;
  2808. /* only low ROM versions need patches */
  2809. return !(le32_to_cpu(ver.rom_version) & ~0xffffU);
  2810. }
  2811. static int btusb_setup_qca(struct hci_dev *hdev)
  2812. {
  2813. struct btusb_data *btdata = hci_get_drvdata(hdev);
  2814. struct usb_device *udev = btdata->udev;
  2815. const struct qca_device_info *info = NULL;
  2816. struct qca_version ver;
  2817. u32 ver_rom;
  2818. u8 status;
  2819. int i, err;
  2820. err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
  2821. sizeof(ver));
  2822. if (err < 0)
  2823. return err;
  2824. ver_rom = le32_to_cpu(ver.rom_version);
  2825. for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
  2826. if (ver_rom == qca_devices_table[i].rom_version)
  2827. info = &qca_devices_table[i];
  2828. }
  2829. if (!info) {
  2830. /* If the rom_version is not matched in the qca_devices_table
  2831. * and the high ROM version is not zero, we assume this chip no
  2832. * need to load the rampatch and nvm.
  2833. */
  2834. if (ver_rom & ~0xffffU)
  2835. return 0;
  2836. bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom);
  2837. return -ENODEV;
  2838. }
  2839. err = btusb_qca_send_vendor_req(udev, QCA_CHECK_STATUS, &status,
  2840. sizeof(status));
  2841. if (err < 0)
  2842. return err;
  2843. if (!(status & QCA_PATCH_UPDATED)) {
  2844. err = btusb_setup_qca_load_rampatch(hdev, &ver, info);
  2845. if (err < 0)
  2846. return err;
  2847. }
  2848. err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
  2849. sizeof(ver));
  2850. if (err < 0)
  2851. return err;
  2852. btdata->qca_dump.fw_version = le32_to_cpu(ver.patch_version);
  2853. btdata->qca_dump.controller_id = le32_to_cpu(ver.rom_version);
  2854. if (!(status & QCA_SYSCFG_UPDATED)) {
  2855. err = btusb_setup_qca_load_nvm(hdev, &ver, info);
  2856. if (err < 0)
  2857. return err;
  2858. /* WCN6855 2.1 and later will reset to apply firmware downloaded here, so
  2859. * wait ~100ms for reset Done then go ahead, otherwise, it maybe
  2860. * cause potential enable failure.
  2861. */
  2862. if (info->rom_version >= 0x00130201)
  2863. msleep(QCA_BT_RESET_WAIT_MS);
  2864. }
  2865. /* Mark HCI_OP_ENHANCED_SETUP_SYNC_CONN as broken as it doesn't seem to
  2866. * work with the likes of HSP/HFP mSBC.
  2867. */
  2868. set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks);
  2869. return 0;
  2870. }
  2871. static inline int __set_diag_interface(struct hci_dev *hdev)
  2872. {
  2873. struct btusb_data *data = hci_get_drvdata(hdev);
  2874. struct usb_interface *intf = data->diag;
  2875. int i;
  2876. if (!data->diag)
  2877. return -ENODEV;
  2878. data->diag_tx_ep = NULL;
  2879. data->diag_rx_ep = NULL;
  2880. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  2881. struct usb_endpoint_descriptor *ep_desc;
  2882. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  2883. if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
  2884. data->diag_tx_ep = ep_desc;
  2885. continue;
  2886. }
  2887. if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
  2888. data->diag_rx_ep = ep_desc;
  2889. continue;
  2890. }
  2891. }
  2892. if (!data->diag_tx_ep || !data->diag_rx_ep) {
  2893. bt_dev_err(hdev, "invalid diagnostic descriptors");
  2894. return -ENODEV;
  2895. }
  2896. return 0;
  2897. }
  2898. static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable)
  2899. {
  2900. struct btusb_data *data = hci_get_drvdata(hdev);
  2901. struct sk_buff *skb;
  2902. struct urb *urb;
  2903. unsigned int pipe;
  2904. if (!data->diag_tx_ep)
  2905. return ERR_PTR(-ENODEV);
  2906. urb = usb_alloc_urb(0, GFP_KERNEL);
  2907. if (!urb)
  2908. return ERR_PTR(-ENOMEM);
  2909. skb = bt_skb_alloc(2, GFP_KERNEL);
  2910. if (!skb) {
  2911. usb_free_urb(urb);
  2912. return ERR_PTR(-ENOMEM);
  2913. }
  2914. skb_put_u8(skb, 0xf0);
  2915. skb_put_u8(skb, enable);
  2916. pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress);
  2917. usb_fill_bulk_urb(urb, data->udev, pipe,
  2918. skb->data, skb->len, btusb_tx_complete, skb);
  2919. skb->dev = (void *)hdev;
  2920. return urb;
  2921. }
  2922. static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable)
  2923. {
  2924. struct btusb_data *data = hci_get_drvdata(hdev);
  2925. struct urb *urb;
  2926. if (!data->diag)
  2927. return -ENODEV;
  2928. if (!test_bit(HCI_RUNNING, &hdev->flags))
  2929. return -ENETDOWN;
  2930. urb = alloc_diag_urb(hdev, enable);
  2931. if (IS_ERR(urb))
  2932. return PTR_ERR(urb);
  2933. return submit_or_queue_tx_urb(hdev, urb);
  2934. }
  2935. #ifdef CONFIG_PM
  2936. static irqreturn_t btusb_oob_wake_handler(int irq, void *priv)
  2937. {
  2938. struct btusb_data *data = priv;
  2939. pm_wakeup_event(&data->udev->dev, 0);
  2940. pm_system_wakeup();
  2941. /* Disable only if not already disabled (keep it balanced) */
  2942. if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) {
  2943. disable_irq_nosync(irq);
  2944. disable_irq_wake(irq);
  2945. }
  2946. return IRQ_HANDLED;
  2947. }
  2948. static const struct of_device_id btusb_match_table[] = {
  2949. { .compatible = "usb1286,204e" },
  2950. { .compatible = "usbcf3,e300" }, /* QCA6174A */
  2951. { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */
  2952. { }
  2953. };
  2954. MODULE_DEVICE_TABLE(of, btusb_match_table);
  2955. /* Use an oob wakeup pin? */
  2956. static int btusb_config_oob_wake(struct hci_dev *hdev)
  2957. {
  2958. struct btusb_data *data = hci_get_drvdata(hdev);
  2959. struct device *dev = &data->udev->dev;
  2960. int irq, ret;
  2961. clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags);
  2962. if (!of_match_device(btusb_match_table, dev))
  2963. return 0;
  2964. /* Move on if no IRQ specified */
  2965. irq = of_irq_get_byname(dev->of_node, "wakeup");
  2966. if (irq <= 0) {
  2967. bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__);
  2968. return 0;
  2969. }
  2970. irq_set_status_flags(irq, IRQ_NOAUTOEN);
  2971. ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler,
  2972. 0, "OOB Wake-on-BT", data);
  2973. if (ret) {
  2974. bt_dev_err(hdev, "%s: IRQ request failed", __func__);
  2975. return ret;
  2976. }
  2977. ret = device_init_wakeup(dev, true);
  2978. if (ret) {
  2979. bt_dev_err(hdev, "%s: failed to init_wakeup", __func__);
  2980. return ret;
  2981. }
  2982. data->oob_wake_irq = irq;
  2983. bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq);
  2984. return 0;
  2985. }
  2986. #endif
  2987. static void btusb_check_needs_reset_resume(struct usb_interface *intf)
  2988. {
  2989. if (dmi_check_system(btusb_needs_reset_resume_table))
  2990. interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
  2991. }
  2992. static bool btusb_wakeup(struct hci_dev *hdev)
  2993. {
  2994. struct btusb_data *data = hci_get_drvdata(hdev);
  2995. return device_may_wakeup(&data->udev->dev);
  2996. }
  2997. static int btusb_shutdown_qca(struct hci_dev *hdev)
  2998. {
  2999. struct sk_buff *skb;
  3000. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  3001. if (IS_ERR(skb)) {
  3002. bt_dev_err(hdev, "HCI reset during shutdown failed");
  3003. return PTR_ERR(skb);
  3004. }
  3005. kfree_skb(skb);
  3006. return 0;
  3007. }
  3008. static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf,
  3009. size_t count, loff_t *ppos)
  3010. {
  3011. struct btusb_data *data = file->private_data;
  3012. char buf[3];
  3013. buf[0] = data->poll_sync ? 'Y' : 'N';
  3014. buf[1] = '\n';
  3015. buf[2] = '\0';
  3016. return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  3017. }
  3018. static ssize_t force_poll_sync_write(struct file *file,
  3019. const char __user *user_buf,
  3020. size_t count, loff_t *ppos)
  3021. {
  3022. struct btusb_data *data = file->private_data;
  3023. bool enable;
  3024. int err;
  3025. err = kstrtobool_from_user(user_buf, count, &enable);
  3026. if (err)
  3027. return err;
  3028. /* Only allow changes while the adapter is down */
  3029. if (test_bit(HCI_UP, &data->hdev->flags))
  3030. return -EPERM;
  3031. if (data->poll_sync == enable)
  3032. return -EALREADY;
  3033. data->poll_sync = enable;
  3034. return count;
  3035. }
  3036. static const struct file_operations force_poll_sync_fops = {
  3037. .owner = THIS_MODULE,
  3038. .open = simple_open,
  3039. .read = force_poll_sync_read,
  3040. .write = force_poll_sync_write,
  3041. .llseek = default_llseek,
  3042. };
  3043. static int btusb_probe(struct usb_interface *intf,
  3044. const struct usb_device_id *id)
  3045. {
  3046. struct usb_endpoint_descriptor *ep_desc;
  3047. struct gpio_desc *reset_gpio;
  3048. struct btusb_data *data;
  3049. struct hci_dev *hdev;
  3050. unsigned ifnum_base;
  3051. int i, err, priv_size;
  3052. BT_DBG("intf %p id %p", intf, id);
  3053. if ((id->driver_info & BTUSB_IFNUM_2) &&
  3054. (intf->cur_altsetting->desc.bInterfaceNumber != 0) &&
  3055. (intf->cur_altsetting->desc.bInterfaceNumber != 2))
  3056. return -ENODEV;
  3057. ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber;
  3058. if (!id->driver_info) {
  3059. const struct usb_device_id *match;
  3060. match = usb_match_id(intf, quirks_table);
  3061. if (match)
  3062. id = match;
  3063. }
  3064. if (id->driver_info == BTUSB_IGNORE)
  3065. return -ENODEV;
  3066. if (id->driver_info & BTUSB_ATH3012) {
  3067. struct usb_device *udev = interface_to_usbdev(intf);
  3068. /* Old firmware would otherwise let ath3k driver load
  3069. * patch and sysconfig files
  3070. */
  3071. if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 &&
  3072. !btusb_qca_need_patch(udev))
  3073. return -ENODEV;
  3074. }
  3075. data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
  3076. if (!data)
  3077. return -ENOMEM;
  3078. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  3079. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  3080. if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
  3081. data->intr_ep = ep_desc;
  3082. continue;
  3083. }
  3084. if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
  3085. data->bulk_tx_ep = ep_desc;
  3086. continue;
  3087. }
  3088. if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
  3089. data->bulk_rx_ep = ep_desc;
  3090. continue;
  3091. }
  3092. }
  3093. if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
  3094. return -ENODEV;
  3095. if (id->driver_info & BTUSB_AMP) {
  3096. data->cmdreq_type = USB_TYPE_CLASS | 0x01;
  3097. data->cmdreq = 0x2b;
  3098. } else {
  3099. data->cmdreq_type = USB_TYPE_CLASS;
  3100. data->cmdreq = 0x00;
  3101. }
  3102. data->udev = interface_to_usbdev(intf);
  3103. data->intf = intf;
  3104. INIT_WORK(&data->work, btusb_work);
  3105. INIT_WORK(&data->waker, btusb_waker);
  3106. INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work);
  3107. skb_queue_head_init(&data->acl_q);
  3108. init_usb_anchor(&data->deferred);
  3109. init_usb_anchor(&data->tx_anchor);
  3110. spin_lock_init(&data->txlock);
  3111. init_usb_anchor(&data->intr_anchor);
  3112. init_usb_anchor(&data->bulk_anchor);
  3113. init_usb_anchor(&data->isoc_anchor);
  3114. init_usb_anchor(&data->diag_anchor);
  3115. init_usb_anchor(&data->ctrl_anchor);
  3116. spin_lock_init(&data->rxlock);
  3117. priv_size = 0;
  3118. data->recv_event = hci_recv_frame;
  3119. data->recv_bulk = btusb_recv_bulk;
  3120. if (id->driver_info & BTUSB_INTEL_COMBINED) {
  3121. /* Allocate extra space for Intel device */
  3122. priv_size += sizeof(struct btintel_data);
  3123. /* Override the rx handlers */
  3124. data->recv_event = btintel_recv_event;
  3125. data->recv_bulk = btusb_recv_bulk_intel;
  3126. } else if (id->driver_info & BTUSB_REALTEK) {
  3127. /* Allocate extra space for Realtek device */
  3128. priv_size += sizeof(struct btrealtek_data);
  3129. data->recv_event = btusb_recv_event_realtek;
  3130. } else if (id->driver_info & BTUSB_MEDIATEK) {
  3131. /* Allocate extra space for Mediatek device */
  3132. priv_size += sizeof(struct btmtk_data);
  3133. }
  3134. data->recv_acl = hci_recv_frame;
  3135. hdev = hci_alloc_dev_priv(priv_size);
  3136. if (!hdev)
  3137. return -ENOMEM;
  3138. hdev->bus = HCI_USB;
  3139. hci_set_drvdata(hdev, data);
  3140. data->hdev = hdev;
  3141. SET_HCIDEV_DEV(hdev, &intf->dev);
  3142. reset_gpio = gpiod_get_optional(&data->udev->dev, "reset",
  3143. GPIOD_OUT_LOW);
  3144. if (IS_ERR(reset_gpio)) {
  3145. err = PTR_ERR(reset_gpio);
  3146. goto out_free_dev;
  3147. } else if (reset_gpio) {
  3148. data->reset_gpio = reset_gpio;
  3149. }
  3150. hdev->open = btusb_open;
  3151. hdev->close = btusb_close;
  3152. hdev->flush = btusb_flush;
  3153. hdev->send = btusb_send_frame;
  3154. hdev->notify = btusb_notify;
  3155. hdev->wakeup = btusb_wakeup;
  3156. #ifdef CONFIG_PM
  3157. err = btusb_config_oob_wake(hdev);
  3158. if (err)
  3159. goto out_free_dev;
  3160. /* Marvell devices may need a specific chip configuration */
  3161. if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) {
  3162. err = marvell_config_oob_wake(hdev);
  3163. if (err)
  3164. goto out_free_dev;
  3165. }
  3166. #endif
  3167. if (id->driver_info & BTUSB_CW6622)
  3168. set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
  3169. if (id->driver_info & BTUSB_BCM2045)
  3170. set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
  3171. if (id->driver_info & BTUSB_BCM92035)
  3172. hdev->setup = btusb_setup_bcm92035;
  3173. if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
  3174. (id->driver_info & BTUSB_BCM_PATCHRAM)) {
  3175. hdev->manufacturer = 15;
  3176. hdev->setup = btbcm_setup_patchram;
  3177. hdev->set_diag = btusb_bcm_set_diag;
  3178. hdev->set_bdaddr = btbcm_set_bdaddr;
  3179. /* Broadcom LM_DIAG Interface numbers are hardcoded */
  3180. data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
  3181. }
  3182. if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
  3183. (id->driver_info & BTUSB_BCM_APPLE)) {
  3184. hdev->manufacturer = 15;
  3185. hdev->setup = btbcm_setup_apple;
  3186. hdev->set_diag = btusb_bcm_set_diag;
  3187. /* Broadcom LM_DIAG Interface numbers are hardcoded */
  3188. data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
  3189. }
  3190. /* Combined Intel Device setup to support multiple setup routine */
  3191. if (id->driver_info & BTUSB_INTEL_COMBINED) {
  3192. err = btintel_configure_setup(hdev, btusb_driver.name);
  3193. if (err)
  3194. goto out_free_dev;
  3195. /* Transport specific configuration */
  3196. hdev->send = btusb_send_frame_intel;
  3197. hdev->cmd_timeout = btusb_intel_cmd_timeout;
  3198. if (id->driver_info & BTUSB_INTEL_NO_WBS_SUPPORT)
  3199. btintel_set_flag(hdev, INTEL_ROM_LEGACY_NO_WBS_SUPPORT);
  3200. if (id->driver_info & BTUSB_INTEL_BROKEN_INITIAL_NCMD)
  3201. btintel_set_flag(hdev, INTEL_BROKEN_INITIAL_NCMD);
  3202. if (id->driver_info & BTUSB_INTEL_BROKEN_SHUTDOWN_LED)
  3203. btintel_set_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED);
  3204. }
  3205. if (id->driver_info & BTUSB_MARVELL)
  3206. hdev->set_bdaddr = btusb_set_bdaddr_marvell;
  3207. if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) &&
  3208. (id->driver_info & BTUSB_MEDIATEK)) {
  3209. hdev->setup = btusb_mtk_setup;
  3210. hdev->shutdown = btusb_mtk_shutdown;
  3211. hdev->manufacturer = 70;
  3212. hdev->cmd_timeout = btmtk_reset_sync;
  3213. hdev->set_bdaddr = btmtk_set_bdaddr;
  3214. hdev->send = btusb_send_frame_mtk;
  3215. set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks);
  3216. set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
  3217. data->recv_acl = btmtk_usb_recv_acl;
  3218. data->suspend = btmtk_usb_suspend;
  3219. data->resume = btmtk_usb_resume;
  3220. data->disconnect = btusb_mtk_disconnect;
  3221. }
  3222. if (id->driver_info & BTUSB_SWAVE) {
  3223. set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
  3224. set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks);
  3225. }
  3226. if (id->driver_info & BTUSB_INTEL_BOOT) {
  3227. hdev->manufacturer = 2;
  3228. set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
  3229. }
  3230. if (id->driver_info & BTUSB_ATH3012) {
  3231. data->setup_on_usb = btusb_setup_qca;
  3232. hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
  3233. set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
  3234. set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
  3235. }
  3236. if (id->driver_info & BTUSB_QCA_ROME) {
  3237. data->setup_on_usb = btusb_setup_qca;
  3238. hdev->shutdown = btusb_shutdown_qca;
  3239. hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
  3240. hdev->cmd_timeout = btusb_qca_cmd_timeout;
  3241. set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
  3242. btusb_check_needs_reset_resume(intf);
  3243. }
  3244. if (id->driver_info & BTUSB_QCA_WCN6855) {
  3245. data->qca_dump.id_vendor = id->idVendor;
  3246. data->qca_dump.id_product = id->idProduct;
  3247. data->recv_event = btusb_recv_evt_qca;
  3248. data->recv_acl = btusb_recv_acl_qca;
  3249. hci_devcd_register(hdev, btusb_coredump_qca, btusb_dump_hdr_qca, NULL);
  3250. data->setup_on_usb = btusb_setup_qca;
  3251. hdev->shutdown = btusb_shutdown_qca;
  3252. hdev->set_bdaddr = btusb_set_bdaddr_wcn6855;
  3253. hdev->cmd_timeout = btusb_qca_cmd_timeout;
  3254. set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
  3255. hci_set_msft_opcode(hdev, 0xFD70);
  3256. }
  3257. if (id->driver_info & BTUSB_AMP) {
  3258. /* AMP controllers do not support SCO packets */
  3259. data->isoc = NULL;
  3260. } else {
  3261. /* Interface orders are hardcoded in the specification */
  3262. data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1);
  3263. data->isoc_ifnum = ifnum_base + 1;
  3264. }
  3265. if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) &&
  3266. (id->driver_info & BTUSB_REALTEK)) {
  3267. btrtl_set_driver_name(hdev, btusb_driver.name);
  3268. hdev->setup = btusb_setup_realtek;
  3269. hdev->shutdown = btrtl_shutdown_realtek;
  3270. hdev->cmd_timeout = btusb_rtl_cmd_timeout;
  3271. hdev->hw_error = btusb_rtl_hw_error;
  3272. /* Realtek devices need to set remote wakeup on auto-suspend */
  3273. set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags);
  3274. set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags);
  3275. }
  3276. if (id->driver_info & BTUSB_ACTIONS_SEMI) {
  3277. /* Support is advertised, but not implemented */
  3278. set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
  3279. set_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks);
  3280. set_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks);
  3281. set_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &hdev->quirks);
  3282. set_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE, &hdev->quirks);
  3283. set_bit(HCI_QUIRK_BROKEN_EXT_CREATE_CONN, &hdev->quirks);
  3284. set_bit(HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT, &hdev->quirks);
  3285. }
  3286. if (!reset)
  3287. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  3288. if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
  3289. if (!disable_scofix)
  3290. set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
  3291. }
  3292. if (id->driver_info & BTUSB_BROKEN_ISOC)
  3293. data->isoc = NULL;
  3294. if (id->driver_info & BTUSB_WIDEBAND_SPEECH)
  3295. set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
  3296. if (id->driver_info & BTUSB_INVALID_LE_STATES)
  3297. set_bit(HCI_QUIRK_BROKEN_LE_STATES, &hdev->quirks);
  3298. if (id->driver_info & BTUSB_DIGIANSWER) {
  3299. data->cmdreq_type = USB_TYPE_VENDOR;
  3300. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  3301. }
  3302. if (id->driver_info & BTUSB_CSR) {
  3303. struct usb_device *udev = data->udev;
  3304. u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
  3305. /* Old firmware would otherwise execute USB reset */
  3306. if (bcdDevice < 0x117)
  3307. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  3308. /* This must be set first in case we disable it for fakes */
  3309. set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
  3310. /* Fake CSR devices with broken commands */
  3311. if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 &&
  3312. le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
  3313. hdev->setup = btusb_setup_csr;
  3314. }
  3315. if (id->driver_info & BTUSB_SNIFFER) {
  3316. struct usb_device *udev = data->udev;
  3317. /* New sniffer firmware has crippled HCI interface */
  3318. if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
  3319. set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
  3320. }
  3321. if (id->driver_info & BTUSB_INTEL_BOOT) {
  3322. /* A bug in the bootloader causes that interrupt interface is
  3323. * only enabled after receiving SetInterface(0, AltSetting=0).
  3324. */
  3325. err = usb_set_interface(data->udev, 0, 0);
  3326. if (err < 0) {
  3327. BT_ERR("failed to set interface 0, alt 0 %d", err);
  3328. goto out_free_dev;
  3329. }
  3330. }
  3331. if (data->isoc) {
  3332. err = usb_driver_claim_interface(&btusb_driver,
  3333. data->isoc, data);
  3334. if (err < 0)
  3335. goto out_free_dev;
  3336. }
  3337. if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) {
  3338. if (!usb_driver_claim_interface(&btusb_driver,
  3339. data->diag, data))
  3340. __set_diag_interface(hdev);
  3341. else
  3342. data->diag = NULL;
  3343. }
  3344. if (enable_autosuspend)
  3345. usb_enable_autosuspend(data->udev);
  3346. data->poll_sync = enable_poll_sync;
  3347. err = hci_register_dev(hdev);
  3348. if (err < 0)
  3349. goto out_free_dev;
  3350. usb_set_intfdata(intf, data);
  3351. debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data,
  3352. &force_poll_sync_fops);
  3353. return 0;
  3354. out_free_dev:
  3355. if (data->reset_gpio)
  3356. gpiod_put(data->reset_gpio);
  3357. hci_free_dev(hdev);
  3358. return err;
  3359. }
  3360. static void btusb_disconnect(struct usb_interface *intf)
  3361. {
  3362. struct btusb_data *data = usb_get_intfdata(intf);
  3363. struct hci_dev *hdev;
  3364. BT_DBG("intf %p", intf);
  3365. if (!data)
  3366. return;
  3367. hdev = data->hdev;
  3368. usb_set_intfdata(data->intf, NULL);
  3369. if (data->isoc)
  3370. usb_set_intfdata(data->isoc, NULL);
  3371. if (data->diag)
  3372. usb_set_intfdata(data->diag, NULL);
  3373. if (data->disconnect)
  3374. data->disconnect(hdev);
  3375. hci_unregister_dev(hdev);
  3376. if (intf == data->intf) {
  3377. if (data->isoc)
  3378. usb_driver_release_interface(&btusb_driver, data->isoc);
  3379. if (data->diag)
  3380. usb_driver_release_interface(&btusb_driver, data->diag);
  3381. } else if (intf == data->isoc) {
  3382. if (data->diag)
  3383. usb_driver_release_interface(&btusb_driver, data->diag);
  3384. usb_driver_release_interface(&btusb_driver, data->intf);
  3385. } else if (intf == data->diag) {
  3386. usb_driver_release_interface(&btusb_driver, data->intf);
  3387. if (data->isoc)
  3388. usb_driver_release_interface(&btusb_driver, data->isoc);
  3389. }
  3390. if (data->oob_wake_irq)
  3391. device_init_wakeup(&data->udev->dev, false);
  3392. if (data->reset_gpio)
  3393. gpiod_put(data->reset_gpio);
  3394. hci_free_dev(hdev);
  3395. }
  3396. #ifdef CONFIG_PM
  3397. static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
  3398. {
  3399. struct btusb_data *data = usb_get_intfdata(intf);
  3400. BT_DBG("intf %p", intf);
  3401. /* Don't auto-suspend if there are connections; external suspend calls
  3402. * shall never fail.
  3403. */
  3404. if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
  3405. return -EBUSY;
  3406. if (data->suspend_count++)
  3407. return 0;
  3408. spin_lock_irq(&data->txlock);
  3409. if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
  3410. set_bit(BTUSB_SUSPENDING, &data->flags);
  3411. spin_unlock_irq(&data->txlock);
  3412. } else {
  3413. spin_unlock_irq(&data->txlock);
  3414. data->suspend_count--;
  3415. return -EBUSY;
  3416. }
  3417. cancel_work_sync(&data->work);
  3418. if (data->suspend)
  3419. data->suspend(data->hdev);
  3420. btusb_stop_traffic(data);
  3421. usb_kill_anchored_urbs(&data->tx_anchor);
  3422. if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) {
  3423. set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags);
  3424. enable_irq_wake(data->oob_wake_irq);
  3425. enable_irq(data->oob_wake_irq);
  3426. }
  3427. /* For global suspend, Realtek devices lose the loaded fw
  3428. * in them. But for autosuspend, firmware should remain.
  3429. * Actually, it depends on whether the usb host sends
  3430. * set feature (enable wakeup) or not.
  3431. */
  3432. if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) {
  3433. if (PMSG_IS_AUTO(message) &&
  3434. device_can_wakeup(&data->udev->dev))
  3435. data->udev->do_remote_wakeup = 1;
  3436. else if (!PMSG_IS_AUTO(message) &&
  3437. !device_may_wakeup(&data->udev->dev)) {
  3438. data->udev->do_remote_wakeup = 0;
  3439. data->udev->reset_resume = 1;
  3440. }
  3441. }
  3442. return 0;
  3443. }
  3444. static void play_deferred(struct btusb_data *data)
  3445. {
  3446. struct urb *urb;
  3447. int err;
  3448. while ((urb = usb_get_from_anchor(&data->deferred))) {
  3449. usb_anchor_urb(urb, &data->tx_anchor);
  3450. err = usb_submit_urb(urb, GFP_ATOMIC);
  3451. if (err < 0) {
  3452. if (err != -EPERM && err != -ENODEV)
  3453. BT_ERR("%s urb %p submission failed (%d)",
  3454. data->hdev->name, urb, -err);
  3455. kfree(urb->setup_packet);
  3456. usb_unanchor_urb(urb);
  3457. usb_free_urb(urb);
  3458. break;
  3459. }
  3460. data->tx_in_flight++;
  3461. usb_free_urb(urb);
  3462. }
  3463. /* Cleanup the rest deferred urbs. */
  3464. while ((urb = usb_get_from_anchor(&data->deferred))) {
  3465. kfree(urb->setup_packet);
  3466. usb_free_urb(urb);
  3467. }
  3468. }
  3469. static int btusb_resume(struct usb_interface *intf)
  3470. {
  3471. struct btusb_data *data = usb_get_intfdata(intf);
  3472. struct hci_dev *hdev = data->hdev;
  3473. int err = 0;
  3474. BT_DBG("intf %p", intf);
  3475. if (--data->suspend_count)
  3476. return 0;
  3477. /* Disable only if not already disabled (keep it balanced) */
  3478. if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) {
  3479. disable_irq(data->oob_wake_irq);
  3480. disable_irq_wake(data->oob_wake_irq);
  3481. }
  3482. if (!test_bit(HCI_RUNNING, &hdev->flags))
  3483. goto done;
  3484. if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
  3485. err = btusb_submit_intr_urb(hdev, GFP_NOIO);
  3486. if (err < 0) {
  3487. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  3488. goto failed;
  3489. }
  3490. }
  3491. if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
  3492. err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
  3493. if (err < 0) {
  3494. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  3495. goto failed;
  3496. }
  3497. btusb_submit_bulk_urb(hdev, GFP_NOIO);
  3498. }
  3499. if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
  3500. if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
  3501. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  3502. else
  3503. btusb_submit_isoc_urb(hdev, GFP_NOIO);
  3504. }
  3505. if (data->resume)
  3506. data->resume(hdev);
  3507. spin_lock_irq(&data->txlock);
  3508. play_deferred(data);
  3509. clear_bit(BTUSB_SUSPENDING, &data->flags);
  3510. spin_unlock_irq(&data->txlock);
  3511. schedule_work(&data->work);
  3512. return 0;
  3513. failed:
  3514. usb_scuttle_anchored_urbs(&data->deferred);
  3515. done:
  3516. spin_lock_irq(&data->txlock);
  3517. clear_bit(BTUSB_SUSPENDING, &data->flags);
  3518. spin_unlock_irq(&data->txlock);
  3519. return err;
  3520. }
  3521. #endif
  3522. #ifdef CONFIG_DEV_COREDUMP
  3523. static void btusb_coredump(struct device *dev)
  3524. {
  3525. struct btusb_data *data = dev_get_drvdata(dev);
  3526. struct hci_dev *hdev = data->hdev;
  3527. if (hdev->dump.coredump)
  3528. hdev->dump.coredump(hdev);
  3529. }
  3530. #endif
  3531. static struct usb_driver btusb_driver = {
  3532. .name = "btusb",
  3533. .probe = btusb_probe,
  3534. .disconnect = btusb_disconnect,
  3535. #ifdef CONFIG_PM
  3536. .suspend = btusb_suspend,
  3537. .resume = btusb_resume,
  3538. #endif
  3539. .id_table = btusb_table,
  3540. .supports_autosuspend = 1,
  3541. .disable_hub_initiated_lpm = 1,
  3542. #ifdef CONFIG_DEV_COREDUMP
  3543. .driver = {
  3544. .coredump = btusb_coredump,
  3545. },
  3546. #endif
  3547. };
  3548. module_usb_driver(btusb_driver);
  3549. module_param(disable_scofix, bool, 0644);
  3550. MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
  3551. module_param(force_scofix, bool, 0644);
  3552. MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
  3553. module_param(enable_autosuspend, bool, 0644);
  3554. MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default");
  3555. module_param(reset, bool, 0644);
  3556. MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
  3557. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
  3558. MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
  3559. MODULE_VERSION(VERSION);
  3560. MODULE_LICENSE("GPL");