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(-)
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
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]>
---
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(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index f036c8f98ea3..c08f4d105e73 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 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);
}
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
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 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(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index c08f4d105e73..6b5bcd44e24c 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,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;
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
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]>
---
Changes v9:
* added lock while disabling the IBS state machine.
---
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 6b5bcd44e24c..99ddc35f08c6 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:
@@ -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);
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Hi Balakrishna,
On Thu, Jan 24, 2019 at 05:38:07PM +0530, Balakrishna Godavarthi wrote:
> 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 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(-)
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index c08f4d105e73..6b5bcd44e24c 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,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.
> + */
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 ... "
> + 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
On Thu, Jan 24, 2019 at 05:38:08PM +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]>
> ---
> Changes v9:
> * added lock while disabling the IBS state machine.
>
> ---
> 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 6b5bcd44e24c..99ddc35f08c6 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:
> @@ -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);
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
On Thu, Jan 24, 2019 at 05:38:06PM +0530, Balakrishna Godavarthi wrote:
> 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]>
> ---
> 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(-)
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index f036c8f98ea3..c08f4d105e73 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 1000
I still doubt that this mega-timeout of 1s is needed, but it shouldn't
do any harm either, so whatever ...
> /* 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. */
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.
> 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);
> }
>
Looks good to me besides possible minor improvements:
Reviewed-by: Matthias Kaehlcke <[email protected]>
Hi Matthias,
On 2019-01-25 05:42, Matthias Kaehlcke wrote:
> Hi Balakrishna,
>
> On Thu, Jan 24, 2019 at 05:38:07PM +0530, Balakrishna Godavarthi wrote:
>> 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 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(-)
>>
>> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
>> index c08f4d105e73..6b5bcd44e24c 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,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.
>> + */
>
> 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 ... "
>
[Bala]: will update.
>> + 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
[Bala; will update.
--
Regards
Balakrishna.
Hi Matthias,
On 2019-01-25 06:44, Matthias Kaehlcke wrote:
> On Thu, Jan 24, 2019 at 05:38:06PM +0530, Balakrishna Godavarthi wrote:
>> 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]>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
>> index f036c8f98ea3..c08f4d105e73 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 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.
>> /* 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. */
>
> 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.
>> 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);
>> }
>>
>
> Looks good to me besides possible minor improvements:
>
> Reviewed-by: Matthias Kaehlcke <[email protected]>
--
Regards
Balakrishna.
On Mon, Jan 28, 2019 at 07:19:56PM +0530, Balakrishna Godavarthi wrote:
> Hi Matthias,
>
> On 2019-01-25 06:44, Matthias Kaehlcke wrote:
> > On Thu, Jan 24, 2019 at 05:38:06PM +0530, Balakrishna Godavarthi wrote:
> > > 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]>
> > > ---
> > > 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(-)
> > >
> > > diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> > > index f036c8f98ea3..c08f4d105e73 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 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.
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.
> > > /* 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. */
> >
> > 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.
>
> > > 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);
> > > }
> > >
> >
> > Looks good to me besides possible minor improvements:
> >
> > Reviewed-by: Matthias Kaehlcke <[email protected]>
>
Hi Matthias,
On 2019-01-28 23:17, Matthias Kaehlcke wrote:
> On Mon, Jan 28, 2019 at 07:19:56PM +0530, Balakrishna Godavarthi wrote:
>> Hi Matthias,
>>
>> On 2019-01-25 06:44, Matthias Kaehlcke wrote:
>> > On Thu, Jan 24, 2019 at 05:38:06PM +0530, Balakrishna Godavarthi wrote:
>> > > 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]>
>> > > ---
>> > > 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(-)
>> > >
>> > > diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
>> > > index f036c8f98ea3..c08f4d105e73 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 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.
>
> 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.
>> > > /* 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. */
>> >
>> > 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.
>>
>> > > 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);
>> > > }
>> > >
>> >
>> > Looks good to me besides possible minor improvements:
>> >
>> > Reviewed-by: Matthias Kaehlcke <[email protected]>
>>
--
Regards
Balakrishna.
Hi Matthias,
On 2019-01-25 06:25, Matthias Kaehlcke wrote:
> On Thu, Jan 24, 2019 at 05:38:08PM +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]>
>> ---
>> Changes v9:
>> * added lock while disabling the IBS state machine.
>>
>> ---
>> 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 6b5bcd44e24c..99ddc35f08c6 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:
>> @@ -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);
>
> 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
[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.
--
Regards
Balakrishna.
On Fri, Feb 01, 2019 at 05:10:11PM +0530, Balakrishna Godavarthi wrote:
> Hi Matthias,
>
> On 2019-01-25 06:25, Matthias Kaehlcke wrote:
> > On Thu, Jan 24, 2019 at 05:38:08PM +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]>
> > > ---
> > > Changes v9:
> > > * added lock while disabling the IBS state machine.
> > >
> > > ---
> > > 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 6b5bcd44e24c..99ddc35f08c6 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:
> > > @@ -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);
> >
> > 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
>
> [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.
Reviewed-by: Matthias Kaehlcke <[email protected]>