Skip to content

Commit 838f595

Browse files
beanhuomartinkpetersen
authored andcommitted
scsi: ufs: core: Add sysfs node for UFS RTC update
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> Link: https://lore.kernel.org/r/20231212220825.85255-4-beanhuo@iokpp.de Acked-by: Avri Altman <avri.altman@wdc.com> Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 6bf999e commit 838f595

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

Documentation/ABI/testing/sysfs-driver-ufs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,3 +1474,10 @@ Description: Indicates status of Write Booster.
14741474

14751475
The file is read only.
14761476

1477+
What: /sys/bus/platform/drivers/ufshcd/*/rtc_update_ms
1478+
What: /sys/bus/platform/devices/*.ufs/rtc_update_ms
1479+
Date: November 2023
1480+
Contact: Bean Huo <beanhuo@micron.com>
1481+
Description:
1482+
rtc_update_ms indicates how often the host should synchronize or update the
1483+
UFS RTC. If set to 0, this will disable UFS RTC periodic update.

drivers/ufs/core/ufs-sysfs.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,35 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr,
255255
return res < 0 ? res : count;
256256
}
257257

258+
static ssize_t rtc_update_ms_show(struct device *dev, struct device_attribute *attr,
259+
char *buf)
260+
{
261+
struct ufs_hba *hba = dev_get_drvdata(dev);
262+
263+
return sysfs_emit(buf, "%d\n", hba->dev_info.rtc_update_period);
264+
}
265+
266+
static ssize_t rtc_update_ms_store(struct device *dev, struct device_attribute *attr,
267+
const char *buf, size_t count)
268+
{
269+
struct ufs_hba *hba = dev_get_drvdata(dev);
270+
unsigned int ms;
271+
bool resume_period_update = false;
272+
273+
if (kstrtouint(buf, 0, &ms))
274+
return -EINVAL;
275+
276+
if (!hba->dev_info.rtc_update_period && ms > 0)
277+
resume_period_update = true;
278+
/* Minimum and maximum update frequency should be synchronized with all UFS vendors */
279+
hba->dev_info.rtc_update_period = ms;
280+
281+
if (resume_period_update)
282+
schedule_delayed_work(&hba->ufs_rtc_update_work,
283+
msecs_to_jiffies(hba->dev_info.rtc_update_period));
284+
return count;
285+
}
286+
258287
static ssize_t enable_wb_buf_flush_show(struct device *dev,
259288
struct device_attribute *attr,
260289
char *buf)
@@ -339,6 +368,7 @@ static DEVICE_ATTR_RW(auto_hibern8);
339368
static DEVICE_ATTR_RW(wb_on);
340369
static DEVICE_ATTR_RW(enable_wb_buf_flush);
341370
static DEVICE_ATTR_RW(wb_flush_threshold);
371+
static DEVICE_ATTR_RW(rtc_update_ms);
342372

343373
static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
344374
&dev_attr_rpm_lvl.attr,
@@ -351,6 +381,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
351381
&dev_attr_wb_on.attr,
352382
&dev_attr_enable_wb_buf_flush.attr,
353383
&dev_attr_wb_flush_threshold.attr,
384+
&dev_attr_rtc_update_ms.attr,
354385
NULL
355386
};
356387

drivers/ufs/core/ufshcd.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8233,9 +8233,9 @@ static void ufshcd_rtc_work(struct work_struct *work)
82338233
if (!ufshcd_is_ufs_dev_busy(hba) && hba->ufshcd_state == UFSHCD_STATE_OPERATIONAL)
82348234
ufshcd_update_rtc(hba);
82358235

8236-
if (ufshcd_is_ufs_dev_active(hba))
8236+
if (ufshcd_is_ufs_dev_active(hba) && hba->dev_info.rtc_update_period)
82378237
schedule_delayed_work(&hba->ufs_rtc_update_work,
8238-
msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
8238+
msecs_to_jiffies(hba->dev_info.rtc_update_period));
82398239
}
82408240

82418241
static void ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf)
@@ -8257,6 +8257,13 @@ static void ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf)
82578257
dev_info->rtc_type = UFS_RTC_RELATIVE;
82588258
dev_info->rtc_time_baseline = 0;
82598259
}
8260+
8261+
/*
8262+
* We ignore TIME_PERIOD defined in wPeriodicRTCUpdate because Spec does not clearly state
8263+
* how to calculate the specific update period for each time unit. And we disable periodic
8264+
* RTC update work, let user configure by sysfs node according to specific circumstance.
8265+
*/
8266+
dev_info->rtc_update_period = 0;
82608267
}
82618268

82628269
static int ufs_get_device_desc(struct ufs_hba *hba)

include/ufs/ufs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ struct ufs_dev_info {
591591
/* UFS RTC */
592592
enum ufs_rtc_time rtc_type;
593593
time64_t rtc_time_baseline;
594+
u32 rtc_update_period;
594595
};
595596

596597
/*

0 commit comments

Comments
 (0)