From patchwork Thu Apr 26 07:38:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 134419 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1908087lji; Thu, 26 Apr 2018 00:39:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+vvU88M6Uo/CCguLvunt+Qix29/wo5KJzSeaTBfmDkIaOHCMAHnGLAuvvo2p32tq1CEZug X-Received: by 10.98.96.135 with SMTP id u129mr27363032pfb.141.1524728341097; Thu, 26 Apr 2018 00:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524728341; cv=none; d=google.com; s=arc-20160816; b=qsq1MAvY5NLQjSRc5Tv6esMzLV3feVgx3gCB6KjrsSFItycCR86dlh/igopTdjls4h pMUZcMR3zVqikt4ozPFGgMJLMgu1vaoDvdW/KLD5rFmkLhcoAJzbwsSCeXjRcetbapEm 6wVBculi20eNU2h8FjojeqZVMTu9QtWdCR4l/vyox+CCvoY+ux26N18X8uBlVJMFqMIg AjDXcRZvLOL1y18NWCizfPj5qvD1ZMKn+5UacP7/+lCL8nlnSwMhrhVfAywKiQMLbgV9 kPDJTy2W3kHmbAoSXurrQ+lY6rVpurp4YA5F6J1OP30g220vwODMUxWndnDfSAH94+QJ iykA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Tr+4T1AjK3KrTD+7ow/Ei8dYhXhZ7PuSyL0cIWh5DQE=; b=Fk4Mr/S2xM/DFTO6srJJ5K8pObruSGmudppTrMlP8Y+KcsttdAT52n7dsCDOI/I0Er KUP3mctR05IgElfaLKCgmbbdG7tJ10Roh6klo2bQlOKrlKo6daKhu5kAcc7Fj5TyE3Oz qBBz8+77jVTNFxift2biRdR/p5R5vrB2D0QvJBVTtOnertothUZQZGq5b7DWPIcrQ117 uOqb0XJ0u1FmzRtVBOvT0hY6IpRhH8/CrQ5gnonzZdf3TCh1wo3lbtau8IhLZcgg8eWN o4GorzFt/CbX4d1guGCDccttw/qBbX8X+gR3NSQL7zVdwXrGR6wT5ZzbP9h37UporWVj DMaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fCq8FuDX; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si15616075pgc.620.2018.04.26.00.39.00; Thu, 26 Apr 2018 00:39:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fCq8FuDX; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754010AbeDZHjA (ORCPT + 1 other); Thu, 26 Apr 2018 03:39:00 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43150 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753997AbeDZHi7 (ORCPT ); Thu, 26 Apr 2018 03:38:59 -0400 Received: by mail-wr0-f193.google.com with SMTP id v15-v6so37572460wrm.10 for ; Thu, 26 Apr 2018 00:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v3saqvNF8xejH/1H4FzQnZ7LfWlJz+2YCmskkY2lS8o=; b=fCq8FuDXH8yE2Q02AL+BFNN73h4vBpILXXeLv7bAwT0ylRzaD1BwmbYuzgX+kA4245 o0EOpHVckMLhIa9k/D+aoF9JtghEw649xuIgWXF2Yfc1oITS5NmWcS81CX5hec8+np6A 2K2wYYqIHMsD99Grty46XgUsP73BEmFP/Xqxo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v3saqvNF8xejH/1H4FzQnZ7LfWlJz+2YCmskkY2lS8o=; b=QntUQJu+4hU2NMKm0+CX3MozxmCPr1UGaEHnx5qFPDFQc4zJrzpf8AdSkWmtztE9hW SpNlwtwqQS3AiuKTCUfKFR58pXPiT0526Ba0Vi9yhDzPgkjJXxwQSHu/Wb3ravpmQFdl Gh9smtxodjJczwAfGzU901qMVg7i1b5XYIrQReLKbTLczIWTLtOvGT8w+NiD0YepLZPb 67ew5hYPB73oJvbJJxDZzi99wTC9xOl7f5quBo7z3wNyTCYQKuusacn+pjrU9iAztVNL onIZPUssVEHhbq9mN948Ps40KASejonAdflPYta5yyiaQ4EovqzPrNkHVO42YOGElUrZ SQJA== X-Gm-Message-State: ALQs6tCcWTAXZuCTzIn30YWhHIORF5rPEojmDasxXMOKQp5rsaLKtrJl QdhjCtfxAz81NoeqjWj2MM03qw== X-Received: by 2002:adf:c412:: with SMTP id v18-v6mr23556208wrf.20.1524728338029; Thu, 26 Apr 2018 00:38:58 -0700 (PDT) Received: from lpoulain-ThinkPad-T470p.home (LFbn-1-10589-161.w90-89.abo.wanadoo.fr. [90.89.181.161]) by smtp.gmail.com with ESMTPSA id u196sm11833221wmf.30.2018.04.26.00.38.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Apr 2018 00:38:57 -0700 (PDT) From: Loic Poulain To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: linux-bluetooth@vger.kernel.org, bgodavar@codeaurora.org, Loic Poulain Subject: [PATCH v2 2/2] Bluetooth: btqca: Add AR3002 rampatch support Date: Thu, 26 Apr 2018 09:38:52 +0200 Message-Id: <1524728332-10093-2-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524728332-10093-1-git-send-email-loic.poulain@linaro.org> References: <1524728332-10093-1-git-send-email-loic.poulain@linaro.org> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds rampatch download compatibility for ROME >= 3.2. Starting with ROME 3.2, the 'download mode' field of the rampatch header indicates if the controller acknowledges (or not) the received rampatch segments. If not, we need to send all the segments without expecting any event from the controller (except for the last segment). Goal is (I assume) to speed-up rampatch download. This fixes BT on Dragonboard-600c P2 which includes the following BT controller: hci0: ROME Patch Version Request hci0: Product:0x00000008 hci0: Patch :0x00000111 hci0: ROM :0x00000302 hci0: SOC :0x00000023 Signed-off-by: Loic Poulain --- v2: Do not check rome version, byte is reserved or dedicated to dnld mode drivers/bluetooth/btqca.c | 105 ++++++++++++++++++++++------------------------ drivers/bluetooth/btqca.h | 11 ++++- 2 files changed, 60 insertions(+), 56 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c index 2793d41..857f219 100644 --- a/drivers/bluetooth/btqca.c +++ b/drivers/bluetooth/btqca.c @@ -127,28 +127,41 @@ static void rome_tlv_check_data(struct rome_config *config, BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff); BT_DBG("Length\t\t : %d bytes", length); + config->dnld_mode = ROME_SKIP_EVT_NONE; + switch (config->type) { case TLV_TYPE_PATCH: tlv_patch = (struct tlv_type_patch *)tlv->data; - BT_DBG("Total Length\t\t : %d bytes", + + /* For Rome version 1.1 to 3.1, all segment commands + * are acked by a vendor specific event (VSE). + * For Rome >= 3.2, the download mode field indicates + * if VSE is skipped by the controller. + * In case VSE is skipped, only the last segment is acked. + */ + config->dnld_mode = tlv_patch->download_mode; + + BT_DBG("Total Length : %d bytes", le32_to_cpu(tlv_patch->total_size)); - BT_DBG("Patch Data Length\t : %d bytes", + BT_DBG("Patch Data Length : %d bytes", le32_to_cpu(tlv_patch->data_length)); BT_DBG("Signing Format Version : 0x%x", tlv_patch->format_version); - BT_DBG("Signature Algorithm\t : 0x%x", + BT_DBG("Signature Algorithm : 0x%x", tlv_patch->signature); - BT_DBG("Reserved\t\t : 0x%x", - le16_to_cpu(tlv_patch->reserved1)); - BT_DBG("Product ID\t\t : 0x%04x", + BT_DBG("Download mode : 0x%x", + tlv_patch->download_mode); + BT_DBG("Reserved : 0x%x", + tlv_patch->reserved1); + BT_DBG("Product ID : 0x%04x", le16_to_cpu(tlv_patch->product_id)); - BT_DBG("Rom Build Version\t : 0x%04x", + BT_DBG("Rom Build Version : 0x%04x", le16_to_cpu(tlv_patch->rom_build)); - BT_DBG("Patch Version\t\t : 0x%04x", + BT_DBG("Patch Version : 0x%04x", le16_to_cpu(tlv_patch->patch_version)); - BT_DBG("Reserved\t\t : 0x%x", + BT_DBG("Reserved : 0x%x", le16_to_cpu(tlv_patch->reserved2)); - BT_DBG("Patch Entry Address\t : 0x%x", + BT_DBG("Patch Entry Address : 0x%x", le32_to_cpu(tlv_patch->entry)); break; @@ -194,8 +207,8 @@ static void rome_tlv_check_data(struct rome_config *config, } } -static int rome_tlv_send_segment(struct hci_dev *hdev, int idx, int seg_size, - const u8 *data) +static int rome_tlv_send_segment(struct hci_dev *hdev, int seg_size, + const u8 *data, enum rome_tlv_dnld_mode mode) { struct sk_buff *skb; struct edl_event_hdr *edl; @@ -203,12 +216,15 @@ static int rome_tlv_send_segment(struct hci_dev *hdev, int idx, int seg_size, u8 cmd[MAX_SIZE_PER_TLV_SEGMENT + 2]; int err = 0; - BT_DBG("%s: Download segment #%d size %d", hdev->name, idx, seg_size); - cmd[0] = EDL_PATCH_TLV_REQ_CMD; cmd[1] = seg_size; memcpy(cmd + 2, data, seg_size); + if (mode == ROME_SKIP_EVT_VSE_CC || mode == ROME_SKIP_EVT_VSE) { + return __hci_cmd_send(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, + cmd); + } + skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, cmd, HCI_VENDOR_PKT, HCI_INIT_TIMEOUT); if (IS_ERR(skb)) { @@ -245,47 +261,12 @@ static int rome_tlv_send_segment(struct hci_dev *hdev, int idx, int seg_size, return err; } -static int rome_tlv_download_request(struct hci_dev *hdev, - const struct firmware *fw) -{ - const u8 *buffer, *data; - int total_segment, remain_size; - int ret, i; - - if (!fw || !fw->data) - return -EINVAL; - - total_segment = fw->size / MAX_SIZE_PER_TLV_SEGMENT; - remain_size = fw->size % MAX_SIZE_PER_TLV_SEGMENT; - - BT_DBG("%s: Total segment num %d remain size %d total size %zu", - hdev->name, total_segment, remain_size, fw->size); - - data = fw->data; - for (i = 0; i < total_segment; i++) { - buffer = data + i * MAX_SIZE_PER_TLV_SEGMENT; - ret = rome_tlv_send_segment(hdev, i, MAX_SIZE_PER_TLV_SEGMENT, - buffer); - if (ret < 0) - return -EIO; - } - - if (remain_size) { - buffer = data + total_segment * MAX_SIZE_PER_TLV_SEGMENT; - ret = rome_tlv_send_segment(hdev, total_segment, remain_size, - buffer); - if (ret < 0) - return -EIO; - } - - return 0; -} - static int rome_download_firmware(struct hci_dev *hdev, struct rome_config *config) { const struct firmware *fw; - int ret; + const u8 *segment; + int ret, remain, i = 0; bt_dev_info(hdev, "ROME Downloading %s", config->fwname); @@ -298,10 +279,24 @@ static int rome_download_firmware(struct hci_dev *hdev, rome_tlv_check_data(config, fw); - ret = rome_tlv_download_request(hdev, fw); - if (ret) { - BT_ERR("%s: Failed to download file: %s (%d)", hdev->name, - config->fwname, ret); + segment = fw->data; + remain = fw->size; + while (remain > 0) { + int segsize = min(MAX_SIZE_PER_TLV_SEGMENT, remain); + + bt_dev_dbg(hdev, "Send segment %d, size %d", i++, segsize); + + remain -= segsize; + /* The last segment is always acked regardless download mode */ + if (!remain || segsize < MAX_SIZE_PER_TLV_SEGMENT) + config->dnld_mode = ROME_SKIP_EVT_NONE; + + ret = rome_tlv_send_segment(hdev, segsize, segment, + config->dnld_mode); + if (ret) + break; + + segment += segsize; } release_firmware(fw); diff --git a/drivers/bluetooth/btqca.h b/drivers/bluetooth/btqca.h index 65e994b..13d77fd 100644 --- a/drivers/bluetooth/btqca.h +++ b/drivers/bluetooth/btqca.h @@ -61,6 +61,13 @@ enum qca_bardrate { QCA_BAUDRATE_RESERVED }; +enum rome_tlv_dnld_mode { + ROME_SKIP_EVT_NONE, + ROME_SKIP_EVT_VSE, + ROME_SKIP_EVT_CC, + ROME_SKIP_EVT_VSE_CC +}; + enum rome_tlv_type { TLV_TYPE_PATCH = 1, TLV_TYPE_NVM @@ -70,6 +77,7 @@ struct rome_config { u8 type; char fwname[64]; uint8_t user_baud_rate; + enum rome_tlv_dnld_mode dnld_mode; }; struct edl_event_hdr { @@ -94,7 +102,8 @@ struct tlv_type_patch { __le32 data_length; __u8 format_version; __u8 signature; - __le16 reserved1; + __u8 download_mode; + __u8 reserved1; __le16 product_id; __le16 rom_build; __le16 patch_version;