2021-07-16 17:59:30

by Pauli Virtanen

[permalink] [raw]
Subject: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Some USB BT adapters don't satisfy the MTU requirement mentioned in
commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
and have ALT 3 setting that produces no/garbled audio. Check that the MTU
condition is satisfied, and fall back to ALT 1 if not.

Tested with USB adapters (mtu<72, produce sound only with ALT1)
BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3)
RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling ALT6).

Signed-off-by: Pauli Virtanen <[email protected]>
---
drivers/bluetooth/btusb.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index a9855a2dd561..3ee66e415c4d 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -1763,9 +1763,11 @@ static void btusb_work(struct work_struct *work)
/* Because mSBC frames do not need to be aligned to the
* SCO packet boundary. If support the Alt 3, use the
* Alt 3 for HCI payload >= 60 Bytes let air packet
- * data satisfy 60 bytes.
+ * data satisfy 60 bytes. USB Alt 3 support also needs
+ * HFP transparent MTU >= 72 Bytes.
*/
- if (new_alts == 1 && btusb_find_altsetting(data, 3))
+ if (new_alts == 1 && hdev->sco_mtu >= 72 &&
+ btusb_find_altsetting(data, 3))
new_alts = 3;
}

--
2.31.1



2021-07-17 13:36:28

by Joseph Hwang

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

It looks reasonable to check sco_mtu. My suggestion is to use
hci_packet_size_usb_alt[3] instead of the magic number 72.

Thanks,
Joseph


On Sat, Jul 17, 2021 at 1:58 AM Pauli Virtanen <[email protected]> wrote:
>
> Some USB BT adapters don't satisfy the MTU requirement mentioned in
> commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> and have ALT 3 setting that produces no/garbled audio. Check that the MTU
> condition is satisfied, and fall back to ALT 1 if not.
>
> Tested with USB adapters (mtu<72, produce sound only with ALT1)
> BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3)
> RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling ALT6).
>
> Signed-off-by: Pauli Virtanen <[email protected]>
> ---
> drivers/bluetooth/btusb.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index a9855a2dd561..3ee66e415c4d 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -1763,9 +1763,11 @@ static void btusb_work(struct work_struct *work)
> /* Because mSBC frames do not need to be aligned to the
> * SCO packet boundary. If support the Alt 3, use the
> * Alt 3 for HCI payload >= 60 Bytes let air packet
> - * data satisfy 60 bytes.
> + * data satisfy 60 bytes. USB Alt 3 support also needs
> + * HFP transparent MTU >= 72 Bytes.
> */
> - if (new_alts == 1 && btusb_find_altsetting(data, 3))
> + if (new_alts == 1 && hdev->sco_mtu >= 72 &&
> + btusb_find_altsetting(data, 3))
> new_alts = 3;
> }
>
> --
> 2.31.1
>
>


--

Joseph Shyh-In Hwang
Email: [email protected]

2021-07-21 15:42:22

by Pauli Virtanen

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Hi,

la, 2021-07-17 kello 21:34 +0800, Joseph Hwang kirjoitti:
> It looks reasonable to check sco_mtu. My suggestion is to use
> hci_packet_size_usb_alt[3] instead of the magic number 72.

Thanks for looking at it. IIUC, hci_packet_size_usb_alt only appears in
previous discussions on this list, which did not seem to reach a
conclusion if this should be computed from wMaxPacketSize. I can do
less magical v2 and add the table.

Different solution would be to make the altsetting choice
manufacturer/device specific flag, as I'm not sure on what hardware
e848dbd364ac was tested on, so maybe it is intended Realtek specific.

Best,
Pauli


> On Sat, Jul 17, 2021 at 1:58 AM Pauli Virtanen <[email protected]> wrote:
> >
> > Some USB BT adapters don't satisfy the MTU requirement mentioned in
> > commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> > and have ALT 3 setting that produces no/garbled audio. Check that the MTU
> > condition is satisfied, and fall back to ALT 1 if not.
> >
> > Tested with USB adapters (mtu<72, produce sound only with ALT1)
> > BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3)
> > RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling ALT6).
> >
> > Signed-off-by: Pauli Virtanen <[email protected]>
> > ---
> > drivers/bluetooth/btusb.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > index a9855a2dd561..3ee66e415c4d 100644
> > --- a/drivers/bluetooth/btusb.c
> > +++ b/drivers/bluetooth/btusb.c
> > @@ -1763,9 +1763,11 @@ static void btusb_work(struct work_struct *work)
> > /* Because mSBC frames do not need to be aligned to the
> > * SCO packet boundary. If support the Alt 3, use the
> > * Alt 3 for HCI payload >= 60 Bytes let air packet
> > - * data satisfy 60 bytes.
> > + * data satisfy 60 bytes. USB Alt 3 support also needs
> > + * HFP transparent MTU >= 72 Bytes.
> > */
> > - if (new_alts == 1 && btusb_find_altsetting(data, 3))
> > + if (new_alts == 1 && hdev->sco_mtu >= 72 &&
> > + btusb_find_altsetting(data, 3))
> > new_alts = 3;
> > }
> >
> > --
> > 2.31.1
> >
> >
>
>


2021-07-22 10:33:35

by Hilda Wu

[permalink] [raw]
Subject: RE: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Hi,

Thanks for your supplement.
Add the sco_mtu condition is better.

When USB BT adapters support the alternate 3, it will announce alternate 3.
However, USB Alt 3 supported also need HFP support transparent MTU in 72 Bytes.
Add this sco_mtu condition could avoid HFP profile transparent MTU not match or not suitable ALT 3.

Regards,
Hilda

-----Original Message-----
From: Pauli Virtanen <[email protected]>
Sent: Wednesday, July 21, 2021 11:40 PM
To: Joseph Hwang <[email protected]>
Cc: linux-bluetooth <[email protected]>; Hilda Wu <[email protected]>
Subject: Re: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Hi,

la, 2021-07-17 kello 21:34 +0800, Joseph Hwang kirjoitti:
> It looks reasonable to check sco_mtu. My suggestion is to use
> hci_packet_size_usb_alt[3] instead of the magic number 72.

Thanks for looking at it. IIUC, hci_packet_size_usb_alt only appears in previous discussions on this list, which did not seem to reach a conclusion if this should be computed from wMaxPacketSize. I can do less magical v2 and add the table.

Different solution would be to make the altsetting choice manufacturer/device specific flag, as I'm not sure on what hardware e848dbd364ac was tested on, so maybe it is intended Realtek specific.

Best,
Pauli


> On Sat, Jul 17, 2021 at 1:58 AM Pauli Virtanen <[email protected]> wrote:
> >
> > Some USB BT adapters don't satisfy the MTU requirement mentioned in
> > commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for
> > WBS") and have ALT 3 setting that produces no/garbled audio. Check
> > that the MTU condition is satisfied, and fall back to ALT 1 if not.
> >
> > Tested with USB adapters (mtu<72, produce sound only with ALT1)
> > BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3)
> > RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling ALT6).
> >
> > Signed-off-by: Pauli Virtanen <[email protected]>
> > ---
> > drivers/bluetooth/btusb.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > index a9855a2dd561..3ee66e415c4d 100644
> > --- a/drivers/bluetooth/btusb.c
> > +++ b/drivers/bluetooth/btusb.c
> > @@ -1763,9 +1763,11 @@ static void btusb_work(struct work_struct *work)
> > /* Because mSBC frames do not need to be aligned to the
> > * SCO packet boundary. If support the Alt 3, use the
> > * Alt 3 for HCI payload >= 60 Bytes let air packet
> > - * data satisfy 60 bytes.
> > + * data satisfy 60 bytes. USB Alt 3 support also needs
> > + * HFP transparent MTU >= 72 Bytes.
> > */
> > - if (new_alts == 1 && btusb_find_altsetting(data, 3))
> > + if (new_alts == 1 && hdev->sco_mtu >= 72 &&
> > + btusb_find_altsetting(data, 3))
> > new_alts = 3;
> > }
> >
> > --
> > 2.31.1
> >
> >
>
>


------Please consider the environment before printing this e-mail.

2021-07-22 13:32:35

by Michał Kępień

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Hi Pauli,

Thank you for your work on this patch!

> Some USB BT adapters don't satisfy the MTU requirement mentioned in
> commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> and have ALT 3 setting that produces no/garbled audio. Check that the MTU
> condition is satisfied, and fall back to ALT 1 if not.
>
> Tested with USB adapters (mtu<72, produce sound only with ALT1)
> BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3)
> RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling ALT6).

Commit e848dbd364aca44c9d23c04bef964fab79e2b34f causes garbled mSBC
audio on my Bluetooth adapter (8087:0a2b), so I gave your patch a try.

Unfortunately, the patch in its current shape does not seem to be enough
to fix things for this adapter, which reports an SCO MTU of 96 bytes and
produces garbled mSBC audio with ALT 3.

For the record, reverting e848dbd364aca44c9d23c04bef964fab79e2b34f on
top of v5.14-rc2 makes mSBC work again with my adapter.

I am no Bluetooth expert, but I will be happy to perform any additional
debugging and/or testing.

--
Best regards,
Michał Kępień

2021-07-22 14:26:58

by Pauli Virtanen

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Hi Michał,

to, 2021-07-22 kello 15:29 +0200, Michał Kępień kirjoitti:
> Thank you for your work on this patch!
>
> > Some USB BT adapters don't satisfy the MTU requirement mentioned in
> > commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> > and have ALT 3 setting that produces no/garbled audio. Check that the MTU
> > condition is satisfied, and fall back to ALT 1 if not.
> >
> > Tested with USB adapters (mtu<72, produce sound only with ALT1)
> > BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3)
> > RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling ALT6).
>
> Commit e848dbd364aca44c9d23c04bef964fab79e2b34f causes garbled mSBC
> audio on my Bluetooth adapter (8087:0a2b), so I gave your patch a try.
>
> Unfortunately, the patch in its current shape does not seem to be enough
> to fix things for this adapter, which reports an SCO MTU of 96 bytes and
> produces garbled mSBC audio with ALT 3.
>
> For the record, reverting e848dbd364aca44c9d23c04bef964fab79e2b34f on
> top of v5.14-rc2 makes mSBC work again with my adapter.
>
> I am no Bluetooth expert, but I will be happy to perform any additional
> debugging and/or testing.

Thanks for testing! What userspace software did you use? Pulseaudio at
least I think had assumption that mtu <= 60, which breaks here
(Pipewire works, don't know about bluez-alsa). If otherwise, maybe it
then needs also the manufacturer flag.

Best,
Pauli

2021-07-22 14:43:01

by Michał Kępień

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: check SCO MTU before enabling USB ALT 3 for WBS

Pauli,

> Thanks for testing! What userspace software did you use? Pulseaudio at
> least I think had assumption that mtu <= 60, which breaks here
> (Pipewire works, don't know about bluez-alsa). If otherwise, maybe it
> then needs also the manufacturer flag.

I am using Pipewire 0.3.32.

When I wrote "this adapter (...) reports an SCO MTU of 96 bytes" in my
previous message, I meant that this was the value present in
hdev->sco_mtu around the problematic code location. If this was the
wrong thing to take a look at, please let me know.

--
Best regards,
Michał Kępień

2021-07-23 10:09:09

by Pauli Virtanen

[permalink] [raw]
Subject: [PATCH v2] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

Some USB BT adapters don't satisfy the MTU requirement mentioned in
commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
and have ALT 3 setting that produces no/garbled audio. Some adapters
with larger MTU were also reported to have problems with ALT 3.

Add a flag and check it and MTU before selecting ALT 3, falling back to
ALT 1. Enable the flag for Realtek, restoring the previous behavior for
non-Realtek devices.

Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
audio) Intel 8087:0a2b.

Signed-off-by: Pauli Virtanen <[email protected]>
Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
---

Changes in v2:
- Explain magic number 72 in a comment; didn't add the table for them,
because it's not used elsewhere and we need just one number from it.
- Add flag for ALT3 support, restoring the behavior
for non-Realtek devices the same as before e848dbd364ac, due to
the problems reported on an Intel adapter. Don't have the device
myself.

drivers/bluetooth/btusb.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 6d23308119d1..5cec719f6cba 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -516,6 +516,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
#define BTUSB_HW_RESET_ACTIVE 12
#define BTUSB_TX_WAIT_VND_EVT 13
#define BTUSB_WAKEUP_DISABLE 14
+#define BTUSB_ALT3_OK_FOR_WBS 15

struct btusb_data {
struct hci_dev *hdev;
@@ -1748,16 +1749,20 @@ static void btusb_work(struct work_struct *work)
/* Bluetooth USB spec recommends alt 6 (63 bytes), but
* many adapters do not support it. Alt 1 appears to
* work for all adapters that do not have alt 6, and
- * which work with WBS at all.
+ * which work with WBS at all. Some devices prefer
+ * alt 3 (HCI payload >= 60 Bytes let air packet
+ * data satisfy 60 bytes), requiring
+ * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
+ * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
*/
- new_alts = btusb_find_altsetting(data, 6) ? 6 : 1;
- /* Because mSBC frames do not need to be aligned to the
- * SCO packet boundary. If support the Alt 3, use the
- * Alt 3 for HCI payload >= 60 Bytes let air packet
- * data satisfy 60 bytes.
- */
- if (new_alts == 1 && btusb_find_altsetting(data, 3))
+ if (btusb_find_altsetting(data, 6))
+ new_alts = 6;
+ else if (test_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags) &&
+ hdev->sco_mtu >= 72 &&
+ btusb_find_altsetting(data, 3))
new_alts = 3;
+ else
+ new_alts = 1;
}

if (btusb_switch_alt_setting(hdev, new_alts) < 0)
@@ -4733,6 +4738,7 @@ static int btusb_probe(struct usb_interface *intf,
* (DEVICE_REMOTE_WAKEUP)
*/
set_bit(BTUSB_WAKEUP_DISABLE, &data->flags);
+ set_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags);
}

if (!reset)
--
2.31.1



2021-07-23 12:19:56

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

Hi Pauli,

> Some USB BT adapters don't satisfy the MTU requirement mentioned in
> commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> and have ALT 3 setting that produces no/garbled audio. Some adapters
> with larger MTU were also reported to have problems with ALT 3.
>
> Add a flag and check it and MTU before selecting ALT 3, falling back to
> ALT 1. Enable the flag for Realtek, restoring the previous behavior for
> non-Realtek devices.
>
> Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
> works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
> works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
> ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
> audio) Intel 8087:0a2b.
>
> Signed-off-by: Pauli Virtanen <[email protected]>
> Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")

before I will apply this, I need Tested-by or Ack-by people that confirm that this fixes their issues now.

> ---
>
> Changes in v2:
> - Explain magic number 72 in a comment; didn't add the table for them,
> because it's not used elsewhere and we need just one number from it.
> - Add flag for ALT3 support, restoring the behavior
> for non-Realtek devices the same as before e848dbd364ac, due to
> the problems reported on an Intel adapter. Don't have the device
> myself.
>
> drivers/bluetooth/btusb.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 6d23308119d1..5cec719f6cba 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -516,6 +516,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
> #define BTUSB_HW_RESET_ACTIVE 12
> #define BTUSB_TX_WAIT_VND_EVT 13
> #define BTUSB_WAKEUP_DISABLE 14
> +#define BTUSB_ALT3_OK_FOR_WBS 15

Rename this to BTUSB_USE_ALT3_FOR_WBS.

>
> struct btusb_data {
> struct hci_dev *hdev;
> @@ -1748,16 +1749,20 @@ static void btusb_work(struct work_struct *work)
> /* Bluetooth USB spec recommends alt 6 (63 bytes), but
> * many adapters do not support it. Alt 1 appears to
> * work for all adapters that do not have alt 6, and
> - * which work with WBS at all.
> + * which work with WBS at all. Some devices prefer
> + * alt 3 (HCI payload >= 60 Bytes let air packet
> + * data satisfy 60 bytes), requiring
> + * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
> + * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
> */
> - new_alts = btusb_find_altsetting(data, 6) ? 6 : 1;
> - /* Because mSBC frames do not need to be aligned to the
> - * SCO packet boundary. If support the Alt 3, use the
> - * Alt 3 for HCI payload >= 60 Bytes let air packet
> - * data satisfy 60 bytes.
> - */
> - if (new_alts == 1 && btusb_find_altsetting(data, 3))
> + if (btusb_find_altsetting(data, 6))
> + new_alts = 6;
> + else if (test_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags) &&
> + hdev->sco_mtu >= 72 &&
> + btusb_find_altsetting(data, 3))

This is whitespace damaged.

> new_alts = 3;
> + else
> + new_alts = 1;
> }
>
> if (btusb_switch_alt_setting(hdev, new_alts) < 0)
> @@ -4733,6 +4738,7 @@ static int btusb_probe(struct usb_interface *intf,
> * (DEVICE_REMOTE_WAKEUP)
> */
> set_bit(BTUSB_WAKEUP_DISABLE, &data->flags);
> + set_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags);
> }

Regards

Marcel

2021-07-25 05:49:45

by Michał Kępień

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

> > Some USB BT adapters don't satisfy the MTU requirement mentioned in
> > commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> > and have ALT 3 setting that produces no/garbled audio. Some adapters
> > with larger MTU were also reported to have problems with ALT 3.
> >
> > Add a flag and check it and MTU before selecting ALT 3, falling back to
> > ALT 1. Enable the flag for Realtek, restoring the previous behavior for
> > non-Realtek devices.
> >
> > Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
> > works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
> > works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
> > ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
> > audio) Intel 8087:0a2b.
> >
> > Signed-off-by: Pauli Virtanen <[email protected]>
> > Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
>
> before I will apply this, I need Tested-by or Ack-by people that confirm that this fixes their issues now.

For 8087:0a2b (with broken mSBC audio since e848dbd364ac):

Tested-by: Michał Kępień <[email protected]>

It would be nice to get this into the stable tree as e848dbd364ac got
there in v5.13.3 (as 15407b14e27b) and v5.10.51 (as 05298f1733c6).

Thanks!

--
Best regards,
Michał Kępień

2021-07-26 18:07:49

by Pauli Virtanen

[permalink] [raw]
Subject: [PATCH v3] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

Some USB BT adapters don't satisfy the MTU requirement mentioned in
commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
and have ALT 3 setting that produces no/garbled audio. Some adapters
with larger MTU were also reported to have problems with ALT 3.

Add a flag and check it and MTU before selecting ALT 3, falling back to
ALT 1. Enable the flag for Realtek, restoring the previous behavior for
non-Realtek devices.

Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
audio) Intel 8087:0a2b.

Signed-off-by: Pauli Virtanen <[email protected]>
Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
Tested-by: Michał Kępień <[email protected]>
---

Changes in v3:
- Rename flag to BTUSB_USE_ALT3_FOR_WBS.
- No spaces in indent.
- Added Tested-by: Michał Kępień

Changes in v2:
- Explain magic number 72 in a comment; didn't add the table for them,
because it's not used elsewhere and we need just one number from it.
- Add flag for ALT3 support, restoring the behavior
for non-Realtek devices the same as before e848dbd364ac, due to
the problems reported on an Intel adapter. Don't have the device
myself.

drivers/bluetooth/btusb.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 6d23308119d1..e8062d0b7d4d 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -516,6 +516,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
#define BTUSB_HW_RESET_ACTIVE 12
#define BTUSB_TX_WAIT_VND_EVT 13
#define BTUSB_WAKEUP_DISABLE 14
+#define BTUSB_USE_ALT3_FOR_WBS 15

struct btusb_data {
struct hci_dev *hdev;
@@ -1748,16 +1749,20 @@ static void btusb_work(struct work_struct *work)
/* Bluetooth USB spec recommends alt 6 (63 bytes), but
* many adapters do not support it. Alt 1 appears to
* work for all adapters that do not have alt 6, and
- * which work with WBS at all.
+ * which work with WBS at all. Some devices prefer
+ * alt 3 (HCI payload >= 60 Bytes let air packet
+ * data satisfy 60 bytes), requiring
+ * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
+ * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
*/
- new_alts = btusb_find_altsetting(data, 6) ? 6 : 1;
- /* Because mSBC frames do not need to be aligned to the
- * SCO packet boundary. If support the Alt 3, use the
- * Alt 3 for HCI payload >= 60 Bytes let air packet
- * data satisfy 60 bytes.
- */
- if (new_alts == 1 && btusb_find_altsetting(data, 3))
+ if (btusb_find_altsetting(data, 6))
+ new_alts = 6;
+ else if (test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags) &&
+ hdev->sco_mtu >= 72 &&
+ btusb_find_altsetting(data, 3))
new_alts = 3;
+ else
+ new_alts = 1;
}

if (btusb_switch_alt_setting(hdev, new_alts) < 0)
@@ -4733,6 +4738,7 @@ static int btusb_probe(struct usb_interface *intf,
* (DEVICE_REMOTE_WAKEUP)
*/
set_bit(BTUSB_WAKEUP_DISABLE, &data->flags);
+ set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags);
}

if (!reset)
--
2.31.1

2021-07-27 02:12:53

by bluez.test.bot

[permalink] [raw]
Subject: RE: [v3] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=521451

---Test result---

Test Summary:
CheckPatch FAIL 0.51 seconds
GitLint PASS 0.11 seconds
BuildKernel PASS 553.49 seconds
TestRunner: Setup PASS 361.85 seconds
TestRunner: l2cap-tester PASS 2.61 seconds
TestRunner: bnep-tester PASS 2.01 seconds
TestRunner: mgmt-tester PASS 31.71 seconds
TestRunner: rfcomm-tester PASS 2.19 seconds
TestRunner: sco-tester PASS 2.16 seconds
TestRunner: smp-tester FAIL 2.18 seconds
TestRunner: userchan-tester PASS 2.01 seconds

Details
##############################
Test: CheckPatch - FAIL - 0.51 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS
WARNING: Unknown commit id 'e848dbd364ac', maybe rebased or not pulled?
#11:
commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")

total: 0 errors, 1 warnings, 42 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] Bluetooth: btusb: check conditions before enabling USB ALT 3" has style problems, please review.

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - PASS - 0.11 seconds
Run gitlint with rule in .gitlint


##############################
Test: BuildKernel - PASS - 553.49 seconds
Build Kernel with minimal configuration supports Bluetooth


##############################
Test: TestRunner: Setup - PASS - 361.85 seconds
Setup environment for running Test Runner


##############################
Test: TestRunner: l2cap-tester - PASS - 2.61 seconds
Run test-runner with l2cap-tester
Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: bnep-tester - PASS - 2.01 seconds
Run test-runner with bnep-tester
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: mgmt-tester - PASS - 31.71 seconds
Run test-runner with mgmt-tester
Total: 448, Passed: 445 (99.3%), Failed: 0, Not Run: 3

##############################
Test: TestRunner: rfcomm-tester - PASS - 2.19 seconds
Run test-runner with rfcomm-tester
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: sco-tester - PASS - 2.16 seconds
Run test-runner with sco-tester
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: smp-tester - FAIL - 2.18 seconds
Run test-runner with smp-tester
Total: 8, Passed: 7 (87.5%), Failed: 1, Not Run: 0

Failed Test Cases
SMP Client - SC Request 2 Failed 0.023 seconds

##############################
Test: TestRunner: userchan-tester - PASS - 2.01 seconds
Run test-runner with userchan-tester
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth


Attachments:
l2cap-tester.log (43.35 kB)
bnep-tester.log (3.51 kB)
mgmt-tester.log (602.43 kB)
rfcomm-tester.log (11.44 kB)
sco-tester.log (9.71 kB)
smp-tester.log (11.47 kB)
userchan-tester.log (5.36 kB)
Download all attachments

2021-07-30 12:36:43

by Pasi Kärkkäinen

[permalink] [raw]
Subject: Re: [PATCH v3] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

Hi,

On Mon, Jul 26, 2021 at 09:02:06PM +0300, Pauli Virtanen wrote:
> Some USB BT adapters don't satisfy the MTU requirement mentioned in
> commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> and have ALT 3 setting that produces no/garbled audio. Some adapters
> with larger MTU were also reported to have problems with ALT 3.
>
> Add a flag and check it and MTU before selecting ALT 3, falling back to
> ALT 1. Enable the flag for Realtek, restoring the previous behavior for
> non-Realtek devices.
>
> Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
> works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
> works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
> ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
> audio) Intel 8087:0a2b.
>
> Signed-off-by: Pauli Virtanen <[email protected]>
> Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> Tested-by: Michał Kępień <[email protected]>
> ---
>

This probably also should have CC [email protected], as users have
started reporting this bug as distros have started shipping kernels with
the faulty patch in it.. so it'd be nice to have the fix backported to
stable kernel trees.


Thanks,

-- Pasi

>
> Changes in v3:
> - Rename flag to BTUSB_USE_ALT3_FOR_WBS.
> - No spaces in indent.
> - Added Tested-by: Michał Kępień
>
> Changes in v2:
> - Explain magic number 72 in a comment; didn't add the table for them,
> because it's not used elsewhere and we need just one number from it.
> - Add flag for ALT3 support, restoring the behavior
> for non-Realtek devices the same as before e848dbd364ac, due to
> the problems reported on an Intel adapter. Don't have the device
> myself.
>

2021-08-10 16:50:02

by Pasi Kärkkäinen

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

Hello Marcel,

On Fri, Jul 23, 2021 at 02:19:09PM +0200, Marcel Holtmann wrote:
> Hi Pauli,
>
> > Some USB BT adapters don't satisfy the MTU requirement mentioned in
> > commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> > and have ALT 3 setting that produces no/garbled audio. Some adapters
> > with larger MTU were also reported to have problems with ALT 3.
> >
> > Add a flag and check it and MTU before selecting ALT 3, falling back to
> > ALT 1. Enable the flag for Realtek, restoring the previous behavior for
> > non-Realtek devices.
> >
> > Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
> > works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
> > works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
> > ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
> > audio) Intel 8087:0a2b.
> >
> > Signed-off-by: Pauli Virtanen <[email protected]>
> > Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
>
> before I will apply this, I need Tested-by or Ack-by people that confirm that this fixes their issues now.
>

Is v3 ok/enough? It has one Tested-by.
It would probably be good to send v4 anyway with CC [email protected] ..


Thanks,

-- Pasi

>
> > ---
> >
> > Changes in v2:
> > - Explain magic number 72 in a comment; didn't add the table for them,
> > because it's not used elsewhere and we need just one number from it.
> > - Add flag for ALT3 support, restoring the behavior
> > for non-Realtek devices the same as before e848dbd364ac, due to
> > the problems reported on an Intel adapter. Don't have the device
> > myself.
> >
> > drivers/bluetooth/btusb.c | 22 ++++++++++++++--------
> > 1 file changed, 14 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > index 6d23308119d1..5cec719f6cba 100644
> > --- a/drivers/bluetooth/btusb.c
> > +++ b/drivers/bluetooth/btusb.c
> > @@ -516,6 +516,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
> > #define BTUSB_HW_RESET_ACTIVE 12
> > #define BTUSB_TX_WAIT_VND_EVT 13
> > #define BTUSB_WAKEUP_DISABLE 14
> > +#define BTUSB_ALT3_OK_FOR_WBS 15
>
> Rename this to BTUSB_USE_ALT3_FOR_WBS.
>
> >
> > struct btusb_data {
> > struct hci_dev *hdev;
> > @@ -1748,16 +1749,20 @@ static void btusb_work(struct work_struct *work)
> > /* Bluetooth USB spec recommends alt 6 (63 bytes), but
> > * many adapters do not support it. Alt 1 appears to
> > * work for all adapters that do not have alt 6, and
> > - * which work with WBS at all.
> > + * which work with WBS at all. Some devices prefer
> > + * alt 3 (HCI payload >= 60 Bytes let air packet
> > + * data satisfy 60 bytes), requiring
> > + * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
> > + * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
> > */
> > - new_alts = btusb_find_altsetting(data, 6) ? 6 : 1;
> > - /* Because mSBC frames do not need to be aligned to the
> > - * SCO packet boundary. If support the Alt 3, use the
> > - * Alt 3 for HCI payload >= 60 Bytes let air packet
> > - * data satisfy 60 bytes.
> > - */
> > - if (new_alts == 1 && btusb_find_altsetting(data, 3))
> > + if (btusb_find_altsetting(data, 6))
> > + new_alts = 6;
> > + else if (test_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags) &&
> > + hdev->sco_mtu >= 72 &&
> > + btusb_find_altsetting(data, 3))
>
> This is whitespace damaged.
>
> > new_alts = 3;
> > + else
> > + new_alts = 1;
> > }
> >
> > if (btusb_switch_alt_setting(hdev, new_alts) < 0)
> > @@ -4733,6 +4738,7 @@ static int btusb_probe(struct usb_interface *intf,
> > * (DEVICE_REMOTE_WAKEUP)
> > */
> > set_bit(BTUSB_WAKEUP_DISABLE, &data->flags);
> > + set_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags);
> > }
>
> Regards
>
> Marcel
>

2021-08-10 18:39:06

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS

Hi Pasi, Pauli,

On Tue, Aug 10, 2021 at 9:50 AM Pasi Kärkkäinen <[email protected]> wrote:
>
> Hello Marcel,
>
> On Fri, Jul 23, 2021 at 02:19:09PM +0200, Marcel Holtmann wrote:
> > Hi Pauli,
> >
> > > Some USB BT adapters don't satisfy the MTU requirement mentioned in
> > > commit e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> > > and have ALT 3 setting that produces no/garbled audio. Some adapters
> > > with larger MTU were also reported to have problems with ALT 3.
> > >
> > > Add a flag and check it and MTU before selecting ALT 3, falling back to
> > > ALT 1. Enable the flag for Realtek, restoring the previous behavior for
> > > non-Realtek devices.
> > >
> > > Tested with USB adapters (mtu<72, no/garbled sound with ALT3, ALT1
> > > works) BCM20702A1 0b05:17cb, CSR8510A10 0a12:0001, and (mtu>=72, ALT3
> > > works) RTL8761BU 0bda:8771, Intel AX200 8087:0029 (after disabling
> > > ALT6). Also got reports for (mtu>=72, ALT 3 reported to produce bad
> > > audio) Intel 8087:0a2b.
> > >
> > > Signed-off-by: Pauli Virtanen <[email protected]>
> > > Fixes: e848dbd364ac ("Bluetooth: btusb: Add support USB ALT 3 for WBS")
> >
> > before I will apply this, I need Tested-by or Ack-by people that confirm that this fixes their issues now.
> >
>
> Is v3 ok/enough? It has one Tested-by.
> It would probably be good to send v4 anyway with CC [email protected] ..
>
>
> Thanks,
>
> -- Pasi
>
> >
> > > ---
> > >
> > > Changes in v2:
> > > - Explain magic number 72 in a comment; didn't add the table for them,
> > > because it's not used elsewhere and we need just one number from it.
> > > - Add flag for ALT3 support, restoring the behavior
> > > for non-Realtek devices the same as before e848dbd364ac, due to
> > > the problems reported on an Intel adapter. Don't have the device
> > > myself.
> > >
> > > drivers/bluetooth/btusb.c | 22 ++++++++++++++--------
> > > 1 file changed, 14 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > > index 6d23308119d1..5cec719f6cba 100644
> > > --- a/drivers/bluetooth/btusb.c
> > > +++ b/drivers/bluetooth/btusb.c
> > > @@ -516,6 +516,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
> > > #define BTUSB_HW_RESET_ACTIVE 12
> > > #define BTUSB_TX_WAIT_VND_EVT 13
> > > #define BTUSB_WAKEUP_DISABLE 14
> > > +#define BTUSB_ALT3_OK_FOR_WBS 15
> >
> > Rename this to BTUSB_USE_ALT3_FOR_WBS.
> >
> > >
> > > struct btusb_data {
> > > struct hci_dev *hdev;
> > > @@ -1748,16 +1749,20 @@ static void btusb_work(struct work_struct *work)
> > > /* Bluetooth USB spec recommends alt 6 (63 bytes), but
> > > * many adapters do not support it. Alt 1 appears to
> > > * work for all adapters that do not have alt 6, and
> > > - * which work with WBS at all.
> > > + * which work with WBS at all. Some devices prefer
> > > + * alt 3 (HCI payload >= 60 Bytes let air packet
> > > + * data satisfy 60 bytes), requiring
> > > + * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
> > > + * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
> > > */
> > > - new_alts = btusb_find_altsetting(data, 6) ? 6 : 1;
> > > - /* Because mSBC frames do not need to be aligned to the
> > > - * SCO packet boundary. If support the Alt 3, use the
> > > - * Alt 3 for HCI payload >= 60 Bytes let air packet
> > > - * data satisfy 60 bytes.
> > > - */
> > > - if (new_alts == 1 && btusb_find_altsetting(data, 3))
> > > + if (btusb_find_altsetting(data, 6))
> > > + new_alts = 6;
> > > + else if (test_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags) &&
> > > + hdev->sco_mtu >= 72 &&
> > > + btusb_find_altsetting(data, 3))
> >
> > This is whitespace damaged.

Ive fixed this and made it fit in 80 columns by reordering the checks.

> >
> > > new_alts = 3;
> > > + else
> > > + new_alts = 1;
> > > }
> > >
> > > if (btusb_switch_alt_setting(hdev, new_alts) < 0)
> > > @@ -4733,6 +4738,7 @@ static int btusb_probe(struct usb_interface *intf,
> > > * (DEVICE_REMOTE_WAKEUP)
> > > */
> > > set_bit(BTUSB_WAKEUP_DISABLE, &data->flags);
> > > + set_bit(BTUSB_ALT3_OK_FOR_WBS, &data->flags);
> > > }
> >
> > Regards
> >
> > Marcel

Applied, thanks.


--
Luiz Augusto von Dentz