From patchwork Wed Nov 6 08:38:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 178631 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp297824ilf; Wed, 6 Nov 2019 00:39:53 -0800 (PST) X-Google-Smtp-Source: APXvYqyithdMoPobwlBKLUcOJB44vEiDTb0QA4Y7mIlIWYqER1sakHznCCLhct4Hl0cpQa/ii7D5 X-Received: by 2002:a50:fc02:: with SMTP id i2mr1362558edr.284.1573029593360; Wed, 06 Nov 2019 00:39:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573029593; cv=none; d=google.com; s=arc-20160816; b=kaoKLMz7JUTUOM2hiGPXF1rEwL4D+GfnpU9LNVluvS3uEzvezl5250ypiIaBeTOrs4 PtyALGj1sy2ncz5GUDZOIs1Wp53BcGJMhRYqRAI4UQmCjwy0erppRjbLC5RMDAlU4CkO dBgoOOBzwpGPxi1PaGT548kRhzsVi98xnTcMCEkKByOQ89Es/8RjwOqsBny+639vu6MC iREJVYvdrLOUrgFfEnZidBhbtJMa+y7hkks7aQTEc5CaM266tBTdWySBLkIpZ8xrx1y0 lX4578pNWtsHrupDuR+8g75wCOIasxkh+pkVFQ5bMGOvGgTjIzyDddrs++D4LR0glbpl /RYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XzjCvGyuCC25xcbuBg9k0Kndy35Mp4ZEULefi/JLMF4=; b=zQtDyplggx5jyla1qm58mkuZG+ozIFAoivAV+MxksZZFUwg3ntImvCVutIDWOAub+o ngXAEeCESdifGxiD6swEDIxFlTZiUJKZOow9oV2D4osClcrjRuhGnZ7SmZJOhixG0cFk r014mg1U+0qLhKBA4j8PAMDoR4l4hIXsOcjMQW/2I35bn2vlsM/e1nTzLkLxPYZORhMY CLYXsH3XxOQBP1X5Kszms9ef2RGi2VCV5nDdDy5RfpU5ds2JLe5ikehMiQMwdkwfg4gW COUkJZC8RDx0UyeVgBxABACnVCU9K8+5n+PbHEw51x6evDpwBmja7G2o+BWGzUQv43QZ 6Zwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jfE4Spko; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u16si13582281edi.310.2019.11.06.00.39.53; Wed, 06 Nov 2019 00:39:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jfE4Spko; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731577AbfKFIjm (ORCPT + 26 others); Wed, 6 Nov 2019 03:39:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:48288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731544AbfKFIjl (ORCPT ); Wed, 6 Nov 2019 03:39:41 -0500 Received: from localhost.localdomain (unknown [223.226.46.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 22C0321882; Wed, 6 Nov 2019 08:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573029580; bh=+me4BFgFFxK3alusWYfMZyVysKc/CceQK1nEa4XFxwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfE4Spko4HGtPQJvXcNOqs9b05c3Aswur2NWf6BcyrGF0TvwTiE6ASBxmRxd7m2ry K/qG36cbWpf76mH0ArF7s1UtoSinmKoiogG0HJtEZCYag9Puurl5zTmZ7iJhbO6m// sfXflNM9u86S7kYpyok6h2/YSXyxeKAGJattTw/E= From: Vinod Koul To: Mathias Nyman , Greg Kroah-Hartman Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Vinod Koul , Yoshihiro Shimoda , Christian Lamparter , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 3/4] usb: xhci: allow multiple firmware versions Date: Wed, 6 Nov 2019 14:08:42 +0530 Message-Id: <20191106083843.1718437-4-vkoul@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191106083843.1718437-1-vkoul@kernel.org> References: <20191106083843.1718437-1-vkoul@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow multiple firmware file versions in table and load them in increasing order as we find them in the file system. Signed-off-by: Vinod Koul Cc: Yoshihiro Shimoda Cc: Christian Lamparter --- drivers/usb/host/xhci-pci.c | 47 +++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) -- 2.23.0 diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index e1c2865df433..4d0c0fd18c23 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -336,13 +336,20 @@ static const struct renesas_fw_entry { * - uPD720201 ES 2.0 sample whose revision ID is 2. * - uPD720201 ES 2.1 sample & CS sample & Mass product, ID is 3. * - uPD720202 ES 2.0 sample & CS sample & Mass product, ID is 2. + * + * Entry expected_version should be kept in decreasing order for a + * chip, so that driver will pick latest version and if that fails + * then next one will be picked */ { "K2013080.mem", 0x0014, 0x02, 0x2013 }, + { "K2026090.mem", 0x0014, 0x03, 0x2026 }, { "K2013080.mem", 0x0014, 0x03, 0x2013 }, + { "K2026090.mem", 0x0015, 0x02, 0x2026 }, { "K2013080.mem", 0x0015, 0x02, 0x2013 }, }; MODULE_FIRMWARE("K2013080.mem"); +MODULE_FIRMWARE("K2026090.mem"); static const struct renesas_fw_entry *renesas_needs_fw_dl(struct pci_dev *dev) { @@ -363,6 +370,24 @@ static const struct renesas_fw_entry *renesas_needs_fw_dl(struct pci_dev *dev) return NULL; } +static const struct +renesas_fw_entry *renesas_get_next_entry(struct pci_dev *dev, + const struct renesas_fw_entry *entry) +{ + const struct renesas_fw_entry *next_entry; + size_t i; + + for (i = 0; i < ARRAY_SIZE(renesas_fw_table); i++) { + next_entry = &renesas_fw_table[i]; + if (next_entry->device == dev->device && + next_entry->revision == dev->revision && + next_entry->expected_version < entry->expected_version) + return next_entry; + } + + return NULL; +} + static int renesas_fw_download_image(struct pci_dev *dev, const u32 *fw, size_t step) @@ -707,6 +732,7 @@ struct renesas_fw_ctx { struct pci_dev *pdev; const struct pci_device_id *id; bool resume; + const struct renesas_fw_entry *entry; }; static int xhci_pci_probe(struct pci_dev *pdev, @@ -966,13 +992,29 @@ static void renesas_fw_callback(const struct firmware *fw, struct renesas_fw_ctx *ctx = context; struct pci_dev *pdev = ctx->pdev; struct device *parent = pdev->dev.parent; + const struct renesas_fw_entry *next_entry; bool rom; int err; if (!fw) { dev_err(&pdev->dev, "firmware failed to load\n"); - - goto cleanup; + /* + * we didn't find firmware, check if we have another + * entry for this device + */ + next_entry = renesas_get_next_entry(ctx->pdev, ctx->entry); + if (next_entry) { + ctx->entry = next_entry; + dev_dbg(&pdev->dev, "Found next entry, requesting: %s\n", + next_entry->firmware_name); + request_firmware_nowait(THIS_MODULE, 1, + next_entry->firmware_name, + &pdev->dev, GFP_KERNEL, + ctx, renesas_fw_callback); + return; + } else { + goto cleanup; + } } err = renesas_fw_verify(pdev, fw->data, fw->size); @@ -1070,6 +1112,7 @@ static int renesas_fw_download_to_hw(struct pci_dev *pdev, ctx->pdev = pdev; ctx->resume = do_resume; ctx->id = id; + ctx->entry = entry; pci_dev_get(pdev); err = request_firmware_nowait(THIS_MODULE, 1, entry->firmware_name,