[PATCH V0 08/21] accel/amdxdna: Restore power mode override on AIE4 hardware start
From: David Zhang
Date: Fri Sep 25 2026 - 21:36:05 EST
Firmware boots in POWER_MODE_DEFAULT after a reload, so re-send the
cached user power mode override whenever the hardware starts. This
ensures the driver cache (ndev->pw_mode) and the firmware power state
remain consistent when the hardware is reinitialized (e.g. across
suspend/resume and runtime PM cycles).
Add aie4_restore_power_mode() to re-send the cached override once the
mailbox is initialized in aie4_pf_hw_start(), aie4_vf_hw_start(), and
aie4_classic_hw_start(). On a fresh probe, pw_mode is POWER_MODE_DEFAULT
so this is a no-op. Failure is returned to the caller so hardware start
aborts cleanly, preventing the driver from continuing with a dead
management channel if a timeout occurs.
In aie4_classic_hw_start(), if aie4_restore_power_mode() fails after
aie4_partition_init() has already succeeded, tear down the partition
before releasing the mailbox so the firmware partition created just
above isn't leaked on this error path. aie4_vf_hw_start() needs no such
fix: it never calls aie4_partition_init() itself, so partition teardown
is not its responsibility; the PF reclaims VF partitions.
Note that system and runtime suspend/resume callbacks (.suspend and
.resume) for AIE4 are implemented in a subsequent patch ("accel/amdxdna:
Implement AIE4 suspend and resume"), where the resume handlers invoke
these hw_start functions and trigger this power mode restoration.
Co-developed-by: Nishad Saraf <nishad.saraf@xxxxxxx>
Signed-off-by: Nishad Saraf <nishad.saraf@xxxxxxx>
Signed-off-by: David Zhang <yidong.zhang@xxxxxxx>
---
drivers/accel/amdxdna/aie4_message.c | 7 ++++--
drivers/accel/amdxdna/aie4_pci.c | 35 ++++++++++++++++++++++++++++
drivers/accel/amdxdna/aie4_pci.h | 3 +++
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/amdxdna/aie4_message.c b/drivers/accel/amdxdna/aie4_message.c
index a7025995d0e0..f5a17e10cc86 100644
--- a/drivers/accel/amdxdna/aie4_message.c
+++ b/drivers/accel/amdxdna/aie4_message.c
@@ -166,7 +166,10 @@ int aie4_msg_set_power_mode(struct amdxdna_dev_hdl *ndev, u8 power_mode)
ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg);
if (ret)
- return ret;
+ XDNA_WARN(ndev->aie.xdna,
+ "Failed to set power mode %u, ret %d", (u32)power_mode, ret);
+ else
+ XDNA_DBG(ndev->aie.xdna, "Power mode set to %u", (u32)power_mode);
- return 0;
+ return ret;
}
diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c
index 3a063d3ffa94..f72d0dac8263 100644
--- a/drivers/accel/amdxdna/aie4_pci.c
+++ b/drivers/accel/amdxdna/aie4_pci.c
@@ -295,6 +295,27 @@ static int aie4_query(struct amdxdna_dev_hdl *ndev)
return 0;
}
+/*
+ * Firmware always boots in POWER_MODE_DEFAULT after a (re)load, so re-send the
+ * cached user override whenever the hardware starts. This keeps the driver
+ * cache (ndev->pw_mode) and the firmware power state consistent across
+ * suspend/resume and runtime PM cycles. On a fresh probe pw_mode is
+ * POWER_MODE_DEFAULT and this is a no-op.
+ *
+ * Power override is a per-VF property in firmware: each supervisor (VF) stores
+ * its own requested mode and the hypervisor arbitrates globally by taking the
+ * highest mode across all supervisors. A full firmware reload on suspend clears
+ * every supervisor override back to default, so each device type (PF, VF and
+ * classic) must re-send its own cached override on resume.
+ */
+int aie4_restore_power_mode(struct amdxdna_dev_hdl *ndev)
+{
+ if (ndev->pw_mode == POWER_MODE_DEFAULT)
+ return 0;
+
+ return aie4_msg_set_power_mode(ndev, ndev->pw_mode);
+}
+
static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev)
{
int ret;
@@ -311,6 +332,10 @@ static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev)
if (ret)
goto mbox_fini;
+ ret = aie4_restore_power_mode(ndev);
+ if (ret)
+ goto mbox_fini;
+
return 0;
mbox_fini:
@@ -348,6 +373,10 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev)
if (ret)
goto mailbox_fini;
+ ret = aie4_restore_power_mode(ndev);
+ if (ret)
+ goto mailbox_fini;
+
return 0;
mailbox_fini:
@@ -389,8 +418,14 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev)
if (ret)
goto mailbox_fini;
+ ret = aie4_restore_power_mode(ndev);
+ if (ret)
+ goto partition_fini;
+
return 0;
+partition_fini:
+ aie4_partition_fini(ndev);
mailbox_fini:
aie4_mailbox_fini(ndev);
stop_fw:
diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h
index 98b637279257..fd2c50dc8080 100644
--- a/drivers/accel/amdxdna/aie4_pci.h
+++ b/drivers/accel/amdxdna/aie4_pci.h
@@ -87,6 +87,9 @@ int aie4_hwctx_init(struct amdxdna_hwctx *hwctx);
void aie4_hwctx_fini(struct amdxdna_hwctx *hwctx);
int aie4_cmd_wait(struct amdxdna_hwctx *hwctx, u64 seq, u32 timeout);
+/* aie4_pci.c */
+int aie4_restore_power_mode(struct amdxdna_dev_hdl *ndev);
+
/* aie4_sriov.c */
#if IS_ENABLED(CONFIG_PCI_IOV)
int aie4_sriov_configure(struct amdxdna_dev *xdna, int num_vfs);
--
2.34.1