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 <linux/unaligned.h>
22 #include <net/bluetooth/bluetooth.h>
23 #include <net/bluetooth/hci_core.h>
24 #include <net/bluetooth/hci_drv.h>
33 static bool disable_scofix
;
34 static bool force_scofix
;
35 static bool enable_autosuspend
= IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND
);
36 static bool enable_poll_sync
= IS_ENABLED(CONFIG_BT_HCIBTUSB_POLL_SYNC
);
37 static bool reset
= true;
39 static struct usb_driver btusb_driver
;
41 #define BTUSB_IGNORE BIT(0)
42 #define BTUSB_DIGIANSWER BIT(1)
43 #define BTUSB_CSR BIT(2)
44 #define BTUSB_SNIFFER BIT(3)
45 #define BTUSB_BCM92035 BIT(4)
46 #define BTUSB_BROKEN_ISOC BIT(5)
47 #define BTUSB_WRONG_SCO_MTU BIT(6)
48 #define BTUSB_ATH3012 BIT(7)
49 #define BTUSB_INTEL_COMBINED BIT(8)
50 #define BTUSB_INTEL_BOOT BIT(9)
51 #define BTUSB_BCM_PATCHRAM BIT(10)
52 #define BTUSB_MARVELL BIT(11)
53 #define BTUSB_SWAVE BIT(12)
54 #define BTUSB_AMP BIT(13)
55 #define BTUSB_QCA_ROME BIT(14)
56 #define BTUSB_BCM_APPLE BIT(15)
57 #define BTUSB_REALTEK BIT(16)
58 #define BTUSB_BCM2045 BIT(17)
59 #define BTUSB_IFNUM_2 BIT(18)
60 #define BTUSB_CW6622 BIT(19)
61 #define BTUSB_MEDIATEK BIT(20)
62 #define BTUSB_WIDEBAND_SPEECH BIT(21)
63 #define BTUSB_INVALID_LE_STATES BIT(22)
64 #define BTUSB_QCA_WCN6855 BIT(23)
65 #define BTUSB_INTEL_BROKEN_SHUTDOWN_LED BIT(24)
66 #define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25)
67 #define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26)
68 #define BTUSB_ACTIONS_SEMI BIT(27)
70 static const struct usb_device_id btusb_table
[] = {
71 /* Generic Bluetooth USB device */
72 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
74 /* Generic Bluetooth AMP device */
75 { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info
= BTUSB_AMP
},
77 /* Generic Bluetooth USB interface */
78 { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) },
80 /* Apple-specific (Broadcom) devices */
81 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01),
82 .driver_info
= BTUSB_BCM_APPLE
| BTUSB_IFNUM_2
},
84 /* MediaTek MT76x0E */
85 { USB_DEVICE(0x0e8d, 0x763f) },
87 /* Broadcom SoftSailing reporting vendor specific */
88 { USB_DEVICE(0x0a5c, 0x21e1) },
90 /* Apple MacBookPro 7,1 */
91 { USB_DEVICE(0x05ac, 0x8213) },
94 { USB_DEVICE(0x05ac, 0x8215) },
96 /* Apple MacBookPro6,2 */
97 { USB_DEVICE(0x05ac, 0x8218) },
99 /* Apple MacBookAir3,1, MacBookAir3,2 */
100 { USB_DEVICE(0x05ac, 0x821b) },
102 /* Apple MacBookAir4,1 */
103 { USB_DEVICE(0x05ac, 0x821f) },
105 /* Apple MacBookPro8,2 */
106 { USB_DEVICE(0x05ac, 0x821a) },
108 /* Apple MacMini5,1 */
109 { USB_DEVICE(0x05ac, 0x8281) },
111 /* AVM BlueFRITZ! USB v2.0 */
112 { USB_DEVICE(0x057c, 0x3800), .driver_info
= BTUSB_SWAVE
},
114 /* Bluetooth Ultraport Module from IBM */
115 { USB_DEVICE(0x04bf, 0x030a) },
117 /* ALPS Modules with non-standard id */
118 { USB_DEVICE(0x044e, 0x3001) },
119 { USB_DEVICE(0x044e, 0x3002) },
121 /* Ericsson with non-standard id */
122 { USB_DEVICE(0x0bdb, 0x1002) },
124 /* Canyon CN-BTU1 with HID interfaces */
125 { USB_DEVICE(0x0c10, 0x0000) },
127 /* Broadcom BCM20702B0 (Dynex/Insignia) */
128 { USB_DEVICE(0x19ff, 0x0239), .driver_info
= BTUSB_BCM_PATCHRAM
},
130 /* Broadcom BCM43142A0 (Foxconn/Lenovo) */
131 { USB_VENDOR_AND_INTERFACE_INFO(0x105b, 0xff, 0x01, 0x01),
132 .driver_info
= BTUSB_BCM_PATCHRAM
},
134 /* Broadcom BCM920703 (HTC Vive) */
135 { USB_VENDOR_AND_INTERFACE_INFO(0x0bb4, 0xff, 0x01, 0x01),
136 .driver_info
= BTUSB_BCM_PATCHRAM
},
138 /* Foxconn - Hon Hai */
139 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
140 .driver_info
= BTUSB_BCM_PATCHRAM
},
142 /* Lite-On Technology - Broadcom based */
143 { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
144 .driver_info
= BTUSB_BCM_PATCHRAM
},
146 /* Broadcom devices with vendor specific id */
147 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
148 .driver_info
= BTUSB_BCM_PATCHRAM
},
150 /* ASUSTek Computer - Broadcom based */
151 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
152 .driver_info
= BTUSB_BCM_PATCHRAM
},
154 /* Belkin F8065bf - Broadcom based */
155 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01),
156 .driver_info
= BTUSB_BCM_PATCHRAM
},
158 /* IMC Networks - Broadcom based */
159 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01),
160 .driver_info
= BTUSB_BCM_PATCHRAM
},
162 /* Dell Computer - Broadcom based */
163 { USB_VENDOR_AND_INTERFACE_INFO(0x413c, 0xff, 0x01, 0x01),
164 .driver_info
= BTUSB_BCM_PATCHRAM
},
166 /* Toshiba Corp - Broadcom based */
167 { USB_VENDOR_AND_INTERFACE_INFO(0x0930, 0xff, 0x01, 0x01),
168 .driver_info
= BTUSB_BCM_PATCHRAM
},
170 /* Intel Bluetooth USB Bootloader (RAM module) */
171 { USB_DEVICE(0x8087, 0x0a5a),
172 .driver_info
= BTUSB_INTEL_BOOT
| BTUSB_BROKEN_ISOC
},
174 { } /* Terminating entry */
177 MODULE_DEVICE_TABLE(usb
, btusb_table
);
179 static const struct usb_device_id quirks_table
[] = {
180 /* CSR BlueCore devices */
181 { USB_DEVICE(0x0a12, 0x0001), .driver_info
= BTUSB_CSR
},
183 /* Broadcom BCM2033 without firmware */
184 { USB_DEVICE(0x0a5c, 0x2033), .driver_info
= BTUSB_IGNORE
},
186 /* Broadcom BCM2045 devices */
187 { USB_DEVICE(0x0a5c, 0x2045), .driver_info
= BTUSB_BCM2045
},
189 /* Atheros 3011 with sflash firmware */
190 { USB_DEVICE(0x0489, 0xe027), .driver_info
= BTUSB_IGNORE
},
191 { USB_DEVICE(0x0489, 0xe03d), .driver_info
= BTUSB_IGNORE
},
192 { USB_DEVICE(0x04f2, 0xaff1), .driver_info
= BTUSB_IGNORE
},
193 { USB_DEVICE(0x0930, 0x0215), .driver_info
= BTUSB_IGNORE
},
194 { USB_DEVICE(0x0cf3, 0x3002), .driver_info
= BTUSB_IGNORE
},
195 { USB_DEVICE(0x0cf3, 0xe019), .driver_info
= BTUSB_IGNORE
},
196 { USB_DEVICE(0x13d3, 0x3304), .driver_info
= BTUSB_IGNORE
},
198 /* Atheros AR9285 Malbec with sflash firmware */
199 { USB_DEVICE(0x03f0, 0x311d), .driver_info
= BTUSB_IGNORE
},
201 /* Atheros 3012 with sflash firmware */
202 { USB_DEVICE(0x0489, 0xe04d), .driver_info
= BTUSB_ATH3012
},
203 { USB_DEVICE(0x0489, 0xe04e), .driver_info
= BTUSB_ATH3012
},
204 { USB_DEVICE(0x0489, 0xe056), .driver_info
= BTUSB_ATH3012
},
205 { USB_DEVICE(0x0489, 0xe057), .driver_info
= BTUSB_ATH3012
},
206 { USB_DEVICE(0x0489, 0xe05f), .driver_info
= BTUSB_ATH3012
},
207 { USB_DEVICE(0x0489, 0xe076), .driver_info
= BTUSB_ATH3012
},
208 { USB_DEVICE(0x0489, 0xe078), .driver_info
= BTUSB_ATH3012
},
209 { USB_DEVICE(0x0489, 0xe095), .driver_info
= BTUSB_ATH3012
},
210 { USB_DEVICE(0x04c5, 0x1330), .driver_info
= BTUSB_ATH3012
},
211 { USB_DEVICE(0x04ca, 0x3004), .driver_info
= BTUSB_ATH3012
},
212 { USB_DEVICE(0x04ca, 0x3005), .driver_info
= BTUSB_ATH3012
},
213 { USB_DEVICE(0x04ca, 0x3006), .driver_info
= BTUSB_ATH3012
},
214 { USB_DEVICE(0x04ca, 0x3007), .driver_info
= BTUSB_ATH3012
},
215 { USB_DEVICE(0x04ca, 0x3008), .driver_info
= BTUSB_ATH3012
},
216 { USB_DEVICE(0x04ca, 0x300b), .driver_info
= BTUSB_ATH3012
},
217 { USB_DEVICE(0x04ca, 0x300d), .driver_info
= BTUSB_ATH3012
},
218 { USB_DEVICE(0x04ca, 0x300f), .driver_info
= BTUSB_ATH3012
},
219 { USB_DEVICE(0x04ca, 0x3010), .driver_info
= BTUSB_ATH3012
},
220 { USB_DEVICE(0x04ca, 0x3014), .driver_info
= BTUSB_ATH3012
},
221 { USB_DEVICE(0x04ca, 0x3018), .driver_info
= BTUSB_ATH3012
},
222 { USB_DEVICE(0x0930, 0x0219), .driver_info
= BTUSB_ATH3012
},
223 { USB_DEVICE(0x0930, 0x021c), .driver_info
= BTUSB_ATH3012
},
224 { USB_DEVICE(0x0930, 0x0220), .driver_info
= BTUSB_ATH3012
},
225 { USB_DEVICE(0x0930, 0x0227), .driver_info
= BTUSB_ATH3012
},
226 { USB_DEVICE(0x0b05, 0x17d0), .driver_info
= BTUSB_ATH3012
},
227 { USB_DEVICE(0x0cf3, 0x0036), .driver_info
= BTUSB_ATH3012
},
228 { USB_DEVICE(0x0cf3, 0x3004), .driver_info
= BTUSB_ATH3012
},
229 { USB_DEVICE(0x0cf3, 0x3008), .driver_info
= BTUSB_ATH3012
},
230 { USB_DEVICE(0x0cf3, 0x311d), .driver_info
= BTUSB_ATH3012
},
231 { USB_DEVICE(0x0cf3, 0x311e), .driver_info
= BTUSB_ATH3012
},
232 { USB_DEVICE(0x0cf3, 0x311f), .driver_info
= BTUSB_ATH3012
},
233 { USB_DEVICE(0x0cf3, 0x3121), .driver_info
= BTUSB_ATH3012
},
234 { USB_DEVICE(0x0cf3, 0x817a), .driver_info
= BTUSB_ATH3012
},
235 { USB_DEVICE(0x0cf3, 0x817b), .driver_info
= BTUSB_ATH3012
},
236 { USB_DEVICE(0x0cf3, 0xe003), .driver_info
= BTUSB_ATH3012
},
237 { USB_DEVICE(0x0cf3, 0xe004), .driver_info
= BTUSB_ATH3012
},
238 { USB_DEVICE(0x0cf3, 0xe005), .driver_info
= BTUSB_ATH3012
},
239 { USB_DEVICE(0x0cf3, 0xe006), .driver_info
= BTUSB_ATH3012
},
240 { USB_DEVICE(0x13d3, 0x3362), .driver_info
= BTUSB_ATH3012
},
241 { USB_DEVICE(0x13d3, 0x3375), .driver_info
= BTUSB_ATH3012
},
242 { USB_DEVICE(0x13d3, 0x3393), .driver_info
= BTUSB_ATH3012
},
243 { USB_DEVICE(0x13d3, 0x3395), .driver_info
= BTUSB_ATH3012
},
244 { USB_DEVICE(0x13d3, 0x3402), .driver_info
= BTUSB_ATH3012
},
245 { USB_DEVICE(0x13d3, 0x3408), .driver_info
= BTUSB_ATH3012
},
246 { USB_DEVICE(0x13d3, 0x3423), .driver_info
= BTUSB_ATH3012
},
247 { USB_DEVICE(0x13d3, 0x3432), .driver_info
= BTUSB_ATH3012
},
248 { USB_DEVICE(0x13d3, 0x3472), .driver_info
= BTUSB_ATH3012
},
249 { USB_DEVICE(0x13d3, 0x3474), .driver_info
= BTUSB_ATH3012
},
250 { USB_DEVICE(0x13d3, 0x3487), .driver_info
= BTUSB_ATH3012
},
251 { USB_DEVICE(0x13d3, 0x3490), .driver_info
= BTUSB_ATH3012
},
253 /* Atheros AR5BBU12 with sflash firmware */
254 { USB_DEVICE(0x0489, 0xe02c), .driver_info
= BTUSB_IGNORE
},
256 /* Atheros AR5BBU12 with sflash firmware */
257 { USB_DEVICE(0x0489, 0xe036), .driver_info
= BTUSB_ATH3012
},
258 { USB_DEVICE(0x0489, 0xe03c), .driver_info
= BTUSB_ATH3012
},
260 /* QCA ROME chipset */
261 { USB_DEVICE(0x0cf3, 0x535b), .driver_info
= BTUSB_QCA_ROME
|
262 BTUSB_WIDEBAND_SPEECH
},
263 { USB_DEVICE(0x0cf3, 0xe007), .driver_info
= BTUSB_QCA_ROME
|
264 BTUSB_WIDEBAND_SPEECH
},
265 { USB_DEVICE(0x0cf3, 0xe009), .driver_info
= BTUSB_QCA_ROME
|
266 BTUSB_WIDEBAND_SPEECH
},
267 { USB_DEVICE(0x0cf3, 0xe010), .driver_info
= BTUSB_QCA_ROME
|
268 BTUSB_WIDEBAND_SPEECH
},
269 { USB_DEVICE(0x0cf3, 0xe300), .driver_info
= BTUSB_QCA_ROME
|
270 BTUSB_WIDEBAND_SPEECH
},
271 { USB_DEVICE(0x0cf3, 0xe301), .driver_info
= BTUSB_QCA_ROME
|
272 BTUSB_WIDEBAND_SPEECH
},
273 { USB_DEVICE(0x0cf3, 0xe360), .driver_info
= BTUSB_QCA_ROME
|
274 BTUSB_WIDEBAND_SPEECH
},
275 { USB_DEVICE(0x0cf3, 0xe500), .driver_info
= BTUSB_QCA_ROME
|
276 BTUSB_WIDEBAND_SPEECH
},
277 { USB_DEVICE(0x0489, 0xe092), .driver_info
= BTUSB_QCA_ROME
|
278 BTUSB_WIDEBAND_SPEECH
},
279 { USB_DEVICE(0x0489, 0xe09f), .driver_info
= BTUSB_QCA_ROME
|
280 BTUSB_WIDEBAND_SPEECH
},
281 { USB_DEVICE(0x0489, 0xe0a2), .driver_info
= BTUSB_QCA_ROME
|
282 BTUSB_WIDEBAND_SPEECH
},
283 { USB_DEVICE(0x04ca, 0x3011), .driver_info
= BTUSB_QCA_ROME
|
284 BTUSB_WIDEBAND_SPEECH
},
285 { USB_DEVICE(0x04ca, 0x3015), .driver_info
= BTUSB_QCA_ROME
|
286 BTUSB_WIDEBAND_SPEECH
},
287 { USB_DEVICE(0x04ca, 0x3016), .driver_info
= BTUSB_QCA_ROME
|
288 BTUSB_WIDEBAND_SPEECH
},
289 { USB_DEVICE(0x04ca, 0x301a), .driver_info
= BTUSB_QCA_ROME
|
290 BTUSB_WIDEBAND_SPEECH
},
291 { USB_DEVICE(0x04ca, 0x3021), .driver_info
= BTUSB_QCA_ROME
|
292 BTUSB_WIDEBAND_SPEECH
},
293 { USB_DEVICE(0x13d3, 0x3491), .driver_info
= BTUSB_QCA_ROME
|
294 BTUSB_WIDEBAND_SPEECH
},
295 { USB_DEVICE(0x13d3, 0x3496), .driver_info
= BTUSB_QCA_ROME
|
296 BTUSB_WIDEBAND_SPEECH
},
297 { USB_DEVICE(0x13d3, 0x3501), .driver_info
= BTUSB_QCA_ROME
|
298 BTUSB_WIDEBAND_SPEECH
},
300 /* QCA WCN6855 chipset */
301 { USB_DEVICE(0x0cf3, 0xe600), .driver_info
= BTUSB_QCA_WCN6855
|
302 BTUSB_WIDEBAND_SPEECH
},
303 { USB_DEVICE(0x0489, 0xe0cc), .driver_info
= BTUSB_QCA_WCN6855
|
304 BTUSB_WIDEBAND_SPEECH
},
305 { USB_DEVICE(0x0489, 0xe0d6), .driver_info
= BTUSB_QCA_WCN6855
|
306 BTUSB_WIDEBAND_SPEECH
},
307 { USB_DEVICE(0x0489, 0xe0e3), .driver_info
= BTUSB_QCA_WCN6855
|
308 BTUSB_WIDEBAND_SPEECH
},
309 { USB_DEVICE(0x10ab, 0x9309), .driver_info
= BTUSB_QCA_WCN6855
|
310 BTUSB_WIDEBAND_SPEECH
},
311 { USB_DEVICE(0x10ab, 0x9409), .driver_info
= BTUSB_QCA_WCN6855
|
312 BTUSB_WIDEBAND_SPEECH
},
313 { USB_DEVICE(0x0489, 0xe0d0), .driver_info
= BTUSB_QCA_WCN6855
|
314 BTUSB_WIDEBAND_SPEECH
},
315 { USB_DEVICE(0x10ab, 0x9108), .driver_info
= BTUSB_QCA_WCN6855
|
316 BTUSB_WIDEBAND_SPEECH
},
317 { USB_DEVICE(0x10ab, 0x9109), .driver_info
= BTUSB_QCA_WCN6855
|
318 BTUSB_WIDEBAND_SPEECH
},
319 { USB_DEVICE(0x10ab, 0x9208), .driver_info
= BTUSB_QCA_WCN6855
|
320 BTUSB_WIDEBAND_SPEECH
},
321 { USB_DEVICE(0x10ab, 0x9209), .driver_info
= BTUSB_QCA_WCN6855
|
322 BTUSB_WIDEBAND_SPEECH
},
323 { USB_DEVICE(0x10ab, 0x9308), .driver_info
= BTUSB_QCA_WCN6855
|
324 BTUSB_WIDEBAND_SPEECH
},
325 { USB_DEVICE(0x10ab, 0x9408), .driver_info
= BTUSB_QCA_WCN6855
|
326 BTUSB_WIDEBAND_SPEECH
},
327 { USB_DEVICE(0x10ab, 0x9508), .driver_info
= BTUSB_QCA_WCN6855
|
328 BTUSB_WIDEBAND_SPEECH
},
329 { USB_DEVICE(0x10ab, 0x9509), .driver_info
= BTUSB_QCA_WCN6855
|
330 BTUSB_WIDEBAND_SPEECH
},
331 { USB_DEVICE(0x10ab, 0x9608), .driver_info
= BTUSB_QCA_WCN6855
|
332 BTUSB_WIDEBAND_SPEECH
},
333 { USB_DEVICE(0x10ab, 0x9609), .driver_info
= BTUSB_QCA_WCN6855
|
334 BTUSB_WIDEBAND_SPEECH
},
335 { USB_DEVICE(0x10ab, 0x9f09), .driver_info
= BTUSB_QCA_WCN6855
|
336 BTUSB_WIDEBAND_SPEECH
},
337 { USB_DEVICE(0x04ca, 0x3022), .driver_info
= BTUSB_QCA_WCN6855
|
338 BTUSB_WIDEBAND_SPEECH
},
339 { USB_DEVICE(0x0489, 0xe0c7), .driver_info
= BTUSB_QCA_WCN6855
|
340 BTUSB_WIDEBAND_SPEECH
},
341 { USB_DEVICE(0x0489, 0xe0c9), .driver_info
= BTUSB_QCA_WCN6855
|
342 BTUSB_WIDEBAND_SPEECH
},
343 { USB_DEVICE(0x0489, 0xe0ca), .driver_info
= BTUSB_QCA_WCN6855
|
344 BTUSB_WIDEBAND_SPEECH
},
345 { USB_DEVICE(0x0489, 0xe0cb), .driver_info
= BTUSB_QCA_WCN6855
|
346 BTUSB_WIDEBAND_SPEECH
},
347 { USB_DEVICE(0x0489, 0xe0ce), .driver_info
= BTUSB_QCA_WCN6855
|
348 BTUSB_WIDEBAND_SPEECH
},
349 { USB_DEVICE(0x0489, 0xe0de), .driver_info
= BTUSB_QCA_WCN6855
|
350 BTUSB_WIDEBAND_SPEECH
},
351 { USB_DEVICE(0x0489, 0xe0df), .driver_info
= BTUSB_QCA_WCN6855
|
352 BTUSB_WIDEBAND_SPEECH
},
353 { USB_DEVICE(0x0489, 0xe0e1), .driver_info
= BTUSB_QCA_WCN6855
|
354 BTUSB_WIDEBAND_SPEECH
},
355 { USB_DEVICE(0x0489, 0xe0ea), .driver_info
= BTUSB_QCA_WCN6855
|
356 BTUSB_WIDEBAND_SPEECH
},
357 { USB_DEVICE(0x0489, 0xe0ec), .driver_info
= BTUSB_QCA_WCN6855
|
358 BTUSB_WIDEBAND_SPEECH
},
359 { USB_DEVICE(0x04ca, 0x3023), .driver_info
= BTUSB_QCA_WCN6855
|
360 BTUSB_WIDEBAND_SPEECH
},
361 { USB_DEVICE(0x04ca, 0x3024), .driver_info
= BTUSB_QCA_WCN6855
|
362 BTUSB_WIDEBAND_SPEECH
},
363 { USB_DEVICE(0x04ca, 0x3a22), .driver_info
= BTUSB_QCA_WCN6855
|
364 BTUSB_WIDEBAND_SPEECH
},
365 { USB_DEVICE(0x04ca, 0x3a24), .driver_info
= BTUSB_QCA_WCN6855
|
366 BTUSB_WIDEBAND_SPEECH
},
367 { USB_DEVICE(0x04ca, 0x3a26), .driver_info
= BTUSB_QCA_WCN6855
|
368 BTUSB_WIDEBAND_SPEECH
},
369 { USB_DEVICE(0x04ca, 0x3a27), .driver_info
= BTUSB_QCA_WCN6855
|
370 BTUSB_WIDEBAND_SPEECH
},
372 /* QCA WCN785x chipset */
373 { USB_DEVICE(0x0cf3, 0xe700), .driver_info
= BTUSB_QCA_WCN6855
|
374 BTUSB_WIDEBAND_SPEECH
},
375 { USB_DEVICE(0x0489, 0xe0fc), .driver_info
= BTUSB_QCA_WCN6855
|
376 BTUSB_WIDEBAND_SPEECH
},
377 { USB_DEVICE(0x0489, 0xe0f3), .driver_info
= BTUSB_QCA_WCN6855
|
378 BTUSB_WIDEBAND_SPEECH
},
379 { USB_DEVICE(0x0489, 0xe100), .driver_info
= BTUSB_QCA_WCN6855
|
380 BTUSB_WIDEBAND_SPEECH
},
381 { USB_DEVICE(0x0489, 0xe103), .driver_info
= BTUSB_QCA_WCN6855
|
382 BTUSB_WIDEBAND_SPEECH
},
383 { USB_DEVICE(0x0489, 0xe10a), .driver_info
= BTUSB_QCA_WCN6855
|
384 BTUSB_WIDEBAND_SPEECH
},
385 { USB_DEVICE(0x0489, 0xe10d), .driver_info
= BTUSB_QCA_WCN6855
|
386 BTUSB_WIDEBAND_SPEECH
},
387 { USB_DEVICE(0x0489, 0xe11b), .driver_info
= BTUSB_QCA_WCN6855
|
388 BTUSB_WIDEBAND_SPEECH
},
389 { USB_DEVICE(0x0489, 0xe11c), .driver_info
= BTUSB_QCA_WCN6855
|
390 BTUSB_WIDEBAND_SPEECH
},
391 { USB_DEVICE(0x0489, 0xe11f), .driver_info
= BTUSB_QCA_WCN6855
|
392 BTUSB_WIDEBAND_SPEECH
},
393 { USB_DEVICE(0x0489, 0xe141), .driver_info
= BTUSB_QCA_WCN6855
|
394 BTUSB_WIDEBAND_SPEECH
},
395 { USB_DEVICE(0x0489, 0xe14a), .driver_info
= BTUSB_QCA_WCN6855
|
396 BTUSB_WIDEBAND_SPEECH
},
397 { USB_DEVICE(0x0489, 0xe14b), .driver_info
= BTUSB_QCA_WCN6855
|
398 BTUSB_WIDEBAND_SPEECH
},
399 { USB_DEVICE(0x0489, 0xe14d), .driver_info
= BTUSB_QCA_WCN6855
|
400 BTUSB_WIDEBAND_SPEECH
},
401 { USB_DEVICE(0x13d3, 0x3623), .driver_info
= BTUSB_QCA_WCN6855
|
402 BTUSB_WIDEBAND_SPEECH
},
403 { USB_DEVICE(0x13d3, 0x3624), .driver_info
= BTUSB_QCA_WCN6855
|
404 BTUSB_WIDEBAND_SPEECH
},
405 { USB_DEVICE(0x2c7c, 0x0130), .driver_info
= BTUSB_QCA_WCN6855
|
406 BTUSB_WIDEBAND_SPEECH
},
407 { USB_DEVICE(0x2c7c, 0x0131), .driver_info
= BTUSB_QCA_WCN6855
|
408 BTUSB_WIDEBAND_SPEECH
},
409 { USB_DEVICE(0x2c7c, 0x0132), .driver_info
= BTUSB_QCA_WCN6855
|
410 BTUSB_WIDEBAND_SPEECH
},
412 /* Broadcom BCM2035 */
413 { USB_DEVICE(0x0a5c, 0x2009), .driver_info
= BTUSB_BCM92035
},
414 { USB_DEVICE(0x0a5c, 0x200a), .driver_info
= BTUSB_WRONG_SCO_MTU
},
415 { USB_DEVICE(0x0a5c, 0x2035), .driver_info
= BTUSB_WRONG_SCO_MTU
},
417 /* Broadcom BCM2045 */
418 { USB_DEVICE(0x0a5c, 0x2039), .driver_info
= BTUSB_WRONG_SCO_MTU
},
419 { USB_DEVICE(0x0a5c, 0x2101), .driver_info
= BTUSB_WRONG_SCO_MTU
},
421 /* IBM/Lenovo ThinkPad with Broadcom chip */
422 { USB_DEVICE(0x0a5c, 0x201e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
423 { USB_DEVICE(0x0a5c, 0x2110), .driver_info
= BTUSB_WRONG_SCO_MTU
},
425 /* HP laptop with Broadcom chip */
426 { USB_DEVICE(0x03f0, 0x171d), .driver_info
= BTUSB_WRONG_SCO_MTU
},
428 /* Dell laptop with Broadcom chip */
429 { USB_DEVICE(0x413c, 0x8126), .driver_info
= BTUSB_WRONG_SCO_MTU
},
431 /* Dell Wireless 370 and 410 devices */
432 { USB_DEVICE(0x413c, 0x8152), .driver_info
= BTUSB_WRONG_SCO_MTU
},
433 { USB_DEVICE(0x413c, 0x8156), .driver_info
= BTUSB_WRONG_SCO_MTU
},
435 /* Belkin F8T012 and F8T013 devices */
436 { USB_DEVICE(0x050d, 0x0012), .driver_info
= BTUSB_WRONG_SCO_MTU
},
437 { USB_DEVICE(0x050d, 0x0013), .driver_info
= BTUSB_WRONG_SCO_MTU
},
439 /* Asus WL-BTD202 device */
440 { USB_DEVICE(0x0b05, 0x1715), .driver_info
= BTUSB_WRONG_SCO_MTU
},
442 /* Kensington Bluetooth USB adapter */
443 { USB_DEVICE(0x047d, 0x105e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
445 /* RTX Telecom based adapters with buggy SCO support */
446 { USB_DEVICE(0x0400, 0x0807), .driver_info
= BTUSB_BROKEN_ISOC
},
447 { USB_DEVICE(0x0400, 0x080a), .driver_info
= BTUSB_BROKEN_ISOC
},
449 /* CONWISE Technology based adapters with buggy SCO support */
450 { USB_DEVICE(0x0e5e, 0x6622),
451 .driver_info
= BTUSB_BROKEN_ISOC
| BTUSB_CW6622
},
453 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
454 { USB_DEVICE(0x1310, 0x0001), .driver_info
= BTUSB_SWAVE
},
456 /* Digianswer devices */
457 { USB_DEVICE(0x08fd, 0x0001), .driver_info
= BTUSB_DIGIANSWER
},
458 { USB_DEVICE(0x08fd, 0x0002), .driver_info
= BTUSB_IGNORE
},
460 /* CSR BlueCore Bluetooth Sniffer */
461 { USB_DEVICE(0x0a12, 0x0002),
462 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
464 /* Frontline ComProbe Bluetooth Sniffer */
465 { USB_DEVICE(0x16d3, 0x0002),
466 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
468 /* Marvell Bluetooth devices */
469 { USB_DEVICE(0x1286, 0x2044), .driver_info
= BTUSB_MARVELL
},
470 { USB_DEVICE(0x1286, 0x2046), .driver_info
= BTUSB_MARVELL
},
471 { USB_DEVICE(0x1286, 0x204e), .driver_info
= BTUSB_MARVELL
},
473 /* Intel Bluetooth devices */
474 { USB_DEVICE(0x8087, 0x0025), .driver_info
= BTUSB_INTEL_COMBINED
},
475 { USB_DEVICE(0x8087, 0x0026), .driver_info
= BTUSB_INTEL_COMBINED
},
476 { USB_DEVICE(0x8087, 0x0029), .driver_info
= BTUSB_INTEL_COMBINED
},
477 { USB_DEVICE(0x8087, 0x0032), .driver_info
= BTUSB_INTEL_COMBINED
},
478 { USB_DEVICE(0x8087, 0x0033), .driver_info
= BTUSB_INTEL_COMBINED
},
479 { USB_DEVICE(0x8087, 0x0035), .driver_info
= BTUSB_INTEL_COMBINED
},
480 { USB_DEVICE(0x8087, 0x0036), .driver_info
= BTUSB_INTEL_COMBINED
},
481 { USB_DEVICE(0x8087, 0x0037), .driver_info
= BTUSB_INTEL_COMBINED
},
482 { USB_DEVICE(0x8087, 0x0038), .driver_info
= BTUSB_INTEL_COMBINED
},
483 { USB_DEVICE(0x8087, 0x0039), .driver_info
= BTUSB_INTEL_COMBINED
},
484 { USB_DEVICE(0x8087, 0x07da), .driver_info
= BTUSB_CSR
},
485 { USB_DEVICE(0x8087, 0x07dc), .driver_info
= BTUSB_INTEL_COMBINED
|
486 BTUSB_INTEL_NO_WBS_SUPPORT
|
487 BTUSB_INTEL_BROKEN_INITIAL_NCMD
|
488 BTUSB_INTEL_BROKEN_SHUTDOWN_LED
},
489 { USB_DEVICE(0x8087, 0x0a2a), .driver_info
= BTUSB_INTEL_COMBINED
|
490 BTUSB_INTEL_NO_WBS_SUPPORT
|
491 BTUSB_INTEL_BROKEN_SHUTDOWN_LED
},
492 { USB_DEVICE(0x8087, 0x0a2b), .driver_info
= BTUSB_INTEL_COMBINED
},
493 { USB_DEVICE(0x8087, 0x0aa7), .driver_info
= BTUSB_INTEL_COMBINED
|
494 BTUSB_INTEL_BROKEN_SHUTDOWN_LED
},
495 { USB_DEVICE(0x8087, 0x0aaa), .driver_info
= BTUSB_INTEL_COMBINED
},
497 /* Other Intel Bluetooth devices */
498 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
499 .driver_info
= BTUSB_IGNORE
},
501 /* Realtek 8821CE Bluetooth devices */
502 { USB_DEVICE(0x13d3, 0x3529), .driver_info
= BTUSB_REALTEK
|
503 BTUSB_WIDEBAND_SPEECH
},
505 /* Realtek 8822CE Bluetooth devices */
506 { USB_DEVICE(0x0bda, 0xb00c), .driver_info
= BTUSB_REALTEK
|
507 BTUSB_WIDEBAND_SPEECH
},
508 { USB_DEVICE(0x0bda, 0xc822), .driver_info
= BTUSB_REALTEK
|
509 BTUSB_WIDEBAND_SPEECH
},
511 /* Realtek 8822CU Bluetooth devices */
512 { USB_DEVICE(0x13d3, 0x3549), .driver_info
= BTUSB_REALTEK
|
513 BTUSB_WIDEBAND_SPEECH
},
515 /* Realtek 8851BE Bluetooth devices */
516 { USB_DEVICE(0x0bda, 0xb850), .driver_info
= BTUSB_REALTEK
},
517 { USB_DEVICE(0x13d3, 0x3600), .driver_info
= BTUSB_REALTEK
},
519 /* Realtek 8852AE Bluetooth devices */
520 { USB_DEVICE(0x0bda, 0x2852), .driver_info
= BTUSB_REALTEK
|
521 BTUSB_WIDEBAND_SPEECH
},
522 { USB_DEVICE(0x0bda, 0xc852), .driver_info
= BTUSB_REALTEK
|
523 BTUSB_WIDEBAND_SPEECH
},
524 { USB_DEVICE(0x0bda, 0x385a), .driver_info
= BTUSB_REALTEK
|
525 BTUSB_WIDEBAND_SPEECH
},
526 { USB_DEVICE(0x0bda, 0x4852), .driver_info
= BTUSB_REALTEK
|
527 BTUSB_WIDEBAND_SPEECH
},
528 { USB_DEVICE(0x04c5, 0x165c), .driver_info
= BTUSB_REALTEK
|
529 BTUSB_WIDEBAND_SPEECH
},
530 { USB_DEVICE(0x04ca, 0x4006), .driver_info
= BTUSB_REALTEK
|
531 BTUSB_WIDEBAND_SPEECH
},
532 { USB_DEVICE(0x0cb8, 0xc549), .driver_info
= BTUSB_REALTEK
|
533 BTUSB_WIDEBAND_SPEECH
},
535 /* Realtek 8852CE Bluetooth devices */
536 { USB_DEVICE(0x04ca, 0x4007), .driver_info
= BTUSB_REALTEK
|
537 BTUSB_WIDEBAND_SPEECH
},
538 { USB_DEVICE(0x04c5, 0x1675), .driver_info
= BTUSB_REALTEK
|
539 BTUSB_WIDEBAND_SPEECH
},
540 { USB_DEVICE(0x0cb8, 0xc558), .driver_info
= BTUSB_REALTEK
|
541 BTUSB_WIDEBAND_SPEECH
},
542 { USB_DEVICE(0x13d3, 0x3587), .driver_info
= BTUSB_REALTEK
|
543 BTUSB_WIDEBAND_SPEECH
},
544 { USB_DEVICE(0x13d3, 0x3586), .driver_info
= BTUSB_REALTEK
|
545 BTUSB_WIDEBAND_SPEECH
},
546 { USB_DEVICE(0x13d3, 0x3592), .driver_info
= BTUSB_REALTEK
|
547 BTUSB_WIDEBAND_SPEECH
},
548 { USB_DEVICE(0x0489, 0xe122), .driver_info
= BTUSB_REALTEK
|
549 BTUSB_WIDEBAND_SPEECH
},
551 /* Realtek 8852BE Bluetooth devices */
552 { USB_DEVICE(0x0cb8, 0xc559), .driver_info
= BTUSB_REALTEK
|
553 BTUSB_WIDEBAND_SPEECH
},
554 { USB_DEVICE(0x0bda, 0x4853), .driver_info
= BTUSB_REALTEK
|
555 BTUSB_WIDEBAND_SPEECH
},
556 { USB_DEVICE(0x0bda, 0x887b), .driver_info
= BTUSB_REALTEK
|
557 BTUSB_WIDEBAND_SPEECH
},
558 { USB_DEVICE(0x0bda, 0xb85b), .driver_info
= BTUSB_REALTEK
|
559 BTUSB_WIDEBAND_SPEECH
},
560 { USB_DEVICE(0x13d3, 0x3570), .driver_info
= BTUSB_REALTEK
|
561 BTUSB_WIDEBAND_SPEECH
},
562 { USB_DEVICE(0x13d3, 0x3571), .driver_info
= BTUSB_REALTEK
|
563 BTUSB_WIDEBAND_SPEECH
},
564 { USB_DEVICE(0x13d3, 0x3572), .driver_info
= BTUSB_REALTEK
|
565 BTUSB_WIDEBAND_SPEECH
},
566 { USB_DEVICE(0x13d3, 0x3591), .driver_info
= BTUSB_REALTEK
|
567 BTUSB_WIDEBAND_SPEECH
},
568 { USB_DEVICE(0x0489, 0xe123), .driver_info
= BTUSB_REALTEK
|
569 BTUSB_WIDEBAND_SPEECH
},
570 { USB_DEVICE(0x0489, 0xe125), .driver_info
= BTUSB_REALTEK
|
571 BTUSB_WIDEBAND_SPEECH
},
573 /* Realtek 8852BT/8852BE-VT Bluetooth devices */
574 { USB_DEVICE(0x0bda, 0x8520), .driver_info
= BTUSB_REALTEK
|
575 BTUSB_WIDEBAND_SPEECH
},
577 /* Realtek 8922AE Bluetooth devices */
578 { USB_DEVICE(0x0bda, 0x8922), .driver_info
= BTUSB_REALTEK
|
579 BTUSB_WIDEBAND_SPEECH
},
580 { USB_DEVICE(0x13d3, 0x3617), .driver_info
= BTUSB_REALTEK
|
581 BTUSB_WIDEBAND_SPEECH
},
582 { USB_DEVICE(0x13d3, 0x3616), .driver_info
= BTUSB_REALTEK
|
583 BTUSB_WIDEBAND_SPEECH
},
584 { USB_DEVICE(0x0489, 0xe130), .driver_info
= BTUSB_REALTEK
|
585 BTUSB_WIDEBAND_SPEECH
},
587 /* Realtek Bluetooth devices */
588 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
589 .driver_info
= BTUSB_REALTEK
},
591 /* MediaTek Bluetooth devices */
592 { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01),
593 .driver_info
= BTUSB_MEDIATEK
|
594 BTUSB_WIDEBAND_SPEECH
},
596 /* Additional MediaTek MT7615E Bluetooth devices */
597 { USB_DEVICE(0x13d3, 0x3560), .driver_info
= BTUSB_MEDIATEK
},
599 /* Additional MediaTek MT7663 Bluetooth devices */
600 { USB_DEVICE(0x043e, 0x310c), .driver_info
= BTUSB_MEDIATEK
|
601 BTUSB_WIDEBAND_SPEECH
},
602 { USB_DEVICE(0x04ca, 0x3801), .driver_info
= BTUSB_MEDIATEK
|
603 BTUSB_WIDEBAND_SPEECH
},
605 /* Additional MediaTek MT7668 Bluetooth devices */
606 { USB_DEVICE(0x043e, 0x3109), .driver_info
= BTUSB_MEDIATEK
|
607 BTUSB_WIDEBAND_SPEECH
},
609 /* Additional MediaTek MT7920 Bluetooth devices */
610 { USB_DEVICE(0x0489, 0xe134), .driver_info
= BTUSB_MEDIATEK
|
611 BTUSB_WIDEBAND_SPEECH
},
612 { USB_DEVICE(0x13d3, 0x3620), .driver_info
= BTUSB_MEDIATEK
|
613 BTUSB_WIDEBAND_SPEECH
},
614 { USB_DEVICE(0x13d3, 0x3621), .driver_info
= BTUSB_MEDIATEK
|
615 BTUSB_WIDEBAND_SPEECH
},
616 { USB_DEVICE(0x13d3, 0x3622), .driver_info
= BTUSB_MEDIATEK
|
617 BTUSB_WIDEBAND_SPEECH
},
619 /* Additional MediaTek MT7921 Bluetooth devices */
620 { USB_DEVICE(0x0489, 0xe0c8), .driver_info
= BTUSB_MEDIATEK
|
621 BTUSB_WIDEBAND_SPEECH
},
622 { USB_DEVICE(0x0489, 0xe0cd), .driver_info
= BTUSB_MEDIATEK
|
623 BTUSB_WIDEBAND_SPEECH
},
624 { USB_DEVICE(0x0489, 0xe0e0), .driver_info
= BTUSB_MEDIATEK
|
625 BTUSB_WIDEBAND_SPEECH
},
626 { USB_DEVICE(0x0489, 0xe0f2), .driver_info
= BTUSB_MEDIATEK
|
627 BTUSB_WIDEBAND_SPEECH
},
628 { USB_DEVICE(0x04ca, 0x3802), .driver_info
= BTUSB_MEDIATEK
|
629 BTUSB_WIDEBAND_SPEECH
},
630 { USB_DEVICE(0x0e8d, 0x0608), .driver_info
= BTUSB_MEDIATEK
|
631 BTUSB_WIDEBAND_SPEECH
},
632 { USB_DEVICE(0x13d3, 0x3563), .driver_info
= BTUSB_MEDIATEK
|
633 BTUSB_WIDEBAND_SPEECH
},
634 { USB_DEVICE(0x13d3, 0x3564), .driver_info
= BTUSB_MEDIATEK
|
635 BTUSB_WIDEBAND_SPEECH
},
636 { USB_DEVICE(0x13d3, 0x3567), .driver_info
= BTUSB_MEDIATEK
|
637 BTUSB_WIDEBAND_SPEECH
},
638 { USB_DEVICE(0x13d3, 0x3576), .driver_info
= BTUSB_MEDIATEK
|
639 BTUSB_WIDEBAND_SPEECH
},
640 { USB_DEVICE(0x13d3, 0x3578), .driver_info
= BTUSB_MEDIATEK
|
641 BTUSB_WIDEBAND_SPEECH
},
642 { USB_DEVICE(0x13d3, 0x3583), .driver_info
= BTUSB_MEDIATEK
|
643 BTUSB_WIDEBAND_SPEECH
},
644 { USB_DEVICE(0x13d3, 0x3606), .driver_info
= BTUSB_MEDIATEK
|
645 BTUSB_WIDEBAND_SPEECH
},
647 /* MediaTek MT7922 Bluetooth devices */
648 { USB_DEVICE(0x13d3, 0x3585), .driver_info
= BTUSB_MEDIATEK
|
649 BTUSB_WIDEBAND_SPEECH
},
650 { USB_DEVICE(0x13d3, 0x3610), .driver_info
= BTUSB_MEDIATEK
|
651 BTUSB_WIDEBAND_SPEECH
},
653 /* MediaTek MT7922A Bluetooth devices */
654 { USB_DEVICE(0x0489, 0xe0d8), .driver_info
= BTUSB_MEDIATEK
|
655 BTUSB_WIDEBAND_SPEECH
},
656 { USB_DEVICE(0x0489, 0xe0d9), .driver_info
= BTUSB_MEDIATEK
|
657 BTUSB_WIDEBAND_SPEECH
},
658 { USB_DEVICE(0x0489, 0xe0e2), .driver_info
= BTUSB_MEDIATEK
|
659 BTUSB_WIDEBAND_SPEECH
},
660 { USB_DEVICE(0x0489, 0xe0e4), .driver_info
= BTUSB_MEDIATEK
|
661 BTUSB_WIDEBAND_SPEECH
},
662 { USB_DEVICE(0x0489, 0xe0f1), .driver_info
= BTUSB_MEDIATEK
|
663 BTUSB_WIDEBAND_SPEECH
},
664 { USB_DEVICE(0x0489, 0xe0f2), .driver_info
= BTUSB_MEDIATEK
|
665 BTUSB_WIDEBAND_SPEECH
},
666 { USB_DEVICE(0x0489, 0xe0f5), .driver_info
= BTUSB_MEDIATEK
|
667 BTUSB_WIDEBAND_SPEECH
},
668 { USB_DEVICE(0x0489, 0xe0f6), .driver_info
= BTUSB_MEDIATEK
|
669 BTUSB_WIDEBAND_SPEECH
},
670 { USB_DEVICE(0x0489, 0xe102), .driver_info
= BTUSB_MEDIATEK
|
671 BTUSB_WIDEBAND_SPEECH
},
672 { USB_DEVICE(0x0489, 0xe152), .driver_info
= BTUSB_MEDIATEK
|
673 BTUSB_WIDEBAND_SPEECH
},
674 { USB_DEVICE(0x0489, 0xe153), .driver_info
= BTUSB_MEDIATEK
|
675 BTUSB_WIDEBAND_SPEECH
},
676 { USB_DEVICE(0x04ca, 0x3804), .driver_info
= BTUSB_MEDIATEK
|
677 BTUSB_WIDEBAND_SPEECH
},
678 { USB_DEVICE(0x04ca, 0x38e4), .driver_info
= BTUSB_MEDIATEK
|
679 BTUSB_WIDEBAND_SPEECH
},
680 { USB_DEVICE(0x13d3, 0x3568), .driver_info
= BTUSB_MEDIATEK
|
681 BTUSB_WIDEBAND_SPEECH
},
682 { USB_DEVICE(0x13d3, 0x3584), .driver_info
= BTUSB_MEDIATEK
|
683 BTUSB_WIDEBAND_SPEECH
},
684 { USB_DEVICE(0x13d3, 0x3605), .driver_info
= BTUSB_MEDIATEK
|
685 BTUSB_WIDEBAND_SPEECH
},
686 { USB_DEVICE(0x13d3, 0x3607), .driver_info
= BTUSB_MEDIATEK
|
687 BTUSB_WIDEBAND_SPEECH
},
688 { USB_DEVICE(0x13d3, 0x3614), .driver_info
= BTUSB_MEDIATEK
|
689 BTUSB_WIDEBAND_SPEECH
},
690 { USB_DEVICE(0x13d3, 0x3615), .driver_info
= BTUSB_MEDIATEK
|
691 BTUSB_WIDEBAND_SPEECH
},
692 { USB_DEVICE(0x35f5, 0x7922), .driver_info
= BTUSB_MEDIATEK
|
693 BTUSB_WIDEBAND_SPEECH
},
695 /* Additional MediaTek MT7925 Bluetooth devices */
696 { USB_DEVICE(0x0489, 0xe111), .driver_info
= BTUSB_MEDIATEK
|
697 BTUSB_WIDEBAND_SPEECH
},
698 { USB_DEVICE(0x0489, 0xe113), .driver_info
= BTUSB_MEDIATEK
|
699 BTUSB_WIDEBAND_SPEECH
},
700 { USB_DEVICE(0x0489, 0xe118), .driver_info
= BTUSB_MEDIATEK
|
701 BTUSB_WIDEBAND_SPEECH
},
702 { USB_DEVICE(0x0489, 0xe11e), .driver_info
= BTUSB_MEDIATEK
|
703 BTUSB_WIDEBAND_SPEECH
},
704 { USB_DEVICE(0x0489, 0xe124), .driver_info
= BTUSB_MEDIATEK
|
705 BTUSB_WIDEBAND_SPEECH
},
706 { USB_DEVICE(0x0489, 0xe139), .driver_info
= BTUSB_MEDIATEK
|
707 BTUSB_WIDEBAND_SPEECH
},
708 { USB_DEVICE(0x0489, 0xe14f), .driver_info
= BTUSB_MEDIATEK
|
709 BTUSB_WIDEBAND_SPEECH
},
710 { USB_DEVICE(0x0489, 0xe150), .driver_info
= BTUSB_MEDIATEK
|
711 BTUSB_WIDEBAND_SPEECH
},
712 { USB_DEVICE(0x0489, 0xe151), .driver_info
= BTUSB_MEDIATEK
|
713 BTUSB_WIDEBAND_SPEECH
},
714 { USB_DEVICE(0x13d3, 0x3602), .driver_info
= BTUSB_MEDIATEK
|
715 BTUSB_WIDEBAND_SPEECH
},
716 { USB_DEVICE(0x13d3, 0x3603), .driver_info
= BTUSB_MEDIATEK
|
717 BTUSB_WIDEBAND_SPEECH
},
718 { USB_DEVICE(0x13d3, 0x3604), .driver_info
= BTUSB_MEDIATEK
|
719 BTUSB_WIDEBAND_SPEECH
},
720 { USB_DEVICE(0x13d3, 0x3608), .driver_info
= BTUSB_MEDIATEK
|
721 BTUSB_WIDEBAND_SPEECH
},
722 { USB_DEVICE(0x13d3, 0x3613), .driver_info
= BTUSB_MEDIATEK
|
723 BTUSB_WIDEBAND_SPEECH
},
724 { USB_DEVICE(0x13d3, 0x3628), .driver_info
= BTUSB_MEDIATEK
|
725 BTUSB_WIDEBAND_SPEECH
},
726 { USB_DEVICE(0x13d3, 0x3630), .driver_info
= BTUSB_MEDIATEK
|
727 BTUSB_WIDEBAND_SPEECH
},
729 /* Additional Realtek 8723AE Bluetooth devices */
730 { USB_DEVICE(0x0930, 0x021d), .driver_info
= BTUSB_REALTEK
},
731 { USB_DEVICE(0x13d3, 0x3394), .driver_info
= BTUSB_REALTEK
},
733 /* Additional Realtek 8723BE Bluetooth devices */
734 { USB_DEVICE(0x0489, 0xe085), .driver_info
= BTUSB_REALTEK
},
735 { USB_DEVICE(0x0489, 0xe08b), .driver_info
= BTUSB_REALTEK
},
736 { USB_DEVICE(0x04f2, 0xb49f), .driver_info
= BTUSB_REALTEK
},
737 { USB_DEVICE(0x13d3, 0x3410), .driver_info
= BTUSB_REALTEK
},
738 { USB_DEVICE(0x13d3, 0x3416), .driver_info
= BTUSB_REALTEK
},
739 { USB_DEVICE(0x13d3, 0x3459), .driver_info
= BTUSB_REALTEK
},
740 { USB_DEVICE(0x13d3, 0x3494), .driver_info
= BTUSB_REALTEK
},
742 /* Additional Realtek 8723BU Bluetooth devices */
743 { USB_DEVICE(0x7392, 0xa611), .driver_info
= BTUSB_REALTEK
},
745 /* Additional Realtek 8723DE Bluetooth devices */
746 { USB_DEVICE(0x0bda, 0xb009), .driver_info
= BTUSB_REALTEK
},
747 { USB_DEVICE(0x2ff8, 0xb011), .driver_info
= BTUSB_REALTEK
},
749 /* Additional Realtek 8761BUV Bluetooth devices */
750 { USB_DEVICE(0x2357, 0x0604), .driver_info
= BTUSB_REALTEK
|
751 BTUSB_WIDEBAND_SPEECH
},
752 { USB_DEVICE(0x0b05, 0x190e), .driver_info
= BTUSB_REALTEK
|
753 BTUSB_WIDEBAND_SPEECH
},
754 { USB_DEVICE(0x2550, 0x8761), .driver_info
= BTUSB_REALTEK
|
755 BTUSB_WIDEBAND_SPEECH
},
756 { USB_DEVICE(0x0bda, 0x8771), .driver_info
= BTUSB_REALTEK
|
757 BTUSB_WIDEBAND_SPEECH
},
758 { USB_DEVICE(0x6655, 0x8771), .driver_info
= BTUSB_REALTEK
|
759 BTUSB_WIDEBAND_SPEECH
},
760 { USB_DEVICE(0x7392, 0xc611), .driver_info
= BTUSB_REALTEK
|
761 BTUSB_WIDEBAND_SPEECH
},
762 { USB_DEVICE(0x2b89, 0x8761), .driver_info
= BTUSB_REALTEK
|
763 BTUSB_WIDEBAND_SPEECH
},
765 /* Additional Realtek 8821AE Bluetooth devices */
766 { USB_DEVICE(0x0b05, 0x17dc), .driver_info
= BTUSB_REALTEK
},
767 { USB_DEVICE(0x13d3, 0x3414), .driver_info
= BTUSB_REALTEK
},
768 { USB_DEVICE(0x13d3, 0x3458), .driver_info
= BTUSB_REALTEK
},
769 { USB_DEVICE(0x13d3, 0x3461), .driver_info
= BTUSB_REALTEK
},
770 { USB_DEVICE(0x13d3, 0x3462), .driver_info
= BTUSB_REALTEK
},
772 /* Additional Realtek 8822BE Bluetooth devices */
773 { USB_DEVICE(0x13d3, 0x3526), .driver_info
= BTUSB_REALTEK
},
774 { USB_DEVICE(0x0b05, 0x185c), .driver_info
= BTUSB_REALTEK
},
776 /* Additional Realtek 8822CE Bluetooth devices */
777 { USB_DEVICE(0x04ca, 0x4005), .driver_info
= BTUSB_REALTEK
|
778 BTUSB_WIDEBAND_SPEECH
},
779 { USB_DEVICE(0x04c5, 0x161f), .driver_info
= BTUSB_REALTEK
|
780 BTUSB_WIDEBAND_SPEECH
},
781 { USB_DEVICE(0x0b05, 0x18ef), .driver_info
= BTUSB_REALTEK
|
782 BTUSB_WIDEBAND_SPEECH
},
783 { USB_DEVICE(0x13d3, 0x3548), .driver_info
= BTUSB_REALTEK
|
784 BTUSB_WIDEBAND_SPEECH
},
785 { USB_DEVICE(0x13d3, 0x3549), .driver_info
= BTUSB_REALTEK
|
786 BTUSB_WIDEBAND_SPEECH
},
787 { USB_DEVICE(0x13d3, 0x3553), .driver_info
= BTUSB_REALTEK
|
788 BTUSB_WIDEBAND_SPEECH
},
789 { USB_DEVICE(0x13d3, 0x3555), .driver_info
= BTUSB_REALTEK
|
790 BTUSB_WIDEBAND_SPEECH
},
791 { USB_DEVICE(0x2ff8, 0x3051), .driver_info
= BTUSB_REALTEK
|
792 BTUSB_WIDEBAND_SPEECH
},
793 { USB_DEVICE(0x1358, 0xc123), .driver_info
= BTUSB_REALTEK
|
794 BTUSB_WIDEBAND_SPEECH
},
795 { USB_DEVICE(0x0bda, 0xc123), .driver_info
= BTUSB_REALTEK
|
796 BTUSB_WIDEBAND_SPEECH
},
797 { USB_DEVICE(0x0cb5, 0xc547), .driver_info
= BTUSB_REALTEK
|
798 BTUSB_WIDEBAND_SPEECH
},
800 /* Actions Semiconductor ATS2851 based devices */
801 { USB_DEVICE(0x10d7, 0xb012), .driver_info
= BTUSB_ACTIONS_SEMI
},
803 /* Silicon Wave based devices */
804 { USB_DEVICE(0x0c10, 0x0000), .driver_info
= BTUSB_SWAVE
},
806 { } /* Terminating entry */
809 /* The Bluetooth USB module build into some devices needs to be reset on resume,
810 * this is a problem with the platform (likely shutting off all power) not with
811 * the module itself. So we use a DMI list to match known broken platforms.
813 static const struct dmi_system_id btusb_needs_reset_resume_table
[] = {
815 /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */
817 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
818 DMI_MATCH(DMI_PRODUCT_NAME
, "OptiPlex 3060"),
822 /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */
824 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
825 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS 13 9360"),
829 /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */
831 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
832 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5565"),
838 struct qca_dump_info
{
839 /* fields for dump collection */
848 #define BTUSB_MAX_ISOC_FRAMES 10
850 #define BTUSB_INTR_RUNNING 0
851 #define BTUSB_BULK_RUNNING 1
852 #define BTUSB_ISOC_RUNNING 2
853 #define BTUSB_SUSPENDING 3
854 #define BTUSB_DID_ISO_RESUME 4
855 #define BTUSB_BOOTLOADER 5
856 #define BTUSB_DOWNLOADING 6
857 #define BTUSB_FIRMWARE_LOADED 7
858 #define BTUSB_FIRMWARE_FAILED 8
859 #define BTUSB_BOOTING 9
860 #define BTUSB_DIAG_RUNNING 10
861 #define BTUSB_OOB_WAKE_ENABLED 11
862 #define BTUSB_HW_RESET_ACTIVE 12
863 #define BTUSB_TX_WAIT_VND_EVT 13
864 #define BTUSB_WAKEUP_AUTOSUSPEND 14
865 #define BTUSB_USE_ALT3_FOR_WBS 15
866 #define BTUSB_ALT6_CONTINUOUS_TX 16
867 #define BTUSB_HW_SSR_ACTIVE 17
870 struct hci_dev
*hdev
;
871 struct usb_device
*udev
;
872 struct usb_interface
*intf
;
873 struct usb_interface
*isoc
;
874 struct usb_interface
*diag
;
881 struct work_struct work
;
882 struct work_struct waker
;
883 struct delayed_work rx_work
;
885 struct sk_buff_head acl_q
;
887 struct usb_anchor deferred
;
888 struct usb_anchor tx_anchor
;
892 struct usb_anchor intr_anchor
;
893 struct usb_anchor bulk_anchor
;
894 struct usb_anchor isoc_anchor
;
895 struct usb_anchor diag_anchor
;
896 struct usb_anchor ctrl_anchor
;
899 struct sk_buff
*evt_skb
;
900 struct sk_buff
*acl_skb
;
901 struct sk_buff
*sco_skb
;
903 struct usb_endpoint_descriptor
*intr_ep
;
904 struct usb_endpoint_descriptor
*bulk_tx_ep
;
905 struct usb_endpoint_descriptor
*bulk_rx_ep
;
906 struct usb_endpoint_descriptor
*isoc_tx_ep
;
907 struct usb_endpoint_descriptor
*isoc_rx_ep
;
908 struct usb_endpoint_descriptor
*diag_tx_ep
;
909 struct usb_endpoint_descriptor
*diag_rx_ep
;
911 struct gpio_desc
*reset_gpio
;
916 unsigned int sco_num
;
917 unsigned int air_mode
;
918 bool usb_alt6_packet_flow
;
922 int (*recv_event
)(struct hci_dev
*hdev
, struct sk_buff
*skb
);
923 int (*recv_acl
)(struct hci_dev
*hdev
, struct sk_buff
*skb
);
924 int (*recv_bulk
)(struct btusb_data
*data
, void *buffer
, int count
);
926 int (*setup_on_usb
)(struct hci_dev
*hdev
);
928 int (*suspend
)(struct hci_dev
*hdev
);
929 int (*resume
)(struct hci_dev
*hdev
);
930 int (*disconnect
)(struct hci_dev
*hdev
);
932 int oob_wake_irq
; /* irq for out-of-band wake-on-bt */
934 struct qca_dump_info qca_dump
;
937 static void btusb_reset(struct hci_dev
*hdev
)
939 struct btusb_data
*data
;
942 data
= hci_get_drvdata(hdev
);
943 /* This is not an unbalanced PM reference since the device will reset */
944 err
= usb_autopm_get_interface(data
->intf
);
946 bt_dev_err(hdev
, "Failed usb_autopm_get_interface: %d", err
);
950 bt_dev_err(hdev
, "Resetting usb device.");
951 usb_queue_reset_device(data
->intf
);
954 static void btusb_intel_reset(struct hci_dev
*hdev
)
956 struct btusb_data
*data
= hci_get_drvdata(hdev
);
957 struct gpio_desc
*reset_gpio
= data
->reset_gpio
;
958 struct btintel_data
*intel_data
= hci_get_priv(hdev
);
960 if (intel_data
->acpi_reset_method
) {
961 if (test_and_set_bit(INTEL_ACPI_RESET_ACTIVE
, intel_data
->flags
)) {
962 bt_dev_err(hdev
, "acpi: last reset failed ? Not resetting again");
966 bt_dev_err(hdev
, "Initiating acpi reset method");
967 /* If ACPI reset method fails, lets try with legacy GPIO
970 if (!intel_data
->acpi_reset_method(hdev
)) {
981 * Toggle the hard reset line if the platform provides one. The reset
982 * is going to yank the device off the USB and then replug. So doing
983 * once is enough. The cleanup is handled correctly on the way out
984 * (standard USB disconnect), and the new device is detected cleanly
985 * and bound to the driver again like it should be.
987 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE
, &data
->flags
)) {
988 bt_dev_err(hdev
, "last reset failed? Not resetting again");
992 bt_dev_err(hdev
, "Initiating HW reset via gpio");
993 gpiod_set_value_cansleep(reset_gpio
, 1);
995 gpiod_set_value_cansleep(reset_gpio
, 0);
998 #define RTK_DEVCOREDUMP_CODE_MEMDUMP 0x01
999 #define RTK_DEVCOREDUMP_CODE_HW_ERR 0x02
1000 #define RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT 0x03
1002 #define RTK_SUB_EVENT_CODE_COREDUMP 0x34
1004 struct rtk_dev_coredump_hdr
{
1010 static inline void btusb_rtl_alloc_devcoredump(struct hci_dev
*hdev
,
1011 struct rtk_dev_coredump_hdr
*hdr
, u8
*buf
, u32 len
)
1013 struct sk_buff
*skb
;
1015 skb
= alloc_skb(len
+ sizeof(*hdr
), GFP_ATOMIC
);
1019 skb_put_data(skb
, hdr
, sizeof(*hdr
));
1021 skb_put_data(skb
, buf
, len
);
1023 if (!hci_devcd_init(hdev
, skb
->len
)) {
1024 hci_devcd_append(hdev
, skb
);
1025 hci_devcd_complete(hdev
);
1027 bt_dev_err(hdev
, "RTL: Failed to generate devcoredump");
1032 static void btusb_rtl_reset(struct hci_dev
*hdev
)
1034 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1035 struct gpio_desc
*reset_gpio
= data
->reset_gpio
;
1036 struct rtk_dev_coredump_hdr hdr
= {
1037 .type
= RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT
,
1040 btusb_rtl_alloc_devcoredump(hdev
, &hdr
, NULL
, 0);
1047 /* Toggle the hard reset line. The Realtek device is going to
1048 * yank itself off the USB and then replug. The cleanup is handled
1049 * correctly on the way out (standard USB disconnect), and the new
1050 * device is detected cleanly and bound to the driver again like
1053 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE
, &data
->flags
)) {
1054 bt_dev_err(hdev
, "last reset failed? Not resetting again");
1058 bt_dev_err(hdev
, "Reset Realtek device via gpio");
1059 gpiod_set_value_cansleep(reset_gpio
, 1);
1061 gpiod_set_value_cansleep(reset_gpio
, 0);
1064 static void btusb_rtl_hw_error(struct hci_dev
*hdev
, u8 code
)
1066 struct rtk_dev_coredump_hdr hdr
= {
1067 .type
= RTK_DEVCOREDUMP_CODE_HW_ERR
,
1071 bt_dev_err(hdev
, "RTL: hw err, trigger devcoredump (%d)", code
);
1073 btusb_rtl_alloc_devcoredump(hdev
, &hdr
, NULL
, 0);
1076 static void btusb_qca_reset(struct hci_dev
*hdev
)
1078 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1079 struct gpio_desc
*reset_gpio
= data
->reset_gpio
;
1081 if (test_bit(BTUSB_HW_SSR_ACTIVE
, &data
->flags
)) {
1082 bt_dev_info(hdev
, "Ramdump in progress, defer reset");
1087 bt_dev_err(hdev
, "Reset qca device via bt_en gpio");
1089 /* Toggle the hard reset line. The qca bt device is going to
1090 * yank itself off the USB and then replug. The cleanup is handled
1091 * correctly on the way out (standard USB disconnect), and the new
1092 * device is detected cleanly and bound to the driver again like
1095 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE
, &data
->flags
)) {
1096 bt_dev_err(hdev
, "last reset failed? Not resetting again");
1100 gpiod_set_value_cansleep(reset_gpio
, 0);
1102 gpiod_set_value_cansleep(reset_gpio
, 1);
1110 static inline void btusb_free_frags(struct btusb_data
*data
)
1112 unsigned long flags
;
1114 spin_lock_irqsave(&data
->rxlock
, flags
);
1116 dev_kfree_skb_irq(data
->evt_skb
);
1117 data
->evt_skb
= NULL
;
1119 dev_kfree_skb_irq(data
->acl_skb
);
1120 data
->acl_skb
= NULL
;
1122 dev_kfree_skb_irq(data
->sco_skb
);
1123 data
->sco_skb
= NULL
;
1125 spin_unlock_irqrestore(&data
->rxlock
, flags
);
1128 static int btusb_recv_event(struct btusb_data
*data
, struct sk_buff
*skb
)
1130 if (data
->intr_interval
) {
1131 /* Trigger dequeue immediately if an event is received */
1132 schedule_delayed_work(&data
->rx_work
, 0);
1135 return data
->recv_event(data
->hdev
, skb
);
1138 static int btusb_recv_intr(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
->evt_skb
;
1151 skb
= bt_skb_alloc(HCI_MAX_EVENT_SIZE
, GFP_ATOMIC
);
1157 hci_skb_pkt_type(skb
) = HCI_EVENT_PKT
;
1158 hci_skb_expect(skb
) = HCI_EVENT_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_EVENT_HDR_SIZE
) {
1169 /* Complete event header */
1170 hci_skb_expect(skb
) = hci_event_hdr(skb
)->plen
;
1172 if (skb_tailroom(skb
) < hci_skb_expect(skb
)) {
1181 if (!hci_skb_expect(skb
)) {
1182 /* Complete frame */
1183 btusb_recv_event(data
, skb
);
1188 data
->evt_skb
= skb
;
1189 spin_unlock_irqrestore(&data
->rxlock
, flags
);
1194 static int btusb_recv_acl(struct btusb_data
*data
, struct sk_buff
*skb
)
1196 /* Only queue ACL packet if intr_interval is set as it means
1197 * force_poll_sync has been enabled.
1199 if (!data
->intr_interval
)
1200 return data
->recv_acl(data
->hdev
, skb
);
1202 skb_queue_tail(&data
->acl_q
, skb
);
1203 schedule_delayed_work(&data
->rx_work
, data
->intr_interval
);
1208 static int btusb_recv_bulk(struct btusb_data
*data
, void *buffer
, int count
)
1210 struct sk_buff
*skb
;
1211 unsigned long flags
;
1214 spin_lock_irqsave(&data
->rxlock
, flags
);
1215 skb
= data
->acl_skb
;
1221 skb
= bt_skb_alloc(HCI_MAX_FRAME_SIZE
, GFP_ATOMIC
);
1227 hci_skb_pkt_type(skb
) = HCI_ACLDATA_PKT
;
1228 hci_skb_expect(skb
) = HCI_ACL_HDR_SIZE
;
1231 len
= min_t(uint
, hci_skb_expect(skb
), count
);
1232 skb_put_data(skb
, buffer
, len
);
1236 hci_skb_expect(skb
) -= len
;
1238 if (skb
->len
== HCI_ACL_HDR_SIZE
) {
1239 __le16 dlen
= hci_acl_hdr(skb
)->dlen
;
1241 /* Complete ACL header */
1242 hci_skb_expect(skb
) = __le16_to_cpu(dlen
);
1244 if (skb_tailroom(skb
) < hci_skb_expect(skb
)) {
1253 if (!hci_skb_expect(skb
)) {
1254 /* Complete frame */
1255 btusb_recv_acl(data
, skb
);
1260 data
->acl_skb
= skb
;
1261 spin_unlock_irqrestore(&data
->rxlock
, flags
);
1266 static bool btusb_validate_sco_handle(struct hci_dev
*hdev
,
1267 struct hci_sco_hdr
*hdr
)
1271 if (hci_dev_test_flag(hdev
, HCI_USER_CHANNEL
))
1272 // Can't validate, userspace controls everything.
1276 * USB isochronous transfers are not designed to be reliable and may
1277 * lose fragments. When this happens, the next first fragment
1278 * encountered might actually be a continuation fragment.
1279 * Validate the handle to detect it and drop it, or else the upper
1280 * layer will get garbage for a while.
1283 handle
= hci_handle(__le16_to_cpu(hdr
->handle
));
1285 switch (hci_conn_lookup_type(hdev
, handle
)) {
1294 static int btusb_recv_isoc(struct btusb_data
*data
, void *buffer
, int count
)
1296 struct sk_buff
*skb
;
1297 unsigned long flags
;
1300 spin_lock_irqsave(&data
->rxlock
, flags
);
1301 skb
= data
->sco_skb
;
1307 skb
= bt_skb_alloc(HCI_MAX_SCO_SIZE
, GFP_ATOMIC
);
1313 hci_skb_pkt_type(skb
) = HCI_SCODATA_PKT
;
1314 hci_skb_expect(skb
) = HCI_SCO_HDR_SIZE
;
1317 len
= min_t(uint
, hci_skb_expect(skb
), count
);
1318 skb_put_data(skb
, buffer
, len
);
1322 hci_skb_expect(skb
) -= len
;
1324 if (skb
->len
== HCI_SCO_HDR_SIZE
) {
1325 /* Complete SCO header */
1326 struct hci_sco_hdr
*hdr
= hci_sco_hdr(skb
);
1328 hci_skb_expect(skb
) = hdr
->dlen
;
1330 if (skb_tailroom(skb
) < hci_skb_expect(skb
) ||
1331 !btusb_validate_sco_handle(data
->hdev
, hdr
)) {
1340 if (!hci_skb_expect(skb
)) {
1341 /* Complete frame */
1342 hci_recv_frame(data
->hdev
, skb
);
1347 data
->sco_skb
= skb
;
1348 spin_unlock_irqrestore(&data
->rxlock
, flags
);
1353 static void btusb_intr_complete(struct urb
*urb
)
1355 struct hci_dev
*hdev
= urb
->context
;
1356 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1359 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
1360 urb
->actual_length
);
1362 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1365 if (urb
->status
== 0) {
1366 hdev
->stat
.byte_rx
+= urb
->actual_length
;
1368 if (btusb_recv_intr(data
, urb
->transfer_buffer
,
1369 urb
->actual_length
) < 0) {
1370 bt_dev_err(hdev
, "corrupted event packet");
1371 hdev
->stat
.err_rx
++;
1373 } else if (urb
->status
== -ENOENT
) {
1374 /* Avoid suspend failed when usb_kill_urb */
1378 if (!test_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
1381 usb_mark_last_busy(data
->udev
);
1382 usb_anchor_urb(urb
, &data
->intr_anchor
);
1384 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
1386 /* -EPERM: urb is being killed;
1387 * -ENODEV: device got disconnected
1389 if (err
!= -EPERM
&& err
!= -ENODEV
)
1390 bt_dev_err(hdev
, "urb %p failed to resubmit (%d)",
1393 hci_cmd_sync_cancel(hdev
, -err
);
1394 usb_unanchor_urb(urb
);
1398 static int btusb_submit_intr_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
1400 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1406 BT_DBG("%s", hdev
->name
);
1411 urb
= usb_alloc_urb(0, mem_flags
);
1415 if (le16_to_cpu(data
->udev
->descriptor
.idVendor
) == 0x0a12 &&
1416 le16_to_cpu(data
->udev
->descriptor
.idProduct
) == 0x0001)
1417 /* Fake CSR devices don't seem to support sort-transter */
1418 size
= le16_to_cpu(data
->intr_ep
->wMaxPacketSize
);
1420 /* Use maximum HCI Event size so the USB stack handles
1421 * ZPL/short-transfer automatically.
1423 size
= HCI_MAX_EVENT_SIZE
;
1425 buf
= kmalloc(size
, mem_flags
);
1431 pipe
= usb_rcvintpipe(data
->udev
, data
->intr_ep
->bEndpointAddress
);
1433 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
,
1434 btusb_intr_complete
, hdev
, data
->intr_ep
->bInterval
);
1436 urb
->transfer_flags
|= URB_FREE_BUFFER
;
1438 usb_anchor_urb(urb
, &data
->intr_anchor
);
1440 err
= usb_submit_urb(urb
, mem_flags
);
1442 if (err
!= -EPERM
&& err
!= -ENODEV
)
1443 bt_dev_err(hdev
, "urb %p submission failed (%d)",
1446 hci_cmd_sync_cancel(hdev
, -err
);
1447 usb_unanchor_urb(urb
);
1450 /* Only initialize intr_interval if URB poll sync is enabled */
1451 if (!data
->poll_sync
)
1454 /* The units are frames (milliseconds) for full and low speed devices,
1455 * and microframes (1/8 millisecond) for highspeed and SuperSpeed
1458 * This is done once on open/resume so it shouldn't change even if
1459 * force_poll_sync changes.
1461 switch (urb
->dev
->speed
) {
1462 case USB_SPEED_SUPER_PLUS
:
1463 case USB_SPEED_SUPER
: /* units are 125us */
1464 data
->intr_interval
= usecs_to_jiffies(urb
->interval
* 125);
1467 data
->intr_interval
= msecs_to_jiffies(urb
->interval
);
1477 static void btusb_bulk_complete(struct urb
*urb
)
1479 struct hci_dev
*hdev
= urb
->context
;
1480 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1483 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
1484 urb
->actual_length
);
1486 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1489 if (urb
->status
== 0) {
1490 hdev
->stat
.byte_rx
+= urb
->actual_length
;
1492 if (data
->recv_bulk(data
, urb
->transfer_buffer
,
1493 urb
->actual_length
) < 0) {
1494 bt_dev_err(hdev
, "corrupted ACL packet");
1495 hdev
->stat
.err_rx
++;
1497 } else if (urb
->status
== -ENOENT
) {
1498 /* Avoid suspend failed when usb_kill_urb */
1502 if (!test_bit(BTUSB_BULK_RUNNING
, &data
->flags
))
1505 usb_anchor_urb(urb
, &data
->bulk_anchor
);
1506 usb_mark_last_busy(data
->udev
);
1508 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
1510 /* -EPERM: urb is being killed;
1511 * -ENODEV: device got disconnected
1513 if (err
!= -EPERM
&& err
!= -ENODEV
)
1514 bt_dev_err(hdev
, "urb %p failed to resubmit (%d)",
1516 usb_unanchor_urb(urb
);
1520 static int btusb_submit_bulk_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
1522 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1526 int err
, size
= HCI_MAX_FRAME_SIZE
;
1528 BT_DBG("%s", hdev
->name
);
1530 if (!data
->bulk_rx_ep
)
1533 urb
= usb_alloc_urb(0, mem_flags
);
1537 buf
= kmalloc(size
, mem_flags
);
1543 pipe
= usb_rcvbulkpipe(data
->udev
, data
->bulk_rx_ep
->bEndpointAddress
);
1545 usb_fill_bulk_urb(urb
, data
->udev
, pipe
, buf
, size
,
1546 btusb_bulk_complete
, hdev
);
1548 urb
->transfer_flags
|= URB_FREE_BUFFER
;
1550 usb_mark_last_busy(data
->udev
);
1551 usb_anchor_urb(urb
, &data
->bulk_anchor
);
1553 err
= usb_submit_urb(urb
, mem_flags
);
1555 if (err
!= -EPERM
&& err
!= -ENODEV
)
1556 bt_dev_err(hdev
, "urb %p submission failed (%d)",
1558 usb_unanchor_urb(urb
);
1566 static void btusb_isoc_complete(struct urb
*urb
)
1568 struct hci_dev
*hdev
= urb
->context
;
1569 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1572 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
1573 urb
->actual_length
);
1575 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1578 if (urb
->status
== 0) {
1579 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
1580 unsigned int offset
= urb
->iso_frame_desc
[i
].offset
;
1581 unsigned int length
= urb
->iso_frame_desc
[i
].actual_length
;
1583 if (urb
->iso_frame_desc
[i
].status
)
1586 hdev
->stat
.byte_rx
+= length
;
1588 if (btusb_recv_isoc(data
, urb
->transfer_buffer
+ offset
,
1590 bt_dev_err(hdev
, "corrupted SCO packet");
1591 hdev
->stat
.err_rx
++;
1594 } else if (urb
->status
== -ENOENT
) {
1595 /* Avoid suspend failed when usb_kill_urb */
1599 if (!test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
1602 usb_anchor_urb(urb
, &data
->isoc_anchor
);
1604 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
1606 /* -EPERM: urb is being killed;
1607 * -ENODEV: device got disconnected
1609 if (err
!= -EPERM
&& err
!= -ENODEV
)
1610 bt_dev_err(hdev
, "urb %p failed to resubmit (%d)",
1612 usb_unanchor_urb(urb
);
1616 static inline void __fill_isoc_descriptor_msbc(struct urb
*urb
, int len
,
1617 int mtu
, struct btusb_data
*data
)
1619 int i
= 0, offset
= 0;
1620 unsigned int interval
;
1622 BT_DBG("len %d mtu %d", len
, mtu
);
1624 /* For mSBC ALT 6 settings some chips need to transmit the data
1625 * continuously without the zero length of USB packets.
1627 if (test_bit(BTUSB_ALT6_CONTINUOUS_TX
, &data
->flags
))
1628 goto ignore_usb_alt6_packet_flow
;
1630 /* For mSBC ALT 6 setting the host will send the packet at continuous
1631 * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting
1632 * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets.
1633 * To maintain the rate we send 63bytes of usb packets alternatively for
1634 * 7ms and 8ms to maintain the rate as 7.5ms.
1636 if (data
->usb_alt6_packet_flow
) {
1638 data
->usb_alt6_packet_flow
= false;
1641 data
->usb_alt6_packet_flow
= true;
1644 for (i
= 0; i
< interval
; i
++) {
1645 urb
->iso_frame_desc
[i
].offset
= offset
;
1646 urb
->iso_frame_desc
[i
].length
= offset
;
1649 ignore_usb_alt6_packet_flow
:
1650 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
1651 urb
->iso_frame_desc
[i
].offset
= offset
;
1652 urb
->iso_frame_desc
[i
].length
= len
;
1656 urb
->number_of_packets
= i
;
1659 static inline void __fill_isoc_descriptor(struct urb
*urb
, int len
, int mtu
)
1663 BT_DBG("len %d mtu %d", len
, mtu
);
1665 for (i
= 0; i
< BTUSB_MAX_ISOC_FRAMES
&& len
>= mtu
;
1666 i
++, offset
+= mtu
, len
-= mtu
) {
1667 urb
->iso_frame_desc
[i
].offset
= offset
;
1668 urb
->iso_frame_desc
[i
].length
= mtu
;
1671 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
1672 urb
->iso_frame_desc
[i
].offset
= offset
;
1673 urb
->iso_frame_desc
[i
].length
= len
;
1677 urb
->number_of_packets
= i
;
1680 static int btusb_submit_isoc_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
1682 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1688 BT_DBG("%s", hdev
->name
);
1690 if (!data
->isoc_rx_ep
)
1693 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, mem_flags
);
1697 size
= le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
) *
1698 BTUSB_MAX_ISOC_FRAMES
;
1700 buf
= kmalloc(size
, mem_flags
);
1706 pipe
= usb_rcvisocpipe(data
->udev
, data
->isoc_rx_ep
->bEndpointAddress
);
1708 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
, btusb_isoc_complete
,
1709 hdev
, data
->isoc_rx_ep
->bInterval
);
1711 urb
->transfer_flags
= URB_FREE_BUFFER
| URB_ISO_ASAP
;
1713 __fill_isoc_descriptor(urb
, size
,
1714 le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
));
1716 usb_anchor_urb(urb
, &data
->isoc_anchor
);
1718 err
= usb_submit_urb(urb
, mem_flags
);
1720 if (err
!= -EPERM
&& err
!= -ENODEV
)
1721 bt_dev_err(hdev
, "urb %p submission failed (%d)",
1723 usb_unanchor_urb(urb
);
1731 static void btusb_diag_complete(struct urb
*urb
)
1733 struct hci_dev
*hdev
= urb
->context
;
1734 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1737 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
1738 urb
->actual_length
);
1740 if (urb
->status
== 0) {
1741 struct sk_buff
*skb
;
1743 skb
= bt_skb_alloc(urb
->actual_length
, GFP_ATOMIC
);
1745 skb_put_data(skb
, urb
->transfer_buffer
,
1746 urb
->actual_length
);
1747 hci_recv_diag(hdev
, skb
);
1749 } else if (urb
->status
== -ENOENT
) {
1750 /* Avoid suspend failed when usb_kill_urb */
1754 if (!test_bit(BTUSB_DIAG_RUNNING
, &data
->flags
))
1757 usb_anchor_urb(urb
, &data
->diag_anchor
);
1758 usb_mark_last_busy(data
->udev
);
1760 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
1762 /* -EPERM: urb is being killed;
1763 * -ENODEV: device got disconnected
1765 if (err
!= -EPERM
&& err
!= -ENODEV
)
1766 bt_dev_err(hdev
, "urb %p failed to resubmit (%d)",
1768 usb_unanchor_urb(urb
);
1772 static int btusb_submit_diag_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
1774 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1778 int err
, size
= HCI_MAX_FRAME_SIZE
;
1780 BT_DBG("%s", hdev
->name
);
1782 if (!data
->diag_rx_ep
)
1785 urb
= usb_alloc_urb(0, mem_flags
);
1789 buf
= kmalloc(size
, mem_flags
);
1795 pipe
= usb_rcvbulkpipe(data
->udev
, data
->diag_rx_ep
->bEndpointAddress
);
1797 usb_fill_bulk_urb(urb
, data
->udev
, pipe
, buf
, size
,
1798 btusb_diag_complete
, hdev
);
1800 urb
->transfer_flags
|= URB_FREE_BUFFER
;
1802 usb_mark_last_busy(data
->udev
);
1803 usb_anchor_urb(urb
, &data
->diag_anchor
);
1805 err
= usb_submit_urb(urb
, mem_flags
);
1807 if (err
!= -EPERM
&& err
!= -ENODEV
)
1808 bt_dev_err(hdev
, "urb %p submission failed (%d)",
1810 usb_unanchor_urb(urb
);
1818 static void btusb_tx_complete(struct urb
*urb
)
1820 struct sk_buff
*skb
= urb
->context
;
1821 struct hci_dev
*hdev
= (struct hci_dev
*)skb
->dev
;
1822 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1823 unsigned long flags
;
1825 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
1826 urb
->actual_length
);
1828 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1832 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
1834 if (hci_skb_pkt_type(skb
) == HCI_COMMAND_PKT
)
1835 hci_cmd_sync_cancel(hdev
, -urb
->status
);
1836 hdev
->stat
.err_tx
++;
1840 spin_lock_irqsave(&data
->txlock
, flags
);
1841 data
->tx_in_flight
--;
1842 spin_unlock_irqrestore(&data
->txlock
, flags
);
1844 kfree(urb
->setup_packet
);
1849 static void btusb_isoc_tx_complete(struct urb
*urb
)
1851 struct sk_buff
*skb
= urb
->context
;
1852 struct hci_dev
*hdev
= (struct hci_dev
*)skb
->dev
;
1854 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
1855 urb
->actual_length
);
1857 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1861 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
1863 hdev
->stat
.err_tx
++;
1866 kfree(urb
->setup_packet
);
1871 static int btusb_open(struct hci_dev
*hdev
)
1873 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1876 BT_DBG("%s", hdev
->name
);
1878 err
= usb_autopm_get_interface(data
->intf
);
1882 /* Patching USB firmware files prior to starting any URBs of HCI path
1883 * It is more safe to use USB bulk channel for downloading USB patch
1885 if (data
->setup_on_usb
) {
1886 err
= data
->setup_on_usb(hdev
);
1891 data
->intf
->needs_remote_wakeup
= 1;
1893 if (test_and_set_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
1896 err
= btusb_submit_intr_urb(hdev
, GFP_KERNEL
);
1900 err
= btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
1902 usb_kill_anchored_urbs(&data
->intr_anchor
);
1906 set_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
1907 btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
1910 if (!btusb_submit_diag_urb(hdev
, GFP_KERNEL
))
1911 set_bit(BTUSB_DIAG_RUNNING
, &data
->flags
);
1915 usb_autopm_put_interface(data
->intf
);
1919 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
1921 usb_autopm_put_interface(data
->intf
);
1925 static void btusb_stop_traffic(struct btusb_data
*data
)
1927 usb_kill_anchored_urbs(&data
->intr_anchor
);
1928 usb_kill_anchored_urbs(&data
->bulk_anchor
);
1929 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1930 usb_kill_anchored_urbs(&data
->diag_anchor
);
1931 usb_kill_anchored_urbs(&data
->ctrl_anchor
);
1934 static int btusb_close(struct hci_dev
*hdev
)
1936 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1939 BT_DBG("%s", hdev
->name
);
1941 cancel_delayed_work(&data
->rx_work
);
1942 cancel_work_sync(&data
->work
);
1943 cancel_work_sync(&data
->waker
);
1945 skb_queue_purge(&data
->acl_q
);
1947 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1948 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
1949 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
1950 clear_bit(BTUSB_DIAG_RUNNING
, &data
->flags
);
1952 btusb_stop_traffic(data
);
1953 btusb_free_frags(data
);
1955 err
= usb_autopm_get_interface(data
->intf
);
1959 data
->intf
->needs_remote_wakeup
= 0;
1961 /* Enable remote wake up for auto-suspend */
1962 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND
, &data
->flags
))
1963 data
->intf
->needs_remote_wakeup
= 1;
1965 usb_autopm_put_interface(data
->intf
);
1968 usb_scuttle_anchored_urbs(&data
->deferred
);
1972 static int btusb_flush(struct hci_dev
*hdev
)
1974 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1976 BT_DBG("%s", hdev
->name
);
1978 cancel_delayed_work(&data
->rx_work
);
1980 skb_queue_purge(&data
->acl_q
);
1982 usb_kill_anchored_urbs(&data
->tx_anchor
);
1983 btusb_free_frags(data
);
1988 static struct urb
*alloc_ctrl_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1990 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1991 struct usb_ctrlrequest
*dr
;
1995 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1997 return ERR_PTR(-ENOMEM
);
1999 dr
= kmalloc(sizeof(*dr
), GFP_KERNEL
);
2002 return ERR_PTR(-ENOMEM
);
2005 dr
->bRequestType
= data
->cmdreq_type
;
2006 dr
->bRequest
= data
->cmdreq
;
2009 dr
->wLength
= __cpu_to_le16(skb
->len
);
2011 pipe
= usb_sndctrlpipe(data
->udev
, 0x00);
2013 usb_fill_control_urb(urb
, data
->udev
, pipe
, (void *)dr
,
2014 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
2016 skb
->dev
= (void *)hdev
;
2021 static struct urb
*alloc_bulk_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2023 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2027 if (!data
->bulk_tx_ep
)
2028 return ERR_PTR(-ENODEV
);
2030 urb
= usb_alloc_urb(0, GFP_KERNEL
);
2032 return ERR_PTR(-ENOMEM
);
2034 pipe
= usb_sndbulkpipe(data
->udev
, data
->bulk_tx_ep
->bEndpointAddress
);
2036 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
2037 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
2039 skb
->dev
= (void *)hdev
;
2044 static struct urb
*alloc_isoc_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2046 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2050 if (!data
->isoc_tx_ep
)
2051 return ERR_PTR(-ENODEV
);
2053 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_KERNEL
);
2055 return ERR_PTR(-ENOMEM
);
2057 pipe
= usb_sndisocpipe(data
->udev
, data
->isoc_tx_ep
->bEndpointAddress
);
2059 usb_fill_int_urb(urb
, data
->udev
, pipe
,
2060 skb
->data
, skb
->len
, btusb_isoc_tx_complete
,
2061 skb
, data
->isoc_tx_ep
->bInterval
);
2063 urb
->transfer_flags
= URB_ISO_ASAP
;
2065 if (data
->isoc_altsetting
== 6)
2066 __fill_isoc_descriptor_msbc(urb
, skb
->len
,
2067 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
),
2070 __fill_isoc_descriptor(urb
, skb
->len
,
2071 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
));
2072 skb
->dev
= (void *)hdev
;
2077 static int submit_tx_urb(struct hci_dev
*hdev
, struct urb
*urb
)
2079 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2082 usb_anchor_urb(urb
, &data
->tx_anchor
);
2084 err
= usb_submit_urb(urb
, GFP_KERNEL
);
2086 if (err
!= -EPERM
&& err
!= -ENODEV
)
2087 bt_dev_err(hdev
, "urb %p submission failed (%d)",
2089 kfree(urb
->setup_packet
);
2090 usb_unanchor_urb(urb
);
2092 usb_mark_last_busy(data
->udev
);
2099 static int submit_or_queue_tx_urb(struct hci_dev
*hdev
, struct urb
*urb
)
2101 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2102 unsigned long flags
;
2105 spin_lock_irqsave(&data
->txlock
, flags
);
2106 suspending
= test_bit(BTUSB_SUSPENDING
, &data
->flags
);
2108 data
->tx_in_flight
++;
2109 spin_unlock_irqrestore(&data
->txlock
, flags
);
2112 return submit_tx_urb(hdev
, urb
);
2114 usb_anchor_urb(urb
, &data
->deferred
);
2115 schedule_work(&data
->waker
);
2121 static int btusb_send_frame(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2125 BT_DBG("%s", hdev
->name
);
2127 switch (hci_skb_pkt_type(skb
)) {
2128 case HCI_COMMAND_PKT
:
2129 urb
= alloc_ctrl_urb(hdev
, skb
);
2131 return PTR_ERR(urb
);
2133 hdev
->stat
.cmd_tx
++;
2134 return submit_or_queue_tx_urb(hdev
, urb
);
2136 case HCI_ACLDATA_PKT
:
2137 urb
= alloc_bulk_urb(hdev
, skb
);
2139 return PTR_ERR(urb
);
2141 hdev
->stat
.acl_tx
++;
2142 return submit_or_queue_tx_urb(hdev
, urb
);
2144 case HCI_SCODATA_PKT
:
2145 if (!hci_dev_test_flag(hdev
, HCI_USER_CHANNEL
) &&
2146 hci_conn_num(hdev
, SCO_LINK
) < 1)
2149 urb
= alloc_isoc_urb(hdev
, skb
);
2151 return PTR_ERR(urb
);
2153 hdev
->stat
.sco_tx
++;
2154 return submit_tx_urb(hdev
, urb
);
2156 case HCI_ISODATA_PKT
:
2157 urb
= alloc_bulk_urb(hdev
, skb
);
2159 return PTR_ERR(urb
);
2161 return submit_or_queue_tx_urb(hdev
, urb
);
2167 static void btusb_notify(struct hci_dev
*hdev
, unsigned int evt
)
2169 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2171 BT_DBG("%s evt %d", hdev
->name
, evt
);
2173 if (hci_conn_num(hdev
, SCO_LINK
) != data
->sco_num
) {
2174 data
->sco_num
= hci_conn_num(hdev
, SCO_LINK
);
2175 data
->air_mode
= evt
;
2176 schedule_work(&data
->work
);
2180 static inline int __set_isoc_interface(struct hci_dev
*hdev
, int altsetting
)
2182 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2183 struct usb_interface
*intf
= data
->isoc
;
2184 struct usb_endpoint_descriptor
*ep_desc
;
2190 err
= usb_set_interface(data
->udev
, data
->isoc_ifnum
, altsetting
);
2192 bt_dev_err(hdev
, "setting interface failed (%d)", -err
);
2196 data
->isoc_altsetting
= altsetting
;
2198 data
->isoc_tx_ep
= NULL
;
2199 data
->isoc_rx_ep
= NULL
;
2201 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
2202 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
2204 if (!data
->isoc_tx_ep
&& usb_endpoint_is_isoc_out(ep_desc
)) {
2205 data
->isoc_tx_ep
= ep_desc
;
2209 if (!data
->isoc_rx_ep
&& usb_endpoint_is_isoc_in(ep_desc
)) {
2210 data
->isoc_rx_ep
= ep_desc
;
2215 if (!data
->isoc_tx_ep
|| !data
->isoc_rx_ep
) {
2216 bt_dev_err(hdev
, "invalid SCO descriptors");
2223 static int btusb_switch_alt_setting(struct hci_dev
*hdev
, int new_alts
)
2225 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2228 if (data
->isoc_altsetting
!= new_alts
) {
2229 unsigned long flags
;
2231 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
2232 usb_kill_anchored_urbs(&data
->isoc_anchor
);
2234 /* When isochronous alternate setting needs to be
2235 * changed, because SCO connection has been added
2236 * or removed, a packet fragment may be left in the
2237 * reassembling state. This could lead to wrongly
2238 * assembled fragments.
2240 * Clear outstanding fragment when selecting a new
2241 * alternate setting.
2243 spin_lock_irqsave(&data
->rxlock
, flags
);
2244 dev_kfree_skb_irq(data
->sco_skb
);
2245 data
->sco_skb
= NULL
;
2246 spin_unlock_irqrestore(&data
->rxlock
, flags
);
2248 err
= __set_isoc_interface(hdev
, new_alts
);
2253 if (!test_and_set_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
2254 if (btusb_submit_isoc_urb(hdev
, GFP_KERNEL
) < 0)
2255 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
2257 btusb_submit_isoc_urb(hdev
, GFP_KERNEL
);
2263 static struct usb_host_interface
*btusb_find_altsetting(struct btusb_data
*data
,
2266 struct usb_interface
*intf
= data
->isoc
;
2269 BT_DBG("Looking for Alt no :%d", alt
);
2274 for (i
= 0; i
< intf
->num_altsetting
; i
++) {
2275 if (intf
->altsetting
[i
].desc
.bAlternateSetting
== alt
)
2276 return &intf
->altsetting
[i
];
2282 static void btusb_work(struct work_struct
*work
)
2284 struct btusb_data
*data
= container_of(work
, struct btusb_data
, work
);
2285 struct hci_dev
*hdev
= data
->hdev
;
2289 if (data
->sco_num
> 0) {
2290 if (!test_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
)) {
2291 err
= usb_autopm_get_interface(data
->isoc
? data
->isoc
: data
->intf
);
2293 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
2294 usb_kill_anchored_urbs(&data
->isoc_anchor
);
2298 set_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
);
2301 if (data
->air_mode
== HCI_NOTIFY_ENABLE_SCO_CVSD
) {
2302 if (hdev
->voice_setting
& 0x0020) {
2303 static const int alts
[3] = { 2, 4, 5 };
2305 new_alts
= alts
[data
->sco_num
- 1];
2307 new_alts
= data
->sco_num
;
2309 } else if (data
->air_mode
== HCI_NOTIFY_ENABLE_SCO_TRANSP
) {
2310 /* Bluetooth USB spec recommends alt 6 (63 bytes), but
2311 * many adapters do not support it. Alt 1 appears to
2312 * work for all adapters that do not have alt 6, and
2313 * which work with WBS at all. Some devices prefer
2314 * alt 3 (HCI payload >= 60 Bytes let air packet
2315 * data satisfy 60 bytes), requiring
2316 * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
2317 * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
2319 if (btusb_find_altsetting(data
, 6))
2321 else if (btusb_find_altsetting(data
, 3) &&
2322 hdev
->sco_mtu
>= 72 &&
2323 test_bit(BTUSB_USE_ALT3_FOR_WBS
, &data
->flags
))
2329 if (btusb_switch_alt_setting(hdev
, new_alts
) < 0)
2330 bt_dev_err(hdev
, "set USB alt:(%d) failed!", new_alts
);
2332 usb_kill_anchored_urbs(&data
->isoc_anchor
);
2334 if (test_and_clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
2335 __set_isoc_interface(hdev
, 0);
2337 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
))
2338 usb_autopm_put_interface(data
->isoc
? data
->isoc
: data
->intf
);
2342 static void btusb_waker(struct work_struct
*work
)
2344 struct btusb_data
*data
= container_of(work
, struct btusb_data
, waker
);
2347 err
= usb_autopm_get_interface(data
->intf
);
2351 usb_autopm_put_interface(data
->intf
);
2354 static void btusb_rx_work(struct work_struct
*work
)
2356 struct btusb_data
*data
= container_of(work
, struct btusb_data
,
2358 struct sk_buff
*skb
;
2360 /* Dequeue ACL data received during the interval */
2361 while ((skb
= skb_dequeue(&data
->acl_q
)))
2362 data
->recv_acl(data
->hdev
, skb
);
2365 static int btusb_setup_bcm92035(struct hci_dev
*hdev
)
2367 struct sk_buff
*skb
;
2370 BT_DBG("%s", hdev
->name
);
2372 skb
= __hci_cmd_sync(hdev
, 0xfc3b, 1, &val
, HCI_INIT_TIMEOUT
);
2374 bt_dev_err(hdev
, "BCM92035 command failed (%ld)", PTR_ERR(skb
));
2381 static int btusb_setup_csr(struct hci_dev
*hdev
)
2383 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2384 u16 bcdDevice
= le16_to_cpu(data
->udev
->descriptor
.bcdDevice
);
2385 struct hci_rp_read_local_version
*rp
;
2386 struct sk_buff
*skb
;
2387 bool is_fake
= false;
2390 BT_DBG("%s", hdev
->name
);
2392 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
2395 int err
= PTR_ERR(skb
);
2396 bt_dev_err(hdev
, "CSR: Local version failed (%d)", err
);
2400 rp
= skb_pull_data(skb
, sizeof(*rp
));
2402 bt_dev_err(hdev
, "CSR: Local version length mismatch");
2407 bt_dev_info(hdev
, "CSR: Setting up dongle with HCI ver=%u rev=%04x",
2408 rp
->hci_ver
, le16_to_cpu(rp
->hci_rev
));
2410 bt_dev_info(hdev
, "LMP ver=%u subver=%04x; manufacturer=%u",
2411 rp
->lmp_ver
, le16_to_cpu(rp
->lmp_subver
),
2412 le16_to_cpu(rp
->manufacturer
));
2414 /* Detect a wide host of Chinese controllers that aren't CSR.
2416 * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891
2418 * The main thing they have in common is that these are really popular low-cost
2419 * options that support newer Bluetooth versions but rely on heavy VID/PID
2420 * squatting of this poor old Bluetooth 1.1 device. Even sold as such.
2422 * We detect actual CSR devices by checking that the HCI manufacturer code
2423 * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and
2424 * HCI rev values always match. As they both store the firmware number.
2426 if (le16_to_cpu(rp
->manufacturer
) != 10 ||
2427 le16_to_cpu(rp
->hci_rev
) != le16_to_cpu(rp
->lmp_subver
))
2430 /* Known legit CSR firmware build numbers and their supported BT versions:
2431 * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e
2432 * - 1.2 (0x2) -> 0x04d9, 0x0529
2433 * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c
2434 * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External)
2435 * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb
2437 * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that
2438 * support BT 1.1 only; so it's a dead giveaway when some
2439 * third-party BT 4.0 dongle reuses it.
2441 else if (le16_to_cpu(rp
->lmp_subver
) <= 0x034e &&
2442 rp
->hci_ver
> BLUETOOTH_VER_1_1
)
2445 else if (le16_to_cpu(rp
->lmp_subver
) <= 0x0529 &&
2446 rp
->hci_ver
> BLUETOOTH_VER_1_2
)
2449 else if (le16_to_cpu(rp
->lmp_subver
) <= 0x0c5c &&
2450 rp
->hci_ver
> BLUETOOTH_VER_2_0
)
2453 else if (le16_to_cpu(rp
->lmp_subver
) <= 0x1899 &&
2454 rp
->hci_ver
> BLUETOOTH_VER_2_1
)
2457 else if (le16_to_cpu(rp
->lmp_subver
) <= 0x22bb &&
2458 rp
->hci_ver
> BLUETOOTH_VER_4_0
)
2461 /* Other clones which beat all the above checks */
2462 else if (bcdDevice
== 0x0134 &&
2463 le16_to_cpu(rp
->lmp_subver
) == 0x0c5c &&
2464 rp
->hci_ver
== BLUETOOTH_VER_2_0
)
2468 bt_dev_warn(hdev
, "CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once...");
2470 /* Generally these clones have big discrepancies between
2471 * advertised features and what's actually supported.
2472 * Probably will need to be expanded in the future;
2473 * without these the controller will lock up.
2475 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY
, &hdev
->quirks
);
2476 set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING
, &hdev
->quirks
);
2477 set_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL
, &hdev
->quirks
);
2478 set_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER
, &hdev
->quirks
);
2479 set_bit(HCI_QUIRK_BROKEN_READ_VOICE_SETTING
, &hdev
->quirks
);
2480 set_bit(HCI_QUIRK_BROKEN_READ_PAGE_SCAN_TYPE
, &hdev
->quirks
);
2482 /* Clear the reset quirk since this is not an actual
2483 * early Bluetooth 1.1 device from CSR.
2485 clear_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2486 clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2489 * Special workaround for these BT 4.0 chip clones, and potentially more:
2491 * - 0x0134: a Barrot 8041a02 (HCI rev: 0x0810 sub: 0x1012)
2492 * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709)
2494 * These controllers are really messed-up.
2496 * 1. Their bulk RX endpoint will never report any data unless
2497 * the device was suspended at least once (yes, really).
2498 * 2. They will not wakeup when autosuspended and receiving data
2499 * on their bulk RX endpoint from e.g. a keyboard or mouse
2500 * (IOW remote-wakeup support is broken for the bulk endpoint).
2502 * To fix 1. enable runtime-suspend, force-suspend the
2503 * HCI and then wake-it up by disabling runtime-suspend.
2505 * To fix 2. clear the HCI's can_wake flag, this way the HCI
2506 * will still be autosuspended when it is not open.
2510 * Because these are widespread problems we prefer generic solutions; so
2511 * apply this initialization quirk to every controller that gets here,
2512 * it should be harmless. The alternative is to not work at all.
2514 pm_runtime_allow(&data
->udev
->dev
);
2516 ret
= pm_runtime_suspend(&data
->udev
->dev
);
2520 bt_dev_warn(hdev
, "CSR: Couldn't suspend the device for our Barrot 8041a02 receive-issue workaround");
2522 pm_runtime_forbid(&data
->udev
->dev
);
2524 device_set_wakeup_capable(&data
->udev
->dev
, false);
2526 /* Re-enable autosuspend if this was requested */
2527 if (enable_autosuspend
)
2528 usb_enable_autosuspend(data
->udev
);
2536 static int inject_cmd_complete(struct hci_dev
*hdev
, __u16 opcode
)
2538 struct sk_buff
*skb
;
2539 struct hci_event_hdr
*hdr
;
2540 struct hci_ev_cmd_complete
*evt
;
2542 skb
= bt_skb_alloc(sizeof(*hdr
) + sizeof(*evt
) + 1, GFP_KERNEL
);
2546 hdr
= skb_put(skb
, sizeof(*hdr
));
2547 hdr
->evt
= HCI_EV_CMD_COMPLETE
;
2548 hdr
->plen
= sizeof(*evt
) + 1;
2550 evt
= skb_put(skb
, sizeof(*evt
));
2552 evt
->opcode
= cpu_to_le16(opcode
);
2554 skb_put_u8(skb
, 0x00);
2556 hci_skb_pkt_type(skb
) = HCI_EVENT_PKT
;
2558 return hci_recv_frame(hdev
, skb
);
2561 static int btusb_recv_bulk_intel(struct btusb_data
*data
, void *buffer
,
2564 struct hci_dev
*hdev
= data
->hdev
;
2566 /* When the device is in bootloader mode, then it can send
2567 * events via the bulk endpoint. These events are treated the
2568 * same way as the ones received from the interrupt endpoint.
2570 if (btintel_test_flag(hdev
, INTEL_BOOTLOADER
))
2571 return btusb_recv_intr(data
, buffer
, count
);
2573 return btusb_recv_bulk(data
, buffer
, count
);
2576 static int btusb_send_frame_intel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2580 BT_DBG("%s", hdev
->name
);
2582 switch (hci_skb_pkt_type(skb
)) {
2583 case HCI_COMMAND_PKT
:
2584 if (btintel_test_flag(hdev
, INTEL_BOOTLOADER
)) {
2585 struct hci_command_hdr
*cmd
= (void *)skb
->data
;
2586 __u16 opcode
= le16_to_cpu(cmd
->opcode
);
2588 /* When in bootloader mode and the command 0xfc09
2589 * is received, it needs to be send down the
2590 * bulk endpoint. So allocate a bulk URB instead.
2592 if (opcode
== 0xfc09)
2593 urb
= alloc_bulk_urb(hdev
, skb
);
2595 urb
= alloc_ctrl_urb(hdev
, skb
);
2597 /* When the 0xfc01 command is issued to boot into
2598 * the operational firmware, it will actually not
2599 * send a command complete event. To keep the flow
2600 * control working inject that event here.
2602 if (opcode
== 0xfc01)
2603 inject_cmd_complete(hdev
, opcode
);
2605 urb
= alloc_ctrl_urb(hdev
, skb
);
2608 return PTR_ERR(urb
);
2610 hdev
->stat
.cmd_tx
++;
2611 return submit_or_queue_tx_urb(hdev
, urb
);
2613 case HCI_ACLDATA_PKT
:
2614 urb
= alloc_bulk_urb(hdev
, skb
);
2616 return PTR_ERR(urb
);
2618 hdev
->stat
.acl_tx
++;
2619 return submit_or_queue_tx_urb(hdev
, urb
);
2621 case HCI_SCODATA_PKT
:
2622 if (!hci_dev_test_flag(hdev
, HCI_USER_CHANNEL
) &&
2623 hci_conn_num(hdev
, SCO_LINK
) < 1)
2626 urb
= alloc_isoc_urb(hdev
, skb
);
2628 return PTR_ERR(urb
);
2630 hdev
->stat
.sco_tx
++;
2631 return submit_tx_urb(hdev
, urb
);
2633 case HCI_ISODATA_PKT
:
2634 urb
= alloc_bulk_urb(hdev
, skb
);
2636 return PTR_ERR(urb
);
2638 return submit_or_queue_tx_urb(hdev
, urb
);
2644 static int btusb_setup_realtek(struct hci_dev
*hdev
)
2646 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2649 ret
= btrtl_setup_realtek(hdev
);
2651 if (btrealtek_test_flag(data
->hdev
, REALTEK_ALT6_CONTINUOUS_TX_CHIP
))
2652 set_bit(BTUSB_ALT6_CONTINUOUS_TX
, &data
->flags
);
2657 static int btusb_recv_event_realtek(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2659 if (skb
->data
[0] == HCI_VENDOR_PKT
&& skb
->data
[2] == RTK_SUB_EVENT_CODE_COREDUMP
) {
2660 struct rtk_dev_coredump_hdr hdr
= {
2661 .code
= RTK_DEVCOREDUMP_CODE_MEMDUMP
,
2664 bt_dev_dbg(hdev
, "RTL: received coredump vendor evt, len %u",
2667 btusb_rtl_alloc_devcoredump(hdev
, &hdr
, skb
->data
, skb
->len
);
2673 return hci_recv_frame(hdev
, skb
);
2676 static void btusb_mtk_claim_iso_intf(struct btusb_data
*data
)
2678 struct btmtk_data
*btmtk_data
= hci_get_priv(data
->hdev
);
2682 * The function usb_driver_claim_interface() is documented to need
2683 * locks held if it's not called from a probe routine. The code here
2684 * is called from the hci_power_on workqueue, so grab the lock.
2686 device_lock(&btmtk_data
->isopkt_intf
->dev
);
2687 err
= usb_driver_claim_interface(&btusb_driver
,
2688 btmtk_data
->isopkt_intf
, data
);
2689 device_unlock(&btmtk_data
->isopkt_intf
->dev
);
2691 btmtk_data
->isopkt_intf
= NULL
;
2692 bt_dev_err(data
->hdev
, "Failed to claim iso interface: %d", err
);
2696 set_bit(BTMTK_ISOPKT_OVER_INTR
, &btmtk_data
->flags
);
2697 init_usb_anchor(&btmtk_data
->isopkt_anchor
);
2700 static void btusb_mtk_release_iso_intf(struct hci_dev
*hdev
)
2702 struct btmtk_data
*btmtk_data
= hci_get_priv(hdev
);
2704 if (test_bit(BTMTK_ISOPKT_OVER_INTR
, &btmtk_data
->flags
)) {
2705 usb_kill_anchored_urbs(&btmtk_data
->isopkt_anchor
);
2706 clear_bit(BTMTK_ISOPKT_RUNNING
, &btmtk_data
->flags
);
2708 dev_kfree_skb_irq(btmtk_data
->isopkt_skb
);
2709 btmtk_data
->isopkt_skb
= NULL
;
2710 usb_set_intfdata(btmtk_data
->isopkt_intf
, NULL
);
2711 usb_driver_release_interface(&btusb_driver
,
2712 btmtk_data
->isopkt_intf
);
2715 clear_bit(BTMTK_ISOPKT_OVER_INTR
, &btmtk_data
->flags
);
2718 static int btusb_mtk_disconnect(struct hci_dev
*hdev
)
2720 /* This function describes the specific additional steps taken by MediaTek
2721 * when Bluetooth usb driver's resume function is called.
2723 btusb_mtk_release_iso_intf(hdev
);
2728 static int btusb_mtk_reset(struct hci_dev
*hdev
, void *rst_data
)
2730 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2731 struct btmtk_data
*btmtk_data
= hci_get_priv(hdev
);
2734 /* It's MediaTek specific bluetooth reset mechanism via USB */
2735 if (test_and_set_bit(BTMTK_HW_RESET_ACTIVE
, &btmtk_data
->flags
)) {
2736 bt_dev_err(hdev
, "last reset failed? Not resetting again");
2740 err
= usb_autopm_get_interface(data
->intf
);
2744 /* Release MediaTek ISO data interface */
2745 btusb_mtk_release_iso_intf(hdev
);
2747 btusb_stop_traffic(data
);
2748 usb_kill_anchored_urbs(&data
->tx_anchor
);
2750 err
= btmtk_usb_subsys_reset(hdev
, btmtk_data
->dev_id
);
2752 usb_queue_reset_device(data
->intf
);
2753 clear_bit(BTMTK_HW_RESET_ACTIVE
, &btmtk_data
->flags
);
2758 static int btusb_send_frame_mtk(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2762 BT_DBG("%s", hdev
->name
);
2764 if (hci_skb_pkt_type(skb
) == HCI_ISODATA_PKT
) {
2765 urb
= alloc_mtk_intr_urb(hdev
, skb
, btusb_tx_complete
);
2767 return PTR_ERR(urb
);
2769 return submit_or_queue_tx_urb(hdev
, urb
);
2771 return btusb_send_frame(hdev
, skb
);
2775 static int btusb_mtk_setup(struct hci_dev
*hdev
)
2777 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2778 struct btmtk_data
*btmtk_data
= hci_get_priv(hdev
);
2780 /* MediaTek WMT vendor cmd requiring below USB resources to
2781 * complete the handshake.
2783 btmtk_data
->drv_name
= btusb_driver
.name
;
2784 btmtk_data
->intf
= data
->intf
;
2785 btmtk_data
->udev
= data
->udev
;
2786 btmtk_data
->ctrl_anchor
= &data
->ctrl_anchor
;
2787 btmtk_data
->reset_sync
= btusb_mtk_reset
;
2789 /* Claim ISO data interface and endpoint */
2790 if (!test_bit(BTMTK_ISOPKT_OVER_INTR
, &btmtk_data
->flags
)) {
2791 btmtk_data
->isopkt_intf
= usb_ifnum_to_if(data
->udev
, MTK_ISO_IFNUM
);
2792 btusb_mtk_claim_iso_intf(data
);
2795 return btmtk_usb_setup(hdev
);
2798 static int btusb_mtk_shutdown(struct hci_dev
*hdev
)
2802 ret
= btmtk_usb_shutdown(hdev
);
2804 /* Release MediaTek iso interface after shutdown */
2805 btusb_mtk_release_iso_intf(hdev
);
2811 /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */
2812 static int marvell_config_oob_wake(struct hci_dev
*hdev
)
2814 struct sk_buff
*skb
;
2815 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2816 struct device
*dev
= &data
->udev
->dev
;
2817 u16 pin
, gap
, opcode
;
2821 /* Move on if no wakeup pin specified */
2822 if (of_property_read_u16(dev
->of_node
, "marvell,wakeup-pin", &pin
) ||
2823 of_property_read_u16(dev
->of_node
, "marvell,wakeup-gap-ms", &gap
))
2826 /* Vendor specific command to configure a GPIO as wake-up pin */
2827 opcode
= hci_opcode_pack(0x3F, 0x59);
2828 cmd
[0] = opcode
& 0xFF;
2829 cmd
[1] = opcode
>> 8;
2830 cmd
[2] = 2; /* length of parameters that follow */
2832 cmd
[4] = gap
; /* time in ms, for which wakeup pin should be asserted */
2834 skb
= bt_skb_alloc(sizeof(cmd
), GFP_KERNEL
);
2836 bt_dev_err(hdev
, "%s: No memory", __func__
);
2840 skb_put_data(skb
, cmd
, sizeof(cmd
));
2841 hci_skb_pkt_type(skb
) = HCI_COMMAND_PKT
;
2843 ret
= btusb_send_frame(hdev
, skb
);
2845 bt_dev_err(hdev
, "%s: configuration failed", __func__
);
2854 static int btusb_set_bdaddr_marvell(struct hci_dev
*hdev
,
2855 const bdaddr_t
*bdaddr
)
2857 struct sk_buff
*skb
;
2862 buf
[1] = sizeof(bdaddr_t
);
2863 memcpy(buf
+ 2, bdaddr
, sizeof(bdaddr_t
));
2865 skb
= __hci_cmd_sync(hdev
, 0xfc22, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
2868 bt_dev_err(hdev
, "changing Marvell device address failed (%ld)",
2877 static int btusb_set_bdaddr_ath3012(struct hci_dev
*hdev
,
2878 const bdaddr_t
*bdaddr
)
2880 struct sk_buff
*skb
;
2887 buf
[3] = sizeof(bdaddr_t
);
2888 memcpy(buf
+ 4, bdaddr
, sizeof(bdaddr_t
));
2890 skb
= __hci_cmd_sync(hdev
, 0xfc0b, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
2893 bt_dev_err(hdev
, "Change address command failed (%ld)", ret
);
2901 static int btusb_set_bdaddr_wcn6855(struct hci_dev
*hdev
,
2902 const bdaddr_t
*bdaddr
)
2904 struct sk_buff
*skb
;
2908 memcpy(buf
, bdaddr
, sizeof(bdaddr_t
));
2910 skb
= __hci_cmd_sync_ev(hdev
, 0xfc14, sizeof(buf
), buf
,
2911 HCI_EV_CMD_COMPLETE
, HCI_INIT_TIMEOUT
);
2914 bt_dev_err(hdev
, "Change address command failed (%ld)", ret
);
2922 #define QCA_MEMDUMP_ACL_HANDLE 0x2EDD
2923 #define QCA_MEMDUMP_SIZE_MAX 0x100000
2924 #define QCA_MEMDUMP_VSE_CLASS 0x01
2925 #define QCA_MEMDUMP_MSG_TYPE 0x08
2926 #define QCA_MEMDUMP_PKT_SIZE 248
2927 #define QCA_LAST_SEQUENCE_NUM 0xffff
2929 struct qca_dump_hdr
{
2937 __le32 ram_dump_size
;
2944 static void btusb_dump_hdr_qca(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2947 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
2949 snprintf(buf
, sizeof(buf
), "Controller Name: 0x%x\n",
2950 btdata
->qca_dump
.controller_id
);
2951 skb_put_data(skb
, buf
, strlen(buf
));
2953 snprintf(buf
, sizeof(buf
), "Firmware Version: 0x%x\n",
2954 btdata
->qca_dump
.fw_version
);
2955 skb_put_data(skb
, buf
, strlen(buf
));
2957 snprintf(buf
, sizeof(buf
), "Driver: %s\nVendor: qca\n",
2959 skb_put_data(skb
, buf
, strlen(buf
));
2961 snprintf(buf
, sizeof(buf
), "VID: 0x%x\nPID:0x%x\n",
2962 btdata
->qca_dump
.id_vendor
, btdata
->qca_dump
.id_product
);
2963 skb_put_data(skb
, buf
, strlen(buf
));
2965 snprintf(buf
, sizeof(buf
), "Lmp Subversion: 0x%x\n",
2967 skb_put_data(skb
, buf
, strlen(buf
));
2970 static void btusb_coredump_qca(struct hci_dev
*hdev
)
2973 static const u8 param
[] = { 0x26 };
2975 err
= __hci_cmd_send(hdev
, 0xfc0c, 1, param
);
2977 bt_dev_err(hdev
, "%s: triggle crash failed (%d)", __func__
, err
);
2980 /* Return: 0 on success, negative errno on failure. */
2981 static int handle_dump_pkt_qca(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2984 unsigned int skip
= 0;
2989 struct qca_dump_hdr
*dump_hdr
;
2990 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
2991 struct usb_device
*udev
= btdata
->udev
;
2993 pkt_type
= hci_skb_pkt_type(skb
);
2994 skip
= sizeof(struct hci_event_hdr
);
2995 if (pkt_type
== HCI_ACLDATA_PKT
)
2996 skip
+= sizeof(struct hci_acl_hdr
);
2998 skb_pull(skb
, skip
);
2999 dump_hdr
= (struct qca_dump_hdr
*)skb
->data
;
3001 seqno
= le16_to_cpu(dump_hdr
->seqno
);
3003 set_bit(BTUSB_HW_SSR_ACTIVE
, &btdata
->flags
);
3004 dump_size
= le32_to_cpu(dump_hdr
->ram_dump_size
);
3005 if (!dump_size
|| (dump_size
> QCA_MEMDUMP_SIZE_MAX
)) {
3007 bt_dev_err(hdev
, "Invalid memdump size(%u)",
3012 ret
= hci_devcd_init(hdev
, dump_size
);
3014 bt_dev_err(hdev
, "memdump init error(%d)", ret
);
3018 btdata
->qca_dump
.ram_dump_size
= dump_size
;
3019 btdata
->qca_dump
.ram_dump_seqno
= 0;
3021 skb_pull(skb
, offsetof(struct qca_dump_hdr
, data0
));
3023 usb_disable_autosuspend(udev
);
3024 bt_dev_info(hdev
, "%s memdump size(%u)\n",
3025 (pkt_type
== HCI_ACLDATA_PKT
) ? "ACL" : "event",
3028 skb_pull(skb
, offsetof(struct qca_dump_hdr
, data
));
3031 if (!btdata
->qca_dump
.ram_dump_size
) {
3033 bt_dev_err(hdev
, "memdump is not active");
3037 if ((seqno
> btdata
->qca_dump
.ram_dump_seqno
+ 1) && (seqno
!= QCA_LAST_SEQUENCE_NUM
)) {
3038 dump_size
= QCA_MEMDUMP_PKT_SIZE
* (seqno
- btdata
->qca_dump
.ram_dump_seqno
- 1);
3039 hci_devcd_append_pattern(hdev
, 0x0, dump_size
);
3041 "expected memdump seqno(%u) is not received(%u)\n",
3042 btdata
->qca_dump
.ram_dump_seqno
, seqno
);
3043 btdata
->qca_dump
.ram_dump_seqno
= seqno
;
3048 hci_devcd_append(hdev
, skb
);
3049 btdata
->qca_dump
.ram_dump_seqno
++;
3050 if (seqno
== QCA_LAST_SEQUENCE_NUM
) {
3052 "memdump done: pkts(%u), total(%u)\n",
3053 btdata
->qca_dump
.ram_dump_seqno
, btdata
->qca_dump
.ram_dump_size
);
3055 hci_devcd_complete(hdev
);
3061 if (btdata
->qca_dump
.ram_dump_size
)
3062 usb_enable_autosuspend(udev
);
3063 btdata
->qca_dump
.ram_dump_size
= 0;
3064 btdata
->qca_dump
.ram_dump_seqno
= 0;
3065 clear_bit(BTUSB_HW_SSR_ACTIVE
, &btdata
->flags
);
3072 /* Return: true if the ACL packet is a dump packet, false otherwise. */
3073 static bool acl_pkt_is_dump_qca(struct hci_dev
*hdev
, struct sk_buff
*skb
)
3075 struct hci_event_hdr
*event_hdr
;
3076 struct hci_acl_hdr
*acl_hdr
;
3077 struct qca_dump_hdr
*dump_hdr
;
3078 struct sk_buff
*clone
= skb_clone(skb
, GFP_ATOMIC
);
3079 bool is_dump
= false;
3084 acl_hdr
= skb_pull_data(clone
, sizeof(*acl_hdr
));
3085 if (!acl_hdr
|| (le16_to_cpu(acl_hdr
->handle
) != QCA_MEMDUMP_ACL_HANDLE
))
3088 event_hdr
= skb_pull_data(clone
, sizeof(*event_hdr
));
3089 if (!event_hdr
|| (event_hdr
->evt
!= HCI_VENDOR_PKT
))
3092 dump_hdr
= skb_pull_data(clone
, sizeof(*dump_hdr
));
3093 if (!dump_hdr
|| (dump_hdr
->vse_class
!= QCA_MEMDUMP_VSE_CLASS
) ||
3094 (dump_hdr
->msg_type
!= QCA_MEMDUMP_MSG_TYPE
))
3103 /* Return: true if the event packet is a dump packet, false otherwise. */
3104 static bool evt_pkt_is_dump_qca(struct hci_dev
*hdev
, struct sk_buff
*skb
)
3106 struct hci_event_hdr
*event_hdr
;
3107 struct qca_dump_hdr
*dump_hdr
;
3108 struct sk_buff
*clone
= skb_clone(skb
, GFP_ATOMIC
);
3109 bool is_dump
= false;
3114 event_hdr
= skb_pull_data(clone
, sizeof(*event_hdr
));
3115 if (!event_hdr
|| (event_hdr
->evt
!= HCI_VENDOR_PKT
))
3118 dump_hdr
= skb_pull_data(clone
, sizeof(*dump_hdr
));
3119 if (!dump_hdr
|| (dump_hdr
->vse_class
!= QCA_MEMDUMP_VSE_CLASS
) ||
3120 (dump_hdr
->msg_type
!= QCA_MEMDUMP_MSG_TYPE
))
3129 static int btusb_recv_acl_qca(struct hci_dev
*hdev
, struct sk_buff
*skb
)
3131 if (acl_pkt_is_dump_qca(hdev
, skb
))
3132 return handle_dump_pkt_qca(hdev
, skb
);
3133 return hci_recv_frame(hdev
, skb
);
3136 static int btusb_recv_evt_qca(struct hci_dev
*hdev
, struct sk_buff
*skb
)
3138 if (evt_pkt_is_dump_qca(hdev
, skb
))
3139 return handle_dump_pkt_qca(hdev
, skb
);
3140 return hci_recv_frame(hdev
, skb
);
3144 #define QCA_DFU_PACKET_LEN 4096
3146 #define QCA_GET_TARGET_VERSION 0x09
3147 #define QCA_CHECK_STATUS 0x05
3148 #define QCA_DFU_DOWNLOAD 0x01
3150 #define QCA_SYSCFG_UPDATED 0x40
3151 #define QCA_PATCH_UPDATED 0x80
3152 #define QCA_DFU_TIMEOUT 3000
3153 #define QCA_FLAG_MULTI_NVM 0x80
3154 #define QCA_BT_RESET_WAIT_MS 100
3156 #define WCN6855_2_0_RAM_VERSION_GF 0x400c1200
3157 #define WCN6855_2_1_RAM_VERSION_GF 0x400c1211
3159 struct qca_version
{
3161 __le32 patch_version
;
3169 struct qca_rampatch_version
{
3170 __le16 rom_version_high
;
3171 __le16 rom_version_low
;
3172 __le16 patch_version
;
3175 struct qca_device_info
{
3177 u8 rampatch_hdr
; /* length of header in rampatch */
3178 u8 nvm_hdr
; /* length of header in NVM */
3179 u8 ver_offset
; /* offset of version structure in rampatch */
3182 static const struct qca_device_info qca_devices_table
[] = {
3183 { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */
3184 { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */
3185 { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */
3186 { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */
3187 { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */
3188 { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */
3189 { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */
3190 { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */
3191 { 0x00130201, 40, 4, 16 }, /* WCN6855 2.1 */
3192 { 0x00190200, 40, 4, 16 }, /* WCN785x 2.0 */
3195 static int btusb_qca_send_vendor_req(struct usb_device
*udev
, u8 request
,
3196 void *data
, u16 size
)
3201 buf
= kmalloc(size
, GFP_KERNEL
);
3205 /* Found some of USB hosts have IOT issues with ours so that we should
3206 * not wait until HCI layer is ready.
3208 pipe
= usb_rcvctrlpipe(udev
, 0);
3209 err
= usb_control_msg(udev
, pipe
, request
, USB_TYPE_VENDOR
| USB_DIR_IN
,
3210 0, 0, buf
, size
, USB_CTRL_GET_TIMEOUT
);
3212 dev_err(&udev
->dev
, "Failed to access otp area (%d)", err
);
3216 memcpy(data
, buf
, size
);
3224 static int btusb_setup_qca_download_fw(struct hci_dev
*hdev
,
3225 const struct firmware
*firmware
,
3228 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
3229 struct usb_device
*udev
= btdata
->udev
;
3230 size_t count
, size
, sent
= 0;
3234 buf
= kmalloc(QCA_DFU_PACKET_LEN
, GFP_KERNEL
);
3238 count
= firmware
->size
;
3240 size
= min_t(size_t, count
, hdr_size
);
3241 memcpy(buf
, firmware
->data
, size
);
3243 /* USB patches should go down to controller through USB path
3244 * because binary format fits to go down through USB channel.
3245 * USB control path is for patching headers and USB bulk is for
3248 pipe
= usb_sndctrlpipe(udev
, 0);
3249 err
= usb_control_msg(udev
, pipe
, QCA_DFU_DOWNLOAD
, USB_TYPE_VENDOR
,
3250 0, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
3252 bt_dev_err(hdev
, "Failed to send headers (%d)", err
);
3259 /* ep2 need time to switch from function acl to function dfu,
3260 * so we add 20ms delay here.
3265 size
= min_t(size_t, count
, QCA_DFU_PACKET_LEN
);
3267 memcpy(buf
, firmware
->data
+ sent
, size
);
3269 pipe
= usb_sndbulkpipe(udev
, 0x02);
3270 err
= usb_bulk_msg(udev
, pipe
, buf
, size
, &len
,
3273 bt_dev_err(hdev
, "Failed to send body at %zd of %zd (%d)",
3274 sent
, firmware
->size
, err
);
3279 bt_dev_err(hdev
, "Failed to get bulk buffer");
3293 static int btusb_setup_qca_load_rampatch(struct hci_dev
*hdev
,
3294 struct qca_version
*ver
,
3295 const struct qca_device_info
*info
)
3297 struct qca_rampatch_version
*rver
;
3298 const struct firmware
*fw
;
3299 u32 ver_rom
, ver_patch
, rver_rom
;
3300 u16 rver_rom_low
, rver_rom_high
, rver_patch
;
3304 ver_rom
= le32_to_cpu(ver
->rom_version
);
3305 ver_patch
= le32_to_cpu(ver
->patch_version
);
3307 snprintf(fwname
, sizeof(fwname
), "qca/rampatch_usb_%08x.bin", ver_rom
);
3309 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
3311 bt_dev_err(hdev
, "failed to request rampatch file: %s (%d)",
3316 bt_dev_info(hdev
, "using rampatch file: %s", fwname
);
3318 rver
= (struct qca_rampatch_version
*)(fw
->data
+ info
->ver_offset
);
3319 rver_rom_low
= le16_to_cpu(rver
->rom_version_low
);
3320 rver_patch
= le16_to_cpu(rver
->patch_version
);
3322 if (ver_rom
& ~0xffffU
) {
3323 rver_rom_high
= le16_to_cpu(rver
->rom_version_high
);
3324 rver_rom
= rver_rom_high
<< 16 | rver_rom_low
;
3326 rver_rom
= rver_rom_low
;
3329 bt_dev_info(hdev
, "QCA: patch rome 0x%x build 0x%x, "
3330 "firmware rome 0x%x build 0x%x",
3331 rver_rom
, rver_patch
, ver_rom
, ver_patch
);
3333 if (rver_rom
!= ver_rom
|| rver_patch
<= ver_patch
) {
3334 bt_dev_err(hdev
, "rampatch file version did not match with firmware");
3339 err
= btusb_setup_qca_download_fw(hdev
, fw
, info
->rampatch_hdr
);
3342 release_firmware(fw
);
3347 static void btusb_generate_qca_nvm_name(char *fwname
, size_t max_size
,
3348 const struct qca_version
*ver
)
3350 u32 rom_version
= le32_to_cpu(ver
->rom_version
);
3351 u16 flag
= le16_to_cpu(ver
->flag
);
3353 if (((flag
>> 8) & 0xff) == QCA_FLAG_MULTI_NVM
) {
3354 /* The board_id should be split into two bytes
3355 * The 1st byte is chip ID, and the 2nd byte is platform ID
3356 * For example, board ID 0x010A, 0x01 is platform ID. 0x0A is chip ID
3357 * we have several platforms, and platform IDs are continuously added
3359 * 0x00 is for Mobile
3361 * 0x02 is for Automotive
3362 * 0x03 is for Consumer electronic
3364 u16 board_id
= (ver
->chip_id
<< 8) + ver
->platform_id
;
3365 const char *variant
;
3367 switch (le32_to_cpu(ver
->ram_version
)) {
3368 case WCN6855_2_0_RAM_VERSION_GF
:
3369 case WCN6855_2_1_RAM_VERSION_GF
:
3377 if (board_id
== 0) {
3378 snprintf(fwname
, max_size
, "qca/nvm_usb_%08x%s.bin",
3379 rom_version
, variant
);
3381 snprintf(fwname
, max_size
, "qca/nvm_usb_%08x%s_%04x.bin",
3382 rom_version
, variant
, board_id
);
3385 snprintf(fwname
, max_size
, "qca/nvm_usb_%08x.bin",
3391 static int btusb_setup_qca_load_nvm(struct hci_dev
*hdev
,
3392 struct qca_version
*ver
,
3393 const struct qca_device_info
*info
)
3395 const struct firmware
*fw
;
3399 btusb_generate_qca_nvm_name(fwname
, sizeof(fwname
), ver
);
3401 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
3403 bt_dev_err(hdev
, "failed to request NVM file: %s (%d)",
3408 bt_dev_info(hdev
, "using NVM file: %s", fwname
);
3410 err
= btusb_setup_qca_download_fw(hdev
, fw
, info
->nvm_hdr
);
3412 release_firmware(fw
);
3417 /* identify the ROM version and check whether patches are needed */
3418 static bool btusb_qca_need_patch(struct usb_device
*udev
)
3420 struct qca_version ver
;
3422 if (btusb_qca_send_vendor_req(udev
, QCA_GET_TARGET_VERSION
, &ver
,
3425 /* only low ROM versions need patches */
3426 return !(le32_to_cpu(ver
.rom_version
) & ~0xffffU
);
3429 static int btusb_setup_qca(struct hci_dev
*hdev
)
3431 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
3432 struct usb_device
*udev
= btdata
->udev
;
3433 const struct qca_device_info
*info
= NULL
;
3434 struct qca_version ver
;
3439 err
= btusb_qca_send_vendor_req(udev
, QCA_GET_TARGET_VERSION
, &ver
,
3444 ver_rom
= le32_to_cpu(ver
.rom_version
);
3446 for (i
= 0; i
< ARRAY_SIZE(qca_devices_table
); i
++) {
3447 if (ver_rom
== qca_devices_table
[i
].rom_version
)
3448 info
= &qca_devices_table
[i
];
3451 /* If the rom_version is not matched in the qca_devices_table
3452 * and the high ROM version is not zero, we assume this chip no
3453 * need to load the rampatch and nvm.
3455 if (ver_rom
& ~0xffffU
)
3458 bt_dev_err(hdev
, "don't support firmware rome 0x%x", ver_rom
);
3462 err
= btusb_qca_send_vendor_req(udev
, QCA_CHECK_STATUS
, &status
,
3467 if (!(status
& QCA_PATCH_UPDATED
)) {
3468 err
= btusb_setup_qca_load_rampatch(hdev
, &ver
, info
);
3473 err
= btusb_qca_send_vendor_req(udev
, QCA_GET_TARGET_VERSION
, &ver
,
3478 btdata
->qca_dump
.fw_version
= le32_to_cpu(ver
.patch_version
);
3479 btdata
->qca_dump
.controller_id
= le32_to_cpu(ver
.rom_version
);
3481 if (!(status
& QCA_SYSCFG_UPDATED
)) {
3482 err
= btusb_setup_qca_load_nvm(hdev
, &ver
, info
);
3486 /* WCN6855 2.1 and later will reset to apply firmware downloaded here, so
3487 * wait ~100ms for reset Done then go ahead, otherwise, it maybe
3488 * cause potential enable failure.
3490 if (info
->rom_version
>= 0x00130201)
3491 msleep(QCA_BT_RESET_WAIT_MS
);
3494 /* Mark HCI_OP_ENHANCED_SETUP_SYNC_CONN as broken as it doesn't seem to
3495 * work with the likes of HSP/HFP mSBC.
3497 set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN
, &hdev
->quirks
);
3502 static inline int __set_diag_interface(struct hci_dev
*hdev
)
3504 struct btusb_data
*data
= hci_get_drvdata(hdev
);
3505 struct usb_interface
*intf
= data
->diag
;
3511 data
->diag_tx_ep
= NULL
;
3512 data
->diag_rx_ep
= NULL
;
3514 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
3515 struct usb_endpoint_descriptor
*ep_desc
;
3517 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
3519 if (!data
->diag_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
3520 data
->diag_tx_ep
= ep_desc
;
3524 if (!data
->diag_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
3525 data
->diag_rx_ep
= ep_desc
;
3530 if (!data
->diag_tx_ep
|| !data
->diag_rx_ep
) {
3531 bt_dev_err(hdev
, "invalid diagnostic descriptors");
3538 static struct urb
*alloc_diag_urb(struct hci_dev
*hdev
, bool enable
)
3540 struct btusb_data
*data
= hci_get_drvdata(hdev
);
3541 struct sk_buff
*skb
;
3545 if (!data
->diag_tx_ep
)
3546 return ERR_PTR(-ENODEV
);
3548 urb
= usb_alloc_urb(0, GFP_KERNEL
);
3550 return ERR_PTR(-ENOMEM
);
3552 skb
= bt_skb_alloc(2, GFP_KERNEL
);
3555 return ERR_PTR(-ENOMEM
);
3558 skb_put_u8(skb
, 0xf0);
3559 skb_put_u8(skb
, enable
);
3561 pipe
= usb_sndbulkpipe(data
->udev
, data
->diag_tx_ep
->bEndpointAddress
);
3563 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
3564 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
3566 skb
->dev
= (void *)hdev
;
3571 static int btusb_bcm_set_diag(struct hci_dev
*hdev
, bool enable
)
3573 struct btusb_data
*data
= hci_get_drvdata(hdev
);
3579 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
3582 urb
= alloc_diag_urb(hdev
, enable
);
3584 return PTR_ERR(urb
);
3586 return submit_or_queue_tx_urb(hdev
, urb
);
3590 static irqreturn_t
btusb_oob_wake_handler(int irq
, void *priv
)
3592 struct btusb_data
*data
= priv
;
3594 pm_wakeup_event(&data
->udev
->dev
, 0);
3597 /* Disable only if not already disabled (keep it balanced) */
3598 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED
, &data
->flags
)) {
3599 disable_irq_nosync(irq
);
3600 disable_irq_wake(irq
);
3605 static const struct of_device_id btusb_match_table
[] = {
3606 { .compatible
= "usb1286,204e" },
3607 { .compatible
= "usbcf3,e300" }, /* QCA6174A */
3608 { .compatible
= "usb4ca,301a" }, /* QCA6174A (Lite-On) */
3611 MODULE_DEVICE_TABLE(of
, btusb_match_table
);
3613 /* Use an oob wakeup pin? */
3614 static int btusb_config_oob_wake(struct hci_dev
*hdev
)
3616 struct btusb_data
*data
= hci_get_drvdata(hdev
);
3617 struct device
*dev
= &data
->udev
->dev
;
3620 clear_bit(BTUSB_OOB_WAKE_ENABLED
, &data
->flags
);
3622 if (!of_match_device(btusb_match_table
, dev
))
3625 /* Move on if no IRQ specified */
3626 irq
= of_irq_get_byname(dev
->of_node
, "wakeup");
3628 bt_dev_dbg(hdev
, "%s: no OOB Wakeup IRQ in DT", __func__
);
3632 irq_set_status_flags(irq
, IRQ_NOAUTOEN
);
3633 ret
= devm_request_irq(&hdev
->dev
, irq
, btusb_oob_wake_handler
,
3634 0, "OOB Wake-on-BT", data
);
3636 bt_dev_err(hdev
, "%s: IRQ request failed", __func__
);
3640 ret
= device_init_wakeup(dev
, true);
3642 bt_dev_err(hdev
, "%s: failed to init_wakeup", __func__
);
3646 data
->oob_wake_irq
= irq
;
3647 bt_dev_info(hdev
, "OOB Wake-on-BT configured at IRQ %u", irq
);
3652 static void btusb_check_needs_reset_resume(struct usb_interface
*intf
)
3654 if (dmi_check_system(btusb_needs_reset_resume_table
))
3655 interface_to_usbdev(intf
)->quirks
|= USB_QUIRK_RESET_RESUME
;
3658 static bool btusb_wakeup(struct hci_dev
*hdev
)
3660 struct btusb_data
*data
= hci_get_drvdata(hdev
);
3662 return device_may_wakeup(&data
->udev
->dev
);
3665 static int btusb_shutdown_qca(struct hci_dev
*hdev
)
3667 struct sk_buff
*skb
;
3669 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
3671 bt_dev_err(hdev
, "HCI reset during shutdown failed");
3672 return PTR_ERR(skb
);
3679 static ssize_t
force_poll_sync_read(struct file
*file
, char __user
*user_buf
,
3680 size_t count
, loff_t
*ppos
)
3682 struct btusb_data
*data
= file
->private_data
;
3685 buf
[0] = data
->poll_sync
? 'Y' : 'N';
3688 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, 2);
3691 static ssize_t
force_poll_sync_write(struct file
*file
,
3692 const char __user
*user_buf
,
3693 size_t count
, loff_t
*ppos
)
3695 struct btusb_data
*data
= file
->private_data
;
3699 err
= kstrtobool_from_user(user_buf
, count
, &enable
);
3703 /* Only allow changes while the adapter is down */
3704 if (test_bit(HCI_UP
, &data
->hdev
->flags
))
3707 if (data
->poll_sync
== enable
)
3710 data
->poll_sync
= enable
;
3715 static const struct file_operations force_poll_sync_fops
= {
3716 .owner
= THIS_MODULE
,
3717 .open
= simple_open
,
3718 .read
= force_poll_sync_read
,
3719 .write
= force_poll_sync_write
,
3720 .llseek
= default_llseek
,
3723 #define BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS \
3724 hci_opcode_pack(HCI_DRV_OGF_DRIVER_SPECIFIC, 0x0000)
3725 #define BTUSB_HCI_DRV_SUPPORTED_ALTSETTINGS_SIZE 0
3726 struct btusb_hci_drv_rp_supported_altsettings
{
3731 #define BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING \
3732 hci_opcode_pack(HCI_DRV_OGF_DRIVER_SPECIFIC, 0x0001)
3733 #define BTUSB_HCI_DRV_SWITCH_ALTSETTING_SIZE 1
3734 struct btusb_hci_drv_cmd_switch_altsetting
{
3738 static const struct {
3741 } btusb_hci_drv_supported_commands
[] = {
3742 /* Common commands */
3743 { HCI_DRV_OP_READ_INFO
, "Read Info" },
3745 /* Driver specific commands */
3746 { BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS
, "Supported Altsettings" },
3747 { BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING
, "Switch Altsetting" },
3749 static int btusb_hci_drv_read_info(struct hci_dev
*hdev
, void *data
,
3752 struct hci_drv_rp_read_info
*rp
;
3755 u16 opcode
, num_supported_commands
=
3756 ARRAY_SIZE(btusb_hci_drv_supported_commands
);
3758 rp_size
= sizeof(*rp
) + num_supported_commands
* 2;
3760 rp
= kmalloc(rp_size
, GFP_KERNEL
);
3764 strscpy_pad(rp
->driver_name
, btusb_driver
.name
);
3766 rp
->num_supported_commands
= cpu_to_le16(num_supported_commands
);
3767 for (i
= 0; i
< num_supported_commands
; i
++) {
3768 opcode
= btusb_hci_drv_supported_commands
[i
].opcode
;
3770 "Supported HCI Drv command (0x%02x|0x%04x): %s",
3771 hci_opcode_ogf(opcode
),
3772 hci_opcode_ocf(opcode
),
3773 btusb_hci_drv_supported_commands
[i
].desc
);
3774 rp
->supported_commands
[i
] = cpu_to_le16(opcode
);
3777 err
= hci_drv_cmd_complete(hdev
, HCI_DRV_OP_READ_INFO
,
3778 HCI_DRV_STATUS_SUCCESS
, rp
, rp_size
);
3784 static int btusb_hci_drv_supported_altsettings(struct hci_dev
*hdev
, void *data
,
3787 struct btusb_data
*drvdata
= hci_get_drvdata(hdev
);
3788 struct btusb_hci_drv_rp_supported_altsettings
*rp
;
3793 /* There are at most 7 alt (0 - 6) */
3794 rp
= kmalloc(sizeof(*rp
) + 7, GFP_KERNEL
);
3800 for (i
= 0; i
<= 6; i
++) {
3801 if (btusb_find_altsetting(drvdata
, i
))
3802 rp
->altsettings
[rp
->num
++] = i
;
3806 rp_size
= sizeof(*rp
) + rp
->num
;
3808 err
= hci_drv_cmd_complete(hdev
, BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS
,
3809 HCI_DRV_STATUS_SUCCESS
, rp
, rp_size
);
3814 static int btusb_hci_drv_switch_altsetting(struct hci_dev
*hdev
, void *data
,
3817 struct btusb_hci_drv_cmd_switch_altsetting
*cmd
= data
;
3820 if (cmd
->altsetting
> 6) {
3821 status
= HCI_DRV_STATUS_INVALID_PARAMETERS
;
3823 if (btusb_switch_alt_setting(hdev
, cmd
->altsetting
))
3824 status
= HCI_DRV_STATUS_UNSPECIFIED_ERROR
;
3826 status
= HCI_DRV_STATUS_SUCCESS
;
3829 return hci_drv_cmd_status(hdev
, BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING
,
3833 static const struct hci_drv_handler btusb_hci_drv_common_handlers
[] = {
3834 { btusb_hci_drv_read_info
, HCI_DRV_READ_INFO_SIZE
},
3837 static const struct hci_drv_handler btusb_hci_drv_specific_handlers
[] = {
3838 { btusb_hci_drv_supported_altsettings
,
3839 BTUSB_HCI_DRV_SUPPORTED_ALTSETTINGS_SIZE
},
3840 { btusb_hci_drv_switch_altsetting
,
3841 BTUSB_HCI_DRV_SWITCH_ALTSETTING_SIZE
},
3844 static struct hci_drv btusb_hci_drv
= {
3845 .common_handler_count
= ARRAY_SIZE(btusb_hci_drv_common_handlers
),
3846 .common_handlers
= btusb_hci_drv_common_handlers
,
3847 .specific_handler_count
= ARRAY_SIZE(btusb_hci_drv_specific_handlers
),
3848 .specific_handlers
= btusb_hci_drv_specific_handlers
,
3851 static int btusb_probe(struct usb_interface
*intf
,
3852 const struct usb_device_id
*id
)
3854 struct usb_endpoint_descriptor
*ep_desc
;
3855 struct gpio_desc
*reset_gpio
;
3856 struct btusb_data
*data
;
3857 struct hci_dev
*hdev
;
3858 unsigned ifnum_base
;
3859 int i
, err
, priv_size
;
3861 BT_DBG("intf %p id %p", intf
, id
);
3863 if ((id
->driver_info
& BTUSB_IFNUM_2
) &&
3864 (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0) &&
3865 (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 2))
3868 ifnum_base
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
3870 if (!id
->driver_info
) {
3871 const struct usb_device_id
*match
;
3873 match
= usb_match_id(intf
, quirks_table
);
3878 if (id
->driver_info
== BTUSB_IGNORE
)
3881 if (id
->driver_info
& BTUSB_ATH3012
) {
3882 struct usb_device
*udev
= interface_to_usbdev(intf
);
3884 /* Old firmware would otherwise let ath3k driver load
3885 * patch and sysconfig files
3887 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) <= 0x0001 &&
3888 !btusb_qca_need_patch(udev
))
3892 data
= devm_kzalloc(&intf
->dev
, sizeof(*data
), GFP_KERNEL
);
3896 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
3897 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
3899 if (!data
->intr_ep
&& usb_endpoint_is_int_in(ep_desc
)) {
3900 data
->intr_ep
= ep_desc
;
3904 if (!data
->bulk_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
3905 data
->bulk_tx_ep
= ep_desc
;
3909 if (!data
->bulk_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
3910 data
->bulk_rx_ep
= ep_desc
;
3915 if (!data
->intr_ep
|| !data
->bulk_tx_ep
|| !data
->bulk_rx_ep
)
3918 if (id
->driver_info
& BTUSB_AMP
) {
3919 data
->cmdreq_type
= USB_TYPE_CLASS
| 0x01;
3920 data
->cmdreq
= 0x2b;
3922 data
->cmdreq_type
= USB_TYPE_CLASS
;
3923 data
->cmdreq
= 0x00;
3926 data
->udev
= interface_to_usbdev(intf
);
3929 INIT_WORK(&data
->work
, btusb_work
);
3930 INIT_WORK(&data
->waker
, btusb_waker
);
3931 INIT_DELAYED_WORK(&data
->rx_work
, btusb_rx_work
);
3933 skb_queue_head_init(&data
->acl_q
);
3935 init_usb_anchor(&data
->deferred
);
3936 init_usb_anchor(&data
->tx_anchor
);
3937 spin_lock_init(&data
->txlock
);
3939 init_usb_anchor(&data
->intr_anchor
);
3940 init_usb_anchor(&data
->bulk_anchor
);
3941 init_usb_anchor(&data
->isoc_anchor
);
3942 init_usb_anchor(&data
->diag_anchor
);
3943 init_usb_anchor(&data
->ctrl_anchor
);
3944 spin_lock_init(&data
->rxlock
);
3948 data
->recv_event
= hci_recv_frame
;
3949 data
->recv_bulk
= btusb_recv_bulk
;
3951 if (id
->driver_info
& BTUSB_INTEL_COMBINED
) {
3952 /* Allocate extra space for Intel device */
3953 priv_size
+= sizeof(struct btintel_data
);
3955 /* Override the rx handlers */
3956 data
->recv_event
= btintel_recv_event
;
3957 data
->recv_bulk
= btusb_recv_bulk_intel
;
3958 } else if (id
->driver_info
& BTUSB_REALTEK
) {
3959 /* Allocate extra space for Realtek device */
3960 priv_size
+= sizeof(struct btrealtek_data
);
3962 data
->recv_event
= btusb_recv_event_realtek
;
3963 } else if (id
->driver_info
& BTUSB_MEDIATEK
) {
3964 /* Allocate extra space for Mediatek device */
3965 priv_size
+= sizeof(struct btmtk_data
);
3968 data
->recv_acl
= hci_recv_frame
;
3970 hdev
= hci_alloc_dev_priv(priv_size
);
3974 hdev
->bus
= HCI_USB
;
3975 hci_set_drvdata(hdev
, data
);
3979 SET_HCIDEV_DEV(hdev
, &intf
->dev
);
3981 reset_gpio
= gpiod_get_optional(&data
->udev
->dev
, "reset",
3983 if (IS_ERR(reset_gpio
)) {
3984 err
= PTR_ERR(reset_gpio
);
3986 } else if (reset_gpio
) {
3987 data
->reset_gpio
= reset_gpio
;
3990 hdev
->open
= btusb_open
;
3991 hdev
->close
= btusb_close
;
3992 hdev
->flush
= btusb_flush
;
3993 hdev
->send
= btusb_send_frame
;
3994 hdev
->notify
= btusb_notify
;
3995 hdev
->wakeup
= btusb_wakeup
;
3996 hdev
->hci_drv
= &btusb_hci_drv
;
3999 err
= btusb_config_oob_wake(hdev
);
4003 /* Marvell devices may need a specific chip configuration */
4004 if (id
->driver_info
& BTUSB_MARVELL
&& data
->oob_wake_irq
) {
4005 err
= marvell_config_oob_wake(hdev
);
4010 if (id
->driver_info
& BTUSB_CW6622
)
4011 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY
, &hdev
->quirks
);
4013 if (id
->driver_info
& BTUSB_BCM2045
)
4014 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY
, &hdev
->quirks
);
4016 if (id
->driver_info
& BTUSB_BCM92035
)
4017 hdev
->setup
= btusb_setup_bcm92035
;
4019 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM
) &&
4020 (id
->driver_info
& BTUSB_BCM_PATCHRAM
)) {
4021 hdev
->manufacturer
= 15;
4022 hdev
->setup
= btbcm_setup_patchram
;
4023 hdev
->set_diag
= btusb_bcm_set_diag
;
4024 hdev
->set_bdaddr
= btbcm_set_bdaddr
;
4026 /* Broadcom LM_DIAG Interface numbers are hardcoded */
4027 data
->diag
= usb_ifnum_to_if(data
->udev
, ifnum_base
+ 2);
4030 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM
) &&
4031 (id
->driver_info
& BTUSB_BCM_APPLE
)) {
4032 hdev
->manufacturer
= 15;
4033 hdev
->setup
= btbcm_setup_apple
;
4034 hdev
->set_diag
= btusb_bcm_set_diag
;
4036 /* Broadcom LM_DIAG Interface numbers are hardcoded */
4037 data
->diag
= usb_ifnum_to_if(data
->udev
, ifnum_base
+ 2);
4040 /* Combined Intel Device setup to support multiple setup routine */
4041 if (id
->driver_info
& BTUSB_INTEL_COMBINED
) {
4042 err
= btintel_configure_setup(hdev
, btusb_driver
.name
);
4046 /* Transport specific configuration */
4047 hdev
->send
= btusb_send_frame_intel
;
4048 hdev
->reset
= btusb_intel_reset
;
4050 if (id
->driver_info
& BTUSB_INTEL_NO_WBS_SUPPORT
)
4051 btintel_set_flag(hdev
, INTEL_ROM_LEGACY_NO_WBS_SUPPORT
);
4053 if (id
->driver_info
& BTUSB_INTEL_BROKEN_INITIAL_NCMD
)
4054 btintel_set_flag(hdev
, INTEL_BROKEN_INITIAL_NCMD
);
4056 if (id
->driver_info
& BTUSB_INTEL_BROKEN_SHUTDOWN_LED
)
4057 btintel_set_flag(hdev
, INTEL_BROKEN_SHUTDOWN_LED
);
4060 if (id
->driver_info
& BTUSB_MARVELL
)
4061 hdev
->set_bdaddr
= btusb_set_bdaddr_marvell
;
4063 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK
) &&
4064 (id
->driver_info
& BTUSB_MEDIATEK
)) {
4065 hdev
->setup
= btusb_mtk_setup
;
4066 hdev
->shutdown
= btusb_mtk_shutdown
;
4067 hdev
->manufacturer
= 70;
4068 hdev
->reset
= btmtk_reset_sync
;
4069 hdev
->set_bdaddr
= btmtk_set_bdaddr
;
4070 hdev
->send
= btusb_send_frame_mtk
;
4071 set_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN
, &hdev
->quirks
);
4072 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP
, &hdev
->quirks
);
4073 data
->recv_acl
= btmtk_usb_recv_acl
;
4074 data
->suspend
= btmtk_usb_suspend
;
4075 data
->resume
= btmtk_usb_resume
;
4076 data
->disconnect
= btusb_mtk_disconnect
;
4079 if (id
->driver_info
& BTUSB_SWAVE
) {
4080 set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE
, &hdev
->quirks
);
4081 set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS
, &hdev
->quirks
);
4084 if (id
->driver_info
& BTUSB_INTEL_BOOT
) {
4085 hdev
->manufacturer
= 2;
4086 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
4089 if (id
->driver_info
& BTUSB_ATH3012
) {
4090 data
->setup_on_usb
= btusb_setup_qca
;
4091 hdev
->set_bdaddr
= btusb_set_bdaddr_ath3012
;
4092 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
4093 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
4096 if (id
->driver_info
& BTUSB_QCA_ROME
) {
4097 data
->setup_on_usb
= btusb_setup_qca
;
4098 hdev
->shutdown
= btusb_shutdown_qca
;
4099 hdev
->set_bdaddr
= btusb_set_bdaddr_ath3012
;
4100 hdev
->reset
= btusb_qca_reset
;
4101 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
4102 btusb_check_needs_reset_resume(intf
);
4105 if (id
->driver_info
& BTUSB_QCA_WCN6855
) {
4106 data
->qca_dump
.id_vendor
= id
->idVendor
;
4107 data
->qca_dump
.id_product
= id
->idProduct
;
4108 data
->recv_event
= btusb_recv_evt_qca
;
4109 data
->recv_acl
= btusb_recv_acl_qca
;
4110 hci_devcd_register(hdev
, btusb_coredump_qca
, btusb_dump_hdr_qca
, NULL
);
4111 data
->setup_on_usb
= btusb_setup_qca
;
4112 hdev
->shutdown
= btusb_shutdown_qca
;
4113 hdev
->set_bdaddr
= btusb_set_bdaddr_wcn6855
;
4114 hdev
->reset
= btusb_qca_reset
;
4115 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
4116 hci_set_msft_opcode(hdev
, 0xFD70);
4119 if (id
->driver_info
& BTUSB_AMP
) {
4120 /* AMP controllers do not support SCO packets */
4123 /* Interface orders are hardcoded in the specification */
4124 data
->isoc
= usb_ifnum_to_if(data
->udev
, ifnum_base
+ 1);
4125 data
->isoc_ifnum
= ifnum_base
+ 1;
4128 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL
) &&
4129 (id
->driver_info
& BTUSB_REALTEK
)) {
4130 btrtl_set_driver_name(hdev
, btusb_driver
.name
);
4131 hdev
->setup
= btusb_setup_realtek
;
4132 hdev
->shutdown
= btrtl_shutdown_realtek
;
4133 hdev
->reset
= btusb_rtl_reset
;
4134 hdev
->hw_error
= btusb_rtl_hw_error
;
4136 /* Realtek devices need to set remote wakeup on auto-suspend */
4137 set_bit(BTUSB_WAKEUP_AUTOSUSPEND
, &data
->flags
);
4138 set_bit(BTUSB_USE_ALT3_FOR_WBS
, &data
->flags
);
4141 if (id
->driver_info
& BTUSB_ACTIONS_SEMI
) {
4142 /* Support is advertised, but not implemented */
4143 set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING
, &hdev
->quirks
);
4144 set_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER
, &hdev
->quirks
);
4145 set_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT
, &hdev
->quirks
);
4146 set_bit(HCI_QUIRK_BROKEN_EXT_SCAN
, &hdev
->quirks
);
4147 set_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE
, &hdev
->quirks
);
4148 set_bit(HCI_QUIRK_BROKEN_EXT_CREATE_CONN
, &hdev
->quirks
);
4149 set_bit(HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT
, &hdev
->quirks
);
4153 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
4155 if (force_scofix
|| id
->driver_info
& BTUSB_WRONG_SCO_MTU
) {
4156 if (!disable_scofix
)
4157 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
);
4160 if (id
->driver_info
& BTUSB_BROKEN_ISOC
)
4163 if (id
->driver_info
& BTUSB_WIDEBAND_SPEECH
)
4164 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED
, &hdev
->quirks
);
4166 if (id
->driver_info
& BTUSB_INVALID_LE_STATES
)
4167 set_bit(HCI_QUIRK_BROKEN_LE_STATES
, &hdev
->quirks
);
4169 if (id
->driver_info
& BTUSB_DIGIANSWER
) {
4170 data
->cmdreq_type
= USB_TYPE_VENDOR
;
4171 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
4174 if (id
->driver_info
& BTUSB_CSR
) {
4175 struct usb_device
*udev
= data
->udev
;
4176 u16 bcdDevice
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
4178 /* Old firmware would otherwise execute USB reset */
4179 if (bcdDevice
< 0x117)
4180 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
4182 /* This must be set first in case we disable it for fakes */
4183 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
4185 /* Fake CSR devices with broken commands */
4186 if (le16_to_cpu(udev
->descriptor
.idVendor
) == 0x0a12 &&
4187 le16_to_cpu(udev
->descriptor
.idProduct
) == 0x0001)
4188 hdev
->setup
= btusb_setup_csr
;
4191 if (id
->driver_info
& BTUSB_SNIFFER
) {
4192 struct usb_device
*udev
= data
->udev
;
4194 /* New sniffer firmware has crippled HCI interface */
4195 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) > 0x997)
4196 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
4199 if (id
->driver_info
& BTUSB_INTEL_BOOT
) {
4200 /* A bug in the bootloader causes that interrupt interface is
4201 * only enabled after receiving SetInterface(0, AltSetting=0).
4203 err
= usb_set_interface(data
->udev
, 0, 0);
4205 BT_ERR("failed to set interface 0, alt 0 %d", err
);
4211 err
= usb_driver_claim_interface(&btusb_driver
,
4217 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM
) && data
->diag
) {
4218 if (!usb_driver_claim_interface(&btusb_driver
,
4220 __set_diag_interface(hdev
);
4225 if (enable_autosuspend
)
4226 usb_enable_autosuspend(data
->udev
);
4228 data
->poll_sync
= enable_poll_sync
;
4230 err
= hci_register_dev(hdev
);
4234 usb_set_intfdata(intf
, data
);
4236 debugfs_create_file("force_poll_sync", 0644, hdev
->debugfs
, data
,
4237 &force_poll_sync_fops
);
4242 if (data
->reset_gpio
)
4243 gpiod_put(data
->reset_gpio
);
4248 static void btusb_disconnect(struct usb_interface
*intf
)
4250 struct btusb_data
*data
= usb_get_intfdata(intf
);
4251 struct hci_dev
*hdev
;
4253 BT_DBG("intf %p", intf
);
4259 usb_set_intfdata(data
->intf
, NULL
);
4262 usb_set_intfdata(data
->isoc
, NULL
);
4265 usb_set_intfdata(data
->diag
, NULL
);
4267 if (data
->disconnect
)
4268 data
->disconnect(hdev
);
4270 hci_unregister_dev(hdev
);
4272 if (intf
== data
->intf
) {
4274 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
4276 usb_driver_release_interface(&btusb_driver
, data
->diag
);
4277 } else if (intf
== data
->isoc
) {
4279 usb_driver_release_interface(&btusb_driver
, data
->diag
);
4280 usb_driver_release_interface(&btusb_driver
, data
->intf
);
4281 } else if (intf
== data
->diag
) {
4282 usb_driver_release_interface(&btusb_driver
, data
->intf
);
4284 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
4287 if (data
->oob_wake_irq
)
4288 device_init_wakeup(&data
->udev
->dev
, false);
4290 if (data
->reset_gpio
)
4291 gpiod_put(data
->reset_gpio
);
4297 static int btusb_suspend(struct usb_interface
*intf
, pm_message_t message
)
4299 struct btusb_data
*data
= usb_get_intfdata(intf
);
4301 BT_DBG("intf %p", intf
);
4303 /* Don't auto-suspend if there are connections; external suspend calls
4306 if (PMSG_IS_AUTO(message
) && hci_conn_count(data
->hdev
))
4309 if (data
->suspend_count
++)
4312 spin_lock_irq(&data
->txlock
);
4313 if (!(PMSG_IS_AUTO(message
) && data
->tx_in_flight
)) {
4314 set_bit(BTUSB_SUSPENDING
, &data
->flags
);
4315 spin_unlock_irq(&data
->txlock
);
4317 spin_unlock_irq(&data
->txlock
);
4318 data
->suspend_count
--;
4322 cancel_work_sync(&data
->work
);
4325 data
->suspend(data
->hdev
);
4327 btusb_stop_traffic(data
);
4328 usb_kill_anchored_urbs(&data
->tx_anchor
);
4330 if (data
->oob_wake_irq
&& device_may_wakeup(&data
->udev
->dev
)) {
4331 set_bit(BTUSB_OOB_WAKE_ENABLED
, &data
->flags
);
4332 enable_irq_wake(data
->oob_wake_irq
);
4333 enable_irq(data
->oob_wake_irq
);
4336 /* For global suspend, Realtek devices lose the loaded fw
4337 * in them. But for autosuspend, firmware should remain.
4338 * Actually, it depends on whether the usb host sends
4339 * set feature (enable wakeup) or not.
4341 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND
, &data
->flags
)) {
4342 if (PMSG_IS_AUTO(message
) &&
4343 device_can_wakeup(&data
->udev
->dev
))
4344 data
->udev
->do_remote_wakeup
= 1;
4345 else if (!PMSG_IS_AUTO(message
) &&
4346 !device_may_wakeup(&data
->udev
->dev
)) {
4347 data
->udev
->do_remote_wakeup
= 0;
4348 data
->udev
->reset_resume
= 1;
4355 static void play_deferred(struct btusb_data
*data
)
4360 while ((urb
= usb_get_from_anchor(&data
->deferred
))) {
4361 usb_anchor_urb(urb
, &data
->tx_anchor
);
4363 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
4365 if (err
!= -EPERM
&& err
!= -ENODEV
)
4366 BT_ERR("%s urb %p submission failed (%d)",
4367 data
->hdev
->name
, urb
, -err
);
4368 kfree(urb
->setup_packet
);
4369 usb_unanchor_urb(urb
);
4374 data
->tx_in_flight
++;
4378 /* Cleanup the rest deferred urbs. */
4379 while ((urb
= usb_get_from_anchor(&data
->deferred
))) {
4380 kfree(urb
->setup_packet
);
4385 static int btusb_resume(struct usb_interface
*intf
)
4387 struct btusb_data
*data
= usb_get_intfdata(intf
);
4388 struct hci_dev
*hdev
= data
->hdev
;
4391 BT_DBG("intf %p", intf
);
4393 if (--data
->suspend_count
)
4396 /* Disable only if not already disabled (keep it balanced) */
4397 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED
, &data
->flags
)) {
4398 disable_irq(data
->oob_wake_irq
);
4399 disable_irq_wake(data
->oob_wake_irq
);
4402 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
4405 if (test_bit(BTUSB_INTR_RUNNING
, &data
->flags
)) {
4406 err
= btusb_submit_intr_urb(hdev
, GFP_NOIO
);
4408 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
4413 if (test_bit(BTUSB_BULK_RUNNING
, &data
->flags
)) {
4414 err
= btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
4416 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
4420 btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
4423 if (test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
4424 if (btusb_submit_isoc_urb(hdev
, GFP_NOIO
) < 0)
4425 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
4427 btusb_submit_isoc_urb(hdev
, GFP_NOIO
);
4433 spin_lock_irq(&data
->txlock
);
4434 play_deferred(data
);
4435 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
4436 spin_unlock_irq(&data
->txlock
);
4437 schedule_work(&data
->work
);
4442 usb_scuttle_anchored_urbs(&data
->deferred
);
4444 spin_lock_irq(&data
->txlock
);
4445 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
4446 spin_unlock_irq(&data
->txlock
);
4452 #ifdef CONFIG_DEV_COREDUMP
4453 static void btusb_coredump(struct device
*dev
)
4455 struct btusb_data
*data
= dev_get_drvdata(dev
);
4456 struct hci_dev
*hdev
= data
->hdev
;
4458 if (hdev
->dump
.coredump
)
4459 hdev
->dump
.coredump(hdev
);
4463 static struct usb_driver btusb_driver
= {
4465 .probe
= btusb_probe
,
4466 .disconnect
= btusb_disconnect
,
4468 .suspend
= btusb_suspend
,
4469 .resume
= btusb_resume
,
4471 .id_table
= btusb_table
,
4472 .supports_autosuspend
= 1,
4473 .disable_hub_initiated_lpm
= 1,
4475 #ifdef CONFIG_DEV_COREDUMP
4477 .coredump
= btusb_coredump
,
4482 module_usb_driver(btusb_driver
);
4484 module_param(disable_scofix
, bool, 0644);
4485 MODULE_PARM_DESC(disable_scofix
, "Disable fixup of wrong SCO buffer size");
4487 module_param(force_scofix
, bool, 0644);
4488 MODULE_PARM_DESC(force_scofix
, "Force fixup of wrong SCO buffers size");
4490 module_param(enable_autosuspend
, bool, 0644);
4491 MODULE_PARM_DESC(enable_autosuspend
, "Enable USB autosuspend by default");
4493 module_param(reset
, bool, 0644);
4494 MODULE_PARM_DESC(reset
, "Send HCI reset command on initialization");
4496 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
4497 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION
);
4498 MODULE_VERSION(VERSION
);
4499 MODULE_LICENSE("GPL");