From patchwork Sat Dec 2 16:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 13477011 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="kIEB1/L9"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="Fua0gh6y" 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 7418E188; Sat, 2 Dec 2023 08:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701532957; cv=none; d=strato.com; s=strato-dkim-0002; b=e866lOBbMx7/D+3JinX3TdM2Bb9lw13zradFKP8vQJTxGkSdW8hwniumWm5PT2ASDR 4+RcZdGEfj4saAqQugRnowDhQvzaI1xZgR3xr87ZhdFYqPUeHhvjrIsGWSpCwzeLlVse HsuM5flwcu1qTq53ZJJqy/2qPuP4C+RXwU+pR5zEkkpSGtobfnsnaIMsyF5Zxp0q65Gj NlvPuRlf8vXO17whOHL6OSM6m1ptyccNaRvwd3gUjdCbbzLRbwO8sPURHksxMCMKF8HY S8aHUc7WLFx4EzTE0aQA8qVhYDC2j8hZtfAsXpDazIK9+FXEmbmL+C7j20/sZGr0U+Aq 1JkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1701532957; 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=Tnpp+igY4DbZNs0oTu7nbRDD42wohiyLate59qDod5Q=; b=gL7ViZ0LmlTlbr9hHjr+XoeAv6IKxjw3mCcfFN4Ec5vrVnN4x5qCoywmJQBNV0zN3i eFOo/N7OA8/JtfvXBG4Q3krLdGgndRHH2kM/7Duat38thSXo8PVe2kkikTUnkIWtTsB1 n+prwPZXHOokSPU7Zju4ylIj/saGyUwUfcqAQIwiHcco+PBEvKe7MWdDToMatqP2iQgQ L6A5guP2VhMIirrzRaGYKgXo9EhAv4n83ep2a0FjYkhb4PiUExD+wEg4neyfL6Ro2GfA oTEG32tqgzn+A3IbhdNiruFRiqx+7sciiFiySWRwX7NbBrYlnLyFZxZMNTzN4bsN8vWe Vp1A== 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=1701532957; 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=Tnpp+igY4DbZNs0oTu7nbRDD42wohiyLate59qDod5Q=; b=kIEB1/L9NCvJ5RUo8J7gpCBoY4QmE9ZM3JJppLYsAL617Ex5kFM+nje8GjTT04OM/s Q3zI/aZi+oB76tNPap1DIRdIZdnS6Im2t0D2Fle5gQa/4+l8ek0ZbTJlSyTavWPgWBJU WLy9JXDfEqqy/lKk3iIBo6zc0DaRWwOvxDRZyQ130EcL8ACdohYfh+LVh2Nva/IqqAx5 f3zqW5Ff0vvj7UjuHRUswpbLDIdB2+Kvkomd5JflAhzHMAxePBoCnLxrn172ye6tb4Sj U+B/1fMkLi80kVoMlIN/+DMvUZK342i6bAHnX2S5sfKrvvQaD7ZD6KznnUmn9MqkT6XM ylyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1701532957; 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=Tnpp+igY4DbZNs0oTu7nbRDD42wohiyLate59qDod5Q=; b=Fua0gh6yCT8HXHdEI/IRJqJnK2BT8GqYfmODKfiqEVluIKXLNNEpnJbTYrlsSFU+BS br0Y2ExM0Ef5DiMt45Ag== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD1QLj68UeUr1+U0BfWsYLe+bQusZClHgu6POSIuOZDSGI3MA01fA==" Received: from Munilab01-lab.speedport.ip by smtp.strato.de (RZmta 49.9.7 AUTH) with ESMTPSA id z8d451zB2G2b5CJ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 2 Dec 2023 17:02:37 +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 v3 1/3] scsi: ufs: core: Add ufshcd_is_ufs_dev_busy() Date: Sat, 2 Dec 2023 17:02:25 +0100 Message-Id: <20231202160227.766529-2-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202160227.766529-1-beanhuo@iokpp.de> References: <20231202160227.766529-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 Reviewed-by: Avri Altman --- drivers/ufs/core/ufshcd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 68d7da02944f..f88f20f27f93 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -235,6 +235,13 @@ ufs_get_desired_pm_lvl_for_dev_link_state(enum ufs_dev_pwr_mode dev_state, return UFS_PM_LVL_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); +} + static const struct ufs_dev_quirk ufs_fixups[] = { /* UFS cards deviations table */ { .wmanufacturerid = UFS_VENDOR_MICRON, @@ -1917,10 +1924,7 @@ static void ufshcd_gate_work(struct work_struct *work) 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); From patchwork Sat Dec 2 16:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 13477013 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="MwBugEDf"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="8WIdxme1" Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A42124; Sat, 2 Dec 2023 08:02:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701532957; cv=none; d=strato.com; s=strato-dkim-0002; b=jzagTXn7LX9mEsgVnfiH6X/SiVFfCmM3poZPx8XDNay4c04+pXaMICM4wDCNpgLhiA lqb6hiJ5AFXOr9IcOOjI0Tmep8S3nDXkAlPvoefBXYxegK3v3aJ90W//SuTjcDVQ1ugU AdB3FbVZMcFhuYc8mG2ZkhMHCkldMATl8Hn6QRP6RDW23WspNizHu6SEi1F67pggfki1 BEWwBQ8ceyQD/gUjq+R/MeWN4CL8VDuJkPXQE137lzzP442C1qZEw2F4FSqK+m5zaK6G ULjn0kzuBkaqGLL9zcX/r3qQlxFX1SWToXMvTi/OYmJB/iOI0bvcPi0+uoFfCcVoUM37 KK1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1701532957; 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=bi41PBpmirH7gK/94LvAmCfOWqfkeZER0pCr8pvmRi0=; b=JtigCenPhm05+mZUx5EwE7Bdzp3NK0j8iUHF6uZyG5F29eL0ucD83JmM9yOeCmx0dV BvQ2yyaRhlFj0gucUHH4muHIuEkThOhVjNSgERphDjSMJLk+wb63HDcdcvi9j6G6ZgBP d7Sfl97lW7i0pcCtplgXZJ1gf5OhZFc600TIh+BEo9q0ENW2rAliy98uxBVuypEynjG0 WB2IjiWZ7EAgHWt9+VTaAEO0drBsYXX7Vcpg49kNnp5y53y0oLV/VO36ztbiEMEedZhW Hv3r5lgm75hCiCDZSAtO42Gb7+tLDLX5w7MwfU0IwP8TUHYpoXzqp75KwKMCq/6FLdKG TWvQ== 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=1701532957; 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=bi41PBpmirH7gK/94LvAmCfOWqfkeZER0pCr8pvmRi0=; b=MwBugEDfq8tydrfnlM5vY2v2XJNwPcq050rgYp2/ocCYLbkI4u0Sy9TMhz0vyUv+QQ 9ld6gyJHtqpemr7CCMqAcq6o6N8ThfcsyD+0NZkTHtL8vQFnxJLS68XzBZ3DCCFHhMht PW/+DMXrJ/Jr3FxtkXlt89P5DFDVujSB24EgprqPQw9OPMuyk8LXlLP0w9a/1jeMdCJg IQhIX4ffN7sXxlubYrhsshNVi6N0/efzSOc4jQerka2wSrzU4nyZvtURosMA0k/nnI1X KT25XpfNS/8LwBDaWOfTt2wdI8/afMmCkRmNb2OOiti7PhW3Rv3wLeQzhCxk/3qvDjM+ 67mw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1701532957; 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=bi41PBpmirH7gK/94LvAmCfOWqfkeZER0pCr8pvmRi0=; b=8WIdxme16b9Y7sau1bfydlb1SDxTt42ugOYC7pblEZf0r2D6GRauF3wn/myPwYmPb/ hWLB8/UmEwiK9muQMoDA== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD1QLj68UeUr1+U0BfWsYLe+bQusZClHgu6POSIuOZDSGI3MA01fA==" Received: from Munilab01-lab.speedport.ip by smtp.strato.de (RZmta 49.9.7 AUTH) with ESMTPSA id z8d451zB2G2b5CK (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 2 Dec 2023 17:02:37 +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 v3 2/3] scsi: ufs: core: Add UFS RTC support Date: Sat, 2 Dec 2023 17:02:26 +0100 Message-Id: <20231202160227.766529-3-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202160227.766529-1-beanhuo@iokpp.de> References: <20231202160227.766529-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 Spec, 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 Acked-by: Avri Altman --- 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 f88f20f27f93..dfc660de656f 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; @@ -684,6 +687,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); @@ -8189,6 +8194,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; @@ -8241,6 +8310,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); @@ -8794,6 +8865,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) { @@ -9750,6 +9823,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: @@ -9844,6 +9919,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 7f0b2c5599cd..7bdda92fcb1c 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -911,6 +911,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; @@ -1071,6 +1073,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 Sat Dec 2 16:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 13477014 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="G9eqaHEL"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="oxdDHlly" Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DAAD18A; Sat, 2 Dec 2023 08:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701532958; cv=none; d=strato.com; s=strato-dkim-0002; b=Z6tfNtR1LqgQUhGZUAjAL/47yg9nw/IFkjS+g62yD7tvoka1fiav/7P4nMevwV0pv7 IlJbqG/L9P0HhqbZB7MoBwrKal/83jmebrD13fUZ3+9C+lExdB0Ju36ofnG2qhuEIypR I/gCMq7r+ptaPbPbq+0m782/Jtnea/AhysuZBr7UUgUdhNgRlmvYmRrBK3wFDs0PbtRS zlhcxASKYrPlvxSGEKEdqzImUJG5D8XwJbWVTJ2aKfe2p7pfvqzjh2d29gmPRw9UIfhV l83f1j6NcCuCkKlwrPGqJlPE7ykNYW7TgzY5ao4qvf/k0GRF3jMF1iLMRepq8lkS0U+t EUIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1701532958; 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=oxMNWR/TdQAOnRsDvUNaC3OMvStYq+qqiw9ndKWZvb8=; b=atzxk6CSr/hz2VfiRhzmLXsg+OSPUhZ4/AfxDPX3NPCYE/0Uor7N/ek2Zr8uTP2avI PRUZxigY51f3B9OBlbhaNNX8rnP4MoF/tt25oyilUA1aRA7mPEaeSt9iVz+pjhGuJasK o+2auw4JiSkgJ6khCZ8ZtRLz3fSz1DcZ/l0oHLKY74qDCrhHWNl+h5IKY4U42Zi7gybV EtrdNkU/abVeEil4Nnc1trQEE0ldQWU5wALMBDuGAGJR7pawt6neg67vQoUvinofZGaC DwqzJsAmrFji+6AnPwDvEFQz2WGnAkI5+XcJ0sA0UdvFm1EAGtlm+anUqicSxbawmycQ LI2Q== 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=1701532958; 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=oxMNWR/TdQAOnRsDvUNaC3OMvStYq+qqiw9ndKWZvb8=; b=G9eqaHELdc+mxqstTAlRYIbnrhMVcaE2jSyHbtMd/oVdvxErxDUNxcZFOQOT/Lz9/l wba6/Sw64vo6Yvs/RNthQK0Kzg081wdnrGOpXIXqlRZqdDxyrhi12k1FQTPERinks/ul e4TiaXBoAPENv4YyL3kGdwj7HIMXcXtrrF9ug0kIaihv8bwkpCVSjXWdzG6H7ReWtPm6 8o6czr0F6yM4L1Yb8jA7Om1XTRrNptfWVh6K2nrXaqzghS83Sv8q8IMehbGIA1PCli5o qQznfrrkEgY4gWvvkAET6aiuEjwpgUBPyK7cQkWfiVIhOONQ1TNXDvaBBzxWmadXqSba sbog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1701532958; 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=oxMNWR/TdQAOnRsDvUNaC3OMvStYq+qqiw9ndKWZvb8=; b=oxdDHllyCAGyLruYARpcyri7Vd9/zdW/5oTl1KjvoTlE/d4zDn9p+07d51ag36EBKQ HhAoao4dCg2g7KhefbDg== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSedrgBzPc9DUyubU4DD1QLj68UeUr1+U0BfWsYLe+bQusZClHgu6POSIuOZDSGI3MA01fA==" Received: from Munilab01-lab.speedport.ip by smtp.strato.de (RZmta 49.9.7 AUTH) with ESMTPSA id z8d451zB2G2b5CL (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 2 Dec 2023 17:02:37 +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 v3 3/3] scsi: ufs: core: Add sysfs node for UFS RTC update Date: Sat, 2 Dec 2023 17:02:27 +0100 Message-Id: <20231202160227.766529-4-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202160227.766529-1-beanhuo@iokpp.de> References: <20231202160227.766529-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 Acked-by: Avri Altman --- 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 dfc660de656f..4864d213d5d9 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8231,9 +8231,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) @@ -8255,6 +8255,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; }; /*