Skip to contentSkip to conversation

Bug fixes for Qualcomm BT chip wcn3990.

PATCH Superseded Balakrishna Godavarthi 2 participants 13 messages Jan 24, 2019 – Feb 1, 2019

Subsystems (3)

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v9 cover Bug fixes for Qualcomm BT chip wcn3990.

The below issues are found in our recent testing.

1. Observed device is not going into off state or not responding. As wcn3990 require a power pulses to turn on the irrespctive of igniting regulators, it was observed that power on or power off pulses are not in sync with respective to chip.
The below patch will help us to wait until byte is pushed on to wires.

* Bluetooth: hci_qca: use wait_until_sent() for power pulses

2. Observed Chip responding when we are in sleep.
This is due to turn on flow control during change baudrate request. The below patch will only pull the RTS line high instead of turning off the flow.

* Bluetooth: hci_qca: Pull RTS line high for baudrate change command.

3. Disable IBS state machine and flush Tx buffer
We are disabling IBS and flushing the Tx buffer before turning off the chip.

This is due to IBS state machine is active when we turn off the chip. This will stop queuing IBS protocol bytes.

* Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

Changes in v9:
* Reverted the 100us delay and used msecs to jiffies inline call.
* Disabling the flow control and enabling it back while setting the firmware.
* Added spinlock while clearing the IBS state machine.

Changes in v8:
* dropped inject the command complete event.
* added one second time for the power pules instead of the indefinite time.

Changes in v7:
* dropped frame reassmebly error patch.
* dropped baudrate change wait time patch.
* increased a wait to 5 ms for power pulses.

Changes in v6:
* added serdev_device_write_flush in qca_send_power_pulse().
* added new patch to update the baudrate change wait time.

Changes in V5:
* added serdev_device_write_flush before sending the power off pulse during shutdown.

Changes in v4:
* used serdev_device_write_buf() instead of serdev_device_write().
* added new patch to stop logging of 0xfc00 timeout on console.

Changes in v3:
* moved IBS & qca_flush to different patch
* updated comments in code fo Deassert RTS patch
Balakrishna Godavarthi (3):
Bluetooth: hci_qca: use wait_until_sent() for power pulses
Bluetooth: hci_qca: Deassert RTS while baudrate change command
Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

 drivers/bluetooth/hci_qca.c | 79 ++++++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 36 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH v9 1/3 Bluetooth: hci_qca: use wait_until_sent() for power pulses

wcn3990 requires a power pulse to turn ON/OFF along with regulators. Sometimes we are observing the power pulses are sent out with some time delay, due to queuing these commands. This is causing synchronization issues with chip, which intern delay the chip setup or may end up with communication issues.

---
Changes in v9:
* Reverted to 100us sleep.
* used inline call msecs_to_jiffies()

Changes in v8:
* Updated 1 second timeout instead of indefinite wait.

Changes in v7:
* updated the wait time to 5 ms after sending power pulses.

Changes in v6:
* added serdev_device_write_flush() in qca_send_power_pulse instead during the power off pulse.

Changes in v5:
* added serdev_device_write_flush() in qca_power_off().

---
 drivers/bluetooth/hci_qca.c | 40 +++++++++++++++----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)
drivers/bluetooth/hci_qca.c +16 -24
index f036c8f98ea3..c08f4d105e73 100644
@@ -60,6 +60,7 @@
 #define IBS_WAKE_RETRANS_TIMEOUT_MS	100
 #define IBS_TX_IDLE_TIMEOUT_MS		2000
 #define BAUDRATE_SETTLE_TIMEOUT_MS	300
+#define POWER_PULSE_TRANS_TIMEOUT_MS	1000
 
 /* susclk rate */
 #define SUSCLK_RATE_32KHZ	32768
@@ -1013,11 +1014,10 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
 		hci_uart_set_baudrate(hu, speed);
 }
 
-static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
+static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd)
 {
-	struct hci_uart *hu = hci_get_drvdata(hdev);
-	struct qca_data *qca = hu->priv;
-	struct sk_buff *skb;
+	int ret;
+	int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS);
 
 	/* These power pulses are single byte command which are sent
 	 * at required baudrate to wcn3990. On wcn3990, we have an external
@@ -1029,21 +1029,19 @@ static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
 	 * save power. Disabling hardware flow control is mandatory while
 	 * sending power pulses to SoC.
 	 */
-	bt_dev_dbg(hdev, "sending power pulse %02x to SoC", cmd);
-
-	skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
-	if (!skb)
-		return -ENOMEM;
+	bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
 
+	serdev_device_write_flush(hu->serdev);
 	hci_uart_set_flow_control(hu, true);
+	ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
+	if (ret < 0) {
+		bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
+		return ret;
+	}
 
-	skb_put_u8(skb, cmd);
-	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
-
-	skb_queue_tail(&qca->txq, skb);
-	hci_uart_tx_wakeup(hu);
+	serdev_device_wait_until_sent(hu->serdev, timeout);
 
-	/* Wait for 100 uS for SoC to settle down */
+	/* Wait for 100 uS for SoC to settle down for the received byte. */
 	usleep_range(100, 200);
 	hci_uart_set_flow_control(hu, false);
 
@@ -1116,7 +1114,6 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 
 static int qca_wcn3990_init(struct hci_uart *hu)
 {
-	struct hci_dev *hdev = hu->hdev;
 	struct qca_serdev *qcadev;
 	int ret;
 
@@ -1139,12 +1136,12 @@ static int qca_wcn3990_init(struct hci_uart *hu)
 
 	/* Forcefully enable wcn3990 to enter in to boot mode. */
 	host_set_baudrate(hu, 2400);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWEROFF_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	if (ret)
 		return ret;
 
 	qca_set_speed(hu, QCA_INIT_SPEED);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWERON_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE);
 	if (ret)
 		return ret;
 
@@ -1274,13 +1271,8 @@ static const struct qca_vreg_data qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {
-	struct serdev_device *serdev = hu->serdev;
-	unsigned char cmd = QCA_WCN3990_POWEROFF_PULSE;
-
 	host_set_baudrate(hu, 2400);
-	hci_uart_set_flow_control(hu, true);
-	serdev_device_write_buf(serdev, &cmd, sizeof(cmd));
-	hci_uart_set_flow_control(hu, false);
+	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);
 }
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v9 1/3
#2 lore raw

Re: [PATCH v9 1/3] Bluetooth: hci_qca: use wait_until_sent() for power pulses

Quoted 33 lines · Balakrishna Godavarthi

wcn3990 requires a power pulse to turn ON/OFF along with regulators. Sometimes we are observing the power pulses are sent out with some time delay, due to queuing these commands. This is causing synchronization issues with chip, which intern delay the chip setup or may end up with communication issues.

---
Changes in v9:
* Reverted to 100us sleep.
* used inline call msecs_to_jiffies()

Changes in v8:
* Updated 1 second timeout instead of indefinite wait.

Changes in v7:
* updated the wait time to 5 ms after sending power pulses.

Changes in v6:
* added serdev_device_write_flush() in qca_send_power_pulse instead during the power off pulse.

Changes in v5:
* added serdev_device_write_flush() in qca_power_off().

---
 drivers/bluetooth/hci_qca.c | 40 +++++++++++++++----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)
drivers/bluetooth/hci_qca.c +0 -0
index f036c8f98ea3..c08f4d105e73 100644

drivers/bluetooth/hci_qca.c line 63

Quoted 4 lines
drivers/bluetooth/hci_qca.c +1 -0
@@ -60,6 +60,7 @@
 #define IBS_WAKE_RETRANS_TIMEOUT_MS	100
 #define IBS_TX_IDLE_TIMEOUT_MS		2000
 #define BAUDRATE_SETTLE_TIMEOUT_MS	300
+#define POWER_PULSE_TRANS_TIMEOUT_MS	1000

I still doubt that this mega-timeout of 1s is needed, but it shouldn't do any harm either, so whatever ...

Quoted 35 lines
drivers/bluetooth/hci_qca.c +10 -9
 /* susclk rate */
 #define SUSCLK_RATE_32KHZ	32768
@@ -1013,11 +1014,10 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
 		hci_uart_set_baudrate(hu, speed);
 }
 
-static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
+static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd)
 {
-	struct hci_uart *hu = hci_get_drvdata(hdev);
-	struct qca_data *qca = hu->priv;
-	struct sk_buff *skb;
+	int ret;
+	int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS);
 
 	/* These power pulses are single byte command which are sent
 	 * at required baudrate to wcn3990. On wcn3990, we have an external
@@ -1029,21 +1029,19 @@ static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
 	 * save power. Disabling hardware flow control is mandatory while
 	 * sending power pulses to SoC.
 	 */
-	bt_dev_dbg(hdev, "sending power pulse %02x to SoC", cmd);
-
-	skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
-	if (!skb)
-		return -ENOMEM;
+	bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
 
+	serdev_device_write_flush(hu->serdev);
 	hci_uart_set_flow_control(hu, true);
+	ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
+	if (ret < 0) {
+		bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
+		return ret;
+	}

drivers/bluetooth/hci_qca.c static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd) · line 1044

Quoted 10 lines
drivers/bluetooth/hci_qca.c +2 -6
 
-	skb_put_u8(skb, cmd);
-	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
-
-	skb_queue_tail(&qca->txq, skb);
-	hci_uart_tx_wakeup(hu);
+	serdev_device_wait_until_sent(hu->serdev, timeout);
 
-	/* Wait for 100 uS for SoC to settle down */
+	/* Wait for 100 uS for SoC to settle down for the received byte. */

I don't think 'for the received byte' adds much value here. If you respin anyway I'd suggest to leave the comment as is.

Quoted 31 lines
drivers/bluetooth/hci_qca.c +2 -4
 	usleep_range(100, 200);
 	hci_uart_set_flow_control(hu, false);
 
@@ -1116,7 +1114,6 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 
 static int qca_wcn3990_init(struct hci_uart *hu)
 {
-	struct hci_dev *hdev = hu->hdev;
 	struct qca_serdev *qcadev;
 	int ret;
 
@@ -1139,12 +1136,12 @@ static int qca_wcn3990_init(struct hci_uart *hu)
 
 	/* Forcefully enable wcn3990 to enter in to boot mode. */
 	host_set_baudrate(hu, 2400);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWEROFF_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	if (ret)
 		return ret;
 
 	qca_set_speed(hu, QCA_INIT_SPEED);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWERON_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE);
 	if (ret)
 		return ret;
 
@@ -1274,13 +1271,8 @@ static const struct qca_vreg_data qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {
-	struct serdev_device *serdev = hu->serdev;

drivers/bluetooth/hci_qca.c static const struct qca_vreg_data qca_soc_data = { · line 1278

Quoted 10 lines
drivers/bluetooth/hci_qca.c +1 -5
-	unsigned char cmd = QCA_WCN3990_POWEROFF_PULSE;
-
 	host_set_baudrate(hu, 2400);
-	hci_uart_set_flow_control(hu, true);
-	serdev_device_write_buf(serdev, &cmd, sizeof(cmd));
-	hci_uart_set_flow_control(hu, false);
+	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);
 }
 

Looks good to me besides possible minor improvements:

#3 lore raw

Re: [PATCH v9 1/3] Bluetooth: hci_qca: use wait_until_sent() for power pulses

Hi Matthias,

Quoted 30 lines · Matthias Kaehlcke
Quoted 29 lines · Balakrishna Godavarthi

wcn3990 requires a power pulse to turn ON/OFF along with regulators. Sometimes we are observing the power pulses are sent out with some time delay, due to queuing these commands. This is causing synchronization issues with chip, which intern delay the chip setup or may end up with communication issues.

---
Changes in v9:
* Reverted to 100us sleep.
* used inline call msecs_to_jiffies()

Changes in v8:
* Updated 1 second timeout instead of indefinite wait.

Changes in v7:
* updated the wait time to 5 ms after sending power pulses.

Changes in v6:
* added serdev_device_write_flush() in qca_send_power_pulse instead during the power off pulse.

Changes in v5:
* added serdev_device_write_flush() in qca_power_off().

---
 drivers/bluetooth/hci_qca.c | 40 
+++++++++++++++----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)
Quoted 13 lines

drivers/bluetooth/hci_qca.c line 63

Quoted 9 lines
drivers/bluetooth/hci_qca.c +1 -0
index f036c8f98ea3..c08f4d105e73 100644
@@ -60,6 +60,7 @@
 #define IBS_WAKE_RETRANS_TIMEOUT_MS	100
 #define IBS_TX_IDLE_TIMEOUT_MS		2000
 #define BAUDRATE_SETTLE_TIMEOUT_MS	300
+#define POWER_PULSE_TRANS_TIMEOUT_MS	1000

I still doubt that this mega-timeout of 1s is needed, but it shouldn't do any harm either, so whatever ...

[Bala]: for now let us have it. we can improve it in the improvement patch
based on the results.

Quoted 45 lines
Quoted 45 lines
drivers/bluetooth/hci_qca.c +3 -4
 /* susclk rate */
 #define SUSCLK_RATE_32KHZ	32768
@@ -1013,11 +1014,10 @@ static inline void host_set_baudrate(struct 
 hci_uart *hu, unsigned int speed)
 		hci_uart_set_baudrate(hu, speed);
 }
 
-static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
+static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd)
 {
-	struct hci_uart *hu = hci_get_drvdata(hdev);
-	struct qca_data *qca = hu->priv;
-	struct sk_buff *skb;
+	int ret;
+	int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS);
 
 	/* These power pulses are single byte command which are sent
drivers/bluetooth/hci_qca.c +8 -10
 	 * at required baudrate to wcn3990. On wcn3990, we have an external
@@ -1029,21 +1029,19 @@ static int qca_send_power_pulse(struct hci_dev 
 *hdev, u8 cmd)
 	 * save power. Disabling hardware flow control is mandatory while
 	 * sending power pulses to SoC.
 	 */
-	bt_dev_dbg(hdev, "sending power pulse %02x to SoC", cmd);
-
-	skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
-	if (!skb)
-		return -ENOMEM;
+	bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
 
+	serdev_device_write_flush(hu->serdev);
 	hci_uart_set_flow_control(hu, true);
+	ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
+	if (ret < 0) {
+		bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
+		return ret;
+	}
 
-	skb_put_u8(skb, cmd);
-	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
-
-	skb_queue_tail(&qca->txq, skb);
-	hci_uart_tx_wakeup(hu);
+	serdev_device_wait_until_sent(hu->serdev, timeout);
 
Quoted 6 lines

drivers/bluetooth/hci_qca.c static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd) · line 1044

Quoted 2 lines
drivers/bluetooth/hci_qca.c +1 -1
-	/* Wait for 100 uS for SoC to settle down */
+	/* Wait for 100 uS for SoC to settle down for the received byte. */

I don't think 'for the received byte' adds much value here. If you respin anyway I'd suggest to leave the comment as is.

[Bala]: will update.

Quoted 48 lines
Quoted 34 lines
drivers/bluetooth/hci_qca.c +2 -3
 	usleep_range(100, 200);
 	hci_uart_set_flow_control(hu, false);
@@ -1116,7 +1114,6 @@ static int qca_set_speed(struct hci_uart *hu, 
 enum qca_speed_type speed_type)
 
 static int qca_wcn3990_init(struct hci_uart *hu)
 {
-	struct hci_dev *hdev = hu->hdev;
 	struct qca_serdev *qcadev;
 	int ret;
@@ -1139,12 +1136,12 @@ static int qca_wcn3990_init(struct hci_uart 
 *hu)
 
 	/* Forcefully enable wcn3990 to enter in to boot mode. */
 	host_set_baudrate(hu, 2400);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWEROFF_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	if (ret)
 		return ret;
 
 	qca_set_speed(hu, QCA_INIT_SPEED);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWERON_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE);
 	if (ret)
 		return ret;
@@ -1274,13 +1271,8 @@ static const struct qca_vreg_data qca_soc_data 
 = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {

drivers/bluetooth/hci_qca.c static const struct qca_vreg_data qca_soc_data · line 1278

Quoted 10 lines
drivers/bluetooth/hci_qca.c +1 -6
-	struct serdev_device *serdev = hu->serdev;
-	unsigned char cmd = QCA_WCN3990_POWEROFF_PULSE;
-
 	host_set_baudrate(hu, 2400);
-	hci_uart_set_flow_control(hu, true);
-	serdev_device_write_buf(serdev, &cmd, sizeof(cmd));
-	hci_uart_set_flow_control(hu, false);
+	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);
 }

Looks good to me besides possible minor improvements:

Signature · 2 lines
Regards
Balakrishna.
#4 lore raw

Re: [PATCH v9 1/3] Bluetooth: hci_qca: use wait_until_sent() for power pulses

Quoted 47 lines · Balakrishna Godavarthi

Hi Matthias,

Quoted 30 lines · Matthias Kaehlcke
Quoted 29 lines · Balakrishna Godavarthi

wcn3990 requires a power pulse to turn ON/OFF along with regulators. Sometimes we are observing the power pulses are sent out with some time delay, due to queuing these commands. This is causing synchronization issues with chip, which intern delay the chip setup or may end up with communication issues.

---
Changes in v9:
* Reverted to 100us sleep.
* used inline call msecs_to_jiffies()

Changes in v8:
* Updated 1 second timeout instead of indefinite wait.

Changes in v7:
* updated the wait time to 5 ms after sending power pulses.

Changes in v6:
* added serdev_device_write_flush() in qca_send_power_pulse instead during the power off pulse.

Changes in v5:
* added serdev_device_write_flush() in qca_power_off().

---
 drivers/bluetooth/hci_qca.c | 40
+++++++++++++++----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)
Quoted 13 lines

drivers/bluetooth/hci_qca.c line 63

Quoted 9 lines
drivers/bluetooth/hci_qca.c +1 -0
index f036c8f98ea3..c08f4d105e73 100644
@@ -60,6 +60,7 @@
 #define IBS_WAKE_RETRANS_TIMEOUT_MS	100
 #define IBS_TX_IDLE_TIMEOUT_MS		2000
 #define BAUDRATE_SETTLE_TIMEOUT_MS	300
+#define POWER_PULSE_TRANS_TIMEOUT_MS	1000

I still doubt that this mega-timeout of 1s is needed, but it shouldn't do any harm either, so whatever ...

Quoted 2 lines

[Bala]: for now let us have it. we can improve it in the improvement patch
based on the results.

Fine.

With the UART buffer flushed and flow control disabled I wonder though what makes you think that it could take longer than a few milliseconds for the byte being put on the wire, short of a bug in the UART driver or hardware, which (if it existed) shouldn't be worked around here.

Quoted 103 lines
Quoted 45 lines
Quoted 45 lines
drivers/bluetooth/hci_qca.c +3 -4
 /* susclk rate */
 #define SUSCLK_RATE_32KHZ	32768
@@ -1013,11 +1014,10 @@ static inline void host_set_baudrate(struct
 hci_uart *hu, unsigned int speed)
 		hci_uart_set_baudrate(hu, speed);
 }
 
-static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
+static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd)
 {
-	struct hci_uart *hu = hci_get_drvdata(hdev);
-	struct qca_data *qca = hu->priv;
-	struct sk_buff *skb;
+	int ret;
+	int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS);
 
 	/* These power pulses are single byte command which are sent
drivers/bluetooth/hci_qca.c +8 -10
 	 * at required baudrate to wcn3990. On wcn3990, we have an external
@@ -1029,21 +1029,19 @@ static int qca_send_power_pulse(struct
 hci_dev *hdev, u8 cmd)
 	 * save power. Disabling hardware flow control is mandatory while
 	 * sending power pulses to SoC.
 	 */
-	bt_dev_dbg(hdev, "sending power pulse %02x to SoC", cmd);
-
-	skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
-	if (!skb)
-		return -ENOMEM;
+	bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
 
+	serdev_device_write_flush(hu->serdev);
 	hci_uart_set_flow_control(hu, true);
+	ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
+	if (ret < 0) {
+		bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
+		return ret;
+	}
 
-	skb_put_u8(skb, cmd);
-	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
-
-	skb_queue_tail(&qca->txq, skb);
-	hci_uart_tx_wakeup(hu);
+	serdev_device_wait_until_sent(hu->serdev, timeout);
 
Quoted 6 lines

drivers/bluetooth/hci_qca.c static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd) · line 1044

Quoted 2 lines
drivers/bluetooth/hci_qca.c +1 -1
-	/* Wait for 100 uS for SoC to settle down */
+	/* Wait for 100 uS for SoC to settle down for the received byte. */

I don't think 'for the received byte' adds much value here. If you respin anyway I'd suggest to leave the comment as is.

[Bala]: will update.

Quoted 48 lines
Quoted 34 lines
drivers/bluetooth/hci_qca.c +2 -3
 	usleep_range(100, 200);
 	hci_uart_set_flow_control(hu, false);
@@ -1116,7 +1114,6 @@ static int qca_set_speed(struct hci_uart *hu,
 enum qca_speed_type speed_type)
 
 static int qca_wcn3990_init(struct hci_uart *hu)
 {
-	struct hci_dev *hdev = hu->hdev;
 	struct qca_serdev *qcadev;
 	int ret;
@@ -1139,12 +1136,12 @@ static int qca_wcn3990_init(struct hci_uart
 *hu)
 
 	/* Forcefully enable wcn3990 to enter in to boot mode. */
 	host_set_baudrate(hu, 2400);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWEROFF_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	if (ret)
 		return ret;
 
 	qca_set_speed(hu, QCA_INIT_SPEED);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWERON_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE);
 	if (ret)
 		return ret;
@@ -1274,13 +1271,8 @@ static const struct qca_vreg_data
 qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {

drivers/bluetooth/hci_qca.c static const struct qca_vreg_data · line 1278

Quoted 10 lines
drivers/bluetooth/hci_qca.c +1 -6
-	struct serdev_device *serdev = hu->serdev;
-	unsigned char cmd = QCA_WCN3990_POWEROFF_PULSE;
-
 	host_set_baudrate(hu, 2400);
-	hci_uart_set_flow_control(hu, true);
-	serdev_device_write_buf(serdev, &cmd, sizeof(cmd));
-	hci_uart_set_flow_control(hu, false);
+	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);
 }

Looks good to me besides possible minor improvements:

#5 lore raw

Re: [PATCH v9 1/3] Bluetooth: hci_qca: use wait_until_sent() for power pulses

Hi Matthias,

Quoted 51 lines · Matthias Kaehlcke
Quoted 47 lines · Balakrishna Godavarthi

Hi Matthias,

Quoted 30 lines · Matthias Kaehlcke
Quoted 29 lines · Balakrishna Godavarthi

wcn3990 requires a power pulse to turn ON/OFF along with regulators. Sometimes we are observing the power pulses are sent out with some time delay, due to queuing these commands. This is causing synchronization issues with chip, which intern delay the chip setup or may end up with communication issues.

---
Changes in v9:
* Reverted to 100us sleep.
* used inline call msecs_to_jiffies()

Changes in v8:
* Updated 1 second timeout instead of indefinite wait.

Changes in v7:
* updated the wait time to 5 ms after sending power pulses.

Changes in v6:
* added serdev_device_write_flush() in qca_send_power_pulse instead during the power off pulse.

Changes in v5:
* added serdev_device_write_flush() in qca_power_off().

---
 drivers/bluetooth/hci_qca.c | 40
+++++++++++++++----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)
Quoted 13 lines

drivers/bluetooth/hci_qca.c line 63

Quoted 9 lines
drivers/bluetooth/hci_qca.c +1 -0
index f036c8f98ea3..c08f4d105e73 100644
@@ -60,6 +60,7 @@
 #define IBS_WAKE_RETRANS_TIMEOUT_MS	100
 #define IBS_TX_IDLE_TIMEOUT_MS		2000
 #define BAUDRATE_SETTLE_TIMEOUT_MS	300
+#define POWER_PULSE_TRANS_TIMEOUT_MS	1000

I still doubt that this mega-timeout of 1s is needed, but it shouldn't do any harm either, so whatever ...

Quoted 2 lines

[Bala]: for now let us have it. we can improve it in the improvement patch
based on the results.

Quoted 7 lines

Fine.

With the UART buffer flushed and flow control disabled I wonder though what makes you think that it could take longer than a few milliseconds for the byte being put on the wire, short of a bug in the UART driver or hardware, which (if it existed) shouldn't be worked around here.

[Bala]: i don't see any issue decreasing to milliseconds. will update it to 100ms.

Quoted 103 lines
Quoted 103 lines
Quoted 45 lines
Quoted 45 lines
drivers/bluetooth/hci_qca.c +3 -4
 /* susclk rate */
 #define SUSCLK_RATE_32KHZ	32768
@@ -1013,11 +1014,10 @@ static inline void host_set_baudrate(struct
 hci_uart *hu, unsigned int speed)
 		hci_uart_set_baudrate(hu, speed);
 }
 
-static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd)
+static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd)
 {
-	struct hci_uart *hu = hci_get_drvdata(hdev);
-	struct qca_data *qca = hu->priv;
-	struct sk_buff *skb;
+	int ret;
+	int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS);
 
 	/* These power pulses are single byte command which are sent
drivers/bluetooth/hci_qca.c +8 -10
 	 * at required baudrate to wcn3990. On wcn3990, we have an external
@@ -1029,21 +1029,19 @@ static int qca_send_power_pulse(struct
 hci_dev *hdev, u8 cmd)
 	 * save power. Disabling hardware flow control is mandatory while
 	 * sending power pulses to SoC.
 	 */
-	bt_dev_dbg(hdev, "sending power pulse %02x to SoC", cmd);
-
-	skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
-	if (!skb)
-		return -ENOMEM;
+	bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
 
+	serdev_device_write_flush(hu->serdev);
 	hci_uart_set_flow_control(hu, true);
+	ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
+	if (ret < 0) {
+		bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
+		return ret;
+	}
 
-	skb_put_u8(skb, cmd);
-	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
-
-	skb_queue_tail(&qca->txq, skb);
-	hci_uart_tx_wakeup(hu);
+	serdev_device_wait_until_sent(hu->serdev, timeout);
 
Quoted 6 lines

drivers/bluetooth/hci_qca.c static int qca_send_power_pulse(struct hci_dev *hdev, u8 cmd) · line 1044

Quoted 2 lines
drivers/bluetooth/hci_qca.c +1 -1
-	/* Wait for 100 uS for SoC to settle down */
+	/* Wait for 100 uS for SoC to settle down for the received byte. */

I don't think 'for the received byte' adds much value here. If you respin anyway I'd suggest to leave the comment as is.

[Bala]: will update.

Quoted 48 lines
Quoted 34 lines
drivers/bluetooth/hci_qca.c +2 -3
 	usleep_range(100, 200);
 	hci_uart_set_flow_control(hu, false);
@@ -1116,7 +1114,6 @@ static int qca_set_speed(struct hci_uart *hu,
 enum qca_speed_type speed_type)
 
 static int qca_wcn3990_init(struct hci_uart *hu)
 {
-	struct hci_dev *hdev = hu->hdev;
 	struct qca_serdev *qcadev;
 	int ret;
@@ -1139,12 +1136,12 @@ static int qca_wcn3990_init(struct hci_uart
 *hu)
 
 	/* Forcefully enable wcn3990 to enter in to boot mode. */
 	host_set_baudrate(hu, 2400);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWEROFF_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	if (ret)
 		return ret;
 
 	qca_set_speed(hu, QCA_INIT_SPEED);
-	ret = qca_send_power_pulse(hdev, QCA_WCN3990_POWERON_PULSE);
+	ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE);
 	if (ret)
 		return ret;
@@ -1274,13 +1271,8 @@ static const struct qca_vreg_data
 qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {

drivers/bluetooth/hci_qca.c static const struct qca_vreg_data · line 1278

Quoted 10 lines
drivers/bluetooth/hci_qca.c +1 -6
-	struct serdev_device *serdev = hu->serdev;
-	unsigned char cmd = QCA_WCN3990_POWEROFF_PULSE;
-
 	host_set_baudrate(hu, 2400);
-	hci_uart_set_flow_control(hu, true);
-	serdev_device_write_buf(serdev, &cmd, sizeof(cmd));
-	hci_uart_set_flow_control(hu, false);
+	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);
 }

Looks good to me besides possible minor improvements:

Signature · 2 lines
Regards
Balakrishna.
#6 lore raw

PATCH v9 2/3 Bluetooth: hci_qca: Deassert RTS while baudrate change command

In reply to Balakrishna Godavarthi

This patch will help to stop frame reassembly errors while changing the baudrate. This is because host send a change baudrate request command to the chip with 115200 bps, Whereas chip will change their UART clocks to the enable for new baudrate and sends the response for the change request command with newer baudrate, On host side we are still operating in 115200 bps which results of reading garbage data. Here we are pulling RTS line, so that chip we will wait to send data to host until host change its baudrate.

---
Changes in v9:
* disabled flow control while setting the baudrate of HOST and chip.

---
 drivers/bluetooth/hci_qca.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/bluetooth/hci_qca.c +13 -11
index c08f4d105e73..6b5bcd44e24c 100644
@@ -964,7 +964,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 	struct hci_uart *hu = hci_get_drvdata(hdev);
 	struct qca_data *qca = hu->priv;
 	struct sk_buff *skb;
-	struct qca_serdev *qcadev;
 	u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
 
 	if (baudrate > QCA_BAUDRATE_3200000)
@@ -978,13 +977,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 		return -ENOMEM;
 	}
 
-	/* Disabling hardware flow control is mandatory while
-	 * sending change baudrate request to wcn3990 SoC.
-	 */
-	qcadev = serdev_device_get_drvdata(hu->serdev);
-	if (qcadev->btsoc_type == QCA_WCN3990)
-		hci_uart_set_flow_control(hu, true);
-
 	/* Assign commands to change baudrate and packet type. */
 	skb_put_data(skb, cmd, sizeof(cmd));
 	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
@@ -1000,9 +992,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 	schedule_timeout(msecs_to_jiffies(BAUDRATE_SETTLE_TIMEOUT_MS));
 	set_current_state(TASK_RUNNING);
 
-	if (qcadev->btsoc_type == QCA_WCN3990)
-		hci_uart_set_flow_control(hu, false);
-
 	return 0;
 }
 
@@ -1089,6 +1078,7 @@ static int qca_check_speeds(struct hci_uart *hu)
 static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 {
 	unsigned int speed, qca_baudrate;
+	struct qca_serdev *qcadev;
 	int ret;
 
 	if (speed_type == QCA_INIT_SPEED) {
@@ -1100,6 +1090,15 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 		if (!speed)
 			return 0;
 
+		/* Deassert RTS while changing the baudrate of chip and host.
+		 * This will prevent chip from transmitting its response with
+		 * the new baudrate while the host port is still operating at
+		 * the old speed.
+		 */
+		qcadev = serdev_device_get_drvdata(hu->serdev);
+		if (qcadev->btsoc_type == QCA_WCN3990)
+			hci_uart_set_flow_control(hu, true);
+
 		qca_baudrate = qca_get_baudrate_value(speed);
 		bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);
 		ret = qca_set_baudrate(hu->hdev, qca_baudrate);
@@ -1107,6 +1106,9 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 			return ret;
 
 		host_set_baudrate(hu, speed);
+
+		if (qcadev->btsoc_type == QCA_WCN3990)
+			hci_uart_set_flow_control(hu, false);
 	}
 
 	return 0;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw

Re: [PATCH v9 2/3] Bluetooth: hci_qca: Deassert RTS while baudrate change command

Hi Balakrishna,

Quoted 64 lines · Balakrishna Godavarthi

This patch will help to stop frame reassembly errors while changing the baudrate. This is because host send a change baudrate request command to the chip with 115200 bps, Whereas chip will change their UART clocks to the enable for new baudrate and sends the response for the change request command with newer baudrate, On host side we are still operating in 115200 bps which results of reading garbage data. Here we are pulling RTS line, so that chip we will wait to send data to host until host change its baudrate.

---
Changes in v9:
* disabled flow control while setting the baudrate of HOST and chip.

---
 drivers/bluetooth/hci_qca.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/bluetooth/hci_qca.c +1 -11
index c08f4d105e73..6b5bcd44e24c 100644
@@ -964,7 +964,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 	struct hci_uart *hu = hci_get_drvdata(hdev);
 	struct qca_data *qca = hu->priv;
 	struct sk_buff *skb;
-	struct qca_serdev *qcadev;
 	u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
 
 	if (baudrate > QCA_BAUDRATE_3200000)
@@ -978,13 +977,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 		return -ENOMEM;
 	}
 
-	/* Disabling hardware flow control is mandatory while
-	 * sending change baudrate request to wcn3990 SoC.
-	 */
-	qcadev = serdev_device_get_drvdata(hu->serdev);
-	if (qcadev->btsoc_type == QCA_WCN3990)
-		hci_uart_set_flow_control(hu, true);
-
 	/* Assign commands to change baudrate and packet type. */
 	skb_put_data(skb, cmd, sizeof(cmd));
 	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
@@ -1000,9 +992,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 	schedule_timeout(msecs_to_jiffies(BAUDRATE_SETTLE_TIMEOUT_MS));
 	set_current_state(TASK_RUNNING);
 
-	if (qcadev->btsoc_type == QCA_WCN3990)
-		hci_uart_set_flow_control(hu, false);
-
 	return 0;
 }
 
@@ -1089,6 +1078,7 @@ static int qca_check_speeds(struct hci_uart *hu)
 static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 {
 	unsigned int speed, qca_baudrate;
+	struct qca_serdev *qcadev;
 	int ret;
 
 	if (speed_type == QCA_INIT_SPEED) {

drivers/bluetooth/hci_qca.c static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) · line 1097

Quoted 8 lines
drivers/bluetooth/hci_qca.c +5 -0
@@ -1100,6 +1090,15 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
 		if (!speed)
 			return 0;
 
+		/* Deassert RTS while changing the baudrate of chip and host.
+		 * This will prevent chip from transmitting its response with
+		 * the new baudrate while the host port is still operating at
+		 * the old speed.
+		 */

It is not necessarily evident which action deasserts RTS, I suggest to rephrase it to something like:

"Disable flow control for wcn3990 to deassert RTS while ... "

drivers/bluetooth/hci_qca.c static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) · line 1104

Quoted 7 lines
drivers/bluetooth/hci_qca.c +4 -0
+		qcadev = serdev_device_get_drvdata(hu->serdev);
+		if (qcadev->btsoc_type == QCA_WCN3990)
+			hci_uart_set_flow_control(hu, true);
+
 		qca_baudrate = qca_get_baudrate_value(speed);
 		bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);
 		ret = qca_set_baudrate(hu->hdev, qca_baudrate);

flow control should be re-enabled in the error path.

Cheers

Matthias

#8 lore raw

Re: [PATCH v9 2/3] Bluetooth: hci_qca: Deassert RTS while baudrate change command

Hi Matthias,

Quoted 84 lines · Matthias Kaehlcke

Hi Balakrishna,

Quoted 68 lines · Balakrishna Godavarthi

This patch will help to stop frame reassembly errors while changing the baudrate. This is because host send a change baudrate request command to the chip with 115200 bps, Whereas chip will change their UART clocks to the enable for new baudrate and sends the response for the change request command with newer baudrate, On host side we are still operating in 115200 bps which results of reading garbage data. Here we are pulling RTS line, so that chip we will wait to send data to host until host change its baudrate.

---
Changes in v9:
* disabled flow control while setting the baudrate of HOST and chip.

---
 drivers/bluetooth/hci_qca.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/bluetooth/hci_qca.c +0 -1
index c08f4d105e73..6b5bcd44e24c 100644
@@ -964,7 +964,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, 
 uint8_t baudrate)
 	struct hci_uart *hu = hci_get_drvdata(hdev);
 	struct qca_data *qca = hu->priv;
 	struct sk_buff *skb;
-	struct qca_serdev *qcadev;
 	u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
 
drivers/bluetooth/hci_qca.c +0 -7
 	if (baudrate > QCA_BAUDRATE_3200000)
@@ -978,13 +977,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, 
 uint8_t baudrate)
 		return -ENOMEM;
 	}
 
-	/* Disabling hardware flow control is mandatory while
-	 * sending change baudrate request to wcn3990 SoC.
-	 */
-	qcadev = serdev_device_get_drvdata(hu->serdev);
-	if (qcadev->btsoc_type == QCA_WCN3990)
-		hci_uart_set_flow_control(hu, true);
-
 	/* Assign commands to change baudrate and packet type. */
 	skb_put_data(skb, cmd, sizeof(cmd));
drivers/bluetooth/hci_qca.c +1 -3
 	hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
@@ -1000,9 +992,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, 
 uint8_t baudrate)
 	schedule_timeout(msecs_to_jiffies(BAUDRATE_SETTLE_TIMEOUT_MS));
 	set_current_state(TASK_RUNNING);
 
-	if (qcadev->btsoc_type == QCA_WCN3990)
-		hci_uart_set_flow_control(hu, false);
-
 	return 0;
 }
@@ -1089,6 +1078,7 @@ static int qca_check_speeds(struct hci_uart *hu)
 static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type 
 speed_type)
 {
 	unsigned int speed, qca_baudrate;
+	struct qca_serdev *qcadev;
 	int ret;
 
drivers/bluetooth/hci_qca.c +0 -0
 	if (speed_type == QCA_INIT_SPEED) {

drivers/bluetooth/hci_qca.c static int qca_set_speed(struct hci_uart *hu, · line 1098

Quoted 9 lines
drivers/bluetooth/hci_qca.c +5 -0
@@ -1100,6 +1090,15 @@ static int qca_set_speed(struct hci_uart *hu, 
 enum qca_speed_type speed_type)
 		if (!speed)
 			return 0;
 
+		/* Deassert RTS while changing the baudrate of chip and host.
+		 * This will prevent chip from transmitting its response with
+		 * the new baudrate while the host port is still operating at
+		 * the old speed.
+		 */

It is not necessarily evident which action deasserts RTS, I suggest to rephrase it to something like:

Quoted 2 lines

"Disable flow control for wcn3990 to deassert RTS while ... "

[Bala]: will update.

Quoted 10 lines
Quoted 7 lines
drivers/bluetooth/hci_qca.c +4 -0
+		qcadev = serdev_device_get_drvdata(hu->serdev);
+		if (qcadev->btsoc_type == QCA_WCN3990)
+			hci_uart_set_flow_control(hu, true);
+
 		qca_baudrate = qca_get_baudrate_value(speed);
 		bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);

ret = qca_set_baudrate(hu->hdev, qca_baudrate);

flow control should be re-enabled in the error path.

Quoted 3 lines

Cheers

Matthias

[Bala; will update.

Signature · 2 lines
Regards
Balakrishna.
#9 lore raw

PATCH v9 3/3 Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

In reply to Balakrishna Godavarthi

During hci down we observed IBS sleep commands are queued in the Tx buffer and hci_uart_write_work is sending data to the chip which is not required as the chip is powered off. This patch will disable IBS and flush the Tx buffer before we turn off the chip.

---
Changes v9:
* added lock while disabling the IBS state machine.

---
 drivers/bluetooth/hci_qca.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_qca.c +15 -2
index 6b5bcd44e24c..99ddc35f08c6 100644
@@ -771,16 +771,17 @@ static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 	/* Prepend skb with frame type */
 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
 
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+
 	/* Don't go to sleep in middle of patch download or
 	 * Out-Of-Band(GPIOs control) sleep is selected.
 	 */
 	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
 		skb_queue_tail(&qca->txq, skb);
+		spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
 		return 0;
 	}
 
-	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
-
 	/* Act according to current state */
 	switch (qca->tx_ibs_state) {
 	case HCI_IBS_TX_AWAKE:
@@ -1273,6 +1274,18 @@ static const struct qca_vreg_data qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {
+	struct qca_data *qca = hu->priv;
+	unsigned long flags;
+
+	/* From this point we go into power off state. But serial port is
+	 * still open, stop queueing the IBS data and flush all the buffered
+	 * data in skb's.
+	 */
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+	clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+	qca_flush(hu);
+	spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
+
 	host_set_baudrate(hu, 2400);
 	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#10 lore raw

Re: [PATCH v9 3/3] Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

Quoted 47 lines · Balakrishna Godavarthi

During hci down we observed IBS sleep commands are queued in the Tx buffer and hci_uart_write_work is sending data to the chip which is not required as the chip is powered off. This patch will disable IBS and flush the Tx buffer before we turn off the chip.

---
Changes v9:
* added lock while disabling the IBS state machine.

---
 drivers/bluetooth/hci_qca.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_qca.c +8 -2
index 6b5bcd44e24c..99ddc35f08c6 100644
@@ -771,16 +771,17 @@ static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 	/* Prepend skb with frame type */
 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
 
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+
 	/* Don't go to sleep in middle of patch download or
 	 * Out-Of-Band(GPIOs control) sleep is selected.
 	 */
 	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
 		skb_queue_tail(&qca->txq, skb);
+		spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
 		return 0;
 	}
 
-	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
-
 	/* Act according to current state */
 	switch (qca->tx_ibs_state) {
 	case HCI_IBS_TX_AWAKE:
@@ -1273,6 +1274,18 @@ static const struct qca_vreg_data qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {
+	struct qca_data *qca = hu->priv;
+	unsigned long flags;
+
+	/* From this point we go into power off state. But serial port is
+	 * still open, stop queueing the IBS data and flush all the buffered

drivers/bluetooth/hci_qca.c static const struct qca_vreg_data qca_soc_data = { · line 1291

Quoted 10 lines
drivers/bluetooth/hci_qca.c +7 -0
+	 * data in skb's.
+	 */
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+	clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+	qca_flush(hu);
+	spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
+
 	host_set_baudrate(hu, 2400);
 	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
 	qca_power_setup(hu, false);

I was about to add my 'Reviewed-by' tag, but I'm still left with a doubt. This patch certainly improves the situation by clearing the IBS bit and flushing the buffered data, however IIUC new data could still be added to the TX queue after releasing the spinlock:

static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)

{
	...

	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
		skb_queue_tail(&qca->txq, skb);

	...
}

To prevent this a boolean/bit like 'shutting_down' or similar would be needed (I don't think there is something common in the HCI core), which is set in qca_power_shutdown(). If the bit is set qca_enqueue() discards the data.

Not sure how important this is, and I don't want to add necessarily more revisions to this series. If it is preferable to have an empty queue after shutdown maybe it can be done in a follow up patch.

Thanks

Matthias

#11 lore raw

Re: [PATCH v9 3/3] Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

Hi Matthias,

Quoted 81 lines · Matthias Kaehlcke
Quoted 58 lines · Balakrishna Godavarthi

During hci down we observed IBS sleep commands are queued in the Tx buffer and hci_uart_write_work is sending data to the chip which is not required as the chip is powered off. This patch will disable IBS and flush the Tx buffer before we turn off the chip.

---
Changes v9:
* added lock while disabling the IBS state machine.

---
 drivers/bluetooth/hci_qca.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_qca.c +3 -2
index 6b5bcd44e24c..99ddc35f08c6 100644
@@ -771,16 +771,17 @@ static int qca_enqueue(struct hci_uart *hu, 
 struct sk_buff *skb)
 	/* Prepend skb with frame type */
 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
 
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+
 	/* Don't go to sleep in middle of patch download or
 	 * Out-Of-Band(GPIOs control) sleep is selected.
 	 */
 	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
 		skb_queue_tail(&qca->txq, skb);
+		spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
 		return 0;
 	}
 
-	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
-
 	/* Act according to current state */
 	switch (qca->tx_ibs_state) {
drivers/bluetooth/hci_qca.c +12 -0
 	case HCI_IBS_TX_AWAKE:
@@ -1273,6 +1274,18 @@ static const struct qca_vreg_data qca_soc_data 
 = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {
+	struct qca_data *qca = hu->priv;
+	unsigned long flags;
+
+	/* From this point we go into power off state. But serial port is
+	 * still open, stop queueing the IBS data and flush all the buffered
+	 * data in skb's.
+	 */
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+	clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+	qca_flush(hu);
+	spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
+
 	host_set_baudrate(hu, 2400);
 	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
Quoted 1 line

qca_power_setup(hu, false);

I was about to add my 'Reviewed-by' tag, but I'm still left with a doubt. This patch certainly improves the situation by clearing the IBS bit and flushing the buffered data, however IIUC new data could still be added to the TX queue after releasing the spinlock:

static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)

{
	...

	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
		skb_queue_tail(&qca->txq, skb);

	...
}

To prevent this a boolean/bit like 'shutting_down' or similar would be needed (I don't think there is something common in the HCI core), which is set in qca_power_shutdown(). If the bit is set qca_enqueue() discards the data.

Quoted 7 lines

Not sure how important this is, and I don't want to add necessarily more revisions to this series. If it is preferable to have an empty queue after shutdown maybe it can be done in a follow up patch.

Thanks

Matthias

[Bala]: during shutdown Bt stack will not send any data to the Bt kernel Tx path.
so this call may not be called. once we shutdown chip.

Signature · 2 lines
Regards
Balakrishna.
Reviewed-by
#12 lore raw

Re: [PATCH v9 3/3] Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

Quoted 88 lines · Balakrishna Godavarthi

Hi Matthias,

Quoted 85 lines · Matthias Kaehlcke
Quoted 58 lines · Balakrishna Godavarthi

During hci down we observed IBS sleep commands are queued in the Tx buffer and hci_uart_write_work is sending data to the chip which is not required as the chip is powered off. This patch will disable IBS and flush the Tx buffer before we turn off the chip.

---
Changes v9:
* added lock while disabling the IBS state machine.

---
 drivers/bluetooth/hci_qca.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_qca.c +3 -2
index 6b5bcd44e24c..99ddc35f08c6 100644
@@ -771,16 +771,17 @@ static int qca_enqueue(struct hci_uart *hu,
 struct sk_buff *skb)
 	/* Prepend skb with frame type */
 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
 
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+
 	/* Don't go to sleep in middle of patch download or
 	 * Out-Of-Band(GPIOs control) sleep is selected.
 	 */
 	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
 		skb_queue_tail(&qca->txq, skb);
+		spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
 		return 0;
 	}
 
-	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
-
 	/* Act according to current state */
 	switch (qca->tx_ibs_state) {
drivers/bluetooth/hci_qca.c +12 -0
 	case HCI_IBS_TX_AWAKE:
@@ -1273,6 +1274,18 @@ static const struct qca_vreg_data
 qca_soc_data = {
 
 static void qca_power_shutdown(struct hci_uart *hu)
 {
+	struct qca_data *qca = hu->priv;
+	unsigned long flags;
+
+	/* From this point we go into power off state. But serial port is
+	 * still open, stop queueing the IBS data and flush all the buffered
+	 * data in skb's.
+	 */
+	spin_lock_irqsave(&qca->hci_ibs_lock, flags);
+	clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+	qca_flush(hu);
+	spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
+
 	host_set_baudrate(hu, 2400);
 	qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE);
Quoted 1 line

qca_power_setup(hu, false);

I was about to add my 'Reviewed-by' tag, but I'm still left with a doubt. This patch certainly improves the situation by clearing the IBS bit and flushing the buffered data, however IIUC new data could still be added to the TX queue after releasing the spinlock:

static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)

{
	...

	if (!test_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags)) {
		skb_queue_tail(&qca->txq, skb);

	...
}

To prevent this a boolean/bit like 'shutting_down' or similar would be needed (I don't think there is something common in the HCI core), which is set in qca_power_shutdown(). If the bit is set qca_enqueue() discards the data.

Not sure how important this is, and I don't want to add necessarily more revisions to this series. If it is preferable to have an empty queue after shutdown maybe it can be done in a follow up patch.

Quoted 7 lines
Quoted 3 lines

Thanks

Matthias

[Bala]: during shutdown Bt stack will not send any data to the Bt kernel Tx path.
so this call may not be called. once we shutdown chip.

Thanks for the clarification! I kinda expected that, but it wasn't evident to me from the core code.