Skip to contentSkip to conversation

ufs: sysfs: Add WB partial flush mode support

PATCH Superseded Daniel Lee 2 participants 2 messages Jun 10

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Daniel Lee

author
#0 lore raw

PATCH v2 1/1 ufs: sysfs: Add WB partial flush mode support

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

---
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               | 326 +++++++++++++++++----
 include/ufs/ufs.h                          |  18 ++
 3 files changed, 366 insertions(+), 63 deletions(-)
Documentation/ABI/testing/sysfs-driver-ufs +85 -0
index 3c422aac778b..32dd38ebaef7 100644
@@ -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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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 <[email protected]>
+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.
drivers/ufs/core/ufs-sysfs.c +263 -63

392 lines not on this page · raw message

include/ufs/ufs.h +18 -0
index 0d48e137d66d..b34ca7aadd69 100644
@@ -146,6 +146,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 */
@@ -191,6 +192,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,
 };
@@ -401,6 +410,15 @@ 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),
Signature · 1 line
2.54.0.1099.g489fc7bff1-goog
#1 lore raw

drivers/ufs/core/ufs-sysfs.c static const char *ufs_wb_resize_status_to_string(enum wb_resize_status status) · line 103

Quoted 7 lines · Daniel Lee
drivers/ufs/core/ufs-sysfs.c +7 -0
+static const char *ufs_wb_pfm_to_string(u32 pfm)
+{
+	if (pfm < NUM_WB_PARTIAL_FLUSH_MODES)
+		return wb_partial_flush_modes[pfm];
+
+	return "unknown";
+}

Is a new function really required for something that can be written as a
single ternary expression? Please consider folding this function into its caller since the above function only has one caller.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+

Please follow the convention used elsewhere in the Linux kernel and only insert a single blank line between definitions.

drivers/ufs/core/ufs-sysfs.c static const struct attribute_group ufs_sysfs_string_descriptors_group = { · line 1572

Quoted 7 lines
drivers/ufs/core/ufs-sysfs.c +7 -0
+	ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,
+		idn, index, &flag);
+	ufshcd_rpm_put_sync(hba);
+	if (ret) {
+		ret = -EINVAL;
+		goto out;
+	}

Why is the error code returned by ufshcd_query_flag() changed into -EINVAL? Isn't this something that should only happen if ufshcd_query_flag() returns a positive value? From the comment block above the definition of ufshcd_query_flag():

* Return: 0 upon success; > 0 in case the UFS device reported an OCS
error;
* < 0 if another error occurred.

drivers/ufs/core/ufs-sysfs.c static const struct attribute_group ufs_sysfs_string_descriptors_group = { · line 1606

Quoted 8 lines
drivers/ufs/core/ufs-sysfs.c +8 -0
+	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) {
+		ret = -EINVAL;
+		goto out;
+	}

Same comment here.

drivers/ufs/core/ufs-sysfs.c static ssize_t wb_resize_status_show(struct device *dev, · line 1850

Quoted 11 lines
drivers/ufs/core/ufs-sysfs.c +11 -0
+	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) {
+		ret = -EINVAL;
+		goto out;
+	}

Same comment here.

drivers/ufs/core/ufs-sysfs.c static ssize_t wb_resize_status_show(struct device *dev, · line 1886

Quoted 7 lines
drivers/ufs/core/ufs-sysfs.c +7 -0
+	ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+		idn, index, 0, &value);
+	ufshcd_rpm_put_sync(hba);
+	if (ret) {
+		ret = -EINVAL;
+		goto out;
+	}

Same comment here.

drivers/ufs/core/ufs-sysfs.c UFS_ATTRIBUTE(wb_avail_buf, _AVAIL_WB_BUFF_SIZE); · line 1956

Quoted 6 lines
drivers/ufs/core/ufs-sysfs.c +6 -0
+	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)
+		return -EINVAL;

Same comment here.

drivers/ufs/core/ufs-sysfs.c UFS_ATTRIBUTE(wb_avail_buf, _AVAIL_WB_BUFF_SIZE); · line 1987

Quoted 6 lines
drivers/ufs/core/ufs-sysfs.c +6 -0
+	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);
+
+	return ret ? -EINVAL : count;

Same comment here.

Otherwise this patch looks good to me.

Thanks,

Bart.