From patchwork Mon Jul 26 13:22:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shiva.linuxworks@gmail.com X-Patchwork-Id: 12399523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69D0BC4338F for ; Mon, 26 Jul 2021 13:23:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53F6260F4F for ; Mon, 26 Jul 2021 13:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233563AbhGZMm5 (ORCPT ); Mon, 26 Jul 2021 08:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233593AbhGZMmz (ORCPT ); Mon, 26 Jul 2021 08:42:55 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E927C061757; Mon, 26 Jul 2021 06:23:24 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id h14so3117757wrx.10; Mon, 26 Jul 2021 06:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9K67sWK8iCvxn8wA3EP4cDIU+lrlaZyWsxH1S+wkYOk=; b=SuZZBJipNbPUZaCppP1IpW/GUu7EREB17r3O2x4RRKUBddZb/DPJWFM2D2yPk6HaS8 dwpZBgsZEe+JxhCYo0i9ZfC1JzogLyjFf2r4NXY+QnIUKgYevYwGkxWgCaQjr+MKV73/ HCfSbSFgw6B9XATA8nj/GEkkYaK19r5+Uwvtl3xKUaHHhuZhwypzUw7lraPUiE/WvEcj haRm31qV4CQ+iVkt5bLMNpFyFx/roj6x9k4OBrqTvojR1mgBmCZ+vMIJEDf3U5jNfGXR vUjkTpfTW97crzw4/5wizMHsUxf99qtVe7fvTJlc6h3SXsZr4YSU5rllmc6CTuO2crzs PxAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9K67sWK8iCvxn8wA3EP4cDIU+lrlaZyWsxH1S+wkYOk=; b=VDCot7owBQAX7/ebBzxZgnNbo7swYMxhA41JXuTByunpE7itxI2bChyuUIfg2xsgxS T7hZrNT9fvWY6rzuSnNiKQ9tJAs5Ha9k8be940PmsqCfGHW0GsqkppkSNqk4lV8IrXrh osi3f2RTFd1Gph13OOx21638zJJpjoFzSSCuPxzvc4le6Mma0U7HSNFHfk0Y3fhV4qWM ehVpafpIbGZNE8B/CZKvJSgbKd8jhQ4Xn1HxHwHsVOnwW3AsMrjOg14dQOeJCYEqT8T1 60XZh7o6d3u/ZPhIlVDOnnZ9dQT5nxFa0RnNuzJrmQ5mkfOeXXLP7qcaWngUGr9v+oGK NBLA== X-Gm-Message-State: AOAM5304mR7Fx+Za/VuJmkjDijtd57O5mKWMxnMC/3RzPogXdTwhJlD3 tgNPm6D3uep2cxUS/TEiYuA= X-Google-Smtp-Source: ABdhPJwxNCP148AFjwK/y0hOukG4j4nAjYbmtdI5DOJLx1OPPGpFdCbRWSx3RwnrbXoJ7AnnSojlhA== X-Received: by 2002:a5d:6708:: with SMTP id o8mr9758731wru.304.1627305803088; Mon, 26 Jul 2021 06:23:23 -0700 (PDT) Received: from microndev.lxd (ip5f5ac0ff.dynamic.kabel-deutschland.de. [95.90.192.255]) by smtp.gmail.com with ESMTPSA id w15sm8580wmi.3.2021.07.26.06.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 06:23:22 -0700 (PDT) From: shiva.linuxworks@gmail.com X-Google-Original-From: sshivamurthy@micron.com To: rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, linux-pm@vger.kernel.org, kbusch@kernel.org, axboe@fb.com, hch@lst.de, sagi@grimberg.me, linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Shivamurthy Shastri , Keith Busch Subject: [PATCH v2 1/2] PM: enable support for imminent power loss Date: Mon, 26 Jul 2021 13:22:22 +0000 Message-Id: <20210726132223.1661-2-sshivamurthy@micron.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210726132223.1661-1-sshivamurthy@micron.com> References: <20210726132223.1661-1-sshivamurthy@micron.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Shivamurthy Shastri If the shutdown is pwerformed when the platform is running on the limited backup power supply, some of the devices might not have enough power to perform a clean shutdown. It is necessary to inform the driver about the limited backup power supply, to allow the driver to decide to perform the minimal required operation for a fast and clean shutdown. Signed-off-by: Keith Busch Signed-off-by: Shivamurthy Shastri --- include/linux/suspend.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 8af13ba60c7e..1898792c10d3 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -210,9 +210,10 @@ extern int suspend_valid_only_mem(suspend_state_t state); extern unsigned int pm_suspend_global_flags; -#define PM_SUSPEND_FLAG_FW_SUSPEND BIT(0) -#define PM_SUSPEND_FLAG_FW_RESUME BIT(1) -#define PM_SUSPEND_FLAG_NO_PLATFORM BIT(2) +#define PM_SUSPEND_FLAG_FW_SUSPEND BIT(0) +#define PM_SUSPEND_FLAG_FW_RESUME BIT(1) +#define PM_SUSPEND_FLAG_NO_PLATFORM BIT(2) +#define PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT BIT(3) static inline void pm_suspend_clear_flags(void) { @@ -234,6 +235,11 @@ static inline void pm_set_suspend_no_platform(void) pm_suspend_global_flags |= PM_SUSPEND_FLAG_NO_PLATFORM; } +static inline void pm_set_power_loss_imminent(void) +{ + pm_suspend_global_flags |= PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT; +} + /** * pm_suspend_via_firmware - Check if platform firmware will suspend the system. * @@ -291,6 +297,22 @@ static inline bool pm_suspend_no_platform(void) return !!(pm_suspend_global_flags & PM_SUSPEND_FLAG_NO_PLATFORM); } +/** + * pm_power_loss_imminent - Check if platform is running on limited backup power + * source + * + * To be called during system-wide power management transitions to sleep states. + * + * Return 'true' if power loss may be imminent due to platform running on + * limited backup supply. If set during a shutdown, drivers should use any + * available shortcuts to prepare their device for abrupt power loss. + */ +static inline bool pm_power_loss_imminent(void) +{ + return !!(pm_suspend_global_flags & + PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT); +} + /* Suspend-to-idle state machnine. */ enum s2idle_states { S2IDLE_STATE_NONE, /* Not suspended/suspending. */ From patchwork Mon Jul 26 13:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shiva.linuxworks@gmail.com X-Patchwork-Id: 12399525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DBB4C4338F for ; Mon, 26 Jul 2021 13:23:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 051DC6056C for ; Mon, 26 Jul 2021 13:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233593AbhGZMnD (ORCPT ); Mon, 26 Jul 2021 08:43:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233688AbhGZMnA (ORCPT ); Mon, 26 Jul 2021 08:43:00 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36BE9C061757; Mon, 26 Jul 2021 06:23:28 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id z8-20020a1c4c080000b029022d4c6cfc37so8163226wmf.5; Mon, 26 Jul 2021 06:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vUFZDTLZHnU1oCPFZuxkDptiIQaZJMAsbw41GQLH7/Q=; b=IVoYLwOw5JN1oCFRdvUg0eLbzGchcEB8nZCO7lBZhKB/8147IS7l3Yk1H31VVU3z2A Zzi36BJr0BwAccqS8ToN9U0HVBotwuEE+JTetVSy8mpum60gIVHO2OBJFS4REbtEP5Oi vBzB3MZLaBo0vQc1+kq0IDflWaKKybxZ9qT7Moyo+upVzVdzOvn14PwjsxfsePynInWd +DTZmblbrQJDUK1SVfCaP4ayBNbBH4gU+KS0arMq8rxDVwZzebCB8org+MoHCC5Sc/zw HVp7edtE6LYcA9tWPN26xxlWcF/pUlLJ+f9aGbf1ttBJbJbBBJ7MEIB4xL4/pb/rcYDH JywA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vUFZDTLZHnU1oCPFZuxkDptiIQaZJMAsbw41GQLH7/Q=; b=ALx1EJKMMOUdaj6xyl11IK14SVBWY6voOH1TOrye7PmcJS52nOjahKlNiTw4PvlzdB qgYYY4dbEUhIfmCvUnl1re966NyDTAVbuBAyBk6tY7k8pxukS13ryTJN2nwVuWxBebHG 9G3fWvnSj09xei5+RhSyZI81xQiCHwp5/54TmWCuckP9cL/CDzQna6/OHFNgUi4/Scc2 6fAJsDmrSSXLdMEP2ah8Y6D3tsokr7Ziu4MxVKEf/g3H/IRJhAdUcYmNIGnc7wI1oSEM HBPhMK3SgLH686HrcDw98hK3PXnIvio/yMv6hB1ZPAnL6CeBdQpZOOuJkCxRpsMQGVAl W7oA== X-Gm-Message-State: AOAM530kVfoS6tmXEg2V1cwpLTiIAlSR2HOzB1JjGf1ciDMG1Ir3MzLQ 36l35D1esHc/CEiH5IDSku8= X-Google-Smtp-Source: ABdhPJzcV8t+TGXZXIiVaksrhgLSCW6B1efSSPRuIX4BgWqT3wYH/A5WVMjNZNNYTKPji0dxHBj9ag== X-Received: by 2002:a05:600c:4f48:: with SMTP id m8mr10032791wmq.22.1627305806793; Mon, 26 Jul 2021 06:23:26 -0700 (PDT) Received: from microndev.lxd (ip5f5ac0ff.dynamic.kabel-deutschland.de. [95.90.192.255]) by smtp.gmail.com with ESMTPSA id w15sm8580wmi.3.2021.07.26.06.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 06:23:26 -0700 (PDT) From: shiva.linuxworks@gmail.com X-Google-Original-From: sshivamurthy@micron.com To: rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, linux-pm@vger.kernel.org, kbusch@kernel.org, axboe@fb.com, hch@lst.de, sagi@grimberg.me, linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Shivamurthy Shastri Subject: [PATCH v2 2/2] nvme: Add abrupt shutdown support Date: Mon, 26 Jul 2021 13:22:23 +0000 Message-Id: <20210726132223.1661-3-sshivamurthy@micron.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210726132223.1661-1-sshivamurthy@micron.com> References: <20210726132223.1661-1-sshivamurthy@micron.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Shivamurthy Shastri Enabling the abrupt shutdown support. In this shutdown type, the host does not need to send Delete I/O Submission Queue and Delete I/O Completion Queue commands to the device. Signed-off-by: Shivamurthy Shastri Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/nvme/host/core.c | 7 ++++++- drivers/nvme/host/pci.c | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 11779be42186..760ffb071c1b 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "nvme.h" @@ -2159,7 +2160,11 @@ int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl) int ret; ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; - ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; + + if (pm_power_loss_imminent()) + ctrl->ctrl_config |= NVME_CC_SHN_ABRUPT; + else + ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); if (ret) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 320051f5a3dd..07be319f63d9 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -2524,13 +2525,14 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown) * Give the controller a chance to complete all entered requests if * doing a safe shutdown. */ - if (!dead && shutdown && freeze) + if (!dead && shutdown && !pm_power_loss_imminent() && freeze) nvme_wait_freeze_timeout(&dev->ctrl, NVME_IO_TIMEOUT); nvme_stop_queues(&dev->ctrl); if (!dead && dev->ctrl.queue_count > 0) { - nvme_disable_io_queues(dev); + if (!pm_power_loss_imminent()) + nvme_disable_io_queues(dev); nvme_disable_admin_queue(dev, shutdown); } nvme_suspend_io_queues(dev);