fix(ufs): add reset before DME_LINKSTARTUP

This change aims to make the UFS code more robust by performing a
controller reset if linkstartup fails. This idea was borrowed from
Linux's ufshcd_link_startup function.

Signed-off-by: Jorge Troncoso <jatron@google.com>
Change-Id: I6b52148d1bf155b11198dc82a39b1120057adaaf
This commit is contained in:
Jorge Troncoso 2021-10-05 22:46:35 -07:00
parent 99ff1a35fe
commit 905635d5e7
2 changed files with 21 additions and 6 deletions

View File

@ -169,18 +169,30 @@ static int ufshc_reset(uintptr_t base)
return 0;
}
static int ufshc_link_startup(uintptr_t base)
static int ufshc_dme_link_startup(uintptr_t base)
{
uic_cmd_t cmd;
memset(&cmd, 0, sizeof(cmd));
cmd.op = DME_LINKSTARTUP;
return ufshc_send_uic_cmd(base, &cmd);
}
static int ufshc_link_startup(uintptr_t base)
{
int data, result;
int retries;
for (retries = 10; retries > 0; retries--) {
memset(&cmd, 0, sizeof(cmd));
cmd.op = DME_LINKSTARTUP;
result = ufshc_send_uic_cmd(base, &cmd);
if (result != 0)
for (retries = DME_LINKSTARTUP_RETRIES; retries > 0; retries--) {
result = ufshc_dme_link_startup(base);
if (result != 0) {
/* Reset controller before trying again */
result = ufshc_reset(base);
if (result != 0) {
return result;
}
continue;
}
while ((mmio_read_32(base + HCS) & HCS_DP) == 0)
;
data = mmio_read_32(base + IS);

View File

@ -258,6 +258,9 @@
/* maximum number of retries for a general UIC command */
#define UFS_UIC_COMMAND_RETRIES 3
/* maximum number of link-startup retries */
#define DME_LINKSTARTUP_RETRIES 10
#define HCE_ENABLE_OUTER_RETRIES 3
#define HCE_ENABLE_INNER_RETRIES 50
#define HCE_ENABLE_TIMEOUT_US 100