Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1223120pxv; Fri, 23 Jul 2021 03:09:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy18yw25kRB2LP5mi1eV4Wn17w80Vew6OJAAUOaEQpKVj9PQS+0N1Aqj3275qvFAUHH79h9 X-Received: by 2002:a05:6402:3442:: with SMTP id l2mr4774334edc.126.1627034948805; Fri, 23 Jul 2021 03:09:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1627034948; cv=pass; d=google.com; s=arc-20160816; b=mTshU0GQZ1dXxFxwhVuvfQDfHuxM937zVS60+NcHbMgqSfOAxdC8HEGaa/ZI+cipkt tgLKdvXn9Her0pgiSwlUwB80is7kNtAJZlyU2qAKEWm2+zN9VuS5dqj7FJMEtaju3jcN lZKAXvE9XH6owxHcColhGGNPqoBiFBTkhnPnxU780ME8ZnbtqCH7w7kY1G16d+Pcc1GH VnNl/RrTuY2UYyQdmaqD82uFqrjoXiKnf5uDi3pPlrGPMg7wqHlmRwgWjzzhEG+D2aFx Df/OfO0UKNzYjT4apTvyQbFJbGq0v7/E9A+ChKvsu1PNOKEv7KqSsYNriG3duv7pl7sz ZO8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=3uptbWrx95C5QIVUbKOBVRAx/tDvlkqdSapqfCHOWS0=; b=tcSoznB+oy/zPXmMLPZvvHfzIIx4chf9he+/pkVfgHTz+2BzGa3FsaU8eWIDORN/yn ZBTA6yME36qMoVy7JQI4WFjzeiC78vanrt3qOuueiXlRD/JJEDrEuZXtfNLC7ERV1GX2 Q4thArU46OodNgQ4V/R7NuV4pMV/l2jVU3QtiKL9aTq9RNE5hnpGT/hO57Qfa+l5DEHC YMo18+DhGxdGi8ITQfzKXa14TW+i+UwUhe2pB1EP84pEs+vF2M1c0oReazcI0moAxU1F OOnEYJKJ6/K/odXy1MIKBOBPqc7G/xT/kpoEIL0bUQhTmlq1UqVgKa72PFV8t7o2a0u7 CtHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iki.fi header.s=meesny header.b=U+u24RPv; arc=pass (i=1); spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si31624100edc.581.2021.07.23.03.08.29; Fri, 23 Jul 2021 03:09:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=meesny header.b=U+u24RPv; arc=pass (i=1); spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbhGWJ0g (ORCPT + 99 others); Fri, 23 Jul 2021 05:26:36 -0400 Received: from meesny.iki.fi ([195.140.195.201]:50138 "EHLO meesny.iki.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbhGWJ0g (ORCPT ); Fri, 23 Jul 2021 05:26:36 -0400 Received: from [192.168.1.195] (91-152-122-41.elisa-laajakaista.fi [91.152.122.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav@iki.fi) by meesny.iki.fi (Postfix) with ESMTPSA id 4219220050; Fri, 23 Jul 2021 13:07:07 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1627034827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3uptbWrx95C5QIVUbKOBVRAx/tDvlkqdSapqfCHOWS0=; b=U+u24RPvh9CljIlxFC/IKhvjjFZZv2unQdmB+g1nHBQC9SDHxksbUnGbjAmbe4z9Qq+5jF CqrBpmNyQGQDXxTms5A8fL6J2Q5beRKWmi5BFpkxEY18FHUuGgR9JVe582MHH1hGeTg3vs Q+b5VR+eg/XaY8L7afLbHfJjYkXJjYk= Message-ID: Subject: [PATCH v2] Bluetooth: btusb: check conditions before enabling USB ALT 3 for WBS From: Pauli Virtanen To: linux-bluetooth Cc: Joseph Hwang , Hilda Wu , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , =?UTF-8?Q?Micha=C5=82_K=C4=99pie=C5=84?= Date: Fri, 23 Jul 2021 13:07:07 +0300 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.3 (3.40.3-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1627034827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3uptbWrx95C5QIVUbKOBVRAx/tDvlkqdSapqfCHOWS0=; b=ed2pjYjLGmUchORHnTE2ja53QQCj3ke/2dadFuWP42LLwiALLRRjPCFBD0DsWrnrWmXIZ6 5Y8oDSn7q+IC9T3qkef1XgmSqCr5hkJvqihxJgVVd6Ypqh5j6t1ZAywu2Wtgnkueq6YYWO KuX2LPKHa3o4DITVqAYfHAW6vjKf49Y= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1627034827; a=rsa-sha256; cv=none; b=AjfPLTIEkZadv+tNmDnhUtScjVhjbxsZ4ZRwtr2BlqqRhjBwF5gonYqhjGas5djHUSSTar DwTeqUrq01NwTfXUf06SIY/BjAbBETZSI1benYVocGOxuds0rtabvb1P75ZEQ8Jlp4JDf4 E0x90HBCR+TGNqwb02E1Oye+y/RiI4c= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav@iki.fi smtp.mailfrom=pav@iki.fi Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 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