Reorganize AIE4 hardware initialization into distinct phases: - aie4_query_fw(): Query NPU and CERT firmware versions. - aie4_config_fw(): Attach work buffer and configure context switch hysteresis. - aie4_setup_aie(): Query AIE version, metadata, initialize DPM frequency table, and initialize partitions.
Update aie4_pf_hw_start(), aie4_vf_hw_start(), and aie4_classic_hw_start() to use these phases and unify error unwinding labels. As part of this, aie4_pf_hw_start() now also calls aie4_query_fw(), which it previously did not do. Additionally: - Zero-initialize struct smu_config smu_conf in aie4_prepare_firmware(). - Clean up iomem pointer type in aie4_fw_is_alive() to void __iomem *. Signed-off-by: David Zhang <[email protected]> --- drivers/accel/amdxdna/aie4_pci.c | 82 +++++++++++++++++++------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c index 60348ec5bc53..b1742116bedd 100644 --- a/drivers/accel/amdxdna/aie4_pci.c +++ b/drivers/accel/amdxdna/aie4_pci.c @@ -49,7 +49,7 @@ static int aie4_fw_is_alive(struct amdxdna_dev *xdna) { const struct amdxdna_dev_priv *npriv = xdna->dev_info->dev_priv; struct amdxdna_dev_hdl *ndev = xdna->dev_handle; - u32 __iomem *src; + void __iomem *src; u32 fw_is_valid; int ret; @@ -273,7 +273,13 @@ static void aie4_partition_fini(struct amdxdna_dev_hdl *ndev) XDNA_ERR(xdna, "partition fini failed: %d", ret); } -static int aie4_query(struct amdxdna_dev_hdl *ndev) +/* + * Called by all three hw_start paths (PF, VF, classic) right after mailbox + * init. aie4_query_cert_firmware_version() runs a CERT protocol + * compatibility check, so firmware/driver compatibility is intentionally + * verified before any other firmware operation is attempted. + */ +static int aie4_query_fw(struct amdxdna_dev_hdl *ndev) { struct amdxdna_dev *xdna = ndev->aie.xdna; int ret; @@ -286,23 +292,6 @@ static int aie4_query(struct amdxdna_dev_hdl *ndev) if (ret) return ret; - ret = aie4_query_aie_version(ndev, &ndev->aie.version); - if (ret) - return ret; - - ret = aie4_query_aie_metadata(ndev, &ndev->aie.metadata); - if (ret) - return ret; - - ndev->total_col = min_t(u32, AIE4_TOTAL_COLUMN, ndev->aie.metadata.cols); - - ret = aie4_init_dpm_freq_table(ndev); - if (ret) { - /* if query dpm from fw failed, using default value */ - if (ndev->priv->hw_ops && ndev->priv->hw_ops->set_dpm) - (void)ndev->priv->hw_ops->set_dpm(&ndev->aie, 0); - } - return 0; } @@ -341,6 +330,30 @@ static int aie4_config_fw(struct amdxdna_dev_hdl *ndev) return 0; } +static int aie4_setup_aie(struct amdxdna_dev_hdl *ndev) +{ + int ret; + + ret = aie4_query_aie_version(ndev, &ndev->aie.version); + if (ret) + return ret; + + ret = aie4_query_aie_metadata(ndev, &ndev->aie.metadata); + if (ret) + return ret; + + ndev->total_col = min_t(u32, AIE4_TOTAL_COLUMN, ndev->aie.metadata.cols); + + ret = aie4_init_dpm_freq_table(ndev); + if (ret) { + /* if query dpm from fw failed, using default value */ + if (ndev->priv->hw_ops && ndev->priv->hw_ops->set_dpm) + (void)ndev->priv->hw_ops->set_dpm(&ndev->aie, 0); + } + + return aie4_partition_init(ndev); +} + static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev) { int ret; @@ -353,6 +366,10 @@ static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev) if (ret) goto stop_fw; + ret = aie4_query_fw(ndev); + if (ret) + goto mbox_fini; + ret = aie4_config_fw(ndev); if (ret) goto mbox_fini; @@ -390,21 +407,21 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev) if (ret) return ret; - ret = aie4_query(ndev); + ret = aie4_query_fw(ndev); if (ret) - goto mailbox_fini; + goto mbox_fini; - ret = aie4_partition_init(ndev); + ret = aie4_setup_aie(ndev); if (ret) - goto mailbox_fini; + goto mbox_fini; ret = aie4_restore_power_mode(ndev); if (ret) - goto mailbox_fini; + goto mbox_fini; return 0; -mailbox_fini: +mbox_fini: aie4_mailbox_fini(ndev); return ret; } @@ -431,17 +448,17 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev) if (ret) goto stop_fw; - ret = aie4_query(ndev); + ret = aie4_query_fw(ndev); if (ret) - goto mailbox_fini; + goto mbox_fini; ret = aie4_config_fw(ndev); if (ret) - goto mailbox_fini; + goto mbox_fini; - ret = aie4_partition_init(ndev); + ret = aie4_setup_aie(ndev); if (ret) - goto mailbox_fini; + goto mbox_fini; ret = aie4_restore_power_mode(ndev); if (ret) @@ -451,10 +468,11 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev) partition_fini: aie4_partition_fini(ndev); -mailbox_fini: +mbox_fini: aie4_mailbox_fini(ndev); stop_fw: aie4_fw_stop(ndev); + return ret; } @@ -528,8 +546,8 @@ static int aie4_prepare_firmware(struct amdxdna_dev_hdl *ndev, void __iomem *tbl[PCI_NUM_RESOURCES]) { struct amdxdna_dev *xdna = ndev->aie.xdna; + struct smu_config smu_conf = {}; struct psp_config psp_conf; - struct smu_config smu_conf; int i; psp_conf.fw_size = npufw->size; -- 2.34.1
