From patchwork Fri Oct 8 14:07:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A686C433EF for ; Fri, 8 Oct 2021 14:03:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E656561042 for ; Fri, 8 Oct 2021 14:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234008AbhJHOFG (ORCPT ); Fri, 8 Oct 2021 10:05:06 -0400 Received: from mga04.intel.com ([192.55.52.120]:22400 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232821AbhJHOFF (ORCPT ); Fri, 8 Oct 2021 10:05:05 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="225286231" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="225286231" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:02:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715520988" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:02:42 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 1/7] Bluetooth: Refactor code to read supported codecs in getsockopt Date: Fri, 8 Oct 2021 19:37:53 +0530 Message-Id: <20211008140759.15493-1-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch moves reading of supported codecs from cache to a new function to reuse over L2CAP sockets to be used in a2dp offload use case. Signed-off-by: Kiran K --- net/bluetooth/hci_codec.c | 88 +++++++++++++++++++++++++++++++++++ net/bluetooth/hci_codec.h | 2 + net/bluetooth/sco.c | 98 +++------------------------------------ 3 files changed, 96 insertions(+), 92 deletions(-) diff --git a/net/bluetooth/hci_codec.c b/net/bluetooth/hci_codec.c index 38201532f58e..f4d8d3a253d8 100644 --- a/net/bluetooth/hci_codec.c +++ b/net/bluetooth/hci_codec.c @@ -250,3 +250,91 @@ void hci_read_supported_codecs_v2(struct hci_dev *hdev) error: kfree_skb(skb); } + +int hci_get_supported_codecs(struct hci_dev *hdev, u8 type, char __user *optval, + int __user *optlen, int len) +{ + int n = 0, buf_len = 0, err = 0; + struct hci_codec_caps *caps; + struct bt_codec codec; + u8 num_codecs = 0, i, __user *ptr; + struct codec_list *c; + + if (!hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) { + err = -EOPNOTSUPP; + goto error; + } + + if (!hdev->get_data_path_id) { + err = -EOPNOTSUPP; + goto error; + } + + /* find total buffer size required to copy codec + capabilities */ + hci_dev_lock(hdev); + list_for_each_entry(c, &hdev->local_codecs, list) { + if (c->transport != type) + continue; + num_codecs++; + for (i = 0, caps = c->caps; i < c->num_caps; i++) { + buf_len += 1 + caps->len; + caps = (void *)&caps->data[caps->len]; + } + buf_len += sizeof(struct bt_codec); + } + hci_dev_unlock(hdev); + + buf_len += sizeof(struct bt_codecs); + if (buf_len > len) { + err = -ENOBUFS; + goto error; + } + ptr = optval; + + if (put_user(num_codecs, ptr)) { + err = -EFAULT; + goto error; + } + ptr += sizeof(num_codecs); + + /* Iterate over all the codecs on required transport */ + hci_dev_lock(hdev); + list_for_each_entry(c, &hdev->local_codecs, list) { + if (c->transport != type) + continue; + + codec.id = c->id; + codec.cid = c->cid; + codec.vid = c->vid; + err = hdev->get_data_path_id(hdev, &codec.data_path); + if (err < 0) + break; + codec.num_caps = c->num_caps; + if (copy_to_user(ptr, &codec, sizeof(codec))) { + err = -EFAULT; + break; + } + ptr += sizeof(codec); + + /* find codec capabilities data length */ + n = 0; + for (i = 0, caps = c->caps; i < c->num_caps; i++) { + n += 1 + caps->len; + caps = (void *)&caps->data[caps->len]; + } + + /* copy codec capabilities data */ + if (n && copy_to_user(ptr, c->caps, n)) { + err = -EFAULT; + break; + } + ptr += n; + } + hci_dev_unlock(hdev); + + if (!err && put_user(buf_len, optlen)) + err = -EFAULT; + +error: + return err; +} diff --git a/net/bluetooth/hci_codec.h b/net/bluetooth/hci_codec.h index a2751930f123..6e849c7d75b9 100644 --- a/net/bluetooth/hci_codec.h +++ b/net/bluetooth/hci_codec.h @@ -5,3 +5,5 @@ void hci_read_supported_codecs(struct hci_dev *hdev); void hci_read_supported_codecs_v2(struct hci_dev *hdev); void hci_codec_list_clear(struct list_head *codec_list); +int hci_get_supported_codecs(struct hci_dev *hdev, u8 type, char __user *optval, + int __user *optlen, int len); diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 8eabf41b2993..0af814c13b5f 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -33,6 +33,8 @@ #include #include +#include "hci_codec.h" + static bool disable_esco; static const struct proto_ops sco_sock_ops; @@ -1032,12 +1034,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, struct bt_voice voice; u32 phys; int pkt_status; - int buf_len; - struct codec_list *c; - u8 num_codecs, i, __user *ptr; struct hci_dev *hdev; - struct hci_codec_caps *caps; - struct bt_codec codec; BT_DBG("sk %p", sk); @@ -1103,98 +1100,15 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, break; case BT_CODEC: - num_codecs = 0; - buf_len = 0; - - hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src, BDADDR_BREDR); + hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src, + BDADDR_BREDR); if (!hdev) { err = -EBADFD; break; } - - if (!hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) { - hci_dev_put(hdev); - err = -EOPNOTSUPP; - break; - } - - if (!hdev->get_data_path_id) { - hci_dev_put(hdev); - err = -EOPNOTSUPP; - break; - } - - /* find total buffer size required to copy codec + caps */ - hci_dev_lock(hdev); - list_for_each_entry(c, &hdev->local_codecs, list) { - if (c->transport != HCI_TRANSPORT_SCO_ESCO) - continue; - num_codecs++; - for (i = 0, caps = c->caps; i < c->num_caps; i++) { - buf_len += 1 + caps->len; - caps = (void *)&caps->data[caps->len]; - } - buf_len += sizeof(struct bt_codec); - } - hci_dev_unlock(hdev); - - buf_len += sizeof(struct bt_codecs); - if (buf_len > len) { - hci_dev_put(hdev); - err = -ENOBUFS; - break; - } - ptr = optval; - - if (put_user(num_codecs, ptr)) { - hci_dev_put(hdev); - err = -EFAULT; - break; - } - ptr += sizeof(num_codecs); - - /* Iterate all the codecs supported over SCO and populate - * codec data - */ - hci_dev_lock(hdev); - list_for_each_entry(c, &hdev->local_codecs, list) { - if (c->transport != HCI_TRANSPORT_SCO_ESCO) - continue; - - codec.id = c->id; - codec.cid = c->cid; - codec.vid = c->vid; - err = hdev->get_data_path_id(hdev, &codec.data_path); - if (err < 0) - break; - codec.num_caps = c->num_caps; - if (copy_to_user(ptr, &codec, sizeof(codec))) { - err = -EFAULT; - break; - } - ptr += sizeof(codec); - - /* find codec capabilities data length */ - len = 0; - for (i = 0, caps = c->caps; i < c->num_caps; i++) { - len += 1 + caps->len; - caps = (void *)&caps->data[caps->len]; - } - - /* copy codec capabilities data */ - if (len && copy_to_user(ptr, c->caps, len)) { - err = -EFAULT; - break; - } - ptr += len; - } - - if (!err && put_user(buf_len, optlen)) - err = -EFAULT; - - hci_dev_unlock(hdev); + err = hci_get_supported_codecs(hdev, HCI_TRANSPORT_SCO_ESCO, + optval, optlen, len); hci_dev_put(hdev); - break; default: From patchwork Fri Oct 8 14:07:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CABDC433FE for ; Fri, 8 Oct 2021 14:03:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71DB861042 for ; Fri, 8 Oct 2021 14:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233385AbhJHOFH (ORCPT ); Fri, 8 Oct 2021 10:05:07 -0400 Received: from mga04.intel.com ([192.55.52.120]:22400 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232200AbhJHOFG (ORCPT ); Fri, 8 Oct 2021 10:05:06 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="225286235" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="225286235" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:02:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715521002" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:02:44 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 2/7] Bluetooth: Support reading of codecs supported over l2cap socket Date: Fri, 8 Oct 2021 19:37:54 +0530 Message-Id: <20211008140759.15493-2-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008140759.15493-1-kiran.k@intel.com> References: <20211008140759.15493-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Codecs supported for A2DP offload use case are returned over l2cap socket. Add BT_CODEC option to getsockopt to return the codecs. Signed-off-by: Kiran K --- include/net/bluetooth/hci.h | 1 + net/bluetooth/l2cap_sock.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 63065bc01b76..451d491f7f68 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -2666,6 +2666,7 @@ static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb) #define hci_iso_data_flags(h) ((h) >> 14) /* codec transport types */ +#define HCI_TRANSPORT_ACL 0x00 #define HCI_TRANSPORT_SCO_ESCO 0x01 /* le24 support */ diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 160c016a5dfb..06f8ea681972 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -36,6 +36,7 @@ #include #include "smp.h" +#include "hci_codec.h" static struct bt_sock_list l2cap_sk_list = { .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock) @@ -549,6 +550,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, struct bt_power pwr; u32 phys; int len, mode, err = 0; + struct hci_dev *hdev; BT_DBG("sk %p", sk); @@ -685,6 +687,18 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, err = -EFAULT; break; + case BT_CODEC: + hdev = hci_get_route(BDADDR_ANY, &chan->src, BDADDR_BREDR); + if (!hdev) { + err = -EBADFD; + break; + } + + err = hci_get_supported_codecs(hdev, HCI_TRANSPORT_ACL, optval, + optlen, len); + hci_dev_put(hdev); + break; + default: err = -ENOPROTOOPT; break; From patchwork Fri Oct 8 14:07:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DD81C433FE for ; Fri, 8 Oct 2021 14:03:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E7CF61029 for ; Fri, 8 Oct 2021 14:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236071AbhJHOFI (ORCPT ); Fri, 8 Oct 2021 10:05:08 -0400 Received: from mga04.intel.com ([192.55.52.120]:22400 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234096AbhJHOFI (ORCPT ); Fri, 8 Oct 2021 10:05:08 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="225286249" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="225286249" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:02:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715521010" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:02:46 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 3/7] Bluetooth: btintel: cache offload use case data Date: Fri, 8 Oct 2021 19:37:55 +0530 Message-Id: <20211008140759.15493-3-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008140759.15493-1-kiran.k@intel.com> References: <20211008140759.15493-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Keep a copy of use cases preset information in driver data. Use cases preset data can be re-used later instead of reading from controller every time. Signed-off-by: Kiran K --- drivers/bluetooth/btintel.c | 6 ++++++ drivers/bluetooth/btintel.h | 1 + 2 files changed, 7 insertions(+) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 9359bff47296..f1431143eff5 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -2219,6 +2219,7 @@ static int btintel_configure_offload(struct hci_dev *hdev) struct sk_buff *skb; int err = 0; struct intel_offload_use_cases *use_cases; + struct btintel_data *intel_data; skb = __hci_cmd_sync(hdev, 0xfc86, 0, NULL, HCI_INIT_TIMEOUT); if (IS_ERR(skb)) { @@ -2239,10 +2240,15 @@ static int btintel_configure_offload(struct hci_dev *hdev) goto error; } + intel_data = hci_get_priv((hdev)); + + intel_data->use_cases = *use_cases; + if (use_cases->preset[0] & 0x03) { hdev->get_data_path_id = btintel_get_data_path_id; hdev->get_codec_config_data = btintel_get_codec_config_data; } + error: kfree_skb(skb); return err; diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index e500c0d7a729..091528d75256 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -158,6 +158,7 @@ enum { struct btintel_data { DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS); + struct intel_offload_use_cases use_cases; }; #define btintel_set_flag(hdev, nr) \ From patchwork Fri Oct 8 14:07:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D434C433F5 for ; Fri, 8 Oct 2021 14:03:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08E1461029 for ; Fri, 8 Oct 2021 14:03:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234083AbhJHOFM (ORCPT ); Fri, 8 Oct 2021 10:05:12 -0400 Received: from mga04.intel.com ([192.55.52.120]:22400 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235027AbhJHOFK (ORCPT ); Fri, 8 Oct 2021 10:05:10 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="225286261" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="225286261" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:02:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715521022" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:02:48 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 4/7] Bluetooth: Pass transport type in get_data_path_id Date: Fri, 8 Oct 2021 19:37:56 +0530 Message-Id: <20211008140759.15493-4-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008140759.15493-1-kiran.k@intel.com> References: <20211008140759.15493-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org To support fetching of data path id for other transport types like a2dp, le audio, pass an additional parameter to get_data_path_id callback function. Signed-off-by: Kiran K --- drivers/bluetooth/btintel.c | 19 +++++++++++++++---- drivers/bluetooth/hci_vhci.c | 6 +++++- include/net/bluetooth/hci_core.h | 3 ++- net/bluetooth/hci_codec.c | 9 ++++++--- net/bluetooth/hci_conn.c | 3 ++- net/bluetooth/hci_request.c | 5 +++-- net/bluetooth/hci_request.h | 3 ++- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index f1431143eff5..de4667179efb 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -2207,11 +2207,22 @@ static int btintel_get_codec_config_data(struct hci_dev *hdev, return err; } -static int btintel_get_data_path_id(struct hci_dev *hdev, __u8 *data_path_id) +static int btintel_get_data_path_id(struct hci_dev *hdev, __u8 transport, + __u8 *data_path_id) { - /* Intel uses 1 as data path id for all the usecases */ - *data_path_id = 1; - return 0; + struct btintel_data *intel_data; + + if (transport != HCI_TRANSPORT_SCO_ESCO) + return -EINVAL; + + intel_data = hci_get_priv((hdev)); + + if (intel_data->use_cases.preset[0] & 0x03) { + /* Intel uses 1 as data path id for all the usecases */ + *data_path_id = 1; + return 0; + } + return -EOPNOTSUPP; } static int btintel_configure_offload(struct hci_dev *hdev) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index 56c6b22be10b..a011d5b5694a 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -78,8 +78,12 @@ static int vhci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) return 0; } -static int vhci_get_data_path_id(struct hci_dev *hdev, u8 *data_path_id) +static int vhci_get_data_path_id(struct hci_dev *hdev, u8 transport, + u8 *data_path_id) { + if (transport != HCI_TRANSPORT_SCO_ESCO) + return -EINVAL; + *data_path_id = 0; return 0; } diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index dd8840e70e25..8b8b45f6d5bd 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -619,7 +619,8 @@ struct hci_dev { void (*cmd_timeout)(struct hci_dev *hdev); bool (*wakeup)(struct hci_dev *hdev); int (*set_quality_report)(struct hci_dev *hdev, bool enable); - int (*get_data_path_id)(struct hci_dev *hdev, __u8 *data_path); + int (*get_data_path_id)(struct hci_dev *hdev, __u8 transport, + __u8 *data_path); int (*get_codec_config_data)(struct hci_dev *hdev, __u8 type, struct bt_codec *codec, __u8 *vnd_len, __u8 **vnd_data); diff --git a/net/bluetooth/hci_codec.c b/net/bluetooth/hci_codec.c index f4d8d3a253d8..6d4e5353f05c 100644 --- a/net/bluetooth/hci_codec.c +++ b/net/bluetooth/hci_codec.c @@ -259,6 +259,7 @@ int hci_get_supported_codecs(struct hci_dev *hdev, u8 type, char __user *optval, struct bt_codec codec; u8 num_codecs = 0, i, __user *ptr; struct codec_list *c; + u8 data_path; if (!hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) { err = -EOPNOTSUPP; @@ -270,6 +271,10 @@ int hci_get_supported_codecs(struct hci_dev *hdev, u8 type, char __user *optval, goto error; } + err = hdev->get_data_path_id(hdev, type, &data_path); + if (err < 0) + goto error; + /* find total buffer size required to copy codec + capabilities */ hci_dev_lock(hdev); list_for_each_entry(c, &hdev->local_codecs, list) { @@ -306,9 +311,7 @@ int hci_get_supported_codecs(struct hci_dev *hdev, u8 type, char __user *optval, codec.id = c->id; codec.cid = c->cid; codec.vid = c->vid; - err = hdev->get_data_path_id(hdev, &codec.data_path); - if (err < 0) - break; + codec.data_path = data_path; codec.num_caps = c->num_caps; if (copy_to_user(ptr, &codec, sizeof(codec))) { err = -EFAULT; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index bd669c95b9a7..62192f463e5c 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -317,7 +317,8 @@ static bool hci_enhanced_setup_sync_conn(struct hci_conn *conn, __u16 handle) /* for offload use case, codec needs to configured before opening SCO */ if (conn->codec.data_path) - hci_req_configure_datapath(hdev, &conn->codec); + hci_req_configure_datapath(hdev, HCI_TRANSPORT_SCO_ESCO, + &conn->codec); conn->state = BT_CONNECT; conn->out = true; diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 92611bfc0b9e..34a104a2ca32 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -2950,7 +2950,8 @@ static void config_data_path_complete(struct hci_dev *hdev, u8 status, bt_dev_dbg(hdev, "status %u", status); } -int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec) +int hci_req_configure_datapath(struct hci_dev *hdev, u8 transport, + struct bt_codec *codec) { struct hci_request req; int err; @@ -2970,7 +2971,7 @@ int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec) goto error; } - err = hdev->get_data_path_id(hdev, &cmd->data_path_id); + err = hdev->get_data_path_id(hdev, transport, &cmd->data_path_id); if (err < 0) goto error; diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h index f31420f58525..d80a4e277a20 100644 --- a/net/bluetooth/hci_request.h +++ b/net/bluetooth/hci_request.h @@ -101,7 +101,8 @@ void __hci_req_update_class(struct hci_request *req); /* Returns true if HCI commands were queued */ bool hci_req_stop_discovery(struct hci_request *req); -int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec); +int hci_req_configure_datapath(struct hci_dev *hdev, u8 transport, + struct bt_codec *codec); static inline void hci_req_update_scan(struct hci_dev *hdev) { From patchwork Fri Oct 8 14:07:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7FBEC433F5 for ; Fri, 8 Oct 2021 14:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 915A061042 for ; Fri, 8 Oct 2021 14:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbhJHOE5 (ORCPT ); Fri, 8 Oct 2021 10:04:57 -0400 Received: from mga17.intel.com ([192.55.52.151]:29654 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbhJHOEz (ORCPT ); Fri, 8 Oct 2021 10:04:55 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="207321168" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="207321168" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:02:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715521056" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:02:50 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 5/7] Bluetooth: btintel: Add support to fetch data path id for a2dp offload Date: Fri, 8 Oct 2021 19:37:57 +0530 Message-Id: <20211008140759.15493-5-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008140759.15493-1-kiran.k@intel.com> References: <20211008140759.15493-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org During *setup*, when configuring offload, set get_data_path_id callback function and support fetching of data path id for a2dp offload use case. Signed-off-by: Kiran K --- drivers/bluetooth/btintel.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index de4667179efb..8dcb0e3c7386 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -2212,16 +2212,30 @@ static int btintel_get_data_path_id(struct hci_dev *hdev, __u8 transport, { struct btintel_data *intel_data; - if (transport != HCI_TRANSPORT_SCO_ESCO) + if (transport != HCI_TRANSPORT_SCO_ESCO && + transport != HCI_TRANSPORT_ACL) { + bt_dev_err(hdev, "Invalid transport type %u", transport); return -EINVAL; + } intel_data = hci_get_priv((hdev)); - if (intel_data->use_cases.preset[0] & 0x03) { - /* Intel uses 1 as data path id for all the usecases */ - *data_path_id = 1; - return 0; + switch (transport) { + case HCI_TRANSPORT_SCO_ESCO: + if (intel_data->use_cases.preset[0] & 0x03) { + *data_path_id = 1; + return 0; + } + break; + case HCI_TRANSPORT_ACL: + if (intel_data->use_cases.preset[0] & 0x08) { + *data_path_id = 1; + return 0; + } + break; } + bt_dev_err(hdev, "Required preset is not supported 0x%02x", + intel_data->use_cases.preset[0]); return -EOPNOTSUPP; } @@ -2260,6 +2274,10 @@ static int btintel_configure_offload(struct hci_dev *hdev) hdev->get_codec_config_data = btintel_get_codec_config_data; } + /* supports SBC codec for a2dp offload */ + if (use_cases->preset[0] & 0x08) + hdev->get_data_path_id = btintel_get_data_path_id; + error: kfree_skb(skb); return err; From patchwork Fri Oct 8 14:07:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3097C433EF for ; Fri, 8 Oct 2021 14:03:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9304060EE5 for ; Fri, 8 Oct 2021 14:03:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbhJHOE7 (ORCPT ); Fri, 8 Oct 2021 10:04:59 -0400 Received: from mga17.intel.com ([192.55.52.151]:29654 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230347AbhJHOE5 (ORCPT ); Fri, 8 Oct 2021 10:04:57 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="207321172" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="207321172" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:03:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715521080" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:02:59 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 6/7] Bluetooth: Remove unused member in struct hci_vnd_codec_v2 Date: Fri, 8 Oct 2021 19:37:58 +0530 Message-Id: <20211008140759.15493-6-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008140759.15493-1-kiran.k@intel.com> References: <20211008140759.15493-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Remove unused "u8 id" member in struct hci_vnd_codec_v2. Vendor codec is identifiable by Company Id and Vendor Id fields. Signed-off-by: Kiran K --- include/net/bluetooth/hci.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 451d491f7f68..7ea1bfce204f 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1393,7 +1393,6 @@ struct hci_std_codecs_v2 { } __packed; struct hci_vnd_codec_v2 { - __u8 id; __le16 cid; __le16 vid; __u8 transport; From patchwork Fri Oct 8 14:07:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 12545493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28062C433FE for ; Fri, 8 Oct 2021 14:03:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10FE861056 for ; Fri, 8 Oct 2021 14:03:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbhJHOE7 (ORCPT ); Fri, 8 Oct 2021 10:04:59 -0400 Received: from mga17.intel.com ([192.55.52.151]:29654 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbhJHOE7 (ORCPT ); Fri, 8 Oct 2021 10:04:59 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="207321183" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="207321183" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 07:03:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="715521107" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga005.fm.intel.com with ESMTP; 08 Oct 2021 07:03:01 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, luiz.von.dentz@intel.com, Kiran K Subject: [PATCH v2 7/7] Bluetooth: Read Output codec capabilities Date: Fri, 8 Oct 2021 19:37:59 +0530 Message-Id: <20211008140759.15493-7-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008140759.15493-1-kiran.k@intel.com> References: <20211008140759.15493-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When reading codec capabilities, read output (controller to host) capabilities also along with input (host to controller) capabilities. Signed-off-by: Kiran K --- net/bluetooth/hci_codec.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/bluetooth/hci_codec.c b/net/bluetooth/hci_codec.c index 6d4e5353f05c..c6bd934dcf36 100644 --- a/net/bluetooth/hci_codec.c +++ b/net/bluetooth/hci_codec.c @@ -159,6 +159,9 @@ void hci_read_supported_codecs(struct hci_dev *hdev) caps.id = std_codecs->codec[i]; caps.direction = 0x00; hci_read_codec_capabilities(hdev, LOCAL_CODEC_ACL_MASK, &caps); + + caps.direction = 0x01; + hci_read_codec_capabilities(hdev, LOCAL_CODEC_ACL_MASK, &caps); } skb_pull(skb, flex_array_size(std_codecs, codec, std_codecs->num) @@ -179,6 +182,9 @@ void hci_read_supported_codecs(struct hci_dev *hdev) caps.vid = vnd_codecs->codec[i].vid; caps.direction = 0x00; hci_read_codec_capabilities(hdev, LOCAL_CODEC_ACL_MASK, &caps); + + caps.direction = 0x01; + hci_read_codec_capabilities(hdev, LOCAL_CODEC_ACL_MASK, &caps); } error: @@ -224,6 +230,10 @@ void hci_read_supported_codecs_v2(struct hci_dev *hdev) for (i = 0; i < std_codecs->num; i++) { caps.id = std_codecs->codec[i].id; + caps.direction = 0x00; + hci_read_codec_capabilities(hdev, std_codecs->codec[i].transport, + &caps); + caps.direction = 0x01; hci_read_codec_capabilities(hdev, std_codecs->codec[i].transport, &caps); } @@ -243,6 +253,10 @@ void hci_read_supported_codecs_v2(struct hci_dev *hdev) caps.id = 0xFF; caps.cid = vnd_codecs->codec[i].cid; caps.vid = vnd_codecs->codec[i].vid; + caps.direction = 0x00; + hci_read_codec_capabilities(hdev, vnd_codecs->codec[i].transport, + &caps); + caps.direction = 0x01; hci_read_codec_capabilities(hdev, vnd_codecs->codec[i].transport, &caps); }