[PATCH v2 8/8] p54: convert to sysdata API

From: Luis R. Rodriguez
Date: Thu Jun 16 2016 - 19:59:58 EST


The Coccinelle sysdata patches were used to help with
this transition. The changes have been carefully manually
vetted for. With the conversion we modify the cases that do
not need the firmware to be kept so that the sysdata API
can release it for us. Using the new sysdata API also means
we can get rid of our own completions.

Generated-by: Coccinelle SmPL
Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxxxx>
---
drivers/net/wireless/intersil/p54/eeprom.c | 2 +-
drivers/net/wireless/intersil/p54/fwio.c | 5 +-
drivers/net/wireless/intersil/p54/led.c | 2 +-
drivers/net/wireless/intersil/p54/main.c | 2 +-
drivers/net/wireless/intersil/p54/p54.h | 3 +-
drivers/net/wireless/intersil/p54/p54pci.c | 26 ++++++----
drivers/net/wireless/intersil/p54/p54pci.h | 4 +-
drivers/net/wireless/intersil/p54/p54spi.c | 81 +++++++++++++++++++-----------
drivers/net/wireless/intersil/p54/p54spi.h | 2 +-
drivers/net/wireless/intersil/p54/p54usb.c | 18 +++----
drivers/net/wireless/intersil/p54/p54usb.h | 4 +-
drivers/net/wireless/intersil/p54/txrx.c | 2 +-
12 files changed, 90 insertions(+), 61 deletions(-)

diff --git a/drivers/net/wireless/intersil/p54/eeprom.c b/drivers/net/wireless/intersil/p54/eeprom.c
index d4c73d39336f..9d048fa1f07f 100644
--- a/drivers/net/wireless/intersil/p54/eeprom.c
+++ b/drivers/net/wireless/intersil/p54/eeprom.c
@@ -16,7 +16,7 @@
* published by the Free Software Foundation.
*/

-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>
#include <linux/sort.h>
#include <linux/slab.h>
diff --git a/drivers/net/wireless/intersil/p54/fwio.c b/drivers/net/wireless/intersil/p54/fwio.c
index 257a9eadd595..6bc8463ccf5e 100644
--- a/drivers/net/wireless/intersil/p54/fwio.c
+++ b/drivers/net/wireless/intersil/p54/fwio.c
@@ -17,7 +17,7 @@
*/

#include <linux/slab.h>
-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>
#include <linux/export.h>

@@ -27,7 +27,8 @@
#include "eeprom.h"
#include "lmac.h"

-int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
+int p54_parse_firmware(struct ieee80211_hw *dev,
+ const struct sysdata_file *fw)
{
struct p54_common *priv = dev->priv;
struct exp_if *exp_if;
diff --git a/drivers/net/wireless/intersil/p54/led.c b/drivers/net/wireless/intersil/p54/led.c
index 9a8fedd3c0f5..b9f18082b1ff 100644
--- a/drivers/net/wireless/intersil/p54/led.c
+++ b/drivers/net/wireless/intersil/p54/led.c
@@ -16,7 +16,7 @@
* published by the Free Software Foundation.
*/

-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>

#include <net/mac80211.h>
diff --git a/drivers/net/wireless/intersil/p54/main.c b/drivers/net/wireless/intersil/p54/main.c
index d5a3bf91a03e..f000e39f677a 100644
--- a/drivers/net/wireless/intersil/p54/main.c
+++ b/drivers/net/wireless/intersil/p54/main.c
@@ -17,7 +17,7 @@
*/

#include <linux/slab.h>
-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>
#include <linux/module.h>

diff --git a/drivers/net/wireless/intersil/p54/p54.h b/drivers/net/wireless/intersil/p54/p54.h
index 529939e611cd..1747119921d6 100644
--- a/drivers/net/wireless/intersil/p54/p54.h
+++ b/drivers/net/wireless/intersil/p54/p54.h
@@ -268,7 +268,8 @@ struct p54_common {
/* interfaces for the drivers */
int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb);
void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb);
-int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw);
+int p54_parse_firmware(struct ieee80211_hw *dev,
+ const struct sysdata_file *fw);
int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len);
int p54_read_eeprom(struct ieee80211_hw *dev);

diff --git a/drivers/net/wireless/intersil/p54/p54pci.c b/drivers/net/wireless/intersil/p54/p54pci.c
index 27a49068d32d..e65497de5454 100644
--- a/drivers/net/wireless/intersil/p54/p54pci.c
+++ b/drivers/net/wireless/intersil/p54/p54pci.c
@@ -15,7 +15,7 @@

#include <linux/pci.h>
#include <linux/slab.h>
-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/completion.h>
@@ -490,7 +490,7 @@ static int p54p_open(struct ieee80211_hw *dev)
return 0;
}

-static void p54p_firmware_step2(const struct firmware *fw,
+static void p54p_firmware_step2(const struct sysdata_file *fw,
void *context)
{
struct p54p_priv *priv = context;
@@ -520,8 +520,6 @@ static void p54p_firmware_step2(const struct firmware *fw,

out:

- complete(&priv->fw_loaded);
-
if (err) {
struct device *parent = pdev->dev.parent;

@@ -542,6 +540,17 @@ out:
pci_dev_put(pdev);
}

+static int p54p_load_firmware(struct p54p_priv *priv)
+{
+ const struct sysdata_file_desc sysdata_desc = {
+ SYSDATA_KEEP_ASYNC(p54p_firmware_step2, priv),
+ };
+
+ return sysdata_file_request_async("isl3886pci", &sysdata_desc,
+ &priv->pdev->dev,
+ &priv->fw_async_cookie);
+}
+
static int p54p_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
@@ -595,7 +604,6 @@ static int p54p_probe(struct pci_dev *pdev,
priv = dev->priv;
priv->pdev = pdev;

- init_completion(&priv->fw_loaded);
SET_IEEE80211_DEV(dev, &pdev->dev);
pci_set_drvdata(pdev, dev);

@@ -620,9 +628,7 @@ static int p54p_probe(struct pci_dev *pdev,
spin_lock_init(&priv->lock);
tasklet_init(&priv->tasklet, p54p_tasklet, (unsigned long)dev);

- err = request_firmware_nowait(THIS_MODULE, 1, "isl3886pci",
- &priv->pdev->dev, GFP_KERNEL,
- priv, p54p_firmware_step2);
+ err = p54p_load_firmware(priv);
if (!err)
return 0;

@@ -652,9 +658,9 @@ static void p54p_remove(struct pci_dev *pdev)
return;

priv = dev->priv;
- wait_for_completion(&priv->fw_loaded);
+ sysdata_synchronize_request(priv->fw_async_cookie);
p54_unregister_common(dev);
- release_firmware(priv->firmware);
+ release_sysdata_file(priv->firmware);
pci_free_consistent(pdev, sizeof(*priv->ring_control),
priv->ring_control, priv->ring_control_dma);
iounmap(priv->map);
diff --git a/drivers/net/wireless/intersil/p54/p54pci.h b/drivers/net/wireless/intersil/p54/p54pci.h
index 68405c142f97..4477f6b943de 100644
--- a/drivers/net/wireless/intersil/p54/p54pci.h
+++ b/drivers/net/wireless/intersil/p54/p54pci.h
@@ -94,7 +94,7 @@ struct p54p_priv {
struct pci_dev *pdev;
struct p54p_csr __iomem *map;
struct tasklet_struct tasklet;
- const struct firmware *firmware;
+ const struct sysdata_file *firmware;
spinlock_t lock;
struct p54p_ring_control *ring_control;
dma_addr_t ring_control_dma;
@@ -105,7 +105,7 @@ struct p54p_priv {
struct sk_buff *tx_buf_data[32];
struct sk_buff *tx_buf_mgmt[4];
struct completion boot_comp;
- struct completion fw_loaded;
+ async_cookie_t fw_async_cookie;
};

#endif /* P54USB_H */
diff --git a/drivers/net/wireless/intersil/p54/p54spi.c b/drivers/net/wireless/intersil/p54/p54spi.c
index 7ab2f43ab425..b38ac2a0b83b 100644
--- a/drivers/net/wireless/intersil/p54/p54spi.c
+++ b/drivers/net/wireless/intersil/p54/p54spi.c
@@ -23,7 +23,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/interrupt.h>
-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/spi/spi.h>
@@ -162,53 +162,74 @@ static int p54spi_spi_write_dma(struct p54s_priv *priv, __le32 base,
return 0;
}

+static int p54spi_request_firmware_found_cb(void *context,
+ const struct sysdata_file *sysdata)
+{
+ int ret;
+ struct p54s_priv *priv = context;
+
+ priv->firmware = sysdata;
+ ret = p54_parse_firmware(priv->hw, priv->firmware);
+ if (ret)
+ release_sysdata_file(priv->firmware);
+
+ return ret;
+}
+
static int p54spi_request_firmware(struct ieee80211_hw *dev)
{
struct p54s_priv *priv = dev->priv;
+ const struct sysdata_file_desc sysdata_desc = {
+ SYSDATA_KEEP_SYNC(p54spi_request_firmware_found_cb, priv),
+ };
int ret;

/* FIXME: should driver use it's own struct device? */
- ret = request_firmware(&priv->firmware, "3826.arm", &priv->spi->dev);
-
+ ret = sysdata_file_request("3826.arm", &sysdata_desc, &priv->spi->dev);
if (ret < 0) {
- dev_err(&priv->spi->dev, "request_firmware() failed: %d", ret);
- return ret;
+ dev_err(&priv->spi->dev,
+ "request_firmware() failed: %d", ret);
}
+ return ret;
+}

- ret = p54_parse_firmware(dev, priv->firmware);
- if (ret) {
- release_firmware(priv->firmware);
- return ret;
- }
+#ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
+static int p54spi_load_eeprom_default(void *context)
+{
+ struct p54s_priv *priv = context;
+ struct ieee80211_hw *dev = priv->hw;

- return 0;
+ dev_info(&priv->spi->dev, "loading default eeprom...\n");
+ return p54_parse_eeprom(dev, (void *) p54spi_eeprom,
+ sizeof(p54spi_eeprom));
}
+#endif
+
+static int p54spi_load_eeprom_cb(void *context,
+ const struct sysdata_file *sysdata)
+{
+ struct p54s_priv *priv = context;
+ struct ieee80211_hw *dev = priv->hw;

+ dev_info(&priv->spi->dev, "loading user eeprom...\n");
+ return p54_parse_eeprom(dev, (void *) sysdata->data,
+ (int)sysdata->size);
+}
static int p54spi_request_eeprom(struct ieee80211_hw *dev)
{
struct p54s_priv *priv = dev->priv;
- const struct firmware *eeprom;
- int ret;
+ const struct sysdata_file_desc sysdata_desc = {
+ SYSDATA_DEFAULT_SYNC(p54spi_load_eeprom_cb, priv),
+#ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
+ SYSDATA_SYNC_OPT_CB(p54spi_load_eeprom_default, priv),
+#endif
+ };

/* allow users to customize their eeprom.
*/

- ret = request_firmware_direct(&eeprom, "3826.eeprom", &priv->spi->dev);
- if (ret < 0) {
-#ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
- dev_info(&priv->spi->dev, "loading default eeprom...\n");
- ret = p54_parse_eeprom(dev, (void *) p54spi_eeprom,
- sizeof(p54spi_eeprom));
-#else
- dev_err(&priv->spi->dev, "Failed to request user eeprom\n");
-#endif /* CONFIG_P54_SPI_DEFAULT_EEPROM */
- } else {
- dev_info(&priv->spi->dev, "loading user eeprom...\n");
- ret = p54_parse_eeprom(dev, (void *) eeprom->data,
- (int)eeprom->size);
- release_firmware(eeprom);
- }
- return ret;
+ return sysdata_file_request("3826.eeprom", &sysdata_desc,
+ &priv->spi->dev);
}

static int p54spi_upload_firmware(struct ieee80211_hw *dev)
@@ -692,7 +713,7 @@ static int p54spi_remove(struct spi_device *spi)

gpio_free(p54spi_gpio_power);
gpio_free(p54spi_gpio_irq);
- release_firmware(priv->firmware);
+ release_sysdata_file(priv->firmware);

mutex_destroy(&priv->mutex);

diff --git a/drivers/net/wireless/intersil/p54/p54spi.h b/drivers/net/wireless/intersil/p54/p54spi.h
index dfaa62aaeb07..f4f20ff7df79 100644
--- a/drivers/net/wireless/intersil/p54/p54spi.h
+++ b/drivers/net/wireless/intersil/p54/p54spi.h
@@ -119,7 +119,7 @@ struct p54s_priv {
struct list_head tx_pending;

enum fw_state fw_state;
- const struct firmware *firmware;
+ const struct sysdata_file *firmware;
};

#endif /* P54SPI_H */
diff --git a/drivers/net/wireless/intersil/p54/p54usb.c b/drivers/net/wireless/intersil/p54/p54usb.c
index 043bd1c23c19..a46d8ff6c3a9 100644
--- a/drivers/net/wireless/intersil/p54/p54usb.c
+++ b/drivers/net/wireless/intersil/p54/p54usb.c
@@ -15,7 +15,7 @@
#include <linux/usb.h>
#include <linux/pci.h>
#include <linux/slab.h>
-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/crc32.h>
@@ -916,14 +916,13 @@ err_out:
return ret;
}

-static void p54u_load_firmware_cb(const struct firmware *firmware,
+static void p54u_load_firmware_cb(const struct sysdata_file *firmware,
void *context)
{
struct p54u_priv *priv = context;
struct usb_device *udev = priv->udev;
int err;

- complete(&priv->fw_wait_load);
if (firmware) {
priv->fw = firmware;
err = p54u_start_ops(priv);
@@ -959,12 +958,14 @@ static int p54u_load_firmware(struct ieee80211_hw *dev,
{
struct usb_device *udev = interface_to_usbdev(intf);
struct p54u_priv *priv = dev->priv;
+ const struct sysdata_file_desc sysdata_desc = {
+ SYSDATA_KEEP_ASYNC(p54u_load_firmware_cb, priv),
+ };
struct device *device = &udev->dev;
int err, i;

BUILD_BUG_ON(ARRAY_SIZE(p54u_fwlist) != __NUM_P54U_HWTYPES);

- init_completion(&priv->fw_wait_load);
i = p54_find_type(priv);
if (i < 0)
return i;
@@ -973,9 +974,8 @@ static int p54u_load_firmware(struct ieee80211_hw *dev,
p54u_fwlist[i].fw);

usb_get_dev(udev);
- err = request_firmware_nowait(THIS_MODULE, 1, p54u_fwlist[i].fw,
- device, GFP_KERNEL, priv,
- p54u_load_firmware_cb);
+ err = sysdata_file_request_async(p54u_fwlist[i].fw, &sysdata_desc,
+ device, &priv->fw_async_cookie);
if (err) {
dev_err(&priv->udev->dev, "(p54usb) cannot load firmware %s "
"(%d)!\n", p54u_fwlist[i].fw, err);
@@ -1069,11 +1069,11 @@ static void p54u_disconnect(struct usb_interface *intf)
return;

priv = dev->priv;
- wait_for_completion(&priv->fw_wait_load);
+ sysdata_synchronize_request(priv->fw_async_cookie);
p54_unregister_common(dev);

usb_put_dev(interface_to_usbdev(intf));
- release_firmware(priv->fw);
+ release_sysdata_file(priv->fw);
p54_free_common(dev);
}

diff --git a/drivers/net/wireless/intersil/p54/p54usb.h b/drivers/net/wireless/intersil/p54/p54usb.h
index a5f5f0fea3bd..089c62a3c2e7 100644
--- a/drivers/net/wireless/intersil/p54/p54usb.h
+++ b/drivers/net/wireless/intersil/p54/p54usb.h
@@ -153,10 +153,10 @@ struct p54u_priv {
spinlock_t lock;
struct sk_buff_head rx_queue;
struct usb_anchor submitted;
- const struct firmware *fw;
+ const struct sysdata_file *fw;

/* asynchronous firmware callback */
- struct completion fw_wait_load;
+ async_cookie_t fw_async_cookie;
};

#endif /* P54USB_H */
diff --git a/drivers/net/wireless/intersil/p54/txrx.c b/drivers/net/wireless/intersil/p54/txrx.c
index 1af7da0b386e..eed08ca886d5 100644
--- a/drivers/net/wireless/intersil/p54/txrx.c
+++ b/drivers/net/wireless/intersil/p54/txrx.c
@@ -17,7 +17,7 @@
*/

#include <linux/export.h>
-#include <linux/firmware.h>
+#include <linux/sysdata.h>
#include <linux/etherdevice.h>
#include <asm/div64.h>

--
2.8.2