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>
27 #include <asm/unaligned.h>
29 #include <net/bluetooth/bluetooth.h>
30 #include <net/bluetooth/hci_core.h>
38 static bool disable_scofix
;
39 static bool force_scofix
;
41 static bool reset
= true;
43 static struct usb_driver btusb_driver
;
45 #define BTUSB_IGNORE 0x01
46 #define BTUSB_DIGIANSWER 0x02
47 #define BTUSB_CSR 0x04
48 #define BTUSB_SNIFFER 0x08
49 #define BTUSB_BCM92035 0x10
50 #define BTUSB_BROKEN_ISOC 0x20
51 #define BTUSB_WRONG_SCO_MTU 0x40
52 #define BTUSB_ATH3012 0x80
53 #define BTUSB_INTEL 0x100
54 #define BTUSB_INTEL_BOOT 0x200
55 #define BTUSB_BCM_PATCHRAM 0x400
56 #define BTUSB_MARVELL 0x800
57 #define BTUSB_SWAVE 0x1000
58 #define BTUSB_INTEL_NEW 0x2000
59 #define BTUSB_AMP 0x4000
60 #define BTUSB_QCA_ROME 0x8000
61 #define BTUSB_BCM_APPLE 0x10000
62 #define BTUSB_REALTEK 0x20000
64 static const struct usb_device_id btusb_table
[] = {
65 /* Generic Bluetooth USB device */
66 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
68 /* Generic Bluetooth AMP device */
69 { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info
= BTUSB_AMP
},
71 /* Generic Bluetooth USB interface */
72 { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) },
74 /* Apple-specific (Broadcom) devices */
75 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01),
76 .driver_info
= BTUSB_BCM_APPLE
},
78 /* MediaTek MT76x0E */
79 { USB_DEVICE(0x0e8d, 0x763f) },
81 /* Broadcom SoftSailing reporting vendor specific */
82 { USB_DEVICE(0x0a5c, 0x21e1) },
84 /* Apple MacBookPro 7,1 */
85 { USB_DEVICE(0x05ac, 0x8213) },
88 { USB_DEVICE(0x05ac, 0x8215) },
90 /* Apple MacBookPro6,2 */
91 { USB_DEVICE(0x05ac, 0x8218) },
93 /* Apple MacBookAir3,1, MacBookAir3,2 */
94 { USB_DEVICE(0x05ac, 0x821b) },
96 /* Apple MacBookAir4,1 */
97 { USB_DEVICE(0x05ac, 0x821f) },
99 /* Apple MacBookPro8,2 */
100 { USB_DEVICE(0x05ac, 0x821a) },
102 /* Apple MacMini5,1 */
103 { USB_DEVICE(0x05ac, 0x8281) },
105 /* AVM BlueFRITZ! USB v2.0 */
106 { USB_DEVICE(0x057c, 0x3800), .driver_info
= BTUSB_SWAVE
},
108 /* Bluetooth Ultraport Module from IBM */
109 { USB_DEVICE(0x04bf, 0x030a) },
111 /* ALPS Modules with non-standard id */
112 { USB_DEVICE(0x044e, 0x3001) },
113 { USB_DEVICE(0x044e, 0x3002) },
115 /* Ericsson with non-standard id */
116 { USB_DEVICE(0x0bdb, 0x1002) },
118 /* Canyon CN-BTU1 with HID interfaces */
119 { USB_DEVICE(0x0c10, 0x0000) },
121 /* Broadcom BCM20702A0 */
122 { USB_DEVICE(0x413c, 0x8197) },
124 /* Broadcom BCM20702B0 (Dynex/Insignia) */
125 { USB_DEVICE(0x19ff, 0x0239), .driver_info
= BTUSB_BCM_PATCHRAM
},
127 /* Foxconn - Hon Hai */
128 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
129 .driver_info
= BTUSB_BCM_PATCHRAM
},
131 /* Lite-On Technology - Broadcom based */
132 { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01),
133 .driver_info
= BTUSB_BCM_PATCHRAM
},
135 /* Broadcom devices with vendor specific id */
136 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
137 .driver_info
= BTUSB_BCM_PATCHRAM
},
139 /* ASUSTek Computer - Broadcom based */
140 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
141 .driver_info
= BTUSB_BCM_PATCHRAM
},
143 /* Belkin F8065bf - Broadcom based */
144 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01),
145 .driver_info
= BTUSB_BCM_PATCHRAM
},
147 /* IMC Networks - Broadcom based */
148 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01),
149 .driver_info
= BTUSB_BCM_PATCHRAM
},
151 /* Intel Bluetooth USB Bootloader (RAM module) */
152 { USB_DEVICE(0x8087, 0x0a5a),
153 .driver_info
= BTUSB_INTEL_BOOT
| BTUSB_BROKEN_ISOC
},
155 { } /* Terminating entry */
158 MODULE_DEVICE_TABLE(usb
, btusb_table
);
160 static const struct usb_device_id blacklist_table
[] = {
161 /* CSR BlueCore devices */
162 { USB_DEVICE(0x0a12, 0x0001), .driver_info
= BTUSB_CSR
},
164 /* Broadcom BCM2033 without firmware */
165 { USB_DEVICE(0x0a5c, 0x2033), .driver_info
= BTUSB_IGNORE
},
167 /* Atheros 3011 with sflash firmware */
168 { USB_DEVICE(0x0489, 0xe027), .driver_info
= BTUSB_IGNORE
},
169 { USB_DEVICE(0x0489, 0xe03d), .driver_info
= BTUSB_IGNORE
},
170 { USB_DEVICE(0x04f2, 0xaff1), .driver_info
= BTUSB_IGNORE
},
171 { USB_DEVICE(0x0930, 0x0215), .driver_info
= BTUSB_IGNORE
},
172 { USB_DEVICE(0x0cf3, 0x3002), .driver_info
= BTUSB_IGNORE
},
173 { USB_DEVICE(0x0cf3, 0xe019), .driver_info
= BTUSB_IGNORE
},
174 { USB_DEVICE(0x13d3, 0x3304), .driver_info
= BTUSB_IGNORE
},
176 /* Atheros AR9285 Malbec with sflash firmware */
177 { USB_DEVICE(0x03f0, 0x311d), .driver_info
= BTUSB_IGNORE
},
179 /* Atheros 3012 with sflash firmware */
180 { USB_DEVICE(0x0489, 0xe04d), .driver_info
= BTUSB_ATH3012
},
181 { USB_DEVICE(0x0489, 0xe04e), .driver_info
= BTUSB_ATH3012
},
182 { USB_DEVICE(0x0489, 0xe056), .driver_info
= BTUSB_ATH3012
},
183 { USB_DEVICE(0x0489, 0xe057), .driver_info
= BTUSB_ATH3012
},
184 { USB_DEVICE(0x0489, 0xe05f), .driver_info
= BTUSB_ATH3012
},
185 { USB_DEVICE(0x0489, 0xe076), .driver_info
= BTUSB_ATH3012
},
186 { USB_DEVICE(0x0489, 0xe078), .driver_info
= BTUSB_ATH3012
},
187 { USB_DEVICE(0x04c5, 0x1330), .driver_info
= BTUSB_ATH3012
},
188 { USB_DEVICE(0x04ca, 0x3004), .driver_info
= BTUSB_ATH3012
},
189 { USB_DEVICE(0x04ca, 0x3005), .driver_info
= BTUSB_ATH3012
},
190 { USB_DEVICE(0x04ca, 0x3006), .driver_info
= BTUSB_ATH3012
},
191 { USB_DEVICE(0x04ca, 0x3007), .driver_info
= BTUSB_ATH3012
},
192 { USB_DEVICE(0x04ca, 0x3008), .driver_info
= BTUSB_ATH3012
},
193 { USB_DEVICE(0x04ca, 0x300b), .driver_info
= BTUSB_ATH3012
},
194 { USB_DEVICE(0x04ca, 0x300d), .driver_info
= BTUSB_ATH3012
},
195 { USB_DEVICE(0x04ca, 0x300f), .driver_info
= BTUSB_ATH3012
},
196 { USB_DEVICE(0x04ca, 0x3010), .driver_info
= BTUSB_ATH3012
},
197 { USB_DEVICE(0x0930, 0x0219), .driver_info
= BTUSB_ATH3012
},
198 { USB_DEVICE(0x0930, 0x0220), .driver_info
= BTUSB_ATH3012
},
199 { USB_DEVICE(0x0930, 0x0227), .driver_info
= BTUSB_ATH3012
},
200 { USB_DEVICE(0x0b05, 0x17d0), .driver_info
= BTUSB_ATH3012
},
201 { USB_DEVICE(0x0cf3, 0x0036), .driver_info
= BTUSB_ATH3012
},
202 { USB_DEVICE(0x0cf3, 0x3004), .driver_info
= BTUSB_ATH3012
},
203 { USB_DEVICE(0x0cf3, 0x3008), .driver_info
= BTUSB_ATH3012
},
204 { USB_DEVICE(0x0cf3, 0x311d), .driver_info
= BTUSB_ATH3012
},
205 { USB_DEVICE(0x0cf3, 0x311e), .driver_info
= BTUSB_ATH3012
},
206 { USB_DEVICE(0x0cf3, 0x311f), .driver_info
= BTUSB_ATH3012
},
207 { USB_DEVICE(0x0cf3, 0x3121), .driver_info
= BTUSB_ATH3012
},
208 { USB_DEVICE(0x0cf3, 0x817a), .driver_info
= BTUSB_ATH3012
},
209 { USB_DEVICE(0x0cf3, 0xe003), .driver_info
= BTUSB_ATH3012
},
210 { USB_DEVICE(0x0cf3, 0xe004), .driver_info
= BTUSB_ATH3012
},
211 { USB_DEVICE(0x0cf3, 0xe005), .driver_info
= BTUSB_ATH3012
},
212 { USB_DEVICE(0x0cf3, 0xe006), .driver_info
= BTUSB_ATH3012
},
213 { USB_DEVICE(0x13d3, 0x3362), .driver_info
= BTUSB_ATH3012
},
214 { USB_DEVICE(0x13d3, 0x3375), .driver_info
= BTUSB_ATH3012
},
215 { USB_DEVICE(0x13d3, 0x3393), .driver_info
= BTUSB_ATH3012
},
216 { USB_DEVICE(0x13d3, 0x3402), .driver_info
= BTUSB_ATH3012
},
217 { USB_DEVICE(0x13d3, 0x3408), .driver_info
= BTUSB_ATH3012
},
218 { USB_DEVICE(0x13d3, 0x3423), .driver_info
= BTUSB_ATH3012
},
219 { USB_DEVICE(0x13d3, 0x3432), .driver_info
= BTUSB_ATH3012
},
220 { USB_DEVICE(0x13d3, 0x3474), .driver_info
= BTUSB_ATH3012
},
222 /* Atheros AR5BBU12 with sflash firmware */
223 { USB_DEVICE(0x0489, 0xe02c), .driver_info
= BTUSB_IGNORE
},
225 /* Atheros AR5BBU12 with sflash firmware */
226 { USB_DEVICE(0x0489, 0xe036), .driver_info
= BTUSB_ATH3012
},
227 { USB_DEVICE(0x0489, 0xe03c), .driver_info
= BTUSB_ATH3012
},
229 /* QCA ROME chipset */
230 { USB_DEVICE(0x0cf3, 0xe007), .driver_info
= BTUSB_QCA_ROME
},
231 { USB_DEVICE(0x0cf3, 0xe300), .driver_info
= BTUSB_QCA_ROME
},
232 { USB_DEVICE(0x0cf3, 0xe360), .driver_info
= BTUSB_QCA_ROME
},
234 /* Broadcom BCM2035 */
235 { USB_DEVICE(0x0a5c, 0x2009), .driver_info
= BTUSB_BCM92035
},
236 { USB_DEVICE(0x0a5c, 0x200a), .driver_info
= BTUSB_WRONG_SCO_MTU
},
237 { USB_DEVICE(0x0a5c, 0x2035), .driver_info
= BTUSB_WRONG_SCO_MTU
},
239 /* Broadcom BCM2045 */
240 { USB_DEVICE(0x0a5c, 0x2039), .driver_info
= BTUSB_WRONG_SCO_MTU
},
241 { USB_DEVICE(0x0a5c, 0x2101), .driver_info
= BTUSB_WRONG_SCO_MTU
},
243 /* IBM/Lenovo ThinkPad with Broadcom chip */
244 { USB_DEVICE(0x0a5c, 0x201e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
245 { USB_DEVICE(0x0a5c, 0x2110), .driver_info
= BTUSB_WRONG_SCO_MTU
},
247 /* HP laptop with Broadcom chip */
248 { USB_DEVICE(0x03f0, 0x171d), .driver_info
= BTUSB_WRONG_SCO_MTU
},
250 /* Dell laptop with Broadcom chip */
251 { USB_DEVICE(0x413c, 0x8126), .driver_info
= BTUSB_WRONG_SCO_MTU
},
253 /* Dell Wireless 370 and 410 devices */
254 { USB_DEVICE(0x413c, 0x8152), .driver_info
= BTUSB_WRONG_SCO_MTU
},
255 { USB_DEVICE(0x413c, 0x8156), .driver_info
= BTUSB_WRONG_SCO_MTU
},
257 /* Belkin F8T012 and F8T013 devices */
258 { USB_DEVICE(0x050d, 0x0012), .driver_info
= BTUSB_WRONG_SCO_MTU
},
259 { USB_DEVICE(0x050d, 0x0013), .driver_info
= BTUSB_WRONG_SCO_MTU
},
261 /* Asus WL-BTD202 device */
262 { USB_DEVICE(0x0b05, 0x1715), .driver_info
= BTUSB_WRONG_SCO_MTU
},
264 /* Kensington Bluetooth USB adapter */
265 { USB_DEVICE(0x047d, 0x105e), .driver_info
= BTUSB_WRONG_SCO_MTU
},
267 /* RTX Telecom based adapters with buggy SCO support */
268 { USB_DEVICE(0x0400, 0x0807), .driver_info
= BTUSB_BROKEN_ISOC
},
269 { USB_DEVICE(0x0400, 0x080a), .driver_info
= BTUSB_BROKEN_ISOC
},
271 /* CONWISE Technology based adapters with buggy SCO support */
272 { USB_DEVICE(0x0e5e, 0x6622), .driver_info
= BTUSB_BROKEN_ISOC
},
274 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
275 { USB_DEVICE(0x1310, 0x0001), .driver_info
= BTUSB_SWAVE
},
277 /* Digianswer devices */
278 { USB_DEVICE(0x08fd, 0x0001), .driver_info
= BTUSB_DIGIANSWER
},
279 { USB_DEVICE(0x08fd, 0x0002), .driver_info
= BTUSB_IGNORE
},
281 /* CSR BlueCore Bluetooth Sniffer */
282 { USB_DEVICE(0x0a12, 0x0002),
283 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
285 /* Frontline ComProbe Bluetooth Sniffer */
286 { USB_DEVICE(0x16d3, 0x0002),
287 .driver_info
= BTUSB_SNIFFER
| BTUSB_BROKEN_ISOC
},
289 /* Marvell Bluetooth devices */
290 { USB_DEVICE(0x1286, 0x2044), .driver_info
= BTUSB_MARVELL
},
291 { USB_DEVICE(0x1286, 0x2046), .driver_info
= BTUSB_MARVELL
},
293 /* Intel Bluetooth devices */
294 { USB_DEVICE(0x8087, 0x07da), .driver_info
= BTUSB_CSR
},
295 { USB_DEVICE(0x8087, 0x07dc), .driver_info
= BTUSB_INTEL
},
296 { USB_DEVICE(0x8087, 0x0a2a), .driver_info
= BTUSB_INTEL
},
297 { USB_DEVICE(0x8087, 0x0a2b), .driver_info
= BTUSB_INTEL_NEW
},
299 /* Other Intel Bluetooth devices */
300 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
301 .driver_info
= BTUSB_IGNORE
},
303 /* Realtek Bluetooth devices */
304 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
305 .driver_info
= BTUSB_REALTEK
},
307 /* Additional Realtek 8723AE Bluetooth devices */
308 { USB_DEVICE(0x0930, 0x021d), .driver_info
= BTUSB_REALTEK
},
309 { USB_DEVICE(0x13d3, 0x3394), .driver_info
= BTUSB_REALTEK
},
311 /* Additional Realtek 8723BE Bluetooth devices */
312 { USB_DEVICE(0x0489, 0xe085), .driver_info
= BTUSB_REALTEK
},
313 { USB_DEVICE(0x0489, 0xe08b), .driver_info
= BTUSB_REALTEK
},
314 { USB_DEVICE(0x13d3, 0x3410), .driver_info
= BTUSB_REALTEK
},
315 { USB_DEVICE(0x13d3, 0x3416), .driver_info
= BTUSB_REALTEK
},
316 { USB_DEVICE(0x13d3, 0x3459), .driver_info
= BTUSB_REALTEK
},
318 /* Additional Realtek 8821AE Bluetooth devices */
319 { USB_DEVICE(0x0b05, 0x17dc), .driver_info
= BTUSB_REALTEK
},
320 { USB_DEVICE(0x13d3, 0x3414), .driver_info
= BTUSB_REALTEK
},
321 { USB_DEVICE(0x13d3, 0x3458), .driver_info
= BTUSB_REALTEK
},
322 { USB_DEVICE(0x13d3, 0x3461), .driver_info
= BTUSB_REALTEK
},
323 { USB_DEVICE(0x13d3, 0x3462), .driver_info
= BTUSB_REALTEK
},
325 /* Silicon Wave based devices */
326 { USB_DEVICE(0x0c10, 0x0000), .driver_info
= BTUSB_SWAVE
},
328 { } /* Terminating entry */
331 #define BTUSB_MAX_ISOC_FRAMES 10
333 #define BTUSB_INTR_RUNNING 0
334 #define BTUSB_BULK_RUNNING 1
335 #define BTUSB_ISOC_RUNNING 2
336 #define BTUSB_SUSPENDING 3
337 #define BTUSB_DID_ISO_RESUME 4
338 #define BTUSB_BOOTLOADER 5
339 #define BTUSB_DOWNLOADING 6
340 #define BTUSB_FIRMWARE_LOADED 7
341 #define BTUSB_FIRMWARE_FAILED 8
342 #define BTUSB_BOOTING 9
343 #define BTUSB_RESET_RESUME 10
344 #define BTUSB_DIAG_RUNNING 11
347 struct hci_dev
*hdev
;
348 struct usb_device
*udev
;
349 struct usb_interface
*intf
;
350 struct usb_interface
*isoc
;
351 struct usb_interface
*diag
;
355 struct work_struct work
;
356 struct work_struct waker
;
358 struct usb_anchor deferred
;
359 struct usb_anchor tx_anchor
;
363 struct usb_anchor intr_anchor
;
364 struct usb_anchor bulk_anchor
;
365 struct usb_anchor isoc_anchor
;
366 struct usb_anchor diag_anchor
;
369 struct sk_buff
*evt_skb
;
370 struct sk_buff
*acl_skb
;
371 struct sk_buff
*sco_skb
;
373 struct usb_endpoint_descriptor
*intr_ep
;
374 struct usb_endpoint_descriptor
*bulk_tx_ep
;
375 struct usb_endpoint_descriptor
*bulk_rx_ep
;
376 struct usb_endpoint_descriptor
*isoc_tx_ep
;
377 struct usb_endpoint_descriptor
*isoc_rx_ep
;
378 struct usb_endpoint_descriptor
*diag_tx_ep
;
379 struct usb_endpoint_descriptor
*diag_rx_ep
;
384 unsigned int sco_num
;
388 int (*recv_event
)(struct hci_dev
*hdev
, struct sk_buff
*skb
);
389 int (*recv_bulk
)(struct btusb_data
*data
, void *buffer
, int count
);
391 int (*setup_on_usb
)(struct hci_dev
*hdev
);
394 static inline void btusb_free_frags(struct btusb_data
*data
)
398 spin_lock_irqsave(&data
->rxlock
, flags
);
400 kfree_skb(data
->evt_skb
);
401 data
->evt_skb
= NULL
;
403 kfree_skb(data
->acl_skb
);
404 data
->acl_skb
= NULL
;
406 kfree_skb(data
->sco_skb
);
407 data
->sco_skb
= NULL
;
409 spin_unlock_irqrestore(&data
->rxlock
, flags
);
412 static int btusb_recv_intr(struct btusb_data
*data
, void *buffer
, int count
)
417 spin_lock(&data
->rxlock
);
424 skb
= bt_skb_alloc(HCI_MAX_EVENT_SIZE
, GFP_ATOMIC
);
430 bt_cb(skb
)->pkt_type
= HCI_EVENT_PKT
;
431 bt_cb(skb
)->expect
= HCI_EVENT_HDR_SIZE
;
434 len
= min_t(uint
, bt_cb(skb
)->expect
, count
);
435 memcpy(skb_put(skb
, len
), buffer
, len
);
439 bt_cb(skb
)->expect
-= len
;
441 if (skb
->len
== HCI_EVENT_HDR_SIZE
) {
442 /* Complete event header */
443 bt_cb(skb
)->expect
= hci_event_hdr(skb
)->plen
;
445 if (skb_tailroom(skb
) < bt_cb(skb
)->expect
) {
454 if (bt_cb(skb
)->expect
== 0) {
456 data
->recv_event(data
->hdev
, skb
);
462 spin_unlock(&data
->rxlock
);
467 static int btusb_recv_bulk(struct btusb_data
*data
, void *buffer
, int count
)
472 spin_lock(&data
->rxlock
);
479 skb
= bt_skb_alloc(HCI_MAX_FRAME_SIZE
, GFP_ATOMIC
);
485 bt_cb(skb
)->pkt_type
= HCI_ACLDATA_PKT
;
486 bt_cb(skb
)->expect
= HCI_ACL_HDR_SIZE
;
489 len
= min_t(uint
, bt_cb(skb
)->expect
, count
);
490 memcpy(skb_put(skb
, len
), buffer
, len
);
494 bt_cb(skb
)->expect
-= len
;
496 if (skb
->len
== HCI_ACL_HDR_SIZE
) {
497 __le16 dlen
= hci_acl_hdr(skb
)->dlen
;
499 /* Complete ACL header */
500 bt_cb(skb
)->expect
= __le16_to_cpu(dlen
);
502 if (skb_tailroom(skb
) < bt_cb(skb
)->expect
) {
511 if (bt_cb(skb
)->expect
== 0) {
513 hci_recv_frame(data
->hdev
, skb
);
519 spin_unlock(&data
->rxlock
);
524 static int btusb_recv_isoc(struct btusb_data
*data
, void *buffer
, int count
)
529 spin_lock(&data
->rxlock
);
536 skb
= bt_skb_alloc(HCI_MAX_SCO_SIZE
, GFP_ATOMIC
);
542 bt_cb(skb
)->pkt_type
= HCI_SCODATA_PKT
;
543 bt_cb(skb
)->expect
= HCI_SCO_HDR_SIZE
;
546 len
= min_t(uint
, bt_cb(skb
)->expect
, count
);
547 memcpy(skb_put(skb
, len
), buffer
, len
);
551 bt_cb(skb
)->expect
-= len
;
553 if (skb
->len
== HCI_SCO_HDR_SIZE
) {
554 /* Complete SCO header */
555 bt_cb(skb
)->expect
= hci_sco_hdr(skb
)->dlen
;
557 if (skb_tailroom(skb
) < bt_cb(skb
)->expect
) {
566 if (bt_cb(skb
)->expect
== 0) {
568 hci_recv_frame(data
->hdev
, skb
);
574 spin_unlock(&data
->rxlock
);
579 static void btusb_intr_complete(struct urb
*urb
)
581 struct hci_dev
*hdev
= urb
->context
;
582 struct btusb_data
*data
= hci_get_drvdata(hdev
);
585 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
588 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
591 if (urb
->status
== 0) {
592 hdev
->stat
.byte_rx
+= urb
->actual_length
;
594 if (btusb_recv_intr(data
, urb
->transfer_buffer
,
595 urb
->actual_length
) < 0) {
596 BT_ERR("%s corrupted event packet", hdev
->name
);
599 } else if (urb
->status
== -ENOENT
) {
600 /* Avoid suspend failed when usb_kill_urb */
604 if (!test_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
607 usb_mark_last_busy(data
->udev
);
608 usb_anchor_urb(urb
, &data
->intr_anchor
);
610 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
612 /* -EPERM: urb is being killed;
613 * -ENODEV: device got disconnected */
614 if (err
!= -EPERM
&& err
!= -ENODEV
)
615 BT_ERR("%s urb %p failed to resubmit (%d)",
616 hdev
->name
, urb
, -err
);
617 usb_unanchor_urb(urb
);
621 static int btusb_submit_intr_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
623 struct btusb_data
*data
= hci_get_drvdata(hdev
);
629 BT_DBG("%s", hdev
->name
);
634 urb
= usb_alloc_urb(0, mem_flags
);
638 size
= le16_to_cpu(data
->intr_ep
->wMaxPacketSize
);
640 buf
= kmalloc(size
, mem_flags
);
646 pipe
= usb_rcvintpipe(data
->udev
, data
->intr_ep
->bEndpointAddress
);
648 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
,
649 btusb_intr_complete
, hdev
, data
->intr_ep
->bInterval
);
651 urb
->transfer_flags
|= URB_FREE_BUFFER
;
653 usb_anchor_urb(urb
, &data
->intr_anchor
);
655 err
= usb_submit_urb(urb
, mem_flags
);
657 if (err
!= -EPERM
&& err
!= -ENODEV
)
658 BT_ERR("%s urb %p submission failed (%d)",
659 hdev
->name
, urb
, -err
);
660 usb_unanchor_urb(urb
);
668 static void btusb_bulk_complete(struct urb
*urb
)
670 struct hci_dev
*hdev
= urb
->context
;
671 struct btusb_data
*data
= hci_get_drvdata(hdev
);
674 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
677 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
680 if (urb
->status
== 0) {
681 hdev
->stat
.byte_rx
+= urb
->actual_length
;
683 if (data
->recv_bulk(data
, urb
->transfer_buffer
,
684 urb
->actual_length
) < 0) {
685 BT_ERR("%s corrupted ACL packet", hdev
->name
);
688 } else if (urb
->status
== -ENOENT
) {
689 /* Avoid suspend failed when usb_kill_urb */
693 if (!test_bit(BTUSB_BULK_RUNNING
, &data
->flags
))
696 usb_anchor_urb(urb
, &data
->bulk_anchor
);
697 usb_mark_last_busy(data
->udev
);
699 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
701 /* -EPERM: urb is being killed;
702 * -ENODEV: device got disconnected */
703 if (err
!= -EPERM
&& err
!= -ENODEV
)
704 BT_ERR("%s urb %p failed to resubmit (%d)",
705 hdev
->name
, urb
, -err
);
706 usb_unanchor_urb(urb
);
710 static int btusb_submit_bulk_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
712 struct btusb_data
*data
= hci_get_drvdata(hdev
);
716 int err
, size
= HCI_MAX_FRAME_SIZE
;
718 BT_DBG("%s", hdev
->name
);
720 if (!data
->bulk_rx_ep
)
723 urb
= usb_alloc_urb(0, mem_flags
);
727 buf
= kmalloc(size
, mem_flags
);
733 pipe
= usb_rcvbulkpipe(data
->udev
, data
->bulk_rx_ep
->bEndpointAddress
);
735 usb_fill_bulk_urb(urb
, data
->udev
, pipe
, buf
, size
,
736 btusb_bulk_complete
, hdev
);
738 urb
->transfer_flags
|= URB_FREE_BUFFER
;
740 usb_mark_last_busy(data
->udev
);
741 usb_anchor_urb(urb
, &data
->bulk_anchor
);
743 err
= usb_submit_urb(urb
, mem_flags
);
745 if (err
!= -EPERM
&& err
!= -ENODEV
)
746 BT_ERR("%s urb %p submission failed (%d)",
747 hdev
->name
, urb
, -err
);
748 usb_unanchor_urb(urb
);
756 static void btusb_isoc_complete(struct urb
*urb
)
758 struct hci_dev
*hdev
= urb
->context
;
759 struct btusb_data
*data
= hci_get_drvdata(hdev
);
762 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
765 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
768 if (urb
->status
== 0) {
769 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
770 unsigned int offset
= urb
->iso_frame_desc
[i
].offset
;
771 unsigned int length
= urb
->iso_frame_desc
[i
].actual_length
;
773 if (urb
->iso_frame_desc
[i
].status
)
776 hdev
->stat
.byte_rx
+= length
;
778 if (btusb_recv_isoc(data
, urb
->transfer_buffer
+ offset
,
780 BT_ERR("%s corrupted SCO packet", hdev
->name
);
784 } else if (urb
->status
== -ENOENT
) {
785 /* Avoid suspend failed when usb_kill_urb */
789 if (!test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
792 usb_anchor_urb(urb
, &data
->isoc_anchor
);
794 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
796 /* -EPERM: urb is being killed;
797 * -ENODEV: device got disconnected */
798 if (err
!= -EPERM
&& err
!= -ENODEV
)
799 BT_ERR("%s urb %p failed to resubmit (%d)",
800 hdev
->name
, urb
, -err
);
801 usb_unanchor_urb(urb
);
805 static inline void __fill_isoc_descriptor(struct urb
*urb
, int len
, int mtu
)
809 BT_DBG("len %d mtu %d", len
, mtu
);
811 for (i
= 0; i
< BTUSB_MAX_ISOC_FRAMES
&& len
>= mtu
;
812 i
++, offset
+= mtu
, len
-= mtu
) {
813 urb
->iso_frame_desc
[i
].offset
= offset
;
814 urb
->iso_frame_desc
[i
].length
= mtu
;
817 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
818 urb
->iso_frame_desc
[i
].offset
= offset
;
819 urb
->iso_frame_desc
[i
].length
= len
;
823 urb
->number_of_packets
= i
;
826 static int btusb_submit_isoc_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
828 struct btusb_data
*data
= hci_get_drvdata(hdev
);
834 BT_DBG("%s", hdev
->name
);
836 if (!data
->isoc_rx_ep
)
839 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, mem_flags
);
843 size
= le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
) *
844 BTUSB_MAX_ISOC_FRAMES
;
846 buf
= kmalloc(size
, mem_flags
);
852 pipe
= usb_rcvisocpipe(data
->udev
, data
->isoc_rx_ep
->bEndpointAddress
);
854 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
, btusb_isoc_complete
,
855 hdev
, data
->isoc_rx_ep
->bInterval
);
857 urb
->transfer_flags
= URB_FREE_BUFFER
| URB_ISO_ASAP
;
859 __fill_isoc_descriptor(urb
, size
,
860 le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
));
862 usb_anchor_urb(urb
, &data
->isoc_anchor
);
864 err
= usb_submit_urb(urb
, mem_flags
);
866 if (err
!= -EPERM
&& err
!= -ENODEV
)
867 BT_ERR("%s urb %p submission failed (%d)",
868 hdev
->name
, urb
, -err
);
869 usb_unanchor_urb(urb
);
877 static void btusb_diag_complete(struct urb
*urb
)
879 struct hci_dev
*hdev
= urb
->context
;
880 struct btusb_data
*data
= hci_get_drvdata(hdev
);
883 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
886 if (urb
->status
== 0) {
889 skb
= bt_skb_alloc(urb
->actual_length
, GFP_ATOMIC
);
891 memcpy(skb_put(skb
, urb
->actual_length
),
892 urb
->transfer_buffer
, urb
->actual_length
);
893 hci_recv_diag(hdev
, skb
);
895 } else if (urb
->status
== -ENOENT
) {
896 /* Avoid suspend failed when usb_kill_urb */
900 if (!test_bit(BTUSB_DIAG_RUNNING
, &data
->flags
))
903 usb_anchor_urb(urb
, &data
->diag_anchor
);
904 usb_mark_last_busy(data
->udev
);
906 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
908 /* -EPERM: urb is being killed;
909 * -ENODEV: device got disconnected */
910 if (err
!= -EPERM
&& err
!= -ENODEV
)
911 BT_ERR("%s urb %p failed to resubmit (%d)",
912 hdev
->name
, urb
, -err
);
913 usb_unanchor_urb(urb
);
917 static int btusb_submit_diag_urb(struct hci_dev
*hdev
, gfp_t mem_flags
)
919 struct btusb_data
*data
= hci_get_drvdata(hdev
);
923 int err
, size
= HCI_MAX_FRAME_SIZE
;
925 BT_DBG("%s", hdev
->name
);
927 if (!data
->diag_rx_ep
)
930 urb
= usb_alloc_urb(0, mem_flags
);
934 buf
= kmalloc(size
, mem_flags
);
940 pipe
= usb_rcvbulkpipe(data
->udev
, data
->diag_rx_ep
->bEndpointAddress
);
942 usb_fill_bulk_urb(urb
, data
->udev
, pipe
, buf
, size
,
943 btusb_diag_complete
, hdev
);
945 urb
->transfer_flags
|= URB_FREE_BUFFER
;
947 usb_mark_last_busy(data
->udev
);
948 usb_anchor_urb(urb
, &data
->diag_anchor
);
950 err
= usb_submit_urb(urb
, mem_flags
);
952 if (err
!= -EPERM
&& err
!= -ENODEV
)
953 BT_ERR("%s urb %p submission failed (%d)",
954 hdev
->name
, urb
, -err
);
955 usb_unanchor_urb(urb
);
963 static void btusb_tx_complete(struct urb
*urb
)
965 struct sk_buff
*skb
= urb
->context
;
966 struct hci_dev
*hdev
= (struct hci_dev
*)skb
->dev
;
967 struct btusb_data
*data
= hci_get_drvdata(hdev
);
969 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
972 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
976 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
981 spin_lock(&data
->txlock
);
982 data
->tx_in_flight
--;
983 spin_unlock(&data
->txlock
);
985 kfree(urb
->setup_packet
);
990 static void btusb_isoc_tx_complete(struct urb
*urb
)
992 struct sk_buff
*skb
= urb
->context
;
993 struct hci_dev
*hdev
= (struct hci_dev
*)skb
->dev
;
995 BT_DBG("%s urb %p status %d count %d", hdev
->name
, urb
, urb
->status
,
998 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
1002 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
1004 hdev
->stat
.err_tx
++;
1007 kfree(urb
->setup_packet
);
1012 static int btusb_open(struct hci_dev
*hdev
)
1014 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1017 BT_DBG("%s", hdev
->name
);
1019 /* Patching USB firmware files prior to starting any URBs of HCI path
1020 * It is more safe to use USB bulk channel for downloading USB patch
1022 if (data
->setup_on_usb
) {
1023 err
= data
->setup_on_usb(hdev
);
1028 err
= usb_autopm_get_interface(data
->intf
);
1032 data
->intf
->needs_remote_wakeup
= 1;
1034 if (test_and_set_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
1037 err
= btusb_submit_intr_urb(hdev
, GFP_KERNEL
);
1041 err
= btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
1043 usb_kill_anchored_urbs(&data
->intr_anchor
);
1047 set_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
1048 btusb_submit_bulk_urb(hdev
, GFP_KERNEL
);
1051 if (!btusb_submit_diag_urb(hdev
, GFP_KERNEL
))
1052 set_bit(BTUSB_DIAG_RUNNING
, &data
->flags
);
1056 usb_autopm_put_interface(data
->intf
);
1060 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
1061 usb_autopm_put_interface(data
->intf
);
1065 static void btusb_stop_traffic(struct btusb_data
*data
)
1067 usb_kill_anchored_urbs(&data
->intr_anchor
);
1068 usb_kill_anchored_urbs(&data
->bulk_anchor
);
1069 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1070 usb_kill_anchored_urbs(&data
->diag_anchor
);
1073 static int btusb_close(struct hci_dev
*hdev
)
1075 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1078 BT_DBG("%s", hdev
->name
);
1080 cancel_work_sync(&data
->work
);
1081 cancel_work_sync(&data
->waker
);
1083 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1084 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
1085 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
1086 clear_bit(BTUSB_DIAG_RUNNING
, &data
->flags
);
1088 btusb_stop_traffic(data
);
1089 btusb_free_frags(data
);
1091 err
= usb_autopm_get_interface(data
->intf
);
1095 data
->intf
->needs_remote_wakeup
= 0;
1096 usb_autopm_put_interface(data
->intf
);
1099 usb_scuttle_anchored_urbs(&data
->deferred
);
1103 static int btusb_flush(struct hci_dev
*hdev
)
1105 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1107 BT_DBG("%s", hdev
->name
);
1109 usb_kill_anchored_urbs(&data
->tx_anchor
);
1110 btusb_free_frags(data
);
1115 static struct urb
*alloc_ctrl_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1117 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1118 struct usb_ctrlrequest
*dr
;
1122 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1124 return ERR_PTR(-ENOMEM
);
1126 dr
= kmalloc(sizeof(*dr
), GFP_KERNEL
);
1129 return ERR_PTR(-ENOMEM
);
1132 dr
->bRequestType
= data
->cmdreq_type
;
1133 dr
->bRequest
= data
->cmdreq
;
1136 dr
->wLength
= __cpu_to_le16(skb
->len
);
1138 pipe
= usb_sndctrlpipe(data
->udev
, 0x00);
1140 usb_fill_control_urb(urb
, data
->udev
, pipe
, (void *)dr
,
1141 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
1143 skb
->dev
= (void *)hdev
;
1148 static struct urb
*alloc_bulk_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1150 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1154 if (!data
->bulk_tx_ep
)
1155 return ERR_PTR(-ENODEV
);
1157 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1159 return ERR_PTR(-ENOMEM
);
1161 pipe
= usb_sndbulkpipe(data
->udev
, data
->bulk_tx_ep
->bEndpointAddress
);
1163 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
1164 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
1166 skb
->dev
= (void *)hdev
;
1171 static struct urb
*alloc_isoc_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1173 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1177 if (!data
->isoc_tx_ep
)
1178 return ERR_PTR(-ENODEV
);
1180 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_KERNEL
);
1182 return ERR_PTR(-ENOMEM
);
1184 pipe
= usb_sndisocpipe(data
->udev
, data
->isoc_tx_ep
->bEndpointAddress
);
1186 usb_fill_int_urb(urb
, data
->udev
, pipe
,
1187 skb
->data
, skb
->len
, btusb_isoc_tx_complete
,
1188 skb
, data
->isoc_tx_ep
->bInterval
);
1190 urb
->transfer_flags
= URB_ISO_ASAP
;
1192 __fill_isoc_descriptor(urb
, skb
->len
,
1193 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
));
1195 skb
->dev
= (void *)hdev
;
1200 static int submit_tx_urb(struct hci_dev
*hdev
, struct urb
*urb
)
1202 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1205 usb_anchor_urb(urb
, &data
->tx_anchor
);
1207 err
= usb_submit_urb(urb
, GFP_KERNEL
);
1209 if (err
!= -EPERM
&& err
!= -ENODEV
)
1210 BT_ERR("%s urb %p submission failed (%d)",
1211 hdev
->name
, urb
, -err
);
1212 kfree(urb
->setup_packet
);
1213 usb_unanchor_urb(urb
);
1215 usb_mark_last_busy(data
->udev
);
1222 static int submit_or_queue_tx_urb(struct hci_dev
*hdev
, struct urb
*urb
)
1224 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1225 unsigned long flags
;
1228 spin_lock_irqsave(&data
->txlock
, flags
);
1229 suspending
= test_bit(BTUSB_SUSPENDING
, &data
->flags
);
1231 data
->tx_in_flight
++;
1232 spin_unlock_irqrestore(&data
->txlock
, flags
);
1235 return submit_tx_urb(hdev
, urb
);
1237 usb_anchor_urb(urb
, &data
->deferred
);
1238 schedule_work(&data
->waker
);
1244 static int btusb_send_frame(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1248 BT_DBG("%s", hdev
->name
);
1250 switch (bt_cb(skb
)->pkt_type
) {
1251 case HCI_COMMAND_PKT
:
1252 urb
= alloc_ctrl_urb(hdev
, skb
);
1254 return PTR_ERR(urb
);
1256 hdev
->stat
.cmd_tx
++;
1257 return submit_or_queue_tx_urb(hdev
, urb
);
1259 case HCI_ACLDATA_PKT
:
1260 urb
= alloc_bulk_urb(hdev
, skb
);
1262 return PTR_ERR(urb
);
1264 hdev
->stat
.acl_tx
++;
1265 return submit_or_queue_tx_urb(hdev
, urb
);
1267 case HCI_SCODATA_PKT
:
1268 if (hci_conn_num(hdev
, SCO_LINK
) < 1)
1271 urb
= alloc_isoc_urb(hdev
, skb
);
1273 return PTR_ERR(urb
);
1275 hdev
->stat
.sco_tx
++;
1276 return submit_tx_urb(hdev
, urb
);
1282 static void btusb_notify(struct hci_dev
*hdev
, unsigned int evt
)
1284 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1286 BT_DBG("%s evt %d", hdev
->name
, evt
);
1288 if (hci_conn_num(hdev
, SCO_LINK
) != data
->sco_num
) {
1289 data
->sco_num
= hci_conn_num(hdev
, SCO_LINK
);
1290 schedule_work(&data
->work
);
1294 static inline int __set_isoc_interface(struct hci_dev
*hdev
, int altsetting
)
1296 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1297 struct usb_interface
*intf
= data
->isoc
;
1298 struct usb_endpoint_descriptor
*ep_desc
;
1304 err
= usb_set_interface(data
->udev
, 1, altsetting
);
1306 BT_ERR("%s setting interface failed (%d)", hdev
->name
, -err
);
1310 data
->isoc_altsetting
= altsetting
;
1312 data
->isoc_tx_ep
= NULL
;
1313 data
->isoc_rx_ep
= NULL
;
1315 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
1316 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
1318 if (!data
->isoc_tx_ep
&& usb_endpoint_is_isoc_out(ep_desc
)) {
1319 data
->isoc_tx_ep
= ep_desc
;
1323 if (!data
->isoc_rx_ep
&& usb_endpoint_is_isoc_in(ep_desc
)) {
1324 data
->isoc_rx_ep
= ep_desc
;
1329 if (!data
->isoc_tx_ep
|| !data
->isoc_rx_ep
) {
1330 BT_ERR("%s invalid SCO descriptors", hdev
->name
);
1337 static void btusb_work(struct work_struct
*work
)
1339 struct btusb_data
*data
= container_of(work
, struct btusb_data
, work
);
1340 struct hci_dev
*hdev
= data
->hdev
;
1344 if (data
->sco_num
> 0) {
1345 if (!test_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
)) {
1346 err
= usb_autopm_get_interface(data
->isoc
? data
->isoc
: data
->intf
);
1348 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1349 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1353 set_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
);
1356 if (hdev
->voice_setting
& 0x0020) {
1357 static const int alts
[3] = { 2, 4, 5 };
1359 new_alts
= alts
[data
->sco_num
- 1];
1361 new_alts
= data
->sco_num
;
1364 if (data
->isoc_altsetting
!= new_alts
) {
1365 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1366 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1368 /* When isochronous alternate setting needs to be
1369 * changed, because SCO connection has been added
1370 * or removed, a packet fragment may be left in the
1371 * reassembling state. This could lead to wrongly
1372 * assembled fragments.
1374 * Clear outstanding fragment when selecting a new
1375 * alternate setting.
1377 spin_lock(&data
->rxlock
);
1378 kfree_skb(data
->sco_skb
);
1379 data
->sco_skb
= NULL
;
1380 spin_unlock(&data
->rxlock
);
1382 if (__set_isoc_interface(hdev
, new_alts
) < 0)
1386 if (!test_and_set_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
1387 if (btusb_submit_isoc_urb(hdev
, GFP_KERNEL
) < 0)
1388 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1390 btusb_submit_isoc_urb(hdev
, GFP_KERNEL
);
1393 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
1394 usb_kill_anchored_urbs(&data
->isoc_anchor
);
1396 __set_isoc_interface(hdev
, 0);
1397 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME
, &data
->flags
))
1398 usb_autopm_put_interface(data
->isoc
? data
->isoc
: data
->intf
);
1402 static void btusb_waker(struct work_struct
*work
)
1404 struct btusb_data
*data
= container_of(work
, struct btusb_data
, waker
);
1407 err
= usb_autopm_get_interface(data
->intf
);
1411 usb_autopm_put_interface(data
->intf
);
1414 static int btusb_setup_bcm92035(struct hci_dev
*hdev
)
1416 struct sk_buff
*skb
;
1419 BT_DBG("%s", hdev
->name
);
1421 skb
= __hci_cmd_sync(hdev
, 0xfc3b, 1, &val
, HCI_INIT_TIMEOUT
);
1423 BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb
));
1430 static int btusb_setup_csr(struct hci_dev
*hdev
)
1432 struct hci_rp_read_local_version
*rp
;
1433 struct sk_buff
*skb
;
1435 BT_DBG("%s", hdev
->name
);
1437 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
1440 int err
= PTR_ERR(skb
);
1441 BT_ERR("%s: CSR: Local version failed (%d)", hdev
->name
, err
);
1445 if (skb
->len
!= sizeof(struct hci_rp_read_local_version
)) {
1446 BT_ERR("%s: CSR: Local version length mismatch", hdev
->name
);
1451 rp
= (struct hci_rp_read_local_version
*)skb
->data
;
1453 /* Detect controllers which aren't real CSR ones. */
1454 if (le16_to_cpu(rp
->manufacturer
) != 10 ||
1455 le16_to_cpu(rp
->lmp_subver
) == 0x0c5c) {
1456 /* Clear the reset quirk since this is not an actual
1457 * early Bluetooth 1.1 device from CSR.
1459 clear_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
1461 /* These fake CSR controllers have all a broken
1462 * stored link key handling and so just disable it.
1464 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY
, &hdev
->quirks
);
1472 static const struct firmware
*btusb_setup_intel_get_fw(struct hci_dev
*hdev
,
1473 struct intel_version
*ver
)
1475 const struct firmware
*fw
;
1479 snprintf(fwname
, sizeof(fwname
),
1480 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
1481 ver
->hw_platform
, ver
->hw_variant
, ver
->hw_revision
,
1482 ver
->fw_variant
, ver
->fw_revision
, ver
->fw_build_num
,
1483 ver
->fw_build_ww
, ver
->fw_build_yy
);
1485 ret
= request_firmware(&fw
, fwname
, &hdev
->dev
);
1487 if (ret
== -EINVAL
) {
1488 BT_ERR("%s Intel firmware file request failed (%d)",
1493 BT_ERR("%s failed to open Intel firmware file: %s(%d)",
1494 hdev
->name
, fwname
, ret
);
1496 /* If the correct firmware patch file is not found, use the
1497 * default firmware patch file instead
1499 snprintf(fwname
, sizeof(fwname
), "intel/ibt-hw-%x.%x.bseq",
1500 ver
->hw_platform
, ver
->hw_variant
);
1501 if (request_firmware(&fw
, fwname
, &hdev
->dev
) < 0) {
1502 BT_ERR("%s failed to open default Intel fw file: %s",
1503 hdev
->name
, fwname
);
1508 BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev
->name
, fwname
);
1513 static int btusb_setup_intel_patching(struct hci_dev
*hdev
,
1514 const struct firmware
*fw
,
1515 const u8
**fw_ptr
, int *disable_patch
)
1517 struct sk_buff
*skb
;
1518 struct hci_command_hdr
*cmd
;
1519 const u8
*cmd_param
;
1520 struct hci_event_hdr
*evt
= NULL
;
1521 const u8
*evt_param
= NULL
;
1522 int remain
= fw
->size
- (*fw_ptr
- fw
->data
);
1524 /* The first byte indicates the types of the patch command or event.
1525 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1526 * in the current firmware buffer doesn't start with 0x01 or
1527 * the size of remain buffer is smaller than HCI command header,
1528 * the firmware file is corrupted and it should stop the patching
1531 if (remain
> HCI_COMMAND_HDR_SIZE
&& *fw_ptr
[0] != 0x01) {
1532 BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev
->name
);
1538 cmd
= (struct hci_command_hdr
*)(*fw_ptr
);
1539 *fw_ptr
+= sizeof(*cmd
);
1540 remain
-= sizeof(*cmd
);
1542 /* Ensure that the remain firmware data is long enough than the length
1543 * of command parameter. If not, the firmware file is corrupted.
1545 if (remain
< cmd
->plen
) {
1546 BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev
->name
);
1550 /* If there is a command that loads a patch in the firmware
1551 * file, then enable the patch upon success, otherwise just
1552 * disable the manufacturer mode, for example patch activation
1553 * is not required when the default firmware patch file is used
1554 * because there are no patch data to load.
1556 if (*disable_patch
&& le16_to_cpu(cmd
->opcode
) == 0xfc8e)
1559 cmd_param
= *fw_ptr
;
1560 *fw_ptr
+= cmd
->plen
;
1561 remain
-= cmd
->plen
;
1563 /* This reads the expected events when the above command is sent to the
1564 * device. Some vendor commands expects more than one events, for
1565 * example command status event followed by vendor specific event.
1566 * For this case, it only keeps the last expected event. so the command
1567 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1568 * last expected event.
1570 while (remain
> HCI_EVENT_HDR_SIZE
&& *fw_ptr
[0] == 0x02) {
1574 evt
= (struct hci_event_hdr
*)(*fw_ptr
);
1575 *fw_ptr
+= sizeof(*evt
);
1576 remain
-= sizeof(*evt
);
1578 if (remain
< evt
->plen
) {
1579 BT_ERR("%s Intel fw corrupted: invalid evt len",
1584 evt_param
= *fw_ptr
;
1585 *fw_ptr
+= evt
->plen
;
1586 remain
-= evt
->plen
;
1589 /* Every HCI commands in the firmware file has its correspond event.
1590 * If event is not found or remain is smaller than zero, the firmware
1591 * file is corrupted.
1593 if (!evt
|| !evt_param
|| remain
< 0) {
1594 BT_ERR("%s Intel fw corrupted: invalid evt read", hdev
->name
);
1598 skb
= __hci_cmd_sync_ev(hdev
, le16_to_cpu(cmd
->opcode
), cmd
->plen
,
1599 cmd_param
, evt
->evt
, HCI_INIT_TIMEOUT
);
1601 BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
1602 hdev
->name
, cmd
->opcode
, PTR_ERR(skb
));
1603 return PTR_ERR(skb
);
1606 /* It ensures that the returned event matches the event data read from
1607 * the firmware file. At fist, it checks the length and then
1608 * the contents of the event.
1610 if (skb
->len
!= evt
->plen
) {
1611 BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev
->name
,
1612 le16_to_cpu(cmd
->opcode
));
1617 if (memcmp(skb
->data
, evt_param
, evt
->plen
)) {
1618 BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)",
1619 hdev
->name
, le16_to_cpu(cmd
->opcode
));
1628 static int btusb_setup_intel(struct hci_dev
*hdev
)
1630 struct sk_buff
*skb
;
1631 const struct firmware
*fw
;
1634 struct intel_version
*ver
;
1636 const u8 mfg_enable
[] = { 0x01, 0x00 };
1637 const u8 mfg_disable
[] = { 0x00, 0x00 };
1638 const u8 mfg_reset_deactivate
[] = { 0x00, 0x01 };
1639 const u8 mfg_reset_activate
[] = { 0x00, 0x02 };
1641 BT_DBG("%s", hdev
->name
);
1643 /* The controller has a bug with the first HCI command sent to it
1644 * returning number of completed commands as zero. This would stall the
1645 * command processing in the Bluetooth core.
1647 * As a workaround, send HCI Reset command first which will reset the
1648 * number of completed commands and allow normal command processing
1651 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
1653 BT_ERR("%s sending initial HCI reset command failed (%ld)",
1654 hdev
->name
, PTR_ERR(skb
));
1655 return PTR_ERR(skb
);
1659 /* Read Intel specific controller version first to allow selection of
1660 * which firmware file to load.
1662 * The returned information are hardware variant and revision plus
1663 * firmware variant, revision and build number.
1665 skb
= __hci_cmd_sync(hdev
, 0xfc05, 0, NULL
, HCI_INIT_TIMEOUT
);
1667 BT_ERR("%s reading Intel fw version command failed (%ld)",
1668 hdev
->name
, PTR_ERR(skb
));
1669 return PTR_ERR(skb
);
1672 if (skb
->len
!= sizeof(*ver
)) {
1673 BT_ERR("%s Intel version event length mismatch", hdev
->name
);
1678 ver
= (struct intel_version
*)skb
->data
;
1680 BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x",
1681 hdev
->name
, ver
->hw_platform
, ver
->hw_variant
,
1682 ver
->hw_revision
, ver
->fw_variant
, ver
->fw_revision
,
1683 ver
->fw_build_num
, ver
->fw_build_ww
, ver
->fw_build_yy
,
1686 /* fw_patch_num indicates the version of patch the device currently
1687 * have. If there is no patch data in the device, it is always 0x00.
1688 * So, if it is other than 0x00, no need to patch the device again.
1690 if (ver
->fw_patch_num
) {
1691 BT_INFO("%s: Intel device is already patched. patch num: %02x",
1692 hdev
->name
, ver
->fw_patch_num
);
1694 btintel_check_bdaddr(hdev
);
1698 /* Opens the firmware patch file based on the firmware version read
1699 * from the controller. If it fails to open the matching firmware
1700 * patch file, it tries to open the default firmware patch file.
1701 * If no patch file is found, allow the device to operate without
1704 fw
= btusb_setup_intel_get_fw(hdev
, ver
);
1707 btintel_check_bdaddr(hdev
);
1714 /* This Intel specific command enables the manufacturer mode of the
1717 * Only while this mode is enabled, the driver can download the
1718 * firmware patch data and configuration parameters.
1720 skb
= __hci_cmd_sync(hdev
, 0xfc11, 2, mfg_enable
, HCI_INIT_TIMEOUT
);
1722 BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
1723 hdev
->name
, PTR_ERR(skb
));
1724 release_firmware(fw
);
1725 return PTR_ERR(skb
);
1732 /* The firmware data file consists of list of Intel specific HCI
1733 * commands and its expected events. The first byte indicates the
1734 * type of the message, either HCI command or HCI event.
1736 * It reads the command and its expected event from the firmware file,
1737 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1738 * the returned event is compared with the event read from the firmware
1739 * file and it will continue until all the messages are downloaded to
1742 * Once the firmware patching is completed successfully,
1743 * the manufacturer mode is disabled with reset and activating the
1746 * If the firmware patching fails, the manufacturer mode is
1747 * disabled with reset and deactivating the patch.
1749 * If the default patch file is used, no reset is done when disabling
1752 while (fw
->size
> fw_ptr
- fw
->data
) {
1755 ret
= btusb_setup_intel_patching(hdev
, fw
, &fw_ptr
,
1758 goto exit_mfg_deactivate
;
1761 release_firmware(fw
);
1764 goto exit_mfg_disable
;
1766 /* Patching completed successfully and disable the manufacturer mode
1767 * with reset and activate the downloaded firmware patches.
1769 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_reset_activate
),
1770 mfg_reset_activate
, HCI_INIT_TIMEOUT
);
1772 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1773 hdev
->name
, PTR_ERR(skb
));
1774 return PTR_ERR(skb
);
1778 BT_INFO("%s: Intel Bluetooth firmware patch completed and activated",
1781 btintel_check_bdaddr(hdev
);
1785 /* Disable the manufacturer mode without reset */
1786 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_disable
), mfg_disable
,
1789 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1790 hdev
->name
, PTR_ERR(skb
));
1791 return PTR_ERR(skb
);
1795 BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev
->name
);
1797 btintel_check_bdaddr(hdev
);
1800 exit_mfg_deactivate
:
1801 release_firmware(fw
);
1803 /* Patching failed. Disable the manufacturer mode with reset and
1804 * deactivate the downloaded firmware patches.
1806 skb
= __hci_cmd_sync(hdev
, 0xfc11, sizeof(mfg_reset_deactivate
),
1807 mfg_reset_deactivate
, HCI_INIT_TIMEOUT
);
1809 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1810 hdev
->name
, PTR_ERR(skb
));
1811 return PTR_ERR(skb
);
1815 BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated",
1818 btintel_check_bdaddr(hdev
);
1822 static int inject_cmd_complete(struct hci_dev
*hdev
, __u16 opcode
)
1824 struct sk_buff
*skb
;
1825 struct hci_event_hdr
*hdr
;
1826 struct hci_ev_cmd_complete
*evt
;
1828 skb
= bt_skb_alloc(sizeof(*hdr
) + sizeof(*evt
) + 1, GFP_ATOMIC
);
1832 hdr
= (struct hci_event_hdr
*)skb_put(skb
, sizeof(*hdr
));
1833 hdr
->evt
= HCI_EV_CMD_COMPLETE
;
1834 hdr
->plen
= sizeof(*evt
) + 1;
1836 evt
= (struct hci_ev_cmd_complete
*)skb_put(skb
, sizeof(*evt
));
1838 evt
->opcode
= cpu_to_le16(opcode
);
1840 *skb_put(skb
, 1) = 0x00;
1842 bt_cb(skb
)->pkt_type
= HCI_EVENT_PKT
;
1844 return hci_recv_frame(hdev
, skb
);
1847 static int btusb_recv_bulk_intel(struct btusb_data
*data
, void *buffer
,
1850 /* When the device is in bootloader mode, then it can send
1851 * events via the bulk endpoint. These events are treated the
1852 * same way as the ones received from the interrupt endpoint.
1854 if (test_bit(BTUSB_BOOTLOADER
, &data
->flags
))
1855 return btusb_recv_intr(data
, buffer
, count
);
1857 return btusb_recv_bulk(data
, buffer
, count
);
1860 static void btusb_intel_bootup(struct btusb_data
*data
, const void *ptr
,
1863 const struct intel_bootup
*evt
= ptr
;
1865 if (len
!= sizeof(*evt
))
1868 if (test_and_clear_bit(BTUSB_BOOTING
, &data
->flags
)) {
1869 smp_mb__after_atomic();
1870 wake_up_bit(&data
->flags
, BTUSB_BOOTING
);
1874 static void btusb_intel_secure_send_result(struct btusb_data
*data
,
1875 const void *ptr
, unsigned int len
)
1877 const struct intel_secure_send_result
*evt
= ptr
;
1879 if (len
!= sizeof(*evt
))
1883 set_bit(BTUSB_FIRMWARE_FAILED
, &data
->flags
);
1885 if (test_and_clear_bit(BTUSB_DOWNLOADING
, &data
->flags
) &&
1886 test_bit(BTUSB_FIRMWARE_LOADED
, &data
->flags
)) {
1887 smp_mb__after_atomic();
1888 wake_up_bit(&data
->flags
, BTUSB_DOWNLOADING
);
1892 static int btusb_recv_event_intel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1894 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1896 if (test_bit(BTUSB_BOOTLOADER
, &data
->flags
)) {
1897 struct hci_event_hdr
*hdr
= (void *)skb
->data
;
1899 if (skb
->len
> HCI_EVENT_HDR_SIZE
&& hdr
->evt
== 0xff &&
1901 const void *ptr
= skb
->data
+ HCI_EVENT_HDR_SIZE
+ 1;
1902 unsigned int len
= skb
->len
- HCI_EVENT_HDR_SIZE
- 1;
1904 switch (skb
->data
[2]) {
1906 /* When switching to the operational firmware
1907 * the device sends a vendor specific event
1908 * indicating that the bootup completed.
1910 btusb_intel_bootup(data
, ptr
, len
);
1913 /* When the firmware loading completes the
1914 * device sends out a vendor specific event
1915 * indicating the result of the firmware
1918 btusb_intel_secure_send_result(data
, ptr
, len
);
1924 return hci_recv_frame(hdev
, skb
);
1927 static int btusb_send_frame_intel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1929 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1932 BT_DBG("%s", hdev
->name
);
1934 switch (bt_cb(skb
)->pkt_type
) {
1935 case HCI_COMMAND_PKT
:
1936 if (test_bit(BTUSB_BOOTLOADER
, &data
->flags
)) {
1937 struct hci_command_hdr
*cmd
= (void *)skb
->data
;
1938 __u16 opcode
= le16_to_cpu(cmd
->opcode
);
1940 /* When in bootloader mode and the command 0xfc09
1941 * is received, it needs to be send down the
1942 * bulk endpoint. So allocate a bulk URB instead.
1944 if (opcode
== 0xfc09)
1945 urb
= alloc_bulk_urb(hdev
, skb
);
1947 urb
= alloc_ctrl_urb(hdev
, skb
);
1949 /* When the 0xfc01 command is issued to boot into
1950 * the operational firmware, it will actually not
1951 * send a command complete event. To keep the flow
1952 * control working inject that event here.
1954 if (opcode
== 0xfc01)
1955 inject_cmd_complete(hdev
, opcode
);
1957 urb
= alloc_ctrl_urb(hdev
, skb
);
1960 return PTR_ERR(urb
);
1962 hdev
->stat
.cmd_tx
++;
1963 return submit_or_queue_tx_urb(hdev
, urb
);
1965 case HCI_ACLDATA_PKT
:
1966 urb
= alloc_bulk_urb(hdev
, skb
);
1968 return PTR_ERR(urb
);
1970 hdev
->stat
.acl_tx
++;
1971 return submit_or_queue_tx_urb(hdev
, urb
);
1973 case HCI_SCODATA_PKT
:
1974 if (hci_conn_num(hdev
, SCO_LINK
) < 1)
1977 urb
= alloc_isoc_urb(hdev
, skb
);
1979 return PTR_ERR(urb
);
1981 hdev
->stat
.sco_tx
++;
1982 return submit_tx_urb(hdev
, urb
);
1988 static int btusb_setup_intel_new(struct hci_dev
*hdev
)
1990 static const u8 reset_param
[] = { 0x00, 0x01, 0x00, 0x01,
1991 0x00, 0x08, 0x04, 0x00 };
1992 struct btusb_data
*data
= hci_get_drvdata(hdev
);
1993 struct sk_buff
*skb
;
1994 struct intel_version
*ver
;
1995 struct intel_boot_params
*params
;
1996 const struct firmware
*fw
;
2000 ktime_t calltime
, delta
, rettime
;
2001 unsigned long long duration
;
2004 BT_DBG("%s", hdev
->name
);
2006 calltime
= ktime_get();
2008 /* Read the Intel version information to determine if the device
2009 * is in bootloader mode or if it already has operational firmware
2012 skb
= __hci_cmd_sync(hdev
, 0xfc05, 0, NULL
, HCI_INIT_TIMEOUT
);
2014 BT_ERR("%s: Reading Intel version information failed (%ld)",
2015 hdev
->name
, PTR_ERR(skb
));
2016 return PTR_ERR(skb
);
2019 if (skb
->len
!= sizeof(*ver
)) {
2020 BT_ERR("%s: Intel version event size mismatch", hdev
->name
);
2025 ver
= (struct intel_version
*)skb
->data
;
2027 /* The hardware platform number has a fixed value of 0x37 and
2028 * for now only accept this single value.
2030 if (ver
->hw_platform
!= 0x37) {
2031 BT_ERR("%s: Unsupported Intel hardware platform (%u)",
2032 hdev
->name
, ver
->hw_platform
);
2037 /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is
2038 * supported by this firmware loading method. This check has been
2039 * put in place to ensure correct forward compatibility options
2040 * when newer hardware variants come along.
2042 if (ver
->hw_variant
!= 0x0b) {
2043 BT_ERR("%s: Unsupported Intel hardware variant (%u)",
2044 hdev
->name
, ver
->hw_variant
);
2049 btintel_version_info(hdev
, ver
);
2051 /* The firmware variant determines if the device is in bootloader
2052 * mode or is running operational firmware. The value 0x06 identifies
2053 * the bootloader and the value 0x23 identifies the operational
2056 * When the operational firmware is already present, then only
2057 * the check for valid Bluetooth device address is needed. This
2058 * determines if the device will be added as configured or
2059 * unconfigured controller.
2061 * It is not possible to use the Secure Boot Parameters in this
2062 * case since that command is only available in bootloader mode.
2064 if (ver
->fw_variant
== 0x23) {
2066 clear_bit(BTUSB_BOOTLOADER
, &data
->flags
);
2067 btintel_check_bdaddr(hdev
);
2071 /* If the device is not in bootloader mode, then the only possible
2072 * choice is to return an error and abort the device initialization.
2074 if (ver
->fw_variant
!= 0x06) {
2075 BT_ERR("%s: Unsupported Intel firmware variant (%u)",
2076 hdev
->name
, ver
->fw_variant
);
2083 /* Read the secure boot parameters to identify the operating
2084 * details of the bootloader.
2086 skb
= __hci_cmd_sync(hdev
, 0xfc0d, 0, NULL
, HCI_INIT_TIMEOUT
);
2088 BT_ERR("%s: Reading Intel boot parameters failed (%ld)",
2089 hdev
->name
, PTR_ERR(skb
));
2090 return PTR_ERR(skb
);
2093 if (skb
->len
!= sizeof(*params
)) {
2094 BT_ERR("%s: Intel boot parameters size mismatch", hdev
->name
);
2099 params
= (struct intel_boot_params
*)skb
->data
;
2101 BT_INFO("%s: Device revision is %u", hdev
->name
,
2102 le16_to_cpu(params
->dev_revid
));
2104 BT_INFO("%s: Secure boot is %s", hdev
->name
,
2105 params
->secure_boot
? "enabled" : "disabled");
2107 BT_INFO("%s: OTP lock is %s", hdev
->name
,
2108 params
->otp_lock
? "enabled" : "disabled");
2110 BT_INFO("%s: API lock is %s", hdev
->name
,
2111 params
->api_lock
? "enabled" : "disabled");
2113 BT_INFO("%s: Debug lock is %s", hdev
->name
,
2114 params
->debug_lock
? "enabled" : "disabled");
2116 BT_INFO("%s: Minimum firmware build %u week %u %u", hdev
->name
,
2117 params
->min_fw_build_nn
, params
->min_fw_build_cw
,
2118 2000 + params
->min_fw_build_yy
);
2120 /* It is required that every single firmware fragment is acknowledged
2121 * with a command complete event. If the boot parameters indicate
2122 * that this bootloader does not send them, then abort the setup.
2124 if (params
->limited_cce
!= 0x00) {
2125 BT_ERR("%s: Unsupported Intel firmware loading method (%u)",
2126 hdev
->name
, params
->limited_cce
);
2131 /* If the OTP has no valid Bluetooth device address, then there will
2132 * also be no valid address for the operational firmware.
2134 if (!bacmp(¶ms
->otp_bdaddr
, BDADDR_ANY
)) {
2135 BT_INFO("%s: No device address configured", hdev
->name
);
2136 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
2139 /* With this Intel bootloader only the hardware variant and device
2140 * revision information are used to select the right firmware.
2142 * Currently this bootloader support is limited to hardware variant
2143 * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b).
2145 snprintf(fwname
, sizeof(fwname
), "intel/ibt-11-%u.sfi",
2146 le16_to_cpu(params
->dev_revid
));
2148 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
2150 BT_ERR("%s: Failed to load Intel firmware file (%d)",
2156 BT_INFO("%s: Found device firmware: %s", hdev
->name
, fwname
);
2158 /* Save the DDC file name for later use to apply once the firmware
2159 * downloading is done.
2161 snprintf(fwname
, sizeof(fwname
), "intel/ibt-11-%u.ddc",
2162 le16_to_cpu(params
->dev_revid
));
2166 if (fw
->size
< 644) {
2167 BT_ERR("%s: Invalid size of firmware file (%zu)",
2168 hdev
->name
, fw
->size
);
2173 set_bit(BTUSB_DOWNLOADING
, &data
->flags
);
2175 /* Start the firmware download transaction with the Init fragment
2176 * represented by the 128 bytes of CSS header.
2178 err
= btintel_secure_send(hdev
, 0x00, 128, fw
->data
);
2180 BT_ERR("%s: Failed to send firmware header (%d)",
2185 /* Send the 256 bytes of public key information from the firmware
2186 * as the PKey fragment.
2188 err
= btintel_secure_send(hdev
, 0x03, 256, fw
->data
+ 128);
2190 BT_ERR("%s: Failed to send firmware public key (%d)",
2195 /* Send the 256 bytes of signature information from the firmware
2196 * as the Sign fragment.
2198 err
= btintel_secure_send(hdev
, 0x02, 256, fw
->data
+ 388);
2200 BT_ERR("%s: Failed to send firmware signature (%d)",
2205 fw_ptr
= fw
->data
+ 644;
2208 while (fw_ptr
- fw
->data
< fw
->size
) {
2209 struct hci_command_hdr
*cmd
= (void *)(fw_ptr
+ frag_len
);
2211 frag_len
+= sizeof(*cmd
) + cmd
->plen
;
2213 /* The parameter length of the secure send command requires
2214 * a 4 byte alignment. It happens so that the firmware file
2215 * contains proper Intel_NOP commands to align the fragments
2218 * Send set of commands with 4 byte alignment from the
2219 * firmware data buffer as a single Data fragement.
2221 if (!(frag_len
% 4)) {
2222 err
= btintel_secure_send(hdev
, 0x01, frag_len
, fw_ptr
);
2224 BT_ERR("%s: Failed to send firmware data (%d)",
2234 set_bit(BTUSB_FIRMWARE_LOADED
, &data
->flags
);
2236 BT_INFO("%s: Waiting for firmware download to complete", hdev
->name
);
2238 /* Before switching the device into operational mode and with that
2239 * booting the loaded firmware, wait for the bootloader notification
2240 * that all fragments have been successfully received.
2242 * When the event processing receives the notification, then the
2243 * BTUSB_DOWNLOADING flag will be cleared.
2245 * The firmware loading should not take longer than 5 seconds
2246 * and thus just timeout if that happens and fail the setup
2249 err
= wait_on_bit_timeout(&data
->flags
, BTUSB_DOWNLOADING
,
2251 msecs_to_jiffies(5000));
2253 BT_ERR("%s: Firmware loading interrupted", hdev
->name
);
2259 BT_ERR("%s: Firmware loading timeout", hdev
->name
);
2264 if (test_bit(BTUSB_FIRMWARE_FAILED
, &data
->flags
)) {
2265 BT_ERR("%s: Firmware loading failed", hdev
->name
);
2270 rettime
= ktime_get();
2271 delta
= ktime_sub(rettime
, calltime
);
2272 duration
= (unsigned long long) ktime_to_ns(delta
) >> 10;
2274 BT_INFO("%s: Firmware loaded in %llu usecs", hdev
->name
, duration
);
2277 release_firmware(fw
);
2282 calltime
= ktime_get();
2284 set_bit(BTUSB_BOOTING
, &data
->flags
);
2286 skb
= __hci_cmd_sync(hdev
, 0xfc01, sizeof(reset_param
), reset_param
,
2289 return PTR_ERR(skb
);
2293 /* The bootloader will not indicate when the device is ready. This
2294 * is done by the operational firmware sending bootup notification.
2296 * Booting into operational firmware should not take longer than
2297 * 1 second. However if that happens, then just fail the setup
2298 * since something went wrong.
2300 BT_INFO("%s: Waiting for device to boot", hdev
->name
);
2302 err
= wait_on_bit_timeout(&data
->flags
, BTUSB_BOOTING
,
2304 msecs_to_jiffies(1000));
2307 BT_ERR("%s: Device boot interrupted", hdev
->name
);
2312 BT_ERR("%s: Device boot timeout", hdev
->name
);
2316 rettime
= ktime_get();
2317 delta
= ktime_sub(rettime
, calltime
);
2318 duration
= (unsigned long long) ktime_to_ns(delta
) >> 10;
2320 BT_INFO("%s: Device booted in %llu usecs", hdev
->name
, duration
);
2322 clear_bit(BTUSB_BOOTLOADER
, &data
->flags
);
2324 /* Once the device is running in operational mode, it needs to apply
2325 * the device configuration (DDC) parameters.
2327 * The device can work without DDC parameters, so even if it fails
2328 * to load the file, no need to fail the setup.
2330 btintel_load_ddc_config(hdev
, fwname
);
2335 static int btusb_shutdown_intel(struct hci_dev
*hdev
)
2337 struct sk_buff
*skb
;
2340 /* Some platforms have an issue with BT LED when the interface is
2341 * down or BT radio is turned off, which takes 5 seconds to BT LED
2342 * goes off. This command turns off the BT LED immediately.
2344 skb
= __hci_cmd_sync(hdev
, 0xfc3f, 0, NULL
, HCI_INIT_TIMEOUT
);
2347 BT_ERR("%s: turning off Intel device LED failed (%ld)",
2356 static int btusb_set_bdaddr_marvell(struct hci_dev
*hdev
,
2357 const bdaddr_t
*bdaddr
)
2359 struct sk_buff
*skb
;
2364 buf
[1] = sizeof(bdaddr_t
);
2365 memcpy(buf
+ 2, bdaddr
, sizeof(bdaddr_t
));
2367 skb
= __hci_cmd_sync(hdev
, 0xfc22, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
2370 BT_ERR("%s: changing Marvell device address failed (%ld)",
2379 static int btusb_set_bdaddr_ath3012(struct hci_dev
*hdev
,
2380 const bdaddr_t
*bdaddr
)
2382 struct sk_buff
*skb
;
2389 buf
[3] = sizeof(bdaddr_t
);
2390 memcpy(buf
+ 4, bdaddr
, sizeof(bdaddr_t
));
2392 skb
= __hci_cmd_sync(hdev
, 0xfc0b, sizeof(buf
), buf
, HCI_INIT_TIMEOUT
);
2395 BT_ERR("%s: Change address command failed (%ld)",
2404 #define QCA_DFU_PACKET_LEN 4096
2406 #define QCA_GET_TARGET_VERSION 0x09
2407 #define QCA_CHECK_STATUS 0x05
2408 #define QCA_DFU_DOWNLOAD 0x01
2410 #define QCA_SYSCFG_UPDATED 0x40
2411 #define QCA_PATCH_UPDATED 0x80
2412 #define QCA_DFU_TIMEOUT 3000
2414 struct qca_version
{
2416 __le32 patch_version
;
2422 struct qca_rampatch_version
{
2424 __le16 patch_version
;
2427 struct qca_device_info
{
2429 u8 rampatch_hdr
; /* length of header in rampatch */
2430 u8 nvm_hdr
; /* length of header in NVM */
2431 u8 ver_offset
; /* offset of version structure in rampatch */
2434 static const struct qca_device_info qca_devices_table
[] = {
2435 { 0x00000100, 20, 4, 10 }, /* Rome 1.0 */
2436 { 0x00000101, 20, 4, 10 }, /* Rome 1.1 */
2437 { 0x00000200, 28, 4, 18 }, /* Rome 2.0 */
2438 { 0x00000201, 28, 4, 18 }, /* Rome 2.1 */
2439 { 0x00000300, 28, 4, 18 }, /* Rome 3.0 */
2440 { 0x00000302, 28, 4, 18 }, /* Rome 3.2 */
2443 static int btusb_qca_send_vendor_req(struct hci_dev
*hdev
, u8 request
,
2444 void *data
, u16 size
)
2446 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
2447 struct usb_device
*udev
= btdata
->udev
;
2451 buf
= kmalloc(size
, GFP_KERNEL
);
2455 /* Found some of USB hosts have IOT issues with ours so that we should
2456 * not wait until HCI layer is ready.
2458 pipe
= usb_rcvctrlpipe(udev
, 0);
2459 err
= usb_control_msg(udev
, pipe
, request
, USB_TYPE_VENDOR
| USB_DIR_IN
,
2460 0, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
2462 BT_ERR("%s: Failed to access otp area (%d)", hdev
->name
, err
);
2466 memcpy(data
, buf
, size
);
2474 static int btusb_setup_qca_download_fw(struct hci_dev
*hdev
,
2475 const struct firmware
*firmware
,
2478 struct btusb_data
*btdata
= hci_get_drvdata(hdev
);
2479 struct usb_device
*udev
= btdata
->udev
;
2480 size_t count
, size
, sent
= 0;
2484 buf
= kmalloc(QCA_DFU_PACKET_LEN
, GFP_KERNEL
);
2488 count
= firmware
->size
;
2490 size
= min_t(size_t, count
, hdr_size
);
2491 memcpy(buf
, firmware
->data
, size
);
2493 /* USB patches should go down to controller through USB path
2494 * because binary format fits to go down through USB channel.
2495 * USB control path is for patching headers and USB bulk is for
2498 pipe
= usb_sndctrlpipe(udev
, 0);
2499 err
= usb_control_msg(udev
, pipe
, QCA_DFU_DOWNLOAD
, USB_TYPE_VENDOR
,
2500 0, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
2502 BT_ERR("%s: Failed to send headers (%d)", hdev
->name
, err
);
2510 size
= min_t(size_t, count
, QCA_DFU_PACKET_LEN
);
2512 memcpy(buf
, firmware
->data
+ sent
, size
);
2514 pipe
= usb_sndbulkpipe(udev
, 0x02);
2515 err
= usb_bulk_msg(udev
, pipe
, buf
, size
, &len
,
2518 BT_ERR("%s: Failed to send body at %zd of %zd (%d)",
2519 hdev
->name
, sent
, firmware
->size
, err
);
2524 BT_ERR("%s: Failed to get bulk buffer", hdev
->name
);
2538 static int btusb_setup_qca_load_rampatch(struct hci_dev
*hdev
,
2539 struct qca_version
*ver
,
2540 const struct qca_device_info
*info
)
2542 struct qca_rampatch_version
*rver
;
2543 const struct firmware
*fw
;
2544 u32 ver_rom
, ver_patch
;
2545 u16 rver_rom
, rver_patch
;
2549 ver_rom
= le32_to_cpu(ver
->rom_version
);
2550 ver_patch
= le32_to_cpu(ver
->patch_version
);
2552 snprintf(fwname
, sizeof(fwname
), "qca/rampatch_usb_%08x.bin", ver_rom
);
2554 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
2556 BT_ERR("%s: failed to request rampatch file: %s (%d)",
2557 hdev
->name
, fwname
, err
);
2561 BT_INFO("%s: using rampatch file: %s", hdev
->name
, fwname
);
2563 rver
= (struct qca_rampatch_version
*)(fw
->data
+ info
->ver_offset
);
2564 rver_rom
= le16_to_cpu(rver
->rom_version
);
2565 rver_patch
= le16_to_cpu(rver
->patch_version
);
2567 BT_INFO("%s: QCA: patch rome 0x%x build 0x%x, firmware rome 0x%x "
2568 "build 0x%x", hdev
->name
, rver_rom
, rver_patch
, ver_rom
,
2571 if (rver_rom
!= ver_rom
|| rver_patch
<= ver_patch
) {
2572 BT_ERR("%s: rampatch file version did not match with firmware",
2578 err
= btusb_setup_qca_download_fw(hdev
, fw
, info
->rampatch_hdr
);
2581 release_firmware(fw
);
2586 static int btusb_setup_qca_load_nvm(struct hci_dev
*hdev
,
2587 struct qca_version
*ver
,
2588 const struct qca_device_info
*info
)
2590 const struct firmware
*fw
;
2594 snprintf(fwname
, sizeof(fwname
), "qca/nvm_usb_%08x.bin",
2595 le32_to_cpu(ver
->rom_version
));
2597 err
= request_firmware(&fw
, fwname
, &hdev
->dev
);
2599 BT_ERR("%s: failed to request NVM file: %s (%d)",
2600 hdev
->name
, fwname
, err
);
2604 BT_INFO("%s: using NVM file: %s", hdev
->name
, fwname
);
2606 err
= btusb_setup_qca_download_fw(hdev
, fw
, info
->nvm_hdr
);
2608 release_firmware(fw
);
2613 static int btusb_setup_qca(struct hci_dev
*hdev
)
2615 const struct qca_device_info
*info
= NULL
;
2616 struct qca_version ver
;
2621 err
= btusb_qca_send_vendor_req(hdev
, QCA_GET_TARGET_VERSION
, &ver
,
2626 ver_rom
= le32_to_cpu(ver
.rom_version
);
2627 for (i
= 0; i
< ARRAY_SIZE(qca_devices_table
); i
++) {
2628 if (ver_rom
== qca_devices_table
[i
].rom_version
)
2629 info
= &qca_devices_table
[i
];
2632 BT_ERR("%s: don't support firmware rome 0x%x", hdev
->name
,
2637 err
= btusb_qca_send_vendor_req(hdev
, QCA_CHECK_STATUS
, &status
,
2642 if (!(status
& QCA_PATCH_UPDATED
)) {
2643 err
= btusb_setup_qca_load_rampatch(hdev
, &ver
, info
);
2648 if (!(status
& QCA_SYSCFG_UPDATED
)) {
2649 err
= btusb_setup_qca_load_nvm(hdev
, &ver
, info
);
2657 #ifdef CONFIG_BT_HCIBTUSB_BCM
2658 static inline int __set_diag_interface(struct hci_dev
*hdev
)
2660 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2661 struct usb_interface
*intf
= data
->diag
;
2667 data
->diag_tx_ep
= NULL
;
2668 data
->diag_rx_ep
= NULL
;
2670 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
2671 struct usb_endpoint_descriptor
*ep_desc
;
2673 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
2675 if (!data
->diag_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
2676 data
->diag_tx_ep
= ep_desc
;
2680 if (!data
->diag_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
2681 data
->diag_rx_ep
= ep_desc
;
2686 if (!data
->diag_tx_ep
|| !data
->diag_rx_ep
) {
2687 BT_ERR("%s invalid diagnostic descriptors", hdev
->name
);
2694 static struct urb
*alloc_diag_urb(struct hci_dev
*hdev
, bool enable
)
2696 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2697 struct sk_buff
*skb
;
2701 if (!data
->diag_tx_ep
)
2702 return ERR_PTR(-ENODEV
);
2704 urb
= usb_alloc_urb(0, GFP_KERNEL
);
2706 return ERR_PTR(-ENOMEM
);
2708 skb
= bt_skb_alloc(2, GFP_KERNEL
);
2711 return ERR_PTR(-ENOMEM
);
2714 *skb_put(skb
, 1) = 0xf0;
2715 *skb_put(skb
, 1) = enable
;
2717 pipe
= usb_sndbulkpipe(data
->udev
, data
->diag_tx_ep
->bEndpointAddress
);
2719 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
2720 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
2722 skb
->dev
= (void *)hdev
;
2727 static int btusb_bcm_set_diag(struct hci_dev
*hdev
, bool enable
)
2729 struct btusb_data
*data
= hci_get_drvdata(hdev
);
2735 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
2738 urb
= alloc_diag_urb(hdev
, enable
);
2740 return PTR_ERR(urb
);
2742 return submit_or_queue_tx_urb(hdev
, urb
);
2746 static int btusb_probe(struct usb_interface
*intf
,
2747 const struct usb_device_id
*id
)
2749 struct usb_endpoint_descriptor
*ep_desc
;
2750 struct btusb_data
*data
;
2751 struct hci_dev
*hdev
;
2754 BT_DBG("intf %p id %p", intf
, id
);
2756 /* interface numbers are hardcoded in the spec */
2757 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
2760 if (!id
->driver_info
) {
2761 const struct usb_device_id
*match
;
2763 match
= usb_match_id(intf
, blacklist_table
);
2768 if (id
->driver_info
== BTUSB_IGNORE
)
2771 if (id
->driver_info
& BTUSB_ATH3012
) {
2772 struct usb_device
*udev
= interface_to_usbdev(intf
);
2774 /* Old firmware would otherwise let ath3k driver load
2775 * patch and sysconfig files */
2776 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) <= 0x0001)
2780 data
= devm_kzalloc(&intf
->dev
, sizeof(*data
), GFP_KERNEL
);
2784 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
2785 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
2787 if (!data
->intr_ep
&& usb_endpoint_is_int_in(ep_desc
)) {
2788 data
->intr_ep
= ep_desc
;
2792 if (!data
->bulk_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
2793 data
->bulk_tx_ep
= ep_desc
;
2797 if (!data
->bulk_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
2798 data
->bulk_rx_ep
= ep_desc
;
2803 if (!data
->intr_ep
|| !data
->bulk_tx_ep
|| !data
->bulk_rx_ep
)
2806 if (id
->driver_info
& BTUSB_AMP
) {
2807 data
->cmdreq_type
= USB_TYPE_CLASS
| 0x01;
2808 data
->cmdreq
= 0x2b;
2810 data
->cmdreq_type
= USB_TYPE_CLASS
;
2811 data
->cmdreq
= 0x00;
2814 data
->udev
= interface_to_usbdev(intf
);
2817 INIT_WORK(&data
->work
, btusb_work
);
2818 INIT_WORK(&data
->waker
, btusb_waker
);
2819 init_usb_anchor(&data
->deferred
);
2820 init_usb_anchor(&data
->tx_anchor
);
2821 spin_lock_init(&data
->txlock
);
2823 init_usb_anchor(&data
->intr_anchor
);
2824 init_usb_anchor(&data
->bulk_anchor
);
2825 init_usb_anchor(&data
->isoc_anchor
);
2826 init_usb_anchor(&data
->diag_anchor
);
2827 spin_lock_init(&data
->rxlock
);
2829 if (id
->driver_info
& BTUSB_INTEL_NEW
) {
2830 data
->recv_event
= btusb_recv_event_intel
;
2831 data
->recv_bulk
= btusb_recv_bulk_intel
;
2832 set_bit(BTUSB_BOOTLOADER
, &data
->flags
);
2834 data
->recv_event
= hci_recv_frame
;
2835 data
->recv_bulk
= btusb_recv_bulk
;
2838 hdev
= hci_alloc_dev();
2842 hdev
->bus
= HCI_USB
;
2843 hci_set_drvdata(hdev
, data
);
2845 if (id
->driver_info
& BTUSB_AMP
)
2846 hdev
->dev_type
= HCI_AMP
;
2848 hdev
->dev_type
= HCI_BREDR
;
2852 SET_HCIDEV_DEV(hdev
, &intf
->dev
);
2854 hdev
->open
= btusb_open
;
2855 hdev
->close
= btusb_close
;
2856 hdev
->flush
= btusb_flush
;
2857 hdev
->send
= btusb_send_frame
;
2858 hdev
->notify
= btusb_notify
;
2860 if (id
->driver_info
& BTUSB_BCM92035
)
2861 hdev
->setup
= btusb_setup_bcm92035
;
2863 #ifdef CONFIG_BT_HCIBTUSB_BCM
2864 if (id
->driver_info
& BTUSB_BCM_PATCHRAM
) {
2865 hdev
->setup
= btbcm_setup_patchram
;
2866 hdev
->set_diag
= btusb_bcm_set_diag
;
2867 hdev
->set_bdaddr
= btbcm_set_bdaddr
;
2869 /* Broadcom LM_DIAG Interface numbers are hardcoded */
2870 data
->diag
= usb_ifnum_to_if(data
->udev
, 2);
2873 if (id
->driver_info
& BTUSB_BCM_APPLE
) {
2874 hdev
->setup
= btbcm_setup_apple
;
2875 hdev
->set_diag
= btusb_bcm_set_diag
;
2877 /* Broadcom LM_DIAG Interface numbers are hardcoded */
2878 data
->diag
= usb_ifnum_to_if(data
->udev
, 2);
2882 if (id
->driver_info
& BTUSB_INTEL
) {
2883 hdev
->setup
= btusb_setup_intel
;
2884 hdev
->shutdown
= btusb_shutdown_intel
;
2885 hdev
->set_bdaddr
= btintel_set_bdaddr
;
2886 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
2887 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2890 if (id
->driver_info
& BTUSB_INTEL_NEW
) {
2891 hdev
->send
= btusb_send_frame_intel
;
2892 hdev
->setup
= btusb_setup_intel_new
;
2893 hdev
->hw_error
= btintel_hw_error
;
2894 hdev
->set_diag
= btintel_set_diag
;
2895 hdev
->set_bdaddr
= btintel_set_bdaddr
;
2896 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
2897 set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG
, &hdev
->quirks
);
2900 if (id
->driver_info
& BTUSB_MARVELL
)
2901 hdev
->set_bdaddr
= btusb_set_bdaddr_marvell
;
2903 if (id
->driver_info
& BTUSB_SWAVE
) {
2904 set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE
, &hdev
->quirks
);
2905 set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS
, &hdev
->quirks
);
2908 if (id
->driver_info
& BTUSB_INTEL_BOOT
)
2909 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
2911 if (id
->driver_info
& BTUSB_ATH3012
) {
2912 hdev
->set_bdaddr
= btusb_set_bdaddr_ath3012
;
2913 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2914 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
2917 if (id
->driver_info
& BTUSB_QCA_ROME
) {
2918 data
->setup_on_usb
= btusb_setup_qca
;
2919 hdev
->set_bdaddr
= btusb_set_bdaddr_ath3012
;
2922 #ifdef CONFIG_BT_HCIBTUSB_RTL
2923 if (id
->driver_info
& BTUSB_REALTEK
) {
2924 hdev
->setup
= btrtl_setup_realtek
;
2926 /* Realtek devices lose their updated firmware over suspend,
2927 * but the USB hub doesn't notice any status change.
2928 * Explicitly request a device reset on resume.
2930 set_bit(BTUSB_RESET_RESUME
, &data
->flags
);
2934 if (id
->driver_info
& BTUSB_AMP
) {
2935 /* AMP controllers do not support SCO packets */
2938 /* Interface numbers are hardcoded in the specification */
2939 data
->isoc
= usb_ifnum_to_if(data
->udev
, 1);
2943 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2945 if (force_scofix
|| id
->driver_info
& BTUSB_WRONG_SCO_MTU
) {
2946 if (!disable_scofix
)
2947 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
);
2950 if (id
->driver_info
& BTUSB_BROKEN_ISOC
)
2953 if (id
->driver_info
& BTUSB_DIGIANSWER
) {
2954 data
->cmdreq_type
= USB_TYPE_VENDOR
;
2955 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2958 if (id
->driver_info
& BTUSB_CSR
) {
2959 struct usb_device
*udev
= data
->udev
;
2960 u16 bcdDevice
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
2962 /* Old firmware would otherwise execute USB reset */
2963 if (bcdDevice
< 0x117)
2964 set_bit(HCI_QUIRK_RESET_ON_CLOSE
, &hdev
->quirks
);
2966 /* Fake CSR devices with broken commands */
2967 if (bcdDevice
<= 0x100 || bcdDevice
== 0x134)
2968 hdev
->setup
= btusb_setup_csr
;
2970 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
2973 if (id
->driver_info
& BTUSB_SNIFFER
) {
2974 struct usb_device
*udev
= data
->udev
;
2976 /* New sniffer firmware has crippled HCI interface */
2977 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) > 0x997)
2978 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
2981 if (id
->driver_info
& BTUSB_INTEL_BOOT
) {
2982 /* A bug in the bootloader causes that interrupt interface is
2983 * only enabled after receiving SetInterface(0, AltSetting=0).
2985 err
= usb_set_interface(data
->udev
, 0, 0);
2987 BT_ERR("failed to set interface 0, alt 0 %d", err
);
2994 err
= usb_driver_claim_interface(&btusb_driver
,
3002 #ifdef CONFIG_BT_HCIBTUSB_BCM
3004 if (!usb_driver_claim_interface(&btusb_driver
,
3006 __set_diag_interface(hdev
);
3012 err
= hci_register_dev(hdev
);
3018 usb_set_intfdata(intf
, data
);
3023 static void btusb_disconnect(struct usb_interface
*intf
)
3025 struct btusb_data
*data
= usb_get_intfdata(intf
);
3026 struct hci_dev
*hdev
;
3028 BT_DBG("intf %p", intf
);
3034 usb_set_intfdata(data
->intf
, NULL
);
3037 usb_set_intfdata(data
->isoc
, NULL
);
3040 usb_set_intfdata(data
->diag
, NULL
);
3042 hci_unregister_dev(hdev
);
3044 if (intf
== data
->intf
) {
3046 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
3048 usb_driver_release_interface(&btusb_driver
, data
->diag
);
3049 } else if (intf
== data
->isoc
) {
3051 usb_driver_release_interface(&btusb_driver
, data
->diag
);
3052 usb_driver_release_interface(&btusb_driver
, data
->intf
);
3053 } else if (intf
== data
->diag
) {
3054 usb_driver_release_interface(&btusb_driver
, data
->intf
);
3056 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
3063 static int btusb_suspend(struct usb_interface
*intf
, pm_message_t message
)
3065 struct btusb_data
*data
= usb_get_intfdata(intf
);
3067 BT_DBG("intf %p", intf
);
3069 if (data
->suspend_count
++)
3072 spin_lock_irq(&data
->txlock
);
3073 if (!(PMSG_IS_AUTO(message
) && data
->tx_in_flight
)) {
3074 set_bit(BTUSB_SUSPENDING
, &data
->flags
);
3075 spin_unlock_irq(&data
->txlock
);
3077 spin_unlock_irq(&data
->txlock
);
3078 data
->suspend_count
--;
3082 cancel_work_sync(&data
->work
);
3084 btusb_stop_traffic(data
);
3085 usb_kill_anchored_urbs(&data
->tx_anchor
);
3087 /* Optionally request a device reset on resume, but only when
3088 * wakeups are disabled. If wakeups are enabled we assume the
3089 * device will stay powered up throughout suspend.
3091 if (test_bit(BTUSB_RESET_RESUME
, &data
->flags
) &&
3092 !device_may_wakeup(&data
->udev
->dev
))
3093 data
->udev
->reset_resume
= 1;
3098 static void play_deferred(struct btusb_data
*data
)
3103 while ((urb
= usb_get_from_anchor(&data
->deferred
))) {
3104 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
3108 data
->tx_in_flight
++;
3110 usb_scuttle_anchored_urbs(&data
->deferred
);
3113 static int btusb_resume(struct usb_interface
*intf
)
3115 struct btusb_data
*data
= usb_get_intfdata(intf
);
3116 struct hci_dev
*hdev
= data
->hdev
;
3119 BT_DBG("intf %p", intf
);
3121 if (--data
->suspend_count
)
3124 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
3127 if (test_bit(BTUSB_INTR_RUNNING
, &data
->flags
)) {
3128 err
= btusb_submit_intr_urb(hdev
, GFP_NOIO
);
3130 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
3135 if (test_bit(BTUSB_BULK_RUNNING
, &data
->flags
)) {
3136 err
= btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
3138 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
3142 btusb_submit_bulk_urb(hdev
, GFP_NOIO
);
3145 if (test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
3146 if (btusb_submit_isoc_urb(hdev
, GFP_NOIO
) < 0)
3147 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
3149 btusb_submit_isoc_urb(hdev
, GFP_NOIO
);
3152 spin_lock_irq(&data
->txlock
);
3153 play_deferred(data
);
3154 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
3155 spin_unlock_irq(&data
->txlock
);
3156 schedule_work(&data
->work
);
3161 usb_scuttle_anchored_urbs(&data
->deferred
);
3163 spin_lock_irq(&data
->txlock
);
3164 clear_bit(BTUSB_SUSPENDING
, &data
->flags
);
3165 spin_unlock_irq(&data
->txlock
);
3171 static struct usb_driver btusb_driver
= {
3173 .probe
= btusb_probe
,
3174 .disconnect
= btusb_disconnect
,
3176 .suspend
= btusb_suspend
,
3177 .resume
= btusb_resume
,
3179 .id_table
= btusb_table
,
3180 .supports_autosuspend
= 1,
3181 .disable_hub_initiated_lpm
= 1,
3184 module_usb_driver(btusb_driver
);
3186 module_param(disable_scofix
, bool, 0644);
3187 MODULE_PARM_DESC(disable_scofix
, "Disable fixup of wrong SCO buffer size");
3189 module_param(force_scofix
, bool, 0644);
3190 MODULE_PARM_DESC(force_scofix
, "Force fixup of wrong SCO buffers size");
3192 module_param(reset
, bool, 0644);
3193 MODULE_PARM_DESC(reset
, "Send HCI reset command on initialization");
3195 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
3196 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION
);
3197 MODULE_VERSION(VERSION
);
3198 MODULE_LICENSE("GPL");