diff --git a/drivers/bus/mhi/core/mhi_pm.c b/drivers/bus/mhi/core/mhi_pm.c index 74548ba2716d..2a58c5fe9ef8 100644 --- a/drivers/bus/mhi/core/mhi_pm.c +++ b/drivers/bus/mhi/core/mhi_pm.c @@ -1648,7 +1648,8 @@ int mhi_device_get_sync(struct mhi_device *mhi_dev, int vote) } EXPORT_SYMBOL(mhi_device_get_sync); -int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, int timeout_us) +int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, int timeout_us, + bool in_panic) { struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl; @@ -1674,11 +1675,20 @@ int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, int timeout_us) return 0; } - while (mhi_cntrl->pm_state != MHI_PM_M0 && - !MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state) && - timeout_us > 0) { - udelay(MHI_FORCE_WAKE_DELAY_US); - timeout_us -= MHI_FORCE_WAKE_DELAY_US; + if (in_panic) { + while (mhi_get_mhi_state(mhi_cntrl) != MHI_STATE_M0 && + !MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state) && + timeout_us > 0) { + udelay(MHI_FORCE_WAKE_DELAY_US); + timeout_us -= MHI_FORCE_WAKE_DELAY_US; + } + } else { + while (mhi_cntrl->pm_state != MHI_PM_M0 && + !MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state) && + timeout_us > 0) { + udelay(MHI_FORCE_WAKE_DELAY_US); + timeout_us -= MHI_FORCE_WAKE_DELAY_US; + } } if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state) || timeout_us <= 0) { diff --git a/drivers/net/wireless/cnss2/pci.c b/drivers/net/wireless/cnss2/pci.c index 2b4afe9cd476..5a649e349f09 100644 --- a/drivers/net/wireless/cnss2/pci.c +++ b/drivers/net/wireless/cnss2/pci.c @@ -3041,7 +3041,7 @@ int cnss_pci_force_wake_request_sync(struct device *dev, int timeout_us) if (test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state)) return -EAGAIN; - return mhi_device_get_sync_atomic(mhi_ctrl->mhi_dev, timeout_us); + return mhi_device_get_sync_atomic(mhi_ctrl->mhi_dev, timeout_us, false); } EXPORT_SYMBOL(cnss_pci_force_wake_request_sync); diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 072e9bee5cc8..142af16fa590 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -617,6 +617,7 @@ int mhi_device_get_sync(struct mhi_device *mhi_dev, int vote); * mhi_device_get_sync_atomic - Asserts device_wait and moves device to M0 * @mhi_dev: Device associated with the channels * @timeout_us: timeout, in micro-seconds + * @in_panic: If requested while kernel is in panic state and no ISRs expected * * The device_wake is asserted to keep device in M0 or bring it to M0. * If device is not in M0 state, then this function will wait for device to @@ -628,6 +629,8 @@ int mhi_device_get_sync(struct mhi_device *mhi_dev, int vote); * Clients can ignore that transition after this function returns as the device * is expected to immediately move from M2 to M0 as wake is asserted and * wouldn't enter low power state. + * If in_panic boolean is set, no ISRs are expected, hence this API will have to + * resort to reading the MHI status register and poll on M0 state change. * * Returns: * 0 if operation was successful (however, M0 -> M2 -> M0 is possible later) as @@ -635,7 +638,9 @@ int mhi_device_get_sync(struct mhi_device *mhi_dev, int vote); * -ETIMEDOUT is device faled to move to M0 before @timeout_us elapsed * -EIO if the MHI state is one of the ERROR states. */ -int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, int timeout_us); +int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, + int timeout_us, + bool in_panic); /** * mhi_device_put - re-enable low power modes