From patchwork Thu Feb 13 16:12:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alyssa Rosenzweig X-Patchwork-Id: 13973693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B575C021A0 for ; Thu, 13 Feb 2025 16:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=r0Nf5RrE3KZyG8T6/Sgi1E+IBrK5T7wX35BvpGHC0+U=; b=3La9pnNZVCPnu5OgzImUBlNQ9r KAH86OIV5YhdQv4MBcD/Jt/T2oPVM605RQHPEZd9GOPaRSbR0fkPis8yxkOHIlKC1YMIe7xKCa7Ny RhJQpAYC2Nb4ppYvvsPqZK8dFR4UTjaTfj6qKV/mtkOh6ClJr5jUFbXxnf9CzDiMVkFzMdVxX2BxU yImfTMnIxUMNkTtLnXBKQNxpwhJEmOIcOj9Kx1nKwUs7mqisV5DPfeTym3AMY0pPZofhkBCRwpdm9 N0cZnKQdKNdTIRAp/A3hPz9eXCh5FYkZ/fCHgyZJ5kvyzBDUUv9MbflZvb+hhKcvcDCM+esOTUnl1 MUr+Ezfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ticH0-0000000Bocs-0uIV; Thu, 13 Feb 2025 16:41:10 +0000 Received: from out-177.mta1.migadu.com ([2001:41d0:203:375::b1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tibq7-0000000BhyT-3YgE; Thu, 13 Feb 2025 16:13:25 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosenzweig.io; s=key1; t=1739463201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r0Nf5RrE3KZyG8T6/Sgi1E+IBrK5T7wX35BvpGHC0+U=; b=rW6iqdT2IIKFIc4ByRE/jDZZXcqFpt+1lHLcNfSkXp99I/OXEDKlcMLXSEM97W1QqmveXY i7DatTU/YoFDZrA09D9uAmUe31w08KGi7PMDVZeNKV4r1xn9ymLXNfy7cnkCZd37Ojodt1 btwzBCh9O/KFyjzfEM1B74wGDDjaafHg+kINcDQX0MHm7ECoA7KZTYmDI4LHj7nv+Y5wZC SZGCblERZNulG7uGHU1mHnzFiJM8ABu+QqmMbn1RHTLTDZE2UF+IrxZnffpfcd8qYkumux W1q9pp9D9pKWoUI2/MhJ2g/dIJ4WOo8CuFeeRMT7M0ssk8CBDALVNpQRWZkfDQ== From: Alyssa Rosenzweig Date: Thu, 13 Feb 2025 11:12:58 -0500 Subject: [PATCH v2 1/2] apple-nvme: Support coprocessors left idle MIME-Version: 1.0 Message-Id: <20250213-nvme-fixes-v2-1-a20032d13e38@rosenzweig.io> References: <20250213-nvme-fixes-v2-0-a20032d13e38@rosenzweig.io> In-Reply-To: <20250213-nvme-fixes-v2-0-a20032d13e38@rosenzweig.io> To: Hector Martin , Sven Peter , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Philipp Zabel Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Alyssa Rosenzweig , Neal Gompa X-Developer-Signature: v=1; a=openpgp-sha256; l=3956; i=alyssa@rosenzweig.io; h=from:subject:message-id; bh=wgj0LnXTlJwA+cyZHdZxivR1UD5uIhGd2SbgazZk4FE=; b=owEBbQKS/ZANAwAIAf7+UFoK9VgNAcsmYgBnrhoc9Ofuju1L0nnrZHtcWJgmTPea5jx4psjLw gjqdLMtVE2JAjMEAAEIAB0WIQRDXuCbsK8A0B2q9jj+/lBaCvVYDQUCZ64aHAAKCRD+/lBaCvVY DRtND/49sh9V1/soTyP5SuFCNJIgFlGeGYy85Ck1KOk0EoE48GPzpnvho6FertRM2gaHItRzems YDHTP4zK4NcW96rugh09hmsIBntluG/DfyHx+asnib+6JQmt8Ahdwycj7NNak7OODb0NH+GoQPx 5yUBRf1fE5oJY7uwwcRaZSc2Sv5Yqxebwxj9MfDmKaVx0MU5vM48uQkQ85rFtmQNXyHDQPsbRL0 MSwCW+o4oUz3dooqIHkC+gigEo0LUj1tnHVqrgWVNboA0e36o2WrGIszUvMNr+h5eXQpALv2TXa 4xB2VN8r1Ry/veiea+JzcYglzVqPferF9lsIyxjTIjj336RNvXLlzit8A1UoQumaiOWFEOSlFks KF0XBTG68hVsERjJBhGOh2huOgqjIbCaNChyHfkdlXxLfQvSAUGRefWKRKswQgSptxJZtJ8/mI8 TTjhpHSD6d1aXmLe3Vfwa5r2Pz4LxvWUIOfReD8KBUh05dLYc5LmJ8PUdt3bk2Ithg6kRU2M7sJ HWAhX5Rinc71c25GrPinTk80YixcBIwWAKMTSHBjOnZ0vDYnjNOFEE3iCXhEJdIGd4iTVocwhu0 hKd9z1kPai//VGEhtzi/C0Tt1/H40jAPjcimBfYYDVQZiq/0yysBn6oCfl0Ffjqk5LzvbOWXu6+ zLmg+ePrBqgnvQw== X-Developer-Key: i=alyssa@rosenzweig.io; a=openpgp; fpr=435EE09BB0AF00D01DAAF638FEFE505A0AF5580D X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250213_081324_180885_2D923305 X-CRM114-Status: GOOD ( 15.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Hector Martin 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 Reviewed-by: Neal Gompa Signed-off-by: Alyssa Rosenzweig --- 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; } From patchwork Thu Feb 13 16:12:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alyssa Rosenzweig X-Patchwork-Id: 13973694 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6AE1C021A6 for ; Thu, 13 Feb 2025 16:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D9CoS5efnNhs2HIJLsLL5qOupZo4J7abKpW0xblWXuM=; b=fZq1HRS+zoJ2eHqRi2jCi6nPgN BvNF6BSlMfafW5W7f+vqwgbp1nFLV6kkSM3SuzYcw++HF+KYcNn57EOxJb1WTEHGrSonJqHqVGuwg FAbKembQf9Q90zzxj5zjWmpQdgQtBiLWGc60vfVO6VDq5yX5pvc0AIrUGqEaEQhL5FTfMUWkhFm+7 KqxpHhOHu85SP5nrdmuKv8MZqEssQuUohUHAZtR2wTLnUxEancNX/wH930Q9VJ49Wmp53la9wfcjE 5gBgs/eL3S8bru4+iFAEXrGwm7t43AArieaztKBp8Ceq+juJPZ3hLZEsvaj8mAKvQ8222Gqf0ZnS9 IOZ3WSfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ticH2-0000000Bofr-2a6A; Thu, 13 Feb 2025 16:41:12 +0000 Received: from out-183.mta1.migadu.com ([2001:41d0:203:375::b7]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tibq9-0000000Bhzs-3TGq for linux-arm-kernel@lists.infradead.org; Thu, 13 Feb 2025 16:13:27 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosenzweig.io; s=key1; t=1739463203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D9CoS5efnNhs2HIJLsLL5qOupZo4J7abKpW0xblWXuM=; b=gGpvePThmOrXYKJAbCRDx3qCBrj4gqVY8GJCPsuAzYZRuO2FxMLi8uf6PfuYjZh/p0hB8w d/2tNLl1p75oWWUfTWvEY9xVGo6xUlz0zxXhPwLlWqAb8bOG1atqBBVgnlSDol1ZPCdZPy 5u8LoQbevgUXTUydAUn+4y4kXMmhbb9j5zCVgh7DQ4I8Jt9YKxIOQW+orgpC8wHsr/T8YC IDWeGUz2MfJ5PXvP22N4Rpys1uJh0r75fOi2aHGeDsSM/t+2pweXeunjpgHpNUpQm3iQM9 vXpQvB+0ZCVa46JfErURVZcu1cnuuS6cIwkhRhx6AvkhiFFU7wLPZ/XNv/0eCA== From: Alyssa Rosenzweig Date: Thu, 13 Feb 2025 11:12:59 -0500 Subject: [PATCH v2 2/2] apple-nvme: Release power domains when probe fails MIME-Version: 1.0 Message-Id: <20250213-nvme-fixes-v2-2-a20032d13e38@rosenzweig.io> References: <20250213-nvme-fixes-v2-0-a20032d13e38@rosenzweig.io> In-Reply-To: <20250213-nvme-fixes-v2-0-a20032d13e38@rosenzweig.io> To: Hector Martin , Sven Peter , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Philipp Zabel Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Alyssa Rosenzweig , Neal Gompa X-Developer-Signature: v=1; a=openpgp-sha256; l=896; i=alyssa@rosenzweig.io; h=from:subject:message-id; bh=Cw3j5ZwF0ZpXtZjtAYoiFOLvFEyNrVEWrLNZJYk08lA=; b=owEBbQKS/ZANAwAIAf7+UFoK9VgNAcsmYgBnrhocGrC88sbMtudltmIRFFMhJDEYdLnbqgA1c B2attrG8DyJAjMEAAEIAB0WIQRDXuCbsK8A0B2q9jj+/lBaCvVYDQUCZ64aHAAKCRD+/lBaCvVY DcFHD/9HNGYW9xjWXZ9DMBfT4a7mVIYsL65qQMmrdbU/r6jbvPTceMAEFdvhzS4ctH/rfYJ5D1C v4roY6Q8CMsuo440S9NtnOQzj9z5RI8gy36qRvhwvKSlWedO/WoVmpibf8YFMPRSvHou3UEK+E3 VRIQdYkwXXeYNeIfVegD4RcTzZ9D9CEUAF/32UShMSG1zLI433NGESgptfoNZL9Jn/lmgnmiKqZ +VMkL4AXhhzmjtdFp8HBTWOFAOSnR7ntWVgO4fv4jwVTRr4ffrM2O7rJos0773rG1lUgnv0llSz 8yj3Rv5Ja5HAYpoJrtLKr9jnnb0vp4wH0jGytf57fhPiXnxpl+DzzFishxMPjr4CNmZ8XE/1mtm PzJm2AXI6HZyXRNwSGfnmN3ekgHkA5k4LWDIxo619yXqj7CbnzHMz8r5ranJeN6gwjNpYRjaYQM cxs8ii91su9Fpoj998qGLUmx0coUMuWkxzPpHyjRQd+u1cbIZ3M5so9on6Ta5HjiG5fXYLlF1pV ucy1ZNszllRF9RX0gWGsWlDs+f2ctZ6rd0G5Sv0ufOhriJcAe3hV2bVJWWPFuz96SbCGsr5JbMd UjemxVBWfWIy+oDu5qO9b6ocCf2dkNHWUmklDgFj5uQ9qorqH4mdpXQ+bYYNr5V47VqJgYAxy0s DScqoDigzuEODDg== X-Developer-Key: i=alyssa@rosenzweig.io; a=openpgp; fpr=435EE09BB0AF00D01DAAF638FEFE505A0AF5580D X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250213_081326_001486_07647DBB X-CRM114-Status: UNSURE ( 8.89 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Hector Martin Signed-off-by: Hector Martin Reviewed-by: Neal Gompa Signed-off-by: Alyssa Rosenzweig --- 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; }