2 HCI USB driver for Linux Bluetooth protocol stack (BlueZ)
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6 Copyright (C) 2003 Maxim Krasnyansky <maxk@qualcomm.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation;
12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
15 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
16 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
17 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
22 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
23 SOFTWARE IS DISCLAIMED.
27 * Bluetooth HCI USB driver.
28 * Based on original USB Bluetooth driver for Linux kernel
29 * Copyright (c) 2000 Greg Kroah-Hartman <greg@kroah.com>
30 * Copyright (c) 2000 Mark Douglas Corner <mcorner@umich.edu>
34 #include <linux/config.h>
35 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/init.h>
39 #include <linux/sched.h>
40 #include <linux/unistd.h>
41 #include <linux/types.h>
42 #include <linux/interrupt.h>
43 #include <linux/moduleparam.h>
45 #include <linux/slab.h>
46 #include <linux/errno.h>
47 #include <linux/string.h>
48 #include <linux/skbuff.h>
50 #include <linux/usb.h>
52 #include <net/bluetooth/bluetooth.h>
53 #include <net/bluetooth/hci_core.h>
57 #ifndef CONFIG_BT_HCIUSB_DEBUG
62 #ifndef CONFIG_BT_HCIUSB_ZERO_PACKET
63 #undef URB_ZERO_PACKET
64 #define URB_ZERO_PACKET 0
67 static int ignore = 0;
68 static int ignore_dga = 0;
69 static int ignore_csr = 0;
70 static int ignore_sniffer = 0;
73 #ifdef CONFIG_BT_HCIUSB_SCO
79 static struct usb_driver hci_usb_driver;
81 static struct usb_device_id bluetooth_ids[] = {
82 /* Generic Bluetooth USB device */
83 { USB_DEVICE_INFO(HCI_DEV_CLASS, HCI_DEV_SUBCLASS, HCI_DEV_PROTOCOL) },
85 /* AVM BlueFRITZ! USB v2.0 */
86 { USB_DEVICE(0x057c, 0x3800) },
88 /* Bluetooth Ultraport Module from IBM */
89 { USB_DEVICE(0x04bf, 0x030a) },
91 /* ALPS Modules with non-standard id */
92 { USB_DEVICE(0x044e, 0x3001) },
93 { USB_DEVICE(0x044e, 0x3002) },
95 /* Ericsson with non-standard id */
96 { USB_DEVICE(0x0bdb, 0x1002) },
98 { } /* Terminating entry */
101 MODULE_DEVICE_TABLE (usb, bluetooth_ids);
103 static struct usb_device_id blacklist_ids[] = {
104 /* CSR BlueCore devices */
105 { USB_DEVICE(0x0a12, 0x0001), .driver_info = HCI_CSR },
107 /* Broadcom BCM2033 without firmware */
108 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = HCI_IGNORE },
110 /* Broadcom BCM2035 */
111 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = HCI_RESET | HCI_BROKEN_ISOC },
112 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = HCI_BCM92035 },
114 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
115 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET },
117 /* Kensington Bluetooth USB adapter */
118 { USB_DEVICE(0x047d, 0x105d), .driver_info = HCI_RESET },
120 /* ISSC Bluetooth Adapter v3.1 */
121 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET },
123 /* RTX Telecom based adapter with buggy SCO support */
124 { USB_DEVICE(0x0400, 0x0807), .driver_info = HCI_BROKEN_ISOC },
126 /* Digianswer devices */
127 { USB_DEVICE(0x08fd, 0x0001), .driver_info = HCI_DIGIANSWER },
128 { USB_DEVICE(0x08fd, 0x0002), .driver_info = HCI_IGNORE },
130 /* CSR BlueCore Bluetooth Sniffer */
131 { USB_DEVICE(0x0a12, 0x0002), .driver_info = HCI_SNIFFER },
133 { } /* Terminating entry */
136 static struct _urb *_urb_alloc(int isoc, gfp_t gfp)
138 struct _urb *_urb = kmalloc(sizeof(struct _urb) +
139 sizeof(struct usb_iso_packet_descriptor) * isoc, gfp);
141 memset(_urb, 0, sizeof(*_urb));
142 usb_init_urb(&_urb->urb);
147 static struct _urb *_urb_dequeue(struct _urb_queue *q)
149 struct _urb *_urb = NULL;
151 spin_lock_irqsave(&q->lock, flags);
153 struct list_head *head = &q->head;
154 struct list_head *next = head->next;
156 _urb = list_entry(next, struct _urb, list);
157 list_del(next); _urb->queue = NULL;
160 spin_unlock_irqrestore(&q->lock, flags);
164 static void hci_usb_rx_complete(struct urb *urb, struct pt_regs *regs);
165 static void hci_usb_tx_complete(struct urb *urb, struct pt_regs *regs);
167 #define __pending_tx(husb, type) (&husb->pending_tx[type-1])
168 #define __pending_q(husb, type) (&husb->pending_q[type-1])
169 #define __completed_q(husb, type) (&husb->completed_q[type-1])
170 #define __transmit_q(husb, type) (&husb->transmit_q[type-1])
171 #define __reassembly(husb, type) (husb->reassembly[type-1])
173 static inline struct _urb *__get_completed(struct hci_usb *husb, int type)
175 return _urb_dequeue(__completed_q(husb, type));
178 #ifdef CONFIG_BT_HCIUSB_SCO
179 static void __fill_isoc_desc(struct urb *urb, int len, int mtu)
183 BT_DBG("len %d mtu %d", len, mtu);
185 for (i=0; i < HCI_MAX_ISOC_FRAMES && len >= mtu; i++, offset += mtu, len -= mtu) {
186 urb->iso_frame_desc[i].offset = offset;
187 urb->iso_frame_desc[i].length = mtu;
188 BT_DBG("desc %d offset %d len %d", i, offset, mtu);
190 if (len && i < HCI_MAX_ISOC_FRAMES) {
191 urb->iso_frame_desc[i].offset = offset;
192 urb->iso_frame_desc[i].length = len;
193 BT_DBG("desc %d offset %d len %d", i, offset, len);
196 urb->number_of_packets = i;
200 static int hci_usb_intr_rx_submit(struct hci_usb *husb)
204 int err, pipe, interval, size;
207 BT_DBG("%s", husb->hdev->name);
209 size = le16_to_cpu(husb->intr_in_ep->desc.wMaxPacketSize);
211 buf = kmalloc(size, GFP_ATOMIC);
215 _urb = _urb_alloc(0, GFP_ATOMIC);
220 _urb->type = HCI_EVENT_PKT;
221 _urb_queue_tail(__pending_q(husb, _urb->type), _urb);
224 pipe = usb_rcvintpipe(husb->udev, husb->intr_in_ep->desc.bEndpointAddress);
225 interval = husb->intr_in_ep->desc.bInterval;
226 usb_fill_int_urb(urb, husb->udev, pipe, buf, size, hci_usb_rx_complete, husb, interval);
228 err = usb_submit_urb(urb, GFP_ATOMIC);
230 BT_ERR("%s intr rx submit failed urb %p err %d",
231 husb->hdev->name, urb, err);
239 static int hci_usb_bulk_rx_submit(struct hci_usb *husb)
243 int err, pipe, size = HCI_MAX_FRAME_SIZE;
246 buf = kmalloc(size, GFP_ATOMIC);
250 _urb = _urb_alloc(0, GFP_ATOMIC);
255 _urb->type = HCI_ACLDATA_PKT;
256 _urb_queue_tail(__pending_q(husb, _urb->type), _urb);
259 pipe = usb_rcvbulkpipe(husb->udev, husb->bulk_in_ep->desc.bEndpointAddress);
260 usb_fill_bulk_urb(urb, husb->udev, pipe, buf, size, hci_usb_rx_complete, husb);
261 urb->transfer_flags = 0;
263 BT_DBG("%s urb %p", husb->hdev->name, urb);
265 err = usb_submit_urb(urb, GFP_ATOMIC);
267 BT_ERR("%s bulk rx submit failed urb %p err %d",
268 husb->hdev->name, urb, err);
276 #ifdef CONFIG_BT_HCIUSB_SCO
277 static int hci_usb_isoc_rx_submit(struct hci_usb *husb)
284 mtu = le16_to_cpu(husb->isoc_in_ep->desc.wMaxPacketSize);
285 size = mtu * HCI_MAX_ISOC_FRAMES;
287 buf = kmalloc(size, GFP_ATOMIC);
291 _urb = _urb_alloc(HCI_MAX_ISOC_FRAMES, GFP_ATOMIC);
296 _urb->type = HCI_SCODATA_PKT;
297 _urb_queue_tail(__pending_q(husb, _urb->type), _urb);
302 urb->dev = husb->udev;
303 urb->pipe = usb_rcvisocpipe(husb->udev, husb->isoc_in_ep->desc.bEndpointAddress);
304 urb->complete = hci_usb_rx_complete;
306 urb->interval = husb->isoc_in_ep->desc.bInterval;
308 urb->transfer_buffer_length = size;
309 urb->transfer_buffer = buf;
310 urb->transfer_flags = URB_ISO_ASAP;
312 __fill_isoc_desc(urb, size, mtu);
314 BT_DBG("%s urb %p", husb->hdev->name, urb);
316 err = usb_submit_urb(urb, GFP_ATOMIC);
318 BT_ERR("%s isoc rx submit failed urb %p err %d",
319 husb->hdev->name, urb, err);
328 /* Initialize device */
329 static int hci_usb_open(struct hci_dev *hdev)
331 struct hci_usb *husb = (struct hci_usb *) hdev->driver_data;
335 BT_DBG("%s", hdev->name);
337 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
340 write_lock_irqsave(&husb->completion_lock, flags);
342 err = hci_usb_intr_rx_submit(husb);
344 for (i = 0; i < HCI_MAX_BULK_RX; i++)
345 hci_usb_bulk_rx_submit(husb);
347 #ifdef CONFIG_BT_HCIUSB_SCO
348 if (husb->isoc_iface)
349 for (i = 0; i < HCI_MAX_ISOC_RX; i++)
350 hci_usb_isoc_rx_submit(husb);
353 clear_bit(HCI_RUNNING, &hdev->flags);
356 write_unlock_irqrestore(&husb->completion_lock, flags);
361 static int hci_usb_flush(struct hci_dev *hdev)
363 struct hci_usb *husb = (struct hci_usb *) hdev->driver_data;
366 BT_DBG("%s", hdev->name);
368 for (i = 0; i < 4; i++)
369 skb_queue_purge(&husb->transmit_q[i]);
373 static void hci_usb_unlink_urbs(struct hci_usb *husb)
377 BT_DBG("%s", husb->hdev->name);
379 for (i = 0; i < 4; i++) {
383 /* Kill pending requests */
384 while ((_urb = _urb_dequeue(&husb->pending_q[i]))) {
386 BT_DBG("%s unlinking _urb %p type %d urb %p",
387 husb->hdev->name, _urb, _urb->type, urb);
389 _urb_queue_tail(__completed_q(husb, _urb->type), _urb);
392 /* Release completed requests */
393 while ((_urb = _urb_dequeue(&husb->completed_q[i]))) {
395 BT_DBG("%s freeing _urb %p type %d urb %p",
396 husb->hdev->name, _urb, _urb->type, urb);
397 kfree(urb->setup_packet);
398 kfree(urb->transfer_buffer);
402 /* Release reassembly buffers */
403 if (husb->reassembly[i]) {
404 kfree_skb(husb->reassembly[i]);
405 husb->reassembly[i] = NULL;
411 static int hci_usb_close(struct hci_dev *hdev)
413 struct hci_usb *husb = (struct hci_usb *) hdev->driver_data;
416 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
419 BT_DBG("%s", hdev->name);
421 /* Synchronize with completion handlers */
422 write_lock_irqsave(&husb->completion_lock, flags);
423 write_unlock_irqrestore(&husb->completion_lock, flags);
425 hci_usb_unlink_urbs(husb);
430 static int __tx_submit(struct hci_usb *husb, struct _urb *_urb)
432 struct urb *urb = &_urb->urb;
435 BT_DBG("%s urb %p type %d", husb->hdev->name, urb, _urb->type);
437 _urb_queue_tail(__pending_q(husb, _urb->type), _urb);
438 err = usb_submit_urb(urb, GFP_ATOMIC);
440 BT_ERR("%s tx submit failed urb %p type %d err %d",
441 husb->hdev->name, urb, _urb->type, err);
443 _urb_queue_tail(__completed_q(husb, _urb->type), _urb);
445 atomic_inc(__pending_tx(husb, _urb->type));
450 static inline int hci_usb_send_ctrl(struct hci_usb *husb, struct sk_buff *skb)
452 struct _urb *_urb = __get_completed(husb, bt_cb(skb)->pkt_type);
453 struct usb_ctrlrequest *dr;
457 _urb = _urb_alloc(0, GFP_ATOMIC);
460 _urb->type = bt_cb(skb)->pkt_type;
462 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
468 dr = (void *) _urb->urb.setup_packet;
470 dr->bRequestType = husb->ctrl_req;
474 dr->wLength = __cpu_to_le16(skb->len);
477 usb_fill_control_urb(urb, husb->udev, usb_sndctrlpipe(husb->udev, 0),
478 (void *) dr, skb->data, skb->len, hci_usb_tx_complete, husb);
480 BT_DBG("%s skb %p len %d", husb->hdev->name, skb, skb->len);
483 return __tx_submit(husb, _urb);
486 static inline int hci_usb_send_bulk(struct hci_usb *husb, struct sk_buff *skb)
488 struct _urb *_urb = __get_completed(husb, bt_cb(skb)->pkt_type);
493 _urb = _urb_alloc(0, GFP_ATOMIC);
496 _urb->type = bt_cb(skb)->pkt_type;
500 pipe = usb_sndbulkpipe(husb->udev, husb->bulk_out_ep->desc.bEndpointAddress);
501 usb_fill_bulk_urb(urb, husb->udev, pipe, skb->data, skb->len,
502 hci_usb_tx_complete, husb);
503 urb->transfer_flags = URB_ZERO_PACKET;
505 BT_DBG("%s skb %p len %d", husb->hdev->name, skb, skb->len);
508 return __tx_submit(husb, _urb);
511 #ifdef CONFIG_BT_HCIUSB_SCO
512 static inline int hci_usb_send_isoc(struct hci_usb *husb, struct sk_buff *skb)
514 struct _urb *_urb = __get_completed(husb, bt_cb(skb)->pkt_type);
518 _urb = _urb_alloc(HCI_MAX_ISOC_FRAMES, GFP_ATOMIC);
521 _urb->type = bt_cb(skb)->pkt_type;
524 BT_DBG("%s skb %p len %d", husb->hdev->name, skb, skb->len);
529 urb->dev = husb->udev;
530 urb->pipe = usb_sndisocpipe(husb->udev, husb->isoc_out_ep->desc.bEndpointAddress);
531 urb->complete = hci_usb_tx_complete;
532 urb->transfer_flags = URB_ISO_ASAP;
534 urb->interval = husb->isoc_out_ep->desc.bInterval;
536 urb->transfer_buffer = skb->data;
537 urb->transfer_buffer_length = skb->len;
539 __fill_isoc_desc(urb, skb->len, le16_to_cpu(husb->isoc_out_ep->desc.wMaxPacketSize));
542 return __tx_submit(husb, _urb);
546 static void hci_usb_tx_process(struct hci_usb *husb)
548 struct sk_buff_head *q;
551 BT_DBG("%s", husb->hdev->name);
554 clear_bit(HCI_USB_TX_WAKEUP, &husb->state);
556 /* Process command queue */
557 q = __transmit_q(husb, HCI_COMMAND_PKT);
558 if (!atomic_read(__pending_tx(husb, HCI_COMMAND_PKT)) &&
559 (skb = skb_dequeue(q))) {
560 if (hci_usb_send_ctrl(husb, skb) < 0)
561 skb_queue_head(q, skb);
564 #ifdef CONFIG_BT_HCIUSB_SCO
565 /* Process SCO queue */
566 q = __transmit_q(husb, HCI_SCODATA_PKT);
567 if (atomic_read(__pending_tx(husb, HCI_SCODATA_PKT)) < HCI_MAX_ISOC_TX &&
568 (skb = skb_dequeue(q))) {
569 if (hci_usb_send_isoc(husb, skb) < 0)
570 skb_queue_head(q, skb);
574 /* Process ACL queue */
575 q = __transmit_q(husb, HCI_ACLDATA_PKT);
576 while (atomic_read(__pending_tx(husb, HCI_ACLDATA_PKT)) < HCI_MAX_BULK_TX &&
577 (skb = skb_dequeue(q))) {
578 if (hci_usb_send_bulk(husb, skb) < 0) {
579 skb_queue_head(q, skb);
583 } while(test_bit(HCI_USB_TX_WAKEUP, &husb->state));
586 static inline void hci_usb_tx_wakeup(struct hci_usb *husb)
588 /* Serialize TX queue processing to avoid data reordering */
589 if (!test_and_set_bit(HCI_USB_TX_PROCESS, &husb->state)) {
590 hci_usb_tx_process(husb);
591 clear_bit(HCI_USB_TX_PROCESS, &husb->state);
593 set_bit(HCI_USB_TX_WAKEUP, &husb->state);
596 /* Send frames from HCI layer */
597 static int hci_usb_send_frame(struct sk_buff *skb)
599 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
600 struct hci_usb *husb;
603 BT_ERR("frame for uknown device (hdev=NULL)");
607 if (!test_bit(HCI_RUNNING, &hdev->flags))
610 BT_DBG("%s type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len);
612 husb = (struct hci_usb *) hdev->driver_data;
614 switch (bt_cb(skb)->pkt_type) {
615 case HCI_COMMAND_PKT:
619 case HCI_ACLDATA_PKT:
623 #ifdef CONFIG_BT_HCIUSB_SCO
624 case HCI_SCODATA_PKT:
634 read_lock(&husb->completion_lock);
636 skb_queue_tail(__transmit_q(husb, bt_cb(skb)->pkt_type), skb);
637 hci_usb_tx_wakeup(husb);
639 read_unlock(&husb->completion_lock);
643 static inline int __recv_frame(struct hci_usb *husb, int type, void *data, int count)
645 BT_DBG("%s type %d data %p count %d", husb->hdev->name, type, data, count);
647 husb->hdev->stat.byte_rx += count;
650 struct sk_buff *skb = __reassembly(husb, type);
651 struct { int expect; } *scb;
655 /* Start of the frame */
659 if (count >= HCI_EVENT_HDR_SIZE) {
660 struct hci_event_hdr *h = data;
661 len = HCI_EVENT_HDR_SIZE + h->plen;
666 case HCI_ACLDATA_PKT:
667 if (count >= HCI_ACL_HDR_SIZE) {
668 struct hci_acl_hdr *h = data;
669 len = HCI_ACL_HDR_SIZE + __le16_to_cpu(h->dlen);
673 #ifdef CONFIG_BT_HCIUSB_SCO
674 case HCI_SCODATA_PKT:
675 if (count >= HCI_SCO_HDR_SIZE) {
676 struct hci_sco_hdr *h = data;
677 len = HCI_SCO_HDR_SIZE + h->dlen;
683 BT_DBG("new packet len %d", len);
685 skb = bt_skb_alloc(len, GFP_ATOMIC);
687 BT_ERR("%s no memory for the packet", husb->hdev->name);
690 skb->dev = (void *) husb->hdev;
691 bt_cb(skb)->pkt_type = type;
693 __reassembly(husb, type) = skb;
695 scb = (void *) skb->cb;
699 scb = (void *) skb->cb;
703 len = min(len, count);
705 memcpy(skb_put(skb, len), data, len);
710 __reassembly(husb, type) = NULL;
711 bt_cb(skb)->pkt_type = type;
715 count -= len; data += len;
720 static void hci_usb_rx_complete(struct urb *urb, struct pt_regs *regs)
722 struct _urb *_urb = container_of(urb, struct _urb, urb);
723 struct hci_usb *husb = (void *) urb->context;
724 struct hci_dev *hdev = husb->hdev;
725 int err, count = urb->actual_length;
727 BT_DBG("%s urb %p type %d status %d count %d flags %x", hdev->name, urb,
728 _urb->type, urb->status, count, urb->transfer_flags);
730 read_lock(&husb->completion_lock);
732 if (!test_bit(HCI_RUNNING, &hdev->flags))
735 if (urb->status || !count)
738 if (_urb->type == HCI_SCODATA_PKT) {
739 #ifdef CONFIG_BT_HCIUSB_SCO
741 for (i=0; i < urb->number_of_packets; i++) {
742 BT_DBG("desc %d status %d offset %d len %d", i,
743 urb->iso_frame_desc[i].status,
744 urb->iso_frame_desc[i].offset,
745 urb->iso_frame_desc[i].actual_length);
747 if (!urb->iso_frame_desc[i].status)
748 __recv_frame(husb, _urb->type,
749 urb->transfer_buffer + urb->iso_frame_desc[i].offset,
750 urb->iso_frame_desc[i].actual_length);
756 err = __recv_frame(husb, _urb->type, urb->transfer_buffer, count);
758 BT_ERR("%s corrupted packet: type %d count %d",
759 husb->hdev->name, _urb->type, count);
765 urb->dev = husb->udev;
766 err = usb_submit_urb(urb, GFP_ATOMIC);
767 BT_DBG("%s urb %p type %d resubmit status %d", hdev->name, urb,
771 read_unlock(&husb->completion_lock);
774 static void hci_usb_tx_complete(struct urb *urb, struct pt_regs *regs)
776 struct _urb *_urb = container_of(urb, struct _urb, urb);
777 struct hci_usb *husb = (void *) urb->context;
778 struct hci_dev *hdev = husb->hdev;
780 BT_DBG("%s urb %p status %d flags %x", hdev->name, urb,
781 urb->status, urb->transfer_flags);
783 atomic_dec(__pending_tx(husb, _urb->type));
785 urb->transfer_buffer = NULL;
786 kfree_skb((struct sk_buff *) _urb->priv);
788 if (!test_bit(HCI_RUNNING, &hdev->flags))
792 hdev->stat.byte_tx += urb->transfer_buffer_length;
796 read_lock(&husb->completion_lock);
799 _urb_queue_tail(__completed_q(husb, _urb->type), _urb);
801 hci_usb_tx_wakeup(husb);
803 read_unlock(&husb->completion_lock);
806 static void hci_usb_destruct(struct hci_dev *hdev)
808 struct hci_usb *husb = (struct hci_usb *) hdev->driver_data;
810 BT_DBG("%s", hdev->name);
815 static void hci_usb_notify(struct hci_dev *hdev, unsigned int evt)
817 BT_DBG("%s evt %d", hdev->name, evt);
820 static int hci_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
822 struct usb_device *udev = interface_to_usbdev(intf);
823 struct usb_host_endpoint *bulk_out_ep = NULL;
824 struct usb_host_endpoint *bulk_in_ep = NULL;
825 struct usb_host_endpoint *intr_in_ep = NULL;
826 struct usb_host_endpoint *ep;
827 struct usb_host_interface *uif;
828 struct usb_interface *isoc_iface;
829 struct hci_usb *husb;
830 struct hci_dev *hdev;
831 int i, e, size, isoc_ifnum, isoc_alts;
833 BT_DBG("udev %p intf %p", udev, intf);
835 if (!id->driver_info) {
836 const struct usb_device_id *match;
837 match = usb_match_id(intf, blacklist_ids);
842 if (ignore || id->driver_info & HCI_IGNORE)
845 if (ignore_dga && id->driver_info & HCI_DIGIANSWER)
848 if (ignore_csr && id->driver_info & HCI_CSR)
851 if (ignore_sniffer && id->driver_info & HCI_SNIFFER)
854 if (intf->cur_altsetting->desc.bInterfaceNumber > 0)
857 /* Find endpoints that we need */
858 uif = intf->cur_altsetting;
859 for (e = 0; e < uif->desc.bNumEndpoints; e++) {
860 ep = &uif->endpoint[e];
862 switch (ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
863 case USB_ENDPOINT_XFER_INT:
864 if (ep->desc.bEndpointAddress & USB_DIR_IN)
868 case USB_ENDPOINT_XFER_BULK:
869 if (ep->desc.bEndpointAddress & USB_DIR_IN)
877 if (!bulk_in_ep || !bulk_out_ep || !intr_in_ep) {
878 BT_DBG("Bulk endpoints not found");
882 if (!(husb = kzalloc(sizeof(struct hci_usb), GFP_KERNEL))) {
883 BT_ERR("Can't allocate: control structure");
888 husb->bulk_out_ep = bulk_out_ep;
889 husb->bulk_in_ep = bulk_in_ep;
890 husb->intr_in_ep = intr_in_ep;
892 if (id->driver_info & HCI_DIGIANSWER)
893 husb->ctrl_req = USB_TYPE_VENDOR;
895 husb->ctrl_req = USB_TYPE_CLASS;
897 /* Find isochronous endpoints that we can use */
903 #ifdef CONFIG_BT_HCIUSB_SCO
904 if (isoc && !(id->driver_info & (HCI_BROKEN_ISOC | HCI_SNIFFER)))
905 isoc_iface = usb_ifnum_to_if(udev, isoc_ifnum);
909 struct usb_host_endpoint *isoc_out_ep = NULL;
910 struct usb_host_endpoint *isoc_in_ep = NULL;
912 for (a = 0; a < isoc_iface->num_altsetting; a++) {
913 uif = &isoc_iface->altsetting[a];
914 for (e = 0; e < uif->desc.bNumEndpoints; e++) {
915 ep = &uif->endpoint[e];
917 switch (ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
918 case USB_ENDPOINT_XFER_ISOC:
919 if (le16_to_cpu(ep->desc.wMaxPacketSize) < size ||
920 uif->desc.bAlternateSetting != isoc)
922 size = le16_to_cpu(ep->desc.wMaxPacketSize);
924 isoc_alts = uif->desc.bAlternateSetting;
926 if (ep->desc.bEndpointAddress & USB_DIR_IN)
935 if (!isoc_in_ep || !isoc_out_ep)
936 BT_DBG("Isoc endpoints not found");
938 BT_DBG("isoc ifnum %d alts %d", isoc_ifnum, isoc_alts);
939 if (usb_driver_claim_interface(&hci_usb_driver, isoc_iface, husb) != 0)
940 BT_ERR("Can't claim isoc interface");
941 else if (usb_set_interface(udev, isoc_ifnum, isoc_alts)) {
942 BT_ERR("Can't set isoc interface settings");
943 husb->isoc_iface = isoc_iface;
944 usb_driver_release_interface(&hci_usb_driver, isoc_iface);
945 husb->isoc_iface = NULL;
947 husb->isoc_iface = isoc_iface;
948 husb->isoc_in_ep = isoc_in_ep;
949 husb->isoc_out_ep = isoc_out_ep;
955 rwlock_init(&husb->completion_lock);
957 for (i = 0; i < 4; i++) {
958 skb_queue_head_init(&husb->transmit_q[i]);
959 _urb_queue_init(&husb->pending_q[i]);
960 _urb_queue_init(&husb->completed_q[i]);
963 /* Initialize and register HCI device */
964 hdev = hci_alloc_dev();
966 BT_ERR("Can't allocate HCI device");
972 hdev->type = HCI_USB;
973 hdev->driver_data = husb;
974 SET_HCIDEV_DEV(hdev, &intf->dev);
976 hdev->open = hci_usb_open;
977 hdev->close = hci_usb_close;
978 hdev->flush = hci_usb_flush;
979 hdev->send = hci_usb_send_frame;
980 hdev->destruct = hci_usb_destruct;
981 hdev->notify = hci_usb_notify;
983 hdev->owner = THIS_MODULE;
985 if (reset || id->driver_info & HCI_RESET)
986 set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
988 if (id->driver_info & HCI_SNIFFER) {
989 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
990 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
993 if (id->driver_info & HCI_BCM92035) {
994 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
997 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
999 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
1000 skb_queue_tail(&hdev->driver_init, skb);
1004 if (hci_register_dev(hdev) < 0) {
1005 BT_ERR("Can't register HCI device");
1010 usb_set_intfdata(intf, husb);
1014 if (husb->isoc_iface)
1015 usb_driver_release_interface(&hci_usb_driver, husb->isoc_iface);
1022 static void hci_usb_disconnect(struct usb_interface *intf)
1024 struct hci_usb *husb = usb_get_intfdata(intf);
1025 struct hci_dev *hdev;
1027 if (!husb || intf == husb->isoc_iface)
1030 usb_set_intfdata(intf, NULL);
1033 BT_DBG("%s", hdev->name);
1035 hci_usb_close(hdev);
1037 if (husb->isoc_iface)
1038 usb_driver_release_interface(&hci_usb_driver, husb->isoc_iface);
1040 if (hci_unregister_dev(hdev) < 0)
1041 BT_ERR("Can't unregister HCI device %s", hdev->name);
1046 static struct usb_driver hci_usb_driver = {
1048 .probe = hci_usb_probe,
1049 .disconnect = hci_usb_disconnect,
1050 .id_table = bluetooth_ids,
1053 static int __init hci_usb_init(void)
1057 BT_INFO("HCI USB driver ver %s", VERSION);
1059 if ((err = usb_register(&hci_usb_driver)) < 0)
1060 BT_ERR("Failed to register HCI USB driver");
1065 static void __exit hci_usb_exit(void)
1067 usb_deregister(&hci_usb_driver);
1070 module_init(hci_usb_init);
1071 module_exit(hci_usb_exit);
1073 module_param(ignore, bool, 0644);
1074 MODULE_PARM_DESC(ignore, "Ignore devices from the matching table");
1076 module_param(ignore_dga, bool, 0644);
1077 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
1079 module_param(ignore_csr, bool, 0644);
1080 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
1082 module_param(ignore_sniffer, bool, 0644);
1083 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
1085 module_param(reset, bool, 0644);
1086 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1088 #ifdef CONFIG_BT_HCIUSB_SCO
1089 module_param(isoc, int, 0644);
1090 MODULE_PARM_DESC(isoc, "Set isochronous transfers for SCO over HCI support");
1093 MODULE_AUTHOR("Maxim Krasnyansky <maxk@qualcomm.com>, Marcel Holtmann <marcel@holtmann.org>");
1094 MODULE_DESCRIPTION("Bluetooth HCI USB driver ver " VERSION);
1095 MODULE_VERSION(VERSION);
1096 MODULE_LICENSE("GPL");