Commit cdda18fb authored by Luca Coelho's avatar Luca Coelho
Browse files

iwlwifi: pnvm: move file loading code to a separate function



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: default avatarLuca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20210210172142.072aa2e8bbc5.Ib351ee5da47a4cee60d44e66d32d2f6bba6f3150@changeid


Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
parent ff11a8ee
Loading
Loading
Loading
Loading
+61 −37
Original line number Diff line number Diff line
// 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,22 +219,11 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
	return -ENOENT;
}

int iwl_pnvm_load(struct iwl_trans *trans,
		  struct iwl_notif_wait_data *notif_wait)
static int iwl_pnvm_get_from_fs(struct iwl_trans *trans, 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) };
	int ret;

	/* if the SKU_ID is empty, there's nothing to do */
	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];
	int ret;

	/*
	 * The prefix unfortunately includes a hyphen at the end, so
@@ -253,24 +240,61 @@ int iwl_pnvm_load(struct iwl_trans *trans,
	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) };
	int ret;

	/* if the SKU_ID is empty, there's nothing to do */
	if (!trans->sku_id[0] && !trans->sku_id[1] && !trans->sku_id[2])
		return 0;

	/*
	 * 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) {
		/*
		 * 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);

			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);