From patchwork Wed Nov 22 17:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 13465295 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="G4xwtv3a"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="s43TIAx2" Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50ED8191; Wed, 22 Nov 2023 09:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700673927; cv=none; d=strato.com; s=strato-dkim-0002; b=BYBlEf7wyIk7+oXl2lHUQyvHBUSD8xBeio7lEreICVuJ9HSFeoKD5kEfiXEbV4yhu3 sM31fj0W4dZA2Em4qnHj56d1/E7OAB/wF1qM8pfGdPrAadb3oGRStRkUhOkqQCNgWaQG HVHnLGPn/LFOrcVaRndZyfI48SMpdl0ycv0hqKL48Z6dJstIjwkcNUwUdKly2sgT2fSJ fneiCT6STYiU6oPtUeGKjW9cNM0iYD0nM4eSRjOgyseplvL6h3zXLBxAj9nXWpn2b5D9 UHyEoLi8sIOwLMkZAp4TL7nQExHrOVS/+vq1gC6se/TIk71y2Tf9V4FXIj5tniKCb8YQ QXnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1700673927; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=j/Fpf9xbkhtgTtWXZAuLn992yVFCJnNNn3gf8aRTnEo=; b=VayH621UvEwywwpJEZ2R3w4pfFpFRU941OXaBuMFrXTQbBXW8Rvfdy7M4Z0Wlj3+Bm emGOUvumkfb2k36w0IUxidtf/JztTXABn7nKijBsLIexvAiAmodjOyCjrrdrZAAz+0LL EeI/nRCxF4wj7PVpa9GiFALe5xjq5Ge2bRArJb9JDnx+K/di9oQnVtvn8gF2AUYpG+5+ pPO6qx6gLAbZhgJNrVAAwq7Ylbl40OmQiL+rTNvd35abGQ1AXPC4bDLYNlfavzs31Fh+ nMaMX4THitAzSNVdEtBx9wM/JDLnK920mDH7FQRgysO8yeLGWCmIk+PYWCrWnN5npXcN JuvQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1700673927; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=j/Fpf9xbkhtgTtWXZAuLn992yVFCJnNNn3gf8aRTnEo=; b=G4xwtv3aTHQ4LZS7w/eJT223GybOAvBTGpQwl4DvtwzUNl28s+znOwe3LbSeypJhYN kdAiemHBkSW6EbsTWSBihxkpb4WrytVfVB4UcshqLhifM0hipSyogDPTdwNLludOtuU1 iObyu4Vr0j7TtshpZ8V3rpYvj2RgYbEcVz1P3YZYHgyd28Zzl9E4RHGoxGoE8SCJQngp Ei83iacHBGnog8M35BRNgL2eHCedfJ6lTv0zFrgI5X1JuujWs0qWTHQdjEXtzuaISqPR mTs7jia6aMO4gyGL39xQ0ZHXOESJmNvhWYjg+c9P3GjnjUg6lHKYZfRQJCsuPQgsxPO1 YH7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1700673927; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=j/Fpf9xbkhtgTtWXZAuLn992yVFCJnNNn3gf8aRTnEo=; b=s43TIAx2HDCkootfShOyYkyD9e0Z5VLM5OiaMJ5ZKJ4hUFuKJDM1BOdMAgemgOJXTE dvBgfwZOvzkE/dbKpYDQ== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD2QzemV2tdlNlNRZBXiUw=" Received: from Munilab01-lab.micron.com by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id z758a5zAMHPRtqK (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 22 Nov 2023 18:25:27 +0100 (CET) From: Bean Huo To: avri.altman@wdc.com, bvanassche@acm.org, alim.akhtar@samsung.com, jejb@linux.ibm.com, martin.petersen@oracle.com, mani@kernel.org, quic_cang@quicinc.com, quic_asutoshd@quicinc.com, beanhuo@micron.com, thomas@t-8ch.de Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, mikebi@micron.com, lporzio@micron.com Subject: [PATCH v2 1/3] scsi: ufs: core: Add ufshcd_is_ufs_dev_busy() Date: Wed, 22 Nov 2023 18:25:10 +0100 Message-Id: <20231122172512.103748-2-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122172512.103748-1-beanhuo@iokpp.de> References: <20231122172512.103748-1-beanhuo@iokpp.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bean Huo Add helper inline for retrieving whether UFS device is busy or not. Signed-off-by: Bean Huo --- drivers/ufs/core/ufshcd.c | 6 +----- include/ufs/ufshcd.h | 8 +++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 68d7da02944f..5d009d2c34f0 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1916,11 +1916,7 @@ static void ufshcd_gate_work(struct work_struct *work) hba->clk_gating.state); goto rel_lock; } - - if (hba->clk_gating.active_reqs - || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL - || hba->outstanding_reqs || hba->outstanding_tasks - || hba->active_uic_cmd || hba->uic_async_done) + if (ufshcd_is_ufs_dev_busy(hba)) goto rel_lock; spin_unlock_irqrestore(hba->host->host_lock, flags); diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 7f0b2c5599cd..b0cd6c6591ef 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -126,7 +126,6 @@ enum uic_link_state { ((h)->curr_dev_pwr_mode == UFS_POWERDOWN_PWR_MODE) #define ufshcd_is_ufs_dev_deepsleep(h) \ ((h)->curr_dev_pwr_mode == UFS_DEEPSLEEP_PWR_MODE) - /* * UFS Power management levels. * Each level is in increasing order of power savings, except DeepSleep @@ -1408,6 +1407,13 @@ static inline int ufshcd_vops_phy_initialization(struct ufs_hba *hba) return 0; } +static inline bool ufshcd_is_ufs_dev_busy(struct ufs_hba *hba) +{ + return (hba->clk_gating.active_reqs || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL || + hba->outstanding_reqs || hba->outstanding_tasks || hba->active_uic_cmd || + hba->uic_async_done); +} + extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[]; int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len, From patchwork Wed Nov 22 17:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 13465296 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="euVW+5cm"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="xzOm0l8U" Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EACB1B1; Wed, 22 Nov 2023 09:25:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700673928; cv=none; d=strato.com; s=strato-dkim-0002; b=O0UQ2RhyE52bR7uRZxHPc7wQmO81xGJWhA5hSqh+JtjsaQwExJGs3OkaASt84Nf20p eCGUP9TP0n2ew/yBE193tGLKqfjQRBpimNXu8XcrVXNly08fmyoeccmELRPQ8dMUSUMh LW6AUPwsBeu2IPmQFbGZgtYBj4A+weXbYCEAbxomGIPQe3ZQXOGCNPm+hQvYciVyviSY LjIlHXSIKRhx2X59PN4MmfU1zX6qZ6N2BaPLw/GYTesESx97JmGIjiAn+vJZCRCSFkxw UWbBHudMtroPoRPcVweG4kWxgC1rt/5OX+zt7f2whhlvpY3qhbqmnHg/bn65/nnyMgmo 5+KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1700673928; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=TaZk/EmlJ6NGsJH1VYRpJgtVrMW9Q9O+FuvbwbxE6sQ=; b=nphAfTZ7CTnhESsDremq3qaXcCKiUsAyTbJb49t8rDXMVtWD7sTWAICzo8HSB7SZb2 Ny8M8El3S0gLmTfpUDjXB9KD69IRd8FU5S3fJOrPNc8t/4VoSy/MS+RgvKOO8XG3Y7HB FSFDTTbXj3heuTfuiw4w+XHBbWPLKpxsYPhbfDjCuvxGYfDDnxeX8NHNQF9IxW/XlVie 7au4gmv1MIZKrIf/Z+QntDttKf3cPNvgdgJE0qbgaUfy2WLwlxyBfY/Rh0luRRRxE8ZR 8J21UmoQagnUoYaZ9xXD4gQOa3BgRQw8LtzK6l6/bU5QVxyICqUDRHbdl6QRz5QAydpZ Fqrw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1700673928; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=TaZk/EmlJ6NGsJH1VYRpJgtVrMW9Q9O+FuvbwbxE6sQ=; b=euVW+5cmbP8BAkBJ6VtWGNnN+/+GWMqDP9SbpFKV2DPOduvjoitm8puy3VneoMCswJ Go5j45qKbidwoleixGynEe1HB3Z4u48z9uzpLs8YstKQybko9a72Fhq+XHxQbi1vUbVg tXH1JlMUTiasXvUSSttgB7R9y5KUzj4c8BxYpAhnh/Fvvl4PaobLagbo4cZAye5omr8k 19MO9WbJob/OKNYLwLlZGCBJJZjfKBNASkHpJ0xpFP7ARfxyvgjpxzmxRGI/jkbOeVZj OwB9s7VujZGAdDOIiY9TBilmk+HD2th542TlpA3IU80gxGHTKmA1RmFUksdnw2Mum9xr v8SQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1700673928; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=TaZk/EmlJ6NGsJH1VYRpJgtVrMW9Q9O+FuvbwbxE6sQ=; b=xzOm0l8U6KOu6k6s/Oe7TovXfhv9HnHzVj5J6IArNpJDWlzXeh9c3C/qHDUz+ag6sG yb/x092DTcZ7wD3ucDAQ== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD2QzemV2tdlNlNRZBXiUw=" Received: from Munilab01-lab.micron.com by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id z758a5zAMHPRtqL (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 22 Nov 2023 18:25:27 +0100 (CET) From: Bean Huo To: avri.altman@wdc.com, bvanassche@acm.org, alim.akhtar@samsung.com, jejb@linux.ibm.com, martin.petersen@oracle.com, mani@kernel.org, quic_cang@quicinc.com, quic_asutoshd@quicinc.com, beanhuo@micron.com, thomas@t-8ch.de Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, mikebi@micron.com, lporzio@micron.com Subject: [PATCH v2 2/3] scsi: ufs: core: Add UFS RTC support Date: Wed, 22 Nov 2023 18:25:11 +0100 Message-Id: <20231122172512.103748-3-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122172512.103748-1-beanhuo@iokpp.de> References: <20231122172512.103748-1-beanhuo@iokpp.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bean Huo Add Real Time Clock (RTC) support for UFS device. This enhancement is crucial for the internal maintenance operations of the UFS device. The patch enables the device to handle both absolute and relative time information. Furthermore, it includes periodic task to update the RTC in accordance with the UFS specification, ensuring the accuracy of RTC information for the device's internal processes. RTC and qTimestamp serve distinct purposes. The RTC provides a coarse level of granularity with, at best, approximate single-second resolution. This makes the RTC well-suited for the device to determine the approximate age of programmed blocks after being updated by the host. On the other hand, qTimestamp offers nanosecond granularity and is specifically designed for synchronizing Device Error Log entries with corresponding host-side logs. Given that the RTC has been a standard feature since UFS Spec 2.0, and qTimestamp was introduced in UFS Spec 4.0, the majority of UFS devices currently on the market rely on RTC. Therefore, it is advisable to continue supporting RTC in the Linux kernel. This ensures compatibility with the prevailing UFS device implementations and facilitates seamless integration with existing hardware. By maintaining support for RTC, we ensure broad compatibility and avoid potential issues arising from deviations in device specifications across different UFS versions. Signed-off-by: Bean Huo Signed-off-by: Mike Bi Signed-off-by: Luca Porzio --- drivers/ufs/core/ufshcd.c | 77 +++++++++++++++++++++++++++++++++++++++ include/ufs/ufs.h | 14 +++++++ include/ufs/ufshcd.h | 4 ++ 3 files changed, 95 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 5d009d2c34f0..4d349eff24c4 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -99,6 +99,9 @@ /* Polling time to wait for fDeviceInit */ #define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */ +/* Default RTC update every 10 seconds */ +#define UFS_RTC_UPDATE_INTERVAL_MS (10 * MSEC_PER_SEC) + /* UFSHC 4.0 compliant HC support this mode. */ static bool use_mcq_mode = true; @@ -677,6 +680,8 @@ static void ufshcd_device_reset(struct ufs_hba *hba) hba->dev_info.wb_enabled = false; hba->dev_info.wb_buf_flush_enabled = false; } + if (hba->dev_info.rtc_type == UFS_RTC_RELATIVE) + hba->dev_info.rtc_time_baseline = 0; } if (err != -EOPNOTSUPP) ufshcd_update_evt_hist(hba, UFS_EVT_DEV_RESET, err); @@ -8181,6 +8186,70 @@ static void ufs_fixup_device_setup(struct ufs_hba *hba) ufshcd_vops_fixup_dev_quirks(hba); } +static int ufshcd_update_rtc(struct ufs_hba *hba) +{ + int err; + u32 val; + struct timespec64 ts64; + + ktime_get_real_ts64(&ts64); + val = ts64.tv_sec - hba->dev_info.rtc_time_baseline; + + ufshcd_rpm_get_sync(hba); + err = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, QUERY_ATTR_IDN_SECONDS_PASSED, + 0, 0, &val); + ufshcd_rpm_put_sync(hba); + + if (err) + dev_err(hba->dev, "%s: Failed to update rtc %d\n", __func__, err); + else if (hba->dev_info.rtc_type == UFS_RTC_RELATIVE) + hba->dev_info.rtc_time_baseline = ts64.tv_sec; + + return err; +} + +static void ufshcd_rtc_work(struct work_struct *work) +{ + struct ufs_hba *hba; + bool is_busy; + + hba = container_of(to_delayed_work(work), struct ufs_hba, ufs_rtc_update_work); + + is_busy = ufshcd_is_ufs_dev_busy(hba); + /* + * RTC updates should not interfere with normal IO requests; we should only update the RTC + * when there are no ongoing requests. + */ + if (!is_busy) + ufshcd_update_rtc(hba); + + if (ufshcd_is_ufs_dev_active(hba)) + schedule_delayed_work(&hba->ufs_rtc_update_work, + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); +} + +static void ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf) +{ + struct ufs_dev_info *dev_info = &hba->dev_info; + u16 periodic_rtc_update = get_unaligned_be16(&desc_buf[DEVICE_DESC_PARAM_FRQ_RTC]); + + if (periodic_rtc_update & UFS_RTC_TIME_BASELINE) { + dev_info->rtc_type = UFS_RTC_ABSOLUTE; + /* + * The concept of measuring time in Linux as the number of seconds elapsed since + * 00:00:00 UTC on January 1, 1970, and UFS ABS RTC is elapsed from January 1st + * 2010 00:00, here we need to adjust ABS baseline. + */ + dev_info->rtc_time_baseline = mktime64(2010, 1, 1, 0, 0, 0) - + mktime64(1970, 1, 1, 0, 0, 0); + } else { + dev_info->rtc_type = UFS_RTC_RELATIVE; + dev_info->rtc_time_baseline = 0; + } + + INIT_DELAYED_WORK(&hba->ufs_rtc_update_work, ufshcd_rtc_work); +} + static int ufs_get_device_desc(struct ufs_hba *hba) { int err; @@ -8233,6 +8302,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) ufshcd_temp_notif_probe(hba, desc_buf); + ufs_init_rtc(hba, desc_buf); + if (hba->ext_iid_sup) ufshcd_ext_iid_probe(hba, desc_buf); @@ -8786,6 +8857,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) ufshcd_force_reset_auto_bkops(hba); ufshcd_set_timestamp_attr(hba); + schedule_delayed_work(&hba->ufs_rtc_update_work, + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); /* Gear up to HS gear if supported */ if (hba->max_pwr_info.is_valid) { @@ -9742,6 +9815,8 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) ret = ufshcd_vops_suspend(hba, pm_op, POST_CHANGE); if (ret) goto set_link_active; + + cancel_delayed_work_sync(&hba->ufs_rtc_update_work); goto out; set_link_active: @@ -9836,6 +9911,8 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) if (ret) goto set_old_link_state; ufshcd_set_timestamp_attr(hba); + schedule_delayed_work(&hba->ufs_rtc_update_work, + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); } if (ufshcd_keep_autobkops_enabled_except_suspend(hba)) diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index e77ab1786856..8022d267fe8a 100644 --- a/include/ufs/ufs.h +++ b/include/ufs/ufs.h @@ -14,6 +14,7 @@ #include #include #include +#include /* * Using static_assert() is not allowed in UAPI header files. Hence the check @@ -551,6 +552,15 @@ struct ufs_vreg_info { struct ufs_vreg *vdd_hba; }; +/* + * UFS device descriptor wPeriodicRTCUpdate bit9 defines RTC time baseline. + */ +#define UFS_RTC_TIME_BASELINE BIT(9) +enum ufs_rtc_time { + UFS_RTC_RELATIVE, + UFS_RTC_ABSOLUTE +}; + struct ufs_dev_info { bool f_power_on_wp_en; /* Keeps information if any of the LU is power on write protected */ @@ -578,6 +588,10 @@ struct ufs_dev_info { /* UFS EXT_IID Enable */ bool b_ext_iid_en; + + /* UFS RTC */ + enum ufs_rtc_time rtc_type; + time64_t rtc_time_baseline; }; /* diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index b0cd6c6591ef..a365ad138eb3 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -910,6 +910,8 @@ enum ufshcd_mcq_opr { * @mcq_base: Multi circular queue registers base address * @uhq: array of supported hardware queues * @dev_cmd_queue: Queue for issuing device management commands + * @mcq_opr: MCQ operation and runtime registers + * @ufs_rtc_update_work: A work for UFS RTC periodic update */ struct ufs_hba { void __iomem *mmio_base; @@ -1070,6 +1072,8 @@ struct ufs_hba { struct ufs_hw_queue *uhq; struct ufs_hw_queue *dev_cmd_queue; struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX]; + + struct delayed_work ufs_rtc_update_work; }; /** From patchwork Wed Nov 22 17:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 13465297 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="tmkqyx1Z"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="SkDr8bks" Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B46E11F; Wed, 22 Nov 2023 09:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700673929; cv=none; d=strato.com; s=strato-dkim-0002; b=L7WFrYebsKHoUGrR1I1AnrhXx43r66fniToUVGhpiG1yTxFPw0MYuimgZ4Squ+ClHW X6jaXfoOvLccEA/oPO7NiPwaVV/cJ80qq/UpscPLDc1IlAe9zIBFG/aC1kkwfdeLfcwP 9CyF5QB9eCvWUjzMzBLMsUxydr3U5uFPZT6qXgDjWA2qsyMHLE13WlbBUbRShP+hKIhm Ck/lh4Q7tCFI9T6uz2knWdtbkmpQ7J4LMwUBdqLoEeDoOx7QoH/oZxWew163cPPXa7Re 2mnOvwXvYaelgt/zrA20CcgEv5Y70IvdVF0kQi5xqq7uEAydvzvE6BQZ0Czjhq2T7g3U gtkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1700673929; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=vZpZ9NKXUQd/HeAYhjZFf4m71jUoBcZvjlDIhfX51No=; b=jVtXAN2Ue+JUsFFZUDqooVnxp2YjrErfvxFChRTLqR7iJb0YNq2jCDWTL6qvhpgtUh pzIdllwANKd86jHjtdfbH66XyCVoo3OQVMDVWbqx71+Dht+xBXi2CEu3bwlWb2qUuddx vUcPdoN6fP527IB+Wea6sAow9hw+LzaoTwwZeMnnrt3tFKFIYreEcN0kCDT3vpqzDWwx IsL8PDMYlqFDaUc91yMIbx7cvJMKM0VLe2sByHsba6gAMga56u8tLvIg7axq6+r5OfuN +CwDI2NVHf0JK5po9e8nEBpme/GWAsKgxRBVqy8aT/GjRKgEpZGRr+G4UTc2+XKNbKVC hnMA== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1700673929; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=vZpZ9NKXUQd/HeAYhjZFf4m71jUoBcZvjlDIhfX51No=; b=tmkqyx1ZPFvm9gGyfWwMoEofS1DdYUQaRl6LJQrjUxJqnjR/fB4ex76ZsOKGEgahoY hhNeiU8HVlaoLvpWKlvBEaBqeU6PmHHz94McXnE897Ri1Tjxzrij9V/9RI3el3bzBp3H zW1emX36yRhicdUZGdlo9NhoTfx7OTPlpoRNrt4Vtqdu9xO+keoArpY35sbYcQlp1Cg5 TzZP6nUr/I/uJZN9PL1vNcduPMbkAjOthzi263gw3GoxgBHYSQYf/Gn4oOHSltPP1HoE e6VAHgJk+KoKtYcdwnQvGxUg6sZ/mTJX6eRDZqpVNDmugVQmyS7C2bXYkb8dwUGeAfbz HyaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1700673929; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=vZpZ9NKXUQd/HeAYhjZFf4m71jUoBcZvjlDIhfX51No=; b=SkDr8bksm3TNE4WuBF4Cj5eiTXNfrzcq2TtVMVuzsZY6y9r4Zdqbd4YYy/WY7O1u76 JS96XsU21T6869eK70Ag== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD2QzemV2tdlNlNRZBXiUw=" Received: from Munilab01-lab.micron.com by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id z758a5zAMHPStqM (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 22 Nov 2023 18:25:28 +0100 (CET) From: Bean Huo To: avri.altman@wdc.com, bvanassche@acm.org, alim.akhtar@samsung.com, jejb@linux.ibm.com, martin.petersen@oracle.com, mani@kernel.org, quic_cang@quicinc.com, quic_asutoshd@quicinc.com, beanhuo@micron.com, thomas@t-8ch.de Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, mikebi@micron.com, lporzio@micron.com Subject: [PATCH v2 3/3] scsi: ufs: core: Add sysfs node for UFS RTC update Date: Wed, 22 Nov 2023 18:25:12 +0100 Message-Id: <20231122172512.103748-4-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122172512.103748-1-beanhuo@iokpp.de> References: <20231122172512.103748-1-beanhuo@iokpp.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bean Huo Introduce a sysfs node named 'rtc_update_ms' within the kernel, enabling user to adjust the RTC periodic update frequency to suit the specific requirements of the system and UFS. Also, this patch allows the user to disable/enable periodic update RTC in the UFS idle time. Signed-off-by: Bean Huo --- Documentation/ABI/testing/sysfs-driver-ufs | 7 +++++ drivers/ufs/core/ufs-sysfs.c | 31 ++++++++++++++++++++++ drivers/ufs/core/ufshcd.c | 11 ++++++-- include/ufs/ufs.h | 1 + 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 0c7efaf62de0..ef1e27584fff 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -1474,3 +1474,10 @@ Description: Indicates status of Write Booster. The file is read only. +What: /sys/bus/platform/drivers/ufshcd/*/rtc_update_ms +What: /sys/bus/platform/devices/*.ufs/rtc_update_ms +Date: November 2023 +Contact: Bean Huo +Description: + rtc_update_ms indicates how often the host should synchronize or update the + UFS RTC. If set to 0, this will disable UFS RTC periodic update. diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index c95906443d5f..bb6b540ccd8e 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -255,6 +255,35 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr, return res < 0 ? res : count; } +static ssize_t rtc_update_ms_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", hba->dev_info.rtc_update_period); +} + +static ssize_t rtc_update_ms_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + unsigned int ms; + bool resume_period_update = false; + + if (kstrtouint(buf, 0, &ms)) + return -EINVAL; + + if (!hba->dev_info.rtc_update_period && ms > 0) + resume_period_update = true; + /* Minimum and maximum update frequency should be synchronized with all UFS vendors */ + hba->dev_info.rtc_update_period = ms; + + if (resume_period_update) + schedule_delayed_work(&hba->ufs_rtc_update_work, + msecs_to_jiffies(hba->dev_info.rtc_update_period)); + return count; +} + static ssize_t enable_wb_buf_flush_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -339,6 +368,7 @@ static DEVICE_ATTR_RW(auto_hibern8); static DEVICE_ATTR_RW(wb_on); static DEVICE_ATTR_RW(enable_wb_buf_flush); static DEVICE_ATTR_RW(wb_flush_threshold); +static DEVICE_ATTR_RW(rtc_update_ms); static struct attribute *ufs_sysfs_ufshcd_attrs[] = { &dev_attr_rpm_lvl.attr, @@ -351,6 +381,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = { &dev_attr_wb_on.attr, &dev_attr_enable_wb_buf_flush.attr, &dev_attr_wb_flush_threshold.attr, + &dev_attr_rtc_update_ms.attr, NULL }; diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 4d349eff24c4..53b4c96f4279 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8223,9 +8223,9 @@ static void ufshcd_rtc_work(struct work_struct *work) if (!is_busy) ufshcd_update_rtc(hba); - if (ufshcd_is_ufs_dev_active(hba)) + if (ufshcd_is_ufs_dev_active(hba) && hba->dev_info.rtc_update_period) schedule_delayed_work(&hba->ufs_rtc_update_work, - msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); + msecs_to_jiffies(hba->dev_info.rtc_update_period)); } static void ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf) @@ -8247,6 +8247,13 @@ static void ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf) dev_info->rtc_time_baseline = 0; } + /* + * We ignore TIME_PERIOD defined in wPeriodicRTCUpdate because Spec does not clearly state + * how to calculate the specific update period for each time unit. Here we disable periodic + * update work, and let user configure by sysfs node according to specific circumstance. + */ + hba->dev_info.rtc_update_period = 0; + INIT_DELAYED_WORK(&hba->ufs_rtc_update_work, ufshcd_rtc_work); } diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index 8022d267fe8a..288724d3be90 100644 --- a/include/ufs/ufs.h +++ b/include/ufs/ufs.h @@ -592,6 +592,7 @@ struct ufs_dev_info { /* UFS RTC */ enum ufs_rtc_time rtc_type; time64_t rtc_time_baseline; + u32 rtc_update_period; }; /*