Currently, we have two APIs towards the transport: 1. load_pnvm/reduced_power: this really tells the transport to allocate the DRAM for the PNVM/reduced power 2. set_pnvm/reduced_power: this tells the transport to point the context info to the previousely allocated DRAM. Then, the PNVM code triggers the doorbell on its own. In order to be prepared for future bus types, rework the APIs: 1. merge the load_* APIs into a single alloc_pnvm API, with a boolean that indicates whether the payloads are of the PNVM or of the reduced power table, and rename it to better indicate what it does. 2. remove the set_* APIs, and replace them by a new kick_pnvm API, which will both setup the context info and kick the doorbel, as this is bus specific. Assisted-by: LLM Reviewed-by: Emmanuel Grumbach Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/pnvm.c | 20 +-- .../net/wireless/intel/iwlwifi/iwl-trans.c | 32 ++-- .../net/wireless/intel/iwlwifi/iwl-trans.h | 37 ++--- .../intel/iwlwifi/pcie/ctxt-info-v2.c | 140 ++++++++++-------- .../intel/iwlwifi/pcie/iwl-context-info-v2.h | 11 +- .../net/wireless/intel/iwlwifi/pcie/trans.c | 6 +- 6 files changed, 116 insertions(+), 130 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c index 884937522ff0..12fad19109bf 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c @@ -383,8 +383,8 @@ iwl_pnvm_load_pnvm_to_trans(struct iwl_trans *trans, if (trans->fail_to_parse_pnvm_image) return; - if (trans->pnvm_loaded) - goto set; + if (trans->pnvm_allocated) + return; data = iwl_get_pnvm_image(trans, &length, sku_id, fw); if (!data) { @@ -402,13 +402,11 @@ iwl_pnvm_load_pnvm_to_trans(struct iwl_trans *trans, goto free; } - ret = iwl_trans_load_pnvm(trans, pnvm_data); + ret = iwl_trans_alloc_pnvm(trans, pnvm_data, false); if (ret) goto free; IWL_DEBUG_INFO(trans, "loaded PNVM version %08x\n", pnvm_data->version); -set: - iwl_trans_set_pnvm(trans); free: /* free only if it was allocated, i.e. not just embedded PNVM data */ if (data != fw->pnvm_data) @@ -428,8 +426,8 @@ iwl_pnvm_load_reduce_power_to_trans(struct iwl_trans *trans, if (trans->failed_to_load_reduce_power_image) return; - if (trans->reduce_power_loaded) - goto set; + if (trans->reduce_power_allocated) + return; data = iwl_uefi_get_reduced_power(trans, &length); if (IS_ERR(data)) { @@ -448,7 +446,7 @@ iwl_pnvm_load_reduce_power_to_trans(struct iwl_trans *trans, goto free; } - ret = iwl_trans_load_reduce_power(trans, pnvm_data); + ret = iwl_trans_alloc_pnvm(trans, pnvm_data, true); if (ret) { IWL_DEBUG_FW(trans, "Failed to load reduce power table %d\n", @@ -457,8 +455,6 @@ iwl_pnvm_load_reduce_power_to_trans(struct iwl_trans *trans, goto free; } -set: - iwl_trans_set_reduce_power(trans); free: kfree(data); kfree(pnvm_data); @@ -483,9 +479,7 @@ int iwl_pnvm_load(struct iwl_trans *trans, ntf_cmds, ARRAY_SIZE(ntf_cmds), iwl_pnvm_complete_fn, trans); - /* kick the doorbell */ - iwl_trans_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, - UREG_DOORBELL_TO_ISR6_PNVM); + iwl_trans_kick_pnvm(trans); return iwl_wait_notification(notif_wait, &pnvm_wait, MVM_UCODE_PNVM_TIMEOUT); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index c2c106d4dd6d..3d805654d232 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -989,35 +989,21 @@ int iwl_trans_get_rxq_dma_data(struct iwl_trans *trans, int queue, } IWL_EXPORT_SYMBOL(iwl_trans_get_rxq_dma_data); -int iwl_trans_load_pnvm(struct iwl_trans *trans, - const struct iwl_pnvm_image *pnvm_data) +int iwl_trans_alloc_pnvm(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads, + bool reduce_power) { - if (WARN_ON_ONCE(!trans->ops->load_pnvm)) + if (WARN_ON_ONCE(!trans->ops->alloc_pnvm)) return -EOPNOTSUPP; - return trans->ops->load_pnvm(trans, pnvm_data); + return trans->ops->alloc_pnvm(trans, payloads, reduce_power); } -IWL_EXPORT_SYMBOL(iwl_trans_load_pnvm); +IWL_EXPORT_SYMBOL(iwl_trans_alloc_pnvm); -void iwl_trans_set_pnvm(struct iwl_trans *trans) +void iwl_trans_kick_pnvm(struct iwl_trans *trans) { - if (WARN_ON_ONCE(!trans->ops->set_pnvm)) + if (WARN_ON_ONCE(!trans->ops->kick_pnvm)) return; - trans->ops->set_pnvm(trans); -} - -int iwl_trans_load_reduce_power(struct iwl_trans *trans, - const struct iwl_pnvm_image *payloads) -{ - if (WARN_ON_ONCE(!trans->ops->load_reduce_power)) - return -EOPNOTSUPP; - return trans->ops->load_reduce_power(trans, payloads); -} - -void iwl_trans_set_reduce_power(struct iwl_trans *trans) -{ - if (WARN_ON_ONCE(!trans->ops->set_reduce_power)) - return; - trans->ops->set_reduce_power(trans); + trans->ops->kick_pnvm(trans); } bool iwl_trans_is_pm_supported(struct iwl_trans *trans) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index f5fa6b5791af..f97bde14cdc8 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -754,11 +754,11 @@ struct iwl_trans_ops; * @status: a bit-mask of transport status flags * @dev: pointer to struct device * that represents the device * @info: device information for use by other layers - * @pnvm_loaded: indicates PNVM was loaded + * @pnvm_allocated: indicates PNVM was allocated * @suppress_cmd_error_once: suppress "FW error in SYNC CMD" once, * e.g. for testing * @fail_to_parse_pnvm_image: set to true if pnvm parsing failed - * @reduce_power_loaded: indicates reduced power section was loaded + * @reduce_power_allocated: indicates reduced power section was allocated * @failed_to_load_reduce_power_image: set to true if pnvm loading failed * @dbgfs_dir: iwlwifi debugfs base dir for this device * @sync_cmd_lockdep_map: lockdep map for checking sync commands @@ -797,9 +797,9 @@ struct iwl_trans { bool step_urm; bool suppress_cmd_error_once; - u8 pnvm_loaded:1; + u8 pnvm_allocated:1; u8 fail_to_parse_pnvm_image:1; - u8 reduce_power_loaded:1; + u8 reduce_power_allocated:1; u8 failed_to_load_reduce_power_image:1; struct dentry *dbgfs_dir; @@ -1182,15 +1182,11 @@ void iwl_trans_sync_nmi(struct iwl_trans *trans); void iwl_trans_force_nmi(struct iwl_trans *trans); -int iwl_trans_load_pnvm(struct iwl_trans *trans, - const struct iwl_pnvm_image *pnvm_data); +int iwl_trans_alloc_pnvm(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads, + bool reduce_power); -void iwl_trans_set_pnvm(struct iwl_trans *trans); - -int iwl_trans_load_reduce_power(struct iwl_trans *trans, - const struct iwl_pnvm_image *payloads); - -void iwl_trans_set_reduce_power(struct iwl_trans *trans); +void iwl_trans_kick_pnvm(struct iwl_trans *trans); static inline bool iwl_trans_dbg_ini_valid(struct iwl_trans *trans) { @@ -1332,10 +1328,9 @@ void iwl_trans_fw_reset_handshake(struct iwl_trans *trans); * @txq_alloc: allocate a TX queue (gen2) * @txq_free: free a TX queue allocated by @txq_alloc * @rxq_dma_data: get the DMA addresses of an RX queue - * @load_pnvm: load the PNVM image - * @set_pnvm: tell the firmware to use the loaded PNVM - * @load_reduce_power: load the reduced power table - * @set_reduce_power: tell the firmware to use the reduced power table + * @alloc_pnvm: allocate and store a copy of the PNVM image, or of the + * reduced power table if @reduce_power is set + * @kick_pnvm: tell the firmware that the PNVM is ready * @is_pm_supported: whether bus power management is supported * @is_ltr_enabled: whether LTR is enabled on the bus * @activate_nic: bring the NIC out of low power and make it accessible @@ -1414,12 +1409,10 @@ struct iwl_trans_ops { int (*rxq_dma_data)(struct iwl_trans *trans, int queue, struct iwl_trans_rxq_dma_data *data); - int (*load_pnvm)(struct iwl_trans *trans, - const struct iwl_pnvm_image *pnvm_data); - void (*set_pnvm)(struct iwl_trans *trans); - int (*load_reduce_power)(struct iwl_trans *trans, - const struct iwl_pnvm_image *payloads); - void (*set_reduce_power)(struct iwl_trans *trans); + int (*alloc_pnvm)(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads, + bool reduce_power); + void (*kick_pnvm)(struct iwl_trans *trans); bool (*is_pm_supported)(struct iwl_trans *trans); bool (*is_ltr_enabled)(struct iwl_trans *trans); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c index c914fd0ca505..804f85006b38 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c @@ -437,9 +437,9 @@ void iwl_pcie_ctxt_info_v2_free(struct iwl_trans *trans, bool alive) trans_pcie->prph_info = NULL; } -static int iwl_pcie_load_payloads_contig(struct iwl_trans *trans, - const struct iwl_pnvm_image *pnvm_data, - struct iwl_dram_data *dram) +static int iwl_pcie_alloc_payloads_contig(struct iwl_trans *trans, + const struct iwl_pnvm_image *pnvm_data, + struct iwl_dram_data *dram) { u32 len, len0, len1; @@ -471,7 +471,7 @@ static int iwl_pcie_load_payloads_contig(struct iwl_trans *trans, return 0; } -static int iwl_pcie_load_payloads_segments +static int iwl_pcie_alloc_payloads_segments (struct iwl_trans *trans, struct iwl_dram_regions *dram_regions, const struct iwl_pnvm_image *pnvm_data) @@ -526,8 +526,54 @@ static int iwl_pcie_load_payloads_segments } -int iwl_trans_pcie_ctx_info_v2_load_pnvm(struct iwl_trans *trans, - const struct iwl_pnvm_image *pnvm_payloads) +static int +iwl_pcie_ctx_info_v2_alloc_reduce_power(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads) +{ + struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl = + &trans_pcie->prph_scratch->ctrl_cfg; + struct iwl_dram_regions *dram_regions = &trans_pcie->reduced_tables_data; + int ret = 0; + + /* only allocate the DRAM if not allocated yet */ + if (trans->reduce_power_allocated) + return 0; + + if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) + return 0; + + if (WARN_ON(prph_sc_ctrl->reduce_power_cfg.size)) + return -EBUSY; + + if (!payloads->n_chunks) { + IWL_DEBUG_FW(trans, "no payloads\n"); + return -EINVAL; + } + + /* save payloads in several DRAM sections */ + if (trans->conf.fragmented_pnvm) { + ret = iwl_pcie_alloc_payloads_segments(trans, + dram_regions, + payloads); + if (!ret) + trans->reduce_power_allocated = true; + } else { + /* save only in one DRAM section */ + ret = iwl_pcie_alloc_payloads_contig(trans, payloads, + &dram_regions->drams[0]); + if (!ret) { + dram_regions->n_regions = 1; + trans->reduce_power_allocated = true; + } + } + + return ret; +} + +int iwl_trans_pcie_ctx_info_v2_alloc_pnvm(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads, + bool reduce_power) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl = @@ -535,8 +581,11 @@ int iwl_trans_pcie_ctx_info_v2_load_pnvm(struct iwl_trans *trans, struct iwl_dram_regions *dram_regions = &trans_pcie->pnvm_data; int ret = 0; + if (reduce_power) + return iwl_pcie_ctx_info_v2_alloc_reduce_power(trans, payloads); + /* only allocate the DRAM if not allocated yet */ - if (trans->pnvm_loaded) + if (trans->pnvm_allocated) return 0; if (WARN_ON(prph_sc_ctrl->pnvm_cfg.pnvm_size)) @@ -545,25 +594,25 @@ int iwl_trans_pcie_ctx_info_v2_load_pnvm(struct iwl_trans *trans, if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) return 0; - if (!pnvm_payloads->n_chunks) { + if (!payloads->n_chunks) { IWL_DEBUG_FW(trans, "no payloads\n"); return -EINVAL; } /* save payloads in several DRAM sections */ if (trans->conf.fragmented_pnvm) { - ret = iwl_pcie_load_payloads_segments(trans, - dram_regions, - pnvm_payloads); + ret = iwl_pcie_alloc_payloads_segments(trans, + dram_regions, + payloads); if (!ret) - trans->pnvm_loaded = true; + trans->pnvm_allocated = true; } else { /* save only in one DRAM section */ - ret = iwl_pcie_load_payloads_contig(trans, pnvm_payloads, - &dram_regions->drams[0]); + ret = iwl_pcie_alloc_payloads_contig(trans, payloads, + &dram_regions->drams[0]); if (!ret) { dram_regions->n_regions = 1; - trans->pnvm_loaded = true; + trans->pnvm_allocated = true; } } @@ -607,61 +656,20 @@ static void iwl_pcie_set_contig_pnvm(struct iwl_trans *trans) cpu_to_le32(trans_pcie->pnvm_data.drams[0].size); } -void iwl_trans_pcie_ctx_info_v2_set_pnvm(struct iwl_trans *trans) +static void iwl_trans_pcie_ctx_info_v2_set_pnvm(struct iwl_trans *trans) { if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) return; + if (!trans->pnvm_allocated) + return; + if (trans->conf.fragmented_pnvm) iwl_pcie_set_pnvm_segments(trans); else iwl_pcie_set_contig_pnvm(trans); } -int iwl_trans_pcie_ctx_info_v2_load_reduce_power(struct iwl_trans *trans, - const struct iwl_pnvm_image *payloads) -{ - struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl = - &trans_pcie->prph_scratch->ctrl_cfg; - struct iwl_dram_regions *dram_regions = &trans_pcie->reduced_tables_data; - int ret = 0; - - /* only allocate the DRAM if not allocated yet */ - if (trans->reduce_power_loaded) - return 0; - - if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) - return 0; - - if (WARN_ON(prph_sc_ctrl->reduce_power_cfg.size)) - return -EBUSY; - - if (!payloads->n_chunks) { - IWL_DEBUG_FW(trans, "no payloads\n"); - return -EINVAL; - } - - /* save payloads in several DRAM sections */ - if (trans->conf.fragmented_pnvm) { - ret = iwl_pcie_load_payloads_segments(trans, - dram_regions, - payloads); - if (!ret) - trans->reduce_power_loaded = true; - } else { - /* save only in one DRAM section */ - ret = iwl_pcie_load_payloads_contig(trans, payloads, - &dram_regions->drams[0]); - if (!ret) { - dram_regions->n_regions = 1; - trans->reduce_power_loaded = true; - } - } - - return ret; -} - static void iwl_pcie_set_reduce_power_segments(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); @@ -687,14 +695,24 @@ static void iwl_pcie_set_contig_reduce_power(struct iwl_trans *trans) cpu_to_le32(trans_pcie->reduced_tables_data.drams[0].size); } -void iwl_trans_pcie_ctx_info_v2_set_reduce_power(struct iwl_trans *trans) +static void iwl_trans_pcie_ctx_info_v2_set_reduce_power(struct iwl_trans *trans) { if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) return; + if (!trans->reduce_power_allocated) + return; + if (trans->conf.fragmented_pnvm) iwl_pcie_set_reduce_power_segments(trans); else iwl_pcie_set_contig_reduce_power(trans); } +void iwl_trans_pcie_kick_pnvm(struct iwl_trans *trans) +{ + iwl_trans_pcie_ctx_info_v2_set_pnvm(trans); + iwl_trans_pcie_ctx_info_v2_set_reduce_power(trans); + iwl_trans_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, + UREG_DOORBELL_TO_ISR6_PNVM); +} diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h b/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h index b432e37ff257..691465d7b376 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h @@ -13,11 +13,8 @@ int iwl_pcie_ctxt_info_v2_alloc(struct iwl_trans *trans, void iwl_pcie_ctxt_info_v2_kick(struct iwl_trans *trans); void iwl_pcie_ctxt_info_v2_free(struct iwl_trans *trans, bool alive); -int iwl_trans_pcie_ctx_info_v2_load_pnvm(struct iwl_trans *trans, - const struct iwl_pnvm_image *pnvm_payloads); -void iwl_trans_pcie_ctx_info_v2_set_pnvm(struct iwl_trans *trans); -int -iwl_trans_pcie_ctx_info_v2_load_reduce_power(struct iwl_trans *trans, - const struct iwl_pnvm_image *payloads); -void iwl_trans_pcie_ctx_info_v2_set_reduce_power(struct iwl_trans *trans); +int iwl_trans_pcie_ctx_info_v2_alloc_pnvm(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads, + bool reduce_power); +void iwl_trans_pcie_kick_pnvm(struct iwl_trans *trans); #endif /* __iwl_context_info_file_v2_h__ */ diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 10bc61fe7ea5..cd7b94b287bb 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -3750,10 +3750,8 @@ const struct iwl_trans_ops iwl_trans_pcie_ops = { .txq_free = iwl_txq_dyn_free, .rxq_dma_data = iwl_trans_pcie_rxq_dma_data, - .load_pnvm = iwl_trans_pcie_ctx_info_v2_load_pnvm, - .set_pnvm = iwl_trans_pcie_ctx_info_v2_set_pnvm, - .load_reduce_power = iwl_trans_pcie_ctx_info_v2_load_reduce_power, - .set_reduce_power = iwl_trans_pcie_ctx_info_v2_set_reduce_power, + .alloc_pnvm = iwl_trans_pcie_ctx_info_v2_alloc_pnvm, + .kick_pnvm = iwl_trans_pcie_kick_pnvm, .is_pm_supported = iwl_pcie_gen1_is_pm_supported, .is_ltr_enabled = iwl_pcie_is_ltr_enabled, -- 2.34.1