Commit e31011ab authored by Stanley Chu's avatar Stanley Chu Committed by Martin K. Petersen

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/20200522083212.4008-4-stanley.chu@mediatek.comReviewed-by: default avatarAvri Altman <avri.altman@wdc.com>
Reviewed-by: default avatarAsutosh Das <asutoshd@codeaurora.org>
Signed-off-by: default avatarStanley Chu <stanley.chu@mediatek.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent c7cee3e7
...@@ -637,7 +637,7 @@ static ssize_t _name##_show(struct device *dev, \ ...@@ -637,7 +637,7 @@ static ssize_t _name##_show(struct device *dev, \
int ret; \ int ret; \
struct ufs_hba *hba = dev_get_drvdata(dev); \ struct ufs_hba *hba = dev_get_drvdata(dev); \
if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \ if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \
index = ufshcd_wb_get_flag_index(hba); \ index = ufshcd_wb_get_query_index(hba); \
pm_runtime_get_sync(hba->dev); \ pm_runtime_get_sync(hba->dev); \
ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \ ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \
QUERY_FLAG_IDN##_uname, index, &flag); \ QUERY_FLAG_IDN##_uname, index, &flag); \
...@@ -680,6 +680,12 @@ static const struct attribute_group ufs_sysfs_flags_group = { ...@@ -680,6 +680,12 @@ static const struct attribute_group ufs_sysfs_flags_group = {
.attrs = ufs_sysfs_device_flags, .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) \ #define UFS_ATTRIBUTE(_name, _uname) \
static ssize_t _name##_show(struct device *dev, \ static ssize_t _name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \ struct device_attribute *attr, char *buf) \
...@@ -687,9 +693,12 @@ static ssize_t _name##_show(struct device *dev, \ ...@@ -687,9 +693,12 @@ static ssize_t _name##_show(struct device *dev, \
struct ufs_hba *hba = dev_get_drvdata(dev); \ struct ufs_hba *hba = dev_get_drvdata(dev); \
u32 value; \ u32 value; \
int ret; \ int ret; \
u8 index = 0; \
if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \
index = ufshcd_wb_get_query_index(hba); \
pm_runtime_get_sync(hba->dev); \ pm_runtime_get_sync(hba->dev); \
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \
QUERY_ATTR_IDN##_uname, 0, 0, &value); \ QUERY_ATTR_IDN##_uname, index, 0, &value); \
pm_runtime_put_sync(hba->dev); \ pm_runtime_put_sync(hba->dev); \
if (ret) \ if (ret) \
return -EINVAL; \ return -EINVAL; \
......
...@@ -5199,7 +5199,7 @@ static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable) ...@@ -5199,7 +5199,7 @@ static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)
else else
opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG; opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG;
index = ufshcd_wb_get_flag_index(hba); index = ufshcd_wb_get_query_index(hba);
ret = ufshcd_query_flag_retry(hba, opcode, ret = ufshcd_query_flag_retry(hba, opcode,
QUERY_FLAG_IDN_WB_EN, index, NULL); QUERY_FLAG_IDN_WB_EN, index, NULL);
if (ret) { if (ret) {
...@@ -5225,7 +5225,7 @@ static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set) ...@@ -5225,7 +5225,7 @@ static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)
else else
val = UPIU_QUERY_OPCODE_CLEAR_FLAG; val = UPIU_QUERY_OPCODE_CLEAR_FLAG;
index = ufshcd_wb_get_flag_index(hba); index = ufshcd_wb_get_query_index(hba);
return ufshcd_query_flag_retry(hba, val, return ufshcd_query_flag_retry(hba, val,
QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8, QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,
index, NULL); index, NULL);
...@@ -5248,7 +5248,7 @@ static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba) ...@@ -5248,7 +5248,7 @@ static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba)
if (!ufshcd_is_wb_allowed(hba) || hba->wb_buf_flush_enabled) if (!ufshcd_is_wb_allowed(hba) || hba->wb_buf_flush_enabled)
return 0; return 0;
index = ufshcd_wb_get_flag_index(hba); index = ufshcd_wb_get_query_index(hba);
ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG, ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN,
index, NULL); index, NULL);
...@@ -5270,7 +5270,7 @@ static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba) ...@@ -5270,7 +5270,7 @@ static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba)
if (!ufshcd_is_wb_allowed(hba) || !hba->wb_buf_flush_enabled) if (!ufshcd_is_wb_allowed(hba) || !hba->wb_buf_flush_enabled)
return 0; return 0;
index = ufshcd_wb_get_flag_index(hba); index = ufshcd_wb_get_query_index(hba);
ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG, ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG,
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN,
index, NULL); index, NULL);
...@@ -5290,10 +5290,12 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba, ...@@ -5290,10 +5290,12 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
{ {
u32 cur_buf; u32 cur_buf;
int ret; int ret;
u8 index;
index = ufshcd_wb_get_query_index(hba);
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR, ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE, QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE,
0, 0, &cur_buf); index, 0, &cur_buf);
if (ret) { if (ret) {
dev_err(hba->dev, "%s dCurWriteBoosterBufferSize read failed %d\n", dev_err(hba->dev, "%s dCurWriteBoosterBufferSize read failed %d\n",
__func__, ret); __func__, ret);
...@@ -5316,6 +5318,7 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba) ...@@ -5316,6 +5318,7 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
{ {
int ret; int ret;
u32 avail_buf; u32 avail_buf;
u8 index;
if (!ufshcd_is_wb_allowed(hba)) if (!ufshcd_is_wb_allowed(hba))
return false; return false;
...@@ -5330,9 +5333,10 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba) ...@@ -5330,9 +5333,10 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
* buffer (dCurrentWriteBoosterBufferSize). There's no point in * buffer (dCurrentWriteBoosterBufferSize). There's no point in
* keeping vcc on when current buffer is empty. * keeping vcc on when current buffer is empty.
*/ */
index = ufshcd_wb_get_query_index(hba);
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR, ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE, QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE,
0, 0, &avail_buf); index, 0, &avail_buf);
if (ret) { if (ret) {
dev_warn(hba->dev, "%s dAvailableWriteBoosterBufferSize read failed %d\n", dev_warn(hba->dev, "%s dAvailableWriteBoosterBufferSize read failed %d\n",
__func__, ret); __func__, ret);
......
...@@ -868,7 +868,7 @@ static inline bool ufshcd_keep_autobkops_enabled_except_suspend( ...@@ -868,7 +868,7 @@ static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND; return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
} }
static inline u8 ufshcd_wb_get_flag_index(struct ufs_hba *hba) static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)
{ {
if (hba->dev_info.b_wb_buffer_type == WB_BUF_MODE_LU_DEDICATED) if (hba->dev_info.b_wb_buffer_type == WB_BUF_MODE_LU_DEDICATED)
return hba->dev_info.wb_dedicated_lu; return hba->dev_info.wb_dedicated_lu;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment