Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp843561pxk; Wed, 9 Sep 2020 23:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFOvjFbhlhT7lKKM9zXa3cNVYo2+TAq6MR3laYX3kev2SV+QCkyvHyuaVYt9qmLCJ2Ax2i X-Received: by 2002:a17:906:ae50:: with SMTP id lf16mr6242621ejb.343.1599718067127; Wed, 09 Sep 2020 23:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599718067; cv=none; d=google.com; s=arc-20160816; b=noTCSk56UuXo1xHVkekMr3YcMtvM2VJ2o9SJCD+0DVlOzJIw15XFwO9WSzkGdSfWsh 0102VyafPoiD2cYYO1R2jje/5OYciwCC4rpH2A8W/jiwVduGfGKFiYbcQ5YBQN7OKLJZ IRiMASSfgtz2fDtm3eQaIgq8diSOt7xca32++r48+730NunkSKhB90/vSd+0fqQThyh2 ScgsPzB98kmF6vV7GTmcNj1WoQaQqKtB3EQmljhnzg2XWXDHyml/11wbZEnQ6XcLckov irsVI3bM6DqjRu6JNMyqm1+SwafYY3VFcKSCsFTeHG9ET1l0b6i9wa5Yz+UABmD0gG3p Di2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vZWQw2MqezQSjPCg0Dku6/BdcAwBC3dDRSyH4V8pXAg=; b=vBZBAcdwDtqAps+3yqmV4+cAbwdTHaDIBxHCD7VNY57K12mHmdvg+UJhy1vy7u37tl KrxRn0Px6krWX19MNYVqWpsuseN4OtsVUxSJ6SMiHy2Dh18GLj9SEQ+u6eSoh99/tQEd u8eYaQxeWlmpcuRlTqUC9P27/Ww4D0H3n7mkhjoeVX+k6FNHGqEZB+YKpx9OXlLq91w2 mfa+ZDBBNlkSWfV1egSatEtb6jWVaAkQuX3YNDeePs29Henc0PXZO2eEcAsoBizrX7XU G30qm7IhpUl5Z/P9SXACiHRK+9wLUxmOYzbR4wwHK5aa64sH67mgYb+obboOxhjTbJGG 9yeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SQZNXcqU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id of21si1666283ejb.345.2020.09.09.23.07.24; Wed, 09 Sep 2020 23:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@chromium.org header.s=google header.b=SQZNXcqU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbgIJGEa (ORCPT + 99 others); Thu, 10 Sep 2020 02:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbgIJGEP (ORCPT ); Thu, 10 Sep 2020 02:04:15 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A51BAC061573 for ; Wed, 9 Sep 2020 23:04:14 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id kk9so2513971pjb.2 for ; Wed, 09 Sep 2020 23:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vZWQw2MqezQSjPCg0Dku6/BdcAwBC3dDRSyH4V8pXAg=; b=SQZNXcqU0ZuZn0AJkjqfkWCEklXGWMXhKkzRoLq85tYAhNvLeQZSzS+KpCuZ4KpW72 wwTVKXiK5Htjys+hkHZ4/YNhZ+CMji2am9sulpMpqCVjWq14byniLkA0VLeLPIRZJUKi 4m85yH8ncqbDTCRcwW9Wx+9C7mtjIdGEjrx54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vZWQw2MqezQSjPCg0Dku6/BdcAwBC3dDRSyH4V8pXAg=; b=PE458H9ppWw/W8VBbg8ZDSR5NEKWE3UQvr2PpCnFrH51nzhSLvHwzFlh5t5MdcyC3E cC1tumUFkgcvn2hr79xmWmjQmdXFOuX8s+lA1e/NdIvIbkmU6SicxDuUDooRbRzN/Whb rbCAN7sn/vnmubefo1gP7PUBgcsZCimGsOK0tBSxqCE5+m0sUEzm9PYFCbsyNzTZiItE WCXmF9gclv/SW6CNKO77wohGwcYM2ngd+iSZw0Sdym0B4WkgwC0ge7av5d0uAOx9Jm0k nkE38HaCCBXwyZCeiw/pH1RYx2vRbmw5hokkFpRrYi4uqQWEQlg7YjzUi2JvD76n6bzG g4IA== X-Gm-Message-State: AOAM532NKCK5Fy87vboGscSIxBdtC5vb2PCVSr4BhO3I7VITiDvGdJht XEIiXZJSprKY3aR8eJrfTwtVvw== X-Received: by 2002:a17:90b:3105:: with SMTP id gc5mr3924629pjb.225.1599717854210; Wed, 09 Sep 2020 23:04:14 -0700 (PDT) Received: from josephsih-z840.tpe.corp.google.com ([2401:fa00:1:10:de4a:3eff:fe7d:ff5f]) by smtp.gmail.com with ESMTPSA id j14sm893236pjz.21.2020.09.09.23.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 23:04:13 -0700 (PDT) From: Joseph Hwang To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com, pali@kernel.org Cc: chromeos-bluetooth-upstreaming@chromium.org, josephsih@google.com, Joseph Hwang , Alain Michaud , Abhishek Pandit-Subedi , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 1/2] Bluetooth: btusb: define HCI packet sizes of USB Alts Date: Thu, 10 Sep 2020 14:04:01 +0800 Message-Id: <20200910140342.v3.1.I56de28ec171134cb9f97062e2c304a72822ca38b@changeid> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200910060403.144524-1-josephsih@chromium.org> References: <20200910060403.144524-1-josephsih@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is desirable to define the HCI packet payload sizes of USB alternate settings so that they can be exposed to user space. Reviewed-by: Alain Michaud Reviewed-by: Abhishek Pandit-Subedi Signed-off-by: Joseph Hwang --- Changes in v3: - Set hdev->sco_mtu to rp->sco_mtu if the latter is smaller. Changes in v2: - Used sco_mtu instead of a new sco_pkt_len member in hdev. - Do not overwrite hdev->sco_mtu in hci_cc_read_buffer_size if it has been set in the USB interface. drivers/bluetooth/btusb.c | 45 +++++++++++++++++++++++++++++---------- net/bluetooth/hci_event.c | 14 +++++++++++- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index fe80588c7bd3a8..651d5731a6c6cf 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -459,6 +459,24 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = { #define BTUSB_WAKEUP_DISABLE 14 #define BTUSB_USE_ALT1_FOR_WBS 15 +/* Per core spec 5, vol 4, part B, table 2.1, + * list the hci packet payload sizes for various ALT settings. + * This is used to set the packet length for the wideband speech. + * If a controller does not probe its usb alt setting, the default + * value will be 0. Any clients at upper layers should interpret it + * as a default value and set a proper packet length accordingly. + * + * To calculate the HCI packet payload length: + * for alternate settings 1 - 5: + * hci_packet_size = suggested_max_packet_size * 3 (packets) - + * 3 (HCI header octets) + * for alternate setting 6: + * hci_packet_size = suggested_max_packet_size - 3 (HCI header octets) + * where suggested_max_packet_size is {9, 17, 25, 33, 49, 63} + * for alt settings 1 - 6. + */ +static const int hci_packet_size_usb_alt[] = { 0, 24, 48, 72, 96, 144, 60 }; + struct btusb_data { struct hci_dev *hdev; struct usb_device *udev; @@ -3959,6 +3977,15 @@ static int btusb_probe(struct usb_interface *intf, hdev->notify = btusb_notify; hdev->prevent_wake = btusb_prevent_wake; + if (id->driver_info & BTUSB_AMP) { + /* AMP controllers do not support SCO packets */ + data->isoc = NULL; + } else { + /* Interface orders are hardcoded in the specification */ + data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); + data->isoc_ifnum = ifnum_base + 1; + } + #ifdef CONFIG_PM err = btusb_config_oob_wake(hdev); if (err) @@ -4022,6 +4049,10 @@ static int btusb_probe(struct usb_interface *intf, hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; hdev->cmd_timeout = btusb_intel_cmd_timeout; + + if (btusb_find_altsetting(data, 6)) + hdev->sco_mtu = hci_packet_size_usb_alt[6]; + set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); @@ -4063,15 +4094,6 @@ static int btusb_probe(struct usb_interface *intf, btusb_check_needs_reset_resume(intf); } - if (id->driver_info & BTUSB_AMP) { - /* AMP controllers do not support SCO packets */ - data->isoc = NULL; - } else { - /* Interface orders are hardcoded in the specification */ - data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); - data->isoc_ifnum = ifnum_base + 1; - } - if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && (id->driver_info & BTUSB_REALTEK)) { hdev->setup = btrtl_setup_realtek; @@ -4083,9 +4105,10 @@ static int btusb_probe(struct usb_interface *intf, * (DEVICE_REMOTE_WAKEUP) */ set_bit(BTUSB_WAKEUP_DISABLE, &data->flags); - if (btusb_find_altsetting(data, 1)) + if (btusb_find_altsetting(data, 1)) { set_bit(BTUSB_USE_ALT1_FOR_WBS, &data->flags); - else + hdev->sco_mtu = hci_packet_size_usb_alt[1]; + } else bt_dev_err(hdev, "Device does not support ALT setting 1"); } diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 33d8458fdd4adc..1869dc7ebbb5ac 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -730,7 +730,19 @@ static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) return; hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); - hdev->sco_mtu = rp->sco_mtu; + /* If the host controller interface is USB, the hdev->sco_mtu is + * set in btusb.c and is not expected to be larger than the max sco + * buffer size returned from the controller in rp->sco_mtu. + */ + if (hdev->sco_mtu > 0) { + if (rp->sco_mtu < hdev->sco_mtu) { + BT_ERR("sco mtu %d changed to max sco buffer size %d", + hdev->sco_mtu, rp->sco_mtu); + hdev->sco_mtu = rp->sco_mtu; + } + } else { + hdev->sco_mtu = rp->sco_mtu; + } hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); -- 2.28.0.618.gf4bc123cb7-goog