scsi: ufs: ufsfbo: Introduce File Based Optimization feature
PATCH 1/1 scsi: ufs: ufsfbo: Introduce File Based Optimization feature
From: lijiaming3 <[email protected]>
Implement File Based Optimization initialization and add sysfs interface.
Stoage devices have a long lifespan. Device performance over its lifespan is not constant and may deteriorate over time
This feature describes a method to improve the performance regression. The host needs to provide File System information to storage device first. Based on that information device analyzes the file system data and provides the host the level of performance regression. The host then may instruct the device to execute optimization procedure to improve the regression level.
--- arch/arm64/configs/defconfig | 1 + drivers/scsi/ufs/Kconfig | 9 + drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs.h | 13 + drivers/scsi/ufs/ufsfbo.c | 1007 ++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufsfbo.h | 143 +++++ drivers/scsi/ufs/ufshcd.c | 15 + drivers/scsi/ufs/ufshcd.h | 7 +- 8 files changed, 1195 insertions(+), 1 deletion(-) create mode 100644 drivers/scsi/ufs/ufsfbo.c create mode 100644 drivers/scsi/ufs/ufsfbo.h
arch/arm64/configs/defconfig +1 -0
@@ -289,6 +289,7 @@ CONFIG_SCSI_UFSHCD_PLATFORM=y CONFIG_SCSI_UFS_QCOM=m CONFIG_SCSI_UFS_HISI=y CONFIG_SCSI_UFS_EXYNOS=y +CONFIG_SCSI_UFS_FBO=y CONFIG_ATA=y CONFIG_SATA_AHCI=y CONFIG_SATA_AHCI_PLATFORM=y
drivers/scsi/ufs/Kconfig +9 -0
@@ -199,3 +199,12 @@ config SCSI_UFS_FAULT_INJECTION help Enable fault injection support in the UFS driver. This makes it easier to test the UFS error handler and abort handler. + +config SCSI_UFS_FBO + bool "Support UFS File-based Optimization" + depends on SCSI_UFSHCD + help + The UFS FBO feature improves Sequential read performance. The Host can + send the LBA to device. The device will return a fragmented state. It + is up to the host to decide whether to defrag. After defragment, + Sequential read performance is improved
drivers/scsi/ufs/Makefile +1 -0
@@ -9,6 +9,7 @@ ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o ufshcd-core-$(CONFIG_SCSI_UFS_HPB) += ufshpb.o +ufshcd-core-$(CONFIG_SCSI_UFS_FBO) += ufsfbo.o ufshcd-core-$(CONFIG_SCSI_UFS_FAULT_INJECTION) += ufs-fault-injection.o obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o tc-dwc-g210.o
drivers/scsi/ufs/ufs.h +13 -0
@@ -170,6 +170,7 @@ enum desc_idn {QUERY_DESC_IDN_GEOMETRY =0x7 ,QUERY_DESC_IDN_POWER =0x8 ,QUERY_DESC_IDN_HEALTH =0x9 , +QUERY_DESC_IDN_FBO =0xA , QUERY_DESC_IDN_MAX, };
@@ -310,6 +311,17 @@ enum health_desc_param { HEALTH_DESC_PARAM_LIFE_TIME_EST_B = 0x4, }; +/* FBO descriptor parameters offsets in bytes */ +enum fbo_desc_param { +FBO_DESC_PARAM_LEN =0x0 , +FBO_DESC_PARAM_VERSION =0x1 , +FBO_DESC_PARAM_REC_LBA_RANGE_SIZE =0x3 , +FBO_DESC_PARAM_MAX_LBA_RANGE_SIZE =0x7 , +FBO_DESC_PARAM_MIN_LBA_RANGE_SIZE =0xB , +FBO_DESC_PARAM_MAX_LBA_RANGE_CONUT =0xF , +FBO_DESC_PARAM_MAX_LBA_RANGE_ALIGNMENT =0x10 , +}; +/* WriteBooster buffer mode */ enum {WB_BUF_MODE_LU_DEDICATED =0x0 ,
@@ -340,6 +352,7 @@ enum {enum {UFS_DEV_HPB_SUPPORT =BIT (7 ),UFS_DEV_WRITE_BOOSTER_SUP =BIT (8 ), +UFS_DEV_FBO_SUP =BIT (17 ), };#define UFS_DEV_HPB_SUPPORT_VERSION 0x310
drivers/scsi/ufs/ufsfbo.c new file +1007 -0
1,007 lines not on this page · raw message
drivers/scsi/ufs/ufsfbo.h new file +143 -0
143 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.c +15 -0
@@ -4956,6 +4956,14 @@ static void ufshcd_hpb_configure(struct ufs_hba *hba, struct scsi_device *sdev)ufshpb_init_hpb_lu (hba, sdev); } +static void ufshcd_fbo_configure (struct ufs_hba *hba,struct scsi_device *sdev) +{ +#ifdef CONFIG_SCSI_UFS_FBO +if (sdev->lun ==0 ) + hba->fbo.sdev_ufs_lu = sdev; +#endif +} +/** * ufshcd_slave_configure - adjust SCSI device configurations * @sdev: pointer to SCSI device
@@ -4986,6 +4994,7 @@ static int ufshcd_slave_configure(struct scsi_device *sdev) sdev->silence_suspend =1 ;ufshcd_crypto_setup_rq_keyslot_manager (hba, q); +ufshcd_fbo_configure (hba, sdev);return 0 ; }
@@ -8005,6 +8014,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)/* Probe and add UFS logical units */ ret =ufshcd_add_lus (hba); +#ifdef CONFIG_SCSI_UFS_FBO +ufsfbo_init (hba); +#endif out:/* * If we failed to initialize the device or the device is not
@@ -9257,6 +9269,9 @@ void ufshcd_remove(struct ufs_hba *hba)if (hba->sdev_ufs_device)ufshcd_rpm_get_sync (hba);ufs_bsg_remove (hba); +#if defined(SCSI_CONFIG_FBO ) +ufsfbo_remove (hba); +#endif ufshpb_remove (hba);ufs_sysfs_remove_nodes (hba->dev);blk_cleanup_queue (hba->tmf_queue);
drivers/scsi/ufs/ufshcd.h +6 -1
@@ -47,7 +47,9 @@#include "ufs.h" #include "ufs_quirks.h" #include "ufshci.h" - +#ifdef CONFIG_SCSI_UFS_FBO +#include "ufsfbo.h" +#endif #define UFSHCD "ufshcd"#define UFSHCD_DRIVER_VERSION "0.2"
@@ -916,6 +918,9 @@ struct ufs_hba {struct dentry *debugfs_root;struct delayed_work debugfs_ee_work;u32 debugfs_ee_rate_limit_ms; +#endif +#ifdef CONFIG_SCSI_UFS_FBO +struct ufsfbo_dev fbo;#endif u32 luns_avail;bool complete_put;
Signature · 1 line
2.37.1
Quoted 86 lines · Jiaming Li
From: lijiaming3 <[email protected]>
Implement File Based Optimization initialization and add sysfs interface.
Stoage devices have a long lifespan. Device performance over its lifespan is not constant and may deteriorate over time
This feature describes a method to improve the performance regression.
The host needs to provide File System information to storage device first. Based on that information device analyzes the file system data and provides the host the level of performance regression. The host then may instruct the device to execute optimization procedure to improve the regression level.Signed-off-by lijiaming3 <[email protected]>---
arch/arm64/configs/defconfig | 1 +
drivers/scsi/ufs/Kconfig | 9 +
drivers/scsi/ufs/Makefile | 1 +
drivers/scsi/ufs/ufs.h | 13 +
drivers/scsi/ufs/ufsfbo.c | 1007
++++++++++++++++++++++++++++++++++drivers/scsi/ufs/ufsfbo.h | 143 +++++ drivers/scsi/ufs/ufshcd.c | 15 + drivers/scsi/ufs/ufshcd.h | 7 +- 8 files changed, 1195 insertions(+), 1 deletion(-)create mode 100644
drivers/scsi/ufs/ufsfbo.c
create mode 100644drivers/scsi/ufs/ufsfbo.harch/arm64/configs/defconfig +0
-0@@ -289,6 +289,7 @@ CONFIG_SCSI_UFSHCD_PLATFORM=yCONFIG_SCSI_UFS_QCOM=m
CONFIG_SCSI_UFS_HISI=y
CONFIG_SCSI_UFS_EXYNOS=y
+CONFIG_SCSI_UFS_FBO=y
CONFIG_ATA=y
CONFIG_SATA_AHCI=y
CONFIG_SATA_AHCI_PLATFORM=ydrivers/scsi/ufs/Kconfig +0
-0@@ -199,3 +199,12 @@ config SCSI_UFS_FAULT_INJECTIONhelp
Enable fault injection support in the UFS driver. This makes it easier
to test the UFS error handler and abort handler.drivers/scsi/ufs/Kconfig +6
-0+ +config SCSI_UFS_FBO + bool "Support UFS File-based Optimization" + depends on SCSI_UFSHCD + help + The UFS FBO feature improves Sequential read performance.The Host can
+ send the LBA to device. The device will return a fragmented state. It
+ is up to the host to decide whether to defrag. After defragment,
+ Sequential read performance is improved
\ No newline at end of filedrivers/scsi/ufs/Makefile +0
-0@@ -9,6 +9,7 @@ ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o
ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o ufshcd-core-$(CONFIG_SCSI_UFS_HPB) += ufshpb.o +ufshcd-core-$(CONFIG_SCSI_UFS_FBO) += ufsfbo.o ufshcd-core-$(CONFIG_SCSI_UFS_FAULT_INJECTION) += ufs-fault- injection.o
obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o tc-dwc-g210.odrivers/scsi/ufs/ufs.h +0
-0
drivers/scsi/ufs/ufs.h enum desc_idn { · line 173
Quoted 4 lines
drivers/scsi/ufs/ufs.h +1
-0@@ -170,6 +170,7 @@ enum desc_idn { QUERY_DESC_IDN_GEOMETRY = 0x7, QUERY_DESC_IDN_POWER = 0x8, QUERY_DESC_IDN_HEALTH = 0x9, + QUERY_DESC_IDN_FBO = 0xA,
Hi Jiaming,
Is this a UFS extended standard or vendor specific feature?
Hi Bean
This is a UFS extended feature in UFS4.0 JEDEC Standard Thanks
-----邮件原件-----
发件人: Bean Huo <[email protected]>
发送时间: 2022年8月24日 22:17
收件人: Jiaming Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected] 抄送: [email protected]; [email protected]; 李佳铭 <[email protected]>
主题: [External Mail]Re: [PATCH] scsi: ufs: ufsfbo: Introduce File Based Optimization feature
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。
Quoted 82 lines · Jiaming Li
From: lijiaming3 <[email protected]>
Implement File Based Optimization initialization and add sysfs interface.
Stoage devices have a long lifespan. Device performance over its lifespan is not constant and may deteriorate over time
This feature describes a method to improve the performance regression. The host needs to provide File System information to storage device first. Based on that information device analyzes the file system data and provides the host the level of performance regression. The host then may instruct the device to execute optimization procedure to improve the regression level.
Signed-off-by lijiaming3 <[email protected]>--- arch/arm64/configs/defconfig | 1 + drivers/scsi/ufs/Kconfig | 9 + drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs.h | 13 + drivers/scsi/ufs/ufsfbo.c | 1007 ++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufsfbo.h | 143 +++++ drivers/scsi/ufs/ufshcd.c | 15 + drivers/scsi/ufs/ufshcd.h | 7 +- 8 files changed, 1195 insertions(+), 1 deletion(-) create mode100644
drivers/scsi/ufs/ufsfbo.ccreate mode 100644drivers/scsi/ufs/ufsfbo.h(quoted diff) +0
-0b/arch/arm64/configs/defconfig index
4972a81d40d6..1363c237b6f3100644arch/arm64/configs/defconfig +0
-0@@ -289,6 +289,7 @@ CONFIG_SCSI_UFSHCD_PLATFORM=y
CONFIG_SCSI_UFS_QCOM=mCONFIG_SCSI_UFS_HISI=yCONFIG_SCSI_UFS_EXYNOS=yarch/arm64/configs/defconfig +1
-0+CONFIG_SCSI_UFS_FBO=y CONFIG_ATA=y CONFIG_SATA_AHCI=y CONFIG_SATA_AHCI_PLATFORM=ydrivers/scsi/ufs/Kconfig index renamed from drivers/scsi/ufs/Kconfig +0
-0
432df76e6318..57b0e8b14543100644drivers/scsi/ufs/Kconfig +0
-0@@ -199,3 +199,12 @@ config SCSI_UFS_FAULT_INJECTION help Enable fault injection support in the UFS driver. This makesit easier
to test the UFS error handler and abort handler.drivers/scsi/ufs/Kconfig +6
-0+ +config SCSI_UFS_FBO + bool "Support UFS File-based Optimization" + depends on SCSI_UFSHCD + help + The UFS FBO feature improves Sequential read performance.The Host can
+ send the LBA to device. The device will return a fragmented
state. It
+ is up to the host to decide whether to defrag. After
defragment,drivers/scsi/ufs/Kconfig +1
-0+ Sequential read performance is improveddrivers/scsi/ufs/Makefile +0
-0@@ -9,6 +9,7 @@ ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o
ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o ufshcd-core-$(CONFIG_SCSI_UFS_HPB) += ufshpb.o +ufshcd-core-$(CONFIG_SCSI_UFS_FBO) += ufsfbo.oufshcd-core-$(CONFIG_SCSI_UFS_FAULT_INJECTION) += ufs-fault-
injection.oobj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o
tc-dwc-g210.o diff --gita/drivers/scsi/ufs/ufs.hb/drivers/scsi/ufs/ufs.hindex8c6b38b1b142..b750ce3f7de9100644
drivers/scsi/ufs/ufs.h enum desc_idn { · line 173
Quoted 4 lines
drivers/scsi/ufs/ufs.h +1
-0@@ -170,6 +170,7 @@ enum desc_idn {QUERY_DESC_IDN_GEOMETRY =0x7 ,QUERY_DESC_IDN_POWER =0x8 ,QUERY_DESC_IDN_HEALTH =0x9 , + QUERY_DESC_IDN_FBO = 0xA,
Hi Jiaming,
Is this a UFS extended standard or vendor specific feature?
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
Quoted 2 lines · 李佳铭
Hi Bean
This is a UFS extended feature in UFS4.0 JEDEC Standard
thanks, I see, it's officially released.
I think you should rebase your driver, the ufs driver has been taken out of the scsi folder.
Kind regards,
Bean
Quoted 1 line · Bean Huo
Is this a UFS extended standard or vendor specific feature?
Hi Bean,
This feature has been standardized by JEDEC. My feedback to the sponsors of this feature a few months ago was that FBO will become obsolete once all UFS devices support Zoned storage for UFS. The FBO standard defines an interface for telling UFS devices about the relationship between LBAs and files. This allows UFS devices to defragment files. UFS devices won't need that information for zoned LUNs since for zoned LUNs the host software will be responsible for ensuring that files occupy a contiguous range of LBAs.
Thanks,
Bart.
Quoted 1 line · Jiaming Li
+#include "
../../../block/blk.h"
Without having taken a look at the rest of this patch, including a block driver private header file in the UFS driver is unacceptable.
drivers/scsi/ufs/ufsfbo.h line 28
Quoted 4 lines
drivers/scsi/ufs/ufsfbo.h new file +4
-0+#define FBO_INFO_MSG(fbo, msg, args...) do { \ + if (fbo->fbo_debug) \ + pr_info("[info]%s:%d:" msg "\n", __func__, __LINE__, ##args); \ + } while (0)
Please use pr_debug() instead.
drivers/scsi/ufs/ufsfbo.h line 31
Quoted 2 lines
drivers/scsi/ufs/ufsfbo.h new file +2
-0+#define FBO_ERR_MSG(msg, args...) \ + pr_err("[err]%s:%d:" msg "\n", __func__, __LINE__, ##args)
Please use pr_err() directly and remove the function name and line numbers from error messages.
drivers/scsi/ufs/ufsfbo.h line 34
Quoted 2 lines
drivers/scsi/ufs/ufsfbo.h new file +2
-0+#define FBO_WARN_MSG(msg, args...) \ + pr_warn("[warn]%s:%d:" msg "\n", __func__, __LINE__, ##args)
Please use pr_warn directly and remove function name and line numbers from warning messages.
Thanks,
Bart.
Hi,
Quoted 4 lines
From: lijiaming3 <[email protected]>
Implement File Based Optimization initialization and add sysfs interface.
Quoted 8 lines
Stoage devices have a long lifespan. Device performance over its lifespan is not constant and may deteriorate over time
This feature describes a method to improve the performance regression. The host needs to provide File System information to storage device first. Based on that information device analyzes the file system data and provides the host the level of performance regression. The host then may instruct the device to execute optimization procedure to improve the regression level.
You might want to break this one long patch into a series of smaller patches. One option is to do it per-functional flows: Init flow, analysis phase, and defrag phase. In your cover letter you might want to elaborate what this feature is all about, And that your design expect a user-space companion that analyze the files. Which is a good place to share a reference to an open source code that does that.
Quoted 1 line
+void
ufsfbo_init(struct ufs_hba *hba)
Maybe ufshbo_probe to note that you are probing the device for this feature?
drivers/scsi/ufs/ufsfbo.c line 517
Quoted 8 lines
drivers/scsi/ufs/ufsfbo.c new file +8
-0+{ +struct ufsfbo_dev *fbo; +int ret =0 ; + + fbo = &hba->fbo; + fbo->hba = hba; + + ret =ufsfbo_get_fbo_support_state (fbo);
You can save reading the device descriptor, if you would call ufsfbo_init from ufs_get_device_desc, Like ufshcd_wb_probe() does.
Quoted 4 lines
drivers/scsi/ufs/ufsfbo.c new file +4
-0+if (ret) { +FBO_ERR_MSG ("NOT Support FBO. ret(%d)" , ret); +return ; + }
drivers/scsi/ufs/ufsfbo.c line 531
Quoted 10 lines
drivers/scsi/ufs/ufsfbo.c new file +10
-0+ ret =ufsfbo_get_fbo_desc_info (fbo); +if (ret) { +FBO_ERR_MSG ("Failed getting fbo info. ret(%d)" , ret); +return ; + } + fbo->fbo_debug = false; + fbo->block_suspend = false; + +if (ufshcd_is_auto_hibern8_supported (fbo->hba)) + fbo->is_auto_enabled = true;
All this power management control code is not needed IMO.
drivers/scsi/ufs/ufsfbo.c line 533
Quoted 2 lines
drivers/scsi/ufs/ufsfbo.c new file +2
-0+ + ret =ufsfbo_create_sysfs (fbo);
You might want to consider splitting your sysfs according to:
- FBOWritebuffer & FBOReadbuffer - part of sdev_group it will allow defragmenting files across all luns.
- the rest per hba
Review
Quoted 4 lines
(quoted diff) +4
-0+static ssize_t ufsfbo_sysfs_show_debug(struct ufsfbo_dev *fbo, char +*buf) { + FBO_INFO_MSG(fbo, "Debug:%d", fbo->fbo_debug); + return sysfs_emit(buf, "%d\n", fbo->fbo_debug); }
I don't think the debug info should be part of your series. Maybe add it as the last patch if you must.
Quoted 2 lines
+/**
+ * structufsfbo_dev- FBO related structure
Maybe ufsfbo_ctrl - as it's your main controlling object. And split it further to ufsfbo_dev_info - ver, rec_lrs, max_lrs, etc. And then all other members
Quoted 7 lines
(quoted diff) +7
-0+int ufsfbo_get_fbo_prog_state(struct ufsfbo_dev *fbo, int *prog_state); +int ufsfbo_operation_control(struct ufsfbo_dev *fbo, int *val); int +ufsfbo_get_exe_level(struct ufsfbo_dev *fbo, int *frag_exe_level); int +ufsfbo_set_exe_level(struct ufsfbo_dev *fbo, int *frag_exe_level); int +ufsfbo_lba_list_write(struct ufsfbo_dev *fbo, const char *buf); int +ufsfbo_read_frag_level(struct ufsfbo_dev *fbo, char *buf); int +ufsfbo_get_fbo_desc_info(struct ufsfbo_dev *fbo); int
Review
Quoted 10 lines
(quoted diff) +10
-0+ufsfbo_get_fbo_support_state(struct ufsfbo_dev *fbo); int +ufsfbo_get_state(struct ufs_hba *hba); void ufsfbo_set_state(struct +ufs_hba *hba, int state); void ufsfbo_init(struct ufs_hba *hba); void +ufsfbo_reset(struct ufs_hba *hba); void ufsfbo_reset_host(struct +ufs_hba *hba); void ufsfbo_remove(struct ufs_hba *hba); int +ufsfbo_is_not_present(struct ufsfbo_dev *fbo); void +ufsfbo_block_enter_suspend(struct ufsfbo_dev *fbo); void +ufsfbo_allow_enter_suspend(struct ufsfbo_dev *fbo); void +ufsfbo_auto_hibern8_enable(struct ufsfbo_dev *fbo, unsigned int val); +#endif /* _UFSFBO_H_ */
You should expose functionality outside the module only if you must. Otherwise, make it privet to the module.
drivers/scsi/ufs/ufshcd.c static void ufshcd_hpb_configure(struct ufs_hba · line 4963
Quoted 13 lines
drivers/scsi/ufs/ufshcd.c index renamed from drivers/scsi/ufs/ufshcd.c +0
-0
2f6468f22b48..9c377c514e17100644drivers/scsi/ufs/ufshcd.c +4
-0@@ -4956,6 +4956,14 @@ static void ufshcd_hpb_configure(struct ufs_hba *hba, struct scsi_device *sdev)ufshpb_init_hpb_lu (hba, sdev); } +static void ufshcd_fbo_configure (struct ufs_hba *hba,struct +scsi_device *sdev) {#ifdef CONFIG_SCSI_UFS_FBO +if (sdev->lun ==0 ) + hba->fbo.sdev_ufs_lu = sdev;#endif }
You won't be needing this if you follow my suggestion above.
drivers/scsi/ufs/ufshcd.c static void ufshcd_async_scan(void *data, · line 8020
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +3
-0@@ -8005,6 +8014,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)/* Probe and add UFS logical units */ ret =ufshcd_add_lus (hba); +#ifdef CONFIG_SCSI_UFS_FBO +ufsfbo_init (hba); +#endif
Instead of wrapping it withing other modules,
Use it in ufsfbo.h
drivers/scsi/ufs/ufshcd.c static void ufshcd_async_scan(void *data,
Quoted 3 lines
drivers/scsi/ufs/ufshcd.c +3
-0+#ifdef CONFIG_SCSI_UFS_FBO +#include "ufsfbo.h" +#endif
Include it in ufshcd.c without the ifdef
drivers/scsi/ufs/ufshcd.c struct ufs_hba { · line 924
Quoted 11 lines
#define UFSHCD "ufshcd"
#defineUFSHCD_DRIVER_VERSION"0.2"drivers/scsi/ufs/ufshcd.c +3
-0@@ -916,6 +918,9 @@ struct ufs_hba {struct dentry *debugfs_root;struct delayed_work debugfs_ee_work;u32 debugfs_ee_rate_limit_ms; +#endif +#ifdef CONFIG_SCSI_UFS_FBO +struct ufsfbo_dev fbo;#endif
If you would use a struct pointer here, you won't need the ifdef.
Thanks,
Avri
Quoted 20 lines
drivers/scsi/ufs/ufsfbo.c new file +20
-0+ +/* SYSFS DEFINE */ +#define define_sysfs_ro (_name) __ATTR(_name, 0444, \ + ufsfbo_sysfs_show_##_name, NULL) +#define define_sysfs_wo (_name) __ATTR(_name, 0200, \ + NULL, ufsfbo_sysfs_store_##_name) +#define define_sysfs_rw (_name) __ATTR(_name, 0644, \ + ufsfbo_sysfs_show_##_name, \ + ufsfbo_sysfs_store_##_name) +static struct ufsfbo_sysfs_entry ufsfbo_sysfs_entries[] = { +define_sysfs_ro (fbo_rec_lrs), +define_sysfs_ro (fbo_max_lrs), +define_sysfs_ro (fbo_min_lrs), +define_sysfs_ro (fbo_max_lrc), +define_sysfs_ro (fbo_lra), +define_sysfs_ro (fbo_prog_state), +define_sysfs_ro (fbo_get_lr_frag_level), +define_sysfs_ro (fbo_support), +define_sysfs_ro (fbo_version), +define_sysfs_wo (fbo_operation_control),
drivers/scsi/ufs/ufsfbo.c line 922
Quoted 10 lines
drivers/scsi/ufs/ufsfbo.c new file +10
-0+define_sysfs_wo (fbo_send_lr_list), +define_sysfs_rw (fbo_exe_threshold), +define_sysfs_rw (fbo_wholefile_enable), +/* debug */ +define_sysfs_rw (debug), +/* Attribute (RAW) */ +define_sysfs_rw (block_suspend), +define_sysfs_rw (auto_hibern8_enable), + __ATTR_NULL +};
Lets stick to the _store / _show naming conventions - people rely on that when they are grepping the code. Also, you need to document the ABI.
Thanks,
Avri
Dear Avri
Thanks for your review. I will modify it according to your suggestion. After the modification, I will try to submit it to Mainline. Therefore, this patch can be ignored, How do I delete it on:
https://patchwork.kernel.org/project/linux-scsi/list/ ? Thanks
-----邮件原件-----
发件人: Avri Altman <[email protected]>
发送时间: 2022年8月25日 16:57
收件人: Jiaming Li <[email protected]>; [email protected]; [email protected] 抄送: [email protected]; [email protected]; 李佳铭 <[email protected]> 主题: [External Mail]RE: [PATCH] scsi: ufs: ufsfbo: Introduce File Based Optimization feature
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。
Quoted 20 lines
drivers/scsi/ufs/ufsfbo.c new file +20
-0+ +/* SYSFS DEFINE */ +#define define_sysfs_ro (_name) __ATTR(_name, 0444, \ + ufsfbo_sysfs_show_##_name, NULL) +#define define_sysfs_wo (_name) __ATTR(_name, 0200, \ + NULL, ufsfbo_sysfs_store_##_name) +#define define_sysfs_rw (_name) __ATTR(_name, 0644, \ + ufsfbo_sysfs_show_##_name, \ + ufsfbo_sysfs_store_##_name) +static struct ufsfbo_sysfs_entry ufsfbo_sysfs_entries[] = { +define_sysfs_ro (fbo_rec_lrs), +define_sysfs_ro (fbo_max_lrs), +define_sysfs_ro (fbo_min_lrs), +define_sysfs_ro (fbo_max_lrc), +define_sysfs_ro (fbo_lra), +define_sysfs_ro (fbo_prog_state), +define_sysfs_ro (fbo_get_lr_frag_level), +define_sysfs_ro (fbo_support), +define_sysfs_ro (fbo_version), +define_sysfs_wo (fbo_operation_control),
drivers/scsi/ufs/ufsfbo.c line 922
Quoted 10 lines
drivers/scsi/ufs/ufsfbo.c new file +10
-0+define_sysfs_wo (fbo_send_lr_list), +define_sysfs_rw (fbo_exe_threshold), +define_sysfs_rw (fbo_wholefile_enable), +/* debug */ +define_sysfs_rw (debug), +/* Attribute (RAW) */ +define_sysfs_rw (block_suspend), +define_sysfs_rw (auto_hibern8_enable), + __ATTR_NULL +};
Lets stick to the _store / _show naming conventions - people rely on that when they are grepping the code. Also, you need to document the ABI.
Thanks,
Avri
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
Quoted 5 lines
Dear Avri
Thanks for your review. I will modify it according to your suggestion. After the modification, I will try to submit it to Mainline. Therefore, this patch can be ignored, How do I delete it on:
https://patchwork.kernel.org/project/linux-scsi/list/ ?
You can't. Just send a v2.
That's fine - its ok for versions to significantly change.
Just remember to document the changes in your cover letter commit log. E.g. :V1->v2:
<a short description of what has changed....>
Thanks,
Avri
Quoted 5 lines · Jiaming Li
drivers/scsi/ufs/Kconfig +0
-0
drivers/scsi/ufs/Kconfig config SCSI_UFS_FAULT_INJECTION · line 207
Quoted 9 lines
drivers/scsi/ufs/Kconfig +6
-0@@ -199,3 +199,12 @@ config SCSI_UFS_FAULT_INJECTION help Enable fault injection support in the UFS driver. This makes it easier to test the UFS error handler and abort handler. + +config SCSI_UFS_FBO + bool "Support UFS File-based Optimization" + depends on SCSI_UFSHCD + help + The UFS FBO feature improves Sequential read performance. The Host can
Sequential -> sequential
Host -> host
drivers/scsi/ufs/Kconfig config SCSI_UFS_FAULT_INJECTION · line 208
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ send the LBA to device. The device will return a fragmented state. It
"The host can send the LBA to the device" is misleading since the host typically sends multiple LBAs to the device.
"The device will return a fragmented state." is wrong - did you perhaps want to write that the device will start defragmentation?
drivers/scsi/ufs/Kconfig config SCSI_UFS_FAULT_INJECTION · line 209
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ FBO_DESC_PARAM_MAX_LBA_RANGE_CONUT = 0xF,
What is "CONUT"? Did you perhaps want to write "COUNT"?
drivers/scsi/ufs/Kconfig config SCSI_UFS_FAULT_INJECTION
Quoted 11 lines
drivers/scsi/ufs/Kconfig +11
-0+static void ufsfbo_scsi_unblock_requests(struct ufs_hba *hba) +{ + if (atomic_dec_and_test(&hba->scsi_block_reqs_cnt)) + scsi_unblock_requests(hba->host); +} + +static void ufsfbo_scsi_block_requests(struct ufs_hba *hba) +{ + if (atomic_inc_return(&hba->scsi_block_reqs_cnt) == 1) + scsi_block_requests(hba->host); +}
Please use ufshcd_scsi_unblock_requests() and ufshcd_scsi_block_requests() instead of duplicating these.
Quoted 45 lines
drivers/scsi/ufs/Kconfig +45
-0+static int ufsfbo_wait_for_doorbell_clr(struct ufs_hba *hba, + u64 wait_timeout_us) +{ + unsigned long flags; + int ret = 0; + u32 tm_doorbell; + u32 tr_doorbell; + bool timeout = false, do_last_check = false; + ktime_t start; + + ufshcd_hold(hba, false); + spin_lock_irqsave(hba->host->host_lock, flags); + /* + * Wait for all the outstanding tasks/transfer requests. + * Verify by checking the doorbell registers are clear. + */ + start = ktime_get(); + do { + if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) { + ret = -EBUSY; + goto out; + } + tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL); + tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); + if (!tm_doorbell && !tr_doorbell) { + timeout = false; + break; + } else if (do_last_check) { + break; + } + spin_unlock_irqrestore(hba->host->host_lock, flags); + schedule(); + if (ktime_to_us(ktime_sub(ktime_get(), start)) > + wait_timeout_us) { + timeout = true; + /* + * We might have scheduled out for long time so make + * sure to check if doorbells are cleared by this time + * or not. + */ + do_last_check = true; + } + spin_lock_irqsave(hba->host->host_lock, flags); + } while (tm_doorbell || tr_doorbell); + if (timeout) {
drivers/scsi/ufs/Kconfig
Quoted 10 lines
drivers/scsi/ufs/Kconfig +10
-0+ dev_err(hba->dev, + "%s: timedout waiting for doorbell to clear (tm=0x%x, tr=0x%x)\n", + __func__, tm_doorbell, tr_doorbell); + ret = -EBUSY; + } +out: + spin_unlock_irqrestore(hba->host->host_lock, flags); + ufshcd_release(hba); + return ret; +}
This looks like a copy of ufshcd_wait_for_doorbell_clr()? Please do not duplicate existing code but instead reuse it. The same comment holds for all the functions below that have been copy/pasted from ufshcd.c.
Quoted 2 lines
drivers/scsi/ufs/Kconfig +2
-0+int ufsfbo_read_frag_level(struct ufsfbo_dev *fbo, char *buf) +{
[ ... ]
drivers/scsi/ufs/Kconfig
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ hba->host->eh_noresume = 1;
Why is this set? This should be documented.
Quoted 5 lines
drivers/scsi/ufs/Kconfig +5
-0+int ufsfbo_init_lba_buffer(struct ufsfbo_dev *fbo, const char *buf, char *lba_buf) +{ + int ret = 0; + char *buf_ptr; + char *lba;
drivers/scsi/ufs/Kconfig
Quoted 10 lines
drivers/scsi/ufs/Kconfig +10
-0+ u64 lba_value_pre, lba_value_post; + int len_index = 1, lba_index = FBO_HEADER_SIZE + FBO_BODY_HEADER_SIZE; + + buf_ptr = kzalloc(strlen(buf) + 1, GFP_KERNEL); + if (!buf_ptr) { + FBO_ERR_MSG("alloc buffer fail"); + ret = -ENOMEM; + return ret; + } + memcpy(buf_ptr, buf, strlen(buf) + 1);
Please use kstrdup() instead of open-coding it.
drivers/scsi/ufs/Kconfig
Quoted 3 lines
drivers/scsi/ufs/Kconfig +3
-0+ /*create lba range buf send for device*/ + lba_buf[5] = fbo->fbo_lba_count; //lba range count + lba_buf[6] = fbo->fbo_wholefile; //calculate whole file
C++-style comments are not allowed in kernel code.
drivers/scsi/ufs/Kconfig
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ while ((lba = strsep(&buf_ptr, ",")) != NULL) {
Another style violation. Please check patches with checkpatch before posting these.
Quoted 2 lines
drivers/scsi/ufs/Kconfig +2
-0+int ufsfbo_lba_list_write(struct ufsfbo_dev *fbo, const char *buf) +{
[ ... ]
drivers/scsi/ufs/Kconfig
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ hba->host->eh_noresume = 1;
Again, why is this set here? Please document this.
Quoted 2 lines
drivers/scsi/ufs/Kconfig +2
-0+void ufsfbo_init(struct ufs_hba *hba) +{
[ ... ]
drivers/scsi/ufs/Kconfig
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ ret = ufsfbo_create_sysfs(fbo);
Please do not call sysfs_create_file() nor kobject_add() directly but instead add an attribute group to ufshcd_driver_groups.
drivers/scsi/ufs/Kconfig
Quoted 1 line
drivers/scsi/ufs/Kconfig +1
-0+ ufsfbo_set_state(hba, FBO_PRESENT);
Consider renaming FBO_PRESENT into FBO_SUPPORTED.
drivers/scsi/ufs/Kconfig
Quoted 8 lines
drivers/scsi/ufs/Kconfig +8
-0+/* SYSFS DEFINE */ +#define define_sysfs_ro(_name) __ATTR(_name, 0444, \ + ufsfbo_sysfs_show_##_name, NULL) +#define define_sysfs_wo(_name) __ATTR(_name, 0200, \ + NULL, ufsfbo_sysfs_store_##_name) +#define define_sysfs_rw(_name) __ATTR(_name, 0644, \ + ufsfbo_sysfs_show_##_name, \ + ufsfbo_sysfs_store_##_name)
Why are these macros necessary? Why can't any of the existing macros be used to define these sysfs attributes, e.g. DEVICE_ATTR_RO()?
Quoted 8 lines
drivers/scsi/ufs/ufsfbo.h new file +2
-0@@ -0,0 +1,143 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/*
drivers/scsi/ufs/ufsfbo.h line 12
Quoted 10 lines
drivers/scsi/ufs/ufsfbo.h new file +10
-0+* Universal Flash Storage File-based Optimization +* +* Copyright (C) 2022 Xiaomi Mobile Software Co., Ltd +* +* Authors: +* lijiaming <[email protected]> +*/ + +#ifndef _UFSFBO_H_ +#define _UFSFBO_H_
Please insert a blank line between the header guard and the include directives.
drivers/scsi/ufs/ufsfbo.h line 13
Quoted 1 line
drivers/scsi/ufs/ufsfbo.h new file +1
-0+#include <linux/interrupt.h>
Why has this header file been included? Please minimize include directives.
drivers/scsi/ufs/ufsfbo.h line 15
Quoted 1 line
drivers/scsi/ufs/ufsfbo.h new file +1
-0+#include <linux/blktrace_api.h>
Why has this header file been included?
drivers/scsi/ufs/ufsfbo.h line 17
Quoted 2 lines
drivers/scsi/ufs/ufsfbo.h new file +2
-0+#include <linux/blkdev.h> +#include <linux/bitfield.h>
Why has this header file been included?
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +0
-0
drivers/scsi/ufs/ufshcd.c static void ufshcd_hpb_configure(struct ufs_hba *hba, struct scsi_device *sdev) · line 4965
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +7
-0@@ -4956,6 +4956,14 @@ static void ufshcd_hpb_configure(struct ufs_hba *hba, struct scsi_device *sdev)ufshpb_init_hpb_lu (hba, sdev); } +static void ufshcd_fbo_configure (struct ufs_hba *hba,struct scsi_device *sdev) +{ +#ifdef CONFIG_SCSI_UFS_FBO +if (sdev->lun ==0 ) + hba->fbo.sdev_ufs_lu = sdev; +#endif +}
Shouldn't this function occur in the file with FBO functions? Additionally, please document why the SCSI device for LUN zero is stored since this is not required by the FBO specification.
Thanks,
Bart.