Skip to content

Commit e89860f

Browse files
Can Guomartinkpetersen
authored andcommitted
scsi: ufs: Do not rely on prefetched data
We were setting bActiveICCLevel attribute for UFS device only once but the type of this attribute has changed from persistent to volatile since UFS device specification v2.1. This attribute is set to the default value after power cycle or hardware reset event. It isn't safe to rely on prefetched data (only used for bActiveICCLevel attribute now). Hence this change removes the code related to data prefetching and set this parameter on every attempt to probe the UFS device. Tested-by: Stanley Chu <[email protected]> Reviewed-by: Stanley Chu <[email protected]> Reviewed-by: Avri Altman <[email protected]> Signed-off-by: Can Guo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ccfa00a commit e89860f

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

drivers/scsi/ufs/ufshcd.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6475,11 +6475,12 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba,
64756475
return icc_level;
64766476
}
64776477

6478-
static void ufshcd_init_icc_levels(struct ufs_hba *hba)
6478+
static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba)
64796479
{
64806480
int ret;
64816481
int buff_len = hba->desc_size.pwr_desc;
64826482
u8 *desc_buf;
6483+
u32 icc_level;
64836484

64846485
desc_buf = kmalloc(buff_len, GFP_KERNEL);
64856486
if (!desc_buf)
@@ -6494,20 +6495,17 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba)
64946495
goto out;
64956496
}
64966497

6497-
hba->init_prefetch_data.icc_level =
6498-
ufshcd_find_max_sup_active_icc_level(hba,
6499-
desc_buf, buff_len);
6500-
dev_dbg(hba->dev, "%s: setting icc_level 0x%x",
6501-
__func__, hba->init_prefetch_data.icc_level);
6498+
icc_level = ufshcd_find_max_sup_active_icc_level(hba, desc_buf,
6499+
buff_len);
6500+
dev_dbg(hba->dev, "%s: setting icc_level 0x%x", __func__, icc_level);
65026501

65036502
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
6504-
QUERY_ATTR_IDN_ACTIVE_ICC_LVL, 0, 0,
6505-
&hba->init_prefetch_data.icc_level);
6503+
QUERY_ATTR_IDN_ACTIVE_ICC_LVL, 0, 0, &icc_level);
65066504

65076505
if (ret)
65086506
dev_err(hba->dev,
65096507
"%s: Failed configuring bActiveICCLevel = %d ret = %d",
6510-
__func__, hba->init_prefetch_data.icc_level , ret);
6508+
__func__, icc_level, ret);
65116509

65126510
out:
65136511
kfree(desc_buf);
@@ -7027,8 +7025,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
70277025
{
70287026
int ret;
70297027

7030-
ufshcd_init_icc_levels(hba);
7031-
70327028
/* Add required well known logical units to scsi mid layer */
70337029
ret = ufshcd_scsi_add_wlus(hba);
70347030
if (ret)
@@ -7126,6 +7122,14 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool async)
71267122
}
71277123
}
71287124

7125+
/*
7126+
* bActiveICCLevel is volatile for UFS device (as per latest v2.1 spec)
7127+
* and for removable UFS card as well, hence always set the parameter.
7128+
* Note: Error handler may issue the device reset hence resetting
7129+
* bActiveICCLevel as well so it is always safe to set this here.
7130+
*/
7131+
ufshcd_set_active_icc_lvl(hba);
7132+
71297133
/* set the state as operational after switching to desired gear */
71307134
hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
71317135

drivers/scsi/ufs/ufshcd.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,6 @@ struct ufs_clk_scaling {
408408
bool is_suspended;
409409
};
410410

411-
/**
412-
* struct ufs_init_prefetch - contains data that is pre-fetched once during
413-
* initialization
414-
* @icc_level: icc level which was read during initialization
415-
*/
416-
struct ufs_init_prefetch {
417-
u32 icc_level;
418-
};
419-
420411
#define UFS_ERR_REG_HIST_LENGTH 8
421412
/**
422413
* struct ufs_err_reg_hist - keeps history of errors
@@ -585,7 +576,6 @@ enum ufshcd_caps {
585576
* @intr_mask: Interrupt Mask Bits
586577
* @ee_ctrl_mask: Exception event control mask
587578
* @is_powered: flag to check if HBA is powered
588-
* @init_prefetch_data: data pre-fetched during initialization
589579
* @eh_work: Worker to handle UFS errors that require s/w attention
590580
* @eeh_work: Worker to handle exception events
591581
* @errors: HBA errors
@@ -674,7 +664,6 @@ struct ufs_hba {
674664
u16 ee_ctrl_mask;
675665
u16 hba_enable_delay_us;
676666
bool is_powered;
677-
struct ufs_init_prefetch init_prefetch_data;
678667

679668
/* Work Queues */
680669
struct work_struct eh_work;

0 commit comments

Comments
 (0)