scsi: ufs: add UFS Host Performance Booster(HPB) support
v3 cover scsi: ufs: add UFS Host Performance Booster(HPB) support
From: Bean Huo <[email protected]>
This patchset is just an RFC to add UFS HPB support in the upstream Linux. Before this series, I have submitted two versions [2] and [4] of UFS HPB driver in the community. The first two series HPB driver patchsets follow the Samsung HPB driver[1] approach, in which the HPB driver submits its HPB READ BUFFER and HPB WRITE BUFFER requests to the SCSI device->request_queueu to execute. Since this fly submission is unacceptable, in this RFC version, I changed it, and now the HPB requests will be directly submitted to UFS device, don't go backwards to SCSI mid-layer. In this approach, the L2P mapping entries loading path will be shorter, and the latency is smaller.
Regarding the UFS HPB feature, which is defined in Jedec Standard Universal Flash (UFS) Host Performance Booster (HPB) Extension Version 1.0, its purpose is to improve read performance by utilizing the host side memory. For the more detail information about HPB, you can refer to the HPB Spec. If the approach in this RFC patchset is accepted and feasible, it is necessary to add a document to detail HPB feature and its implementation later.
Based on the Avri's comments in the second patchset, to be reviewable patches, I shortened HPB driver, deleted HPB host control mode. Also, for change tracing, this patch is RFC v3, including the first two patchsets changes.
This series patch is still based on the [4] branch 5.8/scsi-queue
v2--v3
1. delete GET_BYTE_* and SHIFT_BYTE_* macro definition , using get_unaligned_*()/put_unaligned_*() instead. (Bart Van Assche)
2. change Kconfig help message (Randy Dunlap)
3. delete HPB host control mode code
4. change the way of submission of HPB request, and let the HPB driver directly submit HPB request to UFS.
v1--v2:
1. Rebased the patch on the [3] branch 5.8/scsi-queue
2. Optimized and simplified several functions
3. Add parameter read_threshold in HPB sysfs, by which the user can change read_threshold for the HPB host control mode
4. Add HPB memory limitation, let the user adjust its size according to the system memory capacity
Bean Huo (5):
scsi; ufs: add device descriptor for Host Performance Booster
scsi: ufs: make ufshcd_read_unit_desc_param() non-static func
scsi: ufs: add ufs_features parameter in structure ufs_dev_info
scsi: ufs: add unit and geometry parameters for HPB
scsi: ufs: UFS Host Performance Booster(HPB) driver
drivers/scsi/ufs/Kconfig | 62 + drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs.h | 15 + drivers/scsi/ufs/ufshcd.c | 245 +++- drivers/scsi/ufs/ufshcd.h | 28 +- drivers/scsi/ufs/ufshpb.c | 2767 +++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshpb.h | 423 ++++++ 7 files changed, 3534 insertions(+), 7 deletions(-) create mode 100644 drivers/scsi/ufs/ufshpb.c create mode 100644 drivers/scsi/ufs/ufshpb.h
Signature · 1 line
2.17.1
RFC PATCH v3 1/5 scsi; ufs: add device descriptor for Host Performance Booster
From: Bean Huo <[email protected]>
Add HPB related attributes in devivce descriptor. HPB support is specified by Bit7 of bUFSFeatureSupport, HPB version is indicated by wHPBVersion and the HPB Control Mode is specified by bHPBControl in UFS device descriptor.
--- drivers/scsi/ufs/ufs.h | 6 ++++++ drivers/scsi/ufs/ufshcd.c | 11 +++++++++++ 2 files changed, 17 insertions(+)
drivers/scsi/ufs/ufs.h +6 -0
@@ -258,6 +258,8 @@ enum device_desc_param {DEVICE_DESC_PARAM_PSA_MAX_DATA =0x25 ,DEVICE_DESC_PARAM_PSA_TMT =0x29 ,DEVICE_DESC_PARAM_PRDCT_REV =0x2A , +DEVICE_DESC_PARAM_HPB_VER =0x40 , + DEVICE_DESC_PARAM_HPB_CTRL_MODE = 0x42, };/* Interconnect descriptor parameters offsets in bytes*/
@@ -537,6 +539,10 @@ struct ufs_dev_info {u8 *model;u16 wspecversion;u32 clk_gating_wait_us; +/* HPB Version */ +u16 hpb_ver; +/* bHPBControl */ +u8 hpb_control_mode; };/**
drivers/scsi/ufs/ufshcd.c +11 -0
@@ -6627,6 +6627,17 @@ static int ufs_get_device_desc(struct ufs_hba *hba) goto out; } +if (desc_buf[DEVICE_DESC_PARAM_UFS_FEAT ] &0x80 ) { + hba->dev_info.hpb_control_mode = + desc_buf[DEVICE_DESC_PARAM_HPB_CTRL_MODE ]; + hba->dev_info.hpb_ver = + (u16) (desc_buf[DEVICE_DESC_PARAM_HPB_VER ] <<8 ) | + desc_buf[DEVICE_DESC_PARAM_HPB_VER +1 ]; +dev_info (hba->dev,"HPB Version: 0x%2x\n" , + hba->dev_info.hpb_ver); +dev_info (hba->dev,"HPB control mode: %d\n" , + hba->dev_info.hpb_control_mode); + }/* * getting vendor (manufacturerID) and Bank Index in big endian * format
Signature · 1 line
2.17.1
RFC PATCH v3 2/5 scsi: ufs: make ufshcd_read_unit_desc_param() non-static func
In reply to [email protected]From: Bean Huo <[email protected]>
HPB driver needs to read unit descriptors through ufshcd_read_unit_desc_param(), make it an extern Function.
--- drivers/scsi/ufs/ufshcd.c | 8 +++----- drivers/scsi/ufs/ufshcd.h | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/scsi/ufs/ufshcd.c +3 -5
@@ -3326,11 +3326,9 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,* * Return 0 in case of success, non-zero otherwise */ -static inline int ufshcd_read_unit_desc_param (struct ufs_hba *hba, -int lun, -enum unit_desc_param param_offset, -u8 *param_read_buf, -u32 param_size) +int ufshcd_read_unit_desc_param (struct ufs_hba *hba,int lun, +enum unit_desc_param param_offset, +u8 *param_read_buf,u32 param_size) {/* * Unit descriptors are only available for general purpose LUs (LUN id
drivers/scsi/ufs/ufshcd.h +4 -1
@@ -856,7 +856,10 @@ extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,extern int ufshcd_dme_get_attr (struct ufs_hba *hba,u32 attr_sel,u32 *mib_val,u8 peer);extern int ufshcd_config_pwr_mode (struct ufs_hba *hba, -struct ufs_pa_layer_attr *desired_pwr_mode); +struct ufs_pa_layer_attr *desired_pwr_mode); +extern int ufshcd_read_unit_desc_param (struct ufs_hba *hba,int lun, +enum unit_desc_param param_offset, +u8 *param_read_buf,u32 param_size);/* UIC command interfaces for DME primitives */ #define DME_LOCAL 0
Signature · 1 line
2.17.1
RFC PATCH v3 3/5 scsi: ufs: add ufs_features parameter in structure ufs_dev_info
In reply to [email protected]From: Bean Huo <[email protected]>
Make a copy of bUFSFeaturesSupport, name it ufs_features, add it to structure ufs_dev_info.
--- drivers/scsi/ufs/ufs.h | 2 ++ drivers/scsi/ufs/ufshcd.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/scsi/ufs/ufs.h +2 -0
@@ -543,6 +543,8 @@ struct ufs_dev_info {u16 hpb_ver;/* bHPBControl */ u8 hpb_control_mode; +/* bUFSFeaturesSupport */ +u8 ufs_features; };/**
drivers/scsi/ufs/ufshcd.c +2 -0
@@ -6625,6 +6625,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) goto out; } + dev_info->ufs_features = desc_buf[DEVICE_DESC_PARAM_UFS_FEAT ]; +if (desc_buf[DEVICE_DESC_PARAM_UFS_FEAT ] &0x80 ) { hba->dev_info.hpb_control_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CTRL_MODE ];
Signature · 1 line
2.17.1
RFC PATCH v3 4/5 scsi: ufs: add unit and geometry parameters for HPB
In reply to [email protected]From: Bean Huo <[email protected]>
Add HPB related parameters introduced in Unit Descriptor and Geometry Descriptor.
--- drivers/scsi/ufs/ufs.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/scsi/ufs/ufs.h +7 -0
@@ -219,6 +219,9 @@ enum unit_desc_param {UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT =0x18 ,UNIT_DESC_PARAM_CTX_CAPABILITIES =0x20 ,UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 =0x22 , +UNIT_DESC_PARAM_HPB_MAX_ACTIVE_REGIONS =0x23 , +UNIT_DESC_PARAM_HPB_PIN_REGION_START_OFFSET =0x25 , + UNIT_DESC_PARAM_HPB_NUM_PIN_REGIONS = 0x27, };/* Device descriptor parameters offsets in bytes*/
@@ -304,6 +307,10 @@ enum geometry_desc_param {GEOMETRY_DESC_PARAM_ENM4_MAX_NUM_UNITS =0x3E ,GEOMETRY_DESC_PARAM_ENM4_CAP_ADJ_FCTR =0x42 ,GEOMETRY_DESC_PARAM_OPT_LOG_BLK_SIZE =0x44 , +GEOMETRY_DESC_PARAM_HPB_REGION_SIZE =0x48 , +GEOMETRY_DESC_PARAM_HPB_NUMBER_LU =0x49 , +GEOMETRY_DESC_PARAM_HPB_SUBREGION_SIZE =0x4A , + GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGIONS = 0x4B, };/* Health descriptor parameters offsets in bytes*/
Signature · 1 line
2.17.1
RFC PATCH v3 5/5 scsi: ufs: UFS Host Performance Booster(HPB) driver
In reply to [email protected]From: Bean Huo <[email protected]>
This patch is to add support for the UFS Host Performance Booster (HPB v1.0), which is used to improve UFS read performance, especially for the random read.
NAND flash-based storage devices, including UFS, have mechanisms to translate logical addresses of requests to the corresponding physical addresses of the flash storage. Traditionally this L2P mapping data is loaded to the internal SRAM in the storage controller. When the capacity of storage is larger, a larger size of SRAM for the L2P map data is required. Since increased SRAM size affects the manufacturing cost significantly, it is not cost-effective to allocate all the amount of SRAM needed to keep all the Logical-address to Physical-address (L2P) map data. Therefore, L2P map data, which is required to identify the physical address for the requested IOs, can only be partially stored in SRAM from NAND flash. Due to this partial loading, accessing the flash address area where the L2P information for that address is not loaded in the SRAM can result in serious performance degradation.
The HPB is a software solution for the above problem, which uses the host’s system memory as a cache for the FTL L2P mapping table. It does not need additional hardware support from the host side. By using HPB, the L2P mapping table can be read from host memory and stored in host-side memory. while reading the operation, the corresponding L2P information will be sent to the UFS device along with the reading request. Since the L2P entry is provided in the read request, UFS device does not have to load L2P entry from flash memory. This will significantly improve random read performance.
--- drivers/scsi/ufs/Kconfig | 62 + drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufshcd.c | 234 +++- drivers/scsi/ufs/ufshcd.h | 23 + drivers/scsi/ufs/ufshpb.c | 2767 +++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshpb.h | 423 ++++++ 6 files changed, 3504 insertions(+), 6 deletions(-) create mode 100644 drivers/scsi/ufs/ufshpb.c create mode 100644 drivers/scsi/ufs/ufshpb.h
drivers/scsi/ufs/Kconfig +62 -0
@@ -160,3 +160,65 @@ config SCSI_UFS_BSG Select this if you need a bsg device node for your UFS controller. If unsure, say N. + +config SCSI_UFSHPB + bool "UFS Host Performance Booster (EXPERIMENTAL)" + depends on SCSI_UFSHCD + help + NAND flash-based storage devices, including UFS, have mechanisms to + translate logical addresses of the IO requests to the corresponding + physical addresses of the flash storage. Traditionally, this L2P + mapping data is loaded to the internal SRAM in the storage controller. + When the capacity of storage is larger, a larger size of SRAM for the + L2P map data is required. Since increased SRAM size affects the + manufacturing cost significantly, it is not cost-effective to allocate + all the amount of SRAM needed to keep all the Logical-address to + Physical-address (L2P) map data. Therefore, L2P map data, which is + required to identify the physical address for the requested IOs, can + only be partially stored in SRAM from NAND flash. Due to this partial + loading, accessing the flash address area where the L2P information + for that address is not loaded in the SRAM can result in serious + performance degradation. + + UFS Host Performance Booster (HPB) is a software solution for the + above problem, which uses the host side system memory as a cache for + the FTL L2P mapping table. It does not need additional hardware + support from the host side. By using HPB, the L2P mapping table can be + read from host memory and stored in host-side memory. when performing + the read operation, the corresponding L2P information will be sent to + the UFS device along with the reading request. Since the L2P entry is + provided in the read request, UFS device does not have to load L2P + entry from flash memory to UFS internal SRAM. This will significantly + improve the read performance. + + When selected, this feature will be built in the UFS driver. + + If in doubt, say N. + +config UFSHPB_MAX_MEM_SIZE + int "UFS HPB maximum memory size per controller (in MiB)" + depends on SCSI_UFSHPB + default 128 + range 0 65536 + help + This parameter defines the maximum UFS HPB memory/cache size in the + host system. The recommended HPB cache size by the UFS device can be + calculated from bHPBRegionSize and wDeviceMaxActiveHPBRegions. The + reference formula can be + + (bHPBRegionSize(in KB) / 4KB) * 8 * wDeviceMaxActiveHPBRegions. + + The HPB cache in the host system is used to contain L2P mapping + entries. If the allocated HPB cache size is lower than what calculated + by the above formula, the use of HPB feature may provide lower + performance advantage. But the system memory resource has the + limitation, we can not let HPB driver allocate its cache at will + according to the UFS device recommendation, so an appropriate size of + the cache for HPB should be specified before you choose to use HPB, + then please enter a non-zero positive integer value. + + Nevertheless, if you want to leave this to the HPB driver, and let the + HPB driver allocate the HPB cache based on the recommendation of the + UFS device. Just give 0 value to this parameter. + + Leave the default value if unsure.
drivers/scsi/ufs/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +ufshcd-core-$(CONFIG_SCSI_UFSHPB) += ufshpb.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o
drivers/scsi/ufs/ufshcd.c +228 -6
317 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +23 -0
@@ -70,6 +70,7 @@#include "ufs.h" #include "ufshci.h" +#include "ufshpb.h" #define UFSHCD "ufshcd"#define UFSHCD_DRIVER_VERSION "0.2"
@@ -162,6 +163,17 @@ struct ufs_pm_lvl_states {enum uic_link_state link_state; }; +struct ufs_req { +struct request *req; +u8 cmd[16 ]; +u8 cmd_len; +u8 *sense_buffer; +u8 lun; +unsigned int payload_len; +struct sg_table sgt; +enum dma_data_direction cmd_dir; +struct completion *complete; +};/** * struct ufshcd_lrb - local reference block * @utr_descriptor_ptr: UTRD address of the command
@@ -206,6 +218,7 @@ struct ufshcd_lrb {bool intr_cmd;ktime_t issue_time_stamp;ktime_t compl_time_stamp; +struct ufs_req *ureq;bool req_abort_skip; };
@@ -727,6 +740,15 @@ struct ufs_hba {struct device bsg_dev;struct request_queue *bsg_queue; + +#if defined(CONFIG_SCSI_UFSHPB ) +enum UFSHPB_STATE ufshpb_state; +struct ufshpb_geo hpb_geo; +struct ufshpb_lu *ufshpb_lup[32 ]; +struct delayed_work ufshpb_init_work; +struct work_struct ufshpb_eh_work; +struct scsi_device *sdev_ufs_lu[32 ]; +#endif };/* Returns true if clocks can be gated. Otherwise false */
@@ -962,6 +984,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, u8 *desc_buff, int *buff_len, enum query_opcode desc_op); +int ufshcd_exec_internal_req (struct ufs_hba *hba,struct ufs_req *ureq);/* Wrapper functions for safely calling variant operations */ static inline const char *ufshcd_get_var_name (struct ufs_hba *hba) {
drivers/scsi/ufs/ufshpb.c new file +2767 -0
2,558 lines not on this page · raw message
drivers/scsi/ufs/ufshpb.h new file +423 -0
423 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.