Skip to content

Commit 56cd780

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 d9bf51f commit 56cd780

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;
@@ -1635,9 +1647,12 @@ static void apple_nvme_remove(struct platform_device *pdev)
16351647
apple_nvme_disable(anv, true);
16361648
nvme_uninit_ctrl(&anv->ctrl);
16371649

1638-
if (apple_rtkit_is_running(anv->rtk))
1650+
if (apple_rtkit_is_running(anv->rtk)) {
16391651
apple_rtkit_shutdown(anv->rtk);
16401652

1653+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1654+
}
1655+
16411656
apple_nvme_detach_genpd(anv);
16421657
}
16431658

@@ -1647,8 +1662,11 @@ static void apple_nvme_shutdown(struct platform_device *pdev)
16471662

16481663
flush_delayed_work(&anv->flush_dwork);
16491664
apple_nvme_disable(anv, true);
1650-
if (apple_rtkit_is_running(anv->rtk))
1665+
if (apple_rtkit_is_running(anv->rtk)) {
16511666
apple_rtkit_shutdown(anv->rtk);
1667+
1668+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1669+
}
16521670
}
16531671

16541672
static int apple_nvme_resume(struct device *dev)
@@ -1665,10 +1683,11 @@ static int apple_nvme_suspend(struct device *dev)
16651683

16661684
apple_nvme_disable(anv, true);
16671685

1668-
if (apple_rtkit_is_running(anv->rtk))
1686+
if (apple_rtkit_is_running(anv->rtk)) {
16691687
ret = apple_rtkit_shutdown(anv->rtk);
16701688

1671-
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1689+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1690+
}
16721691

16731692
return ret;
16741693
}

0 commit comments

Comments
 (0)