Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9e7e458 authored by Stanley Chu's avatar Stanley Chu Committed by Greg Kroah-Hartman
Browse files

BACKPORT: 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.com


Reviewed-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>

Bug: 151050916
(cherry picked from commit e31011ab370989022abf216c606f947a3b02a53a)
[ Resolved minor conflict in drivers/scsi/ufs/ufs-sysfs.c ]
Change-Id: Ic32b2a0d821b66c4631c57b90f76ec25cec647c7
Signed-off-by: default avatarStanley Chu <stanley.chu@mediatek.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 3b7a80ec
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -632,7 +632,7 @@ static ssize_t _name##_show(struct device *dev, \
	u8 index = 0;							\
	struct ufs_hba *hba = dev_get_drvdata(dev);			\
	if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname))			\
		index = ufshcd_wb_get_flag_index(hba);			\
		index = ufshcd_wb_get_query_index(hba);			\
	if (ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,		\
		QUERY_FLAG_IDN##_uname, index, &flag))			\
		return -EINVAL;						\
@@ -672,14 +672,23 @@ 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)			\
{									\
	struct ufs_hba *hba = dev_get_drvdata(dev);			\
	u32 value;							\
	u8 index = 0;							\
	if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname))			\
		index = ufshcd_wb_get_query_index(hba);			\
	if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,		\
		QUERY_ATTR_IDN##_uname, 0, 0, &value))			\
		QUERY_ATTR_IDN##_uname, index, 0, &value))		\
		return -EINVAL;						\
	return sprintf(buf, "0x%08X\n", value);				\
}									\
+10 −6
Original line number Diff line number Diff line
@@ -5413,7 +5413,7 @@ static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)
	else
		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,
				      QUERY_FLAG_IDN_WB_EN, index, NULL);
	if (ret) {
@@ -5439,7 +5439,7 @@ static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)
	else
		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,
				QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,
				index, NULL);
@@ -5462,7 +5462,7 @@ static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba)
	if (!ufshcd_is_wb_allowed(hba) || hba->wb_buf_flush_enabled)
		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,
				      QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN,
				      index, NULL);
@@ -5484,7 +5484,7 @@ static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba)
	if (!ufshcd_is_wb_allowed(hba) || !hba->wb_buf_flush_enabled)
		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,
				      QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN,
				      index, NULL);
@@ -5504,10 +5504,12 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
{
	u32 cur_buf;
	int ret;
	u8 index;

	index = ufshcd_wb_get_query_index(hba);
	ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
					      QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE,
					      0, 0, &cur_buf);
					      index, 0, &cur_buf);
	if (ret) {
		dev_err(hba->dev, "%s dCurWriteBoosterBufferSize read failed %d\n",
			__func__, ret);
@@ -5530,6 +5532,7 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
{
	int ret;
	u32 avail_buf;
	u8 index;

	if (!ufshcd_is_wb_allowed(hba))
		return false;
@@ -5544,9 +5547,10 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
	 * buffer (dCurrentWriteBoosterBufferSize). There's no point in
	 * 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,
				      QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE,
				      0, 0, &avail_buf);
				      index, 0, &avail_buf);
	if (ret) {
		dev_warn(hba->dev, "%s dAvailableWriteBoosterBufferSize read failed %d\n",
			 __func__, ret);
+1 −1
Original line number Diff line number Diff line
@@ -971,7 +971,7 @@ static inline bool ufshcd_keep_autobkops_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)
		return hba->dev_info.wb_dedicated_lu;