Skip to contentSkip to conversation

bluetooth: hci_qca: Fix qca6390 enable failure after warm reboot

PATCH Superseded Zijun Hu 2 participants 5 messages May 27, 2020 – May 28, 2020

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

PATCH v3 1/1 bluetooth: hci_qca: Fix qca6390 enable failure after warm reboot

Warm reboot can not restore qca6390 controller baudrate to default due to lack of controllable BT_EN pin or power supply, so fails to download firmware after warm reboot.

Fixed by sending EDL_SOC_RESET VSC to reset controller within added device shutdown implementation.

---
 drivers/bluetooth/hci_qca.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/bluetooth/hci_qca.c +29 -0
index e4a6823..4b6f8b6 100644
@@ -1975,6 +1975,34 @@ static void qca_serdev_remove(struct serdev_device *serdev)
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 }
 
+static void qca_serdev_shutdown(struct device *dev)
+{
+	int ret;
+	int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
+	struct serdev_device *serdev = to_serdev_device(dev);
+	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+	const u8 ibs_wake_cmd[] = { 0xFD };
+	const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
+
+	if (qcadev->btsoc_type == QCA_QCA6390) {
+		serdev_device_write_flush(serdev);
+		serdev_device_write_buf(serdev,
+				ibs_wake_cmd, sizeof(ibs_wake_cmd));
+		serdev_device_wait_until_sent(serdev, timeout);
+		usleep_range(8000, 10000);
+
+		serdev_device_write_flush(serdev);
+		ret = serdev_device_write_buf(serdev,
+				edl_reset_soc_cmd, sizeof(edl_reset_soc_cmd));
+		if (ret < 0) {
+			BT_ERR("QCA send EDL_RESET_REQ error: %d", ret);
+			return;
+		}
+		serdev_device_wait_until_sent(serdev, timeout);
+		usleep_range(8000, 10000);
+	}
+}
+
 static int __maybe_unused qca_suspend(struct device *dev)
 {
 	struct hci_dev *hdev = container_of(dev, struct hci_dev, dev);
@@ -2100,6 +2128,7 @@ static struct serdev_device_driver qca_serdev_driver = {
 		.name = "hci_uart_qca",
 		.of_match_table = of_match_ptr(qca_bluetooth_of_match),
 		.acpi_match_table = ACPI_PTR(qca_bluetooth_acpi_match),
+		.shutdown = qca_serdev_shutdown,
 		.pm = &qca_pm_ops,
 	},
 };
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
#1 lore raw

Hi Zijun,

Quoted 24 lines · Zijun Hu

Warm reboot can not restore qca6390 controller baudrate to default due to lack of controllable BT_EN pin or power supply, so fails to download firmware after warm reboot.

Fixed by sending EDL_SOC_RESET VSC to reset controller within added device shutdown implementation.

---
 drivers/bluetooth/hci_qca.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/bluetooth/hci_qca.c +4 -0
index e4a6823..4b6f8b6 100644
@@ -1975,6 +1975,34 @@ static void qca_serdev_remove(struct serdev_device *serdev)
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 }
 
+static void qca_serdev_shutdown(struct device *dev)
+{
+	int ret;
+	int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1991

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+	struct serdev_device *serdev = to_serdev_device(dev);
+	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+	const u8 ibs_wake_cmd[] = { 0xFD };
+	const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
+
+	if (qcadev->btsoc_type == QCA_QCA6390) {
+		serdev_device_write_flush(serdev);
+		serdev_device_write_buf(serdev,
+				ibs_wake_cmd, sizeof(ibs_wake_cmd));
+		serdev_device_wait_until_sent(serdev, timeout);

Why no check of the return value of serdev_device_write_buf() here, does it make sense to continue if sending the wakeup command failed?

Couldn't serdev_device_write() be used instead of the _write_buf() + _wait_until_sent() combo?

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1994

Quoted 3 lines
drivers/bluetooth/hci_qca.c +3 -0
+		usleep_range(8000, 10000);
+
+		serdev_device_write_flush(serdev);

I suppose the flush is done because _wait_until_sent() could have timed out. Another reason to use _device_write() (if suitable), since it returns -ETIMEDOUT in that case?

Quoted 25 lines
drivers/bluetooth/hci_qca.c +12 -0
+		ret = serdev_device_write_buf(serdev,
+				edl_reset_soc_cmd, sizeof(edl_reset_soc_cmd));
+		if (ret < 0) {
+			BT_ERR("QCA send EDL_RESET_REQ error: %d", ret);
+			return;
+		}
+		serdev_device_wait_until_sent(serdev, timeout);
+		usleep_range(8000, 10000);
+	}
+}
+
 static int __maybe_unused qca_suspend(struct device *dev)
 {
 	struct hci_dev *hdev = container_of(dev, struct hci_dev, dev);
@@ -2100,6 +2128,7 @@ static struct serdev_device_driver qca_serdev_driver = {
 		.name = "hci_uart_qca",
 		.of_match_table = of_match_ptr(qca_bluetooth_of_match),
 		.acpi_match_table = ACPI_PTR(qca_bluetooth_acpi_match),
+		.shutdown = qca_serdev_shutdown,
 		.pm = &qca_pm_ops,
 	},
 };
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
author
#2 lore raw
Quoted 32 lines · Matthias Kaehlcke

Hi Zijun,

Quoted 29 lines · Zijun Hu

Warm reboot can not restore qca6390 controller baudrate to default due to lack of controllable BT_EN pin or power supply, so fails to download firmware after warm reboot.

Fixed by sending EDL_SOC_RESET VSC to reset controller within added device shutdown implementation.

---
 drivers/bluetooth/hci_qca.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/bluetooth/hci_qca.c +9 -0
index e4a6823..4b6f8b6 100644
@@ -1975,6 +1975,34 @@ static void qca_serdev_remove(struct serdev_device *serdev)
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 }
 
+static void qca_serdev_shutdown(struct device *dev)
+{
+	int ret;
+	int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
+	struct serdev_device *serdev = to_serdev_device(dev);
+	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+	const u8 ibs_wake_cmd[] = { 0xFD };
+	const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
+
Quoted 9 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1991

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+	if (qcadev->btsoc_type == QCA_QCA6390) {
+		serdev_device_write_flush(serdev);
+		serdev_device_write_buf(serdev,
+				ibs_wake_cmd, sizeof(ibs_wake_cmd));
+		serdev_device_wait_until_sent(serdev, timeout);

Why no check of the return value of serdev_device_write_buf() here, does it make sense to continue if sending the wakeup command failed?

i will correct it at v4 patch

Quoted 3 lines

Couldn't serdev_device_write() be used instead of the _write_buf() + _wait_until_sent() combo?

i don't think so, serdev_device_write() is not appropriate at here. serdev_device_write_wakeup() should be used to release completion hold by serdev_device_write(), however @hci_serdev_client_ops doesn't use serdev_device_write_wakeup() to implement its write_wakeup operation. we don't want to touch common hci_serdev.c code.

Quoted 8 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1994

Quoted 3 lines
drivers/bluetooth/hci_qca.c +3 -0
+		usleep_range(8000, 10000);
+
+		serdev_device_write_flush(serdev);

I suppose the flush is done because _wait_until_sent() could have timed out. Another reason to use _device_write() (if suitable), since it returns -ETIMEDOUT in that case?

flush is prefixed at write operation to speed up shutdown procedure in case of unexpected data injected during waiting for controller wakeup.
the combo have been used and i just follow it>> + ret = serdev_device_write_buf(serdev,

Quoted 24 lines
Quoted 24 lines
drivers/bluetooth/hci_qca.c +11 -0
+				edl_reset_soc_cmd, sizeof(edl_reset_soc_cmd));
+		if (ret < 0) {
+			BT_ERR("QCA send EDL_RESET_REQ error: %d", ret);
+			return;
+		}
+		serdev_device_wait_until_sent(serdev, timeout);
+		usleep_range(8000, 10000);
+	}
+}
+
 static int __maybe_unused qca_suspend(struct device *dev)
 {
 	struct hci_dev *hdev = container_of(dev, struct hci_dev, dev);
@@ -2100,6 +2128,7 @@ static struct serdev_device_driver qca_serdev_driver = {
 		.name = "hci_uart_qca",
 		.of_match_table = of_match_ptr(qca_bluetooth_of_match),
 		.acpi_match_table = ACPI_PTR(qca_bluetooth_acpi_match),
+		.shutdown = qca_serdev_shutdown,
 		.pm = &qca_pm_ops,
 	},
 };
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
#3 lore raw
Quoted 45 lines · Zijun Hu
Quoted 32 lines · Matthias Kaehlcke

Hi Zijun,

Quoted 29 lines · Zijun Hu

Warm reboot can not restore qca6390 controller baudrate to default due to lack of controllable BT_EN pin or power supply, so fails to download firmware after warm reboot.

Fixed by sending EDL_SOC_RESET VSC to reset controller within added device shutdown implementation.

---
 drivers/bluetooth/hci_qca.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/bluetooth/hci_qca.c +9 -0
index e4a6823..4b6f8b6 100644
@@ -1975,6 +1975,34 @@ static void qca_serdev_remove(struct serdev_device *serdev)
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 }
 
+static void qca_serdev_shutdown(struct device *dev)
+{
+	int ret;
+	int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
+	struct serdev_device *serdev = to_serdev_device(dev);
+	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+	const u8 ibs_wake_cmd[] = { 0xFD };
+	const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
+
Quoted 9 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1991

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+	if (qcadev->btsoc_type == QCA_QCA6390) {
+		serdev_device_write_flush(serdev);
+		serdev_device_write_buf(serdev,
+				ibs_wake_cmd, sizeof(ibs_wake_cmd));
+		serdev_device_wait_until_sent(serdev, timeout);

Why no check of the return value of serdev_device_write_buf() here, does it make sense to continue if sending the wakeup command failed?

i will correct it at v4 patch

Quoted 8 lines
Quoted 3 lines

Couldn't serdev_device_write() be used instead of the _write_buf() + _wait_until_sent() combo?

i don't think so, serdev_device_write() is not appropriate at here. serdev_device_write_wakeup() should be used to release completion hold by serdev_device_write(), however @hci_serdev_client_ops doesn't use serdev_device_write_wakeup() to implement its write_wakeup operation. we don't want to touch common hci_serdev.c code.

Thanks for the clarification!

Quoted 11 lines
Quoted 8 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1994

Quoted 3 lines
drivers/bluetooth/hci_qca.c +3 -0
+		usleep_range(8000, 10000);
+
+		serdev_device_write_flush(serdev);

I suppose the flush is done because _wait_until_sent() could have timed out. Another reason to use _device_write() (if suitable), since it returns -ETIMEDOUT in that case?

flush is prefixed at write operation to speed up shutdown procedure in case of unexpected data injected during waiting for controller wakeup.

hm, wouldn't it be a bug if unexpected data is injected during shutdown? It seems it would be better to detect such a problem and fix the root cause, rather than papering over it.

Also, a flush doesn't really guarantee that there is no unexpected data when serdev_device_write_buf() is called, it could be injected just after returning from _flush().

author
#4 lore raw
Quoted 69 lines · Matthias Kaehlcke
Quoted 45 lines · Zijun Hu
Quoted 32 lines · Matthias Kaehlcke

Hi Zijun,

Quoted 29 lines · Zijun Hu

Warm reboot can not restore qca6390 controller baudrate to default due to lack of controllable BT_EN pin or power supply, so fails to download firmware after warm reboot.

Fixed by sending EDL_SOC_RESET VSC to reset controller within added device shutdown implementation.

---
 drivers/bluetooth/hci_qca.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/bluetooth/hci_qca.c +9 -0
index e4a6823..4b6f8b6 100644
@@ -1975,6 +1975,34 @@ static void qca_serdev_remove(struct serdev_device *serdev)
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 }
 
+static void qca_serdev_shutdown(struct device *dev)
+{
+	int ret;
+	int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
+	struct serdev_device *serdev = to_serdev_device(dev);
+	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+	const u8 ibs_wake_cmd[] = { 0xFD };
+	const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
+
Quoted 9 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1991

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+	if (qcadev->btsoc_type == QCA_QCA6390) {
+		serdev_device_write_flush(serdev);
+		serdev_device_write_buf(serdev,
+				ibs_wake_cmd, sizeof(ibs_wake_cmd));
+		serdev_device_wait_until_sent(serdev, timeout);

Why no check of the return value of serdev_device_write_buf() here, does it make sense to continue if sending the wakeup command failed?

i will correct it at v4 patch

Quoted 8 lines
Quoted 3 lines

Couldn't serdev_device_write() be used instead of the _write_buf() + _wait_until_sent() combo?

i don't think so, serdev_device_write() is not appropriate at here. serdev_device_write_wakeup() should be used to release completion hold by serdev_device_write(), however @hci_serdev_client_ops doesn't use serdev_device_write_wakeup() to implement its write_wakeup operation. we don't want to touch common hci_serdev.c code.

Thanks for the clarification!

Quoted 11 lines
Quoted 8 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1994

Quoted 3 lines
drivers/bluetooth/hci_qca.c +3 -0
+		usleep_range(8000, 10000);
+
+		serdev_device_write_flush(serdev);

I suppose the flush is done because _wait_until_sent() could have timed out. Another reason to use _device_write() (if suitable), since it returns -ETIMEDOUT in that case?

flush is prefixed at write operation to speed up shutdown procedure in case of unexpected data injected during waiting for controller wakeup.

Quoted 8 lines

hm, wouldn't it be a bug if unexpected data is injected during shutdown? It seems it would be better to detect such a problem and fix the root cause, rather than papering over it.

Also, a flush doesn't really guarantee that there is no unexpected data when serdev_device_write_buf() is called, it could be injected just after returning from _flush().

actually, we never see these unexpected data injection scenario and it is impossible to happen theoretically. the main purpose of prefixing flush before the secondary writing is to make code look more perfect and harmonious visually.

BTW, i have updated this patch to v5 version in order to fix these issue pointed.

Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project