diff mbox series

[5/5] usb: xhci: allow multiple firmware versions

Message ID 20190620102154.20805-6-vkoul@kernel.org (mailing list archive)
State Superseded
Headers show
Series usb: xhci: Add support for Renesas USB controllers | expand

Commit Message

Vinod Koul June 20, 2019, 10:21 a.m. UTC
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 <vkoul@kernel.org>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: Christian Lamparter <chunkeey@googlemail.com>
---
 drivers/usb/host/xhci-pci.c | 39 +++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Greg Kroah-Hartman June 20, 2019, 12:20 p.m. UTC | #1
On Thu, Jun 20, 2019 at 03:51:54PM +0530, Vinod Koul wrote:
> 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 <vkoul@kernel.org>
> Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Cc: Christian Lamparter <chunkeey@googlemail.com>
> ---
>  drivers/usb/host/xhci-pci.c | 39 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> index 3574afac44c5..2ee9e6bbabcb 100644
> --- a/drivers/usb/host/xhci-pci.c
> +++ b/drivers/usb/host/xhci-pci.c
> @@ -333,9 +333,12 @@ 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 increasing order

Why?

>  	 */
>  	{ "K2013080.mem", 0x0014, 0x02, 0x2013 },
>  	{ "K2013080.mem", 0x0014, 0x03, 0x2013 },
> +	{ "K2026090.mem", 0x0014, 0x03, 0x2026 },
>  	{ "K2013080.mem", 0x0015, 0x02, 0x2013 },

Just put a { } entry here at the end and then you don't care about the
order at all.  Much simpler and easier to maintain over time.

thanks,

greg k-h
Vinod Koul June 20, 2019, 5:07 p.m. UTC | #2
On 20-06-19, 14:20, Greg Kroah-Hartman wrote:
> On Thu, Jun 20, 2019 at 03:51:54PM +0530, Vinod Koul wrote:
> > 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 <vkoul@kernel.org>
> > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > Cc: Christian Lamparter <chunkeey@googlemail.com>
> > ---
> >  drivers/usb/host/xhci-pci.c | 39 +++++++++++++++++++++++++++++++++++++
> >  1 file changed, 39 insertions(+)
> > 
> > diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> > index 3574afac44c5..2ee9e6bbabcb 100644
> > --- a/drivers/usb/host/xhci-pci.c
> > +++ b/drivers/usb/host/xhci-pci.c
> > @@ -333,9 +333,12 @@ 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 increasing order
> 
> Why?

I should have explained more :)
This is required only for the devices which have multiple versions
available, so it will pick one try it out and if not found go to
subsequent one. So I thought it would be make sense to keep the version
values for a specific device (not whole table) ordered so that we can
pick the next entry. Of course if you have better idea to manage two
versions, am all ears :)

> 
> >  	 */
> >  	{ "K2013080.mem", 0x0014, 0x02, 0x2013 },
> >  	{ "K2013080.mem", 0x0014, 0x03, 0x2013 },
> > +	{ "K2026090.mem", 0x0014, 0x03, 0x2026 },
> >  	{ "K2013080.mem", 0x0015, 0x02, 0x2013 },
> 
> Just put a { } entry here at the end and then you don't care about the
> order at all.  Much simpler and easier to maintain over time.
>
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 3574afac44c5..2ee9e6bbabcb 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -333,9 +333,12 @@  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 increasing order
 	 */
 	{ "K2013080.mem", 0x0014, 0x02, 0x2013 },
 	{ "K2013080.mem", 0x0014, 0x03, 0x2013 },
+	{ "K2026090.mem", 0x0014, 0x03, 0x2026 },
 	{ "K2013080.mem", 0x0015, 0x02, 0x2013 },
 };
 
@@ -358,6 +361,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)
@@ -723,6 +744,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,
@@ -982,6 +1004,7 @@  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 = -ENOENT;
 
@@ -1035,6 +1058,21 @@  static void renesas_fw_callback(const struct firmware *fw,
 		}
 	} else {
 		dev_err(&pdev->dev, "firmware failed to load (%d).", err);
+		/*
+		 * 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;
+		}
 	}
 
 	dev_info(&pdev->dev, "Unloading driver");
@@ -1096,6 +1134,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,