mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manivannan Sadhasivam via B4 Relay <devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org>
To: Manivannan Sadhasivam <mani@kernel.org>,
	 Jeff Hugo <jeff.hugo@oss.qualcomm.com>,
	 Loic Poulain <loic.poulain@oss.qualcomm.com>
Cc: mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	Abel Vesa <abel.vesa@oss.qualcomm.com>,
	 Len Brown <len.brown@intel.com>,
	 Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
	 stable@vger.kernel.org
Subject: [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API
Date: Wed, 02 Dec 2026 09:43:56 +0100	[thread overview]
Message-ID: <20261202-mhi-suspend-fix-v1-1-451bdce5733c@oss.qualcomm.com> (raw)
In-Reply-To: <20261202-mhi-suspend-fix-v1-0-451bdce5733c@oss.qualcomm.com>

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



  reply	other threads:[~2026-12-02  8:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-02 10:15   ` [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202-mhi-suspend-fix-v1-1-451bdce5733c@oss.qualcomm.com \
    --to=devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org \
    --cc=abel.vesa@oss.qualcomm.com \
    --cc=jeff.hugo@oss.qualcomm.com \
    --cc=len.brown@intel.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=mani@kernel.org \
    --cc=manivannan.sadhasivam@oss.qualcomm.com \
    --cc=mhi@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®