From b4ff9ea317c7951ac9f9b1488c8e6ad28e9948f8 Mon Sep 17 00:00:00 2001 From: Yeshwanth Sriram Guntuka Date: Wed, 3 Aug 2022 14:52:27 +0530 Subject: [PATCH] qcacmn: Add functionality for rtpm prevent suspend sync Add provision to call sync prevent suspend which will wait for system to resume and increment usage_count before returning. Change-Id: I855e3fc2660dc7f3f78bb70f8eef6228cbef96d3 CRs-Fixed: 3253335 --- hif/inc/hif.h | 15 +++++++++ hif/src/hif_runtime_pm.c | 67 +++++++++++++++++++++++++++++++++++++++- qdf/inc/qdf_lock.h | 19 +++++++++++- qdf/linux/src/qdf_lock.c | 7 +++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/hif/inc/hif.h b/hif/inc/hif.h index b88677ae53..dfca7f0986 100644 --- a/hif/inc/hif.h +++ b/hif/inc/hif.h @@ -1323,6 +1323,17 @@ QDF_STATUS hif_rtpm_put(uint8_t type, uint32_t id); */ int hif_pm_runtime_prevent_suspend(struct hif_pm_runtime_lock *data); +/** + * hif_pm_runtime_prevent_suspend_sync() - Synchronized prevent Runtime suspend + * @data: runtime PM lock + * + * This function will prevent runtime suspend, by incrementing + * device's usage count. + * + * Return: status + */ +int hif_pm_runtime_prevent_suspend_sync(struct hif_pm_runtime_lock *data); + /** * hif_pm_runtime_allow_suspend() - Allow Runtime suspend * @data: runtime PM lock @@ -1538,6 +1549,10 @@ static inline int hif_pm_runtime_prevent_suspend(struct hif_pm_runtime_lock *data) { return 0; } +static inline +int hif_pm_runtime_prevent_suspend_sync(struct hif_pm_runtime_lock *data) +{ return 0; } + static inline QDF_STATUS hif_rtpm_sync_resume(void) { return QDF_STATUS_SUCCESS; } diff --git a/hif/src/hif_runtime_pm.c b/hif/src/hif_runtime_pm.c index 6a4dee096a..d633187c1e 100644 --- a/hif/src/hif_runtime_pm.c +++ b/hif/src/hif_runtime_pm.c @@ -760,9 +760,74 @@ int hif_pm_runtime_prevent_suspend(struct hif_pm_runtime_lock *lock) return 0; } +/** + * __hif_pm_runtime_prevent_suspend_sync() - synchronized prevent runtime + * suspend for a protocol reason + * @lock: runtime_pm lock being acquired + * + * Return: 0 if successful. + */ +static +int __hif_pm_runtime_prevent_suspend_sync(struct hif_pm_runtime_lock *lock) +{ + int ret = 0; + + if (lock->active) + return 0; + + ret = __hif_rtpm_get_sync(gp_hif_rtpm_ctx->dev); + + /** + * The ret can be -EINPROGRESS, if Runtime status is RPM_RESUMING or + * RPM_SUSPENDING. Any other negative value is an error. + * We shouldn't do runtime_put here as in later point allow + * suspend gets called with the context and there the usage count + * is decremented, so suspend will be prevented. + */ + if (ret < 0 && ret != -EINPROGRESS) { + gp_hif_rtpm_ctx->stats.runtime_get_err++; + hif_err("pm_state: %d ret: %d", + qdf_atomic_read(&gp_hif_rtpm_ctx->pm_state), + ret); + } + + qdf_spin_lock_bh(&gp_hif_rtpm_ctx->prevent_list_lock); + list_add_tail(&lock->list, &gp_hif_rtpm_ctx->prevent_list); + lock->active = true; + gp_hif_rtpm_ctx->prevent_cnt++; + gp_hif_rtpm_ctx->stats.prevent_suspend++; + qdf_spin_unlock_bh(&gp_hif_rtpm_ctx->prevent_list_lock); + + return ret; +} + +int hif_pm_runtime_prevent_suspend_sync(struct hif_pm_runtime_lock *lock) +{ + if (!hif_rtpm_enabled()) + return 0; + + if (!lock) + return -EINVAL; + + if (in_irq()) + WARN_ON(1); + + __hif_pm_runtime_prevent_suspend_sync(lock); + + if (qdf_atomic_read(&gp_hif_rtpm_ctx->pm_state) >= + HIF_RTPM_STATE_SUSPENDING) + hif_info_high("request RTPM resume by %s", + lock->name); + + return 0; +} + int hif_pm_runtime_allow_suspend(struct hif_pm_runtime_lock *lock) { - if (!hif_rtpm_enabled() || !lock) + if (!hif_rtpm_enabled()) + return 0; + + if (!lock) return -EINVAL; if (in_irq()) diff --git a/qdf/inc/qdf_lock.h b/qdf/inc/qdf_lock.h index 3a1d455e5b..b58b17b68c 100644 --- a/qdf/inc/qdf_lock.h +++ b/qdf/inc/qdf_lock.h @@ -684,7 +684,7 @@ QDF_STATUS qdf_rtpm_get(uint8_t type, uint32_t id); QDF_STATUS qdf_rtpm_put(uint8_t type, uint32_t id); /** - * qdf_runtime_pm_allow_suspend() - Prevent Runtime suspend + * qdf_runtime_pm_prevent_suspend() - Prevent Runtime suspend * @data: runtime PM lock * * This function will prevent runtime suspend, by incrementing @@ -694,6 +694,17 @@ QDF_STATUS qdf_rtpm_put(uint8_t type, uint32_t id); */ QDF_STATUS qdf_runtime_pm_prevent_suspend(qdf_runtime_lock_t *lock); +/** + * qdf_runtime_pm_prevent_suspend_sync() - Synchronized Prevent Runtime suspend + * @data: runtime PM lock + * + * This function will prevent runtime suspend, by incrementing + * device's usage count and waits till system is in resumed state. + * + * Return: status + */ +QDF_STATUS qdf_runtime_pm_prevent_suspend_sync(qdf_runtime_lock_t *lock); + /** * qdf_runtime_pm_allow_suspend() - Allow Runtime suspend * @data: runtime PM lock @@ -756,6 +767,12 @@ QDF_STATUS qdf_runtime_pm_prevent_suspend(qdf_runtime_lock_t *lock) return QDF_STATUS_SUCCESS; } +static inline +QDF_STATUS qdf_runtime_pm_prevent_suspend_sync(qdf_runtime_lock_t *lock) +{ + return QDF_STATUS_SUCCESS; +} + static inline QDF_STATUS qdf_runtime_pm_allow_suspend(qdf_runtime_lock_t *lock) { diff --git a/qdf/linux/src/qdf_lock.c b/qdf/linux/src/qdf_lock.c index 4d98d93f2e..f8f2145dde 100644 --- a/qdf/linux/src/qdf_lock.c +++ b/qdf/linux/src/qdf_lock.c @@ -572,6 +572,13 @@ QDF_STATUS qdf_runtime_pm_prevent_suspend(qdf_runtime_lock_t *lock) qdf_export_symbol(qdf_runtime_pm_prevent_suspend); +QDF_STATUS qdf_runtime_pm_prevent_suspend_sync(qdf_runtime_lock_t *lock) +{ + return hif_pm_runtime_prevent_suspend_sync(lock->lock); +} + +qdf_export_symbol(qdf_runtime_pm_prevent_suspend_sync); + QDF_STATUS qdf_runtime_pm_allow_suspend(qdf_runtime_lock_t *lock) { return hif_pm_runtime_allow_suspend(lock->lock);