mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] bus: mhi: host: Do not abort system suspend when the MHI device is busy
@ 2026-12-02  8:43 Manivannan Sadhasivam via B4 Relay
  2026-12-02  8:43 ` [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API Manivannan Sadhasivam via B4 Relay
  2026-12-02  8:43 ` [PATCH 2/2] bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend Manivannan Sadhasivam via B4 Relay
  0 siblings, 2 replies; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-12-02  8:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Jeff Hugo, Loic Poulain
  Cc: mhi, linux-arm-msm, linux-kernel, Abel Vesa, Len Brown,
	Manivannan Sadhasivam, stable

Hi,

This series fixes the system suspend issue reported on both Qcom Glymur based
laptops and Lenovo Thinkpad T16. The MHI driver was preventing the system
suspend by erroring out the suspend callback if the device was busy. But now,
the series tries to drain the in flight uplink transfers and proceeds with the
system suspend upon timeout. During resume, the resume callback will recover
the device if needed.

This series supersedes the series from Len Brown [1], which just ignored the
error returned by the suspend callback. That lets system suspend proceed, but
the failed suspend has already cleared MHI_PCI_DEV_SUSPENDED, so the resume
callback bails out early and never recovers a device that lost power while
suspended.

[1] https://lore.kernel.org/mhi/20261113151940.2922539-1-lenb@kernel.org

Testing
=======

I've tested this series on Glymur CRD. But testing needs to be done on Lenovo
Thinkpad T16. I hope Len can test it on his machine.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
Manivannan Sadhasivam (2):
      bus: mhi: host: Add mhi_pm_suspend_force() API
      bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend

 drivers/bus/mhi/host/internal.h    |  3 +++
 drivers/bus/mhi/host/pci_generic.c | 18 +++++++++++++-----
 drivers/bus/mhi/host/pm.c          | 38 ++++++++++++++++++++++++++++++++------
 include/linux/mhi.h                | 14 ++++++++++++++
 4 files changed, 62 insertions(+), 11 deletions(-)
---
base-commit: c1d8ed37bf1b82c83c10a390890609e1165bdca4
change-id: 20261202-mhi-suspend-fix-a80ed1ec0dd9

Best regards,
--  
மணிவண்ணன் சதாசிவம்



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API
  2026-12-02  8:43 [PATCH 0/2] bus: mhi: host: Do not abort system suspend when the MHI device is busy Manivannan Sadhasivam via B4 Relay
@ 2026-12-02  8:43 ` Manivannan Sadhasivam via B4 Relay
  2026-12-02 10:15   ` Loic Poulain
  2026-12-02 13:50   ` Loic Poulain
  2026-12-02  8:43 ` [PATCH 2/2] bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend Manivannan Sadhasivam via B4 Relay
  1 sibling, 2 replies; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-12-02  8:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Jeff Hugo, Loic Poulain
  Cc: mhi, linux-arm-msm, linux-kernel, Abel Vesa, Len Brown,
	Manivannan Sadhasivam, stable

From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

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.

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@oss.qualcomm.com>
Cc: stable@vger.kernel.org
---
 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;
+		}
+	} 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend
  2026-12-02  8:43 [PATCH 0/2] bus: mhi: host: Do not abort system suspend when the MHI device is busy Manivannan Sadhasivam via B4 Relay
  2026-12-02  8:43 ` [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API Manivannan Sadhasivam via B4 Relay
@ 2026-12-02  8:43 ` Manivannan Sadhasivam via B4 Relay
  2026-12-02 10:19   ` Loic Poulain
  1 sibling, 1 reply; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-12-02  8:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Jeff Hugo, Loic Poulain
  Cc: mhi, linux-arm-msm, linux-kernel, Abel Vesa, Len Brown,
	Manivannan Sadhasivam, stable

From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

System suspend reuses the runtime suspend callback, so it inherits the
-EBUSY abort of mhi_pm_suspend() when the device has asserted WAKE or has
packets pending to be transferred. While aborting works fine for runtime
suspend, it is a disaster for system suspend, because a single driver
aborting suspend aborts the entire suspend process. This is what happens on
Qcom Glymur based laptops and Lenovo Thinkpad T16 laptops, where a failed
MHI modem suspend aborts the whole system suspend:

  mhi-pci-generic 0006:01:00.0: failed to suspend device: -16
  mhi-pci-generic 0006:01:00.0: PM: failed to suspend async: error -16

To fix this issue, make use of the new API mhi_pm_suspend_force() during
system suspend and continue using mhi_pm_suspend() during runtime suspend.
To achieve this, split the common part of the suspend code into
__mhi_pci_suspend() helper with the 'force' argument. And set this argument
to true during system suspend and false during runtime suspend.

If the mhi_pm_suspend_force() API returns an error for any reason, continue
the system suspend as there is nothing more the driver can do. Later during
resume, the device will be recovered if needed.

Reported-by: Len Brown <len.brown@intel.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220020
Reported-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
Fixes: d3800c1dce24 ("bus: mhi: pci_generic: Add support for runtime PM")
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Cc: stable@vger.kernel.org
---
 drivers/bus/mhi/host/pci_generic.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/bus/mhi/host/pci_generic.c b/drivers/bus/mhi/host/pci_generic.c
index b1938c55ffda..9eb7dbb68d2e 100644
--- a/drivers/bus/mhi/host/pci_generic.c
+++ b/drivers/bus/mhi/host/pci_generic.c
@@ -1694,7 +1694,7 @@ static const struct pci_error_handlers mhi_pci_err_handler = {
 	.reset_done = mhi_pci_reset_done,
 };
 
-static int  __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
+static int __mhi_pci_suspend(struct device *dev, bool force)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
@@ -1714,11 +1714,14 @@ static int  __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
 		goto pci_suspend; /* Nothing to do at MHI level */
 
 	/* Transition to M3 state */
-	err = mhi_pm_suspend(mhi_cntrl);
+	err = force ? mhi_pm_suspend_force(mhi_cntrl) : mhi_pm_suspend(mhi_cntrl);
 	if (err) {
 		dev_err(&pdev->dev, "failed to suspend device: %d\n", err);
-		clear_bit(MHI_PCI_DEV_SUSPENDED, &mhi_pdev->status);
-		return -EBUSY;
+		/* For system suspend, sleep anyway and recover on resume */
+		if (!force) {
+			clear_bit(MHI_PCI_DEV_SUSPENDED, &mhi_pdev->status);
+			return -EBUSY;
+		}
 	}
 
 pci_suspend:
@@ -1728,6 +1731,11 @@ static int  __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
 	return 0;
 }
 
+static int __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
+{
+	return __mhi_pci_suspend(dev, false);
+}
+
 static int __maybe_unused mhi_pci_runtime_resume(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -1780,7 +1788,7 @@ static int __maybe_unused mhi_pci_runtime_resume(struct device *dev)
 static int  __maybe_unused mhi_pci_suspend(struct device *dev)
 {
 	pm_runtime_disable(dev);
-	return mhi_pci_runtime_suspend(dev);
+	return __mhi_pci_suspend(dev, true);
 }
 
 static int __maybe_unused mhi_pci_resume(struct device *dev)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API
  2026-12-02  8:43 ` [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API Manivannan Sadhasivam via B4 Relay
@ 2026-12-02 10:15   ` Loic Poulain
  2026-12-02 13:19     ` Manivannan Sadhasivam
  2026-12-02 13:50   ` Loic Poulain
  1 sibling, 1 reply; 7+ messages in thread
From: Loic Poulain @ 2026-12-02 10:15 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: Manivannan Sadhasivam, Jeff Hugo, mhi, linux-arm-msm,
	linux-kernel, Abel Vesa, Len Brown, stable

On Wed, Dec 2, 2026 at 9:44 AM Manivannan Sadhasivam via B4 Relay
<devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org> wrote:
>
> From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
>
> 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@oss.qualcomm.com>
> Cc: stable@vger.kernel.org
> ---
>  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
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend
  2026-12-02  8:43 ` [PATCH 2/2] bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend Manivannan Sadhasivam via B4 Relay
@ 2026-12-02 10:19   ` Loic Poulain
  0 siblings, 0 replies; 7+ messages in thread
From: Loic Poulain @ 2026-12-02 10:19 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: Manivannan Sadhasivam, Jeff Hugo, mhi, linux-arm-msm,
	linux-kernel, Abel Vesa, Len Brown, stable

On Wed, Dec 2, 2026 at 9:44 AM Manivannan Sadhasivam via B4 Relay
<devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org> wrote:
>
> From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
>
> System suspend reuses the runtime suspend callback, so it inherits the
> -EBUSY abort of mhi_pm_suspend() when the device has asserted WAKE or has
> packets pending to be transferred. While aborting works fine for runtime
> suspend, it is a disaster for system suspend, because a single driver
> aborting suspend aborts the entire suspend process. This is what happens on
> Qcom Glymur based laptops and Lenovo Thinkpad T16 laptops, where a failed
> MHI modem suspend aborts the whole system suspend:
>
>   mhi-pci-generic 0006:01:00.0: failed to suspend device: -16
>   mhi-pci-generic 0006:01:00.0: PM: failed to suspend async: error -16
>
> To fix this issue, make use of the new API mhi_pm_suspend_force() during
> system suspend and continue using mhi_pm_suspend() during runtime suspend.
> To achieve this, split the common part of the suspend code into
> __mhi_pci_suspend() helper with the 'force' argument. And set this argument
> to true during system suspend and false during runtime suspend.
>
> If the mhi_pm_suspend_force() API returns an error for any reason, continue
> the system suspend as there is nothing more the driver can do. Later during
> resume, the device will be recovered if needed.
>
> Reported-by: Len Brown <len.brown@intel.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220020
> Reported-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
> Fixes: d3800c1dce24 ("bus: mhi: pci_generic: Add support for runtime PM")
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
> Cc: stable@vger.kernel.org

Reviewed-by: Loic Poulain <loic.poulain@oss.qualcomm.com>

> ---
>  drivers/bus/mhi/host/pci_generic.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/bus/mhi/host/pci_generic.c b/drivers/bus/mhi/host/pci_generic.c
> index b1938c55ffda..9eb7dbb68d2e 100644
> --- a/drivers/bus/mhi/host/pci_generic.c
> +++ b/drivers/bus/mhi/host/pci_generic.c
> @@ -1694,7 +1694,7 @@ static const struct pci_error_handlers mhi_pci_err_handler = {
>         .reset_done = mhi_pci_reset_done,
>  };
>
> -static int  __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
> +static int __mhi_pci_suspend(struct device *dev, bool force)
>  {
>         struct pci_dev *pdev = to_pci_dev(dev);
>         struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
> @@ -1714,11 +1714,14 @@ static int  __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
>                 goto pci_suspend; /* Nothing to do at MHI level */
>
>         /* Transition to M3 state */
> -       err = mhi_pm_suspend(mhi_cntrl);
> +       err = force ? mhi_pm_suspend_force(mhi_cntrl) : mhi_pm_suspend(mhi_cntrl);
>         if (err) {
>                 dev_err(&pdev->dev, "failed to suspend device: %d\n", err);
> -               clear_bit(MHI_PCI_DEV_SUSPENDED, &mhi_pdev->status);
> -               return -EBUSY;
> +               /* For system suspend, sleep anyway and recover on resume */
> +               if (!force) {
> +                       clear_bit(MHI_PCI_DEV_SUSPENDED, &mhi_pdev->status);
> +                       return -EBUSY;
> +               }
>         }
>
>  pci_suspend:
> @@ -1728,6 +1731,11 @@ static int  __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
>         return 0;
>  }
>
> +static int __maybe_unused mhi_pci_runtime_suspend(struct device *dev)
> +{
> +       return __mhi_pci_suspend(dev, false);
> +}
> +
>  static int __maybe_unused mhi_pci_runtime_resume(struct device *dev)
>  {
>         struct pci_dev *pdev = to_pci_dev(dev);
> @@ -1780,7 +1788,7 @@ static int __maybe_unused mhi_pci_runtime_resume(struct device *dev)
>  static int  __maybe_unused mhi_pci_suspend(struct device *dev)
>  {
>         pm_runtime_disable(dev);
> -       return mhi_pci_runtime_suspend(dev);
> +       return __mhi_pci_suspend(dev, true);
>  }
>
>  static int __maybe_unused mhi_pci_resume(struct device *dev)
>
> --
> 2.43.0
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API
  2026-12-02 10:15   ` Loic Poulain
@ 2026-12-02 13:19     ` Manivannan Sadhasivam
  0 siblings, 0 replies; 7+ messages in thread
From: Manivannan Sadhasivam @ 2026-12-02 13:19 UTC (permalink / raw)
  To: Loic Poulain
  Cc: manivannan.sadhasivam, Manivannan Sadhasivam, Jeff Hugo, mhi,
	linux-arm-msm, linux-kernel, Abel Vesa, Len Brown, stable

On 2026-12-02 11:15 +0100, Loic Poulain wrote:
> On Wed, Dec 2, 2026 at 9:44 AM Manivannan Sadhasivam via B4 Relay
> <devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org> wrote:
> >
> > From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
> >
> > 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.
> 

My wording was slightly off in the above paragraph. I wrote it in such a way to
sound like the API deals with device's wakeup capability, but it is just the
wakeup count of the device enforced by the MHI host.

To your question, we should not see any driver holding dev_wake during system
suspend as all of them just do mhi_device_get_sync() to access the device and
make sure it stays in M0 and call mhi_device_put() to allow it to enter M3.
But userspace can hold the device_wake through debugfs. So if device_wake is set
during system suspend, most likely it would come from userspace vote and the MHI
stack can do nothing about it, other than forcing system suspend.

- Mani



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API
  2026-12-02  8:43 ` [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API Manivannan Sadhasivam via B4 Relay
  2026-12-02 10:15   ` Loic Poulain
@ 2026-12-02 13:50   ` Loic Poulain
  1 sibling, 0 replies; 7+ messages in thread
From: Loic Poulain @ 2026-12-02 13:50 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: Manivannan Sadhasivam, Jeff Hugo, mhi, linux-arm-msm,
	linux-kernel, Abel Vesa, Len Brown, stable

On Wed, Dec 2, 2026 at 9:44 AM Manivannan Sadhasivam via B4 Relay
<devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org> wrote:
>
> From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
>
> 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.
>
> 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@oss.qualcomm.com>
> Cc: stable@vger.kernel.org

Reviewed-by: Loic Poulain <loic.poulain@oss.qualcomm.com>

> ---
>  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;
> +               }
> +       } 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
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-02 13:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  8:43 [PATCH 0/2] bus: mhi: host: Do not abort system suspend when the MHI device is busy Manivannan Sadhasivam via B4 Relay
2026-12-02  8:43 ` [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API Manivannan Sadhasivam via B4 Relay
2026-12-02 10:15   ` Loic Poulain
2026-12-02 13:19     ` Manivannan Sadhasivam
2026-12-02 13:50   ` Loic Poulain
2026-12-02  8:43 ` [PATCH 2/2] bus: mhi: host: pci_generic: Use mhi_pm_suspend_force() for system suspend Manivannan Sadhasivam via B4 Relay
2026-12-02 10:19   ` Loic Poulain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®