Skip to content

Commit e8558b8

Browse files
Neeraj Sanjay Kalegregkh
Neeraj Sanjay Kale
authored andcommitted
Bluetooth: btnxpuart: Add handling for boot-signature timeout errors
[ Upstream commit 2748936 ] This handles the timeout error codes sent by the chip as part of the bootloader signatures during firmware download process. When the bootloader does not receive a response packet from the host within a specific time, it adds an error code to the bootloader signature while requesting for the FW chunk from the same offset. The host is expected to clear this error code with a NAK, and reply to only those bootloader signatures which have error code 0. However, the driver was ignoring this error code and replying with the firmware chunks instead, which is apparently ignored by the chip and the chip resends the same bootloader signature with the error code again. This happens in a loop until the error code self clears and firmware download proceeds ahead, adding a couple of milliseconds to the total firmware download time. Commit 689ca16 was an initial implementation which simply printed the following line during driver debug: - FW Download received err 0x04 from chip This commit adds the expected handling to the error codes. This error handling is valid for data_req bootloader signatures for V3 and future bootloader versions. Signed-off-by: Neeraj Sanjay Kale <[email protected]> Fixes: 689ca16 ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets") Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e19f7b0 commit e8558b8

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

drivers/bluetooth/btnxpuart.c

+48-4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ struct btnxpuart_dev {
186186
#define NXP_NAK_V3 0x7b
187187
#define NXP_CRC_ERROR_V3 0x7c
188188

189+
/* Bootloader signature error codes */
190+
#define NXP_ACK_RX_TIMEOUT 0x0002 /* ACK not received from host */
191+
#define NXP_HDR_RX_TIMEOUT 0x0003 /* FW Header chunk not received */
192+
#define NXP_DATA_RX_TIMEOUT 0x0004 /* FW Data chunk not received */
193+
189194
#define HDR_LEN 16
190195

191196
#define NXP_RECV_CHIP_VER_V1 \
@@ -276,6 +281,17 @@ struct nxp_bootloader_cmd {
276281
__be32 crc;
277282
} __packed;
278283

284+
struct nxp_v3_rx_timeout_nak {
285+
u8 nak;
286+
__le32 offset;
287+
u8 crc;
288+
} __packed;
289+
290+
union nxp_v3_rx_timeout_nak_u {
291+
struct nxp_v3_rx_timeout_nak pkt;
292+
u8 buf[6];
293+
};
294+
279295
static u8 crc8_table[CRC8_TABLE_SIZE];
280296

281297
/* Default configurations */
@@ -883,6 +899,32 @@ static int nxp_recv_chip_ver_v3(struct hci_dev *hdev, struct sk_buff *skb)
883899
return 0;
884900
}
885901

902+
static void nxp_handle_fw_download_error(struct hci_dev *hdev, struct v3_data_req *req)
903+
{
904+
struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
905+
__u32 offset = __le32_to_cpu(req->offset);
906+
__u16 err = __le16_to_cpu(req->error);
907+
union nxp_v3_rx_timeout_nak_u nak_tx_buf;
908+
909+
switch (err) {
910+
case NXP_ACK_RX_TIMEOUT:
911+
case NXP_HDR_RX_TIMEOUT:
912+
case NXP_DATA_RX_TIMEOUT:
913+
nak_tx_buf.pkt.nak = NXP_NAK_V3;
914+
nak_tx_buf.pkt.offset = __cpu_to_le32(offset);
915+
nak_tx_buf.pkt.crc = crc8(crc8_table, nak_tx_buf.buf,
916+
sizeof(nak_tx_buf) - 1, 0xff);
917+
serdev_device_write_buf(nxpdev->serdev, nak_tx_buf.buf,
918+
sizeof(nak_tx_buf));
919+
break;
920+
default:
921+
bt_dev_dbg(hdev, "Unknown bootloader error code: %d", err);
922+
break;
923+
924+
}
925+
926+
}
927+
886928
static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)
887929
{
888930
struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
@@ -897,7 +939,12 @@ static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)
897939
if (!req || !nxpdev->fw)
898940
goto free_skb;
899941

900-
nxp_send_ack(NXP_ACK_V3, hdev);
942+
if (!req->error) {
943+
nxp_send_ack(NXP_ACK_V3, hdev);
944+
} else {
945+
nxp_handle_fw_download_error(hdev, req);
946+
goto free_skb;
947+
}
901948

902949
len = __le16_to_cpu(req->len);
903950

@@ -924,9 +971,6 @@ static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)
924971
wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q);
925972
goto free_skb;
926973
}
927-
if (req->error)
928-
bt_dev_dbg(hdev, "FW Download received err 0x%02x from chip",
929-
req->error);
930974

931975
offset = __le32_to_cpu(req->offset);
932976
if (offset < nxpdev->fw_v3_offset_correction) {

0 commit comments

Comments
 (0)