linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag
@ 2021-07-23 11:31 Archie Pusaka
  2021-07-23 11:31 ` [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled Archie Pusaka
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Archie Pusaka @ 2021-07-23 11:31 UTC (permalink / raw)
  To: linux-bluetooth, Marcel Holtmann
  Cc: CrosBT Upstreaming, Archie Pusaka, Abhishek Pandit-Subedi,
	Hilda Wu, Johan Hedberg, Luiz Augusto von Dentz, linux-kernel

From: Archie Pusaka <apusaka@chromium.org>

Some RTL chips resets the FW on suspend, so wakeup is disabled on
those chips. This patch introduces this WAKEUP_DISABLE flag so that
chips that doesn't reset FW on suspend can leave the flag unset and
is allowed to wake the host.

This patch also left RTL8822 WAKEUP_DISABLE flag unset, therefore
allowing it to wake the host, and preventing reprobing on resume.

Signed-off-by: Archie Pusaka <apusaka@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Hilda Wu <hildawu@realtek.com>

---

Changes in v3:
* Rebasing

Changes in v2:
* Remove unnecessary variable

 drivers/bluetooth/hci_h5.c | 83 +++++++++++++++++++++++++++-----------
 1 file changed, 59 insertions(+), 24 deletions(-)

diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index 7b985c7cd26d..fd672111a048 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -51,8 +51,9 @@
 
 /* H5 state flags */
 enum {
-	H5_RX_ESC,	/* SLIP escape mode */
-	H5_TX_ACK_REQ,	/* Pending ack to send */
+	H5_RX_ESC,		/* SLIP escape mode */
+	H5_TX_ACK_REQ,		/* Pending ack to send */
+	H5_WAKEUP_DISABLE,	/* Device cannot wake host */
 };
 
 struct h5 {
@@ -97,6 +98,10 @@ struct h5 {
 	struct gpio_desc *device_wake_gpio;
 };
 
+enum h5_driver_info {
+	H5_INFO_WAKEUP_DISABLE = BIT(0),
+};
+
 struct h5_vnd {
 	int (*setup)(struct h5 *h5);
 	void (*open)(struct h5 *h5);
@@ -106,6 +111,11 @@ struct h5_vnd {
 	const struct acpi_gpio_mapping *acpi_gpio_map;
 };
 
+struct h5_device_data {
+	uint32_t driver_info;
+	struct h5_vnd *vnd;
+};
+
 static void h5_reset_rx(struct h5 *h5);
 
 static void h5_link_control(struct hci_uart *hu, const void *data, size_t len)
@@ -791,6 +801,8 @@ static int h5_serdev_probe(struct serdev_device *serdev)
 {
 	struct device *dev = &serdev->dev;
 	struct h5 *h5;
+	const struct h5_device_data *data;
+	int err;
 
 	h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL);
 	if (!h5)
@@ -807,20 +819,19 @@ static int h5_serdev_probe(struct serdev_device *serdev)
 		if (!match)
 			return -ENODEV;
 
-		h5->vnd = (const struct h5_vnd *)match->driver_data;
+		data = (const struct h5_device_data *)match->driver_data;
+		h5->vnd = data->vnd;
 		h5->id  = (char *)match->id;
 
 		if (h5->vnd->acpi_gpio_map)
 			devm_acpi_dev_add_driver_gpios(dev,
 						       h5->vnd->acpi_gpio_map);
 	} else {
-		const void *data;
-
 		data = of_device_get_match_data(dev);
 		if (!data)
 			return -ENODEV;
 
-		h5->vnd = (const struct h5_vnd *)data;
+		h5->vnd = data->vnd;
 	}
 
 
@@ -833,7 +844,14 @@ static int h5_serdev_probe(struct serdev_device *serdev)
 	if (IS_ERR(h5->device_wake_gpio))
 		return PTR_ERR(h5->device_wake_gpio);
 
-	return hci_uart_register_device(&h5->serdev_hu, &h5p);
+	err = hci_uart_register_device(&h5->serdev_hu, &h5p);
+	if (err)
+		return err;
+
+	if (data->driver_info & H5_INFO_WAKEUP_DISABLE)
+		set_bit(H5_WAKEUP_DISABLE, &h5->flags);
+
+	return 0;
 }
 
 static void h5_serdev_remove(struct serdev_device *serdev)
@@ -921,7 +939,8 @@ static void h5_btrtl_open(struct h5 *h5)
 	 * done by the hci_suspend_notifier is not necessary; it actually causes
 	 * delays and a bunch of errors to get logged, so disable it.
 	 */
-	set_bit(HCI_UART_NO_SUSPEND_NOTIFIER, &h5->hu->flags);
+	if (test_bit(H5_WAKEUP_DISABLE, &h5->flags))
+		set_bit(HCI_UART_NO_SUSPEND_NOTIFIER, &h5->hu->flags);
 
 	/* Devices always start with these fixed parameters */
 	serdev_device_set_flow_control(h5->hu->serdev, false);
@@ -942,15 +961,18 @@ static void h5_btrtl_close(struct h5 *h5)
 
 /* Suspend/resume support. On many devices the RTL BT device loses power during
  * suspend/resume, causing it to lose its firmware and all state. So we simply
- * turn it off on suspend and reprobe on resume.  This mirrors how RTL devices
- * are handled in the USB driver, where the USB_QUIRK_RESET_RESUME is used which
+ * turn it off on suspend and reprobe on resume. This mirrors how RTL devices
+ * are handled in the USB driver, where the BTUSB_WAKEUP_DISABLE is used which
  * also causes a reprobe on resume.
  */
 static int h5_btrtl_suspend(struct h5 *h5)
 {
 	serdev_device_set_flow_control(h5->hu->serdev, false);
 	gpiod_set_value_cansleep(h5->device_wake_gpio, 0);
-	gpiod_set_value_cansleep(h5->enable_gpio, 0);
+
+	if (test_bit(H5_WAKEUP_DISABLE, &h5->flags))
+		gpiod_set_value_cansleep(h5->enable_gpio, 0);
+
 	return 0;
 }
 
@@ -976,17 +998,21 @@ static void h5_btrtl_reprobe_worker(struct work_struct *work)
 
 static int h5_btrtl_resume(struct h5 *h5)
 {
-	struct h5_btrtl_reprobe *reprobe;
+	if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) {
+		struct h5_btrtl_reprobe *reprobe;
 
-	reprobe = kzalloc(sizeof(*reprobe), GFP_KERNEL);
-	if (!reprobe)
-		return -ENOMEM;
+		reprobe = kzalloc(sizeof(*reprobe), GFP_KERNEL);
+		if (!reprobe)
+			return -ENOMEM;
 
-	__module_get(THIS_MODULE);
+		__module_get(THIS_MODULE);
 
-	INIT_WORK(&reprobe->work, h5_btrtl_reprobe_worker);
-	reprobe->dev = get_device(&h5->hu->serdev->dev);
-	queue_work(system_long_wq, &reprobe->work);
+		INIT_WORK(&reprobe->work, h5_btrtl_reprobe_worker);
+		reprobe->dev = get_device(&h5->hu->serdev->dev);
+		queue_work(system_long_wq, &reprobe->work);
+	} else {
+		gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
+	}
 	return 0;
 }
 
@@ -1008,13 +1034,22 @@ static struct h5_vnd rtl_vnd = {
 	.resume		= h5_btrtl_resume,
 	.acpi_gpio_map	= acpi_btrtl_gpios,
 };
+
+static const struct h5_device_data h5_data_rtl8822cs = {
+	.vnd = &rtl_vnd,
+};
+
+static const struct h5_device_data h5_data_rtl8723bs = {
+	.driver_info = H5_INFO_WAKEUP_DISABLE,
+	.vnd = &rtl_vnd,
+};
 #endif
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id h5_acpi_match[] = {
 #ifdef CONFIG_BT_HCIUART_RTL
-	{ "OBDA0623", (kernel_ulong_t)&rtl_vnd },
-	{ "OBDA8723", (kernel_ulong_t)&rtl_vnd },
+	{ "OBDA0623", (kernel_ulong_t)&h5_data_rtl8723bs },
+	{ "OBDA8723", (kernel_ulong_t)&h5_data_rtl8723bs },
 #endif
 	{ },
 };
@@ -1028,11 +1063,11 @@ static const struct dev_pm_ops h5_serdev_pm_ops = {
 static const struct of_device_id rtl_bluetooth_of_match[] = {
 #ifdef CONFIG_BT_HCIUART_RTL
 	{ .compatible = "realtek,rtl8822cs-bt",
-	  .data = (const void *)&rtl_vnd },
+	  .data = (const void *)&h5_data_rtl8822cs },
 	{ .compatible = "realtek,rtl8723bs-bt",
-	  .data = (const void *)&rtl_vnd },
+	  .data = (const void *)&h5_data_rtl8723bs },
 	{ .compatible = "realtek,rtl8723ds-bt",
-	  .data = (const void *)&rtl_vnd },
+	  .data = (const void *)&h5_data_rtl8723bs },
 #endif
 	{ },
 };
-- 
2.32.0.432.gabb21c7263-goog


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

* [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled
  2021-07-23 11:31 [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Archie Pusaka
@ 2021-07-23 11:31 ` Archie Pusaka
  2021-07-23 12:12   ` Marcel Holtmann
  2021-07-23 11:31 ` [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend Archie Pusaka
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Archie Pusaka @ 2021-07-23 11:31 UTC (permalink / raw)
  To: linux-bluetooth, Marcel Holtmann
  Cc: CrosBT Upstreaming, Archie Pusaka, Abhishek Pandit-Subedi,
	Hilda Wu, Johan Hedberg, Luiz Augusto von Dentz, linux-kernel

From: Archie Pusaka <apusaka@chromium.org>

For chips that doesn't reset on suspend, we need to provide the correct
value of flow_control when it resumes. Therefore, store the flow
control value when reading from the config file to be reused upon
suspend.

Signed-off-by: Archie Pusaka <apusaka@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Hilda Wu <hildawu@realtek.com>

---

(no changes since v1)

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

diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index fd672111a048..cbc63b057f33 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -54,6 +54,7 @@ enum {
 	H5_RX_ESC,		/* SLIP escape mode */
 	H5_TX_ACK_REQ,		/* Pending ack to send */
 	H5_WAKEUP_DISABLE,	/* Device cannot wake host */
+	H5_HW_FLOW_CONTROL,	/* Use HW flow control */
 };
 
 struct h5 {
@@ -920,6 +921,9 @@ static int h5_btrtl_setup(struct h5 *h5)
 	serdev_device_set_baudrate(h5->hu->serdev, controller_baudrate);
 	serdev_device_set_flow_control(h5->hu->serdev, flow_control);
 
+	if (flow_control)
+		set_bit(H5_HW_FLOW_CONTROL, &h5->flags);
+
 	err = btrtl_download_firmware(h5->hu->hdev, btrtl_dev);
 	/* Give the device some time before the hci-core sends it a reset */
 	usleep_range(10000, 20000);
@@ -1012,7 +1016,11 @@ static int h5_btrtl_resume(struct h5 *h5)
 		queue_work(system_long_wq, &reprobe->work);
 	} else {
 		gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
+
+		if (test_bit(H5_HW_FLOW_CONTROL, &h5->flags))
+			serdev_device_set_flow_control(h5->hu->serdev, true);
 	}
+
 	return 0;
 }
 
-- 
2.32.0.432.gabb21c7263-goog


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

* [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend
  2021-07-23 11:31 [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Archie Pusaka
  2021-07-23 11:31 ` [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled Archie Pusaka
@ 2021-07-23 11:31 ` Archie Pusaka
  2021-07-23 12:11   ` Marcel Holtmann
  2021-10-27 22:23   ` Ondřej Jirman
  2021-07-23 12:12 ` [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Marcel Holtmann
  2021-07-27  2:09 ` [v3,1/3] " bluez.test.bot
  3 siblings, 2 replies; 11+ messages in thread
From: Archie Pusaka @ 2021-07-23 11:31 UTC (permalink / raw)
  To: linux-bluetooth, Marcel Holtmann
  Cc: CrosBT Upstreaming, Archie Pusaka, Abhishek Pandit-Subedi,
	Hilda Wu, Johan Hedberg, Luiz Augusto von Dentz, linux-kernel

From: Archie Pusaka <apusaka@chromium.org>

This patch allows the controller to suspend after a short period of
inactivity.

Signed-off-by: Archie Pusaka <apusaka@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Reviewed-by: Hilda Wu <hildawu@realtek.com>

---

Changes in v3:
* Reordering #include

 drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index cbc63b057f33..0c0dedece59c 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -12,6 +12,7 @@
 #include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
 #include <linux/of_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/serdev.h>
 #include <linux/skbuff.h>
 
@@ -21,6 +22,8 @@
 #include "btrtl.h"
 #include "hci_uart.h"
 
+#define SUSPEND_TIMEOUT_MS	6000
+
 #define HCI_3WIRE_ACK_PKT	0
 #define HCI_3WIRE_LINK_PKT	15
 
@@ -584,6 +587,10 @@ static int h5_recv(struct hci_uart *hu, const void *data, int count)
 		count -= processed;
 	}
 
+	pm_runtime_get(&hu->serdev->dev);
+	pm_runtime_mark_last_busy(&hu->serdev->dev);
+	pm_runtime_put_autosuspend(&hu->serdev->dev);
+
 	return 0;
 }
 
@@ -620,6 +627,10 @@ static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 		break;
 	}
 
+	pm_runtime_get_sync(&hu->serdev->dev);
+	pm_runtime_mark_last_busy(&hu->serdev->dev);
+	pm_runtime_put_autosuspend(&hu->serdev->dev);
+
 	return 0;
 }
 
@@ -951,6 +962,12 @@ static void h5_btrtl_open(struct h5 *h5)
 	serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN);
 	serdev_device_set_baudrate(h5->hu->serdev, 115200);
 
+	pm_runtime_set_active(&h5->hu->serdev->dev);
+	pm_runtime_use_autosuspend(&h5->hu->serdev->dev);
+	pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev,
+					 SUSPEND_TIMEOUT_MS);
+	pm_runtime_enable(&h5->hu->serdev->dev);
+
 	/* The controller needs up to 500ms to wakeup */
 	gpiod_set_value_cansleep(h5->enable_gpio, 1);
 	gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
@@ -959,6 +976,8 @@ static void h5_btrtl_open(struct h5 *h5)
 
 static void h5_btrtl_close(struct h5 *h5)
 {
+	pm_runtime_disable(&h5->hu->serdev->dev);
+
 	gpiod_set_value_cansleep(h5->device_wake_gpio, 0);
 	gpiod_set_value_cansleep(h5->enable_gpio, 0);
 }
@@ -1066,6 +1085,7 @@ MODULE_DEVICE_TABLE(acpi, h5_acpi_match);
 
 static const struct dev_pm_ops h5_serdev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(h5_serdev_suspend, h5_serdev_resume)
+	SET_RUNTIME_PM_OPS(h5_serdev_suspend, h5_serdev_resume, NULL)
 };
 
 static const struct of_device_id rtl_bluetooth_of_match[] = {
-- 
2.32.0.432.gabb21c7263-goog


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

* Re: [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend
  2021-07-23 11:31 ` [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend Archie Pusaka
@ 2021-07-23 12:11   ` Marcel Holtmann
  2021-10-27 22:23   ` Ondřej Jirman
  1 sibling, 0 replies; 11+ messages in thread
From: Marcel Holtmann @ 2021-07-23 12:11 UTC (permalink / raw)
  To: Archie Pusaka
  Cc: linux-bluetooth, CrosBT Upstreaming, Archie Pusaka,
	Abhishek Pandit-Subedi, Hilda Wu, Johan Hedberg,
	Luiz Augusto von Dentz, linux-kernel

Hi Archie,

> This patch allows the controller to suspend after a short period of
> inactivity.
> 
> Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Reviewed-by: Hilda Wu <hildawu@realtek.com>
> 
> ---
> 
> Changes in v3:
> * Reordering #include
> 
> drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel


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

* Re: [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled
  2021-07-23 11:31 ` [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled Archie Pusaka
@ 2021-07-23 12:12   ` Marcel Holtmann
  0 siblings, 0 replies; 11+ messages in thread
From: Marcel Holtmann @ 2021-07-23 12:12 UTC (permalink / raw)
  To: Archie Pusaka
  Cc: linux-bluetooth, CrosBT Upstreaming, Archie Pusaka,
	Abhishek Pandit-Subedi, Hilda Wu, Johan Hedberg,
	Luiz Augusto von Dentz, linux-kernel

Hi Archie,

> For chips that doesn't reset on suspend, we need to provide the correct
> value of flow_control when it resumes. Therefore, store the flow
> control value when reading from the config file to be reused upon
> suspend.
> 
> Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Reviewed-by: Hilda Wu <hildawu@realtek.com>
> 
> ---
> 
> (no changes since v1)
> 
> drivers/bluetooth/hci_h5.c | 8 ++++++++
> 1 file changed, 8 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel


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

* Re: [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag
  2021-07-23 11:31 [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Archie Pusaka
  2021-07-23 11:31 ` [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled Archie Pusaka
  2021-07-23 11:31 ` [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend Archie Pusaka
@ 2021-07-23 12:12 ` Marcel Holtmann
  2021-07-27  2:09 ` [v3,1/3] " bluez.test.bot
  3 siblings, 0 replies; 11+ messages in thread
From: Marcel Holtmann @ 2021-07-23 12:12 UTC (permalink / raw)
  To: Archie Pusaka
  Cc: linux-bluetooth, CrosBT Upstreaming, Archie Pusaka,
	Abhishek Pandit-Subedi, Hilda Wu, Johan Hedberg,
	Luiz Augusto von Dentz, linux-kernel

Hi Archie,

> Some RTL chips resets the FW on suspend, so wakeup is disabled on
> those chips. This patch introduces this WAKEUP_DISABLE flag so that
> chips that doesn't reset FW on suspend can leave the flag unset and
> is allowed to wake the host.
> 
> This patch also left RTL8822 WAKEUP_DISABLE flag unset, therefore
> allowing it to wake the host, and preventing reprobing on resume.
> 
> Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Reviewed-by: Hilda Wu <hildawu@realtek.com>
> 
> ---
> 
> Changes in v3:
> * Rebasing
> 
> Changes in v2:
> * Remove unnecessary variable
> 
> drivers/bluetooth/hci_h5.c | 83 +++++++++++++++++++++++++++-----------
> 1 file changed, 59 insertions(+), 24 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


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

* RE: [v3,1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag
  2021-07-23 11:31 [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Archie Pusaka
                   ` (2 preceding siblings ...)
  2021-07-23 12:12 ` [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Marcel Holtmann
@ 2021-07-27  2:09 ` bluez.test.bot
  3 siblings, 0 replies; 11+ messages in thread
From: bluez.test.bot @ 2021-07-27  2:09 UTC (permalink / raw)
  To: linux-bluetooth, apusaka

[-- Attachment #1: Type: text/plain, Size: 2727 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=520317

---Test result---

Test Summary:
CheckPatch                    PASS      1.16 seconds
GitLint                       PASS      0.31 seconds
BuildKernel                   PASS      519.38 seconds
TestRunner: Setup             PASS      343.83 seconds
TestRunner: l2cap-tester      PASS      2.51 seconds
TestRunner: bnep-tester       PASS      1.99 seconds
TestRunner: mgmt-tester       PASS      30.69 seconds
TestRunner: rfcomm-tester     PASS      2.12 seconds
TestRunner: sco-tester        PASS      2.04 seconds
TestRunner: smp-tester        FAIL      2.11 seconds
TestRunner: userchan-tester   PASS      1.95 seconds

Details
##############################
Test: CheckPatch - PASS - 1.16 seconds
Run checkpatch.pl script with rule in .checkpatch.conf


##############################
Test: GitLint - PASS - 0.31 seconds
Run gitlint with rule in .gitlint


##############################
Test: BuildKernel - PASS - 519.38 seconds
Build Kernel with minimal configuration supports Bluetooth


##############################
Test: TestRunner: Setup - PASS - 343.83 seconds
Setup environment for running Test Runner


##############################
Test: TestRunner: l2cap-tester - PASS - 2.51 seconds
Run test-runner with l2cap-tester
Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: bnep-tester - PASS - 1.99 seconds
Run test-runner with bnep-tester
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: mgmt-tester - PASS - 30.69 seconds
Run test-runner with mgmt-tester
Total: 448, Passed: 445 (99.3%), Failed: 0, Not Run: 3

##############################
Test: TestRunner: rfcomm-tester - PASS - 2.12 seconds
Run test-runner with rfcomm-tester
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: sco-tester - PASS - 2.04 seconds
Run test-runner with sco-tester
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: smp-tester - FAIL - 2.11 seconds
Run test-runner with smp-tester
Total: 8, Passed: 7 (87.5%), Failed: 1, Not Run: 0

Failed Test Cases
SMP Client - SC Request 2                            Failed       0.022 seconds

##############################
Test: TestRunner: userchan-tester - PASS - 1.95 seconds
Run test-runner with userchan-tester
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth


[-- Attachment #2: l2cap-tester.log --]
[-- Type: application/octet-stream, Size: 44386 bytes --]

[-- Attachment #3: bnep-tester.log --]
[-- Type: application/octet-stream, Size: 3592 bytes --]

[-- Attachment #4: mgmt-tester.log --]
[-- Type: application/octet-stream, Size: 616863 bytes --]

[-- Attachment #5: rfcomm-tester.log --]
[-- Type: application/octet-stream, Size: 11713 bytes --]

[-- Attachment #6: sco-tester.log --]
[-- Type: application/octet-stream, Size: 9948 bytes --]

[-- Attachment #7: smp-tester.log --]
[-- Type: application/octet-stream, Size: 11741 bytes --]

[-- Attachment #8: userchan-tester.log --]
[-- Type: application/octet-stream, Size: 5490 bytes --]

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

* Re: [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend
  2021-07-23 11:31 ` [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend Archie Pusaka
  2021-07-23 12:11   ` Marcel Holtmann
@ 2021-10-27 22:23   ` Ondřej Jirman
  2021-10-27 23:47     ` Ondřej Jirman
  1 sibling, 1 reply; 11+ messages in thread
From: Ondřej Jirman @ 2021-10-27 22:23 UTC (permalink / raw)
  To: Archie Pusaka
  Cc: linux-bluetooth, Marcel Holtmann, CrosBT Upstreaming,
	Archie Pusaka, Abhishek Pandit-Subedi, Hilda Wu, Johan Hedberg,
	Luiz Augusto von Dentz, linux-kernel

Hello Archie,

On Fri, Jul 23, 2021 at 07:31:57PM +0800, Archie Pusaka wrote:
> From: Archie Pusaka <apusaka@chromium.org>
> 
> This patch allows the controller to suspend after a short period of
> inactivity.

I see this pattern in dmesg after this patch: (I've added printks
to many hci_h5 functions to see what's going on)

[  493.150325] h5_dequeue
[  493.150332] h5_dequeue
[  493.150336] h5_dequeue
[  493.150340] h5_dequeue
[  493.150370] h5_dequeue
[  493.150547] h5_recv
[  493.150863] h5_recv
[  493.150878] h5_dequeue
[  493.150885] h5_dequeue
[  493.150888] h5_dequeue
[  493.151315] h5_enqueue
[  493.151328] h5_dequeue
[  493.151350] h5_dequeue
[  493.151447] h5_dequeue
[  493.151612] h5_recv
[  493.151945] h5_recv
[  493.151961] h5_dequeue
[  493.151967] h5_dequeue
[  493.151970] h5_dequeue
[  495.171812] h5_flush
[  495.171845] h5_flush
[  499.267473] h5_serdev_suspend
[  499.267490] h5_btrtl_suspend
[  499.273784] h5_recv
[  499.273828] h5_serdev_resume
[  499.273833] h5_btrtl_resume
[  499.273837] h5_btrtl_resume / reprobe
[  499.273855] h5_btrtl_reprobe_worker
[  499.273913] h5_serdev_remove
[  499.274997] h5_close
[  499.275010] h5_btrtl_close
[  499.275624] h5_serdev_probe
[  499.276126] h5_open
[  499.276132] h5_btrtl_open
[  499.915820] h5_dequeue
[  499.915857] h5_dequeue
[  499.915863] h5_dequeue
[  499.916212] h5_dequeue
[  499.919643] h5_recv
[  499.919675] h5_dequeue
[  499.919682] h5_dequeue
[  499.919687] h5_dequeue
[  499.919692] h5_dequeue

repeating ad nauseam every 6s.

Basically bluetooth device reprobes every 6s. Looks like h5_recv call
after h5_btrtl_suspend wakes the device immediately after suspend.

(there are no users of bluetooth in my userspace) I'd expect the
device to stay suspended after suspend.

I have some extra patches to support 8723cs but nothing that
would affect this codepath. https://megous.com/git/linux/log/?h=bt-5.15

I assume it will have the same behavior with 8723bs which is already
mainline. I guess this issue is specific to devices with H5_INFO_WAKEUP_DISABLE
flag set.

Do you have any ideas?

kind regards,
	o.


> Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Reviewed-by: Hilda Wu <hildawu@realtek.com>
> 
> ---
> 
> Changes in v3:
> * Reordering #include
> 
>  drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
> index cbc63b057f33..0c0dedece59c 100644
> --- a/drivers/bluetooth/hci_h5.c
> +++ b/drivers/bluetooth/hci_h5.c
> @@ -12,6 +12,7 @@
>  #include <linux/kernel.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/of_device.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/serdev.h>
>  #include <linux/skbuff.h>
>  
> @@ -21,6 +22,8 @@
>  #include "btrtl.h"
>  #include "hci_uart.h"
>  
> +#define SUSPEND_TIMEOUT_MS	6000
> +
>  #define HCI_3WIRE_ACK_PKT	0
>  #define HCI_3WIRE_LINK_PKT	15
>  
> @@ -584,6 +587,10 @@ static int h5_recv(struct hci_uart *hu, const void *data, int count)
>  		count -= processed;
>  	}
>  
> +	pm_runtime_get(&hu->serdev->dev);
> +	pm_runtime_mark_last_busy(&hu->serdev->dev);
> +	pm_runtime_put_autosuspend(&hu->serdev->dev);
> +
>  	return 0;
>  }
>  
> @@ -620,6 +627,10 @@ static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
>  		break;
>  	}
>  
> +	pm_runtime_get_sync(&hu->serdev->dev);
> +	pm_runtime_mark_last_busy(&hu->serdev->dev);
> +	pm_runtime_put_autosuspend(&hu->serdev->dev);
> +
>  	return 0;
>  }
>  
> @@ -951,6 +962,12 @@ static void h5_btrtl_open(struct h5 *h5)
>  	serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN);
>  	serdev_device_set_baudrate(h5->hu->serdev, 115200);
>  
> +	pm_runtime_set_active(&h5->hu->serdev->dev);
> +	pm_runtime_use_autosuspend(&h5->hu->serdev->dev);
> +	pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev,
> +					 SUSPEND_TIMEOUT_MS);
> +	pm_runtime_enable(&h5->hu->serdev->dev);
> +
>  	/* The controller needs up to 500ms to wakeup */
>  	gpiod_set_value_cansleep(h5->enable_gpio, 1);
>  	gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
> @@ -959,6 +976,8 @@ static void h5_btrtl_open(struct h5 *h5)
>  
>  static void h5_btrtl_close(struct h5 *h5)
>  {
> +	pm_runtime_disable(&h5->hu->serdev->dev);
> +
>  	gpiod_set_value_cansleep(h5->device_wake_gpio, 0);
>  	gpiod_set_value_cansleep(h5->enable_gpio, 0);
>  }
> @@ -1066,6 +1085,7 @@ MODULE_DEVICE_TABLE(acpi, h5_acpi_match);
>  
>  static const struct dev_pm_ops h5_serdev_pm_ops = {
>  	SET_SYSTEM_SLEEP_PM_OPS(h5_serdev_suspend, h5_serdev_resume)
> +	SET_RUNTIME_PM_OPS(h5_serdev_suspend, h5_serdev_resume, NULL)
>  };
>  
>  static const struct of_device_id rtl_bluetooth_of_match[] = {
> -- 
> 2.32.0.432.gabb21c7263-goog
> 

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

* Re: [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend
  2021-10-27 22:23   ` Ondřej Jirman
@ 2021-10-27 23:47     ` Ondřej Jirman
  2021-10-28  2:06       ` Archie Pusaka
  0 siblings, 1 reply; 11+ messages in thread
From: Ondřej Jirman @ 2021-10-27 23:47 UTC (permalink / raw)
  To: Archie Pusaka, linux-bluetooth, Marcel Holtmann,
	CrosBT Upstreaming, Archie Pusaka, Abhishek Pandit-Subedi,
	Hilda Wu, Johan Hedberg, Luiz Augusto von Dentz, linux-kernel

On Thu, Oct 28, 2021 at 12:23:26AM +0200, megi xff wrote:
> Hello Archie,
> 
> On Fri, Jul 23, 2021 at 07:31:57PM +0800, Archie Pusaka wrote:
> > From: Archie Pusaka <apusaka@chromium.org>
> > 
> > This patch allows the controller to suspend after a short period of
> > inactivity.
> 
> I see this pattern in dmesg after this patch: (I've added printks
> to many hci_h5 functions to see what's going on)
> 
> [  493.150325] h5_dequeue
> [  493.150332] h5_dequeue
> [  493.150336] h5_dequeue
> [  493.150340] h5_dequeue
> [  493.150370] h5_dequeue
> [  493.150547] h5_recv
> [  493.150863] h5_recv
> [  493.150878] h5_dequeue
> [  493.150885] h5_dequeue
> [  493.150888] h5_dequeue
> [  493.151315] h5_enqueue
> [  493.151328] h5_dequeue
> [  493.151350] h5_dequeue
> [  493.151447] h5_dequeue
> [  493.151612] h5_recv
> [  493.151945] h5_recv
> [  493.151961] h5_dequeue
> [  493.151967] h5_dequeue
> [  493.151970] h5_dequeue
> [  495.171812] h5_flush
> [  495.171845] h5_flush
> [  499.267473] h5_serdev_suspend
> [  499.267490] h5_btrtl_suspend
> [  499.273784] h5_recv
> [  499.273828] h5_serdev_resume
> [  499.273833] h5_btrtl_resume
> [  499.273837] h5_btrtl_resume / reprobe
> [  499.273855] h5_btrtl_reprobe_worker
> [  499.273913] h5_serdev_remove
> [  499.274997] h5_close
> [  499.275010] h5_btrtl_close
> [  499.275624] h5_serdev_probe
> [  499.276126] h5_open
> [  499.276132] h5_btrtl_open
> [  499.915820] h5_dequeue
> [  499.915857] h5_dequeue
> [  499.915863] h5_dequeue
> [  499.916212] h5_dequeue
> [  499.919643] h5_recv
> [  499.919675] h5_dequeue
> [  499.919682] h5_dequeue
> [  499.919687] h5_dequeue
> [  499.919692] h5_dequeue
> 
> repeating ad nauseam every 6s.
> 
> Basically bluetooth device reprobes every 6s. Looks like h5_recv call
> after h5_btrtl_suspend wakes the device immediately after suspend.
> 
> (there are no users of bluetooth in my userspace) I'd expect the
> device to stay suspended after suspend.
> 
> I have some extra patches to support 8723cs but nothing that
> would affect this codepath. https://megous.com/git/linux/log/?h=bt-5.15
> 
> I assume it will have the same behavior with 8723bs which is already
> mainline. I guess this issue is specific to devices with H5_INFO_WAKEUP_DISABLE
> flag set.
> 
> Do you have any ideas?

I've added dump_stack() to first h5_recv call after suspend (the one
that's causing the immediate wakeup after runtime PM suspend), and it returns:

[    5.938258] recv
[   13.377775] suspend
[   13.384106] recv
[   13.384120] CPU: 1 PID: 83 Comm: kworker/u8:1 Tainted: G         C        5.15.0-rc7-00002-g64f2c49e8400 #23
[   13.384141] Hardware name: Pine64 PinePhone (1.2) (DT)
[   13.384151] Workqueue: events_unbound flush_to_ldisc
[   13.384196] Call trace:
[   13.384199]  dump_backtrace+0x0/0x15c
[   13.384224]  show_stack+0x14/0x20
[   13.384232]  dump_stack_lvl+0x64/0x7c
[   13.384250]  dump_stack+0x14/0x2c
[   13.384258]  h5_recv+0x44/0xdbc [hci_uart]
[   13.384288]  hci_uart_receive_buf+0x6c/0x94 [hci_uart]
[   13.384298]  ttyport_receive_buf+0x60/0xf4
[   13.384318]  flush_to_ldisc+0xb0/0x160
[   13.384324]  process_one_work+0x1d8/0x380
[   13.384339]  worker_thread+0x178/0x4e0
[   13.384348]  kthread+0x11c/0x130
[   13.384359]  ret_from_fork+0x10/0x20

It's comming from here https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L510

Which can be scheduled from these places:

- https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L65
- https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L413

And that's where I lose a thread of what can be happening. :)

Maybe h5_recv is not a good function to mark activity on the device,
due to tty_buffer code just calling it to check if some data are
available, even if none are? Even if nothing uses bluetooth from
userspace...

kind regards,
	o.

> kind regards,
> 	o.
> 
> 
> > Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> > Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> > Reviewed-by: Hilda Wu <hildawu@realtek.com>
> > 
> > ---
> > 
> > Changes in v3:
> > * Reordering #include
> > 
> >  drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> > 
> > diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
> > index cbc63b057f33..0c0dedece59c 100644
> > --- a/drivers/bluetooth/hci_h5.c
> > +++ b/drivers/bluetooth/hci_h5.c
> > @@ -12,6 +12,7 @@
> >  #include <linux/kernel.h>
> >  #include <linux/mod_devicetable.h>
> >  #include <linux/of_device.h>
> > +#include <linux/pm_runtime.h>
> >  #include <linux/serdev.h>
> >  #include <linux/skbuff.h>
> >  
> > @@ -21,6 +22,8 @@
> >  #include "btrtl.h"
> >  #include "hci_uart.h"
> >  
> > +#define SUSPEND_TIMEOUT_MS	6000
> > +
> >  #define HCI_3WIRE_ACK_PKT	0
> >  #define HCI_3WIRE_LINK_PKT	15
> >  
> > @@ -584,6 +587,10 @@ static int h5_recv(struct hci_uart *hu, const void *data, int count)
> >  		count -= processed;
> >  	}
> >  
> > +	pm_runtime_get(&hu->serdev->dev);
> > +	pm_runtime_mark_last_busy(&hu->serdev->dev);
> > +	pm_runtime_put_autosuspend(&hu->serdev->dev);
> > +
> >  	return 0;
> >  }
> >  
> > @@ -620,6 +627,10 @@ static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
> >  		break;
> >  	}
> >  
> > +	pm_runtime_get_sync(&hu->serdev->dev);
> > +	pm_runtime_mark_last_busy(&hu->serdev->dev);
> > +	pm_runtime_put_autosuspend(&hu->serdev->dev);
> > +
> >  	return 0;
> >  }
> >  
> > @@ -951,6 +962,12 @@ static void h5_btrtl_open(struct h5 *h5)
> >  	serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN);
> >  	serdev_device_set_baudrate(h5->hu->serdev, 115200);
> >  
> > +	pm_runtime_set_active(&h5->hu->serdev->dev);
> > +	pm_runtime_use_autosuspend(&h5->hu->serdev->dev);
> > +	pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev,
> > +					 SUSPEND_TIMEOUT_MS);
> > +	pm_runtime_enable(&h5->hu->serdev->dev);
> > +
> >  	/* The controller needs up to 500ms to wakeup */
> >  	gpiod_set_value_cansleep(h5->enable_gpio, 1);
> >  	gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
> > @@ -959,6 +976,8 @@ static void h5_btrtl_open(struct h5 *h5)
> >  
> >  static void h5_btrtl_close(struct h5 *h5)
> >  {
> > +	pm_runtime_disable(&h5->hu->serdev->dev);
> > +
> >  	gpiod_set_value_cansleep(h5->device_wake_gpio, 0);
> >  	gpiod_set_value_cansleep(h5->enable_gpio, 0);
> >  }
> > @@ -1066,6 +1085,7 @@ MODULE_DEVICE_TABLE(acpi, h5_acpi_match);
> >  
> >  static const struct dev_pm_ops h5_serdev_pm_ops = {
> >  	SET_SYSTEM_SLEEP_PM_OPS(h5_serdev_suspend, h5_serdev_resume)
> > +	SET_RUNTIME_PM_OPS(h5_serdev_suspend, h5_serdev_resume, NULL)
> >  };
> >  
> >  static const struct of_device_id rtl_bluetooth_of_match[] = {
> > -- 
> > 2.32.0.432.gabb21c7263-goog
> > 

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

* Re: [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend
  2021-10-27 23:47     ` Ondřej Jirman
@ 2021-10-28  2:06       ` Archie Pusaka
  2021-10-28  8:12         ` Ondřej Jirman
  0 siblings, 1 reply; 11+ messages in thread
From: Archie Pusaka @ 2021-10-28  2:06 UTC (permalink / raw)
  To: Ondřej Jirman, Archie Pusaka, linux-bluetooth,
	Marcel Holtmann, CrosBT Upstreaming, Abhishek Pandit-Subedi,
	Hilda Wu, Johan Hedberg, Luiz Augusto von Dentz, linux-kernel

Hi Ondrej,

There's a mistake on my side with the WAKEUP_DISABLE flag, but it's
fixed by Hans in this patch.
https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/drivers/bluetooth/hci_h5.c?id=9a9023f314873241a43b5a2b96e9c0caaa958433
Could you try and see whether that fixes your issue?

Thanks,
Archie


On Thu, 28 Oct 2021 at 07:47, Ondřej Jirman <megi@xff.cz> wrote:
>
> On Thu, Oct 28, 2021 at 12:23:26AM +0200, megi xff wrote:
> > Hello Archie,
> >
> > On Fri, Jul 23, 2021 at 07:31:57PM +0800, Archie Pusaka wrote:
> > > From: Archie Pusaka <apusaka@chromium.org>
> > >
> > > This patch allows the controller to suspend after a short period of
> > > inactivity.
> >
> > I see this pattern in dmesg after this patch: (I've added printks
> > to many hci_h5 functions to see what's going on)
> >
> > [  493.150325] h5_dequeue
> > [  493.150332] h5_dequeue
> > [  493.150336] h5_dequeue
> > [  493.150340] h5_dequeue
> > [  493.150370] h5_dequeue
> > [  493.150547] h5_recv
> > [  493.150863] h5_recv
> > [  493.150878] h5_dequeue
> > [  493.150885] h5_dequeue
> > [  493.150888] h5_dequeue
> > [  493.151315] h5_enqueue
> > [  493.151328] h5_dequeue
> > [  493.151350] h5_dequeue
> > [  493.151447] h5_dequeue
> > [  493.151612] h5_recv
> > [  493.151945] h5_recv
> > [  493.151961] h5_dequeue
> > [  493.151967] h5_dequeue
> > [  493.151970] h5_dequeue
> > [  495.171812] h5_flush
> > [  495.171845] h5_flush
> > [  499.267473] h5_serdev_suspend
> > [  499.267490] h5_btrtl_suspend
> > [  499.273784] h5_recv
> > [  499.273828] h5_serdev_resume
> > [  499.273833] h5_btrtl_resume
> > [  499.273837] h5_btrtl_resume / reprobe
> > [  499.273855] h5_btrtl_reprobe_worker
> > [  499.273913] h5_serdev_remove
> > [  499.274997] h5_close
> > [  499.275010] h5_btrtl_close
> > [  499.275624] h5_serdev_probe
> > [  499.276126] h5_open
> > [  499.276132] h5_btrtl_open
> > [  499.915820] h5_dequeue
> > [  499.915857] h5_dequeue
> > [  499.915863] h5_dequeue
> > [  499.916212] h5_dequeue
> > [  499.919643] h5_recv
> > [  499.919675] h5_dequeue
> > [  499.919682] h5_dequeue
> > [  499.919687] h5_dequeue
> > [  499.919692] h5_dequeue
> >
> > repeating ad nauseam every 6s.
> >
> > Basically bluetooth device reprobes every 6s. Looks like h5_recv call
> > after h5_btrtl_suspend wakes the device immediately after suspend.
> >
> > (there are no users of bluetooth in my userspace) I'd expect the
> > device to stay suspended after suspend.
> >
> > I have some extra patches to support 8723cs but nothing that
> > would affect this codepath. https://megous.com/git/linux/log/?h=bt-5.15
> >
> > I assume it will have the same behavior with 8723bs which is already
> > mainline. I guess this issue is specific to devices with H5_INFO_WAKEUP_DISABLE
> > flag set.
> >
> > Do you have any ideas?
>
> I've added dump_stack() to first h5_recv call after suspend (the one
> that's causing the immediate wakeup after runtime PM suspend), and it returns:
>
> [    5.938258] recv
> [   13.377775] suspend
> [   13.384106] recv
> [   13.384120] CPU: 1 PID: 83 Comm: kworker/u8:1 Tainted: G         C        5.15.0-rc7-00002-g64f2c49e8400 #23
> [   13.384141] Hardware name: Pine64 PinePhone (1.2) (DT)
> [   13.384151] Workqueue: events_unbound flush_to_ldisc
> [   13.384196] Call trace:
> [   13.384199]  dump_backtrace+0x0/0x15c
> [   13.384224]  show_stack+0x14/0x20
> [   13.384232]  dump_stack_lvl+0x64/0x7c
> [   13.384250]  dump_stack+0x14/0x2c
> [   13.384258]  h5_recv+0x44/0xdbc [hci_uart]
> [   13.384288]  hci_uart_receive_buf+0x6c/0x94 [hci_uart]
> [   13.384298]  ttyport_receive_buf+0x60/0xf4
> [   13.384318]  flush_to_ldisc+0xb0/0x160
> [   13.384324]  process_one_work+0x1d8/0x380
> [   13.384339]  worker_thread+0x178/0x4e0
> [   13.384348]  kthread+0x11c/0x130
> [   13.384359]  ret_from_fork+0x10/0x20
>
> It's comming from here https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L510
>
> Which can be scheduled from these places:
>
> - https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L65
> - https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L413
>
> And that's where I lose a thread of what can be happening. :)
>
> Maybe h5_recv is not a good function to mark activity on the device,
> due to tty_buffer code just calling it to check if some data are
> available, even if none are? Even if nothing uses bluetooth from
> userspace...
>
> kind regards,
>         o.
>
> > kind regards,
> >       o.
> >
> >
> > > Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> > > Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> > > Reviewed-by: Hilda Wu <hildawu@realtek.com>
> > >
> > > ---
> > >
> > > Changes in v3:
> > > * Reordering #include
> > >
> > >  drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++
> > >  1 file changed, 20 insertions(+)
> > >
> > > diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
> > > index cbc63b057f33..0c0dedece59c 100644
> > > --- a/drivers/bluetooth/hci_h5.c
> > > +++ b/drivers/bluetooth/hci_h5.c
> > > @@ -12,6 +12,7 @@
> > >  #include <linux/kernel.h>
> > >  #include <linux/mod_devicetable.h>
> > >  #include <linux/of_device.h>
> > > +#include <linux/pm_runtime.h>
> > >  #include <linux/serdev.h>
> > >  #include <linux/skbuff.h>
> > >
> > > @@ -21,6 +22,8 @@
> > >  #include "btrtl.h"
> > >  #include "hci_uart.h"
> > >
> > > +#define SUSPEND_TIMEOUT_MS 6000
> > > +
> > >  #define HCI_3WIRE_ACK_PKT  0
> > >  #define HCI_3WIRE_LINK_PKT 15
> > >
> > > @@ -584,6 +587,10 @@ static int h5_recv(struct hci_uart *hu, const void *data, int count)
> > >             count -= processed;
> > >     }
> > >
> > > +   pm_runtime_get(&hu->serdev->dev);
> > > +   pm_runtime_mark_last_busy(&hu->serdev->dev);
> > > +   pm_runtime_put_autosuspend(&hu->serdev->dev);
> > > +
> > >     return 0;
> > >  }
> > >
> > > @@ -620,6 +627,10 @@ static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
> > >             break;
> > >     }
> > >
> > > +   pm_runtime_get_sync(&hu->serdev->dev);
> > > +   pm_runtime_mark_last_busy(&hu->serdev->dev);
> > > +   pm_runtime_put_autosuspend(&hu->serdev->dev);
> > > +
> > >     return 0;
> > >  }
> > >
> > > @@ -951,6 +962,12 @@ static void h5_btrtl_open(struct h5 *h5)
> > >     serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN);
> > >     serdev_device_set_baudrate(h5->hu->serdev, 115200);
> > >
> > > +   pm_runtime_set_active(&h5->hu->serdev->dev);
> > > +   pm_runtime_use_autosuspend(&h5->hu->serdev->dev);
> > > +   pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev,
> > > +                                    SUSPEND_TIMEOUT_MS);
> > > +   pm_runtime_enable(&h5->hu->serdev->dev);
> > > +
> > >     /* The controller needs up to 500ms to wakeup */
> > >     gpiod_set_value_cansleep(h5->enable_gpio, 1);
> > >     gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
> > > @@ -959,6 +976,8 @@ static void h5_btrtl_open(struct h5 *h5)
> > >
> > >  static void h5_btrtl_close(struct h5 *h5)
> > >  {
> > > +   pm_runtime_disable(&h5->hu->serdev->dev);
> > > +
> > >     gpiod_set_value_cansleep(h5->device_wake_gpio, 0);
> > >     gpiod_set_value_cansleep(h5->enable_gpio, 0);
> > >  }
> > > @@ -1066,6 +1085,7 @@ MODULE_DEVICE_TABLE(acpi, h5_acpi_match);
> > >
> > >  static const struct dev_pm_ops h5_serdev_pm_ops = {
> > >     SET_SYSTEM_SLEEP_PM_OPS(h5_serdev_suspend, h5_serdev_resume)
> > > +   SET_RUNTIME_PM_OPS(h5_serdev_suspend, h5_serdev_resume, NULL)
> > >  };
> > >
> > >  static const struct of_device_id rtl_bluetooth_of_match[] = {
> > > --
> > > 2.32.0.432.gabb21c7263-goog
> > >

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

* Re: [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend
  2021-10-28  2:06       ` Archie Pusaka
@ 2021-10-28  8:12         ` Ondřej Jirman
  0 siblings, 0 replies; 11+ messages in thread
From: Ondřej Jirman @ 2021-10-28  8:12 UTC (permalink / raw)
  To: Archie Pusaka
  Cc: linux-bluetooth, Marcel Holtmann, CrosBT Upstreaming,
	Abhishek Pandit-Subedi, Hilda Wu, Johan Hedberg,
	Luiz Augusto von Dentz, linux-kernel

Hell Archie,

On Thu, Oct 28, 2021 at 10:06:58AM +0800, Archie Pusaka wrote:
> Hi Ondrej,
> 
> There's a mistake on my side with the WAKEUP_DISABLE flag, but it's
> fixed by Hans in this patch.
> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/drivers/bluetooth/hci_h5.c?id=9a9023f314873241a43b5a2b96e9c0caaa958433
> Could you try and see whether that fixes your issue?

Yes, that fixes the issue. Thanks. :)

kind regards,
	o.

> Thanks,
> Archie
> 
> 
> On Thu, 28 Oct 2021 at 07:47, Ondřej Jirman <megi@xff.cz> wrote:
> >
> > On Thu, Oct 28, 2021 at 12:23:26AM +0200, megi xff wrote:
> > > Hello Archie,
> > >
> > > On Fri, Jul 23, 2021 at 07:31:57PM +0800, Archie Pusaka wrote:
> > > > From: Archie Pusaka <apusaka@chromium.org>
> > > >
> > > > This patch allows the controller to suspend after a short period of
> > > > inactivity.
> > >
> > > I see this pattern in dmesg after this patch: (I've added printks
> > > to many hci_h5 functions to see what's going on)
> > >
> > > [  493.150325] h5_dequeue
> > > [  493.150332] h5_dequeue
> > > [  493.150336] h5_dequeue
> > > [  493.150340] h5_dequeue
> > > [  493.150370] h5_dequeue
> > > [  493.150547] h5_recv
> > > [  493.150863] h5_recv
> > > [  493.150878] h5_dequeue
> > > [  493.150885] h5_dequeue
> > > [  493.150888] h5_dequeue
> > > [  493.151315] h5_enqueue
> > > [  493.151328] h5_dequeue
> > > [  493.151350] h5_dequeue
> > > [  493.151447] h5_dequeue
> > > [  493.151612] h5_recv
> > > [  493.151945] h5_recv
> > > [  493.151961] h5_dequeue
> > > [  493.151967] h5_dequeue
> > > [  493.151970] h5_dequeue
> > > [  495.171812] h5_flush
> > > [  495.171845] h5_flush
> > > [  499.267473] h5_serdev_suspend
> > > [  499.267490] h5_btrtl_suspend
> > > [  499.273784] h5_recv
> > > [  499.273828] h5_serdev_resume
> > > [  499.273833] h5_btrtl_resume
> > > [  499.273837] h5_btrtl_resume / reprobe
> > > [  499.273855] h5_btrtl_reprobe_worker
> > > [  499.273913] h5_serdev_remove
> > > [  499.274997] h5_close
> > > [  499.275010] h5_btrtl_close
> > > [  499.275624] h5_serdev_probe
> > > [  499.276126] h5_open
> > > [  499.276132] h5_btrtl_open
> > > [  499.915820] h5_dequeue
> > > [  499.915857] h5_dequeue
> > > [  499.915863] h5_dequeue
> > > [  499.916212] h5_dequeue
> > > [  499.919643] h5_recv
> > > [  499.919675] h5_dequeue
> > > [  499.919682] h5_dequeue
> > > [  499.919687] h5_dequeue
> > > [  499.919692] h5_dequeue
> > >
> > > repeating ad nauseam every 6s.
> > >
> > > Basically bluetooth device reprobes every 6s. Looks like h5_recv call
> > > after h5_btrtl_suspend wakes the device immediately after suspend.
> > >
> > > (there are no users of bluetooth in my userspace) I'd expect the
> > > device to stay suspended after suspend.
> > >
> > > I have some extra patches to support 8723cs but nothing that
> > > would affect this codepath. https://megous.com/git/linux/log/?h=bt-5.15
> > >
> > > I assume it will have the same behavior with 8723bs which is already
> > > mainline. I guess this issue is specific to devices with H5_INFO_WAKEUP_DISABLE
> > > flag set.
> > >
> > > Do you have any ideas?
> >
> > I've added dump_stack() to first h5_recv call after suspend (the one
> > that's causing the immediate wakeup after runtime PM suspend), and it returns:
> >
> > [    5.938258] recv
> > [   13.377775] suspend
> > [   13.384106] recv
> > [   13.384120] CPU: 1 PID: 83 Comm: kworker/u8:1 Tainted: G         C        5.15.0-rc7-00002-g64f2c49e8400 #23
> > [   13.384141] Hardware name: Pine64 PinePhone (1.2) (DT)
> > [   13.384151] Workqueue: events_unbound flush_to_ldisc
> > [   13.384196] Call trace:
> > [   13.384199]  dump_backtrace+0x0/0x15c
> > [   13.384224]  show_stack+0x14/0x20
> > [   13.384232]  dump_stack_lvl+0x64/0x7c
> > [   13.384250]  dump_stack+0x14/0x2c
> > [   13.384258]  h5_recv+0x44/0xdbc [hci_uart]
> > [   13.384288]  hci_uart_receive_buf+0x6c/0x94 [hci_uart]
> > [   13.384298]  ttyport_receive_buf+0x60/0xf4
> > [   13.384318]  flush_to_ldisc+0xb0/0x160
> > [   13.384324]  process_one_work+0x1d8/0x380
> > [   13.384339]  worker_thread+0x178/0x4e0
> > [   13.384348]  kthread+0x11c/0x130
> > [   13.384359]  ret_from_fork+0x10/0x20
> >
> > It's comming from here https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L510
> >
> > Which can be scheduled from these places:
> >
> > - https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L65
> > - https://elixir.bootlin.com/linux/latest/source/drivers/tty/tty_buffer.c#L413
> >
> > And that's where I lose a thread of what can be happening. :)
> >
> > Maybe h5_recv is not a good function to mark activity on the device,
> > due to tty_buffer code just calling it to check if some data are
> > available, even if none are? Even if nothing uses bluetooth from
> > userspace...
> >
> > kind regards,
> >         o.
> >
> > > kind regards,
> > >       o.
> > >
> > >
> > > > Signed-off-by: Archie Pusaka <apusaka@chromium.org>
> > > > Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> > > > Reviewed-by: Hilda Wu <hildawu@realtek.com>
> > > >
> > > > ---
> > > >
> > > > Changes in v3:
> > > > * Reordering #include
> > > >
> > > >  drivers/bluetooth/hci_h5.c | 20 ++++++++++++++++++++
> > > >  1 file changed, 20 insertions(+)
> > > >
> > > > diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
> > > > index cbc63b057f33..0c0dedece59c 100644
> > > > --- a/drivers/bluetooth/hci_h5.c
> > > > +++ b/drivers/bluetooth/hci_h5.c
> > > > @@ -12,6 +12,7 @@
> > > >  #include <linux/kernel.h>
> > > >  #include <linux/mod_devicetable.h>
> > > >  #include <linux/of_device.h>
> > > > +#include <linux/pm_runtime.h>
> > > >  #include <linux/serdev.h>
> > > >  #include <linux/skbuff.h>
> > > >
> > > > @@ -21,6 +22,8 @@
> > > >  #include "btrtl.h"
> > > >  #include "hci_uart.h"
> > > >
> > > > +#define SUSPEND_TIMEOUT_MS 6000
> > > > +
> > > >  #define HCI_3WIRE_ACK_PKT  0
> > > >  #define HCI_3WIRE_LINK_PKT 15
> > > >
> > > > @@ -584,6 +587,10 @@ static int h5_recv(struct hci_uart *hu, const void *data, int count)
> > > >             count -= processed;
> > > >     }
> > > >
> > > > +   pm_runtime_get(&hu->serdev->dev);
> > > > +   pm_runtime_mark_last_busy(&hu->serdev->dev);
> > > > +   pm_runtime_put_autosuspend(&hu->serdev->dev);
> > > > +
> > > >     return 0;
> > > >  }
> > > >
> > > > @@ -620,6 +627,10 @@ static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
> > > >             break;
> > > >     }
> > > >
> > > > +   pm_runtime_get_sync(&hu->serdev->dev);
> > > > +   pm_runtime_mark_last_busy(&hu->serdev->dev);
> > > > +   pm_runtime_put_autosuspend(&hu->serdev->dev);
> > > > +
> > > >     return 0;
> > > >  }
> > > >
> > > > @@ -951,6 +962,12 @@ static void h5_btrtl_open(struct h5 *h5)
> > > >     serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN);
> > > >     serdev_device_set_baudrate(h5->hu->serdev, 115200);
> > > >
> > > > +   pm_runtime_set_active(&h5->hu->serdev->dev);
> > > > +   pm_runtime_use_autosuspend(&h5->hu->serdev->dev);
> > > > +   pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev,
> > > > +                                    SUSPEND_TIMEOUT_MS);
> > > > +   pm_runtime_enable(&h5->hu->serdev->dev);
> > > > +
> > > >     /* The controller needs up to 500ms to wakeup */
> > > >     gpiod_set_value_cansleep(h5->enable_gpio, 1);
> > > >     gpiod_set_value_cansleep(h5->device_wake_gpio, 1);
> > > > @@ -959,6 +976,8 @@ static void h5_btrtl_open(struct h5 *h5)
> > > >
> > > >  static void h5_btrtl_close(struct h5 *h5)
> > > >  {
> > > > +   pm_runtime_disable(&h5->hu->serdev->dev);
> > > > +
> > > >     gpiod_set_value_cansleep(h5->device_wake_gpio, 0);
> > > >     gpiod_set_value_cansleep(h5->enable_gpio, 0);
> > > >  }
> > > > @@ -1066,6 +1085,7 @@ MODULE_DEVICE_TABLE(acpi, h5_acpi_match);
> > > >
> > > >  static const struct dev_pm_ops h5_serdev_pm_ops = {
> > > >     SET_SYSTEM_SLEEP_PM_OPS(h5_serdev_suspend, h5_serdev_resume)
> > > > +   SET_RUNTIME_PM_OPS(h5_serdev_suspend, h5_serdev_resume, NULL)
> > > >  };
> > > >
> > > >  static const struct of_device_id rtl_bluetooth_of_match[] = {
> > > > --
> > > > 2.32.0.432.gabb21c7263-goog
> > > >

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

end of thread, other threads:[~2021-10-28  8:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 11:31 [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Archie Pusaka
2021-07-23 11:31 ` [PATCH v3 2/3] Bluetooth: hci_h5: btrtl: Maintain flow control if wakeup is enabled Archie Pusaka
2021-07-23 12:12   ` Marcel Holtmann
2021-07-23 11:31 ` [PATCH v3 3/3] Bluetooth: hci_h5: Add runtime suspend Archie Pusaka
2021-07-23 12:11   ` Marcel Holtmann
2021-10-27 22:23   ` Ondřej Jirman
2021-10-27 23:47     ` Ondřej Jirman
2021-10-28  2:06       ` Archie Pusaka
2021-10-28  8:12         ` Ondřej Jirman
2021-07-23 12:12 ` [PATCH v3 1/3] Bluetooth: hci_h5: add WAKEUP_DISABLE flag Marcel Holtmann
2021-07-27  2:09 ` [v3,1/3] " bluez.test.bot

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).