Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp388093pxb; Wed, 3 Mar 2021 05:59:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrPazTMQtqR0i6Dkt1Xr5q3rn9SEgmx5w4qheTvNOemBvkEZC4yzTV0C7Dm2468F4U8i8U X-Received: by 2002:a05:6402:1613:: with SMTP id f19mr17767163edv.222.1614779967757; Wed, 03 Mar 2021 05:59:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614779967; cv=none; d=google.com; s=arc-20160816; b=ZmZ8HrqK2b5hEzGE4BNHOvNsZ71T5Z/haILVReO4UU7htr/1acM5p2WZ/C2ddc7I+2 xdZY88lXbm3UOUotX7B0sN//c0viaFllYUGfSWxCV3npkhOGYKDFEeQifqdoWNqzg2fg Y531icUScqkNZEQ6a3ioCvg1sRb2sg6RDGTpo9yelweInFfMEo3IP9uoqd3xfmL3zGBA 3Yicj/kw+6/KV24tGcOotpxoovzw4iWoSAtyrg7jpdT/DgZZznI/LGu+mjhbMx4jXwhj 4XUFmAuKCTy0IC/M5565b7N5bxeKZxtJZys9xDkASKvLERh3dpm3v+5zlW4i4C4UZ9wb crpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U+yZn5oAcut/C/aebOJ16/bGakvc9MpdGSWik0h5VXc=; b=CoVT8rphzH9uAcUZMw5Bb28bEGhiNkPyn0XteFhbC5CiQHiD6RYYZTKiKpKqi7kyMn B+i6ze21wJdeUIRc51TB7SCaNky8pgco1BsY1p65Tapy+t1cEzCQaeMv0kW6Y8my9Nqv 8l+krIPy/640Mg1BxDe5d/yU3Os1tuGQwxsuYFcTZx5RXkNN0AT41G95OwNfSPX6Pg9O hgf8F6fnU+jatpr/7iO5FU+v4Xf4XAjka8p/w+BhecKjAOEXqc03tEhBr0VsxyAf5ZpJ TEvfStx6cBEx4OArm7X8138nqsyxUfFwDS5qVApfwrfKWPWaxJX5JUVFeouz4vBXArFi 2dxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WoqBGSdM; 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 dh14si9849317edb.334.2021.03.03.05.59.04; Wed, 03 Mar 2021 05:59:27 -0800 (PST) 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=WoqBGSdM; 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 S242326AbhCAUPD (ORCPT + 99 others); Mon, 1 Mar 2021 15:15:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236171AbhCAUJs (ORCPT ); Mon, 1 Mar 2021 15:09:48 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01BF4C061797 for ; Mon, 1 Mar 2021 12:06:18 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id i14so292734pjz.4 for ; Mon, 01 Mar 2021 12:06:17 -0800 (PST) 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=U+yZn5oAcut/C/aebOJ16/bGakvc9MpdGSWik0h5VXc=; b=WoqBGSdMrcG7i8F+POoakKo8qZE6yUVQgoE3Y8qtfWvdLpMLOZCPTFFQKFSpR4E/L7 0cYCUSTthhZ89M8yRs/gH4Gk6O/9YuTsqFPhhW+v3MNPl7ZKrHGLDN4HhlKScp2QTYX2 gOIBafTn/FrYPZkfvWQBE7NlZk1pEUmwAWO2E= 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=U+yZn5oAcut/C/aebOJ16/bGakvc9MpdGSWik0h5VXc=; b=AqSzItbt4lomanfYmW4vgIfyD7Gc6Hkm9wHHNYjiXWZ+K/mTIjTClX/fwteE+LR3lA 8CtU+YH50eHVXiC525uMsnrhWamZKcvldc2oJ6q9oTQD4vreAW6GY/5jUSN00OR8rSDs laXiz3nFJ78HQKGcKoXkdR9IhKY7UQLrMw8Nz1qhwBne+BDzm3d6RE+pRa/Jytxjj4yy KRGoxMoNsTTuinDzFeN+JZ2Ta02gB08C1fTAS7QX+zBX1AxGJMcRzEdDedLopeQI4o9g jpaoP+Vn2xO8uJ+2wvWHpX+oD9jLjmE19YbCn0gTfA2Bzvv1M0ZW4M2VgOdRW7mvY6iZ gZlw== X-Gm-Message-State: AOAM532h11G5W8gI7yAOd43rLx2TDyWKxa0y5tm2yBkFcGcPxgpOZEhe aNuiaCf6Gim7i2ef+h/C8Doq+g== X-Received: by 2002:a17:90a:ba16:: with SMTP id s22mr646925pjr.88.1614629177608; Mon, 01 Mar 2021 12:06:17 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:d800:e660:6ed:356a]) by smtp.gmail.com with ESMTPSA id t4sm238256pjs.12.2021.03.01.12.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 12:06:17 -0800 (PST) From: Abhishek Pandit-Subedi To: marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, Hans de Goede , linux-bluetooth@vger.kernel.org, Abhishek Pandit-Subedi , Archie Pusaka , Alain Michaud , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski , Luiz Augusto von Dentz Subject: [PATCH 2/2] Bluetooth: Remove unneeded commands for suspend Date: Mon, 1 Mar 2021 12:06:05 -0800 Message-Id: <20210301120602.2.Ifcac8bd85b5339135af8e08370bacecc518b1c35@changeid> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210301200605.106607-1-abhishekpandit@chromium.org> References: <20210301200605.106607-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org During suspend, there are a few scan enable and set event filter commands that don't need to be sent unless there are actual BR/EDR devices capable of waking the system. Check the HCI_PSCAN bit before writing scan enable and use a new dev flag, HCI_EVENT_FILTER_CONFIGURED to control whether to clear the event filter. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Archie Pusaka Reviewed-by: Alain Michaud --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 31 ++++++++++++++++++++++++++ net/bluetooth/hci_request.c | 44 +++++++++++++++++++++++-------------- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index ba2f439bc04d34..ea4ae551c42687 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -320,6 +320,7 @@ enum { HCI_BREDR_ENABLED, HCI_LE_SCAN_INTERRUPTED, HCI_WIDEBAND_SPEECH_ENABLED, + HCI_EVENT_FILTER_CONFIGURED, HCI_DUT_MODE, HCI_VENDOR_DIAG, diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 67668be3461e93..17847e672b98cf 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -395,6 +395,33 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_unlock(hdev); } +static void hci_cc_set_event_filter(struct hci_dev *hdev, struct sk_buff *skb) +{ + __u8 status = *((__u8 *)skb->data); + struct hci_cp_set_event_filter *cp; + void *sent; + + BT_DBG("%s status 0x%2.2x", hdev->name, status); + + sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT); + if (!sent) + return; + + cp = (struct hci_cp_set_event_filter *)sent; + + hci_dev_lock(hdev); + + if (status) + goto done; + + if (cp->flt_type == HCI_FLT_CLEAR_ALL) + hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); + else + hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); +done: + hci_dev_unlock(hdev); +} + static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_rp_read_class_of_dev *rp = (void *) skb->data; @@ -3328,6 +3355,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, hci_cc_write_scan_enable(hdev, skb); break; + case HCI_OP_SET_EVENT_FLT: + hci_cc_set_event_filter(hdev, skb); + break; + case HCI_OP_READ_CLASS_OF_DEV: hci_cc_read_class_of_dev(hdev, skb); break; diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index e55976db4403e7..75a42178c82d9b 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1131,14 +1131,14 @@ static void hci_req_clear_event_filter(struct hci_request *req) { struct hci_cp_set_event_filter f; - memset(&f, 0, sizeof(f)); - f.flt_type = HCI_FLT_CLEAR_ALL; - hci_req_add(req, HCI_OP_SET_EVENT_FLT, 1, &f); + if (!hci_dev_test_flag(req->hdev, HCI_BREDR_ENABLED)) + return; - /* Update page scan state (since we may have modified it when setting - * the event filter). - */ - __hci_req_update_scan(req); + if (hci_dev_test_flag(req->hdev, HCI_EVENT_FILTER_CONFIGURED)) { + memset(&f, 0, sizeof(f)); + f.flt_type = HCI_FLT_CLEAR_ALL; + hci_req_add(req, HCI_OP_SET_EVENT_FLT, 1, &f); + } } static void hci_req_set_event_filter(struct hci_request *req) @@ -1147,6 +1147,10 @@ static void hci_req_set_event_filter(struct hci_request *req) struct hci_cp_set_event_filter f; struct hci_dev *hdev = req->hdev; u8 scan = SCAN_DISABLED; + bool scanning = test_bit(HCI_PSCAN, &hdev->flags); + + if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) + return; /* Always clear event filter when starting */ hci_req_clear_event_filter(req); @@ -1167,12 +1171,13 @@ static void hci_req_set_event_filter(struct hci_request *req) scan = SCAN_PAGE; } - if (scan) + if (scan && !scanning) { set_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); - else + hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); + } else if (!scan && scanning) { set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); - - hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); + hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); + } } static void cancel_adv_timeout(struct hci_dev *hdev) @@ -1315,9 +1320,14 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) hdev->advertising_paused = true; hdev->advertising_old_state = old_state; - /* Disable page scan */ - page_scan = SCAN_DISABLED; - hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &page_scan); + + /* Disable page scan if enabled */ + if (test_bit(HCI_PSCAN, &hdev->flags)) { + page_scan = SCAN_DISABLED; + hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, + &page_scan); + set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); + } /* Disable LE passive scan if enabled */ if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { @@ -1328,9 +1338,6 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) /* Disable advertisement filters */ hci_req_add_set_adv_filter_enable(&req, false); - /* Mark task needing completion */ - set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); - /* Prevent disconnects from causing scanning to be re-enabled */ hdev->scanning_paused = true; @@ -1364,7 +1371,10 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) hdev->suspended = false; hdev->scanning_paused = false; + /* Clear any event filters and restore scan state */ hci_req_clear_event_filter(&req); + __hci_req_update_scan(&req); + /* Reset passive/background scanning to normal */ __hci_update_background_scan(&req); /* Enable all of the advertisement filters */ -- 2.30.1.766.gb4fecdf3b7-goog