Skip to contentSkip to conversation

Fix SCO on some bluetooth adapters

PATCH In review Olivier Galibert 3 participants 3 messages Apr 20, 2006 – Jul 2, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix SCO on some bluetooth adapters

Some bluetooth adapters return an incorrect number of sco packets in READ_BUFFER_SIZE. Add a quirk hook to fix it from the driver side, and use the hook for a first adapter.

---

I tried to take Marcel Holtmann's remarks into account, but he seems unavailable to tell me whether he likes that version, so I'll send it to the whole shebang instead of just him this time.

The main point was "only the driver knows how to fix the problem", hence a function pointer quirk hook. This is definitively not limited to broadcom USB devices, googling for "SCO MTU 64:0" has interesting results.

Pavel, '4' doesn't seem to be a value that happens in any correctly answering adapter, while 8 happens often. Try "SCO MTU 64:4" and "SCO MTU 64:8" for comparison.

 drivers/bluetooth/hci_usb.c      |   12 ++++++++++++
 drivers/bluetooth/hci_usb.h      |    1 +
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_event.c        |   16 ++++++++++++++--
 4 files changed, 28 insertions(+), 2 deletions(-)

841d7690e75189803907fbc4616b984087e7f89c

drivers/bluetooth/hci_usb.c +12 -0
index 92382e8..0cea36b 100644
@@ -130,6 +130,9 @@ static struct usb_device_id blacklist_id
 	/* CSR BlueCore Bluetooth Sniffer */
 	{ USB_DEVICE(0x0a12, 0x0002), .driver_info = HCI_SNIFFER },
 
+	/* Belkin F8T012 */
+	{ USB_DEVICE(0x050d, 0x0012), .driver_info = HCI_READ_BUFFER_SIZE },
+
 	{ }	/* Terminating entry */
 };
 
@@ -817,6 +820,12 @@ static void hci_usb_notify(struct hci_de
 	BT_DBG("%s evt %d", hdev->name, evt);
 }
 
+static void hci_usb_quirk_read_buffer_size(struct hci_dev *hdev)
+{
+	if (!hdev->sco_pkts)
+		hdev->sco_pkts = 8;
+}
+
 static int hci_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
@@ -984,6 +993,9 @@ #endif
 
 	if (reset || id->driver_info & HCI_RESET)
 		set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
+
+	if (id->driver_info & HCI_READ_BUFFER_SIZE)
+		hdev->quirk_read_buffer_size = hci_usb_quirk_read_buffer_size;
 
 	if (id->driver_info & HCI_SNIFFER) {
 		if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
drivers/bluetooth/hci_usb.h +1 -0
index 37100a6..ea11df7 100644
@@ -35,6 +35,7 @@ #define HCI_CSR			0x08
 #define HCI_SNIFFER		0x10
 #define HCI_BCM92035		0x20
 #define HCI_BROKEN_ISOC		0x40
+#define HCI_READ_BUFFER_SIZE    0x80
 
 #define HCI_MAX_IFACE_NUM	3
 
include/net/bluetooth/hci_core.h +1 -0
index bb9f81d..045b61f 100644
@@ -134,6 +134,7 @@ struct hci_dev {
 	void (*destruct)(struct hci_dev *hdev);
 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
 	int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
+	void (*quirk_read_buffer_size)(struct hci_dev *hdev);
 };
 
 struct hci_conn {
net/bluetooth/hci_event.c +14 -2
index eb64555..87358b8 100644
@@ -321,8 +321,20 @@ static void hci_cc_info_param(struct hci
 
 		hdev->acl_mtu  = __le16_to_cpu(bs->acl_mtu);
 		hdev->sco_mtu  = bs->sco_mtu ? bs->sco_mtu : 64;
-		hdev->acl_pkts = hdev->acl_cnt = __le16_to_cpu(bs->acl_max_pkt);
-		hdev->sco_pkts = hdev->sco_cnt = __le16_to_cpu(bs->sco_max_pkt);
+		hdev->acl_pkts = __le16_to_cpu(bs->acl_max_pkt);
+		hdev->sco_pkts = __le16_to_cpu(bs->sco_max_pkt);
+
+		if (hdev->quirk_read_buffer_size)
+			hdev->quirk_read_buffer_size(hdev);
+
+		if (!hdev->acl_mtu || !hdev->sco_mtu || !hdev->acl_pkts || !hdev->sco_pkts) {
+			printk (KERN_WARNING "Your Bluetooth adapter has an incorrect OCF_READ_BUFFER_SIZE reply (%d:%d, %d:%d)\n",
+				hdev->acl_mtu, hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
+			printk (KERN_WARNING "It won't work correctly.  Please contact Marcel Holtmann <[email protected]> with information about your device to try workarounds.\n");
+		}
+				
+		hdev->acl_cnt = hdev->acl_pkts;
+		hdev->sco_cnt = hdev->sco_pkts;
 
 		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
 			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);
Signature · 1 line
1.3.0.rc1.g40e9
#1 lore raw

Re: [PATCH] Fix SCO on some bluetooth adapters (Success report for Belkin F8T012)

Quoted 22 lines · Olivier Galibert

Some bluetooth adapters return an incorrect number of sco packets in READ_BUFFER_SIZE. Add a quirk hook to fix it from the driver side, and use the hook for a first adapter.

---

I tried to take Marcel Holtmann's remarks into account, but he seems unavailable to tell me whether he likes that version, so I'll send it to the whole shebang instead of just him this time.

The main point was "only the driver knows how to fix the problem", hence a function pointer quirk hook. This is definitively not limited to broadcom USB devices, googling for "SCO MTU 64:0" has interesting results.

Pavel, '4' doesn't seem to be a value that happens in any correctly answering adapter, while 8 happens often. Try "SCO MTU 64:4" and "SCO MTU 64:8" for comparison.

Quoted 7 lines
 drivers/bluetooth/hci_usb.c      |   12 ++++++++++++
 drivers/bluetooth/hci_usb.h      |    1 +
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_event.c        |   16 ++++++++++++++--
 4 files changed, 28 insertions(+), 2 deletions(-)

841d7690e75189803907fbc4616b984087e7f89c

Replying to an old email about a patch that hasn't made it yet (at least to 2.6.17.3).

Without this patch I can't use my Belkin F8T012 with the bluetooth alsa sound driver (snd-bt-sco)

with it, I can :)

Thanks Olivier.

Is this likely to be merged?

David

PS, I tried the patch here:
http://bluetooth-alsa.sourceforge.net/sco-mtu.patch
that is mentioned here:
http://bluetooth-alsa.sourceforge.net/
but it doesn't work for me.

#2 lore raw

Re: [PATCH] Fix SCO on some bluetooth adapters (Success report for Belkin F8T012)

Quoted 16 lines · On Sat, 01 Jul 2006 13:22:41 +0100 David Greaves <[email protected]> wrote:
Quoted 5 lines

Pavel, '4' doesn't seem to be a value that happens in any correctly answering adapter, while 8 happens often. Try "SCO MTU 64:4" and "SCO MTU 64:8" for comparison.

Quoted 7 lines
 drivers/bluetooth/hci_usb.c      |   12 ++++++++++++
 drivers/bluetooth/hci_usb.h      |    1 +
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_event.c        |   16 ++++++++++++++--
 4 files changed, 28 insertions(+), 2 deletions(-)

841d7690e75189803907fbc4616b984087e7f89c

Replying to an old email about a patch that hasn't made it yet (at least to 2.6.17.3).

Quoted 8 lines

Without this patch I can't use my Belkin F8T012 with the bluetooth alsa sound driver (snd-bt-sco)

with it, I can :)

Thanks Olivier.

Is this likely to be merged?

It's floating around in -mm still. I resend it to various people when I feel like provoking a fight.

Marcel is working on a better way of fixing this problem.

But it's a teeny patch and `patch -R' is easy. If this patch doesn't break anything, perhaps we should temp-merge it?

From: Olivier Galibert <[email protected]>

Some bluetooth adapters return an incorrect number of sco packets in READ_BUFFER_SIZE. Fix it.

This is the worst possible way to fix it for several reasons:
- this is not a generic fix, it has to me activated explicitely by the driver

- this is not a driver-specific fix either, only one action is possible (change to 8), the driver can only enable it

- this is not a wildcard-able fix, because it overwrites the returned value no matter what, i.e. even when it is correct. So drivers without device id which need it, for instance uart, can't use it.

- there is no warning anywhere when the problematic condition is detected, so users of non-listed buggy hardware have no clue about what is going on, and the list of buggy hardware will be very hard to complete

- the fix is inconsistant with the sco_mtu handling

But that's exactly what Marcel Holtmann wants, so that's what he gets.

Cc Pavel Machek <[email protected]>
Cc Marcel Holtmann <[email protected]>
Cc Greg KH <[email protected]>

[akpm: this is permanacked, but will keep getting sent until the problem is fixed for real]

---

 drivers/bluetooth/hci_usb.c |    6 ++++++
 drivers/bluetooth/hci_usb.h |    1 +
 include/net/bluetooth/hci.h |    3 ++-
 net/bluetooth/hci_event.c   |   10 ++++++++--
 4 files changed, 17 insertions(+), 3 deletions(-)
drivers/bluetooth/hci_usb.c renamed from drivers/bluetooth/hci_usb.c~fix-sco-on-some-bluetooth-adapters-2 +6 -0
diff -puN drivers/bluetooth/hci_usb.c~fix-sco-on-some-bluetooth-adapters-2 drivers/bluetooth/hci_usb.c
@@ -129,6 +129,9 @@ static struct usb_device_id blacklist_id
 	/* CSR BlueCore Bluetooth Sniffer */
 	{ USB_DEVICE(0x0a12, 0x0002), .driver_info = HCI_SNIFFER },
 
+	/* Belkin F8T012 */
+	{ USB_DEVICE(0x050d, 0x0012), .driver_info = HCI_READ_BUFFER_SIZE },
+
 	{ }	/* Terminating entry */
 };
 
@@ -984,6 +987,9 @@ static int hci_usb_probe(struct usb_inte
 	if (reset || id->driver_info & HCI_RESET)
 		set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
 
+	if (id->driver_info & HCI_READ_BUFFER_SIZE)
+		set_bit(HCI_QUIRK_FIX_SCO_PKTS, &hdev->quirks);
+
 	if (id->driver_info & HCI_SNIFFER) {
 		if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
 			set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
drivers/bluetooth/hci_usb.h renamed from drivers/bluetooth/hci_usb.h~fix-sco-on-some-bluetooth-adapters-2 +1 -0
diff -puN drivers/bluetooth/hci_usb.h~fix-sco-on-some-bluetooth-adapters-2 drivers/bluetooth/hci_usb.h
@@ -35,6 +35,7 @@
 #define HCI_SNIFFER		0x10
 #define HCI_BCM92035		0x20
 #define HCI_BROKEN_ISOC		0x40
+#define HCI_READ_BUFFER_SIZE    0x80
 
 #define HCI_MAX_IFACE_NUM	3
 
include/net/bluetooth/hci.h renamed from include/net/bluetooth/hci.h~fix-sco-on-some-bluetooth-adapters-2 +2 -1
diff -puN include/net/bluetooth/hci.h~fix-sco-on-some-bluetooth-adapters-2 include/net/bluetooth/hci.h
@@ -54,7 +54,8 @@
 /* HCI device quirks */
 enum {
 	HCI_QUIRK_RESET_ON_INIT,
-	HCI_QUIRK_RAW_DEVICE
+	HCI_QUIRK_RAW_DEVICE,
+	HCI_QUIRK_FIX_SCO_PKTS
 };
 
 /* HCI device flags */
net/bluetooth/hci_event.c renamed from net/bluetooth/hci_event.c~fix-sco-on-some-bluetooth-adapters-2 +8 -2
diff -puN net/bluetooth/hci_event.c~fix-sco-on-some-bluetooth-adapters-2 net/bluetooth/hci_event.c
@@ -320,8 +320,14 @@ static void hci_cc_info_param(struct hci
 
 		hdev->acl_mtu  = __le16_to_cpu(bs->acl_mtu);
 		hdev->sco_mtu  = bs->sco_mtu ? bs->sco_mtu : 64;
-		hdev->acl_pkts = hdev->acl_cnt = __le16_to_cpu(bs->acl_max_pkt);
-		hdev->sco_pkts = hdev->sco_cnt = __le16_to_cpu(bs->sco_max_pkt);
+		hdev->acl_pkts = __le16_to_cpu(bs->acl_max_pkt);
+		hdev->sco_pkts = __le16_to_cpu(bs->sco_max_pkt);
+
+		if (test_bit(HCI_QUIRK_FIX_SCO_PKTS, &hdev->quirks))
+			hdev->sco_pkts = 8;
+
+		hdev->acl_cnt = hdev->acl_pkts;
+		hdev->sco_cnt = hdev->sco_pkts;
 
 		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
 			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);

_