Skip to contentSkip to conversation

bus: mhi: core: Fix power down latency

PATCH Applied Loic Poulain 4 participants 6 messages May 3, 2021 – May 21, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bus: mhi: core: Fix power down latency

On graceful power-down/disable transition, when an MHI reset is performed, the MHI device loses its context, including interrupt configuration. However, the current implementation is waiting for event(irq) driven state change to confirm reset has been completed, which never happens, and causes reset timeout, leading to unexpected high latency of the mhi_power_down procedure (up to 45 seconds).

Fix that by moving to the recently introduced poll_reg_field method, waiting for the reset bit to be cleared, in the same way as the power_on procedure.

Fixes a6e2e3522f29 ("bus: mhi: core: Add support for PM state transitions")
---
 drivers/bus/mhi/core/pm.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/bus/mhi/core/pm.c +5 -13
index e2e59a3..704a5e2 100644
@@ -465,23 +465,15 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl)
 
 	/* Trigger MHI RESET so that the device will not access host memory */
 	if (!MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state)) {
-		u32 in_reset = -1;
-		unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms);
-
 		dev_dbg(dev, "Triggering MHI Reset in device\n");
 		mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
 
 		/* Wait for the reset bit to be cleared by the device */
-		ret = wait_event_timeout(mhi_cntrl->state_event,
-					 mhi_read_reg_field(mhi_cntrl,
-							    mhi_cntrl->regs,
-							    MHICTRL,
-							    MHICTRL_RESET_MASK,
-							    MHICTRL_RESET_SHIFT,
-							    &in_reset) ||
-					!in_reset, timeout);
-		if (!ret || in_reset)
-			dev_err(dev, "Device failed to exit MHI Reset state\n");
+		ret = mhi_poll_reg_field(mhi_cntrl, mhi_cntrl->regs, MHICTRL,
+				 MHICTRL_RESET_MASK, MHICTRL_RESET_SHIFT, 0,
+				 25000);
+		if (ret)
+			dev_err(dev, "Device failed to clear MHI Reset\n");
 
 		/*
 		 * Device will clear BHI_INTVEC as a part of RESET processing,
Signature · 1 line
2.7.4
#1 lore raw

Hi Manivannan and Hemant,

Quoted 8 lines · Loic Poulain

On graceful power-down/disable transition, when an MHI reset is performed, the MHI device loses its context, including interrupt configuration. However, the current implementation is waiting for event(irq) driven state change to confirm reset has been completed, which never happens, and causes reset timeout, leading to unexpected high latency of the mhi_power_down procedure (up to 45 seconds).

Quoted 6 lines

Fix that by moving to the recently introduced poll_reg_field method, waiting for the reset bit to be cleared, in the same way as the power_on procedure.

Fixes a6e2e3522f29 ("bus: mhi: core: Add support for PM state transitions")

Should be considered for 5.13-rc* since it's a fix.

Regards,
Loic

Quoted 40 lines
---
 drivers/bus/mhi/core/pm.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/bus/mhi/core/pm.c +5 -14
index e2e59a3..704a5e2 100644
@@ -465,23 +465,15 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl)
 
        /* Trigger MHI RESET so that the device will not access host memory */
        if (!MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state)) {
-               u32 in_reset = -1;
-               unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms);
-
                dev_dbg(dev, "Triggering MHI Reset in device\n");
                mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
 
                /* Wait for the reset bit to be cleared by the device */
-               ret = wait_event_timeout(mhi_cntrl->state_event,
-                                        mhi_read_reg_field(mhi_cntrl,
-                                                           mhi_cntrl->regs,
-                                                           MHICTRL,
-                                                           MHICTRL_RESET_MASK,
-                                                           MHICTRL_RESET_SHIFT,
-                                                           &in_reset) ||
-                                       !in_reset, timeout);
-               if (!ret || in_reset)
-                       dev_err(dev, "Device failed to exit MHI Reset state\n");
+               ret = mhi_poll_reg_field(mhi_cntrl, mhi_cntrl->regs, MHICTRL,
+                                MHICTRL_RESET_MASK, MHICTRL_RESET_SHIFT, 0,
+                                25000);
+               if (ret)
+                       dev_err(dev, "Device failed to clear MHI Reset\n");
 
                /*
                 * Device will clear BHI_INTVEC as a part of RESET processing,
--

2.7.4

Reviewed-by on v2 1/1
#2 lore raw
In reply to Loic Poulain
Quoted 7 lines · Loic Poulain

On graceful power-down/disable transition, when an MHI reset is performed, the MHI device loses its context, including interrupt configuration. However, the current implementation is waiting for event(irq) driven state change to confirm reset has been completed, which never happens, and causes reset timeout, leading to unexpected high latency of the mhi_power_down procedure (up to 45 seconds).

Quoted 7 lines

Fix that by moving to the recently introduced poll_reg_field method, waiting for the reset bit to be cleared, in the same way as the power_on procedure.

Fixes a6e2e3522f29 ("bus: mhi: core: Add support for PM state transitions")

---

Quoted 36 lines
 drivers/bus/mhi/core/pm.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/bus/mhi/core/pm.c +5 -13
index e2e59a3..704a5e2 100644
@@ -465,23 +465,15 @@ static void mhi_pm_disable_transition(struct
 mhi_controller *mhi_cntrl)
 
 	/* Trigger MHI RESET so that the device will not access host memory 
 */
 	if (!MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state)) {
-		u32 in_reset = -1;
-		unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms);
-
 		dev_dbg(dev, "Triggering MHI Reset in device\n");
 		mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
 
 		/* Wait for the reset bit to be cleared by the device */
-		ret = wait_event_timeout(mhi_cntrl->state_event,
-					 mhi_read_reg_field(mhi_cntrl,
-							    mhi_cntrl->regs,
-							    MHICTRL,
-							    MHICTRL_RESET_MASK,
-							    MHICTRL_RESET_SHIFT,
-							    &in_reset) ||
-					!in_reset, timeout);
-		if (!ret || in_reset)
-			dev_err(dev, "Device failed to exit MHI Reset state\n");
+		ret = mhi_poll_reg_field(mhi_cntrl, mhi_cntrl->regs, MHICTRL,
+				 MHICTRL_RESET_MASK, MHICTRL_RESET_SHIFT, 0,
+				 25000);
+		if (ret)
+			dev_err(dev, "Device failed to clear MHI Reset\n");
 

drivers/bus/mhi/core/pm.c static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl) · line 479

Quoted 2 lines
drivers/bus/mhi/core/pm.c +0 -0
 		/*
 		 * Device will clear BHI_INTVEC as a part of RESET processing,

Thanks,
Bhaumik
---
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

Reviewed-by on v2 1/1
#3 lore raw
In reply to Loic Poulain
Quoted 7 lines · Loic Poulain

On graceful power-down/disable transition, when an MHI reset is performed, the MHI device loses its context, including interrupt configuration. However, the current implementation is waiting for event(irq) driven state change to confirm reset has been completed, which never happens, and causes reset timeout, leading to unexpected high latency of the mhi_power_down procedure (up to 45 seconds).

Quoted 6 lines

Fix that by moving to the recently introduced poll_reg_field method, waiting for the reset bit to be cleared, in the same way as the power_on procedure.

Fixes a6e2e3522f29 ("bus: mhi: core: Add support for PM state transitions")
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer Reviewed-by on v2 1/1
#4 lore raw
In reply to Loic Poulain
Quoted 7 lines · Loic Poulain

On graceful power-down/disable transition, when an MHI reset is performed, the MHI device loses its context, including interrupt configuration. However, the current implementation is waiting for event(irq) driven state change to confirm reset has been completed, which never happens, and causes reset timeout, leading to unexpected high latency of the mhi_power_down procedure (up to 45 seconds).

Quoted 6 lines

Fix that by moving to the recently introduced poll_reg_field method, waiting for the reset bit to be cleared, in the same way as the power_on procedure.

Fixes a6e2e3522f29 ("bus: mhi: core: Add support for PM state transitions")

Thanks,
Mani

Quoted 40 lines
---
 drivers/bus/mhi/core/pm.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/bus/mhi/core/pm.c +5 -13
index e2e59a3..704a5e2 100644
@@ -465,23 +465,15 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl)
 
 	/* Trigger MHI RESET so that the device will not access host memory */
 	if (!MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state)) {
-		u32 in_reset = -1;
-		unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms);
-
 		dev_dbg(dev, "Triggering MHI Reset in device\n");
 		mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
 
 		/* Wait for the reset bit to be cleared by the device */
-		ret = wait_event_timeout(mhi_cntrl->state_event,
-					 mhi_read_reg_field(mhi_cntrl,
-							    mhi_cntrl->regs,
-							    MHICTRL,
-							    MHICTRL_RESET_MASK,
-							    MHICTRL_RESET_SHIFT,
-							    &in_reset) ||
-					!in_reset, timeout);
-		if (!ret || in_reset)
-			dev_err(dev, "Device failed to exit MHI Reset state\n");
+		ret = mhi_poll_reg_field(mhi_cntrl, mhi_cntrl->regs, MHICTRL,
+				 MHICTRL_RESET_MASK, MHICTRL_RESET_SHIFT, 0,
+				 25000);
+		if (ret)
+			dev_err(dev, "Device failed to clear MHI Reset\n");
 
 		/*
 		 * Device will clear BHI_INTVEC as a part of RESET processing,
Signature · 1 line
2.7.4
maintainer Applied
#5 lore raw
In reply to Loic Poulain
Quoted 7 lines · Loic Poulain

On graceful power-down/disable transition, when an MHI reset is performed, the MHI device loses its context, including interrupt configuration. However, the current implementation is waiting for event(irq) driven state change to confirm reset has been completed, which never happens, and causes reset timeout, leading to unexpected high latency of the mhi_power_down procedure (up to 45 seconds).

Quoted 6 lines

Fix that by moving to the recently introduced poll_reg_field method, waiting for the reset bit to be cleared, in the same way as the power_on procedure.

Fixes a6e2e3522f29 ("bus: mhi: core: Add support for PM state transitions")

Applied to mhi-fixes!

Thanks,
Mani

Quoted 40 lines
---
 drivers/bus/mhi/core/pm.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/bus/mhi/core/pm.c +5 -13
index e2e59a3..704a5e2 100644
@@ -465,23 +465,15 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl)
 
 	/* Trigger MHI RESET so that the device will not access host memory */
 	if (!MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state)) {
-		u32 in_reset = -1;
-		unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms);
-
 		dev_dbg(dev, "Triggering MHI Reset in device\n");
 		mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
 
 		/* Wait for the reset bit to be cleared by the device */
-		ret = wait_event_timeout(mhi_cntrl->state_event,
-					 mhi_read_reg_field(mhi_cntrl,
-							    mhi_cntrl->regs,
-							    MHICTRL,
-							    MHICTRL_RESET_MASK,
-							    MHICTRL_RESET_SHIFT,
-							    &in_reset) ||
-					!in_reset, timeout);
-		if (!ret || in_reset)
-			dev_err(dev, "Device failed to exit MHI Reset state\n");
+		ret = mhi_poll_reg_field(mhi_cntrl, mhi_cntrl->regs, MHICTRL,
+				 MHICTRL_RESET_MASK, MHICTRL_RESET_SHIFT, 0,
+				 25000);
+		if (ret)
+			dev_err(dev, "Device failed to clear MHI Reset\n");
 
 		/*
 		 * Device will clear BHI_INTVEC as a part of RESET processing,
Signature · 1 line
2.7.4