1 /*
2 * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #ifndef __HDD_THERMAL_H
21 #define __HDD_THERMAL_H
22 /**
23 * DOC: wlan_hdd_thermal.h
24 * WLAN Host Device Driver thermal mitigation include file
25 */
26
27 #include <linux/netdevice.h>
28 #include <net/cfg80211.h>
29 #include <qca_vendor.h>
30
31
32 /**
33 * enum hdd_thermal_states - The various thermal states as supported by WLAN
34 * @HDD_THERMAL_STATE_NONE: The normal working state
35 * @HDD_THERMAL_STATE_LIGHT: Intermediate states, WLAN must perform partial
36 * mitigation
37 * @HDD_THERMAL_STATE_MODERATE: Intermediate states, WLAN must perform partial
38 * mitigation
39 * @HDD_THERMAL_STATE_SEVERE: Intermediate states, WLAN must perform partial
40 * mitigation
41 * @HDD_THERMAL_STATE_CRITICAL: Intermediate states, WLAN must perform partial
42 * mitigation
43 * @HDD_THERMAL_STATE_EMERGENCY: The highest state, WLAN must enter forced
44 * IMPS and will disconnect any active STA
45 * connection
46 * @HDD_THERMAL_STATE_INVAL: Placeholder for invalid/unknown state
47 */
48 enum hdd_thermal_states {
49 HDD_THERMAL_STATE_NONE = 0,
50 HDD_THERMAL_STATE_LIGHT = 1,
51 HDD_THERMAL_STATE_MODERATE = 2,
52 HDD_THERMAL_STATE_SEVERE = 3,
53 HDD_THERMAL_STATE_CRITICAL = 4,
54 HDD_THERMAL_STATE_EMERGENCY = 5,
55 HDD_THERMAL_STATE_INVAL = 0xFF,
56 };
57
58 /*
59 * thermal_monitor_id: enum of thermal client
60 * @THERMAL_MONITOR_APPS: Thermal monitor client of APPS
61 * @THERMAL_MONITOR_WPSS: Thermal monitor client for WPSS
62 */
63 enum thermal_monitor_id {
64 THERMAL_MONITOR_APPS = 1,
65 THERMAL_MONITOR_WPSS,
66 };
67
68 #ifdef FW_THERMAL_THROTTLE_SUPPORT
69 int
70 wlan_hdd_cfg80211_set_thermal_mitigation_policy(struct wiphy *wiphy,
71 struct wireless_dev *wdev,
72 const void *data, int data_len);
73
74 /**
75 * wlan_hdd_thermal_config_support() - thermal mitigation support
76 *
77 * Return: true if thermal mitigation support enabled otherwise false
78 */
79 bool wlan_hdd_thermal_config_support(void);
80
81 /**
82 * hdd_restore_thermal_mitigation_config - Restore the saved thermal config
83 * @hdd_ctx: HDD context
84 *
85 * Restore the thermal mitigation config after SSR.
86 *
87 * Return: QDF_STATUS
88 */
89 QDF_STATUS hdd_restore_thermal_mitigation_config(struct hdd_context *hdd_ctx);
90
91 extern const struct nla_policy
92 wlan_hdd_thermal_mitigation_policy
93 [QCA_WLAN_VENDOR_ATTR_THERMAL_CMD_MAX + 1];
94
95 #define FEATURE_THERMAL_VENDOR_COMMANDS \
96 { \
97 .info.vendor_id = QCA_NL80211_VENDOR_ID, \
98 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_THERMAL_CMD, \
99 .flags = WIPHY_VENDOR_CMD_NEED_WDEV, \
100 .doit = wlan_hdd_cfg80211_set_thermal_mitigation_policy, \
101 vendor_command_policy(wlan_hdd_thermal_mitigation_policy, \
102 QCA_WLAN_VENDOR_ATTR_THERMAL_CMD_MAX) \
103 },
104
105 #define FEATURE_THERMAL_VENDOR_EVENTS \
106 [QCA_NL80211_VENDOR_SUBCMD_THERMAL_INDEX] = { \
107 .vendor_id = QCA_NL80211_VENDOR_ID, \
108 .subcmd = QCA_NL80211_VENDOR_SUBCMD_THERMAL_EVENT, \
109 },
110
111 /**
112 * hdd_thermal_mitigation_register() - Register for platform specific thermal
113 * mitigation support
114 * @hdd_ctx: Pointer to Hdd context
115 * @dev: Pointer to the device
116 *
117 * Register to the platform specific thermal mitigation support
118 * Return: None
119 */
120 void hdd_thermal_mitigation_register(struct hdd_context *hdd_ctx,
121 struct device *dev);
122
123 /**
124 * hdd_thermal_mitigation_unregister() - Unregister for platform specific
125 * thermal mitigation support
126 * @hdd_ctx: Pointer to Hdd context
127 * @dev: Pointer to the device
128 *
129 * Unregister to the platform specific thermal mitigation support
130 * Return: None
131 */
132 void hdd_thermal_mitigation_unregister(struct hdd_context *hdd_ctx,
133 struct device *dev);
134
135 /**
136 * wlan_hdd_pld_set_thermal_mitigation() - send the suggested thermal value
137 * to the firmware
138 * @dev: Pointer to the device
139 * @state: Thermal state to set
140 * @mon_id: Thermal monitor id ie.. apps or wpss
141 *
142 * Send the requested thermal mitigation value to the firmware * for the
143 * requested thermal monitor id.
144 *
145 * Return: 0 for success or errno for failure.
146 */
147 int wlan_hdd_pld_set_thermal_mitigation(struct device *dev,
148 unsigned long state, int mon_id);
149 /**
150 * hdd_send_thermal_mitigation_val() - send the suggested thermal value
151 * to the firmware
152 * @hdd_ctx: pointer to hdd context
153 * @level: Thermal mitigation level to set
154 * @mon_id: Thermal monitor id ie.. apps or wpss
155 *
156 * Send the requested thermal mitigation value to the firmware * for the
157 * requested thermal monitor id.
158 *
159 * Return: 0 for success or errno for failure.
160 */
161 QDF_STATUS
162 hdd_send_thermal_mitigation_val(struct hdd_context *hdd_ctx, uint32_t level,
163 uint8_t mon_id);
164 #ifdef FEATURE_WPSS_THERMAL_MITIGATION
165 /**
166 * hdd_thermal_fill_clientid_priority() - fill the client id/priority
167 * @hdd_ctx: pointer to hdd context structure
168 * @mon_id: Thermal monitor id ie.. apps or wpss
169 * @priority_apps: Priority of the apps client to be considered
170 * @priority_wpps: Priority of the wpps client to be considered
171 * @params: pointer to thermal mitigation parameters
172 *
173 * Fill the clientid/priority for the firmwaire to consider.
174 *
175 * Return: none
176 */
177 void
178 hdd_thermal_fill_clientid_priority(struct hdd_context *hdd_ctx, uint8_t mon_id,
179 uint8_t priority_apps, uint8_t priority_wpps,
180 struct thermal_mitigation_params *params);
181 #else
182 static inline void
hdd_thermal_fill_clientid_priority(struct hdd_context * hdd_ctx,uint8_t mon_id,uint8_t priority_apps,uint8_t priority_wpps,struct thermal_mitigation_params * params)183 hdd_thermal_fill_clientid_priority(struct hdd_context *hdd_ctx, uint8_t mon_id,
184 uint8_t priority_apps, uint8_t priority_wpps,
185 struct thermal_mitigation_params *params)
186 {
187 }
188 #endif
189
190 /**
191 * hdd_thermal_register_callbacks() - register thermal event callback
192 * to be called by fwol thermal layer
193 * @hdd_ctx: hdd context
194 *
195 * The callback will be invoked by fwol thermal layer when the target
196 * indicate thermal throttle level changed. Host will report the new
197 * level to upper layer by vendor command event.
198 *
199 * Return: none
200 */
201 void hdd_thermal_register_callbacks(struct hdd_context *hdd_ctx);
202
203 /**
204 * hdd_thermal_unregister_callbacks() - unregister thermal event callback
205 * @hdd_ctx: hdd context
206 *
207 * Return: none
208 */
209 void hdd_thermal_unregister_callbacks(struct hdd_context *hdd_ctx);
210 #else
211 #define FEATURE_THERMAL_VENDOR_COMMANDS
212 #define FEATURE_THERMAL_VENDOR_EVENTS
213
wlan_hdd_thermal_config_support(void)214 static inline bool wlan_hdd_thermal_config_support(void)
215 {
216 return false;
217 }
218
219 static inline
hdd_restore_thermal_mitigation_config(struct hdd_context * hdd_ctx)220 QDF_STATUS hdd_restore_thermal_mitigation_config(struct hdd_context *hdd_ctx)
221 {
222 return false;
223 }
224
225 static inline
hdd_thermal_mitigation_register(struct hdd_context * hdd_ctx,struct device * dev)226 void hdd_thermal_mitigation_register(struct hdd_context *hdd_ctx,
227 struct device *dev)
228 {
229 }
230
231 static inline
hdd_thermal_mitigation_unregister(struct hdd_context * hdd_ctx,struct device * dev)232 void hdd_thermal_mitigation_unregister(struct hdd_context *hdd_ctx,
233 struct device *dev)
234 {
235 }
236
237 static inline
wlan_hdd_pld_set_thermal_mitigation(struct device * dev,unsigned long state,int mon_id)238 int wlan_hdd_pld_set_thermal_mitigation(struct device *dev,
239 unsigned long state, int mon_id)
240 {
241 return 0;
242 }
243
244 static inline void
hdd_thermal_register_callbacks(struct hdd_context * hdd_ctx)245 hdd_thermal_register_callbacks(struct hdd_context *hdd_ctx)
246 {
247 }
248
249 static inline void
hdd_thermal_unregister_callbacks(struct hdd_context * hdd_ctx)250 hdd_thermal_unregister_callbacks(struct hdd_context *hdd_ctx)
251 {
252 }
253
254 static inline QDF_STATUS
hdd_send_thermal_mitigation_val(struct hdd_context * hdd_ctx,uint32_t level,uint8_t mon_id)255 hdd_send_thermal_mitigation_val(struct hdd_context *hdd_ctx, uint32_t level,
256 uint8_t mon_id)
257 {
258 return QDF_STATUS_SUCCESS;
259 }
260 #endif /* FEATURE_THERMAL_VENDOR_COMMANDS */
261
262 #ifdef THERMAL_STATS_SUPPORT
263 QDF_STATUS
264 hdd_send_get_thermal_stats_cmd(struct hdd_context *hdd_ctx,
265 enum thermal_stats_request_type request_type,
266 void (*callback)(void *context,
267 struct thermal_throttle_info *response),
268 void *context);
269 #endif /* THERMAL_STATS_SUPPORT */
270 #endif /* __HDD_THERMAL_H */
271