Commit 7a0bf85b authored by Bean Huo's avatar Bean Huo Committed by Martin K. Petersen

scsi: ufs: Clean up ufs initialization path

At UFS initialization stage, to get the length of the descriptor,
ufshcd_read_desc_length() was being called 6 times. Instead, we will
capture the descriptor size the first time we'll read it.

Delete unnecessary redundant code, remove ufshcd_read_desc_length(),
ufshcd_init_desc_sizes(), and boost UFS initialization.

Link: https://lore.kernel.org/r/20200603091959.27618-5-huobean@gmail.comAcked-by: default avatarAvri Altman <avri.altman@wdc.com>
Reviewed-by: default avatarBart van Assche <bvanassche@acm.org>
Reviewed-by: default avatarStanley Chu <stanley.chu@mediatek.com>
Signed-off-by: default avatarBean Huo <beanhuo@micron.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent cbe193f6
...@@ -200,16 +200,6 @@ enum desc_header_offset { ...@@ -200,16 +200,6 @@ enum desc_header_offset {
QUERY_DESC_DESC_TYPE_OFFSET = 0x01, QUERY_DESC_DESC_TYPE_OFFSET = 0x01,
}; };
enum ufs_desc_def_size {
QUERY_DESC_DEVICE_DEF_SIZE = 0x59,
QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90,
QUERY_DESC_UNIT_DEF_SIZE = 0x2D,
QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06,
QUERY_DESC_GEOMETRY_DEF_SIZE = 0x48,
QUERY_DESC_POWER_DEF_SIZE = 0x62,
QUERY_DESC_HEALTH_DEF_SIZE = 0x25,
};
/* Unit descriptor parameters offsets in bytes*/ /* Unit descriptor parameters offsets in bytes*/
enum unit_desc_param { enum unit_desc_param {
UNIT_DESC_PARAM_LEN = 0x0, UNIT_DESC_PARAM_LEN = 0x0,
......
...@@ -11,13 +11,12 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, ...@@ -11,13 +11,12 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len,
{ {
int desc_size = be16_to_cpu(qr->length); int desc_size = be16_to_cpu(qr->length);
int desc_id = qr->idn; int desc_id = qr->idn;
int ret;
if (desc_size <= 0) if (desc_size <= 0)
return -EINVAL; return -EINVAL;
ret = ufshcd_map_desc_id_to_length(hba, desc_id, desc_len); ufshcd_map_desc_id_to_length(hba, desc_id, desc_len);
if (ret || !*desc_len) if (!*desc_len)
return -EINVAL; return -EINVAL;
*desc_len = min_t(int, *desc_len, desc_size); *desc_len = min_t(int, *desc_len, desc_size);
......
...@@ -3065,95 +3065,32 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, ...@@ -3065,95 +3065,32 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
return err; return err;
} }
/**
* ufshcd_read_desc_length - read the specified descriptor length from header
* @hba: Pointer to adapter instance
* @desc_id: descriptor idn value
* @desc_index: descriptor index
* @desc_length: pointer to variable to read the length of descriptor
*
* Return 0 in case of success, non-zero otherwise
*/
static int ufshcd_read_desc_length(struct ufs_hba *hba,
enum desc_idn desc_id,
int desc_index,
int *desc_length)
{
int ret;
u8 header[QUERY_DESC_HDR_SIZE];
int header_len = QUERY_DESC_HDR_SIZE;
if (desc_id >= QUERY_DESC_IDN_MAX)
return -EINVAL;
ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC,
desc_id, desc_index, 0, header,
&header_len);
if (ret) {
dev_err(hba->dev, "%s: Failed to get descriptor header id %d",
__func__, desc_id);
return ret;
} else if (desc_id != header[QUERY_DESC_DESC_TYPE_OFFSET]) {
dev_warn(hba->dev, "%s: descriptor header id %d and desc_id %d mismatch",
__func__, header[QUERY_DESC_DESC_TYPE_OFFSET],
desc_id);
ret = -EINVAL;
}
*desc_length = header[QUERY_DESC_LENGTH_OFFSET];
return ret;
}
/** /**
* ufshcd_map_desc_id_to_length - map descriptor IDN to its length * ufshcd_map_desc_id_to_length - map descriptor IDN to its length
* @hba: Pointer to adapter instance * @hba: Pointer to adapter instance
* @desc_id: descriptor idn value * @desc_id: descriptor idn value
* @desc_len: mapped desc length (out) * @desc_len: mapped desc length (out)
*
* Return 0 in case of success, non-zero otherwise
*/ */
int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
enum desc_idn desc_id, int *desc_len) int *desc_len)
{ {
switch (desc_id) { if (desc_id >= QUERY_DESC_IDN_MAX || desc_id == QUERY_DESC_IDN_RFU_0 ||
case QUERY_DESC_IDN_DEVICE: desc_id == QUERY_DESC_IDN_RFU_1)
*desc_len = hba->desc_size.dev_desc;
break;
case QUERY_DESC_IDN_POWER:
*desc_len = hba->desc_size.pwr_desc;
break;
case QUERY_DESC_IDN_GEOMETRY:
*desc_len = hba->desc_size.geom_desc;
break;
case QUERY_DESC_IDN_CONFIGURATION:
*desc_len = hba->desc_size.conf_desc;
break;
case QUERY_DESC_IDN_UNIT:
*desc_len = hba->desc_size.unit_desc;
break;
case QUERY_DESC_IDN_INTERCONNECT:
*desc_len = hba->desc_size.interc_desc;
break;
case QUERY_DESC_IDN_STRING:
*desc_len = QUERY_DESC_MAX_SIZE;
break;
case QUERY_DESC_IDN_HEALTH:
*desc_len = hba->desc_size.hlth_desc;
break;
case QUERY_DESC_IDN_RFU_0:
case QUERY_DESC_IDN_RFU_1:
*desc_len = 0;
break;
default:
*desc_len = 0; *desc_len = 0;
return -EINVAL; else
} *desc_len = hba->desc_size[desc_id];
return 0;
} }
EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); EXPORT_SYMBOL(ufshcd_map_desc_id_to_length);
static void ufshcd_update_desc_length(struct ufs_hba *hba,
enum desc_idn desc_id,
unsigned char desc_len)
{
if (hba->desc_size[desc_id] == QUERY_DESC_MAX_SIZE &&
desc_id != QUERY_DESC_IDN_STRING)
hba->desc_size[desc_id] = desc_len;
}
/** /**
* ufshcd_read_desc_param - read the specified descriptor parameter * ufshcd_read_desc_param - read the specified descriptor parameter
* @hba: Pointer to adapter instance * @hba: Pointer to adapter instance
...@@ -3181,16 +3118,11 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, ...@@ -3181,16 +3118,11 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) if (desc_id >= QUERY_DESC_IDN_MAX || !param_size)
return -EINVAL; return -EINVAL;
/* Get the max length of descriptor from structure filled up at probe /* Get the length of descriptor */
* time. ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len);
*/ if (!buff_len) {
ret = ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len); dev_err(hba->dev, "%s: Failed to get desc length", __func__);
return -EINVAL;
/* Sanity checks */
if (ret || !buff_len) {
dev_err(hba->dev, "%s: Failed to get full descriptor length",
__func__);
return ret;
} }
/* Check whether we need temp memory */ /* Check whether we need temp memory */
...@@ -3222,6 +3154,10 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, ...@@ -3222,6 +3154,10 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
goto out; goto out;
} }
/* Update descriptor length */
buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET];
ufshcd_update_desc_length(hba, desc_id, buff_len);
/* Check wherher we will not copy more data, than available */ /* Check wherher we will not copy more data, than available */
if (is_kmalloc && (param_offset + param_size) > buff_len) if (is_kmalloc && (param_offset + param_size) > buff_len)
param_size = buff_len - param_offset; param_size = buff_len - param_offset;
...@@ -6794,7 +6730,7 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba, ...@@ -6794,7 +6730,7 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba,
static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba) static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba)
{ {
int ret; int ret;
int buff_len = hba->desc_size.pwr_desc; int buff_len = hba->desc_size[QUERY_DESC_IDN_POWER];
u8 *desc_buf; u8 *desc_buf;
u32 icc_level; u32 icc_level;
...@@ -6912,7 +6848,8 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf) ...@@ -6912,7 +6848,8 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf)
if (!ufshcd_is_wb_allowed(hba)) if (!ufshcd_is_wb_allowed(hba))
return; return;
if (hba->desc_size.dev_desc < DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) if (hba->desc_size[QUERY_DESC_IDN_DEVICE] <
DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4)
goto wb_disabled; goto wb_disabled;
hba->dev_info.d_ext_ufs_feature_sup = hba->dev_info.d_ext_ufs_feature_sup =
...@@ -7005,7 +6942,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba) ...@@ -7005,7 +6942,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
} }
err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf,
hba->desc_size.dev_desc); hba->desc_size[QUERY_DESC_IDN_DEVICE]);
if (err) { if (err) {
dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n",
__func__, err); __func__, err);
...@@ -7234,53 +7171,13 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) ...@@ -7234,53 +7171,13 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba)
hba->req_abort_count = 0; hba->req_abort_count = 0;
} }
static void ufshcd_init_desc_sizes(struct ufs_hba *hba)
{
int err;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_DEVICE, 0,
&hba->desc_size.dev_desc);
if (err)
hba->desc_size.dev_desc = QUERY_DESC_DEVICE_DEF_SIZE;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_POWER, 0,
&hba->desc_size.pwr_desc);
if (err)
hba->desc_size.pwr_desc = QUERY_DESC_POWER_DEF_SIZE;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_INTERCONNECT, 0,
&hba->desc_size.interc_desc);
if (err)
hba->desc_size.interc_desc = QUERY_DESC_INTERCONNECT_DEF_SIZE;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_CONFIGURATION, 0,
&hba->desc_size.conf_desc);
if (err)
hba->desc_size.conf_desc = QUERY_DESC_CONFIGURATION_DEF_SIZE;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_UNIT, 0,
&hba->desc_size.unit_desc);
if (err)
hba->desc_size.unit_desc = QUERY_DESC_UNIT_DEF_SIZE;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_GEOMETRY, 0,
&hba->desc_size.geom_desc);
if (err)
hba->desc_size.geom_desc = QUERY_DESC_GEOMETRY_DEF_SIZE;
err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_HEALTH, 0,
&hba->desc_size.hlth_desc);
if (err)
hba->desc_size.hlth_desc = QUERY_DESC_HEALTH_DEF_SIZE;
}
static int ufshcd_device_geo_params_init(struct ufs_hba *hba) static int ufshcd_device_geo_params_init(struct ufs_hba *hba)
{ {
int err; int err;
size_t buff_len; size_t buff_len;
u8 *desc_buf; u8 *desc_buf;
buff_len = hba->desc_size.geom_desc; buff_len = hba->desc_size[QUERY_DESC_IDN_GEOMETRY];
desc_buf = kmalloc(buff_len, GFP_KERNEL); desc_buf = kmalloc(buff_len, GFP_KERNEL);
if (!desc_buf) { if (!desc_buf) {
err = -ENOMEM; err = -ENOMEM;
...@@ -7376,10 +7273,11 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba) ...@@ -7376,10 +7273,11 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba)
static int ufshcd_device_params_init(struct ufs_hba *hba) static int ufshcd_device_params_init(struct ufs_hba *hba)
{ {
bool flag; bool flag;
int ret; int ret, i;
/* Init check for device descriptor sizes */ /* Init device descriptor sizes */
ufshcd_init_desc_sizes(hba); for (i = 0; i < QUERY_DESC_IDN_MAX; i++)
hba->desc_size[i] = QUERY_DESC_MAX_SIZE;
/* Init UFS geometry descriptor related parameters */ /* Init UFS geometry descriptor related parameters */
ret = ufshcd_device_geo_params_init(hba); ret = ufshcd_device_geo_params_init(hba);
......
...@@ -236,16 +236,6 @@ struct ufs_dev_cmd { ...@@ -236,16 +236,6 @@ struct ufs_dev_cmd {
struct ufs_query query; struct ufs_query query;
}; };
struct ufs_desc_size {
int dev_desc;
int pwr_desc;
int geom_desc;
int interc_desc;
int unit_desc;
int conf_desc;
int hlth_desc;
};
/** /**
* struct ufs_clk_info - UFS clock related info * struct ufs_clk_info - UFS clock related info
* @list: list headed by hba->clk_list_head * @list: list headed by hba->clk_list_head
...@@ -767,7 +757,7 @@ struct ufs_hba { ...@@ -767,7 +757,7 @@ struct ufs_hba {
bool is_urgent_bkops_lvl_checked; bool is_urgent_bkops_lvl_checked;
struct rw_semaphore clk_scaling_lock; struct rw_semaphore clk_scaling_lock;
struct ufs_desc_size desc_size; unsigned char desc_size[QUERY_DESC_IDN_MAX];
atomic_t scsi_block_reqs_cnt; atomic_t scsi_block_reqs_cnt;
struct device bsg_dev; struct device bsg_dev;
...@@ -1005,8 +995,8 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, ...@@ -1005,8 +995,8 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
int ufshcd_hold(struct ufs_hba *hba, bool async); int ufshcd_hold(struct ufs_hba *hba, bool async);
void ufshcd_release(struct ufs_hba *hba); void ufshcd_release(struct ufs_hba *hba);
int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
int *desc_length); int *desc_length);
u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba); u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba);
......
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