1 /*
2 * Copyright (c) 2012-2020 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 __WLAN_HDD_SAR_LIMITS_H
21 #define __WLAN_HDD_SAR_LIMITS_H
22
23 /**
24 * DOC: wlan_hdd_sar_limits_h
25 *
26 * WLAN Host Device Driver SAR limits API specification
27 */
28
29 #if defined(FEATURE_SAR_LIMITS) && defined(SAR_SAFETY_FEATURE)
30 /**
31 * wlan_hdd_sar_unsolicited_timer_start() - Start SAR unsolicited timer
32 * @hdd_ctx: Pointer to HDD context
33 *
34 * This function checks the state of the sar unsolicited timer, if the
35 * sar_unsolicited_timer is not running, it starts the timer.
36 *
37 * Return: None
38 */
39 void wlan_hdd_sar_unsolicited_timer_start(struct hdd_context *hdd_ctx);
40
41 /**
42 * wlan_hdd_sar_timers_reset() - Reset SAR timers
43 * @hdd_ctx: Pointer to HDD context
44 *
45 * This function checks the state of the sar safety timer, if the
46 * sar_safety_timer is not running, it starts the timer else it stops
47 * the timer and start the timer again.
48 *
49 * Return: None
50 */
51 void wlan_hdd_sar_timers_reset(struct hdd_context *hdd_ctx);
52
53 /**
54 * wlan_hdd_sar_timers_init() - Initialize SAR timers
55 * @hdd_ctx: Pointer to HDD context
56 *
57 * This function initializes sar timers.
58 * Return: None
59 */
60 void wlan_hdd_sar_timers_init(struct hdd_context *hdd_ctx);
61
62 /**
63 * wlan_hdd_sar_timers_deinit() - De-initialize SAR timers
64 * @hdd_ctx: Pointer to HDD context
65 *
66 * This function de-initializes sar timers.
67 * Return: None
68 */
69 void wlan_hdd_sar_timers_deinit(struct hdd_context *hdd_ctx);
70
71 /**
72 * hdd_configure_sar_index() - configures SAR index to the FW
73 * @hdd_ctx: Pointer to HDD context
74 * @sar_index: sar index which needs to be configured to FW
75 *
76 * This function configures SAR power index on both the chains
77 * for SAR version2
78 *
79 * Return: None
80 */
81 void hdd_configure_sar_index(struct hdd_context *hdd_ctx, uint32_t sar_index);
82
83 /**
84 * hdd_disable_sar() - Disable SAR feature to FW
85 * @hdd_ctx: Pointer to HDD context
86 *
87 * This function Disables SAR power index on both the chains
88 *
89 * Return: None
90 */
91 void hdd_disable_sar(struct hdd_context *hdd_ctx);
92
93 /**
94 * hdd_configure_sar_sleep_index() - Configure SAR sleep index to FW
95 * @hdd_ctx: Pointer to HDD context
96 *
97 * This function configures SAR sleep index on both the chains
98 *
99 * Return: None
100 */
101 void hdd_configure_sar_sleep_index(struct hdd_context *hdd_ctx);
102
103 /**
104 * hdd_configure_sar_resume_index() - Configure SAR resume index to FW
105 * @hdd_ctx: Pointer to HDD context
106 *
107 * This function configures SAR resume index on both the chains
108 *
109 * Return: None
110 */
111 void hdd_configure_sar_resume_index(struct hdd_context *hdd_ctx);
112
113 #else
wlan_hdd_sar_unsolicited_timer_start(struct hdd_context * hdd_ctx)114 static inline void wlan_hdd_sar_unsolicited_timer_start(
115 struct hdd_context *hdd_ctx)
116 {
117 }
118
wlan_hdd_sar_timers_reset(struct hdd_context * hdd_ctx)119 static inline void wlan_hdd_sar_timers_reset(struct hdd_context *hdd_ctx)
120 {
121 }
122
wlan_hdd_sar_timers_init(struct hdd_context * hdd_ctx)123 static inline void wlan_hdd_sar_timers_init(struct hdd_context *hdd_ctx)
124 {
125 }
126
wlan_hdd_sar_timers_deinit(struct hdd_context * hdd_ctx)127 static inline void wlan_hdd_sar_timers_deinit(struct hdd_context *hdd_ctx)
128 {
129 }
130
hdd_configure_sar_index(struct hdd_context * hdd_ctx,uint32_t sar_index)131 static inline void hdd_configure_sar_index(struct hdd_context *hdd_ctx,
132 uint32_t sar_index)
133 {
134 }
135
hdd_disable_sar(struct hdd_context * hdd_ctx)136 static inline void hdd_disable_sar(struct hdd_context *hdd_ctx)
137 {
138 }
139
hdd_configure_sar_sleep_index(struct hdd_context * hdd_ctx)140 static inline void hdd_configure_sar_sleep_index(struct hdd_context *hdd_ctx)
141 {
142 }
143
hdd_configure_sar_resume_index(struct hdd_context * hdd_ctx)144 static inline void hdd_configure_sar_resume_index(struct hdd_context *hdd_ctx)
145 {
146 }
147
148 #endif
149
150 #ifdef FEATURE_SAR_LIMITS
151 /**
152 * wlan_hdd_cfg80211_get_sar_power_limits() - Get SAR power limits
153 * @wiphy: Pointer to wireless phy
154 * @wdev: Pointer to wireless device
155 * @data: Pointer to data
156 * @data_len: Length of @data
157 *
158 * Wrapper function of __wlan_hdd_cfg80211_get_sar_power_limits()
159 *
160 * Return: 0 on success, negative errno on failure
161 */
162 int wlan_hdd_cfg80211_get_sar_power_limits(struct wiphy *wiphy,
163 struct wireless_dev *wdev,
164 const void *data,
165 int data_len);
166
167 /**
168 * wlan_hdd_cfg80211_set_sar_power_limits() - Set SAR power limits
169 * @wiphy: Pointer to wireless phy
170 * @wdev: Pointer to wireless device
171 * @data: Pointer to data
172 * @data_len: Length of @data
173 *
174 * Wrapper function of __wlan_hdd_cfg80211_set_sar_power_limits()
175 *
176 * Return: 0 on success, negative errno on failure
177 */
178 int wlan_hdd_cfg80211_set_sar_power_limits(struct wiphy *wiphy,
179 struct wireless_dev *wdev,
180 const void *data,
181 int data_len);
182 /**
183 * wlan_hdd_cfg80211_get_sar_capability() - Get SAR capability
184 * @wiphy: Pointer to wireless phy
185 * @wdev: Pointer to wireless device
186 * @data: Pointer to data
187 * @data_len: Length of @data
188 *
189 * Wrapper function of __wlan_hdd_get_sar_capability()
190 *
191 * Return: 0 on success, negative errno on failure
192 */
193
194 int wlan_hdd_cfg80211_get_sar_capability(struct wiphy *wiphy,
195 struct wireless_dev *wdev,
196 const void *data,
197 int data_len);
198 /**
199 * hdd_store_sar_config() - Store SAR config in HDD context
200 * @hdd_ctx: The HDD context
201 * @sar_limit_cmd: The sar_limit_cmd_params struct to save
202 *
203 * After SSR, the SAR configuration is lost. As SSR is hidden from
204 * userland, this command will not come from userspace after a SSR. To
205 * restore this configuration, save this in hdd context and restore
206 * after re-init.
207 *
208 * Return: None
209 */
210 void hdd_store_sar_config(struct hdd_context *hdd_ctx,
211 struct sar_limit_cmd_params *sar_limit_cmd);
212
213 /**
214 * wlan_hdd_free_sar_config() - Free the resources allocated while storing
215 * SAR config
216 * @hdd_ctx: HDD context
217 *
218 * The driver stores the SAR config values in HDD context so that it can be
219 * restored in the case SSR is invoked. Free those resources.
220 *
221 * Return: None
222 */
223 void wlan_hdd_free_sar_config(struct hdd_context *hdd_ctx);
224
225 extern const struct nla_policy
226 wlan_hdd_sar_limits_policy[QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_MAX + 1];
227
228 #define FEATURE_SAR_LIMITS_VENDOR_COMMANDS \
229 { \
230 .info.vendor_id = QCA_NL80211_VENDOR_ID, \
231 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_SAR_LIMITS, \
232 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | \
233 WIPHY_VENDOR_CMD_NEED_RUNNING, \
234 .doit = wlan_hdd_cfg80211_get_sar_power_limits, \
235 vendor_command_policy(VENDOR_CMD_RAW_DATA, 0) \
236 }, \
237 { \
238 .info.vendor_id = QCA_NL80211_VENDOR_ID, \
239 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_SET_SAR_LIMITS, \
240 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | \
241 WIPHY_VENDOR_CMD_NEED_RUNNING, \
242 .doit = wlan_hdd_cfg80211_set_sar_power_limits, \
243 vendor_command_policy(wlan_hdd_sar_limits_policy, \
244 QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_MAX) \
245 }, \
246 { \
247 .info.vendor_id = QCA_NL80211_VENDOR_ID, \
248 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_GET_SAR_CAPABILITY, \
249 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | \
250 WIPHY_VENDOR_CMD_NEED_RUNNING, \
251 .doit = wlan_hdd_cfg80211_get_sar_capability, \
252 vendor_command_policy(VENDOR_CMD_RAW_DATA, 0) \
253 },
254 #else /* FEATURE_SAR_LIMITS */
255 #define FEATURE_SAR_LIMITS_VENDOR_COMMANDS
256 static inline
hdd_store_sar_config(struct hdd_context * hdd_ctx,struct sar_limit_cmd_params * sar_limit_cmd)257 void hdd_store_sar_config(struct hdd_context *hdd_ctx,
258 struct sar_limit_cmd_params *sar_limit_cmd)
259 {
260 }
261
wlan_hdd_free_sar_config(struct hdd_context * hdd_ctx)262 static inline void wlan_hdd_free_sar_config(struct hdd_context *hdd_ctx)
263 {
264 }
265
266 #endif /* FEATURE_SAR_LIMITS */
267
268 #endif /* __WLAN_HDD_SAR_LIMITS_H */
269
270