Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp187762pxk; Wed, 9 Sep 2020 02:45:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVQHVA3l6U3XIzAnK5s9y6vd0vH1COtMc+UbujrTyX6EuZIANRKVKVLnKHqBa5jBRUtPzJ X-Received: by 2002:a17:906:8c1:: with SMTP id o1mr2912168eje.478.1599644738701; Wed, 09 Sep 2020 02:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599644738; cv=none; d=google.com; s=arc-20160816; b=nuA4WxLSQG0TruXHXOcNTdugDe/FAfxC+6PMVPMUnGWFu8gcctXtLXChO1nf6+07Uv rQurttYJeKRKsNiEuPPtrHf4+cmmUA/jT1GRmjvyTzow46Pl9bu+xX8uSD6OHFmngqfe hwEPdDOqv8QRjdrIr431CwSTVYzRqMFpM8BYw2GHutoA4V940sISWgU9dkRuXZvBeorc st65hIzJF+QvjgF4cITKVeha8Q8wTjkw3vSb6GNVqpioxlMWMBxVH1gGa51wewT4rYyt LdNvRxP+xvbPK/vgIsD6kamcRFIhFuIy2Pot5o1qkb2j+YL2NOHfJOFR7L7yI+GDuPCz 5oug== 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=LM8k8PH144bWX32V81bl75ySx0lFv/PzcP9daHe+hWQ=; b=F2x97IAaJisqDKhGO3U3zmVLQo/Ae+PktY/mgKAjirOXcq9LYBr2h60pX0xAPF1lol gFhQgGR8JPQbDImLzkDu/NQp8hOzaeAmkEgZgQWlBRBESFZX/d7cMeGvGBR9NWvsE2AA HexV2We0ndPTeQg29JYE61mvuGmoiyNcroMT4G88I9+H9ci64atFOOlF4n43iJ6tm8nj aC3icjtvijtcjIfk51RQ0kg64k0HD360+aBk7Agh4Zb75ZFBD83Q1bgH5Y1GvL+W1Y+Y O6TAMqV3gysueC26hIBz1YxCuAAwFoPje7RmusQKWHID8hAkZYjCJh9sEVzrE83pFXN6 urgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JcM5Yd/I"; 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; 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 by16si1160585edb.294.2020.09.09.02.45.13; Wed, 09 Sep 2020 02:45:38 -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=@chromium.org header.s=google header.b="JcM5Yd/I"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730232AbgIIJnZ (ORCPT + 99 others); Wed, 9 Sep 2020 05:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729865AbgIIJmg (ORCPT ); Wed, 9 Sep 2020 05:42:36 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4845C061757 for ; Wed, 9 Sep 2020 02:42:35 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id d6so1658724pfn.9 for ; Wed, 09 Sep 2020 02:42:35 -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=LM8k8PH144bWX32V81bl75ySx0lFv/PzcP9daHe+hWQ=; b=JcM5Yd/IXdWAIh4gsWrVP3HdA6WElnrDWDk5l4ya3I60zj+1HjARAK0+x6mzB0ujBd lX7ywlj0rd48abSwN9kOWF1w2Z1l5yjFya/frkXvJF+D66IK5ywe4hDGhR/nrv8JNi2D wz5Zi/uG2Hh1qKDsvgAPX2UxC+Eb+9O7tuRWE= 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=LM8k8PH144bWX32V81bl75ySx0lFv/PzcP9daHe+hWQ=; b=S+Z8k+gVy4BJ58kkyl7HnerFiz0iGl+P9Zu4Pnp6H8wb9X+eltAGUomefTeIi387GB NvO7fuGjDDROhsMGygURrEiH5hS8wd0B+9BOCwjhIm0Y5k3oJEwR2iNKcFqTRYFyW8AE IImFg8eHo0PsZMn1RxG4c/DGkkbWQA8D08esS8NjzNpx7DZWxDIhejFYOGLDNL7D1G23 ZxgshHYU8sZvBXY0mNh+odsnRTk9b+GnKmAN4Bjm2QcFlzWTFQVugEvXHFc4M9VuFNXj V7ZVm8ndsSLLh3Gx4fuet/HT0/7ds4IjzpnARBryhQaVp6sBaZ0SWAObMyzmE5z3GB7j rImw== X-Gm-Message-State: AOAM533ctMqxxRFN8xB5ez/Ej2ATucPey7TZCgNYWHvnHsM8YUnwn2nh 1OZ6KC5e7IjP+iEdG36O00AqnL74UzGAzRTI X-Received: by 2002:a63:4b47:: with SMTP id k7mr2365937pgl.437.1599644554905; Wed, 09 Sep 2020 02:42:34 -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 a23sm1692275pgv.86.2020.09.09.02.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 02:42:34 -0700 (PDT) From: Joseph Hwang To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com 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 v2 1/2] Bluetooth: btusb: define HCI packet sizes of USB Alts Date: Wed, 9 Sep 2020 17:42:01 +0800 Message-Id: <20200909174129.v2.1.I56de28ec171134cb9f97062e2c304a72822ca38b@changeid> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog In-Reply-To: <20200909094202.3863687-1-josephsih@chromium.org> References: <20200909094202.3863687-1-josephsih@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@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 v2: - 1/2: Used sco_mtu instead of a new sco_pkt_len member in hdev. - 1/2: Do not overwrite hdev->sco_mtu in hci_cc_read_buffer_size if it has been set in the USB interface. - 2/2: Used BT_SNDMTU/BT_RCVMTU instead of creating a new opt name. - 2/2: Used the existing conn->mtu instead of creating a new member in struct sco_pinfo. - 2/2: Noted that the old SCO_OPTIONS in sco_sock_getsockopt_old() would just work as it uses sco_pi(sk)->conn->mtu. drivers/bluetooth/btusb.c | 43 +++++++++++++++++++++++++++++---------- net/bluetooth/hci_event.c | 7 ++++++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index fe80588c7bd3a8..a710233382afff 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -459,6 +459,22 @@ 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) + */ +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 +3975,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 +4047,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 +4092,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 +4103,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..b3e9247fdbcfa1 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -730,7 +730,12 @@ 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; + /* Set sco_mtu only when not yet. + * The sco_mtu would be set in btusb.c + * if the host controller interface is USB. + */ + if (hdev->sco_mtu == 0) + 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.526.ge36021eeef-goog