From 29c57b487aad93cee82b17a71d1511708262526d Mon Sep 17 00:00:00 2001 From: Nitesh Gupta Date: Fri, 26 Mar 2021 11:58:15 +0530 Subject: [PATCH] msm: mhi_dev: Poll for ipa_dma_disable during MHI suspend Poll for ipa_dma_disable prior to entering mhi suspend, until it returns success. this is to prevent IPA disable failure in case on pending transfers. Change-Id: I38143284447b86ce34c47e100e6fe0c23cf28f0b Signed-off-by: Subramanian Ananthanarayanan Signed-off-by: Nitesh Gupta Signed-off-by: Gauri Joshi --- drivers/platform/msm/mhi_dev/mhi_sm.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/platform/msm/mhi_dev/mhi_sm.c b/drivers/platform/msm/mhi_dev/mhi_sm.c index 7e3be7654729..655764d8664d 100644 --- a/drivers/platform/msm/mhi_dev/mhi_sm.c +++ b/drivers/platform/msm/mhi_dev/mhi_sm.c @@ -22,7 +22,10 @@ #define MHI_SM_FUNC_ENTRY() MHI_SM_DBG("ENTRY\n") #define MHI_SM_FUNC_EXIT() MHI_SM_DBG("EXIT\n") -#define PCIE_EP_TIMER_US 500000000 +#define PCIE_EP_TIMER_US 500000000 +#define MHI_IPA_DISABLE_DELAY_MS 10 +#define MHI_IPA_DISABLE_COUNTER 20 + static inline const char *mhi_sm_dev_event_str(enum mhi_dev_event state) { @@ -591,7 +594,7 @@ static int mhi_sm_prepare_suspend(enum mhi_dev_state new_state) { enum mhi_dev_state old_state; struct ep_pcie_inactivity inact_param; - int res = 0, rc; + int res = 0, rc, wait_timeout = 0; MHI_SM_DBG("Switching event:%d\n", new_state); @@ -668,11 +671,24 @@ static int mhi_sm_prepare_suspend(enum mhi_dev_state new_state) (new_state == MHI_DEV_M3_STATE))) { if (mhi_sm_ctx->mhi_dev->use_ipa) { MHI_SM_DBG("Disable IPA with ipa_dma_disable()\n"); - res = ipa_dma_disable(); - if (res) { - MHI_SM_ERR("IPA disable failed\n"); + while (wait_timeout < MHI_IPA_DISABLE_COUNTER) { + /* wait for the disable to finish */ + res = ipa_dma_disable(); + if (!res) + break; + MHI_SM_ERR + ("IPA disable fail cnt:%d\n", + wait_timeout); + msleep(MHI_IPA_DISABLE_DELAY_MS); + wait_timeout++; + } + + if (wait_timeout >= MHI_IPA_DISABLE_COUNTER) { + MHI_SM_ERR + ("Fail to disable IPA for M3\n"); goto exit; } + MHI_SM_ERR("IPA DMA successfully disabled\n"); } }