]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/bluetooth/btusb.c
Bluetooth: Check for P-256 OOB values in Secure Connections Only mode
[mirror_ubuntu-hirsute-kernel.git] / drivers / bluetooth / btusb.c
CommitLineData
5e23b923
MH
1/*
2 *
3 * Generic Bluetooth USB driver
4 *
9bfa35fe 5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
5e23b923
MH
6 *
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
5e23b923 24#include <linux/module.h>
5e23b923 25#include <linux/usb.h>
dffd30ee 26#include <linux/firmware.h>
5e23b923
MH
27
28#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/hci_core.h>
30
cda0dd78 31#define VERSION "0.7"
cfeb4145 32
90ab5ee9
RR
33static bool disable_scofix;
34static bool force_scofix;
7a9d4020 35
90ab5ee9 36static bool reset = 1;
cfeb4145
MH
37
38static struct usb_driver btusb_driver;
39
40#define BTUSB_IGNORE 0x01
7a9d4020
MH
41#define BTUSB_DIGIANSWER 0x02
42#define BTUSB_CSR 0x04
43#define BTUSB_SNIFFER 0x08
44#define BTUSB_BCM92035 0x10
45#define BTUSB_BROKEN_ISOC 0x20
46#define BTUSB_WRONG_SCO_MTU 0x40
2d25f8b4 47#define BTUSB_ATH3012 0x80
dffd30ee 48#define BTUSB_INTEL 0x100
40df783d
MH
49#define BTUSB_INTEL_BOOT 0x200
50#define BTUSB_BCM_PATCHRAM 0x400
ae8df494 51#define BTUSB_MARVELL 0x800
4fcef8ed 52#define BTUSB_SWAVE 0x1000
cda0dd78 53#define BTUSB_INTEL_NEW 0x2000
5e23b923 54
54265202 55static const struct usb_device_id btusb_table[] = {
5e23b923
MH
56 /* Generic Bluetooth USB device */
57 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
58
1fa6535f
HR
59 /* Apple-specific (Broadcom) devices */
60 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
61
178c059e
CYC
62 /* MediaTek MT76x0E */
63 { USB_DEVICE(0x0e8d, 0x763f) },
64
c510eae3 65 /* Broadcom SoftSailing reporting vendor specific */
2e8b5063 66 { USB_DEVICE(0x0a5c, 0x21e1) },
c510eae3 67
3cd01976
NI
68 /* Apple MacBookPro 7,1 */
69 { USB_DEVICE(0x05ac, 0x8213) },
70
0a79f674
CL
71 /* Apple iMac11,1 */
72 { USB_DEVICE(0x05ac, 0x8215) },
73
9c047157
NI
74 /* Apple MacBookPro6,2 */
75 { USB_DEVICE(0x05ac, 0x8218) },
76
3e3ede7d
EH
77 /* Apple MacBookAir3,1, MacBookAir3,2 */
78 { USB_DEVICE(0x05ac, 0x821b) },
79
a63b723d
PAVM
80 /* Apple MacBookAir4,1 */
81 { USB_DEVICE(0x05ac, 0x821f) },
82
88d377b6
MAP
83 /* Apple MacBookPro8,2 */
84 { USB_DEVICE(0x05ac, 0x821a) },
85
f78b6826
JK
86 /* Apple MacMini5,1 */
87 { USB_DEVICE(0x05ac, 0x8281) },
88
cfeb4145 89 /* AVM BlueFRITZ! USB v2.0 */
4fcef8ed 90 { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE },
cfeb4145
MH
91
92 /* Bluetooth Ultraport Module from IBM */
93 { USB_DEVICE(0x04bf, 0x030a) },
94
95 /* ALPS Modules with non-standard id */
96 { USB_DEVICE(0x044e, 0x3001) },
97 { USB_DEVICE(0x044e, 0x3002) },
98
99 /* Ericsson with non-standard id */
100 { USB_DEVICE(0x0bdb, 0x1002) },
101
102 /* Canyon CN-BTU1 with HID interfaces */
7a9d4020 103 { USB_DEVICE(0x0c10, 0x0000) },
cfeb4145 104
d13431ca 105 /* Broadcom BCM20702A0 */
0b880062
AS
106 { USB_DEVICE(0x0489, 0xe042) },
107 { USB_DEVICE(0x04ca, 0x2003) },
1ee3ff61 108 { USB_DEVICE(0x0b05, 0x17b5) },
38a172be 109 { USB_DEVICE(0x0b05, 0x17cb) },
d13431ca 110 { USB_DEVICE(0x413c, 0x8197) },
a86c02ea
F
111 { USB_DEVICE(0x13d3, 0x3404),
112 .driver_info = BTUSB_BCM_PATCHRAM },
d13431ca 113
d049f4e5
MH
114 /* Broadcom BCM20702B0 (Dynex/Insignia) */
115 { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM },
116
98514036 117 /* Foxconn - Hon Hai */
6029ddc2
HS
118 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01),
119 .driver_info = BTUSB_BCM_PATCHRAM },
98514036 120
0b880062 121 /* Broadcom devices with vendor specific id */
10d4c673
PG
122 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
123 .driver_info = BTUSB_BCM_PATCHRAM },
92c385f4 124
c2aef6e8 125 /* ASUSTek Computer - Broadcom based */
9a5abdaa
RD
126 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01),
127 .driver_info = BTUSB_BCM_PATCHRAM },
c2aef6e8 128
5bcecf32
KB
129 /* Belkin F8065bf - Broadcom based */
130 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01) },
131
9113bfd8
JK
132 /* IMC Networks - Broadcom based */
133 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01) },
134
40df783d 135 /* Intel Bluetooth USB Bootloader (RAM module) */
d92f2df0
MH
136 { USB_DEVICE(0x8087, 0x0a5a),
137 .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC },
40df783d 138
5e23b923
MH
139 { } /* Terminating entry */
140};
141
142MODULE_DEVICE_TABLE(usb, btusb_table);
143
54265202 144static const struct usb_device_id blacklist_table[] = {
cfeb4145
MH
145 /* CSR BlueCore devices */
146 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
147
148 /* Broadcom BCM2033 without firmware */
149 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
150
be93112a 151 /* Atheros 3011 with sflash firmware */
0b880062
AS
152 { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
153 { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
154 { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
be93112a 155 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
6eda541d 156 { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
2a7bcccc 157 { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
be93112a 158
509e7861
CYC
159 /* Atheros AR9285 Malbec with sflash firmware */
160 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
161
d9f51b51 162 /* Atheros 3012 with sflash firmware */
0b880062
AS
163 { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
164 { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
165 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
166 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
167 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
4b552bc9 168 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
0b880062
AS
169 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
170 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
171 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
172 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
1fb4e09a 173 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
0b880062
AS
174 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
175 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
134d3b35 176 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
0b880062
AS
177 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
178 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
89d2975f 179 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
a735f9e2 180 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
d66629c1 181 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
2d25f8b4 182 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
94a32d10 183 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
07c0ea87 184 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
b131237c 185 { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
1e56f1eb 186 { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 },
0b880062 187 { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
ebaf5795 188 { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
0b880062 189 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
ac71311e 190 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
0a3658cc 191 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
0b880062
AS
192 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
193 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
eed307e2 194 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
5b77a1f3 195 { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
3bb30a7c 196 { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
033efa92 197 { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
fa2f1394 198 { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
d9f51b51 199
e9036e33
CYC
200 /* Atheros AR5BBU12 with sflash firmware */
201 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
202
85d59726 203 /* Atheros AR5BBU12 with sflash firmware */
bc21fde2 204 { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
0b880062 205 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
85d59726 206
cfeb4145 207 /* Broadcom BCM2035 */
7a9d4020 208 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
0b880062
AS
209 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
210 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
cfeb4145
MH
211
212 /* Broadcom BCM2045 */
7a9d4020
MH
213 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
214 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
bdbef3d6 215
cfeb4145 216 /* IBM/Lenovo ThinkPad with Broadcom chip */
7a9d4020
MH
217 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
218 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
cfeb4145
MH
219
220 /* HP laptop with Broadcom chip */
7a9d4020 221 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
cfeb4145
MH
222
223 /* Dell laptop with Broadcom chip */
7a9d4020 224 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
cfeb4145 225
5ddd4a60 226 /* Dell Wireless 370 and 410 devices */
7a9d4020 227 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
5ddd4a60 228 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
cfeb4145 229
7a9d4020
MH
230 /* Belkin F8T012 and F8T013 devices */
231 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
232 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
cfeb4145 233
5ddd4a60
MH
234 /* Asus WL-BTD202 device */
235 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
236
237 /* Kensington Bluetooth USB adapter */
238 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
239
cfeb4145
MH
240 /* RTX Telecom based adapters with buggy SCO support */
241 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
242 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
243
244 /* CONWISE Technology based adapters with buggy SCO support */
245 { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
246
4fcef8ed
MH
247 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */
248 { USB_DEVICE(0x1300, 0x0001), .driver_info = BTUSB_SWAVE },
249
cfeb4145
MH
250 /* Digianswer devices */
251 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
252 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
253
254 /* CSR BlueCore Bluetooth Sniffer */
4f64fa80
MH
255 { USB_DEVICE(0x0a12, 0x0002),
256 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
cfeb4145
MH
257
258 /* Frontline ComProbe Bluetooth Sniffer */
4f64fa80
MH
259 { USB_DEVICE(0x16d3, 0x0002),
260 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC },
cfeb4145 261
dffd30ee
THJA
262 /* Intel Bluetooth device */
263 { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL },
ef4e5e4a 264 { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL },
cda0dd78 265 { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW },
dffd30ee 266
ae8df494
AK
267 /* Marvell device */
268 { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL },
269 { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL },
270
5e23b923
MH
271 { } /* Terminating entry */
272};
273
9bfa35fe
MH
274#define BTUSB_MAX_ISOC_FRAMES 10
275
5e23b923
MH
276#define BTUSB_INTR_RUNNING 0
277#define BTUSB_BULK_RUNNING 1
9bfa35fe 278#define BTUSB_ISOC_RUNNING 2
7bee549e 279#define BTUSB_SUSPENDING 3
08b8b6c4 280#define BTUSB_DID_ISO_RESUME 4
cda0dd78
MH
281#define BTUSB_BOOTLOADER 5
282#define BTUSB_DOWNLOADING 6
283#define BTUSB_BOOTING 7
284#define BTUSB_FIRMWARE_FAILED 8
5e23b923
MH
285
286struct btusb_data {
287 struct hci_dev *hdev;
288 struct usb_device *udev;
5fbcd260 289 struct usb_interface *intf;
9bfa35fe 290 struct usb_interface *isoc;
5e23b923 291
5e23b923
MH
292 unsigned long flags;
293
294 struct work_struct work;
7bee549e 295 struct work_struct waker;
5e23b923 296
803b5836 297 struct usb_anchor deferred;
5e23b923 298 struct usb_anchor tx_anchor;
803b5836
MH
299 int tx_in_flight;
300 spinlock_t txlock;
301
5e23b923
MH
302 struct usb_anchor intr_anchor;
303 struct usb_anchor bulk_anchor;
9bfa35fe 304 struct usb_anchor isoc_anchor;
803b5836
MH
305 spinlock_t rxlock;
306
307 struct sk_buff *evt_skb;
308 struct sk_buff *acl_skb;
309 struct sk_buff *sco_skb;
5e23b923
MH
310
311 struct usb_endpoint_descriptor *intr_ep;
312 struct usb_endpoint_descriptor *bulk_tx_ep;
313 struct usb_endpoint_descriptor *bulk_rx_ep;
9bfa35fe
MH
314 struct usb_endpoint_descriptor *isoc_tx_ep;
315 struct usb_endpoint_descriptor *isoc_rx_ep;
316
7a9d4020
MH
317 __u8 cmdreq_type;
318
43c2e57f 319 unsigned int sco_num;
9bfa35fe 320 int isoc_altsetting;
6a88adf2 321 int suspend_count;
2cbd3f5c 322
97307f51 323 int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
2cbd3f5c 324 int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
5e23b923
MH
325};
326
803b5836
MH
327static inline void btusb_free_frags(struct btusb_data *data)
328{
329 unsigned long flags;
330
331 spin_lock_irqsave(&data->rxlock, flags);
332
333 kfree_skb(data->evt_skb);
334 data->evt_skb = NULL;
335
336 kfree_skb(data->acl_skb);
337 data->acl_skb = NULL;
338
339 kfree_skb(data->sco_skb);
340 data->sco_skb = NULL;
341
342 spin_unlock_irqrestore(&data->rxlock, flags);
343}
344
1ffa4ad0
MH
345static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
346{
803b5836
MH
347 struct sk_buff *skb;
348 int err = 0;
349
350 spin_lock(&data->rxlock);
351 skb = data->evt_skb;
352
353 while (count) {
354 int len;
355
356 if (!skb) {
357 skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC);
358 if (!skb) {
359 err = -ENOMEM;
360 break;
361 }
362
363 bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
364 bt_cb(skb)->expect = HCI_EVENT_HDR_SIZE;
365 }
366
367 len = min_t(uint, bt_cb(skb)->expect, count);
368 memcpy(skb_put(skb, len), buffer, len);
369
370 count -= len;
371 buffer += len;
372 bt_cb(skb)->expect -= len;
373
374 if (skb->len == HCI_EVENT_HDR_SIZE) {
375 /* Complete event header */
376 bt_cb(skb)->expect = hci_event_hdr(skb)->plen;
377
378 if (skb_tailroom(skb) < bt_cb(skb)->expect) {
379 kfree_skb(skb);
380 skb = NULL;
381
382 err = -EILSEQ;
383 break;
384 }
385 }
386
387 if (bt_cb(skb)->expect == 0) {
388 /* Complete frame */
97307f51 389 data->recv_event(data->hdev, skb);
803b5836
MH
390 skb = NULL;
391 }
392 }
393
394 data->evt_skb = skb;
395 spin_unlock(&data->rxlock);
396
397 return err;
1ffa4ad0
MH
398}
399
400static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
401{
803b5836
MH
402 struct sk_buff *skb;
403 int err = 0;
404
405 spin_lock(&data->rxlock);
406 skb = data->acl_skb;
407
408 while (count) {
409 int len;
410
411 if (!skb) {
412 skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
413 if (!skb) {
414 err = -ENOMEM;
415 break;
416 }
417
418 bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
419 bt_cb(skb)->expect = HCI_ACL_HDR_SIZE;
420 }
421
422 len = min_t(uint, bt_cb(skb)->expect, count);
423 memcpy(skb_put(skb, len), buffer, len);
424
425 count -= len;
426 buffer += len;
427 bt_cb(skb)->expect -= len;
428
429 if (skb->len == HCI_ACL_HDR_SIZE) {
430 __le16 dlen = hci_acl_hdr(skb)->dlen;
431
432 /* Complete ACL header */
433 bt_cb(skb)->expect = __le16_to_cpu(dlen);
434
435 if (skb_tailroom(skb) < bt_cb(skb)->expect) {
436 kfree_skb(skb);
437 skb = NULL;
438
439 err = -EILSEQ;
440 break;
441 }
442 }
443
444 if (bt_cb(skb)->expect == 0) {
445 /* Complete frame */
446 hci_recv_frame(data->hdev, skb);
447 skb = NULL;
448 }
449 }
450
451 data->acl_skb = skb;
452 spin_unlock(&data->rxlock);
453
454 return err;
1ffa4ad0
MH
455}
456
457static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count)
458{
803b5836
MH
459 struct sk_buff *skb;
460 int err = 0;
461
462 spin_lock(&data->rxlock);
463 skb = data->sco_skb;
464
465 while (count) {
466 int len;
467
468 if (!skb) {
469 skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC);
470 if (!skb) {
471 err = -ENOMEM;
472 break;
473 }
474
475 bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
476 bt_cb(skb)->expect = HCI_SCO_HDR_SIZE;
477 }
478
479 len = min_t(uint, bt_cb(skb)->expect, count);
480 memcpy(skb_put(skb, len), buffer, len);
481
482 count -= len;
483 buffer += len;
484 bt_cb(skb)->expect -= len;
485
486 if (skb->len == HCI_SCO_HDR_SIZE) {
487 /* Complete SCO header */
488 bt_cb(skb)->expect = hci_sco_hdr(skb)->dlen;
489
490 if (skb_tailroom(skb) < bt_cb(skb)->expect) {
491 kfree_skb(skb);
492 skb = NULL;
493
494 err = -EILSEQ;
495 break;
496 }
497 }
498
499 if (bt_cb(skb)->expect == 0) {
500 /* Complete frame */
501 hci_recv_frame(data->hdev, skb);
502 skb = NULL;
503 }
504 }
505
506 data->sco_skb = skb;
507 spin_unlock(&data->rxlock);
508
509 return err;
1ffa4ad0
MH
510}
511
5e23b923
MH
512static void btusb_intr_complete(struct urb *urb)
513{
514 struct hci_dev *hdev = urb->context;
155961e8 515 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
516 int err;
517
89e7533d
MH
518 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
519 urb->actual_length);
5e23b923
MH
520
521 if (!test_bit(HCI_RUNNING, &hdev->flags))
522 return;
523
524 if (urb->status == 0) {
9bfa35fe
MH
525 hdev->stat.byte_rx += urb->actual_length;
526
1ffa4ad0
MH
527 if (btusb_recv_intr(data, urb->transfer_buffer,
528 urb->actual_length) < 0) {
5e23b923
MH
529 BT_ERR("%s corrupted event packet", hdev->name);
530 hdev->stat.err_rx++;
531 }
85560c4a
CC
532 } else if (urb->status == -ENOENT) {
533 /* Avoid suspend failed when usb_kill_urb */
534 return;
5e23b923
MH
535 }
536
537 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
538 return;
539
7bee549e 540 usb_mark_last_busy(data->udev);
5e23b923
MH
541 usb_anchor_urb(urb, &data->intr_anchor);
542
543 err = usb_submit_urb(urb, GFP_ATOMIC);
544 if (err < 0) {
4935f1c1
PB
545 /* -EPERM: urb is being killed;
546 * -ENODEV: device got disconnected */
547 if (err != -EPERM && err != -ENODEV)
61faddf6 548 BT_ERR("%s urb %p failed to resubmit (%d)",
89e7533d 549 hdev->name, urb, -err);
5e23b923
MH
550 usb_unanchor_urb(urb);
551 }
552}
553
2eda66f4 554static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
5e23b923 555{
155961e8 556 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
557 struct urb *urb;
558 unsigned char *buf;
559 unsigned int pipe;
560 int err, size;
561
562 BT_DBG("%s", hdev->name);
563
9bfa35fe
MH
564 if (!data->intr_ep)
565 return -ENODEV;
566
2eda66f4 567 urb = usb_alloc_urb(0, mem_flags);
5e23b923
MH
568 if (!urb)
569 return -ENOMEM;
570
571 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
572
2eda66f4 573 buf = kmalloc(size, mem_flags);
5e23b923
MH
574 if (!buf) {
575 usb_free_urb(urb);
576 return -ENOMEM;
577 }
578
579 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
580
581 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
89e7533d 582 btusb_intr_complete, hdev, data->intr_ep->bInterval);
5e23b923
MH
583
584 urb->transfer_flags |= URB_FREE_BUFFER;
585
586 usb_anchor_urb(urb, &data->intr_anchor);
587
2eda66f4 588 err = usb_submit_urb(urb, mem_flags);
5e23b923 589 if (err < 0) {
d4b8d1c9
PB
590 if (err != -EPERM && err != -ENODEV)
591 BT_ERR("%s urb %p submission failed (%d)",
89e7533d 592 hdev->name, urb, -err);
5e23b923 593 usb_unanchor_urb(urb);
5e23b923
MH
594 }
595
596 usb_free_urb(urb);
597
598 return err;
599}
600
601static void btusb_bulk_complete(struct urb *urb)
602{
603 struct hci_dev *hdev = urb->context;
155961e8 604 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
605 int err;
606
89e7533d
MH
607 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
608 urb->actual_length);
5e23b923
MH
609
610 if (!test_bit(HCI_RUNNING, &hdev->flags))
611 return;
612
613 if (urb->status == 0) {
9bfa35fe
MH
614 hdev->stat.byte_rx += urb->actual_length;
615
2cbd3f5c 616 if (data->recv_bulk(data, urb->transfer_buffer,
1ffa4ad0 617 urb->actual_length) < 0) {
5e23b923
MH
618 BT_ERR("%s corrupted ACL packet", hdev->name);
619 hdev->stat.err_rx++;
620 }
85560c4a
CC
621 } else if (urb->status == -ENOENT) {
622 /* Avoid suspend failed when usb_kill_urb */
623 return;
5e23b923
MH
624 }
625
626 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
627 return;
628
629 usb_anchor_urb(urb, &data->bulk_anchor);
652fd781 630 usb_mark_last_busy(data->udev);
5e23b923
MH
631
632 err = usb_submit_urb(urb, GFP_ATOMIC);
633 if (err < 0) {
4935f1c1
PB
634 /* -EPERM: urb is being killed;
635 * -ENODEV: device got disconnected */
636 if (err != -EPERM && err != -ENODEV)
61faddf6 637 BT_ERR("%s urb %p failed to resubmit (%d)",
89e7533d 638 hdev->name, urb, -err);
5e23b923
MH
639 usb_unanchor_urb(urb);
640 }
641}
642
2eda66f4 643static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
5e23b923 644{
155961e8 645 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
646 struct urb *urb;
647 unsigned char *buf;
648 unsigned int pipe;
290ba200 649 int err, size = HCI_MAX_FRAME_SIZE;
5e23b923
MH
650
651 BT_DBG("%s", hdev->name);
652
9bfa35fe
MH
653 if (!data->bulk_rx_ep)
654 return -ENODEV;
655
2eda66f4 656 urb = usb_alloc_urb(0, mem_flags);
5e23b923
MH
657 if (!urb)
658 return -ENOMEM;
659
2eda66f4 660 buf = kmalloc(size, mem_flags);
5e23b923
MH
661 if (!buf) {
662 usb_free_urb(urb);
663 return -ENOMEM;
664 }
665
666 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
667
89e7533d
MH
668 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size,
669 btusb_bulk_complete, hdev);
5e23b923
MH
670
671 urb->transfer_flags |= URB_FREE_BUFFER;
672
7bee549e 673 usb_mark_last_busy(data->udev);
5e23b923
MH
674 usb_anchor_urb(urb, &data->bulk_anchor);
675
2eda66f4 676 err = usb_submit_urb(urb, mem_flags);
5e23b923 677 if (err < 0) {
d4b8d1c9
PB
678 if (err != -EPERM && err != -ENODEV)
679 BT_ERR("%s urb %p submission failed (%d)",
89e7533d 680 hdev->name, urb, -err);
5e23b923 681 usb_unanchor_urb(urb);
5e23b923
MH
682 }
683
684 usb_free_urb(urb);
685
686 return err;
687}
688
9bfa35fe
MH
689static void btusb_isoc_complete(struct urb *urb)
690{
691 struct hci_dev *hdev = urb->context;
155961e8 692 struct btusb_data *data = hci_get_drvdata(hdev);
9bfa35fe
MH
693 int i, err;
694
89e7533d
MH
695 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
696 urb->actual_length);
9bfa35fe
MH
697
698 if (!test_bit(HCI_RUNNING, &hdev->flags))
699 return;
700
701 if (urb->status == 0) {
702 for (i = 0; i < urb->number_of_packets; i++) {
703 unsigned int offset = urb->iso_frame_desc[i].offset;
704 unsigned int length = urb->iso_frame_desc[i].actual_length;
705
706 if (urb->iso_frame_desc[i].status)
707 continue;
708
709 hdev->stat.byte_rx += length;
710
1ffa4ad0
MH
711 if (btusb_recv_isoc(data, urb->transfer_buffer + offset,
712 length) < 0) {
9bfa35fe
MH
713 BT_ERR("%s corrupted SCO packet", hdev->name);
714 hdev->stat.err_rx++;
715 }
716 }
85560c4a
CC
717 } else if (urb->status == -ENOENT) {
718 /* Avoid suspend failed when usb_kill_urb */
719 return;
9bfa35fe
MH
720 }
721
722 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
723 return;
724
725 usb_anchor_urb(urb, &data->isoc_anchor);
726
727 err = usb_submit_urb(urb, GFP_ATOMIC);
728 if (err < 0) {
4935f1c1
PB
729 /* -EPERM: urb is being killed;
730 * -ENODEV: device got disconnected */
731 if (err != -EPERM && err != -ENODEV)
61faddf6 732 BT_ERR("%s urb %p failed to resubmit (%d)",
89e7533d 733 hdev->name, urb, -err);
9bfa35fe
MH
734 usb_unanchor_urb(urb);
735 }
736}
737
42b16b3f 738static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
9bfa35fe
MH
739{
740 int i, offset = 0;
741
742 BT_DBG("len %d mtu %d", len, mtu);
743
744 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
745 i++, offset += mtu, len -= mtu) {
746 urb->iso_frame_desc[i].offset = offset;
747 urb->iso_frame_desc[i].length = mtu;
748 }
749
750 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
751 urb->iso_frame_desc[i].offset = offset;
752 urb->iso_frame_desc[i].length = len;
753 i++;
754 }
755
756 urb->number_of_packets = i;
757}
758
2eda66f4 759static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
9bfa35fe 760{
155961e8 761 struct btusb_data *data = hci_get_drvdata(hdev);
9bfa35fe
MH
762 struct urb *urb;
763 unsigned char *buf;
764 unsigned int pipe;
765 int err, size;
766
767 BT_DBG("%s", hdev->name);
768
769 if (!data->isoc_rx_ep)
770 return -ENODEV;
771
2eda66f4 772 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
9bfa35fe
MH
773 if (!urb)
774 return -ENOMEM;
775
776 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
777 BTUSB_MAX_ISOC_FRAMES;
778
2eda66f4 779 buf = kmalloc(size, mem_flags);
9bfa35fe
MH
780 if (!buf) {
781 usb_free_urb(urb);
782 return -ENOMEM;
783 }
784
785 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
786
fa0fb93f 787 usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
89e7533d 788 hdev, data->isoc_rx_ep->bInterval);
9bfa35fe 789
89e7533d 790 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
9bfa35fe
MH
791
792 __fill_isoc_descriptor(urb, size,
89e7533d 793 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
9bfa35fe
MH
794
795 usb_anchor_urb(urb, &data->isoc_anchor);
796
2eda66f4 797 err = usb_submit_urb(urb, mem_flags);
9bfa35fe 798 if (err < 0) {
d4b8d1c9
PB
799 if (err != -EPERM && err != -ENODEV)
800 BT_ERR("%s urb %p submission failed (%d)",
89e7533d 801 hdev->name, urb, -err);
9bfa35fe 802 usb_unanchor_urb(urb);
9bfa35fe
MH
803 }
804
805 usb_free_urb(urb);
806
807 return err;
808}
809
5e23b923 810static void btusb_tx_complete(struct urb *urb)
7bee549e
ON
811{
812 struct sk_buff *skb = urb->context;
89e7533d 813 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
155961e8 814 struct btusb_data *data = hci_get_drvdata(hdev);
7bee549e 815
89e7533d
MH
816 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
817 urb->actual_length);
7bee549e
ON
818
819 if (!test_bit(HCI_RUNNING, &hdev->flags))
820 goto done;
821
822 if (!urb->status)
823 hdev->stat.byte_tx += urb->transfer_buffer_length;
824 else
825 hdev->stat.err_tx++;
826
827done:
828 spin_lock(&data->txlock);
829 data->tx_in_flight--;
830 spin_unlock(&data->txlock);
831
832 kfree(urb->setup_packet);
833
834 kfree_skb(skb);
835}
836
837static void btusb_isoc_tx_complete(struct urb *urb)
5e23b923
MH
838{
839 struct sk_buff *skb = urb->context;
89e7533d 840 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
5e23b923 841
89e7533d
MH
842 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status,
843 urb->actual_length);
5e23b923
MH
844
845 if (!test_bit(HCI_RUNNING, &hdev->flags))
846 goto done;
847
848 if (!urb->status)
849 hdev->stat.byte_tx += urb->transfer_buffer_length;
850 else
851 hdev->stat.err_tx++;
852
853done:
854 kfree(urb->setup_packet);
855
856 kfree_skb(skb);
857}
858
859static int btusb_open(struct hci_dev *hdev)
860{
155961e8 861 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
862 int err;
863
864 BT_DBG("%s", hdev->name);
865
7bee549e
ON
866 err = usb_autopm_get_interface(data->intf);
867 if (err < 0)
868 return err;
869
870 data->intf->needs_remote_wakeup = 1;
871
5e23b923 872 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
7bee549e 873 goto done;
5e23b923
MH
874
875 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
7bee549e 876 goto done;
5e23b923 877
2eda66f4 878 err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
43c2e57f
MH
879 if (err < 0)
880 goto failed;
881
882 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
5e23b923 883 if (err < 0) {
43c2e57f
MH
884 usb_kill_anchored_urbs(&data->intr_anchor);
885 goto failed;
5e23b923
MH
886 }
887
43c2e57f
MH
888 set_bit(BTUSB_BULK_RUNNING, &data->flags);
889 btusb_submit_bulk_urb(hdev, GFP_KERNEL);
890
7bee549e
ON
891done:
892 usb_autopm_put_interface(data->intf);
43c2e57f
MH
893 return 0;
894
895failed:
896 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
897 clear_bit(HCI_RUNNING, &hdev->flags);
7bee549e 898 usb_autopm_put_interface(data->intf);
5e23b923
MH
899 return err;
900}
901
7bee549e
ON
902static void btusb_stop_traffic(struct btusb_data *data)
903{
904 usb_kill_anchored_urbs(&data->intr_anchor);
905 usb_kill_anchored_urbs(&data->bulk_anchor);
906 usb_kill_anchored_urbs(&data->isoc_anchor);
907}
908
5e23b923
MH
909static int btusb_close(struct hci_dev *hdev)
910{
155961e8 911 struct btusb_data *data = hci_get_drvdata(hdev);
7bee549e 912 int err;
5e23b923
MH
913
914 BT_DBG("%s", hdev->name);
915
916 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
917 return 0;
918
e8c3c3d2 919 cancel_work_sync(&data->work);
404291ac 920 cancel_work_sync(&data->waker);
e8c3c3d2 921
9bfa35fe 922 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
5e23b923 923 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
5e23b923 924 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
7bee549e
ON
925
926 btusb_stop_traffic(data);
803b5836
MH
927 btusb_free_frags(data);
928
7bee549e
ON
929 err = usb_autopm_get_interface(data->intf);
930 if (err < 0)
7b8e2c1d 931 goto failed;
7bee549e
ON
932
933 data->intf->needs_remote_wakeup = 0;
934 usb_autopm_put_interface(data->intf);
5e23b923 935
7b8e2c1d
ON
936failed:
937 usb_scuttle_anchored_urbs(&data->deferred);
5e23b923
MH
938 return 0;
939}
940
941static int btusb_flush(struct hci_dev *hdev)
942{
155961e8 943 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
944
945 BT_DBG("%s", hdev->name);
946
947 usb_kill_anchored_urbs(&data->tx_anchor);
803b5836 948 btusb_free_frags(data);
5e23b923
MH
949
950 return 0;
951}
952
047b2ec8 953static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
5e23b923 954{
155961e8 955 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
956 struct usb_ctrlrequest *dr;
957 struct urb *urb;
958 unsigned int pipe;
5e23b923 959
047b2ec8
MH
960 urb = usb_alloc_urb(0, GFP_KERNEL);
961 if (!urb)
962 return ERR_PTR(-ENOMEM);
5e23b923 963
047b2ec8
MH
964 dr = kmalloc(sizeof(*dr), GFP_KERNEL);
965 if (!dr) {
966 usb_free_urb(urb);
967 return ERR_PTR(-ENOMEM);
968 }
5e23b923 969
047b2ec8
MH
970 dr->bRequestType = data->cmdreq_type;
971 dr->bRequest = 0;
972 dr->wIndex = 0;
973 dr->wValue = 0;
974 dr->wLength = __cpu_to_le16(skb->len);
7bd8f09f 975
047b2ec8 976 pipe = usb_sndctrlpipe(data->udev, 0x00);
5e23b923 977
89e7533d 978 usb_fill_control_urb(urb, data->udev, pipe, (void *)dr,
047b2ec8 979 skb->data, skb->len, btusb_tx_complete, skb);
5e23b923 980
89e7533d 981 skb->dev = (void *)hdev;
5e23b923 982
047b2ec8
MH
983 return urb;
984}
5e23b923 985
047b2ec8
MH
986static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
987{
988 struct btusb_data *data = hci_get_drvdata(hdev);
989 struct urb *urb;
990 unsigned int pipe;
5e23b923 991
047b2ec8
MH
992 if (!data->bulk_tx_ep)
993 return ERR_PTR(-ENODEV);
9bfa35fe 994
047b2ec8
MH
995 urb = usb_alloc_urb(0, GFP_KERNEL);
996 if (!urb)
997 return ERR_PTR(-ENOMEM);
5e23b923 998
047b2ec8 999 pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
5e23b923 1000
047b2ec8
MH
1001 usb_fill_bulk_urb(urb, data->udev, pipe,
1002 skb->data, skb->len, btusb_tx_complete, skb);
5e23b923 1003
89e7533d 1004 skb->dev = (void *)hdev;
5e23b923 1005
047b2ec8
MH
1006 return urb;
1007}
9bfa35fe 1008
047b2ec8
MH
1009static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
1010{
1011 struct btusb_data *data = hci_get_drvdata(hdev);
1012 struct urb *urb;
1013 unsigned int pipe;
9bfa35fe 1014
047b2ec8
MH
1015 if (!data->isoc_tx_ep)
1016 return ERR_PTR(-ENODEV);
9bfa35fe 1017
047b2ec8
MH
1018 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
1019 if (!urb)
1020 return ERR_PTR(-ENOMEM);
9bfa35fe 1021
047b2ec8 1022 pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
9bfa35fe 1023
047b2ec8
MH
1024 usb_fill_int_urb(urb, data->udev, pipe,
1025 skb->data, skb->len, btusb_isoc_tx_complete,
1026 skb, data->isoc_tx_ep->bInterval);
9bfa35fe 1027
047b2ec8 1028 urb->transfer_flags = URB_ISO_ASAP;
5e23b923 1029
047b2ec8
MH
1030 __fill_isoc_descriptor(urb, skb->len,
1031 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
5e23b923 1032
89e7533d 1033 skb->dev = (void *)hdev;
047b2ec8
MH
1034
1035 return urb;
1036}
1037
1038static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb)
1039{
1040 struct btusb_data *data = hci_get_drvdata(hdev);
1041 int err;
7bee549e 1042
5e23b923
MH
1043 usb_anchor_urb(urb, &data->tx_anchor);
1044
e9753eff 1045 err = usb_submit_urb(urb, GFP_KERNEL);
5e23b923 1046 if (err < 0) {
5a9b80e2
PB
1047 if (err != -EPERM && err != -ENODEV)
1048 BT_ERR("%s urb %p submission failed (%d)",
89e7533d 1049 hdev->name, urb, -err);
5e23b923
MH
1050 kfree(urb->setup_packet);
1051 usb_unanchor_urb(urb);
7bee549e
ON
1052 } else {
1053 usb_mark_last_busy(data->udev);
5e23b923
MH
1054 }
1055
54a8a79c 1056 usb_free_urb(urb);
5e23b923
MH
1057 return err;
1058}
1059
047b2ec8
MH
1060static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb)
1061{
1062 struct btusb_data *data = hci_get_drvdata(hdev);
1063 unsigned long flags;
1064 bool suspending;
1065
1066 spin_lock_irqsave(&data->txlock, flags);
1067 suspending = test_bit(BTUSB_SUSPENDING, &data->flags);
1068 if (!suspending)
1069 data->tx_in_flight++;
1070 spin_unlock_irqrestore(&data->txlock, flags);
1071
1072 if (!suspending)
1073 return submit_tx_urb(hdev, urb);
1074
1075 usb_anchor_urb(urb, &data->deferred);
1076 schedule_work(&data->waker);
1077
1078 usb_free_urb(urb);
1079 return 0;
1080}
1081
1082static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
1083{
1084 struct urb *urb;
1085
1086 BT_DBG("%s", hdev->name);
1087
1088 if (!test_bit(HCI_RUNNING, &hdev->flags))
1089 return -EBUSY;
1090
1091 switch (bt_cb(skb)->pkt_type) {
1092 case HCI_COMMAND_PKT:
1093 urb = alloc_ctrl_urb(hdev, skb);
1094 if (IS_ERR(urb))
1095 return PTR_ERR(urb);
1096
1097 hdev->stat.cmd_tx++;
1098 return submit_or_queue_tx_urb(hdev, urb);
1099
1100 case HCI_ACLDATA_PKT:
1101 urb = alloc_bulk_urb(hdev, skb);
1102 if (IS_ERR(urb))
1103 return PTR_ERR(urb);
1104
1105 hdev->stat.acl_tx++;
1106 return submit_or_queue_tx_urb(hdev, urb);
1107
1108 case HCI_SCODATA_PKT:
1109 if (hci_conn_num(hdev, SCO_LINK) < 1)
1110 return -ENODEV;
1111
1112 urb = alloc_isoc_urb(hdev, skb);
1113 if (IS_ERR(urb))
1114 return PTR_ERR(urb);
1115
1116 hdev->stat.sco_tx++;
1117 return submit_tx_urb(hdev, urb);
1118 }
1119
1120 return -EILSEQ;
1121}
1122
5e23b923
MH
1123static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
1124{
155961e8 1125 struct btusb_data *data = hci_get_drvdata(hdev);
5e23b923
MH
1126
1127 BT_DBG("%s evt %d", hdev->name, evt);
1128
014f7bc7
MH
1129 if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) {
1130 data->sco_num = hci_conn_num(hdev, SCO_LINK);
43c2e57f 1131 schedule_work(&data->work);
a780efa8 1132 }
5e23b923
MH
1133}
1134
42b16b3f 1135static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
9bfa35fe 1136{
155961e8 1137 struct btusb_data *data = hci_get_drvdata(hdev);
9bfa35fe
MH
1138 struct usb_interface *intf = data->isoc;
1139 struct usb_endpoint_descriptor *ep_desc;
1140 int i, err;
1141
1142 if (!data->isoc)
1143 return -ENODEV;
1144
1145 err = usb_set_interface(data->udev, 1, altsetting);
1146 if (err < 0) {
1147 BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
1148 return err;
1149 }
1150
1151 data->isoc_altsetting = altsetting;
1152
1153 data->isoc_tx_ep = NULL;
1154 data->isoc_rx_ep = NULL;
1155
1156 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
1157 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
1158
1159 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
1160 data->isoc_tx_ep = ep_desc;
1161 continue;
1162 }
1163
1164 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
1165 data->isoc_rx_ep = ep_desc;
1166 continue;
1167 }
1168 }
1169
1170 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
1171 BT_ERR("%s invalid SCO descriptors", hdev->name);
1172 return -ENODEV;
1173 }
1174
1175 return 0;
1176}
1177
5e23b923
MH
1178static void btusb_work(struct work_struct *work)
1179{
1180 struct btusb_data *data = container_of(work, struct btusb_data, work);
1181 struct hci_dev *hdev = data->hdev;
f4001d28 1182 int new_alts;
7bee549e 1183 int err;
5e23b923 1184
014f7bc7 1185 if (data->sco_num > 0) {
08b8b6c4 1186 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
8efdd0cd 1187 err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
7bee549e
ON
1188 if (err < 0) {
1189 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1190 usb_kill_anchored_urbs(&data->isoc_anchor);
1191 return;
1192 }
1193
08b8b6c4 1194 set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
7bee549e 1195 }
f4001d28
MA
1196
1197 if (hdev->voice_setting & 0x0020) {
1198 static const int alts[3] = { 2, 4, 5 };
89e7533d 1199
014f7bc7 1200 new_alts = alts[data->sco_num - 1];
f4001d28 1201 } else {
014f7bc7 1202 new_alts = data->sco_num;
f4001d28
MA
1203 }
1204
1205 if (data->isoc_altsetting != new_alts) {
9bfa35fe
MH
1206 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1207 usb_kill_anchored_urbs(&data->isoc_anchor);
1208
f4001d28 1209 if (__set_isoc_interface(hdev, new_alts) < 0)
9bfa35fe
MH
1210 return;
1211 }
1212
1213 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
2eda66f4 1214 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
9bfa35fe
MH
1215 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1216 else
2eda66f4 1217 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
9bfa35fe
MH
1218 }
1219 } else {
1220 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1221 usb_kill_anchored_urbs(&data->isoc_anchor);
1222
1223 __set_isoc_interface(hdev, 0);
08b8b6c4 1224 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
8efdd0cd 1225 usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
5e23b923
MH
1226 }
1227}
1228
7bee549e
ON
1229static void btusb_waker(struct work_struct *work)
1230{
1231 struct btusb_data *data = container_of(work, struct btusb_data, waker);
1232 int err;
1233
1234 err = usb_autopm_get_interface(data->intf);
1235 if (err < 0)
1236 return;
1237
1238 usb_autopm_put_interface(data->intf);
1239}
1240
9f8f962c
MH
1241static int btusb_setup_bcm92035(struct hci_dev *hdev)
1242{
1243 struct sk_buff *skb;
1244 u8 val = 0x00;
1245
1246 BT_DBG("%s", hdev->name);
1247
1248 skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT);
1249 if (IS_ERR(skb))
1250 BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb));
1251 else
1252 kfree_skb(skb);
1253
1254 return 0;
1255}
1256
81cac64b
MH
1257static int btusb_setup_csr(struct hci_dev *hdev)
1258{
1259 struct hci_rp_read_local_version *rp;
1260 struct sk_buff *skb;
1261 int ret;
1262
1263 BT_DBG("%s", hdev->name);
1264
1265 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
1266 HCI_INIT_TIMEOUT);
1267 if (IS_ERR(skb)) {
1268 BT_ERR("Reading local version failed (%ld)", -PTR_ERR(skb));
1269 return -PTR_ERR(skb);
1270 }
1271
89e7533d 1272 rp = (struct hci_rp_read_local_version *)skb->data;
81cac64b
MH
1273
1274 if (!rp->status) {
1275 if (le16_to_cpu(rp->manufacturer) != 10) {
1276 /* Clear the reset quirk since this is not an actual
1277 * early Bluetooth 1.1 device from CSR.
1278 */
1279 clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
1280
1281 /* These fake CSR controllers have all a broken
1282 * stored link key handling and so just disable it.
1283 */
1284 set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY,
1285 &hdev->quirks);
1286 }
1287 }
1288
1289 ret = -bt_to_errno(rp->status);
1290
1291 kfree_skb(skb);
1292
1293 return ret;
1294}
1295
dffd30ee
THJA
1296struct intel_version {
1297 u8 status;
1298 u8 hw_platform;
1299 u8 hw_variant;
1300 u8 hw_revision;
1301 u8 fw_variant;
1302 u8 fw_revision;
1303 u8 fw_build_num;
1304 u8 fw_build_ww;
1305 u8 fw_build_yy;
1306 u8 fw_patch_num;
1307} __packed;
1308
cda0dd78
MH
1309struct intel_boot_params {
1310 __u8 status;
1311 __u8 otp_format;
1312 __u8 otp_content;
1313 __u8 otp_patch;
1314 __le16 dev_revid;
1315 __u8 secure_boot;
1316 __u8 key_from_hdr;
1317 __u8 key_type;
1318 __u8 otp_lock;
1319 __u8 api_lock;
1320 __u8 debug_lock;
1321 bdaddr_t otp_bdaddr;
1322 __u8 min_fw_build_nn;
1323 __u8 min_fw_build_cw;
1324 __u8 min_fw_build_yy;
1325 __u8 limited_cce;
1326 __u8 unlocked_state;
1327} __packed;
1328
dffd30ee 1329static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev,
89e7533d 1330 struct intel_version *ver)
dffd30ee
THJA
1331{
1332 const struct firmware *fw;
1333 char fwname[64];
1334 int ret;
1335
1336 snprintf(fwname, sizeof(fwname),
1337 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
1338 ver->hw_platform, ver->hw_variant, ver->hw_revision,
1339 ver->fw_variant, ver->fw_revision, ver->fw_build_num,
1340 ver->fw_build_ww, ver->fw_build_yy);
1341
1342 ret = request_firmware(&fw, fwname, &hdev->dev);
1343 if (ret < 0) {
1344 if (ret == -EINVAL) {
1345 BT_ERR("%s Intel firmware file request failed (%d)",
1346 hdev->name, ret);
1347 return NULL;
1348 }
1349
1350 BT_ERR("%s failed to open Intel firmware file: %s(%d)",
1351 hdev->name, fwname, ret);
1352
1353 /* If the correct firmware patch file is not found, use the
1354 * default firmware patch file instead
1355 */
1356 snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq",
1357 ver->hw_platform, ver->hw_variant);
1358 if (request_firmware(&fw, fwname, &hdev->dev) < 0) {
1359 BT_ERR("%s failed to open default Intel fw file: %s",
1360 hdev->name, fwname);
1361 return NULL;
1362 }
1363 }
1364
1365 BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev->name, fwname);
1366
1367 return fw;
1368}
1369
1370static int btusb_setup_intel_patching(struct hci_dev *hdev,
1371 const struct firmware *fw,
1372 const u8 **fw_ptr, int *disable_patch)
1373{
1374 struct sk_buff *skb;
1375 struct hci_command_hdr *cmd;
1376 const u8 *cmd_param;
1377 struct hci_event_hdr *evt = NULL;
1378 const u8 *evt_param = NULL;
1379 int remain = fw->size - (*fw_ptr - fw->data);
1380
1381 /* The first byte indicates the types of the patch command or event.
1382 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1383 * in the current firmware buffer doesn't start with 0x01 or
1384 * the size of remain buffer is smaller than HCI command header,
1385 * the firmware file is corrupted and it should stop the patching
1386 * process.
1387 */
1388 if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) {
1389 BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev->name);
1390 return -EINVAL;
1391 }
1392 (*fw_ptr)++;
1393 remain--;
1394
1395 cmd = (struct hci_command_hdr *)(*fw_ptr);
1396 *fw_ptr += sizeof(*cmd);
1397 remain -= sizeof(*cmd);
1398
1399 /* Ensure that the remain firmware data is long enough than the length
1400 * of command parameter. If not, the firmware file is corrupted.
1401 */
1402 if (remain < cmd->plen) {
1403 BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev->name);
1404 return -EFAULT;
1405 }
1406
1407 /* If there is a command that loads a patch in the firmware
1408 * file, then enable the patch upon success, otherwise just
1409 * disable the manufacturer mode, for example patch activation
1410 * is not required when the default firmware patch file is used
1411 * because there are no patch data to load.
1412 */
1413 if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e)
1414 *disable_patch = 0;
1415
1416 cmd_param = *fw_ptr;
1417 *fw_ptr += cmd->plen;
1418 remain -= cmd->plen;
1419
1420 /* This reads the expected events when the above command is sent to the
1421 * device. Some vendor commands expects more than one events, for
1422 * example command status event followed by vendor specific event.
1423 * For this case, it only keeps the last expected event. so the command
1424 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1425 * last expected event.
1426 */
1427 while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) {
1428 (*fw_ptr)++;
1429 remain--;
1430
1431 evt = (struct hci_event_hdr *)(*fw_ptr);
1432 *fw_ptr += sizeof(*evt);
1433 remain -= sizeof(*evt);
1434
1435 if (remain < evt->plen) {
1436 BT_ERR("%s Intel fw corrupted: invalid evt len",
1437 hdev->name);
1438 return -EFAULT;
1439 }
1440
1441 evt_param = *fw_ptr;
1442 *fw_ptr += evt->plen;
1443 remain -= evt->plen;
1444 }
1445
1446 /* Every HCI commands in the firmware file has its correspond event.
1447 * If event is not found or remain is smaller than zero, the firmware
1448 * file is corrupted.
1449 */
1450 if (!evt || !evt_param || remain < 0) {
1451 BT_ERR("%s Intel fw corrupted: invalid evt read", hdev->name);
1452 return -EFAULT;
1453 }
1454
1455 skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen,
1456 cmd_param, evt->evt, HCI_INIT_TIMEOUT);
1457 if (IS_ERR(skb)) {
1458 BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
1459 hdev->name, cmd->opcode, PTR_ERR(skb));
d9c78e97 1460 return PTR_ERR(skb);
dffd30ee
THJA
1461 }
1462
1463 /* It ensures that the returned event matches the event data read from
1464 * the firmware file. At fist, it checks the length and then
1465 * the contents of the event.
1466 */
1467 if (skb->len != evt->plen) {
1468 BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev->name,
1469 le16_to_cpu(cmd->opcode));
1470 kfree_skb(skb);
1471 return -EFAULT;
1472 }
1473
1474 if (memcmp(skb->data, evt_param, evt->plen)) {
1475 BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)",
1476 hdev->name, le16_to_cpu(cmd->opcode));
1477 kfree_skb(skb);
1478 return -EFAULT;
1479 }
1480 kfree_skb(skb);
1481
1482 return 0;
1483}
1484
40cb0984
MH
1485#define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
1486
1487static int btusb_check_bdaddr_intel(struct hci_dev *hdev)
1488{
1489 struct sk_buff *skb;
1490 struct hci_rp_read_bd_addr *rp;
1491
1492 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
1493 HCI_INIT_TIMEOUT);
1494 if (IS_ERR(skb)) {
1495 BT_ERR("%s reading Intel device address failed (%ld)",
1496 hdev->name, PTR_ERR(skb));
1497 return PTR_ERR(skb);
1498 }
1499
1500 if (skb->len != sizeof(*rp)) {
1501 BT_ERR("%s Intel device address length mismatch", hdev->name);
1502 kfree_skb(skb);
1503 return -EIO;
1504 }
1505
89e7533d 1506 rp = (struct hci_rp_read_bd_addr *)skb->data;
40cb0984
MH
1507 if (rp->status) {
1508 BT_ERR("%s Intel device address result failed (%02x)",
1509 hdev->name, rp->status);
1510 kfree_skb(skb);
1511 return -bt_to_errno(rp->status);
1512 }
1513
1514 /* For some Intel based controllers, the default Bluetooth device
1515 * address 00:03:19:9E:8B:00 can be found. These controllers are
1516 * fully operational, but have the danger of duplicate addresses
1517 * and that in turn can cause problems with Bluetooth operation.
1518 */
4739b5b1 1519 if (!bacmp(&rp->bdaddr, BDADDR_INTEL)) {
40cb0984
MH
1520 BT_ERR("%s found Intel default device address (%pMR)",
1521 hdev->name, &rp->bdaddr);
4739b5b1
MH
1522 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
1523 }
40cb0984
MH
1524
1525 kfree_skb(skb);
1526
1527 return 0;
1528}
1529
dffd30ee
THJA
1530static int btusb_setup_intel(struct hci_dev *hdev)
1531{
1532 struct sk_buff *skb;
1533 const struct firmware *fw;
1534 const u8 *fw_ptr;
1535 int disable_patch;
1536 struct intel_version *ver;
1537
1538 const u8 mfg_enable[] = { 0x01, 0x00 };
1539 const u8 mfg_disable[] = { 0x00, 0x00 };
1540 const u8 mfg_reset_deactivate[] = { 0x00, 0x01 };
1541 const u8 mfg_reset_activate[] = { 0x00, 0x02 };
1542
1543 BT_DBG("%s", hdev->name);
1544
1545 /* The controller has a bug with the first HCI command sent to it
1546 * returning number of completed commands as zero. This would stall the
1547 * command processing in the Bluetooth core.
1548 *
1549 * As a workaround, send HCI Reset command first which will reset the
1550 * number of completed commands and allow normal command processing
1551 * from now on.
1552 */
1553 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
1554 if (IS_ERR(skb)) {
1555 BT_ERR("%s sending initial HCI reset command failed (%ld)",
1556 hdev->name, PTR_ERR(skb));
d9c78e97 1557 return PTR_ERR(skb);
dffd30ee
THJA
1558 }
1559 kfree_skb(skb);
1560
1561 /* Read Intel specific controller version first to allow selection of
1562 * which firmware file to load.
1563 *
1564 * The returned information are hardware variant and revision plus
1565 * firmware variant, revision and build number.
1566 */
1567 skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
1568 if (IS_ERR(skb)) {
1569 BT_ERR("%s reading Intel fw version command failed (%ld)",
1570 hdev->name, PTR_ERR(skb));
d9c78e97 1571 return PTR_ERR(skb);
dffd30ee
THJA
1572 }
1573
1574 if (skb->len != sizeof(*ver)) {
1575 BT_ERR("%s Intel version event length mismatch", hdev->name);
1576 kfree_skb(skb);
1577 return -EIO;
1578 }
1579
1580 ver = (struct intel_version *)skb->data;
1581 if (ver->status) {
1582 BT_ERR("%s Intel fw version event failed (%02x)", hdev->name,
1583 ver->status);
1584 kfree_skb(skb);
1585 return -bt_to_errno(ver->status);
1586 }
1587
1588 BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x",
1589 hdev->name, ver->hw_platform, ver->hw_variant,
1590 ver->hw_revision, ver->fw_variant, ver->fw_revision,
1591 ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy,
1592 ver->fw_patch_num);
1593
1594 /* fw_patch_num indicates the version of patch the device currently
1595 * have. If there is no patch data in the device, it is always 0x00.
1596 * So, if it is other than 0x00, no need to patch the deivce again.
1597 */
1598 if (ver->fw_patch_num) {
1599 BT_INFO("%s: Intel device is already patched. patch num: %02x",
1600 hdev->name, ver->fw_patch_num);
1601 kfree_skb(skb);
40cb0984 1602 btusb_check_bdaddr_intel(hdev);
dffd30ee
THJA
1603 return 0;
1604 }
1605
1606 /* Opens the firmware patch file based on the firmware version read
1607 * from the controller. If it fails to open the matching firmware
1608 * patch file, it tries to open the default firmware patch file.
1609 * If no patch file is found, allow the device to operate without
1610 * a patch.
1611 */
1612 fw = btusb_setup_intel_get_fw(hdev, ver);
1613 if (!fw) {
1614 kfree_skb(skb);
40cb0984 1615 btusb_check_bdaddr_intel(hdev);
dffd30ee
THJA
1616 return 0;
1617 }
1618 fw_ptr = fw->data;
1619
1620 /* This Intel specific command enables the manufacturer mode of the
1621 * controller.
1622 *
1623 * Only while this mode is enabled, the driver can download the
1624 * firmware patch data and configuration parameters.
1625 */
1626 skb = __hci_cmd_sync(hdev, 0xfc11, 2, mfg_enable, HCI_INIT_TIMEOUT);
1627 if (IS_ERR(skb)) {
1628 BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
1629 hdev->name, PTR_ERR(skb));
1630 release_firmware(fw);
d9c78e97 1631 return PTR_ERR(skb);
dffd30ee
THJA
1632 }
1633
1634 if (skb->data[0]) {
1635 u8 evt_status = skb->data[0];
89e7533d 1636
dffd30ee
THJA
1637 BT_ERR("%s enable Intel manufacturer mode event failed (%02x)",
1638 hdev->name, evt_status);
1639 kfree_skb(skb);
1640 release_firmware(fw);
1641 return -bt_to_errno(evt_status);
1642 }
1643 kfree_skb(skb);
1644
1645 disable_patch = 1;
1646
1647 /* The firmware data file consists of list of Intel specific HCI
1648 * commands and its expected events. The first byte indicates the
1649 * type of the message, either HCI command or HCI event.
1650 *
1651 * It reads the command and its expected event from the firmware file,
1652 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1653 * the returned event is compared with the event read from the firmware
1654 * file and it will continue until all the messages are downloaded to
1655 * the controller.
1656 *
1657 * Once the firmware patching is completed successfully,
1658 * the manufacturer mode is disabled with reset and activating the
1659 * downloaded patch.
1660 *
1661 * If the firmware patching fails, the manufacturer mode is
1662 * disabled with reset and deactivating the patch.
1663 *
1664 * If the default patch file is used, no reset is done when disabling
1665 * the manufacturer.
1666 */
1667 while (fw->size > fw_ptr - fw->data) {
1668 int ret;
1669
1670 ret = btusb_setup_intel_patching(hdev, fw, &fw_ptr,
1671 &disable_patch);
1672 if (ret < 0)
1673 goto exit_mfg_deactivate;
1674 }
1675
1676 release_firmware(fw);
1677
1678 if (disable_patch)
1679 goto exit_mfg_disable;
1680
1681 /* Patching completed successfully and disable the manufacturer mode
1682 * with reset and activate the downloaded firmware patches.
1683 */
1684 skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_activate),
1685 mfg_reset_activate, HCI_INIT_TIMEOUT);
1686 if (IS_ERR(skb)) {
1687 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1688 hdev->name, PTR_ERR(skb));
d9c78e97 1689 return PTR_ERR(skb);
dffd30ee
THJA
1690 }
1691 kfree_skb(skb);
1692
1693 BT_INFO("%s: Intel Bluetooth firmware patch completed and activated",
1694 hdev->name);
1695
40cb0984 1696 btusb_check_bdaddr_intel(hdev);
dffd30ee
THJA
1697 return 0;
1698
1699exit_mfg_disable:
1700 /* Disable the manufacturer mode without reset */
1701 skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_disable), mfg_disable,
1702 HCI_INIT_TIMEOUT);
1703 if (IS_ERR(skb)) {
1704 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1705 hdev->name, PTR_ERR(skb));
d9c78e97 1706 return PTR_ERR(skb);
dffd30ee
THJA
1707 }
1708 kfree_skb(skb);
1709
1710 BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev->name);
40cb0984
MH
1711
1712 btusb_check_bdaddr_intel(hdev);
dffd30ee
THJA
1713 return 0;
1714
1715exit_mfg_deactivate:
1716 release_firmware(fw);
1717
1718 /* Patching failed. Disable the manufacturer mode with reset and
1719 * deactivate the downloaded firmware patches.
1720 */
1721 skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_deactivate),
1722 mfg_reset_deactivate, HCI_INIT_TIMEOUT);
1723 if (IS_ERR(skb)) {
1724 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1725 hdev->name, PTR_ERR(skb));
d9c78e97 1726 return PTR_ERR(skb);
dffd30ee
THJA
1727 }
1728 kfree_skb(skb);
1729
1730 BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated",
1731 hdev->name);
1732
40cb0984 1733 btusb_check_bdaddr_intel(hdev);
dffd30ee
THJA
1734 return 0;
1735}
1736
cda0dd78
MH
1737static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
1738{
1739 struct sk_buff *skb;
1740 struct hci_event_hdr *hdr;
1741 struct hci_ev_cmd_complete *evt;
1742
1743 skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_ATOMIC);
1744 if (!skb)
1745 return -ENOMEM;
1746
1747 hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr));
1748 hdr->evt = HCI_EV_CMD_COMPLETE;
1749 hdr->plen = sizeof(*evt) + 1;
1750
1751 evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt));
1752 evt->ncmd = 0x01;
1753 evt->opcode = cpu_to_le16(opcode);
1754
1755 *skb_put(skb, 1) = 0x00;
1756
1757 bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
1758
1759 return hci_recv_frame(hdev, skb);
1760}
1761
1762static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer,
1763 int count)
1764{
1765 /* When the device is in bootloader mode, then it can send
1766 * events via the bulk endpoint. These events are treated the
1767 * same way as the ones received from the interrupt endpoint.
1768 */
1769 if (test_bit(BTUSB_BOOTLOADER, &data->flags))
1770 return btusb_recv_intr(data, buffer, count);
1771
1772 return btusb_recv_bulk(data, buffer, count);
1773}
1774
1775static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb)
1776{
1777 struct btusb_data *data = hci_get_drvdata(hdev);
1778
1779 if (test_bit(BTUSB_BOOTLOADER, &data->flags)) {
1780 struct hci_event_hdr *hdr = (void *)skb->data;
1781
1782 /* When the firmware loading completes the device sends
1783 * out a vendor specific event indicating the result of
1784 * the firmware loading.
1785 */
1786 if (skb->len == 7 && hdr->evt == 0xff && hdr->plen == 0x05 &&
1787 skb->data[2] == 0x06) {
1788 if (skb->data[3] != 0x00)
1789 test_bit(BTUSB_FIRMWARE_FAILED, &data->flags);
1790
1791 if (test_and_clear_bit(BTUSB_DOWNLOADING, &data->flags))
1792 wake_up_interruptible(&hdev->req_wait_q);
1793 }
1794
1795 /* When switching to the operational firmware the device
1796 * sends a vendor specific event indicating that the bootup
1797 * completed.
1798 */
1799 if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 &&
1800 skb->data[2] == 0x02) {
1801 if (test_and_clear_bit(BTUSB_BOOTING, &data->flags))
1802 wake_up_interruptible(&hdev->req_wait_q);
1803 }
1804 }
1805
1806 return hci_recv_frame(hdev, skb);
1807}
1808
1809static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
1810{
1811 struct btusb_data *data = hci_get_drvdata(hdev);
1812 struct urb *urb;
1813
1814 BT_DBG("%s", hdev->name);
1815
1816 if (!test_bit(HCI_RUNNING, &hdev->flags))
1817 return -EBUSY;
1818
1819 switch (bt_cb(skb)->pkt_type) {
1820 case HCI_COMMAND_PKT:
1821 if (test_bit(BTUSB_BOOTLOADER, &data->flags)) {
1822 struct hci_command_hdr *cmd = (void *)skb->data;
1823 __u16 opcode = le16_to_cpu(cmd->opcode);
1824
1825 /* When in bootloader mode and the command 0xfc09
1826 * is received, it needs to be send down the
1827 * bulk endpoint. So allocate a bulk URB instead.
1828 */
1829 if (opcode == 0xfc09)
1830 urb = alloc_bulk_urb(hdev, skb);
1831 else
1832 urb = alloc_ctrl_urb(hdev, skb);
1833
1834 /* When the 0xfc01 command is issued to boot into
1835 * the operational firmware, it will actually not
1836 * send a command complete event. To keep the flow
1837 * control working inject that event here.
1838 */
1839 if (opcode == 0xfc01)
1840 inject_cmd_complete(hdev, opcode);
1841 } else {
1842 urb = alloc_ctrl_urb(hdev, skb);
1843 }
1844 if (IS_ERR(urb))
1845 return PTR_ERR(urb);
1846
1847 hdev->stat.cmd_tx++;
1848 return submit_or_queue_tx_urb(hdev, urb);
1849
1850 case HCI_ACLDATA_PKT:
1851 urb = alloc_bulk_urb(hdev, skb);
1852 if (IS_ERR(urb))
1853 return PTR_ERR(urb);
1854
1855 hdev->stat.acl_tx++;
1856 return submit_or_queue_tx_urb(hdev, urb);
1857
1858 case HCI_SCODATA_PKT:
1859 if (hci_conn_num(hdev, SCO_LINK) < 1)
1860 return -ENODEV;
1861
1862 urb = alloc_isoc_urb(hdev, skb);
1863 if (IS_ERR(urb))
1864 return PTR_ERR(urb);
1865
1866 hdev->stat.sco_tx++;
1867 return submit_tx_urb(hdev, urb);
1868 }
1869
1870 return -EILSEQ;
1871}
1872
1873static int btusb_intel_secure_send(struct hci_dev *hdev, u8 fragment_type,
1874 u32 plen, const void *param)
1875{
1876 while (plen > 0) {
1877 struct sk_buff *skb;
1878 u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
1879
1880 cmd_param[0] = fragment_type;
1881 memcpy(cmd_param + 1, param, fragment_len);
1882
1883 skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
1884 cmd_param, HCI_INIT_TIMEOUT);
1885 if (IS_ERR(skb))
1886 return PTR_ERR(skb);
1887
1888 kfree_skb(skb);
1889
1890 plen -= fragment_len;
1891 param += fragment_len;
1892 }
1893
1894 return 0;
1895}
1896
1897static void btusb_intel_version_info(struct hci_dev *hdev,
1898 struct intel_version *ver)
1899{
1900 const char *variant;
1901
1902 switch (ver->fw_variant) {
1903 case 0x06:
1904 variant = "Bootloader";
1905 break;
1906 case 0x23:
1907 variant = "Firmware";
1908 break;
1909 default:
1910 return;
1911 }
1912
1913 BT_INFO("%s: %s revision %u.%u build %u week %u %u", hdev->name,
1914 variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
1915 ver->fw_build_num, ver->fw_build_ww, 2000 + ver->fw_build_yy);
1916}
1917
1918static int btusb_setup_intel_new(struct hci_dev *hdev)
1919{
1920 static const u8 reset_param[] = { 0x00, 0x01, 0x00, 0x01,
1921 0x00, 0x08, 0x04, 0x00 };
1922 struct btusb_data *data = hci_get_drvdata(hdev);
1923 struct sk_buff *skb;
1924 struct intel_version *ver;
1925 struct intel_boot_params *params;
1926 const struct firmware *fw;
1927 const u8 *fw_ptr;
1928 char fwname[64];
1929 ktime_t calltime, delta, rettime;
1930 unsigned long long duration;
1931 int err;
1932
1933 BT_DBG("%s", hdev->name);
1934
1935 calltime = ktime_get();
1936
1937 /* Read the Intel version information to determine if the device
1938 * is in bootloader mode or if it already has operational firmware
1939 * loaded.
1940 */
1941 skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
1942 if (IS_ERR(skb)) {
1943 BT_ERR("%s: Reading Intel version information failed (%ld)",
1944 hdev->name, PTR_ERR(skb));
1945 return PTR_ERR(skb);
1946 }
1947
1948 if (skb->len != sizeof(*ver)) {
1949 BT_ERR("%s: Intel version event size mismatch", hdev->name);
1950 kfree_skb(skb);
1951 return -EILSEQ;
1952 }
1953
1954 ver = (struct intel_version *)skb->data;
1955 if (ver->status) {
1956 BT_ERR("%s: Intel version command failure (%02x)",
1957 hdev->name, ver->status);
1958 err = -bt_to_errno(ver->status);
1959 kfree_skb(skb);
1960 return err;
1961 }
1962
1963 /* The hardware platform number has a fixed value of 0x37 and
1964 * for now only accept this single value.
1965 */
1966 if (ver->hw_platform != 0x37) {
1967 BT_ERR("%s: Unsupported Intel hardware platform (%u)",
1968 hdev->name, ver->hw_platform);
1969 kfree_skb(skb);
1970 return -EINVAL;
1971 }
1972
1973 /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is
1974 * supported by this firmware loading method. This check has been
1975 * put in place to ensure correct forward compatibility options
1976 * when newer hardware variants come along.
1977 */
1978 if (ver->hw_variant != 0x0b) {
1979 BT_ERR("%s: Unsupported Intel hardware variant (%u)",
1980 hdev->name, ver->hw_variant);
1981 kfree_skb(skb);
1982 return -EINVAL;
1983 }
1984
1985 btusb_intel_version_info(hdev, ver);
1986
1987 /* The firmware variant determines if the device is in bootloader
1988 * mode or is running operational firmware. The value 0x06 identifies
1989 * the bootloader and the value 0x23 identifies the operational
1990 * firmware.
1991 *
1992 * When the operational firmware is already present, then only
1993 * the check for valid Bluetooth device address is needed. This
1994 * determines if the device will be added as configured or
1995 * unconfigured controller.
1996 *
1997 * It is not possible to use the Secure Boot Parameters in this
1998 * case since that command is only available in bootloader mode.
1999 */
2000 if (ver->fw_variant == 0x23) {
2001 kfree_skb(skb);
2002 clear_bit(BTUSB_BOOTLOADER, &data->flags);
2003 btusb_check_bdaddr_intel(hdev);
2004 return 0;
2005 }
2006
2007 /* If the device is not in bootloader mode, then the only possible
2008 * choice is to return an error and abort the device initialization.
2009 */
2010 if (ver->fw_variant != 0x06) {
2011 BT_ERR("%s: Unsupported Intel firmware variant (%u)",
2012 hdev->name, ver->fw_variant);
2013 kfree_skb(skb);
2014 return -ENODEV;
2015 }
2016
2017 kfree_skb(skb);
2018
2019 /* Read the secure boot parameters to identify the operating
2020 * details of the bootloader.
2021 */
2022 skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
2023 if (IS_ERR(skb)) {
2024 BT_ERR("%s: Reading Intel boot parameters failed (%ld)",
2025 hdev->name, PTR_ERR(skb));
2026 return PTR_ERR(skb);
2027 }
2028
2029 if (skb->len != sizeof(*params)) {
2030 BT_ERR("%s: Intel boot parameters size mismatch", hdev->name);
2031 kfree_skb(skb);
2032 return -EILSEQ;
2033 }
2034
2035 params = (struct intel_boot_params *)skb->data;
2036 if (params->status) {
2037 BT_ERR("%s: Intel boot parameters command failure (%02x)",
2038 hdev->name, params->status);
2039 err = -bt_to_errno(params->status);
2040 kfree_skb(skb);
2041 return err;
2042 }
2043
2044 BT_INFO("%s: Device revision is %u", hdev->name,
2045 le16_to_cpu(params->dev_revid));
2046
2047 BT_INFO("%s: Secure boot is %s", hdev->name,
2048 params->secure_boot ? "enabled" : "disabled");
2049
2050 BT_INFO("%s: Minimum firmware build %u week %u %u", hdev->name,
2051 params->min_fw_build_nn, params->min_fw_build_cw,
2052 2000 + params->min_fw_build_yy);
2053
2054 /* It is required that every single firmware fragment is acknowledged
2055 * with a command complete event. If the boot parameters indicate
2056 * that this bootloader does not send them, then abort the setup.
2057 */
2058 if (params->limited_cce != 0x00) {
2059 BT_ERR("%s: Unsupported Intel firmware loading method (%u)",
2060 hdev->name, params->limited_cce);
2061 kfree_skb(skb);
2062 return -EINVAL;
2063 }
2064
2065 /* If the OTP has no valid Bluetooth device address, then there will
2066 * also be no valid address for the operational firmware.
2067 */
2068 if (!bacmp(&params->otp_bdaddr, BDADDR_ANY)) {
2069 BT_INFO("%s: No device address configured", hdev->name);
2070 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
2071 }
2072
2073 /* With this Intel bootloader only the hardware variant and device
2074 * revision information are used to select the right firmware.
2075 *
2076 * Currently this bootloader support is limited to hardware variant
2077 * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b).
2078 */
2079 snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.sfi",
2080 le16_to_cpu(params->dev_revid));
2081
2082 err = request_firmware(&fw, fwname, &hdev->dev);
2083 if (err < 0) {
2084 BT_ERR("%s: Failed to load Intel firmware file (%d)",
2085 hdev->name, err);
2086 kfree_skb(skb);
2087 return err;
2088 }
2089
2090 BT_INFO("%s: Found device firmware: %s", hdev->name, fwname);
2091
2092 kfree_skb(skb);
2093
2094 if (fw->size < 644) {
2095 BT_ERR("%s: Invalid size of firmware file (%zu)",
2096 hdev->name, fw->size);
2097 err = -EBADF;
2098 goto done;
2099 }
2100
2101 set_bit(BTUSB_DOWNLOADING, &data->flags);
2102
2103 /* Start the firmware download transaction with the Init fragment
2104 * represented by the 128 bytes of CSS header.
2105 */
2106 err = btusb_intel_secure_send(hdev, 0x00, 128, fw->data);
2107 if (err < 0) {
2108 BT_ERR("%s: Failed to send firmware header (%d)",
2109 hdev->name, err);
2110 goto done;
2111 }
2112
2113 /* Send the 256 bytes of public key information from the firmware
2114 * as the PKey fragment.
2115 */
2116 err = btusb_intel_secure_send(hdev, 0x03, 256, fw->data + 128);
2117 if (err < 0) {
2118 BT_ERR("%s: Failed to send firmware public key (%d)",
2119 hdev->name, err);
2120 goto done;
2121 }
2122
2123 /* Send the 256 bytes of signature information from the firmware
2124 * as the Sign fragment.
2125 */
2126 err = btusb_intel_secure_send(hdev, 0x02, 256, fw->data + 388);
2127 if (err < 0) {
2128 BT_ERR("%s: Failed to send firmware signature (%d)",
2129 hdev->name, err);
2130 goto done;
2131 }
2132
2133 fw_ptr = fw->data + 644;
2134
2135 while (fw_ptr - fw->data < fw->size) {
2136 struct hci_command_hdr *cmd = (void *)fw_ptr;
2137 u8 cmd_len;
2138
2139 cmd_len = sizeof(*cmd) + cmd->plen;
2140
2141 /* Send each command from the firmware data buffer as
2142 * a single Data fragment.
2143 */
2144 err = btusb_intel_secure_send(hdev, 0x01, cmd_len, fw_ptr);
2145 if (err < 0) {
2146 BT_ERR("%s: Failed to send firmware data (%d)",
2147 hdev->name, err);
2148 goto done;
2149 }
2150
2151 fw_ptr += cmd_len;
2152 }
2153
2154 /* Before switching the device into operational mode and with that
2155 * booting the loaded firmware, wait for the bootloader notification
2156 * that all fragments have been successfully received.
2157 *
2158 * When the event processing receives the notification, then this
2159 * flag will be cleared. So just in case that happens really quickly,
2160 * check it first before adding the wait queue.
2161 */
2162 if (test_bit(BTUSB_DOWNLOADING, &data->flags)) {
2163 DECLARE_WAITQUEUE(wait, current);
2164 signed long timeout;
2165
2166 BT_INFO("%s: Waiting for firmware download to complete",
2167 hdev->name);
2168
2169 add_wait_queue(&hdev->req_wait_q, &wait);
2170 set_current_state(TASK_INTERRUPTIBLE);
2171
2172 /* The firmware loading should not take longer than 5 seconds
2173 * and thus just timeout if that happens and fail the setup
2174 * of this device.
2175 */
2176 timeout = schedule_timeout(msecs_to_jiffies(5000));
2177
2178 remove_wait_queue(&hdev->req_wait_q, &wait);
2179
2180 if (signal_pending(current)) {
2181 BT_ERR("%s: Firmware loading interrupted", hdev->name);
2182 err = -EINTR;
2183 goto done;
2184 }
2185
2186 if (!timeout) {
2187 BT_ERR("%s: Firmware loading timeout", hdev->name);
2188 err = -ETIMEDOUT;
2189 goto done;
2190 }
2191 }
2192
2193 if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
2194 BT_ERR("%s: Firmware loading failed", hdev->name);
2195 err = -ENOEXEC;
2196 goto done;
2197 }
2198
2199 rettime = ktime_get();
2200 delta = ktime_sub(rettime, calltime);
2201 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
2202
2203 BT_INFO("%s: Firmware loaded in %llu usecs", hdev->name, duration);
2204
2205done:
2206 release_firmware(fw);
2207
2208 if (err < 0)
2209 return err;
2210
2211 calltime = ktime_get();
2212
2213 set_bit(BTUSB_BOOTING, &data->flags);
2214
2215 skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(reset_param), reset_param,
2216 HCI_INIT_TIMEOUT);
2217 if (IS_ERR(skb))
2218 return PTR_ERR(skb);
2219
2220 kfree_skb(skb);
2221
2222 /* The bootloader will not indicate when the device is ready. This
2223 * is done by the operational firmware sending bootup notification.
2224 */
2225 if (test_bit(BTUSB_BOOTING, &data->flags)) {
2226 DECLARE_WAITQUEUE(wait, current);
2227 signed long timeout;
2228
2229 BT_INFO("%s: Waiting for device to boot", hdev->name);
2230
2231 add_wait_queue(&hdev->req_wait_q, &wait);
2232 set_current_state(TASK_INTERRUPTIBLE);
2233
2234 /* Booting into operational firmware should not take
2235 * longer than 1 second. However if that happens, then
2236 * just fail the setup since something went wrong.
2237 */
2238 timeout = schedule_timeout(msecs_to_jiffies(1000));
2239
2240 remove_wait_queue(&hdev->req_wait_q, &wait);
2241
2242 if (signal_pending(current)) {
2243 BT_ERR("%s: Device boot interrupted", hdev->name);
2244 return -EINTR;
2245 }
2246
2247 if (!timeout) {
2248 BT_ERR("%s: Device boot timeout", hdev->name);
2249 return -ETIMEDOUT;
2250 }
2251 }
2252
2253 rettime = ktime_get();
2254 delta = ktime_sub(rettime, calltime);
2255 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
2256
2257 BT_INFO("%s: Device booted in %llu usecs", hdev->name, duration);
2258
2259 clear_bit(BTUSB_BOOTLOADER, &data->flags);
2260
2261 return 0;
2262}
2263
cb8d6597
MH
2264static int btusb_set_bdaddr_intel(struct hci_dev *hdev, const bdaddr_t *bdaddr)
2265{
2266 struct sk_buff *skb;
2267 long ret;
2268
2269 skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
2270 if (IS_ERR(skb)) {
2271 ret = PTR_ERR(skb);
2272 BT_ERR("%s: changing Intel device address failed (%ld)",
89e7533d 2273 hdev->name, ret);
cb8d6597
MH
2274 return ret;
2275 }
2276 kfree_skb(skb);
2277
2278 return 0;
2279}
2280
ae8df494
AK
2281static int btusb_set_bdaddr_marvell(struct hci_dev *hdev,
2282 const bdaddr_t *bdaddr)
2283{
2284 struct sk_buff *skb;
2285 u8 buf[8];
2286 long ret;
2287
2288 buf[0] = 0xfe;
2289 buf[1] = sizeof(bdaddr_t);
2290 memcpy(buf + 2, bdaddr, sizeof(bdaddr_t));
2291
2292 skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT);
2293 if (IS_ERR(skb)) {
2294 ret = PTR_ERR(skb);
2295 BT_ERR("%s: changing Marvell device address failed (%ld)",
2296 hdev->name, ret);
2297 return ret;
2298 }
2299 kfree_skb(skb);
2300
2301 return 0;
2302}
2303
c8abb73f
MH
2304#define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
2305
10d4c673
PG
2306static int btusb_setup_bcm_patchram(struct hci_dev *hdev)
2307{
2308 struct btusb_data *data = hci_get_drvdata(hdev);
2309 struct usb_device *udev = data->udev;
2310 char fw_name[64];
2311 const struct firmware *fw;
2312 const u8 *fw_ptr;
2313 size_t fw_size;
2314 const struct hci_command_hdr *cmd;
2315 const u8 *cmd_param;
2316 u16 opcode;
2317 struct sk_buff *skb;
2318 struct hci_rp_read_local_version *ver;
c8abb73f 2319 struct hci_rp_read_bd_addr *bda;
10d4c673
PG
2320 long ret;
2321
2322 snprintf(fw_name, sizeof(fw_name), "brcm/%s-%04x-%04x.hcd",
2323 udev->product ? udev->product : "BCM",
2324 le16_to_cpu(udev->descriptor.idVendor),
2325 le16_to_cpu(udev->descriptor.idProduct));
2326
2327 ret = request_firmware(&fw, fw_name, &hdev->dev);
2328 if (ret < 0) {
c8abb73f 2329 BT_INFO("%s: BCM: patch %s not found", hdev->name, fw_name);
10d4c673
PG
2330 return 0;
2331 }
2332
2333 /* Reset */
2334 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
2335 if (IS_ERR(skb)) {
2336 ret = PTR_ERR(skb);
2337 BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev->name, ret);
2338 goto done;
2339 }
2340 kfree_skb(skb);
2341
2342 /* Read Local Version Info */
2343 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
2344 HCI_INIT_TIMEOUT);
2345 if (IS_ERR(skb)) {
2346 ret = PTR_ERR(skb);
2347 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
89e7533d 2348 hdev->name, ret);
10d4c673
PG
2349 goto done;
2350 }
2351
2352 if (skb->len != sizeof(*ver)) {
2353 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
89e7533d 2354 hdev->name);
10d4c673
PG
2355 kfree_skb(skb);
2356 ret = -EIO;
2357 goto done;
2358 }
2359
89e7533d 2360 ver = (struct hci_rp_read_local_version *)skb->data;
10d4c673
PG
2361 BT_INFO("%s: BCM: patching hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
2362 "lmp_subver=%04x", hdev->name, ver->hci_ver, ver->hci_rev,
2363 ver->lmp_ver, ver->lmp_subver);
2364 kfree_skb(skb);
2365
2366 /* Start Download */
2367 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
2368 if (IS_ERR(skb)) {
2369 ret = PTR_ERR(skb);
2370 BT_ERR("%s: BCM: Download Minidrv command failed (%ld)",
89e7533d 2371 hdev->name, ret);
10d4c673
PG
2372 goto reset_fw;
2373 }
2374 kfree_skb(skb);
2375
2376 /* 50 msec delay after Download Minidrv completes */
2377 msleep(50);
2378
2379 fw_ptr = fw->data;
2380 fw_size = fw->size;
2381
2382 while (fw_size >= sizeof(*cmd)) {
89e7533d 2383 cmd = (struct hci_command_hdr *)fw_ptr;
10d4c673
PG
2384 fw_ptr += sizeof(*cmd);
2385 fw_size -= sizeof(*cmd);
2386
2387 if (fw_size < cmd->plen) {
2388 BT_ERR("%s: BCM: patch %s is corrupted",
89e7533d 2389 hdev->name, fw_name);
10d4c673
PG
2390 ret = -EINVAL;
2391 goto reset_fw;
2392 }
2393
2394 cmd_param = fw_ptr;
2395 fw_ptr += cmd->plen;
2396 fw_size -= cmd->plen;
2397
2398 opcode = le16_to_cpu(cmd->opcode);
2399
2400 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
2401 HCI_INIT_TIMEOUT);
2402 if (IS_ERR(skb)) {
2403 ret = PTR_ERR(skb);
2404 BT_ERR("%s: BCM: patch command %04x failed (%ld)",
89e7533d 2405 hdev->name, opcode, ret);
10d4c673
PG
2406 goto reset_fw;
2407 }
2408 kfree_skb(skb);
2409 }
2410
2411 /* 250 msec delay after Launch Ram completes */
2412 msleep(250);
2413
2414reset_fw:
2415 /* Reset */
2416 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
2417 if (IS_ERR(skb)) {
2418 ret = PTR_ERR(skb);
2419 BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev->name, ret);
2420 goto done;
2421 }
2422 kfree_skb(skb);
2423
2424 /* Read Local Version Info */
2425 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
2426 HCI_INIT_TIMEOUT);
2427 if (IS_ERR(skb)) {
2428 ret = PTR_ERR(skb);
2429 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
89e7533d 2430 hdev->name, ret);
10d4c673
PG
2431 goto done;
2432 }
2433
2434 if (skb->len != sizeof(*ver)) {
2435 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
89e7533d 2436 hdev->name);
10d4c673
PG
2437 kfree_skb(skb);
2438 ret = -EIO;
2439 goto done;
2440 }
2441
89e7533d 2442 ver = (struct hci_rp_read_local_version *)skb->data;
10d4c673
PG
2443 BT_INFO("%s: BCM: firmware hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
2444 "lmp_subver=%04x", hdev->name, ver->hci_ver, ver->hci_rev,
2445 ver->lmp_ver, ver->lmp_subver);
2446 kfree_skb(skb);
2447
c8abb73f
MH
2448 /* Read BD Address */
2449 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
2450 HCI_INIT_TIMEOUT);
2451 if (IS_ERR(skb)) {
2452 ret = PTR_ERR(skb);
2453 BT_ERR("%s: HCI_OP_READ_BD_ADDR failed (%ld)",
89e7533d 2454 hdev->name, ret);
c8abb73f
MH
2455 goto done;
2456 }
2457
2458 if (skb->len != sizeof(*bda)) {
2459 BT_ERR("%s: HCI_OP_READ_BD_ADDR event length mismatch",
89e7533d 2460 hdev->name);
c8abb73f
MH
2461 kfree_skb(skb);
2462 ret = -EIO;
2463 goto done;
2464 }
2465
89e7533d 2466 bda = (struct hci_rp_read_bd_addr *)skb->data;
c8abb73f
MH
2467 if (bda->status) {
2468 BT_ERR("%s: HCI_OP_READ_BD_ADDR error status (%02x)",
2469 hdev->name, bda->status);
2470 kfree_skb(skb);
2471 ret = -bt_to_errno(bda->status);
2472 goto done;
2473 }
2474
2475 /* The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
2476 * with no configured address.
2477 */
849e5086 2478 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0)) {
c8abb73f
MH
2479 BT_INFO("%s: BCM: using default device address (%pMR)",
2480 hdev->name, &bda->bdaddr);
849e5086
MH
2481 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
2482 }
c8abb73f
MH
2483
2484 kfree_skb(skb);
2485
10d4c673
PG
2486done:
2487 release_firmware(fw);
2488
2489 return ret;
2490}
2491
abbaf50e
MH
2492static int btusb_set_bdaddr_bcm(struct hci_dev *hdev, const bdaddr_t *bdaddr)
2493{
2494 struct sk_buff *skb;
2495 long ret;
2496
2497 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
2498 if (IS_ERR(skb)) {
2499 ret = PTR_ERR(skb);
2500 BT_ERR("%s: BCM: Change address command failed (%ld)",
89e7533d 2501 hdev->name, ret);
abbaf50e
MH
2502 return ret;
2503 }
2504 kfree_skb(skb);
2505
2506 return 0;
2507}
2508
5859223e
TK
2509static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
2510 const bdaddr_t *bdaddr)
2511{
2512 struct sk_buff *skb;
2513 u8 buf[10];
2514 long ret;
2515
2516 buf[0] = 0x01;
2517 buf[1] = 0x01;
2518 buf[2] = 0x00;
2519 buf[3] = sizeof(bdaddr_t);
2520 memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
2521
2522 skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
2523 if (IS_ERR(skb)) {
2524 ret = PTR_ERR(skb);
2525 BT_ERR("%s: Change address command failed (%ld)",
2526 hdev->name, ret);
2527 return ret;
2528 }
2529 kfree_skb(skb);
2530
2531 return 0;
2532}
2533
5e23b923 2534static int btusb_probe(struct usb_interface *intf,
89e7533d 2535 const struct usb_device_id *id)
5e23b923
MH
2536{
2537 struct usb_endpoint_descriptor *ep_desc;
2538 struct btusb_data *data;
2539 struct hci_dev *hdev;
2540 int i, err;
2541
2542 BT_DBG("intf %p id %p", intf, id);
2543
cfeb4145 2544 /* interface numbers are hardcoded in the spec */
5e23b923
MH
2545 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
2546 return -ENODEV;
2547
2548 if (!id->driver_info) {
2549 const struct usb_device_id *match;
89e7533d 2550
5e23b923
MH
2551 match = usb_match_id(intf, blacklist_table);
2552 if (match)
2553 id = match;
2554 }
2555
cfeb4145
MH
2556 if (id->driver_info == BTUSB_IGNORE)
2557 return -ENODEV;
2558
2d25f8b4
SL
2559 if (id->driver_info & BTUSB_ATH3012) {
2560 struct usb_device *udev = interface_to_usbdev(intf);
2561
2562 /* Old firmware would otherwise let ath3k driver load
2563 * patch and sysconfig files */
2564 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001)
2565 return -ENODEV;
2566 }
2567
98921dbd 2568 data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
5e23b923
MH
2569 if (!data)
2570 return -ENOMEM;
2571
2572 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
2573 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
2574
2575 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
2576 data->intr_ep = ep_desc;
2577 continue;
2578 }
2579
2580 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
2581 data->bulk_tx_ep = ep_desc;
2582 continue;
2583 }
2584
2585 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
2586 data->bulk_rx_ep = ep_desc;
2587 continue;
2588 }
2589 }
2590
98921dbd 2591 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
5e23b923 2592 return -ENODEV;
5e23b923 2593
7a9d4020
MH
2594 data->cmdreq_type = USB_TYPE_CLASS;
2595
5e23b923 2596 data->udev = interface_to_usbdev(intf);
5fbcd260 2597 data->intf = intf;
5e23b923 2598
5e23b923 2599 INIT_WORK(&data->work, btusb_work);
7bee549e 2600 INIT_WORK(&data->waker, btusb_waker);
803b5836
MH
2601 init_usb_anchor(&data->deferred);
2602 init_usb_anchor(&data->tx_anchor);
7bee549e 2603 spin_lock_init(&data->txlock);
5e23b923 2604
5e23b923
MH
2605 init_usb_anchor(&data->intr_anchor);
2606 init_usb_anchor(&data->bulk_anchor);
9bfa35fe 2607 init_usb_anchor(&data->isoc_anchor);
803b5836 2608 spin_lock_init(&data->rxlock);
5e23b923 2609
cda0dd78
MH
2610 if (id->driver_info & BTUSB_INTEL_NEW) {
2611 data->recv_event = btusb_recv_event_intel;
2612 data->recv_bulk = btusb_recv_bulk_intel;
2613 set_bit(BTUSB_BOOTLOADER, &data->flags);
2614 } else {
2615 data->recv_event = hci_recv_frame;
2616 data->recv_bulk = btusb_recv_bulk;
2617 }
2cbd3f5c 2618
5e23b923 2619 hdev = hci_alloc_dev();
98921dbd 2620 if (!hdev)
5e23b923 2621 return -ENOMEM;
5e23b923 2622
c13854ce 2623 hdev->bus = HCI_USB;
155961e8 2624 hci_set_drvdata(hdev, data);
5e23b923
MH
2625
2626 data->hdev = hdev;
2627
2628 SET_HCIDEV_DEV(hdev, &intf->dev);
2629
9f8f962c
MH
2630 hdev->open = btusb_open;
2631 hdev->close = btusb_close;
2632 hdev->flush = btusb_flush;
2633 hdev->send = btusb_send_frame;
2634 hdev->notify = btusb_notify;
2635
2636 if (id->driver_info & BTUSB_BCM92035)
2637 hdev->setup = btusb_setup_bcm92035;
5e23b923 2638
abbaf50e 2639 if (id->driver_info & BTUSB_BCM_PATCHRAM) {
10d4c673 2640 hdev->setup = btusb_setup_bcm_patchram;
abbaf50e 2641 hdev->set_bdaddr = btusb_set_bdaddr_bcm;
27c3fbe0 2642 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
abbaf50e 2643 }
10d4c673 2644
cb8d6597 2645 if (id->driver_info & BTUSB_INTEL) {
dffd30ee 2646 hdev->setup = btusb_setup_intel;
cb8d6597
MH
2647 hdev->set_bdaddr = btusb_set_bdaddr_intel;
2648 }
dffd30ee 2649
cda0dd78
MH
2650 if (id->driver_info & BTUSB_INTEL_NEW) {
2651 hdev->send = btusb_send_frame_intel;
2652 hdev->setup = btusb_setup_intel_new;
2653 hdev->set_bdaddr = btusb_set_bdaddr_intel;
2654 }
2655
ae8df494
AK
2656 if (id->driver_info & BTUSB_MARVELL)
2657 hdev->set_bdaddr = btusb_set_bdaddr_marvell;
2658
661cf88a
MH
2659 if (id->driver_info & BTUSB_SWAVE) {
2660 set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks);
d57dbe77 2661 set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks);
661cf88a 2662 }
d57dbe77 2663
40df783d
MH
2664 if (id->driver_info & BTUSB_INTEL_BOOT)
2665 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
2666
5859223e
TK
2667 if (id->driver_info & BTUSB_ATH3012)
2668 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
2669
7a9d4020 2670 /* Interface numbers are hardcoded in the specification */
9bfa35fe
MH
2671 data->isoc = usb_ifnum_to_if(data->udev, 1);
2672
7a9d4020 2673 if (!reset)
a6c511c6 2674 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
cfeb4145
MH
2675
2676 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
2677 if (!disable_scofix)
2678 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
2679 }
2680
9bfa35fe
MH
2681 if (id->driver_info & BTUSB_BROKEN_ISOC)
2682 data->isoc = NULL;
2683
7a9d4020
MH
2684 if (id->driver_info & BTUSB_DIGIANSWER) {
2685 data->cmdreq_type = USB_TYPE_VENDOR;
a6c511c6 2686 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
7a9d4020
MH
2687 }
2688
2689 if (id->driver_info & BTUSB_CSR) {
2690 struct usb_device *udev = data->udev;
81cac64b 2691 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice);
7a9d4020
MH
2692
2693 /* Old firmware would otherwise execute USB reset */
81cac64b 2694 if (bcdDevice < 0x117)
a6c511c6 2695 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
81cac64b
MH
2696
2697 /* Fake CSR devices with broken commands */
2698 if (bcdDevice <= 0x100)
2699 hdev->setup = btusb_setup_csr;
7a9d4020
MH
2700 }
2701
cfeb4145 2702 if (id->driver_info & BTUSB_SNIFFER) {
9bfa35fe 2703 struct usb_device *udev = data->udev;
cfeb4145 2704
7a9d4020 2705 /* New sniffer firmware has crippled HCI interface */
cfeb4145
MH
2706 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
2707 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
2708 }
2709
3a5ef20c
MH
2710 if (id->driver_info & BTUSB_INTEL_BOOT) {
2711 /* A bug in the bootloader causes that interrupt interface is
2712 * only enabled after receiving SetInterface(0, AltSetting=0).
2713 */
2714 err = usb_set_interface(data->udev, 0, 0);
2715 if (err < 0) {
2716 BT_ERR("failed to set interface 0, alt 0 %d", err);
2717 hci_free_dev(hdev);
2718 return err;
2719 }
2720 }
2721
9bfa35fe
MH
2722 if (data->isoc) {
2723 err = usb_driver_claim_interface(&btusb_driver,
89e7533d 2724 data->isoc, data);
9bfa35fe
MH
2725 if (err < 0) {
2726 hci_free_dev(hdev);
9bfa35fe
MH
2727 return err;
2728 }
2729 }
2730
5e23b923
MH
2731 err = hci_register_dev(hdev);
2732 if (err < 0) {
2733 hci_free_dev(hdev);
5e23b923
MH
2734 return err;
2735 }
2736
2737 usb_set_intfdata(intf, data);
2738
2739 return 0;
2740}
2741
2742static void btusb_disconnect(struct usb_interface *intf)
2743{
2744 struct btusb_data *data = usb_get_intfdata(intf);
2745 struct hci_dev *hdev;
2746
2747 BT_DBG("intf %p", intf);
2748
2749 if (!data)
2750 return;
2751
2752 hdev = data->hdev;
5fbcd260
MH
2753 usb_set_intfdata(data->intf, NULL);
2754
2755 if (data->isoc)
2756 usb_set_intfdata(data->isoc, NULL);
5e23b923
MH
2757
2758 hci_unregister_dev(hdev);
2759
5fbcd260
MH
2760 if (intf == data->isoc)
2761 usb_driver_release_interface(&btusb_driver, data->intf);
2762 else if (data->isoc)
2763 usb_driver_release_interface(&btusb_driver, data->isoc);
2764
803b5836 2765 btusb_free_frags(data);
5e23b923
MH
2766 hci_free_dev(hdev);
2767}
2768
7bee549e 2769#ifdef CONFIG_PM
6a88adf2
MH
2770static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
2771{
2772 struct btusb_data *data = usb_get_intfdata(intf);
2773
2774 BT_DBG("intf %p", intf);
2775
2776 if (data->suspend_count++)
2777 return 0;
2778
7bee549e 2779 spin_lock_irq(&data->txlock);
5b1b0b81 2780 if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
7bee549e
ON
2781 set_bit(BTUSB_SUSPENDING, &data->flags);
2782 spin_unlock_irq(&data->txlock);
2783 } else {
2784 spin_unlock_irq(&data->txlock);
2785 data->suspend_count--;
2786 return -EBUSY;
2787 }
2788
6a88adf2
MH
2789 cancel_work_sync(&data->work);
2790
7bee549e 2791 btusb_stop_traffic(data);
6a88adf2
MH
2792 usb_kill_anchored_urbs(&data->tx_anchor);
2793
6a88adf2
MH
2794 return 0;
2795}
2796
7bee549e
ON
2797static void play_deferred(struct btusb_data *data)
2798{
2799 struct urb *urb;
2800 int err;
2801
2802 while ((urb = usb_get_from_anchor(&data->deferred))) {
2803 err = usb_submit_urb(urb, GFP_ATOMIC);
2804 if (err < 0)
2805 break;
2806
2807 data->tx_in_flight++;
2808 }
2809 usb_scuttle_anchored_urbs(&data->deferred);
2810}
2811
6a88adf2
MH
2812static int btusb_resume(struct usb_interface *intf)
2813{
2814 struct btusb_data *data = usb_get_intfdata(intf);
2815 struct hci_dev *hdev = data->hdev;
7bee549e 2816 int err = 0;
6a88adf2
MH
2817
2818 BT_DBG("intf %p", intf);
2819
2820 if (--data->suspend_count)
2821 return 0;
2822
2823 if (!test_bit(HCI_RUNNING, &hdev->flags))
7bee549e 2824 goto done;
6a88adf2
MH
2825
2826 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
2827 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
2828 if (err < 0) {
2829 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
7bee549e 2830 goto failed;
6a88adf2
MH
2831 }
2832 }
2833
2834 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
43c2e57f
MH
2835 err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
2836 if (err < 0) {
6a88adf2 2837 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
7bee549e
ON
2838 goto failed;
2839 }
2840
2841 btusb_submit_bulk_urb(hdev, GFP_NOIO);
6a88adf2
MH
2842 }
2843
2844 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
2845 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
2846 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2847 else
2848 btusb_submit_isoc_urb(hdev, GFP_NOIO);
2849 }
2850
7bee549e
ON
2851 spin_lock_irq(&data->txlock);
2852 play_deferred(data);
2853 clear_bit(BTUSB_SUSPENDING, &data->flags);
2854 spin_unlock_irq(&data->txlock);
2855 schedule_work(&data->work);
2856
6a88adf2 2857 return 0;
7bee549e
ON
2858
2859failed:
2860 usb_scuttle_anchored_urbs(&data->deferred);
2861done:
2862 spin_lock_irq(&data->txlock);
2863 clear_bit(BTUSB_SUSPENDING, &data->flags);
2864 spin_unlock_irq(&data->txlock);
2865
2866 return err;
6a88adf2 2867}
7bee549e 2868#endif
6a88adf2 2869
5e23b923
MH
2870static struct usb_driver btusb_driver = {
2871 .name = "btusb",
2872 .probe = btusb_probe,
2873 .disconnect = btusb_disconnect,
7bee549e 2874#ifdef CONFIG_PM
6a88adf2
MH
2875 .suspend = btusb_suspend,
2876 .resume = btusb_resume,
7bee549e 2877#endif
5e23b923 2878 .id_table = btusb_table,
7bee549e 2879 .supports_autosuspend = 1,
e1f12eb6 2880 .disable_hub_initiated_lpm = 1,
5e23b923
MH
2881};
2882
93f1508c 2883module_usb_driver(btusb_driver);
5e23b923 2884
cfeb4145
MH
2885module_param(disable_scofix, bool, 0644);
2886MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
2887
2888module_param(force_scofix, bool, 0644);
2889MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
2890
2891module_param(reset, bool, 0644);
2892MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
2893
5e23b923
MH
2894MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
2895MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
2896MODULE_VERSION(VERSION);
2897MODULE_LICENSE("GPL");