From patchwork Tue Sep 15 20:45:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 257628 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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 34D86C433E2 for ; Tue, 15 Sep 2020 20:52:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4F8420771 for ; Tue, 15 Sep 2020 20:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600203163; bh=biBRsrW4Fs+Y3FfatFGMejxQwq4kpwq0ahfzBoNIGAM=; h=From:To:Cc:Subject:Date:List-ID:From; b=quglMd56DmBq8rNLTnzrcSHwuVUwXak8om6QiTnxcP3F6rIwDXGCpH7rHfhOJg1uD Ubi5XmUDb7qVcaiRnFmelTGEsxjgVNnDI2+3uOy1KtjomSehNfmrWJdcNbtI/xQY4O 7dqxMip0Fn7FI1EkyquMr6KXhEHZOZbn6QqgYL2o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728047AbgIOUqq (ORCPT ); Tue, 15 Sep 2020 16:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:42646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbgIOUqg (ORCPT ); Tue, 15 Sep 2020 16:46:36 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A4F120809; Tue, 15 Sep 2020 20:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202796; bh=biBRsrW4Fs+Y3FfatFGMejxQwq4kpwq0ahfzBoNIGAM=; h=From:To:Cc:Subject:Date:From; b=TcTPD5CjNScvnACas/DuxQfwIjEVgKejo6dLSYhm84AuwpnT25q9TzTumsFBiJbCq 0ltWf08wjOzM7tYCAoEJ6QMl1yuBlSB9OZ/ca/xZNMSyB0B3cLS6X5Pil/J2KyoWpB /+pt0YNu3CMzHZHBvVJXIxUlgKqGHqzwXplGgKCU= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 1/6] scsi: ufs: atomic update for clkgating_enable Date: Tue, 15 Sep 2020 13:45:27 -0700 Message-Id: <20200915204532.1672300-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Jaegeuk Kim When giving a stress test which enables/disables clkgating, we hit device timeout sometimes. This patch avoids subtle racy condition to address it. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1d157ff58d817..d929c3d1e58cc 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1791,19 +1791,19 @@ static ssize_t ufshcd_clkgate_enable_store(struct device *dev, return -EINVAL; value = !!value; + + spin_lock_irqsave(hba->host->host_lock, flags); if (value == hba->clk_gating.is_enabled) goto out; - if (value) { - ufshcd_release(hba); - } else { - spin_lock_irqsave(hba->host->host_lock, flags); + if (value) + hba->clk_gating.active_reqs--; + else hba->clk_gating.active_reqs++; - spin_unlock_irqrestore(hba->host->host_lock, flags); - } hba->clk_gating.is_enabled = value; out: + spin_unlock_irqrestore(hba->host->host_lock, flags); return count; } From patchwork Tue Sep 15 20:45:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 257627 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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 2D6BDC43461 for ; Tue, 15 Sep 2020 20:54:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E15052080C for ; Tue, 15 Sep 2020 20:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600203277; bh=d1coarY+kYt3CCUrBHh62z5mGDhyA+XvBeFtxID2pGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Zsry8UApFLwmPTTUJB5z8EIU8jjB5aJhEE8mLEqUHD0t+jZQnT9Os/gSJ5gtfwsBk PwyU9WcFV84mWpd62zs+np5mHeMQZuLyLNOO2Tm9/gyt7I6b4SQuZObn+n1cH78cCH VfYoYxHREAVISWocg8qI4ZA8sBTeQRtUWX+IW95E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728061AbgIOUyQ (ORCPT ); Tue, 15 Sep 2020 16:54:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727861AbgIOUqh (ORCPT ); Tue, 15 Sep 2020 16:46:37 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C53DD20936; Tue, 15 Sep 2020 20:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202796; bh=d1coarY+kYt3CCUrBHh62z5mGDhyA+XvBeFtxID2pGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xr8SluegS6UFjDnRpW/eqYJKEKHp5AEwAjkKRdYO08kzM4/klo8niX2DcQe4Zss2c /pDVZNXyll/QpGFYJTmky/I8GRlEj9rr9tP/57W6H9SfvBbFCxfWh8x5XGQLItcKvy s2Cr/rv/S23NegqGZTb2Ysq/QYz3mnFuwwlNTkEg= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 2/6] scsi: ufs: clear UAC for FFU Date: Tue, 15 Sep 2020 13:45:28 -0700 Message-Id: <20200915204532.1672300-2-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915204532.1672300-1-jaegeuk@kernel.org> References: <20200915204532.1672300-1-jaegeuk@kernel.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Jaegeuk Kim In order to conduct FFU or RPMB operations, UFS needs to clear UAC. This patch clears it explicitly, so that we could get no failure given early execution. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index d929c3d1e58cc..5deba03a61f75 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7385,6 +7385,45 @@ static int ufshcd_add_lus(struct ufs_hba *hba) return ret; } +static int +ufshcd_send_request_sense(struct ufs_hba *hba, struct scsi_device *sdp); + +static int ufshcd_clear_uac(struct ufs_hba *hba) +{ + struct scsi_device *sdp; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(hba->host->host_lock, flags); + sdp = hba->sdev_ufs_device; + if (sdp) { + ret = scsi_device_get(sdp); + if (!ret && !scsi_device_online(sdp)) { + ret = -ENODEV; + scsi_device_put(sdp); + } + } else { + ret = -ENODEV; + } + spin_unlock_irqrestore(hba->host->host_lock, flags); + if (ret) + goto out_err; + + if (hba->wlun_dev_clr_ua) { + ret = ufshcd_send_request_sense(hba, sdp); + if (ret) + goto out; + /* Unit attention condition is cleared now */ + hba->wlun_dev_clr_ua = false; + } +out: + scsi_device_put(sdp); +out_err: + if (ret) + dev_err(hba->dev, "%s: Failed UAC clear ret = %d\n", __func__, ret); + return ret; +} + /** * ufshcd_probe_hba - probe hba to detect device and initialize * @hba: per-adapter instance @@ -7500,6 +7539,8 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) pm_runtime_put_sync(hba->dev); ufshcd_exit_clk_scaling(hba); ufshcd_hba_exit(hba); + } else { + ufshcd_clear_uac(hba); } } From patchwork Tue Sep 15 20:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 296749 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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 C0815C43461 for ; Tue, 15 Sep 2020 20:53:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 701CE20809 for ; Tue, 15 Sep 2020 20:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600203227; bh=NOLqD59ZXyc/29xCULK3dghDfnH/zVdAa3vvLnNbexQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lpLStLEJVSG9snWKlYH5ytkne4L47jgHDohMwoumE7pnOC9rJ9WNTdGujgZ9/c5VK FkaierPfS8zU3K6hzcmvW5CDKe0p/aBww1AaOEEgiM1DLace8YSL3LRFAjjgvbGzOU qhmwvVBk5tkB9Rx/bJVY2aojnGu4GI4JfHmjnPfg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727923AbgIOUxc (ORCPT ); Tue, 15 Sep 2020 16:53:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:42694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728078AbgIOUqh (ORCPT ); Tue, 15 Sep 2020 16:46:37 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5F87620771; Tue, 15 Sep 2020 20:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202797; bh=NOLqD59ZXyc/29xCULK3dghDfnH/zVdAa3vvLnNbexQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BvJpNvDXs/tHKPSODHFGSmNMOIiMaLoVGbQdvVWU1ukJHP8Y9LXn2QWOnyanJyg4o x6i5/OeM1HiUgTUXIORPJb78N41aG+tvpX7TCMCskcQL7ZRL9yhLZeD/kR+6IqhmYu fGdgDNxhba/zQtaaWzREvL+ndA2H2+xvPrvIyUZg= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 3/6] scsi: ufs: use WQ_HIGHPRI for gating work Date: Tue, 15 Sep 2020 13:45:29 -0700 Message-Id: <20200915204532.1672300-3-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915204532.1672300-1-jaegeuk@kernel.org> References: <20200915204532.1672300-1-jaegeuk@kernel.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Jaegeuk Kim Must have WQ_MEM_RECLAIM ``WQ_MEM_RECLAIM`` All wq which might be used in the memory reclaim paths **MUST** have this flag set. The wq is guaranteed to have at least one execution context regardless of memory pressure. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 5deba03a61f75..848e33ec40639 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1849,7 +1849,7 @@ static void ufshcd_init_clk_gating(struct ufs_hba *hba) snprintf(wq_name, ARRAY_SIZE(wq_name), "ufs_clk_gating_%d", hba->host->host_no); hba->clk_gating.clk_gating_workq = alloc_ordered_workqueue(wq_name, - WQ_MEM_RECLAIM); + WQ_MEM_RECLAIM | WQ_HIGHPRI); hba->clk_gating.is_enabled = true; From patchwork Tue Sep 15 20:45:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 296751 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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 EEA64C433E2 for ; Tue, 15 Sep 2020 20:47:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A7E620936 for ; Tue, 15 Sep 2020 20:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202842; bh=6CFCy86M8iz95yHuyD/L5TCOMJziCyBzC/IGpcbjHtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nkzp3H1T4XMuR9PITPfFO2HZFC+0R+SS8MWguEEd4uU1ltcLfMBG3IGq5UC5ByqBE /kRKz3x836FRXyLrOOwBhRLvC3b7HDGsgr/yhUvtTqqVMpWSdnTMyQ7YnJ6pF8FEfZ 9oipnTi0ejZrzganmcNzEh1+ZvGfgmk3WXhbObPk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728087AbgIOUrQ (ORCPT ); Tue, 15 Sep 2020 16:47:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728051AbgIOUqq (ORCPT ); Tue, 15 Sep 2020 16:46:46 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F005D212CC; Tue, 15 Sep 2020 20:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202798; bh=6CFCy86M8iz95yHuyD/L5TCOMJziCyBzC/IGpcbjHtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0GKifIzuYRs4t0HlIw0zbNCbSPAjZYiQ7a9d2vmCClRZNhwYxxNsU1HFef/XwWOCt ABqxRgLbCrz4zdV30pebCDiEf+Q0R+Ir+rT/ew5Rk5dTmvtALfbh4m+5tHW1lzAtbf 53kjfucWbMbCamWVUQ1xSog9J5Wow2CcBWb5iPUk= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 4/6] scsi: ufs: fix LINERESET on hibern8 Date: Tue, 15 Sep 2020 13:45:30 -0700 Message-Id: <20200915204532.1672300-4-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915204532.1672300-1-jaegeuk@kernel.org> References: <20200915204532.1672300-1-jaegeuk@kernel.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Jaegeuk Kim When testing infinite test to read sysfs entries of UFS, I got a UFS timeout with the following kernel message. query: dev_cmd_send: seq_no=78082 tag=31, idn=2 query: ufshcd_wait_for_dev_cmd: dev_cmd request timedout, tag 31 query: __ufshcd_query_descriptor: opcode 0x01 for idn 2 failed, index 0, err = -11 -- hibern8: dme: dme_send: cmd_id=0x17 idn=0 query: ufshcd_query_descriptor: failed with error -11, retries 3 -- hibern8: ufshcd_update_uic_error: LINERESET during hibern8 enter -- hibern8: __ufshcd_uic_hibern8_enter: hibern8 enter failed. ret = -110 The problem is casued by hibern8 command issued by ufshcd_suspend(), which is not aware of query command. If autohibern8 is enabled, we actually don't need to issue hibern8 command by suspend. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 20 ++++++++++++++++++-- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 848e33ec40639..bdc82cc3824aa 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3079,8 +3079,12 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, int retries; for (retries = QUERY_REQ_RETRIES; retries > 0; retries--) { - err = __ufshcd_query_descriptor(hba, opcode, idn, index, + err = -EAGAIN; + down_read(&hba->query_lock); + if (!ufshcd_is_link_hibern8(hba)) + err = __ufshcd_query_descriptor(hba, opcode, idn, index, selector, desc_buf, buf_len); + up_read(&hba->query_lock); if (!err || err == -EINVAL) break; } @@ -8263,8 +8267,8 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) enum ufs_pm_level pm_lvl; enum ufs_dev_pwr_mode req_dev_pwr_mode; enum uic_link_state req_link_state; + bool need_upwrite = false; - hba->pm_op_in_progress = 1; if (!ufshcd_is_shutdown_pm(pm_op)) { pm_lvl = ufshcd_is_runtime_pm(pm_op) ? hba->rpm_lvl : hba->spm_lvl; @@ -8275,6 +8279,15 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) req_link_state = UIC_LINK_OFF_STATE; } + if (ufshcd_is_runtime_pm(pm_op) && + req_link_state == UIC_LINK_HIBERN8_STATE && + hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) { + need_upwrite = true; + if (!down_write_trylock(&hba->query_lock)) + return -EBUSY; + } + hba->pm_op_in_progress = 1; + /* * If we can't transition into any of the low power modes * just gate the clocks. @@ -8403,6 +8416,8 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) } hba->pm_op_in_progress = 0; + if (need_upwrite) + up_write(&hba->query_lock); if (ret) ufshcd_update_reg_hist(&hba->ufs_stats.suspend_err, (u32)ret); @@ -8894,6 +8909,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) mutex_init(&hba->dev_cmd.lock); init_rwsem(&hba->clk_scaling_lock); + init_rwsem(&hba->query_lock); ufshcd_init_clk_gating(hba); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 363589c0bd370..6f8e05eaf9661 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -754,6 +754,7 @@ struct ufs_hba { bool is_urgent_bkops_lvl_checked; struct rw_semaphore clk_scaling_lock; + struct rw_semaphore query_lock; unsigned char desc_size[QUERY_DESC_IDN_MAX]; atomic_t scsi_block_reqs_cnt; From patchwork Tue Sep 15 20:45:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 296750 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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 BBD21C43461 for ; Tue, 15 Sep 2020 20:50:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E38320771 for ; Tue, 15 Sep 2020 20:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600203009; bh=iQVkWhUeydRTqFowSvAGvDoWIWi1b0xAmpNyoT5VH2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=n+1/7XYBg6aO6xxuaiS0ukHPThOugppNgCnKdoieAHGxj9WOEoQjYIT//oHoaLRTe M8A5kNxw1+mQFDj09ET7gTgx3ZpxzorUpy3hYDr/YxbUfpIgdh2w49/HXBRvamVREH UroiffacoMrZ3XpA1aAwxdTR3YY66geftiHC8Cow= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbgIOUuE (ORCPT ); Tue, 15 Sep 2020 16:50:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:42760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728082AbgIOUqq (ORCPT ); Tue, 15 Sep 2020 16:46:46 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 79C7620B1F; Tue, 15 Sep 2020 20:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202798; bh=iQVkWhUeydRTqFowSvAGvDoWIWi1b0xAmpNyoT5VH2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REEoR9Z9zfNJqcyZLGcjIj5UQXlNdPoM9F/kW6GAD+oEQ1jMIDRo1otPQ6qgc/hM+ E1/vT0nDts4E+YDxhY7ldIomLycRSrPUiOyJtluCaRMOi+vDRJzk93Su4CJd/lSQlW Qxr2GI+BythJRXMeWjrRqcJ4/7GKCHpJsLpdU/54= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 5/6] scsi: ufs: show ufs part info in error case Date: Tue, 15 Sep 2020 13:45:31 -0700 Message-Id: <20200915204532.1672300-5-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915204532.1672300-1-jaegeuk@kernel.org> References: <20200915204532.1672300-1-jaegeuk@kernel.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Jaegeuk Kim This patch shows ufs part info in kernel messages for debugging purpose. It's useful when we only have the last kernel message. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index bdc82cc3824aa..b81c116b976ff 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -500,6 +500,14 @@ static void ufshcd_print_tmrs(struct ufs_hba *hba, unsigned long bitmap) static void ufshcd_print_host_state(struct ufs_hba *hba) { dev_err(hba->dev, "UFS Host state=%d\n", hba->ufshcd_state); + if (hba->sdev_ufs_device) { + dev_err(hba->dev, " vendor = %.8s\n", + hba->sdev_ufs_device->vendor); + dev_err(hba->dev, " model = %.16s\n", + hba->sdev_ufs_device->model); + dev_err(hba->dev, " rev = %.4s\n", + hba->sdev_ufs_device->rev); + } dev_err(hba->dev, "outstanding reqs=0x%lx tasks=0x%lx\n", hba->outstanding_reqs, hba->outstanding_tasks); dev_err(hba->dev, "saved_err=0x%x, saved_uic_err=0x%x\n", From patchwork Tue Sep 15 20:45:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 257629 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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, 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 7C99FC433E2 for ; Tue, 15 Sep 2020 20:47:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32D3E20771 for ; Tue, 15 Sep 2020 20:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202875; bh=py0H0Nt71dgZGsc2v1e3bd1BFG4ko+PaI/MDzo15VX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hcmOyDtQrXsZphyP/QSuBWIMQggU/2Ud0Da1JB306HSIxPVu/nG2x9ea46FgQcNaB K2iYZX7WUJ2/re8+6hTR08S52ymNI/ZGxOr75I4wJ05tlZt+pPjF6DCI9AaG+EJ1y7 LHKJX26uVMzV7FDhjeBAv53C2MzxLs0+BkJK0FG8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728070AbgIOUrM (ORCPT ); Tue, 15 Sep 2020 16:47:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:42786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728083AbgIOUqr (ORCPT ); Tue, 15 Sep 2020 16:46:47 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1568B21655; Tue, 15 Sep 2020 20:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202799; bh=py0H0Nt71dgZGsc2v1e3bd1BFG4ko+PaI/MDzo15VX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1czTBxu7slicrVo5h3XqzbXp8mbMy9GTa1qHc9jxpAIJIPZ9ckStu39gMC+XCgi9o DELYRBCUSy72rVgzXkSrC4+BAPiimCK4S6Qb5ffIrGqh3n+1MDADJ2lEkAcRuoEasy z+RarUd0ilF6LghxOI7gFv3DyIhLbwlVNKVqlkMs= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 6/6] scsi: add more contexts in the ufs tracepoints Date: Tue, 15 Sep 2020 13:45:32 -0700 Message-Id: <20200915204532.1672300-6-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915204532.1672300-1-jaegeuk@kernel.org> References: <20200915204532.1672300-1-jaegeuk@kernel.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Jaegeuk Kim This adds user-friendly tracepoints with group id. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 6 ++++-- include/trace/events/ufs.h | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index b81c116b976ff..d70ca62c4c6d0 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -336,7 +336,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag, const char *str) { sector_t lba = -1; - u8 opcode = 0; + u8 opcode = 0, group_id = 0; u32 intr, doorbell; struct ufshcd_lrb *lrbp = &hba->lrb[tag]; struct scsi_cmnd *cmd = lrbp->cmd; @@ -362,13 +362,15 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, lba = cmd->request->bio->bi_iter.bi_sector; transfer_len = be32_to_cpu( lrbp->ucd_req_ptr->sc.exp_data_transfer_len); + if (opcode == WRITE_10) + group_id = lrbp->cmd->cmnd[6]; } } intr = ufshcd_readl(hba, REG_INTERRUPT_STATUS); doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); trace_ufshcd_command(dev_name(hba->dev), str, tag, - doorbell, transfer_len, intr, lba, opcode); + doorbell, transfer_len, intr, lba, opcode, group_id); } static void ufshcd_print_clk_freqs(struct ufs_hba *hba) diff --git a/include/trace/events/ufs.h b/include/trace/events/ufs.h index 84841b3a7ffd5..50654f3526392 100644 --- a/include/trace/events/ufs.h +++ b/include/trace/events/ufs.h @@ -11,6 +11,15 @@ #include +#define str_opcode(opcode) \ + __print_symbolic(opcode, \ + { WRITE_16, "WRITE_16" }, \ + { WRITE_10, "WRITE_10" }, \ + { READ_16, "READ_16" }, \ + { READ_10, "READ_10" }, \ + { SYNCHRONIZE_CACHE, "SYNC" }, \ + { UNMAP, "UNMAP" }) + #define UFS_LINK_STATES \ EM(UIC_LINK_OFF_STATE) \ EM(UIC_LINK_ACTIVE_STATE) \ @@ -215,9 +224,10 @@ DEFINE_EVENT(ufshcd_template, ufshcd_init, TRACE_EVENT(ufshcd_command, TP_PROTO(const char *dev_name, const char *str, unsigned int tag, u32 doorbell, int transfer_len, u32 intr, u64 lba, - u8 opcode), + u8 opcode, u8 group_id), - TP_ARGS(dev_name, str, tag, doorbell, transfer_len, intr, lba, opcode), + TP_ARGS(dev_name, str, tag, doorbell, transfer_len, + intr, lba, opcode, group_id), TP_STRUCT__entry( __string(dev_name, dev_name) @@ -228,6 +238,7 @@ TRACE_EVENT(ufshcd_command, __field(u32, intr) __field(u64, lba) __field(u8, opcode) + __field(u8, group_id) ), TP_fast_assign( @@ -239,13 +250,15 @@ TRACE_EVENT(ufshcd_command, __entry->intr = intr; __entry->lba = lba; __entry->opcode = opcode; + __entry->group_id = group_id; ), TP_printk( - "%s: %s: tag: %u, DB: 0x%x, size: %d, IS: %u, LBA: %llu, opcode: 0x%x", + "%s: %s: tag: %u, DB: 0x%x, size: %d, IS: %u, LBA: %llu, opcode: 0x%x (%s), group_id: 0x%x", __get_str(str), __get_str(dev_name), __entry->tag, __entry->doorbell, __entry->transfer_len, - __entry->intr, __entry->lba, (u32)__entry->opcode + __entry->intr, __entry->lba, (u32)__entry->opcode, + str_opcode(__entry->opcode), (u32)__entry->group_id ) );