xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_priv_objs.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
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  * typedef reg_ctry_change_callback() - Regulatory country change callback
89  * @mac_ctx: Pointer to mac context
90  * @vdev_id: vdev ID
91  */
92 typedef void (*reg_ctry_change_callback)(
93 		uint8_t vdev_id);
94 
95 /**
96  * struct ctry_change_cbk_entry - Country change callback entry
97  * @cbk: Callback
98  */
99 struct ctry_change_cbk_entry {
100 	reg_ctry_change_callback cbk;
101 };
102 
103 /**
104  * struct wlan_regulatory_psoc_priv_obj - wlan regulatory psoc private object
105  * @mas_chan_params: master channel parameters list
106  * @chan_list_recvd: whether channel list has been received
107  * @new_user_ctry_pending: In this array, element[phy_id] is true if any user
108  *	country update is pending for pdev (phy_id), used in case of MCL.
109  * @new_init_ctry_pending: In this array, element[phy_id] is true if any user
110  *	country update is pending for pdev (phy_id), used in case of WIN.
111  * @new_11d_ctry_pending: In this array, element[phy_id] is true if any 11d
112  *	country update is pending for pdev (phy_id).
113  * @world_country_pending: In this array, element[phy_id] is true if any world
114  *	country update is pending for pdev (phy_id).
115  * @band_capability: bitmap of bands enabled, using enum reg_wifi_band as the
116  *	bit position value
117  * @ignore_fw_reg_offload_ind: Ignore FW reg offload indication
118  * @six_ghz_supported: whether 6ghz is supported
119  * @five_dot_nine_ghz_supported: whether 5.9ghz is supported
120  *	(service bit WMI_SERVICE_5_DOT_9GHZ_SUPPORT)
121  * @enable_5dot9_ghz_chan_in_master_mode: 5.9 GHz channel support in
122  *	master mode (ini fcc_5dot9_ghz_chan_in_master_mode)
123  * @retain_nol_across_regdmn_update: Retain the NOL list across the regdomain
124  *	changes.
125  * @domain_code_6g_ap: domain code for 6G AP
126  * @domain_code_6g_client: domain code for 6G client
127  * @is_ext_tpc_supported: Whether FW supports new WMI command for TPC
128  * @is_lower_6g_edge_ch_supported: whether lower 6ghz edge channel 5935MHz is
129  * supported
130  * @is_upper_6g_edge_ch_disabled: whether upper 6ghz edge channel 7115MHz is
131  * disabled
132  * @ch_avoid_ext_ind: whether need to update extended channel frequency list
133  * @avoid_freq_ext_list: the extended avoid channel frequency list
134  * @coex_unsafe_chan_nb_user_prefer: Honor coex unsafe chan cmd from firmware or
135  * userspace
136  * @coex_unsafe_chan_reg_disable: To disable reg channels for received coex
137  * unsafe channels list
138  * @reg_afc_dev_type: AFC device deployment type from BDF
139  * @reg_is_eirp_support_preferred: Whether target prefers EIRP format for
140  * WMI Set TPC command
141  * @sta_sap_scc_on_indoor_channel: Value of sap+sta scc on indoor support
142  * @fcc_rules_ptr : Value of fcc channel frequency and tx_power list received
143  * from firmware
144  * @set_fcc_channel: Flag to set fcc channels
145  */
146 struct wlan_regulatory_psoc_priv_obj {
147 	struct mas_chan_params mas_chan_params[PSOC_MAX_PHY_REG_CAP];
148 	bool chan_list_recvd[PSOC_MAX_PHY_REG_CAP];
149 	bool offload_enabled;
150 	bool six_ghz_supported;
151 	bool five_dot_nine_ghz_supported;
152 	uint8_t num_phy;
153 	char cur_country[REG_ALPHA2_LEN + 1];
154 	char def_country[REG_ALPHA2_LEN + 1];
155 	uint16_t def_country_code;
156 	uint16_t def_region_domain;
157 	enum country_src cc_src;
158 	struct wlan_objmgr_psoc *psoc_ptr;
159 	bool new_user_ctry_pending[PSOC_MAX_PHY_REG_CAP];
160 	bool new_init_ctry_pending[PSOC_MAX_PHY_REG_CAP];
161 	bool new_11d_ctry_pending[PSOC_MAX_PHY_REG_CAP];
162 	bool world_country_pending[PSOC_MAX_PHY_REG_CAP];
163 	bool dfs_enabled;
164 	uint32_t band_capability;
165 	bool indoor_chan_enabled;
166 	bool ignore_fw_reg_offload_ind;
167 	bool enable_11d_supp_original;
168 	bool enable_11d_supp;
169 	bool is_11d_offloaded;
170 	uint8_t vdev_id_for_11d_scan;
171 	uint8_t master_vdev_cnt;
172 	uint8_t vdev_cnt_11d;
173 	uint32_t scan_11d_interval;
174 #ifdef HOST_11D_SCAN
175 	bool is_host_11d_inited;
176 	wlan_scan_requester scan_req_id;
177 	uint32_t scan_id;
178 	qdf_mc_timer_t timer;
179 #endif
180 	uint8_t vdev_ids_11d[MAX_STA_VDEV_CNT];
181 	bool user_ctry_priority;
182 	bool user_ctry_set;
183 	struct chan_change_cbk_entry cbk_list[REG_MAX_CHAN_CHANGE_CBKS];
184 	uint8_t num_chan_change_cbks;
185 	struct ctry_change_cbk_entry cc_cbk;
186 	uint8_t ch_avoid_ind;
187 	struct unsafe_ch_list unsafe_chan_list;
188 	struct ch_avoid_ind_type avoid_freq_list;
189 	enum restart_beaconing_on_ch_avoid_rule restart_beaconing;
190 	struct wlan_psoc_host_hal_reg_capabilities_ext
191 			reg_cap[PSOC_MAX_PHY_REG_CAP];
192 	bool force_ssc_disable_indoor_channel;
193 	uint8_t enable_srd_chan_in_master_mode;
194 	bool enable_11d_in_world_mode;
195 	bool enable_5dot9_ghz_chan_in_master_mode;
196 	qdf_spinlock_t cbk_list_lock;
197 	bool retain_nol_across_regdmn_update;
198 #ifdef CONFIG_BAND_6GHZ
199 	uint8_t domain_code_6g_ap[REG_CURRENT_MAX_AP_TYPE];
200 	uint8_t domain_code_6g_client[REG_CURRENT_MAX_AP_TYPE][REG_MAX_CLIENT_TYPE];
201 #endif
202 	bool is_ext_tpc_supported;
203 #if defined(CONFIG_BAND_6GHZ)
204 	bool is_lower_6g_edge_ch_supported;
205 	bool is_upper_6g_edge_ch_disabled;
206 #endif
207 #ifdef FEATURE_WLAN_CH_AVOID_EXT
208 	bool ch_avoid_ext_ind;
209 	struct ch_avoid_ind_type avoid_freq_ext_list;
210 	bool coex_unsafe_chan_nb_user_prefer;
211 	bool coex_unsafe_chan_reg_disable;
212 #endif
213 #ifdef CONFIG_AFC_SUPPORT
214 	enum reg_afc_dev_deploy_type reg_afc_dev_type;
215 	bool reg_is_eirp_support_preferred;
216 #endif
217 	bool sta_sap_scc_on_indoor_channel;
218 #ifdef CONFIG_REG_CLIENT
219 	struct cur_fcc_rule fcc_rules_ptr[MAX_NUM_FCC_RULES];
220 #endif
221 	bool set_fcc_channel;
222 };
223 
224 /**
225  * struct wlan_regulatory_pdev_priv_obj - wlan regulatory pdev private object
226  * @cur_chan_list: current channel list, includes 6G channels
227  * @secondary_cur_chan_list: secondary current channel list, for concurrency
228  * situations
229  * @mas_chan_list: master channel list
230  * from the firmware.
231  * @is_6g_channel_list_populated: indicates the channel lists are populated
232  * @mas_chan_list_6g_ap: master channel list for 6G AP, includes all power types
233  * @mas_chan_list_6g_client: master channel list for 6G client, includes
234  *	all power types
235  * @super_chan_list: 6G super channel list that includes the information of
236  * all 6G power modes for every 6G channel
237  * @band_capability: bitmap of bands enabled, using enum reg_wifi_band as the
238  *	bit position value
239  * @reg_6g_superid: 6Ghz super domain id
240  * @pdev_opened: whether pdev has been opened by application
241  * @reg_cur_6g_ap_pwr_type: 6G AP type ie VLP/SP/LPI.
242  * @reg_cur_6g_client_mobility_type: 6G client type ie Default/Subordinate.
243  * @reg_rnr_tpe_usable: Indicates whether RNR IE is applicable for current reg
244  * domain.
245  * @reg_unspecified_ap_usable: Indicates if the AP type mentioned is not part of
246  * 802.11 standard.
247  * @max_phymode: The maximum phymode supported by the device and regulatory.
248  * @max_chwidth: The maximum bandwidth corresponding to the maximum phymode.
249  * @avoid_chan_ext_list: the extended avoid frequency list.
250  * @afc_cb_lock: The spinlock to synchronize afc callbacks
251  * @afc_cb_obj: The object containing the callback function and opaque argument
252  * @afc_pow_evt_cb_obj: The object containing the callback function and opaque
253  * argument for the AFC power event
254  * @afc_request_id: The last AFC request id received from FW/halphy
255  * @is_6g_afc_power_event_received: indicates if the AFC power event is
256  * received
257  * @is_6g_afc_expiry_event_received: indicates if the AFC exipiry event is
258  * received
259  * @afc_chan_list: Intersection of AFC master and Standard power channel list
260  * @mas_chan_list_6g_afc: AFC master channel list constructed from the AFC
261  * server response.
262  * @power_info: pointer to AFC power information received from the AFC event
263  * sent by the target
264  * @is_reg_noaction_on_afc_pwr_evt: indicates whether regulatory needs to
265  * take action when AFC Power event is received
266  * @reg_6g_thresh_priority_freq: All frequencies greater or equal will be given
267  * priority during channel selection by upper layer
268  * @reg_afc_dev_deployment_type: AFC device deployment type from BDF
269  * @sta_sap_scc_on_indoor_channel: Value of sap+sta scc on indoor support
270  * @fcc_rules_ptr : Value of fcc channel frequency and tx_power list received
271  * from firmware
272  */
273 struct wlan_regulatory_pdev_priv_obj {
274 	struct regulatory_channel cur_chan_list[NUM_CHANNELS];
275 #ifdef CONFIG_REG_CLIENT
276 	struct regulatory_channel secondary_cur_chan_list[NUM_CHANNELS];
277 #endif
278 	struct regulatory_channel mas_chan_list[NUM_CHANNELS];
279 #ifdef CONFIG_BAND_6GHZ
280 	bool is_6g_channel_list_populated;
281 	struct regulatory_channel mas_chan_list_6g_ap[REG_CURRENT_MAX_AP_TYPE][NUM_6GHZ_CHANNELS];
282 	struct regulatory_channel mas_chan_list_6g_client[REG_CURRENT_MAX_AP_TYPE][REG_MAX_CLIENT_TYPE][NUM_6GHZ_CHANNELS];
283 	struct super_chan_info super_chan_list[NUM_6GHZ_CHANNELS];
284 #endif
285 #ifdef DISABLE_CHANNEL_LIST
286 	struct regulatory_channel cache_disable_chan_list[NUM_CHANNELS];
287 	uint32_t num_cache_channels;
288 	bool disable_cached_channels;
289 #endif
290 	char default_country[REG_ALPHA2_LEN + 1];
291 	uint16_t def_region_domain;
292 	uint16_t def_country_code;
293 	char current_country[REG_ALPHA2_LEN + 1];
294 	uint16_t reg_dmn_pair;
295 	uint16_t reg_6g_superid;
296 	uint16_t ctry_code;
297 #ifdef DISABLE_UNII_SHARED_BANDS
298 	uint8_t unii_5g_bitmap;
299 #endif
300 	enum dfs_reg dfs_region;
301 	uint32_t phybitmap;
302 	struct wlan_objmgr_pdev *pdev_ptr;
303 	qdf_freq_t range_2g_low;
304 	qdf_freq_t range_2g_high;
305 	qdf_freq_t range_5g_low;
306 	qdf_freq_t range_5g_high;
307 	bool dfs_enabled;
308 	bool set_fcc_channel;
309 	uint32_t band_capability;
310 	bool indoor_chan_enabled;
311 	bool en_chan_144;
312 	uint64_t wireless_modes;
313 	struct ch_avoid_ind_type freq_avoid_list;
314 	bool force_ssc_disable_indoor_channel;
315 	bool sap_state;
316 	struct reg_rule_info reg_rules;
317 	qdf_spinlock_t reg_rules_lock;
318 	bool chan_list_recvd;
319 	bool pdev_opened;
320 #if defined(CONFIG_BAND_6GHZ)
321 	enum reg_6g_ap_type reg_cur_6g_ap_pwr_type;
322 	enum reg_6g_client_type reg_cur_6g_client_mobility_type;
323 	bool reg_rnr_tpe_usable;
324 	bool reg_unspecified_ap_usable;
325 	qdf_freq_t reg_6g_thresh_priority_freq;
326 #endif
327 #ifdef CONFIG_HOST_FIND_CHAN
328 	enum reg_phymode max_phymode;
329 	enum phy_ch_width max_chwidth;
330 #endif
331 #ifdef FEATURE_WLAN_CH_AVOID_EXT
332 	avoid_ch_ext_list avoid_chan_ext_list;
333 #endif
334 #ifdef CONFIG_AFC_SUPPORT
335 	qdf_spinlock_t afc_cb_lock;
336 	struct afc_cb_handler afc_cb_obj;
337 	struct afc_pow_evt_cb_handler afc_pow_evt_cb_obj;
338 	uint64_t afc_request_id;
339 	bool is_6g_afc_power_event_received;
340 	bool is_6g_afc_expiry_event_received;
341 	struct regulatory_channel afc_chan_list[NUM_6GHZ_CHANNELS];
342 	struct regulatory_channel mas_chan_list_6g_afc[NUM_6GHZ_CHANNELS];
343 	struct reg_fw_afc_power_event *power_info;
344 	bool is_reg_noaction_on_afc_pwr_evt;
345 	enum reg_afc_dev_deploy_type reg_afc_dev_deployment_type;
346 #endif
347 	bool sta_sap_scc_on_indoor_channel;
348 #ifdef CONFIG_REG_CLIENT
349 	struct cur_fcc_rule fcc_rules_ptr[MAX_NUM_FCC_RULES];
350 #endif
351 };
352 
353 /**
354  * reg_get_psoc_obj() - Provides the reg component object pointer
355  * @psoc: pointer to psoc object.
356  *
357  * Return: reg component object pointer
358  */
359 struct wlan_regulatory_psoc_priv_obj *reg_get_psoc_obj(
360 		struct wlan_objmgr_psoc *psoc);
361 
362 /**
363  * reg_get_pdev_obj() - Provides the reg component object pointer
364  * @psoc: pointer to psoc object.
365  *
366  * Return: reg component object pointer
367  */
368 struct wlan_regulatory_pdev_priv_obj *reg_get_pdev_obj(
369 		struct wlan_objmgr_pdev *pdev);
370 
371 /**
372  * wlan_regulatory_psoc_obj_created_notification() - PSOC obj create callback
373  * @psoc: PSOC object
374  * @arg_list: Variable argument list
375  *
376  * This callback is registered with object manager during initialization to
377  * get notified when the object is created.
378  *
379  * Return: Success or Failure
380  */
381 QDF_STATUS wlan_regulatory_psoc_obj_created_notification(
382 		struct wlan_objmgr_psoc *psoc, void *arg_list);
383 
384 /**
385  * wlan_regulatory_psoc_obj_destroyed_notification() - PSOC obj delete callback
386  * @psoc: PSOC object
387  * @arg_list: Variable argument list
388  *
389  * This callback is registered with object manager during initialization to
390  * get notified when the object is deleted.
391  *
392  * Return: Success or Failure
393  */
394 QDF_STATUS wlan_regulatory_psoc_obj_destroyed_notification(
395 	struct wlan_objmgr_psoc *psoc, void *arg_list);
396 
397 /**
398  * wlan_regulatory_pdev_obj_created_notification() - PDEV obj create callback
399  * @pdev: pdev object
400  * @arg_list: Variable argument list
401  *
402  * This callback is registered with object manager during initialization to
403  * get notified when the pdev object is created.
404  *
405  * Return: Success or Failure
406  */
407 QDF_STATUS wlan_regulatory_pdev_obj_created_notification(
408 	struct wlan_objmgr_pdev *pdev, void *arg_list);
409 
410 /**
411  * wlan_regulatory_pdev_obj_destroyed_notification() - PDEV obj destroy callback
412  * @pdev: pdev object
413  * @arg_list: Variable argument list
414  *
415  * This callback is registered with object manager during initialization to
416  * get notified when the pdev object is destroyed.
417  *
418  * Return: Success or Failure
419  */
420 QDF_STATUS wlan_regulatory_pdev_obj_destroyed_notification(
421 		struct wlan_objmgr_pdev *pdev, void *arg_list);
422 
423 #ifdef CONFIG_AFC_SUPPORT
424 /**
425  * reg_free_afc_pwr_info() - Free the AFC power information object
426  * @pdev_priv_obj: Pointer to pdev_priv_obj
427  *
428  * Return: void
429  */
430 void
431 reg_free_afc_pwr_info(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj);
432 #else
433 static inline void
434 reg_free_afc_pwr_info(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
435 {
436 }
437 #endif
438 #endif
439