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