[PATCH v3 5/6] bus: mhi: core: Improve mhi_sync_power_up handling for SYS_ERR state

Vivek.Pernamitta@quicinc.com posted 6 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v3 5/6] bus: mhi: core: Improve mhi_sync_power_up handling for SYS_ERR state
Posted by Vivek.Pernamitta@quicinc.com 1 month, 1 week ago
From: Vivek Pernamitta <quic_vpernami@quicinc.com>

In power-up, reboot, or recovery scenarios, mhi_sync_power_up() is invoked
by the controller driver to wait for the device to enter Mission Mode.

However, in some cases, the device may be in SYS_ERR state due to a
previous device reset. SYS_ERR is a valid state, but currently, the host
exits at wait_event_timeout() prematurely when MHI_PM_IN_ERROR_STATE is
detected, causing mhi_sync_power_up() to fail.

If MHI is torn down before SYS_ERR is serviced, recovery is not possible.
Instead of aborting, the SYS_ERR handler should process the error and queue
the next state transition to bring the device into Mission Mode.

This change ensures mhi_sync_power_up() waits for Mission Mode even
after SYS_ERR, enabling proper recovery and improving robustness.

Signed-off-by: Vivek Pernamitta <quic_vpernami@quicinc.com>
---
 drivers/bus/mhi/host/internal.h | 2 ++
 drivers/bus/mhi/host/pm.c       | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h
index 034be33565b78eff9bdefd93faa4f3ce93825bad..9e37e5c9a6c7e07d54300adce51c9db9052e477a 100644
--- a/drivers/bus/mhi/host/internal.h
+++ b/drivers/bus/mhi/host/internal.h
@@ -170,6 +170,8 @@ enum mhi_pm_state {
 							MHI_PM_IN_ERROR_STATE(pm_state))
 #define MHI_PM_IN_SUSPEND_STATE(pm_state)		(pm_state & \
 							(MHI_PM_M3_ENTER | MHI_PM_M3))
+#define MHI_PM_IN_UNRECOVERABLE_ERROR(pm_state)		((pm_state == MHI_PM_FW_DL_ERR) || \
+							(pm_state >= MHI_PM_SYS_ERR_FAIL))
 
 #define NR_OF_CMD_RINGS					1
 #define CMD_EL_PER_RING					128
diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c
index 33d92bf2fc3ed48db5f7fe80e4f0ef9fe2d2f2ab..e908bbce79e9a8a76881b5d040c7e9d4985124dc 100644
--- a/drivers/bus/mhi/host/pm.c
+++ b/drivers/bus/mhi/host/pm.c
@@ -1279,7 +1279,7 @@ int mhi_sync_power_up(struct mhi_controller *mhi_cntrl)
 		mhi_cntrl->ready_timeout_ms : mhi_cntrl->timeout_ms;
 	wait_event_timeout(mhi_cntrl->state_event,
 			   MHI_IN_MISSION_MODE(mhi_cntrl->ee) ||
-			   MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state),
+			   MHI_PM_IN_UNRECOVERABLE_ERROR(mhi_cntrl->pm_state),
 			   msecs_to_jiffies(timeout_ms));
 
 	ret = (MHI_IN_MISSION_MODE(mhi_cntrl->ee)) ? 0 : -ETIMEDOUT;

-- 
2.34.1
Re: [PATCH v3 5/6] bus: mhi: core: Improve mhi_sync_power_up handling for SYS_ERR state
Posted by Manivannan Sadhasivam 4 weeks ago
On Thu, Aug 21, 2025 at 06:25:37PM GMT, Vivek.Pernamitta@quicinc.com wrote:
> From: Vivek Pernamitta <quic_vpernami@quicinc.com>
> 
> In power-up, reboot, or recovery scenarios, mhi_sync_power_up() is invoked
> by the controller driver to wait for the device to enter Mission Mode.
> 
> However, in some cases, the device may be in SYS_ERR state due to a
> previous device reset. SYS_ERR is a valid state, but currently, the host
> exits at wait_event_timeout() prematurely when MHI_PM_IN_ERROR_STATE is
> detected, causing mhi_sync_power_up() to fail.
> 
> If MHI is torn down before SYS_ERR is serviced, recovery is not possible.
> Instead of aborting, the SYS_ERR handler should process the error and queue
> the next state transition to bring the device into Mission Mode.
> 
> This change ensures mhi_sync_power_up() waits for Mission Mode even
> after SYS_ERR, enabling proper recovery and improving robustness.
> 

Reword the description in imperative mood. Also, if this is an independent fix,
this patch should be moved to the start of the series.

> Signed-off-by: Vivek Pernamitta <quic_vpernami@quicinc.com>
> ---
>  drivers/bus/mhi/host/internal.h | 2 ++
>  drivers/bus/mhi/host/pm.c       | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h
> index 034be33565b78eff9bdefd93faa4f3ce93825bad..9e37e5c9a6c7e07d54300adce51c9db9052e477a 100644
> --- a/drivers/bus/mhi/host/internal.h
> +++ b/drivers/bus/mhi/host/internal.h
> @@ -170,6 +170,8 @@ enum mhi_pm_state {
>  							MHI_PM_IN_ERROR_STATE(pm_state))
>  #define MHI_PM_IN_SUSPEND_STATE(pm_state)		(pm_state & \
>  							(MHI_PM_M3_ENTER | MHI_PM_M3))
> +#define MHI_PM_IN_UNRECOVERABLE_ERROR(pm_state)		((pm_state == MHI_PM_FW_DL_ERR) || \

MHI_PM_IN_UNRECOVERABLE_STATE?

- Mani

-- 
மணிவண்ணன் சதாசிவம்