scsi: ufs: host: mediatek: Return error directly on idle wait timeout

Optimize the recovery flow by returning an error code immediately if a
wait idle timeout occurs, rather than waiting for the link to reach the
up state. Shorten the recovery process and improve error handling
efficiency when idle state transitions fail.

Signed-off-by: Sanjeev Y <sanjeev.y@mediatek.com>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Sanjeev Y 2025-09-03 10:44:43 +08:00 committed by Martin K. Petersen
parent f5ca8d0c7a
commit f29ec85ac4

View File

@ -416,7 +416,7 @@ static void ufs_mtk_dbg_sel(struct ufs_hba *hba)
}
}
static void ufs_mtk_wait_idle_state(struct ufs_hba *hba,
static int ufs_mtk_wait_idle_state(struct ufs_hba *hba,
unsigned long retry_ms)
{
u64 timeout, time_checked;
@ -452,8 +452,12 @@ static void ufs_mtk_wait_idle_state(struct ufs_hba *hba,
break;
} while (time_checked < timeout);
if (wait_idle && sm != VS_HCE_BASE)
if (wait_idle && sm != VS_HCE_BASE) {
dev_info(hba->dev, "wait idle tmo: 0x%x\n", val);
return -ETIMEDOUT;
}
return 0;
}
static int ufs_mtk_wait_link_state(struct ufs_hba *hba, u32 state,
@ -1437,9 +1441,13 @@ static int ufs_mtk_auto_hibern8_disable(struct ufs_hba *hba)
ufshcd_writel(hba, 0, REG_AUTO_HIBERNATE_IDLE_TIMER);
/* wait host return to idle state when auto-hibern8 off */
ufs_mtk_wait_idle_state(hba, 5);
ret = ufs_mtk_wait_idle_state(hba, 5);
if (ret)
goto out;
ret = ufs_mtk_wait_link_state(hba, VS_LINK_UP, 100);
out:
if (ret) {
dev_warn(hba->dev, "exit h8 state fail, ret=%d\n", ret);
@ -1614,7 +1622,11 @@ static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
return err;
/* Check link state to make sure exit h8 success */
ufs_mtk_wait_idle_state(hba, 5);
err = ufs_mtk_wait_idle_state(hba, 5);
if (err) {
dev_warn(hba->dev, "wait idle fail, err=%d\n", err);
return err;
}
err = ufs_mtk_wait_link_state(hba, VS_LINK_UP, 100);
if (err) {
dev_warn(hba->dev, "exit h8 state fail, err=%d\n", err);