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 enable_poll_sync = IS_ENABLED(CONFIG_BT_HCIBTUSB_POLL_SYNC);
36 static bool reset = true;
38 static struct usb_driver btusb_driver;
40 #define BTUSB_IGNORE BIT(0)
41 #define BTUSB_DIGIANSWER BIT(1)
42 #define BTUSB_CSR BIT(2)
43 #define BTUSB_SNIFFER BIT(3)
44 #define BTUSB_BCM92035 BIT(4)
45 #define BTUSB_BROKEN_ISOC BIT(5)
46 #define BTUSB_WRONG_SCO_MTU BIT(6)
47 #define BTUSB_ATH3012 BIT(7)
48 #define BTUSB_INTEL_COMBINED BIT(8)
49 #define BTUSB_INTEL_BOOT BIT(9)
50 #define BTUSB_BCM_PATCHRAM BIT(10)
51 #define BTUSB_MARVELL BIT(11)
52 #define BTUSB_SWAVE BIT(12)
53 #define BTUSB_AMP BIT(13)
54 #define BTUSB_QCA_ROME BIT(14)
55 #define BTUSB_BCM_APPLE BIT(15)
56 #define BTUSB_REALTEK BIT(16)
57 #define BTUSB_BCM2045 BIT(17)
58 #define BTUSB_IFNUM_2 BIT(18)
59 #define BTUSB_CW6622 BIT(19)
60 #define BTUSB_MEDIATEK BIT(20)
61 #define BTUSB_WIDEBAND_SPEECH BIT(21)
62 #define BTUSB_VALID_LE_STATES BIT(22)
63 #define BTUSB_QCA_WCN6855 BIT(23)
64 #define BTUSB_INTEL_BROKEN_SHUTDOWN_LED BIT(24)
65 #define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25)
66 #define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26)
67 #define BTUSB_ACTIONS_SEMI BIT(27)
69 static const struct usb_device_id btusb_table[] = {
70 /* Generic Bluetooth USB device */
71 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
73 /* Generic Bluetooth AMP device */
74 { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP },
76 /* Generic Bluetooth USB interface */
77 { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) },
79 /* Apple-specific (Broadcom) devices */
80 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01),
81 .driver_info = BTUSB_BCM_APPLE | BTUSB_IFNUM_2 },
83 /* MediaTek MT76x0E */
84 { USB_DEVICE(0x0e8d, 0x763f) },
86 /* Broadcom SoftSailing reporting vendor specific */
87 { USB_DEVICE(0x0a5c, 0x21e1) },
89 /* Apple MacBookPro 7,1 */
90 { USB_DEVICE(0x05ac, 0x8213) },
93 { USB_DEVICE(0x05ac, 0x8215) },
95 /* Apple MacBookPro6,2 */
96 { USB_DEVICE(0x05ac, 0x8218) },
98 /* Apple MacBookAir3,1, MacBookAir3,2 */
99 { USB_DEVICE(0x05ac, 0x821b) },
101 /* Apple MacBookAir4,1 */
102 { USB_DEVICE(0x05ac, 0x821f) },
104 /* Apple MacBookPro8,2 */
105 { USB_DEVICE(0x05ac, 0x821a) },
107 /* Apple MacMini5,1 */
108 { USB_DEVICE(0x05ac, 0x8281) },
110 /* AVM BlueFRITZ! USB v2.0 */
111 { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE },
113 /* Bluetooth Ultraport Module from IBM */
114 { USB_DEVICE(0x04bf, 0x030a) },
116 /* ALPS Modules with non-standard id */
117 { USB_DEVICE(0x044e, 0x3001) },
118 { USB_DEVICE(0x044e, 0x3002) },
120 /* Ericsson with non-standard id */
121 { USB_DEVICE(0x0bdb, 0x1002) },
123 /* Canyon CN-BTU1 with HID interfaces */
124 { USB_DEVICE(0x0c10, 0x0000) },
126 /* Broadcom BCM20702B0 (Dynex/Insignia) */
127 { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM },
129 /* Broadcom BCM43142A0 (Foxconn/Lenovo) */
130 { USB_VENDOR_AND_INTERFACE_INFO(0x105b, 0xff, 0x01, 0x01),
131 .driver_info = BTUSB_BCM_PATCHRAM },
133 /* Broadcom BCM920703 (HTC Vive) */
134 { USB_VENDOR_AND_INTERFACE_INFO(0x0bb4, 0xff, 0x01, 0x01),
135 .driver_info = BTUSB_BCM_PATCHRAM },
137 /* Foxconn - Hon Hai */
138 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
139 .driver_info = BTUSB_BCM_PATCHRAM },
141 /* Lite-On Technology - Broadcom based */
142 { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
143 .driver_info = BTUSB_BCM_PATCHRAM },
145 /* Broadcom devices with vendor specific id */
146 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
147 .driver_info = BTUSB_BCM_PATCHRAM },
149 /* ASUSTek Computer - Broadcom based */
150 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
151 .driver_info = BTUSB_BCM_PATCHRAM },
153 /* Belkin F8065bf - Broadcom based */
154 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01),
155 .driver_info = BTUSB_BCM_PATCHRAM },
157 /* IMC Networks - Broadcom based */
158 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01),
159 .driver_info = BTUSB_BCM_PATCHRAM },
161 /* Dell Computer - Broadcom based */
162 { USB_VENDOR_AND_INTERFACE_INFO(0x413c, 0xff, 0x01, 0x01),
163 .driver_info = BTUSB_BCM_PATCHRAM },
165 /* Toshiba Corp - Broadcom based */
166 { USB_VENDOR_AND_INTERFACE_INFO(0x0930, 0xff, 0x01, 0x01),
167 .driver_info = BTUSB_BCM_PATCHRAM },
169 /* Intel Bluetooth USB Bootloader (RAM module) */
170 { USB_DEVICE(0x8087, 0x0a5a),
171 .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC },
173 { } /* Terminating entry */
176 MODULE_DEVICE_TABLE(usb, btusb_table);
178 static const struct usb_device_id quirks_table[] = {
179 /* CSR BlueCore devices */
180 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
182 /* Broadcom BCM2033 without firmware */
183 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
185 /* Broadcom BCM2045 devices */
186 { USB_DEVICE(0x0a5c, 0x2045), .driver_info = BTUSB_BCM2045 },
188 /* Atheros 3011 with sflash firmware */
189 { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
190 { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
191 { USB_DEVICE(0x04f2, 0xaff1), .driver_info = BTUSB_IGNORE },
192 { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
193 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
194 { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
195 { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
197 /* Atheros AR9285 Malbec with sflash firmware */
198 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
200 /* Atheros 3012 with sflash firmware */
201 { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
202 { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
203 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
204 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
205 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
206 { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 },
207 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
208 { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 },
209 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
210 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
211 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
212 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
213 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
214 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
215 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
216 { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 },
217 { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
218 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
219 { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 },
220 { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 },
221 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
222 { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 },
223 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
224 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
225 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
226 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
227 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
228 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
229 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
230 { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
231 { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 },
232 { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
233 { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
234 { USB_DEVICE(0x0cf3, 0x817b), .driver_info = BTUSB_ATH3012 },
235 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
236 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
237 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
238 { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
239 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
240 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
241 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
242 { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 },
243 { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
244 { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
245 { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
246 { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
247 { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 },
248 { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 },
249 { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 },
250 { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 },
252 /* Atheros AR5BBU12 with sflash firmware */
253 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
255 /* Atheros AR5BBU12 with sflash firmware */
256 { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
257 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
259 /* QCA ROME chipset */
260 { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME |
261 BTUSB_WIDEBAND_SPEECH },
262 { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME |
263 BTUSB_WIDEBAND_SPEECH },
264 { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME |
265 BTUSB_WIDEBAND_SPEECH },
266 { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME |
267 BTUSB_WIDEBAND_SPEECH },
268 { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME |
269 BTUSB_WIDEBAND_SPEECH },
270 { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME |
271 BTUSB_WIDEBAND_SPEECH },
272 { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME |
273 BTUSB_WIDEBAND_SPEECH },
274 { USB_DEVICE(0x0cf3, 0xe500), .driver_info = BTUSB_QCA_ROME |
275 BTUSB_WIDEBAND_SPEECH },
276 { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME |
277 BTUSB_WIDEBAND_SPEECH },
278 { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME |
279 BTUSB_WIDEBAND_SPEECH },
280 { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME |
281 BTUSB_WIDEBAND_SPEECH },
282 { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME |
283 BTUSB_WIDEBAND_SPEECH },
284 { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME |
285 BTUSB_WIDEBAND_SPEECH },
286 { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME |
287 BTUSB_WIDEBAND_SPEECH },
288 { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME |
289 BTUSB_WIDEBAND_SPEECH },
290 { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME |
291 BTUSB_WIDEBAND_SPEECH },
292 { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME |
293 BTUSB_WIDEBAND_SPEECH },
294 { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME |
295 BTUSB_WIDEBAND_SPEECH },
296 { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME |
297 BTUSB_WIDEBAND_SPEECH },
299 /* QCA WCN6855 chipset */
300 { USB_DEVICE(0x0cf3, 0xe600), .driver_info = BTUSB_QCA_WCN6855 |
301 BTUSB_WIDEBAND_SPEECH |
302 BTUSB_VALID_LE_STATES },
303 { USB_DEVICE(0x0489, 0xe0cc), .driver_info = BTUSB_QCA_WCN6855 |
304 BTUSB_WIDEBAND_SPEECH |
305 BTUSB_VALID_LE_STATES },
306 { USB_DEVICE(0x0489, 0xe0d6), .driver_info = BTUSB_QCA_WCN6855 |
307 BTUSB_WIDEBAND_SPEECH |
308 BTUSB_VALID_LE_STATES },
309 { USB_DEVICE(0x0489, 0xe0e3), .driver_info = BTUSB_QCA_WCN6855 |
310 BTUSB_WIDEBAND_SPEECH |
311 BTUSB_VALID_LE_STATES },
312 { USB_DEVICE(0x10ab, 0x9309), .driver_info = BTUSB_QCA_WCN6855 |
313 BTUSB_WIDEBAND_SPEECH |
314 BTUSB_VALID_LE_STATES },
315 { USB_DEVICE(0x10ab, 0x9409), .driver_info = BTUSB_QCA_WCN6855 |
316 BTUSB_WIDEBAND_SPEECH |
317 BTUSB_VALID_LE_STATES },
318 { USB_DEVICE(0x0489, 0xe0d0), .driver_info = BTUSB_QCA_WCN6855 |
319 BTUSB_WIDEBAND_SPEECH |
320 BTUSB_VALID_LE_STATES },
321 { USB_DEVICE(0x10ab, 0x9108), .driver_info = BTUSB_QCA_WCN6855 |
322 BTUSB_WIDEBAND_SPEECH |
323 BTUSB_VALID_LE_STATES },
324 { USB_DEVICE(0x10ab, 0x9109), .driver_info = BTUSB_QCA_WCN6855 |
325 BTUSB_WIDEBAND_SPEECH |
326 BTUSB_VALID_LE_STATES },
327 { USB_DEVICE(0x10ab, 0x9208), .driver_info = BTUSB_QCA_WCN6855 |
328 BTUSB_WIDEBAND_SPEECH |
329 BTUSB_VALID_LE_STATES },
330 { USB_DEVICE(0x10ab, 0x9209), .driver_info = BTUSB_QCA_WCN6855 |
331 BTUSB_WIDEBAND_SPEECH |
332 BTUSB_VALID_LE_STATES },
333 { USB_DEVICE(0x10ab, 0x9308), .driver_info = BTUSB_QCA_WCN6855 |
334 BTUSB_WIDEBAND_SPEECH |
335 BTUSB_VALID_LE_STATES },
336 { USB_DEVICE(0x10ab, 0x9408), .driver_info = BTUSB_QCA_WCN6855 |
337 BTUSB_WIDEBAND_SPEECH |
338 BTUSB_VALID_LE_STATES },
339 { USB_DEVICE(0x10ab, 0x9508), .driver_info = BTUSB_QCA_WCN6855 |
340 BTUSB_WIDEBAND_SPEECH |
341 BTUSB_VALID_LE_STATES },
342 { USB_DEVICE(0x10ab, 0x9509), .driver_info = BTUSB_QCA_WCN6855 |
343 BTUSB_WIDEBAND_SPEECH |
344 BTUSB_VALID_LE_STATES },
345 { USB_DEVICE(0x10ab, 0x9608), .driver_info = BTUSB_QCA_WCN6855 |
346 BTUSB_WIDEBAND_SPEECH |
347 BTUSB_VALID_LE_STATES },
348 { USB_DEVICE(0x10ab, 0x9609), .driver_info = BTUSB_QCA_WCN6855 |
349 BTUSB_WIDEBAND_SPEECH |
350 BTUSB_VALID_LE_STATES },
351 { USB_DEVICE(0x10ab, 0x9f09), .driver_info = BTUSB_QCA_WCN6855 |
352 BTUSB_WIDEBAND_SPEECH |
353 BTUSB_VALID_LE_STATES },
354 { USB_DEVICE(0x04ca, 0x3022), .driver_info = BTUSB_QCA_WCN6855 |
355 BTUSB_WIDEBAND_SPEECH |
356 BTUSB_VALID_LE_STATES },
357 { USB_DEVICE(0x0489, 0xe0c7), .driver_info = BTUSB_QCA_WCN6855 |
358 BTUSB_WIDEBAND_SPEECH |
359 BTUSB_VALID_LE_STATES },
360 { USB_DEVICE(0x0489, 0xe0c9), .driver_info = BTUSB_QCA_WCN6855 |
361 BTUSB_WIDEBAND_SPEECH |
362 BTUSB_VALID_LE_STATES },
363 { USB_DEVICE(0x0489, 0xe0ca), .driver_info = BTUSB_QCA_WCN6855 |
364 BTUSB_WIDEBAND_SPEECH |
365 BTUSB_VALID_LE_STATES },
366 { USB_DEVICE(0x0489, 0xe0cb), .driver_info = BTUSB_QCA_WCN6855 |
367 BTUSB_WIDEBAND_SPEECH |
368 BTUSB_VALID_LE_STATES },
369 { USB_DEVICE(0x0489, 0xe0ce), .driver_info = BTUSB_QCA_WCN6855 |
370 BTUSB_WIDEBAND_SPEECH |
371 BTUSB_VALID_LE_STATES },
372 { USB_DEVICE(0x0489, 0xe0de), .driver_info = BTUSB_QCA_WCN6855 |
373 BTUSB_WIDEBAND_SPEECH |
374 BTUSB_VALID_LE_STATES },
375 { USB_DEVICE(0x0489, 0xe0df), .driver_info = BTUSB_QCA_WCN6855 |
376 BTUSB_WIDEBAND_SPEECH |
377 BTUSB_VALID_LE_STATES },
378 { USB_DEVICE(0x0489, 0xe0e1), .driver_info = BTUSB_QCA_WCN6855 |
379 BTUSB_WIDEBAND_SPEECH |
380 BTUSB_VALID_LE_STATES },
381 { USB_DEVICE(0x0489, 0xe0ea), .driver_info = BTUSB_QCA_WCN6855 |
382 BTUSB_WIDEBAND_SPEECH |
383 BTUSB_VALID_LE_STATES },
384 { USB_DEVICE(0x0489, 0xe0ec), .driver_info = BTUSB_QCA_WCN6855 |
385 BTUSB_WIDEBAND_SPEECH |
386 BTUSB_VALID_LE_STATES },
387 { USB_DEVICE(0x04ca, 0x3023), .driver_info = BTUSB_QCA_WCN6855 |
388 BTUSB_WIDEBAND_SPEECH |
389 BTUSB_VALID_LE_STATES },
390 { USB_DEVICE(0x04ca, 0x3024), .driver_info = BTUSB_QCA_WCN6855 |
391 BTUSB_WIDEBAND_SPEECH |
392 BTUSB_VALID_LE_STATES },
393 { USB_DEVICE(0x04ca, 0x3a22), .driver_info = BTUSB_QCA_WCN6855 |
394 BTUSB_WIDEBAND_SPEECH |
395 BTUSB_VALID_LE_STATES },
396 { USB_DEVICE(0x04ca, 0x3a24), .driver_info = BTUSB_QCA_WCN6855 |
397 BTUSB_WIDEBAND_SPEECH |
398 BTUSB_VALID_LE_STATES },
399 { USB_DEVICE(0x04ca, 0x3a26), .driver_info = BTUSB_QCA_WCN6855 |
400 BTUSB_WIDEBAND_SPEECH |
401 BTUSB_VALID_LE_STATES },
402 { USB_DEVICE(0x04ca, 0x3a27), .driver_info = BTUSB_QCA_WCN6855 |
403 BTUSB_WIDEBAND_SPEECH |
404 BTUSB_VALID_LE_STATES },
406 /* QCA WCN785x chipset */
407 { USB_DEVICE(0x0cf3, 0xe700), .driver_info = BTUSB_QCA_WCN6855 |
408 BTUSB_WIDEBAND_SPEECH |
409 BTUSB_VALID_LE_STATES },
411 /* Broadcom BCM2035 */
412 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
413 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
414 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
416 /* Broadcom BCM2045 */
417 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
418 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
420 /* IBM/Lenovo ThinkPad with Broadcom chip */
421 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
422 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
424 /* HP laptop with Broadcom chip */
425 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
427 /* Dell laptop with Broadcom chip */
428 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
430 /* Dell Wireless 370 and 410 devices */
431 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
432 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
434 /* Belkin F8T012 and F8T013 devices */
435 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
436 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
438 /* Asus WL-BTD202 device */
439 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
441 /* Kensington Bluetooth USB adapter */
442 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
444 /* RTX Telecom based adapters with buggy SCO support */
445 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
446 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
448 /* CONWISE Technology based adapters with buggy SCO support */
449 { USB_DEVICE(0x0e5e, 0x6622),
450 .driver_info = BTUSB_BROKEN_ISOC | BTUSB_CW6622},
452 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
453 { USB_DEVICE(0x1310, 0x0001), .driver_info = BTUSB_SWAVE },
455 /* Digianswer devices */
456 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
457 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
459 /* CSR BlueCore Bluetooth Sniffer */
460 { USB_DEVICE(0x0a12, 0x0002),
461 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
463 /* Frontline ComProbe Bluetooth Sniffer */
464 { USB_DEVICE(0x16d3, 0x0002),
465 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
467 /* Marvell Bluetooth devices */
468 { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL },
469 { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL },
470 { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL },
472 /* Intel Bluetooth devices */
473 { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_COMBINED },
474 { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_COMBINED },
475 { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_COMBINED },
476 { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_COMBINED },
477 { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_COMBINED },
478 { USB_DEVICE(0x8087, 0x0035), .driver_info = BTUSB_INTEL_COMBINED },
479 { USB_DEVICE(0x8087, 0x0036), .driver_info = BTUSB_INTEL_COMBINED },
480 { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR },
481 { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED |
482 BTUSB_INTEL_NO_WBS_SUPPORT |
483 BTUSB_INTEL_BROKEN_INITIAL_NCMD |
484 BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
485 { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED |
486 BTUSB_INTEL_NO_WBS_SUPPORT |
487 BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
488 { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_COMBINED },
489 { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL_COMBINED |
490 BTUSB_INTEL_BROKEN_SHUTDOWN_LED },
491 { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_COMBINED },
493 /* Other Intel Bluetooth devices */
494 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
495 .driver_info = BTUSB_IGNORE },
497 /* Realtek 8821CE Bluetooth devices */
498 { USB_DEVICE(0x13d3, 0x3529), .driver_info = BTUSB_REALTEK |
499 BTUSB_WIDEBAND_SPEECH },
501 /* Realtek 8822CE Bluetooth devices */
502 { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK |
503 BTUSB_WIDEBAND_SPEECH },
504 { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK |
505 BTUSB_WIDEBAND_SPEECH },
507 /* Realtek 8822CU Bluetooth devices */
508 { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK |
509 BTUSB_WIDEBAND_SPEECH },
511 /* Realtek 8852AE Bluetooth devices */
512 { USB_DEVICE(0x0bda, 0x2852), .driver_info = BTUSB_REALTEK |
513 BTUSB_WIDEBAND_SPEECH },
514 { USB_DEVICE(0x0bda, 0xc852), .driver_info = BTUSB_REALTEK |
515 BTUSB_WIDEBAND_SPEECH },
516 { USB_DEVICE(0x0bda, 0x385a), .driver_info = BTUSB_REALTEK |
517 BTUSB_WIDEBAND_SPEECH },
518 { USB_DEVICE(0x0bda, 0x4852), .driver_info = BTUSB_REALTEK |
519 BTUSB_WIDEBAND_SPEECH },
520 { USB_DEVICE(0x04c5, 0x165c), .driver_info = BTUSB_REALTEK |
521 BTUSB_WIDEBAND_SPEECH },
522 { USB_DEVICE(0x04ca, 0x4006), .driver_info = BTUSB_REALTEK |
523 BTUSB_WIDEBAND_SPEECH },
524 { USB_DEVICE(0x0cb8, 0xc549), .driver_info = BTUSB_REALTEK |
525 BTUSB_WIDEBAND_SPEECH },
527 /* Realtek 8852CE Bluetooth devices */
528 { USB_DEVICE(0x04ca, 0x4007), .driver_info = BTUSB_REALTEK |
529 BTUSB_WIDEBAND_SPEECH },
530 { USB_DEVICE(0x04c5, 0x1675), .driver_info = BTUSB_REALTEK |
531 BTUSB_WIDEBAND_SPEECH },
532 { USB_DEVICE(0x0cb8, 0xc558), .driver_info = BTUSB_REALTEK |
533 BTUSB_WIDEBAND_SPEECH },
534 { USB_DEVICE(0x13d3, 0x3587), .driver_info = BTUSB_REALTEK |
535 BTUSB_WIDEBAND_SPEECH },
536 { USB_DEVICE(0x13d3, 0x3586), .driver_info = BTUSB_REALTEK |
537 BTUSB_WIDEBAND_SPEECH },
538 { USB_DEVICE(0x13d3, 0x3592), .driver_info = BTUSB_REALTEK |
539 BTUSB_WIDEBAND_SPEECH },
541 /* Realtek 8852BE Bluetooth devices */
542 { USB_DEVICE(0x0cb8, 0xc559), .driver_info = BTUSB_REALTEK |
543 BTUSB_WIDEBAND_SPEECH },
544 { USB_DEVICE(0x0bda, 0x887b), .driver_info = BTUSB_REALTEK |
545 BTUSB_WIDEBAND_SPEECH },
546 { USB_DEVICE(0x13d3, 0x3571), .driver_info = BTUSB_REALTEK |
547 BTUSB_WIDEBAND_SPEECH },
549 /* Realtek Bluetooth devices */
550 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
551 .driver_info = BTUSB_REALTEK },
553 /* MediaTek Bluetooth devices */
554 { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01),
555 .driver_info = BTUSB_MEDIATEK |
556 BTUSB_WIDEBAND_SPEECH |
557 BTUSB_VALID_LE_STATES },
559 /* Additional MediaTek MT7615E Bluetooth devices */
560 { USB_DEVICE(0x13d3, 0x3560), .driver_info = BTUSB_MEDIATEK},
562 /* Additional MediaTek MT7663 Bluetooth devices */
563 { USB_DEVICE(0x043e, 0x310c), .driver_info = BTUSB_MEDIATEK |
564 BTUSB_WIDEBAND_SPEECH |
565 BTUSB_VALID_LE_STATES },
566 { USB_DEVICE(0x04ca, 0x3801), .driver_info = BTUSB_MEDIATEK |
567 BTUSB_WIDEBAND_SPEECH |
568 BTUSB_VALID_LE_STATES },
570 /* Additional MediaTek MT7668 Bluetooth devices */
571 { USB_DEVICE(0x043e, 0x3109), .driver_info = BTUSB_MEDIATEK |
572 BTUSB_WIDEBAND_SPEECH |
573 BTUSB_VALID_LE_STATES },
575 /* Additional MediaTek MT7921 Bluetooth devices */
576 { USB_DEVICE(0x0489, 0xe0c8), .driver_info = BTUSB_MEDIATEK |
577 BTUSB_WIDEBAND_SPEECH |
578 BTUSB_VALID_LE_STATES },
579 { USB_DEVICE(0x0489, 0xe0e0), .driver_info = BTUSB_MEDIATEK |
580 BTUSB_WIDEBAND_SPEECH |
581 BTUSB_VALID_LE_STATES },
582 { USB_DEVICE(0x0489, 0xe0f2), .driver_info = BTUSB_MEDIATEK |
583 BTUSB_WIDEBAND_SPEECH |
584 BTUSB_VALID_LE_STATES },
585 { USB_DEVICE(0x04ca, 0x3802), .driver_info = BTUSB_MEDIATEK |
586 BTUSB_WIDEBAND_SPEECH |
587 BTUSB_VALID_LE_STATES },
588 { USB_DEVICE(0x13d3, 0x3563), .driver_info = BTUSB_MEDIATEK |
589 BTUSB_WIDEBAND_SPEECH |
590 BTUSB_VALID_LE_STATES },
591 { USB_DEVICE(0x13d3, 0x3564), .driver_info = BTUSB_MEDIATEK |
592 BTUSB_WIDEBAND_SPEECH |
593 BTUSB_VALID_LE_STATES },
594 { USB_DEVICE(0x13d3, 0x3567), .driver_info = BTUSB_MEDIATEK |
595 BTUSB_WIDEBAND_SPEECH |
596 BTUSB_VALID_LE_STATES },
597 { USB_DEVICE(0x13d3, 0x3578), .driver_info = BTUSB_MEDIATEK |
598 BTUSB_WIDEBAND_SPEECH |
599 BTUSB_VALID_LE_STATES },
600 { USB_DEVICE(0x13d3, 0x3583), .driver_info = BTUSB_MEDIATEK |
601 BTUSB_WIDEBAND_SPEECH |
602 BTUSB_VALID_LE_STATES },
603 { USB_DEVICE(0x0489, 0xe0cd), .driver_info = BTUSB_MEDIATEK |
604 BTUSB_WIDEBAND_SPEECH |
605 BTUSB_VALID_LE_STATES },
606 { USB_DEVICE(0x0e8d, 0x0608), .driver_info = BTUSB_MEDIATEK |
607 BTUSB_WIDEBAND_SPEECH |
608 BTUSB_VALID_LE_STATES },
610 /* MediaTek MT7922A Bluetooth devices */
611 { USB_DEVICE(0x0489, 0xe0d8), .driver_info = BTUSB_MEDIATEK |
612 BTUSB_WIDEBAND_SPEECH |
613 BTUSB_VALID_LE_STATES },
614 { USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK |
615 BTUSB_WIDEBAND_SPEECH |
616 BTUSB_VALID_LE_STATES },
617 { USB_DEVICE(0x0489, 0xe0f5), .driver_info = BTUSB_MEDIATEK |
618 BTUSB_WIDEBAND_SPEECH |
619 BTUSB_VALID_LE_STATES },
620 { USB_DEVICE(0x13d3, 0x3568), .driver_info = BTUSB_MEDIATEK |
621 BTUSB_WIDEBAND_SPEECH |
622 BTUSB_VALID_LE_STATES },
623 { USB_DEVICE(0x0489, 0xe0e2), .driver_info = BTUSB_MEDIATEK |
624 BTUSB_WIDEBAND_SPEECH |
625 BTUSB_VALID_LE_STATES },
626 { USB_DEVICE(0x0489, 0xe0e4), .driver_info = BTUSB_MEDIATEK |
627 BTUSB_WIDEBAND_SPEECH |
628 BTUSB_VALID_LE_STATES },
629 { USB_DEVICE(0x0489, 0xe0f1), .driver_info = BTUSB_MEDIATEK |
630 BTUSB_WIDEBAND_SPEECH |
631 BTUSB_VALID_LE_STATES },
632 { USB_DEVICE(0x0489, 0xe0f2), .driver_info = BTUSB_MEDIATEK |
633 BTUSB_WIDEBAND_SPEECH |
634 BTUSB_VALID_LE_STATES },
635 { USB_DEVICE(0x0489, 0xe0f5), .driver_info = BTUSB_MEDIATEK |
636 BTUSB_WIDEBAND_SPEECH |
637 BTUSB_VALID_LE_STATES },
638 { USB_DEVICE(0x0489, 0xe0f6), .driver_info = BTUSB_MEDIATEK |
639 BTUSB_WIDEBAND_SPEECH |
640 BTUSB_VALID_LE_STATES },
641 { USB_DEVICE(0x0489, 0xe102), .driver_info = BTUSB_MEDIATEK |
642 BTUSB_WIDEBAND_SPEECH |
643 BTUSB_VALID_LE_STATES },
644 { USB_DEVICE(0x04ca, 0x3804), .driver_info = BTUSB_MEDIATEK |
645 BTUSB_WIDEBAND_SPEECH |
646 BTUSB_VALID_LE_STATES },
648 /* Additional Realtek 8723AE Bluetooth devices */
649 { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK },
650 { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK },
652 /* Additional Realtek 8723BE Bluetooth devices */
653 { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK },
654 { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK },
655 { USB_DEVICE(0x04f2, 0xb49f), .driver_info = BTUSB_REALTEK },
656 { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK },
657 { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK },
658 { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK },
659 { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK },
661 /* Additional Realtek 8723BU Bluetooth devices */
662 { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK },
664 /* Additional Realtek 8723DE Bluetooth devices */
665 { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK },
666 { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK },
668 /* Additional Realtek 8761BUV Bluetooth devices */
669 { USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK |
670 BTUSB_WIDEBAND_SPEECH },
671 { USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK |
672 BTUSB_WIDEBAND_SPEECH },
673 { USB_DEVICE(0x2550, 0x8761), .driver_info = BTUSB_REALTEK |
674 BTUSB_WIDEBAND_SPEECH },
675 { USB_DEVICE(0x0bda, 0x8771), .driver_info = BTUSB_REALTEK |
676 BTUSB_WIDEBAND_SPEECH },
677 { USB_DEVICE(0x6655, 0x8771), .driver_info = BTUSB_REALTEK |
678 BTUSB_WIDEBAND_SPEECH },
679 { USB_DEVICE(0x7392, 0xc611), .driver_info = BTUSB_REALTEK |
680 BTUSB_WIDEBAND_SPEECH },
681 { USB_DEVICE(0x2b89, 0x8761), .driver_info = BTUSB_REALTEK |
682 BTUSB_WIDEBAND_SPEECH },
684 /* Additional Realtek 8821AE Bluetooth devices */
685 { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK },
686 { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK },
687 { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK },
688 { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK },
689 { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK },
691 /* Additional Realtek 8822BE Bluetooth devices */
692 { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK },
693 { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK },
695 /* Additional Realtek 8822CE Bluetooth devices */
696 { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK |
697 BTUSB_WIDEBAND_SPEECH },
698 { USB_DEVICE(0x04c5, 0x161f), .driver_info = BTUSB_REALTEK |
699 BTUSB_WIDEBAND_SPEECH },
700 { USB_DEVICE(0x0b05, 0x18ef), .driver_info = BTUSB_REALTEK |
701 BTUSB_WIDEBAND_SPEECH },
702 { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK |
703 BTUSB_WIDEBAND_SPEECH },
704 { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK |
705 BTUSB_WIDEBAND_SPEECH },
706 { USB_DEVICE(0x13d3, 0x3553), .driver_info = BTUSB_REALTEK |
707 BTUSB_WIDEBAND_SPEECH },
708 { USB_DEVICE(0x13d3, 0x3555), .driver_info = BTUSB_REALTEK |
709 BTUSB_WIDEBAND_SPEECH },
710 { USB_DEVICE(0x2ff8, 0x3051), .driver_info = BTUSB_REALTEK |
711 BTUSB_WIDEBAND_SPEECH },
712 { USB_DEVICE(0x1358, 0xc123), .driver_info = BTUSB_REALTEK |
713 BTUSB_WIDEBAND_SPEECH },
714 { USB_DEVICE(0x0bda, 0xc123), .driver_info = BTUSB_REALTEK |
715 BTUSB_WIDEBAND_SPEECH },
716 { USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK |
717 BTUSB_WIDEBAND_SPEECH },
719 /* Actions Semiconductor ATS2851 based devices */
720 { USB_DEVICE(0x10d7, 0xb012), .driver_info = BTUSB_ACTIONS_SEMI },
722 /* Silicon Wave based devices */
723 { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE },
725 { } /* Terminating entry */
728 /* The Bluetooth USB module build into some devices needs to be reset on resume,
729 * this is a problem with the platform (likely shutting off all power) not with
730 * the module itself. So we use a DMI list to match known broken platforms.
732 static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
734 /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */
736 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
737 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"),
741 /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */
743 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
744 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"),
748 /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */
750 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
751 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"),
757 struct qca_dump_info {
758 /* fields for dump collection */
767 #define BTUSB_MAX_ISOC_FRAMES 10
769 #define BTUSB_INTR_RUNNING 0
770 #define BTUSB_BULK_RUNNING 1
771 #define BTUSB_ISOC_RUNNING 2
772 #define BTUSB_SUSPENDING 3
773 #define BTUSB_DID_ISO_RESUME 4
774 #define BTUSB_BOOTLOADER 5
775 #define BTUSB_DOWNLOADING 6
776 #define BTUSB_FIRMWARE_LOADED 7
777 #define BTUSB_FIRMWARE_FAILED 8
778 #define BTUSB_BOOTING 9
779 #define BTUSB_DIAG_RUNNING 10
780 #define BTUSB_OOB_WAKE_ENABLED 11
781 #define BTUSB_HW_RESET_ACTIVE 12
782 #define BTUSB_TX_WAIT_VND_EVT 13
783 #define BTUSB_WAKEUP_AUTOSUSPEND 14
784 #define BTUSB_USE_ALT3_FOR_WBS 15
785 #define BTUSB_ALT6_CONTINUOUS_TX 16
786 #define BTUSB_HW_SSR_ACTIVE 17
789 struct hci_dev *hdev;
790 struct usb_device *udev;
791 struct usb_interface *intf;
792 struct usb_interface *isoc;
793 struct usb_interface *diag;
800 struct work_struct work;
801 struct work_struct waker;
802 struct delayed_work rx_work;
804 struct sk_buff_head acl_q;
806 struct usb_anchor deferred;
807 struct usb_anchor tx_anchor;
811 struct usb_anchor intr_anchor;
812 struct usb_anchor bulk_anchor;
813 struct usb_anchor isoc_anchor;
814 struct usb_anchor diag_anchor;
815 struct usb_anchor ctrl_anchor;
818 struct sk_buff *evt_skb;
819 struct sk_buff *acl_skb;
820 struct sk_buff *sco_skb;
822 struct usb_endpoint_descriptor *intr_ep;
823 struct usb_endpoint_descriptor *bulk_tx_ep;
824 struct usb_endpoint_descriptor *bulk_rx_ep;
825 struct usb_endpoint_descriptor *isoc_tx_ep;
826 struct usb_endpoint_descriptor *isoc_rx_ep;
827 struct usb_endpoint_descriptor *diag_tx_ep;
828 struct usb_endpoint_descriptor *diag_rx_ep;
830 struct gpio_desc *reset_gpio;
835 unsigned int sco_num;
836 unsigned int air_mode;
837 bool usb_alt6_packet_flow;
841 int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
842 int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb);
843 int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
845 int (*setup_on_usb)(struct hci_dev *hdev);
847 int oob_wake_irq; /* irq for out-of-band wake-on-bt */
848 unsigned cmd_timeout_cnt;
850 struct qca_dump_info qca_dump;
853 static void btusb_reset(struct hci_dev *hdev)
855 struct btusb_data *data;
863 data = hci_get_drvdata(hdev);
864 /* This is not an unbalanced PM reference since the device will reset */
865 err = usb_autopm_get_interface(data->intf);
867 bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err);
871 bt_dev_err(hdev, "Resetting usb device.");
872 usb_queue_reset_device(data->intf);
875 static void btusb_intel_cmd_timeout(struct hci_dev *hdev)
877 struct btusb_data *data = hci_get_drvdata(hdev);
878 struct gpio_desc *reset_gpio = data->reset_gpio;
879 struct btintel_data *intel_data = hci_get_priv(hdev);
881 if (++data->cmd_timeout_cnt < 5)
884 if (intel_data->acpi_reset_method) {
885 if (test_and_set_bit(INTEL_ACPI_RESET_ACTIVE, intel_data->flags)) {
886 bt_dev_err(hdev, "acpi: last reset failed ? Not resetting again");
890 bt_dev_err(hdev, "Initiating acpi reset method");
891 /* If ACPI reset method fails, lets try with legacy GPIO
894 if (!intel_data->acpi_reset_method(hdev)) {
905 * Toggle the hard reset line if the platform provides one. The reset
906 * is going to yank the device off the USB and then replug. So doing
907 * once is enough. The cleanup is handled correctly on the way out
908 * (standard USB disconnect), and the new device is detected cleanly
909 * and bound to the driver again like it should be.
911 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
912 bt_dev_err(hdev, "last reset failed? Not resetting again");
916 bt_dev_err(hdev, "Initiating HW reset via gpio");
917 gpiod_set_value_cansleep(reset_gpio, 1);
919 gpiod_set_value_cansleep(reset_gpio, 0);
922 #define RTK_DEVCOREDUMP_CODE_MEMDUMP 0x01
923 #define RTK_DEVCOREDUMP_CODE_HW_ERR 0x02
924 #define RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT 0x03
926 #define RTK_SUB_EVENT_CODE_COREDUMP 0x34
928 struct rtk_dev_coredump_hdr {
934 static inline void btusb_rtl_alloc_devcoredump(struct hci_dev *hdev,
935 struct rtk_dev_coredump_hdr *hdr, u8 *buf, u32 len)
939 skb = alloc_skb(len + sizeof(*hdr), GFP_ATOMIC);
943 skb_put_data(skb, hdr, sizeof(*hdr));
945 skb_put_data(skb, buf, len);
947 if (!hci_devcd_init(hdev, skb->len)) {
948 hci_devcd_append(hdev, skb);
949 hci_devcd_complete(hdev);
951 bt_dev_err(hdev, "RTL: Failed to generate devcoredump");
956 static void btusb_rtl_cmd_timeout(struct hci_dev *hdev)
958 struct btusb_data *data = hci_get_drvdata(hdev);
959 struct gpio_desc *reset_gpio = data->reset_gpio;
960 struct rtk_dev_coredump_hdr hdr = {
961 .type = RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT,
964 btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0);
966 if (++data->cmd_timeout_cnt < 5)
974 /* Toggle the hard reset line. The Realtek device is going to
975 * yank itself off the USB and then replug. The cleanup is handled
976 * correctly on the way out (standard USB disconnect), and the new
977 * device is detected cleanly and bound to the driver again like
980 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
981 bt_dev_err(hdev, "last reset failed? Not resetting again");
985 bt_dev_err(hdev, "Reset Realtek device via gpio");
986 gpiod_set_value_cansleep(reset_gpio, 1);
988 gpiod_set_value_cansleep(reset_gpio, 0);
991 static void btusb_rtl_hw_error(struct hci_dev *hdev, u8 code)
993 struct rtk_dev_coredump_hdr hdr = {
994 .type = RTK_DEVCOREDUMP_CODE_HW_ERR,
998 bt_dev_err(hdev, "RTL: hw err, trigger devcoredump (%d)", code);
1000 btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0);
1003 static void btusb_qca_cmd_timeout(struct hci_dev *hdev)
1005 struct btusb_data *data = hci_get_drvdata(hdev);
1006 struct gpio_desc *reset_gpio = data->reset_gpio;
1008 if (test_bit(BTUSB_HW_SSR_ACTIVE, &data->flags)) {
1009 bt_dev_info(hdev, "Ramdump in progress, defer cmd_timeout");
1013 if (++data->cmd_timeout_cnt < 5)
1017 bt_dev_err(hdev, "Reset qca device via bt_en gpio");
1019 /* Toggle the hard reset line. The qca bt device is going to
1020 * yank itself off the USB and then replug. The cleanup is handled
1021 * correctly on the way out (standard USB disconnect), and the new
1022 * device is detected cleanly and bound to the driver again like
1025 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
1026 bt_dev_err(hdev, "last reset failed? Not resetting again");
1030 gpiod_set_value_cansleep(reset_gpio, 0);
1032 gpiod_set_value_cansleep(reset_gpio, 1);
1040 static inline void btusb_free_frags(struct btusb_data *data)
1042 unsigned long flags;
1044 spin_lock_irqsave(&data->rxlock, flags);
1046 dev_kfree_skb_irq(data->evt_skb);
1047 data->evt_skb = NULL;
1049 dev_kfree_skb_irq(data->acl_skb);
1050 data->acl_skb = NULL;
1052 dev_kfree_skb_irq(data->sco_skb);
1053 data->sco_skb = NULL;
1055 spin_unlock_irqrestore(&data->rxlock, flags);
1058 static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
1060 if (data->intr_interval) {
1061 /* Trigger dequeue immediatelly if an event is received */
1062 schedule_delayed_work(&data->rx_work, 0);
1065 return data->recv_event(data->hdev, skb);
1068 static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
1070 struct sk_buff *skb;
1071 unsigned long flags;
1074 spin_lock_irqsave(&data->rxlock, flags);
1075 skb = data->evt_skb;
1081 skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC);
1087 hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
1088 hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE;
1091 len = min_t(uint, hci_skb_expect(skb), count);
1092 skb_put_data(skb, buffer, len);
1096 hci_skb_expect(skb) -= len;
1098 if (skb->len == HCI_EVENT_HDR_SIZE) {
1099 /* Complete event header */
1100 hci_skb_expect(skb) = hci_event_hdr(skb)->plen;
1102 if (skb_tailroom(skb) < hci_skb_expect(skb)) {
1111 if (!hci_skb_expect(skb)) {
1112 /* Complete frame */
1113 btusb_recv_event(data, skb);
1118 data->evt_skb = skb;
1119 spin_unlock_irqrestore(&data->rxlock, flags);
1124 static int btusb_recv_acl(struct btusb_data *data, struct sk_buff *skb)
1126 /* Only queue ACL packet if intr_interval is set as it means
1127 * force_poll_sync has been enabled.
1129 if (!data->intr_interval)
1130 return data->recv_acl(data->hdev, skb);
1132 skb_queue_tail(&data->acl_q, skb);
1133 schedule_delayed_work(&data->rx_work, data->intr_interval);
1138 static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
1140 struct sk_buff *skb;
1141 unsigned long flags;
1144 spin_lock_irqsave(&data->rxlock, flags);
1145 skb = data->acl_skb;
1151 skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
1157 hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT;
1158 hci_skb_expect(skb) = HCI_ACL_HDR_SIZE;
1161 len = min_t(uint, hci_skb_expect(skb), count);
1162 skb_put_data(skb, buffer, len);
1166 hci_skb_expect(skb) -= len;
1168 if (skb->len == HCI_ACL_HDR_SIZE) {
1169 __le16 dlen = hci_acl_hdr(skb)->dlen;
1171 /* Complete ACL header */
1172 hci_skb_expect(skb) = __le16_to_cpu(dlen);
1174 if (skb_tailroom(skb) < hci_skb_expect(skb)) {
1183 if (!hci_skb_expect(skb)) {
1184 /* Complete frame */
1185 btusb_recv_acl(data, skb);
1190 data->acl_skb = skb;
1191 spin_unlock_irqrestore(&data->rxlock, flags);
1196 static bool btusb_validate_sco_handle(struct hci_dev *hdev,
1197 struct hci_sco_hdr *hdr)
1201 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL))
1202 // Can't validate, userspace controls everything.
1206 * USB isochronous transfers are not designed to be reliable and may
1207 * lose fragments. When this happens, the next first fragment
1208 * encountered might actually be a continuation fragment.
1209 * Validate the handle to detect it and drop it, or else the upper
1210 * layer will get garbage for a while.
1213 handle = hci_handle(__le16_to_cpu(hdr->handle));
1215 switch (hci_conn_lookup_type(hdev, handle)) {
1224 static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count)
1226 struct sk_buff *skb;
1227 unsigned long flags;
1230 spin_lock_irqsave(&data->rxlock, flags);
1231 skb = data->sco_skb;
1237 skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC);
1243 hci_skb_pkt_type(skb) = HCI_SCODATA_PKT;
1244 hci_skb_expect(skb) = HCI_SCO_HDR_SIZE;
1247 len = min_t(uint, hci_skb_expect(skb), count);
1248 skb_put_data(skb, buffer, len);
1252 hci_skb_expect(skb) -= len;
1254 if (skb->len == HCI_SCO_HDR_SIZE) {
1255 /* Complete SCO header */
1256 struct hci_sco_hdr *hdr = hci_sco_hdr(skb);
1258 hci_skb_expect(skb) = hdr->dlen;
1260 if (skb_tailroom(skb) < hci_skb_expect(skb) ||
1261 !btusb_validate_sco_handle(data->hdev, hdr)) {
1270 if (!hci_skb_expect(skb)) {
1271 /* Complete frame */
1272 hci_recv_frame(data->hdev, skb);
1277 data->sco_skb = skb;
1278 spin_unlock_irqrestore(&data->rxlock, flags);
1283 static void btusb_intr_complete(struct urb *urb)
1285 struct hci_dev *hdev = urb->context;
1286 struct btusb_data *data = hci_get_drvdata(hdev);
1289 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1290 urb->actual_length);
1292 if (!test_bit(HCI_RUNNING, &hdev->flags))
1295 if (urb->status == 0) {
1296 hdev->stat.byte_rx += urb->actual_length;
1298 if (btusb_recv_intr(data, urb->transfer_buffer,
1299 urb->actual_length) < 0) {
1300 bt_dev_err(hdev, "corrupted event packet");
1301 hdev->stat.err_rx++;
1303 } else if (urb->status == -ENOENT) {
1304 /* Avoid suspend failed when usb_kill_urb */
1308 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
1311 usb_mark_last_busy(data->udev);
1312 usb_anchor_urb(urb, &data->intr_anchor);
1314 err = usb_submit_urb(urb, GFP_ATOMIC);
1316 /* -EPERM: urb is being killed;
1317 * -ENODEV: device got disconnected
1319 if (err != -EPERM && err != -ENODEV)
1320 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1323 hci_cmd_sync_cancel(hdev, -err);
1324 usb_unanchor_urb(urb);
1328 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
1330 struct btusb_data *data = hci_get_drvdata(hdev);
1336 BT_DBG("%s", hdev->name);
1341 urb = usb_alloc_urb(0, mem_flags);
1345 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
1347 buf = kmalloc(size, mem_flags);
1353 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
1355 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
1356 btusb_intr_complete, hdev, data->intr_ep->bInterval);
1358 urb->transfer_flags |= URB_FREE_BUFFER;
1360 usb_anchor_urb(urb, &data->intr_anchor);
1362 err = usb_submit_urb(urb, mem_flags);
1364 if (err != -EPERM && err != -ENODEV)
1365 bt_dev_err(hdev, "urb %p submission failed (%d)",
1368 hci_cmd_sync_cancel(hdev, -err);
1369 usb_unanchor_urb(urb);
1372 /* Only initialize intr_interval if URB poll sync is enabled */
1373 if (!data->poll_sync)
1376 /* The units are frames (milliseconds) for full and low speed devices,
1377 * and microframes (1/8 millisecond) for highspeed and SuperSpeed
1380 * This is done once on open/resume so it shouldn't change even if
1381 * force_poll_sync changes.
1383 switch (urb->dev->speed) {
1384 case USB_SPEED_SUPER_PLUS:
1385 case USB_SPEED_SUPER: /* units are 125us */
1386 data->intr_interval = usecs_to_jiffies(urb->interval * 125);
1389 data->intr_interval = msecs_to_jiffies(urb->interval);
1399 static void btusb_bulk_complete(struct urb *urb)
1401 struct hci_dev *hdev = urb->context;
1402 struct btusb_data *data = hci_get_drvdata(hdev);
1405 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1406 urb->actual_length);
1408 if (!test_bit(HCI_RUNNING, &hdev->flags))
1411 if (urb->status == 0) {
1412 hdev->stat.byte_rx += urb->actual_length;
1414 if (data->recv_bulk(data, urb->transfer_buffer,
1415 urb->actual_length) < 0) {
1416 bt_dev_err(hdev, "corrupted ACL packet");
1417 hdev->stat.err_rx++;
1419 } else if (urb->status == -ENOENT) {
1420 /* Avoid suspend failed when usb_kill_urb */
1424 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
1427 usb_anchor_urb(urb, &data->bulk_anchor);
1428 usb_mark_last_busy(data->udev);
1430 err = usb_submit_urb(urb, GFP_ATOMIC);
1432 /* -EPERM: urb is being killed;
1433 * -ENODEV: device got disconnected
1435 if (err != -EPERM && err != -ENODEV)
1436 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1438 usb_unanchor_urb(urb);
1442 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
1444 struct btusb_data *data = hci_get_drvdata(hdev);
1448 int err, size = HCI_MAX_FRAME_SIZE;
1450 BT_DBG("%s", hdev->name);
1452 if (!data->bulk_rx_ep)
1455 urb = usb_alloc_urb(0, mem_flags);
1459 buf = kmalloc(size, mem_flags);
1465 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
1467 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
1468 btusb_bulk_complete, hdev);
1470 urb->transfer_flags |= URB_FREE_BUFFER;
1472 usb_mark_last_busy(data->udev);
1473 usb_anchor_urb(urb, &data->bulk_anchor);
1475 err = usb_submit_urb(urb, mem_flags);
1477 if (err != -EPERM && err != -ENODEV)
1478 bt_dev_err(hdev, "urb %p submission failed (%d)",
1480 usb_unanchor_urb(urb);
1488 static void btusb_isoc_complete(struct urb *urb)
1490 struct hci_dev *hdev = urb->context;
1491 struct btusb_data *data = hci_get_drvdata(hdev);
1494 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1495 urb->actual_length);
1497 if (!test_bit(HCI_RUNNING, &hdev->flags))
1500 if (urb->status == 0) {
1501 for (i = 0; i < urb->number_of_packets; i++) {
1502 unsigned int offset = urb->iso_frame_desc[i].offset;
1503 unsigned int length = urb->iso_frame_desc[i].actual_length;
1505 if (urb->iso_frame_desc[i].status)
1508 hdev->stat.byte_rx += length;
1510 if (btusb_recv_isoc(data, urb->transfer_buffer + offset,
1512 bt_dev_err(hdev, "corrupted SCO packet");
1513 hdev->stat.err_rx++;
1516 } else if (urb->status == -ENOENT) {
1517 /* Avoid suspend failed when usb_kill_urb */
1521 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
1524 usb_anchor_urb(urb, &data->isoc_anchor);
1526 err = usb_submit_urb(urb, GFP_ATOMIC);
1528 /* -EPERM: urb is being killed;
1529 * -ENODEV: device got disconnected
1531 if (err != -EPERM && err != -ENODEV)
1532 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1534 usb_unanchor_urb(urb);
1538 static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len,
1539 int mtu, struct btusb_data *data)
1541 int i = 0, offset = 0;
1542 unsigned int interval;
1544 BT_DBG("len %d mtu %d", len, mtu);
1546 /* For mSBC ALT 6 settings some chips need to transmit the data
1547 * continuously without the zero length of USB packets.
1549 if (test_bit(BTUSB_ALT6_CONTINUOUS_TX, &data->flags))
1550 goto ignore_usb_alt6_packet_flow;
1552 /* For mSBC ALT 6 setting the host will send the packet at continuous
1553 * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting
1554 * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets.
1555 * To maintain the rate we send 63bytes of usb packets alternatively for
1556 * 7ms and 8ms to maintain the rate as 7.5ms.
1558 if (data->usb_alt6_packet_flow) {
1560 data->usb_alt6_packet_flow = false;
1563 data->usb_alt6_packet_flow = true;
1566 for (i = 0; i < interval; i++) {
1567 urb->iso_frame_desc[i].offset = offset;
1568 urb->iso_frame_desc[i].length = offset;
1571 ignore_usb_alt6_packet_flow:
1572 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
1573 urb->iso_frame_desc[i].offset = offset;
1574 urb->iso_frame_desc[i].length = len;
1578 urb->number_of_packets = i;
1581 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
1585 BT_DBG("len %d mtu %d", len, mtu);
1587 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
1588 i++, offset += mtu, len -= mtu) {
1589 urb->iso_frame_desc[i].offset = offset;
1590 urb->iso_frame_desc[i].length = mtu;
1593 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
1594 urb->iso_frame_desc[i].offset = offset;
1595 urb->iso_frame_desc[i].length = len;
1599 urb->number_of_packets = i;
1602 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
1604 struct btusb_data *data = hci_get_drvdata(hdev);
1610 BT_DBG("%s", hdev->name);
1612 if (!data->isoc_rx_ep)
1615 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
1619 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
1620 BTUSB_MAX_ISOC_FRAMES;
1622 buf = kmalloc(size, mem_flags);
1628 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
1630 usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
1631 hdev, data->isoc_rx_ep->bInterval);
1633 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
1635 __fill_isoc_descriptor(urb, size,
1636 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
1638 usb_anchor_urb(urb, &data->isoc_anchor);
1640 err = usb_submit_urb(urb, mem_flags);
1642 if (err != -EPERM && err != -ENODEV)
1643 bt_dev_err(hdev, "urb %p submission failed (%d)",
1645 usb_unanchor_urb(urb);
1653 static void btusb_diag_complete(struct urb *urb)
1655 struct hci_dev *hdev = urb->context;
1656 struct btusb_data *data = hci_get_drvdata(hdev);
1659 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1660 urb->actual_length);
1662 if (urb->status == 0) {
1663 struct sk_buff *skb;
1665 skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC);
1667 skb_put_data(skb, urb->transfer_buffer,
1668 urb->actual_length);
1669 hci_recv_diag(hdev, skb);
1671 } else if (urb->status == -ENOENT) {
1672 /* Avoid suspend failed when usb_kill_urb */
1676 if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags))
1679 usb_anchor_urb(urb, &data->diag_anchor);
1680 usb_mark_last_busy(data->udev);
1682 err = usb_submit_urb(urb, GFP_ATOMIC);
1684 /* -EPERM: urb is being killed;
1685 * -ENODEV: device got disconnected
1687 if (err != -EPERM && err != -ENODEV)
1688 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
1690 usb_unanchor_urb(urb);
1694 static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags)
1696 struct btusb_data *data = hci_get_drvdata(hdev);
1700 int err, size = HCI_MAX_FRAME_SIZE;
1702 BT_DBG("%s", hdev->name);
1704 if (!data->diag_rx_ep)
1707 urb = usb_alloc_urb(0, mem_flags);
1711 buf = kmalloc(size, mem_flags);
1717 pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress);
1719 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
1720 btusb_diag_complete, hdev);
1722 urb->transfer_flags |= URB_FREE_BUFFER;
1724 usb_mark_last_busy(data->udev);
1725 usb_anchor_urb(urb, &data->diag_anchor);
1727 err = usb_submit_urb(urb, mem_flags);
1729 if (err != -EPERM && err != -ENODEV)
1730 bt_dev_err(hdev, "urb %p submission failed (%d)",
1732 usb_unanchor_urb(urb);
1740 static void btusb_tx_complete(struct urb *urb)
1742 struct sk_buff *skb = urb->context;
1743 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
1744 struct btusb_data *data = hci_get_drvdata(hdev);
1745 unsigned long flags;
1747 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1748 urb->actual_length);
1750 if (!test_bit(HCI_RUNNING, &hdev->flags))
1754 hdev->stat.byte_tx += urb->transfer_buffer_length;
1756 if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT)
1757 hci_cmd_sync_cancel(hdev, -urb->status);
1758 hdev->stat.err_tx++;
1762 spin_lock_irqsave(&data->txlock, flags);
1763 data->tx_in_flight--;
1764 spin_unlock_irqrestore(&data->txlock, flags);
1766 kfree(urb->setup_packet);
1771 static void btusb_isoc_tx_complete(struct urb *urb)
1773 struct sk_buff *skb = urb->context;
1774 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
1776 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
1777 urb->actual_length);
1779 if (!test_bit(HCI_RUNNING, &hdev->flags))
1783 hdev->stat.byte_tx += urb->transfer_buffer_length;
1785 hdev->stat.err_tx++;
1788 kfree(urb->setup_packet);
1793 static int btusb_open(struct hci_dev *hdev)
1795 struct btusb_data *data = hci_get_drvdata(hdev);
1798 BT_DBG("%s", hdev->name);
1800 err = usb_autopm_get_interface(data->intf);
1804 /* Patching USB firmware files prior to starting any URBs of HCI path
1805 * It is more safe to use USB bulk channel for downloading USB patch
1807 if (data->setup_on_usb) {
1808 err = data->setup_on_usb(hdev);
1813 data->intf->needs_remote_wakeup = 1;
1815 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
1818 err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
1822 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
1824 usb_kill_anchored_urbs(&data->intr_anchor);
1828 set_bit(BTUSB_BULK_RUNNING, &data->flags);
1829 btusb_submit_bulk_urb(hdev, GFP_KERNEL);
1832 if (!btusb_submit_diag_urb(hdev, GFP_KERNEL))
1833 set_bit(BTUSB_DIAG_RUNNING, &data->flags);
1837 usb_autopm_put_interface(data->intf);
1841 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1843 usb_autopm_put_interface(data->intf);
1847 static void btusb_stop_traffic(struct btusb_data *data)
1849 usb_kill_anchored_urbs(&data->intr_anchor);
1850 usb_kill_anchored_urbs(&data->bulk_anchor);
1851 usb_kill_anchored_urbs(&data->isoc_anchor);
1852 usb_kill_anchored_urbs(&data->diag_anchor);
1853 usb_kill_anchored_urbs(&data->ctrl_anchor);
1856 static int btusb_close(struct hci_dev *hdev)
1858 struct btusb_data *data = hci_get_drvdata(hdev);
1861 BT_DBG("%s", hdev->name);
1863 cancel_delayed_work(&data->rx_work);
1864 cancel_work_sync(&data->work);
1865 cancel_work_sync(&data->waker);
1867 skb_queue_purge(&data->acl_q);
1869 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1870 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
1871 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1872 clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
1874 btusb_stop_traffic(data);
1875 btusb_free_frags(data);
1877 err = usb_autopm_get_interface(data->intf);
1881 data->intf->needs_remote_wakeup = 0;
1883 /* Enable remote wake up for auto-suspend */
1884 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags))
1885 data->intf->needs_remote_wakeup = 1;
1887 usb_autopm_put_interface(data->intf);
1890 usb_scuttle_anchored_urbs(&data->deferred);
1894 static int btusb_flush(struct hci_dev *hdev)
1896 struct btusb_data *data = hci_get_drvdata(hdev);
1898 BT_DBG("%s", hdev->name);
1900 cancel_delayed_work(&data->rx_work);
1902 skb_queue_purge(&data->acl_q);
1904 usb_kill_anchored_urbs(&data->tx_anchor);
1905 btusb_free_frags(data);
1910 static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
1912 struct btusb_data *data = hci_get_drvdata(hdev);
1913 struct usb_ctrlrequest *dr;
1917 urb = usb_alloc_urb(0, GFP_KERNEL);
1919 return ERR_PTR(-ENOMEM);
1921 dr = kmalloc(sizeof(*dr), GFP_KERNEL);
1924 return ERR_PTR(-ENOMEM);
1927 dr->bRequestType = data->cmdreq_type;
1928 dr->bRequest = data->cmdreq;
1931 dr->wLength = __cpu_to_le16(skb->len);
1933 pipe = usb_sndctrlpipe(data->udev, 0x00);
1935 usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
1936 skb->data, skb->len, btusb_tx_complete, skb);
1938 skb->dev = (void *)hdev;
1943 static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
1945 struct btusb_data *data = hci_get_drvdata(hdev);
1949 if (!data->bulk_tx_ep)
1950 return ERR_PTR(-ENODEV);
1952 urb = usb_alloc_urb(0, GFP_KERNEL);
1954 return ERR_PTR(-ENOMEM);
1956 pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
1958 usb_fill_bulk_urb(urb, data->udev, pipe,
1959 skb->data, skb->len, btusb_tx_complete, skb);
1961 skb->dev = (void *)hdev;
1966 static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
1968 struct btusb_data *data = hci_get_drvdata(hdev);
1972 if (!data->isoc_tx_ep)
1973 return ERR_PTR(-ENODEV);
1975 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
1977 return ERR_PTR(-ENOMEM);
1979 pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
1981 usb_fill_int_urb(urb, data->udev, pipe,
1982 skb->data, skb->len, btusb_isoc_tx_complete,
1983 skb, data->isoc_tx_ep->bInterval);
1985 urb->transfer_flags = URB_ISO_ASAP;
1987 if (data->isoc_altsetting == 6)
1988 __fill_isoc_descriptor_msbc(urb, skb->len,
1989 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize),
1992 __fill_isoc_descriptor(urb, skb->len,
1993 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
1994 skb->dev = (void *)hdev;
1999 static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb)
2001 struct btusb_data *data = hci_get_drvdata(hdev);
2004 usb_anchor_urb(urb, &data->tx_anchor);
2006 err = usb_submit_urb(urb, GFP_KERNEL);
2008 if (err != -EPERM && err != -ENODEV)
2009 bt_dev_err(hdev, "urb %p submission failed (%d)",
2011 kfree(urb->setup_packet);
2012 usb_unanchor_urb(urb);
2014 usb_mark_last_busy(data->udev);
2021 static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb)
2023 struct btusb_data *data = hci_get_drvdata(hdev);
2024 unsigned long flags;
2027 spin_lock_irqsave(&data->txlock, flags);
2028 suspending = test_bit(BTUSB_SUSPENDING, &data->flags);
2030 data->tx_in_flight++;
2031 spin_unlock_irqrestore(&data->txlock, flags);
2034 return submit_tx_urb(hdev, urb);
2036 usb_anchor_urb(urb, &data->deferred);
2037 schedule_work(&data->waker);
2043 static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
2047 BT_DBG("%s", hdev->name);
2049 switch (hci_skb_pkt_type(skb)) {
2050 case HCI_COMMAND_PKT:
2051 urb = alloc_ctrl_urb(hdev, skb);
2053 return PTR_ERR(urb);
2055 hdev->stat.cmd_tx++;
2056 return submit_or_queue_tx_urb(hdev, urb);
2058 case HCI_ACLDATA_PKT:
2059 urb = alloc_bulk_urb(hdev, skb);
2061 return PTR_ERR(urb);
2063 hdev->stat.acl_tx++;
2064 return submit_or_queue_tx_urb(hdev, urb);
2066 case HCI_SCODATA_PKT:
2067 if (hci_conn_num(hdev, SCO_LINK) < 1)
2070 urb = alloc_isoc_urb(hdev, skb);
2072 return PTR_ERR(urb);
2074 hdev->stat.sco_tx++;
2075 return submit_tx_urb(hdev, urb);
2077 case HCI_ISODATA_PKT:
2078 urb = alloc_bulk_urb(hdev, skb);
2080 return PTR_ERR(urb);
2082 return submit_or_queue_tx_urb(hdev, urb);
2088 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
2090 struct btusb_data *data = hci_get_drvdata(hdev);
2092 BT_DBG("%s evt %d", hdev->name, evt);
2094 if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) {
2095 data->sco_num = hci_conn_num(hdev, SCO_LINK);
2096 data->air_mode = evt;
2097 schedule_work(&data->work);
2101 static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
2103 struct btusb_data *data = hci_get_drvdata(hdev);
2104 struct usb_interface *intf = data->isoc;
2105 struct usb_endpoint_descriptor *ep_desc;
2111 err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting);
2113 bt_dev_err(hdev, "setting interface failed (%d)", -err);
2117 data->isoc_altsetting = altsetting;
2119 data->isoc_tx_ep = NULL;
2120 data->isoc_rx_ep = NULL;
2122 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
2123 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
2125 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
2126 data->isoc_tx_ep = ep_desc;
2130 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
2131 data->isoc_rx_ep = ep_desc;
2136 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
2137 bt_dev_err(hdev, "invalid SCO descriptors");
2144 static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts)
2146 struct btusb_data *data = hci_get_drvdata(hdev);
2149 if (data->isoc_altsetting != new_alts) {
2150 unsigned long flags;
2152 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2153 usb_kill_anchored_urbs(&data->isoc_anchor);
2155 /* When isochronous alternate setting needs to be
2156 * changed, because SCO connection has been added
2157 * or removed, a packet fragment may be left in the
2158 * reassembling state. This could lead to wrongly
2159 * assembled fragments.
2161 * Clear outstanding fragment when selecting a new
2162 * alternate setting.
2164 spin_lock_irqsave(&data->rxlock, flags);
2165 dev_kfree_skb_irq(data->sco_skb);
2166 data->sco_skb = NULL;
2167 spin_unlock_irqrestore(&data->rxlock, flags);
2169 err = __set_isoc_interface(hdev, new_alts);
2174 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
2175 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
2176 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2178 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
2184 static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data,
2187 struct usb_interface *intf = data->isoc;
2190 BT_DBG("Looking for Alt no :%d", alt);
2195 for (i = 0; i < intf->num_altsetting; i++) {
2196 if (intf->altsetting[i].desc.bAlternateSetting == alt)
2197 return &intf->altsetting[i];
2203 static void btusb_work(struct work_struct *work)
2205 struct btusb_data *data = container_of(work, struct btusb_data, work);
2206 struct hci_dev *hdev = data->hdev;
2210 if (data->sco_num > 0) {
2211 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
2212 err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
2214 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2215 usb_kill_anchored_urbs(&data->isoc_anchor);
2219 set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
2222 if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) {
2223 if (hdev->voice_setting & 0x0020) {
2224 static const int alts[3] = { 2, 4, 5 };
2226 new_alts = alts[data->sco_num - 1];
2228 new_alts = data->sco_num;
2230 } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) {
2231 /* Bluetooth USB spec recommends alt 6 (63 bytes), but
2232 * many adapters do not support it. Alt 1 appears to
2233 * work for all adapters that do not have alt 6, and
2234 * which work with WBS at all. Some devices prefer
2235 * alt 3 (HCI payload >= 60 Bytes let air packet
2236 * data satisfy 60 bytes), requiring
2237 * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
2238 * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
2240 if (btusb_find_altsetting(data, 6))
2242 else if (btusb_find_altsetting(data, 3) &&
2243 hdev->sco_mtu >= 72 &&
2244 test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags))
2250 if (btusb_switch_alt_setting(hdev, new_alts) < 0)
2251 bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts);
2253 usb_kill_anchored_urbs(&data->isoc_anchor);
2255 if (test_and_clear_bit(BTUSB_ISOC_RUNNING, &data->flags))
2256 __set_isoc_interface(hdev, 0);
2258 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
2259 usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
2263 static void btusb_waker(struct work_struct *work)
2265 struct btusb_data *data = container_of(work, struct btusb_data, waker);
2268 err = usb_autopm_get_interface(data->intf);
2272 usb_autopm_put_interface(data->intf);
2275 static void btusb_rx_work(struct work_struct *work)
2277 struct btusb_data *data = container_of(work, struct btusb_data,
2279 struct sk_buff *skb;
2281 /* Dequeue ACL data received during the interval */
2282 while ((skb = skb_dequeue(&data->acl_q)))
2283 data->recv_acl(data->hdev, skb);
2286 static int btusb_setup_bcm92035(struct hci_dev *hdev)
2288 struct sk_buff *skb;
2291 BT_DBG("%s", hdev->name);
2293 skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT);
2295 bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb));
2302 static int btusb_setup_csr(struct hci_dev *hdev)
2304 struct btusb_data *data = hci_get_drvdata(hdev);
2305 u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice);
2306 struct hci_rp_read_local_version *rp;
2307 struct sk_buff *skb;
2308 bool is_fake = false;
2311 BT_DBG("%s", hdev->name);
2313 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
2316 int err = PTR_ERR(skb);
2317 bt_dev_err(hdev, "CSR: Local version failed (%d)", err);
2321 rp = skb_pull_data(skb, sizeof(*rp));
2323 bt_dev_err(hdev, "CSR: Local version length mismatch");
2328 bt_dev_info(hdev, "CSR: Setting up dongle with HCI ver=%u rev=%04x",
2329 rp->hci_ver, le16_to_cpu(rp->hci_rev));
2331 bt_dev_info(hdev, "LMP ver=%u subver=%04x; manufacturer=%u",
2332 rp->lmp_ver, le16_to_cpu(rp->lmp_subver),
2333 le16_to_cpu(rp->manufacturer));
2335 /* Detect a wide host of Chinese controllers that aren't CSR.
2337 * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891
2339 * The main thing they have in common is that these are really popular low-cost
2340 * options that support newer Bluetooth versions but rely on heavy VID/PID
2341 * squatting of this poor old Bluetooth 1.1 device. Even sold as such.
2343 * We detect actual CSR devices by checking that the HCI manufacturer code
2344 * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and
2345 * HCI rev values always match. As they both store the firmware number.
2347 if (le16_to_cpu(rp->manufacturer) != 10 ||
2348 le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver))
2351 /* Known legit CSR firmware build numbers and their supported BT versions:
2352 * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e
2353 * - 1.2 (0x2) -> 0x04d9, 0x0529
2354 * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c
2355 * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External)
2356 * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb
2358 * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that
2359 * support BT 1.1 only; so it's a dead giveaway when some
2360 * third-party BT 4.0 dongle reuses it.
2362 else if (le16_to_cpu(rp->lmp_subver) <= 0x034e &&
2363 rp->hci_ver > BLUETOOTH_VER_1_1)
2366 else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 &&
2367 rp->hci_ver > BLUETOOTH_VER_1_2)
2370 else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c &&
2371 rp->hci_ver > BLUETOOTH_VER_2_0)
2374 else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 &&
2375 rp->hci_ver > BLUETOOTH_VER_2_1)
2378 else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb &&
2379 rp->hci_ver > BLUETOOTH_VER_4_0)
2382 /* Other clones which beat all the above checks */
2383 else if (bcdDevice == 0x0134 &&
2384 le16_to_cpu(rp->lmp_subver) == 0x0c5c &&
2385 rp->hci_ver == BLUETOOTH_VER_2_0)
2389 bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once...");
2391 /* Generally these clones have big discrepancies between
2392 * advertised features and what's actually supported.
2393 * Probably will need to be expanded in the future;
2394 * without these the controller will lock up.
2396 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
2397 set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
2398 set_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks);
2399 set_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks);
2401 /* Clear the reset quirk since this is not an actual
2402 * early Bluetooth 1.1 device from CSR.
2404 clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
2405 clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
2408 * Special workaround for these BT 4.0 chip clones, and potentially more:
2410 * - 0x0134: a Barrot 8041a02 (HCI rev: 0x0810 sub: 0x1012)
2411 * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709)
2413 * These controllers are really messed-up.
2415 * 1. Their bulk RX endpoint will never report any data unless
2416 * the device was suspended at least once (yes, really).
2417 * 2. They will not wakeup when autosuspended and receiving data
2418 * on their bulk RX endpoint from e.g. a keyboard or mouse
2419 * (IOW remote-wakeup support is broken for the bulk endpoint).
2421 * To fix 1. enable runtime-suspend, force-suspend the
2422 * HCI and then wake-it up by disabling runtime-suspend.
2424 * To fix 2. clear the HCI's can_wake flag, this way the HCI
2425 * will still be autosuspended when it is not open.
2429 * Because these are widespread problems we prefer generic solutions; so
2430 * apply this initialization quirk to every controller that gets here,
2431 * it should be harmless. The alternative is to not work at all.
2433 pm_runtime_allow(&data->udev->dev);
2435 ret = pm_runtime_suspend(&data->udev->dev);
2439 bt_dev_warn(hdev, "CSR: Couldn't suspend the device for our Barrot 8041a02 receive-issue workaround");
2441 pm_runtime_forbid(&data->udev->dev);
2443 device_set_wakeup_capable(&data->udev->dev, false);
2445 /* Re-enable autosuspend if this was requested */
2446 if (enable_autosuspend)
2447 usb_enable_autosuspend(data->udev);
2455 static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
2457 struct sk_buff *skb;
2458 struct hci_event_hdr *hdr;
2459 struct hci_ev_cmd_complete *evt;
2461 skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL);
2465 hdr = skb_put(skb, sizeof(*hdr));
2466 hdr->evt = HCI_EV_CMD_COMPLETE;
2467 hdr->plen = sizeof(*evt) + 1;
2469 evt = skb_put(skb, sizeof(*evt));
2471 evt->opcode = cpu_to_le16(opcode);
2473 skb_put_u8(skb, 0x00);
2475 hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
2477 return hci_recv_frame(hdev, skb);
2480 static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer,
2483 struct hci_dev *hdev = data->hdev;
2485 /* When the device is in bootloader mode, then it can send
2486 * events via the bulk endpoint. These events are treated the
2487 * same way as the ones received from the interrupt endpoint.
2489 if (btintel_test_flag(hdev, INTEL_BOOTLOADER))
2490 return btusb_recv_intr(data, buffer, count);
2492 return btusb_recv_bulk(data, buffer, count);
2495 static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
2499 BT_DBG("%s", hdev->name);
2501 switch (hci_skb_pkt_type(skb)) {
2502 case HCI_COMMAND_PKT:
2503 if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
2504 struct hci_command_hdr *cmd = (void *)skb->data;
2505 __u16 opcode = le16_to_cpu(cmd->opcode);
2507 /* When in bootloader mode and the command 0xfc09
2508 * is received, it needs to be send down the
2509 * bulk endpoint. So allocate a bulk URB instead.
2511 if (opcode == 0xfc09)
2512 urb = alloc_bulk_urb(hdev, skb);
2514 urb = alloc_ctrl_urb(hdev, skb);
2516 /* When the 0xfc01 command is issued to boot into
2517 * the operational firmware, it will actually not
2518 * send a command complete event. To keep the flow
2519 * control working inject that event here.
2521 if (opcode == 0xfc01)
2522 inject_cmd_complete(hdev, opcode);
2524 urb = alloc_ctrl_urb(hdev, skb);
2527 return PTR_ERR(urb);
2529 hdev->stat.cmd_tx++;
2530 return submit_or_queue_tx_urb(hdev, urb);
2532 case HCI_ACLDATA_PKT:
2533 urb = alloc_bulk_urb(hdev, skb);
2535 return PTR_ERR(urb);
2537 hdev->stat.acl_tx++;
2538 return submit_or_queue_tx_urb(hdev, urb);
2540 case HCI_SCODATA_PKT:
2541 if (hci_conn_num(hdev, SCO_LINK) < 1)
2544 urb = alloc_isoc_urb(hdev, skb);
2546 return PTR_ERR(urb);
2548 hdev->stat.sco_tx++;
2549 return submit_tx_urb(hdev, urb);
2551 case HCI_ISODATA_PKT:
2552 urb = alloc_bulk_urb(hdev, skb);
2554 return PTR_ERR(urb);
2556 return submit_or_queue_tx_urb(hdev, urb);
2562 static int btusb_setup_realtek(struct hci_dev *hdev)
2564 struct btusb_data *data = hci_get_drvdata(hdev);
2567 ret = btrtl_setup_realtek(hdev);
2569 if (btrealtek_test_flag(data->hdev, REALTEK_ALT6_CONTINUOUS_TX_CHIP))
2570 set_bit(BTUSB_ALT6_CONTINUOUS_TX, &data->flags);
2575 static int btusb_recv_event_realtek(struct hci_dev *hdev, struct sk_buff *skb)
2577 if (skb->data[0] == HCI_VENDOR_PKT && skb->data[2] == RTK_SUB_EVENT_CODE_COREDUMP) {
2578 struct rtk_dev_coredump_hdr hdr = {
2579 .code = RTK_DEVCOREDUMP_CODE_MEMDUMP,
2582 bt_dev_dbg(hdev, "RTL: received coredump vendor evt, len %u",
2585 btusb_rtl_alloc_devcoredump(hdev, &hdr, skb->data, skb->len);
2591 return hci_recv_frame(hdev, skb);
2594 /* UHW CR mapping */
2595 #define MTK_BT_MISC 0x70002510
2596 #define MTK_BT_SUBSYS_RST 0x70002610
2597 #define MTK_UDMA_INT_STA_BT 0x74000024
2598 #define MTK_UDMA_INT_STA_BT1 0x74000308
2599 #define MTK_BT_WDT_STATUS 0x740003A0
2600 #define MTK_EP_RST_OPT 0x74011890
2601 #define MTK_EP_RST_IN_OUT_OPT 0x00010001
2602 #define MTK_BT_RST_DONE 0x00000100
2603 #define MTK_BT_RESET_REG_CONNV3 0x70028610
2604 #define MTK_BT_READ_DEV_ID 0x70010200
2607 static void btusb_mtk_wmt_recv(struct urb *urb)
2609 struct hci_dev *hdev = urb->context;
2610 struct btusb_data *data = hci_get_drvdata(hdev);
2611 struct sk_buff *skb;
2614 if (urb->status == 0 && urb->actual_length > 0) {
2615 hdev->stat.byte_rx += urb->actual_length;
2617 /* WMT event shouldn't be fragmented and the size should be
2618 * less than HCI_WMT_MAX_EVENT_SIZE.
2620 skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC);
2622 hdev->stat.err_rx++;
2623 kfree(urb->setup_packet);
2627 hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
2628 skb_put_data(skb, urb->transfer_buffer, urb->actual_length);
2630 /* When someone waits for the WMT event, the skb is being cloned
2631 * and being processed the events from there then.
2633 if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) {
2634 data->evt_skb = skb_clone(skb, GFP_ATOMIC);
2635 if (!data->evt_skb) {
2637 kfree(urb->setup_packet);
2642 err = hci_recv_frame(hdev, skb);
2644 kfree_skb(data->evt_skb);
2645 data->evt_skb = NULL;
2646 kfree(urb->setup_packet);
2650 if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT,
2652 /* Barrier to sync with other CPUs */
2653 smp_mb__after_atomic();
2654 wake_up_bit(&data->flags,
2655 BTUSB_TX_WAIT_VND_EVT);
2657 kfree(urb->setup_packet);
2659 } else if (urb->status == -ENOENT) {
2660 /* Avoid suspend failed when usb_kill_urb */
2664 usb_mark_last_busy(data->udev);
2666 /* The URB complete handler is still called with urb->actual_length = 0
2667 * when the event is not available, so we should keep re-submitting
2668 * URB until WMT event returns, Also, It's necessary to wait some time
2669 * between the two consecutive control URBs to relax the target device
2670 * to generate the event. Otherwise, the WMT event cannot return from
2671 * the device successfully.
2675 usb_anchor_urb(urb, &data->ctrl_anchor);
2676 err = usb_submit_urb(urb, GFP_ATOMIC);
2678 kfree(urb->setup_packet);
2679 /* -EPERM: urb is being killed;
2680 * -ENODEV: device got disconnected
2682 if (err != -EPERM && err != -ENODEV)
2683 bt_dev_err(hdev, "urb %p failed to resubmit (%d)",
2685 usb_unanchor_urb(urb);
2689 static int btusb_mtk_submit_wmt_recv_urb(struct hci_dev *hdev)
2691 struct btusb_data *data = hci_get_drvdata(hdev);
2692 struct usb_ctrlrequest *dr;
2698 urb = usb_alloc_urb(0, GFP_KERNEL);
2702 dr = kmalloc(sizeof(*dr), GFP_KERNEL);
2708 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_IN;
2710 dr->wIndex = cpu_to_le16(0);
2711 dr->wValue = cpu_to_le16(48);
2712 dr->wLength = cpu_to_le16(size);
2714 buf = kmalloc(size, GFP_KERNEL);
2721 pipe = usb_rcvctrlpipe(data->udev, 0);
2723 usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
2724 buf, size, btusb_mtk_wmt_recv, hdev);
2726 urb->transfer_flags |= URB_FREE_BUFFER;
2728 usb_anchor_urb(urb, &data->ctrl_anchor);
2729 err = usb_submit_urb(urb, GFP_KERNEL);
2731 if (err != -EPERM && err != -ENODEV)
2732 bt_dev_err(hdev, "urb %p submission failed (%d)",
2734 usb_unanchor_urb(urb);
2742 static int btusb_mtk_hci_wmt_sync(struct hci_dev *hdev,
2743 struct btmtk_hci_wmt_params *wmt_params)
2745 struct btusb_data *data = hci_get_drvdata(hdev);
2746 struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc;
2747 u32 hlen, status = BTMTK_WMT_INVALID;
2748 struct btmtk_hci_wmt_evt *wmt_evt;
2749 struct btmtk_hci_wmt_cmd *wc;
2750 struct btmtk_wmt_hdr *hdr;
2753 /* Send the WMT command and wait until the WMT event returns */
2754 hlen = sizeof(*hdr) + wmt_params->dlen;
2758 wc = kzalloc(hlen, GFP_KERNEL);
2764 hdr->op = wmt_params->op;
2765 hdr->dlen = cpu_to_le16(wmt_params->dlen + 1);
2766 hdr->flag = wmt_params->flag;
2767 memcpy(wc->data, wmt_params->data, wmt_params->dlen);
2769 set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2771 /* WMT cmd/event doesn't follow up the generic HCI cmd/event handling,
2772 * it needs constantly polling control pipe until the host received the
2773 * WMT event, thus, we should require to specifically acquire PM counter
2774 * on the USB to prevent the interface from entering auto suspended
2775 * while WMT cmd/event in progress.
2777 err = usb_autopm_get_interface(data->intf);
2781 err = __hci_cmd_send(hdev, 0xfc6f, hlen, wc);
2784 clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2785 usb_autopm_put_interface(data->intf);
2789 /* Submit control IN URB on demand to process the WMT event */
2790 err = btusb_mtk_submit_wmt_recv_urb(hdev);
2792 usb_autopm_put_interface(data->intf);
2797 /* The vendor specific WMT commands are all answered by a vendor
2798 * specific event and will have the Command Status or Command
2799 * Complete as with usual HCI command flow control.
2801 * After sending the command, wait for BTUSB_TX_WAIT_VND_EVT
2802 * state to be cleared. The driver specific event receive routine
2803 * will clear that state and with that indicate completion of the
2806 err = wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT,
2807 TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT);
2808 if (err == -EINTR) {
2809 bt_dev_err(hdev, "Execution of wmt command interrupted");
2810 clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2815 bt_dev_err(hdev, "Execution of wmt command timed out");
2816 clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags);
2821 /* Parse and handle the return WMT event */
2822 wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data;
2823 if (wmt_evt->whdr.op != hdr->op) {
2824 bt_dev_err(hdev, "Wrong op received %d expected %d",
2825 wmt_evt->whdr.op, hdr->op);
2830 switch (wmt_evt->whdr.op) {
2831 case BTMTK_WMT_SEMAPHORE:
2832 if (wmt_evt->whdr.flag == 2)
2833 status = BTMTK_WMT_PATCH_UNDONE;
2835 status = BTMTK_WMT_PATCH_DONE;
2837 case BTMTK_WMT_FUNC_CTRL:
2838 wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt;
2839 if (be16_to_cpu(wmt_evt_funcc->status) == 0x404)
2840 status = BTMTK_WMT_ON_DONE;
2841 else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420)
2842 status = BTMTK_WMT_ON_PROGRESS;
2844 status = BTMTK_WMT_ON_UNDONE;
2846 case BTMTK_WMT_PATCH_DWNLD:
2847 if (wmt_evt->whdr.flag == 2)
2848 status = BTMTK_WMT_PATCH_DONE;
2849 else if (wmt_evt->whdr.flag == 1)
2850 status = BTMTK_WMT_PATCH_PROGRESS;
2852 status = BTMTK_WMT_PATCH_UNDONE;
2856 if (wmt_params->status)
2857 *wmt_params->status = status;
2860 kfree_skb(data->evt_skb);
2861 data->evt_skb = NULL;
2867 static int btusb_mtk_func_query(struct hci_dev *hdev)
2869 struct btmtk_hci_wmt_params wmt_params;
2873 /* Query whether the function is enabled */
2874 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
2875 wmt_params.flag = 4;
2876 wmt_params.dlen = sizeof(param);
2877 wmt_params.data = ¶m;
2878 wmt_params.status = &status;
2880 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
2882 bt_dev_err(hdev, "Failed to query function status (%d)", err);
2889 static int btusb_mtk_uhw_reg_write(struct btusb_data *data, u32 reg, u32 val)
2891 struct hci_dev *hdev = data->hdev;
2895 buf = kzalloc(4, GFP_KERNEL);
2899 put_unaligned_le32(val, buf);
2901 pipe = usb_sndctrlpipe(data->udev, 0);
2902 err = usb_control_msg(data->udev, pipe, 0x02,
2904 reg >> 16, reg & 0xffff,
2905 buf, 4, USB_CTRL_SET_TIMEOUT);
2907 bt_dev_err(hdev, "Failed to write uhw reg(%d)", err);
2917 static int btusb_mtk_uhw_reg_read(struct btusb_data *data, u32 reg, u32 *val)
2919 struct hci_dev *hdev = data->hdev;
2923 buf = kzalloc(4, GFP_KERNEL);
2927 pipe = usb_rcvctrlpipe(data->udev, 0);
2928 err = usb_control_msg(data->udev, pipe, 0x01,
2930 reg >> 16, reg & 0xffff,
2931 buf, 4, USB_CTRL_SET_TIMEOUT);
2933 bt_dev_err(hdev, "Failed to read uhw reg(%d)", err);
2937 *val = get_unaligned_le32(buf);
2938 bt_dev_dbg(hdev, "reg=%x, value=0x%08x", reg, *val);
2946 static int btusb_mtk_reg_read(struct btusb_data *data, u32 reg, u32 *val)
2948 int pipe, err, size = sizeof(u32);
2951 buf = kzalloc(size, GFP_KERNEL);
2955 pipe = usb_rcvctrlpipe(data->udev, 0);
2956 err = usb_control_msg(data->udev, pipe, 0x63,
2957 USB_TYPE_VENDOR | USB_DIR_IN,
2958 reg >> 16, reg & 0xffff,
2959 buf, size, USB_CTRL_SET_TIMEOUT);
2963 *val = get_unaligned_le32(buf);
2971 static int btusb_mtk_id_get(struct btusb_data *data, u32 reg, u32 *id)
2973 return btusb_mtk_reg_read(data, reg, id);
2976 static u32 btusb_mtk_reset_done(struct hci_dev *hdev)
2978 struct btusb_data *data = hci_get_drvdata(hdev);
2981 btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
2983 return val & MTK_BT_RST_DONE;
2986 static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
2988 struct btusb_data *data = hci_get_drvdata(hdev);
2989 struct btmediatek_data *mediatek;
2993 /* It's MediaTek specific bluetooth reset mechanism via USB */
2994 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
2995 bt_dev_err(hdev, "last reset failed? Not resetting again");
2999 err = usb_autopm_get_interface(data->intf);
3003 btusb_stop_traffic(data);
3004 usb_kill_anchored_urbs(&data->tx_anchor);
3005 mediatek = hci_get_priv(hdev);
3007 if (mediatek->dev_id == 0x7925) {
3008 btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val);
3010 btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val);
3011 btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val);
3014 btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val);
3015 btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, 0x00010001);
3016 btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val);
3018 btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val);
3019 btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x000000FF);
3020 btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT, &val);
3021 btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT1, 0x000000FF);
3022 btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT1, &val);
3025 /* It's Device EndPoint Reset Option Register */
3026 bt_dev_dbg(hdev, "Initiating reset mechanism via uhw");
3027 btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT);
3028 btusb_mtk_uhw_reg_read(data, MTK_BT_WDT_STATUS, &val);
3030 /* Reset the bluetooth chip via USB interface. */
3031 btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 1);
3032 btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x000000FF);
3033 btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT, &val);
3034 btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT1, 0x000000FF);
3035 btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT1, &val);
3036 /* MT7921 need to delay 20ms between toggle reset bit */
3038 btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 0);
3039 btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
3042 err = readx_poll_timeout(btusb_mtk_reset_done, hdev, val,
3043 val & MTK_BT_RST_DONE, 20000, 1000000);
3045 bt_dev_err(hdev, "Reset timeout");
3047 btusb_mtk_id_get(data, 0x70010200, &val);
3049 bt_dev_err(hdev, "Can't get device id, subsys reset fail.");
3051 usb_queue_reset_device(data->intf);
3053 clear_bit(BTUSB_HW_RESET_ACTIVE, &data->flags);
3058 static int btusb_mtk_setup(struct hci_dev *hdev)
3060 struct btusb_data *data = hci_get_drvdata(hdev);
3061 struct btmtk_hci_wmt_params wmt_params;
3062 ktime_t calltime, delta, rettime;
3063 struct btmtk_tci_sleep tci_sleep;
3064 unsigned long long duration;
3065 struct sk_buff *skb;
3069 char fw_bin_name[64];
3072 struct btmediatek_data *mediatek;
3074 calltime = ktime_get();
3076 err = btusb_mtk_id_get(data, 0x80000008, &dev_id);
3078 bt_dev_err(hdev, "Failed to get device id (%d)", err);
3082 if (!dev_id || dev_id != 0x7663) {
3083 err = btusb_mtk_id_get(data, 0x70010200, &dev_id);
3085 bt_dev_err(hdev, "Failed to get device id (%d)", err);
3088 err = btusb_mtk_id_get(data, 0x80021004, &fw_version);
3090 bt_dev_err(hdev, "Failed to get fw version (%d)", err);
3095 mediatek = hci_get_priv(hdev);
3096 mediatek->dev_id = dev_id;
3097 mediatek->reset_sync = btusb_mtk_reset;
3099 err = btmtk_register_coredump(hdev, btusb_driver.name, fw_version);
3101 bt_dev_err(hdev, "Failed to register coredump (%d)", err);
3105 fwname = FIRMWARE_MT7663;
3108 fwname = FIRMWARE_MT7668;
3113 if (dev_id == 0x7925)
3114 snprintf(fw_bin_name, sizeof(fw_bin_name),
3115 "mediatek/mt%04x/BT_RAM_CODE_MT%04x_1_%x_hdr.bin",
3116 dev_id & 0xffff, dev_id & 0xffff, (fw_version & 0xff) + 1);
3118 snprintf(fw_bin_name, sizeof(fw_bin_name),
3119 "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin",
3120 dev_id & 0xffff, (fw_version & 0xff) + 1);
3122 err = btmtk_setup_firmware_79xx(hdev, fw_bin_name,
3123 btusb_mtk_hci_wmt_sync);
3125 bt_dev_err(hdev, "Failed to set up firmware (%d)", err);
3129 /* It's Device EndPoint Reset Option Register */
3130 btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT);
3132 /* Enable Bluetooth protocol */
3134 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
3135 wmt_params.flag = 0;
3136 wmt_params.dlen = sizeof(param);
3137 wmt_params.data = ¶m;
3138 wmt_params.status = NULL;
3140 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
3142 bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
3146 hci_set_msft_opcode(hdev, 0xFD30);
3147 hci_set_aosp_capable(hdev);
3150 bt_dev_err(hdev, "Unsupported hardware variant (%08x)",
3155 /* Query whether the firmware is already download */
3156 wmt_params.op = BTMTK_WMT_SEMAPHORE;
3157 wmt_params.flag = 1;
3158 wmt_params.dlen = 0;
3159 wmt_params.data = NULL;
3160 wmt_params.status = &status;
3162 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
3164 bt_dev_err(hdev, "Failed to query firmware status (%d)", err);
3168 if (status == BTMTK_WMT_PATCH_DONE) {
3169 bt_dev_info(hdev, "firmware already downloaded");
3170 goto ignore_setup_fw;
3173 /* Setup a firmware which the device definitely requires */
3174 err = btmtk_setup_firmware(hdev, fwname,
3175 btusb_mtk_hci_wmt_sync);
3180 err = readx_poll_timeout(btusb_mtk_func_query, hdev, status,
3181 status < 0 || status != BTMTK_WMT_ON_PROGRESS,
3183 /* -ETIMEDOUT happens */
3187 /* The other errors happen in btusb_mtk_func_query */
3191 if (status == BTMTK_WMT_ON_DONE) {
3192 bt_dev_info(hdev, "function already on");
3193 goto ignore_func_on;
3196 /* Enable Bluetooth protocol */
3198 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
3199 wmt_params.flag = 0;
3200 wmt_params.dlen = sizeof(param);
3201 wmt_params.data = ¶m;
3202 wmt_params.status = NULL;
3204 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
3206 bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
3211 /* Apply the low power environment setup */
3212 tci_sleep.mode = 0x5;
3213 tci_sleep.duration = cpu_to_le16(0x640);
3214 tci_sleep.host_duration = cpu_to_le16(0x640);
3215 tci_sleep.host_wakeup_pin = 0;
3216 tci_sleep.time_compensation = 0;
3218 skb = __hci_cmd_sync(hdev, 0xfc7a, sizeof(tci_sleep), &tci_sleep,
3222 bt_dev_err(hdev, "Failed to apply low power setting (%d)", err);
3228 rettime = ktime_get();
3229 delta = ktime_sub(rettime, calltime);
3230 duration = (unsigned long long)ktime_to_ns(delta) >> 10;
3232 bt_dev_info(hdev, "Device setup in %llu usecs", duration);
3237 static int btusb_mtk_shutdown(struct hci_dev *hdev)
3239 struct btmtk_hci_wmt_params wmt_params;
3243 /* Disable the device */
3244 wmt_params.op = BTMTK_WMT_FUNC_CTRL;
3245 wmt_params.flag = 0;
3246 wmt_params.dlen = sizeof(param);
3247 wmt_params.data = ¶m;
3248 wmt_params.status = NULL;
3250 err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
3252 bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
3259 static int btusb_recv_acl_mtk(struct hci_dev *hdev, struct sk_buff *skb)
3261 struct btusb_data *data = hci_get_drvdata(hdev);
3262 u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle);
3263 struct sk_buff *skb_cd;
3266 case 0xfc6f: /* Firmware dump from device */
3267 /* When the firmware hangs, the device can no longer
3268 * suspend and thus disable auto-suspend.
3270 usb_disable_autosuspend(data->udev);
3272 /* We need to forward the diagnostic packet to userspace daemon
3273 * for backward compatibility, so we have to clone the packet
3274 * extraly for the in-kernel coredump support.
3276 skb_cd = skb_clone(skb, GFP_ATOMIC);
3278 btmtk_process_coredump(hdev, skb_cd);
3281 case 0x05ff: /* Firmware debug logging 1 */
3282 case 0x05fe: /* Firmware debug logging 2 */
3283 return hci_recv_diag(hdev, skb);
3286 return hci_recv_frame(hdev, skb);
3290 /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */
3291 static int marvell_config_oob_wake(struct hci_dev *hdev)
3293 struct sk_buff *skb;
3294 struct btusb_data *data = hci_get_drvdata(hdev);
3295 struct device *dev = &data->udev->dev;
3296 u16 pin, gap, opcode;
3300 /* Move on if no wakeup pin specified */
3301 if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) ||
3302 of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap))
3305 /* Vendor specific command to configure a GPIO as wake-up pin */
3306 opcode = hci_opcode_pack(0x3F, 0x59);
3307 cmd[0] = opcode & 0xFF;
3308 cmd[1] = opcode >> 8;
3309 cmd[2] = 2; /* length of parameters that follow */
3311 cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */
3313 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
3315 bt_dev_err(hdev, "%s: No memory", __func__);
3319 skb_put_data(skb, cmd, sizeof(cmd));
3320 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
3322 ret = btusb_send_frame(hdev, skb);
3324 bt_dev_err(hdev, "%s: configuration failed", __func__);
3333 static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
3334 const bdaddr_t *bdaddr)
3336 struct sk_buff *skb;
3341 buf[1] = sizeof(bdaddr_t);
3342 memcpy(buf + 2, bdaddr, sizeof(bdaddr_t));
3344 skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT);
3347 bt_dev_err(hdev, "changing Marvell device address failed (%ld)",
3356 static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
3357 const bdaddr_t *bdaddr)
3359 struct sk_buff *skb;
3366 buf[3] = sizeof(bdaddr_t);
3367 memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
3369 skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
3372 bt_dev_err(hdev, "Change address command failed (%ld)", ret);
3380 static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev,
3381 const bdaddr_t *bdaddr)
3383 struct sk_buff *skb;
3387 memcpy(buf, bdaddr, sizeof(bdaddr_t));
3389 skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf,
3390 HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
3393 bt_dev_err(hdev, "Change address command failed (%ld)", ret);
3401 #define QCA_MEMDUMP_ACL_HANDLE 0x2EDD
3402 #define QCA_MEMDUMP_SIZE_MAX 0x100000
3403 #define QCA_MEMDUMP_VSE_CLASS 0x01
3404 #define QCA_MEMDUMP_MSG_TYPE 0x08
3405 #define QCA_MEMDUMP_PKT_SIZE 248
3406 #define QCA_LAST_SEQUENCE_NUM 0xffff
3408 struct qca_dump_hdr {
3416 __le32 ram_dump_size;
3423 static void btusb_dump_hdr_qca(struct hci_dev *hdev, struct sk_buff *skb)
3426 struct btusb_data *btdata = hci_get_drvdata(hdev);
3428 snprintf(buf, sizeof(buf), "Controller Name: 0x%x\n",
3429 btdata->qca_dump.controller_id);
3430 skb_put_data(skb, buf, strlen(buf));
3432 snprintf(buf, sizeof(buf), "Firmware Version: 0x%x\n",
3433 btdata->qca_dump.fw_version);
3434 skb_put_data(skb, buf, strlen(buf));
3436 snprintf(buf, sizeof(buf), "Driver: %s\nVendor: qca\n",
3438 skb_put_data(skb, buf, strlen(buf));
3440 snprintf(buf, sizeof(buf), "VID: 0x%x\nPID:0x%x\n",
3441 btdata->qca_dump.id_vendor, btdata->qca_dump.id_product);
3442 skb_put_data(skb, buf, strlen(buf));
3444 snprintf(buf, sizeof(buf), "Lmp Subversion: 0x%x\n",
3446 skb_put_data(skb, buf, strlen(buf));
3449 static void btusb_coredump_qca(struct hci_dev *hdev)
3451 static const u8 param[] = { 0x26 };
3452 struct sk_buff *skb;
3454 skb = __hci_cmd_sync(hdev, 0xfc0c, 1, param, HCI_CMD_TIMEOUT);
3456 bt_dev_err(hdev, "%s: triggle crash failed (%ld)", __func__, PTR_ERR(skb));
3461 * ==0: not a dump pkt.
3462 * < 0: fails to handle a dump pkt
3465 static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
3470 unsigned int sk_len;
3474 struct hci_event_hdr *event_hdr;
3475 struct hci_acl_hdr *acl_hdr;
3476 struct qca_dump_hdr *dump_hdr;
3477 struct btusb_data *btdata = hci_get_drvdata(hdev);
3478 struct usb_device *udev = btdata->udev;
3480 pkt_type = hci_skb_pkt_type(skb);
3484 if (pkt_type == HCI_ACLDATA_PKT) {
3485 acl_hdr = hci_acl_hdr(skb);
3486 if (le16_to_cpu(acl_hdr->handle) != QCA_MEMDUMP_ACL_HANDLE)
3488 sk_ptr += HCI_ACL_HDR_SIZE;
3489 sk_len -= HCI_ACL_HDR_SIZE;
3490 event_hdr = (struct hci_event_hdr *)sk_ptr;
3492 event_hdr = hci_event_hdr(skb);
3495 if ((event_hdr->evt != HCI_VENDOR_PKT)
3496 || (event_hdr->plen != (sk_len - HCI_EVENT_HDR_SIZE)))
3499 sk_ptr += HCI_EVENT_HDR_SIZE;
3500 sk_len -= HCI_EVENT_HDR_SIZE;
3502 dump_hdr = (struct qca_dump_hdr *)sk_ptr;
3503 if ((sk_len < offsetof(struct qca_dump_hdr, data))
3504 || (dump_hdr->vse_class != QCA_MEMDUMP_VSE_CLASS)
3505 || (dump_hdr->msg_type != QCA_MEMDUMP_MSG_TYPE))
3508 /*it is dump pkt now*/
3509 seqno = le16_to_cpu(dump_hdr->seqno);
3511 set_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags);
3512 dump_size = le32_to_cpu(dump_hdr->ram_dump_size);
3513 if (!dump_size || (dump_size > QCA_MEMDUMP_SIZE_MAX)) {
3515 bt_dev_err(hdev, "Invalid memdump size(%u)",
3520 ret = hci_devcd_init(hdev, dump_size);
3522 bt_dev_err(hdev, "memdump init error(%d)", ret);
3526 btdata->qca_dump.ram_dump_size = dump_size;
3527 btdata->qca_dump.ram_dump_seqno = 0;
3528 sk_ptr += offsetof(struct qca_dump_hdr, data0);
3529 sk_len -= offsetof(struct qca_dump_hdr, data0);
3531 usb_disable_autosuspend(udev);
3532 bt_dev_info(hdev, "%s memdump size(%u)\n",
3533 (pkt_type == HCI_ACLDATA_PKT) ? "ACL" : "event",
3536 sk_ptr += offsetof(struct qca_dump_hdr, data);
3537 sk_len -= offsetof(struct qca_dump_hdr, data);
3540 if (!btdata->qca_dump.ram_dump_size) {
3542 bt_dev_err(hdev, "memdump is not active");
3546 if ((seqno > btdata->qca_dump.ram_dump_seqno + 1) && (seqno != QCA_LAST_SEQUENCE_NUM)) {
3547 dump_size = QCA_MEMDUMP_PKT_SIZE * (seqno - btdata->qca_dump.ram_dump_seqno - 1);
3548 hci_devcd_append_pattern(hdev, 0x0, dump_size);
3550 "expected memdump seqno(%u) is not received(%u)\n",
3551 btdata->qca_dump.ram_dump_seqno, seqno);
3552 btdata->qca_dump.ram_dump_seqno = seqno;
3557 skb_pull(skb, skb->len - sk_len);
3558 hci_devcd_append(hdev, skb);
3559 btdata->qca_dump.ram_dump_seqno++;
3560 if (seqno == QCA_LAST_SEQUENCE_NUM) {
3562 "memdump done: pkts(%u), total(%u)\n",
3563 btdata->qca_dump.ram_dump_seqno, btdata->qca_dump.ram_dump_size);
3565 hci_devcd_complete(hdev);
3571 if (btdata->qca_dump.ram_dump_size)
3572 usb_enable_autosuspend(udev);
3573 btdata->qca_dump.ram_dump_size = 0;
3574 btdata->qca_dump.ram_dump_seqno = 0;
3575 clear_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags);
3582 static int btusb_recv_acl_qca(struct hci_dev *hdev, struct sk_buff *skb)
3584 if (handle_dump_pkt_qca(hdev, skb))
3586 return hci_recv_frame(hdev, skb);
3589 static int btusb_recv_evt_qca(struct hci_dev *hdev, struct sk_buff *skb)
3591 if (handle_dump_pkt_qca(hdev, skb))
3593 return hci_recv_frame(hdev, skb);
3597 #define QCA_DFU_PACKET_LEN 4096
3599 #define QCA_GET_TARGET_VERSION 0x09
3600 #define QCA_CHECK_STATUS 0x05
3601 #define QCA_DFU_DOWNLOAD 0x01
3603 #define QCA_SYSCFG_UPDATED 0x40
3604 #define QCA_PATCH_UPDATED 0x80
3605 #define QCA_DFU_TIMEOUT 3000
3606 #define QCA_FLAG_MULTI_NVM 0x80
3607 #define QCA_BT_RESET_WAIT_MS 100
3609 #define WCN6855_2_0_RAM_VERSION_GF 0x400c1200
3610 #define WCN6855_2_1_RAM_VERSION_GF 0x400c1211
3612 struct qca_version {
3614 __le32 patch_version;
3622 struct qca_rampatch_version {
3623 __le16 rom_version_high;
3624 __le16 rom_version_low;
3625 __le16 patch_version;
3628 struct qca_device_info {
3630 u8 rampatch_hdr; /* length of header in rampatch */
3631 u8 nvm_hdr; /* length of header in NVM */
3632 u8 ver_offset; /* offset of version structure in rampatch */
3635 static const struct qca_device_info qca_devices_table[] = {
3636 { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */
3637 { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */
3638 { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */
3639 { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */
3640 { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */
3641 { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */
3642 { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */
3643 { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */
3644 { 0x00130201, 40, 4, 16 }, /* WCN6855 2.1 */
3645 { 0x00190200, 40, 4, 16 }, /* WCN785x 2.0 */
3648 static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request,
3649 void *data, u16 size)
3654 buf = kmalloc(size, GFP_KERNEL);
3658 /* Found some of USB hosts have IOT issues with ours so that we should
3659 * not wait until HCI layer is ready.
3661 pipe = usb_rcvctrlpipe(udev, 0);
3662 err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN,
3663 0, 0, buf, size, USB_CTRL_SET_TIMEOUT);
3665 dev_err(&udev->dev, "Failed to access otp area (%d)", err);
3669 memcpy(data, buf, size);
3677 static int btusb_setup_qca_download_fw(struct hci_dev *hdev,
3678 const struct firmware *firmware,
3681 struct btusb_data *btdata = hci_get_drvdata(hdev);
3682 struct usb_device *udev = btdata->udev;
3683 size_t count, size, sent = 0;
3687 buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL);
3691 count = firmware->size;
3693 size = min_t(size_t, count, hdr_size);
3694 memcpy(buf, firmware->data, size);
3696 /* USB patches should go down to controller through USB path
3697 * because binary format fits to go down through USB channel.
3698 * USB control path is for patching headers and USB bulk is for
3701 pipe = usb_sndctrlpipe(udev, 0);
3702 err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR,
3703 0, 0, buf, size, USB_CTRL_SET_TIMEOUT);
3705 bt_dev_err(hdev, "Failed to send headers (%d)", err);
3712 /* ep2 need time to switch from function acl to function dfu,
3713 * so we add 20ms delay here.
3718 size = min_t(size_t, count, QCA_DFU_PACKET_LEN);
3720 memcpy(buf, firmware->data + sent, size);
3722 pipe = usb_sndbulkpipe(udev, 0x02);
3723 err = usb_bulk_msg(udev, pipe, buf, size, &len,
3726 bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)",
3727 sent, firmware->size, err);
3732 bt_dev_err(hdev, "Failed to get bulk buffer");
3746 static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev,
3747 struct qca_version *ver,
3748 const struct qca_device_info *info)
3750 struct qca_rampatch_version *rver;
3751 const struct firmware *fw;
3752 u32 ver_rom, ver_patch, rver_rom;
3753 u16 rver_rom_low, rver_rom_high, rver_patch;
3757 ver_rom = le32_to_cpu(ver->rom_version);
3758 ver_patch = le32_to_cpu(ver->patch_version);
3760 snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin", ver_rom);
3762 err = request_firmware(&fw, fwname, &hdev->dev);
3764 bt_dev_err(hdev, "failed to request rampatch file: %s (%d)",
3769 bt_dev_info(hdev, "using rampatch file: %s", fwname);
3771 rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset);
3772 rver_rom_low = le16_to_cpu(rver->rom_version_low);
3773 rver_patch = le16_to_cpu(rver->patch_version);
3775 if (ver_rom & ~0xffffU) {
3776 rver_rom_high = le16_to_cpu(rver->rom_version_high);
3777 rver_rom = rver_rom_high << 16 | rver_rom_low;
3779 rver_rom = rver_rom_low;
3782 bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, "
3783 "firmware rome 0x%x build 0x%x",
3784 rver_rom, rver_patch, ver_rom, ver_patch);
3786 if (rver_rom != ver_rom || rver_patch <= ver_patch) {
3787 bt_dev_err(hdev, "rampatch file version did not match with firmware");
3792 err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr);
3795 release_firmware(fw);
3800 static void btusb_generate_qca_nvm_name(char *fwname, size_t max_size,
3801 const struct qca_version *ver)
3803 u32 rom_version = le32_to_cpu(ver->rom_version);
3804 u16 flag = le16_to_cpu(ver->flag);
3806 if (((flag >> 8) & 0xff) == QCA_FLAG_MULTI_NVM) {
3807 /* The board_id should be split into two bytes
3808 * The 1st byte is chip ID, and the 2nd byte is platform ID
3809 * For example, board ID 0x010A, 0x01 is platform ID. 0x0A is chip ID
3810 * we have several platforms, and platform IDs are continuously added
3812 * 0x00 is for Mobile
3814 * 0x02 is for Automotive
3815 * 0x03 is for Consumer electronic
3817 u16 board_id = (ver->chip_id << 8) + ver->platform_id;
3818 const char *variant;
3820 switch (le32_to_cpu(ver->ram_version)) {
3821 case WCN6855_2_0_RAM_VERSION_GF:
3822 case WCN6855_2_1_RAM_VERSION_GF:
3830 if (board_id == 0) {
3831 snprintf(fwname, max_size, "qca/nvm_usb_%08x%s.bin",
3832 rom_version, variant);
3834 snprintf(fwname, max_size, "qca/nvm_usb_%08x%s_%04x.bin",
3835 rom_version, variant, board_id);
3838 snprintf(fwname, max_size, "qca/nvm_usb_%08x.bin",
3844 static int btusb_setup_qca_load_nvm(struct hci_dev *hdev,
3845 struct qca_version *ver,
3846 const struct qca_device_info *info)
3848 const struct firmware *fw;
3852 btusb_generate_qca_nvm_name(fwname, sizeof(fwname), ver);
3854 err = request_firmware(&fw, fwname, &hdev->dev);
3856 bt_dev_err(hdev, "failed to request NVM file: %s (%d)",
3861 bt_dev_info(hdev, "using NVM file: %s", fwname);
3863 err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr);
3865 release_firmware(fw);
3870 /* identify the ROM version and check whether patches are needed */
3871 static bool btusb_qca_need_patch(struct usb_device *udev)
3873 struct qca_version ver;
3875 if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3878 /* only low ROM versions need patches */
3879 return !(le32_to_cpu(ver.rom_version) & ~0xffffU);
3882 static int btusb_setup_qca(struct hci_dev *hdev)
3884 struct btusb_data *btdata = hci_get_drvdata(hdev);
3885 struct usb_device *udev = btdata->udev;
3886 const struct qca_device_info *info = NULL;
3887 struct qca_version ver;
3892 err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3897 ver_rom = le32_to_cpu(ver.rom_version);
3899 for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
3900 if (ver_rom == qca_devices_table[i].rom_version)
3901 info = &qca_devices_table[i];
3904 /* If the rom_version is not matched in the qca_devices_table
3905 * and the high ROM version is not zero, we assume this chip no
3906 * need to load the rampatch and nvm.
3908 if (ver_rom & ~0xffffU)
3911 bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom);
3915 err = btusb_qca_send_vendor_req(udev, QCA_CHECK_STATUS, &status,
3920 if (!(status & QCA_PATCH_UPDATED)) {
3921 err = btusb_setup_qca_load_rampatch(hdev, &ver, info);
3926 err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3931 btdata->qca_dump.fw_version = le32_to_cpu(ver.patch_version);
3932 btdata->qca_dump.controller_id = le32_to_cpu(ver.rom_version);
3934 if (!(status & QCA_SYSCFG_UPDATED)) {
3935 err = btusb_setup_qca_load_nvm(hdev, &ver, info);
3939 /* WCN6855 2.1 and later will reset to apply firmware downloaded here, so
3940 * wait ~100ms for reset Done then go ahead, otherwise, it maybe
3941 * cause potential enable failure.
3943 if (info->rom_version >= 0x00130201)
3944 msleep(QCA_BT_RESET_WAIT_MS);
3947 /* Mark HCI_OP_ENHANCED_SETUP_SYNC_CONN as broken as it doesn't seem to
3948 * work with the likes of HSP/HFP mSBC.
3950 set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks);
3955 static inline int __set_diag_interface(struct hci_dev *hdev)
3957 struct btusb_data *data = hci_get_drvdata(hdev);
3958 struct usb_interface *intf = data->diag;
3964 data->diag_tx_ep = NULL;
3965 data->diag_rx_ep = NULL;
3967 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
3968 struct usb_endpoint_descriptor *ep_desc;
3970 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
3972 if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
3973 data->diag_tx_ep = ep_desc;
3977 if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
3978 data->diag_rx_ep = ep_desc;
3983 if (!data->diag_tx_ep || !data->diag_rx_ep) {
3984 bt_dev_err(hdev, "invalid diagnostic descriptors");
3991 static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable)
3993 struct btusb_data *data = hci_get_drvdata(hdev);
3994 struct sk_buff *skb;
3998 if (!data->diag_tx_ep)
3999 return ERR_PTR(-ENODEV);
4001 urb = usb_alloc_urb(0, GFP_KERNEL);
4003 return ERR_PTR(-ENOMEM);
4005 skb = bt_skb_alloc(2, GFP_KERNEL);
4008 return ERR_PTR(-ENOMEM);
4011 skb_put_u8(skb, 0xf0);
4012 skb_put_u8(skb, enable);
4014 pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress);
4016 usb_fill_bulk_urb(urb, data->udev, pipe,
4017 skb->data, skb->len, btusb_tx_complete, skb);
4019 skb->dev = (void *)hdev;
4024 static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable)
4026 struct btusb_data *data = hci_get_drvdata(hdev);
4032 if (!test_bit(HCI_RUNNING, &hdev->flags))
4035 urb = alloc_diag_urb(hdev, enable);
4037 return PTR_ERR(urb);
4039 return submit_or_queue_tx_urb(hdev, urb);
4043 static irqreturn_t btusb_oob_wake_handler(int irq, void *priv)
4045 struct btusb_data *data = priv;
4047 pm_wakeup_event(&data->udev->dev, 0);
4050 /* Disable only if not already disabled (keep it balanced) */
4051 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) {
4052 disable_irq_nosync(irq);
4053 disable_irq_wake(irq);
4058 static const struct of_device_id btusb_match_table[] = {
4059 { .compatible = "usb1286,204e" },
4060 { .compatible = "usbcf3,e300" }, /* QCA6174A */
4061 { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */
4064 MODULE_DEVICE_TABLE(of, btusb_match_table);
4066 /* Use an oob wakeup pin? */
4067 static int btusb_config_oob_wake(struct hci_dev *hdev)
4069 struct btusb_data *data = hci_get_drvdata(hdev);
4070 struct device *dev = &data->udev->dev;
4073 clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags);
4075 if (!of_match_device(btusb_match_table, dev))
4078 /* Move on if no IRQ specified */
4079 irq = of_irq_get_byname(dev->of_node, "wakeup");
4081 bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__);
4085 irq_set_status_flags(irq, IRQ_NOAUTOEN);
4086 ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler,
4087 0, "OOB Wake-on-BT", data);
4089 bt_dev_err(hdev, "%s: IRQ request failed", __func__);
4093 ret = device_init_wakeup(dev, true);
4095 bt_dev_err(hdev, "%s: failed to init_wakeup", __func__);
4099 data->oob_wake_irq = irq;
4100 bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq);
4105 static void btusb_check_needs_reset_resume(struct usb_interface *intf)
4107 if (dmi_check_system(btusb_needs_reset_resume_table))
4108 interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
4111 static bool btusb_wakeup(struct hci_dev *hdev)
4113 struct btusb_data *data = hci_get_drvdata(hdev);
4115 return device_may_wakeup(&data->udev->dev);
4118 static int btusb_shutdown_qca(struct hci_dev *hdev)
4120 struct sk_buff *skb;
4122 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
4124 bt_dev_err(hdev, "HCI reset during shutdown failed");
4125 return PTR_ERR(skb);
4132 static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf,
4133 size_t count, loff_t *ppos)
4135 struct btusb_data *data = file->private_data;
4138 buf[0] = data->poll_sync ? 'Y' : 'N';
4141 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
4144 static ssize_t force_poll_sync_write(struct file *file,
4145 const char __user *user_buf,
4146 size_t count, loff_t *ppos)
4148 struct btusb_data *data = file->private_data;
4152 err = kstrtobool_from_user(user_buf, count, &enable);
4156 /* Only allow changes while the adapter is down */
4157 if (test_bit(HCI_UP, &data->hdev->flags))
4160 if (data->poll_sync == enable)
4163 data->poll_sync = enable;
4168 static const struct file_operations force_poll_sync_fops = {
4169 .open = simple_open,
4170 .read = force_poll_sync_read,
4171 .write = force_poll_sync_write,
4172 .llseek = default_llseek,
4175 static int btusb_probe(struct usb_interface *intf,
4176 const struct usb_device_id *id)
4178 struct usb_endpoint_descriptor *ep_desc;
4179 struct gpio_desc *reset_gpio;
4180 struct btusb_data *data;
4181 struct hci_dev *hdev;
4182 unsigned ifnum_base;
4183 int i, err, priv_size;
4185 BT_DBG("intf %p id %p", intf, id);
4187 if ((id->driver_info & BTUSB_IFNUM_2) &&
4188 (intf->cur_altsetting->desc.bInterfaceNumber != 0) &&
4189 (intf->cur_altsetting->desc.bInterfaceNumber != 2))
4192 ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber;
4194 if (!id->driver_info) {
4195 const struct usb_device_id *match;
4197 match = usb_match_id(intf, quirks_table);
4202 if (id->driver_info == BTUSB_IGNORE)
4205 if (id->driver_info & BTUSB_ATH3012) {
4206 struct usb_device *udev = interface_to_usbdev(intf);
4208 /* Old firmware would otherwise let ath3k driver load
4209 * patch and sysconfig files
4211 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 &&
4212 !btusb_qca_need_patch(udev))
4216 data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
4220 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
4221 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
4223 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
4224 data->intr_ep = ep_desc;
4228 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
4229 data->bulk_tx_ep = ep_desc;
4233 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
4234 data->bulk_rx_ep = ep_desc;
4239 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
4242 if (id->driver_info & BTUSB_AMP) {
4243 data->cmdreq_type = USB_TYPE_CLASS | 0x01;
4244 data->cmdreq = 0x2b;
4246 data->cmdreq_type = USB_TYPE_CLASS;
4247 data->cmdreq = 0x00;
4250 data->udev = interface_to_usbdev(intf);
4253 INIT_WORK(&data->work, btusb_work);
4254 INIT_WORK(&data->waker, btusb_waker);
4255 INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work);
4257 skb_queue_head_init(&data->acl_q);
4259 init_usb_anchor(&data->deferred);
4260 init_usb_anchor(&data->tx_anchor);
4261 spin_lock_init(&data->txlock);
4263 init_usb_anchor(&data->intr_anchor);
4264 init_usb_anchor(&data->bulk_anchor);
4265 init_usb_anchor(&data->isoc_anchor);
4266 init_usb_anchor(&data->diag_anchor);
4267 init_usb_anchor(&data->ctrl_anchor);
4268 spin_lock_init(&data->rxlock);
4272 data->recv_event = hci_recv_frame;
4273 data->recv_bulk = btusb_recv_bulk;
4275 if (id->driver_info & BTUSB_INTEL_COMBINED) {
4276 /* Allocate extra space for Intel device */
4277 priv_size += sizeof(struct btintel_data);
4279 /* Override the rx handlers */
4280 data->recv_event = btintel_recv_event;
4281 data->recv_bulk = btusb_recv_bulk_intel;
4282 } else if (id->driver_info & BTUSB_REALTEK) {
4283 /* Allocate extra space for Realtek device */
4284 priv_size += sizeof(struct btrealtek_data);
4286 data->recv_event = btusb_recv_event_realtek;
4287 } else if (id->driver_info & BTUSB_MEDIATEK) {
4288 /* Allocate extra space for Mediatek device */
4289 priv_size += sizeof(struct btmediatek_data);
4292 data->recv_acl = hci_recv_frame;
4294 hdev = hci_alloc_dev_priv(priv_size);
4298 hdev->bus = HCI_USB;
4299 hci_set_drvdata(hdev, data);
4301 if (id->driver_info & BTUSB_AMP)
4302 hdev->dev_type = HCI_AMP;
4304 hdev->dev_type = HCI_PRIMARY;
4308 SET_HCIDEV_DEV(hdev, &intf->dev);
4310 reset_gpio = gpiod_get_optional(&data->udev->dev, "reset",
4312 if (IS_ERR(reset_gpio)) {
4313 err = PTR_ERR(reset_gpio);
4315 } else if (reset_gpio) {
4316 data->reset_gpio = reset_gpio;
4319 hdev->open = btusb_open;
4320 hdev->close = btusb_close;
4321 hdev->flush = btusb_flush;
4322 hdev->send = btusb_send_frame;
4323 hdev->notify = btusb_notify;
4324 hdev->wakeup = btusb_wakeup;
4327 err = btusb_config_oob_wake(hdev);
4331 /* Marvell devices may need a specific chip configuration */
4332 if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) {
4333 err = marvell_config_oob_wake(hdev);
4338 if (id->driver_info & BTUSB_CW6622)
4339 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
4341 if (id->driver_info & BTUSB_BCM2045)
4342 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
4344 if (id->driver_info & BTUSB_BCM92035)
4345 hdev->setup = btusb_setup_bcm92035;
4347 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
4348 (id->driver_info & BTUSB_BCM_PATCHRAM)) {
4349 hdev->manufacturer = 15;
4350 hdev->setup = btbcm_setup_patchram;
4351 hdev->set_diag = btusb_bcm_set_diag;
4352 hdev->set_bdaddr = btbcm_set_bdaddr;
4354 /* Broadcom LM_DIAG Interface numbers are hardcoded */
4355 data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
4358 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) &&
4359 (id->driver_info & BTUSB_BCM_APPLE)) {
4360 hdev->manufacturer = 15;
4361 hdev->setup = btbcm_setup_apple;
4362 hdev->set_diag = btusb_bcm_set_diag;
4364 /* Broadcom LM_DIAG Interface numbers are hardcoded */
4365 data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2);
4368 /* Combined Intel Device setup to support multiple setup routine */
4369 if (id->driver_info & BTUSB_INTEL_COMBINED) {
4370 err = btintel_configure_setup(hdev, btusb_driver.name);
4374 /* Transport specific configuration */
4375 hdev->send = btusb_send_frame_intel;
4376 hdev->cmd_timeout = btusb_intel_cmd_timeout;
4378 if (id->driver_info & BTUSB_INTEL_NO_WBS_SUPPORT)
4379 btintel_set_flag(hdev, INTEL_ROM_LEGACY_NO_WBS_SUPPORT);
4381 if (id->driver_info & BTUSB_INTEL_BROKEN_INITIAL_NCMD)
4382 btintel_set_flag(hdev, INTEL_BROKEN_INITIAL_NCMD);
4384 if (id->driver_info & BTUSB_INTEL_BROKEN_SHUTDOWN_LED)
4385 btintel_set_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED);
4388 if (id->driver_info & BTUSB_MARVELL)
4389 hdev->set_bdaddr = btusb_set_bdaddr_marvell;
4391 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) &&
4392 (id->driver_info & BTUSB_MEDIATEK)) {
4393 hdev->setup = btusb_mtk_setup;
4394 hdev->shutdown = btusb_mtk_shutdown;
4395 hdev->manufacturer = 70;
4396 hdev->cmd_timeout = btmtk_reset_sync;
4397 hdev->set_bdaddr = btmtk_set_bdaddr;
4398 set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &hdev->quirks);
4399 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
4400 data->recv_acl = btusb_recv_acl_mtk;
4403 if (id->driver_info & BTUSB_SWAVE) {
4404 set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
4405 set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks);
4408 if (id->driver_info & BTUSB_INTEL_BOOT) {
4409 hdev->manufacturer = 2;
4410 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
4413 if (id->driver_info & BTUSB_ATH3012) {
4414 data->setup_on_usb = btusb_setup_qca;
4415 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
4416 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
4417 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
4420 if (id->driver_info & BTUSB_QCA_ROME) {
4421 data->setup_on_usb = btusb_setup_qca;
4422 hdev->shutdown = btusb_shutdown_qca;
4423 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
4424 hdev->cmd_timeout = btusb_qca_cmd_timeout;
4425 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
4426 btusb_check_needs_reset_resume(intf);
4429 if (id->driver_info & BTUSB_QCA_WCN6855) {
4430 data->qca_dump.id_vendor = id->idVendor;
4431 data->qca_dump.id_product = id->idProduct;
4432 data->recv_event = btusb_recv_evt_qca;
4433 data->recv_acl = btusb_recv_acl_qca;
4434 hci_devcd_register(hdev, btusb_coredump_qca, btusb_dump_hdr_qca, NULL);
4435 data->setup_on_usb = btusb_setup_qca;
4436 hdev->shutdown = btusb_shutdown_qca;
4437 hdev->set_bdaddr = btusb_set_bdaddr_wcn6855;
4438 hdev->cmd_timeout = btusb_qca_cmd_timeout;
4439 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
4440 hci_set_msft_opcode(hdev, 0xFD70);
4443 if (id->driver_info & BTUSB_AMP) {
4444 /* AMP controllers do not support SCO packets */
4447 /* Interface orders are hardcoded in the specification */
4448 data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1);
4449 data->isoc_ifnum = ifnum_base + 1;
4452 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) &&
4453 (id->driver_info & BTUSB_REALTEK)) {
4454 btrtl_set_driver_name(hdev, btusb_driver.name);
4455 hdev->setup = btusb_setup_realtek;
4456 hdev->shutdown = btrtl_shutdown_realtek;
4457 hdev->cmd_timeout = btusb_rtl_cmd_timeout;
4458 hdev->hw_error = btusb_rtl_hw_error;
4460 /* Realtek devices need to set remote wakeup on auto-suspend */
4461 set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags);
4462 set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags);
4465 if (id->driver_info & BTUSB_ACTIONS_SEMI) {
4466 /* Support is advertised, but not implemented */
4467 set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
4468 set_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks);
4469 set_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks);
4470 set_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &hdev->quirks);
4474 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
4476 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
4477 if (!disable_scofix)
4478 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
4481 if (id->driver_info & BTUSB_BROKEN_ISOC)
4484 if (id->driver_info & BTUSB_WIDEBAND_SPEECH)
4485 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
4487 if (id->driver_info & BTUSB_VALID_LE_STATES)
4488 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
4490 if (id->driver_info & BTUSB_DIGIANSWER) {
4491 data->cmdreq_type = USB_TYPE_VENDOR;
4492 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
4495 if (id->driver_info & BTUSB_CSR) {
4496 struct usb_device *udev = data->udev;
4497 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
4499 /* Old firmware would otherwise execute USB reset */
4500 if (bcdDevice < 0x117)
4501 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
4503 /* This must be set first in case we disable it for fakes */
4504 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
4506 /* Fake CSR devices with broken commands */
4507 if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 &&
4508 le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
4509 hdev->setup = btusb_setup_csr;
4512 if (id->driver_info & BTUSB_SNIFFER) {
4513 struct usb_device *udev = data->udev;
4515 /* New sniffer firmware has crippled HCI interface */
4516 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
4517 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
4520 if (id->driver_info & BTUSB_INTEL_BOOT) {
4521 /* A bug in the bootloader causes that interrupt interface is
4522 * only enabled after receiving SetInterface(0, AltSetting=0).
4524 err = usb_set_interface(data->udev, 0, 0);
4526 BT_ERR("failed to set interface 0, alt 0 %d", err);
4532 err = usb_driver_claim_interface(&btusb_driver,
4538 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) {
4539 if (!usb_driver_claim_interface(&btusb_driver,
4541 __set_diag_interface(hdev);
4546 if (enable_autosuspend)
4547 usb_enable_autosuspend(data->udev);
4549 data->poll_sync = enable_poll_sync;
4551 err = hci_register_dev(hdev);
4555 usb_set_intfdata(intf, data);
4557 debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data,
4558 &force_poll_sync_fops);
4563 if (data->reset_gpio)
4564 gpiod_put(data->reset_gpio);
4569 static void btusb_disconnect(struct usb_interface *intf)
4571 struct btusb_data *data = usb_get_intfdata(intf);
4572 struct hci_dev *hdev;
4574 BT_DBG("intf %p", intf);
4580 usb_set_intfdata(data->intf, NULL);
4583 usb_set_intfdata(data->isoc, NULL);
4586 usb_set_intfdata(data->diag, NULL);
4588 hci_unregister_dev(hdev);
4590 if (intf == data->intf) {
4592 usb_driver_release_interface(&btusb_driver, data->isoc);
4594 usb_driver_release_interface(&btusb_driver, data->diag);
4595 } else if (intf == data->isoc) {
4597 usb_driver_release_interface(&btusb_driver, data->diag);
4598 usb_driver_release_interface(&btusb_driver, data->intf);
4599 } else if (intf == data->diag) {
4600 usb_driver_release_interface(&btusb_driver, data->intf);
4602 usb_driver_release_interface(&btusb_driver, data->isoc);
4605 if (data->oob_wake_irq)
4606 device_init_wakeup(&data->udev->dev, false);
4608 if (data->reset_gpio)
4609 gpiod_put(data->reset_gpio);
4615 static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
4617 struct btusb_data *data = usb_get_intfdata(intf);
4619 BT_DBG("intf %p", intf);
4621 if (data->suspend_count++)
4624 spin_lock_irq(&data->txlock);
4625 if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
4626 set_bit(BTUSB_SUSPENDING, &data->flags);
4627 spin_unlock_irq(&data->txlock);
4629 spin_unlock_irq(&data->txlock);
4630 data->suspend_count--;
4634 cancel_work_sync(&data->work);
4636 btusb_stop_traffic(data);
4637 usb_kill_anchored_urbs(&data->tx_anchor);
4639 if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) {
4640 set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags);
4641 enable_irq_wake(data->oob_wake_irq);
4642 enable_irq(data->oob_wake_irq);
4645 /* For global suspend, Realtek devices lose the loaded fw
4646 * in them. But for autosuspend, firmware should remain.
4647 * Actually, it depends on whether the usb host sends
4648 * set feature (enable wakeup) or not.
4650 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) {
4651 if (PMSG_IS_AUTO(message) &&
4652 device_can_wakeup(&data->udev->dev))
4653 data->udev->do_remote_wakeup = 1;
4654 else if (!PMSG_IS_AUTO(message) &&
4655 !device_may_wakeup(&data->udev->dev)) {
4656 data->udev->do_remote_wakeup = 0;
4657 data->udev->reset_resume = 1;
4664 static void play_deferred(struct btusb_data *data)
4669 while ((urb = usb_get_from_anchor(&data->deferred))) {
4670 usb_anchor_urb(urb, &data->tx_anchor);
4672 err = usb_submit_urb(urb, GFP_ATOMIC);
4674 if (err != -EPERM && err != -ENODEV)
4675 BT_ERR("%s urb %p submission failed (%d)",
4676 data->hdev->name, urb, -err);
4677 kfree(urb->setup_packet);
4678 usb_unanchor_urb(urb);
4683 data->tx_in_flight++;
4687 /* Cleanup the rest deferred urbs. */
4688 while ((urb = usb_get_from_anchor(&data->deferred))) {
4689 kfree(urb->setup_packet);
4694 static int btusb_resume(struct usb_interface *intf)
4696 struct btusb_data *data = usb_get_intfdata(intf);
4697 struct hci_dev *hdev = data->hdev;
4700 BT_DBG("intf %p", intf);
4702 if (--data->suspend_count)
4705 /* Disable only if not already disabled (keep it balanced) */
4706 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) {
4707 disable_irq(data->oob_wake_irq);
4708 disable_irq_wake(data->oob_wake_irq);
4711 if (!test_bit(HCI_RUNNING, &hdev->flags))
4714 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
4715 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
4717 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
4722 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
4723 err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
4725 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
4729 btusb_submit_bulk_urb(hdev, GFP_NOIO);
4732 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
4733 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
4734 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
4736 btusb_submit_isoc_urb(hdev, GFP_NOIO);
4739 spin_lock_irq(&data->txlock);
4740 play_deferred(data);
4741 clear_bit(BTUSB_SUSPENDING, &data->flags);
4742 spin_unlock_irq(&data->txlock);
4743 schedule_work(&data->work);
4748 usb_scuttle_anchored_urbs(&data->deferred);
4750 spin_lock_irq(&data->txlock);
4751 clear_bit(BTUSB_SUSPENDING, &data->flags);
4752 spin_unlock_irq(&data->txlock);
4758 #ifdef CONFIG_DEV_COREDUMP
4759 static void btusb_coredump(struct device *dev)
4761 struct btusb_data *data = dev_get_drvdata(dev);
4762 struct hci_dev *hdev = data->hdev;
4764 if (hdev->dump.coredump)
4765 hdev->dump.coredump(hdev);
4769 static struct usb_driver btusb_driver = {
4771 .probe = btusb_probe,
4772 .disconnect = btusb_disconnect,
4774 .suspend = btusb_suspend,
4775 .resume = btusb_resume,
4777 .id_table = btusb_table,
4778 .supports_autosuspend = 1,
4779 .disable_hub_initiated_lpm = 1,
4781 #ifdef CONFIG_DEV_COREDUMP
4784 .coredump = btusb_coredump,
4790 module_usb_driver(btusb_driver);
4792 module_param(disable_scofix, bool, 0644);
4793 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
4795 module_param(force_scofix, bool, 0644);
4796 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
4798 module_param(enable_autosuspend, bool, 0644);
4799 MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default");
4801 module_param(reset, bool, 0644);
4802 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
4804 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
4805 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
4806 MODULE_VERSION(VERSION);
4807 MODULE_LICENSE("GPL");