* [PATCH v3 RESEND] ufs: sysfs: Add WB partial flush mode support
@ 2026-11-16 2:05 Daniel Lee
2026-11-16 3:02 ` Bart Van Assche
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Lee @ 2026-11-16 2:05 UTC (permalink / raw)
To: James.Bottomley, martin.petersen
Cc: alim.akhtar, avri.altman, bvanassche, tanghuan, linux-scsi,
linux-kernel, chullee
Expose the following JEDEC UFS 4.1 Extended WriteBooster attributes and
flags to sysfs to support FIFO and Pinned partial flush modes:
- wb_partial_flush_mode
- wb_max_fifo_size
- wb_cur_fifo_size
- wb_pinned_cur_size
- wb_pinned_avail_pct
- wb_pinned_cumulative_write_size
- wb_pinned_size
- wb_non_pinned_min_size
- wb_unpin_enable
Introduce UFS_ATTRIBUTE_RW and UFS_FLAG_RW to support writable attributes
and flags.
Document the new entries under Documentation/ABI/testing/sysfs-driver-ufs.
Assisted-by: Gemini:gemini-3.1
Signed-off-by: Daniel Lee <chullee@google.com>
---
v3:
- Fold ufs_wb_pfm_to_string() into wb_partial_flush_mode_show().
- Propagate actual error codes for non-OCS error (ret < 0), while keeping -EINVAL for OCS errors (ret > 0).
- Clean up blank lines.
v2:
- Change wb_partial_flush_mode attribute to accept and report strings instead of numbers for better usability.
- Order local variable declarations from longest to shortest in new functions.
Documentation/ABI/testing/sysfs-driver-ufs | 85 ++++++
drivers/ufs/core/ufs-sysfs.c | 311 ++++++++++++++++-----
include/ufs/ufs.h | 17 ++
3 files changed, 350 insertions(+), 63 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs
index 3c422aac7..32dd38eba 100644
--- a/Documentation/ABI/testing/sysfs-driver-ufs
+++ b/Documentation/ABI/testing/sysfs-driver-ufs
@@ -1791,3 +1791,88 @@ Description:
will be rejected.
The attribute is read/write.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_partial_flush_mode
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_partial_flush_mode
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry controls Extended WriteBooster partial flush modes.
+
+ ======== ==============================
+ "none" No partial flush
+ "fifo" FIFO mode
+ "pinned" Pinned mode
+ ======== ==============================
+
+ The attribute is read-write.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_max_fifo_size
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_max_fifo_size
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry configures the maximum size in Allocation Units reserved for the
+ WriteBooster FIFO Buffer size.
+ The attribute is read-write.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_cur_fifo_size
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_cur_fifo_size
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry shows the current size in Allocation Units of the WriteBooster FIFO
+ Buffer size.
+ The attribute is read only.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_pinned_size
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_pinned_size
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry configures the allocated size in Allocation Units for the UFS
+ Pinned WriteBooster buffer.
+ The attribute is read-write.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_pinned_cur_size
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_pinned_cur_size
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry shows the current allocated size in Allocation Units for the UFS
+ Pinned WriteBooster buffer.
+ The attribute is read-only.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_pinned_avail_pct
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_pinned_avail_pct
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry shows the percentage of available space remaining in the
+ Pinned WriteBooster buffer.
+ The attribute is read-only.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_pinned_cumulative_write_size
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_pinned_cumulative_write_size
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry shows the total cumulative size of data written to the
+ Pinned WriteBooster buffer.
+ The attribute is read-only.
+
+What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_non_pinned_min_size
+What: /sys/bus/platform/devices/*.ufs/attributes/wb_non_pinned_min_size
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry configures the minimum size in Allocation Units for the
+ Non-Pinned WriteBooster Buffer area when Pinned partial flush mode is active.
+ The attribute is read-write.
+
+What: /sys/bus/platform/drivers/ufshcd/*/flags/wb_unpin_enable
+What: /sys/bus/platform/devices/*.ufs/flags/wb_unpin_enable
+Date: June 2026
+Contact: Daniel Lee <chullee@google.com>
+Description: This entry controls the Pinned WriteBooster unpin enable flag (fUnpinEn).
+
+ ====== ==============================================================
+ 0 Unpin Disable: pinned data is not flushed by WriteBooster
+ Buffer flush operation.
+ 1 Unpin Enable: pinned data is flushed by WriteBooster
+ Buffer flush operation.
+ ====== ==============================================================
+
+ The attribute is read-write.
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index cf49ad025..97301f95e 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -89,6 +89,12 @@ static const char *ufs_wb_resize_status_to_string(enum wb_resize_status status)
}
}
+static const char * const wb_partial_flush_modes[] = {
+ [WB_PARTIAL_FLUSH_NONE] = "none",
+ [WB_PARTIAL_FLUSH_FIFO] = "fifo",
+ [WB_PARTIAL_FLUSH_PINNED] = "pinned",
+};
+
static const char * const ufs_hid_states[] = {
[HID_IDLE] = "idle",
[ANALYSIS_IN_PROGRESS] = "analysis_in_progress",
@@ -1528,41 +1534,94 @@ static const struct attribute_group ufs_sysfs_string_descriptors_group = {
static inline bool ufshcd_is_wb_flags(enum flag_idn idn)
{
- return idn >= QUERY_FLAG_IDN_WB_EN &&
- idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8;
+ return (idn >= QUERY_FLAG_IDN_WB_EN &&
+ idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) ||
+ idn == QUERY_FLAG_IDN_WB_UNPIN_EN;
+}
+
+static ssize_t ufs_sysfs_flag_show(struct device *dev,
+ struct device_attribute *attr, char *buf, enum flag_idn idn)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u8 index = 0;
+ bool flag;
+ int ret;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+ if (ufshcd_is_wb_flags(idn))
+ index = ufshcd_wb_get_query_index(hba);
+ ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,
+ idn, index, &flag);
+ ufshcd_rpm_put_sync(hba);
+ if (ret > 0)
+ ret = -EINVAL;
+ if (ret)
+ goto out;
+ ret = sysfs_emit(buf, "%s\n", str_true_false(flag));
+out:
+ up(&hba->host_sem);
+ return ret;
+}
+
+static ssize_t ufs_sysfs_flag_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count,
+ enum flag_idn idn)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u8 index = 0;
+ bool value;
+ int ret;
+
+ if (kstrtobool(buf, &value))
+ return -EINVAL;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+ if (ufshcd_is_wb_flags(idn))
+ index = ufshcd_wb_get_query_index(hba);
+ ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_query_flag(hba,
+ value ? UPIU_QUERY_OPCODE_SET_FLAG : UPIU_QUERY_OPCODE_CLEAR_FLAG,
+ idn, index, NULL);
+ ufshcd_rpm_put_sync(hba);
+ if (ret > 0)
+ ret = -EINVAL;
+ up(&hba->host_sem);
+ return ret ? ret : count;
}
#define UFS_FLAG(_name, _uname) \
static ssize_t _name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
- bool flag; \
- u8 index = 0; \
- int ret; \
- struct ufs_hba *hba = dev_get_drvdata(dev); \
- \
- down(&hba->host_sem); \
- if (!ufshcd_is_user_access_allowed(hba)) { \
- up(&hba->host_sem); \
- return -EBUSY; \
- } \
- if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \
- index = ufshcd_wb_get_query_index(hba); \
- ufshcd_rpm_get_sync(hba); \
- ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \
- QUERY_FLAG_IDN##_uname, index, &flag); \
- ufshcd_rpm_put_sync(hba); \
- if (ret) { \
- ret = -EINVAL; \
- goto out; \
- } \
- ret = sysfs_emit(buf, "%s\n", str_true_false(flag)); \
-out: \
- up(&hba->host_sem); \
- return ret; \
+ return ufs_sysfs_flag_show(dev, attr, buf, \
+ QUERY_FLAG_IDN##_uname); \
} \
static DEVICE_ATTR_RO(_name)
+#define UFS_FLAG_RW(_name, _uname) \
+static ssize_t _name##_show(struct device *dev, \
+ struct device_attribute *attr, char *buf) \
+{ \
+ return ufs_sysfs_flag_show(dev, attr, buf, \
+ QUERY_FLAG_IDN##_uname); \
+} \
+static ssize_t _name##_store(struct device *dev, \
+ struct device_attribute *attr, const char *buf, size_t count) \
+{ \
+ return ufs_sysfs_flag_store(dev, attr, buf, count, \
+ QUERY_FLAG_IDN##_uname); \
+} \
+static DEVICE_ATTR_RW(_name)
+
UFS_FLAG(device_init, _FDEVICEINIT);
UFS_FLAG(permanent_wpe, _PERMANENT_WPE);
UFS_FLAG(power_on_wpe, _PWR_ON_WPE);
@@ -1574,6 +1633,7 @@ UFS_FLAG(disable_fw_update, _PERMANENTLY_DISABLE_FW_UPDATE);
UFS_FLAG(wb_enable, _WB_EN);
UFS_FLAG(wb_flush_en, _WB_BUFF_FLUSH_EN);
UFS_FLAG(wb_flush_during_h8, _WB_BUFF_FLUSH_DURING_HIBERN8);
+UFS_FLAG_RW(wb_unpin_enable, _WB_UNPIN_EN);
static struct attribute *ufs_sysfs_device_flags[] = {
&dev_attr_device_init.attr,
@@ -1587,6 +1647,7 @@ static struct attribute *ufs_sysfs_device_flags[] = {
&dev_attr_wb_enable.attr,
&dev_attr_wb_flush_en.attr,
&dev_attr_wb_flush_during_h8.attr,
+ &dev_attr_wb_unpin_enable.attr,
NULL,
};
@@ -1672,8 +1733,10 @@ static DEVICE_ATTR_RW(max_number_of_rtt);
static inline bool ufshcd_is_wb_attrs(enum attr_idn idn)
{
- return idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS &&
- idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE;
+ return (idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS &&
+ idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE) ||
+ (idn >= QUERY_ATTR_IDN_WB_PFM &&
+ idn <= QUERY_ATTR_IDN_NON_PINNED_WB_MIN_SIZE);
}
static inline bool ufshcd_is_qword_attr(enum attr_idn idn)
@@ -1743,48 +1806,97 @@ static ssize_t wb_resize_status_show(struct device *dev,
static DEVICE_ATTR_RO(wb_resize_status);
+static ssize_t ufs_sysfs_attr_show(struct device *dev,
+ struct device_attribute *attr, char *buf, enum attr_idn idn)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u64 qword_value;
+ u8 index = 0;
+ u32 value;
+ int ret;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+ if (ufshcd_is_wb_attrs(idn))
+ index = ufshcd_wb_get_query_index(hba);
+ ufshcd_rpm_get_sync(hba);
+ if (ufshcd_is_qword_attr(idn))
+ ret = ufshcd_query_attr_qword(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ idn, index, 0, &qword_value);
+ else
+ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ idn, index, 0, &value);
+ ufshcd_rpm_put_sync(hba);
+ if (ret > 0)
+ ret = -EINVAL;
+ if (ret)
+ goto out;
+ if (ufshcd_is_qword_attr(idn))
+ ret = sysfs_emit(buf, "0x%016llX\n", qword_value);
+ else
+ ret = sysfs_emit(buf, "0x%08X\n", value);
+out:
+ up(&hba->host_sem);
+ return ret;
+}
+
+static ssize_t ufs_sysfs_attr_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count,
+ enum attr_idn idn)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u8 index = 0;
+ u32 value;
+ int ret;
+
+ if (kstrtou32(buf, 0, &value))
+ return -EINVAL;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+ if (ufshcd_is_wb_attrs(idn))
+ index = ufshcd_wb_get_query_index(hba);
+ ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+ idn, index, 0, &value);
+ ufshcd_rpm_put_sync(hba);
+ if (ret > 0)
+ ret = -EINVAL;
+ up(&hba->host_sem);
+ return ret ? ret : count;
+}
+
#define UFS_ATTRIBUTE(_name, _uname) \
static ssize_t _name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
- struct ufs_hba *hba = dev_get_drvdata(dev); \
- u64 qword_value; \
- u32 value; \
- int ret; \
- u8 index = 0; \
- \
- down(&hba->host_sem); \
- if (!ufshcd_is_user_access_allowed(hba)) { \
- up(&hba->host_sem); \
- return -EBUSY; \
- } \
- if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \
- index = ufshcd_wb_get_query_index(hba); \
- ufshcd_rpm_get_sync(hba); \
- if (ufshcd_is_qword_attr(QUERY_ATTR_IDN##_uname)) \
- ret = ufshcd_query_attr_qword(hba, \
- UPIU_QUERY_OPCODE_READ_ATTR, \
- QUERY_ATTR_IDN##_uname, \
- index, 0, &qword_value); \
- else \
- ret = ufshcd_query_attr(hba, \
- UPIU_QUERY_OPCODE_READ_ATTR, \
- QUERY_ATTR_IDN##_uname, index, 0, &value); \
- ufshcd_rpm_put_sync(hba); \
- if (ret) { \
- ret = -EINVAL; \
- goto out; \
- } \
- if (ufshcd_is_qword_attr(QUERY_ATTR_IDN##_uname)) \
- ret = sysfs_emit(buf, "0x%016llX\n", qword_value); \
- else \
- ret = sysfs_emit(buf, "0x%08X\n", value); \
-out: \
- up(&hba->host_sem); \
- return ret; \
+ return ufs_sysfs_attr_show(dev, attr, buf, \
+ QUERY_ATTR_IDN##_uname); \
} \
static DEVICE_ATTR_RO(_name)
+#define UFS_ATTRIBUTE_RW(_name, _uname) \
+static ssize_t _name##_show(struct device *dev, \
+ struct device_attribute *attr, char *buf) \
+{ \
+ return ufs_sysfs_attr_show(dev, attr, buf, \
+ QUERY_ATTR_IDN##_uname); \
+} \
+static ssize_t _name##_store(struct device *dev, \
+ struct device_attribute *attr, \
+ const char *buf, size_t count) \
+{ \
+ return ufs_sysfs_attr_store(dev, attr, buf, count, \
+ QUERY_ATTR_IDN##_uname); \
+} \
+static DEVICE_ATTR_RW(_name)
+
UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN);
UFS_ATTRIBUTE(current_power_mode, _POWER_MODE);
UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL);
@@ -1805,6 +1917,71 @@ UFS_ATTRIBUTE(wb_avail_buf, _AVAIL_WB_BUFF_SIZE);
UFS_ATTRIBUTE(wb_life_time_est, _WB_BUFF_LIFE_TIME_EST);
UFS_ATTRIBUTE(wb_cur_buf, _CURR_WB_BUFF_SIZE);
+static ssize_t wb_partial_flush_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u32 value;
+ int ret;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+ ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ QUERY_ATTR_IDN_WB_PFM, ufshcd_wb_get_query_index(hba), 0, &value);
+ ufshcd_rpm_put_sync(hba);
+ up(&hba->host_sem);
+ if (ret > 0)
+ ret = -EINVAL;
+ if (ret)
+ return ret;
+
+ return sysfs_emit(buf, "%s\n", value < NUM_WB_PARTIAL_FLUSH_MODES ?
+ wb_partial_flush_modes[value] : "unknown");
+}
+
+static ssize_t wb_partial_flush_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u32 value;
+ int mode;
+ int ret;
+
+ mode = sysfs_match_string(wb_partial_flush_modes, buf);
+ if (mode < 0)
+ return -EINVAL;
+
+ value = mode;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+ ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+ QUERY_ATTR_IDN_WB_PFM, ufshcd_wb_get_query_index(hba), 0, &value);
+ ufshcd_rpm_put_sync(hba);
+ up(&hba->host_sem);
+
+ if (ret > 0)
+ ret = -EINVAL;
+ return ret ? ret : count;
+}
+
+static DEVICE_ATTR_RW(wb_partial_flush_mode);
+UFS_ATTRIBUTE_RW(wb_max_fifo_size, _MAX_FIFO_SIZE_WB_PFM);
+UFS_ATTRIBUTE(wb_cur_fifo_size, _CURRENT_FIFO_SIZE_WB_PFM);
+UFS_ATTRIBUTE(wb_pinned_cur_size, _PINNED_WB_CURRENT_SIZE);
+UFS_ATTRIBUTE(wb_pinned_avail_pct, _PINNED_WB_AVAIL_PERC);
+UFS_ATTRIBUTE(wb_pinned_cumulative_write_size, _PINNED_WB_CUMMULATIVE_WS);
+UFS_ATTRIBUTE_RW(wb_pinned_size, _PINNED_WB_SIZE);
+UFS_ATTRIBUTE_RW(wb_non_pinned_min_size, _NON_PINNED_WB_MIN_SIZE);
static struct attribute *ufs_sysfs_attributes[] = {
&dev_attr_boot_lun_enabled.attr,
@@ -1829,6 +2006,14 @@ static struct attribute *ufs_sysfs_attributes[] = {
&dev_attr_wb_cur_buf.attr,
&dev_attr_wb_resize_hint.attr,
&dev_attr_wb_resize_status.attr,
+ &dev_attr_wb_partial_flush_mode.attr,
+ &dev_attr_wb_max_fifo_size.attr,
+ &dev_attr_wb_cur_fifo_size.attr,
+ &dev_attr_wb_pinned_cur_size.attr,
+ &dev_attr_wb_pinned_avail_pct.attr,
+ &dev_attr_wb_pinned_cumulative_write_size.attr,
+ &dev_attr_wb_pinned_size.attr,
+ &dev_attr_wb_non_pinned_min_size.attr,
NULL,
};
diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h
index b0207e694..f6011ef1a 100644
--- a/include/ufs/ufs.h
+++ b/include/ufs/ufs.h
@@ -151,6 +151,7 @@ enum flag_idn {
QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 = 0x10,
QUERY_FLAG_IDN_HPB_RESET = 0x11,
QUERY_FLAG_IDN_HPB_EN = 0x12,
+ QUERY_FLAG_IDN_WB_UNPIN_EN = 0x13,
};
/* Attribute idn for Query requests */
@@ -196,6 +197,14 @@ enum attr_idn {
QUERY_ATTR_IDN_WB_BUF_RESIZE_HINT = 0x3C,
QUERY_ATTR_IDN_WB_BUF_RESIZE_EN = 0x3D,
QUERY_ATTR_IDN_WB_BUF_RESIZE_STATUS = 0x3E,
+ QUERY_ATTR_IDN_WB_PFM = 0x3F,
+ QUERY_ATTR_IDN_MAX_FIFO_SIZE_WB_PFM = 0x40,
+ QUERY_ATTR_IDN_CURRENT_FIFO_SIZE_WB_PFM = 0x41,
+ QUERY_ATTR_IDN_PINNED_WB_CURRENT_SIZE = 0x42,
+ QUERY_ATTR_IDN_PINNED_WB_AVAIL_PERC = 0x43,
+ QUERY_ATTR_IDN_PINNED_WB_CUMMULATIVE_WS = 0x44,
+ QUERY_ATTR_IDN_PINNED_WB_SIZE = 0x45,
+ QUERY_ATTR_IDN_NON_PINNED_WB_MIN_SIZE = 0x46,
QUERY_ATTR_IDN_TX_EQ_GN_SETTINGS = 0x47,
QUERY_ATTR_IDN_TX_EQ_GN_SETTINGS_EXT = 0x48,
};
@@ -406,6 +415,14 @@ enum {
UFS_DEV_WB_BUF_RESIZE = BIT(0),
};
+/* Possible values for bWriteBoosterBufferPartialFlushMode */
+enum wb_partial_flush_mode {
+ WB_PARTIAL_FLUSH_NONE = 0,
+ WB_PARTIAL_FLUSH_FIFO = 1,
+ WB_PARTIAL_FLUSH_PINNED = 2,
+ NUM_WB_PARTIAL_FLUSH_MODES = 3,
+};
+
/* Possible values for dExtendedUFSFeaturesSupport */
enum {
UFS_DEV_HIGH_TEMP_NOTIF = BIT(4),
--
2.56.0.611.g1030f0b940-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3 RESEND] ufs: sysfs: Add WB partial flush mode support
2026-11-16 2:05 [PATCH v3 RESEND] ufs: sysfs: Add WB partial flush mode support Daniel Lee
@ 2026-11-16 3:02 ` Bart Van Assche
0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2026-11-16 3:02 UTC (permalink / raw)
To: Daniel Lee, James.Bottomley, martin.petersen
Cc: alim.akhtar, avri.altman, tanghuan, linux-scsi, linux-kernel
On 11/15/26 6:05 PM, Daniel Lee wrote:
> +What:
/sys/bus/platform/drivers/ufshcd/*/attributes/wb_partial_flush_mode
> +What: /sys/bus/platform/devices/*.ufs/attributes/wb_partial_flush_mode
> +Date: June 2026
> +Contact: Daniel Lee <chullee@google.com>
> +Description: This entry controls Extended WriteBooster partial flush
modes.
> +
> + ======== ==============================
> + "none" No partial flush
> + "fifo" FIFO mode
> + "pinned" Pinned mode
> + ======== ==============================
> +
> + The attribute is read-write.
Please update the Date: field across the new ABI entries (June 2026 has
passed).
Also, please drop the quotes around "none", "fifo", and "pinned" to match
the other string attributes in this file (such as wb_resize_hint,
wb_resize_status, and hid/state), since literal quotes are neither emitted
nor accepted.
> +Description: This entry configures the maximum size in Allocation
Units reserved for the
> + WriteBooster FIFO Buffer size.
> + The attribute is read-write.
> +
> +What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_cur_fifo_size
> +What: /sys/bus/platform/devices/*.ufs/attributes/wb_cur_fifo_size
> +Date: June 2026
> +Contact: Daniel Lee <chullee@google.com>
> +Description: This entry shows the current size in Allocation Units
of the WriteBooster FIFO
> + Buffer size.
> + The attribute is read only.
Minor: please drop the redundant trailing "size" in "WriteBooster FIFO
Buffer size" in both descriptions above.
> +What: /sys/bus/platform/drivers/ufshcd/*/attributes/wb_pinned_avail_pct
> +What: /sys/bus/platform/devices/*.ufs/attributes/wb_pinned_avail_pct
> +Date: June 2026
> +Contact: Daniel Lee <chullee@google.com>
> +Description: This entry shows the percentage of available space
remaining in the
> + Pinned WriteBooster buffer.
> + The attribute is read-only.
Per JESD220G Table 14.28 (IDN 43h,
bPinnedWriteBoosterBufferAvailablePercentage),
this value is reported in 10% granularity (00h: 0%, 01h-09h: 10%-90%,
0Ah: 100%), not 0-100%. Please document the 10% granularity so userspace
does not misinterpret 0x0000000A as 10%.
> +What:
/sys/bus/platform/drivers/ufshcd/*/attributes/wb_pinned_cumulative_write_size
> +What:
/sys/bus/platform/devices/*.ufs/attributes/wb_pinned_cumulative_write_size
> +Date: June 2026
> +Contact: Daniel Lee <chullee@google.com>
> +Description: This entry shows the total cumulative size of data
written to the
> + Pinned WriteBooster buffer.
> + The attribute is read-only.
Please state the unit here: per JESD220G Table 14.28 (IDN 44h), this value
is in units of 10 MB (and saturates at 0xFFFFFFFF).
> +What: /sys/bus/platform/drivers/ufshcd/*/flags/wb_unpin_enable
> +What: /sys/bus/platform/devices/*.ufs/flags/wb_unpin_enable
> +Date: June 2026
> +Contact: Daniel Lee <chullee@google.com>
> +Description: This entry controls the Pinned WriteBooster unpin
enable flag (fUnpinEn).
> +
> + ======
==============================================================
> + 0 Unpin Disable: pinned data is not flushed by WriteBooster
> + Buffer flush operation.
> + 1 Unpin Enable: pinned data is flushed by WriteBooster
> + Buffer flush operation.
> + ======
==============================================================
> +
> + The attribute is read-write.
ufs_sysfs_flag_show() emits "false" or "true" via str_true_false(flag),
not 0 or 1, while ufs_sysfs_flag_store() accepts any kstrtobool() value
(0/1, false/true, n/y, off/on). Please update this description so it
accurately reflects what reading returns and what writing accepts.
> static inline bool ufshcd_is_wb_flags(enum flag_idn idn)
> {
> - return idn >= QUERY_FLAG_IDN_WB_EN &&
> - idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8;
> + return (idn >= QUERY_FLAG_IDN_WB_EN &&
> + idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) ||
> + idn == QUERY_FLAG_IDN_WB_UNPIN_EN;
> +}
Per JESD220G Table 14.26, fUnpinEn (13h) has Type "D" (device-level,
addressed with INDEX = 00h and SELECTOR = 00h per Note 1), unlike flags
0Eh-10h which are "A/LU/0 or D" (Note 4). Including
QUERY_FLAG_IDN_WB_UNPIN_EN here will send a non-zero INDEX when
WriteBooster uses an LU-dedicated buffer on a non-zero LUN. Please leave
ufshcd_is_wb_flags() unchanged.
> static inline bool ufshcd_is_wb_attrs(enum attr_idn idn)
> {
> - return idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS &&
> - idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE;
> + return (idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS &&
> + idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE) ||
> + (idn >= QUERY_ATTR_IDN_WB_PFM &&
> + idn <= QUERY_ATTR_IDN_NON_PINNED_WB_MIN_SIZE);
> }
Same issue here. Per JESD220G Table 14.28:
- 3Fh (bWriteBoosterBufferPartialFlushMode),
42h (dPinnedWriteBoosterBufferCurrentAllocUnits),
43h (bPinnedWriteBoosterBufferAvailablePercentage), and
44h (dPinnedWriteBoosterCummulativeWrittenSize) are Type "D" (INDEX =
00h).
- Only 40h, 41h, 45h, and 46h are "A/LU/0 or D" (Note 15).
Please restrict ufshcd_is_wb_attrs() to the LU-indexed attributes
(1Ch-1Fh, 40h-41h, and 45h-46h).
> +static ssize_t ufs_sysfs_attr_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count,
> + enum attr_idn idn)
> +{
> + struct ufs_hba *hba = dev_get_drvdata(dev);
> + u8 index = 0;
> + u32 value;
> + int ret;
> +
> + if (kstrtou32(buf, 0, &value))
> + return -EINVAL;
Since ufs_sysfs_attr_show() supports 64-bit attributes via
ufshcd_is_qword_attr(idn), please either support ufshcd_is_qword_attr(idn)
here as well or guard against it (e.g. WARN_ON_ONCE) so a future
UFS_ATTRIBUTE_RW() user for a 64-bit attribute cannot silently issue a
32-bit query.
> + ufshcd_rpm_get_sync(hba);
> + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
> + QUERY_ATTR_IDN_WB_PFM, ufshcd_wb_get_query_index(hba), 0, &value);
> + ufshcd_rpm_put_sync(hba);
Since QUERY_ATTR_IDN_WB_PFM (3Fh) is Type "D" per JESD220G Table 14.28,
please pass 0 instead of ufshcd_wb_get_query_index(hba) here and in
wb_partial_flush_mode_store().
Also, unlike wb_resize_hint / wb_resize_status / wb_resize_enable, none of
the new entries check hba->dev_info.ext_wb_sup
(wExtendedWriteBoosterSupport:
BIT(1) for FIFO Partial Flush Mode and BIT(2) for Pinned Partial Flush
Mode per JESD220G Table 14.4, plus hba->dev_info.b_presrv_uspc_en for
Pinned mode per Section 13.4.18.7). Should we define those capability bits
in include/ufs/ufs.h and check them (returning -EOPNOTSUPP or hiding
unsupported attributes via .is_visible) rather than waking the device and
issuing unsupported queries on devices without these features?
> + QUERY_ATTR_IDN_PINNED_WB_CUMMULATIVE_WS = 0x44,
Please spell this CUMULATIVE (single 'M'), matching the sysfs attribute
name wb_pinned_cumulative_write_size and JESD220G Section 13.4.18.7.2.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 3:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 2:05 [PATCH v3 RESEND] ufs: sysfs: Add WB partial flush mode support Daniel Lee
2026-11-16 3:02 ` Bart Van Assche
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®