Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bluetooth: btnxpuart: Add handling for boot-signature timeout errors

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 689ca16e5232 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 <neeraj.sanjaykale@nxp.com>
Fixes: 689ca16e5232 ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

authored by

Neeraj Sanjay Kale and committed by
Luiz Augusto von Dentz
27489364 cb24bb7e

+48 -4
+48 -4
drivers/bluetooth/btnxpuart.c
··· 193 193 #define NXP_NAK_V3 0x7b 194 194 #define NXP_CRC_ERROR_V3 0x7c 195 195 196 + /* Bootloader signature error codes */ 197 + #define NXP_ACK_RX_TIMEOUT 0x0002 /* ACK not received from host */ 198 + #define NXP_HDR_RX_TIMEOUT 0x0003 /* FW Header chunk not received */ 199 + #define NXP_DATA_RX_TIMEOUT 0x0004 /* FW Data chunk not received */ 200 + 196 201 #define HDR_LEN 16 197 202 198 203 #define NXP_RECV_CHIP_VER_V1 \ ··· 287 282 __le32 payload_len; 288 283 __be32 crc; 289 284 } __packed; 285 + 286 + struct nxp_v3_rx_timeout_nak { 287 + u8 nak; 288 + __le32 offset; 289 + u8 crc; 290 + } __packed; 291 + 292 + union nxp_v3_rx_timeout_nak_u { 293 + struct nxp_v3_rx_timeout_nak pkt; 294 + u8 buf[6]; 295 + }; 290 296 291 297 static u8 crc8_table[CRC8_TABLE_SIZE]; 292 298 ··· 959 943 return 0; 960 944 } 961 945 946 + static void nxp_handle_fw_download_error(struct hci_dev *hdev, struct v3_data_req *req) 947 + { 948 + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); 949 + __u32 offset = __le32_to_cpu(req->offset); 950 + __u16 err = __le16_to_cpu(req->error); 951 + union nxp_v3_rx_timeout_nak_u nak_tx_buf; 952 + 953 + switch (err) { 954 + case NXP_ACK_RX_TIMEOUT: 955 + case NXP_HDR_RX_TIMEOUT: 956 + case NXP_DATA_RX_TIMEOUT: 957 + nak_tx_buf.pkt.nak = NXP_NAK_V3; 958 + nak_tx_buf.pkt.offset = __cpu_to_le32(offset); 959 + nak_tx_buf.pkt.crc = crc8(crc8_table, nak_tx_buf.buf, 960 + sizeof(nak_tx_buf) - 1, 0xff); 961 + serdev_device_write_buf(nxpdev->serdev, nak_tx_buf.buf, 962 + sizeof(nak_tx_buf)); 963 + break; 964 + default: 965 + bt_dev_dbg(hdev, "Unknown bootloader error code: %d", err); 966 + break; 967 + 968 + } 969 + 970 + } 971 + 962 972 static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb) 963 973 { 964 974 struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); ··· 999 957 if (!req || !nxpdev->fw) 1000 958 goto free_skb; 1001 959 1002 - nxp_send_ack(NXP_ACK_V3, hdev); 960 + if (!req->error) { 961 + nxp_send_ack(NXP_ACK_V3, hdev); 962 + } else { 963 + nxp_handle_fw_download_error(hdev, req); 964 + goto free_skb; 965 + } 1003 966 1004 967 len = __le16_to_cpu(req->len); 1005 968 ··· 1031 984 wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q); 1032 985 goto free_skb; 1033 986 } 1034 - if (req->error) 1035 - bt_dev_dbg(hdev, "FW Download received err 0x%02x from chip", 1036 - req->error); 1037 987 1038 988 offset = __le32_to_cpu(req->offset); 1039 989 if (offset < nxpdev->fw_v3_offset_correction) {