From patchwork Mon Apr 26 03:48:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 12223805 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 D80A4C433ED for ; Mon, 26 Apr 2021 03:49:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B54A460FEE for ; Mon, 26 Apr 2021 03:49:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbhDZDts (ORCPT ); Sun, 25 Apr 2021 23:49:48 -0400 Received: from labrats.qualcomm.com ([199.106.110.90]:13025 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbhDZDts (ORCPT ); Sun, 25 Apr 2021 23:49:48 -0400 IronPort-SDR: 3e3uV39P0B8HuKxQCSPezPO2rW/XS/iSizVim7xlB2F+4LbJVvunMpB6XkM5lgBk4Vg7UVxDMY 5NnoBC62JvjCHCsmjNzpva4v8dNUcEypQDc4wl+TfyBY/lh3F8atEpdxg5+UMsiZKbmy6Qz9A0 q2eKLXWCrk+avwhTxW87ccviV3TJqHAfVN6kZ9FqAkyw1b4+xtJykb+nXtpe3ICBUk+LLwt5P0 p2UecaTkGYjuztZxWUNVGrbLTW1O/Im0ONhwNExL79+b//OlNwdY0p7v2UrOKt1daENXLzwP4d NLc= X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="29759516" Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by labrats.qualcomm.com with ESMTP; 25 Apr 2021 20:49:06 -0700 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg01-sd.qualcomm.com with ESMTP; 25 Apr 2021 20:49:05 -0700 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id E64492121E; Sun, 25 Apr 2021 20:49:05 -0700 (PDT) From: Can Guo To: asutoshd@codeaurora.org, ziqichen@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Jaegeuk Kim , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/3] scsi: ufs: Do not put UFS power into LPM if link is broken Date: Sun, 25 Apr 2021 20:48:38 -0700 Message-Id: <1619408921-30426-2-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619408921-30426-1-git-send-email-cang@codeaurora.org> References: <1619408921-30426-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org During resume, if link is broken due to AH8 failure, make sure ufshcd_resume() do not put UFS power back into LPM. Fixes: 4db7a23605973 ("scsi: ufs: Fix concurrency of error handler and other error recovery paths") Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6da1da8..28501bb 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8660,7 +8660,7 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba *hba) } else if (!ufshcd_is_ufs_dev_active(hba)) { ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, false); vcc_off = true; - if (!ufshcd_is_link_active(hba)) { + if (ufshcd_is_link_hibern8(hba) || ufshcd_is_link_off(hba)) { ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq); ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq2); } @@ -8682,7 +8682,7 @@ static int ufshcd_vreg_set_hpm(struct ufs_hba *hba) !hba->dev_info.is_lu_power_on_wp) { ret = ufshcd_setup_vreg(hba, true); } else if (!ufshcd_is_ufs_dev_active(hba)) { - if (!ret && !ufshcd_is_link_active(hba)) { + if (!ufshcd_is_link_active(hba)) { ret = ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq); if (ret) goto vcc_disable; From patchwork Mon Apr 26 03:48:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 12223807 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 D6C4DC43460 for ; Mon, 26 Apr 2021 03:49:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8EF461152 for ; Mon, 26 Apr 2021 03:49:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231794AbhDZDtv (ORCPT ); Sun, 25 Apr 2021 23:49:51 -0400 Received: from labrats.qualcomm.com ([199.106.110.90]:5837 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231768AbhDZDtv (ORCPT ); Sun, 25 Apr 2021 23:49:51 -0400 IronPort-SDR: 8HxJbIwCH5tOuGTh8QNxHXSsu6ez7b5G4tX3+h5H3KJhaYYiIwFWgigf/vUWy8D04vXTZKmwOk zCzXP8zGSkDd/NgBOtRO364rckk2ngqvQ1SCPZeJVHO2k25F6nmtqzBRMNGOFXKWBh7IDyOd8J NaZIzfLP74otDpll3Z7OS4KxYeuop9ozX4SxsxUNhneMHZ+Eo0S2sJr0E55wVUQo6t4vCCiNKb 9HO0Te9MYTpmzaZo72bGkFN/6CmQo9ZxZJsyUKKRNp4/kcs/s7zmynKkzZlJtPEb9WTrshYnSN Luw= X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="47849242" Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by labrats.qualcomm.com with ESMTP; 25 Apr 2021 20:49:10 -0700 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg02-sd.qualcomm.com with ESMTP; 25 Apr 2021 20:49:09 -0700 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id 933442121E; Sun, 25 Apr 2021 20:49:09 -0700 (PDT) From: Can Guo To: asutoshd@codeaurora.org, ziqichen@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Jaegeuk Kim , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend Date: Sun, 25 Apr 2021 20:48:39 -0700 Message-Id: <1619408921-30426-3-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619408921-30426-1-git-send-email-cang@codeaurora.org> References: <1619408921-30426-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org During ufs system suspend, leaving rpm_dev_flush_recheck_work running or pending is risky, because concurrency may happen btw system suspend/resume and runtime resume routine. Fix it by cancelling rpm_dev_flush_recheck_work synchronously during system suspend. Fixes: 51dd905bd2f61 ("scsi: ufs: Fix WriteBooster flush during runtime suspend") Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 28501bb..a2f9c8e 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9044,6 +9044,8 @@ int ufshcd_system_suspend(struct ufs_hba *hba) if (!hba->is_powered) return 0; + cancel_delayed_work_sync(&hba->rpm_dev_flush_recheck_work); + if ((ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) == hba->curr_dev_pwr_mode) && (ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl) == From patchwork Mon Apr 26 03:48:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 12223809 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 8665FC433ED for ; Mon, 26 Apr 2021 03:49:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 690E561163 for ; Mon, 26 Apr 2021 03:49:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbhDZDt4 (ORCPT ); Sun, 25 Apr 2021 23:49:56 -0400 Received: from labrats.qualcomm.com ([199.106.110.90]:3644 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231805AbhDZDty (ORCPT ); Sun, 25 Apr 2021 23:49:54 -0400 IronPort-SDR: Mz0+g2QATWyjFtvhcy8T3ikHAIlypk/4nWXTqPRGKEUjAehJFv8TP0tBqGjQ5u+FhitYFXnPqb omq43wHwiZQ3SrFOUF9mXMHSB78jWteRMOC4p/9u+1gENnPugcB8p9F6mGdeWdqNNWoY7/xwDA L4tgEre/CXBy1eWPJnlSg4DAcsI6hWB40zj/WR41PrE9P2eSp4sVPUxId+vLDXEGrr5YMv26ez UaZOB6QOwgeicW8Zf7W+5RJuNRfN6PLZVWYItaxq0s4WawENLoS7i6PJ4/t21QgD6Lf/nwg9Ov YKc= X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="29759517" Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by labrats.qualcomm.com with ESMTP; 25 Apr 2021 20:49:13 -0700 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg03-sd.qualcomm.com with ESMTP; 25 Apr 2021 20:49:13 -0700 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id 3E4642121E; Sun, 25 Apr 2021 20:49:13 -0700 (PDT) From: Can Guo To: asutoshd@codeaurora.org, ziqichen@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Jaegeuk Kim , Gilad Broner , Subhash Jadavani , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/3] scsi: ufs: Narrow down fast pass in system suspend path Date: Sun, 25 Apr 2021 20:48:40 -0700 Message-Id: <1619408921-30426-4-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619408921-30426-1-git-send-email-cang@codeaurora.org> References: <1619408921-30426-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If spm_lvl is set to 0 or 1, when system suspend kicks start and hba is runtime active, system suspend may just bail without doing anything (the fast pass), leaving other contexts still running, e.g., clock gating and clock scaling. When system resume kicks start, concurrency can happen btw ufshcd_resume() and these contexts, leading to various stability issues. Fix it by adding a check against hba's runtime status and allowing fast pass only if hba is runtime suspended, otherwise let system suspend go ahead call ufshcd_suspend(). This can guarantee that these contexts are stopped by either runtime suspend or system suspend. Fixes: 0b257734344aa ("scsi: ufs: optimize system suspend handling") Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a2f9c8e..c480f88 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9050,6 +9050,7 @@ int ufshcd_system_suspend(struct ufs_hba *hba) hba->curr_dev_pwr_mode) && (ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl) == hba->uic_link_state) && + pm_runtime_suspended(hba->dev) && !hba->dev_info.b_rpm_dev_flush_capable) goto out;