Skip to content

Commit 194d1f8

Browse files
Alon Giladijmberg-intel
authored andcommitted
wifi: iwlwifi: Separate loading and setting of pnvm image into two functions
Take the part that is copying the pnvm image into DRAM, out of the the method that sets the prph_scratch. Makes the code cleaner since those 2 operations don't always happen together (loading should happen only once while setting can happen more than once). In addition, each operation will get more complex in the future when it will support also larger pnvm images. Signed-off-by: Alon Giladi <[email protected]> Signed-off-by: Gregory Greenman <[email protected]> Link: https://lore.kernel.org/r/20230606103519.4c0728239fd6.Ibc30a9fbdb6123dadbe2dbb89318dbd5ec01080a@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent 5f40850 commit 194d1f8

File tree

5 files changed

+65
-47
lines changed

5 files changed

+65
-47
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static int iwl_pnvm_handle_section(struct iwl_trans *trans, const u8 *data,
3838
u16 mac_type = 0, rf_id = 0;
3939
struct iwl_pnvm_image pnvm_data = {};
4040
bool hw_match = false;
41+
int ret;
4142

4243
IWL_DEBUG_FW(trans, "Handling PNVM section\n");
4344

@@ -152,9 +153,14 @@ static int iwl_pnvm_handle_section(struct iwl_trans *trans, const u8 *data,
152153
return -ENOENT;
153154
}
154155

156+
ret = iwl_trans_load_pnvm(trans, &pnvm_data);
157+
if (ret)
158+
return ret;
159+
155160
IWL_INFO(trans, "loaded PNVM version %08x\n", sha1);
156161

157-
return iwl_trans_set_pnvm(trans, &pnvm_data);
162+
iwl_trans_set_pnvm(trans);
163+
return 0;
158164
}
159165

160166
static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
@@ -262,9 +268,7 @@ int iwl_pnvm_load(struct iwl_trans *trans,
262268
* need to set it again.
263269
*/
264270
if (trans->pnvm_loaded) {
265-
ret = iwl_trans_set_pnvm(trans, NULL);
266-
if (ret)
267-
return ret;
271+
iwl_trans_set_pnvm(trans);
268272
goto skip_parse;
269273
}
270274

drivers/net/wireless/intel/iwlwifi/iwl-context-info-gen3.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
279279
const struct fw_img *fw);
280280
void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans, bool alive);
281281

282-
int iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans,
283-
const struct iwl_pnvm_image *pnvm_payloads);
282+
int iwl_trans_pcie_ctx_info_gen3_load_pnvm(struct iwl_trans *trans,
283+
const struct iwl_pnvm_image *pnvm_payloads);
284+
void iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans);
284285
int iwl_trans_pcie_ctx_info_gen3_set_reduce_power(struct iwl_trans *trans,
285286
const void *data, u32 len);
286287
int iwl_trans_pcie_ctx_info_gen3_set_step(struct iwl_trans *trans,

drivers/net/wireless/intel/iwlwifi/iwl-trans.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ struct iwl_pnvm_image {
557557
* Note that the transport must fill in the proper file headers.
558558
* @debugfs_cleanup: used in the driver unload flow to make a proper cleanup
559559
* of the trans debugfs
560+
* @load_pnvm: save the pnvm data in DRAM
560561
* @set_pnvm: set the pnvm data in the prph scratch buffer, inside the
561562
* context info.
562563
* @interrupts: disable/enable interrupts to transport
@@ -630,8 +631,9 @@ struct iwl_trans_ops {
630631
void *sanitize_ctx);
631632
void (*debugfs_cleanup)(struct iwl_trans *trans);
632633
void (*sync_nmi)(struct iwl_trans *trans);
633-
int (*set_pnvm)(struct iwl_trans *trans,
634-
const struct iwl_pnvm_image *pnvm_data);
634+
int (*load_pnvm)(struct iwl_trans *trans,
635+
const struct iwl_pnvm_image *pnvm_payloads);
636+
void (*set_pnvm)(struct iwl_trans *trans);
635637
int (*set_reduce_power)(struct iwl_trans *trans,
636638
const void *data, u32 len);
637639
void (*interrupts)(struct iwl_trans *trans, bool enable);
@@ -1532,19 +1534,16 @@ static inline void iwl_trans_sync_nmi(struct iwl_trans *trans)
15321534
void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr,
15331535
u32 sw_err_bit);
15341536

1535-
static inline int iwl_trans_set_pnvm(struct iwl_trans *trans,
1536-
const struct iwl_pnvm_image *pnvm_data)
1537+
static inline int iwl_trans_load_pnvm(struct iwl_trans *trans,
1538+
const struct iwl_pnvm_image *pnvm_data)
15371539
{
1538-
if (trans->ops->set_pnvm) {
1539-
int ret = trans->ops->set_pnvm(trans, pnvm_data);
1540-
1541-
if (ret)
1542-
return ret;
1543-
}
1544-
1545-
trans->pnvm_loaded = true;
1540+
return trans->ops->load_pnvm(trans, pnvm_data);
1541+
}
15461542

1547-
return 0;
1543+
static inline void iwl_trans_set_pnvm(struct iwl_trans *trans)
1544+
{
1545+
if (trans->ops->set_pnvm)
1546+
trans->ops->set_pnvm(trans);
15481547
}
15491548

15501549
static inline int iwl_trans_set_reduce_power(struct iwl_trans *trans,

drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-gen3.c

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -281,55 +281,68 @@ void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans, bool alive)
281281
trans_pcie->prph_info = NULL;
282282
}
283283

284-
int iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans,
285-
const struct iwl_pnvm_image *pnvm_payloads)
284+
int iwl_trans_pcie_ctx_info_gen3_load_pnvm(struct iwl_trans *trans,
285+
const struct iwl_pnvm_image *pnvm_payloads)
286286
{
287287
struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
288288
struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl =
289289
&trans_pcie->prph_scratch->ctrl_cfg;
290290
struct iwl_dram_data *dram = &trans_pcie->pnvm_dram;
291+
u32 len, len0, len1;
291292

292293
if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210)
293294
return 0;
294295

295296
/* only allocate the DRAM if not allocated yet */
296-
if (!trans->pnvm_loaded) {
297-
u32 len, len0, len1;
297+
if (trans->pnvm_loaded)
298+
return 0;
298299

299-
if (WARN_ON(prph_sc_ctrl->pnvm_cfg.pnvm_size))
300-
return -EBUSY;
300+
if (WARN_ON(prph_sc_ctrl->pnvm_cfg.pnvm_size))
301+
return -EBUSY;
301302

302-
if (pnvm_payloads->n_chunks !=
303-
UNFRAGMENTED_PNVM_PAYLOADS_NUMBER) {
304-
IWL_DEBUG_FW(trans, "expected 2 payloads, got %d.\n",
305-
pnvm_payloads->n_chunks);
306-
return -EINVAL;
307-
}
308-
len0 = pnvm_payloads->chunks[0].len;
309-
len1 = pnvm_payloads->chunks[1].len;
310-
if (len1 > 0xFFFFFFFF - len0) {
311-
IWL_DEBUG_FW(trans, "sizes of payloads overflow.\n");
303+
if (pnvm_payloads->n_chunks != UNFRAGMENTED_PNVM_PAYLOADS_NUMBER) {
304+
IWL_DEBUG_FW(trans, "expected 2 payloads, got %d.\n",
305+
pnvm_payloads->n_chunks);
312306
return -EINVAL;
313-
}
314-
len = len0 + len1;
307+
}
315308

316-
dram->block = iwl_pcie_ctxt_info_dma_alloc_coherent(trans, len, &dram->physical);
317-
if (!dram->block) {
318-
IWL_DEBUG_FW(trans, "Failed to allocate PNVM DMA.\n");
319-
return -ENOMEM;
320-
}
321-
dram->size = len;
322-
memcpy(dram->block, pnvm_payloads->chunks[0].data, len0);
323-
memcpy((u8 *)dram->block + len0, pnvm_payloads->chunks[1].data,
324-
len1);
309+
len0 = pnvm_payloads->chunks[0].len;
310+
len1 = pnvm_payloads->chunks[1].len;
311+
if (len1 > 0xFFFFFFFF - len0) {
312+
IWL_DEBUG_FW(trans, "sizes of payloads overflow.\n");
313+
return -EINVAL;
314+
}
315+
len = len0 + len1;
316+
317+
dram->block = iwl_pcie_ctxt_info_dma_alloc_coherent(trans, len,
318+
&dram->physical);
319+
if (!dram->block) {
320+
IWL_DEBUG_FW(trans, "Failed to allocate PNVM DMA.\n");
321+
return -ENOMEM;
325322
}
326323

324+
dram->size = len;
325+
memcpy(dram->block, pnvm_payloads->chunks[0].data, len0);
326+
memcpy((u8 *)dram->block + len0, pnvm_payloads->chunks[1].data, len1);
327+
328+
trans->pnvm_loaded = true;
329+
return 0;
330+
}
331+
332+
void iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans)
333+
{
334+
struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
335+
struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl =
336+
&trans_pcie->prph_scratch->ctrl_cfg;
337+
338+
if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210)
339+
return;
340+
327341
prph_sc_ctrl->pnvm_cfg.pnvm_base_addr =
328342
cpu_to_le64(trans_pcie->pnvm_dram.physical);
329343
prph_sc_ctrl->pnvm_cfg.pnvm_size =
330344
cpu_to_le32(trans_pcie->pnvm_dram.size);
331345

332-
return 0;
333346
}
334347

335348
int iwl_trans_pcie_ctx_info_gen3_set_reduce_power(struct iwl_trans *trans,

drivers/net/wireless/intel/iwlwifi/pcie/trans.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,6 +3536,7 @@ static const struct iwl_trans_ops trans_ops_pcie_gen2 = {
35363536
.txq_free = iwl_txq_dyn_free,
35373537
.wait_txq_empty = iwl_trans_pcie_wait_txq_empty,
35383538
.rxq_dma_data = iwl_trans_pcie_rxq_dma_data,
3539+
.load_pnvm = iwl_trans_pcie_ctx_info_gen3_load_pnvm,
35393540
.set_pnvm = iwl_trans_pcie_ctx_info_gen3_set_pnvm,
35403541
.set_reduce_power = iwl_trans_pcie_ctx_info_gen3_set_reduce_power,
35413542
#ifdef CONFIG_IWLWIFI_DEBUGFS

0 commit comments

Comments
 (0)