3 * Generic Bluetooth USB driver
5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/usb.h>
26 #include <linux/firmware.h>
28 #include <net/bluetooth/bluetooth.h>
29 #include <net/bluetooth/hci_core.h>
33 static bool disable_scofix
;
34 static bool force_scofix
;
36 static bool reset
= 1;
38 static struct usb_driver btusb_driver
;
40 #define BTUSB_IGNORE 0x01
41 #define BTUSB_DIGIANSWER 0x02
42 #define BTUSB_CSR 0x04
43 #define BTUSB_SNIFFER 0x08
44 #define BTUSB_BCM92035 0x10
45 #define BTUSB_BROKEN_ISOC 0x20
46 #define BTUSB_WRONG_SCO_MTU 0x40
47 #define BTUSB_ATH3012 0x80
48 #define BTUSB_INTEL 0x100
49 #define BTUSB_INTEL_BOOT 0x200
50 #define BTUSB_BCM_PATCHRAM 0x400
51 #define BTUSB_MARVELL 0x800
53 static const struct usb_device_id btusb_table
[] = {
54 /* Generic Bluetooth USB device */
55 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
57 /* Apple-specific (Broadcom) devices */
58 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
60 /* MediaTek MT76x0E */
61 { USB_DEVICE(0x0e8d, 0x763f) },
63 /* Broadcom SoftSailing reporting vendor specific */
64 { USB_DEVICE(0x0a5c, 0x21e1) },
66 /* Apple MacBookPro 7,1 */
67 { USB_DEVICE(0x05ac, 0x8213) },
70 { USB_DEVICE(0x05ac, 0x8215) },
72 /* Apple MacBookPro6,2 */
73 { USB_DEVICE(0x05ac, 0x8218) },
75 /* Apple MacBookAir3,1, MacBookAir3,2 */
76 { USB_DEVICE(0x05ac, 0x821b) },
78 /* Apple MacBookAir4,1 */
79 { USB_DEVICE(0x05ac, 0x821f) },
81 /* Apple MacBookPro8,2 */
82 { USB_DEVICE(0x05ac, 0x821a) },
84 /* Apple MacMini5,1 */
85 { USB_DEVICE(0x05ac, 0x8281) },
87 /* AVM BlueFRITZ! USB v2.0 */
88 { USB_DEVICE(0x057c, 0x3800) },
90 /* Bluetooth Ultraport Module from IBM */
91 { USB_DEVICE(0x04bf, 0x030a) },
93 /* ALPS Modules with non-standard id */
94 { USB_DEVICE(0x044e, 0x3001) },
95 { USB_DEVICE(0x044e, 0x3002) },
97 /* Ericsson with non-standard id */
98 { USB_DEVICE(0x0bdb, 0x1002) },
100 /* Canyon CN-BTU1 with HID interfaces */
101 { USB_DEVICE(0x0c10, 0x0000) },
103 /* Broadcom BCM20702A0 */
104 { USB_DEVICE(0x0489, 0xe042) },
105 { USB_DEVICE(0x04ca, 0x2003) },
106 { USB_DEVICE(0x0b05, 0x17b5) },
107 { USB_DEVICE(0x0b05, 0x17cb) },
108 { USB_DEVICE(0x413c, 0x8197) },
110 /* Foxconn - Hon Hai */
111 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
113 /* Broadcom devices with vendor specific id */
114 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
115 .driver_info
= BTUSB_BCM_PATCHRAM
},
117 /* ASUSTek Computer - Broadcom based */
118 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01) },
120 /* Belkin F8065bf - Broadcom based */
121 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01) },
123 /* IMC Networks - Broadcom based */
124 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01) },
126 /* Intel Bluetooth USB Bootloader (RAM module) */
127 { USB_DEVICE(0x8087, 0x0a5a),
128 .driver_info
= BTUSB_INTEL_BOOT
| BTUSB_BROKEN_ISOC
},
130 { } /* Terminating entry */
133 MODULE_DEVICE_TABLE(usb
, btusb_table
);
135 static const struct usb_device_id blacklist_table
[] = {
136 /* CSR BlueCore devices */
137 { USB_DEVICE(0x0a12, 0x0001), .driver_info
= BTUSB_CSR
},
139 /* Broadcom BCM2033 without firmware */
140 { USB_DEVICE(0x0a5c, 0x2033), .driver_info
= BTUSB_IGNORE
},
142 /* Atheros 3011 with sflash firmware */
143 { USB_DEVICE(0x0489, 0xe027), .driver_info
= BTUSB_IGNORE
},
144 { USB_DEVICE(0x0489, 0xe03d), .driver_info
= BTUSB_IGNORE
},
145 { USB_DEVICE(0x0930, 0x0215), .driver_info
= BTUSB_IGNORE
},
146 { USB_DEVICE(0x0cf3, 0x3002), .driver_info
= BTUSB_IGNORE
},
147 { USB_DEVICE(0x0cf3, 0xe019), .driver_info
= BTUSB_IGNORE
},
148 { USB_DEVICE(0x13d3, 0x3304), .driver_info
= BTUSB_IGNORE
},
150 /* Atheros AR9285 Malbec with sflash firmware */
151 { USB_DEVICE(0x03f0, 0x311d), .driver_info
= BTUSB_IGNORE
},
153 /* Atheros 3012 with sflash firmware */
154 { USB_DEVICE(0x0489, 0xe04d), .driver_info
= BTUSB_ATH3012
},
155 { USB_DEVICE(0x0489, 0xe04e), .driver_info
= BTUSB_ATH3012
},
156 { USB_DEVICE(0x0489, 0xe056), .driver_info
= BTUSB_ATH3012
},
157 { USB_DEVICE(0x0489, 0xe057), .driver_info
= BTUSB_ATH3012
},
158 { USB_DEVICE(0x0489, 0xe05f), .driver_info
= BTUSB_ATH3012
},
159 { USB_DEVICE(0x04c5, 0x1330), .driver_info
= BTUSB_ATH3012
},
160 { USB_DEVICE(0x04ca, 0x3004), .driver_info
= BTUSB_ATH3012
},
161 { USB_DEVICE(0x04ca, 0x3005), .driver_info
= BTUSB_ATH3012
},
162 { USB_DEVICE(0x04ca, 0x3006), .driver_info
= BTUSB_ATH3012
},
163 { USB_DEVICE(0x04ca, 0x3007), .driver_info
= BTUSB_ATH3012
},
164 { USB_DEVICE(0x04ca, 0x3008), .driver_info
= BTUSB_ATH3012
},
165 { USB_DEVICE(0x04ca, 0x300b), .driver_info
= BTUSB_ATH3012
},
166 { USB_DEVICE(0x0930, 0x0219), .driver_info
= BTUSB_ATH3012
},
167 { USB_DEVICE(0x0930, 0x0220), .driver_info
= BTUSB_ATH3012
},
168 { USB_DEVICE(0x0930, 0x0227), .driver_info
= BTUSB_ATH3012
},
169 { USB_DEVICE(0x0b05, 0x17d0), .driver_info
= BTUSB_ATH3012
},
170 { USB_DEVICE(0x0cf3, 0x0036), .driver_info
= BTUSB_ATH3012
},
171 { USB_DEVICE(0x0cf3, 0x3004), .driver_info
= BTUSB_ATH3012
},
172 { USB_DEVICE(0x0cf3, 0x3008), .driver_info
= BTUSB_ATH3012
},
173 { USB_DEVICE(0x0cf3, 0x311d), .driver_info
= BTUSB_ATH3012
},
174 { USB_DEVICE(0x0cf3, 0x311e), .driver_info
= BTUSB_ATH3012
},
175 { USB_DEVICE(0x0cf3, 0x311f), .driver_info
= BTUSB_ATH3012
},
176 { USB_DEVICE(0x0cf3, 0x3121), .driver_info
= BTUSB_ATH3012
},
177 { USB_DEVICE(0x0cf3, 0x817a), .driver_info
= BTUSB_ATH3012
},
178 { USB_DEVICE(0x0cf3, 0xe003), .driver_info
= BTUSB_ATH3012
},
179 { USB_DEVICE(0x0cf3, 0xe004), .driver_info
= BTUSB_ATH3012
},
180 { USB_DEVICE(0x0cf3, 0xe005), .driver_info
= BTUSB_ATH3012
},
181 { USB_DEVICE(0x13d3, 0x3362), .driver_info
= BTUSB_ATH3012
},
182 { USB_DEVICE(0x13d3, 0x3375), .driver_info
= BTUSB_ATH3012
},
183 { USB_DEVICE(0x13d3, 0x3393), .driver_info
= BTUSB_ATH3012
},
184 { USB_DEVICE(0x13d3, 0x3402), .driver_info
= BTUSB_ATH3012
},
185 { USB_DEVICE(0x13d3, 0x3432), .driver_info
= BTUSB_ATH3012
},
187 /* Atheros AR5BBU12 with sflash firmware */
188 { USB_DEVICE(0x0489, 0xe02c), .driver_info
= BTUSB_IGNORE
},
190 /* Atheros AR5BBU12 with sflash firmware */
191 { USB_DEVICE(0x0489, 0xe036), .driver_info
= BTUSB_ATH3012
},
192 { USB_DEVICE(0x0489, 0xe03c), .driver_info
= BTUSB_ATH3012
},
194 /* Broadcom BCM2035 */
195 { USB_DEVICE(0x0a5c, 0x2009), .driver_info
= BTUSB_BCM92035
},
196 { USB_DEVICE(0x0a5c, 0x200a), .driver_info
= BTUSB_WRONG_SCO_MTU
},
197 { USB_DEVICE(0x0a5c, 0x2035), .driver_info
= BTUSB_WRONG_SCO_MTU
},
199 /* Broadcom BCM2045 */
200 { USB_DEVICE(0x0a5c, 0x2039), .driver_info
= BTUSB_WRONG_SCO_MTU
},
201 { USB_DEVICE(0x0a5c, 0x2101), .driver_info
= BTUSB_WRONG_SCO_MTU
},
203 /* IBM/Lenovo ThinkPad with Broadcom chip */
204 { USB_DEVICE(0x0a5c, 0x201e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
205 { USB_DEVICE(0x0a5c, 0x2110), .driver_info
= BTUSB_WRONG_SCO_MTU
},
207 /* HP laptop with Broadcom chip */
208 { USB_DEVICE(0x03f0, 0x171d), .driver_info
= BTUSB_WRONG_SCO_MTU
},
210 /* Dell laptop with Broadcom chip */
211 { USB_DEVICE(0x413c, 0x8126), .driver_info
= BTUSB_WRONG_SCO_MTU
},
213 /* Dell Wireless 370 and 410 devices */
214 { USB_DEVICE(0x413c, 0x8152), .driver_info
= BTUSB_WRONG_SCO_MTU
},
215 { USB_DEVICE(0x413c, 0x8156), .driver_info
= BTUSB_WRONG_SCO_MTU
},
217 /* Belkin F8T012 and F8T013 devices */
218 { USB_DEVICE(0x050d, 0x0012), .driver_info
= BTUSB_WRONG_SCO_MTU
},
219 { USB_DEVICE(0x050d, 0x0013), .driver_info
= BTUSB_WRONG_SCO_MTU
},
221 /* Asus WL-BTD202 device */
222 { USB_DEVICE(0x0b05, 0x1715), .driver_info
= BTUSB_WRONG_SCO_MTU
},
224 /* Kensington Bluetooth USB adapter */
225 { USB_DEVICE(0x047d, 0x105e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
227 /* RTX Telecom based adapters with buggy SCO support */
228 { USB_DEVICE(0x0400, 0x0807), .driver_info
= BTUSB_BROKEN_ISOC
},
229 { USB_DEVICE(0x0400, 0x080a), .driver_info
= BTUSB_BROKEN_ISOC
},
231 /* CONWISE Technology based adapters with buggy SCO support */
232 { USB_DEVICE(0x0e5e, 0x6622), .driver_info
= BTUSB_BROKEN_ISOC
},
234 /* Digianswer devices */
235 { USB_DEVICE(0x08fd, 0x0001), .driver_info
= BTUSB_DIGIANSWER
},
236 { USB_DEVICE(0x08fd, 0x0002), .driver_info
= BTUSB_IGNORE
},
238 /* CSR BlueCore Bluetooth Sniffer */
239 { USB_DEVICE(0x0a12, 0x0002),
240 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
242 /* Frontline ComProbe Bluetooth Sniffer */
243 { USB_DEVICE(0x16d3, 0x0002),
244 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
246 /* Intel Bluetooth device */
247 { USB_DEVICE(0x8087, 0x07dc), .driver_info
= BTUSB_INTEL
},
248 { USB_DEVICE(0x8087, 0x0a2a), .driver_info
= BTUSB_INTEL
},
251 { USB_DEVICE(0x1286, 0x2044), .driver_info
= BTUSB_MARVELL
},
252 { USB_DEVICE(0x1286, 0x2046), .driver_info
= BTUSB_MARVELL
},
254 { } /* Terminating entry */
257 #define BTUSB_MAX_ISOC_FRAMES 10
259 #define BTUSB_INTR_RUNNING 0
260 #define BTUSB_BULK_RUNNING 1
261 #define BTUSB_ISOC_RUNNING 2
262 #define BTUSB_SUSPENDING 3
263 #define BTUSB_DID_ISO_RESUME 4
266 struct hci_dev
*hdev
;
267 struct usb_device
*udev
;
268 struct usb_interface
*intf
;
269 struct usb_interface
*isoc
;
275 struct work_struct work
;
276 struct work_struct waker
;
278 struct usb_anchor tx_anchor
;
279 struct usb_anchor intr_anchor
;
280 struct usb_anchor bulk_anchor
;
281 struct usb_anchor isoc_anchor
;
282 struct usb_anchor deferred
;
286 struct usb_endpoint_descriptor
*intr_ep
;
287 struct usb_endpoint_descriptor
*bulk_tx_ep
;
288 struct usb_endpoint_descriptor
*bulk_rx_ep
;
289 struct usb_endpoint_descriptor
*isoc_tx_ep
;
290 struct usb_endpoint_descriptor
*isoc_rx_ep
;
294 unsigned int sco_num
;
299 static int inc_tx(struct btusb_data
*data
)
304 spin_lock_irqsave(&data
->txlock
, flags
);
305 rv
= test_bit(BTUSB_SUSPENDING
, &data
->flags
);
307 data
->tx_in_flight
++;
308 spin_unlock_irqrestore(&data
->txlock
, flags
);
313 static void btusb_intr_complete(struct urb
*urb
)
315 struct hci_dev
*hdev
= urb
->context
;
316 struct btusb_data
*data
= hci_get_drvdata(hdev
);
319 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
320 urb
, urb
->status
, urb
->actual_length
);
322 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
325 if (urb
->status
== 0) {
326 hdev
->stat
.byte_rx
+= urb
->actual_length
;
328 if (hci_recv_fragment(hdev
, HCI_EVENT_PKT
,
329 urb
->transfer_buffer
,
330 urb
->actual_length
) < 0) {
331 BT_ERR("%s corrupted event packet", hdev
->name
);
336 if (!test_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
339 usb_mark_last_busy(data
->udev
);
340 usb_anchor_urb(urb
, &data
->intr_anchor
);
342 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
344 /* -EPERM: urb is being killed;
345 * -ENODEV: device got disconnected */
346 if (err
!= -EPERM
&& err
!= -ENODEV
)
347 BT_ERR("%s urb %p failed to resubmit (%d)",
348 hdev
->name
, urb
, -err
);
349 usb_unanchor_urb(urb
);
353 static int btusb_submit_intr_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
355 struct btusb_data
*data
= hci_get_drvdata(hdev
);
361 BT_DBG("%s", hdev
->name
);
366 urb
= usb_alloc_urb(0, mem_flags
);
370 size
= le16_to_cpu(data
->intr_ep
->wMaxPacketSize
);
372 buf
= kmalloc(size
, mem_flags
);
378 pipe
= usb_rcvintpipe(data
->udev
, data
->intr_ep
->bEndpointAddress
);
380 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
,
381 btusb_intr_complete
, hdev
,
382 data
->intr_ep
->bInterval
);
384 urb
->transfer_flags
|= URB_FREE_BUFFER
;
386 usb_anchor_urb(urb
, &data
->intr_anchor
);
388 err
= usb_submit_urb(urb
, mem_flags
);
390 if (err
!= -EPERM
&& err
!= -ENODEV
)
391 BT_ERR("%s urb %p submission failed (%d)",
392 hdev
->name
, urb
, -err
);
393 usb_unanchor_urb(urb
);
401 static void btusb_bulk_complete(struct urb
*urb
)
403 struct hci_dev
*hdev
= urb
->context
;
404 struct btusb_data
*data
= hci_get_drvdata(hdev
);
407 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
408 urb
, urb
->status
, urb
->actual_length
);
410 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
413 if (urb
->status
== 0) {
414 hdev
->stat
.byte_rx
+= urb
->actual_length
;
416 if (hci_recv_fragment(hdev
, HCI_ACLDATA_PKT
,
417 urb
->transfer_buffer
,
418 urb
->actual_length
) < 0) {
419 BT_ERR("%s corrupted ACL packet", hdev
->name
);
424 if (!test_bit(BTUSB_BULK_RUNNING
, &data
->flags
))
427 usb_anchor_urb(urb
, &data
->bulk_anchor
);
428 usb_mark_last_busy(data
->udev
);
430 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
432 /* -EPERM: urb is being killed;
433 * -ENODEV: device got disconnected */
434 if (err
!= -EPERM
&& err
!= -ENODEV
)
435 BT_ERR("%s urb %p failed to resubmit (%d)",
436 hdev
->name
, urb
, -err
);
437 usb_unanchor_urb(urb
);
441 static int btusb_submit_bulk_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
443 struct btusb_data
*data
= hci_get_drvdata(hdev
);
447 int err
, size
= HCI_MAX_FRAME_SIZE
;
449 BT_DBG("%s", hdev
->name
);
451 if (!data
->bulk_rx_ep
)
454 urb
= usb_alloc_urb(0, mem_flags
);
458 buf
= kmalloc(size
, mem_flags
);
464 pipe
= usb_rcvbulkpipe(data
->udev
, data
->bulk_rx_ep
->bEndpointAddress
);
466 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
467 buf
, size
, btusb_bulk_complete
, hdev
);
469 urb
->transfer_flags
|= URB_FREE_BUFFER
;
471 usb_mark_last_busy(data
->udev
);
472 usb_anchor_urb(urb
, &data
->bulk_anchor
);
474 err
= usb_submit_urb(urb
, mem_flags
);
476 if (err
!= -EPERM
&& err
!= -ENODEV
)
477 BT_ERR("%s urb %p submission failed (%d)",
478 hdev
->name
, urb
, -err
);
479 usb_unanchor_urb(urb
);
487 static void btusb_isoc_complete(struct urb
*urb
)
489 struct hci_dev
*hdev
= urb
->context
;
490 struct btusb_data
*data
= hci_get_drvdata(hdev
);
493 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
494 urb
, urb
->status
, urb
->actual_length
);
496 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
499 if (urb
->status
== 0) {
500 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
501 unsigned int offset
= urb
->iso_frame_desc
[i
].offset
;
502 unsigned int length
= urb
->iso_frame_desc
[i
].actual_length
;
504 if (urb
->iso_frame_desc
[i
].status
)
507 hdev
->stat
.byte_rx
+= length
;
509 if (hci_recv_fragment(hdev
, HCI_SCODATA_PKT
,
510 urb
->transfer_buffer
+ offset
,
512 BT_ERR("%s corrupted SCO packet", hdev
->name
);
518 if (!test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
521 usb_anchor_urb(urb
, &data
->isoc_anchor
);
523 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
525 /* -EPERM: urb is being killed;
526 * -ENODEV: device got disconnected */
527 if (err
!= -EPERM
&& err
!= -ENODEV
)
528 BT_ERR("%s urb %p failed to resubmit (%d)",
529 hdev
->name
, urb
, -err
);
530 usb_unanchor_urb(urb
);
534 static inline void __fill_isoc_descriptor(struct urb
*urb
, int len
, int mtu
)
538 BT_DBG("len %d mtu %d", len
, mtu
);
540 for (i
= 0; i
< BTUSB_MAX_ISOC_FRAMES
&& len
>= mtu
;
541 i
++, offset
+= mtu
, len
-= mtu
) {
542 urb
->iso_frame_desc
[i
].offset
= offset
;
543 urb
->iso_frame_desc
[i
].length
= mtu
;
546 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
547 urb
->iso_frame_desc
[i
].offset
= offset
;
548 urb
->iso_frame_desc
[i
].length
= len
;
552 urb
->number_of_packets
= i
;
555 static int btusb_submit_isoc_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
557 struct btusb_data
*data
= hci_get_drvdata(hdev
);
563 BT_DBG("%s", hdev
->name
);
565 if (!data
->isoc_rx_ep
)
568 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, mem_flags
);
572 size
= le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
) *
573 BTUSB_MAX_ISOC_FRAMES
;
575 buf
= kmalloc(size
, mem_flags
);
581 pipe
= usb_rcvisocpipe(data
->udev
, data
->isoc_rx_ep
->bEndpointAddress
);
583 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
, btusb_isoc_complete
,
584 hdev
, data
->isoc_rx_ep
->bInterval
);
586 urb
->transfer_flags
= URB_FREE_BUFFER
| URB_ISO_ASAP
;
588 __fill_isoc_descriptor(urb
, size
,
589 le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
));
591 usb_anchor_urb(urb
, &data
->isoc_anchor
);
593 err
= usb_submit_urb(urb
, mem_flags
);
595 if (err
!= -EPERM
&& err
!= -ENODEV
)
596 BT_ERR("%s urb %p submission failed (%d)",
597 hdev
->name
, urb
, -err
);
598 usb_unanchor_urb(urb
);
606 static void btusb_tx_complete(struct urb
*urb
)
608 struct sk_buff
*skb
= urb
->context
;
609 struct hci_dev
*hdev
= (struct hci_dev
*) skb
->dev
;
610 struct btusb_data
*data
= hci_get_drvdata(hdev
);
612 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
613 urb
, urb
->status
, urb
->actual_length
);
615 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
619 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
624 spin_lock(&data
->txlock
);
625 data
->tx_in_flight
--;
626 spin_unlock(&data
->txlock
);
628 kfree(urb
->setup_packet
);
633 static void btusb_isoc_tx_complete(struct urb
*urb
)
635 struct sk_buff
*skb
= urb
->context
;
636 struct hci_dev
*hdev
= (struct hci_dev
*) skb
->dev
;
638 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
639 urb
, urb
->status
, urb
->actual_length
);
641 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
645 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
650 kfree(urb
->setup_packet
);
655 static int btusb_open(struct hci_dev
*hdev
)
657 struct btusb_data
*data
= hci_get_drvdata(hdev
);
660 BT_DBG("%s", hdev
->name
);
662 err
= usb_autopm_get_interface(data
->intf
);
666 data
->intf
->needs_remote_wakeup
= 1;
668 if (test_and_set_bit(HCI_RUNNING
, &hdev
->flags
))
671 if (test_and_set_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
674 err
= btusb_submit_intr_urb(hdev
, GFP_KERNEL
);
678 err
= btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
680 usb_kill_anchored_urbs(&data
->intr_anchor
);
684 set_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
685 btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
688 usb_autopm_put_interface(data
->intf
);
692 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
693 clear_bit(HCI_RUNNING
, &hdev
->flags
);
694 usb_autopm_put_interface(data
->intf
);
698 static void btusb_stop_traffic(struct btusb_data
*data
)
700 usb_kill_anchored_urbs(&data
->intr_anchor
);
701 usb_kill_anchored_urbs(&data
->bulk_anchor
);
702 usb_kill_anchored_urbs(&data
->isoc_anchor
);
705 static int btusb_close(struct hci_dev
*hdev
)
707 struct btusb_data
*data
= hci_get_drvdata(hdev
);
710 BT_DBG("%s", hdev
->name
);
712 if (!test_and_clear_bit(HCI_RUNNING
, &hdev
->flags
))
715 cancel_work_sync(&data
->work
);
716 cancel_work_sync(&data
->waker
);
718 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
719 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
720 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
722 btusb_stop_traffic(data
);
723 err
= usb_autopm_get_interface(data
->intf
);
727 data
->intf
->needs_remote_wakeup
= 0;
728 usb_autopm_put_interface(data
->intf
);
731 usb_scuttle_anchored_urbs(&data
->deferred
);
735 static int btusb_flush(struct hci_dev
*hdev
)
737 struct btusb_data
*data
= hci_get_drvdata(hdev
);
739 BT_DBG("%s", hdev
->name
);
741 usb_kill_anchored_urbs(&data
->tx_anchor
);
746 static int btusb_send_frame(struct hci_dev
*hdev
, struct sk_buff
*skb
)
748 struct btusb_data
*data
= hci_get_drvdata(hdev
);
749 struct usb_ctrlrequest
*dr
;
754 BT_DBG("%s", hdev
->name
);
756 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
759 skb
->dev
= (void *) hdev
;
761 switch (bt_cb(skb
)->pkt_type
) {
762 case HCI_COMMAND_PKT
:
763 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
767 dr
= kmalloc(sizeof(*dr
), GFP_ATOMIC
);
773 dr
->bRequestType
= data
->cmdreq_type
;
777 dr
->wLength
= __cpu_to_le16(skb
->len
);
779 pipe
= usb_sndctrlpipe(data
->udev
, 0x00);
781 usb_fill_control_urb(urb
, data
->udev
, pipe
, (void *) dr
,
782 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
787 case HCI_ACLDATA_PKT
:
788 if (!data
->bulk_tx_ep
)
791 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
795 pipe
= usb_sndbulkpipe(data
->udev
,
796 data
->bulk_tx_ep
->bEndpointAddress
);
798 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
799 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
804 case HCI_SCODATA_PKT
:
805 if (!data
->isoc_tx_ep
|| hci_conn_num(hdev
, SCO_LINK
) < 1)
808 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_ATOMIC
);
812 pipe
= usb_sndisocpipe(data
->udev
,
813 data
->isoc_tx_ep
->bEndpointAddress
);
815 usb_fill_int_urb(urb
, data
->udev
, pipe
,
816 skb
->data
, skb
->len
, btusb_isoc_tx_complete
,
817 skb
, data
->isoc_tx_ep
->bInterval
);
819 urb
->transfer_flags
= URB_ISO_ASAP
;
821 __fill_isoc_descriptor(urb
, skb
->len
,
822 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
));
833 usb_anchor_urb(urb
, &data
->deferred
);
834 schedule_work(&data
->waker
);
840 usb_anchor_urb(urb
, &data
->tx_anchor
);
842 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
844 if (err
!= -EPERM
&& err
!= -ENODEV
)
845 BT_ERR("%s urb %p submission failed (%d)",
846 hdev
->name
, urb
, -err
);
847 kfree(urb
->setup_packet
);
848 usb_unanchor_urb(urb
);
850 usb_mark_last_busy(data
->udev
);
858 static void btusb_notify(struct hci_dev
*hdev
, unsigned int evt
)
860 struct btusb_data
*data
= hci_get_drvdata(hdev
);
862 BT_DBG("%s evt %d", hdev
->name
, evt
);
864 if (hci_conn_num(hdev
, SCO_LINK
) != data
->sco_num
) {
865 data
->sco_num
= hci_conn_num(hdev
, SCO_LINK
);
866 schedule_work(&data
->work
);
870 static inline int __set_isoc_interface(struct hci_dev
*hdev
, int altsetting
)
872 struct btusb_data
*data
= hci_get_drvdata(hdev
);
873 struct usb_interface
*intf
= data
->isoc
;
874 struct usb_endpoint_descriptor
*ep_desc
;
880 err
= usb_set_interface(data
->udev
, 1, altsetting
);
882 BT_ERR("%s setting interface failed (%d)", hdev
->name
, -err
);
886 data
->isoc_altsetting
= altsetting
;
888 data
->isoc_tx_ep
= NULL
;
889 data
->isoc_rx_ep
= NULL
;
891 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
892 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
894 if (!data
->isoc_tx_ep
&& usb_endpoint_is_isoc_out(ep_desc
)) {
895 data
->isoc_tx_ep
= ep_desc
;
899 if (!data
->isoc_rx_ep
&& usb_endpoint_is_isoc_in(ep_desc
)) {
900 data
->isoc_rx_ep
= ep_desc
;
905 if (!data
->isoc_tx_ep
|| !data
->isoc_rx_ep
) {
906 BT_ERR("%s invalid SCO descriptors", hdev
->name
);
913 static void btusb_work(struct work_struct
*work
)
915 struct btusb_data
*data
= container_of(work
, struct btusb_data
, work
);
916 struct hci_dev
*hdev
= data
->hdev
;
920 if (data
->sco_num
> 0) {
921 if (!test_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
)) {
922 err
= usb_autopm_get_interface(data
->isoc
? data
->isoc
: data
->intf
);
924 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
925 usb_kill_anchored_urbs(&data
->isoc_anchor
);
929 set_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
);
932 if (hdev
->voice_setting
& 0x0020) {
933 static const int alts
[3] = { 2, 4, 5 };
934 new_alts
= alts
[data
->sco_num
- 1];
936 new_alts
= data
->sco_num
;
939 if (data
->isoc_altsetting
!= new_alts
) {
940 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
941 usb_kill_anchored_urbs(&data
->isoc_anchor
);
943 if (__set_isoc_interface(hdev
, new_alts
) < 0)
947 if (!test_and_set_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
948 if (btusb_submit_isoc_urb(hdev
, GFP_KERNEL
) < 0)
949 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
951 btusb_submit_isoc_urb(hdev
, GFP_KERNEL
);
954 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
955 usb_kill_anchored_urbs(&data
->isoc_anchor
);
957 __set_isoc_interface(hdev
, 0);
958 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
))
959 usb_autopm_put_interface(data
->isoc
? data
->isoc
: data
->intf
);
963 static void btusb_waker(struct work_struct
*work
)
965 struct btusb_data
*data
= container_of(work
, struct btusb_data
, waker
);
968 err
= usb_autopm_get_interface(data
->intf
);
972 usb_autopm_put_interface(data
->intf
);
975 static int btusb_setup_bcm92035(struct hci_dev
*hdev
)
980 BT_DBG("%s", hdev
->name
);
982 skb
= __hci_cmd_sync(hdev
, 0xfc3b, 1, &val
, HCI_INIT_TIMEOUT
);
984 BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb
));
991 static int btusb_setup_csr(struct hci_dev
*hdev
)
993 struct hci_rp_read_local_version
*rp
;
997 BT_DBG("%s", hdev
->name
);
999 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
1002 BT_ERR("Reading local version failed (%ld)", -PTR_ERR(skb
));
1003 return -PTR_ERR(skb
);
1006 rp
= (struct hci_rp_read_local_version
*) skb
->data
;
1009 if (le16_to_cpu(rp
->manufacturer
) != 10) {
1010 /* Clear the reset quirk since this is not an actual
1011 * early Bluetooth 1.1 device from CSR.
1013 clear_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
1015 /* These fake CSR controllers have all a broken
1016 * stored link key handling and so just disable it.
1018 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY
,
1023 ret
= -bt_to_errno(rp
->status
);
1030 struct intel_version
{
1043 static const struct firmware
*btusb_setup_intel_get_fw(struct hci_dev
*hdev
,
1044 struct intel_version
*ver
)
1046 const struct firmware
*fw
;
1050 snprintf(fwname
, sizeof(fwname
),
1051 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
1052 ver
->hw_platform
, ver
->hw_variant
, ver
->hw_revision
,
1053 ver
->fw_variant
, ver
->fw_revision
, ver
->fw_build_num
,
1054 ver
->fw_build_ww
, ver
->fw_build_yy
);
1056 ret
= request_firmware(&fw
, fwname
, &hdev
->dev
);
1058 if (ret
== -EINVAL
) {
1059 BT_ERR("%s Intel firmware file request failed (%d)",
1064 BT_ERR("%s failed to open Intel firmware file: %s(%d)",
1065 hdev
->name
, fwname
, ret
);
1067 /* If the correct firmware patch file is not found, use the
1068 * default firmware patch file instead
1070 snprintf(fwname
, sizeof(fwname
), "intel/ibt-hw-%x.%x.bseq",
1071 ver
->hw_platform
, ver
->hw_variant
);
1072 if (request_firmware(&fw
, fwname
, &hdev
->dev
) < 0) {
1073 BT_ERR("%s failed to open default Intel fw file: %s",
1074 hdev
->name
, fwname
);
1079 BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev
->name
, fwname
);
1084 static int btusb_setup_intel_patching(struct hci_dev
*hdev
,
1085 const struct firmware
*fw
,
1086 const u8
**fw_ptr
, int *disable_patch
)
1088 struct sk_buff
*skb
;
1089 struct hci_command_hdr
*cmd
;
1090 const u8
*cmd_param
;
1091 struct hci_event_hdr
*evt
= NULL
;
1092 const u8
*evt_param
= NULL
;
1093 int remain
= fw
->size
- (*fw_ptr
- fw
->data
);
1095 /* The first byte indicates the types of the patch command or event.
1096 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1097 * in the current firmware buffer doesn't start with 0x01 or
1098 * the size of remain buffer is smaller than HCI command header,
1099 * the firmware file is corrupted and it should stop the patching
1102 if (remain
> HCI_COMMAND_HDR_SIZE
&& *fw_ptr
[0] != 0x01) {
1103 BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev
->name
);
1109 cmd
= (struct hci_command_hdr
*)(*fw_ptr
);
1110 *fw_ptr
+= sizeof(*cmd
);
1111 remain
-= sizeof(*cmd
);
1113 /* Ensure that the remain firmware data is long enough than the length
1114 * of command parameter. If not, the firmware file is corrupted.
1116 if (remain
< cmd
->plen
) {
1117 BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev
->name
);
1121 /* If there is a command that loads a patch in the firmware
1122 * file, then enable the patch upon success, otherwise just
1123 * disable the manufacturer mode, for example patch activation
1124 * is not required when the default firmware patch file is used
1125 * because there are no patch data to load.
1127 if (*disable_patch
&& le16_to_cpu(cmd
->opcode
) == 0xfc8e)
1130 cmd_param
= *fw_ptr
;
1131 *fw_ptr
+= cmd
->plen
;
1132 remain
-= cmd
->plen
;
1134 /* This reads the expected events when the above command is sent to the
1135 * device. Some vendor commands expects more than one events, for
1136 * example command status event followed by vendor specific event.
1137 * For this case, it only keeps the last expected event. so the command
1138 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1139 * last expected event.
1141 while (remain
> HCI_EVENT_HDR_SIZE
&& *fw_ptr
[0] == 0x02) {
1145 evt
= (struct hci_event_hdr
*)(*fw_ptr
);
1146 *fw_ptr
+= sizeof(*evt
);
1147 remain
-= sizeof(*evt
);
1149 if (remain
< evt
->plen
) {
1150 BT_ERR("%s Intel fw corrupted: invalid evt len",
1155 evt_param
= *fw_ptr
;
1156 *fw_ptr
+= evt
->plen
;
1157 remain
-= evt
->plen
;
1160 /* Every HCI commands in the firmware file has its correspond event.
1161 * If event is not found or remain is smaller than zero, the firmware
1162 * file is corrupted.
1164 if (!evt
|| !evt_param
|| remain
< 0) {
1165 BT_ERR("%s Intel fw corrupted: invalid evt read", hdev
->name
);
1169 skb
= __hci_cmd_sync_ev(hdev
, le16_to_cpu(cmd
->opcode
), cmd
->plen
,
1170 cmd_param
, evt
->evt
, HCI_INIT_TIMEOUT
);
1172 BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
1173 hdev
->name
, cmd
->opcode
, PTR_ERR(skb
));
1174 return PTR_ERR(skb
);
1177 /* It ensures that the returned event matches the event data read from
1178 * the firmware file. At fist, it checks the length and then
1179 * the contents of the event.
1181 if (skb
->len
!= evt
->plen
) {
1182 BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev
->name
,
1183 le16_to_cpu(cmd
->opcode
));
1188 if (memcmp(skb
->data
, evt_param
, evt
->plen
)) {
1189 BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)",
1190 hdev
->name
, le16_to_cpu(cmd
->opcode
));
1199 #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
1201 static int btusb_check_bdaddr_intel(struct hci_dev
*hdev
)
1203 struct sk_buff
*skb
;
1204 struct hci_rp_read_bd_addr
*rp
;
1206 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_BD_ADDR
, 0, NULL
,
1209 BT_ERR("%s reading Intel device address failed (%ld)",
1210 hdev
->name
, PTR_ERR(skb
));
1211 return PTR_ERR(skb
);
1214 if (skb
->len
!= sizeof(*rp
)) {
1215 BT_ERR("%s Intel device address length mismatch", hdev
->name
);
1220 rp
= (struct hci_rp_read_bd_addr
*) skb
->data
;
1222 BT_ERR("%s Intel device address result failed (%02x)",
1223 hdev
->name
, rp
->status
);
1225 return -bt_to_errno(rp
->status
);
1228 /* For some Intel based controllers, the default Bluetooth device
1229 * address 00:03:19:9E:8B:00 can be found. These controllers are
1230 * fully operational, but have the danger of duplicate addresses
1231 * and that in turn can cause problems with Bluetooth operation.
1233 if (!bacmp(&rp
->bdaddr
, BDADDR_INTEL
)) {
1234 BT_ERR("%s found Intel default device address (%pMR)",
1235 hdev
->name
, &rp
->bdaddr
);
1236 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
1244 static int btusb_setup_intel(struct hci_dev
*hdev
)
1246 struct sk_buff
*skb
;
1247 const struct firmware
*fw
;
1250 struct intel_version
*ver
;
1252 const u8 mfg_enable
[] = { 0x01, 0x00 };
1253 const u8 mfg_disable
[] = { 0x00, 0x00 };
1254 const u8 mfg_reset_deactivate
[] = { 0x00, 0x01 };
1255 const u8 mfg_reset_activate
[] = { 0x00, 0x02 };
1257 BT_DBG("%s", hdev
->name
);
1259 /* The controller has a bug with the first HCI command sent to it
1260 * returning number of completed commands as zero. This would stall the
1261 * command processing in the Bluetooth core.
1263 * As a workaround, send HCI Reset command first which will reset the
1264 * number of completed commands and allow normal command processing
1267 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
1269 BT_ERR("%s sending initial HCI reset command failed (%ld)",
1270 hdev
->name
, PTR_ERR(skb
));
1271 return PTR_ERR(skb
);
1275 /* Read Intel specific controller version first to allow selection of
1276 * which firmware file to load.
1278 * The returned information are hardware variant and revision plus
1279 * firmware variant, revision and build number.
1281 skb
= __hci_cmd_sync(hdev
, 0xfc05, 0, NULL
, HCI_INIT_TIMEOUT
);
1283 BT_ERR("%s reading Intel fw version command failed (%ld)",
1284 hdev
->name
, PTR_ERR(skb
));
1285 return PTR_ERR(skb
);
1288 if (skb
->len
!= sizeof(*ver
)) {
1289 BT_ERR("%s Intel version event length mismatch", hdev
->name
);
1294 ver
= (struct intel_version
*)skb
->data
;
1296 BT_ERR("%s Intel fw version event failed (%02x)", hdev
->name
,
1299 return -bt_to_errno(ver
->status
);
1302 BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x",
1303 hdev
->name
, ver
->hw_platform
, ver
->hw_variant
,
1304 ver
->hw_revision
, ver
->fw_variant
, ver
->fw_revision
,
1305 ver
->fw_build_num
, ver
->fw_build_ww
, ver
->fw_build_yy
,
1308 /* fw_patch_num indicates the version of patch the device currently
1309 * have. If there is no patch data in the device, it is always 0x00.
1310 * So, if it is other than 0x00, no need to patch the deivce again.
1312 if (ver
->fw_patch_num
) {
1313 BT_INFO("%s: Intel device is already patched. patch num: %02x",
1314 hdev
->name
, ver
->fw_patch_num
);
1316 btusb_check_bdaddr_intel(hdev
);
1320 /* Opens the firmware patch file based on the firmware version read
1321 * from the controller. If it fails to open the matching firmware
1322 * patch file, it tries to open the default firmware patch file.
1323 * If no patch file is found, allow the device to operate without
1326 fw
= btusb_setup_intel_get_fw(hdev
, ver
);
1329 btusb_check_bdaddr_intel(hdev
);
1334 /* This Intel specific command enables the manufacturer mode of the
1337 * Only while this mode is enabled, the driver can download the
1338 * firmware patch data and configuration parameters.
1340 skb
= __hci_cmd_sync(hdev
, 0xfc11, 2, mfg_enable
, HCI_INIT_TIMEOUT
);
1342 BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
1343 hdev
->name
, PTR_ERR(skb
));
1344 release_firmware(fw
);
1345 return PTR_ERR(skb
);
1349 u8 evt_status
= skb
->data
[0];
1350 BT_ERR("%s enable Intel manufacturer mode event failed (%02x)",
1351 hdev
->name
, evt_status
);
1353 release_firmware(fw
);
1354 return -bt_to_errno(evt_status
);
1360 /* The firmware data file consists of list of Intel specific HCI
1361 * commands and its expected events. The first byte indicates the
1362 * type of the message, either HCI command or HCI event.
1364 * It reads the command and its expected event from the firmware file,
1365 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1366 * the returned event is compared with the event read from the firmware
1367 * file and it will continue until all the messages are downloaded to
1370 * Once the firmware patching is completed successfully,
1371 * the manufacturer mode is disabled with reset and activating the
1374 * If the firmware patching fails, the manufacturer mode is
1375 * disabled with reset and deactivating the patch.
1377 * If the default patch file is used, no reset is done when disabling
1380 while (fw
->size
> fw_ptr
- fw
->data
) {
1383 ret
= btusb_setup_intel_patching(hdev
, fw
, &fw_ptr
,
1386 goto exit_mfg_deactivate
;
1389 release_firmware(fw
);
1392 goto exit_mfg_disable
;
1394 /* Patching completed successfully and disable the manufacturer mode
1395 * with reset and activate the downloaded firmware patches.
1397 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_reset_activate
),
1398 mfg_reset_activate
, HCI_INIT_TIMEOUT
);
1400 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1401 hdev
->name
, PTR_ERR(skb
));
1402 return PTR_ERR(skb
);
1406 BT_INFO("%s: Intel Bluetooth firmware patch completed and activated",
1409 btusb_check_bdaddr_intel(hdev
);
1413 /* Disable the manufacturer mode without reset */
1414 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_disable
), mfg_disable
,
1417 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1418 hdev
->name
, PTR_ERR(skb
));
1419 return PTR_ERR(skb
);
1423 BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev
->name
);
1425 btusb_check_bdaddr_intel(hdev
);
1428 exit_mfg_deactivate
:
1429 release_firmware(fw
);
1431 /* Patching failed. Disable the manufacturer mode with reset and
1432 * deactivate the downloaded firmware patches.
1434 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_reset_deactivate
),
1435 mfg_reset_deactivate
, HCI_INIT_TIMEOUT
);
1437 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1438 hdev
->name
, PTR_ERR(skb
));
1439 return PTR_ERR(skb
);
1443 BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated",
1446 btusb_check_bdaddr_intel(hdev
);
1450 static int btusb_set_bdaddr_intel(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
1452 struct sk_buff
*skb
;
1455 skb
= __hci_cmd_sync(hdev
, 0xfc31, 6, bdaddr
, HCI_INIT_TIMEOUT
);
1458 BT_ERR("%s: changing Intel device address failed (%ld)",
1467 static int btusb_set_bdaddr_marvell(struct hci_dev
*hdev
,
1468 const bdaddr_t
*bdaddr
)
1470 struct sk_buff
*skb
;
1475 buf
[1] = sizeof(bdaddr_t
);
1476 memcpy(buf
+ 2, bdaddr
, sizeof(bdaddr_t
));
1478 skb
= __hci_cmd_sync(hdev
, 0xfc22, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
1481 BT_ERR("%s: changing Marvell device address failed (%ld)",
1490 #define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
1492 static int btusb_setup_bcm_patchram(struct hci_dev
*hdev
)
1494 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1495 struct usb_device
*udev
= data
->udev
;
1497 const struct firmware
*fw
;
1500 const struct hci_command_hdr
*cmd
;
1501 const u8
*cmd_param
;
1503 struct sk_buff
*skb
;
1504 struct hci_rp_read_local_version
*ver
;
1505 struct hci_rp_read_bd_addr
*bda
;
1508 snprintf(fw_name
, sizeof(fw_name
), "brcm/%s-%04x-%04x.hcd",
1509 udev
->product
? udev
->product
: "BCM",
1510 le16_to_cpu(udev
->descriptor
.idVendor
),
1511 le16_to_cpu(udev
->descriptor
.idProduct
));
1513 ret
= request_firmware(&fw
, fw_name
, &hdev
->dev
);
1515 BT_INFO("%s: BCM: patch %s not found", hdev
->name
, fw_name
);
1520 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
1523 BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev
->name
, ret
);
1528 /* Read Local Version Info */
1529 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
1533 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
1538 if (skb
->len
!= sizeof(*ver
)) {
1539 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
1546 ver
= (struct hci_rp_read_local_version
*) skb
->data
;
1547 BT_INFO("%s: BCM: patching hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
1548 "lmp_subver=%04x", hdev
->name
, ver
->hci_ver
, ver
->hci_rev
,
1549 ver
->lmp_ver
, ver
->lmp_subver
);
1552 /* Start Download */
1553 skb
= __hci_cmd_sync(hdev
, 0xfc2e, 0, NULL
, HCI_INIT_TIMEOUT
);
1556 BT_ERR("%s: BCM: Download Minidrv command failed (%ld)",
1562 /* 50 msec delay after Download Minidrv completes */
1568 while (fw_size
>= sizeof(*cmd
)) {
1569 cmd
= (struct hci_command_hdr
*) fw_ptr
;
1570 fw_ptr
+= sizeof(*cmd
);
1571 fw_size
-= sizeof(*cmd
);
1573 if (fw_size
< cmd
->plen
) {
1574 BT_ERR("%s: BCM: patch %s is corrupted",
1575 hdev
->name
, fw_name
);
1581 fw_ptr
+= cmd
->plen
;
1582 fw_size
-= cmd
->plen
;
1584 opcode
= le16_to_cpu(cmd
->opcode
);
1586 skb
= __hci_cmd_sync(hdev
, opcode
, cmd
->plen
, cmd_param
,
1590 BT_ERR("%s: BCM: patch command %04x failed (%ld)",
1591 hdev
->name
, opcode
, ret
);
1597 /* 250 msec delay after Launch Ram completes */
1602 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
1605 BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev
->name
, ret
);
1610 /* Read Local Version Info */
1611 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
1615 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
1620 if (skb
->len
!= sizeof(*ver
)) {
1621 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
1628 ver
= (struct hci_rp_read_local_version
*) skb
->data
;
1629 BT_INFO("%s: BCM: firmware hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
1630 "lmp_subver=%04x", hdev
->name
, ver
->hci_ver
, ver
->hci_rev
,
1631 ver
->lmp_ver
, ver
->lmp_subver
);
1634 /* Read BD Address */
1635 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_BD_ADDR
, 0, NULL
,
1639 BT_ERR("%s: HCI_OP_READ_BD_ADDR failed (%ld)",
1644 if (skb
->len
!= sizeof(*bda
)) {
1645 BT_ERR("%s: HCI_OP_READ_BD_ADDR event length mismatch",
1652 bda
= (struct hci_rp_read_bd_addr
*) skb
->data
;
1654 BT_ERR("%s: HCI_OP_READ_BD_ADDR error status (%02x)",
1655 hdev
->name
, bda
->status
);
1657 ret
= -bt_to_errno(bda
->status
);
1661 /* The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
1662 * with no configured address.
1664 if (!bacmp(&bda
->bdaddr
, BDADDR_BCM20702A0
)) {
1665 BT_INFO("%s: BCM: using default device address (%pMR)",
1666 hdev
->name
, &bda
->bdaddr
);
1667 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
1673 release_firmware(fw
);
1678 static int btusb_set_bdaddr_bcm(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
1680 struct sk_buff
*skb
;
1683 skb
= __hci_cmd_sync(hdev
, 0xfc01, 6, bdaddr
, HCI_INIT_TIMEOUT
);
1686 BT_ERR("%s: BCM: Change address command failed (%ld)",
1695 static int btusb_probe(struct usb_interface
*intf
,
1696 const struct usb_device_id
*id
)
1698 struct usb_endpoint_descriptor
*ep_desc
;
1699 struct btusb_data
*data
;
1700 struct hci_dev
*hdev
;
1703 BT_DBG("intf %p id %p", intf
, id
);
1705 /* interface numbers are hardcoded in the spec */
1706 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
1709 if (!id
->driver_info
) {
1710 const struct usb_device_id
*match
;
1711 match
= usb_match_id(intf
, blacklist_table
);
1716 if (id
->driver_info
== BTUSB_IGNORE
)
1719 if (id
->driver_info
& BTUSB_ATH3012
) {
1720 struct usb_device
*udev
= interface_to_usbdev(intf
);
1722 /* Old firmware would otherwise let ath3k driver load
1723 * patch and sysconfig files */
1724 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) <= 0x0001)
1728 data
= devm_kzalloc(&intf
->dev
, sizeof(*data
), GFP_KERNEL
);
1732 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
1733 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
1735 if (!data
->intr_ep
&& usb_endpoint_is_int_in(ep_desc
)) {
1736 data
->intr_ep
= ep_desc
;
1740 if (!data
->bulk_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
1741 data
->bulk_tx_ep
= ep_desc
;
1745 if (!data
->bulk_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
1746 data
->bulk_rx_ep
= ep_desc
;
1751 if (!data
->intr_ep
|| !data
->bulk_tx_ep
|| !data
->bulk_rx_ep
)
1754 data
->cmdreq_type
= USB_TYPE_CLASS
;
1756 data
->udev
= interface_to_usbdev(intf
);
1759 spin_lock_init(&data
->lock
);
1761 INIT_WORK(&data
->work
, btusb_work
);
1762 INIT_WORK(&data
->waker
, btusb_waker
);
1763 spin_lock_init(&data
->txlock
);
1765 init_usb_anchor(&data
->tx_anchor
);
1766 init_usb_anchor(&data
->intr_anchor
);
1767 init_usb_anchor(&data
->bulk_anchor
);
1768 init_usb_anchor(&data
->isoc_anchor
);
1769 init_usb_anchor(&data
->deferred
);
1771 hdev
= hci_alloc_dev();
1775 hdev
->bus
= HCI_USB
;
1776 hci_set_drvdata(hdev
, data
);
1780 SET_HCIDEV_DEV(hdev
, &intf
->dev
);
1782 hdev
->open
= btusb_open
;
1783 hdev
->close
= btusb_close
;
1784 hdev
->flush
= btusb_flush
;
1785 hdev
->send
= btusb_send_frame
;
1786 hdev
->notify
= btusb_notify
;
1788 if (id
->driver_info
& BTUSB_BCM92035
)
1789 hdev
->setup
= btusb_setup_bcm92035
;
1791 if (id
->driver_info
& BTUSB_BCM_PATCHRAM
) {
1792 hdev
->setup
= btusb_setup_bcm_patchram
;
1793 hdev
->set_bdaddr
= btusb_set_bdaddr_bcm
;
1796 if (id
->driver_info
& BTUSB_INTEL
) {
1797 hdev
->setup
= btusb_setup_intel
;
1798 hdev
->set_bdaddr
= btusb_set_bdaddr_intel
;
1801 if (id
->driver_info
& BTUSB_MARVELL
)
1802 hdev
->set_bdaddr
= btusb_set_bdaddr_marvell
;
1804 if (id
->driver_info
& BTUSB_INTEL_BOOT
)
1805 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
1807 /* Interface numbers are hardcoded in the specification */
1808 data
->isoc
= usb_ifnum_to_if(data
->udev
, 1);
1811 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
1813 if (force_scofix
|| id
->driver_info
& BTUSB_WRONG_SCO_MTU
) {
1814 if (!disable_scofix
)
1815 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
);
1818 if (id
->driver_info
& BTUSB_BROKEN_ISOC
)
1821 if (id
->driver_info
& BTUSB_DIGIANSWER
) {
1822 data
->cmdreq_type
= USB_TYPE_VENDOR
;
1823 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
1826 if (id
->driver_info
& BTUSB_CSR
) {
1827 struct usb_device
*udev
= data
->udev
;
1828 u16 bcdDevice
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
1830 /* Old firmware would otherwise execute USB reset */
1831 if (bcdDevice
< 0x117)
1832 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
1834 /* Fake CSR devices with broken commands */
1835 if (bcdDevice
<= 0x100)
1836 hdev
->setup
= btusb_setup_csr
;
1839 if (id
->driver_info
& BTUSB_SNIFFER
) {
1840 struct usb_device
*udev
= data
->udev
;
1842 /* New sniffer firmware has crippled HCI interface */
1843 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) > 0x997)
1844 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
1847 if (id
->driver_info
& BTUSB_INTEL_BOOT
) {
1848 /* A bug in the bootloader causes that interrupt interface is
1849 * only enabled after receiving SetInterface(0, AltSetting=0).
1851 err
= usb_set_interface(data
->udev
, 0, 0);
1853 BT_ERR("failed to set interface 0, alt 0 %d", err
);
1860 err
= usb_driver_claim_interface(&btusb_driver
,
1868 err
= hci_register_dev(hdev
);
1874 usb_set_intfdata(intf
, data
);
1879 static void btusb_disconnect(struct usb_interface
*intf
)
1881 struct btusb_data
*data
= usb_get_intfdata(intf
);
1882 struct hci_dev
*hdev
;
1884 BT_DBG("intf %p", intf
);
1890 usb_set_intfdata(data
->intf
, NULL
);
1893 usb_set_intfdata(data
->isoc
, NULL
);
1895 hci_unregister_dev(hdev
);
1897 if (intf
== data
->isoc
)
1898 usb_driver_release_interface(&btusb_driver
, data
->intf
);
1899 else if (data
->isoc
)
1900 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
1906 static int btusb_suspend(struct usb_interface
*intf
, pm_message_t message
)
1908 struct btusb_data
*data
= usb_get_intfdata(intf
);
1910 BT_DBG("intf %p", intf
);
1912 if (data
->suspend_count
++)
1915 spin_lock_irq(&data
->txlock
);
1916 if (!(PMSG_IS_AUTO(message
) && data
->tx_in_flight
)) {
1917 set_bit(BTUSB_SUSPENDING
, &data
->flags
);
1918 spin_unlock_irq(&data
->txlock
);
1920 spin_unlock_irq(&data
->txlock
);
1921 data
->suspend_count
--;
1925 cancel_work_sync(&data
->work
);
1927 btusb_stop_traffic(data
);
1928 usb_kill_anchored_urbs(&data
->tx_anchor
);
1933 static void play_deferred(struct btusb_data
*data
)
1938 while ((urb
= usb_get_from_anchor(&data
->deferred
))) {
1939 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
1943 data
->tx_in_flight
++;
1945 usb_scuttle_anchored_urbs(&data
->deferred
);
1948 static int btusb_resume(struct usb_interface
*intf
)
1950 struct btusb_data
*data
= usb_get_intfdata(intf
);
1951 struct hci_dev
*hdev
= data
->hdev
;
1954 BT_DBG("intf %p", intf
);
1956 if (--data
->suspend_count
)
1959 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1962 if (test_bit(BTUSB_INTR_RUNNING
, &data
->flags
)) {
1963 err
= btusb_submit_intr_urb(hdev
, GFP_NOIO
);
1965 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
1970 if (test_bit(BTUSB_BULK_RUNNING
, &data
->flags
)) {
1971 err
= btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
1973 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
1977 btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
1980 if (test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
1981 if (btusb_submit_isoc_urb(hdev
, GFP_NOIO
) < 0)
1982 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1984 btusb_submit_isoc_urb(hdev
, GFP_NOIO
);
1987 spin_lock_irq(&data
->txlock
);
1988 play_deferred(data
);
1989 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
1990 spin_unlock_irq(&data
->txlock
);
1991 schedule_work(&data
->work
);
1996 usb_scuttle_anchored_urbs(&data
->deferred
);
1998 spin_lock_irq(&data
->txlock
);
1999 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
2000 spin_unlock_irq(&data
->txlock
);
2006 static struct usb_driver btusb_driver
= {
2008 .probe
= btusb_probe
,
2009 .disconnect
= btusb_disconnect
,
2011 .suspend
= btusb_suspend
,
2012 .resume
= btusb_resume
,
2014 .id_table
= btusb_table
,
2015 .supports_autosuspend
= 1,
2016 .disable_hub_initiated_lpm
= 1,
2019 module_usb_driver(btusb_driver
);
2021 module_param(disable_scofix
, bool, 0644);
2022 MODULE_PARM_DESC(disable_scofix
, "Disable fixup of wrong SCO buffer size");
2024 module_param(force_scofix
, bool, 0644);
2025 MODULE_PARM_DESC(force_scofix
, "Force fixup of wrong SCO buffers size");
2027 module_param(reset
, bool, 0644);
2028 MODULE_PARM_DESC(reset
, "Send HCI reset command on initialization");
2030 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
2031 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION
);
2032 MODULE_VERSION(VERSION
);
2033 MODULE_LICENSE("GPL");