btusb.c 130 KB

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