24 #include <linux/module.h>
32 static bool ignore_dga;
33 static bool ignore_csr;
34 static bool ignore_sniffer;
35 static bool disable_scofix;
36 static bool force_scofix;
38 static bool reset = 1;
40 static struct usb_driver btusb_driver;
42 #define BTUSB_IGNORE 0x01
43 #define BTUSB_DIGIANSWER 0x02
44 #define BTUSB_CSR 0x04
45 #define BTUSB_SNIFFER 0x08
46 #define BTUSB_BCM92035 0x10
47 #define BTUSB_BROKEN_ISOC 0x20
48 #define BTUSB_WRONG_SCO_MTU 0x40
49 #define BTUSB_ATH3012 0x80
53 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
56 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
59 { USB_DEVICE(0x0a5c, 0x21e1) },
62 { USB_DEVICE(0x05ac, 0x8213) },
65 { USB_DEVICE(0x05ac, 0x8215) },
68 { USB_DEVICE(0x05ac, 0x8218) },
71 { USB_DEVICE(0x05ac, 0x821b) },
74 { USB_DEVICE(0x05ac, 0x821f) },
77 { USB_DEVICE(0x05ac, 0x821a) },
80 { USB_DEVICE(0x05ac, 0x8281) },
83 { USB_DEVICE(0x057c, 0x3800) },
86 { USB_DEVICE(0x04bf, 0x030a) },
89 { USB_DEVICE(0x044e, 0x3001) },
90 { USB_DEVICE(0x044e, 0x3002) },
93 { USB_DEVICE(0x0bdb, 0x1002) },
96 { USB_DEVICE(0x0c10, 0x0000) },
99 { USB_DEVICE(0x04ca, 0x2003) },
100 { USB_DEVICE(0x0489, 0xe042) },
101 { USB_DEVICE(0x413c, 0x8197) },
104 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
107 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) },
116 { USB_DEVICE(0x0a12, 0x0001), .driver_info =
BTUSB_CSR },
119 { USB_DEVICE(0x0a5c, 0x2033), .driver_info =
BTUSB_IGNORE },
122 { USB_DEVICE(0x0cf3, 0x3002), .driver_info =
BTUSB_IGNORE },
123 { USB_DEVICE(0x0cf3, 0xe019), .driver_info =
BTUSB_IGNORE },
124 { USB_DEVICE(0x13d3, 0x3304), .driver_info =
BTUSB_IGNORE },
125 { USB_DEVICE(0x0930, 0x0215), .driver_info =
BTUSB_IGNORE },
126 { USB_DEVICE(0x0489, 0xe03d), .driver_info =
BTUSB_IGNORE },
127 { USB_DEVICE(0x0489, 0xe027), .driver_info =
BTUSB_IGNORE },
130 { USB_DEVICE(0x03f0, 0x311d), .driver_info =
BTUSB_IGNORE },
133 { USB_DEVICE(0x0cf3, 0x3004), .driver_info =
BTUSB_ATH3012 },
134 { USB_DEVICE(0x0cf3, 0x311d), .driver_info =
BTUSB_ATH3012 },
135 { USB_DEVICE(0x13d3, 0x3375), .driver_info =
BTUSB_ATH3012 },
136 { USB_DEVICE(0x04ca, 0x3005), .driver_info =
BTUSB_ATH3012 },
137 { USB_DEVICE(0x13d3, 0x3362), .driver_info =
BTUSB_ATH3012 },
138 { USB_DEVICE(0x0cf3, 0xe004), .driver_info =
BTUSB_ATH3012 },
139 { USB_DEVICE(0x0930, 0x0219), .driver_info =
BTUSB_ATH3012 },
140 { USB_DEVICE(0x0489, 0xe057), .driver_info =
BTUSB_ATH3012 },
143 { USB_DEVICE(0x0489, 0xe02c), .driver_info =
BTUSB_IGNORE },
146 { USB_DEVICE(0x0489, 0xe03c), .driver_info =
BTUSB_ATH3012 },
147 { USB_DEVICE(0x0489, 0xe036), .driver_info =
BTUSB_ATH3012 },
191 { USB_DEVICE(0x08fd, 0x0002), .driver_info =
BTUSB_IGNORE },
194 { USB_DEVICE(0x0a12, 0x0002), .driver_info =
BTUSB_SNIFFER },
197 { USB_DEVICE(0x16d3, 0x0002), .driver_info =
BTUSB_SNIFFER },
202 #define BTUSB_MAX_ISOC_FRAMES 10
204 #define BTUSB_INTR_RUNNING 0
205 #define BTUSB_BULK_RUNNING 1
206 #define BTUSB_ISOC_RUNNING 2
207 #define BTUSB_SUSPENDING 3
208 #define BTUSB_DID_ISO_RESUME 4
253 spin_unlock_irqrestore(&data->
txlock, flags);
258 static void btusb_intr_complete(
struct urb *
urb)
260 struct hci_dev *hdev = urb->context;
264 BT_DBG(
"%s urb %p status %d count %d", hdev->
name,
265 urb, urb->status, urb->actual_length);
270 if (urb->status == 0) {
271 hdev->
stat.byte_rx += urb->actual_length;
274 urb->transfer_buffer,
275 urb->actual_length) < 0) {
276 BT_ERR(
"%s corrupted event packet", hdev->
name);
284 usb_mark_last_busy(data->
udev);
292 BT_ERR(
"%s urb %p failed to resubmit (%d)",
293 hdev->
name, urb, -err);
298 static int btusb_submit_intr_urb(
struct hci_dev *hdev,
gfp_t mem_flags)
300 struct btusb_data *data = hci_get_drvdata(hdev);
317 buf =
kmalloc(size, mem_flags);
323 pipe = usb_rcvintpipe(data->
udev, data->
intr_ep->bEndpointAddress);
325 usb_fill_int_urb(urb, data->
udev, pipe, buf, size,
326 btusb_intr_complete, hdev,
329 urb->transfer_flags |= URB_FREE_BUFFER;
336 BT_ERR(
"%s urb %p submission failed (%d)",
337 hdev->
name, urb, -err);
346 static void btusb_bulk_complete(
struct urb *urb)
348 struct hci_dev *hdev = urb->context;
349 struct btusb_data *data = hci_get_drvdata(hdev);
352 BT_DBG(
"%s urb %p status %d count %d", hdev->
name,
353 urb, urb->status, urb->actual_length);
358 if (urb->status == 0) {
359 hdev->
stat.byte_rx += urb->actual_length;
362 urb->transfer_buffer,
363 urb->actual_length) < 0) {
364 BT_ERR(
"%s corrupted ACL packet", hdev->
name);
373 usb_mark_last_busy(data->
udev);
380 BT_ERR(
"%s urb %p failed to resubmit (%d)",
381 hdev->
name, urb, -err);
386 static int btusb_submit_bulk_urb(
struct hci_dev *hdev,
gfp_t mem_flags)
388 struct btusb_data *data = hci_get_drvdata(hdev);
403 buf =
kmalloc(size, mem_flags);
409 pipe = usb_rcvbulkpipe(data->
udev, data->
bulk_rx_ep->bEndpointAddress);
411 usb_fill_bulk_urb(urb, data->
udev, pipe,
412 buf, size, btusb_bulk_complete, hdev);
414 urb->transfer_flags |= URB_FREE_BUFFER;
416 usb_mark_last_busy(data->
udev);
422 BT_ERR(
"%s urb %p submission failed (%d)",
423 hdev->
name, urb, -err);
432 static void btusb_isoc_complete(
struct urb *urb)
434 struct hci_dev *hdev = urb->context;
435 struct btusb_data *data = hci_get_drvdata(hdev);
438 BT_DBG(
"%s urb %p status %d count %d", hdev->
name,
439 urb, urb->status, urb->actual_length);
444 if (urb->status == 0) {
445 for (i = 0; i < urb->number_of_packets; i++) {
447 unsigned int length = urb->iso_frame_desc[
i].actual_length;
449 if (urb->iso_frame_desc[i].status)
455 urb->transfer_buffer + offset,
457 BT_ERR(
"%s corrupted SCO packet", hdev->
name);
473 BT_ERR(
"%s urb %p failed to resubmit (%d)",
474 hdev->
name, urb, -err);
479 static inline void __fill_isoc_descriptor(
struct urb *urb,
int len,
int mtu)
483 BT_DBG(
"len %d mtu %d", len, mtu);
485 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
486 i++, offset += mtu, len -= mtu) {
487 urb->iso_frame_desc[
i].offset =
offset;
488 urb->iso_frame_desc[
i].length = mtu;
492 urb->iso_frame_desc[
i].offset =
offset;
493 urb->iso_frame_desc[
i].length = len;
497 urb->number_of_packets =
i;
500 static int btusb_submit_isoc_urb(
struct hci_dev *hdev,
gfp_t mem_flags)
502 struct btusb_data *data = hci_get_drvdata(hdev);
520 buf =
kmalloc(size, mem_flags);
526 pipe = usb_rcvisocpipe(data->
udev, data->
isoc_rx_ep->bEndpointAddress);
528 usb_fill_int_urb(urb, data->
udev, pipe, buf, size, btusb_isoc_complete,
531 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
533 __fill_isoc_descriptor(urb, size,
541 BT_ERR(
"%s urb %p submission failed (%d)",
542 hdev->
name, urb, -err);
551 static void btusb_tx_complete(
struct urb *urb)
555 struct btusb_data *data = hci_get_drvdata(hdev);
557 BT_DBG(
"%s urb %p status %d count %d", hdev->
name,
558 urb, urb->status, urb->actual_length);
564 hdev->
stat.byte_tx += urb->transfer_buffer_length;
571 spin_unlock(&data->
txlock);
573 kfree(urb->setup_packet);
578 static void btusb_isoc_tx_complete(
struct urb *urb)
580 struct sk_buff *skb = urb->context;
583 BT_DBG(
"%s urb %p status %d count %d", hdev->
name,
584 urb, urb->status, urb->actual_length);
590 hdev->
stat.byte_tx += urb->transfer_buffer_length;
595 kfree(urb->setup_packet);
600 static int btusb_open(
struct hci_dev *hdev)
602 struct btusb_data *data = hci_get_drvdata(hdev);
607 err = usb_autopm_get_interface(data->
intf);
611 data->
intf->needs_remote_wakeup = 1;
619 err = btusb_submit_intr_urb(hdev,
GFP_KERNEL);
623 err = btusb_submit_bulk_urb(hdev,
GFP_KERNEL);
633 usb_autopm_put_interface(data->
intf);
639 usb_autopm_put_interface(data->
intf);
643 static void btusb_stop_traffic(
struct btusb_data *data)
650 static int btusb_close(
struct hci_dev *hdev)
652 struct btusb_data *data = hci_get_drvdata(hdev);
667 btusb_stop_traffic(data);
668 err = usb_autopm_get_interface(data->
intf);
672 data->
intf->needs_remote_wakeup = 0;
673 usb_autopm_put_interface(data->
intf);
680 static int btusb_flush(
struct hci_dev *hdev)
682 struct btusb_data *data = hci_get_drvdata(hdev);
691 static int btusb_send_frame(
struct sk_buff *skb)
694 struct btusb_data *data = hci_get_drvdata(hdev);
705 switch (
bt_cb(skb)->pkt_type) {
723 pipe = usb_sndctrlpipe(data->
udev, 0x00);
725 usb_fill_control_urb(urb, data->
udev, pipe, (
void *) dr,
726 skb->
data, skb->
len, btusb_tx_complete, skb);
739 pipe = usb_sndbulkpipe(data->
udev,
742 usb_fill_bulk_urb(urb, data->
udev, pipe,
743 skb->
data, skb->
len, btusb_tx_complete, skb);
756 pipe = usb_sndisocpipe(data->
udev,
759 usb_fill_int_urb(urb, data->
udev, pipe,
760 skb->
data, skb->
len, btusb_isoc_tx_complete,
763 urb->transfer_flags = URB_ISO_ASAP;
765 __fill_isoc_descriptor(urb, skb->
len,
789 BT_ERR(
"%s urb %p submission failed (%d)",
790 hdev->
name, urb, -err);
791 kfree(urb->setup_packet);
794 usb_mark_last_busy(data->
udev);
802 static void btusb_notify(
struct hci_dev *hdev,
unsigned int evt)
804 struct btusb_data *data = hci_get_drvdata(hdev);
814 static inline int __set_isoc_interface(
struct hci_dev *hdev,
int altsetting)
816 struct btusb_data *data = hci_get_drvdata(hdev);
826 BT_ERR(
"%s setting interface failed (%d)", hdev->
name, -err);
835 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
836 ep_desc = &intf->cur_altsetting->endpoint[
i].desc;
838 if (!data->
isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
843 if (!data->
isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
850 BT_ERR(
"%s invalid SCO descriptors", hdev->
name);
866 err = usb_autopm_get_interface(data->
isoc ? data->
isoc : data->
intf);
877 static const int alts[3] = { 2, 4, 5 };
878 new_alts = alts[hdev->
conn_hash.sco_num - 1];
887 if (__set_isoc_interface(hdev, new_alts) < 0)
892 if (btusb_submit_isoc_urb(hdev,
GFP_KERNEL) < 0)
901 __set_isoc_interface(hdev, 0);
903 usb_autopm_put_interface(data->
isoc ? data->
isoc : data->
intf);
912 err = usb_autopm_get_interface(data->
intf);
916 usb_autopm_put_interface(data->
intf);
927 BT_DBG(
"intf %p id %p", intf,
id);
930 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
933 if (!id->driver_info) {
946 if (ignore_csr && id->driver_info &
BTUSB_CSR)
953 struct usb_device *
udev = interface_to_usbdev(intf);
957 if (
le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001)
965 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
966 ep_desc = &intf->cur_altsetting->endpoint[
i].desc;
968 if (!data->
intr_ep && usb_endpoint_is_int_in(ep_desc)) {
973 if (!data->
bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
978 if (!data->
bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
989 data->
udev = interface_to_usbdev(intf);
1009 hci_set_drvdata(hdev, data);
1015 hdev->
open = btusb_open;
1016 hdev->
close = btusb_close;
1017 hdev->
flush = btusb_flush;
1018 hdev->
send = btusb_send_frame;
1019 hdev->
notify = btusb_notify;
1028 if (!disable_scofix)
1041 struct usb_device *udev = data->
udev;
1044 if (
le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
1049 struct usb_device *udev = data->
udev;
1052 if (
le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
1059 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
1084 usb_set_intfdata(intf, data);
1091 struct btusb_data *data = usb_get_intfdata(intf);
1100 usb_set_intfdata(data->
intf,
NULL);
1103 usb_set_intfdata(data->
isoc,
NULL);
1107 if (intf == data->
isoc)
1109 else if (data->
isoc)
1118 struct btusb_data *data = usb_get_intfdata(intf);
1125 spin_lock_irq(&data->
txlock);
1128 spin_unlock_irq(&data->
txlock);
1130 spin_unlock_irq(&data->
txlock);
1137 btusb_stop_traffic(data);
1143 static void play_deferred(
struct btusb_data *data)
1160 struct btusb_data *data = usb_get_intfdata(intf);
1173 err = btusb_submit_intr_urb(hdev,
GFP_NOIO);
1181 err = btusb_submit_bulk_urb(hdev,
GFP_NOIO);
1187 btusb_submit_bulk_urb(hdev,
GFP_NOIO);
1191 if (btusb_submit_isoc_urb(hdev,
GFP_NOIO) < 0)
1194 btusb_submit_isoc_urb(hdev,
GFP_NOIO);
1197 spin_lock_irq(&data->
txlock);
1198 play_deferred(data);
1200 spin_unlock_irq(&data->
txlock);
1208 spin_lock_irq(&data->
txlock);
1210 spin_unlock_irq(&data->
txlock);
1216 static struct usb_driver btusb_driver = {
1218 .probe = btusb_probe,
1219 .disconnect = btusb_disconnect,
1221 .suspend = btusb_suspend,
1222 .resume = btusb_resume,
1224 .id_table = btusb_table,
1225 .supports_autosuspend = 1,
1226 .disable_hub_initiated_lpm = 1,
1241 MODULE_PARM_DESC(disable_scofix,
"Disable fixup of wrong SCO buffer size");