Revert "BACKPORT: FROMGIT: Bluetooth: Fix Advertisement Monitor Suspend/Resume"
Reason for revert: Regression in wake on Bluetooth from suspend/resume.
This reverts commit 6a68352f71c92fb821fceddf94c055fbcdb86f40.
BUG=b:203008170
TEST=Manually do suspend/resume wake up test on dooly
Signed-off-by: Manish Mandlik <mmandlik@google.com>
Change-Id: Iee9f658862f513b5ce0d4154d7c504fa3d7712ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3243872
Tested-by: Manish Mandlik <mmandlik@chromium.org>
Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Commit-Queue: Manish Mandlik <mmandlik@chromium.org>
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index e26d40c..dea0d4f 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -1290,24 +1290,21 @@
}
}
-static void hci_req_prepare_adv_monitor_suspend(struct hci_request *req,
- bool suspending)
+static void hci_req_add_set_adv_filter_enable(struct hci_request *req,
+ bool enable)
{
struct hci_dev *hdev = req->hdev;
switch (hci_get_adv_monitor_offload_ext(hdev)) {
case HCI_ADV_MONITOR_EXT_MSFT:
- if (suspending)
- msft_suspend(hdev);
- else
- msft_resume(hdev);
+ msft_req_add_set_filter_enable(req, enable);
break;
default:
return;
}
/* No need to block when enabling since it's on resume path */
- if (hdev->suspended && suspending)
+ if (hdev->suspended && !enable)
set_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks);
}
@@ -1374,7 +1371,7 @@
}
/* Disable advertisement filters */
- hci_req_prepare_adv_monitor_suspend(&req, true);
+ hci_req_add_set_adv_filter_enable(&req, false);
/* Prevent disconnects from causing scanning to be re-enabled */
hdev->scanning_paused = true;
@@ -1416,7 +1413,7 @@
/* Reset passive/background scanning to normal */
__hci_update_background_scan(&req);
/* Enable all of the advertisement filters */
- hci_req_prepare_adv_monitor_suspend(&req, false);
+ hci_req_add_set_adv_filter_enable(&req, true);
/* Unpause directed advertising */
hdev->advertising_paused = false;
diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c
index d7796a5..d1de65a 100644
--- a/net/bluetooth/msft.c
+++ b/net/bluetooth/msft.c
@@ -94,14 +94,11 @@
__u16 pending_add_handle;
__u16 pending_remove_handle;
__u8 reregistering;
- __u8 suspending;
__u8 filter_enabled;
};
static int __msft_add_monitor_pattern(struct hci_dev *hdev,
struct adv_monitor *monitor);
-static int __msft_remove_monitor(struct hci_dev *hdev,
- struct adv_monitor *monitor, u16 handle);
bool msft_monitor_supported(struct hci_dev *hdev)
{
@@ -154,7 +151,7 @@
}
/* This function requires the caller holds hdev->lock */
-static void reregister_monitor(struct hci_dev *hdev, int handle)
+static void reregister_monitor_on_restart(struct hci_dev *hdev, int handle)
{
struct adv_monitor *monitor;
struct msft_data *msft = hdev->msft_data;
@@ -182,69 +179,6 @@
}
}
-/* This function requires the caller holds hdev->lock */
-static void remove_monitor_on_suspend(struct hci_dev *hdev, int handle)
-{
- struct adv_monitor *monitor;
- struct msft_data *msft = hdev->msft_data;
- int err;
-
- while (1) {
- monitor = idr_get_next(&hdev->adv_monitors_idr, &handle);
- if (!monitor) {
- /* All monitors have been removed */
- msft->suspending = false;
- hci_update_background_scan(hdev);
- return;
- }
-
- msft->pending_remove_handle = (u16)handle;
- err = __msft_remove_monitor(hdev, monitor, handle);
-
- /* If success, return and wait for monitor removed callback */
- if (!err)
- return;
-
- /* Otherwise free the monitor and keep removing */
- hci_free_adv_monitor(hdev, monitor);
- handle++;
- }
-}
-
-/* This function requires the caller holds hdev->lock */
-void msft_suspend(struct hci_dev *hdev)
-{
- struct msft_data *msft = hdev->msft_data;
-
- if (!msft)
- return;
-
- if (msft_monitor_supported(hdev)) {
- msft->suspending = true;
- /* Quitely remove all monitors on suspend to avoid waking up
- * the system.
- */
- remove_monitor_on_suspend(hdev, 0);
- }
-}
-
-/* This function requires the caller holds hdev->lock */
-void msft_resume(struct hci_dev *hdev)
-{
- struct msft_data *msft = hdev->msft_data;
-
- if (!msft)
- return;
-
- if (msft_monitor_supported(hdev)) {
- msft->reregistering = true;
- /* Monitors are removed on suspend, so we need to add all
- * monitors on resume.
- */
- reregister_monitor(hdev, 0);
- }
-}
-
void msft_do_open(struct hci_dev *hdev)
{
struct msft_data *msft = hdev->msft_data;
@@ -277,7 +211,7 @@
/* Monitors get removed on power off, so we need to explicitly
* tell the controller to re-monitor.
*/
- reregister_monitor(hdev, 0);
+ reregister_monitor_on_restart(hdev, 0);
}
}
@@ -445,7 +379,8 @@
/* If in restart/reregister sequence, keep registering. */
if (msft->reregistering)
- reregister_monitor(hdev, msft->pending_add_handle + 1);
+ reregister_monitor_on_restart(hdev,
+ msft->pending_add_handle + 1);
hci_dev_unlock(hdev);
@@ -482,25 +417,13 @@
if (handle_data) {
monitor = idr_find(&hdev->adv_monitors_idr,
handle_data->mgmt_handle);
-
- if (monitor && monitor->state == ADV_MONITOR_STATE_OFFLOADED)
- monitor->state = ADV_MONITOR_STATE_REGISTERED;
-
- /* Do not free the monitor if it is being removed due to
- * suspend. It will be re-monitored on resume.
- */
- if (monitor && !msft->suspending)
+ if (monitor)
hci_free_adv_monitor(hdev, monitor);
list_del(&handle_data->list);
kfree(handle_data);
}
- /* If in suspend/remove sequence, keep removing. */
- if (msft->suspending)
- remove_monitor_on_suspend(hdev,
- msft->pending_remove_handle + 1);
-
/* If remove all monitors is required, we need to continue the process
* here because the earlier it was paused when waiting for the
* response from controller.
@@ -519,8 +442,7 @@
hci_dev_unlock(hdev);
done:
- if (!msft->suspending)
- hci_remove_adv_monitor_complete(hdev, status);
+ hci_remove_adv_monitor_complete(hdev, status);
}
static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev,
@@ -653,15 +575,15 @@
if (!msft)
return -EOPNOTSUPP;
- if (msft->reregistering || msft->suspending)
+ if (msft->reregistering)
return -EBUSY;
return __msft_add_monitor_pattern(hdev, monitor);
}
/* This function requires the caller holds hdev->lock */
-static int __msft_remove_monitor(struct hci_dev *hdev,
- struct adv_monitor *monitor, u16 handle)
+int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,
+ u16 handle)
{
struct msft_cp_le_cancel_monitor_advertisement cp;
struct msft_monitor_advertisement_handle_data *handle_data;
@@ -669,6 +591,12 @@
struct msft_data *msft = hdev->msft_data;
int err = 0;
+ if (!msft)
+ return -EOPNOTSUPP;
+
+ if (msft->reregistering)
+ return -EBUSY;
+
handle_data = msft_find_handle_data(hdev, monitor->handle, true);
/* If no matched handle, just remove without telling controller */
@@ -688,21 +616,6 @@
return err;
}
-/* This function requires the caller holds hdev->lock */
-int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,
- u16 handle)
-{
- struct msft_data *msft = hdev->msft_data;
-
- if (!msft)
- return -EOPNOTSUPP;
-
- if (msft->reregistering || msft->suspending)
- return -EBUSY;
-
- return __msft_remove_monitor(hdev, monitor, handle);
-}
-
void msft_req_add_set_filter_enable(struct hci_request *req, bool enable)
{
struct hci_dev *hdev = req->hdev;
diff --git a/net/bluetooth/msft.h b/net/bluetooth/msft.h
index cd04f6d..c20eb9f 100644
--- a/net/bluetooth/msft.h
+++ b/net/bluetooth/msft.h
@@ -24,8 +24,6 @@
u16 handle);
void msft_req_add_set_filter_enable(struct hci_request *req, bool enable);
int msft_set_filter_enable(struct hci_dev *hdev, bool enable);
-void msft_suspend(struct hci_dev *hdev);
-void msft_resume(struct hci_dev *hdev);
#else
@@ -60,7 +58,4 @@
return -EOPNOTSUPP;
}
-static inline void msft_suspend(struct hci_dev *hdev) {}
-static inline void msft_resume(struct hci_dev *hdev) {}
-
#endif