From patchwork Tue Sep 28 21:36:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12523893 X-Patchwork-Delegate: marcel@holtmann.org 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 5402FC433F5 for ; Tue, 28 Sep 2021 21:36:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3273F61206 for ; Tue, 28 Sep 2021 21:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242944AbhI1Vii (ORCPT ); Tue, 28 Sep 2021 17:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbhI1Vih (ORCPT ); Tue, 28 Sep 2021 17:38:37 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9096C06161C for ; Tue, 28 Sep 2021 14:36:57 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id n18so431915pgm.12 for ; Tue, 28 Sep 2021 14:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=hym3bLNj/USdMTU9o29QHXzP+w7cc1MS83jShdmHhOE=; b=DaXqPaYML1omf6gaM4nkXwYQWWVQZGbTnrGE575zwpeczVsuOZMW0n/mSjhuH7iT37 5T5w6Gos2c5ZAreQ73+cCygcR4N+OXbwrxWF5ZOlfYFhzjkK8Mx48+v995CIC7kqLQey o8Mu+7oDnEF4YIWaHRK6NkbWB/kqxfKl61CFINctHuIzhTzjVXlwF9idrbH4NgfJxLNQ 9ODA26wL3YSPOSKG2qCjHKwqmfcLoWGyu9BtHgGRzmjizdy6ydbvHuwORSEuaRDUlyE7 hyMZOQA9nr/LCLj+tnOAzsNLzuA3fxovwfpYegpoWtojbgBSOh136tFU6brm2rXAvmk3 2tLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=hym3bLNj/USdMTU9o29QHXzP+w7cc1MS83jShdmHhOE=; b=SlbyoVZk5gYATuFWAdjyc7e3iRCcfuaGnqth2qPDhmYpV+xhwbhZJwn9/YrE/JSYca r59fhIutrVvQbabgnQw1j9tiQoviI5bROmHlbLbHuxVSMxGTs8vHFAVqs++zkqXnqoc3 PHE7+cCJ2sLyPQWAa+5c6v1jAgh/eeyLO6LjzayGQLDM1JTavfQuAHAjSzIPmqgOVdmV UKs+pNLpOL56aDLSiCDaErOQ5Vox+45f6rVOdoLIQg/MUaiZjSLzR/IpPs5aZJecX9W+ 8b85GrVwDOdo4Bc+QTNEHcMI6iIb6TlGvIGG6M67GplLvlzTfcgtY191MOXEYUmFcnZx HkSA== X-Gm-Message-State: AOAM5320xl3V6rxIxkxJ40oCv+WeuY2dY69eCHFBOjjAB/3ZIFf9eyts eHGrqfV9R1uNm0lIZh6aUfCa5niaoJY= X-Google-Smtp-Source: ABdhPJx6kT7fA6eMJgYMX+qaxF6g0ir3y6rBaj7hiASUK/lCUobfXRghJS0B0vgLcIanCEzGGSfYdA== X-Received: by 2002:aa7:9e90:0:b0:43f:2abb:a504 with SMTP id p16-20020aa79e90000000b0043f2abba504mr7668868pfq.35.1632865016955; Tue, 28 Sep 2021 14:36:56 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id ml21sm2053862pjb.55.2021.09.28.14.36.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 14:36:56 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/3] Bluetooth: Make use of hci_{suspend,resume}_dev on suspend notifier Date: Tue, 28 Sep 2021 14:36:51 -0700 Message-Id: <20210928213653.3028439-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This moves code from hci_suspend_notifier to hci_{suspend,resume}_dev since some driver may handle pm directly using HCI_QUIRK_NO_SUSPEND_NOTIFIER they would instead call hci_{suspend,resume}_dev directly and we want that to have the same behavior regardless of where pm is being handled. Signed-off-by: Luiz Augusto von Dentz --- v2: Clarify why some code is being move into hci_{suspend,resume}_dev and move debugfs entries to hci_vhci driver so it emulates more closely the behavior of the driver implementing pm handling and calling the likes of hci_suspend_dev. net/bluetooth/hci_core.c | 116 ++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index aeec5a3031a6..ea063ce4d7af 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3626,55 +3626,12 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, struct hci_dev *hdev = container_of(nb, struct hci_dev, suspend_notifier); int ret = 0; - u8 state = BT_RUNNING; - - /* If powering down, wait for completion. */ - if (mgmt_powering_down(hdev)) { - set_bit(SUSPEND_POWERING_DOWN, hdev->suspend_tasks); - ret = hci_suspend_wait_event(hdev); - if (ret) - goto done; - } - /* Suspend notifier should only act on events when powered. */ - if (!hdev_is_powered(hdev) || - hci_dev_test_flag(hdev, HCI_UNREGISTER)) - goto done; - - if (action == PM_SUSPEND_PREPARE) { - /* Suspend consists of two actions: - * - First, disconnect everything and make the controller not - * connectable (disabling scanning) - * - Second, program event filter/accept list and enable scan - */ - ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT); - if (!ret) - state = BT_SUSPEND_DISCONNECT; - - /* Only configure accept list if disconnect succeeded and wake - * isn't being prevented. - */ - if (!ret && !(hdev->prevent_wake && hdev->prevent_wake(hdev))) { - ret = hci_change_suspend_state(hdev, - BT_SUSPEND_CONFIGURE_WAKE); - if (!ret) - state = BT_SUSPEND_CONFIGURE_WAKE; - } + if (action == PM_SUSPEND_PREPARE) + ret = hci_suspend_dev(hdev); + else if (action == PM_POST_SUSPEND) + ret = hci_resume_dev(hdev); - hci_clear_wake_reason(hdev); - mgmt_suspending(hdev, state); - - } else if (action == PM_POST_SUSPEND) { - ret = hci_change_suspend_state(hdev, BT_RUNNING); - - mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, - hdev->wake_addr_type); - } - -done: - /* We always allow suspend even if suspend preparation failed and - * attempt to recover in resume. - */ if (ret) bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", action, ret); @@ -4017,16 +3974,77 @@ EXPORT_SYMBOL(hci_release_dev); /* Suspend HCI device */ int hci_suspend_dev(struct hci_dev *hdev) { + int ret; + u8 state = BT_RUNNING; + + bt_dev_dbg(hdev, ""); + + /* Suspend should only act on when powered. */ + if (!hdev_is_powered(hdev) || + hci_dev_test_flag(hdev, HCI_UNREGISTER)) + return 0; + + /* If powering down, wait for completion. */ + if (mgmt_powering_down(hdev)) { + set_bit(SUSPEND_POWERING_DOWN, hdev->suspend_tasks); + ret = hci_suspend_wait_event(hdev); + if (ret) + goto done; + } + + /* Suspend consists of two actions: + * - First, disconnect everything and make the controller not + * connectable (disabling scanning) + * - Second, program event filter/accept list and enable scan + */ + ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT); + if (!ret) + state = BT_SUSPEND_DISCONNECT; + + /* Only configure accept list if disconnect succeeded and wake + * isn't being prevented. + */ + if (!ret && !(hdev->prevent_wake && hdev->prevent_wake(hdev))) { + ret = hci_change_suspend_state(hdev, BT_SUSPEND_CONFIGURE_WAKE); + if (!ret) + state = BT_SUSPEND_CONFIGURE_WAKE; + } + + hci_clear_wake_reason(hdev); + mgmt_suspending(hdev, state); + +done: + /* We always allow suspend even if suspend preparation failed and + * attempt to recover in resume. + */ hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); - return 0; + return ret; } EXPORT_SYMBOL(hci_suspend_dev); /* Resume HCI device */ int hci_resume_dev(struct hci_dev *hdev) { + int ret; + + bt_dev_dbg(hdev, ""); + + /* Resume should only act on when powered. */ + if (!hdev_is_powered(hdev) || + hci_dev_test_flag(hdev, HCI_UNREGISTER)) + return 0; + + /* If powering down don't attempt to resume */ + if (mgmt_powering_down(hdev)) + return 0; + + ret = hci_change_suspend_state(hdev, BT_RUNNING); + + mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, + hdev->wake_addr_type); + hci_sock_dev_event(hdev, HCI_DEV_RESUME); - return 0; + return ret; } EXPORT_SYMBOL(hci_resume_dev); From patchwork Tue Sep 28 21:36:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12523895 X-Patchwork-Delegate: marcel@holtmann.org 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 3C663C433FE for ; Tue, 28 Sep 2021 21:37:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 255FA61206 for ; Tue, 28 Sep 2021 21:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242950AbhI1Vij (ORCPT ); Tue, 28 Sep 2021 17:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbhI1Vii (ORCPT ); Tue, 28 Sep 2021 17:38:38 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F880C06161C for ; Tue, 28 Sep 2021 14:36:59 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id s16so187010pfk.0 for ; Tue, 28 Sep 2021 14:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Fpd125Fp3aw0OcEBLjwQau/IVlYDW1wDNutvI1kdhkQ=; b=OVZkq4mwmUywUb1vC1Ry3lQASyysa8TWPMyns7VZK3SqmxVoRAUwqvt7Bb7mDelTfy hGux+0ro/KwRPz9pipEs4wFq+V6rvcmAfOXOQxXATHj9HEEYjRoPJbe7nMnubEG2j5om z1Iy/qlnxjiIkU44oBEJ5/3brVQeHiKrNDFowuqUtGTZll/QA7EE7OnVUA70OjYUt9v/ 6W0/3JON3xHuQ3Kl9OfixAU+zGu2VSQ+ynB6K//APytC4cVsSQ66KrhwXKwCraaOR3VH pFrCDWCHquOori+86nyDPclWMFgrHsx5I6b6NM/Ehu8haHe2PlQsUx4Y8BvkE7M3YHAA nS4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fpd125Fp3aw0OcEBLjwQau/IVlYDW1wDNutvI1kdhkQ=; b=ZTn7OycyW1RTFNnX3iew/bpFrHUcny5QH37K91TqQwAmDDOz3HEaGrGhNPM8UdA9Uo 91enTX3AgJwq3i5LDksKKB7hM1AiYeJ0Zi0CYbtRK9YLZc1CfkEnF226V0Nh4MhbpUO4 bYV3CKJHCyfK3DWPSGYyaVaHD3f1tiCURKtkpp0sd5attBdWrqovUrr8J0+CJ9bDJokj gKhBy1nFiRfeTzfeXEInkYNsGbizsogUBHEviulsgIizmwPPGcditjU+K18On4XgmO2s kYVphBsuN7iG/HzL2vP9NnJ6mndZcrrHnlW7+cTphs5ZUWooMyzf3PttGB1U9+CSDWmS WYvw== X-Gm-Message-State: AOAM531QyHQYiw9yHeEi/HNddoBHCSYVU+hMxwmHcdMvHlExBBbr2h3V Bh+5hiHsr/72SDM9MGBua1HMVtY58EU= X-Google-Smtp-Source: ABdhPJx7PejY0X48ctb3R7rlMhwNvBpdaxUnQ7T5Gk2+E2YYwkLIu6Law+2GEuOq9cjOozM50SQGiA== X-Received: by 2002:a05:6a00:c3:b0:43d:e6be:b2a6 with SMTP id e3-20020a056a0000c300b0043de6beb2a6mr7511715pfj.34.1632865018249; Tue, 28 Sep 2021 14:36:58 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id ml21sm2053862pjb.55.2021.09.28.14.36.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 14:36:57 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 2/3] Bluetooth: hci_vhci: Add force_suspend entry Date: Tue, 28 Sep 2021 14:36:52 -0700 Message-Id: <20210928213653.3028439-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928213653.3028439-1-luiz.dentz@gmail.com> References: <20210928213653.3028439-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds force_suspend which can be used to force the controller into suspend/resume state. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index cc3679f3491d..52f9106faeae 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -91,6 +92,51 @@ static int vhci_get_codec_config_data(struct hci_dev *hdev, __u8 type, return 0; } +static ssize_t force_suspend_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct hci_dev *hdev = file->private_data; + char buf[3]; + + buf[0] = hdev->suspended ? 'Y' : 'N'; + buf[1] = '\n'; + buf[2] = '\0'; + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); +} + +static ssize_t force_suspend_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct hci_dev *hdev = file->private_data; + bool enable; + int err; + + err = kstrtobool_from_user(user_buf, count, &enable); + if (err) + return err; + + if (hdev->suspended == enable) + return -EALREADY; + + if (enable) + err = hci_suspend_dev(hdev); + else + err = hci_resume_dev(hdev); + + if (err) + return err; + + return count; +} + +static const struct file_operations force_suspend_fops = { + .open = simple_open, + .read = force_suspend_read, + .write = force_suspend_write, + .llseek = default_llseek, +}; + static int __vhci_create_device(struct vhci_data *data, __u8 opcode) { struct hci_dev *hdev; @@ -149,6 +195,9 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode) return -EBUSY; } + debugfs_create_file("force_suspend", 0644, hdev->debugfs, hdev, + &force_suspend_fops); + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; skb_put_u8(skb, 0xff); From patchwork Tue Sep 28 21:36:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 12523897 X-Patchwork-Delegate: marcel@holtmann.org 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 37E95C433EF for ; Tue, 28 Sep 2021 21:37:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26540611CE for ; Tue, 28 Sep 2021 21:37:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242969AbhI1Vik (ORCPT ); Tue, 28 Sep 2021 17:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbhI1Vij (ORCPT ); Tue, 28 Sep 2021 17:38:39 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F35C06161C for ; Tue, 28 Sep 2021 14:37:00 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 133so488033pgb.1 for ; Tue, 28 Sep 2021 14:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=X5UvtBIEd/KLYSlijNmdwPM9ku2ECn9PfyFZL2jvL0U=; b=hHkPJSNaxSFkhJYF3654XdoIjSFM3F36T/t47P6eRuFKcPXz5V1BZZoUVcCeGaGunD CgtwFgAXDaZYgD7YWnvcgBPitLd6teBs3CFzUN+CD2N786h9TgyWwPATxyFuF4hD+bzr YMlxCpvkMki49E52YYqlGRDFZ1kVmNm2309aCBONTD44Tas3rKIEVzxafHckvrbopvve 8+A/CkWKCLFa49RlaJkJTZzRL3qnfPWOSKaI1yHvjBDJb7CeeQxk/0x0IRI5izw6BTGp sHgmWYF9O7I59guBLYoronJtwVR2eMN3c06UkmGFGzZx/hXuBX7BVazbs4TeXTDcCSxi 9auA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X5UvtBIEd/KLYSlijNmdwPM9ku2ECn9PfyFZL2jvL0U=; b=yfSLcMMnhO6g9tdSywtXER19AkMUf5zcb89YHr2/0iDdRIVhzAkj5CgK8uE0FlycX8 GD7OIR7zFEPYmR1p0ZZ1b3jCxNYsx6xvrg8ZPUT9mZFRdfvYyWOrxOFD8C8smbyRHYFK gKeFzmA6kL9loOx+yt8+E//zA6AuTmg0KfUAswenTUA/nTDi1NUO7wPTaQhBchnPDQg/ iqld3SlE2naXlOqE0+7ZIz3EGH28o43iRgJC8x+I5iP8xnobe6ocuVDvyh5mc8OfRQVN 1E5gfItgFjZTM4vlqEqD3RKgLHpXUg8W32vYzCLDBaOqqJTV+DJR8XvQYkhBHKc9OMQE b6yw== X-Gm-Message-State: AOAM531VWDbfQMnKagiIUgajsoQ6POnTHO4OrlWBcFxADOazW9eU+NJm JVh4bPgMYA9fhEeXDkdFl8p5ouENM98= X-Google-Smtp-Source: ABdhPJwPIkJ59SQt8VNEaokVG2Peqylvn1B0PGbZaKQAfhmwl6R8pxJkCUabXt6YCARV+JTeab/0VQ== X-Received: by 2002:a63:348c:: with SMTP id b134mr6453256pga.243.1632865019319; Tue, 28 Sep 2021 14:36:59 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id ml21sm2053862pjb.55.2021.09.28.14.36.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 14:36:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 3/3] Bluetooth: hci_vhci: Add force_prevent_wake entry Date: Tue, 28 Sep 2021 14:36:53 -0700 Message-Id: <20210928213653.3028439-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928213653.3028439-1-luiz.dentz@gmail.com> References: <20210928213653.3028439-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds force_prevent_wake which can be used to force a certain state while interacting with force_suspend. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index 52f9106faeae..60a408a49828 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -137,6 +137,51 @@ static const struct file_operations force_suspend_fops = { .llseek = default_llseek, }; +static bool prevent_wake; + +static ssize_t force_prevent_wake_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + char buf[3]; + + buf[0] = prevent_wake ? 'Y' : 'N'; + buf[1] = '\n'; + buf[2] = '\0'; + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); +} + +static bool hci_debugfs_prevent_wake(struct hci_dev *hdev) +{ + return prevent_wake; +} + +static ssize_t force_prevent_wake_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct hci_dev *hdev = file->private_data; + bool enable; + int err; + + err = kstrtobool_from_user(user_buf, count, &enable); + if (err) + return err; + + if (prevent_wake == enable) + return -EALREADY; + + hdev->prevent_wake = hci_debugfs_prevent_wake; + + return count; +} + +static const struct file_operations force_prevent_wake_fops = { + .open = simple_open, + .read = force_prevent_wake_read, + .write = force_prevent_wake_write, + .llseek = default_llseek, +}; + static int __vhci_create_device(struct vhci_data *data, __u8 opcode) { struct hci_dev *hdev; @@ -198,6 +243,9 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode) debugfs_create_file("force_suspend", 0644, hdev->debugfs, hdev, &force_suspend_fops); + debugfs_create_file("force_prevent_wake", 0644, hdev->debugfs, hdev, + &force_prevent_wake_fops); + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; skb_put_u8(skb, 0xff);