Re: [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API

From: Loic Poulain

Date: Wed Dec 02 2026 - 05:16:06 EST


On Wed, Dec 2, 2026 at 9:44 AM Manivannan Sadhasivam via B4 Relay
<devnull+manivannan.sadhasivam.oss.qualcomm.com@xxxxxxxxxx> wrote:
>
> From: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
>
> Currently, mhi_pm_suspend() returns -EBUSY when suspend is not completed
> due to device asserting WAKE or packets pending to be transferred to the
> device. While this suspend abort works fine for runtime suspend, it is a
> disaster for system suspend, because a single driver aborting suspend
> aborts the entire suspend process.
>
> So to fix this issue, introduce a new API mhi_pm_suspend_force(), which
> forces the MHI stack to trigger suspend instead of bailing out. It does so
> by waiting 100ms for the pending packets to be drained and ignoring device
> WAKE. Even if the device is wakeup capable, suspend can proceed and the
> device can wakeup the system later.

Why ignoring device wake? can we have more info on this.

>
> If the packets are not drained within the 100ms timeout, -EIO is returned
> to the caller and the caller is expected to handle that failure
> accordingly.
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> ---
> drivers/bus/mhi/host/internal.h | 3 +++
> drivers/bus/mhi/host/pm.c | 38 ++++++++++++++++++++++++++++++++------
> include/linux/mhi.h | 14 ++++++++++++++
> 3 files changed, 49 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h
> index 7b0ee5e3a12d..a11a00b2eda5 100644
> --- a/drivers/bus/mhi/host/internal.h
> +++ b/drivers/bus/mhi/host/internal.h
> @@ -292,6 +292,9 @@ struct mhi_chan {
> /* Default MHI timeout */
> #define MHI_TIMEOUT_MS (1000)
>
> +#define MHI_PKT_DRAIN_POLL_US (1 * USEC_PER_MSEC)
> +#define MHI_PKT_DRAIN_TIMEOUT_US (100 * USEC_PER_MSEC)
> +
> /* debugfs related functions */
> #ifdef CONFIG_MHI_BUS_DEBUG
> void mhi_create_debugfs(struct mhi_controller *mhi_cntrl);
> diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c
> index ced83fbb1a51..847774f19161 100644
> --- a/drivers/bus/mhi/host/pm.c
> +++ b/drivers/bus/mhi/host/pm.c
> @@ -9,6 +9,7 @@
> #include <linux/dma-direction.h>
> #include <linux/dma-mapping.h>
> #include <linux/interrupt.h>
> +#include <linux/iopoll.h>
> #include <linux/list.h>
> #include <linux/mhi.h>
> #include <linux/module.h>
> @@ -856,7 +857,7 @@ void mhi_pm_st_worker(struct work_struct *work)
> }
> }
>
> -int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
> +static int __mhi_pm_suspend(struct mhi_controller *mhi_cntrl, bool force)
> {
> struct mhi_chan *itr, *tmp;
> struct device *dev = &mhi_cntrl->mhi_dev->dev;
> @@ -869,10 +870,24 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
> if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state))
> return -EIO;
>
> - /* Return busy if there are any pending resources */
> - if (atomic_read(&mhi_cntrl->dev_wake) ||
> - atomic_read(&mhi_cntrl->pending_pkts))
> - return -EBUSY;
> + if (force) {
> + int pkts;
> +
> + ret = readx_poll_timeout(atomic_read, &mhi_cntrl->pending_pkts, pkts,
> + !pkts || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state),
> + MHI_PKT_DRAIN_POLL_US, MHI_PKT_DRAIN_TIMEOUT_US);
> +
> + if (ret || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) {
> + dev_err(dev, "Could not drain pending packets, PM state: %s\n",
> + to_mhi_pm_state_str(mhi_cntrl->pm_state));
> + return -EIO;

That would probably deserve a dedicated flush/drain helper, but
otherwise looks good.

> + }
> + } else {
> + /* Return busy if there are any pending resources */
> + if (atomic_read(&mhi_cntrl->dev_wake) ||
> + atomic_read(&mhi_cntrl->pending_pkts))
> + return -EBUSY;
> + }
>
> /* Take MHI out of M2 state */
> read_lock_bh(&mhi_cntrl->pm_lock);
> @@ -897,7 +912,7 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
>
> write_lock_irq(&mhi_cntrl->pm_lock);
>
> - if (atomic_read(&mhi_cntrl->dev_wake) ||
> + if ((!force && atomic_read(&mhi_cntrl->dev_wake)) ||
> atomic_read(&mhi_cntrl->pending_pkts)) {
> write_unlock_irq(&mhi_cntrl->pm_lock);
> return -EBUSY;
> @@ -959,8 +974,19 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
>
> return 0;
> }
> +
> +int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
> +{
> + return __mhi_pm_suspend(mhi_cntrl, false);
> +}
> EXPORT_SYMBOL_GPL(mhi_pm_suspend);
>
> +int mhi_pm_suspend_force(struct mhi_controller *mhi_cntrl)
> +{
> + return __mhi_pm_suspend(mhi_cntrl, true);
> +}
> +EXPORT_SYMBOL_GPL(mhi_pm_suspend_force);
> +
> static int __mhi_pm_resume(struct mhi_controller *mhi_cntrl, bool force)
> {
> struct mhi_chan *itr, *tmp;
> diff --git a/include/linux/mhi.h b/include/linux/mhi.h
> index 65e8a397cc50..63823214f3fb 100644
> --- a/include/linux/mhi.h
> +++ b/include/linux/mhi.h
> @@ -674,6 +674,20 @@ void mhi_unprepare_after_power_down(struct mhi_controller *mhi_cntrl);
> */
> int mhi_pm_suspend(struct mhi_controller *mhi_cntrl);
>
> +/**
> + * mhi_pm_suspend_force - Force MHI into a suspended state
> + * @mhi_cntrl: MHI controller
> + *
> + * Like mhi_pm_suspend(), but instead of returning busy as soon as the device
> + * has pending work, it waits a bounded time for the uplink transfers to drain
> + * and ignores the device WAKE vote. A wakeup capable device can still wake the
> + * system up later. This API is intended for system suspend, where one driver
> + * refusing to suspend aborts the whole transition.
> + *
> + * Return: 0 if the suspend succeeds, a negative error code otherwise
> + */
> +int mhi_pm_suspend_force(struct mhi_controller *mhi_cntrl);
> +
> /**
> * mhi_pm_resume - Resume MHI from suspended state
> * @mhi_cntrl: MHI controller
>
> --
> 2.43.0
>
>