1 /* 2 * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef __HIF_RUNTIME_PM_H__ 18 #define __HIF_RUNTIME_PM_H__ 19 20 #ifdef FEATURE_RUNTIME_PM 21 22 /** 23 * enum hif_pm_runtime_state - Driver States for Runtime Power Management 24 * HIF_PM_RUNTIME_STATE_NONE: runtime pm is off 25 * HIF_PM_RUNTIME_STATE_ON: runtime pm is active and link is active 26 * HIF_PM_RUNTIME_STATE_RESUMING: a runtime resume is in progress 27 * HIF_PM_RUNTIME_STATE_SUSPENDING: a runtime suspend is in progress 28 * HIF_PM_RUNTIME_STATE_SUSPENDED: the driver is runtime suspended 29 */ 30 enum hif_pm_runtime_state { 31 HIF_PM_RUNTIME_STATE_NONE, 32 HIF_PM_RUNTIME_STATE_ON, 33 HIF_PM_RUNTIME_STATE_RESUMING, 34 HIF_PM_RUNTIME_STATE_SUSPENDING, 35 HIF_PM_RUNTIME_STATE_SUSPENDED, 36 }; 37 38 /** 39 * struct hif_pm_runtime_lock - data structure for preventing runtime suspend 40 * @list - global list of runtime locks 41 * @active - true if this lock is preventing suspend 42 * @name - character string for tracking this lock 43 */ 44 struct hif_pm_runtime_lock { 45 struct list_head list; 46 bool active; 47 uint32_t timeout; 48 const char *name; 49 }; 50 51 /* Debugging stats for RTPM for HTC layer */ 52 struct hif_pm_runtime_htc_stats { 53 uint32_t rtpm_get_htt_resp; 54 uint32_t rtpm_get_htt_no_resp; 55 uint32_t rtpm_put_htt_resp; 56 uint32_t rtpm_put_htt_no_resp; 57 uint32_t rtpm_put_htt_error; 58 uint32_t rtpm_put_htc_cleanup; 59 uint32_t rtpm_get_htc_kick_queues; 60 uint32_t rtpm_put_htc_kick_queues; 61 uint32_t rtpm_get_htt_fetch_pkts; 62 uint32_t rtpm_put_htt_fetch_pkts; 63 }; 64 65 /* Debugging stats for Runtime PM */ 66 struct hif_pci_pm_stats { 67 u32 suspended; 68 u32 suspend_err; 69 u32 resumed; 70 atomic_t runtime_get; 71 atomic_t runtime_put; 72 atomic_t runtime_get_dbgid[RTPM_ID_MAX]; 73 atomic_t runtime_put_dbgid[RTPM_ID_MAX]; 74 uint64_t runtime_get_timestamp_dbgid[RTPM_ID_MAX]; 75 uint64_t runtime_put_timestamp_dbgid[RTPM_ID_MAX]; 76 u32 request_resume; 77 atomic_t allow_suspend; 78 atomic_t prevent_suspend; 79 u32 prevent_suspend_timeout; 80 u32 allow_suspend_timeout; 81 u32 runtime_get_err; 82 wlan_rtpm_dbgid last_resume_rtpm_dbgid; 83 void *last_busy_marker; 84 qdf_time_t last_busy_timestamp; 85 unsigned long suspend_jiffies; 86 struct hif_pm_runtime_htc_stats pm_stats_htc; 87 }; 88 89 struct hif_runtime_pm_ctx { 90 atomic_t pm_state; 91 atomic_t monitor_wake_intr; 92 uint32_t prevent_suspend_cnt; 93 struct hif_pci_pm_stats pm_stats; 94 struct work_struct pm_work; 95 spinlock_t runtime_lock; /* Generic spinlock for Runtime PM */ 96 qdf_spinlock_t runtime_suspend_lock; 97 qdf_timer_t runtime_timer; 98 struct list_head prevent_suspend_list; 99 unsigned long runtime_timer_expires; 100 qdf_runtime_lock_t prevent_linkdown_lock; 101 atomic_t pm_dp_rx_busy; 102 qdf_time_t dp_last_busy_timestamp; 103 #ifdef WLAN_OPEN_SOURCE 104 struct dentry *pm_dentry; 105 #endif 106 }; 107 108 #include <linux/pm_runtime.h> 109 110 static inline int hif_pm_request_resume(struct device *dev) 111 { 112 return pm_request_resume(dev); 113 } 114 115 static inline int __hif_pm_runtime_get(struct device *dev) 116 { 117 return pm_runtime_get(dev); 118 } 119 120 static inline int hif_pm_runtime_put_auto(struct device *dev) 121 { 122 return pm_runtime_put_autosuspend(dev); 123 } 124 125 void hif_pm_runtime_open(struct hif_softc *scn); 126 void hif_pm_runtime_start(struct hif_softc *scn); 127 void hif_pm_runtime_stop(struct hif_softc *scn); 128 void hif_pm_runtime_close(struct hif_softc *scn); 129 void hif_runtime_prevent_linkdown(struct hif_softc *scn, bool flag); 130 131 #else 132 static inline void hif_pm_runtime_open(struct hif_softc *scn) {} 133 static inline void hif_pm_runtime_start(struct hif_softc *scn) {} 134 static inline void hif_pm_runtime_stop(struct hif_softc *scn) {} 135 static inline void hif_pm_runtime_close(struct hif_softc *scn) {} 136 static inline void hif_runtime_prevent_linkdown(struct hif_softc *scn, 137 bool flag) {} 138 #endif /* FEATURE_RUNTIME_PM */ 139 #endif /* __HIF_RUNTIME_PM_H__ */ 140