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>
36 static bool disable_scofix
;
37 static bool force_scofix
;
39 static bool reset
= 1;
41 static struct usb_driver btusb_driver
;
43 #define BTUSB_IGNORE 0x01
44 #define BTUSB_DIGIANSWER 0x02
45 #define BTUSB_CSR 0x04
46 #define BTUSB_SNIFFER 0x08
47 #define BTUSB_BCM92035 0x10
48 #define BTUSB_BROKEN_ISOC 0x20
49 #define BTUSB_WRONG_SCO_MTU 0x40
50 #define BTUSB_ATH3012 0x80
51 #define BTUSB_INTEL 0x100
52 #define BTUSB_INTEL_BOOT 0x200
53 #define BTUSB_BCM_PATCHRAM 0x400
54 #define BTUSB_MARVELL 0x800
55 #define BTUSB_SWAVE 0x1000
56 #define BTUSB_INTEL_NEW 0x2000
57 #define BTUSB_AMP 0x4000
58 #define BTUSB_QCA_ROME 0x8000
59 #define BTUSB_BCM_APPLE 0x10000
61 static const struct usb_device_id btusb_table
[] = {
62 /* Generic Bluetooth USB device */
63 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
65 /* Generic Bluetooth AMP device */
66 { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info
= BTUSB_AMP
},
68 /* Apple-specific (Broadcom) devices */
69 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01),
70 .driver_info
= BTUSB_BCM_APPLE
},
72 /* MediaTek MT76x0E */
73 { USB_DEVICE(0x0e8d, 0x763f) },
75 /* Broadcom SoftSailing reporting vendor specific */
76 { USB_DEVICE(0x0a5c, 0x21e1) },
78 /* Apple MacBookPro 7,1 */
79 { USB_DEVICE(0x05ac, 0x8213) },
82 { USB_DEVICE(0x05ac, 0x8215) },
84 /* Apple MacBookPro6,2 */
85 { USB_DEVICE(0x05ac, 0x8218) },
87 /* Apple MacBookAir3,1, MacBookAir3,2 */
88 { USB_DEVICE(0x05ac, 0x821b) },
90 /* Apple MacBookAir4,1 */
91 { USB_DEVICE(0x05ac, 0x821f) },
93 /* Apple MacBookPro8,2 */
94 { USB_DEVICE(0x05ac, 0x821a) },
96 /* Apple MacMini5,1 */
97 { USB_DEVICE(0x05ac, 0x8281) },
99 /* AVM BlueFRITZ! USB v2.0 */
100 { USB_DEVICE(0x057c, 0x3800), .driver_info
= BTUSB_SWAVE
},
102 /* Bluetooth Ultraport Module from IBM */
103 { USB_DEVICE(0x04bf, 0x030a) },
105 /* ALPS Modules with non-standard id */
106 { USB_DEVICE(0x044e, 0x3001) },
107 { USB_DEVICE(0x044e, 0x3002) },
109 /* Ericsson with non-standard id */
110 { USB_DEVICE(0x0bdb, 0x1002) },
112 /* Canyon CN-BTU1 with HID interfaces */
113 { USB_DEVICE(0x0c10, 0x0000) },
115 /* Broadcom BCM20702A0 */
116 { USB_DEVICE(0x413c, 0x8197) },
118 /* Broadcom BCM20702B0 (Dynex/Insignia) */
119 { USB_DEVICE(0x19ff, 0x0239), .driver_info
= BTUSB_BCM_PATCHRAM
},
121 /* Foxconn - Hon Hai */
122 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
123 .driver_info
= BTUSB_BCM_PATCHRAM
},
125 /* Lite-On Technology - Broadcom based */
126 { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
127 .driver_info
= BTUSB_BCM_PATCHRAM
},
129 /* Broadcom devices with vendor specific id */
130 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
131 .driver_info
= BTUSB_BCM_PATCHRAM
},
133 /* ASUSTek Computer - Broadcom based */
134 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
135 .driver_info
= BTUSB_BCM_PATCHRAM
},
137 /* Belkin F8065bf - Broadcom based */
138 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01),
139 .driver_info
= BTUSB_BCM_PATCHRAM
},
141 /* IMC Networks - Broadcom based */
142 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01),
143 .driver_info
= BTUSB_BCM_PATCHRAM
},
145 /* Intel Bluetooth USB Bootloader (RAM module) */
146 { USB_DEVICE(0x8087, 0x0a5a),
147 .driver_info
= BTUSB_INTEL_BOOT
| BTUSB_BROKEN_ISOC
},
149 { } /* Terminating entry */
152 MODULE_DEVICE_TABLE(usb
, btusb_table
);
154 static const struct usb_device_id blacklist_table
[] = {
155 /* CSR BlueCore devices */
156 { USB_DEVICE(0x0a12, 0x0001), .driver_info
= BTUSB_CSR
},
158 /* Broadcom BCM2033 without firmware */
159 { USB_DEVICE(0x0a5c, 0x2033), .driver_info
= BTUSB_IGNORE
},
161 /* Atheros 3011 with sflash firmware */
162 { USB_DEVICE(0x0489, 0xe027), .driver_info
= BTUSB_IGNORE
},
163 { USB_DEVICE(0x0489, 0xe03d), .driver_info
= BTUSB_IGNORE
},
164 { USB_DEVICE(0x04f2, 0xaff1), .driver_info
= BTUSB_IGNORE
},
165 { USB_DEVICE(0x0930, 0x0215), .driver_info
= BTUSB_IGNORE
},
166 { USB_DEVICE(0x0cf3, 0x3002), .driver_info
= BTUSB_IGNORE
},
167 { USB_DEVICE(0x0cf3, 0xe019), .driver_info
= BTUSB_IGNORE
},
168 { USB_DEVICE(0x13d3, 0x3304), .driver_info
= BTUSB_IGNORE
},
170 /* Atheros AR9285 Malbec with sflash firmware */
171 { USB_DEVICE(0x03f0, 0x311d), .driver_info
= BTUSB_IGNORE
},
173 /* Atheros 3012 with sflash firmware */
174 { USB_DEVICE(0x0489, 0xe04d), .driver_info
= BTUSB_ATH3012
},
175 { USB_DEVICE(0x0489, 0xe04e), .driver_info
= BTUSB_ATH3012
},
176 { USB_DEVICE(0x0489, 0xe056), .driver_info
= BTUSB_ATH3012
},
177 { USB_DEVICE(0x0489, 0xe057), .driver_info
= BTUSB_ATH3012
},
178 { USB_DEVICE(0x0489, 0xe05f), .driver_info
= BTUSB_ATH3012
},
179 { USB_DEVICE(0x0489, 0xe078), .driver_info
= BTUSB_ATH3012
},
180 { USB_DEVICE(0x04c5, 0x1330), .driver_info
= BTUSB_ATH3012
},
181 { USB_DEVICE(0x04ca, 0x3004), .driver_info
= BTUSB_ATH3012
},
182 { USB_DEVICE(0x04ca, 0x3005), .driver_info
= BTUSB_ATH3012
},
183 { USB_DEVICE(0x04ca, 0x3006), .driver_info
= BTUSB_ATH3012
},
184 { USB_DEVICE(0x04ca, 0x3007), .driver_info
= BTUSB_ATH3012
},
185 { USB_DEVICE(0x04ca, 0x3008), .driver_info
= BTUSB_ATH3012
},
186 { USB_DEVICE(0x04ca, 0x300b), .driver_info
= BTUSB_ATH3012
},
187 { USB_DEVICE(0x04ca, 0x3010), .driver_info
= BTUSB_ATH3012
},
188 { USB_DEVICE(0x0930, 0x0219), .driver_info
= BTUSB_ATH3012
},
189 { USB_DEVICE(0x0930, 0x0220), .driver_info
= BTUSB_ATH3012
},
190 { USB_DEVICE(0x0930, 0x0227), .driver_info
= BTUSB_ATH3012
},
191 { USB_DEVICE(0x0b05, 0x17d0), .driver_info
= BTUSB_ATH3012
},
192 { USB_DEVICE(0x0cf3, 0x0036), .driver_info
= BTUSB_ATH3012
},
193 { USB_DEVICE(0x0cf3, 0x3004), .driver_info
= BTUSB_ATH3012
},
194 { USB_DEVICE(0x0cf3, 0x3008), .driver_info
= BTUSB_ATH3012
},
195 { USB_DEVICE(0x0cf3, 0x311d), .driver_info
= BTUSB_ATH3012
},
196 { USB_DEVICE(0x0cf3, 0x311e), .driver_info
= BTUSB_ATH3012
},
197 { USB_DEVICE(0x0cf3, 0x311f), .driver_info
= BTUSB_ATH3012
},
198 { USB_DEVICE(0x0cf3, 0x3121), .driver_info
= BTUSB_ATH3012
},
199 { USB_DEVICE(0x0cf3, 0x817a), .driver_info
= BTUSB_ATH3012
},
200 { USB_DEVICE(0x0cf3, 0xe003), .driver_info
= BTUSB_ATH3012
},
201 { USB_DEVICE(0x0cf3, 0xe004), .driver_info
= BTUSB_ATH3012
},
202 { USB_DEVICE(0x0cf3, 0xe005), .driver_info
= BTUSB_ATH3012
},
203 { USB_DEVICE(0x13d3, 0x3362), .driver_info
= BTUSB_ATH3012
},
204 { USB_DEVICE(0x13d3, 0x3375), .driver_info
= BTUSB_ATH3012
},
205 { USB_DEVICE(0x13d3, 0x3393), .driver_info
= BTUSB_ATH3012
},
206 { USB_DEVICE(0x13d3, 0x3402), .driver_info
= BTUSB_ATH3012
},
207 { USB_DEVICE(0x13d3, 0x3408), .driver_info
= BTUSB_ATH3012
},
208 { USB_DEVICE(0x13d3, 0x3423), .driver_info
= BTUSB_ATH3012
},
209 { USB_DEVICE(0x13d3, 0x3432), .driver_info
= BTUSB_ATH3012
},
211 /* Atheros AR5BBU12 with sflash firmware */
212 { USB_DEVICE(0x0489, 0xe02c), .driver_info
= BTUSB_IGNORE
},
214 /* Atheros AR5BBU12 with sflash firmware */
215 { USB_DEVICE(0x0489, 0xe036), .driver_info
= BTUSB_ATH3012
},
216 { USB_DEVICE(0x0489, 0xe03c), .driver_info
= BTUSB_ATH3012
},
218 /* QCA ROME chipset */
219 { USB_DEVICE(0x0cf3, 0xe300), .driver_info
= BTUSB_QCA_ROME
},
220 { USB_DEVICE(0x0cf3, 0xe360), .driver_info
= BTUSB_QCA_ROME
},
222 /* Broadcom BCM2035 */
223 { USB_DEVICE(0x0a5c, 0x2009), .driver_info
= BTUSB_BCM92035
},
224 { USB_DEVICE(0x0a5c, 0x200a), .driver_info
= BTUSB_WRONG_SCO_MTU
},
225 { USB_DEVICE(0x0a5c, 0x2035), .driver_info
= BTUSB_WRONG_SCO_MTU
},
227 /* Broadcom BCM2045 */
228 { USB_DEVICE(0x0a5c, 0x2039), .driver_info
= BTUSB_WRONG_SCO_MTU
},
229 { USB_DEVICE(0x0a5c, 0x2101), .driver_info
= BTUSB_WRONG_SCO_MTU
},
231 /* IBM/Lenovo ThinkPad with Broadcom chip */
232 { USB_DEVICE(0x0a5c, 0x201e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
233 { USB_DEVICE(0x0a5c, 0x2110), .driver_info
= BTUSB_WRONG_SCO_MTU
},
235 /* HP laptop with Broadcom chip */
236 { USB_DEVICE(0x03f0, 0x171d), .driver_info
= BTUSB_WRONG_SCO_MTU
},
238 /* Dell laptop with Broadcom chip */
239 { USB_DEVICE(0x413c, 0x8126), .driver_info
= BTUSB_WRONG_SCO_MTU
},
241 /* Dell Wireless 370 and 410 devices */
242 { USB_DEVICE(0x413c, 0x8152), .driver_info
= BTUSB_WRONG_SCO_MTU
},
243 { USB_DEVICE(0x413c, 0x8156), .driver_info
= BTUSB_WRONG_SCO_MTU
},
245 /* Belkin F8T012 and F8T013 devices */
246 { USB_DEVICE(0x050d, 0x0012), .driver_info
= BTUSB_WRONG_SCO_MTU
},
247 { USB_DEVICE(0x050d, 0x0013), .driver_info
= BTUSB_WRONG_SCO_MTU
},
249 /* Asus WL-BTD202 device */
250 { USB_DEVICE(0x0b05, 0x1715), .driver_info
= BTUSB_WRONG_SCO_MTU
},
252 /* Kensington Bluetooth USB adapter */
253 { USB_DEVICE(0x047d, 0x105e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
255 /* RTX Telecom based adapters with buggy SCO support */
256 { USB_DEVICE(0x0400, 0x0807), .driver_info
= BTUSB_BROKEN_ISOC
},
257 { USB_DEVICE(0x0400, 0x080a), .driver_info
= BTUSB_BROKEN_ISOC
},
259 /* CONWISE Technology based adapters with buggy SCO support */
260 { USB_DEVICE(0x0e5e, 0x6622), .driver_info
= BTUSB_BROKEN_ISOC
},
262 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
263 { USB_DEVICE(0x1300, 0x0001), .driver_info
= BTUSB_SWAVE
},
265 /* Digianswer devices */
266 { USB_DEVICE(0x08fd, 0x0001), .driver_info
= BTUSB_DIGIANSWER
},
267 { USB_DEVICE(0x08fd, 0x0002), .driver_info
= BTUSB_IGNORE
},
269 /* CSR BlueCore Bluetooth Sniffer */
270 { USB_DEVICE(0x0a12, 0x0002),
271 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
273 /* Frontline ComProbe Bluetooth Sniffer */
274 { USB_DEVICE(0x16d3, 0x0002),
275 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
277 /* Marvell Bluetooth devices */
278 { USB_DEVICE(0x1286, 0x2044), .driver_info
= BTUSB_MARVELL
},
279 { USB_DEVICE(0x1286, 0x2046), .driver_info
= BTUSB_MARVELL
},
281 /* Intel Bluetooth devices */
282 { USB_DEVICE(0x8087, 0x07da), .driver_info
= BTUSB_CSR
},
283 { USB_DEVICE(0x8087, 0x07dc), .driver_info
= BTUSB_INTEL
},
284 { USB_DEVICE(0x8087, 0x0a2a), .driver_info
= BTUSB_INTEL
},
285 { USB_DEVICE(0x8087, 0x0a2b), .driver_info
= BTUSB_INTEL_NEW
},
287 /* Other Intel Bluetooth devices */
288 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
289 .driver_info
= BTUSB_IGNORE
},
291 { } /* Terminating entry */
294 #define BTUSB_MAX_ISOC_FRAMES 10
296 #define BTUSB_INTR_RUNNING 0
297 #define BTUSB_BULK_RUNNING 1
298 #define BTUSB_ISOC_RUNNING 2
299 #define BTUSB_SUSPENDING 3
300 #define BTUSB_DID_ISO_RESUME 4
301 #define BTUSB_BOOTLOADER 5
302 #define BTUSB_DOWNLOADING 6
303 #define BTUSB_FIRMWARE_LOADED 7
304 #define BTUSB_FIRMWARE_FAILED 8
305 #define BTUSB_BOOTING 9
308 struct hci_dev
*hdev
;
309 struct usb_device
*udev
;
310 struct usb_interface
*intf
;
311 struct usb_interface
*isoc
;
315 struct work_struct work
;
316 struct work_struct waker
;
318 struct usb_anchor deferred
;
319 struct usb_anchor tx_anchor
;
323 struct usb_anchor intr_anchor
;
324 struct usb_anchor bulk_anchor
;
325 struct usb_anchor isoc_anchor
;
328 struct sk_buff
*evt_skb
;
329 struct sk_buff
*acl_skb
;
330 struct sk_buff
*sco_skb
;
332 struct usb_endpoint_descriptor
*intr_ep
;
333 struct usb_endpoint_descriptor
*bulk_tx_ep
;
334 struct usb_endpoint_descriptor
*bulk_rx_ep
;
335 struct usb_endpoint_descriptor
*isoc_tx_ep
;
336 struct usb_endpoint_descriptor
*isoc_rx_ep
;
341 unsigned int sco_num
;
345 int (*recv_event
)(struct hci_dev
*hdev
, struct sk_buff
*skb
);
346 int (*recv_bulk
)(struct btusb_data
*data
, void *buffer
, int count
);
348 int (*setup_on_usb
)(struct hci_dev
*hdev
);
351 static inline void btusb_free_frags(struct btusb_data
*data
)
355 spin_lock_irqsave(&data
->rxlock
, flags
);
357 kfree_skb(data
->evt_skb
);
358 data
->evt_skb
= NULL
;
360 kfree_skb(data
->acl_skb
);
361 data
->acl_skb
= NULL
;
363 kfree_skb(data
->sco_skb
);
364 data
->sco_skb
= NULL
;
366 spin_unlock_irqrestore(&data
->rxlock
, flags
);
369 static int btusb_recv_intr(struct btusb_data
*data
, void *buffer
, int count
)
374 spin_lock(&data
->rxlock
);
381 skb
= bt_skb_alloc(HCI_MAX_EVENT_SIZE
, GFP_ATOMIC
);
387 bt_cb(skb
)->pkt_type
= HCI_EVENT_PKT
;
388 bt_cb(skb
)->expect
= HCI_EVENT_HDR_SIZE
;
391 len
= min_t(uint
, bt_cb(skb
)->expect
, count
);
392 memcpy(skb_put(skb
, len
), buffer
, len
);
396 bt_cb(skb
)->expect
-= len
;
398 if (skb
->len
== HCI_EVENT_HDR_SIZE
) {
399 /* Complete event header */
400 bt_cb(skb
)->expect
= hci_event_hdr(skb
)->plen
;
402 if (skb_tailroom(skb
) < bt_cb(skb
)->expect
) {
411 if (bt_cb(skb
)->expect
== 0) {
413 data
->recv_event(data
->hdev
, skb
);
419 spin_unlock(&data
->rxlock
);
424 static int btusb_recv_bulk(struct btusb_data
*data
, void *buffer
, int count
)
429 spin_lock(&data
->rxlock
);
436 skb
= bt_skb_alloc(HCI_MAX_FRAME_SIZE
, GFP_ATOMIC
);
442 bt_cb(skb
)->pkt_type
= HCI_ACLDATA_PKT
;
443 bt_cb(skb
)->expect
= HCI_ACL_HDR_SIZE
;
446 len
= min_t(uint
, bt_cb(skb
)->expect
, count
);
447 memcpy(skb_put(skb
, len
), buffer
, len
);
451 bt_cb(skb
)->expect
-= len
;
453 if (skb
->len
== HCI_ACL_HDR_SIZE
) {
454 __le16 dlen
= hci_acl_hdr(skb
)->dlen
;
456 /* Complete ACL header */
457 bt_cb(skb
)->expect
= __le16_to_cpu(dlen
);
459 if (skb_tailroom(skb
) < bt_cb(skb
)->expect
) {
468 if (bt_cb(skb
)->expect
== 0) {
470 hci_recv_frame(data
->hdev
, skb
);
476 spin_unlock(&data
->rxlock
);
481 static int btusb_recv_isoc(struct btusb_data
*data
, void *buffer
, int count
)
486 spin_lock(&data
->rxlock
);
493 skb
= bt_skb_alloc(HCI_MAX_SCO_SIZE
, GFP_ATOMIC
);
499 bt_cb(skb
)->pkt_type
= HCI_SCODATA_PKT
;
500 bt_cb(skb
)->expect
= HCI_SCO_HDR_SIZE
;
503 len
= min_t(uint
, bt_cb(skb
)->expect
, count
);
504 memcpy(skb_put(skb
, len
), buffer
, len
);
508 bt_cb(skb
)->expect
-= len
;
510 if (skb
->len
== HCI_SCO_HDR_SIZE
) {
511 /* Complete SCO header */
512 bt_cb(skb
)->expect
= hci_sco_hdr(skb
)->dlen
;
514 if (skb_tailroom(skb
) < bt_cb(skb
)->expect
) {
523 if (bt_cb(skb
)->expect
== 0) {
525 hci_recv_frame(data
->hdev
, skb
);
531 spin_unlock(&data
->rxlock
);
536 static void btusb_intr_complete(struct urb
*urb
)
538 struct hci_dev
*hdev
= urb
->context
;
539 struct btusb_data
*data
= hci_get_drvdata(hdev
);
542 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
545 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
548 if (urb
->status
== 0) {
549 hdev
->stat
.byte_rx
+= urb
->actual_length
;
551 if (btusb_recv_intr(data
, urb
->transfer_buffer
,
552 urb
->actual_length
) < 0) {
553 BT_ERR("%s corrupted event packet", hdev
->name
);
556 } else if (urb
->status
== -ENOENT
) {
557 /* Avoid suspend failed when usb_kill_urb */
561 if (!test_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
564 usb_mark_last_busy(data
->udev
);
565 usb_anchor_urb(urb
, &data
->intr_anchor
);
567 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
569 /* -EPERM: urb is being killed;
570 * -ENODEV: device got disconnected */
571 if (err
!= -EPERM
&& err
!= -ENODEV
)
572 BT_ERR("%s urb %p failed to resubmit (%d)",
573 hdev
->name
, urb
, -err
);
574 usb_unanchor_urb(urb
);
578 static int btusb_submit_intr_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
580 struct btusb_data
*data
= hci_get_drvdata(hdev
);
586 BT_DBG("%s", hdev
->name
);
591 urb
= usb_alloc_urb(0, mem_flags
);
595 size
= le16_to_cpu(data
->intr_ep
->wMaxPacketSize
);
597 buf
= kmalloc(size
, mem_flags
);
603 pipe
= usb_rcvintpipe(data
->udev
, data
->intr_ep
->bEndpointAddress
);
605 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
,
606 btusb_intr_complete
, hdev
, data
->intr_ep
->bInterval
);
608 urb
->transfer_flags
|= URB_FREE_BUFFER
;
610 usb_anchor_urb(urb
, &data
->intr_anchor
);
612 err
= usb_submit_urb(urb
, mem_flags
);
614 if (err
!= -EPERM
&& err
!= -ENODEV
)
615 BT_ERR("%s urb %p submission failed (%d)",
616 hdev
->name
, urb
, -err
);
617 usb_unanchor_urb(urb
);
625 static void btusb_bulk_complete(struct urb
*urb
)
627 struct hci_dev
*hdev
= urb
->context
;
628 struct btusb_data
*data
= hci_get_drvdata(hdev
);
631 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
634 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
637 if (urb
->status
== 0) {
638 hdev
->stat
.byte_rx
+= urb
->actual_length
;
640 if (data
->recv_bulk(data
, urb
->transfer_buffer
,
641 urb
->actual_length
) < 0) {
642 BT_ERR("%s corrupted ACL packet", hdev
->name
);
645 } else if (urb
->status
== -ENOENT
) {
646 /* Avoid suspend failed when usb_kill_urb */
650 if (!test_bit(BTUSB_BULK_RUNNING
, &data
->flags
))
653 usb_anchor_urb(urb
, &data
->bulk_anchor
);
654 usb_mark_last_busy(data
->udev
);
656 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
658 /* -EPERM: urb is being killed;
659 * -ENODEV: device got disconnected */
660 if (err
!= -EPERM
&& err
!= -ENODEV
)
661 BT_ERR("%s urb %p failed to resubmit (%d)",
662 hdev
->name
, urb
, -err
);
663 usb_unanchor_urb(urb
);
667 static int btusb_submit_bulk_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
669 struct btusb_data
*data
= hci_get_drvdata(hdev
);
673 int err
, size
= HCI_MAX_FRAME_SIZE
;
675 BT_DBG("%s", hdev
->name
);
677 if (!data
->bulk_rx_ep
)
680 urb
= usb_alloc_urb(0, mem_flags
);
684 buf
= kmalloc(size
, mem_flags
);
690 pipe
= usb_rcvbulkpipe(data
->udev
, data
->bulk_rx_ep
->bEndpointAddress
);
692 usb_fill_bulk_urb(urb
, data
->udev
, pipe
, buf
, size
,
693 btusb_bulk_complete
, hdev
);
695 urb
->transfer_flags
|= URB_FREE_BUFFER
;
697 usb_mark_last_busy(data
->udev
);
698 usb_anchor_urb(urb
, &data
->bulk_anchor
);
700 err
= usb_submit_urb(urb
, mem_flags
);
702 if (err
!= -EPERM
&& err
!= -ENODEV
)
703 BT_ERR("%s urb %p submission failed (%d)",
704 hdev
->name
, urb
, -err
);
705 usb_unanchor_urb(urb
);
713 static void btusb_isoc_complete(struct urb
*urb
)
715 struct hci_dev
*hdev
= urb
->context
;
716 struct btusb_data
*data
= hci_get_drvdata(hdev
);
719 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
722 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
725 if (urb
->status
== 0) {
726 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
727 unsigned int offset
= urb
->iso_frame_desc
[i
].offset
;
728 unsigned int length
= urb
->iso_frame_desc
[i
].actual_length
;
730 if (urb
->iso_frame_desc
[i
].status
)
733 hdev
->stat
.byte_rx
+= length
;
735 if (btusb_recv_isoc(data
, urb
->transfer_buffer
+ offset
,
737 BT_ERR("%s corrupted SCO packet", hdev
->name
);
741 } else if (urb
->status
== -ENOENT
) {
742 /* Avoid suspend failed when usb_kill_urb */
746 if (!test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
749 usb_anchor_urb(urb
, &data
->isoc_anchor
);
751 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
753 /* -EPERM: urb is being killed;
754 * -ENODEV: device got disconnected */
755 if (err
!= -EPERM
&& err
!= -ENODEV
)
756 BT_ERR("%s urb %p failed to resubmit (%d)",
757 hdev
->name
, urb
, -err
);
758 usb_unanchor_urb(urb
);
762 static inline void __fill_isoc_descriptor(struct urb
*urb
, int len
, int mtu
)
766 BT_DBG("len %d mtu %d", len
, mtu
);
768 for (i
= 0; i
< BTUSB_MAX_ISOC_FRAMES
&& len
>= mtu
;
769 i
++, offset
+= mtu
, len
-= mtu
) {
770 urb
->iso_frame_desc
[i
].offset
= offset
;
771 urb
->iso_frame_desc
[i
].length
= mtu
;
774 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
775 urb
->iso_frame_desc
[i
].offset
= offset
;
776 urb
->iso_frame_desc
[i
].length
= len
;
780 urb
->number_of_packets
= i
;
783 static int btusb_submit_isoc_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
785 struct btusb_data
*data
= hci_get_drvdata(hdev
);
791 BT_DBG("%s", hdev
->name
);
793 if (!data
->isoc_rx_ep
)
796 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, mem_flags
);
800 size
= le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
) *
801 BTUSB_MAX_ISOC_FRAMES
;
803 buf
= kmalloc(size
, mem_flags
);
809 pipe
= usb_rcvisocpipe(data
->udev
, data
->isoc_rx_ep
->bEndpointAddress
);
811 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
, btusb_isoc_complete
,
812 hdev
, data
->isoc_rx_ep
->bInterval
);
814 urb
->transfer_flags
= URB_FREE_BUFFER
| URB_ISO_ASAP
;
816 __fill_isoc_descriptor(urb
, size
,
817 le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
));
819 usb_anchor_urb(urb
, &data
->isoc_anchor
);
821 err
= usb_submit_urb(urb
, mem_flags
);
823 if (err
!= -EPERM
&& err
!= -ENODEV
)
824 BT_ERR("%s urb %p submission failed (%d)",
825 hdev
->name
, urb
, -err
);
826 usb_unanchor_urb(urb
);
834 static void btusb_tx_complete(struct urb
*urb
)
836 struct sk_buff
*skb
= urb
->context
;
837 struct hci_dev
*hdev
= (struct hci_dev
*)skb
->dev
;
838 struct btusb_data
*data
= hci_get_drvdata(hdev
);
840 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
843 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
847 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
852 spin_lock(&data
->txlock
);
853 data
->tx_in_flight
--;
854 spin_unlock(&data
->txlock
);
856 kfree(urb
->setup_packet
);
861 static void btusb_isoc_tx_complete(struct urb
*urb
)
863 struct sk_buff
*skb
= urb
->context
;
864 struct hci_dev
*hdev
= (struct hci_dev
*)skb
->dev
;
866 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
869 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
873 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
878 kfree(urb
->setup_packet
);
883 static int btusb_open(struct hci_dev
*hdev
)
885 struct btusb_data
*data
= hci_get_drvdata(hdev
);
888 BT_DBG("%s", hdev
->name
);
890 /* Patching USB firmware files prior to starting any URBs of HCI path
891 * It is more safe to use USB bulk channel for downloading USB patch
893 if (data
->setup_on_usb
) {
894 err
= data
->setup_on_usb(hdev
);
899 err
= usb_autopm_get_interface(data
->intf
);
903 data
->intf
->needs_remote_wakeup
= 1;
905 if (test_and_set_bit(HCI_RUNNING
, &hdev
->flags
))
908 if (test_and_set_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
911 err
= btusb_submit_intr_urb(hdev
, GFP_KERNEL
);
915 err
= btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
917 usb_kill_anchored_urbs(&data
->intr_anchor
);
921 set_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
922 btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
925 usb_autopm_put_interface(data
->intf
);
929 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
930 clear_bit(HCI_RUNNING
, &hdev
->flags
);
931 usb_autopm_put_interface(data
->intf
);
935 static void btusb_stop_traffic(struct btusb_data
*data
)
937 usb_kill_anchored_urbs(&data
->intr_anchor
);
938 usb_kill_anchored_urbs(&data
->bulk_anchor
);
939 usb_kill_anchored_urbs(&data
->isoc_anchor
);
942 static int btusb_close(struct hci_dev
*hdev
)
944 struct btusb_data
*data
= hci_get_drvdata(hdev
);
947 BT_DBG("%s", hdev
->name
);
949 if (!test_and_clear_bit(HCI_RUNNING
, &hdev
->flags
))
952 cancel_work_sync(&data
->work
);
953 cancel_work_sync(&data
->waker
);
955 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
956 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
957 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
959 btusb_stop_traffic(data
);
960 btusb_free_frags(data
);
962 err
= usb_autopm_get_interface(data
->intf
);
966 data
->intf
->needs_remote_wakeup
= 0;
967 usb_autopm_put_interface(data
->intf
);
970 usb_scuttle_anchored_urbs(&data
->deferred
);
974 static int btusb_flush(struct hci_dev
*hdev
)
976 struct btusb_data
*data
= hci_get_drvdata(hdev
);
978 BT_DBG("%s", hdev
->name
);
980 usb_kill_anchored_urbs(&data
->tx_anchor
);
981 btusb_free_frags(data
);
986 static struct urb
*alloc_ctrl_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
988 struct btusb_data
*data
= hci_get_drvdata(hdev
);
989 struct usb_ctrlrequest
*dr
;
993 urb
= usb_alloc_urb(0, GFP_KERNEL
);
995 return ERR_PTR(-ENOMEM
);
997 dr
= kmalloc(sizeof(*dr
), GFP_KERNEL
);
1000 return ERR_PTR(-ENOMEM
);
1003 dr
->bRequestType
= data
->cmdreq_type
;
1004 dr
->bRequest
= data
->cmdreq
;
1007 dr
->wLength
= __cpu_to_le16(skb
->len
);
1009 pipe
= usb_sndctrlpipe(data
->udev
, 0x00);
1011 usb_fill_control_urb(urb
, data
->udev
, pipe
, (void *)dr
,
1012 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
1014 skb
->dev
= (void *)hdev
;
1019 static struct urb
*alloc_bulk_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1021 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1025 if (!data
->bulk_tx_ep
)
1026 return ERR_PTR(-ENODEV
);
1028 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1030 return ERR_PTR(-ENOMEM
);
1032 pipe
= usb_sndbulkpipe(data
->udev
, data
->bulk_tx_ep
->bEndpointAddress
);
1034 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
1035 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
1037 skb
->dev
= (void *)hdev
;
1042 static struct urb
*alloc_isoc_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1044 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1048 if (!data
->isoc_tx_ep
)
1049 return ERR_PTR(-ENODEV
);
1051 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_KERNEL
);
1053 return ERR_PTR(-ENOMEM
);
1055 pipe
= usb_sndisocpipe(data
->udev
, data
->isoc_tx_ep
->bEndpointAddress
);
1057 usb_fill_int_urb(urb
, data
->udev
, pipe
,
1058 skb
->data
, skb
->len
, btusb_isoc_tx_complete
,
1059 skb
, data
->isoc_tx_ep
->bInterval
);
1061 urb
->transfer_flags
= URB_ISO_ASAP
;
1063 __fill_isoc_descriptor(urb
, skb
->len
,
1064 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
));
1066 skb
->dev
= (void *)hdev
;
1071 static int submit_tx_urb(struct hci_dev
*hdev
, struct urb
*urb
)
1073 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1076 usb_anchor_urb(urb
, &data
->tx_anchor
);
1078 err
= usb_submit_urb(urb
, GFP_KERNEL
);
1080 if (err
!= -EPERM
&& err
!= -ENODEV
)
1081 BT_ERR("%s urb %p submission failed (%d)",
1082 hdev
->name
, urb
, -err
);
1083 kfree(urb
->setup_packet
);
1084 usb_unanchor_urb(urb
);
1086 usb_mark_last_busy(data
->udev
);
1093 static int submit_or_queue_tx_urb(struct hci_dev
*hdev
, struct urb
*urb
)
1095 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1096 unsigned long flags
;
1099 spin_lock_irqsave(&data
->txlock
, flags
);
1100 suspending
= test_bit(BTUSB_SUSPENDING
, &data
->flags
);
1102 data
->tx_in_flight
++;
1103 spin_unlock_irqrestore(&data
->txlock
, flags
);
1106 return submit_tx_urb(hdev
, urb
);
1108 usb_anchor_urb(urb
, &data
->deferred
);
1109 schedule_work(&data
->waker
);
1115 static int btusb_send_frame(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1119 BT_DBG("%s", hdev
->name
);
1121 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1124 switch (bt_cb(skb
)->pkt_type
) {
1125 case HCI_COMMAND_PKT
:
1126 urb
= alloc_ctrl_urb(hdev
, skb
);
1128 return PTR_ERR(urb
);
1130 hdev
->stat
.cmd_tx
++;
1131 return submit_or_queue_tx_urb(hdev
, urb
);
1133 case HCI_ACLDATA_PKT
:
1134 urb
= alloc_bulk_urb(hdev
, skb
);
1136 return PTR_ERR(urb
);
1138 hdev
->stat
.acl_tx
++;
1139 return submit_or_queue_tx_urb(hdev
, urb
);
1141 case HCI_SCODATA_PKT
:
1142 if (hci_conn_num(hdev
, SCO_LINK
) < 1)
1145 urb
= alloc_isoc_urb(hdev
, skb
);
1147 return PTR_ERR(urb
);
1149 hdev
->stat
.sco_tx
++;
1150 return submit_tx_urb(hdev
, urb
);
1156 static void btusb_notify(struct hci_dev
*hdev
, unsigned int evt
)
1158 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1160 BT_DBG("%s evt %d", hdev
->name
, evt
);
1162 if (hci_conn_num(hdev
, SCO_LINK
) != data
->sco_num
) {
1163 data
->sco_num
= hci_conn_num(hdev
, SCO_LINK
);
1164 schedule_work(&data
->work
);
1168 static inline int __set_isoc_interface(struct hci_dev
*hdev
, int altsetting
)
1170 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1171 struct usb_interface
*intf
= data
->isoc
;
1172 struct usb_endpoint_descriptor
*ep_desc
;
1178 err
= usb_set_interface(data
->udev
, 1, altsetting
);
1180 BT_ERR("%s setting interface failed (%d)", hdev
->name
, -err
);
1184 data
->isoc_altsetting
= altsetting
;
1186 data
->isoc_tx_ep
= NULL
;
1187 data
->isoc_rx_ep
= NULL
;
1189 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
1190 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
1192 if (!data
->isoc_tx_ep
&& usb_endpoint_is_isoc_out(ep_desc
)) {
1193 data
->isoc_tx_ep
= ep_desc
;
1197 if (!data
->isoc_rx_ep
&& usb_endpoint_is_isoc_in(ep_desc
)) {
1198 data
->isoc_rx_ep
= ep_desc
;
1203 if (!data
->isoc_tx_ep
|| !data
->isoc_rx_ep
) {
1204 BT_ERR("%s invalid SCO descriptors", hdev
->name
);
1211 static void btusb_work(struct work_struct
*work
)
1213 struct btusb_data
*data
= container_of(work
, struct btusb_data
, work
);
1214 struct hci_dev
*hdev
= data
->hdev
;
1218 if (data
->sco_num
> 0) {
1219 if (!test_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
)) {
1220 err
= usb_autopm_get_interface(data
->isoc
? data
->isoc
: data
->intf
);
1222 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1223 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1227 set_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
);
1230 if (hdev
->voice_setting
& 0x0020) {
1231 static const int alts
[3] = { 2, 4, 5 };
1233 new_alts
= alts
[data
->sco_num
- 1];
1235 new_alts
= data
->sco_num
;
1238 if (data
->isoc_altsetting
!= new_alts
) {
1239 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1240 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1242 if (__set_isoc_interface(hdev
, new_alts
) < 0)
1246 if (!test_and_set_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
1247 if (btusb_submit_isoc_urb(hdev
, GFP_KERNEL
) < 0)
1248 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1250 btusb_submit_isoc_urb(hdev
, GFP_KERNEL
);
1253 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1254 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1256 __set_isoc_interface(hdev
, 0);
1257 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
))
1258 usb_autopm_put_interface(data
->isoc
? data
->isoc
: data
->intf
);
1262 static void btusb_waker(struct work_struct
*work
)
1264 struct btusb_data
*data
= container_of(work
, struct btusb_data
, waker
);
1267 err
= usb_autopm_get_interface(data
->intf
);
1271 usb_autopm_put_interface(data
->intf
);
1274 static struct sk_buff
*btusb_read_local_version(struct hci_dev
*hdev
)
1276 struct sk_buff
*skb
;
1278 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
1281 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
1282 hdev
->name
, PTR_ERR(skb
));
1286 if (skb
->len
!= sizeof(struct hci_rp_read_local_version
)) {
1287 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
1290 return ERR_PTR(-EIO
);
1296 static int btusb_setup_bcm92035(struct hci_dev
*hdev
)
1298 struct sk_buff
*skb
;
1301 BT_DBG("%s", hdev
->name
);
1303 skb
= __hci_cmd_sync(hdev
, 0xfc3b, 1, &val
, HCI_INIT_TIMEOUT
);
1305 BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb
));
1312 static int btusb_setup_csr(struct hci_dev
*hdev
)
1314 struct hci_rp_read_local_version
*rp
;
1315 struct sk_buff
*skb
;
1318 BT_DBG("%s", hdev
->name
);
1320 skb
= btusb_read_local_version(hdev
);
1322 return -PTR_ERR(skb
);
1324 rp
= (struct hci_rp_read_local_version
*)skb
->data
;
1327 if (le16_to_cpu(rp
->manufacturer
) != 10) {
1328 /* Clear the reset quirk since this is not an actual
1329 * early Bluetooth 1.1 device from CSR.
1331 clear_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
1333 /* These fake CSR controllers have all a broken
1334 * stored link key handling and so just disable it.
1336 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY
,
1341 ret
= -bt_to_errno(rp
->status
);
1348 static const struct firmware
*btusb_setup_intel_get_fw(struct hci_dev
*hdev
,
1349 struct intel_version
*ver
)
1351 const struct firmware
*fw
;
1355 snprintf(fwname
, sizeof(fwname
),
1356 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
1357 ver
->hw_platform
, ver
->hw_variant
, ver
->hw_revision
,
1358 ver
->fw_variant
, ver
->fw_revision
, ver
->fw_build_num
,
1359 ver
->fw_build_ww
, ver
->fw_build_yy
);
1361 ret
= request_firmware(&fw
, fwname
, &hdev
->dev
);
1363 if (ret
== -EINVAL
) {
1364 BT_ERR("%s Intel firmware file request failed (%d)",
1369 BT_ERR("%s failed to open Intel firmware file: %s(%d)",
1370 hdev
->name
, fwname
, ret
);
1372 /* If the correct firmware patch file is not found, use the
1373 * default firmware patch file instead
1375 snprintf(fwname
, sizeof(fwname
), "intel/ibt-hw-%x.%x.bseq",
1376 ver
->hw_platform
, ver
->hw_variant
);
1377 if (request_firmware(&fw
, fwname
, &hdev
->dev
) < 0) {
1378 BT_ERR("%s failed to open default Intel fw file: %s",
1379 hdev
->name
, fwname
);
1384 BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev
->name
, fwname
);
1389 static int btusb_setup_intel_patching(struct hci_dev
*hdev
,
1390 const struct firmware
*fw
,
1391 const u8
**fw_ptr
, int *disable_patch
)
1393 struct sk_buff
*skb
;
1394 struct hci_command_hdr
*cmd
;
1395 const u8
*cmd_param
;
1396 struct hci_event_hdr
*evt
= NULL
;
1397 const u8
*evt_param
= NULL
;
1398 int remain
= fw
->size
- (*fw_ptr
- fw
->data
);
1400 /* The first byte indicates the types of the patch command or event.
1401 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1402 * in the current firmware buffer doesn't start with 0x01 or
1403 * the size of remain buffer is smaller than HCI command header,
1404 * the firmware file is corrupted and it should stop the patching
1407 if (remain
> HCI_COMMAND_HDR_SIZE
&& *fw_ptr
[0] != 0x01) {
1408 BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev
->name
);
1414 cmd
= (struct hci_command_hdr
*)(*fw_ptr
);
1415 *fw_ptr
+= sizeof(*cmd
);
1416 remain
-= sizeof(*cmd
);
1418 /* Ensure that the remain firmware data is long enough than the length
1419 * of command parameter. If not, the firmware file is corrupted.
1421 if (remain
< cmd
->plen
) {
1422 BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev
->name
);
1426 /* If there is a command that loads a patch in the firmware
1427 * file, then enable the patch upon success, otherwise just
1428 * disable the manufacturer mode, for example patch activation
1429 * is not required when the default firmware patch file is used
1430 * because there are no patch data to load.
1432 if (*disable_patch
&& le16_to_cpu(cmd
->opcode
) == 0xfc8e)
1435 cmd_param
= *fw_ptr
;
1436 *fw_ptr
+= cmd
->plen
;
1437 remain
-= cmd
->plen
;
1439 /* This reads the expected events when the above command is sent to the
1440 * device. Some vendor commands expects more than one events, for
1441 * example command status event followed by vendor specific event.
1442 * For this case, it only keeps the last expected event. so the command
1443 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1444 * last expected event.
1446 while (remain
> HCI_EVENT_HDR_SIZE
&& *fw_ptr
[0] == 0x02) {
1450 evt
= (struct hci_event_hdr
*)(*fw_ptr
);
1451 *fw_ptr
+= sizeof(*evt
);
1452 remain
-= sizeof(*evt
);
1454 if (remain
< evt
->plen
) {
1455 BT_ERR("%s Intel fw corrupted: invalid evt len",
1460 evt_param
= *fw_ptr
;
1461 *fw_ptr
+= evt
->plen
;
1462 remain
-= evt
->plen
;
1465 /* Every HCI commands in the firmware file has its correspond event.
1466 * If event is not found or remain is smaller than zero, the firmware
1467 * file is corrupted.
1469 if (!evt
|| !evt_param
|| remain
< 0) {
1470 BT_ERR("%s Intel fw corrupted: invalid evt read", hdev
->name
);
1474 skb
= __hci_cmd_sync_ev(hdev
, le16_to_cpu(cmd
->opcode
), cmd
->plen
,
1475 cmd_param
, evt
->evt
, HCI_INIT_TIMEOUT
);
1477 BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
1478 hdev
->name
, cmd
->opcode
, PTR_ERR(skb
));
1479 return PTR_ERR(skb
);
1482 /* It ensures that the returned event matches the event data read from
1483 * the firmware file. At fist, it checks the length and then
1484 * the contents of the event.
1486 if (skb
->len
!= evt
->plen
) {
1487 BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev
->name
,
1488 le16_to_cpu(cmd
->opcode
));
1493 if (memcmp(skb
->data
, evt_param
, evt
->plen
)) {
1494 BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)",
1495 hdev
->name
, le16_to_cpu(cmd
->opcode
));
1504 static int btusb_setup_intel(struct hci_dev
*hdev
)
1506 struct sk_buff
*skb
;
1507 const struct firmware
*fw
;
1510 struct intel_version
*ver
;
1512 const u8 mfg_enable
[] = { 0x01, 0x00 };
1513 const u8 mfg_disable
[] = { 0x00, 0x00 };
1514 const u8 mfg_reset_deactivate
[] = { 0x00, 0x01 };
1515 const u8 mfg_reset_activate
[] = { 0x00, 0x02 };
1517 BT_DBG("%s", hdev
->name
);
1519 /* The controller has a bug with the first HCI command sent to it
1520 * returning number of completed commands as zero. This would stall the
1521 * command processing in the Bluetooth core.
1523 * As a workaround, send HCI Reset command first which will reset the
1524 * number of completed commands and allow normal command processing
1527 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
1529 BT_ERR("%s sending initial HCI reset command failed (%ld)",
1530 hdev
->name
, PTR_ERR(skb
));
1531 return PTR_ERR(skb
);
1535 /* Read Intel specific controller version first to allow selection of
1536 * which firmware file to load.
1538 * The returned information are hardware variant and revision plus
1539 * firmware variant, revision and build number.
1541 skb
= __hci_cmd_sync(hdev
, 0xfc05, 0, NULL
, HCI_INIT_TIMEOUT
);
1543 BT_ERR("%s reading Intel fw version command failed (%ld)",
1544 hdev
->name
, PTR_ERR(skb
));
1545 return PTR_ERR(skb
);
1548 if (skb
->len
!= sizeof(*ver
)) {
1549 BT_ERR("%s Intel version event length mismatch", hdev
->name
);
1554 ver
= (struct intel_version
*)skb
->data
;
1556 BT_ERR("%s Intel fw version event failed (%02x)", hdev
->name
,
1559 return -bt_to_errno(ver
->status
);
1562 BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x",
1563 hdev
->name
, ver
->hw_platform
, ver
->hw_variant
,
1564 ver
->hw_revision
, ver
->fw_variant
, ver
->fw_revision
,
1565 ver
->fw_build_num
, ver
->fw_build_ww
, ver
->fw_build_yy
,
1568 /* fw_patch_num indicates the version of patch the device currently
1569 * have. If there is no patch data in the device, it is always 0x00.
1570 * So, if it is other than 0x00, no need to patch the deivce again.
1572 if (ver
->fw_patch_num
) {
1573 BT_INFO("%s: Intel device is already patched. patch num: %02x",
1574 hdev
->name
, ver
->fw_patch_num
);
1576 btintel_check_bdaddr(hdev
);
1580 /* Opens the firmware patch file based on the firmware version read
1581 * from the controller. If it fails to open the matching firmware
1582 * patch file, it tries to open the default firmware patch file.
1583 * If no patch file is found, allow the device to operate without
1586 fw
= btusb_setup_intel_get_fw(hdev
, ver
);
1589 btintel_check_bdaddr(hdev
);
1594 /* This Intel specific command enables the manufacturer mode of the
1597 * Only while this mode is enabled, the driver can download the
1598 * firmware patch data and configuration parameters.
1600 skb
= __hci_cmd_sync(hdev
, 0xfc11, 2, mfg_enable
, HCI_INIT_TIMEOUT
);
1602 BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
1603 hdev
->name
, PTR_ERR(skb
));
1604 release_firmware(fw
);
1605 return PTR_ERR(skb
);
1609 u8 evt_status
= skb
->data
[0];
1611 BT_ERR("%s enable Intel manufacturer mode event failed (%02x)",
1612 hdev
->name
, evt_status
);
1614 release_firmware(fw
);
1615 return -bt_to_errno(evt_status
);
1621 /* The firmware data file consists of list of Intel specific HCI
1622 * commands and its expected events. The first byte indicates the
1623 * type of the message, either HCI command or HCI event.
1625 * It reads the command and its expected event from the firmware file,
1626 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1627 * the returned event is compared with the event read from the firmware
1628 * file and it will continue until all the messages are downloaded to
1631 * Once the firmware patching is completed successfully,
1632 * the manufacturer mode is disabled with reset and activating the
1635 * If the firmware patching fails, the manufacturer mode is
1636 * disabled with reset and deactivating the patch.
1638 * If the default patch file is used, no reset is done when disabling
1641 while (fw
->size
> fw_ptr
- fw
->data
) {
1644 ret
= btusb_setup_intel_patching(hdev
, fw
, &fw_ptr
,
1647 goto exit_mfg_deactivate
;
1650 release_firmware(fw
);
1653 goto exit_mfg_disable
;
1655 /* Patching completed successfully and disable the manufacturer mode
1656 * with reset and activate the downloaded firmware patches.
1658 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_reset_activate
),
1659 mfg_reset_activate
, HCI_INIT_TIMEOUT
);
1661 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1662 hdev
->name
, PTR_ERR(skb
));
1663 return PTR_ERR(skb
);
1667 BT_INFO("%s: Intel Bluetooth firmware patch completed and activated",
1670 btintel_check_bdaddr(hdev
);
1674 /* Disable the manufacturer mode without reset */
1675 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_disable
), mfg_disable
,
1678 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1679 hdev
->name
, PTR_ERR(skb
));
1680 return PTR_ERR(skb
);
1684 BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev
->name
);
1686 btintel_check_bdaddr(hdev
);
1689 exit_mfg_deactivate
:
1690 release_firmware(fw
);
1692 /* Patching failed. Disable the manufacturer mode with reset and
1693 * deactivate the downloaded firmware patches.
1695 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_reset_deactivate
),
1696 mfg_reset_deactivate
, HCI_INIT_TIMEOUT
);
1698 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1699 hdev
->name
, PTR_ERR(skb
));
1700 return PTR_ERR(skb
);
1704 BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated",
1707 btintel_check_bdaddr(hdev
);
1711 static int inject_cmd_complete(struct hci_dev
*hdev
, __u16 opcode
)
1713 struct sk_buff
*skb
;
1714 struct hci_event_hdr
*hdr
;
1715 struct hci_ev_cmd_complete
*evt
;
1717 skb
= bt_skb_alloc(sizeof(*hdr
) + sizeof(*evt
) + 1, GFP_ATOMIC
);
1721 hdr
= (struct hci_event_hdr
*)skb_put(skb
, sizeof(*hdr
));
1722 hdr
->evt
= HCI_EV_CMD_COMPLETE
;
1723 hdr
->plen
= sizeof(*evt
) + 1;
1725 evt
= (struct hci_ev_cmd_complete
*)skb_put(skb
, sizeof(*evt
));
1727 evt
->opcode
= cpu_to_le16(opcode
);
1729 *skb_put(skb
, 1) = 0x00;
1731 bt_cb(skb
)->pkt_type
= HCI_EVENT_PKT
;
1733 return hci_recv_frame(hdev
, skb
);
1736 static int btusb_recv_bulk_intel(struct btusb_data
*data
, void *buffer
,
1739 /* When the device is in bootloader mode, then it can send
1740 * events via the bulk endpoint. These events are treated the
1741 * same way as the ones received from the interrupt endpoint.
1743 if (test_bit(BTUSB_BOOTLOADER
, &data
->flags
))
1744 return btusb_recv_intr(data
, buffer
, count
);
1746 return btusb_recv_bulk(data
, buffer
, count
);
1749 static void btusb_intel_bootup(struct btusb_data
*data
, const void *ptr
,
1752 const struct intel_bootup
*evt
= ptr
;
1754 if (len
!= sizeof(*evt
))
1757 if (test_and_clear_bit(BTUSB_BOOTING
, &data
->flags
)) {
1758 smp_mb__after_atomic();
1759 wake_up_bit(&data
->flags
, BTUSB_BOOTING
);
1763 static void btusb_intel_secure_send_result(struct btusb_data
*data
,
1764 const void *ptr
, unsigned int len
)
1766 const struct intel_secure_send_result
*evt
= ptr
;
1768 if (len
!= sizeof(*evt
))
1772 set_bit(BTUSB_FIRMWARE_FAILED
, &data
->flags
);
1774 if (test_and_clear_bit(BTUSB_DOWNLOADING
, &data
->flags
) &&
1775 test_bit(BTUSB_FIRMWARE_LOADED
, &data
->flags
)) {
1776 smp_mb__after_atomic();
1777 wake_up_bit(&data
->flags
, BTUSB_DOWNLOADING
);
1781 static int btusb_recv_event_intel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1783 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1785 if (test_bit(BTUSB_BOOTLOADER
, &data
->flags
)) {
1786 struct hci_event_hdr
*hdr
= (void *)skb
->data
;
1788 if (skb
->len
> HCI_EVENT_HDR_SIZE
&& hdr
->evt
== 0xff &&
1790 const void *ptr
= skb
->data
+ HCI_EVENT_HDR_SIZE
+ 1;
1791 unsigned int len
= skb
->len
- HCI_EVENT_HDR_SIZE
- 1;
1793 switch (skb
->data
[2]) {
1795 /* When switching to the operational firmware
1796 * the device sends a vendor specific event
1797 * indicating that the bootup completed.
1799 btusb_intel_bootup(data
, ptr
, len
);
1802 /* When the firmware loading completes the
1803 * device sends out a vendor specific event
1804 * indicating the result of the firmware
1807 btusb_intel_secure_send_result(data
, ptr
, len
);
1813 return hci_recv_frame(hdev
, skb
);
1816 static int btusb_send_frame_intel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1818 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1821 BT_DBG("%s", hdev
->name
);
1823 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1826 switch (bt_cb(skb
)->pkt_type
) {
1827 case HCI_COMMAND_PKT
:
1828 if (test_bit(BTUSB_BOOTLOADER
, &data
->flags
)) {
1829 struct hci_command_hdr
*cmd
= (void *)skb
->data
;
1830 __u16 opcode
= le16_to_cpu(cmd
->opcode
);
1832 /* When in bootloader mode and the command 0xfc09
1833 * is received, it needs to be send down the
1834 * bulk endpoint. So allocate a bulk URB instead.
1836 if (opcode
== 0xfc09)
1837 urb
= alloc_bulk_urb(hdev
, skb
);
1839 urb
= alloc_ctrl_urb(hdev
, skb
);
1841 /* When the 0xfc01 command is issued to boot into
1842 * the operational firmware, it will actually not
1843 * send a command complete event. To keep the flow
1844 * control working inject that event here.
1846 if (opcode
== 0xfc01)
1847 inject_cmd_complete(hdev
, opcode
);
1849 urb
= alloc_ctrl_urb(hdev
, skb
);
1852 return PTR_ERR(urb
);
1854 hdev
->stat
.cmd_tx
++;
1855 return submit_or_queue_tx_urb(hdev
, urb
);
1857 case HCI_ACLDATA_PKT
:
1858 urb
= alloc_bulk_urb(hdev
, skb
);
1860 return PTR_ERR(urb
);
1862 hdev
->stat
.acl_tx
++;
1863 return submit_or_queue_tx_urb(hdev
, urb
);
1865 case HCI_SCODATA_PKT
:
1866 if (hci_conn_num(hdev
, SCO_LINK
) < 1)
1869 urb
= alloc_isoc_urb(hdev
, skb
);
1871 return PTR_ERR(urb
);
1873 hdev
->stat
.sco_tx
++;
1874 return submit_tx_urb(hdev
, urb
);
1880 static int btusb_intel_secure_send(struct hci_dev
*hdev
, u8 fragment_type
,
1881 u32 plen
, const void *param
)
1884 struct sk_buff
*skb
;
1885 u8 cmd_param
[253], fragment_len
= (plen
> 252) ? 252 : plen
;
1887 cmd_param
[0] = fragment_type
;
1888 memcpy(cmd_param
+ 1, param
, fragment_len
);
1890 skb
= __hci_cmd_sync(hdev
, 0xfc09, fragment_len
+ 1,
1891 cmd_param
, HCI_INIT_TIMEOUT
);
1893 return PTR_ERR(skb
);
1897 plen
-= fragment_len
;
1898 param
+= fragment_len
;
1904 static void btusb_intel_version_info(struct hci_dev
*hdev
,
1905 struct intel_version
*ver
)
1907 const char *variant
;
1909 switch (ver
->fw_variant
) {
1911 variant
= "Bootloader";
1914 variant
= "Firmware";
1920 BT_INFO("%s: %s revision %u.%u build %u week %u %u", hdev
->name
,
1921 variant
, ver
->fw_revision
>> 4, ver
->fw_revision
& 0x0f,
1922 ver
->fw_build_num
, ver
->fw_build_ww
, 2000 + ver
->fw_build_yy
);
1925 static int btusb_setup_intel_new(struct hci_dev
*hdev
)
1927 static const u8 reset_param
[] = { 0x00, 0x01, 0x00, 0x01,
1928 0x00, 0x08, 0x04, 0x00 };
1929 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1930 struct sk_buff
*skb
;
1931 struct intel_version
*ver
;
1932 struct intel_boot_params
*params
;
1933 const struct firmware
*fw
;
1936 ktime_t calltime
, delta
, rettime
;
1937 unsigned long long duration
;
1940 BT_DBG("%s", hdev
->name
);
1942 calltime
= ktime_get();
1944 /* Read the Intel version information to determine if the device
1945 * is in bootloader mode or if it already has operational firmware
1948 skb
= __hci_cmd_sync(hdev
, 0xfc05, 0, NULL
, HCI_INIT_TIMEOUT
);
1950 BT_ERR("%s: Reading Intel version information failed (%ld)",
1951 hdev
->name
, PTR_ERR(skb
));
1952 return PTR_ERR(skb
);
1955 if (skb
->len
!= sizeof(*ver
)) {
1956 BT_ERR("%s: Intel version event size mismatch", hdev
->name
);
1961 ver
= (struct intel_version
*)skb
->data
;
1963 BT_ERR("%s: Intel version command failure (%02x)",
1964 hdev
->name
, ver
->status
);
1965 err
= -bt_to_errno(ver
->status
);
1970 /* The hardware platform number has a fixed value of 0x37 and
1971 * for now only accept this single value.
1973 if (ver
->hw_platform
!= 0x37) {
1974 BT_ERR("%s: Unsupported Intel hardware platform (%u)",
1975 hdev
->name
, ver
->hw_platform
);
1980 /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is
1981 * supported by this firmware loading method. This check has been
1982 * put in place to ensure correct forward compatibility options
1983 * when newer hardware variants come along.
1985 if (ver
->hw_variant
!= 0x0b) {
1986 BT_ERR("%s: Unsupported Intel hardware variant (%u)",
1987 hdev
->name
, ver
->hw_variant
);
1992 btusb_intel_version_info(hdev
, ver
);
1994 /* The firmware variant determines if the device is in bootloader
1995 * mode or is running operational firmware. The value 0x06 identifies
1996 * the bootloader and the value 0x23 identifies the operational
1999 * When the operational firmware is already present, then only
2000 * the check for valid Bluetooth device address is needed. This
2001 * determines if the device will be added as configured or
2002 * unconfigured controller.
2004 * It is not possible to use the Secure Boot Parameters in this
2005 * case since that command is only available in bootloader mode.
2007 if (ver
->fw_variant
== 0x23) {
2009 clear_bit(BTUSB_BOOTLOADER
, &data
->flags
);
2010 btintel_check_bdaddr(hdev
);
2014 /* If the device is not in bootloader mode, then the only possible
2015 * choice is to return an error and abort the device initialization.
2017 if (ver
->fw_variant
!= 0x06) {
2018 BT_ERR("%s: Unsupported Intel firmware variant (%u)",
2019 hdev
->name
, ver
->fw_variant
);
2026 /* Read the secure boot parameters to identify the operating
2027 * details of the bootloader.
2029 skb
= __hci_cmd_sync(hdev
, 0xfc0d, 0, NULL
, HCI_INIT_TIMEOUT
);
2031 BT_ERR("%s: Reading Intel boot parameters failed (%ld)",
2032 hdev
->name
, PTR_ERR(skb
));
2033 return PTR_ERR(skb
);
2036 if (skb
->len
!= sizeof(*params
)) {
2037 BT_ERR("%s: Intel boot parameters size mismatch", hdev
->name
);
2042 params
= (struct intel_boot_params
*)skb
->data
;
2043 if (params
->status
) {
2044 BT_ERR("%s: Intel boot parameters command failure (%02x)",
2045 hdev
->name
, params
->status
);
2046 err
= -bt_to_errno(params
->status
);
2051 BT_INFO("%s: Device revision is %u", hdev
->name
,
2052 le16_to_cpu(params
->dev_revid
));
2054 BT_INFO("%s: Secure boot is %s", hdev
->name
,
2055 params
->secure_boot
? "enabled" : "disabled");
2057 BT_INFO("%s: Minimum firmware build %u week %u %u", hdev
->name
,
2058 params
->min_fw_build_nn
, params
->min_fw_build_cw
,
2059 2000 + params
->min_fw_build_yy
);
2061 /* It is required that every single firmware fragment is acknowledged
2062 * with a command complete event. If the boot parameters indicate
2063 * that this bootloader does not send them, then abort the setup.
2065 if (params
->limited_cce
!= 0x00) {
2066 BT_ERR("%s: Unsupported Intel firmware loading method (%u)",
2067 hdev
->name
, params
->limited_cce
);
2072 /* If the OTP has no valid Bluetooth device address, then there will
2073 * also be no valid address for the operational firmware.
2075 if (!bacmp(¶ms
->otp_bdaddr
, BDADDR_ANY
)) {
2076 BT_INFO("%s: No device address configured", hdev
->name
);
2077 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
2080 /* With this Intel bootloader only the hardware variant and device
2081 * revision information are used to select the right firmware.
2083 * Currently this bootloader support is limited to hardware variant
2084 * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b).
2086 snprintf(fwname
, sizeof(fwname
), "intel/ibt-11-%u.sfi",
2087 le16_to_cpu(params
->dev_revid
));
2089 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
2091 BT_ERR("%s: Failed to load Intel firmware file (%d)",
2097 BT_INFO("%s: Found device firmware: %s", hdev
->name
, fwname
);
2101 if (fw
->size
< 644) {
2102 BT_ERR("%s: Invalid size of firmware file (%zu)",
2103 hdev
->name
, fw
->size
);
2108 set_bit(BTUSB_DOWNLOADING
, &data
->flags
);
2110 /* Start the firmware download transaction with the Init fragment
2111 * represented by the 128 bytes of CSS header.
2113 err
= btusb_intel_secure_send(hdev
, 0x00, 128, fw
->data
);
2115 BT_ERR("%s: Failed to send firmware header (%d)",
2120 /* Send the 256 bytes of public key information from the firmware
2121 * as the PKey fragment.
2123 err
= btusb_intel_secure_send(hdev
, 0x03, 256, fw
->data
+ 128);
2125 BT_ERR("%s: Failed to send firmware public key (%d)",
2130 /* Send the 256 bytes of signature information from the firmware
2131 * as the Sign fragment.
2133 err
= btusb_intel_secure_send(hdev
, 0x02, 256, fw
->data
+ 388);
2135 BT_ERR("%s: Failed to send firmware signature (%d)",
2140 fw_ptr
= fw
->data
+ 644;
2142 while (fw_ptr
- fw
->data
< fw
->size
) {
2143 struct hci_command_hdr
*cmd
= (void *)fw_ptr
;
2146 cmd_len
= sizeof(*cmd
) + cmd
->plen
;
2148 /* Send each command from the firmware data buffer as
2149 * a single Data fragment.
2151 err
= btusb_intel_secure_send(hdev
, 0x01, cmd_len
, fw_ptr
);
2153 BT_ERR("%s: Failed to send firmware data (%d)",
2161 set_bit(BTUSB_FIRMWARE_LOADED
, &data
->flags
);
2163 BT_INFO("%s: Waiting for firmware download to complete", hdev
->name
);
2165 /* Before switching the device into operational mode and with that
2166 * booting the loaded firmware, wait for the bootloader notification
2167 * that all fragments have been successfully received.
2169 * When the event processing receives the notification, then the
2170 * BTUSB_DOWNLOADING flag will be cleared.
2172 * The firmware loading should not take longer than 5 seconds
2173 * and thus just timeout if that happens and fail the setup
2176 err
= wait_on_bit_timeout(&data
->flags
, BTUSB_DOWNLOADING
,
2178 msecs_to_jiffies(5000));
2180 BT_ERR("%s: Firmware loading interrupted", hdev
->name
);
2186 BT_ERR("%s: Firmware loading timeout", hdev
->name
);
2191 if (test_bit(BTUSB_FIRMWARE_FAILED
, &data
->flags
)) {
2192 BT_ERR("%s: Firmware loading failed", hdev
->name
);
2197 rettime
= ktime_get();
2198 delta
= ktime_sub(rettime
, calltime
);
2199 duration
= (unsigned long long) ktime_to_ns(delta
) >> 10;
2201 BT_INFO("%s: Firmware loaded in %llu usecs", hdev
->name
, duration
);
2204 release_firmware(fw
);
2209 calltime
= ktime_get();
2211 set_bit(BTUSB_BOOTING
, &data
->flags
);
2213 skb
= __hci_cmd_sync(hdev
, 0xfc01, sizeof(reset_param
), reset_param
,
2216 return PTR_ERR(skb
);
2220 /* The bootloader will not indicate when the device is ready. This
2221 * is done by the operational firmware sending bootup notification.
2223 * Booting into operational firmware should not take longer than
2224 * 1 second. However if that happens, then just fail the setup
2225 * since something went wrong.
2227 BT_INFO("%s: Waiting for device to boot", hdev
->name
);
2229 err
= wait_on_bit_timeout(&data
->flags
, BTUSB_BOOTING
,
2231 msecs_to_jiffies(1000));
2234 BT_ERR("%s: Device boot interrupted", hdev
->name
);
2239 BT_ERR("%s: Device boot timeout", hdev
->name
);
2243 rettime
= ktime_get();
2244 delta
= ktime_sub(rettime
, calltime
);
2245 duration
= (unsigned long long) ktime_to_ns(delta
) >> 10;
2247 BT_INFO("%s: Device booted in %llu usecs", hdev
->name
, duration
);
2249 clear_bit(BTUSB_BOOTLOADER
, &data
->flags
);
2254 static void btusb_hw_error_intel(struct hci_dev
*hdev
, u8 code
)
2256 struct sk_buff
*skb
;
2259 BT_ERR("%s: Hardware error 0x%2.2x", hdev
->name
, code
);
2261 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
2263 BT_ERR("%s: Reset after hardware error failed (%ld)",
2264 hdev
->name
, PTR_ERR(skb
));
2269 skb
= __hci_cmd_sync(hdev
, 0xfc22, 1, &type
, HCI_INIT_TIMEOUT
);
2271 BT_ERR("%s: Retrieving Intel exception info failed (%ld)",
2272 hdev
->name
, PTR_ERR(skb
));
2276 if (skb
->len
!= 13) {
2277 BT_ERR("%s: Exception info size mismatch", hdev
->name
);
2282 if (skb
->data
[0] != 0x00) {
2283 BT_ERR("%s: Exception info command failure (%02x)",
2284 hdev
->name
, skb
->data
[0]);
2289 BT_ERR("%s: Exception info %s", hdev
->name
, (char *)(skb
->data
+ 1));
2294 static int btusb_shutdown_intel(struct hci_dev
*hdev
)
2296 struct sk_buff
*skb
;
2299 /* Some platforms have an issue with BT LED when the interface is
2300 * down or BT radio is turned off, which takes 5 seconds to BT LED
2301 * goes off. This command turns off the BT LED immediately.
2303 skb
= __hci_cmd_sync(hdev
, 0xfc3f, 0, NULL
, HCI_INIT_TIMEOUT
);
2306 BT_ERR("%s: turning off Intel device LED failed (%ld)",
2315 static int btusb_set_bdaddr_marvell(struct hci_dev
*hdev
,
2316 const bdaddr_t
*bdaddr
)
2318 struct sk_buff
*skb
;
2323 buf
[1] = sizeof(bdaddr_t
);
2324 memcpy(buf
+ 2, bdaddr
, sizeof(bdaddr_t
));
2326 skb
= __hci_cmd_sync(hdev
, 0xfc22, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
2329 BT_ERR("%s: changing Marvell device address failed (%ld)",
2338 static int btusb_set_bdaddr_ath3012(struct hci_dev
*hdev
,
2339 const bdaddr_t
*bdaddr
)
2341 struct sk_buff
*skb
;
2348 buf
[3] = sizeof(bdaddr_t
);
2349 memcpy(buf
+ 4, bdaddr
, sizeof(bdaddr_t
));
2351 skb
= __hci_cmd_sync(hdev
, 0xfc0b, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
2354 BT_ERR("%s: Change address command failed (%ld)",
2363 #define QCA_DFU_PACKET_LEN 4096
2365 #define QCA_GET_TARGET_VERSION 0x09
2366 #define QCA_CHECK_STATUS 0x05
2367 #define QCA_DFU_DOWNLOAD 0x01
2369 #define QCA_SYSCFG_UPDATED 0x40
2370 #define QCA_PATCH_UPDATED 0x80
2371 #define QCA_DFU_TIMEOUT 3000
2373 struct qca_version
{
2375 __le32 patch_version
;
2381 struct qca_rampatch_version
{
2383 __le16 patch_version
;
2386 struct qca_device_info
{
2388 u8 rampatch_hdr
; /* length of header in rampatch */
2389 u8 nvm_hdr
; /* length of header in NVM */
2390 u8 ver_offset
; /* offset of version structure in rampatch */
2393 static const struct qca_device_info qca_devices_table
[] = {
2394 { 0x00000100, 20, 4, 10 }, /* Rome 1.0 */
2395 { 0x00000101, 20, 4, 10 }, /* Rome 1.1 */
2396 { 0x00000201, 28, 4, 18 }, /* Rome 2.1 */
2397 { 0x00000300, 28, 4, 18 }, /* Rome 3.0 */
2398 { 0x00000302, 28, 4, 18 }, /* Rome 3.2 */
2401 static int btusb_qca_send_vendor_req(struct hci_dev
*hdev
, u8 request
,
2402 void *data
, u16 size
)
2404 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
2405 struct usb_device
*udev
= btdata
->udev
;
2409 buf
= kmalloc(size
, GFP_KERNEL
);
2413 /* Found some of USB hosts have IOT issues with ours so that we should
2414 * not wait until HCI layer is ready.
2416 pipe
= usb_rcvctrlpipe(udev
, 0);
2417 err
= usb_control_msg(udev
, pipe
, request
, USB_TYPE_VENDOR
| USB_DIR_IN
,
2418 0, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
2420 BT_ERR("%s: Failed to access otp area (%d)", hdev
->name
, err
);
2424 memcpy(data
, buf
, size
);
2432 static int btusb_setup_qca_download_fw(struct hci_dev
*hdev
,
2433 const struct firmware
*firmware
,
2436 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
2437 struct usb_device
*udev
= btdata
->udev
;
2438 size_t count
, size
, sent
= 0;
2442 buf
= kmalloc(QCA_DFU_PACKET_LEN
, GFP_KERNEL
);
2446 count
= firmware
->size
;
2448 size
= min_t(size_t, count
, hdr_size
);
2449 memcpy(buf
, firmware
->data
, size
);
2451 /* USB patches should go down to controller through USB path
2452 * because binary format fits to go down through USB channel.
2453 * USB control path is for patching headers and USB bulk is for
2456 pipe
= usb_sndctrlpipe(udev
, 0);
2457 err
= usb_control_msg(udev
, pipe
, QCA_DFU_DOWNLOAD
, USB_TYPE_VENDOR
,
2458 0, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
2460 BT_ERR("%s: Failed to send headers (%d)", hdev
->name
, err
);
2468 size
= min_t(size_t, count
, QCA_DFU_PACKET_LEN
);
2470 memcpy(buf
, firmware
->data
+ sent
, size
);
2472 pipe
= usb_sndbulkpipe(udev
, 0x02);
2473 err
= usb_bulk_msg(udev
, pipe
, buf
, size
, &len
,
2476 BT_ERR("%s: Failed to send body at %zd of %zd (%d)",
2477 hdev
->name
, sent
, firmware
->size
, err
);
2482 BT_ERR("%s: Failed to get bulk buffer", hdev
->name
);
2496 static int btusb_setup_qca_load_rampatch(struct hci_dev
*hdev
,
2497 struct qca_version
*ver
,
2498 const struct qca_device_info
*info
)
2500 struct qca_rampatch_version
*rver
;
2501 const struct firmware
*fw
;
2502 u32 ver_rom
, ver_patch
;
2503 u16 rver_rom
, rver_patch
;
2507 ver_rom
= le32_to_cpu(ver
->rom_version
);
2508 ver_patch
= le32_to_cpu(ver
->patch_version
);
2510 snprintf(fwname
, sizeof(fwname
), "qca/rampatch_usb_%08x.bin", ver_rom
);
2512 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
2514 BT_ERR("%s: failed to request rampatch file: %s (%d)",
2515 hdev
->name
, fwname
, err
);
2519 BT_INFO("%s: using rampatch file: %s", hdev
->name
, fwname
);
2521 rver
= (struct qca_rampatch_version
*)(fw
->data
+ info
->ver_offset
);
2522 rver_rom
= le16_to_cpu(rver
->rom_version
);
2523 rver_patch
= le16_to_cpu(rver
->patch_version
);
2525 BT_INFO("%s: QCA: patch rome 0x%x build 0x%x, firmware rome 0x%x "
2526 "build 0x%x", hdev
->name
, rver_rom
, rver_patch
, ver_rom
,
2529 if (rver_rom
!= ver_rom
|| rver_patch
<= ver_patch
) {
2530 BT_ERR("%s: rampatch file version did not match with firmware",
2536 err
= btusb_setup_qca_download_fw(hdev
, fw
, info
->rampatch_hdr
);
2539 release_firmware(fw
);
2544 static int btusb_setup_qca_load_nvm(struct hci_dev
*hdev
,
2545 struct qca_version
*ver
,
2546 const struct qca_device_info
*info
)
2548 const struct firmware
*fw
;
2552 snprintf(fwname
, sizeof(fwname
), "qca/nvm_usb_%08x.bin",
2553 le32_to_cpu(ver
->rom_version
));
2555 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
2557 BT_ERR("%s: failed to request NVM file: %s (%d)",
2558 hdev
->name
, fwname
, err
);
2562 BT_INFO("%s: using NVM file: %s", hdev
->name
, fwname
);
2564 err
= btusb_setup_qca_download_fw(hdev
, fw
, info
->nvm_hdr
);
2566 release_firmware(fw
);
2571 static int btusb_setup_qca(struct hci_dev
*hdev
)
2573 const struct qca_device_info
*info
= NULL
;
2574 struct qca_version ver
;
2579 err
= btusb_qca_send_vendor_req(hdev
, QCA_GET_TARGET_VERSION
, &ver
,
2584 ver_rom
= le32_to_cpu(ver
.rom_version
);
2585 for (i
= 0; i
< ARRAY_SIZE(qca_devices_table
); i
++) {
2586 if (ver_rom
== qca_devices_table
[i
].rom_version
)
2587 info
= &qca_devices_table
[i
];
2590 BT_ERR("%s: don't support firmware rome 0x%x", hdev
->name
,
2595 err
= btusb_qca_send_vendor_req(hdev
, QCA_CHECK_STATUS
, &status
,
2600 if (!(status
& QCA_PATCH_UPDATED
)) {
2601 err
= btusb_setup_qca_load_rampatch(hdev
, &ver
, info
);
2606 if (!(status
& QCA_SYSCFG_UPDATED
)) {
2607 err
= btusb_setup_qca_load_nvm(hdev
, &ver
, info
);
2615 static int btusb_probe(struct usb_interface
*intf
,
2616 const struct usb_device_id
*id
)
2618 struct usb_endpoint_descriptor
*ep_desc
;
2619 struct btusb_data
*data
;
2620 struct hci_dev
*hdev
;
2623 BT_DBG("intf %p id %p", intf
, id
);
2625 /* interface numbers are hardcoded in the spec */
2626 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
2629 if (!id
->driver_info
) {
2630 const struct usb_device_id
*match
;
2632 match
= usb_match_id(intf
, blacklist_table
);
2637 if (id
->driver_info
== BTUSB_IGNORE
)
2640 if (id
->driver_info
& BTUSB_ATH3012
) {
2641 struct usb_device
*udev
= interface_to_usbdev(intf
);
2643 /* Old firmware would otherwise let ath3k driver load
2644 * patch and sysconfig files */
2645 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) <= 0x0001)
2649 data
= devm_kzalloc(&intf
->dev
, sizeof(*data
), GFP_KERNEL
);
2653 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
2654 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
2656 if (!data
->intr_ep
&& usb_endpoint_is_int_in(ep_desc
)) {
2657 data
->intr_ep
= ep_desc
;
2661 if (!data
->bulk_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
2662 data
->bulk_tx_ep
= ep_desc
;
2666 if (!data
->bulk_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
2667 data
->bulk_rx_ep
= ep_desc
;
2672 if (!data
->intr_ep
|| !data
->bulk_tx_ep
|| !data
->bulk_rx_ep
)
2675 if (id
->driver_info
& BTUSB_AMP
) {
2676 data
->cmdreq_type
= USB_TYPE_CLASS
| 0x01;
2677 data
->cmdreq
= 0x2b;
2679 data
->cmdreq_type
= USB_TYPE_CLASS
;
2680 data
->cmdreq
= 0x00;
2683 data
->udev
= interface_to_usbdev(intf
);
2686 INIT_WORK(&data
->work
, btusb_work
);
2687 INIT_WORK(&data
->waker
, btusb_waker
);
2688 init_usb_anchor(&data
->deferred
);
2689 init_usb_anchor(&data
->tx_anchor
);
2690 spin_lock_init(&data
->txlock
);
2692 init_usb_anchor(&data
->intr_anchor
);
2693 init_usb_anchor(&data
->bulk_anchor
);
2694 init_usb_anchor(&data
->isoc_anchor
);
2695 spin_lock_init(&data
->rxlock
);
2697 if (id
->driver_info
& BTUSB_INTEL_NEW
) {
2698 data
->recv_event
= btusb_recv_event_intel
;
2699 data
->recv_bulk
= btusb_recv_bulk_intel
;
2700 set_bit(BTUSB_BOOTLOADER
, &data
->flags
);
2702 data
->recv_event
= hci_recv_frame
;
2703 data
->recv_bulk
= btusb_recv_bulk
;
2706 hdev
= hci_alloc_dev();
2710 hdev
->bus
= HCI_USB
;
2711 hci_set_drvdata(hdev
, data
);
2713 if (id
->driver_info
& BTUSB_AMP
)
2714 hdev
->dev_type
= HCI_AMP
;
2716 hdev
->dev_type
= HCI_BREDR
;
2720 SET_HCIDEV_DEV(hdev
, &intf
->dev
);
2722 hdev
->open
= btusb_open
;
2723 hdev
->close
= btusb_close
;
2724 hdev
->flush
= btusb_flush
;
2725 hdev
->send
= btusb_send_frame
;
2726 hdev
->notify
= btusb_notify
;
2728 if (id
->driver_info
& BTUSB_BCM92035
)
2729 hdev
->setup
= btusb_setup_bcm92035
;
2731 #ifdef CONFIG_BT_HCIBTUSB_BCM
2732 if (id
->driver_info
& BTUSB_BCM_PATCHRAM
) {
2733 hdev
->setup
= btbcm_setup_patchram
;
2734 hdev
->set_bdaddr
= btbcm_set_bdaddr
;
2737 if (id
->driver_info
& BTUSB_BCM_APPLE
)
2738 hdev
->setup
= btbcm_setup_apple
;
2741 if (id
->driver_info
& BTUSB_INTEL
) {
2742 hdev
->setup
= btusb_setup_intel
;
2743 hdev
->shutdown
= btusb_shutdown_intel
;
2744 hdev
->set_bdaddr
= btintel_set_bdaddr
;
2745 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
2746 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2749 if (id
->driver_info
& BTUSB_INTEL_NEW
) {
2750 hdev
->send
= btusb_send_frame_intel
;
2751 hdev
->setup
= btusb_setup_intel_new
;
2752 hdev
->hw_error
= btusb_hw_error_intel
;
2753 hdev
->set_bdaddr
= btintel_set_bdaddr
;
2754 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
2757 if (id
->driver_info
& BTUSB_MARVELL
)
2758 hdev
->set_bdaddr
= btusb_set_bdaddr_marvell
;
2760 if (id
->driver_info
& BTUSB_SWAVE
) {
2761 set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE
, &hdev
->quirks
);
2762 set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS
, &hdev
->quirks
);
2765 if (id
->driver_info
& BTUSB_INTEL_BOOT
)
2766 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
2768 if (id
->driver_info
& BTUSB_ATH3012
) {
2769 hdev
->set_bdaddr
= btusb_set_bdaddr_ath3012
;
2770 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2771 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
2774 if (id
->driver_info
& BTUSB_QCA_ROME
) {
2775 data
->setup_on_usb
= btusb_setup_qca
;
2776 hdev
->set_bdaddr
= btusb_set_bdaddr_ath3012
;
2779 if (id
->driver_info
& BTUSB_AMP
) {
2780 /* AMP controllers do not support SCO packets */
2783 /* Interface numbers are hardcoded in the specification */
2784 data
->isoc
= usb_ifnum_to_if(data
->udev
, 1);
2788 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2790 if (force_scofix
|| id
->driver_info
& BTUSB_WRONG_SCO_MTU
) {
2791 if (!disable_scofix
)
2792 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
);
2795 if (id
->driver_info
& BTUSB_BROKEN_ISOC
)
2798 if (id
->driver_info
& BTUSB_DIGIANSWER
) {
2799 data
->cmdreq_type
= USB_TYPE_VENDOR
;
2800 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2803 if (id
->driver_info
& BTUSB_CSR
) {
2804 struct usb_device
*udev
= data
->udev
;
2805 u16 bcdDevice
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
2807 /* Old firmware would otherwise execute USB reset */
2808 if (bcdDevice
< 0x117)
2809 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2811 /* Fake CSR devices with broken commands */
2812 if (bcdDevice
<= 0x100)
2813 hdev
->setup
= btusb_setup_csr
;
2815 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2818 if (id
->driver_info
& BTUSB_SNIFFER
) {
2819 struct usb_device
*udev
= data
->udev
;
2821 /* New sniffer firmware has crippled HCI interface */
2822 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) > 0x997)
2823 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
2826 if (id
->driver_info
& BTUSB_INTEL_BOOT
) {
2827 /* A bug in the bootloader causes that interrupt interface is
2828 * only enabled after receiving SetInterface(0, AltSetting=0).
2830 err
= usb_set_interface(data
->udev
, 0, 0);
2832 BT_ERR("failed to set interface 0, alt 0 %d", err
);
2839 err
= usb_driver_claim_interface(&btusb_driver
,
2847 err
= hci_register_dev(hdev
);
2853 usb_set_intfdata(intf
, data
);
2858 static void btusb_disconnect(struct usb_interface
*intf
)
2860 struct btusb_data
*data
= usb_get_intfdata(intf
);
2861 struct hci_dev
*hdev
;
2863 BT_DBG("intf %p", intf
);
2869 usb_set_intfdata(data
->intf
, NULL
);
2872 usb_set_intfdata(data
->isoc
, NULL
);
2874 hci_unregister_dev(hdev
);
2876 if (intf
== data
->isoc
)
2877 usb_driver_release_interface(&btusb_driver
, data
->intf
);
2878 else if (data
->isoc
)
2879 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
2885 static int btusb_suspend(struct usb_interface
*intf
, pm_message_t message
)
2887 struct btusb_data
*data
= usb_get_intfdata(intf
);
2889 BT_DBG("intf %p", intf
);
2891 if (data
->suspend_count
++)
2894 spin_lock_irq(&data
->txlock
);
2895 if (!(PMSG_IS_AUTO(message
) && data
->tx_in_flight
)) {
2896 set_bit(BTUSB_SUSPENDING
, &data
->flags
);
2897 spin_unlock_irq(&data
->txlock
);
2899 spin_unlock_irq(&data
->txlock
);
2900 data
->suspend_count
--;
2904 cancel_work_sync(&data
->work
);
2906 btusb_stop_traffic(data
);
2907 usb_kill_anchored_urbs(&data
->tx_anchor
);
2912 static void play_deferred(struct btusb_data
*data
)
2917 while ((urb
= usb_get_from_anchor(&data
->deferred
))) {
2918 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
2922 data
->tx_in_flight
++;
2924 usb_scuttle_anchored_urbs(&data
->deferred
);
2927 static int btusb_resume(struct usb_interface
*intf
)
2929 struct btusb_data
*data
= usb_get_intfdata(intf
);
2930 struct hci_dev
*hdev
= data
->hdev
;
2933 BT_DBG("intf %p", intf
);
2935 if (--data
->suspend_count
)
2938 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
2941 if (test_bit(BTUSB_INTR_RUNNING
, &data
->flags
)) {
2942 err
= btusb_submit_intr_urb(hdev
, GFP_NOIO
);
2944 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
2949 if (test_bit(BTUSB_BULK_RUNNING
, &data
->flags
)) {
2950 err
= btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
2952 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
2956 btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
2959 if (test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
2960 if (btusb_submit_isoc_urb(hdev
, GFP_NOIO
) < 0)
2961 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
2963 btusb_submit_isoc_urb(hdev
, GFP_NOIO
);
2966 spin_lock_irq(&data
->txlock
);
2967 play_deferred(data
);
2968 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
2969 spin_unlock_irq(&data
->txlock
);
2970 schedule_work(&data
->work
);
2975 usb_scuttle_anchored_urbs(&data
->deferred
);
2977 spin_lock_irq(&data
->txlock
);
2978 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
2979 spin_unlock_irq(&data
->txlock
);
2985 static struct usb_driver btusb_driver
= {
2987 .probe
= btusb_probe
,
2988 .disconnect
= btusb_disconnect
,
2990 .suspend
= btusb_suspend
,
2991 .resume
= btusb_resume
,
2993 .id_table
= btusb_table
,
2994 .supports_autosuspend
= 1,
2995 .disable_hub_initiated_lpm
= 1,
2998 module_usb_driver(btusb_driver
);
3000 module_param(disable_scofix
, bool, 0644);
3001 MODULE_PARM_DESC(disable_scofix
, "Disable fixup of wrong SCO buffer size");
3003 module_param(force_scofix
, bool, 0644);
3004 MODULE_PARM_DESC(force_scofix
, "Force fixup of wrong SCO buffers size");
3006 module_param(reset
, bool, 0644);
3007 MODULE_PARM_DESC(reset
, "Send HCI reset command on initialization");
3009 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
3010 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION
);
3011 MODULE_VERSION(VERSION
);
3012 MODULE_LICENSE("GPL");