From patchwork Wed Feb 10 15:23:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Coelho X-Patchwork-Id: 12081045 X-Patchwork-Delegate: luca@coelho.fi Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4625C433E0 for ; Wed, 10 Feb 2021 15:25:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A889464E8C for ; Wed, 10 Feb 2021 15:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbhBJPZC (ORCPT ); Wed, 10 Feb 2021 10:25:02 -0500 Received: from paleale.coelho.fi ([176.9.41.70]:45366 "EHLO farmhouse.coelho.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231759AbhBJPYy (ORCPT ); Wed, 10 Feb 2021 10:24:54 -0500 Received: from 91-156-6-193.elisa-laajakaista.fi ([91.156.6.193] helo=redipa.ger.corp.intel.com) by farmhouse.coelho.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1l9rLU-0049nr-13; Wed, 10 Feb 2021 17:24:00 +0200 From: Luca Coelho To: kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org Date: Wed, 10 Feb 2021 17:23:53 +0200 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210210152355.419776-1-luca@coelho.fi> References: <20210210152355.419776-1-luca@coelho.fi> MIME-Version: 1.0 Subject: [PATCH 6/8] iwlwifi: pnvm: move file loading code to a separate function Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Luca Coelho In preparation to support loading the PNVM from UEFI, move the function that loads the PNVM from the filesystem to a separate function. This will make it easier to try to load from both places later on. Signed-off-by: Luca Coelho --- drivers/net/wireless/intel/iwlwifi/fw/pnvm.c | 98 ++++++++++++-------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c index 37ce4fe136c5..d515af8c1686 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c @@ -1,9 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause -/****************************************************************************** - * - * Copyright(c) 2020 Intel Corporation - * - *****************************************************************************/ +/* + * Copyright(c) 2020-2021 Intel Corporation + */ #include "iwl-drv.h" #include "pnvm.h" @@ -221,9 +219,44 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data, return -ENOENT; } +static int iwl_pnvm_get_from_fs(struct iwl_trans *trans, u8 **data, size_t *len) +{ + const struct firmware *pnvm; + char pnvm_name[64]; + int ret; + + /* + * The prefix unfortunately includes a hyphen at the end, so + * don't add the dot here... + */ + snprintf(pnvm_name, sizeof(pnvm_name), "%spnvm", + trans->cfg->fw_name_pre); + + /* ...but replace the hyphen with the dot here. */ + if (strlen(trans->cfg->fw_name_pre) < sizeof(pnvm_name)) + pnvm_name[strlen(trans->cfg->fw_name_pre) - 1] = '.'; + + ret = firmware_request_nowarn(&pnvm, pnvm_name, trans->dev); + if (ret) { + IWL_DEBUG_FW(trans, "PNVM file %s not found %d\n", + pnvm_name, ret); + return ret; + } + + *data = kmemdup(pnvm->data, pnvm->size, GFP_KERNEL); + if (!*data) + return -ENOMEM; + + *len = pnvm->size; + + return 0; +} + int iwl_pnvm_load(struct iwl_trans *trans, struct iwl_notif_wait_data *notif_wait) { + u8 *data; + size_t len; struct iwl_notification_wait pnvm_wait; static const u16 ntf_cmds[] = { WIDE_ID(REGULATORY_AND_NVM_GROUP, PNVM_INIT_COMPLETE_NTFY) }; @@ -233,44 +266,35 @@ int iwl_pnvm_load(struct iwl_trans *trans, if (!trans->sku_id[0] && !trans->sku_id[1] && !trans->sku_id[2]) return 0; - /* load from disk only if we haven't done it (or tried) before */ - if (!trans->pnvm_loaded) { - const struct firmware *pnvm; - char pnvm_name[64]; + /* + * If we already loaded (or tried to load) it before, we just + * need to set it again. + */ + if (trans->pnvm_loaded) { + ret = iwl_trans_set_pnvm(trans, NULL, 0); + if (ret) + return ret; + goto skip_parse; + } + /* Try to load the PNVM from the filesystem */ + ret = iwl_pnvm_get_from_fs(trans, &data, &len); + if (ret) { /* - * The prefix unfortunately includes a hyphen at the end, so - * don't add the dot here... + * Pretend we've loaded it - at least we've tried and + * couldn't load it at all, so there's no point in + * trying again over and over. */ - snprintf(pnvm_name, sizeof(pnvm_name), "%spnvm", - trans->cfg->fw_name_pre); - - /* ...but replace the hyphen with the dot here. */ - if (strlen(trans->cfg->fw_name_pre) < sizeof(pnvm_name)) - pnvm_name[strlen(trans->cfg->fw_name_pre) - 1] = '.'; - - ret = firmware_request_nowarn(&pnvm, pnvm_name, trans->dev); - if (ret) { - IWL_DEBUG_FW(trans, "PNVM file %s not found %d\n", - pnvm_name, ret); - /* - * Pretend we've loaded it - at least we've tried and - * couldn't load it at all, so there's no point in - * trying again over and over. - */ - trans->pnvm_loaded = true; - } else { - iwl_pnvm_parse(trans, pnvm->data, pnvm->size); + trans->pnvm_loaded = true; - release_firmware(pnvm); - } - } else { - /* if we already loaded, we need to set it again */ - ret = iwl_trans_set_pnvm(trans, NULL, 0); - if (ret) - return ret; + goto skip_parse; } + iwl_pnvm_parse(trans, data, len); + + kfree(data); + +skip_parse: iwl_init_notification_wait(notif_wait, &pnvm_wait, ntf_cmds, ARRAY_SIZE(ntf_cmds), iwl_pnvm_complete_fn, trans);