btusb.c 75 KB

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