Skip to content

Commit e31011a

Browse files
Stanley Chumartinkpetersen
authored andcommitted
scsi: ufs: Fix index of attributes query for WriteBooster feature
For WriteBooster feature related attributes, the index used by query shall be LUN ID if LU Dedicated buffer mode is enabled. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Avri Altman <[email protected]> Reviewed-by: Asutosh Das <[email protected]> Signed-off-by: Stanley Chu <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent c7cee3e commit e31011a

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

drivers/scsi/ufs/ufs-sysfs.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static ssize_t _name##_show(struct device *dev, \
637637
int ret; \
638638
struct ufs_hba *hba = dev_get_drvdata(dev); \
639639
if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \
640-
index = ufshcd_wb_get_flag_index(hba); \
640+
index = ufshcd_wb_get_query_index(hba); \
641641
pm_runtime_get_sync(hba->dev); \
642642
ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \
643643
QUERY_FLAG_IDN##_uname, index, &flag); \
@@ -680,16 +680,25 @@ static const struct attribute_group ufs_sysfs_flags_group = {
680680
.attrs = ufs_sysfs_device_flags,
681681
};
682682

683+
static inline bool ufshcd_is_wb_attrs(enum attr_idn idn)
684+
{
685+
return ((idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS) &&
686+
(idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE));
687+
}
688+
683689
#define UFS_ATTRIBUTE(_name, _uname) \
684690
static ssize_t _name##_show(struct device *dev, \
685691
struct device_attribute *attr, char *buf) \
686692
{ \
687693
struct ufs_hba *hba = dev_get_drvdata(dev); \
688694
u32 value; \
689695
int ret; \
696+
u8 index = 0; \
697+
if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \
698+
index = ufshcd_wb_get_query_index(hba); \
690699
pm_runtime_get_sync(hba->dev); \
691700
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \
692-
QUERY_ATTR_IDN##_uname, 0, 0, &value); \
701+
QUERY_ATTR_IDN##_uname, index, 0, &value); \
693702
pm_runtime_put_sync(hba->dev); \
694703
if (ret) \
695704
return -EINVAL; \

drivers/scsi/ufs/ufshcd.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5199,7 +5199,7 @@ static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)
51995199
else
52005200
opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG;
52015201

5202-
index = ufshcd_wb_get_flag_index(hba);
5202+
index = ufshcd_wb_get_query_index(hba);
52035203
ret = ufshcd_query_flag_retry(hba, opcode,
52045204
QUERY_FLAG_IDN_WB_EN, index, NULL);
52055205
if (ret) {
@@ -5225,7 +5225,7 @@ static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)
52255225
else
52265226
val = UPIU_QUERY_OPCODE_CLEAR_FLAG;
52275227

5228-
index = ufshcd_wb_get_flag_index(hba);
5228+
index = ufshcd_wb_get_query_index(hba);
52295229
return ufshcd_query_flag_retry(hba, val,
52305230
QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,
52315231
index, NULL);
@@ -5248,7 +5248,7 @@ static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba)
52485248
if (!ufshcd_is_wb_allowed(hba) || hba->wb_buf_flush_enabled)
52495249
return 0;
52505250

5251-
index = ufshcd_wb_get_flag_index(hba);
5251+
index = ufshcd_wb_get_query_index(hba);
52525252
ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
52535253
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN,
52545254
index, NULL);
@@ -5270,7 +5270,7 @@ static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba)
52705270
if (!ufshcd_is_wb_allowed(hba) || !hba->wb_buf_flush_enabled)
52715271
return 0;
52725272

5273-
index = ufshcd_wb_get_flag_index(hba);
5273+
index = ufshcd_wb_get_query_index(hba);
52745274
ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG,
52755275
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN,
52765276
index, NULL);
@@ -5290,10 +5290,12 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
52905290
{
52915291
u32 cur_buf;
52925292
int ret;
5293+
u8 index;
52935294

5295+
index = ufshcd_wb_get_query_index(hba);
52945296
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
52955297
QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE,
5296-
0, 0, &cur_buf);
5298+
index, 0, &cur_buf);
52975299
if (ret) {
52985300
dev_err(hba->dev, "%s dCurWriteBoosterBufferSize read failed %d\n",
52995301
__func__, ret);
@@ -5316,6 +5318,7 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
53165318
{
53175319
int ret;
53185320
u32 avail_buf;
5321+
u8 index;
53195322

53205323
if (!ufshcd_is_wb_allowed(hba))
53215324
return false;
@@ -5330,9 +5333,10 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
53305333
* buffer (dCurrentWriteBoosterBufferSize). There's no point in
53315334
* keeping vcc on when current buffer is empty.
53325335
*/
5336+
index = ufshcd_wb_get_query_index(hba);
53335337
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
53345338
QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE,
5335-
0, 0, &avail_buf);
5339+
index, 0, &avail_buf);
53365340
if (ret) {
53375341
dev_warn(hba->dev, "%s dAvailableWriteBoosterBufferSize read failed %d\n",
53385342
__func__, ret);

drivers/scsi/ufs/ufshcd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
868868
return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
869869
}
870870

871-
static inline u8 ufshcd_wb_get_flag_index(struct ufs_hba *hba)
871+
static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)
872872
{
873873
if (hba->dev_info.b_wb_buffer_type == WB_BUF_MODE_LU_DEDICATED)
874874
return hba->dev_info.wb_dedicated_lu;

0 commit comments

Comments
 (0)