ufs: core: Add WB buffer resize support
Subsystems (2)
PATCH v7 1/1 ufs: core: Add WB buffer resize support
Follow JESD220G, Support WB buffer resize function through sysfs, the host can obtain resize hint and resize status, and enable the resize operation. To achieve this goals, three sysfs nodes have been added:
1. wb_resize_enable
2. wb_resize_hint
3. wb_resize_status
The detailed definition of the three nodes can be found in the sysfs documentation.
Changelog
===
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]/
--- Documentation/ABI/testing/sysfs-driver-ufs | 52 ++++++++ drivers/ufs/core/ufs-sysfs.c | 131 +++++++++++++++++++++ drivers/ufs/core/ufshcd.c | 15 +++ include/ufs/ufs.h | 27 ++++- include/ufs/ufshcd.h | 1 + 5 files changed, 225 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-ufs +52 -0
@@ -1604,3 +1604,55 @@ Description: prevent the UFS from frequently performing clock gating/ungating. The attribute is read/write. + +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 decrease or increase the WriteBooster Buffer size by setting + this attribute. + + ======== ====================================== + IDLE There is no resize operation + DECREASE Decrease WriteBooster buffer size + INCREASE Increase WriteBooster buffer size + Others Reserved + ======== ====================================== + + The attribute 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 + Others Reserved + ========= ====================================== + + The attribute 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 Idle (resize operation is not issued) + IN_PROGRESS Resize operation in progress + COMPLETE_SUCCESS Resize operation completed successfully + GENERAL_FAIL Resize operation general failure + Others Reserved + ================ ======================================== + + The attribute is read only.
drivers/ufs/core/ufs-sysfs.c +131 -0
167 lines not on this page · raw message
drivers/ufs/core/ufshcd.c +15 -0
@@ -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,u32 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) {
include/ufs/ufs.h +26 -1
@@ -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 */
@@ -454,6 +457,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 ,
include/ufs/ufshcd.h +1 -0
@@ -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,u32 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
Bart Van Assche
reviewerQuoted 15 lines · Huan Tang
Documentation/ABI/testing/sysfs-driver-ufs +7
-0@@ -1604,3 +1604,55 @@ Description: prevent the UFS from frequently performing clock gating/ungating. The attribute is read/write. + +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 decrease or increase the WriteBooster Buffer size by setting
Documentation/ABI/testing/sysfs-driver-ufs Description: · line 1623
Quoted 10 lines
Documentation/ABI/testing/sysfs-driver-ufs +10
-0+ this attribute. + + ======== ====================================== + IDLE There is no resize operation + DECREASE Decrease WriteBooster buffer size + INCREASE Increase WriteBooster buffer size + Others Reserved + ======== ====================================== + + The attribute is write only.
The description of the attribute contradicts the name of the attribute. Wouldn't wb_resize_enable be a better name for this attribute? Additionally, that name will be easier to recognize for anyone who is familiar with the UFS 4.1 standard.
To be consistent with other sysfs attributes, the names of the verbs should be changed from upper case to lower case and "Others - Reserved" should be left out. This comment also applies to the other attributes.
Documentation/ABI/testing/sysfs-driver-ufs Description: · line 1632
Quoted 9 lines
Documentation/ABI/testing/sysfs-driver-ufs +9
-0+static const char *ufs_wb_resize_hint_to_string(enum wb_resize_hint hint) +{ + switch (hint) { + case WB_RESIZE_HINT_KEEP: return "KEEP"; + case WB_RESIZE_HINT_DECREASE: return "DECREASE"; + case WB_RESIZE_HINT_INCREASE: return "INCREASE"; + default: return "UNKNOWN"; + } +}
The formatting of the above switch/case statement is not compliant with the Linux kernel coding style.
Thanks,
Bart.
Quoted 9 lines
The description of the attribute contradicts the name of the attribute. Wouldn't
wb_resize_enablebe a better name for this attribute? Additionally, that name will be easier to recognize for anyone who is familiar with the UFS 4.1 standard.To be consistent with other sysfs attributes, the names of the verbs should be changed from upper case to lower case and "Others - Reserved" should be left out. This comment also applies to the other attributes.
Quoted 12 lines
drivers/ufs/core/ufs-sysfs.c static const char *ufs_hs_gear_to_string(enum ufs_hs_gear_tag gear) · line 68
Quoted 9 lines
drivers/ufs/core/ufs-sysfs.c +9
-0+static const char *ufs_wb_resize_hint_to_string (enum wb_resize_hint hint) +{ +switch (hint) { +case WB_RESIZE_HINT_KEEP :return "KEEP" ; +case WB_RESIZE_HINT_DECREASE :return "DECREASE" ; +case WB_RESIZE_HINT_INCREASE :return "INCREASE" ; +default :return "UNKNOWN" ; + } +}The formatting of the above switch/case statement is not compliant with the Linux kernel coding style.
Bart sir,
Thank you for your reply .
I have modified it according to your comments, as follows:
https://lore.kernel.org/all/[email protected]/
Thank you for your patience, please help review again.
Thanks
Huan