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

Commit 0b832d2e authored by Asutosh Das's avatar Asutosh Das Committed by Sahitya Tummala
Browse files

scsi: ufs: enable write booster only if provisioned



Check if write booster is provisioned.
Don't rely only on device capability to enable write booster.

Change-Id: I96ff2943d60b1432606509fdb2c38ac8176400e1
Signed-off-by: default avatarAsutosh Das <asutoshd@codeaurora.org>
Signed-off-by: default avatarSahitya Tummala <stummala@codeaurora.org>
parent e62f769e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ enum unit_desc_param {
	UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT	= 0x18,
	UNIT_DESC_PARAM_CTX_CAPABILITIES	= 0x20,
	UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1	= 0x22,
	UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS	= 0x29,
};

/* Device descriptor parameters offsets in bytes*/
@@ -205,6 +206,8 @@ enum device_desc_param {
	DEVICE_DESC_PARAM_PSA_TMT		= 0x29,
	DEVICE_DESC_PARAM_PRDCT_REV		= 0x2A,
	DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP	= 0x4F,
	DEVICE_DESC_PARAM_WB_TYPE		= 0x54,
	DEVICE_DESC_PARAM_WB_SHARED_ALLOC_UNITS = 0x55,
};

/* Interconnect descriptor parameters offsets in bytes*/
@@ -600,6 +603,7 @@ struct ufs_dev_info {
	u8	i_product_name;
	u16	w_spec_version;
	u32	d_ext_ufs_feature_sup;
	u8	b_wb_buffer_type;

	/* query flags */
	bool f_power_on_wp_en;
@@ -613,6 +617,8 @@ struct ufs_dev_info {
	unsigned int quirks;

	bool keep_vcc_on;

	bool wb_config_lun;
};

#define MAX_MODEL_LEN 16
+60 −4
Original line number Diff line number Diff line
@@ -6060,6 +6060,37 @@ 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
@@ -6849,8 +6880,10 @@ static void ufshcd_bkops_exception_event_handler(struct ufs_hba *hba)

static bool ufshcd_wb_sup(struct ufs_hba *hba)
{
	return !!(hba->dev_info.d_ext_ufs_feature_sup &
		  UFS_DEV_WRITE_BOOSTER_SUP);
	return ((hba->dev_info.d_ext_ufs_feature_sup &
		   UFS_DEV_WRITE_BOOSTER_SUP) &&
		  (hba->dev_info.b_wb_buffer_type
		   || hba->dev_info.wb_config_lun));
}

static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)
@@ -8437,7 +8470,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
	int err;
	size_t buff_len;
	u8 model_index;
	u8 *desc_buf;
	u8 *desc_buf, wb_buf[4];
	u32 lun, res;

	buff_len = max_t(size_t, hba->desc_size.dev_desc,
			 QUERY_DESC_MAX_SIZE + 1);
@@ -8469,7 +8503,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
	if ((dev_desc->wspecversion >= 0x310) ||
	    (dev_desc->wmanufacturerid == UFS_VENDOR_TOSHIBA &&
	     dev_desc->wspecversion >= 0x300 &&
	     hba->desc_size.dev_desc >= 0x59))
	     hba->desc_size.dev_desc >= 0x59)) {
		hba->dev_info.d_ext_ufs_feature_sup =
			desc_buf[DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP]
								<< 24 |
@@ -8478,7 +8512,29 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
			desc_buf[DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 2]
								<< 8 |
			desc_buf[DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 3];
		hba->dev_info.b_wb_buffer_type =
			desc_buf[DEVICE_DESC_PARAM_WB_TYPE];

		if (hba->dev_info.b_wb_buffer_type)
			goto skip_unit_desc;

		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);
			if (err)
				break;

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

skip_unit_desc:
	/* Zero-pad entire buffer for string termination. */
	memset(desc_buf, 0, buff_len);