Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755350AbdC3DZm (ORCPT ); Wed, 29 Mar 2017 23:25:42 -0400 Received: from mail.kernel.org ([198.145.29.136]:51974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754554AbdC3DZh (ORCPT ); Wed, 29 Mar 2017 23:25:37 -0400 From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: wagi@monom.org, dwmw2@infradead.org, rafal@milecki.pl, arend.vanspriel@broadcom.com, rjw@rjwysocki.net, yi1.li@linux.intel.com, atull@opensource.altera.com, moritz.fischer@ettus.com, pmladek@suse.com, johannes.berg@intel.com, emmanuel.grumbach@intel.com, luciano.coelho@intel.com, kvalo@codeaurora.org, luto@kernel.org, takahiro.akashi@linaro.org, dhowells@redhat.com, pjones@redhat.com, linux-kernel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH v6 4/5] iwlwifi: convert to use driver data API Date: Wed, 29 Mar 2017 20:25:13 -0700 Message-Id: <20170330032514.17173-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170330032514.17173-1-mcgrof@kernel.org> References: <20170330032514.17173-1-mcgrof@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4680 Lines: 149 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 --- 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 #include -#include +#include #include #include @@ -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