btusb.c 76 KB

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