2019-02-04 15:06:58

by Balakrishna Godavarthi

[permalink] [raw]
Subject: [PATCH v11 0/3] 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 v11:
* added correct signatures for the patch.

Changes in v10:
* Decreased wait time for power pulse to 100 ms instead of 1second.
* enabling the flow control back when baudarte change request fails.
* updated review comments.

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 | 82 ++++++++++++++++++++-----------------
1 file changed, 44 insertions(+), 38 deletions(-)

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



2019-02-04 15:07:15

by Balakrishna Godavarthi

[permalink] [raw]
Subject: [PATCH v11 3/3] Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

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.

Signed-off-by: Balakrishna Godavarthi <[email protected]>
---
drivers/bluetooth/hci_qca.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index e3cf0dbfc89d..5e03504c4e0c 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -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:
@@ -1275,6 +1276,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);
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2019-02-04 15:07:17

by Balakrishna Godavarthi

[permalink] [raw]
Subject: [PATCH v11 2/3] Bluetooth: hci_qca: Deassert RTS while baudrate change command

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.

Signed-off-by: Balakrishna Godavarthi <[email protected]>
Tested-by: Matthias Kaehlcke <[email protected]>
Reviewed-by: Matthias Kaehlcke <[email protected]>
---
Changes in v10:
Enabled flow control back when the baudarte change request fails.
---
drivers/bluetooth/hci_qca.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 9a1c0a71b460..e3cf0dbfc89d 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -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,7 +1078,8 @@ 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;
- int ret;
+ struct qca_serdev *qcadev;
+ int ret = 0;

if (speed_type == QCA_INIT_SPEED) {
speed = qca_get_speed(hu, QCA_INIT_SPEED);
@@ -1100,16 +1090,27 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
if (!speed)
return 0;

+ /* Disable flow control for wcn3990 to deassert RTS while
+ * changing the baudrate of chip and host.
+ */
+ 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);
if (ret)
- return ret;
+ goto error;

host_set_baudrate(hu, speed);
+
+error:
+ if (qcadev->btsoc_type == QCA_WCN3990)
+ hci_uart_set_flow_control(hu, false);
}

- return 0;
+ return ret;
}

static int qca_wcn3990_init(struct hci_uart *hu)
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2019-02-04 15:07:19

by Balakrishna Godavarthi

[permalink] [raw]
Subject: [PATCH v11 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.

Signed-off-by: Balakrishna Godavarthi <[email protected]>
Reviewed-by: Matthias Kaehlcke <[email protected]>
---
Changes in v10:
Updated the wait time to 100 us for power pules.
---
drivers/bluetooth/hci_qca.c | 38 +++++++++++++++----------------------
1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 53ac5ade532b..9a1c0a71b460 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -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 100

/* 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,19 +1029,17 @@ 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 */
usleep_range(100, 200);
@@ -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;

@@ -1277,13 +1274,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);
}

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2019-02-04 17:31:37

by Matthias Kaehlcke

[permalink] [raw]
Subject: Re: [PATCH v11 3/3] Bluetooth: hci_qca: Disable IBS state machine and flush Tx buffer

On Mon, Feb 04, 2019 at 08:36:43PM +0530, Balakrishna Godavarthi wrote:
> 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.
>
> Signed-off-by: Balakrishna Godavarthi <[email protected]>
> ---
> drivers/bluetooth/hci_qca.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index e3cf0dbfc89d..5e03504c4e0c 100644
> --- a/drivers/bluetooth/hci_qca.c
> +++ b/drivers/bluetooth/hci_qca.c
> @@ -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:
> @@ -1275,6 +1276,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);

Reviewed-by: Matthias Kaehlcke <[email protected]>

2019-02-18 10:50:59

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH v11 0/3] Bug fixes for Qualcomm BT chip wcn3990

Hi Balakrishna,

> 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 v11:
> * added correct signatures for the patch.
>
> Changes in v10:
> * Decreased wait time for power pulse to 100 ms instead of 1second.
> * enabling the flow control back when baudarte change request fails.
> * updated review comments.
>
> 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 | 82 ++++++++++++++++++++-----------------
> 1 file changed, 44 insertions(+), 38 deletions(-)

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

Regards

Marcel