scsi: ufs: Support WriteBooster on Samsung UFS devices
Subsystems (2)
cover scsi: ufs: Support WriteBooster on Samsung UFS devices
Hi,
Samsung UFS devices are widely used in the market, however these devices need some special handling to support WriteBooster. Introduce a device quirk to handle this special requirement.
Currently Bean Huo is doing some nice cleanup work for device descriptor length so our series will have merge conflict. I would like to submit this series first for review and then resend with conflict fix after Bean's series gets accepted.
Stanley Chu (2):
scsi: ufs: Support WriteBooster on Samsung UFS devices
scsi: ufs-mediatek: Support WriteBooster on Samsung UFS devices
drivers/scsi/ufs/ufs-mediatek.c | 3 +++ drivers/scsi/ufs/ufs-sysfs.c | 12 --------- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufs_quirks.h | 7 +++++ drivers/scsi/ufs/ufshcd.c | 45 ++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 20 +++++++++++++++ 6 files changed, 75 insertions(+), 13 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/2 scsi: ufs: Support WriteBooster on Samsung UFS devices
Samsung UFS devices are widely used in the market, however these devices need some special handling to support WriteBooster.
The major part is that Samsung UFS devices need to use specific "selector" value for WriteBooster related query operations. Therefore, introduce a device quirk to handle the special requirement and then WriteBooster can be enabled on these devices.
--- drivers/scsi/ufs/ufs-sysfs.c | 12 ---------- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufs_quirks.h | 7 ++++++ drivers/scsi/ufs/ufshcd.c | 43 ++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 20 ++++++++++++++++ 5 files changed, 70 insertions(+), 13 deletions(-)
drivers/scsi/ufs/ufs-sysfs.c +0 -12
@@ -622,12 +622,6 @@ static const struct attribute_group ufs_sysfs_string_descriptors_group = { .attrs = ufs_sysfs_string_descriptors, }; -static inline bool ufshcd_is_wb_flags (enum flag_idn idn) -{ -return ((idn >=QUERY_FLAG_IDN_WB_EN ) && - (idn <=QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 )); -} -#define UFS_FLAG (_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \
@@ -680,12 +674,6 @@ static const struct attribute_group ufs_sysfs_flags_group = { .attrs = ufs_sysfs_device_flags, }; -static inline bool ufshcd_is_wb_attrs (enum attr_idn idn) -{ -return ((idn >=QUERY_ATTR_IDN_WB_FLUSH_STATUS ) && - (idn <=QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE )); -} -#define UFS_ATTRIBUTE (_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \
drivers/scsi/ufs/ufs.h +1 -0
@@ -61,6 +61,7 @@* This means max. LUN number reported from UFS device could be 0xC17F. */ #define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F +#define UFS_UPIU_RPMB_QUERY_INDEX 0xC4#define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)#define UFS_UPIU_WLUN_ID (1 << 7)
drivers/scsi/ufs/ufs_quirks.h +7 -0
@@ -108,4 +108,11 @@ struct ufs_dev_fix {*/ #define UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES (1 << 10) +/* +* Some UFS devices need to use special selector to operate WriteBooster +* related flags and attributes. Enable this quirk to make these devices +* work normally. +*/ +#define UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR (1 << 11) +#endif /* UFS_QUIRKS_H_ */
drivers/scsi/ufs/ufshcd.c +42 -1
79 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +20 -0
@@ -876,6 +876,26 @@ static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)return 0 ; } +static inline bool ufshcd_is_wb_attrs (enum attr_idn idn) +{ +return ((idn >=QUERY_ATTR_IDN_WB_FLUSH_STATUS ) && + (idn <=QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE )); +} + +static inline bool ufshcd_is_wb_desc (enum desc_idn idn,u8 index) +{ +return (idn <=QUERY_DESC_IDN_CONFIGURATION ) || + ((idn ==QUERY_DESC_IDN_UNIT ) && + (index !=UFS_UPIU_RPMB_QUERY_INDEX )) || + (idn ==QUERY_DESC_IDN_GEOMETRY ); +} + +static inline bool ufshcd_is_wb_flags (enum flag_idn idn) +{ +return ((idn >=QUERY_FLAG_IDN_WB_EN ) && + (idn <=QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 )); +} +extern int ufshcd_runtime_suspend (struct ufs_hba *hba);extern int ufshcd_runtime_resume (struct ufs_hba *hba);extern int ufshcd_runtime_idle (struct ufs_hba *hba);
Signature · 5 lines
2.18.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +1
-1@@ -2801,11 +2801,17 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, {struct ufs_query_req *request =NULL ;struct ufs_query_res *response =NULL ; -int err, selector =0 ; +int err;
drivers/scsi/ufs/ufshcd.c int ufshcd_query_flag(struct ufs_hba *hba, enum · line 2815
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +6
-0int timeout =QUERY_REQ_TIMEOUT ; +u8 selector =0 ;BUG_ON (!hba); +if (hba->dev_quirks &UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ) { +if (ufshcd_is_wb_flags (idn)) + selector =1 ; + } +
Why not make the caller set the applicable selector, Instead of checking this for every flag?
drivers/scsi/ufs/ufshcd.c int ufshcd_query_attr(struct ufs_hba *hba, enum · line 2896
Quoted 13 lines
drivers/scsi/ufs/ufshcd.c +0
-0ufshcd_hold (hba, false);mutex_lock (&hba->dev_cmd.lock);ufshcd_init_query(hba, &request, &response, opcode, idn, index,
drivers/scsi/ufs/ufshcd.c +5
-0@@ -2882,6 +2888,11 @@ int ufshcd_query_attr(struct ufs_hba *hba, enumquery_opcode opcode, goto out; } +if (hba->dev_quirks &UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ) { +if (ufshcd_is_wb_attrs (idn)) + selector =1 ; + } +
Same here
drivers/scsi/ufs/ufshcd.c int ufshcd_query_descriptor_retry(struct ufs_hba · line 3061
Quoted 13 lines
(quoted diff) +0
-0mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index,selector);drivers/scsi/ufs/ufshcd.c +5
-0@@ -3042,6 +3053,11 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, int err;int retries; +if (hba->dev_quirks &UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ) { +if (ufshcd_is_wb_desc (idn, index)) + selector =1 ; + } +
And here.
But this can't be true -
Are you setting the selector = 1 for reading any field for those descriptors? Shouldn't it be for the wb specific fields?
Quoted 15 lines
drivers/scsi/ufs/ufshcd.c +0
-0for (retries =QUERY_REQ_RETRIES ; retries >0 ; retries--) { err = __ufshcd_query_descriptor(hba, opcode, idn, index,selector, desc_buf, buf_len);drivers/scsi/ufs/ufshcd.c +2
-0@@ -6907,8 +6923,10 @@ static int ufs_get_device_desc(struct ufs_hba *hba)size_t buff_len;u8 model_index;u8 *desc_buf; +u8 retry_cnt =0 ;struct ufs_dev_info *dev_info = &hba->dev_info; +retry: buff_len =max_t (size_t, hba->desc_size.dev_desc,QUERY_DESC_MAX_SIZE +1 ); desc_buf =kmalloc (buff_len,GFP_KERNEL );
drivers/scsi/ufs/ufshcd.c static int ufs_get_device_desc(struct ufs_hba *hba) · line 6970
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +2
-0@@ -6948,6 +6966,29 @@ static int ufs_get_device_desc(struct ufs_hba *hba)ufs_fixup_device_setup (hba); +if (!retry_cnt && (hba->dev_quirks & +UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR )) {
If you only want to enter this clause once - you should use something other than retry_cnt, Which the reader expects to performs retries....
Also, this is becoming too wired -
From your commit log I get that for specific Samsung devices, You need to query wb descriptor fields/attributes/flags using selectore = 1. But what it has to do with descriptor sizes?
Quoted 59 lines
drivers/scsi/ufs/ufshcd.c +21
-0+/* +* Update WriteBooster related descriptor length with specific +* seletor used. +*/ +ufshcd_read_desc_length (hba,QUERY_DESC_IDN_DEVICE ,0 , + &hba->desc_size.dev_desc); +ufshcd_read_desc_length (hba,QUERY_DESC_IDN_CONFIGURATION ,0 , + &hba->desc_size.conf_desc); +ufshcd_read_desc_length (hba,QUERY_DESC_IDN_UNIT ,0 , + &hba->desc_size.unit_desc); +ufshcd_read_desc_length (hba,QUERY_DESC_IDN_GEOMETRY ,0 , + &hba->desc_size.geom_desc); +/* +* Read device descriptor again with specific selector used to +* get WriteBooster related fileds. +*/ +kfree (desc_buf); + retry_cnt++; + goto retry; + } +/* * Probe WB only for UFS-3.1 devices or UFS devices with quirk *
UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURESenableddrivers/scsi/ufs/ufshcd.h +20
-0@@ -876,6 +876,26 @@ static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)return 0 ; } +static inline bool ufshcd_is_wb_attrs (enum attr_idn idn) +{ +return ((idn >=QUERY_ATTR_IDN_WB_FLUSH_STATUS ) && + (idn <=QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE )); +} + +static inline bool ufshcd_is_wb_desc (enum desc_idn idn,u8 index) +{ +return (idn <=QUERY_DESC_IDN_CONFIGURATION ) || + ((idn ==QUERY_DESC_IDN_UNIT ) && + (index !=UFS_UPIU_RPMB_QUERY_INDEX )) || + (idn ==QUERY_DESC_IDN_GEOMETRY ); +} + +static inline bool ufshcd_is_wb_flags (enum flag_idn idn) +{ +return ((idn >=QUERY_FLAG_IDN_WB_EN ) && + (idn <=QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 )); +} +extern int ufshcd_runtime_suspend (struct ufs_hba *hba);extern int ufshcd_runtime_resume (struct ufs_hba *hba);extern int
ufshcd_runtime_idle(struct ufs_hba *hba);
--
2.18.0
Hi Avri,
Quoted 12 lines · Avri Altman
Quoted 12 lines
drivers/scsi/ufs/ufshcd.c +2
-1@@ -2801,11 +2801,17 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, {struct ufs_query_req *request =NULL ;struct ufs_query_res *response =NULL ; -int err, selector =0 ; +int err;int timeout =QUERY_REQ_TIMEOUT ; +u8 selector =0 ;BUG_ON (!hba);
Quoted 7 lines
drivers/scsi/ufs/ufshcd.c int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, · line 2814
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +5
-0+if (hba->dev_quirks &UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ) { +if (ufshcd_is_wb_flags (idn)) + selector =1 ; + } +Why not make the caller set the applicable selector, Instead of checking this for every flag?
This way have the minimum modification efforts and places compared to other ways. However it looks a little wired because the selector control is better assigned by users. I will submit next version with changing the way selector assigned for comparison.
Quoted 24 lines
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +0
-0ufshcd_hold (hba, false);mutex_lock (&hba->dev_cmd.lock);ufshcd_init_query(hba, &request, &response, opcode, idn, index,
drivers/scsi/ufs/ufshcd.c int ufshcd_query_attr(struct ufs_hba *hba, enum · line 2896
Quoted 9 lines
drivers/scsi/ufs/ufshcd.c +5
-0@@ -2882,6 +2888,11 @@ int ufshcd_query_attr(struct ufs_hba *hba, enumquery_opcode opcode, goto out; } +if (hba->dev_quirks &UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ) { +if (ufshcd_is_wb_attrs (idn)) + selector =1 ; + } +Same here
Quoted 8 lines
(quoted diff) +0
-0mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index,selector);drivers/scsi/ufs/ufshcd.c +0
-0@@ -3042,6 +3053,11 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, int err;int retries;
Quoted 9 lines
drivers/scsi/ufs/ufshcd.c int ufshcd_query_descriptor_retry(struct ufs_hba *hba, · line 3060
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +5
-0+if (hba->dev_quirks &UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ) { +if (ufshcd_is_wb_desc (idn, index)) + selector =1 ; + } +And here.
But this can't be true -
Are you setting the selector = 1 for reading any field for those descriptors? Shouldn't it be for the wb specific fields?
Yes, thanks for remind this.
I shall assign selector = 1 for WB related fields only in descriptors.
Quoted 18 lines
Quoted 18 lines
drivers/scsi/ufs/ufshcd.c +0
-0for (retries =QUERY_REQ_RETRIES ; retries >0 ; retries--) { err = __ufshcd_query_descriptor(hba, opcode, idn, index,selector, desc_buf, buf_len);drivers/scsi/ufs/ufshcd.c +2
-0@@ -6907,8 +6923,10 @@ static int ufs_get_device_desc(struct ufs_hba *hba)size_t buff_len;u8 model_index;u8 *desc_buf; +u8 retry_cnt =0 ;struct ufs_dev_info *dev_info = &hba->dev_info; +retry: buff_len =max_t (size_t, hba->desc_size.dev_desc,QUERY_DESC_MAX_SIZE +1 ); desc_buf =kmalloc (buff_len,GFP_KERNEL );@@ -6948,6 +6966,29 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
Quoted 6 lines
drivers/scsi/ufs/ufshcd.c static int ufs_get_device_desc(struct ufs_hba *hba) · line 6970
Quoted 4 lines
drivers/scsi/ufs/ufshcd.c +2
-0ufs_fixup_device_setup (hba); +if (!retry_cnt && (hba->dev_quirks & +UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR )) {If you only want to enter this clause once - you should use something other than
retry_cnt, Which the reader expects to performs retries....
OK! I will fix this label by using another more comprehensible name.
Quoted 5 lines
Also, this is becoming too wired -
From your commit log I get that for specific Samsung devices, You need to query wb descriptor fields/attributes/flags using selectore = 1. But what it has to do with descriptor sizes?
Sorry to not mention clearly in the commit log.
Here driver needs to update the descriptor size to a "longer size" which includes the "hidden WB related fields" which can be "found" by selector = 1.
If descriptor size is not updated, any query can only get the fields offset within current descriptor size even if selector = 1, and out-of-boundary desc_buf[] access will happen in ufshcd_read_desc_param().
PS. The check of "param_offset" to prevent possible out-of-boundary desc_buf[] access can be patched as well.
Thanks,
Stanley Chu
PATCH 2/2 scsi: ufs-mediatek: Support WriteBooster on Samsung UFS devices
In reply to Stanley ChuAdd device quirk "UFS_DEVICE_QUIRK_WB_USING_SPECIAL_SELECTOR" on all Samsung UFS devices to enable WriteBooster on those devices.
--- drivers/scsi/ufs/ufs-mediatek.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/ufs/ufs-mediatek.c +3 -0
@@ -32,6 +32,9 @@ ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, high, res)static struct ufs_dev_fix ufs_mtk_dev_fixups[] = { +UFS_FIX (UFS_VENDOR_SAMSUNG ,UFS_ANY_MODEL , +UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES | +UFS_DEVICE_QUIRK_WB_SPECIAL_SELECTOR ),UFS_FIX (UFS_VENDOR_SKHYNIX ,"H9HQ21AFAMZDAR" ,UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES ),END_FIX
Signature · 1 line
2.18.0
Quoted 11 lines
Hi,
Samsung UFS devices are widely used in the market, however these devices need some special handling to support WriteBooster. Introduce a device quirk to handle this special requirement.Currently Bean Huo is doing some nice cleanup work for device descriptor length so our series will have merge conflict. I would like to submit this series first for review and then resend with conflict fix after Bean's series gets accepted.
Maybe better to wait few days for that series to be accepted ?
Thanks,
Avri