Browse Source

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
Yeshwanth Sriram Guntuka 2 years ago
parent
commit
b4ff9ea317
4 changed files with 106 additions and 2 deletions
  1. 15 0
      hif/inc/hif.h
  2. 66 1
      hif/src/hif_runtime_pm.c
  3. 18 1
      qdf/inc/qdf_lock.h
  4. 7 0
      qdf/linux/src/qdf_lock.c

+ 15 - 0
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; }

+ 66 - 1
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())

+ 18 - 1
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)
 {

+ 7 - 0
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);