[RFT 1/3] cxgb4: make ethtool set_flash use request_firmware_nowait()

From: Luis R. Rodriguez
Date: Fri Jun 20 2014 - 20:40:51 EST


From: "Luis R. Rodriguez" <mcgrof@xxxxxxxx>

cxgb4 loading can take a while, this is part of the crusade to
change it to be asynchronous.

Cc: Casey Leedom <leedom@xxxxxxxxxxx>
Cc: Hariprasad Shenai <hariprasad@xxxxxxxxxxx>
Cc: Philip Oswald <poswald@xxxxxxxx>
Cc: Santosh Rastapur <santosh@xxxxxxxxxxx>
Cc: Jeffrey Cheung <jcheung@xxxxxxxx>
Cc: David Chang <dchang@xxxxxxxx>
Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxx>
---
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 3 ++
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 40 ++++++++++++++++++++-----
2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
index f503dce..bcf9acf 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
@@ -647,6 +647,9 @@ struct adapter {
struct dentry *debugfs_root;

spinlock_t stats_lock;
+
+ struct completion flash_comp;
+ int flash_comp_status;
};

/* Defined bit width of user definable filter tuples
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 2f8d6b9..9cf6f3e 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -2713,22 +2713,48 @@ out:
return err;
}

+static void cxgb4_flash_complete(const struct firmware *fw, void *context)
+{
+ struct adapter *adap = context;
+ int ret;
+
+ if (!fw) {
+ adap->flash_comp_status = -EINVAL;
+ goto out;
+ }
+
+ ret = t4_load_fw(adap, fw->data, fw->size);
+ if (!ret)
+ adap->flash_comp_status = ret;
+
+out:
+ release_firmware(fw);
+ complete(&adap->flash_comp);
+}
+
static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
{
int ret;
- const struct firmware *fw;
struct adapter *adap = netdev2adap(netdev);

+ init_completion(&adap->flash_comp);
+ adap->flash_comp_status = 0;
+
ef->data[sizeof(ef->data) - 1] = '\0';
- ret = request_firmware(&fw, ef->data, adap->pdev_dev);
+ ret = request_firmware_nowait(THIS_MODULE, 1, ef->data,
+ adap->pdev_dev, GFP_KERNEL,
+ adap, cxgb4_flash_complete);
if (ret < 0)
return ret;

- ret = t4_load_fw(adap, fw->data, fw->size);
- release_firmware(fw);
- if (!ret)
- dev_info(adap->pdev_dev, "loaded firmware %s\n", ef->data);
- return ret;
+ wait_for_completion(&adap->flash_comp);
+
+ if (adap->flash_comp_status != 0)
+ return adap->flash_comp_status;
+
+ dev_info(adap->pdev_dev, "loaded firmware %s\n", ef->data);
+
+ return 0;
}

#define WOL_SUPPORTED (WAKE_BCAST | WAKE_MAGIC)
--
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/