3 * Generic Bluetooth USB driver
5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/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>
33 #include <linux/usb.h>
35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h>
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;
48 static struct usb_driver btusb_driver;
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
58 static struct usb_device_id btusb_table[] = {
59 /* Generic Bluetooth USB device */
60 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
62 /* Apple MacBookPro 7,1 */
63 { USB_DEVICE(0x05ac, 0x8213) },
66 { USB_DEVICE(0x05ac, 0x8215) },
68 /* Apple MacBookPro6,2 */
69 { USB_DEVICE(0x05ac, 0x8218) },
71 /* Apple MacBookAir3,1, MacBookAir3,2 */
72 { USB_DEVICE(0x05ac, 0x821b) },
74 /* AVM BlueFRITZ! USB v2.0 */
75 { USB_DEVICE(0x057c, 0x3800) },
77 /* Bluetooth Ultraport Module from IBM */
78 { USB_DEVICE(0x04bf, 0x030a) },
80 /* ALPS Modules with non-standard id */
81 { USB_DEVICE(0x044e, 0x3001) },
82 { USB_DEVICE(0x044e, 0x3002) },
84 /* Ericsson with non-standard id */
85 { USB_DEVICE(0x0bdb, 0x1002) },
87 /* Canyon CN-BTU1 with HID interfaces */
88 { USB_DEVICE(0x0c10, 0x0000) },
90 { } /* Terminating entry */
93 MODULE_DEVICE_TABLE(usb, btusb_table);
95 static struct usb_device_id blacklist_table[] = {
96 /* CSR BlueCore devices */
97 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
99 /* Broadcom BCM2033 without firmware */
100 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
102 /* Atheros 3011 with sflash firmware */
103 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
105 /* Atheros AR9285 Malbec with sflash firmware */
106 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
108 /* Atheros 3012 with sflash firmware */
109 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_IGNORE },
111 /* Broadcom BCM2035 */
112 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
113 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
114 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
116 /* Broadcom BCM2045 */
117 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
118 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
120 /* IBM/Lenovo ThinkPad with Broadcom chip */
121 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
122 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
124 /* HP laptop with Broadcom chip */
125 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
127 /* Dell laptop with Broadcom chip */
128 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
130 /* Dell Wireless 370 and 410 devices */
131 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
132 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
134 /* Belkin F8T012 and F8T013 devices */
135 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
136 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
138 /* Asus WL-BTD202 device */
139 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
141 /* Kensington Bluetooth USB adapter */
142 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
144 /* RTX Telecom based adapters with buggy SCO support */
145 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
146 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
148 /* CONWISE Technology based adapters with buggy SCO support */
149 { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
151 /* Digianswer devices */
152 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
153 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
155 /* CSR BlueCore Bluetooth Sniffer */
156 { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
158 /* Frontline ComProbe Bluetooth Sniffer */
159 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
161 { } /* Terminating entry */
164 #define BTUSB_MAX_ISOC_FRAMES 10
166 #define BTUSB_INTR_RUNNING 0
167 #define BTUSB_BULK_RUNNING 1
168 #define BTUSB_ISOC_RUNNING 2
169 #define BTUSB_SUSPENDING 3
170 #define BTUSB_DID_ISO_RESUME 4
173 struct hci_dev *hdev;
174 struct usb_device *udev;
175 struct usb_interface *intf;
176 struct usb_interface *isoc;
182 struct work_struct work;
183 struct work_struct waker;
185 struct usb_anchor tx_anchor;
186 struct usb_anchor intr_anchor;
187 struct usb_anchor bulk_anchor;
188 struct usb_anchor isoc_anchor;
189 struct usb_anchor deferred;
193 struct usb_endpoint_descriptor *intr_ep;
194 struct usb_endpoint_descriptor *bulk_tx_ep;
195 struct usb_endpoint_descriptor *bulk_rx_ep;
196 struct usb_endpoint_descriptor *isoc_tx_ep;
197 struct usb_endpoint_descriptor *isoc_rx_ep;
201 unsigned int sco_num;
206 static int inc_tx(struct btusb_data *data)
211 spin_lock_irqsave(&data->txlock, flags);
212 rv = test_bit(BTUSB_SUSPENDING, &data->flags);
214 data->tx_in_flight++;
215 spin_unlock_irqrestore(&data->txlock, flags);
220 static void btusb_intr_complete(struct urb *urb)
222 struct hci_dev *hdev = urb->context;
223 struct btusb_data *data = hdev->driver_data;
226 BT_DBG("%s urb %p status %d count %d", hdev->name,
227 urb, urb->status, urb->actual_length);
229 if (!test_bit(HCI_RUNNING, &hdev->flags))
232 if (urb->status == 0) {
233 hdev->stat.byte_rx += urb->actual_length;
235 if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
236 urb->transfer_buffer,
237 urb->actual_length) < 0) {
238 BT_ERR("%s corrupted event packet", hdev->name);
243 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
246 usb_mark_last_busy(data->udev);
247 usb_anchor_urb(urb, &data->intr_anchor);
249 err = usb_submit_urb(urb, GFP_ATOMIC);
252 BT_ERR("%s urb %p failed to resubmit (%d)",
253 hdev->name, urb, -err);
254 usb_unanchor_urb(urb);
258 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
260 struct btusb_data *data = hdev->driver_data;
266 BT_DBG("%s", hdev->name);
271 urb = usb_alloc_urb(0, mem_flags);
275 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
277 buf = kmalloc(size, mem_flags);
283 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
285 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
286 btusb_intr_complete, hdev,
287 data->intr_ep->bInterval);
289 urb->transfer_flags |= URB_FREE_BUFFER;
291 usb_anchor_urb(urb, &data->intr_anchor);
293 err = usb_submit_urb(urb, mem_flags);
295 BT_ERR("%s urb %p submission failed (%d)",
296 hdev->name, urb, -err);
297 usb_unanchor_urb(urb);
305 static void btusb_bulk_complete(struct urb *urb)
307 struct hci_dev *hdev = urb->context;
308 struct btusb_data *data = hdev->driver_data;
311 BT_DBG("%s urb %p status %d count %d", hdev->name,
312 urb, urb->status, urb->actual_length);
314 if (!test_bit(HCI_RUNNING, &hdev->flags))
317 if (urb->status == 0) {
318 hdev->stat.byte_rx += urb->actual_length;
320 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
321 urb->transfer_buffer,
322 urb->actual_length) < 0) {
323 BT_ERR("%s corrupted ACL packet", hdev->name);
328 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
331 usb_anchor_urb(urb, &data->bulk_anchor);
332 usb_mark_last_busy(data->udev);
334 err = usb_submit_urb(urb, GFP_ATOMIC);
337 BT_ERR("%s urb %p failed to resubmit (%d)",
338 hdev->name, urb, -err);
339 usb_unanchor_urb(urb);
343 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
345 struct btusb_data *data = hdev->driver_data;
349 int err, size = HCI_MAX_FRAME_SIZE;
351 BT_DBG("%s", hdev->name);
353 if (!data->bulk_rx_ep)
356 urb = usb_alloc_urb(0, mem_flags);
360 buf = kmalloc(size, mem_flags);
366 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
368 usb_fill_bulk_urb(urb, data->udev, pipe,
369 buf, size, btusb_bulk_complete, hdev);
371 urb->transfer_flags |= URB_FREE_BUFFER;
373 usb_mark_last_busy(data->udev);
374 usb_anchor_urb(urb, &data->bulk_anchor);
376 err = usb_submit_urb(urb, mem_flags);
378 BT_ERR("%s urb %p submission failed (%d)",
379 hdev->name, urb, -err);
380 usb_unanchor_urb(urb);
388 static void btusb_isoc_complete(struct urb *urb)
390 struct hci_dev *hdev = urb->context;
391 struct btusb_data *data = hdev->driver_data;
394 BT_DBG("%s urb %p status %d count %d", hdev->name,
395 urb, urb->status, urb->actual_length);
397 if (!test_bit(HCI_RUNNING, &hdev->flags))
400 if (urb->status == 0) {
401 for (i = 0; i < urb->number_of_packets; i++) {
402 unsigned int offset = urb->iso_frame_desc[i].offset;
403 unsigned int length = urb->iso_frame_desc[i].actual_length;
405 if (urb->iso_frame_desc[i].status)
408 hdev->stat.byte_rx += length;
410 if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
411 urb->transfer_buffer + offset,
413 BT_ERR("%s corrupted SCO packet", hdev->name);
419 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
422 usb_anchor_urb(urb, &data->isoc_anchor);
424 err = usb_submit_urb(urb, GFP_ATOMIC);
427 BT_ERR("%s urb %p failed to resubmit (%d)",
428 hdev->name, urb, -err);
429 usb_unanchor_urb(urb);
433 static void inline __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
437 BT_DBG("len %d mtu %d", len, mtu);
439 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
440 i++, offset += mtu, len -= mtu) {
441 urb->iso_frame_desc[i].offset = offset;
442 urb->iso_frame_desc[i].length = mtu;
445 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
446 urb->iso_frame_desc[i].offset = offset;
447 urb->iso_frame_desc[i].length = len;
451 urb->number_of_packets = i;
454 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
456 struct btusb_data *data = hdev->driver_data;
462 BT_DBG("%s", hdev->name);
464 if (!data->isoc_rx_ep)
467 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
471 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
472 BTUSB_MAX_ISOC_FRAMES;
474 buf = kmalloc(size, mem_flags);
480 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
482 urb->dev = data->udev;
485 urb->complete = btusb_isoc_complete;
486 urb->interval = data->isoc_rx_ep->bInterval;
488 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
489 urb->transfer_buffer = buf;
490 urb->transfer_buffer_length = size;
492 __fill_isoc_descriptor(urb, size,
493 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
495 usb_anchor_urb(urb, &data->isoc_anchor);
497 err = usb_submit_urb(urb, mem_flags);
499 BT_ERR("%s urb %p submission failed (%d)",
500 hdev->name, urb, -err);
501 usb_unanchor_urb(urb);
509 static void btusb_tx_complete(struct urb *urb)
511 struct sk_buff *skb = urb->context;
512 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
513 struct btusb_data *data = hdev->driver_data;
515 BT_DBG("%s urb %p status %d count %d", hdev->name,
516 urb, urb->status, urb->actual_length);
518 if (!test_bit(HCI_RUNNING, &hdev->flags))
522 hdev->stat.byte_tx += urb->transfer_buffer_length;
527 spin_lock(&data->txlock);
528 data->tx_in_flight--;
529 spin_unlock(&data->txlock);
531 kfree(urb->setup_packet);
536 static void btusb_isoc_tx_complete(struct urb *urb)
538 struct sk_buff *skb = urb->context;
539 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
541 BT_DBG("%s urb %p status %d count %d", hdev->name,
542 urb, urb->status, urb->actual_length);
544 if (!test_bit(HCI_RUNNING, &hdev->flags))
548 hdev->stat.byte_tx += urb->transfer_buffer_length;
553 kfree(urb->setup_packet);
558 static int btusb_open(struct hci_dev *hdev)
560 struct btusb_data *data = hdev->driver_data;
563 BT_DBG("%s", hdev->name);
565 err = usb_autopm_get_interface(data->intf);
569 data->intf->needs_remote_wakeup = 1;
571 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
574 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
577 err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
581 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
583 usb_kill_anchored_urbs(&data->intr_anchor);
587 set_bit(BTUSB_BULK_RUNNING, &data->flags);
588 btusb_submit_bulk_urb(hdev, GFP_KERNEL);
591 usb_autopm_put_interface(data->intf);
595 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
596 clear_bit(HCI_RUNNING, &hdev->flags);
597 usb_autopm_put_interface(data->intf);
601 static void btusb_stop_traffic(struct btusb_data *data)
603 usb_kill_anchored_urbs(&data->intr_anchor);
604 usb_kill_anchored_urbs(&data->bulk_anchor);
605 usb_kill_anchored_urbs(&data->isoc_anchor);
608 static int btusb_close(struct hci_dev *hdev)
610 struct btusb_data *data = hdev->driver_data;
613 BT_DBG("%s", hdev->name);
615 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
618 cancel_work_sync(&data->work);
619 cancel_work_sync(&data->waker);
621 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
622 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
623 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
625 btusb_stop_traffic(data);
626 err = usb_autopm_get_interface(data->intf);
630 data->intf->needs_remote_wakeup = 0;
631 usb_autopm_put_interface(data->intf);
634 usb_scuttle_anchored_urbs(&data->deferred);
638 static int btusb_flush(struct hci_dev *hdev)
640 struct btusb_data *data = hdev->driver_data;
642 BT_DBG("%s", hdev->name);
644 usb_kill_anchored_urbs(&data->tx_anchor);
649 static int btusb_send_frame(struct sk_buff *skb)
651 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
652 struct btusb_data *data = hdev->driver_data;
653 struct usb_ctrlrequest *dr;
658 BT_DBG("%s", hdev->name);
660 if (!test_bit(HCI_RUNNING, &hdev->flags))
663 switch (bt_cb(skb)->pkt_type) {
664 case HCI_COMMAND_PKT:
665 urb = usb_alloc_urb(0, GFP_ATOMIC);
669 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
675 dr->bRequestType = data->cmdreq_type;
679 dr->wLength = __cpu_to_le16(skb->len);
681 pipe = usb_sndctrlpipe(data->udev, 0x00);
683 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
684 skb->data, skb->len, btusb_tx_complete, skb);
689 case HCI_ACLDATA_PKT:
690 if (!data->bulk_tx_ep || hdev->conn_hash.acl_num < 1)
693 urb = usb_alloc_urb(0, GFP_ATOMIC);
697 pipe = usb_sndbulkpipe(data->udev,
698 data->bulk_tx_ep->bEndpointAddress);
700 usb_fill_bulk_urb(urb, data->udev, pipe,
701 skb->data, skb->len, btusb_tx_complete, skb);
706 case HCI_SCODATA_PKT:
707 if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)
710 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
714 pipe = usb_sndisocpipe(data->udev,
715 data->isoc_tx_ep->bEndpointAddress);
717 usb_fill_int_urb(urb, data->udev, pipe,
718 skb->data, skb->len, btusb_isoc_tx_complete,
719 skb, data->isoc_tx_ep->bInterval);
721 urb->transfer_flags = URB_ISO_ASAP;
723 __fill_isoc_descriptor(urb, skb->len,
724 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
735 usb_anchor_urb(urb, &data->deferred);
736 schedule_work(&data->waker);
742 usb_anchor_urb(urb, &data->tx_anchor);
744 err = usb_submit_urb(urb, GFP_ATOMIC);
746 BT_ERR("%s urb %p submission failed", hdev->name, urb);
747 kfree(urb->setup_packet);
748 usb_unanchor_urb(urb);
750 usb_mark_last_busy(data->udev);
759 static void btusb_destruct(struct hci_dev *hdev)
761 struct btusb_data *data = hdev->driver_data;
763 BT_DBG("%s", hdev->name);
768 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
770 struct btusb_data *data = hdev->driver_data;
772 BT_DBG("%s evt %d", hdev->name, evt);
774 if (hdev->conn_hash.sco_num != data->sco_num) {
775 data->sco_num = hdev->conn_hash.sco_num;
776 schedule_work(&data->work);
780 static int inline __set_isoc_interface(struct hci_dev *hdev, int altsetting)
782 struct btusb_data *data = hdev->driver_data;
783 struct usb_interface *intf = data->isoc;
784 struct usb_endpoint_descriptor *ep_desc;
790 err = usb_set_interface(data->udev, 1, altsetting);
792 BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
796 data->isoc_altsetting = altsetting;
798 data->isoc_tx_ep = NULL;
799 data->isoc_rx_ep = NULL;
801 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
802 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
804 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
805 data->isoc_tx_ep = ep_desc;
809 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
810 data->isoc_rx_ep = ep_desc;
815 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
816 BT_ERR("%s invalid SCO descriptors", hdev->name);
823 static void btusb_work(struct work_struct *work)
825 struct btusb_data *data = container_of(work, struct btusb_data, work);
826 struct hci_dev *hdev = data->hdev;
829 if (hdev->conn_hash.sco_num > 0) {
830 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
831 err = usb_autopm_get_interface(data->isoc);
833 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
834 usb_kill_anchored_urbs(&data->isoc_anchor);
838 set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
840 if (data->isoc_altsetting != 2) {
841 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
842 usb_kill_anchored_urbs(&data->isoc_anchor);
844 if (__set_isoc_interface(hdev, 2) < 0)
848 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
849 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
850 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
852 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
855 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
856 usb_kill_anchored_urbs(&data->isoc_anchor);
858 __set_isoc_interface(hdev, 0);
859 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
860 usb_autopm_put_interface(data->isoc);
864 static void btusb_waker(struct work_struct *work)
866 struct btusb_data *data = container_of(work, struct btusb_data, waker);
869 err = usb_autopm_get_interface(data->intf);
873 usb_autopm_put_interface(data->intf);
876 static int btusb_probe(struct usb_interface *intf,
877 const struct usb_device_id *id)
879 struct usb_endpoint_descriptor *ep_desc;
880 struct btusb_data *data;
881 struct hci_dev *hdev;
884 BT_DBG("intf %p id %p", intf, id);
886 /* interface numbers are hardcoded in the spec */
887 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
890 if (!id->driver_info) {
891 const struct usb_device_id *match;
892 match = usb_match_id(intf, blacklist_table);
897 if (id->driver_info == BTUSB_IGNORE)
900 if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
903 if (ignore_csr && id->driver_info & BTUSB_CSR)
906 if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
909 data = kzalloc(sizeof(*data), GFP_KERNEL);
913 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
914 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
916 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
917 data->intr_ep = ep_desc;
921 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
922 data->bulk_tx_ep = ep_desc;
926 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
927 data->bulk_rx_ep = ep_desc;
932 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
937 data->cmdreq_type = USB_TYPE_CLASS;
939 data->udev = interface_to_usbdev(intf);
942 spin_lock_init(&data->lock);
944 INIT_WORK(&data->work, btusb_work);
945 INIT_WORK(&data->waker, btusb_waker);
946 spin_lock_init(&data->txlock);
948 init_usb_anchor(&data->tx_anchor);
949 init_usb_anchor(&data->intr_anchor);
950 init_usb_anchor(&data->bulk_anchor);
951 init_usb_anchor(&data->isoc_anchor);
952 init_usb_anchor(&data->deferred);
954 hdev = hci_alloc_dev();
961 hdev->driver_data = data;
965 SET_HCIDEV_DEV(hdev, &intf->dev);
967 hdev->open = btusb_open;
968 hdev->close = btusb_close;
969 hdev->flush = btusb_flush;
970 hdev->send = btusb_send_frame;
971 hdev->destruct = btusb_destruct;
972 hdev->notify = btusb_notify;
974 hdev->owner = THIS_MODULE;
976 /* Interface numbers are hardcoded in the specification */
977 data->isoc = usb_ifnum_to_if(data->udev, 1);
980 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
982 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
984 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
987 if (id->driver_info & BTUSB_BROKEN_ISOC)
990 if (id->driver_info & BTUSB_DIGIANSWER) {
991 data->cmdreq_type = USB_TYPE_VENDOR;
992 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
995 if (id->driver_info & BTUSB_CSR) {
996 struct usb_device *udev = data->udev;
998 /* Old firmware would otherwise execute USB reset */
999 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
1000 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1003 if (id->driver_info & BTUSB_SNIFFER) {
1004 struct usb_device *udev = data->udev;
1006 /* New sniffer firmware has crippled HCI interface */
1007 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
1008 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
1013 if (id->driver_info & BTUSB_BCM92035) {
1014 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
1015 struct sk_buff *skb;
1017 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
1019 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
1020 skb_queue_tail(&hdev->driver_init, skb);
1025 err = usb_driver_claim_interface(&btusb_driver,
1034 err = hci_register_dev(hdev);
1041 usb_set_intfdata(intf, data);
1043 usb_enable_autosuspend(interface_to_usbdev(intf));
1048 static void btusb_disconnect(struct usb_interface *intf)
1050 struct btusb_data *data = usb_get_intfdata(intf);
1051 struct hci_dev *hdev;
1053 BT_DBG("intf %p", intf);
1060 __hci_dev_hold(hdev);
1062 usb_set_intfdata(data->intf, NULL);
1065 usb_set_intfdata(data->isoc, NULL);
1067 hci_unregister_dev(hdev);
1069 if (intf == data->isoc)
1070 usb_driver_release_interface(&btusb_driver, data->intf);
1071 else if (data->isoc)
1072 usb_driver_release_interface(&btusb_driver, data->isoc);
1074 __hci_dev_put(hdev);
1080 static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
1082 struct btusb_data *data = usb_get_intfdata(intf);
1084 BT_DBG("intf %p", intf);
1086 if (data->suspend_count++)
1089 spin_lock_irq(&data->txlock);
1090 if (!((message.event & PM_EVENT_AUTO) && data->tx_in_flight)) {
1091 set_bit(BTUSB_SUSPENDING, &data->flags);
1092 spin_unlock_irq(&data->txlock);
1094 spin_unlock_irq(&data->txlock);
1095 data->suspend_count--;
1099 cancel_work_sync(&data->work);
1101 btusb_stop_traffic(data);
1102 usb_kill_anchored_urbs(&data->tx_anchor);
1107 static void play_deferred(struct btusb_data *data)
1112 while ((urb = usb_get_from_anchor(&data->deferred))) {
1113 err = usb_submit_urb(urb, GFP_ATOMIC);
1117 data->tx_in_flight++;
1119 usb_scuttle_anchored_urbs(&data->deferred);
1122 static int btusb_resume(struct usb_interface *intf)
1124 struct btusb_data *data = usb_get_intfdata(intf);
1125 struct hci_dev *hdev = data->hdev;
1128 BT_DBG("intf %p", intf);
1130 if (--data->suspend_count)
1133 if (!test_bit(HCI_RUNNING, &hdev->flags))
1136 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
1137 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
1139 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1144 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
1145 err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
1147 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
1151 btusb_submit_bulk_urb(hdev, GFP_NOIO);
1154 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
1155 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
1156 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1158 btusb_submit_isoc_urb(hdev, GFP_NOIO);
1161 spin_lock_irq(&data->txlock);
1162 play_deferred(data);
1163 clear_bit(BTUSB_SUSPENDING, &data->flags);
1164 spin_unlock_irq(&data->txlock);
1165 schedule_work(&data->work);
1170 usb_scuttle_anchored_urbs(&data->deferred);
1172 spin_lock_irq(&data->txlock);
1173 clear_bit(BTUSB_SUSPENDING, &data->flags);
1174 spin_unlock_irq(&data->txlock);
1180 static struct usb_driver btusb_driver = {
1182 .probe = btusb_probe,
1183 .disconnect = btusb_disconnect,
1185 .suspend = btusb_suspend,
1186 .resume = btusb_resume,
1188 .id_table = btusb_table,
1189 .supports_autosuspend = 1,
1192 static int __init btusb_init(void)
1194 BT_INFO("Generic Bluetooth USB driver ver %s", VERSION);
1196 return usb_register(&btusb_driver);
1199 static void __exit btusb_exit(void)
1201 usb_deregister(&btusb_driver);
1204 module_init(btusb_init);
1205 module_exit(btusb_exit);
1207 module_param(ignore_dga, bool, 0644);
1208 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
1210 module_param(ignore_csr, bool, 0644);
1211 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
1213 module_param(ignore_sniffer, bool, 0644);
1214 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
1216 module_param(disable_scofix, bool, 0644);
1217 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
1219 module_param(force_scofix, bool, 0644);
1220 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
1222 module_param(reset, bool, 0644);
1223 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1225 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
1226 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
1227 MODULE_VERSION(VERSION);
1228 MODULE_LICENSE("GPL");