From patchwork Thu May 26 11:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Hwang X-Patchwork-Id: 12862302 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3ECAC433FE for ; Thu, 26 May 2022 11:22:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347125AbiEZLWL (ORCPT ); Thu, 26 May 2022 07:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346964AbiEZLWH (ORCPT ); Thu, 26 May 2022 07:22:07 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E9BFF2B for ; Thu, 26 May 2022 04:21:55 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id c65so885402pfb.1 for ; Thu, 26 May 2022 04:21:55 -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=kNtuB840A1q3OEONvZZSgOOnkUcYtuWuq+G8qAKrj5A=; b=IHDSwip5ZkMn+jZZWR3D8OeVtPwjy0QmHUMctL7i0m0Ofx9wv7he/E0B26+bpNyLRp EkT6a4FMkj5BKxgLtPinkFF4jZl88m2X8+3acFoDhKQdFiP/IfosuMC6/fGLcuuDablW Nlb6FCR+IE/aOvnQSBVdgpyq35OilOjJQbduU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kNtuB840A1q3OEONvZZSgOOnkUcYtuWuq+G8qAKrj5A=; b=a40MkQyD1prkdPtHSGmmmSkZCkhtvJi/ANp5KdHBV7B/RfliAPuaT6kP8enwUtBwvi 3F2sg9kqI3ty+Mg5SFeyBF5umS8MTZ48HXlpZOSptsa2yGrUp/TfSKJkz72t7Tu1YSVz rqI3O3DnHc22AB7AzdFxVFqM1PuC6ZhbuXf6wPu2NX5zScIx/tZ/zDNQ863/K9F1UPOt QukUvhhpMEIDEd1iX4KaeqR8XQ7EsMwkd4FR2RH41i9twZL61sxhSvTo6WOZ95XdQHqy pioWdZnktSQcc1HNDg1S0pRSQ58+gttP2ROefgf4K7hEGSxjgf8JmzRncoaO7bu/sLRS rhbQ== X-Gm-Message-State: AOAM5338TWxQaeRhOmn1VaDk/J5r7ElXucyvrKX8/4+5YllwqR3GmVjH RRxQoU16eCWEotxvVv4ddKu6pkdjMotscQ== X-Google-Smtp-Source: ABdhPJzwGrsjJ7DYpbm/S3lJ4MxlWN/pogwg1wixchK7IkXIlj7XbhGDsW+3B9oczPekcFPg3c/90g== X-Received: by 2002:a63:5415:0:b0:3fb:971:460a with SMTP id i21-20020a635415000000b003fb0971460amr3226121pgb.86.1653564114093; Thu, 26 May 2022 04:21:54 -0700 (PDT) Received: from localhost (174.71.80.34.bc.googleusercontent.com. [34.80.71.174]) by smtp.gmail.com with UTF8SMTPSA id y20-20020a170903011400b0015e8d4eb22fsm1229917plc.121.2022.05.26.04.21.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 May 2022 04:21:53 -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 , Archie Pusaka , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v6 3/5] Bluetooth: hci_event: Add vendor functions to handle vendor events Date: Thu, 26 May 2022 19:21:32 +0800 Message-Id: <20220526192047.v6.3.I63681490281b2392aa1ac05dff91a126394ab649@changeid> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog In-Reply-To: <20220526112135.2486883-1-josephsih@chromium.org> References: <20220526112135.2486883-1-josephsih@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds vendor_get_prefix and vendor_evt in the evt_prefixes table so that any vendor driver can set up the functions to handle particular vendor events. The hci_vendor_evt function checks if a vendor event matches the vendor prefix returned by vendor_get_prefix. If yes, the event is pushed down to the driver's vendor_evt function to handle. The driver function will call hdev->hci_recv_quality_report to pass data through mgmt if needed. Signed-off-by: Joseph Hwang Reviewed-by: Archie Pusaka --- (no changes since v5) Changes in v5: - Use vendor_get_ext_prefix and vendor_evt to invoke callbacks from drivers to handle vendor events. - Use hdev->hci_recv_quality_report to pass vendor event data from drivers back to the kernel. The mgmt_quality_report is then used to surface the data through the mgmt socket. - Remove the unnecessary "void *data" portion from vendor_evt. - The Intel specifics are pushed down to the driver and are implemented in a separate subsequent patch. Changes in v3: - Move intel_vendor_evt() from hci_event.c to the btintel driver. Changes in v2: - Drop the pull_quality_report_data function from hci_dev. Do not bother hci_dev with it. Do not bleed the details into the core. include/net/bluetooth/hci_core.h | 5 +++++ net/bluetooth/hci_core.c | 1 + net/bluetooth/hci_event.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index f89738c6b973..9e48d606591e 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -642,6 +642,11 @@ 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); + struct ext_vendor_prefix *(*vendor_get_ext_prefix)( + struct hci_dev *hdev); + void (*vendor_evt)(struct hci_dev *hdev, struct sk_buff *skb); + int (*hci_recv_quality_report)(struct hci_dev *hdev, void *data, + u32 data_len, u8 quality_spec); int (*get_data_path_id)(struct hci_dev *hdev, __u8 *data_path); int (*get_codec_config_data)(struct hci_dev *hdev, __u8 type, struct bt_codec *codec, __u8 *vnd_len, diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index ad4f4ab0afca..3e22b4b452f1 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2650,6 +2650,7 @@ int hci_register_dev(struct hci_dev *hdev) idr_init(&hdev->adv_monitors_idr); msft_register(hdev); + hdev->hci_recv_quality_report = mgmt_quality_report; return id; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 8398971eddf4..85c205ea9c59 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4260,6 +4260,20 @@ static void hci_num_comp_blocks_evt(struct hci_dev *hdev, void *data, queue_work(hdev->workqueue, &hdev->tx_work); } +static struct ext_vendor_prefix *vendor_get_ext_prefix(struct hci_dev *hdev) +{ + if (hdev->vendor_get_ext_prefix) + return hdev->vendor_get_ext_prefix(hdev); + + return NULL; +} + +static void vendor_evt(struct hci_dev *hdev, struct sk_buff *skb) +{ + if (hdev->vendor_evt) + hdev->vendor_evt(hdev, skb); +} + /* Every distinct vendor specification must have a well-defined vendor * event prefix to determine if a vendor event meets the specification. * Some vendor prefixes are fixed values while some other vendor prefixes @@ -4276,6 +4290,11 @@ static struct ext_vendor_event_prefix { { aosp_get_ext_prefix, aosp_vendor_evt }, { msft_get_ext_prefix, msft_vendor_evt }, + /* Any vendor driver that handles particular vendor events should set + * up hdev->vendor_get_prefix and hdev->vendor_evt callbacks in driver. + */ + { vendor_get_ext_prefix, vendor_evt }, + /* end with a null entry */ {}, };