2024-06-14 08:26:01

by Neeraj Sanjay Kale

[permalink] [raw]
Subject: [PATCH v2] 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 <[email protected]>
Fixes: 689ca16e5232 ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets")
---
v2: Improve commit message, avoid type casting (Paul Menzel)
---
drivers/bluetooth/btnxpuart.c | 52 ++++++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c
index 00757a7cd8b5..fd7f25bed5b6 100644
--- a/drivers/bluetooth/btnxpuart.c
+++ b/drivers/bluetooth/btnxpuart.c
@@ -189,6 +189,11 @@ struct btnxpuart_dev {
#define NXP_NAK_V3 0x7b
#define NXP_CRC_ERROR_V3 0x7c

+/* Bootloader signature error codes */
+#define NXP_ACK_RX_TIMEOUT 0x0002 /* ACK not received from host */
+#define NXP_HDR_RX_TIMEOUT 0x0003 /* FW Header chunk not received */
+#define NXP_DATA_RX_TIMEOUT 0x0004 /* FW Data chunk not received */
+
#define HDR_LEN 16

#define NXP_RECV_CHIP_VER_V1 \
@@ -279,6 +284,17 @@ struct nxp_bootloader_cmd {
__be32 crc;
} __packed;

+struct nxp_v3_rx_timeout_nak {
+ u8 nak;
+ __le32 offset;
+ u8 crc;
+} __packed;
+
+union nxp_v3_rx_timeout_nak_u {
+ struct nxp_v3_rx_timeout_nak pkt;
+ u8 buf[6];
+};
+
static u8 crc8_table[CRC8_TABLE_SIZE];

/* Default configurations */
@@ -912,6 +928,32 @@ static int nxp_recv_chip_ver_v3(struct hci_dev *hdev, struct sk_buff *skb)
return 0;
}

+static void nxp_handle_fw_download_error(struct hci_dev *hdev, struct v3_data_req *req)
+{
+ struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
+ __u32 offset = __le32_to_cpu(req->offset);
+ __u16 err = __le16_to_cpu(req->error);
+ union nxp_v3_rx_timeout_nak_u nak_tx_buf;
+
+ switch (err) {
+ case NXP_ACK_RX_TIMEOUT:
+ case NXP_HDR_RX_TIMEOUT:
+ case NXP_DATA_RX_TIMEOUT:
+ nak_tx_buf.pkt.nak = NXP_NAK_V3;
+ nak_tx_buf.pkt.offset = __cpu_to_le32(offset);
+ nak_tx_buf.pkt.crc = crc8(crc8_table, nak_tx_buf.buf,
+ sizeof(nak_tx_buf) - 1, 0xff);
+ serdev_device_write_buf(nxpdev->serdev, nak_tx_buf.buf,
+ sizeof(nak_tx_buf));
+ break;
+ default:
+ bt_dev_dbg(hdev, "Unknown bootloader error code: %d", err);
+ break;
+
+ }
+
+}
+
static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)
{
struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
@@ -926,7 +968,12 @@ static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)
if (!req || !nxpdev->fw)
goto free_skb;

- nxp_send_ack(NXP_ACK_V3, hdev);
+ if (!req->error) {
+ nxp_send_ack(NXP_ACK_V3, hdev);
+ } else {
+ nxp_handle_fw_download_error(hdev, req);
+ goto free_skb;
+ }

len = __le16_to_cpu(req->len);

@@ -953,9 +1000,6 @@ static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)
wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q);
goto free_skb;
}
- if (req->error)
- bt_dev_dbg(hdev, "FW Download received err 0x%02x from chip",
- req->error);

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



2024-06-14 09:00:40

by bluez.test.bot

[permalink] [raw]
Subject: RE: [v2] Bluetooth: btnxpuart: Add handling for boot-signature timeout errors

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=861976

---Test result---

Test Summary:
CheckPatch PASS 0.81 seconds
GitLint PASS 1.37 seconds
SubjectPrefix PASS 0.24 seconds
BuildKernel PASS 30.56 seconds
CheckAllWarning PASS 32.60 seconds
CheckSparse PASS 40.97 seconds
CheckSmatch PASS 106.04 seconds
BuildKernel32 PASS 29.33 seconds
TestRunnerSetup PASS 536.95 seconds
TestRunner_l2cap-tester PASS 18.54 seconds
TestRunner_iso-tester PASS 30.92 seconds
TestRunner_bnep-tester PASS 4.80 seconds
TestRunner_mgmt-tester PASS 108.98 seconds
TestRunner_rfcomm-tester PASS 7.39 seconds
TestRunner_sco-tester PASS 15.09 seconds
TestRunner_ioctl-tester PASS 7.98 seconds
TestRunner_mesh-tester PASS 5.95 seconds
TestRunner_smp-tester PASS 7.30 seconds
TestRunner_userchan-tester PASS 5.13 seconds
IncrementalBuild PASS 28.28 seconds



---
Regards,
Linux Bluetooth

2024-06-14 17:00:56

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: btnxpuart: Add handling for boot-signature timeout errors

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Fri, 14 Jun 2024 13:53:38 +0530 you wrote:
> 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.
>
> [...]

Here is the summary with links:
- [v2] Bluetooth: btnxpuart: Add handling for boot-signature timeout errors
https://git.kernel.org/bluetooth/bluetooth-next/c/96385cbdfb95

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html