1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Generic Bluetooth USB driver
6 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
10 #include <linux/module.h>
11 #include <linux/usb.h>
12 #include <linux/usb/quirks.h>
13 #include <linux/firmware.h>
14 #include <linux/iopoll.h>
15 #include <linux/of_device.h>
16 #include <linux/of_irq.h>
17 #include <linux/suspend.h>
18 #include <linux/gpio/consumer.h>
19 #include <linux/debugfs.h>
20 #include <asm/unaligned.h>
22 #include <net/bluetooth/bluetooth.h>
23 #include <net/bluetooth/hci_core.h>
32 static bool disable_scofix;
33 static bool force_scofix;
34 static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND);
35 static bool reset = true;
37 static struct usb_driver btusb_driver;
39 #define BTUSB_IGNORE BIT(0)
40 #define BTUSB_DIGIANSWER BIT(1)
41 #define BTUSB_CSR BIT(2)
42 #define BTUSB_SNIFFER BIT(3)
43 #define BTUSB_BCM92035 BIT(4)
44 #define BTUSB_BROKEN_ISOC BIT(5)
45 #define BTUSB_WRONG_SCO_MTU BIT(6)
46 #define BTUSB_ATH3012 BIT(7)
47 #define BTUSB_INTEL_COMBINED BIT(8)
48 #define BTUSB_INTEL_BOOT BIT(9)
49 #define BTUSB_BCM_PATCHRAM BIT(10)
50 #define BTUSB_MARVELL BIT(11)
51 #define BTUSB_SWAVE BIT(12)
52 #define BTUSB_AMP BIT(13)
53 #define BTUSB_QCA_ROME BIT(14)
54 #define BTUSB_BCM_APPLE BIT(15)
55 #define BTUSB_REALTEK BIT(16)
56 #define BTUSB_BCM2045 BIT(17)
57 #define BTUSB_IFNUM_2 BIT(18)
58 #define BTUSB_CW6622 BIT(19)
59 #define BTUSB_MEDIATEK BIT(20)
60 #define BTUSB_WIDEBAND_SPEECH BIT(21)
61 #define BTUSB_VALID_LE_STATES BIT(22)
62 #define BTUSB_QCA_WCN6855 BIT(23)
63 #define BTUSB_INTEL_BROKEN_SHUTDOWN_LED BIT(24)
64 #define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25)
65 #define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26)
67 static const struct usb_device_id btusb_table[] = {
68 /* Generic Bluetooth USB device */
69 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
71 /* Generic Bluetooth AMP device */
72 { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP },
74 /* Generic Bluetooth USB interface */
75 { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) },
77 /* Apple-specific (Broadcom) devices */
78 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01),
79 .driver_info = BTUSB_BCM_APPLE | BTUSB_IFNUM_2 },
81 /* MediaTek MT76x0E */
82 { USB_DEVICE(0x0e8d, 0x763f) },
84 /* Broadcom SoftSailing reporting vendor specific */
85 { USB_DEVICE(0x0a5c, 0x21e1) },
87 /* Apple MacBookPro 7,1 */
88 { USB_DEVICE(0x05ac, 0x8213) },
91 { USB_DEVICE(0x05ac, 0x8215) },
93 /* Apple MacBookPro6,2 */
94 { USB_DEVICE(0x05ac, 0x8218) },
96 /* Apple MacBookAir3,1, MacBookAir3,2 */
97 { USB_DEVICE(0x05ac, 0x821b) },
99 /* Apple MacBookAir4,1 */
100 { USB_DEVICE(0x05ac, 0x821f) },
102 /* Apple MacBookPro8,2 */
103 { USB_DEVICE(0x05ac, 0x821a) },
105 /* Apple MacMini5,1 */
106 { USB_DEVICE(0x05ac, 0x8281) },
108 /* AVM BlueFRITZ! USB v2.0 */
109 { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE },
111 /* Bluetooth Ultraport Module from IBM */
112 { USB_DEVICE(0x04bf, 0x030a) },
114 /* ALPS Modules with non-standard id */
115 { USB_DEVICE(0x044e, 0x3001) },
116 { USB_DEVICE(0x044e, 0x3002) },
118 /* Ericsson with non-standard id */
119 { USB_DEVICE(0x0bdb, 0x1002) },
121 /* Canyon CN-BTU1 with HID interfaces */
122 { USB_DEVICE(0x0c10, 0x0000) },
124 /* Broadcom BCM20702B0 (Dynex/Insignia) */
125 { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM },
127 /* Broadcom BCM43142A0 (Foxconn/Lenovo) */
128 { USB_VENDOR_AND_INTERFACE_INFO(0x105b, 0xff, 0x01, 0x01),
129 .driver_info = BTUSB_BCM_PATCHRAM },
131 /* Broadcom BCM920703 (HTC Vive) */
132 { USB_VENDOR_AND_INTERFACE_INFO(0x0bb4, 0xff, 0x01, 0x01),
133 .driver_info = BTUSB_BCM_PATCHRAM },
135 /* Foxconn - Hon Hai */
136 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
137 .driver_info = BTUSB_BCM_PATCHRAM },
139 /* Lite-On Technology - Broadcom based */
140 { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
141 .driver_info = BTUSB_BCM_PATCHRAM },
143 /* Broadcom devices with vendor specific id */
144 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
145 .driver_info = BTUSB_BCM_PATCHRAM },
147 /* ASUSTek Computer - Broadcom based */
148 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
149 .driver_info = BTUSB_BCM_PATCHRAM },
151 /* Belkin F8065bf - Broadcom based */
152 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01),
153 .driver_info = BTUSB_BCM_PATCHRAM },
155 /* IMC Networks - Broadcom based */
156 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01),
157 .driver_info = BTUSB_BCM_PATCHRAM },
159 /* Dell Computer - Broadcom based */
160 { USB_VENDOR_AND_INTERFACE_INFO(0x413c, 0xff, 0x01, 0x01),
161 .driver_info = BTUSB_BCM_PATCHRAM },
163 /* Toshiba Corp - Broadcom based */
164 { USB_VENDOR_AND_INTERFACE_INFO(0x0930, 0xff, 0x01, 0x01),
165 .driver_info = BTUSB_BCM_PATCHRAM },
167 /* Intel Bluetooth USB Bootloader (RAM module) */
168 { USB_DEVICE(0x8087, 0x0a5a),
169 .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC },
171 { } /* Terminating entry */
174 MODULE_DEVICE_TABLE(usb, btusb_table);
176 static const struct usb_device_id blacklist_table[] = {
177 /* CSR BlueCore devices */
178 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
180 /* Broadcom BCM2033 without firmware */
181 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
183 /* Broadcom BCM2045 devices */
184 { USB_DEVICE(0x0a5c, 0x2045), .driver_info = BTUSB_BCM2045 },
186 /* Atheros 3011 with sflash firmware */
187 { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
188 { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
189 { USB_DEVICE(0x04f2, 0xaff1), .driver_info = BTUSB_IGNORE },
190 { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
191 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
192 { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
193 { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
195 /* Atheros AR9285 Malbec with sflash firmware */
196 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
198 /* Atheros 3012 with sflash firmware */
199 { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
200 { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
201 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
202 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
203 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
204 { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 },
205 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
206 { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 },
207 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
208 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
209 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
210 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
211 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
212 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
213 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
214 { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 },
215 { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
216 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
217 { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 },
218 { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 },
219 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
220 { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 },
221 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
222 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
223 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
224 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
225 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
226 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
227 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
228 { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
229 { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 },
230 { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
231 { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
232 { USB_DEVICE(0x0cf3, 0x817b), .driver_info = BTUSB_ATH3012 },
233 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
234 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
235 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
236 { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
237 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
238 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
239 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
240 { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 },
241 { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
242 { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
243 { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
244 { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
245 { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 },
246 { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 },
247 { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 },
248 { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 },
250 /* Atheros AR5BBU12 with sflash firmware */
251 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
253 /* Atheros AR5BBU12 with sflash firmware */
254 { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
255 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
257 /* QCA ROME chipset */
258 { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME |
259 BTUSB_WIDEBAND_SPEECH },
260 { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME |
261 BTUSB_WIDEBAND_SPEECH },
262 { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME |
263 BTUSB_WIDEBAND_SPEECH },
264 { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME |
265 BTUSB_WIDEBAND_SPEECH },
266 { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME |
267 BTUSB_WIDEBAND_SPEECH },
268 { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME |
269 BTUSB_WIDEBAND_SPEECH },
270 { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME |
271 BTUSB_WIDEBAND_SPEECH },
272 { USB_DEVICE(0x0cf3, 0xe500), .driver_info = BTUSB_QCA_ROME |
273 BTUSB_WIDEBAND_SPEECH },
274 { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME |
275 BTUSB_WIDEBAND_SPEECH },
276 { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME |
277 BTUSB_WIDEBAND_SPEECH },
278 { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME |
279 BTUSB_WIDEBAND_SPEECH },
280 { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME |
281 BTUSB_WIDEBAND_SPEECH },
282 { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME |
283 BTUSB_WIDEBAND_SPEECH },
284 { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME |
285 BTUSB_WIDEBAND_SPEECH },
286 { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME |
287 BTUSB_WIDEBAND_SPEECH },
288 { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME |
289 BTUSB_WIDEBAND_SPEECH },
290 { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME |
291 BTUSB_WIDEBAND_SPEECH },
292 { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME |
293 BTUSB_WIDEBAND_SPEECH },
294 { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME |
295 BTUSB_WIDEBAND_SPEECH },
297 /* QCA WCN6855 chipset */
298 { USB_DEVICE(0x0cf3, 0xe600), .driver_info = BTUSB_QCA_WCN6855 |
299 BTUSB_WIDEBAND_SPEECH |
300 BTUSB_VALID_LE_STATES },
301 { USB_DEVICE(0x0489, 0xe0cc), .driver_info = BTUSB_QCA_WCN6855 |
302 BTUSB_WIDEBAND_SPEECH |
303 BTUSB_VALID_LE_STATES },
304 { USB_DEVICE(0x0489, 0xe0d6), .driver_info = BTUSB_QCA_WCN6855 |
305 BTUSB_WIDEBAND_SPEECH |
306 BTUSB_VALID_LE_STATES },
307 { USB_DEVICE(0x0489, 0xe0e3), .driver_info = BTUSB_QCA_WCN6855 |
308 BTUSB_WIDEBAND_SPEECH |
309 BTUSB_VALID_LE_STATES },
310 { USB_DEVICE(0x10ab, 0x9309), .driver_info = BTUSB_QCA_WCN6855 |
311 BTUSB_WIDEBAND_SPEECH |
312 BTUSB_VALID_LE_STATES },
313 { USB_DEVICE(0x10ab, 0x9409), .driver_info = BTUSB_QCA_WCN6855 |
314 BTUSB_WIDEBAND_SPEECH |
315 BTUSB_VALID_LE_STATES },
316 { USB_DEVICE(0x0489, 0xe0d0), .driver_info = BTUSB_QCA_WCN6855 |
317 BTUSB_WIDEBAND_SPEECH |
318 BTUSB_VALID_LE_STATES },
320 /* QCA WCN785x chipset */
321 { USB_DEVICE(0x0cf3, 0xe700), .driver_info = BTUSB_QCA_WCN6855 |
322 BTUSB_WIDEBAND_SPEECH |
323 BTUSB_VALID_LE_STATES },
325 /* Broadcom BCM2035 */
326 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
327 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
328 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
330 /* Broadcom BCM2045 */
331 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
332 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
334 /* IBM/Lenovo ThinkPad with Broadcom chip */
335 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
336 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
338 /* HP laptop with Broadcom chip */
339 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
341 /* Dell laptop with Broadcom chip */
342 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
344 /* Dell Wireless 370 and 410 devices */
345 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
346 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
348 /* Belkin F8T012 and F8T013 devices */
349 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
350 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
352 /* Asus WL-BTD202 device */
353 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
355 /* Kensington Bluetooth USB adapter */
356 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
358 /* RTX Telecom based adapters with buggy SCO support */
359 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
360 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
362 /* CONWISE Technology based adapters with buggy SCO support */
363 { USB_DEVICE(0x0e5e, 0x6622),
364 .driver_info = BTUSB_BROKEN_ISOC | BTUSB_CW6622},
366 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
367 { USB_DEVICE(0x1310, 0x0001), .driver_info = BTUSB_SWAVE },
369 /* Digianswer devices */
370 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
371 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
373 /* CSR BlueCore Bluetooth Sniffer */
374 { USB_DEVICE(0x0a12, 0x0002),
375 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
377 /* Frontline ComProbe Bluetooth Sniffer */
378 { USB_DEVICE(0x16d3, 0x0002),
379 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
381 /* Marvell Bluetooth devices */
382 { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL },
383 { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL },
384 { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL },
386 /* Intel Bluetooth devices */
387 { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_COMBINED },
388 { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_COMBINED },
389 { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_COMBINED },
390 { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_COMBINED },
391 { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_COMBINED },
392 { USB_DEVICE(0x8087, 0x0035), .driver_info = BTUSB_INTEL_COMBINED },
393 { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR },
394 { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED |
395 BTUSB_INTEL_NO_WBS_SUPPORT |
396 BTUSB_INTEL_BROKEN_INITIAL_NCMD |
397 BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
398 { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED |
399 BTUSB_INTEL_NO_WBS_SUPPORT |
400 BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
401 { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_COMBINED },
402 { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL_COMBINED |
403 BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
404 { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_COMBINED },
406 /* Other Intel Bluetooth devices */
407 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
408 .driver_info = BTUSB_IGNORE },
410 /* Realtek 8822CE Bluetooth devices */
411 { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK |
412 BTUSB_WIDEBAND_SPEECH },
413 { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK |
414 BTUSB_WIDEBAND_SPEECH },
416 /* Realtek 8852AE Bluetooth devices */
417 { USB_DEVICE(0x0bda, 0x2852), .driver_info = BTUSB_REALTEK |
418 BTUSB_WIDEBAND_SPEECH },
419 { USB_DEVICE(0x0bda, 0xc852), .driver_info = BTUSB_REALTEK |
420 BTUSB_WIDEBAND_SPEECH },
421 { USB_DEVICE(0x0bda, 0x385a), .driver_info = BTUSB_REALTEK |
422 BTUSB_WIDEBAND_SPEECH },
423 { USB_DEVICE(0x0bda, 0x4852), .driver_info = BTUSB_REALTEK |
424 BTUSB_WIDEBAND_SPEECH },
425 { USB_DEVICE(0x04c5, 0x165c), .driver_info = BTUSB_REALTEK |
426 BTUSB_WIDEBAND_SPEECH },
427 { USB_DEVICE(0x04ca, 0x4006), .driver_info = BTUSB_REALTEK |
428 BTUSB_WIDEBAND_SPEECH },
429 { USB_DEVICE(0x0cb8, 0xc549), .driver_info = BTUSB_REALTEK |
430 BTUSB_WIDEBAND_SPEECH },
432 /* Realtek 8852CE Bluetooth devices */
433 { USB_DEVICE(0x04ca, 0x4007), .driver_info = BTUSB_REALTEK |
434 BTUSB_WIDEBAND_SPEECH },
435 { USB_DEVICE(0x04c5, 0x1675), .driver_info = BTUSB_REALTEK |
436 BTUSB_WIDEBAND_SPEECH },
437 { USB_DEVICE(0x0cb8, 0xc558), .driver_info = BTUSB_REALTEK |
438 BTUSB_WIDEBAND_SPEECH },
439 { USB_DEVICE(0x13d3, 0x3587), .driver_info = BTUSB_REALTEK |
440 BTUSB_WIDEBAND_SPEECH },
441 { USB_DEVICE(0x13d3, 0x3586), .driver_info = BTUSB_REALTEK |
442 BTUSB_WIDEBAND_SPEECH },
443 { USB_DEVICE(0x13d3, 0x3592), .driver_info = BTUSB_REALTEK |
444 BTUSB_WIDEBAND_SPEECH },
446 /* Realtek Bluetooth devices */
447 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
448 .driver_info = BTUSB_REALTEK },
450 /* MediaTek Bluetooth devices */
451 { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01),
452 .driver_info = BTUSB_MEDIATEK |
453 BTUSB_WIDEBAND_SPEECH |
454 BTUSB_VALID_LE_STATES },
456 /* Additional MediaTek MT7615E Bluetooth devices */
457 { USB_DEVICE(0x13d3, 0x3560), .driver_info = BTUSB_MEDIATEK},
459 /* Additional MediaTek MT7663 Bluetooth devices */
460 { USB_DEVICE(0x043e, 0x310c), .driver_info = BTUSB_MEDIATEK |
461 BTUSB_WIDEBAND_SPEECH |
462 BTUSB_VALID_LE_STATES },
464 /* Additional MediaTek MT7668 Bluetooth devices */
465 { USB_DEVICE(0x043e, 0x3109), .driver_info = BTUSB_MEDIATEK |
466 BTUSB_WIDEBAND_SPEECH |
467 BTUSB_VALID_LE_STATES },
469 /* Additional MediaTek MT7921 Bluetooth devices */
470 { USB_DEVICE(0x0489, 0xe0c8), .driver_info = BTUSB_MEDIATEK |
471 BTUSB_WIDEBAND_SPEECH |
472 BTUSB_VALID_LE_STATES },
473 { USB_DEVICE(0x0489, 0xe0e0), .driver_info = BTUSB_MEDIATEK |
474 BTUSB_WIDEBAND_SPEECH |
475 BTUSB_VALID_LE_STATES },
476 { USB_DEVICE(0x04ca, 0x3802), .driver_info = BTUSB_MEDIATEK |
477 BTUSB_WIDEBAND_SPEECH |
478 BTUSB_VALID_LE_STATES },
479 { USB_DEVICE(0x13d3, 0x3563), .driver_info = BTUSB_MEDIATEK |
480 BTUSB_WIDEBAND_SPEECH |
481 BTUSB_VALID_LE_STATES },
482 { USB_DEVICE(0x13d3, 0x3564), .driver_info = BTUSB_MEDIATEK |
483 BTUSB_WIDEBAND_SPEECH |
484 BTUSB_VALID_LE_STATES },
485 { USB_DEVICE(0x13d3, 0x3567), .driver_info = BTUSB_MEDIATEK |
486 BTUSB_WIDEBAND_SPEECH |
487 BTUSB_VALID_LE_STATES },
488 { USB_DEVICE(0x13d3, 0x3578), .driver_info = BTUSB_MEDIATEK |
489 BTUSB_WIDEBAND_SPEECH |
490 BTUSB_VALID_LE_STATES },
491 { USB_DEVICE(0x13d3, 0x3583), .driver_info = BTUSB_MEDIATEK |
492 BTUSB_WIDEBAND_SPEECH |
493 BTUSB_VALID_LE_STATES },
494 { USB_DEVICE(0x0489, 0xe0cd), .driver_info = BTUSB_MEDIATEK |
495 BTUSB_WIDEBAND_SPEECH |
496 BTUSB_VALID_LE_STATES },
497 { USB_DEVICE(0x0e8d, 0x0608), .driver_info = BTUSB_MEDIATEK |
498 BTUSB_WIDEBAND_SPEECH |
499 BTUSB_VALID_LE_STATES },
501 /* MediaTek MT7922A Bluetooth devices */
502 { USB_DEVICE(0x0489, 0xe0d8), .driver_info = BTUSB_MEDIATEK |
503 BTUSB_WIDEBAND_SPEECH |
504 BTUSB_VALID_LE_STATES },
505 { USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK |
506 BTUSB_WIDEBAND_SPEECH |
507 BTUSB_VALID_LE_STATES },
508 { USB_DEVICE(0x13d3, 0x3568), .driver_info = BTUSB_MEDIATEK |
509 BTUSB_WIDEBAND_SPEECH |
510 BTUSB_VALID_LE_STATES },
511 { USB_DEVICE(0x0489, 0xe0e2), .driver_info = BTUSB_MEDIATEK |
512 BTUSB_WIDEBAND_SPEECH |
513 BTUSB_VALID_LE_STATES },
515 /* Additional Realtek 8723AE Bluetooth devices */
516 { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK },
517 { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK },
519 /* Additional Realtek 8723BE Bluetooth devices */
520 { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK },
521 { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK },
522 { USB_DEVICE(0x04f2, 0xb49f), .driver_info = BTUSB_REALTEK },
523 { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK },
524 { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK },
525 { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK },
526 { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK },
528 /* Additional Realtek 8723BU Bluetooth devices */
529 { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK },
531 /* Additional Realtek 8723DE Bluetooth devices */
532 { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK },
533 { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK },
535 /* Additional Realtek 8761BUV Bluetooth devices */
536 { USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK |
537 BTUSB_WIDEBAND_SPEECH },
538 { USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK |
539 BTUSB_WIDEBAND_SPEECH },
540 { USB_DEVICE(0x2550, 0x8761), .driver_info = BTUSB_REALTEK |
541 BTUSB_WIDEBAND_SPEECH },
542 { USB_DEVICE(0x0bda, 0x8771), .driver_info = BTUSB_REALTEK |
543 BTUSB_WIDEBAND_SPEECH },
544 { USB_DEVICE(0x7392, 0xc611), .driver_info = BTUSB_REALTEK |
545 BTUSB_WIDEBAND_SPEECH },
547 /* Additional Realtek 8821AE Bluetooth devices */
548 { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK },
549 { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK },
550 { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK },
551 { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK },
552 { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK },
554 /* Additional Realtek 8822BE Bluetooth devices */
555 { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK },
556 { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK },
558 /* Additional Realtek 8822CE Bluetooth devices */
559 { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK |
560 BTUSB_WIDEBAND_SPEECH },
561 { USB_DEVICE(0x04c5, 0x161f), .driver_info = BTUSB_REALTEK |
562 BTUSB_WIDEBAND_SPEECH },
563 { USB_DEVICE(0x0b05, 0x18ef), .driver_info = BTUSB_REALTEK |
564 BTUSB_WIDEBAND_SPEECH },
565 { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK |
566 BTUSB_WIDEBAND_SPEECH },
567 { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK |
568 BTUSB_WIDEBAND_SPEECH },
569 { USB_DEVICE(0x13d3, 0x3553), .driver_info = BTUSB_REALTEK |
570 BTUSB_WIDEBAND_SPEECH },
571 { USB_DEVICE(0x13d3, 0x3555), .driver_info = BTUSB_REALTEK |
572 BTUSB_WIDEBAND_SPEECH },
573 { USB_DEVICE(0x2ff8, 0x3051), .driver_info = BTUSB_REALTEK |
574 BTUSB_WIDEBAND_SPEECH },
575 { USB_DEVICE(0x1358, 0xc123), .driver_info = BTUSB_REALTEK |
576 BTUSB_WIDEBAND_SPEECH },
577 { USB_DEVICE(0x0bda, 0xc123), .driver_info = BTUSB_REALTEK |
578 BTUSB_WIDEBAND_SPEECH },
579 { USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK |
580 BTUSB_WIDEBAND_SPEECH },
582 /* Silicon Wave based devices */
583 { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE },
585 { } /* Terminating entry */
588 /* The Bluetooth USB module build into some devices needs to be reset on resume,
589 * this is a problem with the platform (likely shutting off all power) not with
590 * the module itself. So we use a DMI list to match known broken platforms.
592 static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
594 /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */
596 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
597 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"),
601 /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */
603 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
604 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"),
608 /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */
610 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
611 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"),
617 #define BTUSB_MAX_ISOC_FRAMES 10
619 #define BTUSB_INTR_RUNNING 0
620 #define BTUSB_BULK_RUNNING 1
621 #define BTUSB_ISOC_RUNNING 2
622 #define BTUSB_SUSPENDING 3
623 #define BTUSB_DID_ISO_RESUME 4
624 #define BTUSB_BOOTLOADER 5
625 #define BTUSB_DOWNLOADING 6
626 #define BTUSB_FIRMWARE_LOADED 7
627 #define BTUSB_FIRMWARE_FAILED 8
628 #define BTUSB_BOOTING 9
629 #define BTUSB_DIAG_RUNNING 10
630 #define BTUSB_OOB_WAKE_ENABLED 11
631 #define BTUSB_HW_RESET_ACTIVE 12
632 #define BTUSB_TX_WAIT_VND_EVT 13
633 #define BTUSB_WAKEUP_AUTOSUSPEND 14
634 #define BTUSB_USE_ALT3_FOR_WBS 15
637 struct hci_dev *hdev;
638 struct usb_device *udev;
639 struct usb_interface *intf;
640 struct usb_interface *isoc;
641 struct usb_interface *diag;
648 struct work_struct work;
649 struct work_struct waker;
650 struct delayed_work rx_work;
652 struct sk_buff_head acl_q;
654 struct usb_anchor deferred;
655 struct usb_anchor tx_anchor;
659 struct usb_anchor intr_anchor;
660 struct usb_anchor bulk_anchor;
661 struct usb_anchor isoc_anchor;
662 struct usb_anchor diag_anchor;
663 struct usb_anchor ctrl_anchor;
666 struct sk_buff *evt_skb;
667 struct sk_buff *acl_skb;
668 struct sk_buff *sco_skb;
670 struct usb_endpoint_descriptor *intr_ep;
671 struct usb_endpoint_descriptor *bulk_tx_ep;
672 struct usb_endpoint_descriptor *bulk_rx_ep;
673 struct usb_endpoint_descriptor *isoc_tx_ep;
674 struct usb_endpoint_descriptor *isoc_rx_ep;
675 struct usb_endpoint_descriptor *diag_tx_ep;
676 struct usb_endpoint_descriptor *diag_rx_ep;
678 struct gpio_desc *reset_gpio;
683 unsigned int sco_num;
684 unsigned int air_mode;
685 bool usb_alt6_packet_flow;
689 int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
690 int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb);
691 int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
693 int (*setup_on_usb)(struct hci_dev *hdev);
695 int oob_wake_irq; /* irq for out-of-band wake-on-bt */
696 unsigned cmd_timeout_cnt;
699 static void btusb_intel_cmd_timeout(struct hci_dev *hdev)
701 struct btusb_data *data = hci_get_drvdata(hdev);
702 struct gpio_desc *reset_gpio = data->reset_gpio;
704 if (++data->cmd_timeout_cnt < 5)
708 bt_dev_err(hdev, "No way to reset. Ignoring and continuing");
713 * Toggle the hard reset line if the platform provides one. The reset
714 * is going to yank the device off the USB and then replug. So doing
715 * once is enough. The cleanup is handled correctly on the way out
716 * (standard USB disconnect), and the new device is detected cleanly
717 * and bound to the driver again like it should be.
719 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
720 bt_dev_err(hdev, "last reset failed? Not resetting again");
724 bt_dev_err(hdev, "Initiating HW reset via gpio");
725 gpiod_set_value_cansleep(reset_gpio, 1);
727 gpiod_set_value_cansleep(reset_gpio, 0);
730 static void btusb_rtl_cmd_timeout(struct hci_dev *hdev)
732 struct btusb_data *data = hci_get_drvdata(hdev);
733 struct gpio_desc *reset_gpio = data->reset_gpio;
735 if (++data->cmd_timeout_cnt < 5)
739 bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring");
743 /* Toggle the hard reset line. The Realtek device is going to
744 * yank itself off the USB and then replug. The cleanup is handled
745 * correctly on the way out (standard USB disconnect), and the new
746 * device is detected cleanly and bound to the driver again like
749 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
750 bt_dev_err(hdev, "last reset failed? Not resetting again");
754 bt_dev_err(hdev, "Reset Realtek device via gpio");
755 gpiod_set_value_cansleep(reset_gpio, 1);
757 gpiod_set_value_cansleep(reset_gpio, 0);
760 static void btusb_qca_cmd_timeout(struct hci_dev *hdev)
762 struct btusb_data *data = hci_get_drvdata(hdev);
763 struct gpio_desc *reset_gpio = data->reset_gpio;
766 if (++data->cmd_timeout_cnt < 5)
770 bt_dev_err(hdev, "Reset qca device via bt_en gpio");
772 /* Toggle the hard reset line. The qca bt device is going to
773 * yank itself off the USB and then replug. The cleanup is handled
774 * correctly on the way out (standard USB disconnect), and the new
775 * device is detected cleanly and bound to the driver again like
778 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
779 bt_dev_err(hdev, "last reset failed? Not resetting again");
783 gpiod_set_value_cansleep(reset_gpio, 0);
785 gpiod_set_value_cansleep(reset_gpio, 1);
790 bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device.");
791 /* This is not an unbalanced PM reference since the device will reset */
792 err = usb_autopm_get_interface(data->intf);
794 usb_queue_reset_device(data->intf);
796 bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err);
799 static inline void btusb_free_frags(struct btusb_data *data)
803 spin_lock_irqsave(&data->rxlock, flags);
805 kfree_skb(data->evt_skb);
806 data->evt_skb = NULL;
808 kfree_skb(data->acl_skb);
809 data->acl_skb = NULL;
811 kfree_skb(data->sco_skb);
812 data->sco_skb = NULL;
814 spin_unlock_irqrestore(&data->rxlock, flags);
817 static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
819 if (data->intr_interval) {
820 /* Trigger dequeue immediatelly if an event is received */
821 schedule_delayed_work(&data->rx_work, 0);
824 return data->recv_event(data->hdev, skb);
827 static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
833 spin_lock_irqsave(&data->rxlock, flags);
840 skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC);
846 hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
847 hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE;
850 len = min_t(uint, hci_skb_expect(skb), count);
851 skb_put_data(skb, buffer, len);
855 hci_skb_expect(skb) -= len;
857 if (skb->len == HCI_EVENT_HDR_SIZE) {
858 /* Complete event header */
859 hci_skb_expect(skb) = hci_event_hdr(skb)->plen;
861 if (skb_tailroom(skb) < hci_skb_expect(skb)) {
870 if (!hci_skb_expect(skb)) {
872 btusb_recv_event(data, skb);
878 spin_unlock_irqrestore(&data->rxlock, flags);
883 static int btusb_recv_acl(struct btusb_data *data, struct sk_buff *skb)
885 /* Only queue ACL packet if intr_interval is set as it means
886 * force_poll_sync has been enabled.
888 if (!data->intr_interval)
889 return data->recv_acl(data->hdev, skb);
891 skb_queue_tail(&data->acl_q, skb);
892 schedule_delayed_work(&data->rx_work, data->intr_interval);
897 static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
903 spin_lock_irqsave(&data->rxlock, flags);
910 skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
916 hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT;
917 hci_skb_expect(skb) = HCI_ACL_HDR_SIZE;
920 len = min_t(uint, hci_skb_expect(skb), count);
921 skb_put_data(skb, buffer, len);
925 hci_skb_expect(skb) -= len;
927 if (skb->len == HCI_ACL_HDR_SIZE) {
928 __u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle);
929 __le16 dlen = hci_acl_hdr(skb)->dlen;
932 /* Complete ACL header */
933 hci_skb_expect(skb) = __le16_to_cpu(dlen);
935 /* Detect if ISO packet has been sent over bulk */
936 if (hci_conn_num(data->hdev, ISO_LINK)) {
937 type = hci_conn_lookup_type(data->hdev,
939 if (type == ISO_LINK)
940 hci_skb_pkt_type(skb) = HCI_ISODATA_PKT;
943 if (skb_tailroom(skb) < hci_skb_expect(skb)) {
952 if (!hci_skb_expect(skb)) {
954 btusb_recv_acl(data, skb);
960 spin_unlock_irqrestore(&data->rxlock, flags);
965 static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count)
971 spin_lock_irqsave(&data->rxlock, flags);
978 skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC);
984 hci_skb_pkt_type(skb) = HCI_SCODATA_PKT;
985 hci_skb_expect(skb) = HCI_SCO_HDR_SIZE;
988 len = min_t(uint, hci_skb_expect(skb), count);
989 skb_put_data(skb, buffer, len);
993 hci_skb_expect(skb) -= len;
995 if (skb->len == HCI_SCO_HDR_SIZE) {
996 /* Complete SCO header */
997 hci_skb_expect(skb) = hci_sco_hdr(skb)->dlen;
999 if (skb_tailroom(skb) < hci_skb_expect(skb)) {
1008 if (!hci_skb_expect(skb)) {
1009 /* Complete frame */
1010 hci_recv_frame(data->hdev, skb);
1015 data->sco_skb = skb;
1016 spin_unlock_irqrestore(&data->rxlock, flags);
1021 static void btusb_intr_complete(struct urb *urb)
1023 struct hci_dev *hdev = urb->context;
1024 struct btusb_data *data = hci_get_drvdata(hdev);
1027 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1028 urb->actual_length);
1030 if (!test_bit(HCI_RUNNING, &hdev->flags))
1033 if (urb->status == 0) {
1034 hdev->stat.byte_rx += urb->actual_length;
1036 if (btusb_recv_intr(data, urb->transfer_buffer,
1037 urb->actual_length) < 0) {
1038 bt_dev_err(hdev, "corrupted event packet");
1039 hdev->stat.err_rx++;
1041 } else if (urb->status == -ENOENT) {
1042 /* Avoid suspend failed when usb_kill_urb */
1046 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
1049 usb_mark_last_busy(data->udev);
1050 usb_anchor_urb(urb, &data->intr_anchor);
1052 err = usb_submit_urb(urb, GFP_ATOMIC);
1054 /* -EPERM: urb is being killed;
1055 * -ENODEV: device got disconnected
1057 if (err != -EPERM && err != -ENODEV)
1058 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1061 hci_cmd_sync_cancel(hdev, -err);
1062 usb_unanchor_urb(urb);
1066 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
1068 struct btusb_data *data = hci_get_drvdata(hdev);
1074 BT_DBG("%s", hdev->name);
1079 urb = usb_alloc_urb(0, mem_flags);
1083 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
1085 buf = kmalloc(size, mem_flags);
1091 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
1093 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
1094 btusb_intr_complete, hdev, data->intr_ep->bInterval);
1096 urb->transfer_flags |= URB_FREE_BUFFER;
1098 usb_anchor_urb(urb, &data->intr_anchor);
1100 err = usb_submit_urb(urb, mem_flags);
1102 if (err != -EPERM && err != -ENODEV)
1103 bt_dev_err(hdev, "urb %p submission failed (%d)",
1106 hci_cmd_sync_cancel(hdev, -err);
1107 usb_unanchor_urb(urb);
1110 /* Only initialize intr_interval if URB poll sync is enabled */
1111 if (!data->poll_sync)
1114 /* The units are frames (milliseconds) for full and low speed devices,
1115 * and microframes (1/8 millisecond) for highspeed and SuperSpeed
1118 * This is done once on open/resume so it shouldn't change even if
1119 * force_poll_sync changes.
1121 switch (urb->dev->speed) {
1122 case USB_SPEED_SUPER_PLUS:
1123 case USB_SPEED_SUPER: /* units are 125us */
1124 data->intr_interval = usecs_to_jiffies(urb->interval * 125);
1127 data->intr_interval = msecs_to_jiffies(urb->interval);
1137 static void btusb_bulk_complete(struct urb *urb)
1139 struct hci_dev *hdev = urb->context;
1140 struct btusb_data *data = hci_get_drvdata(hdev);
1143 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1144 urb->actual_length);
1146 if (!test_bit(HCI_RUNNING, &hdev->flags))
1149 if (urb->status == 0) {
1150 hdev->stat.byte_rx += urb->actual_length;
1152 if (data->recv_bulk(data, urb->transfer_buffer,
1153 urb->actual_length) < 0) {
1154 bt_dev_err(hdev, "corrupted ACL packet");
1155 hdev->stat.err_rx++;
1157 } else if (urb->status == -ENOENT) {
1158 /* Avoid suspend failed when usb_kill_urb */
1162 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
1165 usb_anchor_urb(urb, &data->bulk_anchor);
1166 usb_mark_last_busy(data->udev);
1168 err = usb_submit_urb(urb, GFP_ATOMIC);
1170 /* -EPERM: urb is being killed;
1171 * -ENODEV: device got disconnected
1173 if (err != -EPERM && err != -ENODEV)
1174 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1176 usb_unanchor_urb(urb);
1180 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
1182 struct btusb_data *data = hci_get_drvdata(hdev);
1186 int err, size = HCI_MAX_FRAME_SIZE;
1188 BT_DBG("%s", hdev->name);
1190 if (!data->bulk_rx_ep)
1193 urb = usb_alloc_urb(0, mem_flags);
1197 buf = kmalloc(size, mem_flags);
1203 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
1205 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
1206 btusb_bulk_complete, hdev);
1208 urb->transfer_flags |= URB_FREE_BUFFER;
1210 usb_mark_last_busy(data->udev);
1211 usb_anchor_urb(urb, &data->bulk_anchor);
1213 err = usb_submit_urb(urb, mem_flags);
1215 if (err != -EPERM && err != -ENODEV)
1216 bt_dev_err(hdev, "urb %p submission failed (%d)",
1218 usb_unanchor_urb(urb);
1226 static void btusb_isoc_complete(struct urb *urb)
1228 struct hci_dev *hdev = urb->context;
1229 struct btusb_data *data = hci_get_drvdata(hdev);
1232 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1233 urb->actual_length);
1235 if (!test_bit(HCI_RUNNING, &hdev->flags))
1238 if (urb->status == 0) {
1239 for (i = 0; i < urb->number_of_packets; i++) {
1240 unsigned int offset = urb->iso_frame_desc[i].offset;
1241 unsigned int length = urb->iso_frame_desc[i].actual_length;
1243 if (urb->iso_frame_desc[i].status)
1246 hdev->stat.byte_rx += length;
1248 if (btusb_recv_isoc(data, urb->transfer_buffer + offset,
1250 bt_dev_err(hdev, "corrupted SCO packet");
1251 hdev->stat.err_rx++;
1254 } else if (urb->status == -ENOENT) {
1255 /* Avoid suspend failed when usb_kill_urb */
1259 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
1262 usb_anchor_urb(urb, &data->isoc_anchor);
1264 err = usb_submit_urb(urb, GFP_ATOMIC);
1266 /* -EPERM: urb is being killed;
1267 * -ENODEV: device got disconnected
1269 if (err != -EPERM && err != -ENODEV)
1270 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1272 usb_unanchor_urb(urb);
1276 static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len,
1277 int mtu, struct btusb_data *data)
1280 unsigned int interval;
1282 BT_DBG("len %d mtu %d", len, mtu);
1284 /* For mSBC ALT 6 setting the host will send the packet at continuous
1285 * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting
1286 * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets.
1287 * To maintain the rate we send 63bytes of usb packets alternatively for
1288 * 7ms and 8ms to maintain the rate as 7.5ms.
1290 if (data->usb_alt6_packet_flow) {
1292 data->usb_alt6_packet_flow = false;
1295 data->usb_alt6_packet_flow = true;
1298 for (i = 0; i < interval; i++) {
1299 urb->iso_frame_desc[i].offset = offset;
1300 urb->iso_frame_desc[i].length = offset;
1303 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
1304 urb->iso_frame_desc[i].offset = offset;
1305 urb->iso_frame_desc[i].length = len;
1309 urb->number_of_packets = i;
1312 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
1316 BT_DBG("len %d mtu %d", len, mtu);
1318 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
1319 i++, offset += mtu, len -= mtu) {
1320 urb->iso_frame_desc[i].offset = offset;
1321 urb->iso_frame_desc[i].length = mtu;
1324 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
1325 urb->iso_frame_desc[i].offset = offset;
1326 urb->iso_frame_desc[i].length = len;
1330 urb->number_of_packets = i;
1333 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
1335 struct btusb_data *data = hci_get_drvdata(hdev);
1341 BT_DBG("%s", hdev->name);
1343 if (!data->isoc_rx_ep)
1346 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
1350 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
1351 BTUSB_MAX_ISOC_FRAMES;
1353 buf = kmalloc(size, mem_flags);
1359 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
1361 usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
1362 hdev, data->isoc_rx_ep->bInterval);
1364 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
1366 __fill_isoc_descriptor(urb, size,
1367 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
1369 usb_anchor_urb(urb, &data->isoc_anchor);
1371 err = usb_submit_urb(urb, mem_flags);
1373 if (err != -EPERM && err != -ENODEV)
1374 bt_dev_err(hdev, "urb %p submission failed (%d)",
1376 usb_unanchor_urb(urb);
1384 static void btusb_diag_complete(struct urb *urb)
1386 struct hci_dev *hdev = urb->context;
1387 struct btusb_data *data = hci_get_drvdata(hdev);
1390 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1391 urb->actual_length);
1393 if (urb->status == 0) {
1394 struct sk_buff *skb;
1396 skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC);
1398 skb_put_data(skb, urb->transfer_buffer,
1399 urb->actual_length);
1400 hci_recv_diag(hdev, skb);
1402 } else if (urb->status == -ENOENT) {
1403 /* Avoid suspend failed when usb_kill_urb */
1407 if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags))
1410 usb_anchor_urb(urb, &data->diag_anchor);
1411 usb_mark_last_busy(data->udev);
1413 err = usb_submit_urb(urb, GFP_ATOMIC);
1415 /* -EPERM: urb is being killed;
1416 * -ENODEV: device got disconnected
1418 if (err != -EPERM && err != -ENODEV)
1419 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1421 usb_unanchor_urb(urb);
1425 static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags)
1427 struct btusb_data *data = hci_get_drvdata(hdev);
1431 int err, size = HCI_MAX_FRAME_SIZE;
1433 BT_DBG("%s", hdev->name);
1435 if (!data->diag_rx_ep)
1438 urb = usb_alloc_urb(0, mem_flags);
1442 buf = kmalloc(size, mem_flags);
1448 pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress);
1450 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
1451 btusb_diag_complete, hdev);
1453 urb->transfer_flags |= URB_FREE_BUFFER;
1455 usb_mark_last_busy(data->udev);
1456 usb_anchor_urb(urb, &data->diag_anchor);
1458 err = usb_submit_urb(urb, mem_flags);
1460 if (err != -EPERM && err != -ENODEV)
1461 bt_dev_err(hdev, "urb %p submission failed (%d)",
1463 usb_unanchor_urb(urb);
1471 static void btusb_tx_complete(struct urb *urb)
1473 struct sk_buff *skb = urb->context;
1474 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
1475 struct btusb_data *data = hci_get_drvdata(hdev);
1476 unsigned long flags;
1478 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1479 urb->actual_length);
1481 if (!test_bit(HCI_RUNNING, &hdev->flags))
1485 hdev->stat.byte_tx += urb->transfer_buffer_length;
1487 if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT)
1488 hci_cmd_sync_cancel(hdev, -urb->status);
1489 hdev->stat.err_tx++;
1493 spin_lock_irqsave(&data->txlock, flags);
1494 data->tx_in_flight--;
1495 spin_unlock_irqrestore(&data->txlock, flags);
1497 kfree(urb->setup_packet);
1502 static void btusb_isoc_tx_complete(struct urb *urb)
1504 struct sk_buff *skb = urb->context;
1505 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
1507 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1508 urb->actual_length);
1510 if (!test_bit(HCI_RUNNING, &hdev->flags))
1514 hdev->stat.byte_tx += urb->transfer_buffer_length;
1516 hdev->stat.err_tx++;
1519 kfree(urb->setup_packet);
1524 static int btusb_open(struct hci_dev *hdev)
1526 struct btusb_data *data = hci_get_drvdata(hdev);
1529 BT_DBG("%s", hdev->name);
1531 err = usb_autopm_get_interface(data->intf);
1535 /* Patching USB firmware files prior to starting any URBs of HCI path
1536 * It is more safe to use USB bulk channel for downloading USB patch
1538 if (data->setup_on_usb) {
1539 err = data->setup_on_usb(hdev);
1544 data->intf->needs_remote_wakeup = 1;
1546 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
1549 err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
1553 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
1555 usb_kill_anchored_urbs(&data->intr_anchor);
1559 set_bit(BTUSB_BULK_RUNNING, &data->flags);
1560 btusb_submit_bulk_urb(hdev, GFP_KERNEL);
1563 if (!btusb_submit_diag_urb(hdev, GFP_KERNEL))
1564 set_bit(BTUSB_DIAG_RUNNING, &data->flags);
1568 usb_autopm_put_interface(data->intf);
1572 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1574 usb_autopm_put_interface(data->intf);
1578 static void btusb_stop_traffic(struct btusb_data *data)
1580 usb_kill_anchored_urbs(&data->intr_anchor);
1581 usb_kill_anchored_urbs(&data->bulk_anchor);
1582 usb_kill_anchored_urbs(&data->isoc_anchor);
1583 usb_kill_anchored_urbs(&data->diag_anchor);
1584 usb_kill_anchored_urbs(&data->ctrl_anchor);
1587 static int btusb_close(struct hci_dev *hdev)
1589 struct btusb_data *data = hci_get_drvdata(hdev);
1592 BT_DBG("%s", hdev->name);
1594 cancel_delayed_work(&data->rx_work);
1595 cancel_work_sync(&data->work);
1596 cancel_work_sync(&data->waker);
1598 skb_queue_purge(&data->acl_q);
1600 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1601 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
1602 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1603 clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
1605 btusb_stop_traffic(data);
1606 btusb_free_frags(data);
1608 err = usb_autopm_get_interface(data->intf);
1612 data->intf->needs_remote_wakeup = 0;
1614 /* Enable remote wake up for auto-suspend */
1615 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags))
1616 data->intf->needs_remote_wakeup = 1;
1618 usb_autopm_put_interface(data->intf);
1621 usb_scuttle_anchored_urbs(&data->deferred);
1625 static int btusb_flush(struct hci_dev *hdev)
1627 struct btusb_data *data = hci_get_drvdata(hdev);
1629 BT_DBG("%s", hdev->name);
1631 cancel_delayed_work(&data->rx_work);
1633 skb_queue_purge(&data->acl_q);
1635 usb_kill_anchored_urbs(&data->tx_anchor);
1636 btusb_free_frags(data);
1641 static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
1643 struct btusb_data *data = hci_get_drvdata(hdev);
1644 struct usb_ctrlrequest *dr;
1648 urb = usb_alloc_urb(0, GFP_KERNEL);
1650 return ERR_PTR(-ENOMEM);
1652 dr = kmalloc(sizeof(*dr), GFP_KERNEL);
1655 return ERR_PTR(-ENOMEM);
1658 dr->bRequestType = data->cmdreq_type;
1659 dr->bRequest = data->cmdreq;
1662 dr->wLength = __cpu_to_le16(skb->len);
1664 pipe = usb_sndctrlpipe(data->udev, 0x00);
1666 usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
1667 skb->data, skb->len, btusb_tx_complete, skb);
1669 skb->dev = (void *)hdev;
1674 static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
1676 struct btusb_data *data = hci_get_drvdata(hdev);
1680 if (!data->bulk_tx_ep)
1681 return ERR_PTR(-ENODEV);
1683 urb = usb_alloc_urb(0, GFP_KERNEL);
1685 return ERR_PTR(-ENOMEM);
1687 pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
1689 usb_fill_bulk_urb(urb, data->udev, pipe,
1690 skb->data, skb->len, btusb_tx_complete, skb);
1692 skb->dev = (void *)hdev;
1697 static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
1699 struct btusb_data *data = hci_get_drvdata(hdev);
1703 if (!data->isoc_tx_ep)
1704 return ERR_PTR(-ENODEV);
1706 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
1708 return ERR_PTR(-ENOMEM);
1710 pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
1712 usb_fill_int_urb(urb, data->udev, pipe,
1713 skb->data, skb->len, btusb_isoc_tx_complete,
1714 skb, data->isoc_tx_ep->bInterval);
1716 urb->transfer_flags = URB_ISO_ASAP;
1718 if (data->isoc_altsetting == 6)
1719 __fill_isoc_descriptor_msbc(urb, skb->len,
1720 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize),
1723 __fill_isoc_descriptor(urb, skb->len,
1724 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
1725 skb->dev = (void *)hdev;
1730 static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb)
1732 struct btusb_data *data = hci_get_drvdata(hdev);
1735 usb_anchor_urb(urb, &data->tx_anchor);
1737 err = usb_submit_urb(urb, GFP_KERNEL);
1739 if (err != -EPERM && err != -ENODEV)
1740 bt_dev_err(hdev, "urb %p submission failed (%d)",
1742 kfree(urb->setup_packet);
1743 usb_unanchor_urb(urb);
1745 usb_mark_last_busy(data->udev);
1752 static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb)
1754 struct btusb_data *data = hci_get_drvdata(hdev);
1755 unsigned long flags;
1758 spin_lock_irqsave(&data->txlock, flags);
1759 suspending = test_bit(BTUSB_SUSPENDING, &data->flags);
1761 data->tx_in_flight++;
1762 spin_unlock_irqrestore(&data->txlock, flags);
1765 return submit_tx_urb(hdev, urb);
1767 usb_anchor_urb(urb, &data->deferred);
1768 schedule_work(&data->waker);
1774 static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
1778 BT_DBG("%s", hdev->name);
1780 switch (hci_skb_pkt_type(skb)) {
1781 case HCI_COMMAND_PKT:
1782 urb = alloc_ctrl_urb(hdev, skb);
1784 return PTR_ERR(urb);
1786 hdev->stat.cmd_tx++;
1787 return submit_or_queue_tx_urb(hdev, urb);
1789 case HCI_ACLDATA_PKT:
1790 urb = alloc_bulk_urb(hdev, skb);
1792 return PTR_ERR(urb);
1794 hdev->stat.acl_tx++;
1795 return submit_or_queue_tx_urb(hdev, urb);
1797 case HCI_SCODATA_PKT:
1798 if (hci_conn_num(hdev, SCO_LINK) < 1)
1801 urb = alloc_isoc_urb(hdev, skb);
1803 return PTR_ERR(urb);
1805 hdev->stat.sco_tx++;
1806 return submit_tx_urb(hdev, urb);
1808 case HCI_ISODATA_PKT:
1809 urb = alloc_bulk_urb(hdev, skb);
1811 return PTR_ERR(urb);
1813 return submit_or_queue_tx_urb(hdev, urb);
1819 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
1821 struct btusb_data *data = hci_get_drvdata(hdev);
1823 BT_DBG("%s evt %d", hdev->name, evt);
1825 if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) {
1826 data->sco_num = hci_conn_num(hdev, SCO_LINK);
1827 data->air_mode = evt;
1828 schedule_work(&data->work);
1832 static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
1834 struct btusb_data *data = hci_get_drvdata(hdev);
1835 struct usb_interface *intf = data->isoc;
1836 struct usb_endpoint_descriptor *ep_desc;
1842 err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting);
1844 bt_dev_err(hdev, "setting interface failed (%d)", -err);
1848 data->isoc_altsetting = altsetting;
1850 data->isoc_tx_ep = NULL;
1851 data->isoc_rx_ep = NULL;
1853 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
1854 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
1856 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
1857 data->isoc_tx_ep = ep_desc;
1861 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
1862 data->isoc_rx_ep = ep_desc;
1867 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
1868 bt_dev_err(hdev, "invalid SCO descriptors");
1875 static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts)
1877 struct btusb_data *data = hci_get_drvdata(hdev);
1880 if (data->isoc_altsetting != new_alts) {
1881 unsigned long flags;
1883 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1884 usb_kill_anchored_urbs(&data->isoc_anchor);
1886 /* When isochronous alternate setting needs to be
1887 * changed, because SCO connection has been added
1888 * or removed, a packet fragment may be left in the
1889 * reassembling state. This could lead to wrongly
1890 * assembled fragments.
1892 * Clear outstanding fragment when selecting a new
1893 * alternate setting.
1895 spin_lock_irqsave(&data->rxlock, flags);
1896 kfree_skb(data->sco_skb);
1897 data->sco_skb = NULL;
1898 spin_unlock_irqrestore(&data->rxlock, flags);
1900 err = __set_isoc_interface(hdev, new_alts);
1905 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
1906 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
1907 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1909 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
1915 static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data,
1918 struct usb_interface *intf = data->isoc;
1921 BT_DBG("Looking for Alt no :%d", alt);
1926 for (i = 0; i < intf->num_altsetting; i++) {
1927 if (intf->altsetting[i].desc.bAlternateSetting == alt)
1928 return &intf->altsetting[i];
1934 static void btusb_work(struct work_struct *work)
1936 struct btusb_data *data = container_of(work, struct btusb_data, work);
1937 struct hci_dev *hdev = data->hdev;
1941 if (data->sco_num > 0) {
1942 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
1943 err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
1945 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1946 usb_kill_anchored_urbs(&data->isoc_anchor);
1950 set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
1953 if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) {
1954 if (hdev->voice_setting & 0x0020) {
1955 static const int alts[3] = { 2, 4, 5 };
1957 new_alts = alts[data->sco_num - 1];
1959 new_alts = data->sco_num;
1961 } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) {
1962 /* Bluetooth USB spec recommends alt 6 (63 bytes), but
1963 * many adapters do not support it. Alt 1 appears to
1964 * work for all adapters that do not have alt 6, and
1965 * which work with WBS at all. Some devices prefer
1966 * alt 3 (HCI payload >= 60 Bytes let air packet
1967 * data satisfy 60 bytes), requiring
1968 * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
1969 * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
1971 if (btusb_find_altsetting(data, 6))
1973 else if (btusb_find_altsetting(data, 3) &&
1974 hdev->sco_mtu >= 72 &&
1975 test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags))
1981 if (btusb_switch_alt_setting(hdev, new_alts) < 0)
1982 bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts);
1984 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1985 usb_kill_anchored_urbs(&data->isoc_anchor);
1987 __set_isoc_interface(hdev, 0);
1988 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
1989 usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
1993 static void btusb_waker(struct work_struct *work)
1995 struct btusb_data *data = container_of(work, struct btusb_data, waker);
1998 err = usb_autopm_get_interface(data->intf);
2002 usb_autopm_put_interface(data->intf);
2005 static void btusb_rx_work(struct work_struct *work)
2007 struct btusb_data *data = container_of(work, struct btusb_data,
2009 struct sk_buff *skb;
2011 /* Dequeue ACL data received during the interval */
2012 while ((skb = skb_dequeue(&data->acl_q)))
2013 data->recv_acl(data->hdev, skb);
2016 static int btusb_setup_bcm92035(struct hci_dev *hdev)
2018 struct sk_buff *skb;
2021 BT_DBG("%s", hdev->name);
2023 skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT);
2025 bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb));
2032 static int btusb_setup_csr(struct hci_dev *hdev)
2034 struct btusb_data *data = hci_get_drvdata(hdev);
2035 u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice);
2036 struct hci_rp_read_local_version *rp;
2037 struct sk_buff *skb;
2038 bool is_fake = false;
2041 BT_DBG("%s", hdev->name);
2043 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
2046 int err = PTR_ERR(skb);
2047 bt_dev_err(hdev, "CSR: Local version failed (%d)", err);
2051 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
2052 bt_dev_err(hdev, "CSR: Local version length mismatch");
2057 rp = (struct hci_rp_read_local_version *)skb->data;
2059 /* Detect a wide host of Chinese controllers that aren't CSR.
2061 * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891
2063 * The main thing they have in common is that these are really popular low-cost
2064 * options that support newer Bluetooth versions but rely on heavy VID/PID
2065 * squatting of this poor old Bluetooth 1.1 device. Even sold as such.
2067 * We detect actual CSR devices by checking that the HCI manufacturer code
2068 * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and
2069 * HCI rev values always match. As they both store the firmware number.
2071 if (le16_to_cpu(rp->manufacturer) != 10 ||
2072 le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver))
2075 /* Known legit CSR firmware build numbers and their supported BT versions:
2076 * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e
2077 * - 1.2 (0x2) -> 0x04d9, 0x0529
2078 * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c
2079 * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External)
2080 * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb
2082 * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that
2083 * support BT 1.1 only; so it's a dead giveaway when some
2084 * third-party BT 4.0 dongle reuses it.
2086 else if (le16_to_cpu(rp->lmp_subver) <= 0x034e &&
2087 le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1)
2090 else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 &&
2091 le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2)
2094 else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c &&
2095 le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0)
2098 else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 &&
2099 le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1)
2102 else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb &&
2103 le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0)
2106 /* Other clones which beat all the above checks */
2107 else if (bcdDevice == 0x0134 &&
2108 le16_to_cpu(rp->lmp_subver) == 0x0c5c &&
2109 le16_to_cpu(rp->hci_ver) == BLUETOOTH_VER_2_0)
2113 bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once...");
2115 /* Generally these clones have big discrepancies between
2116 * advertised features and what's actually supported.
2117 * Probably will need to be expanded in the future;
2118 * without these the controller will lock up.
2120 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
2121 set_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks);
2122 set_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks);
2124 /* Clear the reset quirk since this is not an actual
2125 * early Bluetooth 1.1 device from CSR.
2127 clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
2128 clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
2131 * Special workaround for these BT 4.0 chip clones, and potentially more:
2133 * - 0x0134: a Barrot 8041a02 (HCI rev: 0x0810 sub: 0x1012)
2134 * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709)
2136 * These controllers are really messed-up.
2138 * 1. Their bulk RX endpoint will never report any data unless
2139 * the device was suspended at least once (yes, really).
2140 * 2. They will not wakeup when autosuspended and receiving data
2141 * on their bulk RX endpoint from e.g. a keyboard or mouse
2142 * (IOW remote-wakeup support is broken for the bulk endpoint).
2144 * To fix 1. enable runtime-suspend, force-suspend the
2145 * HCI and then wake-it up by disabling runtime-suspend.
2147 * To fix 2. clear the HCI's can_wake flag, this way the HCI
2148 * will still be autosuspended when it is not open.
2152 * Because these are widespread problems we prefer generic solutions; so
2153 * apply this initialization quirk to every controller that gets here,
2154 * it should be harmless. The alternative is to not work at all.
2156 pm_runtime_allow(&data->udev->dev);
2158 ret = pm_runtime_suspend(&data->udev->dev);
2162 bt_dev_warn(hdev, "CSR: Couldn't suspend the device for our Barrot 8041a02 receive-issue workaround");
2164 pm_runtime_forbid(&data->udev->dev);
2166 device_set_wakeup_capable(&data->udev->dev, false);
2168 /* Re-enable autosuspend if this was requested */
2169 if (enable_autosuspend)
2170 usb_enable_autosuspend(data->udev);
2178 static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
2180 struct sk_buff *skb;
2181 struct hci_event_hdr *hdr;
2182 struct hci_ev_cmd_complete *evt;
2184 skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL);
2188 hdr = skb_put(skb, sizeof(*hdr));
2189 hdr->evt = HCI_EV_CMD_COMPLETE;
2190 hdr->plen = sizeof(*evt) + 1;
2192 evt = skb_put(skb, sizeof(*evt));
2194 evt->opcode = cpu_to_le16(opcode);
2196 skb_put_u8(skb, 0x00);
2198 hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
2200 return hci_recv_frame(hdev, skb);
2203 static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer,
2206 struct hci_dev *hdev = data->hdev;
2208 /* When the device is in bootloader mode, then it can send
2209 * events via the bulk endpoint. These events are treated the
2210 * same way as the ones received from the interrupt endpoint.
2212 if (btintel_test_flag(hdev, INTEL_BOOTLOADER))
2213 return btusb_recv_intr(data, buffer, count);
2215 return btusb_recv_bulk(data, buffer, count);
2218 static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb)
2220 if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
2221 struct hci_event_hdr *hdr = (void *)skb->data;
2223 if (skb->len > HCI_EVENT_HDR_SIZE && hdr->evt == 0xff &&
2225 const void *ptr = skb->data + HCI_EVENT_HDR_SIZE + 1;
2226 unsigned int len = skb->len - HCI_EVENT_HDR_SIZE - 1;
2228 switch (skb->data[2]) {
2230 /* When switching to the operational firmware
2231 * the device sends a vendor specific event
2232 * indicating that the bootup completed.
2234 btintel_bootup(hdev, ptr, len);
2237 /* When the firmware loading completes the
2238 * device sends out a vendor specific event
2239 * indicating the result of the firmware
2242 btintel_secure_send_result(hdev, ptr, len);
2248 return hci_recv_frame(hdev, skb);
2251 static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
2255 BT_DBG("%s", hdev->name);
2257 switch (hci_skb_pkt_type(skb)) {
2258 case HCI_COMMAND_PKT:
2259 if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
2260 struct hci_command_hdr *cmd = (void *)skb->data;
2261 __u16 opcode = le16_to_cpu(cmd->opcode);
2263 /* When in bootloader mode and the command 0xfc09
2264 * is received, it needs to be send down the
2265 * bulk endpoint. So allocate a bulk URB instead.
2267 if (opcode == 0xfc09)
2268 urb = alloc_bulk_urb(hdev, skb);
2270 urb = alloc_ctrl_urb(hdev, skb);
2272 /* When the 0xfc01 command is issued to boot into
2273 * the operational firmware, it will actually not
2274 * send a command complete event. To keep the flow
2275 * control working inject that event here.
2277 if (opcode == 0xfc01)
2278 inject_cmd_complete(hdev, opcode);
2280 urb = alloc_ctrl_urb(hdev, skb);
2283 return PTR_ERR(urb);
2285 hdev->stat.cmd_tx++;
2286 return submit_or_queue_tx_urb(hdev, urb);
2288 case HCI_ACLDATA_PKT:
2289 urb = alloc_bulk_urb(hdev, skb);
2291 return PTR_ERR(urb);
2293 hdev->stat.acl_tx++;
2294 return submit_or_queue_tx_urb(hdev, urb);
2296 case HCI_SCODATA_PKT:
2297 if (hci_conn_num(hdev, SCO_LINK) < 1)
2300 urb = alloc_isoc_urb(hdev, skb);
2302 return PTR_ERR(urb);
2304 hdev->stat.sco_tx++;
2305 return submit_tx_urb(hdev, urb);
2307 case HCI_ISODATA_PKT:
2308 urb = alloc_bulk_urb(hdev, skb);
2310 return PTR_ERR(urb);
2312 return submit_or_queue_tx_urb(hdev, urb);
2318 /* UHW CR mapping */
2319 #define MTK_BT_MISC 0x70002510
2320 #define MTK_BT_SUBSYS_RST 0x70002610
2321 #define MTK_UDMA_INT_STA_BT 0x74000024
2322 #define MTK_UDMA_INT_STA_BT1 0x74000308
2323 #define MTK_BT_WDT_STATUS 0x740003A0
2324 #define MTK_EP_RST_OPT 0x74011890
2325 #define MTK_EP_RST_IN_OUT_OPT 0x00010001
2326 #define MTK_BT_RST_DONE 0x00000100
2327 #define MTK_BT_RESET_WAIT_MS 100
2328 #define MTK_BT_RESET_NUM_TRIES 10
2330 static void btusb_mtk_wmt_recv(struct urb *urb)
2332 struct hci_dev *hdev = urb->context;
2333 struct btusb_data *data = hci_get_drvdata(hdev);
2334 struct sk_buff *skb;
2337 if (urb->status == 0 && urb->actual_length > 0) {
2338 hdev->stat.byte_rx += urb->actual_length;
2340 /* WMT event shouldn't be fragmented and the size should be
2341 * less than HCI_WMT_MAX_EVENT_SIZE.
2343 skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC);
2345 hdev->stat.err_rx++;
2346 kfree(urb->setup_packet);
2350 hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
2351 skb_put_data(skb, urb->transfer_buffer, urb->actual_length);
2353 /* When someone waits for the WMT event, the skb is being cloned
2354 * and being processed the events from there then.
2356 if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) {
2357 data->evt_skb = skb_clone(skb, GFP_ATOMIC);
2358 if (!data->evt_skb) {
2360 kfree(urb->setup_packet);
2365 err = hci_recv_frame(hdev, skb);
2367 kfree_skb(data->evt_skb);
2368 data->evt_skb = NULL;
2369 kfree(urb->setup_packet);
2373 if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT,
2375 /* Barrier to sync with other CPUs */
2376 smp_mb__after_atomic();
2377 wake_up_bit(&data->flags,
2378 BTUSB_TX_WAIT_VND_EVT);
2380 kfree(urb->setup_packet);
2382 } else if (urb->status == -ENOENT) {
2383 /* Avoid suspend failed when usb_kill_urb */
2387 usb_mark_last_busy(data->udev);
2389 /* The URB complete handler is still called with urb->actual_length = 0
2390 * when the event is not available, so we should keep re-submitting
2391 * URB until WMT event returns, Also, It's necessary to wait some time
2392 * between the two consecutive control URBs to relax the target device
2393 * to generate the event. Otherwise, the WMT event cannot return from
2394 * the device successfully.
2398 usb_anchor_urb(urb, &data->ctrl_anchor);
2399 err = usb_submit_urb(urb, GFP_ATOMIC);
2401 kfree(urb->setup_packet);
2402 /* -EPERM: urb is being killed;
2403 * -ENODEV: device got disconnected
2405 if (err != -EPERM && err != -ENODEV)
2406 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
2408 usb_unanchor_urb(urb);
2412 static int btusb_mtk_submit_wmt_recv_urb(struct hci_dev *hdev)
2414 struct btusb_data *data = hci_get_drvdata(hdev);
2415 struct usb_ctrlrequest *dr;
2421 urb = usb_alloc_urb(0, GFP_KERNEL);
2425 dr = kmalloc(sizeof(*dr), GFP_KERNEL);
2431 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_IN;
2433 dr->wIndex = cpu_to_le16(0);
2434 dr->wValue = cpu_to_le16(48);
2435 dr->wLength = cpu_to_le16(size);
2437 buf = kmalloc(size, GFP_KERNEL);
2444 pipe = usb_rcvctrlpipe(data->udev, 0);
2446 usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
2447 buf, size, btusb_mtk_wmt_recv, hdev);
2449 urb->transfer_flags |= URB_FREE_BUFFER;
2451 usb_anchor_urb(urb, &data->ctrl_anchor);
2452 err = usb_submit_urb(urb, GFP_KERNEL);
2454 if (err != -EPERM && err != -ENODEV)
2455 bt_dev_err(hdev, "urb %p submission failed (%d)",
2457 usb_unanchor_urb(urb);
2465 static int btusb_mtk_hci_wmt_sync(struct hci_dev *hdev,
2466 struct btmtk_hci_wmt_params *wmt_params)
2468 struct btusb_data *data = hci_get_drvdata(hdev);
2469 struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc;
2470 u32 hlen, status = BTMTK_WMT_INVALID;
2471 struct btmtk_hci_wmt_evt *wmt_evt;
2472 struct btmtk_hci_wmt_cmd *wc;
2473 struct btmtk_wmt_hdr *hdr;
2476 /* Send the WMT command and wait until the WMT event returns */
2477 hlen = sizeof(*hdr) + wmt_params->dlen;
2481 wc = kzalloc(hlen, GFP_KERNEL);
2487 hdr->op = wmt_params->op;
2488 hdr->dlen = cpu_to_le16(wmt_params->dlen + 1);
2489 hdr->flag = wmt_params->flag;
2490 memcpy(wc->data, wmt_params->data, wmt_params->dlen);
2492 set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2494 /* WMT cmd/event doesn't follow up the generic HCI cmd/event handling,
2495 * it needs constantly polling control pipe until the host received the
2496 * WMT event, thus, we should require to specifically acquire PM counter
2497 * on the USB to prevent the interface from entering auto suspended
2498 * while WMT cmd/event in progress.
2500 err = usb_autopm_get_interface(data->intf);
2504 err = __hci_cmd_send(hdev, 0xfc6f, hlen, wc);
2507 clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2508 usb_autopm_put_interface(data->intf);
2512 /* Submit control IN URB on demand to process the WMT event */
2513 err = btusb_mtk_submit_wmt_recv_urb(hdev);
2515 usb_autopm_put_interface(data->intf);
2520 /* The vendor specific WMT commands are all answered by a vendor
2521 * specific event and will have the Command Status or Command
2522 * Complete as with usual HCI command flow control.
2524 * After sending the command, wait for BTUSB_TX_WAIT_VND_EVT
2525 * state to be cleared. The driver specific event receive routine
2526 * will clear that state and with that indicate completion of the
2529 err = wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT,
2530 TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT);
2531 if (err == -EINTR) {
2532 bt_dev_err(hdev, "Execution of wmt command interrupted");
2533 clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2538 bt_dev_err(hdev, "Execution of wmt command timed out");
2539 clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2544 /* Parse and handle the return WMT event */
2545 wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data;
2546 if (wmt_evt->whdr.op != hdr->op) {
2547 bt_dev_err(hdev, "Wrong op received %d expected %d",
2548 wmt_evt->whdr.op, hdr->op);
2553 switch (wmt_evt->whdr.op) {
2554 case BTMTK_WMT_SEMAPHORE:
2555 if (wmt_evt->whdr.flag == 2)
2556 status = BTMTK_WMT_PATCH_UNDONE;
2558 status = BTMTK_WMT_PATCH_DONE;
2560 case BTMTK_WMT_FUNC_CTRL:
2561 wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt;
2562 if (be16_to_cpu(wmt_evt_funcc->status) == 0x404)
2563 status = BTMTK_WMT_ON_DONE;
2564 else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420)
2565 status = BTMTK_WMT_ON_PROGRESS;
2567 status = BTMTK_WMT_ON_UNDONE;
2569 case BTMTK_WMT_PATCH_DWNLD:
2570 if (wmt_evt->whdr.flag == 2)
2571 status = BTMTK_WMT_PATCH_DONE;
2572 else if (wmt_evt->whdr.flag == 1)
2573 status = BTMTK_WMT_PATCH_PROGRESS;
2575 status = BTMTK_WMT_PATCH_UNDONE;
2579 if (wmt_params->status)
2580 *wmt_params->status = status;
2583 kfree_skb(data->evt_skb);
2584 data->evt_skb = NULL;
2590 static int btusb_mtk_func_query(struct hci_dev *hdev)
2592 struct btmtk_hci_wmt_params wmt_params;
2596 /* Query whether the function is enabled */
2597 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
2598 wmt_params.flag = 4;
2599 wmt_params.dlen = sizeof(param);
2600 wmt_params.data = ¶m;
2601 wmt_params.status = &status;
2603 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
2605 bt_dev_err(hdev, "Failed to query function status (%d)", err);
2612 static int btusb_mtk_uhw_reg_write(struct btusb_data *data, u32 reg, u32 val)
2614 struct hci_dev *hdev = data->hdev;
2618 buf = kzalloc(4, GFP_KERNEL);
2622 put_unaligned_le32(val, buf);
2624 pipe = usb_sndctrlpipe(data->udev, 0);
2625 err = usb_control_msg(data->udev, pipe, 0x02,
2627 reg >> 16, reg & 0xffff,
2628 buf, 4, USB_CTRL_SET_TIMEOUT);
2630 bt_dev_err(hdev, "Failed to write uhw reg(%d)", err);
2640 static int btusb_mtk_uhw_reg_read(struct btusb_data *data, u32 reg, u32 *val)
2642 struct hci_dev *hdev = data->hdev;
2646 buf = kzalloc(4, GFP_KERNEL);
2650 pipe = usb_rcvctrlpipe(data->udev, 0);
2651 err = usb_control_msg(data->udev, pipe, 0x01,
2653 reg >> 16, reg & 0xffff,
2654 buf, 4, USB_CTRL_SET_TIMEOUT);
2656 bt_dev_err(hdev, "Failed to read uhw reg(%d)", err);
2660 *val = get_unaligned_le32(buf);
2661 bt_dev_dbg(hdev, "reg=%x, value=0x%08x", reg, *val);
2669 static int btusb_mtk_reg_read(struct btusb_data *data, u32 reg, u32 *val)
2671 int pipe, err, size = sizeof(u32);
2674 buf = kzalloc(size, GFP_KERNEL);
2678 pipe = usb_rcvctrlpipe(data->udev, 0);
2679 err = usb_control_msg(data->udev, pipe, 0x63,
2680 USB_TYPE_VENDOR | USB_DIR_IN,
2681 reg >> 16, reg & 0xffff,
2682 buf, size, USB_CTRL_SET_TIMEOUT);
2686 *val = get_unaligned_le32(buf);
2694 static int btusb_mtk_id_get(struct btusb_data *data, u32 reg, u32 *id)
2696 return btusb_mtk_reg_read(data, reg, id);
2699 static int btusb_mtk_setup(struct hci_dev *hdev)
2701 struct btusb_data *data = hci_get_drvdata(hdev);
2702 struct btmtk_hci_wmt_params wmt_params;
2703 ktime_t calltime, delta, rettime;
2704 struct btmtk_tci_sleep tci_sleep;
2705 unsigned long long duration;
2706 struct sk_buff *skb;
2710 char fw_bin_name[64];
2714 calltime = ktime_get();
2716 err = btusb_mtk_id_get(data, 0x80000008, &dev_id);
2718 bt_dev_err(hdev, "Failed to get device id (%d)", err);
2723 err = btusb_mtk_id_get(data, 0x70010200, &dev_id);
2725 bt_dev_err(hdev, "Failed to get device id (%d)", err);
2728 err = btusb_mtk_id_get(data, 0x80021004, &fw_version);
2730 bt_dev_err(hdev, "Failed to get fw version (%d)", err);
2737 fwname = FIRMWARE_MT7663;
2740 fwname = FIRMWARE_MT7668;
2744 snprintf(fw_bin_name, sizeof(fw_bin_name),
2745 "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin",
2746 dev_id & 0xffff, (fw_version & 0xff) + 1);
2747 err = btmtk_setup_firmware_79xx(hdev, fw_bin_name,
2748 btusb_mtk_hci_wmt_sync);
2750 bt_dev_err(hdev, "Failed to set up firmware (%d)", err);
2754 /* It's Device EndPoint Reset Option Register */
2755 btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT);
2757 /* Enable Bluetooth protocol */
2759 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
2760 wmt_params.flag = 0;
2761 wmt_params.dlen = sizeof(param);
2762 wmt_params.data = ¶m;
2763 wmt_params.status = NULL;
2765 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
2767 bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
2771 hci_set_msft_opcode(hdev, 0xFD30);
2772 hci_set_aosp_capable(hdev);
2775 bt_dev_err(hdev, "Unsupported hardware variant (%08x)",
2780 /* Query whether the firmware is already download */
2781 wmt_params.op = BTMTK_WMT_SEMAPHORE;
2782 wmt_params.flag = 1;
2783 wmt_params.dlen = 0;
2784 wmt_params.data = NULL;
2785 wmt_params.status = &status;
2787 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
2789 bt_dev_err(hdev, "Failed to query firmware status (%d)", err);
2793 if (status == BTMTK_WMT_PATCH_DONE) {
2794 bt_dev_info(hdev, "firmware already downloaded");
2795 goto ignore_setup_fw;
2798 /* Setup a firmware which the device definitely requires */
2799 err = btmtk_setup_firmware(hdev, fwname,
2800 btusb_mtk_hci_wmt_sync);
2805 err = readx_poll_timeout(btusb_mtk_func_query, hdev, status,
2806 status < 0 || status != BTMTK_WMT_ON_PROGRESS,
2808 /* -ETIMEDOUT happens */
2812 /* The other errors happen in btusb_mtk_func_query */
2816 if (status == BTMTK_WMT_ON_DONE) {
2817 bt_dev_info(hdev, "function already on");
2818 goto ignore_func_on;
2821 /* Enable Bluetooth protocol */
2823 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
2824 wmt_params.flag = 0;
2825 wmt_params.dlen = sizeof(param);
2826 wmt_params.data = ¶m;
2827 wmt_params.status = NULL;
2829 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
2831 bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
2836 /* Apply the low power environment setup */
2837 tci_sleep.mode = 0x5;
2838 tci_sleep.duration = cpu_to_le16(0x640);
2839 tci_sleep.host_duration = cpu_to_le16(0x640);
2840 tci_sleep.host_wakeup_pin = 0;
2841 tci_sleep.time_compensation = 0;
2843 skb = __hci_cmd_sync(hdev, 0xfc7a, sizeof(tci_sleep), &tci_sleep,
2847 bt_dev_err(hdev, "Failed to apply low power setting (%d)", err);
2853 rettime = ktime_get();
2854 delta = ktime_sub(rettime, calltime);
2855 duration = (unsigned long long)ktime_to_ns(delta) >> 10;
2857 bt_dev_info(hdev, "Device setup in %llu usecs", duration);
2862 static int btusb_mtk_shutdown(struct hci_dev *hdev)
2864 struct btmtk_hci_wmt_params wmt_params;
2868 /* Disable the device */
2869 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
2870 wmt_params.flag = 0;
2871 wmt_params.dlen = sizeof(param);
2872 wmt_params.data = ¶m;
2873 wmt_params.status = NULL;
2875 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
2877 bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
2884 static void btusb_mtk_cmd_timeout(struct hci_dev *hdev)
2886 struct btusb_data *data = hci_get_drvdata(hdev);
2890 /* It's MediaTek specific bluetooth reset mechanism via USB */
2891 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
2892 bt_dev_err(hdev, "last reset failed? Not resetting again");
2896 err = usb_autopm_get_interface(data->intf);
2900 btusb_stop_traffic(data);
2901 usb_kill_anchored_urbs(&data->tx_anchor);
2903 /* It's Device EndPoint Reset Option Register */
2904 bt_dev_dbg(hdev, "Initiating reset mechanism via uhw");
2905 btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT);
2906 btusb_mtk_uhw_reg_read(data, MTK_BT_WDT_STATUS, &val);
2908 /* Reset the bluetooth chip via USB interface. */
2909 btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 1);
2910 btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x000000FF);
2911 btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT, &val);
2912 btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT1, 0x000000FF);
2913 btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT1, &val);
2914 /* MT7921 need to delay 20ms between toggle reset bit */
2916 btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 0);
2917 btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
2919 /* Poll the register until reset is completed */
2921 btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
2922 if (val & MTK_BT_RST_DONE) {
2923 bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
2927 bt_dev_dbg(hdev, "Polling Bluetooth Reset CR");
2929 msleep(MTK_BT_RESET_WAIT_MS);
2930 } while (retry < MTK_BT_RESET_NUM_TRIES);
2932 btusb_mtk_id_get(data, 0x70010200, &val);
2934 bt_dev_err(hdev, "Can't get device id, subsys reset fail.");
2936 usb_queue_reset_device(data->intf);
2938 clear_bit(BTUSB_HW_RESET_ACTIVE, &data->flags);
2941 static int btusb_recv_acl_mtk(struct hci_dev *hdev, struct sk_buff *skb)
2943 struct btusb_data *data = hci_get_drvdata(hdev);
2944 u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle);
2947 case 0xfc6f: /* Firmware dump from device */
2948 /* When the firmware hangs, the device can no longer
2949 * suspend and thus disable auto-suspend.
2951 usb_disable_autosuspend(data->udev);
2953 case 0x05ff: /* Firmware debug logging 1 */
2954 case 0x05fe: /* Firmware debug logging 2 */
2955 return hci_recv_diag(hdev, skb);
2958 return hci_recv_frame(hdev, skb);
2962 /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */
2963 static int marvell_config_oob_wake(struct hci_dev *hdev)
2965 struct sk_buff *skb;
2966 struct btusb_data *data = hci_get_drvdata(hdev);
2967 struct device *dev = &data->udev->dev;
2968 u16 pin, gap, opcode;
2972 /* Move on if no wakeup pin specified */
2973 if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) ||
2974 of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap))
2977 /* Vendor specific command to configure a GPIO as wake-up pin */
2978 opcode = hci_opcode_pack(0x3F, 0x59);
2979 cmd[0] = opcode & 0xFF;
2980 cmd[1] = opcode >> 8;
2981 cmd[2] = 2; /* length of parameters that follow */
2983 cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */
2985 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
2987 bt_dev_err(hdev, "%s: No memory", __func__);
2991 skb_put_data(skb, cmd, sizeof(cmd));
2992 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
2994 ret = btusb_send_frame(hdev, skb);
2996 bt_dev_err(hdev, "%s: configuration failed", __func__);
3005 static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
3006 const bdaddr_t *bdaddr)
3008 struct sk_buff *skb;
3013 buf[1] = sizeof(bdaddr_t);
3014 memcpy(buf + 2, bdaddr, sizeof(bdaddr_t));
3016 skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT);
3019 bt_dev_err(hdev, "changing Marvell device address failed (%ld)",
3028 static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
3029 const bdaddr_t *bdaddr)
3031 struct sk_buff *skb;
3038 buf[3] = sizeof(bdaddr_t);
3039 memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
3041 skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
3044 bt_dev_err(hdev, "Change address command failed (%ld)", ret);
3052 static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev,
3053 const bdaddr_t *bdaddr)
3055 struct sk_buff *skb;
3059 memcpy(buf, bdaddr, sizeof(bdaddr_t));
3061 skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf,
3062 HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
3065 bt_dev_err(hdev, "Change address command failed (%ld)", ret);
3073 #define QCA_DFU_PACKET_LEN 4096
3075 #define QCA_GET_TARGET_VERSION 0x09
3076 #define QCA_CHECK_STATUS 0x05
3077 #define QCA_DFU_DOWNLOAD 0x01
3079 #define QCA_SYSCFG_UPDATED 0x40
3080 #define QCA_PATCH_UPDATED 0x80
3081 #define QCA_DFU_TIMEOUT 3000
3082 #define QCA_FLAG_MULTI_NVM 0x80
3083 #define QCA_BT_RESET_WAIT_MS 100
3085 #define WCN6855_2_0_RAM_VERSION_GF 0x400c1200
3086 #define WCN6855_2_1_RAM_VERSION_GF 0x400c1211
3088 struct qca_version {
3090 __le32 patch_version;
3098 struct qca_rampatch_version {
3099 __le16 rom_version_high;
3100 __le16 rom_version_low;
3101 __le16 patch_version;
3104 struct qca_device_info {
3106 u8 rampatch_hdr; /* length of header in rampatch */
3107 u8 nvm_hdr; /* length of header in NVM */
3108 u8 ver_offset; /* offset of version structure in rampatch */
3111 static const struct qca_device_info qca_devices_table[] = {
3112 { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */
3113 { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */
3114 { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */
3115 { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */
3116 { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */
3117 { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */
3118 { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */
3119 { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */
3120 { 0x00130201, 40, 4, 16 }, /* WCN6855 2.1 */
3121 { 0x00190200, 40, 4, 16 }, /* WCN785x 2.0 */
3124 static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request,
3125 void *data, u16 size)
3130 buf = kmalloc(size, GFP_KERNEL);
3134 /* Found some of USB hosts have IOT issues with ours so that we should
3135 * not wait until HCI layer is ready.
3137 pipe = usb_rcvctrlpipe(udev, 0);
3138 err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN,
3139 0, 0, buf, size, USB_CTRL_SET_TIMEOUT);
3141 dev_err(&udev->dev, "Failed to access otp area (%d)", err);
3145 memcpy(data, buf, size);
3153 static int btusb_setup_qca_download_fw(struct hci_dev *hdev,
3154 const struct firmware *firmware,
3157 struct btusb_data *btdata = hci_get_drvdata(hdev);
3158 struct usb_device *udev = btdata->udev;
3159 size_t count, size, sent = 0;
3163 buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL);
3167 count = firmware->size;
3169 size = min_t(size_t, count, hdr_size);
3170 memcpy(buf, firmware->data, size);
3172 /* USB patches should go down to controller through USB path
3173 * because binary format fits to go down through USB channel.
3174 * USB control path is for patching headers and USB bulk is for
3177 pipe = usb_sndctrlpipe(udev, 0);
3178 err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR,
3179 0, 0, buf, size, USB_CTRL_SET_TIMEOUT);
3181 bt_dev_err(hdev, "Failed to send headers (%d)", err);
3188 /* ep2 need time to switch from function acl to function dfu,
3189 * so we add 20ms delay here.
3194 size = min_t(size_t, count, QCA_DFU_PACKET_LEN);
3196 memcpy(buf, firmware->data + sent, size);
3198 pipe = usb_sndbulkpipe(udev, 0x02);
3199 err = usb_bulk_msg(udev, pipe, buf, size, &len,
3202 bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)",
3203 sent, firmware->size, err);
3208 bt_dev_err(hdev, "Failed to get bulk buffer");
3222 static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev,
3223 struct qca_version *ver,
3224 const struct qca_device_info *info)
3226 struct qca_rampatch_version *rver;
3227 const struct firmware *fw;
3228 u32 ver_rom, ver_patch, rver_rom;
3229 u16 rver_rom_low, rver_rom_high, rver_patch;
3233 ver_rom = le32_to_cpu(ver->rom_version);
3234 ver_patch = le32_to_cpu(ver->patch_version);
3236 snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin", ver_rom);
3238 err = request_firmware(&fw, fwname, &hdev->dev);
3240 bt_dev_err(hdev, "failed to request rampatch file: %s (%d)",
3245 bt_dev_info(hdev, "using rampatch file: %s", fwname);
3247 rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset);
3248 rver_rom_low = le16_to_cpu(rver->rom_version_low);
3249 rver_patch = le16_to_cpu(rver->patch_version);
3251 if (ver_rom & ~0xffffU) {
3252 rver_rom_high = le16_to_cpu(rver->rom_version_high);
3253 rver_rom = le32_to_cpu(rver_rom_high << 16 | rver_rom_low);
3255 rver_rom = rver_rom_low;
3258 bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, "
3259 "firmware rome 0x%x build 0x%x",
3260 rver_rom, rver_patch, ver_rom, ver_patch);
3262 if (rver_rom != ver_rom || rver_patch <= ver_patch) {
3263 bt_dev_err(hdev, "rampatch file version did not match with firmware");
3268 err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr);
3271 release_firmware(fw);
3276 static void btusb_generate_qca_nvm_name(char *fwname, size_t max_size,
3277 const struct qca_version *ver)
3279 u32 rom_version = le32_to_cpu(ver->rom_version);
3280 u16 flag = le16_to_cpu(ver->flag);
3282 if (((flag >> 8) & 0xff) == QCA_FLAG_MULTI_NVM) {
3283 /* The board_id should be split into two bytes
3284 * The 1st byte is chip ID, and the 2nd byte is platform ID
3285 * For example, board ID 0x010A, 0x01 is platform ID. 0x0A is chip ID
3286 * we have several platforms, and platform IDs are continuously added
3288 * 0x00 is for Mobile
3290 * 0x02 is for Automotive
3291 * 0x03 is for Consumer electronic
3293 u16 board_id = (ver->chip_id << 8) + ver->platform_id;
3294 const char *variant;
3296 switch (le32_to_cpu(ver->ram_version)) {
3297 case WCN6855_2_0_RAM_VERSION_GF:
3298 case WCN6855_2_1_RAM_VERSION_GF:
3306 if (board_id == 0) {
3307 snprintf(fwname, max_size, "qca/nvm_usb_%08x%s.bin",
3308 rom_version, variant);
3310 snprintf(fwname, max_size, "qca/nvm_usb_%08x%s_%04x.bin",
3311 rom_version, variant, board_id);
3314 snprintf(fwname, max_size, "qca/nvm_usb_%08x.bin",
3320 static int btusb_setup_qca_load_nvm(struct hci_dev *hdev,
3321 struct qca_version *ver,
3322 const struct qca_device_info *info)
3324 const struct firmware *fw;
3328 btusb_generate_qca_nvm_name(fwname, sizeof(fwname), ver);
3330 err = request_firmware(&fw, fwname, &hdev->dev);
3332 bt_dev_err(hdev, "failed to request NVM file: %s (%d)",
3337 bt_dev_info(hdev, "using NVM file: %s", fwname);
3339 err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr);
3341 release_firmware(fw);
3346 /* identify the ROM version and check whether patches are needed */
3347 static bool btusb_qca_need_patch(struct usb_device *udev)
3349 struct qca_version ver;
3351 if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3354 /* only low ROM versions need patches */
3355 return !(le32_to_cpu(ver.rom_version) & ~0xffffU);
3358 static int btusb_setup_qca(struct hci_dev *hdev)
3360 struct btusb_data *btdata = hci_get_drvdata(hdev);
3361 struct usb_device *udev = btdata->udev;
3362 const struct qca_device_info *info = NULL;
3363 struct qca_version ver;
3368 err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3373 ver_rom = le32_to_cpu(ver.rom_version);
3375 for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
3376 if (ver_rom == qca_devices_table[i].rom_version)
3377 info = &qca_devices_table[i];
3380 /* If the rom_version is not matched in the qca_devices_table
3381 * and the high ROM version is not zero, we assume this chip no
3382 * need to load the rampatch and nvm.
3384 if (ver_rom & ~0xffffU)
3387 bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom);
3391 err = btusb_qca_send_vendor_req(udev, QCA_CHECK_STATUS, &status,
3396 if (!(status & QCA_PATCH_UPDATED)) {
3397 err = btusb_setup_qca_load_rampatch(hdev, &ver, info);
3402 err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3407 if (!(status & QCA_SYSCFG_UPDATED)) {
3408 err = btusb_setup_qca_load_nvm(hdev, &ver, info);
3412 /* WCN6855 2.1 and later will reset to apply firmware downloaded here, so
3413 * wait ~100ms for reset Done then go ahead, otherwise, it maybe
3414 * cause potential enable failure.
3416 if (info->rom_version >= 0x00130201)
3417 msleep(QCA_BT_RESET_WAIT_MS);
3420 /* Mark HCI_OP_ENHANCED_SETUP_SYNC_CONN as broken as it doesn't seem to
3421 * work with the likes of HSP/HFP mSBC.
3423 set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks);
3428 static inline int __set_diag_interface(struct hci_dev *hdev)
3430 struct btusb_data *data = hci_get_drvdata(hdev);
3431 struct usb_interface *intf = data->diag;
3437 data->diag_tx_ep = NULL;
3438 data->diag_rx_ep = NULL;
3440 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
3441 struct usb_endpoint_descriptor *ep_desc;
3443 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
3445 if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
3446 data->diag_tx_ep = ep_desc;
3450 if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
3451 data->diag_rx_ep = ep_desc;
3456 if (!data->diag_tx_ep || !data->diag_rx_ep) {
3457 bt_dev_err(hdev, "invalid diagnostic descriptors");
3464 static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable)
3466 struct btusb_data *data = hci_get_drvdata(hdev);
3467 struct sk_buff *skb;
3471 if (!data->diag_tx_ep)
3472 return ERR_PTR(-ENODEV);
3474 urb = usb_alloc_urb(0, GFP_KERNEL);
3476 return ERR_PTR(-ENOMEM);
3478 skb = bt_skb_alloc(2, GFP_KERNEL);
3481 return ERR_PTR(-ENOMEM);
3484 skb_put_u8(skb, 0xf0);
3485 skb_put_u8(skb, enable);
3487 pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress);
3489 usb_fill_bulk_urb(urb, data->udev, pipe,
3490 skb->data, skb->len, btusb_tx_complete, skb);
3492 skb->dev = (void *)hdev;
3497 static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable)
3499 struct btusb_data *data = hci_get_drvdata(hdev);
3505 if (!test_bit(HCI_RUNNING, &hdev->flags))
3508 urb = alloc_diag_urb(hdev, enable);
3510 return PTR_ERR(urb);
3512 return submit_or_queue_tx_urb(hdev, urb);
3516 static irqreturn_t btusb_oob_wake_handler(int irq, void *priv)
3518 struct btusb_data *data = priv;
3520 pm_wakeup_event(&data->udev->dev, 0);
3523 /* Disable only if not already disabled (keep it balanced) */
3524 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) {
3525 disable_irq_nosync(irq);
3526 disable_irq_wake(irq);
3531 static const struct of_device_id btusb_match_table[] = {
3532 { .compatible = "usb1286,204e" },
3533 { .compatible = "usbcf3,e300" }, /* QCA6174A */
3534 { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */
3537 MODULE_DEVICE_TABLE(of, btusb_match_table);
3539 /* Use an oob wakeup pin? */
3540 static int btusb_config_oob_wake(struct hci_dev *hdev)
3542 struct btusb_data *data = hci_get_drvdata(hdev);
3543 struct device *dev = &data->udev->dev;
3546 clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags);
3548 if (!of_match_device(btusb_match_table, dev))
3551 /* Move on if no IRQ specified */
3552 irq = of_irq_get_byname(dev->of_node, "wakeup");
3554 bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__);
3558 irq_set_status_flags(irq, IRQ_NOAUTOEN);
3559 ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler,
3560 0, "OOB Wake-on-BT", data);
3562 bt_dev_err(hdev, "%s: IRQ request failed", __func__);
3566 ret = device_init_wakeup(dev, true);
3568 bt_dev_err(hdev, "%s: failed to init_wakeup", __func__);
3572 data->oob_wake_irq = irq;
3573 bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq);
3578 static void btusb_check_needs_reset_resume(struct usb_interface *intf)
3580 if (dmi_check_system(btusb_needs_reset_resume_table))
3581 interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
3584 static bool btusb_wakeup(struct hci_dev *hdev)
3586 struct btusb_data *data = hci_get_drvdata(hdev);
3588 return device_may_wakeup(&data->udev->dev);
3591 static int btusb_shutdown_qca(struct hci_dev *hdev)
3593 struct sk_buff *skb;
3595 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
3597 bt_dev_err(hdev, "HCI reset during shutdown failed");
3598 return PTR_ERR(skb);
3605 static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf,
3606 size_t count, loff_t *ppos)
3608 struct btusb_data *data = file->private_data;
3611 buf[0] = data->poll_sync ? 'Y' : 'N';
3614 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
3617 static ssize_t force_poll_sync_write(struct file *file,
3618 const char __user *user_buf,
3619 size_t count, loff_t *ppos)
3621 struct btusb_data *data = file->private_data;
3625 err = kstrtobool_from_user(user_buf, count, &enable);
3629 /* Only allow changes while the adapter is down */
3630 if (test_bit(HCI_UP, &data->hdev->flags))
3633 if (data->poll_sync == enable)
3636 data->poll_sync = enable;
3641 static const struct file_operations force_poll_sync_fops = {
3642 .open = simple_open,
3643 .read = force_poll_sync_read,
3644 .write = force_poll_sync_write,
3645 .llseek = default_llseek,
3648 static int btusb_probe(struct usb_interface *intf,
3649 const struct usb_device_id *id)
3651 struct usb_endpoint_descriptor *ep_desc;
3652 struct gpio_desc *reset_gpio;
3653 struct btusb_data *data;
3654 struct hci_dev *hdev;
3655 unsigned ifnum_base;
3656 int i, err, priv_size;
3658 BT_DBG("intf %p id %p", intf, id);
3660 /* interface numbers are hardcoded in the spec */
3661 if (intf->cur_altsetting->desc.bInterfaceNumber != 0) {
3662 if (!(id->driver_info & BTUSB_IFNUM_2))
3664 if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
3668 ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber;
3670 if (!id->driver_info) {
3671 const struct usb_device_id *match;
3673 match = usb_match_id(intf, blacklist_table);
3678 if (id->driver_info == BTUSB_IGNORE)
3681 if (id->driver_info & BTUSB_ATH3012) {
3682 struct usb_device *udev = interface_to_usbdev(intf);
3684 /* Old firmware would otherwise let ath3k driver load
3685 * patch and sysconfig files
3687 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 &&
3688 !btusb_qca_need_patch(udev))
3692 data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
3696 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
3697 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
3699 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
3700 data->intr_ep = ep_desc;
3704 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
3705 data->bulk_tx_ep = ep_desc;
3709 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
3710 data->bulk_rx_ep = ep_desc;
3715 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
3718 if (id->driver_info & BTUSB_AMP) {
3719 data->cmdreq_type = USB_TYPE_CLASS | 0x01;
3720 data->cmdreq = 0x2b;
3722 data->cmdreq_type = USB_TYPE_CLASS;
3723 data->cmdreq = 0x00;
3726 data->udev = interface_to_usbdev(intf);
3729 INIT_WORK(&data->work, btusb_work);
3730 INIT_WORK(&data->waker, btusb_waker);
3731 INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work);
3733 skb_queue_head_init(&data->acl_q);
3735 init_usb_anchor(&data->deferred);
3736 init_usb_anchor(&data->tx_anchor);
3737 spin_lock_init(&data->txlock);
3739 init_usb_anchor(&data->intr_anchor);
3740 init_usb_anchor(&data->bulk_anchor);
3741 init_usb_anchor(&data->isoc_anchor);
3742 init_usb_anchor(&data->diag_anchor);
3743 init_usb_anchor(&data->ctrl_anchor);
3744 spin_lock_init(&data->rxlock);
3748 data->recv_event = hci_recv_frame;
3749 data->recv_bulk = btusb_recv_bulk;
3751 if (id->driver_info & BTUSB_INTEL_COMBINED) {
3752 /* Allocate extra space for Intel device */
3753 priv_size += sizeof(struct btintel_data);
3755 /* Override the rx handlers */
3756 data->recv_event = btusb_recv_event_intel;
3757 data->recv_bulk = btusb_recv_bulk_intel;
3760 data->recv_acl = hci_recv_frame;
3762 hdev = hci_alloc_dev_priv(priv_size);
3766 hdev->bus = HCI_USB;
3767 hci_set_drvdata(hdev, data);
3769 if (id->driver_info & BTUSB_AMP)
3770 hdev->dev_type = HCI_AMP;
3772 hdev->dev_type = HCI_PRIMARY;
3776 SET_HCIDEV_DEV(hdev, &intf->dev);
3778 reset_gpio = gpiod_get_optional(&data->udev->dev, "reset",
3780 if (IS_ERR(reset_gpio)) {
3781 err = PTR_ERR(reset_gpio);
3783 } else if (reset_gpio) {
3784 data->reset_gpio = reset_gpio;
3787 hdev->open = btusb_open;
3788 hdev->close = btusb_close;
3789 hdev->flush = btusb_flush;
3790 hdev->send = btusb_send_frame;
3791 hdev->notify = btusb_notify;
3792 hdev->wakeup = btusb_wakeup;
3795 err = btusb_config_oob_wake(hdev);
3799 /* Marvell devices may need a specific chip configuration */
3800 if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) {
3801 err = marvell_config_oob_wake(hdev);
3806 if (id->driver_info & BTUSB_CW6622)
3807 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
3809 if (id->driver_info & BTUSB_BCM2045)
3810 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
3812 if (id->driver_info & BTUSB_BCM92035)
3813 hdev->setup = btusb_setup_bcm92035;
3815 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
3816 (id->driver_info & BTUSB_BCM_PATCHRAM)) {
3817 hdev->manufacturer = 15;
3818 hdev->setup = btbcm_setup_patchram;
3819 hdev->set_diag = btusb_bcm_set_diag;
3820 hdev->set_bdaddr = btbcm_set_bdaddr;
3822 /* Broadcom LM_DIAG Interface numbers are hardcoded */
3823 data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
3826 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
3827 (id->driver_info & BTUSB_BCM_APPLE)) {
3828 hdev->manufacturer = 15;
3829 hdev->setup = btbcm_setup_apple;
3830 hdev->set_diag = btusb_bcm_set_diag;
3832 /* Broadcom LM_DIAG Interface numbers are hardcoded */
3833 data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
3836 /* Combined Intel Device setup to support multiple setup routine */
3837 if (id->driver_info & BTUSB_INTEL_COMBINED) {
3838 err = btintel_configure_setup(hdev);
3842 /* Transport specific configuration */
3843 hdev->send = btusb_send_frame_intel;
3844 hdev->cmd_timeout = btusb_intel_cmd_timeout;
3846 if (id->driver_info & BTUSB_INTEL_NO_WBS_SUPPORT)
3847 btintel_set_flag(hdev, INTEL_ROM_LEGACY_NO_WBS_SUPPORT);
3849 if (id->driver_info & BTUSB_INTEL_BROKEN_INITIAL_NCMD)
3850 btintel_set_flag(hdev, INTEL_BROKEN_INITIAL_NCMD);
3852 if (id->driver_info & BTUSB_INTEL_BROKEN_SHUTDOWN_LED)
3853 btintel_set_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED);
3856 if (id->driver_info & BTUSB_MARVELL)
3857 hdev->set_bdaddr = btusb_set_bdaddr_marvell;
3859 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) &&
3860 (id->driver_info & BTUSB_MEDIATEK)) {
3861 hdev->setup = btusb_mtk_setup;
3862 hdev->shutdown = btusb_mtk_shutdown;
3863 hdev->manufacturer = 70;
3864 hdev->cmd_timeout = btusb_mtk_cmd_timeout;
3865 hdev->set_bdaddr = btmtk_set_bdaddr;
3866 set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks);
3867 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
3868 data->recv_acl = btusb_recv_acl_mtk;
3871 if (id->driver_info & BTUSB_SWAVE) {
3872 set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
3873 set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks);
3876 if (id->driver_info & BTUSB_INTEL_BOOT) {
3877 hdev->manufacturer = 2;
3878 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
3881 if (id->driver_info & BTUSB_ATH3012) {
3882 data->setup_on_usb = btusb_setup_qca;
3883 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
3884 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
3885 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
3888 if (id->driver_info & BTUSB_QCA_ROME) {
3889 data->setup_on_usb = btusb_setup_qca;
3890 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
3891 hdev->cmd_timeout = btusb_qca_cmd_timeout;
3892 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
3893 btusb_check_needs_reset_resume(intf);
3896 if (id->driver_info & BTUSB_QCA_WCN6855) {
3897 data->setup_on_usb = btusb_setup_qca;
3898 hdev->shutdown = btusb_shutdown_qca;
3899 hdev->set_bdaddr = btusb_set_bdaddr_wcn6855;
3900 hdev->cmd_timeout = btusb_qca_cmd_timeout;
3901 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
3902 hci_set_msft_opcode(hdev, 0xFD70);
3905 if (id->driver_info & BTUSB_AMP) {
3906 /* AMP controllers do not support SCO packets */
3909 /* Interface orders are hardcoded in the specification */
3910 data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1);
3911 data->isoc_ifnum = ifnum_base + 1;
3914 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) &&
3915 (id->driver_info & BTUSB_REALTEK)) {
3916 hdev->setup = btrtl_setup_realtek;
3917 hdev->shutdown = btrtl_shutdown_realtek;
3918 hdev->cmd_timeout = btusb_rtl_cmd_timeout;
3920 /* Realtek devices need to set remote wakeup on auto-suspend */
3921 set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags);
3922 set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags);
3926 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
3928 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
3929 if (!disable_scofix)
3930 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
3933 if (id->driver_info & BTUSB_BROKEN_ISOC)
3936 if (id->driver_info & BTUSB_WIDEBAND_SPEECH)
3937 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
3939 if (id->driver_info & BTUSB_VALID_LE_STATES)
3940 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
3942 if (id->driver_info & BTUSB_DIGIANSWER) {
3943 data->cmdreq_type = USB_TYPE_VENDOR;
3944 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
3947 if (id->driver_info & BTUSB_CSR) {
3948 struct usb_device *udev = data->udev;
3949 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
3951 /* Old firmware would otherwise execute USB reset */
3952 if (bcdDevice < 0x117)
3953 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
3955 /* This must be set first in case we disable it for fakes */
3956 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
3958 /* Fake CSR devices with broken commands */
3959 if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 &&
3960 le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
3961 hdev->setup = btusb_setup_csr;
3964 if (id->driver_info & BTUSB_SNIFFER) {
3965 struct usb_device *udev = data->udev;
3967 /* New sniffer firmware has crippled HCI interface */
3968 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
3969 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
3972 if (id->driver_info & BTUSB_INTEL_BOOT) {
3973 /* A bug in the bootloader causes that interrupt interface is
3974 * only enabled after receiving SetInterface(0, AltSetting=0).
3976 err = usb_set_interface(data->udev, 0, 0);
3978 BT_ERR("failed to set interface 0, alt 0 %d", err);
3984 err = usb_driver_claim_interface(&btusb_driver,
3990 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) {
3991 if (!usb_driver_claim_interface(&btusb_driver,
3993 __set_diag_interface(hdev);
3998 if (enable_autosuspend)
3999 usb_enable_autosuspend(data->udev);
4001 err = hci_register_dev(hdev);
4005 usb_set_intfdata(intf, data);
4007 debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data,
4008 &force_poll_sync_fops);
4013 if (data->reset_gpio)
4014 gpiod_put(data->reset_gpio);
4019 static void btusb_disconnect(struct usb_interface *intf)
4021 struct btusb_data *data = usb_get_intfdata(intf);
4022 struct hci_dev *hdev;
4024 BT_DBG("intf %p", intf);
4030 usb_set_intfdata(data->intf, NULL);
4033 usb_set_intfdata(data->isoc, NULL);
4036 usb_set_intfdata(data->diag, NULL);
4038 hci_unregister_dev(hdev);
4040 if (intf == data->intf) {
4042 usb_driver_release_interface(&btusb_driver, data->isoc);
4044 usb_driver_release_interface(&btusb_driver, data->diag);
4045 } else if (intf == data->isoc) {
4047 usb_driver_release_interface(&btusb_driver, data->diag);
4048 usb_driver_release_interface(&btusb_driver, data->intf);
4049 } else if (intf == data->diag) {
4050 usb_driver_release_interface(&btusb_driver, data->intf);
4052 usb_driver_release_interface(&btusb_driver, data->isoc);
4055 if (data->oob_wake_irq)
4056 device_init_wakeup(&data->udev->dev, false);
4058 if (data->reset_gpio)
4059 gpiod_put(data->reset_gpio);
4065 static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
4067 struct btusb_data *data = usb_get_intfdata(intf);
4069 BT_DBG("intf %p", intf);
4071 if (data->suspend_count++)
4074 spin_lock_irq(&data->txlock);
4075 if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
4076 set_bit(BTUSB_SUSPENDING, &data->flags);
4077 spin_unlock_irq(&data->txlock);
4079 spin_unlock_irq(&data->txlock);
4080 data->suspend_count--;
4084 cancel_work_sync(&data->work);
4086 btusb_stop_traffic(data);
4087 usb_kill_anchored_urbs(&data->tx_anchor);
4089 if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) {
4090 set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags);
4091 enable_irq_wake(data->oob_wake_irq);
4092 enable_irq(data->oob_wake_irq);
4095 /* For global suspend, Realtek devices lose the loaded fw
4096 * in them. But for autosuspend, firmware should remain.
4097 * Actually, it depends on whether the usb host sends
4098 * set feature (enable wakeup) or not.
4100 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) {
4101 if (PMSG_IS_AUTO(message) &&
4102 device_can_wakeup(&data->udev->dev))
4103 data->udev->do_remote_wakeup = 1;
4104 else if (!PMSG_IS_AUTO(message) &&
4105 !device_may_wakeup(&data->udev->dev)) {
4106 data->udev->do_remote_wakeup = 0;
4107 data->udev->reset_resume = 1;
4114 static void play_deferred(struct btusb_data *data)
4119 while ((urb = usb_get_from_anchor(&data->deferred))) {
4120 usb_anchor_urb(urb, &data->tx_anchor);
4122 err = usb_submit_urb(urb, GFP_ATOMIC);
4124 if (err != -EPERM && err != -ENODEV)
4125 BT_ERR("%s urb %p submission failed (%d)",
4126 data->hdev->name, urb, -err);
4127 kfree(urb->setup_packet);
4128 usb_unanchor_urb(urb);
4133 data->tx_in_flight++;
4137 /* Cleanup the rest deferred urbs. */
4138 while ((urb = usb_get_from_anchor(&data->deferred))) {
4139 kfree(urb->setup_packet);
4144 static int btusb_resume(struct usb_interface *intf)
4146 struct btusb_data *data = usb_get_intfdata(intf);
4147 struct hci_dev *hdev = data->hdev;
4150 BT_DBG("intf %p", intf);
4152 if (--data->suspend_count)
4155 /* Disable only if not already disabled (keep it balanced) */
4156 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) {
4157 disable_irq(data->oob_wake_irq);
4158 disable_irq_wake(data->oob_wake_irq);
4161 if (!test_bit(HCI_RUNNING, &hdev->flags))
4164 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
4165 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
4167 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
4172 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
4173 err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
4175 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
4179 btusb_submit_bulk_urb(hdev, GFP_NOIO);
4182 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
4183 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
4184 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
4186 btusb_submit_isoc_urb(hdev, GFP_NOIO);
4189 spin_lock_irq(&data->txlock);
4190 play_deferred(data);
4191 clear_bit(BTUSB_SUSPENDING, &data->flags);
4192 spin_unlock_irq(&data->txlock);
4193 schedule_work(&data->work);
4198 usb_scuttle_anchored_urbs(&data->deferred);
4200 spin_lock_irq(&data->txlock);
4201 clear_bit(BTUSB_SUSPENDING, &data->flags);
4202 spin_unlock_irq(&data->txlock);
4208 static struct usb_driver btusb_driver = {
4210 .probe = btusb_probe,
4211 .disconnect = btusb_disconnect,
4213 .suspend = btusb_suspend,
4214 .resume = btusb_resume,
4216 .id_table = btusb_table,
4217 .supports_autosuspend = 1,
4218 .disable_hub_initiated_lpm = 1,
4221 module_usb_driver(btusb_driver);
4223 module_param(disable_scofix, bool, 0644);
4224 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
4226 module_param(force_scofix, bool, 0644);
4227 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
4229 module_param(enable_autosuspend, bool, 0644);
4230 MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default");
4232 module_param(reset, bool, 0644);
4233 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
4235 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
4236 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
4237 MODULE_VERSION(VERSION);
4238 MODULE_LICENSE("GPL");