1
1
// 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
+ */
7
5
8
6
#include "iwl-drv.h"
9
7
#include "pnvm.h"
@@ -221,9 +219,44 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
221
219
return - ENOENT ;
222
220
}
223
221
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
+
224
255
int iwl_pnvm_load (struct iwl_trans * trans ,
225
256
struct iwl_notif_wait_data * notif_wait )
226
257
{
258
+ u8 * data ;
259
+ size_t len ;
227
260
struct iwl_notification_wait pnvm_wait ;
228
261
static const u16 ntf_cmds [] = { WIDE_ID (REGULATORY_AND_NVM_GROUP ,
229
262
PNVM_INIT_COMPLETE_NTFY ) };
@@ -233,44 +266,35 @@ int iwl_pnvm_load(struct iwl_trans *trans,
233
266
if (!trans -> sku_id [0 ] && !trans -> sku_id [1 ] && !trans -> sku_id [2 ])
234
267
return 0 ;
235
268
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
+ }
240
279
280
+ /* Try to load the PNVM from the filesystem */
281
+ ret = iwl_pnvm_get_from_fs (trans , & data , & len );
282
+ if (ret ) {
241
283
/*
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.
244
287
*/
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;
264
289
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 ;
272
291
}
273
292
293
+ iwl_pnvm_parse (trans , data , len );
294
+
295
+ kfree (data );
296
+
297
+ skip_parse :
274
298
iwl_init_notification_wait (notif_wait , & pnvm_wait ,
275
299
ntf_cmds , ARRAY_SIZE (ntf_cmds ),
276
300
iwl_pnvm_complete_fn , trans );
0 commit comments