From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796201056; b=n/1Df8Vbsrm1rp/+saawy+cMvIZG9U1tR9KNkvuSWJwYmSo7BKlObav29hy6jVDQEkNc bYo5HJoKVR4grGrUqmSXJ9vNFUK6XPDIKsbeKERrzbu8eikooRC3vcJ8T1XjMkDPYecMP 8hK25T4tK00fQYbHO8FsYtRO1B/OgnQHqW9XtSJxfIO7NpPQeJyiMjXRl6uDIcSxfqidU l+CTsDqWpTiDi/UB1hepyFomlQQyDWdzvAosjT2RsonNDfPhABG+omAf3dRFlyrwgYoo6 eYOWD4JXrgnqL4cQDdKgJIBoHTzqYPRhgPCfjwPKIZ3zqMd4M8r8oQ/l3CPoWXsRarA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796201056; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=fxI2OOUTJNQ6fcjoN1xF7Mh9H0L8+BaoGy0Gj66kb+Q=; b=ShEA08bzjfOwCIEsAOXEvLyQCsrMcX/1kYCXK/1hXamY+pH/Hug+q49A2uXBat0jg8se +pnzyY5hY9cohbQxuV9IGJgqZTzChwDOJTrDthRlJziE8zfr8QU/ArkY2TjlQGcdnhXFN cXEtrRd+c6FNezhndZnX2Y/pcqAdOPozgfeDhNalGfauNbXrj4KDmjfhdr2vbt8x9qEHd Klk2/kO/7ho1zhKMeUeSjVwS9stA/xvV7jjuVm83KitZmej5YRK31jeoxfZvfsZfmLp0H zZwEaa5vUuBoh81jddC7IyzQd0K8NjrJRVB10kAwvM2WYm+94AaAyOeq/mFBw/zi3SA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SkwS9vI0; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C274606A683; Wed, 2 Dec 2026 08:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SkwS9vI0 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796201055; b=GrJA2lvjoB/B2Wlx793gpYhlq697B4e9+Mmc6995NIyRHty+SQAmnk2qCHY2nY2ApfrV akFd36X5dvZRo9KIWT8r8BPll0IYLsEM0o6lsQt4jUfxWJRQmF7dsgG5yCuQRw++p7JcC NEBsrHEk8sNTmgVqOiJcM9wKrigJab6q9+k5SHvUkM39dM9pJViX6Hf86t2iakp8urGGY 7uvLikxPEbsGLhYVPbszKftHgDa4YGrVDGzx4HiaRGi7X1xitqCewJNLjqX+70/zJzVJa V0TBUnpWiRi+q/QUH0bbgcQoDWMCB/K6dDCb5x0HrP2/udFRzHXvhJvq1ldqG0N36Xg== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796201055; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=fxI2OOUTJNQ6fcjoN1xF7Mh9H0L8+BaoGy0Gj66kb+Q=; b=oQlqacMiBceMgivyWGiPdzJGUE6xSSMrSCKDnFtM8SYD5CZE4IzXVpl2WWrZPTVya1Vk XHNuqvTXfygx68Bf3c5ZZFwzW2+25YxllQH6LQU/3/rVHY4plSJqlL8kej+WpX+J2nLb6 y8MdcSDciHhnsjC/PmaLCUcxjFmMPARMfFrePLMLjr3fM4evYWmSfWZpopFAAtHSsZpoZ JJSQUL82xZ87+/ilxdl5Ay5b4EBk/I7ar3zRncQF4MgdJWSYp4zBpHJ/JmoL506gY5rDz My3V5yMA/dA90881uy+OwSKhx2DWvStMIJfYJA/Bzpc9VMm5zOjYKQmfvoUkwyaz+4g== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id A94E41F00893; Wed, 2 Dec 2026 08:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796201055; bh=fxI2OOUTJNQ6fcjoN1xF7Mh9H0L8+BaoGy0Gj66kb+Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=SkwS9vI0foypWIuMldx2BCmTW3rDLdPjvKHEr6MThQqvsL09N/G0/KZGyFL5VLa75 kYBjWePSxOVTaWSiuy0naSRFve1KceAY/3bBy8knD/BwRPt7B2KQx3piMcHabfXyx4 aw1Vt9na7oWYdb+UZvr3zEMUPrpdQ8EsxntKmkPDECGTuH9Epg85kAIsSqP3/fwRW6 q9GpZLz//QGITQmM16MaMXeRCm4t8HQg/1UpIYWupgYMhhq8C4MPXjON6CSeeCeGON 2XO2LZjfbJEyldXgtfDA4PWzP1d55kP+WOdeIDm4nt9BAnHjNP+aEebLC/4rJ7PQ0t qfsCGfT/x8NtQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 31FBC4F319; Wed, 2 Dec 2026 08:44:04 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Wed, 02 Dec 2026 09:43:56 +0100 Subject: [PATCH 1/2] bus: mhi: host: Add mhi_pm_suspend_force() API X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261202-mhi-suspend-fix-v1-1-451bdce5733c@oss.qualcomm.com> References: <20261202-mhi-suspend-fix-v1-0-451bdce5733c@oss.qualcomm.com> In-Reply-To: <20261202-mhi-suspend-fix-v1-0-451bdce5733c@oss.qualcomm.com> To: Manivannan Sadhasivam , Jeff Hugo , Loic Poulain Cc: mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Vesa , Len Brown , Manivannan Sadhasivam , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5294; i=manivannan.sadhasivam@oss.qualcomm.com; h=from:subject:message-id; bh=/0Ru0EYeY1o1/Vp6UVuN6dYK4IUrJZP3b2z6oWC+tLM=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBrD9pSPe0GDfu4ZuoxDeZMqF9fsZRVV1jekWIOb TD+6CdE5OCJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCaw/aUgAKCRBVnxHm/pHO 9TfTCACenmJ4KxnyfRdlTJu1zv2IJnEJ/n1nWp2JusyGQMe6kicnlmjr8d/cwry112m5ZMzrf6A x1HqvnTXBts5EqqsScE1iVRYVgxZQ7937tGnVFjnP1IhMU3J3yPlvedeq6THdEP+eFn80pWi+0x 7LhJpKuaQrm+N1e1+ldTw1pnHb/Z0OhWRSagyFsiE8ZpR2mIX6zI0NO745DvBOCmdhFS53AlO35 fWoKh+S+Q8kq9fK39UbDNoizPXxyPq6RO0wQLOYQbK+Ka58CfUMjCm5ySCoQiBRmG0rEXiLVu2Z 8bcrEH3hfHjUCWGjIYBgAcsqPVClYb/dmiPGhj6l8ETA3yrT X-Developer-Key: i=manivannan.sadhasivam@oss.qualcomm.com; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@oss.qualcomm.com/default with auth_id=461 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@oss.qualcomm.com Content-Transfer-Encoding: 7bit From: Manivannan Sadhasivam 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 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 #include #include +#include #include #include #include @@ -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