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

Commit 20ecc8a2 authored by Ziqi Chen's avatar Ziqi Chen
Browse files

scsi: ufs: Fix per-LU WB buffer size setting error



Currently we pass sizeof(*d_lun_wbb_au) as param size to request
dLUNumWriteBoosterBufferAllocUnits. In this way we can only get 1 byte
data while dLunNumWriteBoosterBufferAllocUnites size should be 4 bytes.
To fix this issue, we should pass the actual size of that buffer. The
founction ufshcd_get_wb_alloc_units() is redundant, remove it and
directly call ufshcd_read_unit_desc_param() in ufs_get_device_desc()
to read back the dLUNumWriteBoosterBufferAllocUnits.

Change-Id: Ie6eee00dcb1a4c2334abc2a01d3e81994018835a
Signed-off-by: default avatarZiqi Chen <ziqichen@codeaurora.org>
parent 9a52f417
Loading
Loading
Loading
Loading
+11 −39
Original line number Diff line number Diff line
@@ -6087,37 +6087,6 @@ static int ufshcd_get_lu_wp(struct ufs_hba *hba,
	return ret;
}

/*
 * ufshcd_get_wb_alloc_units - returns "dLUNumWriteBoosterBufferAllocUnits"
 * @hba: per-adapter instance
 * @lun: UFS device lun id
 * @d_lun_wbb_au: pointer to buffer to hold the LU's alloc units info
 *
 * Returns 0 in case of success and d_lun_wbb_au would be returned
 * Returns -ENOTSUPP if reading d_lun_wbb_au is not supported.
 * Returns -EINVAL in case of invalid parameters passed to this function.
 */
static int ufshcd_get_wb_alloc_units(struct ufs_hba *hba,
			    u8 lun,
			    u8 *d_lun_wbb_au)
{
	int ret;

	if (!d_lun_wbb_au)
		ret = -EINVAL;

	/* WB can be supported only from LU0..LU7 */
	else if (lun >= UFS_UPIU_MAX_GENERAL_LUN)
		ret = -ENOTSUPP;
	else
		ret = ufshcd_read_unit_desc_param(hba,
					  lun,
					  UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS,
					  d_lun_wbb_au,
					  sizeof(*d_lun_wbb_au));
	return ret;
}

/**
 * ufshcd_get_lu_power_on_wp_status - get LU's power on write protect
 * status
@@ -8500,9 +8469,9 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
{
	int err;
	size_t buff_len;
	u8 model_index;
	u8 *desc_buf, wb_buf[4];
	u32 lun, res;
	u8 model_index, lun;
	u8 *desc_buf;
	u32 d_lu_wb_buf_alloc;

	buff_len = max_t(size_t, hba->desc_size.dev_desc,
			 QUERY_DESC_MAX_SIZE + 1);
@@ -8552,14 +8521,17 @@ static int ufs_get_device_desc(struct ufs_hba *hba,

		hba->dev_info.wb_config_lun = false;
		for (lun = 0; lun < UFS_UPIU_MAX_GENERAL_LUN; lun++) {
			memset(wb_buf, 0, sizeof(wb_buf));
			err = ufshcd_get_wb_alloc_units(hba, lun, wb_buf);
			d_lu_wb_buf_alloc = 0;
			err = ufshcd_read_unit_desc_param(hba,
					lun,
					UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS,
					(u8 *)&d_lu_wb_buf_alloc,
					sizeof(d_lu_wb_buf_alloc));

			if (err)
				break;

			res = wb_buf[0] << 24 | wb_buf[1] << 16 |
				wb_buf[2] << 8 | wb_buf[3];
			if (res) {
			if (d_lu_wb_buf_alloc) {
				hba->dev_info.wb_config_lun = true;
				break;
			}