From: Bean Huo <beanhuo@iokpp.de>
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 [thread overview]
Message-ID: <20231202160227.766529-4-beanhuo@iokpp.de> (raw)
In-Reply-To: <20231202160227.766529-1-beanhuo@iokpp.de>
From: Bean Huo <beanhuo@micron.com>
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 <beanhuo@micron.com>
---
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 <beanhuo@micron.com>
+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;
};
/*
--
2.34.1
next prev parent reply other threads:[~2023-12-02 16:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-02 16:02 [PATCH v3 0/3] Add UFS RTC support Bean Huo
2023-12-02 16:02 ` [PATCH v3 1/3] scsi: ufs: core: Add ufshcd_is_ufs_dev_busy() Bean Huo
2023-12-06 19:36 ` Avri Altman
2023-12-02 16:02 ` [PATCH v3 2/3] scsi: ufs: core: Add UFS RTC support Bean Huo
2023-12-04 12:13 ` Avri Altman
2023-12-04 12:23 ` Avri Altman
2023-12-06 19:38 ` Avri Altman
2023-12-07 0:59 ` Bart Van Assche
2023-12-07 23:02 ` Bean Huo
2023-12-02 16:02 ` Bean Huo [this message]
2023-12-06 19:39 ` [PATCH v3 3/3] scsi: ufs: core: Add sysfs node for UFS RTC update Avri Altman
2023-12-06 17:08 ` [PATCH v3 0/3] Add UFS RTC support Bean Huo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231202160227.766529-4-beanhuo@iokpp.de \
--to=beanhuo@iokpp.de \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@wdc.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=lporzio@micron.com \
--cc=mani@kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mikebi@micron.com \
--cc=quic_asutoshd@quicinc.com \
--cc=quic_cang@quicinc.com \
--cc=thomas@t-8ch.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®