Skip to content

Commit 2faa3f1

Browse files
mkaehlckeholtmann
authored andcommitted
Bluetooth: hci_qca: wcn3990: Drop baudrate change vendor event
Firmware download to the WCN3990 often fails with a 'TLV response size mismatch' error: [ 133.064659] Bluetooth: hci0: setting up wcn3990 [ 133.489150] Bluetooth: hci0: QCA controller version 0x02140201 [ 133.495245] Bluetooth: hci0: QCA Downloading qca/crbtfw21.tlv [ 133.507214] Bluetooth: hci0: QCA TLV response size mismatch [ 133.513265] Bluetooth: hci0: QCA Failed to download patch (-84) This is caused by a vendor event that corresponds to an earlier command to change the baudrate. The event is not processed in the context of the baudrate change and is later interpreted as response to the firmware download command (which is also a vendor command), but the driver detects that the event doesn't have the expected amount of associated data. More details: For the WCN3990 the vendor command for a baudrate change isn't sent as synchronous HCI command, because the controller sends the corresponding vendor event with the new baudrate. The event is received and decoded after the baudrate change of the host port. Identify the 'unused' event when it is received and don't add it to the queue of RX frames. Signed-off-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 32646db commit 2faa3f1

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

‎drivers/bluetooth/hci_qca.c‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <linux/kernel.h>
1919
#include <linux/clk.h>
20+
#include <linux/completion.h>
2021
#include <linux/debugfs.h>
2122
#include <linux/delay.h>
2223
#include <linux/device.h>
@@ -53,6 +54,7 @@
5354

5455
enum qca_flags {
5556
QCA_IBS_ENABLED,
57+
QCA_DROP_VENDOR_EVENT,
5658
};
5759

5860
/* HCI_IBS transmit side sleep protocol states */
@@ -97,6 +99,7 @@ struct qca_data {
9799
struct work_struct ws_rx_vote_off;
98100
struct work_struct ws_tx_vote_off;
99101
unsigned long flags;
102+
struct completion drop_ev_comp;
100103

101104
/* For debugging purpose */
102105
u64 ibs_sent_wacks;
@@ -478,6 +481,7 @@ static int qca_open(struct hci_uart *hu)
478481
INIT_WORK(&qca->ws_tx_vote_off, qca_wq_serial_tx_clock_vote_off);
479482

480483
qca->hu = hu;
484+
init_completion(&qca->drop_ev_comp);
481485

482486
/* Assume we start with both sides asleep -- extra wakes OK */
483487
qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
@@ -872,6 +876,35 @@ static int qca_recv_acl_data(struct hci_dev *hdev, struct sk_buff *skb)
872876
return hci_recv_frame(hdev, skb);
873877
}
874878

879+
static int qca_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
880+
{
881+
struct hci_uart *hu = hci_get_drvdata(hdev);
882+
struct qca_data *qca = hu->priv;
883+
884+
if (test_bit(QCA_DROP_VENDOR_EVENT, &qca->flags)) {
885+
struct hci_event_hdr *hdr = (void *)skb->data;
886+
887+
/* For the WCN3990 the vendor command for a baudrate change
888+
* isn't sent as synchronous HCI command, because the
889+
* controller sends the corresponding vendor event with the
890+
* new baudrate. The event is received and properly decoded
891+
* after changing the baudrate of the host port. It needs to
892+
* be dropped, otherwise it can be misinterpreted as
893+
* response to a later firmware download command (also a
894+
* vendor command).
895+
*/
896+
897+
if (hdr->evt == HCI_EV_VENDOR)
898+
complete(&qca->drop_ev_comp);
899+
900+
kfree(skb);
901+
902+
return 0;
903+
}
904+
905+
return hci_recv_frame(hdev, skb);
906+
}
907+
875908
#define QCA_IBS_SLEEP_IND_EVENT \
876909
.type = HCI_IBS_SLEEP_IND, \
877910
.hlen = 0, \
@@ -896,7 +929,7 @@ static int qca_recv_acl_data(struct hci_dev *hdev, struct sk_buff *skb)
896929
static const struct h4_recv_pkt qca_recv_pkts[] = {
897930
{ H4_RECV_ACL, .recv = qca_recv_acl_data },
898931
{ H4_RECV_SCO, .recv = hci_recv_frame },
899-
{ H4_RECV_EVENT, .recv = hci_recv_frame },
932+
{ H4_RECV_EVENT, .recv = qca_recv_event },
900933
{ QCA_IBS_WAKE_IND_EVENT, .recv = qca_ibs_wake_ind },
901934
{ QCA_IBS_WAKE_ACK_EVENT, .recv = qca_ibs_wake_ack },
902935
{ QCA_IBS_SLEEP_IND_EVENT, .recv = qca_ibs_sleep_ind },
@@ -1091,6 +1124,7 @@ static int qca_check_speeds(struct hci_uart *hu)
10911124
static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
10921125
{
10931126
unsigned int speed, qca_baudrate;
1127+
struct qca_data *qca = hu->priv;
10941128
int ret = 0;
10951129

10961130
if (speed_type == QCA_INIT_SPEED) {
@@ -1110,6 +1144,11 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
11101144
if (qca_is_wcn399x(soc_type))
11111145
hci_uart_set_flow_control(hu, true);
11121146

1147+
if (soc_type == QCA_WCN3990) {
1148+
reinit_completion(&qca->drop_ev_comp);
1149+
set_bit(QCA_DROP_VENDOR_EVENT, &qca->flags);
1150+
}
1151+
11131152
qca_baudrate = qca_get_baudrate_value(speed);
11141153
bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);
11151154
ret = qca_set_baudrate(hu->hdev, qca_baudrate);
@@ -1121,6 +1160,20 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
11211160
error:
11221161
if (qca_is_wcn399x(soc_type))
11231162
hci_uart_set_flow_control(hu, false);
1163+
1164+
if (soc_type == QCA_WCN3990) {
1165+
/* Wait for the controller to send the vendor event
1166+
* for the baudrate change command.
1167+
*/
1168+
if (!wait_for_completion_timeout(&qca->drop_ev_comp,
1169+
msecs_to_jiffies(100))) {
1170+
bt_dev_err(hu->hdev,
1171+
"Failed to change controller baudrate\n");
1172+
ret = -ETIMEDOUT;
1173+
}
1174+
1175+
clear_bit(QCA_DROP_VENDOR_EVENT, &qca->flags);
1176+
}
11241177
}
11251178

11261179
return ret;

0 commit comments

Comments
 (0)