* [PATCH v2 1/2] apple-nvme: Support coprocessors left idle
2025-02-13 16:12 [PATCH v2 0/2] apple-nvme: bug fixes Alyssa Rosenzweig
@ 2025-02-13 16:12 ` Alyssa Rosenzweig
2025-02-13 16:12 ` [PATCH v2 2/2] apple-nvme: Release power domains when probe fails Alyssa Rosenzweig
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alyssa Rosenzweig @ 2025-02-13 16:12 UTC (permalink / raw)
To: Hector Martin, Sven Peter, Keith Busch, Jens Axboe,
Christoph Hellwig, Sagi Grimberg, Philipp Zabel
Cc: asahi, linux-arm-kernel, linux-nvme, linux-kernel,
Alyssa Rosenzweig, Neal Gompa
From: Hector Martin <marcan@marcan.st>
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>
Reviewed-by: Neal Gompa <neal@gompa.dev>
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
drivers/nvme/host/apple.c | 53 ++++++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 17 deletions(-)
diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
index 1de11b722f049abbc96a6bb62b072ac973b8c4aa..5e1c01a67ee81a36faa3da2f86a3a24fefcdfd6f 100644
--- a/drivers/nvme/host/apple.c
+++ b/drivers/nvme/host/apple.c
@@ -1011,25 +1011,37 @@ static void apple_nvme_reset_work(struct work_struct *work)
ret = apple_rtkit_shutdown(anv->rtk);
if (ret)
goto out;
+
+ writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
}
- writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
+ /*
+ * Only do the soft-reset if the CPU is not running, which means either we
+ * or the previous stage shut it down cleanly.
+ */
+ if (!(readl(anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL) &
+ APPLE_ANS_COPROC_CPU_CONTROL_RUN)) {
- ret = reset_control_assert(anv->reset);
- if (ret)
- goto out;
+ ret = reset_control_assert(anv->reset);
+ if (ret)
+ goto out;
- ret = apple_rtkit_reinit(anv->rtk);
- if (ret)
- goto out;
+ ret = apple_rtkit_reinit(anv->rtk);
+ if (ret)
+ goto out;
- ret = reset_control_deassert(anv->reset);
- if (ret)
- goto out;
+ ret = reset_control_deassert(anv->reset);
+ if (ret)
+ goto out;
+
+ writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN,
+ anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
+
+ ret = apple_rtkit_boot(anv->rtk);
+ } else {
+ ret = apple_rtkit_wake(anv->rtk);
+ }
- writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN,
- anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
- ret = apple_rtkit_boot(anv->rtk);
if (ret) {
dev_err(anv->dev, "ANS did not boot");
goto out;
@@ -1563,9 +1575,12 @@ static void apple_nvme_remove(struct platform_device *pdev)
apple_nvme_disable(anv, true);
nvme_uninit_ctrl(&anv->ctrl);
- if (apple_rtkit_is_running(anv->rtk))
+ if (apple_rtkit_is_running(anv->rtk)) {
apple_rtkit_shutdown(anv->rtk);
+ writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
+ }
+
apple_nvme_detach_genpd(anv);
}
@@ -1574,8 +1589,11 @@ static void apple_nvme_shutdown(struct platform_device *pdev)
struct apple_nvme *anv = platform_get_drvdata(pdev);
apple_nvme_disable(anv, true);
- if (apple_rtkit_is_running(anv->rtk))
+ if (apple_rtkit_is_running(anv->rtk)) {
apple_rtkit_shutdown(anv->rtk);
+
+ writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
+ }
}
static int apple_nvme_resume(struct device *dev)
@@ -1592,10 +1610,11 @@ static int apple_nvme_suspend(struct device *dev)
apple_nvme_disable(anv, true);
- if (apple_rtkit_is_running(anv->rtk))
+ if (apple_rtkit_is_running(anv->rtk)) {
ret = apple_rtkit_shutdown(anv->rtk);
- writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
+ writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
+ }
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/2] apple-nvme: Release power domains when probe fails
2025-02-13 16:12 [PATCH v2 0/2] apple-nvme: bug fixes Alyssa Rosenzweig
2025-02-13 16:12 ` [PATCH v2 1/2] apple-nvme: Support coprocessors left idle Alyssa Rosenzweig
@ 2025-02-13 16:12 ` Alyssa Rosenzweig
2025-02-13 16:14 ` [PATCH v2 0/2] apple-nvme: bug fixes Sven Peter
2025-02-18 15:42 ` Keith Busch
3 siblings, 0 replies; 5+ messages in thread
From: Alyssa Rosenzweig @ 2025-02-13 16:12 UTC (permalink / raw)
To: Hector Martin, Sven Peter, Keith Busch, Jens Axboe,
Christoph Hellwig, Sagi Grimberg, Philipp Zabel
Cc: asahi, linux-arm-kernel, linux-nvme, linux-kernel,
Alyssa Rosenzweig, Neal Gompa
From: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Reviewed-by: Neal Gompa <neal@gompa.dev>
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
drivers/nvme/host/apple.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
index 5e1c01a67ee81a36faa3da2f86a3a24fefcdfd6f..a060f69558e76970bfba046cca5127243e8a51b7 100644
--- a/drivers/nvme/host/apple.c
+++ b/drivers/nvme/host/apple.c
@@ -1528,6 +1528,7 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev)
return anv;
put_dev:
+ apple_nvme_detach_genpd(anv);
put_device(anv->dev);
return ERR_PTR(ret);
}
@@ -1561,6 +1562,7 @@ static int apple_nvme_probe(struct platform_device *pdev)
nvme_uninit_ctrl(&anv->ctrl);
out_put_ctrl:
nvme_put_ctrl(&anv->ctrl);
+ apple_nvme_detach_genpd(anv);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] apple-nvme: bug fixes
2025-02-13 16:12 [PATCH v2 0/2] apple-nvme: bug fixes Alyssa Rosenzweig
2025-02-13 16:12 ` [PATCH v2 1/2] apple-nvme: Support coprocessors left idle Alyssa Rosenzweig
2025-02-13 16:12 ` [PATCH v2 2/2] apple-nvme: Release power domains when probe fails Alyssa Rosenzweig
@ 2025-02-13 16:14 ` Sven Peter
2025-02-18 15:42 ` Keith Busch
3 siblings, 0 replies; 5+ messages in thread
From: Sven Peter @ 2025-02-13 16:14 UTC (permalink / raw)
To: Alyssa Rosenzweig, Hector Martin, Keith Busch, Jens Axboe,
hch@lst.de, sagi@grimberg.me, Philipp Zabel
Cc: asahi, linux-arm-kernel, linux-nvme, linux-kernel, Neal Gompa
On Thu, Feb 13, 2025, at 17:12, Alyssa Rosenzweig wrote:
> This small series fixes two unrelated issues with the Apple NVMe driver.
>
> * fix NVMe on certain combinations of firmware + machine
> * fix a power domain leak
>
> Although these are strict bug fixes, given the early stage of mainlining
> for these SoCs, none of this needs to be backported.
>
> Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> ---
For both patches:
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Best,
Sven
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] apple-nvme: bug fixes
2025-02-13 16:12 [PATCH v2 0/2] apple-nvme: bug fixes Alyssa Rosenzweig
` (2 preceding siblings ...)
2025-02-13 16:14 ` [PATCH v2 0/2] apple-nvme: bug fixes Sven Peter
@ 2025-02-18 15:42 ` Keith Busch
3 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2025-02-18 15:42 UTC (permalink / raw)
To: Alyssa Rosenzweig
Cc: Hector Martin, Sven Peter, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, Philipp Zabel, asahi, linux-arm-kernel, linux-nvme,
linux-kernel, Neal Gompa
On Thu, Feb 13, 2025 at 11:12:57AM -0500, Alyssa Rosenzweig wrote:
> This small series fixes two unrelated issues with the Apple NVMe driver.
>
> * fix NVMe on certain combinations of firmware + machine
> * fix a power domain leak
Thanks, applied to nvme-6.14.
^ permalink raw reply [flat|nested] 5+ messages in thread