From patchwork Wed Jan 11 04:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 41739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3124893wrt; Tue, 10 Jan 2023 20:39:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXsFCx78gQcMV8b3ru0MuQA09EgdGof8AqOrz1slE4f56ImZLgO9pmgkWm1gFuwkOYcdnhfn X-Received: by 2002:a17:906:b7ce:b0:84d:411d:64a4 with SMTP id fy14-20020a170906b7ce00b0084d411d64a4mr9327269ejb.38.1673411965995; Tue, 10 Jan 2023 20:39:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673411965; cv=none; d=google.com; s=arc-20160816; b=xQLjFd8R1gyU7XHutzjSD4O7dhdFbNeQBUIYRrCL+ikYjm2rxoFoigr6NR2iYRN2Rg XNDzfGqTiB53oPI6qwJ8nCjynefjF8P1ihO+imPOrFOXhw82qNbEwSK915JYzLjE+EUD 83kQZ/4WszbUETZ524N5QdApNXo2xDblws4SS9vZuHpu6K3aLlKDyPr7RImg0iGazGFG 6+N6jLvVTHkw1lo258PFGaa/R9Il1crtU8Mhr90yIXw3bjjjm4R0gjrjayTGn2cLh3oq UDiRGPMKAobNSceTW9CEXTOrzbkuwP+gLiApaIgWnc50yl4Ur8dBy7V2VDLiTDxe6Cy8 7HRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DrGnilphed++uUZkhm3rd0G2c4sVV31GlOelQ1DnBls=; b=QgNG+Y/EcYi9enYlMz89CF8wEPamCN7nG31pxSw51AOe6Si/7xlF/bHUQlaiaTvVGV cA1V6KHUI3r6A/XbrJ7Mg6OLAdZjsV/VMKArM1uAoYTya/tzFo23YUfcFUBtzRXvH4VR IqqR4g7PlCLK0rXmIFLTxJ0ChTd6duLGM2oqyQZzJ8KVltENe0QmrWsNDs6NMdcSYeYT 5Qcb5IoA9gyaVh2zZk3ZhLmzs5RyjI8QN5H6LsmDBSHRgrc0ian+H00Hci99fTHpN9Pv +TU1j6L44RAtAqJBfWK6Zcql0ZzgFZ7FyGh0LH5rq7/sAOvpSchU2cXrz3G5DGKWPkT9 k2IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=QY5tqf60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xe6-20020a170907318600b00780488c11bbsi13998879ejb.388.2023.01.10.20.39.03; Tue, 10 Jan 2023 20:39:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=QY5tqf60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230015AbjAKEis (ORCPT + 99 others); Tue, 10 Jan 2023 23:38:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbjAKEi3 (ORCPT ); Tue, 10 Jan 2023 23:38:29 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83F78643B for ; Tue, 10 Jan 2023 20:38:28 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sendonly@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id A9EC6422CC; Wed, 11 Jan 2023 04:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1673411907; bh=Q3CUKLEywf+vR4+nGROpaJQqVS2PQmhEl5Il4+LejRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QY5tqf60SZHxFaNdFYSzNvp4IdFLjD4OU8BawnpwU74nj7igN5fSFDF1+fcojF39A sOVlpJT9RhW6yM4BHm02nodGm1dFnVtmoqCnFikp1F9d/8cT3SuUqKczh83l09wMoo Zz+ydkC/lTC43zhbi3SjksPhqde146WnH3Ge1L59zI7Cg8TeHT4GQTiqLfm70xYxh7 LVdvZPRhSF4FctliGqXRgKXSjYPgtSRKMkB+ouZ2NiQ/4azKsNZx88fxEu31eKkYae js5/uMv+MwTL1AyrKdtdx76z3wHbPDiWP65rW7ZcORH+fhFmpmvHqNkiBHju5CgmAS FS6P8dLLiUcuA== From: Hector Martin To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Eric Curtin , Janne Grunau , Sven Peter , Alyssa Rosenzweig , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hector Martin Subject: [PATCH 1/2] nvme-apple: Do not try to shut down the controller twice Date: Wed, 11 Jan 2023 13:36:13 +0900 Message-Id: <20230111043614.27087-2-marcan@marcan.st> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230111043614.27087-1-marcan@marcan.st> References: <20230111043614.27087-1-marcan@marcan.st> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754699626000484204?= X-GMAIL-MSGID: =?utf-8?q?1754699626000484204?= The blamed commit stopped explicitly disabling the controller when we do a controlled shutdown, but apple_nvme_reset_work was only checking for the disable bit before deciding to issue another disable. Check for the shutdown state too, to avoid breakage. This issue does not affect nvme-pci, since it only issues controller shutdowns when the system is actually shutting down anyway. Fixes: c76b8308e4c9 ("nvme-apple: fix controller shutdown in apple_nvme_disable") Signed-off-by: Hector Martin --- drivers/nvme/host/apple.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index e13a992b6096..1961376447dc 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -1023,7 +1023,8 @@ static void apple_nvme_reset_work(struct work_struct *work) goto out; } - if (anv->ctrl.ctrl_config & NVME_CC_ENABLE) + if (anv->ctrl.ctrl_config & NVME_CC_ENABLE && + !(anv->ctrl.ctrl_config & NVME_CC_SHN_MASK)) apple_nvme_disable(anv, false); /* RTKit must be shut down cleanly for the (soft)-reset to work */ From patchwork Wed Jan 11 04:36:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 41740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3131603wrt; Tue, 10 Jan 2023 21:04:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXvvOY5QmtKFzwFA4dVxuYcmasMsLnN9XGJdOTe6edsQQ0UeWsfhzAs2+H2oiHFJu5dlgnSJ X-Received: by 2002:a05:6a20:6682:b0:af:73c4:1c1f with SMTP id o2-20020a056a20668200b000af73c41c1fmr71802529pzh.42.1673413471126; Tue, 10 Jan 2023 21:04:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673413471; cv=none; d=google.com; s=arc-20160816; b=aLgwmQTKeWpIhuWB5emwm+1DZEshsMu0JWL4g1W3+G7a0cLPlMI5SkhMrmjrBhOcoZ oK20WmpYuK2eEN7pWQ+z59XvsZvkfISx0c1Akh4EHZvDku8eOvD9orS8LlTKNXFGHYmh PburoGT5fxp2hPcT1YY7QQYcwcgjccvDVUBs19XsFRAt62g8hywQimFLTnnoSbD3liav JqjI4oLh/9bDgNM2/rgHyTtcBeE20HJeujdgPA30zAqr8PgbCl+VYWzZqgja+q0o+igQ Qu1EkduBRuxYmpLoMKNdyyHvm9Fh0kkvXRK1m4PjxoQ2AxdPiCWrARaV9nZg5iRV6uuw hjww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F1OuSTZ/ff90luHGSTPVfp/ZA1ziWXV0nowGCAVC+oI=; b=scfFC50zFiWjdbj9mIUGguNHUwKSsfSQAuGjvzoFLw4/q3iWCgG7ZSyLqjLQ5wx0Mq MkzCk+FfEa7GQA3c5Jj6qUaemCCPT6IbBYZOr8W63UimNQtAD3+H/V5di0I70OLXlWic PqteqvXFfzI9m9pg41dkc5HTlYD2JrQXgZTffT+xRSZb70vhTdhv43Mt1/72GedjhimH PS/P6p3ErjV+Rfmg2MgRG61/KZoGxxfdDBZvcKrB2WhGxXEI1Pi0XruA3Dj4GbDu49Sc UyFd/nRX1ZTJmzmFttztTx/0vUzjL9CF2f1PKElNRBjVIBpbmt8C+SvdxOUzYsYUAo8v Qwiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=gtOdbdn7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a63e143000000b0049a8afc9b21si14201583pgk.730.2023.01.10.21.04.15; Tue, 10 Jan 2023 21:04:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=gtOdbdn7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbjAKEjD (ORCPT + 99 others); Tue, 10 Jan 2023 23:39:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231579AbjAKEie (ORCPT ); Tue, 10 Jan 2023 23:38:34 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93C807640 for ; Tue, 10 Jan 2023 20:38:32 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sendonly@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id 9EA3E4245E; Wed, 11 Jan 2023 04:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1673411911; bh=3mwbRHlRhjEn6d7ialc4jgg5I5MLJj7InHbf8EL6vA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gtOdbdn7hRKNeJrKJRvmsoB4h2WV3TdpgzrVGVcpQ+O/RUW4pAwhiS3d5c65/H4lv pJhXSXKrNTs7s8odh9yDMffyHuPvieDbG3RC7gWLalFhXhltp/ytsHX1dcIN74JUES tPz+pwugBCo+WOiapqL9nubi4zzwg1YjNgeqC0Uy7U4oVr9O0cH9ApVemrOaEE+SCW +UjamWWPMvp/gXVXdzpdunJkBp7+G2p/42WU82fSJUFtZej9YELwvVRIXWvMx8JlS/ 2YzLZGzn2w7Py8Wv3Bsjf4QEBty+FrMl0s1LX8po9TVKPCwyiAPUG2eAjpeeXyJnrB 1e+lPNgb1sjBA== From: Hector Martin To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Eric Curtin , Janne Grunau , Sven Peter , Alyssa Rosenzweig , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hector Martin Subject: [PATCH 2/2] nvme: Handle shut down controllers during initialization Date: Wed, 11 Jan 2023 13:36:14 +0900 Message-Id: <20230111043614.27087-3-marcan@marcan.st> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230111043614.27087-1-marcan@marcan.st> References: <20230111043614.27087-1-marcan@marcan.st> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754701203504262991?= X-GMAIL-MSGID: =?utf-8?q?1754701203504262991?= According to the spec, controllers need an explicit reset to become active again after a controller shutdown. Check for this state in nvme_enable_ctrl and issue an explicit disable if required, which will trigger the required reset. Fixes: c76b8308e4c9 ("nvme-apple: fix controller shutdown in apple_nvme_disable") Signed-off-by: Hector Martin --- drivers/nvme/host/core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 7be562a4e1aa..84e5db192ff9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2410,6 +2410,19 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl) if (ret) return ret; + /* + * If the controller is enabled but shut down, we need to disable it to + * reset it and have it come up. If the controller has completed a + * shutdown and is disabled, then we need to clear the shutdown request + * and enable it in the same write to CC. + * See NVMe Base Spec 2.0c Figure 47. + */ + if (ctrl->ctrl_config & NVME_CC_SHN_MASK && ctrl->ctrl_config & NVME_CC_ENABLE) { + ret = nvme_disable_ctrl(ctrl, false); + if (ret) + return ret; + } + ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; ctrl->ctrl_config |= NVME_CC_ENABLE; ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); if (ret)