xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_priv_objs.h (revision 8b3dca18206e1a0461492f082fa6e270b092c035)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: reg_priv_objs.h
22  * This file contains regulatory component private data structures.
23  */
24 
25 #ifndef __REG_PRIV_OBJS_H
26 #define __REG_PRIV_OBJS_H
27 
28 #include <wlan_scan_public_structs.h>
29 #ifdef CONFIG_AFC_SUPPORT
30 #include "reg_services_common.h"
31 #endif
32 #include <wlan_objmgr_psoc_obj.h>
33 
34 #define reg_alert(params...) \
35 	QDF_TRACE_FATAL(QDF_MODULE_ID_REGULATORY, params)
36 #define reg_err(params...) \
37 	QDF_TRACE_ERROR(QDF_MODULE_ID_REGULATORY, params)
38 #define reg_err_rl(params...) \
39 	QDF_TRACE_ERROR_RL(QDF_MODULE_ID_REGULATORY, params)
40 #define reg_warn(params...) \
41 	QDF_TRACE_WARN(QDF_MODULE_ID_REGULATORY, params)
42 #define reg_notice(params...) \
43 	QDF_TRACE_INFO(QDF_MODULE_ID_REGULATORY, params)
44 #define reg_info(params...) \
45 	QDF_TRACE_INFO(QDF_MODULE_ID_REGULATORY, params)
46 #define reg_debug(params...) \
47 	QDF_TRACE_DEBUG(QDF_MODULE_ID_REGULATORY, params)
48 #define reg_debug_rl(params...) \
49 	QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_REGULATORY, params)
50 
51 #define reg_nofl_alert(params...) \
52 	QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_REGULATORY, params)
53 #define reg_nofl_err(params...) \
54 	QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_REGULATORY, params)
55 #define reg_nofl_warn(params...) \
56 	QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_REGULATORY, params)
57 #define reg_nofl_info(params...) \
58 	QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_REGULATORY, params)
59 #define reg_nofl_debug(params...) \
60 	QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_REGULATORY, params)
61 
62 /**
63  * typedef reg_chan_change_callback() - Regulatory channel change callback
64  * @psoc: Pointer to psoc
65  * @pdev: Pointer to pdev
66  * @chan_list: Pointer to regulatory channel list
67  * @avoid_freq_ind: Pointer to avoid frequencies
68  * @arg: list of arguments
69  */
70 typedef void (*reg_chan_change_callback)(
71 		struct wlan_objmgr_psoc *psoc,
72 		struct wlan_objmgr_pdev *pdev,
73 		struct regulatory_channel *chan_list,
74 		struct avoid_freq_ind_data *avoid_freq_ind,
75 		void *arg);
76 
77 /**
78  * struct chan_change_cbk_entry - Channel change callback entry
79  * @cbk: Callback
80  * @arg: Arguments
81  */
82 struct chan_change_cbk_entry {
83 	reg_chan_change_callback cbk;
84 	void *arg;
85 };
86 
87 /**
88  * struct wlan_regulatory_psoc_priv_obj - wlan regulatory psoc private object
89  * @mas_chan_params: master channel parameters list
90  * @chan_list_recvd: whether channel list has been received
91  * @new_user_ctry_pending: In this array, element[phy_id] is true if any user
92  *	country update is pending for pdev (phy_id), used in case of MCL.
93  * @new_init_ctry_pending: In this array, element[phy_id] is true if any user
94  *	country update is pending for pdev (phy_id), used in case of WIN.
95  * @new_11d_ctry_pending: In this array, element[phy_id] is true if any 11d
96  *	country update is pending for pdev (phy_id).
97  * @world_country_pending: In this array, element[phy_id] is true if any world
98  *	country update is pending for pdev (phy_id).
99  * @band_capability: bitmap of bands enabled, using enum reg_wifi_band as the
100  *	bit position value
101  * @ignore_fw_reg_offload_ind: Ignore FW reg offload indication
102  * @six_ghz_supported: whether 6ghz is supported
103  * @five_dot_nine_ghz_supported: whether 5.9ghz is supported
104  *	(service bit WMI_SERVICE_5_DOT_9GHZ_SUPPORT)
105  * @enable_5dot9_ghz_chan_in_master_mode: 5.9 GHz channel support in
106  *	master mode (ini fcc_5dot9_ghz_chan_in_master_mode)
107  * @retain_nol_across_regdmn_update: Retain the NOL list across the regdomain
108  *	changes.
109  * @domain_code_6g_ap: domain code for 6G AP
110  * @domain_code_6g_client: domain code for 6G client
111  * @is_ext_tpc_supported: Whether FW supports new WMI command for TPC
112  * @is_lower_6g_edge_ch_supported: whether lower 6ghz edge channel 5935MHz is
113  * supported
114  * @is_upper_6g_edge_ch_disabled: whether upper 6ghz edge channel 7115MHz is
115  * disabled
116  * @ch_avoid_ext_ind: whether need to update extended channel frequency list
117  * @avoid_freq_ext_list: the extended avoid channel frequency list
118  * @coex_unsafe_chan_nb_user_prefer: Honor coex unsafe chan cmd from firmware or
119  * userspace
120  * @coex_unsafe_chan_reg_disable: To disable reg channels for received coex
121  * unsafe channels list
122  * @reg_afc_dev_type: AFC device deployment type from BDF
123  * @sta_sap_scc_on_indoor_channel: Value of sap+sta scc on indoor support
124  * @fcc_rules_ptr : Value of fcc channel frequency and tx_power list received
125  * from firmware
126  * @set_fcc_channel: Flag to set fcc channels
127  */
128 struct wlan_regulatory_psoc_priv_obj {
129 	struct mas_chan_params mas_chan_params[PSOC_MAX_PHY_REG_CAP];
130 	bool chan_list_recvd[PSOC_MAX_PHY_REG_CAP];
131 	bool offload_enabled;
132 	bool six_ghz_supported;
133 	bool five_dot_nine_ghz_supported;
134 	uint8_t num_phy;
135 	char cur_country[REG_ALPHA2_LEN + 1];
136 	char def_country[REG_ALPHA2_LEN + 1];
137 	uint16_t def_country_code;
138 	uint16_t def_region_domain;
139 	enum country_src cc_src;
140 	struct wlan_objmgr_psoc *psoc_ptr;
141 	bool new_user_ctry_pending[PSOC_MAX_PHY_REG_CAP];
142 	bool new_init_ctry_pending[PSOC_MAX_PHY_REG_CAP];
143 	bool new_11d_ctry_pending[PSOC_MAX_PHY_REG_CAP];
144 	bool world_country_pending[PSOC_MAX_PHY_REG_CAP];
145 	bool dfs_enabled;
146 	uint32_t band_capability;
147 	bool indoor_chan_enabled;
148 	bool ignore_fw_reg_offload_ind;
149 	bool enable_11d_supp_original;
150 	bool enable_11d_supp;
151 	bool is_11d_offloaded;
152 	uint8_t vdev_id_for_11d_scan;
153 	uint8_t master_vdev_cnt;
154 	uint8_t vdev_cnt_11d;
155 	uint32_t scan_11d_interval;
156 #ifdef HOST_11D_SCAN
157 	bool is_host_11d_inited;
158 	wlan_scan_requester scan_req_id;
159 	uint32_t scan_id;
160 	qdf_mc_timer_t timer;
161 #endif
162 	uint8_t vdev_ids_11d[MAX_STA_VDEV_CNT];
163 	bool user_ctry_priority;
164 	bool user_ctry_set;
165 	struct chan_change_cbk_entry cbk_list[REG_MAX_CHAN_CHANGE_CBKS];
166 	uint8_t num_chan_change_cbks;
167 	uint8_t ch_avoid_ind;
168 	struct unsafe_ch_list unsafe_chan_list;
169 	struct ch_avoid_ind_type avoid_freq_list;
170 	enum restart_beaconing_on_ch_avoid_rule restart_beaconing;
171 	struct wlan_psoc_host_hal_reg_capabilities_ext
172 			reg_cap[PSOC_MAX_PHY_REG_CAP];
173 	bool force_ssc_disable_indoor_channel;
174 	uint8_t enable_srd_chan_in_master_mode;
175 	bool enable_11d_in_world_mode;
176 	bool enable_5dot9_ghz_chan_in_master_mode;
177 	qdf_spinlock_t cbk_list_lock;
178 	bool retain_nol_across_regdmn_update;
179 #ifdef CONFIG_BAND_6GHZ
180 	uint8_t domain_code_6g_ap[REG_CURRENT_MAX_AP_TYPE];
181 	uint8_t domain_code_6g_client[REG_CURRENT_MAX_AP_TYPE][REG_MAX_CLIENT_TYPE];
182 #endif
183 	bool is_ext_tpc_supported;
184 #if defined(CONFIG_BAND_6GHZ)
185 	bool is_lower_6g_edge_ch_supported;
186 	bool is_upper_6g_edge_ch_disabled;
187 #endif
188 #ifdef FEATURE_WLAN_CH_AVOID_EXT
189 	bool ch_avoid_ext_ind;
190 	struct ch_avoid_ind_type avoid_freq_ext_list;
191 	bool coex_unsafe_chan_nb_user_prefer;
192 	bool coex_unsafe_chan_reg_disable;
193 #endif
194 #ifdef CONFIG_AFC_SUPPORT
195 	enum reg_afc_dev_deploy_type reg_afc_dev_type;
196 #endif
197 	bool sta_sap_scc_on_indoor_channel;
198 #ifdef CONFIG_REG_CLIENT
199 	struct cur_fcc_rule fcc_rules_ptr[MAX_NUM_FCC_RULES];
200 #endif
201 	bool set_fcc_channel;
202 };
203 
204 /**
205  * struct wlan_regulatory_pdev_priv_obj - wlan regulatory pdev private object
206  * @cur_chan_list: current channel list, includes 6G channels
207  * @secondary_cur_chan_list: secondary current channel list, for concurrency
208  * situations
209  * @mas_chan_list: master channel list
210  * from the firmware.
211  * @is_6g_channel_list_populated: indicates the channel lists are populated
212  * @mas_chan_list_6g_ap: master channel list for 6G AP, includes all power types
213  * @mas_chan_list_6g_client: master channel list for 6G client, includes
214  *	all power types
215  * @super_chan_list: 6G super channel list that includes the information of
216  * all 6G power modes for every 6G channel
217  * @band_capability: bitmap of bands enabled, using enum reg_wifi_band as the
218  *	bit position value
219  * @reg_6g_superid: 6Ghz super domain id
220  * @pdev_opened: whether pdev has been opened by application
221  * @reg_cur_6g_ap_pwr_type: 6G AP type ie VLP/SP/LPI.
222  * @reg_cur_6g_client_mobility_type: 6G client type ie Default/Subordinate.
223  * @reg_rnr_tpe_usable: Indicates whether RNR IE is applicable for current reg
224  * domain.
225  * @reg_unspecified_ap_usable: Indicates if the AP type mentioned is not part of
226  * 802.11 standard.
227  * @max_phymode: The maximum phymode supported by the device and regulatory.
228  * @max_chwidth: The maximum bandwidth corresponding to the maximum phymode.
229  * @avoid_chan_ext_list: the extended avoid frequency list.
230  * @afc_cb_lock: The spinlock to synchronize afc callbacks
231  * @afc_cb_obj: The object containing the callback function and opaque argument
232  * @afc_pow_evt_cb_obj: The object containing the callback function and opaque
233  * argument for the AFC power event
234  * @afc_request_id: The last AFC request id received from FW/halphy
235  * @is_6g_afc_power_event_received: indicates if the AFC power event is
236  * received
237  * @is_6g_afc_expiry_event_received: indicates if the AFC exipiry event is
238  * received
239  * @afc_chan_list: Intersection of AFC master and Standard power channel list
240  * @mas_chan_list_6g_afc: AFC master channel list constructed from the AFC
241  * server response.
242  * @power_info: pointer to AFC power information received from the AFC event
243  * sent by the target
244  * @is_reg_noaction_on_afc_pwr_evt: indicates whether regulatory needs to
245  * take action when AFC Power event is received
246  * @reg_6g_thresh_priority_freq: All frequencies greater or equal will be given
247  * priority during channel selection by upper layer
248  * @reg_afc_dev_deployment_type: AFC device deployment type from BDF
249  * @sta_sap_scc_on_indoor_channel: Value of sap+sta scc on indoor support
250  * @fcc_rules_ptr : Value of fcc channel frequency and tx_power list received
251  * from firmware
252  */
253 struct wlan_regulatory_pdev_priv_obj {
254 	struct regulatory_channel cur_chan_list[NUM_CHANNELS];
255 #ifdef CONFIG_REG_CLIENT
256 	struct regulatory_channel secondary_cur_chan_list[NUM_CHANNELS];
257 #endif
258 	struct regulatory_channel mas_chan_list[NUM_CHANNELS];
259 #ifdef CONFIG_BAND_6GHZ
260 	bool is_6g_channel_list_populated;
261 	struct regulatory_channel mas_chan_list_6g_ap[REG_CURRENT_MAX_AP_TYPE][NUM_6GHZ_CHANNELS];
262 	struct regulatory_channel mas_chan_list_6g_client[REG_CURRENT_MAX_AP_TYPE][REG_MAX_CLIENT_TYPE][NUM_6GHZ_CHANNELS];
263 	struct super_chan_info super_chan_list[NUM_6GHZ_CHANNELS];
264 #endif
265 #ifdef DISABLE_CHANNEL_LIST
266 	struct regulatory_channel cache_disable_chan_list[NUM_CHANNELS];
267 	uint32_t num_cache_channels;
268 	bool disable_cached_channels;
269 #endif
270 	char default_country[REG_ALPHA2_LEN + 1];
271 	uint16_t def_region_domain;
272 	uint16_t def_country_code;
273 	char current_country[REG_ALPHA2_LEN + 1];
274 	uint16_t reg_dmn_pair;
275 	uint16_t reg_6g_superid;
276 	uint16_t ctry_code;
277 #ifdef DISABLE_UNII_SHARED_BANDS
278 	uint8_t unii_5g_bitmap;
279 #endif
280 	enum dfs_reg dfs_region;
281 	uint32_t phybitmap;
282 	struct wlan_objmgr_pdev *pdev_ptr;
283 	qdf_freq_t range_2g_low;
284 	qdf_freq_t range_2g_high;
285 	qdf_freq_t range_5g_low;
286 	qdf_freq_t range_5g_high;
287 	bool dfs_enabled;
288 	bool set_fcc_channel;
289 	uint32_t band_capability;
290 	bool indoor_chan_enabled;
291 	bool en_chan_144;
292 	uint64_t wireless_modes;
293 	struct ch_avoid_ind_type freq_avoid_list;
294 	bool force_ssc_disable_indoor_channel;
295 	bool sap_state;
296 	struct reg_rule_info reg_rules;
297 	qdf_spinlock_t reg_rules_lock;
298 	bool chan_list_recvd;
299 	bool pdev_opened;
300 #if defined(CONFIG_BAND_6GHZ)
301 	enum reg_6g_ap_type reg_cur_6g_ap_pwr_type;
302 	enum reg_6g_client_type reg_cur_6g_client_mobility_type;
303 	bool reg_rnr_tpe_usable;
304 	bool reg_unspecified_ap_usable;
305 	qdf_freq_t reg_6g_thresh_priority_freq;
306 #endif
307 #ifdef CONFIG_HOST_FIND_CHAN
308 	enum reg_phymode max_phymode;
309 	enum phy_ch_width max_chwidth;
310 #endif
311 #ifdef FEATURE_WLAN_CH_AVOID_EXT
312 	avoid_ch_ext_list avoid_chan_ext_list;
313 #endif
314 #ifdef CONFIG_AFC_SUPPORT
315 	qdf_spinlock_t afc_cb_lock;
316 	struct afc_cb_handler afc_cb_obj;
317 	struct afc_pow_evt_cb_handler afc_pow_evt_cb_obj;
318 	uint64_t afc_request_id;
319 	bool is_6g_afc_power_event_received;
320 	bool is_6g_afc_expiry_event_received;
321 	struct regulatory_channel afc_chan_list[NUM_6GHZ_CHANNELS];
322 	struct regulatory_channel mas_chan_list_6g_afc[NUM_6GHZ_CHANNELS];
323 	struct reg_fw_afc_power_event *power_info;
324 	bool is_reg_noaction_on_afc_pwr_evt;
325 	enum reg_afc_dev_deploy_type reg_afc_dev_deployment_type;
326 #endif
327 	bool sta_sap_scc_on_indoor_channel;
328 #ifdef CONFIG_REG_CLIENT
329 	struct cur_fcc_rule fcc_rules_ptr[MAX_NUM_FCC_RULES];
330 #endif
331 };
332 
333 /**
334  * reg_get_psoc_obj() - Provides the reg component object pointer
335  * @psoc: pointer to psoc object.
336  *
337  * Return: reg component object pointer
338  */
339 struct wlan_regulatory_psoc_priv_obj *reg_get_psoc_obj(
340 		struct wlan_objmgr_psoc *psoc);
341 
342 /**
343  * reg_get_pdev_obj() - Provides the reg component object pointer
344  * @psoc: pointer to psoc object.
345  *
346  * Return: reg component object pointer
347  */
348 struct wlan_regulatory_pdev_priv_obj *reg_get_pdev_obj(
349 		struct wlan_objmgr_pdev *pdev);
350 
351 /**
352  * wlan_regulatory_psoc_obj_created_notification() - PSOC obj create callback
353  * @psoc: PSOC object
354  * @arg_list: Variable argument list
355  *
356  * This callback is registered with object manager during initialization to
357  * get notified when the object is created.
358  *
359  * Return: Success or Failure
360  */
361 QDF_STATUS wlan_regulatory_psoc_obj_created_notification(
362 		struct wlan_objmgr_psoc *psoc, void *arg_list);
363 
364 /**
365  * wlan_regulatory_psoc_obj_destroyed_notification() - PSOC obj delete callback
366  * @psoc: PSOC object
367  * @arg_list: Variable argument list
368  *
369  * This callback is registered with object manager during initialization to
370  * get notified when the object is deleted.
371  *
372  * Return: Success or Failure
373  */
374 QDF_STATUS wlan_regulatory_psoc_obj_destroyed_notification(
375 	struct wlan_objmgr_psoc *psoc, void *arg_list);
376 
377 /**
378  * wlan_regulatory_pdev_obj_created_notification() - PDEV obj create callback
379  * @pdev: pdev object
380  * @arg_list: Variable argument list
381  *
382  * This callback is registered with object manager during initialization to
383  * get notified when the pdev object is created.
384  *
385  * Return: Success or Failure
386  */
387 QDF_STATUS wlan_regulatory_pdev_obj_created_notification(
388 	struct wlan_objmgr_pdev *pdev, void *arg_list);
389 
390 /**
391  * wlan_regulatory_pdev_obj_destroyed_notification() - PDEV obj destroy callback
392  * @pdev: pdev object
393  * @arg_list: Variable argument list
394  *
395  * This callback is registered with object manager during initialization to
396  * get notified when the pdev object is destroyed.
397  *
398  * Return: Success or Failure
399  */
400 QDF_STATUS wlan_regulatory_pdev_obj_destroyed_notification(
401 		struct wlan_objmgr_pdev *pdev, void *arg_list);
402 
403 #ifdef CONFIG_AFC_SUPPORT
404 /**
405  * reg_free_afc_pwr_info() - Free the AFC power information object
406  * @pdev_priv_obj: Pointer to pdev_priv_obj
407  *
408  * Return: void
409  */
410 void
411 reg_free_afc_pwr_info(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj);
412 #else
413 static inline void
414 reg_free_afc_pwr_info(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
415 {
416 }
417 #endif
418 #endif
419