btusb.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971
  1. /*
  2. *
  3. * Generic Bluetooth USB driver
  4. *
  5. * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/usb.h>
  25. #include <linux/firmware.h>
  26. #include <net/bluetooth/bluetooth.h>
  27. #include <net/bluetooth/hci_core.h>
  28. #define VERSION "0.7"
  29. static bool disable_scofix;
  30. static bool force_scofix;
  31. static bool reset = 1;
  32. static struct usb_driver btusb_driver;
  33. #define BTUSB_IGNORE 0x01
  34. #define BTUSB_DIGIANSWER 0x02
  35. #define BTUSB_CSR 0x04
  36. #define BTUSB_SNIFFER 0x08
  37. #define BTUSB_BCM92035 0x10
  38. #define BTUSB_BROKEN_ISOC 0x20
  39. #define BTUSB_WRONG_SCO_MTU 0x40
  40. #define BTUSB_ATH3012 0x80
  41. #define BTUSB_INTEL 0x100
  42. #define BTUSB_INTEL_BOOT 0x200
  43. #define BTUSB_BCM_PATCHRAM 0x400
  44. #define BTUSB_MARVELL 0x800
  45. #define BTUSB_SWAVE 0x1000
  46. #define BTUSB_INTEL_NEW 0x2000
  47. #define BTUSB_AMP 0x4000
  48. static const struct usb_device_id btusb_table[] = {
  49. /* Generic Bluetooth USB device */
  50. { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
  51. /* Generic Bluetooth AMP device */
  52. { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP },
  53. /* Apple-specific (Broadcom) devices */
  54. { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
  55. /* MediaTek MT76x0E */
  56. { USB_DEVICE(0x0e8d, 0x763f) },
  57. /* Broadcom SoftSailing reporting vendor specific */
  58. { USB_DEVICE(0x0a5c, 0x21e1) },
  59. /* Apple MacBookPro 7,1 */
  60. { USB_DEVICE(0x05ac, 0x8213) },
  61. /* Apple iMac11,1 */
  62. { USB_DEVICE(0x05ac, 0x8215) },
  63. /* Apple MacBookPro6,2 */
  64. { USB_DEVICE(0x05ac, 0x8218) },
  65. /* Apple MacBookAir3,1, MacBookAir3,2 */
  66. { USB_DEVICE(0x05ac, 0x821b) },
  67. /* Apple MacBookAir4,1 */
  68. { USB_DEVICE(0x05ac, 0x821f) },
  69. /* Apple MacBookPro8,2 */
  70. { USB_DEVICE(0x05ac, 0x821a) },
  71. /* Apple MacMini5,1 */
  72. { USB_DEVICE(0x05ac, 0x8281) },
  73. /* AVM BlueFRITZ! USB v2.0 */
  74. { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE },
  75. /* Bluetooth Ultraport Module from IBM */
  76. { USB_DEVICE(0x04bf, 0x030a) },
  77. /* ALPS Modules with non-standard id */
  78. { USB_DEVICE(0x044e, 0x3001) },
  79. { USB_DEVICE(0x044e, 0x3002) },
  80. /* Ericsson with non-standard id */
  81. { USB_DEVICE(0x0bdb, 0x1002) },
  82. /* Canyon CN-BTU1 with HID interfaces */
  83. { USB_DEVICE(0x0c10, 0x0000) },
  84. /* Broadcom BCM20702A0 */
  85. { USB_DEVICE(0x0489, 0xe042) },
  86. { USB_DEVICE(0x04ca, 0x2003) },
  87. { USB_DEVICE(0x0b05, 0x17b5) },
  88. { USB_DEVICE(0x0b05, 0x17cb) },
  89. { USB_DEVICE(0x413c, 0x8197) },
  90. { USB_DEVICE(0x13d3, 0x3404),
  91. .driver_info = BTUSB_BCM_PATCHRAM },
  92. /* Broadcom BCM20702B0 (Dynex/Insignia) */
  93. { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM },
  94. /* Foxconn - Hon Hai */
  95. { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
  96. .driver_info = BTUSB_BCM_PATCHRAM },
  97. /* Lite-On Technology - Broadcom based */
  98. { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
  99. .driver_info = BTUSB_BCM_PATCHRAM },
  100. /* Broadcom devices with vendor specific id */
  101. { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
  102. .driver_info = BTUSB_BCM_PATCHRAM },
  103. /* ASUSTek Computer - Broadcom based */
  104. { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
  105. .driver_info = BTUSB_BCM_PATCHRAM },
  106. /* Belkin F8065bf - Broadcom based */
  107. { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01) },
  108. /* IMC Networks - Broadcom based */
  109. { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01) },
  110. /* Intel Bluetooth USB Bootloader (RAM module) */
  111. { USB_DEVICE(0x8087, 0x0a5a),
  112. .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC },
  113. { } /* Terminating entry */
  114. };
  115. MODULE_DEVICE_TABLE(usb, btusb_table);
  116. static const struct usb_device_id blacklist_table[] = {
  117. /* CSR BlueCore devices */
  118. { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
  119. /* Broadcom BCM2033 without firmware */
  120. { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
  121. /* Atheros 3011 with sflash firmware */
  122. { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
  123. { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
  124. { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
  125. { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
  126. { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
  127. { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
  128. /* Atheros AR9285 Malbec with sflash firmware */
  129. { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
  130. /* Atheros 3012 with sflash firmware */
  131. { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
  132. { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
  133. { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
  134. { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
  135. { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
  136. { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
  137. { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
  138. { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
  139. { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
  140. { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
  141. { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
  142. { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
  143. { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
  144. { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
  145. { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
  146. { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
  147. { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
  148. { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
  149. { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
  150. { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
  151. { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
  152. { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
  153. { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
  154. { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 },
  155. { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
  156. { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
  157. { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
  158. { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
  159. { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
  160. { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
  161. { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
  162. { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
  163. { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
  164. { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
  165. { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
  166. { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
  167. /* Atheros AR5BBU12 with sflash firmware */
  168. { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
  169. /* Atheros AR5BBU12 with sflash firmware */
  170. { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
  171. { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
  172. /* Broadcom BCM2035 */
  173. { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
  174. { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
  175. { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
  176. /* Broadcom BCM2045 */
  177. { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
  178. { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
  179. /* IBM/Lenovo ThinkPad with Broadcom chip */
  180. { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
  181. { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
  182. /* HP laptop with Broadcom chip */
  183. { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
  184. /* Dell laptop with Broadcom chip */
  185. { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
  186. /* Dell Wireless 370 and 410 devices */
  187. { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
  188. { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
  189. /* Belkin F8T012 and F8T013 devices */
  190. { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
  191. { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
  192. /* Asus WL-BTD202 device */
  193. { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
  194. /* Kensington Bluetooth USB adapter */
  195. { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
  196. /* RTX Telecom based adapters with buggy SCO support */
  197. { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
  198. { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
  199. /* CONWISE Technology based adapters with buggy SCO support */
  200. { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
  201. /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
  202. { USB_DEVICE(0x1300, 0x0001), .driver_info = BTUSB_SWAVE },
  203. /* Digianswer devices */
  204. { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
  205. { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
  206. /* CSR BlueCore Bluetooth Sniffer */
  207. { USB_DEVICE(0x0a12, 0x0002),
  208. .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
  209. /* Frontline ComProbe Bluetooth Sniffer */
  210. { USB_DEVICE(0x16d3, 0x0002),
  211. .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
  212. /* Marvell Bluetooth devices */
  213. { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL },
  214. { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL },
  215. /* Intel Bluetooth devices */
  216. { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR },
  217. { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL },
  218. { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL },
  219. { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW },
  220. /* Other Intel Bluetooth devices */
  221. { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
  222. .driver_info = BTUSB_IGNORE },
  223. { } /* Terminating entry */
  224. };
  225. #define BTUSB_MAX_ISOC_FRAMES 10
  226. #define BTUSB_INTR_RUNNING 0
  227. #define BTUSB_BULK_RUNNING 1
  228. #define BTUSB_ISOC_RUNNING 2
  229. #define BTUSB_SUSPENDING 3
  230. #define BTUSB_DID_ISO_RESUME 4
  231. #define BTUSB_BOOTLOADER 5
  232. #define BTUSB_DOWNLOADING 6
  233. #define BTUSB_FIRMWARE_LOADED 7
  234. #define BTUSB_FIRMWARE_FAILED 8
  235. #define BTUSB_BOOTING 9
  236. struct btusb_data {
  237. struct hci_dev *hdev;
  238. struct usb_device *udev;
  239. struct usb_interface *intf;
  240. struct usb_interface *isoc;
  241. unsigned long flags;
  242. struct work_struct work;
  243. struct work_struct waker;
  244. struct usb_anchor deferred;
  245. struct usb_anchor tx_anchor;
  246. int tx_in_flight;
  247. spinlock_t txlock;
  248. struct usb_anchor intr_anchor;
  249. struct usb_anchor bulk_anchor;
  250. struct usb_anchor isoc_anchor;
  251. spinlock_t rxlock;
  252. struct sk_buff *evt_skb;
  253. struct sk_buff *acl_skb;
  254. struct sk_buff *sco_skb;
  255. struct usb_endpoint_descriptor *intr_ep;
  256. struct usb_endpoint_descriptor *bulk_tx_ep;
  257. struct usb_endpoint_descriptor *bulk_rx_ep;
  258. struct usb_endpoint_descriptor *isoc_tx_ep;
  259. struct usb_endpoint_descriptor *isoc_rx_ep;
  260. __u8 cmdreq_type;
  261. __u8 cmdreq;
  262. unsigned int sco_num;
  263. int isoc_altsetting;
  264. int suspend_count;
  265. int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
  266. int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
  267. };
  268. static int btusb_wait_on_bit_timeout(void *word, int bit, unsigned long timeout,
  269. unsigned mode)
  270. {
  271. might_sleep();
  272. if (!test_bit(bit, word))
  273. return 0;
  274. return out_of_line_wait_on_bit_timeout(word, bit, bit_wait_timeout,
  275. mode, timeout);
  276. }
  277. static inline void btusb_free_frags(struct btusb_data *data)
  278. {
  279. unsigned long flags;
  280. spin_lock_irqsave(&data->rxlock, flags);
  281. kfree_skb(data->evt_skb);
  282. data->evt_skb = NULL;
  283. kfree_skb(data->acl_skb);
  284. data->acl_skb = NULL;
  285. kfree_skb(data->sco_skb);
  286. data->sco_skb = NULL;
  287. spin_unlock_irqrestore(&data->rxlock, flags);
  288. }
  289. static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
  290. {
  291. struct sk_buff *skb;
  292. int err = 0;
  293. spin_lock(&data->rxlock);
  294. skb = data->evt_skb;
  295. while (count) {
  296. int len;
  297. if (!skb) {
  298. skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC);
  299. if (!skb) {
  300. err = -ENOMEM;
  301. break;
  302. }
  303. bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
  304. bt_cb(skb)->expect = HCI_EVENT_HDR_SIZE;
  305. }
  306. len = min_t(uint, bt_cb(skb)->expect, count);
  307. memcpy(skb_put(skb, len), buffer, len);
  308. count -= len;
  309. buffer += len;
  310. bt_cb(skb)->expect -= len;
  311. if (skb->len == HCI_EVENT_HDR_SIZE) {
  312. /* Complete event header */
  313. bt_cb(skb)->expect = hci_event_hdr(skb)->plen;
  314. if (skb_tailroom(skb) < bt_cb(skb)->expect) {
  315. kfree_skb(skb);
  316. skb = NULL;
  317. err = -EILSEQ;
  318. break;
  319. }
  320. }
  321. if (bt_cb(skb)->expect == 0) {
  322. /* Complete frame */
  323. data->recv_event(data->hdev, skb);
  324. skb = NULL;
  325. }
  326. }
  327. data->evt_skb = skb;
  328. spin_unlock(&data->rxlock);
  329. return err;
  330. }
  331. static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
  332. {
  333. struct sk_buff *skb;
  334. int err = 0;
  335. spin_lock(&data->rxlock);
  336. skb = data->acl_skb;
  337. while (count) {
  338. int len;
  339. if (!skb) {
  340. skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
  341. if (!skb) {
  342. err = -ENOMEM;
  343. break;
  344. }
  345. bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
  346. bt_cb(skb)->expect = HCI_ACL_HDR_SIZE;
  347. }
  348. len = min_t(uint, bt_cb(skb)->expect, count);
  349. memcpy(skb_put(skb, len), buffer, len);
  350. count -= len;
  351. buffer += len;
  352. bt_cb(skb)->expect -= len;
  353. if (skb->len == HCI_ACL_HDR_SIZE) {
  354. __le16 dlen = hci_acl_hdr(skb)->dlen;
  355. /* Complete ACL header */
  356. bt_cb(skb)->expect = __le16_to_cpu(dlen);
  357. if (skb_tailroom(skb) < bt_cb(skb)->expect) {
  358. kfree_skb(skb);
  359. skb = NULL;
  360. err = -EILSEQ;
  361. break;
  362. }
  363. }
  364. if (bt_cb(skb)->expect == 0) {
  365. /* Complete frame */
  366. hci_recv_frame(data->hdev, skb);
  367. skb = NULL;
  368. }
  369. }
  370. data->acl_skb = skb;
  371. spin_unlock(&data->rxlock);
  372. return err;
  373. }
  374. static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count)
  375. {
  376. struct sk_buff *skb;
  377. int err = 0;
  378. spin_lock(&data->rxlock);
  379. skb = data->sco_skb;
  380. while (count) {
  381. int len;
  382. if (!skb) {
  383. skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC);
  384. if (!skb) {
  385. err = -ENOMEM;
  386. break;
  387. }
  388. bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
  389. bt_cb(skb)->expect = HCI_SCO_HDR_SIZE;
  390. }
  391. len = min_t(uint, bt_cb(skb)->expect, count);
  392. memcpy(skb_put(skb, len), buffer, len);
  393. count -= len;
  394. buffer += len;
  395. bt_cb(skb)->expect -= len;
  396. if (skb->len == HCI_SCO_HDR_SIZE) {
  397. /* Complete SCO header */
  398. bt_cb(skb)->expect = hci_sco_hdr(skb)->dlen;
  399. if (skb_tailroom(skb) < bt_cb(skb)->expect) {
  400. kfree_skb(skb);
  401. skb = NULL;
  402. err = -EILSEQ;
  403. break;
  404. }
  405. }
  406. if (bt_cb(skb)->expect == 0) {
  407. /* Complete frame */
  408. hci_recv_frame(data->hdev, skb);
  409. skb = NULL;
  410. }
  411. }
  412. data->sco_skb = skb;
  413. spin_unlock(&data->rxlock);
  414. return err;
  415. }
  416. static void btusb_intr_complete(struct urb *urb)
  417. {
  418. struct hci_dev *hdev = urb->context;
  419. struct btusb_data *data = hci_get_drvdata(hdev);
  420. int err;
  421. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  422. urb->actual_length);
  423. if (!test_bit(HCI_RUNNING, &hdev->flags))
  424. return;
  425. if (urb->status == 0) {
  426. hdev->stat.byte_rx += urb->actual_length;
  427. if (btusb_recv_intr(data, urb->transfer_buffer,
  428. urb->actual_length) < 0) {
  429. BT_ERR("%s corrupted event packet", hdev->name);
  430. hdev->stat.err_rx++;
  431. }
  432. } else if (urb->status == -ENOENT) {
  433. /* Avoid suspend failed when usb_kill_urb */
  434. return;
  435. }
  436. if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
  437. return;
  438. usb_mark_last_busy(data->udev);
  439. usb_anchor_urb(urb, &data->intr_anchor);
  440. err = usb_submit_urb(urb, GFP_ATOMIC);
  441. if (err < 0) {
  442. /* -EPERM: urb is being killed;
  443. * -ENODEV: device got disconnected */
  444. if (err != -EPERM && err != -ENODEV)
  445. BT_ERR("%s urb %p failed to resubmit (%d)",
  446. hdev->name, urb, -err);
  447. usb_unanchor_urb(urb);
  448. }
  449. }
  450. static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
  451. {
  452. struct btusb_data *data = hci_get_drvdata(hdev);
  453. struct urb *urb;
  454. unsigned char *buf;
  455. unsigned int pipe;
  456. int err, size;
  457. BT_DBG("%s", hdev->name);
  458. if (!data->intr_ep)
  459. return -ENODEV;
  460. urb = usb_alloc_urb(0, mem_flags);
  461. if (!urb)
  462. return -ENOMEM;
  463. size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
  464. buf = kmalloc(size, mem_flags);
  465. if (!buf) {
  466. usb_free_urb(urb);
  467. return -ENOMEM;
  468. }
  469. pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
  470. usb_fill_int_urb(urb, data->udev, pipe, buf, size,
  471. btusb_intr_complete, hdev, data->intr_ep->bInterval);
  472. urb->transfer_flags |= URB_FREE_BUFFER;
  473. usb_anchor_urb(urb, &data->intr_anchor);
  474. err = usb_submit_urb(urb, mem_flags);
  475. if (err < 0) {
  476. if (err != -EPERM && err != -ENODEV)
  477. BT_ERR("%s urb %p submission failed (%d)",
  478. hdev->name, urb, -err);
  479. usb_unanchor_urb(urb);
  480. }
  481. usb_free_urb(urb);
  482. return err;
  483. }
  484. static void btusb_bulk_complete(struct urb *urb)
  485. {
  486. struct hci_dev *hdev = urb->context;
  487. struct btusb_data *data = hci_get_drvdata(hdev);
  488. int err;
  489. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  490. urb->actual_length);
  491. if (!test_bit(HCI_RUNNING, &hdev->flags))
  492. return;
  493. if (urb->status == 0) {
  494. hdev->stat.byte_rx += urb->actual_length;
  495. if (data->recv_bulk(data, urb->transfer_buffer,
  496. urb->actual_length) < 0) {
  497. BT_ERR("%s corrupted ACL packet", hdev->name);
  498. hdev->stat.err_rx++;
  499. }
  500. } else if (urb->status == -ENOENT) {
  501. /* Avoid suspend failed when usb_kill_urb */
  502. return;
  503. }
  504. if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
  505. return;
  506. usb_anchor_urb(urb, &data->bulk_anchor);
  507. usb_mark_last_busy(data->udev);
  508. err = usb_submit_urb(urb, GFP_ATOMIC);
  509. if (err < 0) {
  510. /* -EPERM: urb is being killed;
  511. * -ENODEV: device got disconnected */
  512. if (err != -EPERM && err != -ENODEV)
  513. BT_ERR("%s urb %p failed to resubmit (%d)",
  514. hdev->name, urb, -err);
  515. usb_unanchor_urb(urb);
  516. }
  517. }
  518. static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
  519. {
  520. struct btusb_data *data = hci_get_drvdata(hdev);
  521. struct urb *urb;
  522. unsigned char *buf;
  523. unsigned int pipe;
  524. int err, size = HCI_MAX_FRAME_SIZE;
  525. BT_DBG("%s", hdev->name);
  526. if (!data->bulk_rx_ep)
  527. return -ENODEV;
  528. urb = usb_alloc_urb(0, mem_flags);
  529. if (!urb)
  530. return -ENOMEM;
  531. buf = kmalloc(size, mem_flags);
  532. if (!buf) {
  533. usb_free_urb(urb);
  534. return -ENOMEM;
  535. }
  536. pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
  537. usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
  538. btusb_bulk_complete, hdev);
  539. urb->transfer_flags |= URB_FREE_BUFFER;
  540. usb_mark_last_busy(data->udev);
  541. usb_anchor_urb(urb, &data->bulk_anchor);
  542. err = usb_submit_urb(urb, mem_flags);
  543. if (err < 0) {
  544. if (err != -EPERM && err != -ENODEV)
  545. BT_ERR("%s urb %p submission failed (%d)",
  546. hdev->name, urb, -err);
  547. usb_unanchor_urb(urb);
  548. }
  549. usb_free_urb(urb);
  550. return err;
  551. }
  552. static void btusb_isoc_complete(struct urb *urb)
  553. {
  554. struct hci_dev *hdev = urb->context;
  555. struct btusb_data *data = hci_get_drvdata(hdev);
  556. int i, err;
  557. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  558. urb->actual_length);
  559. if (!test_bit(HCI_RUNNING, &hdev->flags))
  560. return;
  561. if (urb->status == 0) {
  562. for (i = 0; i < urb->number_of_packets; i++) {
  563. unsigned int offset = urb->iso_frame_desc[i].offset;
  564. unsigned int length = urb->iso_frame_desc[i].actual_length;
  565. if (urb->iso_frame_desc[i].status)
  566. continue;
  567. hdev->stat.byte_rx += length;
  568. if (btusb_recv_isoc(data, urb->transfer_buffer + offset,
  569. length) < 0) {
  570. BT_ERR("%s corrupted SCO packet", hdev->name);
  571. hdev->stat.err_rx++;
  572. }
  573. }
  574. } else if (urb->status == -ENOENT) {
  575. /* Avoid suspend failed when usb_kill_urb */
  576. return;
  577. }
  578. if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
  579. return;
  580. usb_anchor_urb(urb, &data->isoc_anchor);
  581. err = usb_submit_urb(urb, GFP_ATOMIC);
  582. if (err < 0) {
  583. /* -EPERM: urb is being killed;
  584. * -ENODEV: device got disconnected */
  585. if (err != -EPERM && err != -ENODEV)
  586. BT_ERR("%s urb %p failed to resubmit (%d)",
  587. hdev->name, urb, -err);
  588. usb_unanchor_urb(urb);
  589. }
  590. }
  591. static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
  592. {
  593. int i, offset = 0;
  594. BT_DBG("len %d mtu %d", len, mtu);
  595. for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
  596. i++, offset += mtu, len -= mtu) {
  597. urb->iso_frame_desc[i].offset = offset;
  598. urb->iso_frame_desc[i].length = mtu;
  599. }
  600. if (len && i < BTUSB_MAX_ISOC_FRAMES) {
  601. urb->iso_frame_desc[i].offset = offset;
  602. urb->iso_frame_desc[i].length = len;
  603. i++;
  604. }
  605. urb->number_of_packets = i;
  606. }
  607. static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
  608. {
  609. struct btusb_data *data = hci_get_drvdata(hdev);
  610. struct urb *urb;
  611. unsigned char *buf;
  612. unsigned int pipe;
  613. int err, size;
  614. BT_DBG("%s", hdev->name);
  615. if (!data->isoc_rx_ep)
  616. return -ENODEV;
  617. urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
  618. if (!urb)
  619. return -ENOMEM;
  620. size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
  621. BTUSB_MAX_ISOC_FRAMES;
  622. buf = kmalloc(size, mem_flags);
  623. if (!buf) {
  624. usb_free_urb(urb);
  625. return -ENOMEM;
  626. }
  627. pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
  628. usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
  629. hdev, data->isoc_rx_ep->bInterval);
  630. urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
  631. __fill_isoc_descriptor(urb, size,
  632. le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
  633. usb_anchor_urb(urb, &data->isoc_anchor);
  634. err = usb_submit_urb(urb, mem_flags);
  635. if (err < 0) {
  636. if (err != -EPERM && err != -ENODEV)
  637. BT_ERR("%s urb %p submission failed (%d)",
  638. hdev->name, urb, -err);
  639. usb_unanchor_urb(urb);
  640. }
  641. usb_free_urb(urb);
  642. return err;
  643. }
  644. static void btusb_tx_complete(struct urb *urb)
  645. {
  646. struct sk_buff *skb = urb->context;
  647. struct hci_dev *hdev = (struct hci_dev *)skb->dev;
  648. struct btusb_data *data = hci_get_drvdata(hdev);
  649. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  650. urb->actual_length);
  651. if (!test_bit(HCI_RUNNING, &hdev->flags))
  652. goto done;
  653. if (!urb->status)
  654. hdev->stat.byte_tx += urb->transfer_buffer_length;
  655. else
  656. hdev->stat.err_tx++;
  657. done:
  658. spin_lock(&data->txlock);
  659. data->tx_in_flight--;
  660. spin_unlock(&data->txlock);
  661. kfree(urb->setup_packet);
  662. kfree_skb(skb);
  663. }
  664. static void btusb_isoc_tx_complete(struct urb *urb)
  665. {
  666. struct sk_buff *skb = urb->context;
  667. struct hci_dev *hdev = (struct hci_dev *)skb->dev;
  668. BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
  669. urb->actual_length);
  670. if (!test_bit(HCI_RUNNING, &hdev->flags))
  671. goto done;
  672. if (!urb->status)
  673. hdev->stat.byte_tx += urb->transfer_buffer_length;
  674. else
  675. hdev->stat.err_tx++;
  676. done:
  677. kfree(urb->setup_packet);
  678. kfree_skb(skb);
  679. }
  680. static int btusb_open(struct hci_dev *hdev)
  681. {
  682. struct btusb_data *data = hci_get_drvdata(hdev);
  683. int err;
  684. BT_DBG("%s", hdev->name);
  685. err = usb_autopm_get_interface(data->intf);
  686. if (err < 0)
  687. return err;
  688. data->intf->needs_remote_wakeup = 1;
  689. if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
  690. goto done;
  691. if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
  692. goto done;
  693. err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
  694. if (err < 0)
  695. goto failed;
  696. err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
  697. if (err < 0) {
  698. usb_kill_anchored_urbs(&data->intr_anchor);
  699. goto failed;
  700. }
  701. set_bit(BTUSB_BULK_RUNNING, &data->flags);
  702. btusb_submit_bulk_urb(hdev, GFP_KERNEL);
  703. done:
  704. usb_autopm_put_interface(data->intf);
  705. return 0;
  706. failed:
  707. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  708. clear_bit(HCI_RUNNING, &hdev->flags);
  709. usb_autopm_put_interface(data->intf);
  710. return err;
  711. }
  712. static void btusb_stop_traffic(struct btusb_data *data)
  713. {
  714. usb_kill_anchored_urbs(&data->intr_anchor);
  715. usb_kill_anchored_urbs(&data->bulk_anchor);
  716. usb_kill_anchored_urbs(&data->isoc_anchor);
  717. }
  718. static int btusb_close(struct hci_dev *hdev)
  719. {
  720. struct btusb_data *data = hci_get_drvdata(hdev);
  721. int err;
  722. BT_DBG("%s", hdev->name);
  723. if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
  724. return 0;
  725. cancel_work_sync(&data->work);
  726. cancel_work_sync(&data->waker);
  727. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  728. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  729. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  730. btusb_stop_traffic(data);
  731. btusb_free_frags(data);
  732. err = usb_autopm_get_interface(data->intf);
  733. if (err < 0)
  734. goto failed;
  735. data->intf->needs_remote_wakeup = 0;
  736. usb_autopm_put_interface(data->intf);
  737. failed:
  738. usb_scuttle_anchored_urbs(&data->deferred);
  739. return 0;
  740. }
  741. static int btusb_flush(struct hci_dev *hdev)
  742. {
  743. struct btusb_data *data = hci_get_drvdata(hdev);
  744. BT_DBG("%s", hdev->name);
  745. usb_kill_anchored_urbs(&data->tx_anchor);
  746. btusb_free_frags(data);
  747. return 0;
  748. }
  749. static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
  750. {
  751. struct btusb_data *data = hci_get_drvdata(hdev);
  752. struct usb_ctrlrequest *dr;
  753. struct urb *urb;
  754. unsigned int pipe;
  755. urb = usb_alloc_urb(0, GFP_KERNEL);
  756. if (!urb)
  757. return ERR_PTR(-ENOMEM);
  758. dr = kmalloc(sizeof(*dr), GFP_KERNEL);
  759. if (!dr) {
  760. usb_free_urb(urb);
  761. return ERR_PTR(-ENOMEM);
  762. }
  763. dr->bRequestType = data->cmdreq_type;
  764. dr->bRequest = data->cmdreq;
  765. dr->wIndex = 0;
  766. dr->wValue = 0;
  767. dr->wLength = __cpu_to_le16(skb->len);
  768. pipe = usb_sndctrlpipe(data->udev, 0x00);
  769. usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
  770. skb->data, skb->len, btusb_tx_complete, skb);
  771. skb->dev = (void *)hdev;
  772. return urb;
  773. }
  774. static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
  775. {
  776. struct btusb_data *data = hci_get_drvdata(hdev);
  777. struct urb *urb;
  778. unsigned int pipe;
  779. if (!data->bulk_tx_ep)
  780. return ERR_PTR(-ENODEV);
  781. urb = usb_alloc_urb(0, GFP_KERNEL);
  782. if (!urb)
  783. return ERR_PTR(-ENOMEM);
  784. pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
  785. usb_fill_bulk_urb(urb, data->udev, pipe,
  786. skb->data, skb->len, btusb_tx_complete, skb);
  787. skb->dev = (void *)hdev;
  788. return urb;
  789. }
  790. static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
  791. {
  792. struct btusb_data *data = hci_get_drvdata(hdev);
  793. struct urb *urb;
  794. unsigned int pipe;
  795. if (!data->isoc_tx_ep)
  796. return ERR_PTR(-ENODEV);
  797. urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
  798. if (!urb)
  799. return ERR_PTR(-ENOMEM);
  800. pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
  801. usb_fill_int_urb(urb, data->udev, pipe,
  802. skb->data, skb->len, btusb_isoc_tx_complete,
  803. skb, data->isoc_tx_ep->bInterval);
  804. urb->transfer_flags = URB_ISO_ASAP;
  805. __fill_isoc_descriptor(urb, skb->len,
  806. le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
  807. skb->dev = (void *)hdev;
  808. return urb;
  809. }
  810. static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb)
  811. {
  812. struct btusb_data *data = hci_get_drvdata(hdev);
  813. int err;
  814. usb_anchor_urb(urb, &data->tx_anchor);
  815. err = usb_submit_urb(urb, GFP_KERNEL);
  816. if (err < 0) {
  817. if (err != -EPERM && err != -ENODEV)
  818. BT_ERR("%s urb %p submission failed (%d)",
  819. hdev->name, urb, -err);
  820. kfree(urb->setup_packet);
  821. usb_unanchor_urb(urb);
  822. } else {
  823. usb_mark_last_busy(data->udev);
  824. }
  825. usb_free_urb(urb);
  826. return err;
  827. }
  828. static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb)
  829. {
  830. struct btusb_data *data = hci_get_drvdata(hdev);
  831. unsigned long flags;
  832. bool suspending;
  833. spin_lock_irqsave(&data->txlock, flags);
  834. suspending = test_bit(BTUSB_SUSPENDING, &data->flags);
  835. if (!suspending)
  836. data->tx_in_flight++;
  837. spin_unlock_irqrestore(&data->txlock, flags);
  838. if (!suspending)
  839. return submit_tx_urb(hdev, urb);
  840. usb_anchor_urb(urb, &data->deferred);
  841. schedule_work(&data->waker);
  842. usb_free_urb(urb);
  843. return 0;
  844. }
  845. static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
  846. {
  847. struct urb *urb;
  848. BT_DBG("%s", hdev->name);
  849. if (!test_bit(HCI_RUNNING, &hdev->flags))
  850. return -EBUSY;
  851. switch (bt_cb(skb)->pkt_type) {
  852. case HCI_COMMAND_PKT:
  853. urb = alloc_ctrl_urb(hdev, skb);
  854. if (IS_ERR(urb))
  855. return PTR_ERR(urb);
  856. hdev->stat.cmd_tx++;
  857. return submit_or_queue_tx_urb(hdev, urb);
  858. case HCI_ACLDATA_PKT:
  859. urb = alloc_bulk_urb(hdev, skb);
  860. if (IS_ERR(urb))
  861. return PTR_ERR(urb);
  862. hdev->stat.acl_tx++;
  863. return submit_or_queue_tx_urb(hdev, urb);
  864. case HCI_SCODATA_PKT:
  865. if (hci_conn_num(hdev, SCO_LINK) < 1)
  866. return -ENODEV;
  867. urb = alloc_isoc_urb(hdev, skb);
  868. if (IS_ERR(urb))
  869. return PTR_ERR(urb);
  870. hdev->stat.sco_tx++;
  871. return submit_tx_urb(hdev, urb);
  872. }
  873. return -EILSEQ;
  874. }
  875. static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
  876. {
  877. struct btusb_data *data = hci_get_drvdata(hdev);
  878. BT_DBG("%s evt %d", hdev->name, evt);
  879. if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) {
  880. data->sco_num = hci_conn_num(hdev, SCO_LINK);
  881. schedule_work(&data->work);
  882. }
  883. }
  884. static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
  885. {
  886. struct btusb_data *data = hci_get_drvdata(hdev);
  887. struct usb_interface *intf = data->isoc;
  888. struct usb_endpoint_descriptor *ep_desc;
  889. int i, err;
  890. if (!data->isoc)
  891. return -ENODEV;
  892. err = usb_set_interface(data->udev, 1, altsetting);
  893. if (err < 0) {
  894. BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
  895. return err;
  896. }
  897. data->isoc_altsetting = altsetting;
  898. data->isoc_tx_ep = NULL;
  899. data->isoc_rx_ep = NULL;
  900. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  901. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  902. if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
  903. data->isoc_tx_ep = ep_desc;
  904. continue;
  905. }
  906. if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
  907. data->isoc_rx_ep = ep_desc;
  908. continue;
  909. }
  910. }
  911. if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
  912. BT_ERR("%s invalid SCO descriptors", hdev->name);
  913. return -ENODEV;
  914. }
  915. return 0;
  916. }
  917. static void btusb_work(struct work_struct *work)
  918. {
  919. struct btusb_data *data = container_of(work, struct btusb_data, work);
  920. struct hci_dev *hdev = data->hdev;
  921. int new_alts;
  922. int err;
  923. if (data->sco_num > 0) {
  924. if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
  925. err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
  926. if (err < 0) {
  927. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  928. usb_kill_anchored_urbs(&data->isoc_anchor);
  929. return;
  930. }
  931. set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
  932. }
  933. if (hdev->voice_setting & 0x0020) {
  934. static const int alts[3] = { 2, 4, 5 };
  935. new_alts = alts[data->sco_num - 1];
  936. } else {
  937. new_alts = data->sco_num;
  938. }
  939. if (data->isoc_altsetting != new_alts) {
  940. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  941. usb_kill_anchored_urbs(&data->isoc_anchor);
  942. if (__set_isoc_interface(hdev, new_alts) < 0)
  943. return;
  944. }
  945. if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
  946. if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
  947. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  948. else
  949. btusb_submit_isoc_urb(hdev, GFP_KERNEL);
  950. }
  951. } else {
  952. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  953. usb_kill_anchored_urbs(&data->isoc_anchor);
  954. __set_isoc_interface(hdev, 0);
  955. if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
  956. usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
  957. }
  958. }
  959. static void btusb_waker(struct work_struct *work)
  960. {
  961. struct btusb_data *data = container_of(work, struct btusb_data, waker);
  962. int err;
  963. err = usb_autopm_get_interface(data->intf);
  964. if (err < 0)
  965. return;
  966. usb_autopm_put_interface(data->intf);
  967. }
  968. static int btusb_setup_bcm92035(struct hci_dev *hdev)
  969. {
  970. struct sk_buff *skb;
  971. u8 val = 0x00;
  972. BT_DBG("%s", hdev->name);
  973. skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT);
  974. if (IS_ERR(skb))
  975. BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb));
  976. else
  977. kfree_skb(skb);
  978. return 0;
  979. }
  980. static int btusb_setup_csr(struct hci_dev *hdev)
  981. {
  982. struct hci_rp_read_local_version *rp;
  983. struct sk_buff *skb;
  984. int ret;
  985. BT_DBG("%s", hdev->name);
  986. skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
  987. HCI_INIT_TIMEOUT);
  988. if (IS_ERR(skb)) {
  989. BT_ERR("Reading local version failed (%ld)", -PTR_ERR(skb));
  990. return -PTR_ERR(skb);
  991. }
  992. rp = (struct hci_rp_read_local_version *)skb->data;
  993. if (!rp->status) {
  994. if (le16_to_cpu(rp->manufacturer) != 10) {
  995. /* Clear the reset quirk since this is not an actual
  996. * early Bluetooth 1.1 device from CSR.
  997. */
  998. clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  999. /* These fake CSR controllers have all a broken
  1000. * stored link key handling and so just disable it.
  1001. */
  1002. set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY,
  1003. &hdev->quirks);
  1004. }
  1005. }
  1006. ret = -bt_to_errno(rp->status);
  1007. kfree_skb(skb);
  1008. return ret;
  1009. }
  1010. struct intel_version {
  1011. u8 status;
  1012. u8 hw_platform;
  1013. u8 hw_variant;
  1014. u8 hw_revision;
  1015. u8 fw_variant;
  1016. u8 fw_revision;
  1017. u8 fw_build_num;
  1018. u8 fw_build_ww;
  1019. u8 fw_build_yy;
  1020. u8 fw_patch_num;
  1021. } __packed;
  1022. struct intel_boot_params {
  1023. __u8 status;
  1024. __u8 otp_format;
  1025. __u8 otp_content;
  1026. __u8 otp_patch;
  1027. __le16 dev_revid;
  1028. __u8 secure_boot;
  1029. __u8 key_from_hdr;
  1030. __u8 key_type;
  1031. __u8 otp_lock;
  1032. __u8 api_lock;
  1033. __u8 debug_lock;
  1034. bdaddr_t otp_bdaddr;
  1035. __u8 min_fw_build_nn;
  1036. __u8 min_fw_build_cw;
  1037. __u8 min_fw_build_yy;
  1038. __u8 limited_cce;
  1039. __u8 unlocked_state;
  1040. } __packed;
  1041. static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev,
  1042. struct intel_version *ver)
  1043. {
  1044. const struct firmware *fw;
  1045. char fwname[64];
  1046. int ret;
  1047. snprintf(fwname, sizeof(fwname),
  1048. "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
  1049. ver->hw_platform, ver->hw_variant, ver->hw_revision,
  1050. ver->fw_variant, ver->fw_revision, ver->fw_build_num,
  1051. ver->fw_build_ww, ver->fw_build_yy);
  1052. ret = request_firmware(&fw, fwname, &hdev->dev);
  1053. if (ret < 0) {
  1054. if (ret == -EINVAL) {
  1055. BT_ERR("%s Intel firmware file request failed (%d)",
  1056. hdev->name, ret);
  1057. return NULL;
  1058. }
  1059. BT_ERR("%s failed to open Intel firmware file: %s(%d)",
  1060. hdev->name, fwname, ret);
  1061. /* If the correct firmware patch file is not found, use the
  1062. * default firmware patch file instead
  1063. */
  1064. snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq",
  1065. ver->hw_platform, ver->hw_variant);
  1066. if (request_firmware(&fw, fwname, &hdev->dev) < 0) {
  1067. BT_ERR("%s failed to open default Intel fw file: %s",
  1068. hdev->name, fwname);
  1069. return NULL;
  1070. }
  1071. }
  1072. BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev->name, fwname);
  1073. return fw;
  1074. }
  1075. static int btusb_setup_intel_patching(struct hci_dev *hdev,
  1076. const struct firmware *fw,
  1077. const u8 **fw_ptr, int *disable_patch)
  1078. {
  1079. struct sk_buff *skb;
  1080. struct hci_command_hdr *cmd;
  1081. const u8 *cmd_param;
  1082. struct hci_event_hdr *evt = NULL;
  1083. const u8 *evt_param = NULL;
  1084. int remain = fw->size - (*fw_ptr - fw->data);
  1085. /* The first byte indicates the types of the patch command or event.
  1086. * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
  1087. * in the current firmware buffer doesn't start with 0x01 or
  1088. * the size of remain buffer is smaller than HCI command header,
  1089. * the firmware file is corrupted and it should stop the patching
  1090. * process.
  1091. */
  1092. if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) {
  1093. BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev->name);
  1094. return -EINVAL;
  1095. }
  1096. (*fw_ptr)++;
  1097. remain--;
  1098. cmd = (struct hci_command_hdr *)(*fw_ptr);
  1099. *fw_ptr += sizeof(*cmd);
  1100. remain -= sizeof(*cmd);
  1101. /* Ensure that the remain firmware data is long enough than the length
  1102. * of command parameter. If not, the firmware file is corrupted.
  1103. */
  1104. if (remain < cmd->plen) {
  1105. BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev->name);
  1106. return -EFAULT;
  1107. }
  1108. /* If there is a command that loads a patch in the firmware
  1109. * file, then enable the patch upon success, otherwise just
  1110. * disable the manufacturer mode, for example patch activation
  1111. * is not required when the default firmware patch file is used
  1112. * because there are no patch data to load.
  1113. */
  1114. if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e)
  1115. *disable_patch = 0;
  1116. cmd_param = *fw_ptr;
  1117. *fw_ptr += cmd->plen;
  1118. remain -= cmd->plen;
  1119. /* This reads the expected events when the above command is sent to the
  1120. * device. Some vendor commands expects more than one events, for
  1121. * example command status event followed by vendor specific event.
  1122. * For this case, it only keeps the last expected event. so the command
  1123. * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
  1124. * last expected event.
  1125. */
  1126. while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) {
  1127. (*fw_ptr)++;
  1128. remain--;
  1129. evt = (struct hci_event_hdr *)(*fw_ptr);
  1130. *fw_ptr += sizeof(*evt);
  1131. remain -= sizeof(*evt);
  1132. if (remain < evt->plen) {
  1133. BT_ERR("%s Intel fw corrupted: invalid evt len",
  1134. hdev->name);
  1135. return -EFAULT;
  1136. }
  1137. evt_param = *fw_ptr;
  1138. *fw_ptr += evt->plen;
  1139. remain -= evt->plen;
  1140. }
  1141. /* Every HCI commands in the firmware file has its correspond event.
  1142. * If event is not found or remain is smaller than zero, the firmware
  1143. * file is corrupted.
  1144. */
  1145. if (!evt || !evt_param || remain < 0) {
  1146. BT_ERR("%s Intel fw corrupted: invalid evt read", hdev->name);
  1147. return -EFAULT;
  1148. }
  1149. skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen,
  1150. cmd_param, evt->evt, HCI_INIT_TIMEOUT);
  1151. if (IS_ERR(skb)) {
  1152. BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
  1153. hdev->name, cmd->opcode, PTR_ERR(skb));
  1154. return PTR_ERR(skb);
  1155. }
  1156. /* It ensures that the returned event matches the event data read from
  1157. * the firmware file. At fist, it checks the length and then
  1158. * the contents of the event.
  1159. */
  1160. if (skb->len != evt->plen) {
  1161. BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev->name,
  1162. le16_to_cpu(cmd->opcode));
  1163. kfree_skb(skb);
  1164. return -EFAULT;
  1165. }
  1166. if (memcmp(skb->data, evt_param, evt->plen)) {
  1167. BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)",
  1168. hdev->name, le16_to_cpu(cmd->opcode));
  1169. kfree_skb(skb);
  1170. return -EFAULT;
  1171. }
  1172. kfree_skb(skb);
  1173. return 0;
  1174. }
  1175. #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
  1176. static int btusb_check_bdaddr_intel(struct hci_dev *hdev)
  1177. {
  1178. struct sk_buff *skb;
  1179. struct hci_rp_read_bd_addr *rp;
  1180. skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
  1181. HCI_INIT_TIMEOUT);
  1182. if (IS_ERR(skb)) {
  1183. BT_ERR("%s reading Intel device address failed (%ld)",
  1184. hdev->name, PTR_ERR(skb));
  1185. return PTR_ERR(skb);
  1186. }
  1187. if (skb->len != sizeof(*rp)) {
  1188. BT_ERR("%s Intel device address length mismatch", hdev->name);
  1189. kfree_skb(skb);
  1190. return -EIO;
  1191. }
  1192. rp = (struct hci_rp_read_bd_addr *)skb->data;
  1193. if (rp->status) {
  1194. BT_ERR("%s Intel device address result failed (%02x)",
  1195. hdev->name, rp->status);
  1196. kfree_skb(skb);
  1197. return -bt_to_errno(rp->status);
  1198. }
  1199. /* For some Intel based controllers, the default Bluetooth device
  1200. * address 00:03:19:9E:8B:00 can be found. These controllers are
  1201. * fully operational, but have the danger of duplicate addresses
  1202. * and that in turn can cause problems with Bluetooth operation.
  1203. */
  1204. if (!bacmp(&rp->bdaddr, BDADDR_INTEL)) {
  1205. BT_ERR("%s found Intel default device address (%pMR)",
  1206. hdev->name, &rp->bdaddr);
  1207. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  1208. }
  1209. kfree_skb(skb);
  1210. return 0;
  1211. }
  1212. static int btusb_setup_intel(struct hci_dev *hdev)
  1213. {
  1214. struct sk_buff *skb;
  1215. const struct firmware *fw;
  1216. const u8 *fw_ptr;
  1217. int disable_patch;
  1218. struct intel_version *ver;
  1219. const u8 mfg_enable[] = { 0x01, 0x00 };
  1220. const u8 mfg_disable[] = { 0x00, 0x00 };
  1221. const u8 mfg_reset_deactivate[] = { 0x00, 0x01 };
  1222. const u8 mfg_reset_activate[] = { 0x00, 0x02 };
  1223. BT_DBG("%s", hdev->name);
  1224. /* The controller has a bug with the first HCI command sent to it
  1225. * returning number of completed commands as zero. This would stall the
  1226. * command processing in the Bluetooth core.
  1227. *
  1228. * As a workaround, send HCI Reset command first which will reset the
  1229. * number of completed commands and allow normal command processing
  1230. * from now on.
  1231. */
  1232. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  1233. if (IS_ERR(skb)) {
  1234. BT_ERR("%s sending initial HCI reset command failed (%ld)",
  1235. hdev->name, PTR_ERR(skb));
  1236. return PTR_ERR(skb);
  1237. }
  1238. kfree_skb(skb);
  1239. /* Read Intel specific controller version first to allow selection of
  1240. * which firmware file to load.
  1241. *
  1242. * The returned information are hardware variant and revision plus
  1243. * firmware variant, revision and build number.
  1244. */
  1245. skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
  1246. if (IS_ERR(skb)) {
  1247. BT_ERR("%s reading Intel fw version command failed (%ld)",
  1248. hdev->name, PTR_ERR(skb));
  1249. return PTR_ERR(skb);
  1250. }
  1251. if (skb->len != sizeof(*ver)) {
  1252. BT_ERR("%s Intel version event length mismatch", hdev->name);
  1253. kfree_skb(skb);
  1254. return -EIO;
  1255. }
  1256. ver = (struct intel_version *)skb->data;
  1257. if (ver->status) {
  1258. BT_ERR("%s Intel fw version event failed (%02x)", hdev->name,
  1259. ver->status);
  1260. kfree_skb(skb);
  1261. return -bt_to_errno(ver->status);
  1262. }
  1263. BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x",
  1264. hdev->name, ver->hw_platform, ver->hw_variant,
  1265. ver->hw_revision, ver->fw_variant, ver->fw_revision,
  1266. ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy,
  1267. ver->fw_patch_num);
  1268. /* fw_patch_num indicates the version of patch the device currently
  1269. * have. If there is no patch data in the device, it is always 0x00.
  1270. * So, if it is other than 0x00, no need to patch the deivce again.
  1271. */
  1272. if (ver->fw_patch_num) {
  1273. BT_INFO("%s: Intel device is already patched. patch num: %02x",
  1274. hdev->name, ver->fw_patch_num);
  1275. kfree_skb(skb);
  1276. btusb_check_bdaddr_intel(hdev);
  1277. return 0;
  1278. }
  1279. /* Opens the firmware patch file based on the firmware version read
  1280. * from the controller. If it fails to open the matching firmware
  1281. * patch file, it tries to open the default firmware patch file.
  1282. * If no patch file is found, allow the device to operate without
  1283. * a patch.
  1284. */
  1285. fw = btusb_setup_intel_get_fw(hdev, ver);
  1286. if (!fw) {
  1287. kfree_skb(skb);
  1288. btusb_check_bdaddr_intel(hdev);
  1289. return 0;
  1290. }
  1291. fw_ptr = fw->data;
  1292. /* This Intel specific command enables the manufacturer mode of the
  1293. * controller.
  1294. *
  1295. * Only while this mode is enabled, the driver can download the
  1296. * firmware patch data and configuration parameters.
  1297. */
  1298. skb = __hci_cmd_sync(hdev, 0xfc11, 2, mfg_enable, HCI_INIT_TIMEOUT);
  1299. if (IS_ERR(skb)) {
  1300. BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
  1301. hdev->name, PTR_ERR(skb));
  1302. release_firmware(fw);
  1303. return PTR_ERR(skb);
  1304. }
  1305. if (skb->data[0]) {
  1306. u8 evt_status = skb->data[0];
  1307. BT_ERR("%s enable Intel manufacturer mode event failed (%02x)",
  1308. hdev->name, evt_status);
  1309. kfree_skb(skb);
  1310. release_firmware(fw);
  1311. return -bt_to_errno(evt_status);
  1312. }
  1313. kfree_skb(skb);
  1314. disable_patch = 1;
  1315. /* The firmware data file consists of list of Intel specific HCI
  1316. * commands and its expected events. The first byte indicates the
  1317. * type of the message, either HCI command or HCI event.
  1318. *
  1319. * It reads the command and its expected event from the firmware file,
  1320. * and send to the controller. Once __hci_cmd_sync_ev() returns,
  1321. * the returned event is compared with the event read from the firmware
  1322. * file and it will continue until all the messages are downloaded to
  1323. * the controller.
  1324. *
  1325. * Once the firmware patching is completed successfully,
  1326. * the manufacturer mode is disabled with reset and activating the
  1327. * downloaded patch.
  1328. *
  1329. * If the firmware patching fails, the manufacturer mode is
  1330. * disabled with reset and deactivating the patch.
  1331. *
  1332. * If the default patch file is used, no reset is done when disabling
  1333. * the manufacturer.
  1334. */
  1335. while (fw->size > fw_ptr - fw->data) {
  1336. int ret;
  1337. ret = btusb_setup_intel_patching(hdev, fw, &fw_ptr,
  1338. &disable_patch);
  1339. if (ret < 0)
  1340. goto exit_mfg_deactivate;
  1341. }
  1342. release_firmware(fw);
  1343. if (disable_patch)
  1344. goto exit_mfg_disable;
  1345. /* Patching completed successfully and disable the manufacturer mode
  1346. * with reset and activate the downloaded firmware patches.
  1347. */
  1348. skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_activate),
  1349. mfg_reset_activate, HCI_INIT_TIMEOUT);
  1350. if (IS_ERR(skb)) {
  1351. BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
  1352. hdev->name, PTR_ERR(skb));
  1353. return PTR_ERR(skb);
  1354. }
  1355. kfree_skb(skb);
  1356. BT_INFO("%s: Intel Bluetooth firmware patch completed and activated",
  1357. hdev->name);
  1358. btusb_check_bdaddr_intel(hdev);
  1359. return 0;
  1360. exit_mfg_disable:
  1361. /* Disable the manufacturer mode without reset */
  1362. skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_disable), mfg_disable,
  1363. HCI_INIT_TIMEOUT);
  1364. if (IS_ERR(skb)) {
  1365. BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
  1366. hdev->name, PTR_ERR(skb));
  1367. return PTR_ERR(skb);
  1368. }
  1369. kfree_skb(skb);
  1370. BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev->name);
  1371. btusb_check_bdaddr_intel(hdev);
  1372. return 0;
  1373. exit_mfg_deactivate:
  1374. release_firmware(fw);
  1375. /* Patching failed. Disable the manufacturer mode with reset and
  1376. * deactivate the downloaded firmware patches.
  1377. */
  1378. skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_deactivate),
  1379. mfg_reset_deactivate, HCI_INIT_TIMEOUT);
  1380. if (IS_ERR(skb)) {
  1381. BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
  1382. hdev->name, PTR_ERR(skb));
  1383. return PTR_ERR(skb);
  1384. }
  1385. kfree_skb(skb);
  1386. BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated",
  1387. hdev->name);
  1388. btusb_check_bdaddr_intel(hdev);
  1389. return 0;
  1390. }
  1391. static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
  1392. {
  1393. struct sk_buff *skb;
  1394. struct hci_event_hdr *hdr;
  1395. struct hci_ev_cmd_complete *evt;
  1396. skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_ATOMIC);
  1397. if (!skb)
  1398. return -ENOMEM;
  1399. hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr));
  1400. hdr->evt = HCI_EV_CMD_COMPLETE;
  1401. hdr->plen = sizeof(*evt) + 1;
  1402. evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt));
  1403. evt->ncmd = 0x01;
  1404. evt->opcode = cpu_to_le16(opcode);
  1405. *skb_put(skb, 1) = 0x00;
  1406. bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
  1407. return hci_recv_frame(hdev, skb);
  1408. }
  1409. static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer,
  1410. int count)
  1411. {
  1412. /* When the device is in bootloader mode, then it can send
  1413. * events via the bulk endpoint. These events are treated the
  1414. * same way as the ones received from the interrupt endpoint.
  1415. */
  1416. if (test_bit(BTUSB_BOOTLOADER, &data->flags))
  1417. return btusb_recv_intr(data, buffer, count);
  1418. return btusb_recv_bulk(data, buffer, count);
  1419. }
  1420. static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb)
  1421. {
  1422. struct btusb_data *data = hci_get_drvdata(hdev);
  1423. if (test_bit(BTUSB_BOOTLOADER, &data->flags)) {
  1424. struct hci_event_hdr *hdr = (void *)skb->data;
  1425. /* When the firmware loading completes the device sends
  1426. * out a vendor specific event indicating the result of
  1427. * the firmware loading.
  1428. */
  1429. if (skb->len == 7 && hdr->evt == 0xff && hdr->plen == 0x05 &&
  1430. skb->data[2] == 0x06) {
  1431. if (skb->data[3] != 0x00)
  1432. test_bit(BTUSB_FIRMWARE_FAILED, &data->flags);
  1433. if (test_and_clear_bit(BTUSB_DOWNLOADING,
  1434. &data->flags) &&
  1435. test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) {
  1436. smp_mb__after_atomic();
  1437. wake_up_bit(&data->flags, BTUSB_DOWNLOADING);
  1438. }
  1439. }
  1440. /* When switching to the operational firmware the device
  1441. * sends a vendor specific event indicating that the bootup
  1442. * completed.
  1443. */
  1444. if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 &&
  1445. skb->data[2] == 0x02) {
  1446. if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) {
  1447. smp_mb__after_atomic();
  1448. wake_up_bit(&data->flags, BTUSB_BOOTING);
  1449. }
  1450. }
  1451. }
  1452. return hci_recv_frame(hdev, skb);
  1453. }
  1454. static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
  1455. {
  1456. struct btusb_data *data = hci_get_drvdata(hdev);
  1457. struct urb *urb;
  1458. BT_DBG("%s", hdev->name);
  1459. if (!test_bit(HCI_RUNNING, &hdev->flags))
  1460. return -EBUSY;
  1461. switch (bt_cb(skb)->pkt_type) {
  1462. case HCI_COMMAND_PKT:
  1463. if (test_bit(BTUSB_BOOTLOADER, &data->flags)) {
  1464. struct hci_command_hdr *cmd = (void *)skb->data;
  1465. __u16 opcode = le16_to_cpu(cmd->opcode);
  1466. /* When in bootloader mode and the command 0xfc09
  1467. * is received, it needs to be send down the
  1468. * bulk endpoint. So allocate a bulk URB instead.
  1469. */
  1470. if (opcode == 0xfc09)
  1471. urb = alloc_bulk_urb(hdev, skb);
  1472. else
  1473. urb = alloc_ctrl_urb(hdev, skb);
  1474. /* When the 0xfc01 command is issued to boot into
  1475. * the operational firmware, it will actually not
  1476. * send a command complete event. To keep the flow
  1477. * control working inject that event here.
  1478. */
  1479. if (opcode == 0xfc01)
  1480. inject_cmd_complete(hdev, opcode);
  1481. } else {
  1482. urb = alloc_ctrl_urb(hdev, skb);
  1483. }
  1484. if (IS_ERR(urb))
  1485. return PTR_ERR(urb);
  1486. hdev->stat.cmd_tx++;
  1487. return submit_or_queue_tx_urb(hdev, urb);
  1488. case HCI_ACLDATA_PKT:
  1489. urb = alloc_bulk_urb(hdev, skb);
  1490. if (IS_ERR(urb))
  1491. return PTR_ERR(urb);
  1492. hdev->stat.acl_tx++;
  1493. return submit_or_queue_tx_urb(hdev, urb);
  1494. case HCI_SCODATA_PKT:
  1495. if (hci_conn_num(hdev, SCO_LINK) < 1)
  1496. return -ENODEV;
  1497. urb = alloc_isoc_urb(hdev, skb);
  1498. if (IS_ERR(urb))
  1499. return PTR_ERR(urb);
  1500. hdev->stat.sco_tx++;
  1501. return submit_tx_urb(hdev, urb);
  1502. }
  1503. return -EILSEQ;
  1504. }
  1505. static int btusb_intel_secure_send(struct hci_dev *hdev, u8 fragment_type,
  1506. u32 plen, const void *param)
  1507. {
  1508. while (plen > 0) {
  1509. struct sk_buff *skb;
  1510. u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
  1511. cmd_param[0] = fragment_type;
  1512. memcpy(cmd_param + 1, param, fragment_len);
  1513. skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
  1514. cmd_param, HCI_INIT_TIMEOUT);
  1515. if (IS_ERR(skb))
  1516. return PTR_ERR(skb);
  1517. kfree_skb(skb);
  1518. plen -= fragment_len;
  1519. param += fragment_len;
  1520. }
  1521. return 0;
  1522. }
  1523. static void btusb_intel_version_info(struct hci_dev *hdev,
  1524. struct intel_version *ver)
  1525. {
  1526. const char *variant;
  1527. switch (ver->fw_variant) {
  1528. case 0x06:
  1529. variant = "Bootloader";
  1530. break;
  1531. case 0x23:
  1532. variant = "Firmware";
  1533. break;
  1534. default:
  1535. return;
  1536. }
  1537. BT_INFO("%s: %s revision %u.%u build %u week %u %u", hdev->name,
  1538. variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
  1539. ver->fw_build_num, ver->fw_build_ww, 2000 + ver->fw_build_yy);
  1540. }
  1541. static int btusb_setup_intel_new(struct hci_dev *hdev)
  1542. {
  1543. static const u8 reset_param[] = { 0x00, 0x01, 0x00, 0x01,
  1544. 0x00, 0x08, 0x04, 0x00 };
  1545. struct btusb_data *data = hci_get_drvdata(hdev);
  1546. struct sk_buff *skb;
  1547. struct intel_version *ver;
  1548. struct intel_boot_params *params;
  1549. const struct firmware *fw;
  1550. const u8 *fw_ptr;
  1551. char fwname[64];
  1552. ktime_t calltime, delta, rettime;
  1553. unsigned long long duration;
  1554. int err;
  1555. BT_DBG("%s", hdev->name);
  1556. calltime = ktime_get();
  1557. /* Read the Intel version information to determine if the device
  1558. * is in bootloader mode or if it already has operational firmware
  1559. * loaded.
  1560. */
  1561. skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
  1562. if (IS_ERR(skb)) {
  1563. BT_ERR("%s: Reading Intel version information failed (%ld)",
  1564. hdev->name, PTR_ERR(skb));
  1565. return PTR_ERR(skb);
  1566. }
  1567. if (skb->len != sizeof(*ver)) {
  1568. BT_ERR("%s: Intel version event size mismatch", hdev->name);
  1569. kfree_skb(skb);
  1570. return -EILSEQ;
  1571. }
  1572. ver = (struct intel_version *)skb->data;
  1573. if (ver->status) {
  1574. BT_ERR("%s: Intel version command failure (%02x)",
  1575. hdev->name, ver->status);
  1576. err = -bt_to_errno(ver->status);
  1577. kfree_skb(skb);
  1578. return err;
  1579. }
  1580. /* The hardware platform number has a fixed value of 0x37 and
  1581. * for now only accept this single value.
  1582. */
  1583. if (ver->hw_platform != 0x37) {
  1584. BT_ERR("%s: Unsupported Intel hardware platform (%u)",
  1585. hdev->name, ver->hw_platform);
  1586. kfree_skb(skb);
  1587. return -EINVAL;
  1588. }
  1589. /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is
  1590. * supported by this firmware loading method. This check has been
  1591. * put in place to ensure correct forward compatibility options
  1592. * when newer hardware variants come along.
  1593. */
  1594. if (ver->hw_variant != 0x0b) {
  1595. BT_ERR("%s: Unsupported Intel hardware variant (%u)",
  1596. hdev->name, ver->hw_variant);
  1597. kfree_skb(skb);
  1598. return -EINVAL;
  1599. }
  1600. btusb_intel_version_info(hdev, ver);
  1601. /* The firmware variant determines if the device is in bootloader
  1602. * mode or is running operational firmware. The value 0x06 identifies
  1603. * the bootloader and the value 0x23 identifies the operational
  1604. * firmware.
  1605. *
  1606. * When the operational firmware is already present, then only
  1607. * the check for valid Bluetooth device address is needed. This
  1608. * determines if the device will be added as configured or
  1609. * unconfigured controller.
  1610. *
  1611. * It is not possible to use the Secure Boot Parameters in this
  1612. * case since that command is only available in bootloader mode.
  1613. */
  1614. if (ver->fw_variant == 0x23) {
  1615. kfree_skb(skb);
  1616. clear_bit(BTUSB_BOOTLOADER, &data->flags);
  1617. btusb_check_bdaddr_intel(hdev);
  1618. return 0;
  1619. }
  1620. /* If the device is not in bootloader mode, then the only possible
  1621. * choice is to return an error and abort the device initialization.
  1622. */
  1623. if (ver->fw_variant != 0x06) {
  1624. BT_ERR("%s: Unsupported Intel firmware variant (%u)",
  1625. hdev->name, ver->fw_variant);
  1626. kfree_skb(skb);
  1627. return -ENODEV;
  1628. }
  1629. kfree_skb(skb);
  1630. /* Read the secure boot parameters to identify the operating
  1631. * details of the bootloader.
  1632. */
  1633. skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
  1634. if (IS_ERR(skb)) {
  1635. BT_ERR("%s: Reading Intel boot parameters failed (%ld)",
  1636. hdev->name, PTR_ERR(skb));
  1637. return PTR_ERR(skb);
  1638. }
  1639. if (skb->len != sizeof(*params)) {
  1640. BT_ERR("%s: Intel boot parameters size mismatch", hdev->name);
  1641. kfree_skb(skb);
  1642. return -EILSEQ;
  1643. }
  1644. params = (struct intel_boot_params *)skb->data;
  1645. if (params->status) {
  1646. BT_ERR("%s: Intel boot parameters command failure (%02x)",
  1647. hdev->name, params->status);
  1648. err = -bt_to_errno(params->status);
  1649. kfree_skb(skb);
  1650. return err;
  1651. }
  1652. BT_INFO("%s: Device revision is %u", hdev->name,
  1653. le16_to_cpu(params->dev_revid));
  1654. BT_INFO("%s: Secure boot is %s", hdev->name,
  1655. params->secure_boot ? "enabled" : "disabled");
  1656. BT_INFO("%s: Minimum firmware build %u week %u %u", hdev->name,
  1657. params->min_fw_build_nn, params->min_fw_build_cw,
  1658. 2000 + params->min_fw_build_yy);
  1659. /* It is required that every single firmware fragment is acknowledged
  1660. * with a command complete event. If the boot parameters indicate
  1661. * that this bootloader does not send them, then abort the setup.
  1662. */
  1663. if (params->limited_cce != 0x00) {
  1664. BT_ERR("%s: Unsupported Intel firmware loading method (%u)",
  1665. hdev->name, params->limited_cce);
  1666. kfree_skb(skb);
  1667. return -EINVAL;
  1668. }
  1669. /* If the OTP has no valid Bluetooth device address, then there will
  1670. * also be no valid address for the operational firmware.
  1671. */
  1672. if (!bacmp(&params->otp_bdaddr, BDADDR_ANY)) {
  1673. BT_INFO("%s: No device address configured", hdev->name);
  1674. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  1675. }
  1676. /* With this Intel bootloader only the hardware variant and device
  1677. * revision information are used to select the right firmware.
  1678. *
  1679. * Currently this bootloader support is limited to hardware variant
  1680. * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b).
  1681. */
  1682. snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.sfi",
  1683. le16_to_cpu(params->dev_revid));
  1684. err = request_firmware(&fw, fwname, &hdev->dev);
  1685. if (err < 0) {
  1686. BT_ERR("%s: Failed to load Intel firmware file (%d)",
  1687. hdev->name, err);
  1688. kfree_skb(skb);
  1689. return err;
  1690. }
  1691. BT_INFO("%s: Found device firmware: %s", hdev->name, fwname);
  1692. kfree_skb(skb);
  1693. if (fw->size < 644) {
  1694. BT_ERR("%s: Invalid size of firmware file (%zu)",
  1695. hdev->name, fw->size);
  1696. err = -EBADF;
  1697. goto done;
  1698. }
  1699. set_bit(BTUSB_DOWNLOADING, &data->flags);
  1700. /* Start the firmware download transaction with the Init fragment
  1701. * represented by the 128 bytes of CSS header.
  1702. */
  1703. err = btusb_intel_secure_send(hdev, 0x00, 128, fw->data);
  1704. if (err < 0) {
  1705. BT_ERR("%s: Failed to send firmware header (%d)",
  1706. hdev->name, err);
  1707. goto done;
  1708. }
  1709. /* Send the 256 bytes of public key information from the firmware
  1710. * as the PKey fragment.
  1711. */
  1712. err = btusb_intel_secure_send(hdev, 0x03, 256, fw->data + 128);
  1713. if (err < 0) {
  1714. BT_ERR("%s: Failed to send firmware public key (%d)",
  1715. hdev->name, err);
  1716. goto done;
  1717. }
  1718. /* Send the 256 bytes of signature information from the firmware
  1719. * as the Sign fragment.
  1720. */
  1721. err = btusb_intel_secure_send(hdev, 0x02, 256, fw->data + 388);
  1722. if (err < 0) {
  1723. BT_ERR("%s: Failed to send firmware signature (%d)",
  1724. hdev->name, err);
  1725. goto done;
  1726. }
  1727. fw_ptr = fw->data + 644;
  1728. while (fw_ptr - fw->data < fw->size) {
  1729. struct hci_command_hdr *cmd = (void *)fw_ptr;
  1730. u8 cmd_len;
  1731. cmd_len = sizeof(*cmd) + cmd->plen;
  1732. /* Send each command from the firmware data buffer as
  1733. * a single Data fragment.
  1734. */
  1735. err = btusb_intel_secure_send(hdev, 0x01, cmd_len, fw_ptr);
  1736. if (err < 0) {
  1737. BT_ERR("%s: Failed to send firmware data (%d)",
  1738. hdev->name, err);
  1739. goto done;
  1740. }
  1741. fw_ptr += cmd_len;
  1742. }
  1743. set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
  1744. BT_INFO("%s: Waiting for firmware download to complete", hdev->name);
  1745. /* Before switching the device into operational mode and with that
  1746. * booting the loaded firmware, wait for the bootloader notification
  1747. * that all fragments have been successfully received.
  1748. *
  1749. * When the event processing receives the notification, then the
  1750. * BTUSB_DOWNLOADING flag will be cleared.
  1751. *
  1752. * The firmware loading should not take longer than 5 seconds
  1753. * and thus just timeout if that happens and fail the setup
  1754. * of this device.
  1755. */
  1756. err = btusb_wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING,
  1757. msecs_to_jiffies(5000),
  1758. TASK_INTERRUPTIBLE);
  1759. if (err == 1) {
  1760. BT_ERR("%s: Firmware loading interrupted", hdev->name);
  1761. err = -EINTR;
  1762. goto done;
  1763. }
  1764. if (err) {
  1765. BT_ERR("%s: Firmware loading timeout", hdev->name);
  1766. err = -ETIMEDOUT;
  1767. goto done;
  1768. }
  1769. if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
  1770. BT_ERR("%s: Firmware loading failed", hdev->name);
  1771. err = -ENOEXEC;
  1772. goto done;
  1773. }
  1774. rettime = ktime_get();
  1775. delta = ktime_sub(rettime, calltime);
  1776. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  1777. BT_INFO("%s: Firmware loaded in %llu usecs", hdev->name, duration);
  1778. done:
  1779. release_firmware(fw);
  1780. if (err < 0)
  1781. return err;
  1782. calltime = ktime_get();
  1783. set_bit(BTUSB_BOOTING, &data->flags);
  1784. skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(reset_param), reset_param,
  1785. HCI_INIT_TIMEOUT);
  1786. if (IS_ERR(skb))
  1787. return PTR_ERR(skb);
  1788. kfree_skb(skb);
  1789. /* The bootloader will not indicate when the device is ready. This
  1790. * is done by the operational firmware sending bootup notification.
  1791. *
  1792. * Booting into operational firmware should not take longer than
  1793. * 1 second. However if that happens, then just fail the setup
  1794. * since something went wrong.
  1795. */
  1796. BT_INFO("%s: Waiting for device to boot", hdev->name);
  1797. err = btusb_wait_on_bit_timeout(&data->flags, BTUSB_BOOTING,
  1798. msecs_to_jiffies(1000),
  1799. TASK_INTERRUPTIBLE);
  1800. if (err == 1) {
  1801. BT_ERR("%s: Device boot interrupted", hdev->name);
  1802. return -EINTR;
  1803. }
  1804. if (err) {
  1805. BT_ERR("%s: Device boot timeout", hdev->name);
  1806. return -ETIMEDOUT;
  1807. }
  1808. rettime = ktime_get();
  1809. delta = ktime_sub(rettime, calltime);
  1810. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  1811. BT_INFO("%s: Device booted in %llu usecs", hdev->name, duration);
  1812. clear_bit(BTUSB_BOOTLOADER, &data->flags);
  1813. return 0;
  1814. }
  1815. static void btusb_hw_error_intel(struct hci_dev *hdev, u8 code)
  1816. {
  1817. struct sk_buff *skb;
  1818. u8 type = 0x00;
  1819. BT_ERR("%s: Hardware error 0x%2.2x", hdev->name, code);
  1820. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  1821. if (IS_ERR(skb)) {
  1822. BT_ERR("%s: Reset after hardware error failed (%ld)",
  1823. hdev->name, PTR_ERR(skb));
  1824. return;
  1825. }
  1826. kfree_skb(skb);
  1827. skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT);
  1828. if (IS_ERR(skb)) {
  1829. BT_ERR("%s: Retrieving Intel exception info failed (%ld)",
  1830. hdev->name, PTR_ERR(skb));
  1831. return;
  1832. }
  1833. if (skb->len != 13) {
  1834. BT_ERR("%s: Exception info size mismatch", hdev->name);
  1835. kfree_skb(skb);
  1836. return;
  1837. }
  1838. if (skb->data[0] != 0x00) {
  1839. BT_ERR("%s: Exception info command failure (%02x)",
  1840. hdev->name, skb->data[0]);
  1841. kfree_skb(skb);
  1842. return;
  1843. }
  1844. BT_ERR("%s: Exception info %s", hdev->name, (char *)(skb->data + 1));
  1845. kfree_skb(skb);
  1846. }
  1847. static int btusb_set_bdaddr_intel(struct hci_dev *hdev, const bdaddr_t *bdaddr)
  1848. {
  1849. struct sk_buff *skb;
  1850. long ret;
  1851. skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
  1852. if (IS_ERR(skb)) {
  1853. ret = PTR_ERR(skb);
  1854. BT_ERR("%s: changing Intel device address failed (%ld)",
  1855. hdev->name, ret);
  1856. return ret;
  1857. }
  1858. kfree_skb(skb);
  1859. return 0;
  1860. }
  1861. static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
  1862. const bdaddr_t *bdaddr)
  1863. {
  1864. struct sk_buff *skb;
  1865. u8 buf[8];
  1866. long ret;
  1867. buf[0] = 0xfe;
  1868. buf[1] = sizeof(bdaddr_t);
  1869. memcpy(buf + 2, bdaddr, sizeof(bdaddr_t));
  1870. skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT);
  1871. if (IS_ERR(skb)) {
  1872. ret = PTR_ERR(skb);
  1873. BT_ERR("%s: changing Marvell device address failed (%ld)",
  1874. hdev->name, ret);
  1875. return ret;
  1876. }
  1877. kfree_skb(skb);
  1878. return 0;
  1879. }
  1880. #define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
  1881. static int btusb_setup_bcm_patchram(struct hci_dev *hdev)
  1882. {
  1883. struct btusb_data *data = hci_get_drvdata(hdev);
  1884. struct usb_device *udev = data->udev;
  1885. char fw_name[64];
  1886. const struct firmware *fw;
  1887. const u8 *fw_ptr;
  1888. size_t fw_size;
  1889. const struct hci_command_hdr *cmd;
  1890. const u8 *cmd_param;
  1891. u16 opcode;
  1892. struct sk_buff *skb;
  1893. struct hci_rp_read_local_version *ver;
  1894. struct hci_rp_read_bd_addr *bda;
  1895. long ret;
  1896. snprintf(fw_name, sizeof(fw_name), "brcm/%s-%04x-%04x.hcd",
  1897. udev->product ? udev->product : "BCM",
  1898. le16_to_cpu(udev->descriptor.idVendor),
  1899. le16_to_cpu(udev->descriptor.idProduct));
  1900. ret = request_firmware(&fw, fw_name, &hdev->dev);
  1901. if (ret < 0) {
  1902. BT_INFO("%s: BCM: patch %s not found", hdev->name, fw_name);
  1903. return 0;
  1904. }
  1905. /* Reset */
  1906. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  1907. if (IS_ERR(skb)) {
  1908. ret = PTR_ERR(skb);
  1909. BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev->name, ret);
  1910. goto done;
  1911. }
  1912. kfree_skb(skb);
  1913. /* Read Local Version Info */
  1914. skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
  1915. HCI_INIT_TIMEOUT);
  1916. if (IS_ERR(skb)) {
  1917. ret = PTR_ERR(skb);
  1918. BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
  1919. hdev->name, ret);
  1920. goto done;
  1921. }
  1922. if (skb->len != sizeof(*ver)) {
  1923. BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
  1924. hdev->name);
  1925. kfree_skb(skb);
  1926. ret = -EIO;
  1927. goto done;
  1928. }
  1929. ver = (struct hci_rp_read_local_version *)skb->data;
  1930. BT_INFO("%s: BCM: patching hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
  1931. "lmp_subver=%04x", hdev->name, ver->hci_ver, ver->hci_rev,
  1932. ver->lmp_ver, ver->lmp_subver);
  1933. kfree_skb(skb);
  1934. /* Start Download */
  1935. skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
  1936. if (IS_ERR(skb)) {
  1937. ret = PTR_ERR(skb);
  1938. BT_ERR("%s: BCM: Download Minidrv command failed (%ld)",
  1939. hdev->name, ret);
  1940. goto reset_fw;
  1941. }
  1942. kfree_skb(skb);
  1943. /* 50 msec delay after Download Minidrv completes */
  1944. msleep(50);
  1945. fw_ptr = fw->data;
  1946. fw_size = fw->size;
  1947. while (fw_size >= sizeof(*cmd)) {
  1948. cmd = (struct hci_command_hdr *)fw_ptr;
  1949. fw_ptr += sizeof(*cmd);
  1950. fw_size -= sizeof(*cmd);
  1951. if (fw_size < cmd->plen) {
  1952. BT_ERR("%s: BCM: patch %s is corrupted",
  1953. hdev->name, fw_name);
  1954. ret = -EINVAL;
  1955. goto reset_fw;
  1956. }
  1957. cmd_param = fw_ptr;
  1958. fw_ptr += cmd->plen;
  1959. fw_size -= cmd->plen;
  1960. opcode = le16_to_cpu(cmd->opcode);
  1961. skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
  1962. HCI_INIT_TIMEOUT);
  1963. if (IS_ERR(skb)) {
  1964. ret = PTR_ERR(skb);
  1965. BT_ERR("%s: BCM: patch command %04x failed (%ld)",
  1966. hdev->name, opcode, ret);
  1967. goto reset_fw;
  1968. }
  1969. kfree_skb(skb);
  1970. }
  1971. /* 250 msec delay after Launch Ram completes */
  1972. msleep(250);
  1973. reset_fw:
  1974. /* Reset */
  1975. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  1976. if (IS_ERR(skb)) {
  1977. ret = PTR_ERR(skb);
  1978. BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev->name, ret);
  1979. goto done;
  1980. }
  1981. kfree_skb(skb);
  1982. /* Read Local Version Info */
  1983. skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
  1984. HCI_INIT_TIMEOUT);
  1985. if (IS_ERR(skb)) {
  1986. ret = PTR_ERR(skb);
  1987. BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
  1988. hdev->name, ret);
  1989. goto done;
  1990. }
  1991. if (skb->len != sizeof(*ver)) {
  1992. BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
  1993. hdev->name);
  1994. kfree_skb(skb);
  1995. ret = -EIO;
  1996. goto done;
  1997. }
  1998. ver = (struct hci_rp_read_local_version *)skb->data;
  1999. BT_INFO("%s: BCM: firmware hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
  2000. "lmp_subver=%04x", hdev->name, ver->hci_ver, ver->hci_rev,
  2001. ver->lmp_ver, ver->lmp_subver);
  2002. kfree_skb(skb);
  2003. /* Read BD Address */
  2004. skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
  2005. HCI_INIT_TIMEOUT);
  2006. if (IS_ERR(skb)) {
  2007. ret = PTR_ERR(skb);
  2008. BT_ERR("%s: HCI_OP_READ_BD_ADDR failed (%ld)",
  2009. hdev->name, ret);
  2010. goto done;
  2011. }
  2012. if (skb->len != sizeof(*bda)) {
  2013. BT_ERR("%s: HCI_OP_READ_BD_ADDR event length mismatch",
  2014. hdev->name);
  2015. kfree_skb(skb);
  2016. ret = -EIO;
  2017. goto done;
  2018. }
  2019. bda = (struct hci_rp_read_bd_addr *)skb->data;
  2020. if (bda->status) {
  2021. BT_ERR("%s: HCI_OP_READ_BD_ADDR error status (%02x)",
  2022. hdev->name, bda->status);
  2023. kfree_skb(skb);
  2024. ret = -bt_to_errno(bda->status);
  2025. goto done;
  2026. }
  2027. /* The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
  2028. * with no configured address.
  2029. */
  2030. if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0)) {
  2031. BT_INFO("%s: BCM: using default device address (%pMR)",
  2032. hdev->name, &bda->bdaddr);
  2033. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  2034. }
  2035. kfree_skb(skb);
  2036. done:
  2037. release_firmware(fw);
  2038. return ret;
  2039. }
  2040. static int btusb_set_bdaddr_bcm(struct hci_dev *hdev, const bdaddr_t *bdaddr)
  2041. {
  2042. struct sk_buff *skb;
  2043. long ret;
  2044. skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
  2045. if (IS_ERR(skb)) {
  2046. ret = PTR_ERR(skb);
  2047. BT_ERR("%s: BCM: Change address command failed (%ld)",
  2048. hdev->name, ret);
  2049. return ret;
  2050. }
  2051. kfree_skb(skb);
  2052. return 0;
  2053. }
  2054. static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
  2055. const bdaddr_t *bdaddr)
  2056. {
  2057. struct sk_buff *skb;
  2058. u8 buf[10];
  2059. long ret;
  2060. buf[0] = 0x01;
  2061. buf[1] = 0x01;
  2062. buf[2] = 0x00;
  2063. buf[3] = sizeof(bdaddr_t);
  2064. memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
  2065. skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
  2066. if (IS_ERR(skb)) {
  2067. ret = PTR_ERR(skb);
  2068. BT_ERR("%s: Change address command failed (%ld)",
  2069. hdev->name, ret);
  2070. return ret;
  2071. }
  2072. kfree_skb(skb);
  2073. return 0;
  2074. }
  2075. static int btusb_probe(struct usb_interface *intf,
  2076. const struct usb_device_id *id)
  2077. {
  2078. struct usb_endpoint_descriptor *ep_desc;
  2079. struct btusb_data *data;
  2080. struct hci_dev *hdev;
  2081. int i, err;
  2082. BT_DBG("intf %p id %p", intf, id);
  2083. /* interface numbers are hardcoded in the spec */
  2084. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  2085. return -ENODEV;
  2086. if (!id->driver_info) {
  2087. const struct usb_device_id *match;
  2088. match = usb_match_id(intf, blacklist_table);
  2089. if (match)
  2090. id = match;
  2091. }
  2092. if (id->driver_info == BTUSB_IGNORE)
  2093. return -ENODEV;
  2094. if (id->driver_info & BTUSB_ATH3012) {
  2095. struct usb_device *udev = interface_to_usbdev(intf);
  2096. /* Old firmware would otherwise let ath3k driver load
  2097. * patch and sysconfig files */
  2098. if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001)
  2099. return -ENODEV;
  2100. }
  2101. data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
  2102. if (!data)
  2103. return -ENOMEM;
  2104. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  2105. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  2106. if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
  2107. data->intr_ep = ep_desc;
  2108. continue;
  2109. }
  2110. if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
  2111. data->bulk_tx_ep = ep_desc;
  2112. continue;
  2113. }
  2114. if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
  2115. data->bulk_rx_ep = ep_desc;
  2116. continue;
  2117. }
  2118. }
  2119. if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
  2120. return -ENODEV;
  2121. if (id->driver_info & BTUSB_AMP) {
  2122. data->cmdreq_type = USB_TYPE_CLASS | 0x01;
  2123. data->cmdreq = 0x2b;
  2124. } else {
  2125. data->cmdreq_type = USB_TYPE_CLASS;
  2126. data->cmdreq = 0x00;
  2127. }
  2128. data->udev = interface_to_usbdev(intf);
  2129. data->intf = intf;
  2130. INIT_WORK(&data->work, btusb_work);
  2131. INIT_WORK(&data->waker, btusb_waker);
  2132. init_usb_anchor(&data->deferred);
  2133. init_usb_anchor(&data->tx_anchor);
  2134. spin_lock_init(&data->txlock);
  2135. init_usb_anchor(&data->intr_anchor);
  2136. init_usb_anchor(&data->bulk_anchor);
  2137. init_usb_anchor(&data->isoc_anchor);
  2138. spin_lock_init(&data->rxlock);
  2139. if (id->driver_info & BTUSB_INTEL_NEW) {
  2140. data->recv_event = btusb_recv_event_intel;
  2141. data->recv_bulk = btusb_recv_bulk_intel;
  2142. set_bit(BTUSB_BOOTLOADER, &data->flags);
  2143. } else {
  2144. data->recv_event = hci_recv_frame;
  2145. data->recv_bulk = btusb_recv_bulk;
  2146. }
  2147. hdev = hci_alloc_dev();
  2148. if (!hdev)
  2149. return -ENOMEM;
  2150. hdev->bus = HCI_USB;
  2151. hci_set_drvdata(hdev, data);
  2152. if (id->driver_info & BTUSB_AMP)
  2153. hdev->dev_type = HCI_AMP;
  2154. else
  2155. hdev->dev_type = HCI_BREDR;
  2156. data->hdev = hdev;
  2157. SET_HCIDEV_DEV(hdev, &intf->dev);
  2158. hdev->open = btusb_open;
  2159. hdev->close = btusb_close;
  2160. hdev->flush = btusb_flush;
  2161. hdev->send = btusb_send_frame;
  2162. hdev->notify = btusb_notify;
  2163. if (id->driver_info & BTUSB_BCM92035)
  2164. hdev->setup = btusb_setup_bcm92035;
  2165. if (id->driver_info & BTUSB_BCM_PATCHRAM) {
  2166. hdev->setup = btusb_setup_bcm_patchram;
  2167. hdev->set_bdaddr = btusb_set_bdaddr_bcm;
  2168. set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
  2169. }
  2170. if (id->driver_info & BTUSB_INTEL) {
  2171. hdev->setup = btusb_setup_intel;
  2172. hdev->set_bdaddr = btusb_set_bdaddr_intel;
  2173. set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
  2174. }
  2175. if (id->driver_info & BTUSB_INTEL_NEW) {
  2176. hdev->send = btusb_send_frame_intel;
  2177. hdev->setup = btusb_setup_intel_new;
  2178. hdev->hw_error = btusb_hw_error_intel;
  2179. hdev->set_bdaddr = btusb_set_bdaddr_intel;
  2180. set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
  2181. }
  2182. if (id->driver_info & BTUSB_MARVELL)
  2183. hdev->set_bdaddr = btusb_set_bdaddr_marvell;
  2184. if (id->driver_info & BTUSB_SWAVE) {
  2185. set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
  2186. set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks);
  2187. }
  2188. if (id->driver_info & BTUSB_INTEL_BOOT)
  2189. set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
  2190. if (id->driver_info & BTUSB_ATH3012) {
  2191. hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
  2192. set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
  2193. }
  2194. if (id->driver_info & BTUSB_AMP) {
  2195. /* AMP controllers do not support SCO packets */
  2196. data->isoc = NULL;
  2197. } else {
  2198. /* Interface numbers are hardcoded in the specification */
  2199. data->isoc = usb_ifnum_to_if(data->udev, 1);
  2200. }
  2201. if (!reset)
  2202. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  2203. if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
  2204. if (!disable_scofix)
  2205. set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
  2206. }
  2207. if (id->driver_info & BTUSB_BROKEN_ISOC)
  2208. data->isoc = NULL;
  2209. if (id->driver_info & BTUSB_DIGIANSWER) {
  2210. data->cmdreq_type = USB_TYPE_VENDOR;
  2211. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  2212. }
  2213. if (id->driver_info & BTUSB_CSR) {
  2214. struct usb_device *udev = data->udev;
  2215. u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
  2216. /* Old firmware would otherwise execute USB reset */
  2217. if (bcdDevice < 0x117)
  2218. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  2219. /* Fake CSR devices with broken commands */
  2220. if (bcdDevice <= 0x100)
  2221. hdev->setup = btusb_setup_csr;
  2222. }
  2223. if (id->driver_info & BTUSB_SNIFFER) {
  2224. struct usb_device *udev = data->udev;
  2225. /* New sniffer firmware has crippled HCI interface */
  2226. if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
  2227. set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
  2228. }
  2229. if (id->driver_info & BTUSB_INTEL_BOOT) {
  2230. /* A bug in the bootloader causes that interrupt interface is
  2231. * only enabled after receiving SetInterface(0, AltSetting=0).
  2232. */
  2233. err = usb_set_interface(data->udev, 0, 0);
  2234. if (err < 0) {
  2235. BT_ERR("failed to set interface 0, alt 0 %d", err);
  2236. hci_free_dev(hdev);
  2237. return err;
  2238. }
  2239. }
  2240. if (data->isoc) {
  2241. err = usb_driver_claim_interface(&btusb_driver,
  2242. data->isoc, data);
  2243. if (err < 0) {
  2244. hci_free_dev(hdev);
  2245. return err;
  2246. }
  2247. }
  2248. err = hci_register_dev(hdev);
  2249. if (err < 0) {
  2250. hci_free_dev(hdev);
  2251. return err;
  2252. }
  2253. usb_set_intfdata(intf, data);
  2254. return 0;
  2255. }
  2256. static void btusb_disconnect(struct usb_interface *intf)
  2257. {
  2258. struct btusb_data *data = usb_get_intfdata(intf);
  2259. struct hci_dev *hdev;
  2260. BT_DBG("intf %p", intf);
  2261. if (!data)
  2262. return;
  2263. hdev = data->hdev;
  2264. usb_set_intfdata(data->intf, NULL);
  2265. if (data->isoc)
  2266. usb_set_intfdata(data->isoc, NULL);
  2267. hci_unregister_dev(hdev);
  2268. if (intf == data->isoc)
  2269. usb_driver_release_interface(&btusb_driver, data->intf);
  2270. else if (data->isoc)
  2271. usb_driver_release_interface(&btusb_driver, data->isoc);
  2272. hci_free_dev(hdev);
  2273. }
  2274. #ifdef CONFIG_PM
  2275. static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
  2276. {
  2277. struct btusb_data *data = usb_get_intfdata(intf);
  2278. BT_DBG("intf %p", intf);
  2279. if (data->suspend_count++)
  2280. return 0;
  2281. spin_lock_irq(&data->txlock);
  2282. if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
  2283. set_bit(BTUSB_SUSPENDING, &data->flags);
  2284. spin_unlock_irq(&data->txlock);
  2285. } else {
  2286. spin_unlock_irq(&data->txlock);
  2287. data->suspend_count--;
  2288. return -EBUSY;
  2289. }
  2290. cancel_work_sync(&data->work);
  2291. btusb_stop_traffic(data);
  2292. usb_kill_anchored_urbs(&data->tx_anchor);
  2293. return 0;
  2294. }
  2295. static void play_deferred(struct btusb_data *data)
  2296. {
  2297. struct urb *urb;
  2298. int err;
  2299. while ((urb = usb_get_from_anchor(&data->deferred))) {
  2300. err = usb_submit_urb(urb, GFP_ATOMIC);
  2301. if (err < 0)
  2302. break;
  2303. data->tx_in_flight++;
  2304. }
  2305. usb_scuttle_anchored_urbs(&data->deferred);
  2306. }
  2307. static int btusb_resume(struct usb_interface *intf)
  2308. {
  2309. struct btusb_data *data = usb_get_intfdata(intf);
  2310. struct hci_dev *hdev = data->hdev;
  2311. int err = 0;
  2312. BT_DBG("intf %p", intf);
  2313. if (--data->suspend_count)
  2314. return 0;
  2315. if (!test_bit(HCI_RUNNING, &hdev->flags))
  2316. goto done;
  2317. if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
  2318. err = btusb_submit_intr_urb(hdev, GFP_NOIO);
  2319. if (err < 0) {
  2320. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  2321. goto failed;
  2322. }
  2323. }
  2324. if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
  2325. err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
  2326. if (err < 0) {
  2327. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  2328. goto failed;
  2329. }
  2330. btusb_submit_bulk_urb(hdev, GFP_NOIO);
  2331. }
  2332. if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
  2333. if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
  2334. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  2335. else
  2336. btusb_submit_isoc_urb(hdev, GFP_NOIO);
  2337. }
  2338. spin_lock_irq(&data->txlock);
  2339. play_deferred(data);
  2340. clear_bit(BTUSB_SUSPENDING, &data->flags);
  2341. spin_unlock_irq(&data->txlock);
  2342. schedule_work(&data->work);
  2343. return 0;
  2344. failed:
  2345. usb_scuttle_anchored_urbs(&data->deferred);
  2346. done:
  2347. spin_lock_irq(&data->txlock);
  2348. clear_bit(BTUSB_SUSPENDING, &data->flags);
  2349. spin_unlock_irq(&data->txlock);
  2350. return err;
  2351. }
  2352. #endif
  2353. static struct usb_driver btusb_driver = {
  2354. .name = "btusb",
  2355. .probe = btusb_probe,
  2356. .disconnect = btusb_disconnect,
  2357. #ifdef CONFIG_PM
  2358. .suspend = btusb_suspend,
  2359. .resume = btusb_resume,
  2360. #endif
  2361. .id_table = btusb_table,
  2362. .supports_autosuspend = 1,
  2363. .disable_hub_initiated_lpm = 1,
  2364. };
  2365. module_usb_driver(btusb_driver);
  2366. module_param(disable_scofix, bool, 0644);
  2367. MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
  2368. module_param(force_scofix, bool, 0644);
  2369. MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
  2370. module_param(reset, bool, 0644);
  2371. MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
  2372. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
  2373. MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
  2374. MODULE_VERSION(VERSION);
  2375. MODULE_LICENSE("GPL");