[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170330032514.17173-5-mcgrof@kernel.org>
Date: Wed, 29 Mar 2017 20:25:13 -0700
From: "Luis R. Rodriguez" <mcgrof@...nel.org>
To: gregkh@...uxfoundation.org
Cc: wagi@...om.org, dwmw2@...radead.org, rafal@...ecki.pl,
arend.vanspriel@...adcom.com, rjw@...ysocki.net,
yi1.li@...ux.intel.com, atull@...nsource.altera.com,
moritz.fischer@...us.com, pmladek@...e.com,
johannes.berg@...el.com, emmanuel.grumbach@...el.com,
luciano.coelho@...el.com, kvalo@...eaurora.org, luto@...nel.org,
takahiro.akashi@...aro.org, dhowells@...hat.com, pjones@...hat.com,
linux-kernel@...r.kernel.org,
"Luis R. Rodriguez" <mcgrof@...nel.org>
Subject: [PATCH v6 4/5] iwlwifi: convert to use driver data API
The driver data API provides support for looking for firmware
from a specific set of API ranges, so just use that. Since we
free the firmware on the callback immediately after consuming it,
this also takes avantage of that feature.
Signed-off-by: Luis R. Rodriguez <mcgrof@...nel.org>
---
drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 67 ++++++++++------------------
1 file changed, 23 insertions(+), 44 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
index be466a074c1d..b6643aa5b344 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
@@ -66,7 +66,7 @@
*****************************************************************************/
#include <linux/completion.h>
#include <linux/dma-mapping.h>
-#include <linux/firmware.h>
+#include <linux/driver_data.h>
#include <linux/module.h>
#include <linux/vmalloc.h>
@@ -206,36 +206,20 @@ static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
return 0;
}
-static void iwl_req_fw_callback(const struct firmware *ucode_raw,
- void *context);
+static int iwl_req_fw_callback(const struct firmware *ucode_raw, void *context);
-static int iwl_request_firmware(struct iwl_drv *drv, bool first)
+static int iwl_request_firmware(struct iwl_drv *drv)
{
const char *name_pre = drv->trans->cfg->fw_name_pre;
- char tag[8];
-
- if (first) {
- drv->fw_index = drv->trans->cfg->ucode_api_max;
- sprintf(tag, "%d", drv->fw_index);
- } else {
- drv->fw_index--;
- sprintf(tag, "%d", drv->fw_index);
- }
-
- if (drv->fw_index < drv->trans->cfg->ucode_api_min) {
- IWL_ERR(drv, "no suitable firmware found!\n");
- return -ENOENT;
- }
-
- snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s%s.ucode",
- name_pre, tag);
-
- IWL_DEBUG_INFO(drv, "attempting to load firmware '%s'\n",
- drv->firmware_name);
-
- return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
- drv->trans->dev,
- GFP_KERNEL, drv, iwl_req_fw_callback);
+ const struct iwl_cfg *cfg = drv->trans->cfg;
+ const struct driver_data_req_params req_params = {
+ DRIVER_DATA_API_CB(iwl_req_fw_callback, drv),
+ DRIVER_DATA_API(cfg->ucode_api_min, cfg->ucode_api_max, ".ucode"),
+ };
+
+ return driver_data_request_async(name_pre,
+ &req_params,
+ drv->trans->dev);
}
struct fw_img_parsing {
@@ -1237,7 +1221,7 @@ static void _iwl_op_mode_stop(struct iwl_drv *drv)
* If loaded successfully, copies the firmware into buffers
* for the card to fetch (via DMA).
*/
-static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
+static int iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
{
struct iwl_drv *drv = context;
struct iwl_fw *fw = &drv->fw;
@@ -1260,10 +1244,12 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
if (!pieces)
- return;
+ return -ENOMEM;
- if (!ucode_raw)
- goto try_again;
+ if (!ucode_raw) {
+ err = -ENOENT;
+ goto free;
+ }
IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
drv->firmware_name, ucode_raw->size);
@@ -1426,9 +1412,6 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
fw->ucode_capa.standard_phy_calibration_size =
IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
- /* We have our copies now, allow OS release its copies */
- release_firmware(ucode_raw);
-
mutex_lock(&iwlwifi_opmode_table_mtx);
switch (fw->type) {
case IWL_FW_DVM:
@@ -1483,16 +1466,13 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
goto free;
try_again:
- /* try next, if any */
- release_firmware(ucode_raw);
- if (iwl_request_firmware(drv, false))
- goto out_unbind;
+ err = -EAGAIN;
goto free;
out_free_fw:
+ err = -ENOMEM;
IWL_ERR(drv, "failed to allocate pci memory\n");
iwl_dealloc_ucode(drv);
- release_firmware(ucode_raw);
out_unbind:
complete(&drv->request_firmware_complete);
device_release_driver(drv->trans->dev);
@@ -1501,6 +1481,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
kfree(pieces->img[i].sec);
kfree(pieces->dbg_mem_tlv);
kfree(pieces);
+ return err;
}
struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
@@ -1541,11 +1522,9 @@ struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
}
#endif
- ret = iwl_request_firmware(drv, true);
- if (ret) {
- IWL_ERR(trans, "Couldn't request the fw\n");
+ ret = iwl_request_firmware(drv);
+ if (ret)
goto err_fw;
- }
return drv;
--
2.11.0
Powered by blists - more mailing lists