Skip to content

Commit cdda18f

Browse files
committed
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: Luca Coelho <[email protected]> Link: https://lore.kernel.org/r/iwlwifi.20210210172142.072aa2e8bbc5.Ib351ee5da47a4cee60d44e66d32d2f6bba6f3150@changeid Signed-off-by: Luca Coelho <[email protected]>
1 parent ff11a8e commit cdda18f

File tree

1 file changed

+61
-37
lines changed
  • drivers/net/wireless/intel/iwlwifi/fw

1 file changed

+61
-37
lines changed

drivers/net/wireless/intel/iwlwifi/fw/pnvm.c

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2-
/******************************************************************************
3-
*
4-
* Copyright(c) 2020 Intel Corporation
5-
*
6-
*****************************************************************************/
2+
/*
3+
* Copyright(c) 2020-2021 Intel Corporation
4+
*/
75

86
#include "iwl-drv.h"
97
#include "pnvm.h"
@@ -221,9 +219,44 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
221219
return -ENOENT;
222220
}
223221

222+
static int iwl_pnvm_get_from_fs(struct iwl_trans *trans, u8 **data, size_t *len)
223+
{
224+
const struct firmware *pnvm;
225+
char pnvm_name[64];
226+
int ret;
227+
228+
/*
229+
* The prefix unfortunately includes a hyphen at the end, so
230+
* don't add the dot here...
231+
*/
232+
snprintf(pnvm_name, sizeof(pnvm_name), "%spnvm",
233+
trans->cfg->fw_name_pre);
234+
235+
/* ...but replace the hyphen with the dot here. */
236+
if (strlen(trans->cfg->fw_name_pre) < sizeof(pnvm_name))
237+
pnvm_name[strlen(trans->cfg->fw_name_pre) - 1] = '.';
238+
239+
ret = firmware_request_nowarn(&pnvm, pnvm_name, trans->dev);
240+
if (ret) {
241+
IWL_DEBUG_FW(trans, "PNVM file %s not found %d\n",
242+
pnvm_name, ret);
243+
return ret;
244+
}
245+
246+
*data = kmemdup(pnvm->data, pnvm->size, GFP_KERNEL);
247+
if (!*data)
248+
return -ENOMEM;
249+
250+
*len = pnvm->size;
251+
252+
return 0;
253+
}
254+
224255
int iwl_pnvm_load(struct iwl_trans *trans,
225256
struct iwl_notif_wait_data *notif_wait)
226257
{
258+
u8 *data;
259+
size_t len;
227260
struct iwl_notification_wait pnvm_wait;
228261
static const u16 ntf_cmds[] = { WIDE_ID(REGULATORY_AND_NVM_GROUP,
229262
PNVM_INIT_COMPLETE_NTFY) };
@@ -233,44 +266,35 @@ int iwl_pnvm_load(struct iwl_trans *trans,
233266
if (!trans->sku_id[0] && !trans->sku_id[1] && !trans->sku_id[2])
234267
return 0;
235268

236-
/* load from disk only if we haven't done it (or tried) before */
237-
if (!trans->pnvm_loaded) {
238-
const struct firmware *pnvm;
239-
char pnvm_name[64];
269+
/*
270+
* If we already loaded (or tried to load) it before, we just
271+
* need to set it again.
272+
*/
273+
if (trans->pnvm_loaded) {
274+
ret = iwl_trans_set_pnvm(trans, NULL, 0);
275+
if (ret)
276+
return ret;
277+
goto skip_parse;
278+
}
240279

280+
/* Try to load the PNVM from the filesystem */
281+
ret = iwl_pnvm_get_from_fs(trans, &data, &len);
282+
if (ret) {
241283
/*
242-
* The prefix unfortunately includes a hyphen at the end, so
243-
* don't add the dot here...
284+
* Pretend we've loaded it - at least we've tried and
285+
* couldn't load it at all, so there's no point in
286+
* trying again over and over.
244287
*/
245-
snprintf(pnvm_name, sizeof(pnvm_name), "%spnvm",
246-
trans->cfg->fw_name_pre);
247-
248-
/* ...but replace the hyphen with the dot here. */
249-
if (strlen(trans->cfg->fw_name_pre) < sizeof(pnvm_name))
250-
pnvm_name[strlen(trans->cfg->fw_name_pre) - 1] = '.';
251-
252-
ret = firmware_request_nowarn(&pnvm, pnvm_name, trans->dev);
253-
if (ret) {
254-
IWL_DEBUG_FW(trans, "PNVM file %s not found %d\n",
255-
pnvm_name, ret);
256-
/*
257-
* Pretend we've loaded it - at least we've tried and
258-
* couldn't load it at all, so there's no point in
259-
* trying again over and over.
260-
*/
261-
trans->pnvm_loaded = true;
262-
} else {
263-
iwl_pnvm_parse(trans, pnvm->data, pnvm->size);
288+
trans->pnvm_loaded = true;
264289

265-
release_firmware(pnvm);
266-
}
267-
} else {
268-
/* if we already loaded, we need to set it again */
269-
ret = iwl_trans_set_pnvm(trans, NULL, 0);
270-
if (ret)
271-
return ret;
290+
goto skip_parse;
272291
}
273292

293+
iwl_pnvm_parse(trans, data, len);
294+
295+
kfree(data);
296+
297+
skip_parse:
274298
iwl_init_notification_wait(notif_wait, &pnvm_wait,
275299
ntf_cmds, ARRAY_SIZE(ntf_cmds),
276300
iwl_pnvm_complete_fn, trans);

0 commit comments

Comments
 (0)