From: Vivek Pernamitta quic_vpernami@quicinc.com
[ Upstream commit aa1a0e93ed21a06acb7ca9d4a4a9fce75ea53d0c ]
Allow mhi_sync_power_up to handle SYS_ERR during power-up, reboot, or recovery. This is to avoid premature exit when MHI_PM_IN_ERROR_STATE is observed during above mentioned system states.
To achieve this, treat SYS_ERR as a valid state and let its handler process the error and queue the next transition to Mission Mode instead of aborting early.
Signed-off-by: Vivek Pernamitta quic_vpernami@quicinc.com [mani: reworded description] Signed-off-by: Manivannan Sadhasivam manivannan.sadhasivam@oss.qualcomm.com Link: https://patch.msgid.link/20250912-uevent_vdev_next-20250911-v4-5-fa2f6ccd301... Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES – the change keeps `mhi_sync_power_up()` waiting through recoverable SYS_ERR handling instead of aborting immediately, which fixes real device bring-up failures without touching unrelated logic.
- `drivers/bus/mhi/host/pm.c:1287` now waits for `MHI_PM_FATAL_ERROR(pm_state)` instead of any `MHI_PM_IN_ERROR_STATE`, so the synchronous power-up path no longer bails as soon as the controller reports `SYS_ERR_DETECT`/`SYS_ERR_PROCESS`; that lets the existing SYS_ERR recovery workflow (`mhi_pm_sys_error_transition()` at `drivers/bus/mhi/host/pm.c:597`) drive the device back to mission mode instead of forcing an unnecessary tear-down (`mhi_power_down()` call that follows on timeout). - `drivers/bus/mhi/host/internal.h:173` introduces `MHI_PM_FATAL_ERROR()` to classify only firmware-download failures and states ≥`MHI_PM_SYS_ERR_FAIL` as fatal. This mirrors the state-machine design where `SYS_ERR_DETECT/PROCESS` are transitional and should be handled, while `SYS_ERR_FAIL`, `SHUTDOWN_PROCESS`, and `LD_ERR_FATAL_DETECT` are terminal. - Without this patch, any transient SYS_ERR during power-up/recovery causes `wait_event_timeout()` to return immediately, leading to `-ETIMEDOUT` and forced power-down; that breaks reboot/recovery flows for controllers that legitimately enter SYS_ERR before reinitialising. With the patch, fatal errors still short-circuit (so failure propagation is unchanged) and the normal timeout still protects against hangs, keeping risk minimal. - Dependencies: it assumes the earlier addition of the `MHI_PM_SYS_ERR_FAIL` state (`drivers/bus/mhi/host/internal.h:152`), so stable trees lacking commit bce3f770684cc (Jan 2024) need that prerequisite; otherwise the fix is self-contained.
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 034be33565b78..9f815cfac763e 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_FATAL_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 33d92bf2fc3ed..31b20c07de9ee 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_FATAL_ERROR(mhi_cntrl->pm_state), msecs_to_jiffies(timeout_ms));
ret = (MHI_IN_MISSION_MODE(mhi_cntrl->ee)) ? 0 : -ETIMEDOUT;