22eb03979c80a4799f43734d7a168260fe51ba23
[pandora-kernel.git] / drivers / bluetooth / btusb.c
1 /*
2  *
3  *  Generic Bluetooth USB driver
4  *
5  *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
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
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/sched.h>
30 #include <linux/errno.h>
31 #include <linux/skbuff.h>
32
33 #include <linux/usb.h>
34
35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h>
37
38 #define VERSION "0.6"
39
40 static int ignore_dga;
41 static int ignore_csr;
42 static int ignore_sniffer;
43 static int disable_scofix;
44 static int force_scofix;
45
46 static int reset = 1;
47
48 static struct usb_driver btusb_driver;
49
50 #define BTUSB_IGNORE            0x01
51 #define BTUSB_DIGIANSWER        0x02
52 #define BTUSB_CSR               0x04
53 #define BTUSB_SNIFFER           0x08
54 #define BTUSB_BCM92035          0x10
55 #define BTUSB_BROKEN_ISOC       0x20
56 #define BTUSB_WRONG_SCO_MTU     0x40
57 #define BTUSB_ATH3012           0x80
58
59 static struct usb_device_id btusb_table[] = {
60         /* Generic Bluetooth USB device */
61         { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
62
63         /* Apple-specific (Broadcom) devices */
64         { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
65
66         /* MediaTek MT76x0E */
67         { USB_DEVICE(0x0e8d, 0x763f) },
68
69         /* Broadcom SoftSailing reporting vendor specific */
70         { USB_DEVICE(0x0a5c, 0x21e1) },
71
72         /* Apple MacBookPro 7,1 */
73         { USB_DEVICE(0x05ac, 0x8213) },
74
75         /* Apple iMac11,1 */
76         { USB_DEVICE(0x05ac, 0x8215) },
77
78         /* Apple MacBookPro6,2 */
79         { USB_DEVICE(0x05ac, 0x8218) },
80
81         /* Apple MacBookAir3,1, MacBookAir3,2 */
82         { USB_DEVICE(0x05ac, 0x821b) },
83
84         /* Apple MacBookAir4,1 */
85         { USB_DEVICE(0x05ac, 0x821f) },
86
87         /* Apple MacBookPro8,2 */
88         { USB_DEVICE(0x05ac, 0x821a) },
89
90         /* Apple MacMini5,1 */
91         { USB_DEVICE(0x05ac, 0x8281) },
92
93         /* AVM BlueFRITZ! USB v2.0 */
94         { USB_DEVICE(0x057c, 0x3800) },
95
96         /* Bluetooth Ultraport Module from IBM */
97         { USB_DEVICE(0x04bf, 0x030a) },
98
99         /* ALPS Modules with non-standard id */
100         { USB_DEVICE(0x044e, 0x3001) },
101         { USB_DEVICE(0x044e, 0x3002) },
102
103         /* Ericsson with non-standard id */
104         { USB_DEVICE(0x0bdb, 0x1002) },
105
106         /* Canyon CN-BTU1 with HID interfaces */
107         { USB_DEVICE(0x0c10, 0x0000) },
108
109         /* Broadcom BCM20702A0 */
110         { USB_DEVICE(0x0489, 0xe042) },
111         { USB_DEVICE(0x04ca, 0x2003) },
112         { USB_DEVICE(0x0b05, 0x17b5) },
113         { USB_DEVICE(0x0b05, 0x17cb) },
114         { USB_DEVICE(0x413c, 0x8197) },
115
116         /* Foxconn - Hon Hai */
117         { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
118
119         /* Broadcom devices with vendor specific id */
120         { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) },
121
122         /* Belkin F8065bf - Broadcom based */
123         { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01) },
124
125         /* IMC Networks - Broadcom based */
126         { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01) },
127
128         { }     /* Terminating entry */
129 };
130
131 MODULE_DEVICE_TABLE(usb, btusb_table);
132
133 static struct usb_device_id blacklist_table[] = {
134         /* CSR BlueCore devices */
135         { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
136
137         /* Broadcom BCM2033 without firmware */
138         { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
139
140         /* Atheros 3011 with sflash firmware */
141         { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
142         { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
143         { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
144         { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
145         { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
146         { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
147
148         /* Atheros AR9285 Malbec with sflash firmware */
149         { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
150
151         /* Atheros 3012 with sflash firmware */
152         { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
153         { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
154         { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
155         { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
156         { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
157         { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
158         { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
159         { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
160         { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
161         { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
162         { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
163         { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
164         { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
165         { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
166         { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
167         { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
168         { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
169         { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
170         { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
171         { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 },
172         { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
173         { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
174         { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
175         { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
176         { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
177         { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
178         { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
179         { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
180         { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
181
182         /* Atheros AR5BBU12 with sflash firmware */
183         { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
184
185         /* Atheros AR5BBU12 with sflash firmware */
186         { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
187         { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
188
189         /* Broadcom BCM2035 */
190         { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
191         { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
192         { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
193
194         /* Broadcom BCM2045 */
195         { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
196         { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
197
198         /* IBM/Lenovo ThinkPad with Broadcom chip */
199         { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
200         { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
201
202         /* HP laptop with Broadcom chip */
203         { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
204
205         /* Dell laptop with Broadcom chip */
206         { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
207
208         /* Dell Wireless 370 and 410 devices */
209         { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
210         { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
211
212         /* Belkin F8T012 and F8T013 devices */
213         { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
214         { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
215
216         /* Asus WL-BTD202 device */
217         { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
218
219         /* Kensington Bluetooth USB adapter */
220         { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
221
222         /* RTX Telecom based adapters with buggy SCO support */
223         { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
224         { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
225
226         /* CONWISE Technology based adapters with buggy SCO support */
227         { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
228
229         /* Digianswer devices */
230         { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
231         { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
232
233         /* CSR BlueCore Bluetooth Sniffer */
234         { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
235
236         /* Frontline ComProbe Bluetooth Sniffer */
237         { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
238
239         { }     /* Terminating entry */
240 };
241
242 #define BTUSB_MAX_ISOC_FRAMES   10
243
244 #define BTUSB_INTR_RUNNING      0
245 #define BTUSB_BULK_RUNNING      1
246 #define BTUSB_ISOC_RUNNING      2
247 #define BTUSB_SUSPENDING        3
248 #define BTUSB_DID_ISO_RESUME    4
249
250 struct btusb_data {
251         struct hci_dev       *hdev;
252         struct usb_device    *udev;
253         struct usb_interface *intf;
254         struct usb_interface *isoc;
255
256         spinlock_t lock;
257
258         unsigned long flags;
259
260         struct work_struct work;
261         struct work_struct waker;
262
263         struct usb_anchor tx_anchor;
264         struct usb_anchor intr_anchor;
265         struct usb_anchor bulk_anchor;
266         struct usb_anchor isoc_anchor;
267         struct usb_anchor deferred;
268         int tx_in_flight;
269         spinlock_t txlock;
270
271         struct usb_endpoint_descriptor *intr_ep;
272         struct usb_endpoint_descriptor *bulk_tx_ep;
273         struct usb_endpoint_descriptor *bulk_rx_ep;
274         struct usb_endpoint_descriptor *isoc_tx_ep;
275         struct usb_endpoint_descriptor *isoc_rx_ep;
276
277         __u8 cmdreq_type;
278
279         unsigned int sco_num;
280         int isoc_altsetting;
281         int suspend_count;
282 };
283
284 static int inc_tx(struct btusb_data *data)
285 {
286         unsigned long flags;
287         int rv;
288
289         spin_lock_irqsave(&data->txlock, flags);
290         rv = test_bit(BTUSB_SUSPENDING, &data->flags);
291         if (!rv)
292                 data->tx_in_flight++;
293         spin_unlock_irqrestore(&data->txlock, flags);
294
295         return rv;
296 }
297
298 static void btusb_intr_complete(struct urb *urb)
299 {
300         struct hci_dev *hdev = urb->context;
301         struct btusb_data *data = hdev->driver_data;
302         int err;
303
304         BT_DBG("%s urb %p status %d count %d", hdev->name,
305                                         urb, urb->status, urb->actual_length);
306
307         if (!test_bit(HCI_RUNNING, &hdev->flags))
308                 return;
309
310         if (urb->status == 0) {
311                 hdev->stat.byte_rx += urb->actual_length;
312
313                 if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
314                                                 urb->transfer_buffer,
315                                                 urb->actual_length) < 0) {
316                         BT_ERR("%s corrupted event packet", hdev->name);
317                         hdev->stat.err_rx++;
318                 }
319         } else if (urb->status == -ENOENT) {
320                 /* Avoid suspend failed when usb_kill_urb */
321                 return;
322         }
323
324         if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
325                 return;
326
327         usb_mark_last_busy(data->udev);
328         usb_anchor_urb(urb, &data->intr_anchor);
329
330         err = usb_submit_urb(urb, GFP_ATOMIC);
331         if (err < 0) {
332                 /* -EPERM: urb is being killed;
333                  * -ENODEV: device got disconnected */
334                 if (err != -EPERM && err != -ENODEV)
335                         BT_ERR("%s urb %p failed to resubmit (%d)",
336                                                 hdev->name, urb, -err);
337                 usb_unanchor_urb(urb);
338         }
339 }
340
341 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
342 {
343         struct btusb_data *data = hdev->driver_data;
344         struct urb *urb;
345         unsigned char *buf;
346         unsigned int pipe;
347         int err, size;
348
349         BT_DBG("%s", hdev->name);
350
351         if (!data->intr_ep)
352                 return -ENODEV;
353
354         urb = usb_alloc_urb(0, mem_flags);
355         if (!urb)
356                 return -ENOMEM;
357
358         size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
359
360         buf = kmalloc(size, mem_flags);
361         if (!buf) {
362                 usb_free_urb(urb);
363                 return -ENOMEM;
364         }
365
366         pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
367
368         usb_fill_int_urb(urb, data->udev, pipe, buf, size,
369                                                 btusb_intr_complete, hdev,
370                                                 data->intr_ep->bInterval);
371
372         urb->transfer_flags |= URB_FREE_BUFFER;
373
374         usb_anchor_urb(urb, &data->intr_anchor);
375
376         err = usb_submit_urb(urb, mem_flags);
377         if (err < 0) {
378                 BT_ERR("%s urb %p submission failed (%d)",
379                                                 hdev->name, urb, -err);
380                 usb_unanchor_urb(urb);
381         }
382
383         usb_free_urb(urb);
384
385         return err;
386 }
387
388 static void btusb_bulk_complete(struct urb *urb)
389 {
390         struct hci_dev *hdev = urb->context;
391         struct btusb_data *data = hdev->driver_data;
392         int err;
393
394         BT_DBG("%s urb %p status %d count %d", hdev->name,
395                                         urb, urb->status, urb->actual_length);
396
397         if (!test_bit(HCI_RUNNING, &hdev->flags))
398                 return;
399
400         if (urb->status == 0) {
401                 hdev->stat.byte_rx += urb->actual_length;
402
403                 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
404                                                 urb->transfer_buffer,
405                                                 urb->actual_length) < 0) {
406                         BT_ERR("%s corrupted ACL packet", hdev->name);
407                         hdev->stat.err_rx++;
408                 }
409         } else if (urb->status == -ENOENT) {
410                 /* Avoid suspend failed when usb_kill_urb */
411                 return;
412         }
413
414         if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
415                 return;
416
417         usb_anchor_urb(urb, &data->bulk_anchor);
418         usb_mark_last_busy(data->udev);
419
420         err = usb_submit_urb(urb, GFP_ATOMIC);
421         if (err < 0) {
422                 /* -EPERM: urb is being killed;
423                  * -ENODEV: device got disconnected */
424                 if (err != -EPERM && err != -ENODEV)
425                         BT_ERR("%s urb %p failed to resubmit (%d)",
426                                                 hdev->name, urb, -err);
427                 usb_unanchor_urb(urb);
428         }
429 }
430
431 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
432 {
433         struct btusb_data *data = hdev->driver_data;
434         struct urb *urb;
435         unsigned char *buf;
436         unsigned int pipe;
437         int err, size = HCI_MAX_FRAME_SIZE;
438
439         BT_DBG("%s", hdev->name);
440
441         if (!data->bulk_rx_ep)
442                 return -ENODEV;
443
444         urb = usb_alloc_urb(0, mem_flags);
445         if (!urb)
446                 return -ENOMEM;
447
448         buf = kmalloc(size, mem_flags);
449         if (!buf) {
450                 usb_free_urb(urb);
451                 return -ENOMEM;
452         }
453
454         pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
455
456         usb_fill_bulk_urb(urb, data->udev, pipe,
457                                         buf, size, btusb_bulk_complete, hdev);
458
459         urb->transfer_flags |= URB_FREE_BUFFER;
460
461         usb_mark_last_busy(data->udev);
462         usb_anchor_urb(urb, &data->bulk_anchor);
463
464         err = usb_submit_urb(urb, mem_flags);
465         if (err < 0) {
466                 BT_ERR("%s urb %p submission failed (%d)",
467                                                 hdev->name, urb, -err);
468                 usb_unanchor_urb(urb);
469         }
470
471         usb_free_urb(urb);
472
473         return err;
474 }
475
476 static void btusb_isoc_complete(struct urb *urb)
477 {
478         struct hci_dev *hdev = urb->context;
479         struct btusb_data *data = hdev->driver_data;
480         int i, err;
481
482         BT_DBG("%s urb %p status %d count %d", hdev->name,
483                                         urb, urb->status, urb->actual_length);
484
485         if (!test_bit(HCI_RUNNING, &hdev->flags))
486                 return;
487
488         if (urb->status == 0) {
489                 for (i = 0; i < urb->number_of_packets; i++) {
490                         unsigned int offset = urb->iso_frame_desc[i].offset;
491                         unsigned int length = urb->iso_frame_desc[i].actual_length;
492
493                         if (urb->iso_frame_desc[i].status)
494                                 continue;
495
496                         hdev->stat.byte_rx += length;
497
498                         if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
499                                                 urb->transfer_buffer + offset,
500                                                                 length) < 0) {
501                                 BT_ERR("%s corrupted SCO packet", hdev->name);
502                                 hdev->stat.err_rx++;
503                         }
504                 }
505         } else if (urb->status == -ENOENT) {
506                 /* Avoid suspend failed when usb_kill_urb */
507                 return;
508         }
509
510         if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
511                 return;
512
513         usb_anchor_urb(urb, &data->isoc_anchor);
514
515         err = usb_submit_urb(urb, GFP_ATOMIC);
516         if (err < 0) {
517                 /* -EPERM: urb is being killed;
518                  * -ENODEV: device got disconnected */
519                 if (err != -EPERM && err != -ENODEV)
520                         BT_ERR("%s urb %p failed to resubmit (%d)",
521                                                 hdev->name, urb, -err);
522                 usb_unanchor_urb(urb);
523         }
524 }
525
526 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
527 {
528         int i, offset = 0;
529
530         BT_DBG("len %d mtu %d", len, mtu);
531
532         for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
533                                         i++, offset += mtu, len -= mtu) {
534                 urb->iso_frame_desc[i].offset = offset;
535                 urb->iso_frame_desc[i].length = mtu;
536         }
537
538         if (len && i < BTUSB_MAX_ISOC_FRAMES) {
539                 urb->iso_frame_desc[i].offset = offset;
540                 urb->iso_frame_desc[i].length = len;
541                 i++;
542         }
543
544         urb->number_of_packets = i;
545 }
546
547 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
548 {
549         struct btusb_data *data = hdev->driver_data;
550         struct urb *urb;
551         unsigned char *buf;
552         unsigned int pipe;
553         int err, size;
554
555         BT_DBG("%s", hdev->name);
556
557         if (!data->isoc_rx_ep)
558                 return -ENODEV;
559
560         urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
561         if (!urb)
562                 return -ENOMEM;
563
564         size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
565                                                 BTUSB_MAX_ISOC_FRAMES;
566
567         buf = kmalloc(size, mem_flags);
568         if (!buf) {
569                 usb_free_urb(urb);
570                 return -ENOMEM;
571         }
572
573         pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
574
575         usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
576                                 hdev, data->isoc_rx_ep->bInterval);
577
578         urb->transfer_flags  = URB_FREE_BUFFER | URB_ISO_ASAP;
579
580         __fill_isoc_descriptor(urb, size,
581                         le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
582
583         usb_anchor_urb(urb, &data->isoc_anchor);
584
585         err = usb_submit_urb(urb, mem_flags);
586         if (err < 0) {
587                 BT_ERR("%s urb %p submission failed (%d)",
588                                                 hdev->name, urb, -err);
589                 usb_unanchor_urb(urb);
590         }
591
592         usb_free_urb(urb);
593
594         return err;
595 }
596
597 static void btusb_tx_complete(struct urb *urb)
598 {
599         struct sk_buff *skb = urb->context;
600         struct hci_dev *hdev = (struct hci_dev *) skb->dev;
601         struct btusb_data *data = hdev->driver_data;
602
603         BT_DBG("%s urb %p status %d count %d", hdev->name,
604                                         urb, urb->status, urb->actual_length);
605
606         if (!test_bit(HCI_RUNNING, &hdev->flags))
607                 goto done;
608
609         if (!urb->status)
610                 hdev->stat.byte_tx += urb->transfer_buffer_length;
611         else
612                 hdev->stat.err_tx++;
613
614 done:
615         spin_lock(&data->txlock);
616         data->tx_in_flight--;
617         spin_unlock(&data->txlock);
618
619         kfree(urb->setup_packet);
620
621         kfree_skb(skb);
622 }
623
624 static void btusb_isoc_tx_complete(struct urb *urb)
625 {
626         struct sk_buff *skb = urb->context;
627         struct hci_dev *hdev = (struct hci_dev *) skb->dev;
628
629         BT_DBG("%s urb %p status %d count %d", hdev->name,
630                                         urb, urb->status, urb->actual_length);
631
632         if (!test_bit(HCI_RUNNING, &hdev->flags))
633                 goto done;
634
635         if (!urb->status)
636                 hdev->stat.byte_tx += urb->transfer_buffer_length;
637         else
638                 hdev->stat.err_tx++;
639
640 done:
641         kfree(urb->setup_packet);
642
643         kfree_skb(skb);
644 }
645
646 static int btusb_open(struct hci_dev *hdev)
647 {
648         struct btusb_data *data = hdev->driver_data;
649         int err;
650
651         BT_DBG("%s", hdev->name);
652
653         err = usb_autopm_get_interface(data->intf);
654         if (err < 0)
655                 return err;
656
657         data->intf->needs_remote_wakeup = 1;
658
659         if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
660                 goto done;
661
662         if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
663                 goto done;
664
665         err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
666         if (err < 0)
667                 goto failed;
668
669         err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
670         if (err < 0) {
671                 usb_kill_anchored_urbs(&data->intr_anchor);
672                 goto failed;
673         }
674
675         set_bit(BTUSB_BULK_RUNNING, &data->flags);
676         btusb_submit_bulk_urb(hdev, GFP_KERNEL);
677
678 done:
679         usb_autopm_put_interface(data->intf);
680         return 0;
681
682 failed:
683         clear_bit(BTUSB_INTR_RUNNING, &data->flags);
684         clear_bit(HCI_RUNNING, &hdev->flags);
685         usb_autopm_put_interface(data->intf);
686         return err;
687 }
688
689 static void btusb_stop_traffic(struct btusb_data *data)
690 {
691         usb_kill_anchored_urbs(&data->intr_anchor);
692         usb_kill_anchored_urbs(&data->bulk_anchor);
693         usb_kill_anchored_urbs(&data->isoc_anchor);
694 }
695
696 static int btusb_close(struct hci_dev *hdev)
697 {
698         struct btusb_data *data = hdev->driver_data;
699         int err;
700
701         BT_DBG("%s", hdev->name);
702
703         if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
704                 return 0;
705
706         cancel_work_sync(&data->work);
707         cancel_work_sync(&data->waker);
708
709         clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
710         clear_bit(BTUSB_BULK_RUNNING, &data->flags);
711         clear_bit(BTUSB_INTR_RUNNING, &data->flags);
712
713         btusb_stop_traffic(data);
714         err = usb_autopm_get_interface(data->intf);
715         if (err < 0)
716                 goto failed;
717
718         data->intf->needs_remote_wakeup = 0;
719         usb_autopm_put_interface(data->intf);
720
721 failed:
722         usb_scuttle_anchored_urbs(&data->deferred);
723         return 0;
724 }
725
726 static int btusb_flush(struct hci_dev *hdev)
727 {
728         struct btusb_data *data = hdev->driver_data;
729
730         BT_DBG("%s", hdev->name);
731
732         usb_kill_anchored_urbs(&data->tx_anchor);
733
734         return 0;
735 }
736
737 static int btusb_send_frame(struct sk_buff *skb)
738 {
739         struct hci_dev *hdev = (struct hci_dev *) skb->dev;
740         struct btusb_data *data = hdev->driver_data;
741         struct usb_ctrlrequest *dr;
742         struct urb *urb;
743         unsigned int pipe;
744         int err;
745
746         BT_DBG("%s", hdev->name);
747
748         if (!test_bit(HCI_RUNNING, &hdev->flags))
749                 return -EBUSY;
750
751         switch (bt_cb(skb)->pkt_type) {
752         case HCI_COMMAND_PKT:
753                 urb = usb_alloc_urb(0, GFP_ATOMIC);
754                 if (!urb)
755                         return -ENOMEM;
756
757                 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
758                 if (!dr) {
759                         usb_free_urb(urb);
760                         return -ENOMEM;
761                 }
762
763                 dr->bRequestType = data->cmdreq_type;
764                 dr->bRequest     = 0;
765                 dr->wIndex       = 0;
766                 dr->wValue       = 0;
767                 dr->wLength      = __cpu_to_le16(skb->len);
768
769                 pipe = usb_sndctrlpipe(data->udev, 0x00);
770
771                 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
772                                 skb->data, skb->len, btusb_tx_complete, skb);
773
774                 hdev->stat.cmd_tx++;
775                 break;
776
777         case HCI_ACLDATA_PKT:
778                 if (!data->bulk_tx_ep)
779                         return -ENODEV;
780
781                 urb = usb_alloc_urb(0, GFP_ATOMIC);
782                 if (!urb)
783                         return -ENOMEM;
784
785                 pipe = usb_sndbulkpipe(data->udev,
786                                         data->bulk_tx_ep->bEndpointAddress);
787
788                 usb_fill_bulk_urb(urb, data->udev, pipe,
789                                 skb->data, skb->len, btusb_tx_complete, skb);
790
791                 hdev->stat.acl_tx++;
792                 break;
793
794         case HCI_SCODATA_PKT:
795                 if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)
796                         return -ENODEV;
797
798                 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
799                 if (!urb)
800                         return -ENOMEM;
801
802                 pipe = usb_sndisocpipe(data->udev,
803                                         data->isoc_tx_ep->bEndpointAddress);
804
805                 usb_fill_int_urb(urb, data->udev, pipe,
806                                 skb->data, skb->len, btusb_isoc_tx_complete,
807                                 skb, data->isoc_tx_ep->bInterval);
808
809                 urb->transfer_flags  = URB_ISO_ASAP;
810
811                 __fill_isoc_descriptor(urb, skb->len,
812                                 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
813
814                 hdev->stat.sco_tx++;
815                 goto skip_waking;
816
817         default:
818                 return -EILSEQ;
819         }
820
821         err = inc_tx(data);
822         if (err) {
823                 usb_anchor_urb(urb, &data->deferred);
824                 schedule_work(&data->waker);
825                 err = 0;
826                 goto done;
827         }
828
829 skip_waking:
830         usb_anchor_urb(urb, &data->tx_anchor);
831
832         err = usb_submit_urb(urb, GFP_ATOMIC);
833         if (err < 0) {
834                 BT_ERR("%s urb %p submission failed", hdev->name, urb);
835                 kfree(urb->setup_packet);
836                 usb_unanchor_urb(urb);
837         } else {
838                 usb_mark_last_busy(data->udev);
839         }
840
841 done:
842         usb_free_urb(urb);
843         return err;
844 }
845
846 static void btusb_destruct(struct hci_dev *hdev)
847 {
848         struct btusb_data *data = hdev->driver_data;
849
850         BT_DBG("%s", hdev->name);
851
852         kfree(data);
853 }
854
855 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
856 {
857         struct btusb_data *data = hdev->driver_data;
858
859         BT_DBG("%s evt %d", hdev->name, evt);
860
861         if (hdev->conn_hash.sco_num != data->sco_num) {
862                 data->sco_num = hdev->conn_hash.sco_num;
863                 schedule_work(&data->work);
864         }
865 }
866
867 static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
868 {
869         struct btusb_data *data = hdev->driver_data;
870         struct usb_interface *intf = data->isoc;
871         struct usb_endpoint_descriptor *ep_desc;
872         int i, err;
873
874         if (!data->isoc)
875                 return -ENODEV;
876
877         err = usb_set_interface(data->udev, 1, altsetting);
878         if (err < 0) {
879                 BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
880                 return err;
881         }
882
883         data->isoc_altsetting = altsetting;
884
885         data->isoc_tx_ep = NULL;
886         data->isoc_rx_ep = NULL;
887
888         for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
889                 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
890
891                 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
892                         data->isoc_tx_ep = ep_desc;
893                         continue;
894                 }
895
896                 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
897                         data->isoc_rx_ep = ep_desc;
898                         continue;
899                 }
900         }
901
902         if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
903                 BT_ERR("%s invalid SCO descriptors", hdev->name);
904                 return -ENODEV;
905         }
906
907         return 0;
908 }
909
910 static void btusb_work(struct work_struct *work)
911 {
912         struct btusb_data *data = container_of(work, struct btusb_data, work);
913         struct hci_dev *hdev = data->hdev;
914         int err;
915
916         if (hdev->conn_hash.sco_num > 0) {
917                 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
918                         err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
919                         if (err < 0) {
920                                 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
921                                 usb_kill_anchored_urbs(&data->isoc_anchor);
922                                 return;
923                         }
924
925                         set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
926                 }
927                 if (data->isoc_altsetting != 2) {
928                         clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
929                         usb_kill_anchored_urbs(&data->isoc_anchor);
930
931                         if (__set_isoc_interface(hdev, 2) < 0)
932                                 return;
933                 }
934
935                 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
936                         if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
937                                 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
938                         else
939                                 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
940                 }
941         } else {
942                 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
943                 usb_kill_anchored_urbs(&data->isoc_anchor);
944
945                 __set_isoc_interface(hdev, 0);
946                 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
947                         usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
948         }
949 }
950
951 static void btusb_waker(struct work_struct *work)
952 {
953         struct btusb_data *data = container_of(work, struct btusb_data, waker);
954         int err;
955
956         err = usb_autopm_get_interface(data->intf);
957         if (err < 0)
958                 return;
959
960         usb_autopm_put_interface(data->intf);
961 }
962
963 static int btusb_probe(struct usb_interface *intf,
964                                 const struct usb_device_id *id)
965 {
966         struct usb_endpoint_descriptor *ep_desc;
967         struct btusb_data *data;
968         struct hci_dev *hdev;
969         int i, err;
970
971         BT_DBG("intf %p id %p", intf, id);
972
973         /* interface numbers are hardcoded in the spec */
974         if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
975                 return -ENODEV;
976
977         if (!id->driver_info) {
978                 const struct usb_device_id *match;
979                 match = usb_match_id(intf, blacklist_table);
980                 if (match)
981                         id = match;
982         }
983
984         if (id->driver_info == BTUSB_IGNORE)
985                 return -ENODEV;
986
987         if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
988                 return -ENODEV;
989
990         if (ignore_csr && id->driver_info & BTUSB_CSR)
991                 return -ENODEV;
992
993         if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
994                 return -ENODEV;
995
996         if (id->driver_info & BTUSB_ATH3012) {
997                 struct usb_device *udev = interface_to_usbdev(intf);
998
999                 /* Old firmware would otherwise let ath3k driver load
1000                  * patch and sysconfig files */
1001                 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001)
1002                         return -ENODEV;
1003         }
1004
1005         data = kzalloc(sizeof(*data), GFP_KERNEL);
1006         if (!data)
1007                 return -ENOMEM;
1008
1009         for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
1010                 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
1011
1012                 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
1013                         data->intr_ep = ep_desc;
1014                         continue;
1015                 }
1016
1017                 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
1018                         data->bulk_tx_ep = ep_desc;
1019                         continue;
1020                 }
1021
1022                 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
1023                         data->bulk_rx_ep = ep_desc;
1024                         continue;
1025                 }
1026         }
1027
1028         if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
1029                 kfree(data);
1030                 return -ENODEV;
1031         }
1032
1033         data->cmdreq_type = USB_TYPE_CLASS;
1034
1035         data->udev = interface_to_usbdev(intf);
1036         data->intf = intf;
1037
1038         spin_lock_init(&data->lock);
1039
1040         INIT_WORK(&data->work, btusb_work);
1041         INIT_WORK(&data->waker, btusb_waker);
1042         spin_lock_init(&data->txlock);
1043
1044         init_usb_anchor(&data->tx_anchor);
1045         init_usb_anchor(&data->intr_anchor);
1046         init_usb_anchor(&data->bulk_anchor);
1047         init_usb_anchor(&data->isoc_anchor);
1048         init_usb_anchor(&data->deferred);
1049
1050         hdev = hci_alloc_dev();
1051         if (!hdev) {
1052                 kfree(data);
1053                 return -ENOMEM;
1054         }
1055
1056         hdev->bus = HCI_USB;
1057         hdev->driver_data = data;
1058
1059         data->hdev = hdev;
1060
1061         SET_HCIDEV_DEV(hdev, &intf->dev);
1062
1063         hdev->open     = btusb_open;
1064         hdev->close    = btusb_close;
1065         hdev->flush    = btusb_flush;
1066         hdev->send     = btusb_send_frame;
1067         hdev->destruct = btusb_destruct;
1068         hdev->notify   = btusb_notify;
1069
1070         hdev->owner = THIS_MODULE;
1071
1072         /* Interface numbers are hardcoded in the specification */
1073         data->isoc = usb_ifnum_to_if(data->udev, 1);
1074
1075         if (!reset)
1076                 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1077
1078         if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
1079                 if (!disable_scofix)
1080                         set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
1081         }
1082
1083         if (id->driver_info & BTUSB_BROKEN_ISOC)
1084                 data->isoc = NULL;
1085
1086         if (id->driver_info & BTUSB_DIGIANSWER) {
1087                 data->cmdreq_type = USB_TYPE_VENDOR;
1088                 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1089         }
1090
1091         if (id->driver_info & BTUSB_CSR) {
1092                 struct usb_device *udev = data->udev;
1093
1094                 /* Old firmware would otherwise execute USB reset */
1095                 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
1096                         set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1097         }
1098
1099         if (id->driver_info & BTUSB_SNIFFER) {
1100                 struct usb_device *udev = data->udev;
1101
1102                 /* New sniffer firmware has crippled HCI interface */
1103                 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
1104                         set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
1105
1106                 data->isoc = NULL;
1107         }
1108
1109         if (id->driver_info & BTUSB_BCM92035) {
1110                 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
1111                 struct sk_buff *skb;
1112
1113                 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
1114                 if (skb) {
1115                         memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
1116                         skb_queue_tail(&hdev->driver_init, skb);
1117                 }
1118         }
1119
1120         if (data->isoc) {
1121                 err = usb_driver_claim_interface(&btusb_driver,
1122                                                         data->isoc, data);
1123                 if (err < 0) {
1124                         hci_free_dev(hdev);
1125                         kfree(data);
1126                         return err;
1127                 }
1128         }
1129
1130         err = hci_register_dev(hdev);
1131         if (err < 0) {
1132                 hci_free_dev(hdev);
1133                 kfree(data);
1134                 return err;
1135         }
1136
1137         usb_set_intfdata(intf, data);
1138
1139         return 0;
1140 }
1141
1142 static void btusb_disconnect(struct usb_interface *intf)
1143 {
1144         struct btusb_data *data = usb_get_intfdata(intf);
1145         struct hci_dev *hdev;
1146
1147         BT_DBG("intf %p", intf);
1148
1149         if (!data)
1150                 return;
1151
1152         hdev = data->hdev;
1153
1154         __hci_dev_hold(hdev);
1155
1156         usb_set_intfdata(data->intf, NULL);
1157
1158         if (data->isoc)
1159                 usb_set_intfdata(data->isoc, NULL);
1160
1161         hci_unregister_dev(hdev);
1162
1163         if (intf == data->isoc)
1164                 usb_driver_release_interface(&btusb_driver, data->intf);
1165         else if (data->isoc)
1166                 usb_driver_release_interface(&btusb_driver, data->isoc);
1167
1168         __hci_dev_put(hdev);
1169
1170         hci_free_dev(hdev);
1171 }
1172
1173 #ifdef CONFIG_PM
1174 static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
1175 {
1176         struct btusb_data *data = usb_get_intfdata(intf);
1177
1178         BT_DBG("intf %p", intf);
1179
1180         if (data->suspend_count++)
1181                 return 0;
1182
1183         spin_lock_irq(&data->txlock);
1184         if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
1185                 set_bit(BTUSB_SUSPENDING, &data->flags);
1186                 spin_unlock_irq(&data->txlock);
1187         } else {
1188                 spin_unlock_irq(&data->txlock);
1189                 data->suspend_count--;
1190                 return -EBUSY;
1191         }
1192
1193         cancel_work_sync(&data->work);
1194
1195         btusb_stop_traffic(data);
1196         usb_kill_anchored_urbs(&data->tx_anchor);
1197
1198         return 0;
1199 }
1200
1201 static void play_deferred(struct btusb_data *data)
1202 {
1203         struct urb *urb;
1204         int err;
1205
1206         while ((urb = usb_get_from_anchor(&data->deferred))) {
1207                 err = usb_submit_urb(urb, GFP_ATOMIC);
1208                 if (err < 0)
1209                         break;
1210
1211                 data->tx_in_flight++;
1212         }
1213         usb_scuttle_anchored_urbs(&data->deferred);
1214 }
1215
1216 static int btusb_resume(struct usb_interface *intf)
1217 {
1218         struct btusb_data *data = usb_get_intfdata(intf);
1219         struct hci_dev *hdev = data->hdev;
1220         int err = 0;
1221
1222         BT_DBG("intf %p", intf);
1223
1224         if (--data->suspend_count)
1225                 return 0;
1226
1227         if (!test_bit(HCI_RUNNING, &hdev->flags))
1228                 goto done;
1229
1230         if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
1231                 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
1232                 if (err < 0) {
1233                         clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1234                         goto failed;
1235                 }
1236         }
1237
1238         if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
1239                 err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
1240                 if (err < 0) {
1241                         clear_bit(BTUSB_BULK_RUNNING, &data->flags);
1242                         goto failed;
1243                 }
1244
1245                 btusb_submit_bulk_urb(hdev, GFP_NOIO);
1246         }
1247
1248         if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
1249                 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
1250                         clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1251                 else
1252                         btusb_submit_isoc_urb(hdev, GFP_NOIO);
1253         }
1254
1255         spin_lock_irq(&data->txlock);
1256         play_deferred(data);
1257         clear_bit(BTUSB_SUSPENDING, &data->flags);
1258         spin_unlock_irq(&data->txlock);
1259         schedule_work(&data->work);
1260
1261         return 0;
1262
1263 failed:
1264         usb_scuttle_anchored_urbs(&data->deferred);
1265 done:
1266         spin_lock_irq(&data->txlock);
1267         clear_bit(BTUSB_SUSPENDING, &data->flags);
1268         spin_unlock_irq(&data->txlock);
1269
1270         return err;
1271 }
1272 #endif
1273
1274 static struct usb_driver btusb_driver = {
1275         .name           = "btusb",
1276         .probe          = btusb_probe,
1277         .disconnect     = btusb_disconnect,
1278 #ifdef CONFIG_PM
1279         .suspend        = btusb_suspend,
1280         .resume         = btusb_resume,
1281 #endif
1282         .id_table       = btusb_table,
1283         .supports_autosuspend = 1,
1284 };
1285
1286 static int __init btusb_init(void)
1287 {
1288         BT_INFO("Generic Bluetooth USB driver ver %s", VERSION);
1289
1290         return usb_register(&btusb_driver);
1291 }
1292
1293 static void __exit btusb_exit(void)
1294 {
1295         usb_deregister(&btusb_driver);
1296 }
1297
1298 module_init(btusb_init);
1299 module_exit(btusb_exit);
1300
1301 module_param(ignore_dga, bool, 0644);
1302 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
1303
1304 module_param(ignore_csr, bool, 0644);
1305 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
1306
1307 module_param(ignore_sniffer, bool, 0644);
1308 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
1309
1310 module_param(disable_scofix, bool, 0644);
1311 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
1312
1313 module_param(force_scofix, bool, 0644);
1314 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
1315
1316 module_param(reset, bool, 0644);
1317 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1318
1319 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
1320 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
1321 MODULE_VERSION(VERSION);
1322 MODULE_LICENSE("GPL");