Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp657991lqs; Fri, 14 Jun 2024 01:26:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUihOGMX09V4rSy863AhwAbvcVMOs0q/pJlMpth0f69Va7qoPa63KOQAXqIZq316nDTCYPz6dBW65jurvHydqccZCC6VV/nVNhrcwYUTw== X-Google-Smtp-Source: AGHT+IEbzBc8pALb/DXFy/4WfCznHCtui34OuvF9mJE/IlrW5GoSUV2prIfiLh19xzulwIBJRTl8 X-Received: by 2002:a50:cd49:0:b0:57c:a701:2311 with SMTP id 4fb4d7f45d1cf-57cbd6c6e20mr1479952a12.26.1718353560940; Fri, 14 Jun 2024 01:26:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718353560; cv=pass; d=google.com; s=arc-20160816; b=yxbpmQ7DGwp01mtN235rrdwleiE2T8rAvaNr2DvGDtcdyRPxaKnBbcm9uVxIg+EJzS LprummaFes0bKWzS7t1nMXcjtyeGXVmBu0F76baoUFu4b67GGnQWsrAUkV1+oQ1WkSoJ w9ed5Vaay3uDFZC2XNhxJqF+iQ9nxEcne17t3Zxwbvz6EwvECx08SyvUswMd7gJF2lzP +spi++hfty2a5gOd5NG7BLFT2vsxjAlBJFIOXJ3fDKw0xGDTLJlBMMJ+bE2mm8tsTtIA KWTfTfyjtHMZZ7QKG6YJ2+Oo13qunjamFk3jNS0OnZqQiob4gccI6zfWg14Pwd/Or7Uc yLIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=y6Td/RWGibxC5EZs9PqowUvvXlkVXwai0CFNS52/8vE=; fh=jQ5WhQ7D240g5cMA531jgN8TDQBEvBFiS/zbNVHHlic=; b=Xi6Qm5UYzT3lfseeUKEbVJG5pgS2xup4s3pDQihTsS1mrR5ht0XgRart0Dyau6CdUU rC36Fno2p4aXvgvJZrwAsgtMg6UDglnUJIdleidxU2+UU56Mivg/ghJ13MHhU6p9teCE tQCsoTINGSir1GZwHYq1mrxO2i3+0YepTZvZP5op2Aj9WWwbHVsh+8aBHK6rDkQm2ceS uQjVynv5iuMrLTttko7+ofsqYRGscDaYgEJraPue5gBGhTsoMpTvo7KzpUeIlZKPAMc9 2OZMVmbYVV7g/lBBTtys87XHRBpvwAF3gWOziRyGUkeRI72BBZaD9ca1BVdin74TJBFe 7GRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-bluetooth+bounces-5310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb744096csi1578697a12.357.2024.06.14.01.26.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 01:26:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-5310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-bluetooth+bounces-5310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A88EA1F22BFB for ; Fri, 14 Jun 2024 08:26:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7E96186297; Fri, 14 Jun 2024 08:25:53 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B95891836DE; Fri, 14 Jun 2024 08:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.121.34.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718353553; cv=none; b=ntG7A3QZr5hdxsaewNPHR00pyl2YUllKxE296LHQNkSfvSpjCAfd5xtRrDVJPMCFDiRiwjJo3WMV7crPptI2/y6ehYNp0SQo3dIcWCvWJsvoXCIpjg6322+wceGL2Q5eOS/XoWz+QBhgZ8snykz0AtPoDK3C0/6pbBplbJvNYOY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718353553; c=relaxed/simple; bh=n5ERbc459S9Htag/xAuMET2+wMLaFjbD6QqIAA6kQCA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=udp0lDh22MwrUBVBnY/RjBB+xW3RPpuTyCoVGbO+1PPMroV6p27EXLRh94LEcsrQEfFKpoJIfYdhQvFWn0bHYW3kvB93GfovqY2sBqT+V9wWbWlXbh1GbuyuqR70bpV2Brjmdm1OPdRmb0jl/hl6Txk1YWa1Re+g1MmT+hWlGLM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; arc=none smtp.client-ip=92.121.34.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 28AF81A186A; Fri, 14 Jun 2024 10:25:50 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 4462F1A1806; Fri, 14 Jun 2024 10:25:49 +0200 (CEST) Received: from pe-lt8779.in-pnq01.nxp.com (pe-lt8779.in-pnq01.nxp.com [10.17.104.141]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 15B99180222A; Fri, 14 Jun 2024 16:25:47 +0800 (+08) From: Neeraj Sanjay Kale To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, neeraj.sanjaykale@nxp.com, sherry.sun@nxp.com, ziniu.wang_1@nxp.com, haibo.chen@nxp.com, LnxRevLi@nxp.com Subject: [PATCH v2] Bluetooth: btnxpuart: Add handling for boot-signature timeout errors Date: Fri, 14 Jun 2024 13:53:38 +0530 Message-Id: <20240614082338.6530-1-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP 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 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