Skip to content

Commit f7c1c5e

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 f59e516 commit f7c1c5e

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;
@@ -1612,9 +1624,12 @@ static void apple_nvme_remove(struct platform_device *pdev)
16121624
apple_nvme_disable(anv, true);
16131625
nvme_uninit_ctrl(&anv->ctrl);
16141626

1615-
if (apple_rtkit_is_running(anv->rtk))
1627+
if (apple_rtkit_is_running(anv->rtk)) {
16161628
apple_rtkit_shutdown(anv->rtk);
16171629

1630+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1631+
}
1632+
16181633
apple_nvme_detach_genpd(anv);
16191634
}
16201635

@@ -1624,8 +1639,11 @@ static void apple_nvme_shutdown(struct platform_device *pdev)
16241639

16251640
flush_delayed_work(&anv->flush_dwork);
16261641
apple_nvme_disable(anv, true);
1627-
if (apple_rtkit_is_running(anv->rtk))
1642+
if (apple_rtkit_is_running(anv->rtk)) {
16281643
apple_rtkit_shutdown(anv->rtk);
1644+
1645+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1646+
}
16291647
}
16301648

16311649
static int apple_nvme_resume(struct device *dev)
@@ -1642,10 +1660,11 @@ static int apple_nvme_suspend(struct device *dev)
16421660

16431661
apple_nvme_disable(anv, true);
16441662

1645-
if (apple_rtkit_is_running(anv->rtk))
1663+
if (apple_rtkit_is_running(anv->rtk)) {
16461664
ret = apple_rtkit_shutdown(anv->rtk);
16471665

1648-
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1666+
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
1667+
}
16491668

16501669
return ret;
16511670
}

0 commit comments

Comments
 (0)