From 70b1c8bc37755f523f617650386f12138bf7c01e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:01:11 +1100 Subject: [PATCH] accel/ane: h17: retry a failed resume after power cycling ANE_SYS Since #1283, a latched ANE_SYS power-on during system sleep is left failed: the PS reset recovery cannot run from the noirq resume, where it hung the Neo. genpd treats the domain as on, the boot at PM_POST_SUSPEND fails, and the engine stays quarantined until the next boot. That happens on about one boot in four to eight. The resume at PM_POST_SUSPEND runs in process context after the thaw, where the PMGR can run the recovery. When the boot after sleep fails, put the engine down, power cycle ANE_SYS with apple_pmgr_ps_cycle() (a power-on that latches again is cleared there), and boot once more. The engine is quarantined only if that fails too. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_fw_cold.c | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/accel/ane/ane_fw_cold.c b/drivers/accel/ane/ane_fw_cold.c index 5ea7e8fc865b8..f89dc3d441472 100644 --- a/drivers/accel/ane/ane_fw_cold.c +++ b/drivers/accel/ane/ane_fw_cold.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "ane_fw_cold.h" @@ -78,6 +79,7 @@ struct ane_fw_backend { /* The last cold boot after sleep: firmware ready, first replay, count. */ u64 resume_ready_ns, resume_first_ns; unsigned int resume_replayed; + unsigned int resume_recoveries; /* * EXCLAVE_MODE_STOP completed in this firmware boot: the warm boots * keep the firmware out of Exclave mode. Cleared by every cold boot. @@ -824,6 +826,46 @@ static int ane_fw_genpd_event(struct notifier_block *nb, unsigned long action, v return NOTIFY_OK; } +/* + * In system sleep ANE_SYS powers on from genpd's noirq resume. A power-on + * that latches there is left failed (the PMGR cannot run its PS reset + * recovery in that phase), genpd carries on as if the domain were on, and + * the boot after sleep fails. Here, in process context after the thaw, put + * the engine down, power cycle ANE_SYS through the PMGR (which clears a + * latched power-on outside system sleep) and boot once more. + */ +static int ane_fw_resume_retry(struct ane_fw_backend *b, int error) +{ + struct device_node *np; + int ret; + + dev_warn(&b->pdev->dev, "H17 ANE: resume failed (%d); power cycling ANE_SYS and booting again\n", + error); + if (b->powered) { + ret = ane_fw_power_down(b); + if (ret) + return ret; + } else if (b->power_ref) { + b->power_ref = false; + pm_runtime_put_sync(b->power); + } + np = of_parse_phandle(b->pdev->dev.of_node, "power-domains", 0); + if (!np) + return -ENODEV; + /* -EINVAL: genpd turned ANE_SYS off, so the next power-on is a fresh one. */ + ret = apple_pmgr_ps_cycle(np); + of_node_put(np); + if (ret && ret != -EINVAL) + return ret; + ret = ane_fw_cold_cycle_boot(b); + if (!ret) { + b->resume_recoveries++; + dev_info(&b->pdev->dev, "H17 ANE: recovered after a failed resume (%u so far)\n", + b->resume_recoveries); + } + return ret; +} + static void ane_fw_sleep_resume(struct ane_fw_backend *b) { s64 ready, first; @@ -847,6 +889,8 @@ static void ane_fw_sleep_resume(struct ane_fw_backend *b) if (!ret) ret = ane_fw_cold_cycle_boot(b); } + if (ret) + ret = ane_fw_resume_retry(b, ret); if (ret) { /* Every mapping and backing stays for diagnosis. */ ane_fw_quarantine(b, ret);