Skip to content

Commit 8f682bc

Browse files
marcanjannau
authored andcommitted
apple-nvme: Support coprocessors left idle
iBoot on at least some firmwares/machines leaves ANS2 running, requiring a wake command instead of a CPU boot (and if we reset ANS2 in that state, everything breaks). Only stop the CPU if RTKit was running, and only do the reset dance if the CPU is stopped. Normal shutdown handoff: - RTKit not yet running - CPU detected not running - Reset - CPU powerup - RTKit boot wait ANS2 left running/idle: - RTKit not yet running - CPU detected running - RTKit wake message Sleep/resume cycle: - RTKit shutdown - CPU stopped - (sleep here) - CPU detected not running - Reset - CPU powerup - RTKit boot wait Shutdown or device removal: - RTKit shutdown - CPU stopped Therefore, the CPU running bit serves as a consistent flag of whether the coprocessor is fully stopped or just idle. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 185472e commit 8f682bc

1 file changed

Lines changed: 36 additions & 17 deletions

File tree

drivers/nvme/host/apple.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,25 +1049,37 @@ static void apple_nvme_reset_work(struct work_struct *work)
10491049
ret = apple_rtkit_shutdown(anv->rtk);
10501050
if (ret)
10511051
goto out;
1052+
1053+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
10521054
}
10531055

1054-
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1056+
/*
1057+
* Only do the soft-reset if the CPU is not running, which means either we
1058+
* or the previous stage shut it down cleanly.
1059+
*/
1060+
if (!(readl(anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL) &
1061+
APPLE_ANS_COPROC_CPU_CONTROL_RUN)) {
10551062

1056-
ret = reset_control_assert(anv->reset);
1057-
if (ret)
1058-
goto out;
1063+
ret = reset_control_assert(anv->reset);
1064+
if (ret)
1065+
goto out;
10591066

1060-
ret = apple_rtkit_reinit(anv->rtk);
1061-
if (ret)
1062-
goto out;
1067+
ret = apple_rtkit_reinit(anv->rtk);
1068+
if (ret)
1069+
goto out;
10631070

1064-
ret = reset_control_deassert(anv->reset);
1065-
if (ret)
1066-
goto out;
1071+
ret = reset_control_deassert(anv->reset);
1072+
if (ret)
1073+
goto out;
1074+
1075+
writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN,
1076+
anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1077+
1078+
ret = apple_rtkit_boot(anv->rtk);
1079+
} else {
1080+
ret = apple_rtkit_wake(anv->rtk);
1081+
}
10671082

1068-
writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN,
1069-
anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1070-
ret = apple_rtkit_boot(anv->rtk);
10711083
if (ret) {
10721084
dev_err(anv->dev, "ANS did not boot");
10731085
goto out;
@@ -1630,9 +1642,12 @@ static void apple_nvme_remove(struct platform_device *pdev)
16301642
apple_nvme_disable(anv, true);
16311643
nvme_uninit_ctrl(&anv->ctrl);
16321644

1633-
if (apple_rtkit_is_running(anv->rtk))
1645+
if (apple_rtkit_is_running(anv->rtk)) {
16341646
apple_rtkit_shutdown(anv->rtk);
16351647

1648+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1649+
}
1650+
16361651
apple_nvme_detach_genpd(anv);
16371652
}
16381653

@@ -1642,8 +1657,11 @@ static void apple_nvme_shutdown(struct platform_device *pdev)
16421657

16431658
flush_delayed_work(&anv->flush_dwork);
16441659
apple_nvme_disable(anv, true);
1645-
if (apple_rtkit_is_running(anv->rtk))
1660+
if (apple_rtkit_is_running(anv->rtk)) {
16461661
apple_rtkit_shutdown(anv->rtk);
1662+
1663+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1664+
}
16471665
}
16481666

16491667
static int apple_nvme_resume(struct device *dev)
@@ -1660,10 +1678,11 @@ static int apple_nvme_suspend(struct device *dev)
16601678

16611679
apple_nvme_disable(anv, true);
16621680

1663-
if (apple_rtkit_is_running(anv->rtk))
1681+
if (apple_rtkit_is_running(anv->rtk)) {
16641682
ret = apple_rtkit_shutdown(anv->rtk);
16651683

1666-
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1684+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1685+
}
16671686

16681687
return ret;
16691688
}

0 commit comments

Comments
 (0)