Skip to contentSkip to conversation

ufs: core: Add WB buffer resize support

PATCH Superseded Huan Tang 2 participants 3 messages Apr 7, 2025 – Apr 11, 2025

Subsystems (2)

v10 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Huan Tang

author
#0 lore raw

PATCH v10 1/1 ufs: core: Add WB buffer resize support

Follow JESD220G, support WB buffer resize feature through sysfs; Query bit0 of ext_wb_sup to determine whether the device supports WB resize;Query wb_resize_hint and wb_resize_status to get the device's resize hint and resize status; Set wb_resize_enable to enable resize operation. To achieve this goals, four sysfs nodes have been added:
1. ext_wb_sup
2. wb_resize_enable
3. wb_resize_hint
4. wb_resize_status
The detailed definition of the four nodes can be found in the sysfs documentation.

Changelog
===
v9 - > v10:
fix commit message error:remove "^M"

v8 - > v9:

	1.Add "ext_wb_sup" node
	2.Fix some coding errors,for example: "gerneral" -> "general"
	3.Add a check bit0 of ext_wb_sup
	4.Following Bean's advice: use enum in ufshcd_wb_set_resize_en

v7 - > v8:
1.Optimized the description in the sysfs-driver-ufs file 2.Replace uppercase with lowercase, for example: "KEEP" -> "keep" 3.Fix coding style issues with switch/case statements

v6 - > v7:
1.Use "xxxx_to_string" for string convert
2.Use uppercase characters, for example: "keep" -> "KEEP" 3.Resize enable mode support "IDLE"

v5 - > v6:
1.Fix mistake: obtain the return value of "sysfs_emit"

v4 - > v5:
1.For the three new attributes: use words in sysfs instead of numbers

v3 - > v4:
1.modify three attributes name and description in document 2.add enum wb_resize_en in ufs.h
3.modify function name and parameters in ufs-sysfs.c, ufshcd.h, ufshcd.c

v2 - > v3:
Remove needless code:
drivers/ufs/core/ufs-sysfs.c:441:2:
index = ufshcd_wb_get_query_index(hba)

v1 - > v2:
Remove unused variable "u8 index", drivers/ufs/core/ufs-sysfs.c:419:12: warning: variable 'index' set but not used.

v1

	https://lore.kernel.org/all/[email protected]/
v2
	https://lore.kernel.org/all/[email protected]/
v3
	https://lore.kernel.org/all/[email protected]/
v4
	https://lore.kernel.org/all/[email protected]/
v5
	https://lore.kernel.org/all/[email protected]/
v6
	https://lore.kernel.org/all/[email protected]/
v7
	https://lore.kernel.org/all/[email protected]/
v8
	https://lore.kernel.org/all/[email protected]/
v9
	https://lore.kernel.org/all/[email protected]/
---
 Documentation/ABI/testing/sysfs-driver-ufs |  59 +++++++++
 drivers/ufs/core/ufs-sysfs.c               | 144 +++++++++++++++++++++
 drivers/ufs/core/ufshcd.c                  |  18 +++
 include/ufs/ufs.h                          |  34 ++++-
 include/ufs/ufshcd.h                       |   1 +
 5 files changed, 255 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-ufs +59 -0
index ae0191295d29..ea9d6186cefd 100644
@@ -1604,3 +1604,62 @@ Description:
 		prevent the UFS from frequently performing clock gating/ungating.
 
 		The attribute is read/write.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/device_descriptor/ext_wb_sup
+What:		/sys/bus/platform/devices/*.ufs/device_descriptor/ext_wb_sup
+Date:		April 2025
+Contact:	Huan Tang <[email protected]>
+Description:
+		This file shows extended WriteBooster features supported by
+		the device.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/wb_resize_enable
+What:		/sys/bus/platform/devices/*.ufs/wb_resize_enable
+Date:		April 2025
+Contact:	Huan Tang <[email protected]>
+Description:
+		The host can enable the WriteBooster buffer resize by setting this
+		attribute.
+
+		========  ======================================
+		idle      There is no resize operation
+		decrease  Decrease WriteBooster buffer size
+		increase  Increase WriteBooster buffer size
+		========  ======================================
+
+		The file is write only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/attributes/wb_resize_hint
+What:		/sys/bus/platform/devices/*.ufs/attributes/wb_resize_hint
+Date:		April 2025
+Contact:	Huan Tang <[email protected]>
+Description:
+		wb_resize_hint indicates hint information about which type of resize
+		for WriteBooster buffer is recommended by the device.
+
+		=========  ======================================
+		keep       Recommend keep the buffer size
+		decrease   Recommend to decrease the buffer size
+		increase   Recommend to increase the buffer size
+		=========  ======================================
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/attributes/wb_resize_status
+What:		/sys/bus/platform/devices/*.ufs/attributes/wb_resize_status
+Date:		April 2025
+Contact:	Huan Tang <[email protected]>
+Description:
+		The host can check the resize operation status of the WriteBooster
+		buffer by reading this attribute.
+
+		================  ========================================
+		idle              Resize operation is not issued
+		in_progress       Resize operation in progress
+		complete_success  Resize operation completed successfully
+		general_fail      Resize operation general failure
+		================  ========================================
+
+		The file is read only.
drivers/ufs/core/ufs-sysfs.c +144 -0

192 lines not on this page · raw message

drivers/ufs/core/ufshcd.c +18 -0
index 83b092cbb864..a73838062ddf 100644
@@ -6068,6 +6068,21 @@ int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable)
 	return ret;
 }
 
+int ufshcd_wb_set_resize_en(struct ufs_hba *hba, enum wb_resize_en en_mode)
+{
+	int ret;
+	u8 index;
+
+	index = ufshcd_wb_get_query_index(hba);
+	ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+				QUERY_ATTR_IDN_WB_BUF_RESIZE_EN, index, 0, &en_mode);
+	if (ret)
+		dev_err(hba->dev, "%s: Enable WB buf resize operation failed %d\n",
+			__func__, ret);
+
+	return ret;
+}
+
 static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
 						u32 avail_buf)
 {
@@ -8067,6 +8082,9 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, const u8 *desc_buf)
 	 */
 	dev_info->wb_buffer_type = desc_buf[DEVICE_DESC_PARAM_WB_TYPE];
 
+	dev_info->ext_wb_sup =  get_unaligned_be16(desc_buf +
+						DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP);
+
 	dev_info->b_presrv_uspc_en =
 		desc_buf[DEVICE_DESC_PARAM_WB_PRESRV_USRSPC_EN];
 
include/ufs/ufs.h +33 -1
index 8a24ed59ec46..9dc8b872b24d 100644
@@ -180,7 +180,10 @@ enum attr_idn {
 	QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE       = 0x1D,
 	QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST    = 0x1E,
 	QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE        = 0x1F,
-	QUERY_ATTR_IDN_TIMESTAMP		= 0x30
+	QUERY_ATTR_IDN_TIMESTAMP		= 0x30,
+	QUERY_ATTR_IDN_WB_BUF_RESIZE_HINT	= 0x3C,
+	QUERY_ATTR_IDN_WB_BUF_RESIZE_EN		= 0x3D,
+	QUERY_ATTR_IDN_WB_BUF_RESIZE_STATUS	= 0x3E,
 };
 
 /* Descriptor idn for Query requests */
@@ -289,6 +292,7 @@ enum device_desc_param {
 	DEVICE_DESC_PARAM_PRDCT_REV		= 0x2A,
 	DEVICE_DESC_PARAM_HPB_VER		= 0x40,
 	DEVICE_DESC_PARAM_HPB_CONTROL		= 0x42,
+	DEVICE_DESC_PARAM_EXT_WB_SUP		= 0x4D,
 	DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP	= 0x4F,
 	DEVICE_DESC_PARAM_WB_PRESRV_USRSPC_EN	= 0x53,
 	DEVICE_DESC_PARAM_WB_TYPE		= 0x54,
@@ -383,6 +387,11 @@ enum {
 	UFSHCD_AMP		= 3,
 };
 
+/*  Possible values for wExtendedWriteBoosterSupport */
+enum {
+	UFS_DEV_WB_BUF_RESIZE	= BIT(0),
+};
+
 /* Possible values for dExtendedUFSFeaturesSupport */
 enum {
 	UFS_DEV_HIGH_TEMP_NOTIF		= BIT(4),
@@ -454,6 +463,28 @@ enum ufs_ref_clk_freq {
 	REF_CLK_FREQ_INVAL	= -1,
 };
 
+/* bWriteBoosterBufferResizeEn attribute */
+enum wb_resize_en {
+	WB_RESIZE_EN_IDLE	= 0,
+	WB_RESIZE_EN_DECREASE	= 1,
+	WB_RESIZE_EN_INCREASE	= 2,
+};
+
+/* bWriteBoosterBufferResizeHint attribute */
+enum wb_resize_hint {
+	WB_RESIZE_HINT_KEEP	= 0,
+	WB_RESIZE_HINT_DECREASE	= 1,
+	WB_RESIZE_HINT_INCREASE	= 2,
+};
+
+/* bWriteBoosterBufferResizeStatus attribute */
+enum wb_resize_status {
+	WB_RESIZE_STATUS_IDLE	           = 0,
+	WB_RESIZE_STATUS_IN_PROGRESS       = 1,
+	WB_RESIZE_STATUS_COMPLETE_SUCCESS  = 2,
+	WB_RESIZE_STATUS_GENERAL_FAIL      = 3,
+};
+
 /* Query response result code */
 enum {
 	QUERY_RESULT_SUCCESS                    = 0x00,
@@ -578,6 +609,7 @@ struct ufs_dev_info {
 	bool    wb_buf_flush_enabled;
 	u8	wb_dedicated_lu;
 	u8      wb_buffer_type;
+	u16	ext_wb_sup;
 
 	bool	b_rpm_dev_flush_capable;
 	u8	b_presrv_uspc_en;
include/ufs/ufshcd.h +1 -0
index f56050ce9445..722307182630 100644
@@ -1471,6 +1471,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 				     struct scatterlist *sg_list, enum dma_data_direction dir);
 int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
 int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable);
+int ufshcd_wb_set_resize_en(struct ufs_hba *hba, enum wb_resize_en en_mode);
 int ufshcd_suspend_prepare(struct device *dev);
 int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);
 void ufshcd_resume_complete(struct device *dev);
Signature · 1 line
2.39.0
#1 lore raw

Documentation/ABI/testing/sysfs-driver-ufs Description: · line 1616

Quoted 9 lines · Huan Tang
Documentation/ABI/testing/sysfs-driver-ufs +9 -0
+What:		/sys/bus/platform/drivers/ufshcd/*/device_descriptor/ext_wb_sup
+What:		/sys/bus/platform/devices/*.ufs/device_descriptor/ext_wb_sup
+Date:		April 2025
+Contact:	Huan Tang <[email protected]>
+Description:
+		This file shows extended WriteBooster features supported by
+		the device.
+
+		The file is read only.

Please remove this attribute again. I don't think that it is useful to make the value of wExtendedWriteBoosterSupport available in sysfs. Additionally, wExtendedWriteBoosterSupport is a bitfield and hence exporting it directly violates the sysfs one-value-per-attribute rule.

Quoted 4 lines
Documentation/ABI/testing/sysfs-driver-ufs +4 -0
+What:		/sys/bus/platform/drivers/ufshcd/*/attributes/wb_resize_status
+What:		/sys/bus/platform/devices/*.ufs/attributes/wb_resize_status
+Date:		April 2025
+Contact:	Huan Tang <[email protected]>

Documentation/ABI/testing/sysfs-driver-ufs Description: · line 1663

Quoted 10 lines
Documentation/ABI/testing/sysfs-driver-ufs +10 -0
+Description:
+		The host can check the resize operation status of the WriteBooster
+		buffer by reading this attribute.
+
+		================  ========================================
+		idle              Resize operation is not issued
+		in_progress       Resize operation in progress
+		complete_success  Resize operation completed successfully
+		general_fail      Resize operation general failure
+		================  ========================================

Why "general_fail" instead of "general_failure"?

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

Quoted 5 lines
drivers/ufs/core/ufs-sysfs.c +5 -0
+static const char * const wb_resize_en_mode[] = {
+	[WB_RESIZE_EN_IDLE]		= "idle",
+	[WB_RESIZE_EN_DECREASE]		= "decrease",
+	[WB_RESIZE_EN_INCREASE]		= "increase",
+};

A minor comment: please remove one tab in front of "=" for the value assignments in the above array definition.

Quoted 7 lines
drivers/ufs/core/ufs-sysfs.c +7 -0
+static ssize_t wb_resize_hint_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	int ret;
+	u32 value;
+

drivers/ufs/core/ufs-sysfs.c static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) · line 1616

Quoted 10 lines
drivers/ufs/core/ufs-sysfs.c +10 -0
+	ret = wb_read_resize_attrs(hba,
+			QUERY_ATTR_IDN_WB_BUF_RESIZE_HINT, &value);
+	if (ret)
+		goto out;
+
+	ret = sysfs_emit(buf, "%s\n", ufs_wb_resize_hint_to_string(value));
+
+out:
+	return ret;
+}

The formatting of the above code is not compliant with the Linux kernel coding style guide. Please reformat this patch, e.g. with "git clang-format HEAD^".

Otherwise this patch looks good to me.

Thanks,

Bart.

author
#2 lore raw
Quoted 5 lines

Please remove this attribute again. I don't think that it is useful to make the value of wExtendedWriteBoosterSupport available in sysfs. Additionally, wExtendedWriteBoosterSupport is a bitfield and hence exporting it directly violates the sysfs one-value-per-attribute rule.

Quoted 9 lines

Why "general_fail" instead of "general_failure"?

A minor comment: please remove one tab in front of "=" for the value assignments in the above array definition.

The formatting of the above code is not compliant with the Linux kernel coding style guide. Please reformat this patch, e.g. with "git clang-format HEAD^".

Hi bart sir,

Thank you for your reply and comments! I have modified it as follows:
https://lore.kernel.org/all/[email protected]/

Best wishes to you !

Thanks
Huan