linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup
@ 2020-05-13  2:19 Abhishek Pandit-Subedi
  2020-05-13  2:19 ` [PATCH 1/3] Bluetooth: Rename BT_SUSPEND_COMPLETE Abhishek Pandit-Subedi
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-05-13  2:19 UTC (permalink / raw)
  To: marcel, linux-bluetooth
  Cc: chromeos-bluetooth-upstreaming, Abhishek Pandit-Subedi,
	David S. Miller, Johan Hedberg, netdev, linux-kernel,
	Jakub Kicinski


Hi linux-bluetooth,

This patch series adds a hook to prevent Bluetooth from scanning during
suspend if it is not configured to wake up. It's not always clear who
the wakeup owner is from looking at hdev->dev so we need the driver to
inform us whether to set up scanning.

By default, when no `prevent_wake` hook is implemented, we always
configure scanning for wake-up.

Thanks
Abhishek



Abhishek Pandit-Subedi (3):
  Bluetooth: Rename BT_SUSPEND_COMPLETE
  Bluetooth: Add hook for driver to prevent wake from suspend
  Bluetooth: btusb: Implement hdev->prevent_wake

 drivers/bluetooth/btusb.c        | 8 ++++++++
 include/net/bluetooth/hci_core.h | 3 ++-
 net/bluetooth/hci_core.c         | 8 +++++---
 net/bluetooth/hci_request.c      | 2 +-
 4 files changed, 16 insertions(+), 5 deletions(-)

-- 
2.26.2.645.ge9eca65c58-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] Bluetooth: Rename BT_SUSPEND_COMPLETE
  2020-05-13  2:19 [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Abhishek Pandit-Subedi
@ 2020-05-13  2:19 ` Abhishek Pandit-Subedi
  2020-05-13  2:19 ` [PATCH 2/3] Bluetooth: Add hook for driver to prevent wake from suspend Abhishek Pandit-Subedi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-05-13  2:19 UTC (permalink / raw)
  To: marcel, linux-bluetooth
  Cc: chromeos-bluetooth-upstreaming, Abhishek Pandit-Subedi,
	Alain Michaud, David S. Miller, Johan Hedberg, netdev,
	linux-kernel, Jakub Kicinski

Renamed BT_SUSPEND_COMPLETE to BT_SUSPEND_CONFIGURE_WAKE since it sets
up the event filter and whitelist for wake-up.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Alain Michaud <alainm@chromium.org>
---

 include/net/bluetooth/hci_core.h | 2 +-
 net/bluetooth/hci_core.c         | 2 +-
 net/bluetooth/hci_request.c      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 0c7f3ad766652..869ee2b30a4c1 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -110,7 +110,7 @@ enum suspend_tasks {
 enum suspended_state {
 	BT_RUNNING = 0,
 	BT_SUSPEND_DISCONNECT,
-	BT_SUSPEND_COMPLETE,
+	BT_SUSPEND_CONFIGURE_WAKE,
 };
 
 struct hci_conn_hash {
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 51d3992732762..de1f4e72ec065 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3353,7 +3353,7 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action,
 		/* Only configure whitelist if disconnect succeeded */
 		if (!ret)
 			ret = hci_change_suspend_state(hdev,
-						       BT_SUSPEND_COMPLETE);
+						BT_SUSPEND_CONFIGURE_WAKE);
 	} else if (action == PM_POST_SUSPEND) {
 		ret = hci_change_suspend_state(hdev, BT_RUNNING);
 	}
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 3f470f0e432c7..88941a2131c4d 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -1090,7 +1090,7 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next)
 				   disconnect_counter);
 			set_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks);
 		}
-	} else if (next == BT_SUSPEND_COMPLETE) {
+	} else if (next == BT_SUSPEND_CONFIGURE_WAKE) {
 		/* Unpause to take care of updating scanning params */
 		hdev->scanning_paused = false;
 		/* Enable event filter for paired devices */
-- 
2.26.2.645.ge9eca65c58-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] Bluetooth: Add hook for driver to prevent wake from suspend
  2020-05-13  2:19 [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Abhishek Pandit-Subedi
  2020-05-13  2:19 ` [PATCH 1/3] Bluetooth: Rename BT_SUSPEND_COMPLETE Abhishek Pandit-Subedi
@ 2020-05-13  2:19 ` Abhishek Pandit-Subedi
  2020-05-13  2:19 ` [PATCH 3/3] Bluetooth: btusb: Implement hdev->prevent_wake Abhishek Pandit-Subedi
  2020-05-13  7:12 ` [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Marcel Holtmann
  3 siblings, 0 replies; 5+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-05-13  2:19 UTC (permalink / raw)
  To: marcel, linux-bluetooth
  Cc: chromeos-bluetooth-upstreaming, Abhishek Pandit-Subedi,
	Alain Michaud, David S. Miller, Johan Hedberg, netdev,
	linux-kernel, Jakub Kicinski

Let drivers have a hook to disable configuring scanning during suspend.
Drivers should use the device_may_wakeup function call to determine
whether hci should be configured for wakeup.

For example, an implementation for btusb may look like the following:

  bool btusb_prevent_wake(struct hci_dev *hdev)
  {
        struct btusb_data *data = hci_get_drvdata(hdev);
        return !device_may_wakeup(&data->udev->dev);
  }

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Alain Michaud <alainm@chromium.org>
---

 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_core.c         | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 869ee2b30a4c1..5dcf85f186c6c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -503,6 +503,7 @@ struct hci_dev {
 	int (*set_diag)(struct hci_dev *hdev, bool enable);
 	int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 	void (*cmd_timeout)(struct hci_dev *hdev);
+	bool (*prevent_wake)(struct hci_dev *hdev);
 };
 
 #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index de1f4e72ec065..dbe2d79f233fb 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3350,8 +3350,10 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action,
 		 */
 		ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT);
 
-		/* Only configure whitelist if disconnect succeeded */
-		if (!ret)
+		/* Only configure whitelist 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);
 	} else if (action == PM_POST_SUSPEND) {
-- 
2.26.2.645.ge9eca65c58-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] Bluetooth: btusb: Implement hdev->prevent_wake
  2020-05-13  2:19 [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Abhishek Pandit-Subedi
  2020-05-13  2:19 ` [PATCH 1/3] Bluetooth: Rename BT_SUSPEND_COMPLETE Abhishek Pandit-Subedi
  2020-05-13  2:19 ` [PATCH 2/3] Bluetooth: Add hook for driver to prevent wake from suspend Abhishek Pandit-Subedi
@ 2020-05-13  2:19 ` Abhishek Pandit-Subedi
  2020-05-13  7:12 ` [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Marcel Holtmann
  3 siblings, 0 replies; 5+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-05-13  2:19 UTC (permalink / raw)
  To: marcel, linux-bluetooth
  Cc: chromeos-bluetooth-upstreaming, Abhishek Pandit-Subedi,
	Alain Michaud, Johan Hedberg, linux-kernel

Implement the prevent_wake hook by checking device_may_wakeup on the usb
interface. This prevents the Bluetooth core from enabling scanning when
the device isn't expected to wake from suspend.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Alain Michaud <alainm@chromium.org>
---

 drivers/bluetooth/btusb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 8ae3ad7a60131..c17359c0e3201 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -3698,6 +3698,13 @@ static void btusb_check_needs_reset_resume(struct usb_interface *intf)
 		interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
 }
 
+static bool btusb_prevent_wake(struct hci_dev *hdev)
+{
+	struct btusb_data *data = hci_get_drvdata(hdev);
+
+	return !device_may_wakeup(&data->udev->dev);
+}
+
 static int btusb_probe(struct usb_interface *intf,
 		       const struct usb_device_id *id)
 {
@@ -3831,6 +3838,7 @@ static int btusb_probe(struct usb_interface *intf,
 	hdev->flush  = btusb_flush;
 	hdev->send   = btusb_send_frame;
 	hdev->notify = btusb_notify;
+	hdev->prevent_wake = btusb_prevent_wake;
 
 #ifdef CONFIG_PM
 	err = btusb_config_oob_wake(hdev);
-- 
2.26.2.645.ge9eca65c58-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup
  2020-05-13  2:19 [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Abhishek Pandit-Subedi
                   ` (2 preceding siblings ...)
  2020-05-13  2:19 ` [PATCH 3/3] Bluetooth: btusb: Implement hdev->prevent_wake Abhishek Pandit-Subedi
@ 2020-05-13  7:12 ` Marcel Holtmann
  3 siblings, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2020-05-13  7:12 UTC (permalink / raw)
  To: Abhishek Pandit-Subedi
  Cc: BlueZ, ChromeOS Bluetooth Upstreaming, David S. Miller,
	Johan Hedberg, netdev, linux-kernel, Jakub Kicinski

Hi Abhishek,

> This patch series adds a hook to prevent Bluetooth from scanning during
> suspend if it is not configured to wake up. It's not always clear who
> the wakeup owner is from looking at hdev->dev so we need the driver to
> inform us whether to set up scanning.
> 
> By default, when no `prevent_wake` hook is implemented, we always
> configure scanning for wake-up.
> 
> Thanks
> Abhishek
> 
> 
> 
> Abhishek Pandit-Subedi (3):
>  Bluetooth: Rename BT_SUSPEND_COMPLETE
>  Bluetooth: Add hook for driver to prevent wake from suspend
>  Bluetooth: btusb: Implement hdev->prevent_wake
> 
> drivers/bluetooth/btusb.c        | 8 ++++++++
> include/net/bluetooth/hci_core.h | 3 ++-
> net/bluetooth/hci_core.c         | 8 +++++---
> net/bluetooth/hci_request.c      | 2 +-
> 4 files changed, 16 insertions(+), 5 deletions(-)

all 3 patches have been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-13  7:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13  2:19 [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Abhishek Pandit-Subedi
2020-05-13  2:19 ` [PATCH 1/3] Bluetooth: Rename BT_SUSPEND_COMPLETE Abhishek Pandit-Subedi
2020-05-13  2:19 ` [PATCH 2/3] Bluetooth: Add hook for driver to prevent wake from suspend Abhishek Pandit-Subedi
2020-05-13  2:19 ` [PATCH 3/3] Bluetooth: btusb: Implement hdev->prevent_wake Abhishek Pandit-Subedi
2020-05-13  7:12 ` [PATCH 0/3] Bluetooth: Prevent scanning when device is not configured for wakeup Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).