Skip to contentSkip to conversation

scsi: ufs: core: support WB buffer resize function

PATCH In review Lu Hongfei 2 participants 8 messages Sep 11, 2023 – Oct 20, 2023

Subsystems (2)
lore
Share & tools
lore

Lu Hongfei

author
#0 lore raw

v3 cover scsi: ufs: core: support WB buffer resize function

Hello,

In August 2023, the ballot for resizing the WriteBooster buffer has been approved.

This v3 series implements the function of controlling the WriteBooster buffer resize via sysfs that will be supported in UFS.

version 2 changes
-Using sysfs to control WB buffer resize instead of exception event handler -Removed content related to exception event
-Solved several issues that caused compilation errors

version 3 changes
-Removed UFS version number check
-Optimized several function names to make their definitions clear and easy to understand
-Fixed several formatting issues to avoid reporting warning information during compilation
-Removed the ufshcd_scsi_block_requests(), ufshcd_wait_for_doorbell_clr() and ufshcd_scsi_unblock_requests() calls in ufshcd_configure_wb_buf_resize.

------------------------------------------------------------------------
Lu Hongfei (3):
scsi: ufs: core: add wb buffer resize related attr_idn
scsi: ufs: core: Add sysfs attribute to control WB buffer resize
function
scsi: ufs: core: Add sysfs attributes to get the hint information and
status of WB buffer resize

 Documentation/ABI/testing/sysfs-driver-ufs | 52 ++++++++++++++++
 drivers/ufs/core/ufs-sysfs.c               | 70 ++++++++++++++++++++++
 drivers/ufs/core/ufshcd.c                  | 15 +++++
 include/ufs/ufs.h                          |  5 +-
 include/ufs/ufshcd.h                       |  1 +
 5 files changed, 142 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.0
author
#1 lore raw

PATCH v3 1/3 scsi: ufs: core: add wb buffer resize related attr_idn

As we know, the ballot for resizing the WriteBooster buffer has been approved.

UFS will support the WB buffer resize function, and UFS driver can add definitions for attr_idn related to this function to support this feature.

---
 include/ufs/ufs.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/ufs/ufs.h +4 -1
index 0cced88f4531..d174702ae960 100644
@@ -179,7 +179,10 @@ enum attr_idn {
 	QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST    = 0x1E,
 	QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE        = 0x1F,
 	QUERY_ATTR_IDN_EXT_IID_EN		= 0x2A,
-	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 */
Signature · 1 line
2.39.0
author
#2 lore raw

PATCH v3 2/3 scsi: ufs: core: Add sysfs attribute to control WB buffer resize function

In reply to Lu Hongfei

Add wb_buf_resize_control sysfs node, which allows the host to control the WB buffer resize function.

Add ufshcd_configure_wb_buf_resize() function which will write the bWriteBoosterBufferResizeEn attribute to enable WB buffer resize.

The detailed definition of the this node can be found in the sysfs documentation.

---
 Documentation/ABI/testing/sysfs-driver-ufs | 17 ++++++++++++
 drivers/ufs/core/ufs-sysfs.c               | 32 ++++++++++++++++++++++
 drivers/ufs/core/ufshcd.c                  | 15 ++++++++++
 include/ufs/ufshcd.h                       |  1 +
 4 files changed, 65 insertions(+)
Documentation/ABI/testing/sysfs-driver-ufs +17 -0
index 0c7efaf62de0..b8bd7e844cb0 100644
@@ -1437,6 +1437,23 @@ Description:
 		If avail_wb_buff < wb_flush_threshold, it indicates that WriteBooster buffer needs to
 		be flushed, otherwise it is not necessary.
 
+What:		/sys/bus/platform/drivers/ufshcd/*/wb_buf_resize_control
+What:		/sys/bus/platform/devices/*.ufs/wb_buf_resize_control
+Date:		Sept 2023
+Contact:	Lu Hongfei <[email protected]>
+Description:
+		The host can decrease or increase the WriteBooster Buffer size by setting
+		this file.
+
+		======  ======================================
+		   00h  Idle (There is no resize operation)
+		   01h  Decrease WriteBooster Buffer Size
+		   02h  Increase WriteBooster Buffer Size
+		Others  Reserved
+		======  ======================================
+
+		The file is write only.
+
 Contact:	Daniil Lunev <[email protected]>
 What:		/sys/bus/platform/drivers/ufshcd/*/capabilities/
 What:		/sys/bus/platform/devices/*.ufs/capabilities/
drivers/ufs/core/ufs-sysfs.c +32 -0
index c95906443d5f..c14da6770316 100644
@@ -329,6 +329,36 @@ static ssize_t wb_flush_threshold_store(struct device *dev,
 	return count;
 }
 
+static ssize_t wb_buf_resize_control_store(struct device *dev,
+					  struct device_attribute *attr,
+					  const char *buf, size_t count)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	unsigned int wb_buf_resize_op;
+
+	if (!ufshcd_is_wb_allowed(hba) || !hba->dev_info.wb_enabled) {
+		dev_err(dev, "The WB is not allowed or disabled!\n");
+		return -EINVAL;
+	}
+
+	if (!hba->dev_info.b_presrv_uspc_en) {
+		dev_err(dev, "The WB buf resize is not allowed!\n");
+		return -EINVAL;
+	}
+
+	if (kstrtouint(buf, 0, &wb_buf_resize_op))
+		return -EINVAL;
+
+	if (wb_buf_resize_op != 0x01 && wb_buf_resize_op != 0x02) {
+		dev_err(dev, "The operation %u is invalid!\n", wb_buf_resize_op);
+		return -EINVAL;
+	}
+
+	ufshcd_configure_wb_buf_resize(hba, wb_buf_resize_op);
+
+	return count;
+}
+
 static DEVICE_ATTR_RW(rpm_lvl);
 static DEVICE_ATTR_RO(rpm_target_dev_state);
 static DEVICE_ATTR_RO(rpm_target_link_state);
@@ -339,6 +369,7 @@ static DEVICE_ATTR_RW(auto_hibern8);
 static DEVICE_ATTR_RW(wb_on);
 static DEVICE_ATTR_RW(enable_wb_buf_flush);
 static DEVICE_ATTR_RW(wb_flush_threshold);
+static DEVICE_ATTR_WO(wb_buf_resize_control);
 
 static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_rpm_lvl.attr,
@@ -351,6 +382,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_wb_on.attr,
 	&dev_attr_enable_wb_buf_flush.attr,
 	&dev_attr_wb_flush_threshold.attr,
+	&dev_attr_wb_buf_resize_control.attr,
 	NULL
 };
 
drivers/ufs/core/ufshcd.c +15 -0
index c2df07545f96..7a9b9d941155 100644
@@ -6046,6 +6046,21 @@ static bool ufshcd_wb_need_flush(struct ufs_hba *hba)
 	return ufshcd_wb_presrv_usrspc_keep_vcc_on(hba, avail_buf);
 }
 
+int ufshcd_configure_wb_buf_resize(struct ufs_hba *hba, u32 resize_op)
+{
+	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, &resize_op);
+	if (ret)
+		dev_err(hba->dev,
+			"%s: Enable WB buf resize operation failed %d\n",
+			__func__, ret);
+	return ret;
+}
+
 static void ufshcd_rpm_dev_flush_recheck_work(struct work_struct *work)
 {
 	struct ufs_hba *hba = container_of(to_delayed_work(work),
include/ufs/ufshcd.h +1 -0
index 7d07b256e906..a2e5fddfc245 100644
@@ -1381,6 +1381,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 				     struct ufs_ehs *ehs_rsp, int sg_cnt,
 				     struct scatterlist *sg_list, enum dma_data_direction dir);
 int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
+int ufshcd_configure_wb_buf_resize(struct ufs_hba *hba, u32 resize_op);
 int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable);
 int ufshcd_suspend_prepare(struct device *dev);
 int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);
Signature · 1 line
2.39.0
author
#3 lore raw

PATCH v3 3/3 scsi: ufs: core: Add sysfs attributes to get the hint information and status of WB buffer resize

In reply to Lu Hongfei

The host can get the hint information and status of WB buffer resize through sysfs. To achieve this goal, two sysfs nodes have been added:
1. wb_buf_resize_hint
2. wb_buf_resize_status

The host can read wb_buf_resize_hint, obtain the hint information about which type of resize for wb buffer, and enable wb buffer resize based on the hint information. Considering that this process may take a long time, the host can confirm the resize status by reading wb_buf_resize_status.

The detailed definition of the two nodes can be found in the sysfs documentation.

---
 Documentation/ABI/testing/sysfs-driver-ufs | 35 ++++++++++++++++++++
 drivers/ufs/core/ufs-sysfs.c               | 38 ++++++++++++++++++++++
 2 files changed, 73 insertions(+)
Documentation/ABI/testing/sysfs-driver-ufs +35 -0
index b8bd7e844cb0..4b03f4b8cd49 100644
@@ -1454,6 +1454,41 @@ Description:
 
 		The file is write only.
 
+What:		/sys/bus/platform/drivers/ufshcd/*/wb_buf_resize_hint
+What:		/sys/bus/platform/devices/*.ufs/wb_buf_resize_hint
+Date:		Sept 2023
+Contact:	Lu Hongfei <[email protected]>
+Description:
+		wb_buf_resize_hint indicates hint information about which type of resize for
+		WriteBooster Buffer is recommended by the device.
+
+		======  ======================================
+		   00h  Recommend keep the buffer size
+		   01h  Recommend to decrease the buffer size
+		   02h  Recommend to increase the buffer size
+		Others: Reserved
+		======  ======================================
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/wb_buf_resize_status
+What:		/sys/bus/platform/devices/*.ufs/wb_buf_resize_status
+Date:		Sept 2023
+Contact:	Lu Hongfei <[email protected]>
+Description:
+		The host can check the Resize operation status of the WriteBooster Buffer
+		by reading this file.
+
+		======  ========================================
+		   00h  Idle (resize operation is not issued)
+		   01h  Resize operation in progress
+		   02h  Resize operation completed successfully
+		   03h  Resize operation general failure
+		Others  Reserved
+		======  ========================================
+
+		The file is read only.
+
 Contact:	Daniil Lunev <[email protected]>
 What:		/sys/bus/platform/drivers/ufshcd/*/capabilities/
 What:		/sys/bus/platform/devices/*.ufs/capabilities/
drivers/ufs/core/ufs-sysfs.c +38 -0
index c14da6770316..e416b9802ad3 100644
@@ -359,6 +359,40 @@ static ssize_t wb_buf_resize_control_store(struct device *dev,
 	return count;
 }
 
+static ssize_t wb_buf_resize_hint_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	u32 value;
+	u8 index = ufshcd_wb_get_query_index(hba);
+
+	if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+			QUERY_ATTR_IDN_WB_BUF_RESIZE_HINT, index, 0, &value)) {
+		dev_err(hba->dev, "Read WB Buffer Resize Hint info failed\n");
+		return  -EINVAL;
+	}
+
+	return sysfs_emit(buf, "%u\n", value);
+}
+
+static ssize_t wb_buf_resize_status_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	u32 value;
+	u8 index = ufshcd_wb_get_query_index(hba);
+
+	if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+			QUERY_ATTR_IDN_WB_BUF_RESIZE_STATUS, index, 0, &value)) {
+		dev_err(hba->dev, "Read WB Buffer Resize Status info failed\n");
+		return -EINVAL;
+	}
+
+	return sysfs_emit(buf, "%u\n", value);
+}
+
 static DEVICE_ATTR_RW(rpm_lvl);
 static DEVICE_ATTR_RO(rpm_target_dev_state);
 static DEVICE_ATTR_RO(rpm_target_link_state);
@@ -370,6 +404,8 @@ static DEVICE_ATTR_RW(wb_on);
 static DEVICE_ATTR_RW(enable_wb_buf_flush);
 static DEVICE_ATTR_RW(wb_flush_threshold);
 static DEVICE_ATTR_WO(wb_buf_resize_control);
+static DEVICE_ATTR_RO(wb_buf_resize_hint);
+static DEVICE_ATTR_RO(wb_buf_resize_status);
 
 static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_rpm_lvl.attr,
@@ -383,6 +419,8 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_enable_wb_buf_flush.attr,
 	&dev_attr_wb_flush_threshold.attr,
 	&dev_attr_wb_buf_resize_control.attr,
+	&dev_attr_wb_buf_resize_hint.attr,
+	&dev_attr_wb_buf_resize_status.attr,
 	NULL
 };
 
Signature · 1 line
2.39.0
author
#4 lore raw
In reply to Lu Hongfei
Quoted 30 lines · Lu Hongfei

Hello,

In August 2023, the ballot for resizing the WriteBooster buffer has been approved.

This v3 series implements the function of controlling the WriteBooster buffer resize via sysfs that will be supported in UFS.

version 2 changes

(quoted diff) +0 -3
-Using sysfs to control WB buffer resize instead of exception event handler
-Removed content related to exception event
-Solved several issues that caused compilation errors

version 3 changes

(quoted diff) +0 -2
-Removed UFS version number check
-Optimized several function names to make their definitions clear and easy

to understand
-Fixed several formatting issues to avoid reporting warning information during compilation
-Removed the ufshcd_scsi_block_requests(), ufshcd_wait_for_doorbell_clr() and ufshcd_scsi_unblock_requests() calls in ufshcd_configure_wb_buf_resize.

------------------------------------------------------------------------
Lu Hongfei (3):
scsi: ufs: core: add wb buffer resize related attr_idn
scsi: ufs: core: Add sysfs attribute to control WB buffer resize
function
scsi: ufs: core: Add sysfs attributes to get the hint information and
status of WB buffer resize

Quoted 6 lines
  Documentation/ABI/testing/sysfs-driver-ufs | 52 ++++++++++++++++
  drivers/ufs/core/ufs-sysfs.c               | 70 ++++++++++++++++++++++
  drivers/ufs/core/ufshcd.c                  | 15 +++++
  include/ufs/ufs.h                          |  5 +-
  include/ufs/ufshcd.h                       |  1 +
  5 files changed, 142 insertions(+), 1 deletion(-)

Hi Bart,

        Are there any new developments in this group of patches?

Thanks,

Hongfei

author
#5 lore raw
In reply to Lu Hongfei
Quoted 30 lines · Lu Hongfei

Hello,

In August 2023, the ballot for resizing the WriteBooster buffer has been approved.

This v3 series implements the function of controlling the WriteBooster buffer resize via sysfs that will be supported in UFS.

version 2 changes

(quoted diff) +0 -3
-Using sysfs to control WB buffer resize instead of exception event handler
-Removed content related to exception event
-Solved several issues that caused compilation errors

version 3 changes

(quoted diff) +0 -2
-Removed UFS version number check
-Optimized several function names to make their definitions clear and easy

to understand
-Fixed several formatting issues to avoid reporting warning information during compilation
-Removed the ufshcd_scsi_block_requests(), ufshcd_wait_for_doorbell_clr() and ufshcd_scsi_unblock_requests() calls in ufshcd_configure_wb_buf_resize.

------------------------------------------------------------------------
Lu Hongfei (3):
scsi: ufs: core: add wb buffer resize related attr_idn
scsi: ufs: core: Add sysfs attribute to control WB buffer resize
function
scsi: ufs: core: Add sysfs attributes to get the hint information and
status of WB buffer resize

Quoted 6 lines
  Documentation/ABI/testing/sysfs-driver-ufs | 52 ++++++++++++++++
  drivers/ufs/core/ufs-sysfs.c               | 70 ++++++++++++++++++++++
  drivers/ufs/core/ufshcd.c                  | 15 +++++
  include/ufs/ufs.h                          |  5 +-
  include/ufs/ufshcd.h                       |  1 +
  5 files changed, 142 insertions(+), 1 deletion(-)

Hi Bart,

Are there any new developments in this group of patches?

Thanks,

Hongfei.

#6 lore raw
Quoted 1 line · Lu Hongfei

Are there any new developments in this group of patches?

The JEDEC ballot about resizing the WriteBooster buffer has not yet been approved. Please wait with posting patches that implement support for a JEDEC feature until agreement has been reached in JEDEC.

Thanks,

Bart.

author
#7 lore raw
Quoted 11 lines · Bart Van Assche
Quoted 1 line · Lu Hongfei

Are there any new developments in this group of patches?

The JEDEC ballot about resizing the WriteBooster buffer has not yet been approved. Please wait with posting patches that implement support for a JEDEC feature until agreement has been reached in JEDEC.

Thanks,

Bart.

I got it.

Thanks,

Hongfei.