xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_services_common.h (revision 45a38684b07295822dc8eba39e293408f203eec8)
1 /*
2  * Copyright (c) 2017-2020 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_services.h
22  * This file provides prototypes of the regulatory component
23  * service functions
24  */
25 
26 #ifndef __REG_SERVICES_COMMON_H_
27 #define __REG_SERVICES_COMMON_H_
28 
29 #define IS_VALID_PSOC_REG_OBJ(psoc_priv_obj) (psoc_priv_obj)
30 #define IS_VALID_PDEV_REG_OBJ(pdev_priv_obj) (pdev_priv_obj)
31 #define FREQ_TO_CHAN_SCALE     5
32 /* The distance between the 80Mhz center and the nearest 20Mhz channel */
33 #define NEAREST_20MHZ_CHAN_FREQ_OFFSET     10
34 #define NUM_20_MHZ_CHAN_IN_80_MHZ_CHAN     4
35 #define NUM_20_MHZ_CHAN_IN_160_MHZ_CHAN    8
36 
37 #ifdef CONFIG_CHAN_NUM_API
38 #define REG_MIN_24GHZ_CH_NUM channel_map[MIN_24GHZ_CHANNEL].chan_num
39 #define REG_MAX_24GHZ_CH_NUM channel_map[MAX_24GHZ_CHANNEL].chan_num
40 #define REG_MIN_5GHZ_CH_NUM channel_map[MIN_5GHZ_CHANNEL].chan_num
41 #define REG_MAX_5GHZ_CH_NUM channel_map[MAX_5GHZ_CHANNEL].chan_num
42 
43 #define REG_IS_24GHZ_CH(chan_num) \
44 	(((chan_num) >= REG_MIN_24GHZ_CH_NUM) &&	\
45 	 ((chan_num) <= REG_MAX_24GHZ_CH_NUM))
46 #endif /* CONFIG_CHAN_NUM_API */
47 
48 #define REG_MIN_24GHZ_CH_FREQ channel_map[MIN_24GHZ_CHANNEL].center_freq
49 #define REG_MAX_24GHZ_CH_FREQ channel_map[MAX_24GHZ_CHANNEL].center_freq
50 
51 #define REG_IS_24GHZ_CH_FREQ(freq) \
52 	(((freq) >= REG_MIN_24GHZ_CH_FREQ) &&   \
53 	((freq) <= REG_MAX_24GHZ_CH_FREQ))
54 
55 #ifdef CONFIG_CHAN_FREQ_API
56 #define REG_MIN_5GHZ_CH_FREQ channel_map[MIN_5GHZ_CHANNEL].center_freq
57 #define REG_MAX_5GHZ_CH_FREQ channel_map[MAX_5GHZ_CHANNEL].center_freq
58 #endif /* CONFIG_CHAN_FREQ_API */
59 
60 #define REG_MIN_49GHZ_CH_FREQ channel_map[MIN_49GHZ_CHANNEL].center_freq
61 #define REG_MAX_49GHZ_CH_FREQ channel_map[MAX_49GHZ_CHANNEL].center_freq
62 
63 #define REG_IS_49GHZ_FREQ(freq) \
64 	(((freq) >= REG_MIN_49GHZ_CH_FREQ) &&   \
65 	((freq) <= REG_MAX_49GHZ_CH_FREQ))
66 
67 #ifdef CONFIG_CHAN_NUM_API
68 #define REG_IS_5GHZ_CH(chan_num) \
69 	(((chan_num) >= REG_MIN_5GHZ_CH_NUM) &&	\
70 	 ((chan_num) <= REG_MAX_5GHZ_CH_NUM))
71 #endif /* CONFIG_CHAN_NUM_API */
72 
73 #define REG_IS_5GHZ_FREQ(freq) \
74 	(((freq) >= channel_map[MIN_5GHZ_CHANNEL].center_freq) &&	\
75 	 ((freq) <= channel_map[MAX_5GHZ_CHANNEL].center_freq))
76 
77 /*
78  * It should be 2.5 MHz actually but since we are using integer use 2
79  * instead, which does not create any problem in the start edge calculation.
80  */
81 #define HALF_5MHZ_BW     2
82 #define HALF_20MHZ_BW    10
83 
84 #define FIVEG_STARTING_EDGE_FREQ (channel_map_global[MIN_49GHZ_CHANNEL]. \
85 				  center_freq - HALF_5MHZ_BW)
86 #define FIVEG_ENDING_EDGE_FREQ   (channel_map_global[MAX_5GHZ_CHANNEL]. \
87 				  center_freq + HALF_20MHZ_BW)
88 
89 #ifdef CONFIG_BAND_6GHZ
90 #define SIXG_STARTING_EDGE_FREQ  (channel_map_global[MIN_6GHZ_CHANNEL]. \
91 				  center_freq - HALF_20MHZ_BW)
92 #define SIXG_ENDING_EDGE_FREQ    (channel_map_global[MAX_6GHZ_CHANNEL]. \
93 				  center_freq + HALF_20MHZ_BW)
94 
95 #define FREQ_LEFT_SHIFT         55
96 #define SIX_GHZ_NON_ORPHAN_START_FREQ \
97 	(channel_map_global[MIN_6GHZ_NON_ORPHAN_CHANNEL].center_freq  - 5)
98 #define CHAN_FREQ_5935          5935
99 #define NUM_80MHZ_BAND_IN_6G    16
100 #define NUM_PSC_FREQ            15
101 #define PSC_BAND_MHZ (FREQ_TO_CHAN_SCALE * NUM_80MHZ_BAND_IN_6G)
102 #define REG_MIN_6GHZ_CHAN_FREQ channel_map[MIN_6GHZ_CHANNEL].center_freq
103 #define REG_MAX_6GHZ_CHAN_FREQ channel_map[MAX_6GHZ_CHANNEL].center_freq
104 #else
105 #define FREQ_LEFT_SHIFT         0
106 #define SIX_GHZ_NON_ORPHAN_START_FREQ       0
107 #define CHAN_FREQ_5935          0
108 #define NUM_80MHZ_BAND_IN_6G    0
109 #define NUM_PSC_FREQ            0
110 #define PSC_BAND_MHZ (FREQ_TO_CHAN_SCALE * NUM_80MHZ_BAND_IN_6G)
111 #define REG_MIN_6GHZ_CHAN_FREQ  0
112 #define REG_MAX_6GHZ_CHAN_FREQ  0
113 #endif /*CONFIG_BAND_6GHZ*/
114 
115 #define REG_CH_NUM(ch_enum) channel_map[ch_enum].chan_num
116 #define REG_CH_TO_FREQ(ch_enum) channel_map[ch_enum].center_freq
117 
118 /* EEPROM setting is a country code */
119 #define    COUNTRY_ERD_FLAG     0x8000
120 #define MIN_6GHZ_OPER_CLASS 131
121 #define MAX_6GHZ_OPER_CLASS 136
122 
123 extern const struct chan_map *channel_map;
124 extern const struct chan_map channel_map_us[];
125 extern const struct chan_map channel_map_eu[];
126 extern const struct chan_map channel_map_jp[];
127 extern const struct chan_map channel_map_china[];
128 extern const struct chan_map channel_map_global[];
129 
130 /**
131  * reg_get_channel_list_with_power() - Provides the channel list with power
132  * @pdev: Pointer to pdev
133  * @ch_list: Pointer to the channel list.
134  * @num_chan: Pointer to save number of channels
135  *
136  * Return: QDF_STATUS
137  */
138 QDF_STATUS reg_get_channel_list_with_power(struct wlan_objmgr_pdev *pdev,
139 					   struct channel_power *ch_list,
140 					   uint8_t *num_chan);
141 
142 #ifdef CONFIG_CHAN_NUM_API
143 /**
144  * reg_get_chan_enum() - Get channel enum for given channel number
145  * @chan_num: Channel number
146  *
147  * Return: Channel enum
148  */
149 enum channel_enum reg_get_chan_enum(uint8_t chan_num);
150 
151 /**
152  * reg_get_channel_state() - Get channel state from regulatory
153  * @pdev: Pointer to pdev
154  * @ch: channel number.
155  *
156  * Return: channel state
157  */
158 enum channel_state reg_get_channel_state(struct wlan_objmgr_pdev *pdev,
159 					 uint8_t ch);
160 
161 /**
162  * reg_get_5g_bonded_channel() - get the 5G bonded channel state
163  * @pdev: Pointer to pdev structure
164  * @chan_num: channel number
165  * @ch_width: channel width
166  * @bonded_chan_ptr_ptr: bonded channel ptr ptr
167  *
168  * Return: channel state
169  */
170 enum channel_state reg_get_5g_bonded_channel(
171 		struct wlan_objmgr_pdev *pdev, uint8_t chan_num,
172 		enum phy_ch_width ch_width,
173 		const struct bonded_channel **bonded_chan_ptr_ptr);
174 
175 /**
176  * reg_get_5g_bonded_channel_state() - Get channel state for 5G bonded channel
177  * @pdev: Pointer to pdev
178  * @ch: channel number.
179  * @bw: channel band width
180  *
181  * Return: channel state
182  */
183 enum channel_state reg_get_5g_bonded_channel_state(
184 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
185 		enum phy_ch_width bw);
186 
187 /**
188  * reg_get_2g_bonded_channel_state() - Get channel state for 2G bonded channel
189  * @ch: channel number.
190  * @pdev: Pointer to pdev
191  * @oper_ch: Primary channel number
192  * @sec_ch: Secondary channel number
193  * @bw: channel band width
194  *
195  * Return: channel state
196  */
197 enum channel_state reg_get_2g_bonded_channel_state(
198 		struct wlan_objmgr_pdev *pdev, uint8_t oper_ch, uint8_t sec_ch,
199 		enum phy_ch_width bw);
200 
201 /**
202  * reg_set_channel_params () - Sets channel parameteres for given bandwidth
203  * @pdev: Pointer to pdev
204  * @ch: channel number.
205  * @sec_ch_2g: Secondary 2G channel
206  * @ch_params: pointer to the channel parameters.
207  *
208  * Return: None
209  */
210 void reg_set_channel_params(struct wlan_objmgr_pdev *pdev,
211 			    uint8_t ch, uint8_t sec_ch_2g,
212 			    struct ch_params *ch_params);
213 
214 /**
215  * reg_is_disable_ch() - Check if the given channel in disable state
216  * @pdev: Pointer to pdev
217  * @chan: channel number
218  *
219  * Return: True if channel state is disabled, else false
220  */
221 bool reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, uint8_t chan);
222 #endif /* CONFIG_CHAN_NUM_API */
223 
224 /**
225  * reg_read_default_country() - Get the default regulatory country
226  * @psoc: The physical SoC to get default country from
227  * @country_code: the buffer to populate the country code into
228  *
229  * Return: QDF_STATUS
230  */
231 QDF_STATUS reg_read_default_country(struct wlan_objmgr_psoc *psoc,
232 				    uint8_t *country_code);
233 
234 /**
235  * reg_get_ctry_idx_max_bw_from_country_code() - Get the max 5G bandwidth
236  * from country code
237  * @cc : Country Code
238  * @max_bw_5g : Max 5G bandwidth supported by the country
239  *
240  * Return : QDF_STATUS
241  */
242 
243 QDF_STATUS reg_get_max_5g_bw_from_country_code(uint16_t cc,
244 					       uint16_t *max_bw_5g);
245 
246 /**
247  * reg_get_max_5g_bw_from_regdomain() - Get the max 5G bandwidth
248  * supported by the regdomain
249  * @orig_regdmn : Regdomain pair value
250  * @max_bw_5g : Max 5G bandwidth supported by the country
251  *
252  * Return : QDF_STATUS
253  */
254 
255 QDF_STATUS reg_get_max_5g_bw_from_regdomain(uint16_t regdmn,
256 					    uint16_t *max_bw_5g);
257 
258 /**
259  * reg_get_current_dfs_region () - Get the current dfs region
260  * @pdev: Pointer to pdev
261  * @dfs_reg: pointer to dfs region
262  *
263  * Return: None
264  */
265 void reg_get_current_dfs_region(struct wlan_objmgr_pdev *pdev,
266 				enum dfs_reg *dfs_reg);
267 
268 #ifdef CONFIG_CHAN_NUM_API
269 /**
270  * reg_get_channel_reg_power() - Get the txpower for the given channel
271  * @pdev: Pointer to pdev
272  * @chan_num: Channel number
273  *
274  * Return: txpower
275  */
276 uint32_t reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev,
277 				   uint8_t chan_num);
278 
279 /**
280  * reg_get_channel_freq() - Get the channel frequency
281  * @pdev: Pointer to pdev
282  * @chan_num: Channel number
283  *
284  * Return: frequency
285  */
286 qdf_freq_t reg_get_channel_freq(struct wlan_objmgr_pdev *pdev,
287 				uint8_t chan_num);
288 #endif /* CONFIG_CHAN_NUM_API */
289 
290 /**
291  * reg_get_bw_value() - give bandwidth value
292  * bw: bandwidth enum
293  *
294  * Return: uint16_t
295  */
296 uint16_t reg_get_bw_value(enum phy_ch_width bw);
297 
298 /**
299  * reg_set_dfs_region () - Set the current dfs region
300  * @pdev: Pointer to pdev
301  * @dfs_reg: pointer to dfs region
302  *
303  * Return: None
304  */
305 void reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
306 			enum dfs_reg dfs_reg);
307 
308 #ifdef CONFIG_CHAN_NUM_API
309 /**
310  * reg_chan_to_band() - Get band from channel number
311  * @chan_num: channel number
312  *
313  * Return: band info
314  */
315 enum band_info reg_chan_to_band(uint8_t chan_num);
316 #endif /* CONFIG_CHAN_NUM_API */
317 
318 /**
319  * reg_program_chan_list() - Set user country code and populate the channel list
320  * @pdev: Pointer to pdev
321  * @rd: Pointer to cc_regdmn_s structure
322  *
323  * Return: QDF_STATUS
324  */
325 QDF_STATUS reg_program_chan_list(struct wlan_objmgr_pdev *pdev,
326 				 struct cc_regdmn_s *rd);
327 
328 #ifdef CONFIG_CHAN_NUM_API
329 /**
330  * reg_update_nol_ch () - Updates NOL channels in current channel list
331  * @pdev: pointer to pdev object
332  * @ch_list: pointer to NOL channel list
333  * @num_ch: No.of channels in list
334  * @update_nol: set/reset the NOL status
335  *
336  * Return: None
337  */
338 void reg_update_nol_ch(struct wlan_objmgr_pdev *pdev, uint8_t *chan_list,
339 		       uint8_t num_chan, bool nol_chan);
340 
341 /**
342  * reg_is_dfs_ch () - Checks the channel state for DFS
343  * @pdev: pdev ptr
344  * @chan: channel
345  *
346  * Return: true or false
347  */
348 bool reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, uint8_t chan);
349 #endif /* CONFIG_CHAN_NUM_API */
350 
351 /**
352  * reg_freq_to_chan() - Get channel number from frequency.
353  * @pdev: Pointer to pdev
354  * @freq: Channel frequency
355  *
356  * Return: Channel number if success, otherwise 0
357  */
358 uint8_t reg_freq_to_chan(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq);
359 
360 /**
361  * reg_chan_to_freq() - Get frequency from channel number
362  * @pdev: Pointer to pdev
363  * @chan_num: Channel number
364  *
365  * Return: Channel frequency if success, otherwise 0
366  */
367 qdf_freq_t reg_chan_to_freq(struct wlan_objmgr_pdev *pdev, uint8_t chan_num);
368 
369 /**
370  * reg_legacy_chan_to_freq() - Get freq from chan noumber, for 2G and 5G
371  * @pdev: Pointer to pdev
372  * @chan_num: Channel number
373  *
374  * Return: Channel frequency if success, otherwise 0
375  */
376 uint16_t reg_legacy_chan_to_freq(struct wlan_objmgr_pdev *pdev,
377 				 uint8_t chan_num);
378 
379 #ifdef CONFIG_CHAN_NUM_API
380 /**
381  * reg_chan_is_49ghz() - Check if the input channel number is 4.9GHz
382  * @pdev: Pdev pointer
383  * @chan_num: Input channel number
384  *
385  * Return: true if the channel is 4.9GHz else false.
386  */
387 bool reg_chan_is_49ghz(struct wlan_objmgr_pdev *pdev, uint8_t chan_num);
388 #endif /* CONFIG_CHAN_NUM_API */
389 
390 /**
391  * reg_program_default_cc() - Program default country code
392  * @pdev: Pdev pointer
393  * @regdmn: Regdomain value
394  *
395  * Return: QDF_STATUS
396  */
397 QDF_STATUS reg_program_default_cc(struct wlan_objmgr_pdev *pdev,
398 				  uint16_t regdmn);
399 
400 /**
401  * reg_get_current_cc() - Get current country code
402  * @pdev: Pdev pointer
403  * @regdmn: Pointer to get current country values
404  *
405  * Return: QDF_STATUS
406  */
407 QDF_STATUS reg_get_current_cc(struct wlan_objmgr_pdev *pdev,
408 			      struct cc_regdmn_s *rd);
409 
410 /**
411  * reg_set_regdb_offloaded() - set/clear regulatory offloaded flag
412  *
413  * @psoc: psoc pointer
414  * Return: Success or Failure
415  */
416 QDF_STATUS reg_set_regdb_offloaded(struct wlan_objmgr_psoc *psoc, bool val);
417 
418 /**
419  * reg_get_curr_regdomain() - Get current regdomain in use
420  * @pdev: pdev pointer
421  * @cur_regdmn: Current regdomain info
422  *
423  * Return: QDF status
424  */
425 QDF_STATUS reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
426 				  struct cur_regdmn_info *cur_regdmn);
427 
428 /**
429  * reg_modify_chan_144() - Enable/Disable channel 144
430  * @pdev: pdev pointer
431  * @en_chan_144: flag to disable/enable channel 144
432  *
433  * Return: Success or Failure
434  */
435 QDF_STATUS reg_modify_chan_144(struct wlan_objmgr_pdev *pdev, bool en_chan_144);
436 
437 /**
438  * reg_get_en_chan_144() - get en_chan_144 flag value
439  * @pdev: pdev pointer
440  *
441  * Return: en_chan_144 flag value
442  */
443 bool reg_get_en_chan_144(struct wlan_objmgr_pdev *pdev);
444 
445 /**
446  * reg_get_hal_reg_cap() - Get HAL REG capabilities
447  * @psoc: psoc for country information
448  *
449  * Return: hal reg cap pointer
450  */
451 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_get_hal_reg_cap(
452 		struct wlan_objmgr_psoc *psoc);
453 
454 /**
455  * reg_set_hal_reg_cap() - Set HAL REG capabilities
456  * @psoc: psoc for country information
457  * @reg_cap: Regulatory caps pointer
458  * @phy_cnt: number of phy
459  *
460  * Return: hal reg cap pointer
461  */
462 QDF_STATUS reg_set_hal_reg_cap(
463 		struct wlan_objmgr_psoc *psoc,
464 		struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap,
465 		uint16_t phy_cnt);
466 
467 /**
468  * reg_update_hal_reg_cap() - Update HAL REG capabilities
469  * @psoc: psoc pointer
470  * @wireless_modes: 11AX wireless modes
471  * @phy_id: phy id
472  *
473  * Return: QDF_STATUS
474  */
475 QDF_STATUS reg_update_hal_reg_cap(struct wlan_objmgr_psoc *psoc,
476 				  uint32_t wireless_modes, uint8_t phy_id);
477 
478 /**
479  * reg_chan_in_range() - Check if the given channel is in pdev's channel range
480  * @chan_list: Pointer to regulatory channel list.
481  * @low_freq_2g: Low frequency 2G.
482  * @high_freq_2g: High frequency 2G.
483  * @low_freq_5g: Low frequency 5G.
484  * @high_freq_5g: High frequency 5G.
485  * @ch_enum: Channel enum.
486  *
487  * Return: true if ch_enum is with in pdev's channel range, else false.
488  */
489 bool reg_chan_in_range(struct regulatory_channel *chan_list,
490 		       qdf_freq_t low_freq_2g, qdf_freq_t high_freq_2g,
491 		       qdf_freq_t low_freq_5g, qdf_freq_t high_freq_5g,
492 		       enum channel_enum ch_enum);
493 
494 /**
495  * reg_init_channel_map() - Initialize the channel list based on the dfs region.
496  * @dfs_region: Dfs region
497  */
498 void reg_init_channel_map(enum dfs_reg dfs_region);
499 
500 /**
501  * reg_get_psoc_tx_ops() - Get regdb tx ops
502  * @psoc: Pointer to psoc structure
503  */
504 struct wlan_lmac_if_reg_tx_ops *reg_get_psoc_tx_ops(
505 	struct wlan_objmgr_psoc *psoc);
506 
507 #ifdef CONFIG_CHAN_NUM_API
508 /**
509  * reg_update_nol_history_ch() - Set nol-history flag for the channels in the
510  * list.
511  * @pdev: Pdev ptr.
512  * @ch_list: Input channel list.
513  * @num_ch: Number of channels.
514  * @nol_history_ch: NOL-History flag.
515  *
516  * Return: void
517  */
518 void reg_update_nol_history_ch(struct wlan_objmgr_pdev *pdev,
519 			       uint8_t *chan_list,
520 			       uint8_t num_chan,
521 			       bool nol_history_chan);
522 
523 /**
524  * reg_is_24ghz_ch() - Check if the given channel number is 2.4GHz
525  * @chan: Channel number
526  *
527  * Return: true if channel number is 2.4GHz, else false
528  */
529 bool reg_is_24ghz_ch(uint32_t chan);
530 
531 /**
532  * reg_is_5ghz_ch() - Check if the given channel number is 5GHz
533  * @chan: Channel number
534  *
535  * Return: true if channel number is 5GHz, else false
536  */
537 bool reg_is_5ghz_ch(uint32_t chan);
538 #endif /* CONFIG_CHAN_NUM_API */
539 
540 /**
541  * reg_is_24ghz_ch_freq() - Check if the given channel frequency is 2.4GHz
542  * @freq: Channel frequency
543  *
544  * Return: true if channel frequency is 2.4GHz, else false
545  */
546 bool reg_is_24ghz_ch_freq(uint32_t freq);
547 
548 /**
549  * reg_is_5ghz_ch_freq() - Check if the given channel frequency is 5GHz
550  * @freq: Channel frequency
551  *
552  * Return: true if channel frequency is 5GHz, else false
553  */
554 bool reg_is_5ghz_ch_freq(uint32_t freq);
555 
556 #ifdef CONFIG_BAND_6GHZ
557 /**
558  * reg_is_6ghz_chan_freq() - Check if the given channel frequency is 6GHz
559  * @freq: Channel frequency
560  *
561  * Return: true if channel frequency is 6GHz, else false
562  */
563 bool reg_is_6ghz_chan_freq(uint16_t freq);
564 
565 #ifdef CONFIG_6G_FREQ_OVERLAP
566 /**
567  * reg_is_range_only6g() - Check if the given low_freq and high_freq is in
568  * the 6G range.
569  *
570  * @low_freq - Low frequency.
571  * @high_freq - High frequency.
572  *
573  * Return: Return true if given low_freq and high_freq overlaps 6G range,
574  * else false.
575  */
576 bool reg_is_range_only6g(qdf_freq_t low_freq, qdf_freq_t high_freq);
577 #endif
578 
579 /**
580  * REG_IS_6GHZ_FREQ() - Check if the given channel frequency is 6GHz
581  * @freq: Channel frequency
582  *
583  * Return: true if channel frequency is 6GHz, else false
584  */
585 static inline bool REG_IS_6GHZ_FREQ(uint16_t freq)
586 {
587 	return ((freq >= REG_MIN_6GHZ_CHAN_FREQ) &&
588 		(freq <= REG_MAX_6GHZ_CHAN_FREQ));
589 }
590 
591 /**
592  * reg_is_6ghz_psc_chan_freq() - Check if the given 6GHz channel frequency is
593  * preferred scanning channel frequency.
594  * @freq: Channel frequency
595  *
596  * Return: true if given 6GHz channel frequency is preferred scanning channel
597  * frequency, else false
598  */
599 bool reg_is_6ghz_psc_chan_freq(uint16_t freq);
600 
601 /**
602  * reg_is_6g_freq_indoor() - Check if a 6GHz frequency is indoor.
603  * @pdev: Pointer to pdev.
604  * @freq: Channel frequency.
605  *
606  * Return: Return true if a 6GHz frequency is indoor, else false.
607  */
608 bool reg_is_6g_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq);
609 
610 /**
611  * reg_min_6ghz_chan_freq() - Get minimum 6GHz channel center frequency
612  *
613  * Return: Minimum 6GHz channel center frequency
614  */
615 uint16_t reg_min_6ghz_chan_freq(void);
616 
617 /**
618  * reg_max_6ghz_chan_freq() - Get maximum 6GHz channel center frequency
619  *
620  * Return: Maximum 6GHz channel center frequency
621  */
622 uint16_t reg_max_6ghz_chan_freq(void);
623 #else
624 static inline bool reg_is_6ghz_chan_freq(uint16_t freq)
625 {
626 	return false;
627 }
628 
629 static inline bool
630 reg_is_6g_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
631 {
632 	return false;
633 }
634 
635 #ifdef CONFIG_6G_FREQ_OVERLAP
636 static inline bool reg_is_range_only6g(qdf_freq_t low_freq,
637 				       qdf_freq_t high_freq)
638 {
639 	return false;
640 }
641 #endif
642 
643 static inline bool REG_IS_6GHZ_FREQ(uint16_t freq)
644 {
645 	return false;
646 }
647 
648 static inline bool reg_is_6ghz_psc_chan_freq(uint16_t freq)
649 {
650 	return false;
651 }
652 
653 static inline uint16_t reg_min_6ghz_chan_freq(void)
654 {
655 	return 0;
656 }
657 
658 static inline uint16_t reg_max_6ghz_chan_freq(void)
659 {
660 	return 0;
661 }
662 #endif /* CONFIG_BAND_6GHZ */
663 
664 /**
665  * reg_get_band_channel_list() - Get the channel list and number of channels
666  * @pdev: pdev ptr
667  * @band_mask: Input bitmap with band set
668  * @channel_list: Pointer to Channel List
669  *
670  * Get the given channel list and number of channels from the current channel
671  * list based on input band bitmap.
672  *
673  * Return: Number of channels, else 0 to indicate error
674  */
675 uint16_t reg_get_band_channel_list(struct wlan_objmgr_pdev *pdev,
676 				   uint8_t band_mask,
677 				   struct regulatory_channel *channel_list);
678 
679 /**
680  * reg_chan_band_to_freq - Return channel frequency based on the channel number
681  * and band.
682  * @pdev: pdev ptr
683  * @chan: Channel Number
684  * @band_mask: Bitmap for bands
685  *
686  * Return: Return channel frequency or return 0, if the channel is disabled or
687  * if the input channel number or band_mask is invalid. Composite bands are
688  * supported only for 2.4Ghz and 5Ghz bands. For other bands the following
689  * priority is given: 1) 6Ghz 2) 5Ghz 3) 2.4Ghz.
690  */
691 qdf_freq_t reg_chan_band_to_freq(struct wlan_objmgr_pdev *pdev,
692 				 uint8_t chan,
693 				 uint8_t band_mask);
694 
695 /**
696  * reg_is_49ghz_freq() - Check if the given channel frequency is 4.9GHz
697  * @freq: Channel frequency
698  *
699  * Return: true if channel frequency is 4.9GHz, else false
700  */
701 bool reg_is_49ghz_freq(qdf_freq_t freq);
702 
703 /**
704  * reg_ch_num() - Get channel number from channel enum
705  * @ch_enum: Channel enum
706  *
707  * Return: channel number
708  */
709 qdf_freq_t reg_ch_num(uint32_t ch_enum);
710 
711 /**
712  * reg_ch_to_freq() - Get channel frequency from channel enum
713  * @ch_enum: Channel enum
714  *
715  * Return: channel frequency
716  */
717 qdf_freq_t reg_ch_to_freq(uint32_t ch_enum);
718 
719 #ifdef CONFIG_CHAN_NUM_API
720 /**
721  * reg_is_same_band_channels() - Check if given channel numbers have same band
722  * @chan_num1: Channel number1
723  * @chan_num2: Channel number2
724  *
725  * Return: true if both the channels has the same band.
726  */
727 bool reg_is_same_band_channels(uint8_t chan_num1, uint8_t chan_num2);
728 
729 /**
730  * reg_is_channel_valid_5g_sbs() Check if the given channel is 5G SBS.
731  * @curchan: current channel
732  * @newchan:new channel
733  *
734  * Return: true if the given channel is a valid 5G SBS
735  */
736 bool reg_is_channel_valid_5g_sbs(uint8_t curchan, uint8_t newchan);
737 
738 /**
739  * reg_min_24ghz_ch_num() - Get minimum 2.4GHz channel number
740  *
741  * Return: Minimum 2.4GHz channel number
742  */
743 uint8_t reg_min_24ghz_ch_num(void);
744 
745 /**
746  * reg_max_24ghz_ch_num() - Get maximum 2.4GHz channel number
747  *
748  * Return: Maximum 2.4GHz channel number
749  */
750 uint8_t reg_max_24ghz_ch_num(void);
751 
752 /**
753  * reg_min_5ghz_ch_num() - Get minimum 5GHz channel number
754  *
755  * Return: Minimum 5GHz channel number
756  */
757 uint8_t reg_min_5ghz_ch_num(void);
758 
759 /**
760  * reg_max_5ghz_ch_num() - Get maximum 5GHz channel number
761  *
762  * Return: Maximum 5GHz channel number
763  */
764 uint8_t reg_max_5ghz_ch_num(void);
765 #endif /* CONFIG_CHAN_NUM_API */
766 
767 #ifdef CONFIG_CHAN_FREQ_API
768 /**
769  * reg_min_24ghz_chan_freq() - Get minimum 2.4GHz channel frequency
770  *
771  * Return: Minimum 2.4GHz channel frequency
772  */
773 qdf_freq_t reg_min_24ghz_chan_freq(void);
774 
775 /**
776  * reg_max_24ghz_chan_freq() - Get maximum 2.4GHz channel frequency
777  *
778  * Return: Maximum 2.4GHz channel frequency
779  */
780 qdf_freq_t reg_max_24ghz_chan_freq(void);
781 
782 /**
783  * reg_min_5ghz_chan_freq() - Get minimum 5GHz channel frequency
784  *
785  * Return: Minimum 5GHz channel frequency
786  */
787 qdf_freq_t reg_min_5ghz_chan_freq(void);
788 
789 /**
790  * reg_max_5ghz_chan_freq() - Get maximum 5GHz channel frequency
791  *
792  * Return: Maximum 5GHz channel frequency
793  */
794 qdf_freq_t reg_max_5ghz_chan_freq(void);
795 #endif /* CONFIG_CHAN_FREQ_API */
796 
797 /**
798  * reg_enable_dfs_channels() - Enable the use of DFS channels
799  * @pdev: The physical dev to enable/disable DFS channels for
800  *
801  * Return: QDF_STATUS
802  */
803 QDF_STATUS reg_enable_dfs_channels(struct wlan_objmgr_pdev *pdev, bool enable);
804 
805 /**
806  * reg_is_regdmn_en302502_applicable() - Find if ETSI EN302_502 radar pattern
807  * is applicable in current regulatory domain.
808  * @pdev: Pdev object pointer.
809  *
810  * Return: True if en302_502 is applicable, else false.
811  */
812 bool reg_is_regdmn_en302502_applicable(struct wlan_objmgr_pdev *pdev);
813 
814 /**
815  * reg_modify_pdev_chan_range() - Compute current channel list
816  * in accordance with the modified reg caps.
817  * @pdev: The physical dev for which channel list must be built.
818  *
819  * Return: QDF_STATUS
820  */
821 QDF_STATUS reg_modify_pdev_chan_range(struct wlan_objmgr_pdev *pdev);
822 
823 /**
824  * reg_update_pdev_wireless_modes() - Update the wireless_modes in the
825  * pdev_priv_obj with the input wireless_modes
826  * @pdev: pointer to wlan_objmgr_pdev.
827  * @wireless_modes: Wireless modes.
828  *
829  * Return : QDF_STATUS
830  */
831 QDF_STATUS reg_update_pdev_wireless_modes(struct wlan_objmgr_pdev *pdev,
832 					  uint32_t wireless_modes);
833 
834 /**
835  * reg_get_phybitmap() - Get phybitmap from regulatory pdev_priv_obj
836  * @pdev: pdev pointer
837  * @phybitmap: pointer to phybitmap
838  *
839  * Return: QDF STATUS
840  */
841 QDF_STATUS reg_get_phybitmap(struct wlan_objmgr_pdev *pdev,
842 			     uint16_t *phybitmap);
843 #ifdef DISABLE_UNII_SHARED_BANDS
844 /**
845  * reg_disable_chan_coex() - Disable Coexisting channels based on the input
846  * bitmask.
847  * @pdev: pointer to wlan_objmgr_pdev.
848  * unii_5g_bitmap: UNII 5G bitmap.
849  *
850  * Return : QDF_STATUS
851  */
852 QDF_STATUS reg_disable_chan_coex(struct wlan_objmgr_pdev *pdev,
853 				 uint8_t unii_5g_bitmap);
854 #endif
855 
856 #ifdef CONFIG_CHAN_FREQ_API
857 /**
858  * reg_is_freq_present_in_cur_chan_list() - Check the input frequency
859  * @pdev: Pointer to pdev
860  * @freq: Channel center frequency in MHz
861  *
862  * Check if the input channel center frequency is present in the current
863  * channel list
864  *
865  * Return: Return true if channel center frequency is present in the current
866  * channel list, else return false.
867  */
868 bool
869 reg_is_freq_present_in_cur_chan_list(struct wlan_objmgr_pdev *pdev,
870 				     qdf_freq_t freq);
871 
872 /**
873  * reg_get_chan_enum_for_freq() - Get channel enum for given channel frequency
874  * @freq: Channel Frequency
875  *
876  * Return: Channel enum
877  */
878 enum channel_enum reg_get_chan_enum_for_freq(qdf_freq_t freq);
879 
880 /**
881  * reg_get_channel_list_with_power_for_freq() - Provides the channel list with
882  * power
883  * @pdev: Pointer to pdev
884  * @ch_list: Pointer to the channel list.
885  * @num_chan: Pointer to save number of channels
886  *
887  * Return: QDF_STATUS
888  */
889 QDF_STATUS
890 reg_get_channel_list_with_power_for_freq(struct wlan_objmgr_pdev *pdev,
891 					 struct channel_power *ch_list,
892 					 uint8_t *num_chan);
893 
894 /**
895  * reg_get_channel_state_for_freq() - Get channel state from regulatory
896  * @pdev: Pointer to pdev
897  * @freq: channel center frequency.
898  *
899  * Return: channel state
900  */
901 enum channel_state reg_get_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
902 						  qdf_freq_t freq);
903 
904 /**
905  * reg_get_5g_bonded_channel_state_for_freq() - Get channel state for
906  * 5G bonded channel using the channel frequency
907  * @pdev: Pointer to pdev
908  * @freq: channel center frequency.
909  * @bw: channel band width
910  *
911  * Return: channel state
912  */
913 enum channel_state
914 reg_get_5g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
915 					 qdf_freq_t freq,
916 					 enum phy_ch_width bw);
917 
918 /**
919  * reg_get_2g_bonded_channel_state_for_freq() - Get channel state for 2G
920  * bonded channel
921  * @freq: channel center frequency.
922  * @pdev: Pointer to pdev
923  * @oper_ch_freq: Primary channel center frequency
924  * @sec_ch_freq: Secondary channel center frequency
925  * @bw: channel band width
926  *
927  * Return: channel state
928  */
929 enum channel_state
930 reg_get_2g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
931 					 qdf_freq_t oper_ch_freq,
932 					 qdf_freq_t sec_ch_freq,
933 					 enum phy_ch_width bw);
934 
935 /**
936  * reg_set_channel_params_for_freq () - Sets channel parameteres for given
937  * bandwidth
938  * @pdev: Pointer to pdev
939  * @freq: Channel center frequency.
940  * @sec_ch_2g_freq: Secondary 2G channel frequency
941  * @ch_params: pointer to the channel parameters.
942  *
943  * Return: None
944  */
945 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
946 				     qdf_freq_t freq,
947 				     qdf_freq_t sec_ch_2g_freq,
948 				     struct ch_params *ch_params);
949 
950 /**
951  * reg_get_channel_reg_power_for_freq() - Get the txpower for the given channel
952  * @pdev: Pointer to pdev
953  * @freq: Channel frequency
954  *
955  * Return: txpower
956  */
957 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev,
958 					   qdf_freq_t freq);
959 
960 /**
961  * reg_update_nol_ch_for_freq () - Updates NOL channels in current channel list
962  * @pdev: pointer to pdev object
963  * @chan_freq_list: pointer to NOL channel list
964  * @num_ch: No.of channels in list
965  * @update_nol: set/reset the NOL status
966  *
967  * Return: None
968  */
969 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev,
970 				uint16_t *chan_freq_list,
971 				uint8_t num_chan,
972 				bool nol_chan);
973 /**
974  * reg_is_dfs_for_freq () - Checks the channel state for DFS
975  * @pdev: pdev ptr
976  * @freq: Channel center frequency
977  *
978  * Return: true or false
979  */
980 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq);
981 
982 /**
983  * reg_chan_freq_is_49ghz() - Check if the input channel center frequency is
984  * 4.9GHz
985  * @pdev: Pdev pointer
986  * @chan_num: Input channel center frequency
987  *
988  * Return: true if the frequency is 4.9GHz else false.
989  */
990 bool reg_chan_freq_is_49ghz(qdf_freq_t freq);
991 
992 /**
993  * reg_update_nol_history_ch_for_freq() - Set nol-history flag for the channels
994  * in the list.
995  * @pdev: Pdev ptr.
996  * @chan_list: Input channel freqeuncy list.
997  * @num_ch: Number of channels.
998  * @nol_history_ch: NOL-History flag.
999  *
1000  * Return: void
1001  */
1002 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev,
1003 					uint16_t *chan_list,
1004 					uint8_t num_chan,
1005 					bool nol_history_chan);
1006 
1007 /**
1008  * reg_is_same_5g_band_freqs() - Check if given channel center
1009  * frequencies have same band
1010  * @freq1: Channel Center Frequency 1
1011  * @freq2: Channel Center Frequency 2
1012  *
1013  * Return: true if both the frequencies has the same band.
1014  */
1015 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2);
1016 
1017 /**
1018  * reg_is_frequency_valid_5g_sbs() Check if the given frequency is 5G SBS.
1019  * @curfreq: current channel frequency
1020  * @newfreq: new channel center frequency
1021  *
1022  * Return: true if the given center frequency is a valid 5G SBS
1023  */
1024 bool reg_is_frequency_valid_5g_sbs(qdf_freq_t curfreq, qdf_freq_t newfreq);
1025 
1026 /**
1027  * reg_freq_to_band() - Get band from channel frequency
1028  * @chan_num: channel frequency
1029  *
1030  * Return: wifi band
1031  */
1032 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq);
1033 
1034 /**
1035  * reg_min_chan_freq() - minimum channel frequency supported
1036  *
1037  * Return: channel frequency
1038  */
1039 qdf_freq_t reg_min_chan_freq(void);
1040 
1041 /**
1042  * reg_max_chan_freq() - maximum channel frequency supported
1043  *
1044  * Return: channel frequency
1045  */
1046 qdf_freq_t reg_max_chan_freq(void);
1047 
1048 /**
1049  * reg_get_5g_bonded_channel_for_freq()- Return the channel state for a
1050  * 5G or 6G channel frequency based on the channel width and bonded channel
1051  * @pdev: Pointer to pdev.
1052  * @freq: Channel center frequency.
1053  * @ch_width: Channel Width.
1054  * @bonded_chan_ptr_ptr: Pointer to bonded_channel_freq.
1055  *
1056  * Return: Channel State
1057  */
1058 enum channel_state
1059 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev,
1060 				   uint16_t freq,
1061 				   enum phy_ch_width ch_width,
1062 				   const struct bonded_channel_freq
1063 				   **bonded_chan_ptr_ptr);
1064 
1065 /**
1066  * reg_is_disable_for_freq() - Check if the given channel frequency in
1067  * disable state
1068  * @pdev: Pointer to pdev
1069  * @freq: Channel frequency
1070  *
1071  * Return: True if channel state is disabled, else false
1072  */
1073 bool reg_is_disable_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq);
1074 #endif /* CONFIG_CHAN_FREQ_API */
1075 
1076 /**
1077  * reg_get_max_tx_power() - Get maximum tx power from the current channel list
1078  * @pdev: Pointer to pdev
1079  *
1080  * Return: return the value of the maximum tx power in the current channel list
1081  *
1082  */
1083 uint8_t reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev);
1084 
1085 /**
1086  * reg_set_ignore_fw_reg_offload_ind() - Set if regdb offload indication
1087  * needs to be ignored
1088  * @psoc: Pointer to psoc
1089  *
1090  * Return: QDF_STATUS
1091  */
1092 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc);
1093 
1094 /**
1095  * reg_get_ignore_fw_reg_offload_ind() - Check whether regdb offload indication
1096  * needs to be ignored
1097  *
1098  * @psoc: Pointer to psoc
1099  */
1100 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc);
1101 
1102 /**
1103  * reg_set_6ghz_supported() - Set if 6ghz is supported
1104  *
1105  * @psoc: Pointer to psoc
1106  * @val: value
1107  */
1108 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc,
1109 				  bool val);
1110 
1111 /**
1112  * reg_set_5dot9_ghz_supported() - Set if 5.9ghz is supported
1113  *
1114  * @psoc: Pointer to psoc
1115  * @val: value
1116  */
1117 QDF_STATUS reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc,
1118 				       bool val);
1119 
1120 /**
1121  * reg_is_6ghz_op_class() - Check whether 6ghz oper class
1122  *
1123  * @pdev: Pointer to pdev
1124  * @op_class: oper class
1125  */
1126 bool reg_is_6ghz_op_class(struct wlan_objmgr_pdev *pdev,
1127 			  uint8_t op_class);
1128 
1129 #ifdef CONFIG_REG_CLIENT
1130 /**
1131  * reg_is_6ghz_supported() - Whether 6ghz is supported
1132  *
1133  * @psoc: pointer to psoc
1134  */
1135 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc);
1136 #endif
1137 
1138 /**
1139  * reg_is_5dot9_ghz_supported() - Whether 5.9ghz is supported
1140  *
1141  * @psoc: pointer to psoc
1142  */
1143 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc);
1144 
1145 /**
1146  * reg_is_fcc_regdmn () - Checks if the current reg domain is FCC3/FCC8/FCC15/
1147  * FCC16 or not
1148  * @pdev: pdev ptr
1149  *
1150  * Return: true or false
1151  */
1152 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev);
1153 
1154 /**
1155  * reg_is_5dot9_ghz_freq () - Checks if the frequency is 5.9 GHz freq or not
1156  * @freq: frequency
1157  * @pdev: pdev ptr
1158  *
1159  * Return: true or false
1160  */
1161 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq);
1162 
1163 /**
1164  * reg_is_5dot9_ghz_chan_allowed_master_mode () - Checks if 5.9 GHz channels
1165  * are allowed in master mode or not.
1166  *
1167  * @pdev: pdev ptr
1168  *
1169  * Return: true or false
1170  */
1171 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev);
1172 
1173 /**
1174  * reg_get_unii_5g_bitmap() - get unii_5g_bitmap value
1175  * @pdev: pdev pointer
1176  * @bitmap: Pointer to retrieve the unii_5g_bitmap of enum reg_unii_band
1177  *
1178  * Return: QDF_STATUS
1179  */
1180 #ifdef DISABLE_UNII_SHARED_BANDS
1181 QDF_STATUS
1182 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap);
1183 #endif
1184 
1185 #ifdef CHECK_REG_PHYMODE
1186 /**
1187  * reg_get_max_phymode() - Recursively find the best possible phymode given a
1188  * phymode, a frequency, and per-country regulations
1189  * @pdev: pdev pointer
1190  * @phy_in: phymode that the user requested
1191  * @freq: current operating center frequency
1192  *
1193  * Return: maximum phymode allowed in current country that is <= phy_in
1194  */
1195 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev,
1196 				     enum reg_phymode phy_in,
1197 				     qdf_freq_t freq);
1198 #else
1199 static inline enum reg_phymode
1200 reg_get_max_phymode(struct wlan_objmgr_pdev *pdev,
1201 		    enum reg_phymode phy_in,
1202 		    qdf_freq_t freq)
1203 {
1204 	return REG_PHYMODE_INVALID;
1205 }
1206 #endif /* CHECK_REG_PHYMODE */
1207 
1208 #ifdef CONFIG_REG_CLIENT
1209 /**
1210  * reg_band_bitmap_to_band_info() - Convert the band_bitmap to a band_info enum.
1211  *	Since band_info enum only has combinations for 2G and 5G, 6G is not
1212  *	considered in this function.
1213  * @band_bitmap: bitmap on top of reg_wifi_band of bands enabled
1214  *
1215  * Return: BAND_ALL if both 2G and 5G band is enabled
1216  *	BAND_2G if 2G is enabled but 5G isn't
1217  *	BAND_5G if 5G is enabled but 2G isn't
1218  */
1219 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap);
1220 #endif
1221 
1222 #endif
1223