qcacld-3.0: Log runtime suspend resume occurances

Keep track of how many times supesend resume succeeds and fails
also mark last busy on a failed runtime suspend or a successful
runtime resume.

Change-Id: I04df805429e3a9ce91bc3d7f27bfd598396257c9
CRs-Fixed: 935300
diff --git a/core/hdd/src/wlan_hdd_driver_ops.c b/core/hdd/src/wlan_hdd_driver_ops.c
index dc9d1ea..ada5569 100644
--- a/core/hdd/src/wlan_hdd_driver_ops.c
+++ b/core/hdd/src/wlan_hdd_driver_ops.c
@@ -541,11 +541,14 @@
 	void *hdd_ctx = cds_get_context(CDF_MODULE_ID_HDD);
 	int status = wlan_hdd_validate_context(hdd_ctx);
 
-	if (0 != status)
+	if (0 != status) {
+		hif_log_runtime_suspend_failure();
 		return status;
+	}
 
 	if (!hif_can_suspend_link()) {
 		hdd_err("Runtime PM not supported for link up suspend");
+		hif_log_runtime_suspend_failure();
 		return -EINVAL;
 	}
 
@@ -567,6 +570,7 @@
 		goto resume_hif;
 
 	hif_runtime_pm_set_state_suspended();
+	hif_log_runtime_suspend_success();
 	return status;
 
 resume_hif:
@@ -576,6 +580,7 @@
 resume_htc:
 	CDF_BUG(!htc_runtime_resume());
 set_state:
+	hif_log_runtime_suspend_failure();
 	hif_runtime_pm_set_state_on();
 	return status;
 }
@@ -615,6 +620,7 @@
 	CDF_BUG(!hif_runtime_resume());
 	CDF_BUG(!wma_runtime_resume());
 	CDF_BUG(!htc_runtime_resume());
+	hif_log_runtime_resume_success();
 	hif_runtime_pm_set_state_on();
 	return 0;
 }
diff --git a/core/hif/inc/hif.h b/core/hif/inc/hif.h
index 40950c3..ec210a9 100644
--- a/core/hif/inc/hif.h
+++ b/core/hif/inc/hif.h
@@ -694,6 +694,13 @@
 void hif_runtime_pm_set_state_inprogress(void);
 void hif_runtime_pm_set_state_on(void);
 void hif_runtime_pm_set_state_suspended(void);
+
+#ifdef FEATURE_RUNTIME_PM
+void hif_log_runtime_suspend_success(void);
+void hif_log_runtime_suspend_failure(void);
+void hif_log_runtime_resume_success(void);
+#endif
+
 int dump_ce_register(struct ol_softc *scn);
 int ol_copy_ramdump(struct ol_softc *scn);
 void hif_pktlogmod_exit(void *hif_ctx);
diff --git a/core/hif/src/pcie/if_pci.c b/core/hif/src/pcie/if_pci.c
index a70811e..af05003 100644
--- a/core/hif/src/pcie/if_pci.c
+++ b/core/hif/src/pcie/if_pci.c
@@ -1883,6 +1883,67 @@
 	__hif_runtime_pm_set_state(HIF_PM_RUNTIME_STATE_SUSPENDED);
 }
 
+
+#ifdef FEATURE_RUNTIME_PM
+static inline struct hif_pci_softc *get_sc(void)
+{
+	struct ol_softc *scn = cds_get_context(CDF_MODULE_ID_HIF);
+
+	if (NULL == scn) {
+		HIF_ERROR("%s: Could not disable ASPM scn is null",
+		       __func__);
+		return NULL;
+	}
+
+	return scn->hif_sc;
+}
+
+/**
+ * hif_log_runtime_suspend_success() - log a successful runtime suspend
+ */
+void hif_log_runtime_suspend_success(void)
+{
+	struct hif_pci_softc *sc = get_sc();
+	if (sc == NULL)
+		return;
+
+	sc->pm_stats.suspended++;
+	sc->pm_stats.suspend_jiffies = jiffies;
+}
+
+/**
+ * hif_log_runtime_suspend_failure() - log a failed runtime suspend
+ *
+ * log a failed runtime suspend
+ * mark last busy to prevent immediate runtime suspend
+ */
+void hif_log_runtime_suspend_failure(void)
+{
+	struct hif_pci_softc *sc = get_sc();
+	if (sc == NULL)
+		return;
+
+	sc->pm_stats.suspend_err++;
+	hif_pm_runtime_mark_last_busy(sc->dev);
+}
+
+/**
+ * hif_log_runtime_resume_success() - log a successful runtime resume
+ *
+ * log a successfull runtime resume
+ * mark last busy to prevent immediate runtime suspend
+ */
+void hif_log_runtime_resume_success(void)
+{
+	struct hif_pci_softc *sc = get_sc();
+	if (sc == NULL)
+		return;
+
+	sc->pm_stats.resumed++;
+	hif_pm_runtime_mark_last_busy(sc->dev);
+}
+#endif
+
 /**
  * hif_runtime_suspend() - do the bus suspend part of a runtime suspend
  *