xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_utils.h (revision 8ddef7dd9a290d4a9b1efd5d3efacf51d78a1a0d)
1 /*
2  * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
3  *
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 /**
21  * DOC: reg_utils.h
22  * This file provides prototypes for setting and getting regulatory variables.
23  */
24 
25 #ifndef __REG_UTILS_H_
26 #define __REG_UTILS_H_
27 
28 #ifdef WLAN_FEATURE_DSRC
29 #define REG_DSRC_START_FREQ channel_map[MIN_DSRC_CHANNEL].center_freq
30 #define REG_DSRC_END_FREQ   channel_map[MAX_DSRC_CHANNEL].center_freq
31 #endif
32 
33 #define REG_ETSI13_SRD_START_FREQ 5745
34 #define REG_ETSI13_SRD_END_FREQ   5865
35 
36 #define REG_IS_CHANNEL_VALID_5G_SBS(curchan, newchan)	\
37 	((curchan) > (newchan) ?				\
38 	 REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	\
39 	 - REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	\
40 	 > REG_SBS_SEPARATION_THRESHOLD :		\
41 	 REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	\
42 	 - REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	\
43 	 > REG_SBS_SEPARATION_THRESHOLD)
44 
45 #ifdef CONFIG_MCL_REGDB
46 /**
47  * reg_chan_has_dfs_attribute() - check channel has dfs attribue or not
48  * @ch: channel number.
49  *
50  * This API get chan initial dfs attribue flag from regdomain
51  *
52  * Return: true if chan is dfs, otherwise false
53  */
54 bool reg_chan_has_dfs_attribute(struct wlan_objmgr_pdev *pdev, uint32_t ch);
55 
56 /**
57  * reg_set_band() - Sets the band information for the PDEV
58  * @pdev: The physical dev to set the band for
59  * @band: The set band parameters to configure for the pysical device
60  *
61  * Return: QDF_STATUS
62  */
63 QDF_STATUS reg_set_band(struct wlan_objmgr_pdev *pdev, enum band_info band);
64 
65 #ifdef DISABLE_CHANNEL_LIST
66 /**
67  * reg_restore_cached_channels() - Cache the current state of the channles
68  * @pdev: The physical dev to cache the channels for
69  */
70 QDF_STATUS reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev);
71 
72 /**
73  * reg_cache_channel_state() - Cache the current state of the channles
74  * @pdev: The physical dev to cache the channels for
75  * @channel_list: List of the channels for which states needs to be cached
76  * @num_channels: Number of channels in the list
77  *
78  */
79 QDF_STATUS reg_cache_channel_state(struct wlan_objmgr_pdev *pdev,
80 				   uint32_t *channel_list,
81 				   uint32_t num_channels);
82 #else
83 static inline
84 QDF_STATUS reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev)
85 {
86 	return QDF_STATUS_SUCCESS;
87 }
88 
89 static inline
90 QDF_STATUS reg_cache_channel_state(struct wlan_objmgr_pdev *pdev,
91 				   uint32_t *channel_list,
92 				   uint32_t num_channels)
93 {
94 	return QDF_STATUS_SUCCESS;
95 }
96 #endif
97 
98 /**
99  * reg_set_fcc_constraint() - Apply fcc constraints on channels 12/13
100  * @pdev: The physical dev to set the band for
101  *
102  * This function reduces the transmit power on channels 12 and 13, to comply
103  * with FCC regulations in the USA.
104  *
105  * Return: QDF_STATUS
106  */
107 QDF_STATUS reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev,
108 				  bool fcc_constraint);
109 
110 /**
111  * reg_read_current_country() - Get the current regulatory country
112  * @psoc: The physical SoC to get current country from
113  * @country_code: the buffer to populate the country code into
114  *
115  * Return: QDF_STATUS
116  */
117 QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc,
118 				    uint8_t *country_code);
119 
120 /**
121  * reg_set_default_country() - Set the default regulatory country
122  * @psoc: The physical SoC to set default country for
123  * @req: The country information to configure
124  *
125  * Return: QDF_STATUS
126  */
127 QDF_STATUS reg_set_default_country(struct wlan_objmgr_psoc *psoc,
128 				   uint8_t *country);
129 
130 /**
131  * reg_is_world_alpha2 - is reg world mode
132  * @alpha2: country code pointer
133  *
134  * Return: true or false
135  */
136 bool reg_is_world_alpha2(uint8_t *alpha2);
137 
138 /**
139  * reg_is_us_alpha2 - is US country code
140  * @alpha2: country code pointer
141  *
142  * Return: true or false
143  */
144 bool reg_is_us_alpha2(uint8_t *alpha2);
145 
146 /**
147  * reg_set_country() - Set the current regulatory country
148  * @pdev: pdev device for country information
149  * @country: country value
150  *
151  * Return: QDF_STATUS
152  */
153 QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev, uint8_t *country);
154 
155 /**
156  * reg_reset_country() - Reset the regulatory country to default
157  * @psoc: The physical SoC to reset country for
158  *
159  * Return: QDF_STATUS
160  */
161 QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc);
162 
163 /**
164  * reg_get_domain_from_country_code() - Get regdomain from country code
165  * @reg_domain_ptr: Pointer to save regdomain
166  * @country_alpha2: country string
167  * @source: Country code source
168  *
169  * Return: QDF_STATUS
170  */
171 QDF_STATUS reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr,
172 					    const uint8_t *country_alpha2,
173 					    enum country_src source);
174 
175 /**
176  * reg_is_passive_or_disable_ch() - Check if the given channel is passive or
177  * disabled.
178  * @pdev: Pointer to physical dev
179  * @chan: Channel number
180  *
181  * Return: true if channel is passive or disabled, else false.
182  */
183 bool reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
184 
185 /**
186  * reg_is_disable_ch() - Check if the given channel in disable state
187  * @pdev: Pointer to pdev
188  * @chan: channel number
189  *
190  * Return: True if channel state is disabled, else false
191  */
192 bool reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
193 
194 /**
195  * reg_set_config_vars () - set configration variables
196  * @psoc: psoc ptr
197  * @config_vars: configuration struct
198  *
199  * Return: QDF_STATUS
200  */
201 QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
202 			       struct reg_config_vars config_vars);
203 
204 /**
205  * reg_is_regdb_offloaded() - is regdb offloaded
206  * @psoc: Pointer to psoc object
207  *
208  * Return: true if regdb is offloaded, else false
209  */
210 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc);
211 
212 /**
213  * reg_program_mas_chan_list() - Program the master channel list
214  * @psoc: Pointer to psoc structure
215  * @reg_channels: Pointer to reg channels
216  * @alpha2: country string
217  * @dfs_region: DFS region
218  */
219 void reg_program_mas_chan_list(struct wlan_objmgr_psoc *psoc,
220 			       struct regulatory_channel *reg_channels,
221 			       uint8_t *alpha2, enum dfs_reg dfs_region);
222 
223 /**
224  * reg_get_regd_rules() - provides the reg domain rules info
225  * @pdev: pdev pointer
226  * @reg_rules: regulatory rules
227  *
228  * Return: QDF_STATUS
229  */
230 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev,
231 			      struct reg_rule_info *reg_rules);
232 
233 /**
234  * reg_get_cc_and_src() - Get country string and country source
235  * @psoc: Pointer to psoc
236  * @alpha2: Pointer to save country string
237  *
238  * Return: country_src
239  */
240 enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
241 				    uint8_t *alpha2);
242 
243 /**
244  * reg_reset_ctry_pending_hints() - Reset all country pending hints
245  * @soc_reg: regulatory private object
246  *
247  * Return: None
248  */
249 void
250 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg);
251 
252 /**
253  * reg_set_curr_country() - Set current country update
254  * @soc_reg: regulatory private object
255  * @regulat_info: regulatory info from firmware
256  * @tx_ops: send operations for regulatory component
257  *
258  * During SSR or restart of wlan modules after interface change timer phase,
259  * this function is used to send the recent user/11d country code to firmware.
260  *
261  * Return: QDF_STATUS_SUCCESS if correct country is configured
262  * else return failure
263  * error code.
264  */
265 QDF_STATUS reg_set_curr_country(
266 		struct wlan_regulatory_psoc_priv_obj *soc_reg,
267 		struct cur_regulatory_info *regulat_info,
268 		struct wlan_lmac_if_reg_tx_ops *tx_ops);
269 
270 /**
271  * reg_ignore_default_country() - Ignore default country update
272  * @soc_reg: regulatory private object
273  * @regulat_info: regulatory info from firmware
274  *
275  * During SSR or restart of wlan modules after interface change timer phase,
276  * this function is used to ignore default country code from firmware.
277  *
278  * Return: If default country needs to be ignored return true else false.
279  */
280 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg,
281 				struct cur_regulatory_info *regulat_info);
282 
283 #else
284 
285 static inline bool reg_chan_has_dfs_attribute(struct wlan_objmgr_pdev *pdev,
286 					      uint32_t ch)
287 {
288 	return false;
289 }
290 
291 static inline QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc,
292 						  uint8_t *country_code)
293 {
294 	return QDF_STATUS_SUCCESS;
295 }
296 
297 static inline bool reg_is_world_alpha2(uint8_t *alpha2)
298 {
299 	return false;
300 }
301 
302 static inline bool reg_is_us_alpha2(uint8_t *alpha2)
303 {
304 	return false;
305 }
306 
307 static inline QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev,
308 					 uint8_t *country)
309 {
310 	return QDF_STATUS_SUCCESS;
311 }
312 
313 static inline QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc)
314 {
315 	return QDF_STATUS_SUCCESS;
316 }
317 
318 static inline QDF_STATUS reg_get_domain_from_country_code(
319 	v_REGDOMAIN_t *reg_domain_ptr, const uint8_t *country_alpha2,
320 	enum country_src source)
321 {
322 	return QDF_STATUS_SUCCESS;
323 }
324 
325 static inline bool reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev,
326 						uint32_t chan)
327 {
328 	return false;
329 }
330 
331 static inline bool reg_is_disable_ch(struct wlan_objmgr_pdev *pdev,
332 				     uint32_t chan)
333 {
334 	return false;
335 }
336 
337 static inline QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
338 					     struct reg_config_vars config_vars)
339 {
340 	return QDF_STATUS_SUCCESS;
341 }
342 
343 static inline bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc)
344 {
345 	return false;
346 }
347 
348 static inline void reg_program_mas_chan_list(
349 	struct wlan_objmgr_psoc *psoc,
350 	struct regulatory_channel *reg_channels,
351 	uint8_t *alpha2, enum dfs_reg dfs_region)
352 {
353 }
354 
355 static inline QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev,
356 					    struct reg_rule_info *reg_rules)
357 {
358 	return QDF_STATUS_SUCCESS;
359 }
360 
361 static inline enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
362 						  uint8_t *alpha2)
363 {
364 		return SOURCE_UNKNOWN;
365 }
366 
367 static inline void
368 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg)
369 {
370 }
371 
372 static inline QDF_STATUS reg_set_curr_country(
373 		struct wlan_regulatory_psoc_priv_obj *soc_reg,
374 		struct cur_regulatory_info *regulat_info,
375 		struct wlan_lmac_if_reg_tx_ops *tx_ops)
376 {
377 	return QDF_STATUS_SUCCESS;
378 }
379 
380 static inline
381 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg,
382 				struct cur_regulatory_info *regulat_info)
383 {
384 	return false;
385 }
386 #endif
387 
388 #if defined(WLAN_FEATURE_DSRC) && defined(CONFIG_MCL_REGDB)
389 /**
390  * reg_is_dsrc_chan () - Checks the channel for DSRC or not
391  * @chan: channel
392  * @pdev: pdev ptr
393  *
394  * Return: true or false
395  */
396 bool reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, uint32_t chan);
397 
398 static inline bool reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev,
399 					  uint32_t chan)
400 {
401 	return false;
402 }
403 
404 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev)
405 {
406 	return false;
407 }
408 
409 static inline bool
410 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
411 {
412 	return true;
413 }
414 #elif defined(CONFIG_MCL_REGDB)
415 static inline bool reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev,
416 				    uint32_t chan)
417 {
418 	return false;
419 }
420 
421 /**
422  * reg_is_etsi13_regdmn () - Checks if the current reg domain is ETSI13 or not
423  * @pdev: pdev ptr
424  *
425  * Return: true or false
426  */
427 bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev);
428 
429 /**
430  * reg_is_etsi13_srd_chan () - Checks the channel for ETSI13 srd ch or not
431  * @chan: channel
432  * @pdev: pdev ptr
433  *
434  * Return: true or false
435  */
436 bool reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev, uint32_t chan);
437 
438 /**
439  * reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is ETSI13
440  * and SRD channels are allowed in master mode or not.
441  *
442  * @pdev: pdev ptr
443  *
444  * Return: true or false
445  */
446 bool reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev);
447 #else
448 static inline bool reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev,
449 				    uint32_t chan)
450 {
451 	return false;
452 }
453 
454 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev)
455 {
456 	return false;
457 }
458 
459 static inline bool
460 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
461 {
462 	return false;
463 }
464 
465 static inline bool reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev,
466 					  uint32_t chan)
467 {
468 	return false;
469 }
470 #endif
471 
472 #if defined(DISABLE_CHANNEL_LIST) && defined(CONFIG_MCL_REGDB)
473 /**
474  * set_disable_channel_state() - Set disable channel state flag
475  * @pdev_priv_obj: Pointer to pdev object
476  */
477 void set_disable_channel_state(
478 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj);
479 #else
480 static inline void set_disable_channel_state(
481 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
482 {
483 }
484 #endif
485 #endif
486