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