ufs: introduce UFSHCD_QUIRK_USE_OF_HCE quirk
PATCH 1/1 ufs: introduce UFSHCD_QUIRK_USE_OF_HCE quirk
Some host controller might not initialize itself by setting "Host Controller Enable" to 1.
They should do this to reset UIC.
In such cases, 'DME reset' and 'DME enable' are required for normal subsequent operations.
--- drivers/scsi/ufs/ufshcd.c | 44 +++++++++++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +43 -1
@@ -2496,6 +2496,37 @@ static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba)usleep_range (min_sleep_time_us, min_sleep_time_us +50 ); } +static int ufshcd_dme_reset (struct ufs_hba *hba) +{ +struct uic_command uic_cmd = {0 }; +int ret; + + uic_cmd.command =UIC_CMD_DME_RESET ; + uic_cmd.argument1 =0x1 ; + + ret =ufshcd_send_uic_cmd (hba, &uic_cmd); +if (ret) +dev_err (hba->dev, +"dme-reset: error code %d\n" , ret); + +return ret; +} + +static int ufshcd_dme_enable (struct ufs_hba *hba) +{ +struct uic_command uic_cmd = {0 }; +int ret; + + uic_cmd.command =UIC_CMD_DME_ENABLE ; + + ret =ufshcd_send_uic_cmd (hba, &uic_cmd); +if (ret) +dev_err (hba->dev, +"dme-enable: error code %d\n" , ret); + +return ret; +} +/** * ufshcd_dme_set_attr - UIC command for DME_SET, DME_PEER_SET * @hba: per adapter instance
@@ -3101,6 +3132,7 @@ static inline void ufshcd_hba_stop(struct ufs_hba *hba, bool can_sleep)static int ufshcd_hba_enable (struct ufs_hba *hba) {int retry; +int ret =0 ;/* * msleep of 1 and 5 used in this function might result in msleep(20),
@@ -3117,6 +3149,9 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)ufshcd_vops_hce_enable_notify (hba,PRE_CHANGE ); +if (hba->quirks &UFSHCD_QUIRK_USE_OF_HCE ) + goto use_dme; +/* start controller initialization sequence */ ufshcd_hba_start (hba);
@@ -3145,12 +3180,19 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)msleep (5 ); } +use_dme:/* enable UIC related interrupts */ ufshcd_enable_intr (hba,UFSHCD_UIC_MASK ); +if (hba->quirks &UFSHCD_QUIRK_USE_OF_HCE ) { + ret =ufshcd_dme_reset (hba); +if (!ret) + ret =ufshcd_dme_enable (hba); + } +ufshcd_vops_hce_enable_notify (hba,POST_CHANGE ); -return 0 ; +return ret; }static int ufshcd_disable_tx_lcc (struct ufs_hba *hba,bool peer)
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -496,6 +496,7 @@ struct ufs_hba {#define UFSHCD_QUIRK_GET_VS_RESULT UFS_BIT(6)#define UFSHCD_QUIRK_BROKEN_DWORD_UTRD UFS_BIT(7)#define UFSHCD_QUIRK_BROKEN_REQ_LIST_CLR UFS_BIT(8) +#define UFSHCD_QUIRK_USE_OF_HCE UFS_BIT(9)unsigned int quirks;/* Deviations from standard UFSHCI spec. */
Signature · 1 line
2.1.4
Quoted 4 lines · Kiwoong Kim
Some host controller might not initialize itself
by setting "Host Controller Enable" to 1.They should do this to reset UIC.
I am not sure if i understood this statment. can you give more details?
Quoted 2 lines
In such cases, 'DME reset' and 'DME enable' are required for normal subsequent operations.
This means HCE implementation is broken, you should name the quirk as UFSHCD_QUIRK_BROKEN_HCE .
Quoted 19 lines
Signed-off-by Kiwoong Kim <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 44 +++++++++++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)drivers/scsi/ufs/ufshcd.c +2
-0@@ -2496,6 +2496,37 @@ static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba) usleep_range(min_sleep_time_us, min_sleep_time_us + 50); } +static int ufshcd_dme_reset(struct ufs_hba *hba) +{
drivers/scsi/ufs/ufshcd.c static inline void · line 2511
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10
-0+struct uic_command uic_cmd = {0 }; +int ret; + + uic_cmd.command =UIC_CMD_DME_RESET ; + uic_cmd.argument1 =0x1 ; + + ret =ufshcd_send_uic_cmd (hba, &uic_cmd); +if (ret) +dev_err (hba->dev, +"dme-reset: error code %d\n" , ret);
This error message doesn't say which DME command failed, do you want to add that?
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +5
-0+ +return ret; +} + +static int ufshcd_dme_enable (struct ufs_hba *hba)
drivers/scsi/ufs/ufshcd.c static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba) · line 2525
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10
-0+{ +struct uic_command uic_cmd = {0 }; +int ret; + + uic_cmd.command =UIC_CMD_DME_ENABLE ; + + ret =ufshcd_send_uic_cmd (hba, &uic_cmd); +if (ret) +dev_err (hba->dev, +"dme-enable: error code %d\n" , ret);
This error message doesn't say which DME command failed, do you want to add that?
Quoted 61 lines
drivers/scsi/ufs/ufshcd.c +4
-0+ +return ret; +} +/** * ufshcd_dme_set_attr - UIC command for DME_SET, DME_PEER_SET * @hba: per adapter instance
drivers/scsi/ufs/ufshcd.c +1
-0@@ -3101,6 +3132,7 @@ static inline void ufshcd_hba_stop(struct ufs_hba *hba, bool can_sleep)static int ufshcd_hba_enable (struct ufs_hba *hba) {int retry; +int ret =0 ;/* * msleep of 1 and 5 used in this function might result in
msleep(20),drivers/scsi/ufs/ufshcd.c +11
-1@@ -3117,6 +3149,9 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)ufshcd_vops_hce_enable_notify (hba,PRE_CHANGE ); +if (hba->quirks &UFSHCD_QUIRK_USE_OF_HCE ) + goto use_dme; +/* start controller initialization sequence */ ufshcd_hba_start (hba);@@ -3145,12 +3180,19 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)msleep (5 ); } +use_dme:/* enable UIC related interrupts */ ufshcd_enable_intr (hba,UFSHCD_UIC_MASK ); +if (hba->quirks &UFSHCD_QUIRK_USE_OF_HCE ) { + ret =ufshcd_dme_reset (hba); +if (!ret) + ret =ufshcd_dme_enable (hba); + } +ufshcd_vops_hce_enable_notify (hba,POST_CHANGE ); -return 0 ; +return ret; }static int
ufshcd_disable_tx_lcc(struct ufs_hba *hba, bool peer)drivers/scsi/ufs/ufshcd.h +1
-0@@ -496,6 +496,7 @@ struct ufs_hba {#define UFSHCD_QUIRK_GET_VS_RESULT UFS_BIT(6)#define UFSHCD_QUIRK_BROKEN_DWORD_UTRD UFS_BIT(7)#define UFSHCD_QUIRK_BROKEN_REQ_LIST_CLR UFS_BIT(8) +#define UFSHCD_QUIRK_USE_OF_HCE UFS_BIT(9)unsigned int quirks;/* Deviations from standard UFSHCI spec. */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 9 lines · Kiwoong Kim
Quoted 4 lines
Some host controller might not initialize itself by setting "Host Controller Enable" to 1.
They should do this to reset UIC.
I am not sure if i understood this statment. can you give more details?
UFSHCI spec says as follows:
- When HCE is ‘0’ and software writes ‘1’, the host controller hardware shall execute the step 2 described in section 7.1.1 of this standard, including reset of the host UTP and UIC layers.
I found that a specific controller didn't execute reset of UIC layers Properly for an internal problem.
At that time, DME reset and DME enable could make UIC be reset properly instead of using "Host Controller Enable".
Quoted 6 lines
Quoted 3 lines
In such cases, 'DME reset' and 'DME enable' are required for normal subsequent operations.
This means HCE implementation is broken, you should name the quirk as
UFSHCD_QUIRK_BROKEN_HCE.
Okay.
Quoted 17 lines
Quoted 17 lines
Signed-off-by Kiwoong Kim <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 44 +++++++++++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)drivers/scsi/ufs/ufshcd.c +0
-0@@ -2496,6 +2496,37 @@ static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba) usleep_range(min_sleep_time_us, min_sleep_time_us + 50); }
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba) · line 2510
Quoted 11 lines
drivers/scsi/ufs/ufshcd.c +11
-0+static int ufshcd_dme_reset (struct ufs_hba *hba) { +struct uic_command uic_cmd = {0 }; +int ret; + + uic_cmd.command =UIC_CMD_DME_RESET ; + uic_cmd.argument1 =0x1 ; + + ret =ufshcd_send_uic_cmd (hba, &uic_cmd); +if (ret) +dev_err (hba->dev, +"dme-reset: error code %d\n" , ret);This error message doesn't say which DME command failed, do you want to add that?
I think that the string "dme-reset" is useful when clarifying some problems. But if you don't agree merging it to mainline, I'll remove it in next version.
Quoted 10 lines
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +9
-0+ +return ret; +} + +static int ufshcd_dme_enable (struct ufs_hba *hba) { +struct uic_command uic_cmd = {0 }; +int ret; + + uic_cmd.command =UIC_CMD_DME_ENABLE ;
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba) · line 2525
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +5
-0+ + ret =ufshcd_send_uic_cmd (hba, &uic_cmd); +if (ret) +dev_err (hba->dev, +"dme-enable: error code %d\n" , ret);This error message doesn't say which DME command failed, do you want to add that?
Same with above.
Quoted 66 lines
Quoted 54 lines
drivers/scsi/ufs/ufshcd.c +4
-0+ +return ret; +} +/** * ufshcd_dme_set_attr - UIC command for DME_SET, DME_PEER_SET * @hba: per adapter instance @@ -3101,6 +3132,7 @@ static inline void ufshcd_hba_stop(struct
ufs_hba*hba, boolcan_sleep) static intufshcd_hba_enable(struct ufs_hba *hba){drivers/scsi/ufs/ufshcd.c +1
-0int retry; +int ret =0 ;/* * msleep of 1 and 5 used in this function might result in msleep(20), @@ -3117,6 +3149,9 @@ static int
ufshcd_hba_enable(struct ufs_hba *hba)drivers/scsi/ufs/ufshcd.c +11
-1ufshcd_vops_hce_enable_notify (hba,PRE_CHANGE ); +if (hba->quirks &UFSHCD_QUIRK_USE_OF_HCE ) + goto use_dme; +/* start controller initialization sequence */ ufshcd_hba_start (hba);@@ -3145,12 +3180,19 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)msleep (5 ); } +use_dme:/* enable UIC related interrupts */ ufshcd_enable_intr (hba,UFSHCD_UIC_MASK ); +if (hba->quirks &UFSHCD_QUIRK_USE_OF_HCE ) { + ret =ufshcd_dme_reset (hba); +if (!ret) + ret =ufshcd_dme_enable (hba); + } +ufshcd_vops_hce_enable_notify (hba,POST_CHANGE ); -return 0 ; +return ret; }static int
ufshcd_disable_tx_lcc(struct ufs_hba *hba, bool peer)diff
--gita/drivers/scsi/ufs/ufshcd.hb/drivers/scsi/ufs/ufshcd.hindex c4abd76..6a96f24 100644drivers/scsi/ufs/ufshcd.h struct ufs_hba { · line 502
Quoted 7 lines
drivers/scsi/ufs/ufshcd.h +1
-0@@ -496,6 +496,7 @@ struct ufs_hba {#define UFSHCD_QUIRK_GET_VS_RESULT UFS_BIT(6)#define UFSHCD_QUIRK_BROKEN_DWORD_UTRD UFS_BIT(7)#define UFSHCD_QUIRK_BROKEN_REQ_LIST_CLR UFS_BIT(8) +#define UFSHCD_QUIRK_USE_OF_HCE UFS_BIT(9)unsigned int quirks;/* Deviations from standard UFSHCI spec. */
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project