xref: /wlan-driver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_build_chan_list.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  *
6  * Permission to use, copy, modify, and/or distribute this software for
7  * any purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18  * PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 /**
22  * DOC: reg_build_chan_list.h
23  * This file provides prototypes of the regulatory component to build master
24  * and current channel list.
25  */
26 
27 #ifndef __REG_BUILD_CHAN_LIST_H__
28 #define __REG_BUILD_CHAN_LIST_H__
29 
30 #define CHAN_12_CENT_FREQ 2467
31 #define CHAN_13_CENT_FREQ 2472
32 
33 #ifdef WLAN_FEATURE_11BE
34 #define REG_MAX_20M_SUB_CH 16
35 #else
36 #define REG_MAX_20M_SUB_CH  8
37 #endif
38 
39 #ifdef CONFIG_AFC_SUPPORT
40 #define MIN_AFC_BW 2
41 #ifdef WLAN_FEATURE_11BE
42 #define AFC_BW_320 320
43 #endif
44 #define AFC_BW_160 160
45 #endif
46 
47 #define HALF_IEEE_CH_SEP  2
48 #define IEEE_20MHZ_CH_SEP 4
49 
50 /* Check if the freq lies within low_freq and high_freq (both inclusive) */
51 #define IS_WITHIN_RANGE_ASYM(_freq, _low_freq, _high_freq)\
52 	(((_freq) >= (_low_freq) && (_freq) <= (_high_freq)))
53 
54 #include "reg_priv_objs.h"
55 /**
56  * reg_reset_reg_rules() - provides the reg domain rules info
57  * @reg_rules: reg rules pointer
58  *
59  * Return: None
60  */
61 void reg_reset_reg_rules(struct reg_rule_info *reg_rules);
62 
63 /**
64  * reg_init_pdev_mas_chan_list() - Initialize pdev master channel list
65  * @pdev_priv_obj: Pointer to regdb pdev private object.
66  * @mas_chan_params: Master channel params.
67  */
68 void reg_init_pdev_mas_chan_list(
69 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
70 		struct mas_chan_params *mas_chan_params);
71 
72 /**
73  * reg_save_reg_rules_to_pdev() - Save psoc reg-rules to pdev.
74  * @psoc_reg_rules: reg rules pointer
75  * @pdev_priv_obj: Pointer to regdb pdev private object.
76  */
77 void reg_save_reg_rules_to_pdev(
78 		struct reg_rule_info *psoc_reg_rules,
79 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj);
80 
81 /**
82  * reg_compute_pdev_current_chan_list() - Compute pdev current channel list.
83  * @pdev_priv_obj: Pointer to regdb pdev private object.
84  */
85 void reg_compute_pdev_current_chan_list(
86 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj);
87 
88 /**
89  * reg_propagate_mas_chan_list_to_pdev() - Propagate master channel list to pdev
90  * @psoc: Pointer to psoc object.
91  * @object: Void pointer to pdev object.
92  * @arg: Pointer to direction.
93  */
94 void reg_propagate_mas_chan_list_to_pdev(struct wlan_objmgr_psoc *psoc,
95 					 void *object, void *arg);
96 
97 #ifdef CONFIG_BAND_6GHZ
98 /**
99  * reg_process_master_chan_list_ext() - Compute master channel extended list
100  * based on the regulatory rules.
101  * @reg_info: Pointer to regulatory info
102  *
103  * Return: QDF_STATUS
104  */
105 QDF_STATUS
106 reg_process_master_chan_list_ext(struct cur_regulatory_info *reg_info);
107 
108 /**
109  * reg_get_6g_ap_master_chan_list() - Get a pdev's ap master channel
110  *                                    list depending on ap power type
111  * @pdev: pdev object
112  * @ap_pwr_type: Power type (LPI/VLP/SP)
113  * @chan_list: Pointer to the channel list. The output channel list
114  *
115  * Return: QDF_STATUS
116  */
117 QDF_STATUS reg_get_6g_ap_master_chan_list(struct wlan_objmgr_pdev *pdev,
118 					  enum reg_6g_ap_type ap_pwr_type,
119 					  struct regulatory_channel *chan_list);
120 
121 /**
122  * reg_get_reg_maschan_lst_frm_6g_pwr_mode() - Return the mas_chan_list entry
123  * for based on the channel index and input power mode
124  * @supp_pwr_mode: 6G supported power mode
125  * @pdev_priv_obj: Pointer to pdev_priv_obj
126  * @chan_idx: Channel index
127  *
128  * Return: Pointer to struct regulatory_channel
129  */
130 struct regulatory_channel *reg_get_reg_maschan_lst_frm_6g_pwr_mode(
131 			enum supported_6g_pwr_types supp_pwr_mode,
132 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
133 			uint16_t chan_idx);
134 
135 /**
136  * reg_convert_supported_6g_pwr_type_to_ap_pwr_type() - The supported 6G power
137  * type is a combination of AP and client power types. This API return the 6G AP
138  * power type portion of the supported 6G power type.
139  * @in_6g_pwr_type: input 6G supported power type.
140  *
141  * Return: 6G AP power type.
142  */
143 enum reg_6g_ap_type
144 reg_convert_supported_6g_pwr_type_to_ap_pwr_type(enum supported_6g_pwr_types
145 						in_6g_pwr_type);
146 
147 #ifdef CONFIG_REG_CLIENT
148 /**
149  * reg_get_power_string() - get power string from power enum type
150  * @power_type: power type enum value
151  *
152  * Return: power type string
153  */
154 const char *reg_get_power_string(enum reg_6g_ap_type power_type);
155 #endif
156 
157 #ifdef CONFIG_AFC_SUPPORT
158 /**
159  * reg_process_afc_event() - Process the afc event and compute the 6 GHz AFC
160  * channel list based on the frequency range and channel frequency indices set.
161  * @afc_info: Pointer to AFC regulatory info
162  *
163  * Return: QDF_STATUS
164  */
165 QDF_STATUS
166 reg_process_afc_event(struct afc_regulatory_info *afc_info);
167 
168 /**
169  * reg_get_subchannels_for_opclass() - Get the list of subchannels based on the
170  * the channel frequency index and opclass.
171  * @cfi: Channel frequency index
172  * @opclass: Operating class
173  * @subchannels: Pointer to list of subchannels
174  *
175  * Return: void
176  */
177 uint8_t reg_get_subchannels_for_opclass(uint8_t cfi,
178 					uint8_t opclass,
179 					uint8_t *subchannels);
180 #endif
181 
182 /**
183  * reg_psd_2_eirp() - Calculate EIRP from PSD and bandwidth
184  * channel list
185  * @pdev: pdev pointer
186  * @psd: Power Spectral Density in dBm/MHz
187  * @ch_bw: Bandwdith of a channel in MHz (20/40/80/160/320 etc)
188  * @eirp:  EIRP power  in dBm
189  *
190  * Return: QDF_STATUS
191  */
192 QDF_STATUS reg_psd_2_eirp(struct wlan_objmgr_pdev *pdev,
193 			  int16_t psd,
194 			  uint16_t ch_bw,
195 			  int16_t *eirp);
196 
197 /**
198  * reg_eirp_2_psd() - Calculate PSD from EIRP and bandwidth
199  * channel list
200  * @pdev: pdev pointer
201  * @ch_bw: Bandwdith of a channel in MHz (20/40/80/160/320 etc)
202  * @eirp:  EIRP power  in dBm
203  * @psd: Power Spectral Density in dBm/MHz
204  *
205  * Return: QDF_STATUS
206  */
207 QDF_STATUS reg_eirp_2_psd(struct wlan_objmgr_pdev *pdev,
208 			  uint16_t ch_bw,
209 			  int16_t eirp,
210 			  int16_t *psd);
211 
212 /**
213  * reg_is_supp_pwr_mode_invalid() - Is 6 GHz power mode invalid
214  * @supp_pwr_mode: 6 GHz power mode to test
215  *
216  * Indicates if the given 6G power mode is one of the valid power
217  * modes enumerated by enum supported_6g_pwr_types from REG_AP_LPI to
218  * REG_CLI_SUB_VLP.
219  *
220  * Note: REG_BEST_PWR_MODE and REG_CURRENT_PWR_MODE are not valid 6 GHz power
221  * modes.
222  *
223  * Return: True for any valid power mode from REG_AP_LPI tp REG_CLI_SUB_VLP.
224  * False otherwise.
225  */
226 static inline bool
reg_is_supp_pwr_mode_invalid(enum supported_6g_pwr_types supp_pwr_mode)227 reg_is_supp_pwr_mode_invalid(enum supported_6g_pwr_types supp_pwr_mode)
228 {
229 	return (supp_pwr_mode < REG_AP_LPI || supp_pwr_mode > REG_CLI_SUB_VLP);
230 }
231 
232 /**
233  * reg_copy_from_super_chan_info_to_reg_channel() - Copy the structure
234  * fields from a super channel entry to the regulatory channel fields.
235  *
236  * @chan: Pointer to the regulatory channel where the fields of super channel
237  * entry is copied to.
238  * @sc_entry: Input super channel entry whose fields are copied to the
239  * regulatory channel structure.
240  * @in_6g_pwr_mode: Input 6g power type. If the power type is best power mode,
241  * get the best power mode of the given super channel entry and copy its
242  * information to the regulatory channel fields.
243  */
244 void
245 reg_copy_from_super_chan_info_to_reg_channel(struct regulatory_channel *chan,
246 					     const struct super_chan_info sc_entry,
247 					     enum supported_6g_pwr_types
248 					     in_6g_pwr_mode);
249 
250 /**
251  * reg_set_ap_pwr_type() - Set the AP power type.
252  * @pdev_priv_obj: pdev private object
253  *
254  * Set the AP power type as per AFC device deployment if AFC is available.
255  * Otherwise set it to indoor by default.
256  *
257  * Return: None
258  */
259 void reg_set_ap_pwr_type(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj);
260 
261 /**
262  * reg_get_6g_pwrmode_chan_list() - Get the modified channel list. The modified
263  * current channel list consists of 2G and 5G portions of the current channel
264  * list and the 6G portion of the current channel list is derived from the input
265  * 6g power type.
266  * @pdev_priv_obj: Pointer to pdev private object.
267  * @chan_list: channel list pointer
268  * @in_6g_pwr_mode: Input 6GHz power mode.
269  *
270  * Return:
271  * QDF_STATUS_SUCCESS: Success
272  * QDF_STATUS_E_INVAL: Failed to get channel list
273  */
274 QDF_STATUS
275 reg_get_6g_pwrmode_chan_list(struct wlan_regulatory_pdev_priv_obj
276 			     *pdev_priv_obj,
277 			     struct regulatory_channel *chan_list,
278 			     enum supported_6g_pwr_types in_6g_pwr_mode);
279 #else /* CONFIG_BAND_6GHZ */
280 static inline QDF_STATUS
reg_get_6g_ap_master_chan_list(struct wlan_objmgr_pdev * pdev,enum reg_6g_ap_type ap_pwr_type,struct regulatory_channel * chan_list)281 reg_get_6g_ap_master_chan_list(struct wlan_objmgr_pdev *pdev,
282 			       enum reg_6g_ap_type ap_pwr_type,
283 			       struct regulatory_channel *chan_list)
284 {
285 	return QDF_STATUS_E_FAILURE;
286 }
287 
288 static inline
reg_get_reg_maschan_lst_frm_6g_pwr_mode(enum supported_6g_pwr_types supp_pwr_mode,struct wlan_regulatory_pdev_priv_obj * pdev_priv_obj,uint16_t chan_idx)289 struct regulatory_channel *reg_get_reg_maschan_lst_frm_6g_pwr_mode(
290 			enum supported_6g_pwr_types supp_pwr_mode,
291 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
292 			uint16_t chan_idx)
293 {
294 	return NULL;
295 }
296 
297 static inline uint8_t
reg_get_subchannels_for_opclass(uint8_t cfi,uint8_t opclass,uint8_t * subchannels)298 reg_get_subchannels_for_opclass(uint8_t cfi,
299 				uint8_t opclass,
300 				uint8_t *subchannels)
301 {
302 	return 0;
303 }
304 
reg_psd_2_eirp(struct wlan_objmgr_pdev * pdev,int16_t psd,uint16_t ch_bw,int16_t * eirp)305 static inline QDF_STATUS reg_psd_2_eirp(struct wlan_objmgr_pdev *pdev,
306 					int16_t psd,
307 					uint16_t ch_bw,
308 					int16_t *eirp)
309 {
310 	return QDF_STATUS_E_FAILURE;
311 }
312 
reg_eirp_2_psd(struct wlan_objmgr_pdev * pdev,uint16_t ch_bw,int16_t eirp,int16_t * psd)313 static inline QDF_STATUS reg_eirp_2_psd(struct wlan_objmgr_pdev *pdev,
314 					uint16_t ch_bw,
315 					int16_t eirp,
316 					int16_t *psd)
317 {
318 	return QDF_STATUS_E_FAILURE;
319 }
320 
321 static inline bool
reg_is_supp_pwr_mode_invalid(enum supported_6g_pwr_types supp_pwr_mode)322 reg_is_supp_pwr_mode_invalid(enum supported_6g_pwr_types supp_pwr_mode)
323 {
324 	return true;
325 }
326 
327 static inline void
reg_copy_from_super_chan_info_to_reg_channel(struct regulatory_channel * chan,const struct super_chan_info sc_entry,enum supported_6g_pwr_types in_6g_pwr_mode)328 reg_copy_from_super_chan_info_to_reg_channel(struct regulatory_channel *chan,
329 					     const struct super_chan_info sc_entry,
330 					     enum supported_6g_pwr_types
331 					     in_6g_pwr_mode)
332 {
333 }
334 
335 static inline void
reg_set_ap_pwr_type(struct wlan_regulatory_pdev_priv_obj * pdev_priv_obj)336 reg_set_ap_pwr_type(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
337 {
338 }
339 
340 static inline QDF_STATUS
reg_get_6g_pwrmode_chan_list(struct wlan_regulatory_pdev_priv_obj * pdev_priv_obj,struct regulatory_channel * chan_list,enum supported_6g_pwr_types in_6g_pwr_mode)341 reg_get_6g_pwrmode_chan_list(struct wlan_regulatory_pdev_priv_obj
342 			     *pdev_priv_obj,
343 			     struct regulatory_channel *chan_list,
344 			     enum supported_6g_pwr_types in_6g_pwr_mode)
345 {
346 	return QDF_STATUS_E_INVAL;
347 }
348 #endif /* CONFIG_BAND_6GHZ */
349 /**
350  * reg_process_master_chan_list() - Compute master channel list based on the
351  * regulatory rules.
352  * @reg_info: Pointer to regulatory info
353  *
354  * Return: QDF_STATUS
355  */
356 QDF_STATUS reg_process_master_chan_list(struct cur_regulatory_info *reg_info);
357 
358 /**
359  * reg_get_pwrmode_chan_list() - Get the modified channel list. A modified
360  * current channel list consists of 2G and 5G portions of the current channel
361  * list and the 6G portion of the current channel list is derived from the input
362  * 6g power type.
363  * @pdev: Pointer to pdev
364  * @chan_list: channel list pointer
365  * @in_6g_pwr_mode: Input 6GHz power mode.
366  *
367  * Return:
368  * QDF_STATUS_SUCCESS: Success
369  * QDF_STATUS_E_INVAL: Failed to get channel list
370  */
371 QDF_STATUS reg_get_pwrmode_chan_list(struct wlan_objmgr_pdev *pdev,
372 				     struct regulatory_channel *chan_list,
373 				     enum supported_6g_pwr_types
374 				     in_6g_pwr_mode);
375 
376 /**
377  * reg_get_current_chan_list() - provide the pdev current channel list
378  * @pdev: pdev pointer
379  * @chan_list: channel list pointer
380  *
381  * Return: QDF_STATUS
382  */
383 QDF_STATUS reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
384 				     struct regulatory_channel *chan_list);
385 
386 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ)
387 /**
388  * reg_get_6g_afc_chan_list() - provide the pdev afc channel list
389  * @pdev: pdev pointer
390  * @chan_list: channel list pointer
391  *
392  * Return: QDF_STATUS
393  */
394 QDF_STATUS reg_get_6g_afc_chan_list(struct wlan_objmgr_pdev *pdev,
395 				    struct regulatory_channel *chan_list);
396 
397 /**
398  * reg_get_6g_afc_mas_chan_list() - provide the pdev afc master channel list
399  * @pdev: pdev pointer
400  * @chan_list: channel list pointer
401  *
402  * Return: QDF_STATUS
403  */
404 QDF_STATUS
405 reg_get_6g_afc_mas_chan_list(struct wlan_objmgr_pdev *pdev,
406 			     struct regulatory_channel *chan_list);
407 #endif
408 
409 #ifdef CONFIG_REG_CLIENT
410 /**
411  * reg_get_secondary_current_chan_list() - provide the pdev secondary current
412  * channel list
413  * @pdev: pdev pointer
414  * @chan_list: channel list pointer
415  *
416  * Return: QDF_STATUS
417  */
418 QDF_STATUS
419 reg_get_secondary_current_chan_list(struct wlan_objmgr_pdev *pdev,
420 				    struct regulatory_channel *chan_list);
421 #endif
422 
423 /**
424  * reg_is_chan_disabled_and_not_nol() - In the regulatory channel list, a
425  * channel may be disabled by the regulatory/device or by radar. Radar is
426  * temporary and a radar disabled channel does not mean that the channel is
427  * permanently disabled. The API checks if the channel is disabled, but not due
428  * to radar.
429  * @chan: Regulatory channel object
430  *
431  * Return: True,  the channel is disabled, but not due to radar, else false.
432  */
433 bool reg_is_chan_disabled_and_not_nol(struct regulatory_channel *chan);
434 #endif
435