xref: /wlan-driver/qca-wifi-host-cmn/target_if/regulatory/src/target_if_reg.c (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-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: target_if_reg.c
23  * This file contains regulatory target interfaces.
24  */
25 
26 #include <wmi_unified_api.h>
27 #include <reg_services_public_struct.h>
28 #include <wlan_reg_tgt_api.h>
29 #include <target_if.h>
30 #include <target_if_reg.h>
31 #include <wmi_unified_reg_api.h>
32 #include <qdf_platform.h>
33 #include <target_if_reg_11d.h>
34 #include <target_if_reg_lte.h>
35 #include <wlan_reg_ucfg_api.h>
36 #include <wlan_utility.h>
37 #ifdef CONFIG_REG_CLIENT
38 #include <wlan_dcs_tgt_api.h>
39 #endif
40 
41 /**
42  * get_chan_list_cc_event_id() - Get chan_list_cc event id
43  *
44  * Return: Event id
45  */
get_chan_list_cc_event_id(void)46 static inline uint32_t get_chan_list_cc_event_id(void)
47 {
48 	return wmi_reg_chan_list_cc_event_id;
49 }
50 
51 /**
52  * tgt_if_regulatory_is_regdb_offloaded() - Check if regdb is offloaded
53  * @psoc: Pointer to psoc
54  *
55  * Return: true if regdb if offloaded, else false
56  */
tgt_if_regulatory_is_regdb_offloaded(struct wlan_objmgr_psoc * psoc)57 static bool tgt_if_regulatory_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc)
58 {
59 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
60 
61 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
62 
63 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
64 	if (!reg_rx_ops) {
65 		target_if_err("reg_rx_ops is NULL");
66 		return false;
67 	}
68 
69 	if (!wmi_handle)
70 		return false;
71 
72 	if (reg_rx_ops->reg_ignore_fw_reg_offload_ind &&
73 	    reg_rx_ops->reg_ignore_fw_reg_offload_ind(psoc)) {
74 		target_if_debug("User disabled regulatory offload from ini");
75 		return 0;
76 	}
77 
78 	return wmi_service_enabled(wmi_handle, wmi_service_regulatory_db);
79 }
80 
81 /**
82  * tgt_if_regulatory_is_6ghz_supported() - Check if 6 GHz is supported
83  * @psoc: Pointer to psoc
84  *
85  * Return: true if regdb if offloaded, else false
86  */
tgt_if_regulatory_is_6ghz_supported(struct wlan_objmgr_psoc * psoc)87 static bool tgt_if_regulatory_is_6ghz_supported(struct wlan_objmgr_psoc *psoc)
88 {
89 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
90 
91 	if (!wmi_handle)
92 		return false;
93 
94 	return wmi_service_enabled(wmi_handle, wmi_service_6ghz_support);
95 }
96 
97 /**
98  * tgt_if_regulatory_is_5dot9_ghz_supported() - Check if 5.9 GHz is supported
99  * @psoc: Pointer to psoc
100  *
101  * Return: true if 5.9 GHz is supported, else false
102  */
103 static bool
tgt_if_regulatory_is_5dot9_ghz_supported(struct wlan_objmgr_psoc * psoc)104 tgt_if_regulatory_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc)
105 {
106 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
107 
108 	if (!wmi_handle)
109 		return false;
110 
111 	return wmi_service_enabled(wmi_handle, wmi_service_5dot9_ghz_support);
112 }
113 
114 /**
115  * tgt_if_regulatory_is_there_serv_ready_extn() - Check for service ready
116  * extension
117  * @psoc: Pointer to psoc object
118  *
119  * Return: true if service ready extension is present, else false.
120  */
tgt_if_regulatory_is_there_serv_ready_extn(struct wlan_objmgr_psoc * psoc)121 static bool tgt_if_regulatory_is_there_serv_ready_extn(
122 		struct wlan_objmgr_psoc *psoc)
123 {
124 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
125 
126 	if (!wmi_handle)
127 		return false;
128 
129 	return wmi_service_enabled(wmi_handle, wmi_service_ext_msg);
130 }
131 
132 /**
133  * target_if_regulatory_get_rx_ops() - Get regdb rx ops
134  * @psoc: Pointer to psoc object
135  *
136  * Return: Reg rx_ops
137  */
138 struct wlan_lmac_if_reg_rx_ops *
target_if_regulatory_get_rx_ops(struct wlan_objmgr_psoc * psoc)139 target_if_regulatory_get_rx_ops(struct wlan_objmgr_psoc *psoc)
140 {
141 	struct wlan_lmac_if_rx_ops *rx_ops;
142 
143 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
144 	if (!rx_ops) {
145 		target_if_err("rx_ops is NULL");
146 		return NULL;
147 	}
148 
149 	return &rx_ops->reg_rx_ops;
150 }
151 
152 struct wlan_lmac_if_reg_tx_ops *
target_if_regulatory_get_tx_ops(struct wlan_objmgr_psoc * psoc)153 target_if_regulatory_get_tx_ops(struct wlan_objmgr_psoc *psoc)
154 {
155 	struct wlan_lmac_if_tx_ops *tx_ops;
156 
157 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
158 	if (!tx_ops) {
159 		target_if_err("tx_ops is NULL");
160 		return NULL;
161 	}
162 
163 	return &tx_ops->reg_ops;
164 }
165 
target_if_reg_set_offloaded_info(struct wlan_objmgr_psoc * psoc)166 QDF_STATUS target_if_reg_set_offloaded_info(struct wlan_objmgr_psoc *psoc)
167 {
168 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
169 
170 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
171 	if (!reg_rx_ops) {
172 		target_if_err("reg_rx_ops is NULL");
173 		return QDF_STATUS_E_FAILURE;
174 	}
175 
176 	if (reg_rx_ops->reg_set_regdb_offloaded)
177 		reg_rx_ops->reg_set_regdb_offloaded(
178 				psoc,
179 				tgt_if_regulatory_is_regdb_offloaded(psoc));
180 
181 	if (reg_rx_ops->reg_set_11d_offloaded)
182 		reg_rx_ops->reg_set_11d_offloaded(
183 				psoc, tgt_if_regulatory_is_11d_offloaded(psoc));
184 
185 	return QDF_STATUS_SUCCESS;
186 }
187 
target_if_reg_set_6ghz_info(struct wlan_objmgr_psoc * psoc)188 QDF_STATUS target_if_reg_set_6ghz_info(struct wlan_objmgr_psoc *psoc)
189 {
190 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
191 
192 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
193 	if (!reg_rx_ops) {
194 		target_if_err("reg_rx_ops is NULL");
195 		return QDF_STATUS_E_FAILURE;
196 	}
197 
198 	if (reg_rx_ops->reg_set_6ghz_supported)
199 		reg_rx_ops->reg_set_6ghz_supported(
200 			psoc,
201 			tgt_if_regulatory_is_6ghz_supported(psoc));
202 
203 	return QDF_STATUS_SUCCESS;
204 }
205 
target_if_reg_set_5dot9_ghz_info(struct wlan_objmgr_psoc * psoc)206 QDF_STATUS target_if_reg_set_5dot9_ghz_info(struct wlan_objmgr_psoc *psoc)
207 {
208 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
209 
210 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
211 	if (!reg_rx_ops) {
212 		target_if_err("reg_rx_ops is NULL");
213 		return QDF_STATUS_E_FAILURE;
214 	}
215 
216 	if (reg_rx_ops->reg_set_5dot9_ghz_supported)
217 		reg_rx_ops->reg_set_5dot9_ghz_supported(
218 			psoc,
219 			tgt_if_regulatory_is_5dot9_ghz_supported(psoc));
220 
221 	return QDF_STATUS_SUCCESS;
222 }
223 
224 bool
target_if_reg_is_reg_cc_ext_event_host_supported(struct wlan_objmgr_psoc * psoc)225 target_if_reg_is_reg_cc_ext_event_host_supported(struct wlan_objmgr_psoc *psoc)
226 {
227 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
228 	bool reg_ext_cc_supp = false;
229 
230 	reg_tx_ops = target_if_regulatory_get_tx_ops(psoc);
231 	if (!reg_tx_ops) {
232 		target_if_err("reg_tx_ops is NULL");
233 		return reg_ext_cc_supp;
234 	}
235 
236 	if (reg_tx_ops->register_master_ext_handler)
237 		reg_ext_cc_supp = true;
238 
239 	return reg_ext_cc_supp;
240 }
241 
242 /**
243  * tgt_reg_chan_list_update_handler() - Channel list update handler
244  * @handle: scn handle
245  * @event_buf: pointer to event buffer
246  * @len: buffer length
247  *
248  * Return: 0 on success
249  */
tgt_reg_chan_list_update_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)250 static int tgt_reg_chan_list_update_handler(ol_scn_t handle, uint8_t *event_buf,
251 					    uint32_t len)
252 {
253 	struct wlan_objmgr_psoc *psoc;
254 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
255 	struct cur_regulatory_info *reg_info;
256 	QDF_STATUS status;
257 	struct wmi_unified *wmi_handle;
258 	int ret_val = 0;
259 
260 	TARGET_IF_ENTER();
261 
262 	psoc = target_if_get_psoc_from_scn_hdl(handle);
263 	if (!psoc) {
264 		target_if_err("psoc ptr is NULL");
265 		return -EINVAL;
266 	}
267 
268 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
269 	if (!reg_rx_ops) {
270 		target_if_err("reg_rx_ops is NULL");
271 		return -EINVAL;
272 	}
273 
274 	if (!reg_rx_ops->master_list_handler) {
275 		target_if_err("master_list_handler is NULL");
276 		return -EINVAL;
277 	}
278 
279 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
280 	if (!wmi_handle) {
281 		target_if_err("invalid wmi handle");
282 		return -EINVAL;
283 	}
284 
285 	reg_info = qdf_mem_malloc(sizeof(*reg_info));
286 	if (!reg_info)
287 		return -ENOMEM;
288 
289 	if (wmi_extract_reg_chan_list_update_event(wmi_handle,
290 						   event_buf, reg_info, len)
291 	    != QDF_STATUS_SUCCESS) {
292 		target_if_err("Extraction of channel list event failed");
293 		ret_val = -EFAULT;
294 		goto clean;
295 	}
296 
297 	if (reg_info->phy_id >= PSOC_MAX_PHY_REG_CAP) {
298 		target_if_err_rl("phy_id %d is out of bounds",
299 				 reg_info->phy_id);
300 		ret_val = -EFAULT;
301 		goto clean;
302 	}
303 
304 	reg_info->psoc = psoc;
305 
306 	status = reg_rx_ops->master_list_handler(reg_info);
307 	if (status != QDF_STATUS_SUCCESS) {
308 		target_if_err("Failed to process master channel list handler");
309 		ret_val = -EFAULT;
310 	}
311 
312 clean:
313 	qdf_mem_free(reg_info->reg_rules_2g_ptr);
314 	qdf_mem_free(reg_info->reg_rules_5g_ptr);
315 	qdf_mem_free(reg_info);
316 
317 	TARGET_IF_EXIT();
318 
319 	return ret_val;
320 }
321 
322 /**
323  * tgt_if_regulatory_register_master_list_handler() - Register master channel
324  * list
325  * @psoc: Pointer to psoc
326  * @arg: Pointer to argument list
327  *
328  * Return: QDF_STATUS
329  */
tgt_if_regulatory_register_master_list_handler(struct wlan_objmgr_psoc * psoc,void * arg)330 static QDF_STATUS tgt_if_regulatory_register_master_list_handler(
331 	struct wlan_objmgr_psoc *psoc, void *arg)
332 {
333 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
334 
335 	if (!wmi_handle)
336 		return QDF_STATUS_E_FAILURE;
337 
338 	return wmi_unified_register_event_handler(
339 			wmi_handle, wmi_reg_chan_list_cc_event_id,
340 			tgt_reg_chan_list_update_handler, WMI_RX_WORK_CTX);
341 }
342 
343 /**
344  * tgt_if_regulatory_unregister_master_list_handler() - Unregister master
345  * channel list
346  * @psoc: Pointer to psoc
347  * @arg: Pointer to argument list
348  *
349  * Return: QDF_STATUS
350  */
tgt_if_regulatory_unregister_master_list_handler(struct wlan_objmgr_psoc * psoc,void * arg)351 static QDF_STATUS tgt_if_regulatory_unregister_master_list_handler(
352 	struct wlan_objmgr_psoc *psoc, void *arg)
353 {
354 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
355 
356 	if (!wmi_handle)
357 		return QDF_STATUS_E_FAILURE;
358 
359 	return wmi_unified_unregister_event_handler(
360 			wmi_handle, wmi_reg_chan_list_cc_event_id);
361 }
362 
363 #ifdef CONFIG_BAND_6GHZ
364 #ifdef CONFIG_REG_CLIENT
365 /**
366  * tgt_reg_mem_free_fcc_rules() - Free regulatory fcc rules
367  * @reg_info: Pointer to regulatory info
368  *
369  */
tgt_reg_mem_free_fcc_rules(struct cur_regulatory_info * reg_info)370 static void tgt_reg_mem_free_fcc_rules(struct cur_regulatory_info *reg_info)
371 {
372 	qdf_mem_free(reg_info->fcc_rules_ptr);
373 }
374 #else
tgt_reg_mem_free_fcc_rules(struct cur_regulatory_info * reg_info)375 static void tgt_reg_mem_free_fcc_rules(struct cur_regulatory_info *reg_info)
376 {
377 }
378 #endif
379 
380 /**
381  * tgt_reg_chan_list_ext_update_handler() - Extended channel list update handler
382  * @handle: scn handle
383  * @event_buf: pointer to event buffer
384  * @len: buffer length
385  *
386  * Return: 0 on success
387  */
tgt_reg_chan_list_ext_update_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)388 static int tgt_reg_chan_list_ext_update_handler(ol_scn_t handle,
389 						uint8_t *event_buf,
390 						uint32_t len)
391 {
392 	struct wlan_objmgr_psoc *psoc;
393 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
394 	struct cur_regulatory_info *reg_info;
395 	QDF_STATUS status;
396 	struct wmi_unified *wmi_handle;
397 	int ret_val = 0;
398 	uint32_t i;
399 
400 	TARGET_IF_ENTER();
401 
402 	psoc = target_if_get_psoc_from_scn_hdl(handle);
403 	if (!psoc) {
404 		target_if_err("psoc ptr is NULL");
405 		return -EINVAL;
406 	}
407 
408 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
409 	if (!reg_rx_ops) {
410 		target_if_err("reg_rx_ops is NULL");
411 		return -EINVAL;
412 	}
413 
414 	if (!reg_rx_ops->master_list_ext_handler) {
415 		target_if_err("master_list_ext_handler is NULL");
416 		return -EINVAL;
417 	}
418 
419 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
420 	if (!wmi_handle) {
421 		target_if_err("invalid wmi handle");
422 		return -EINVAL;
423 	}
424 
425 	reg_info = qdf_mem_malloc(sizeof(*reg_info));
426 	if (!reg_info)
427 		return -ENOMEM;
428 
429 	status = wmi_extract_reg_chan_list_ext_update_event(wmi_handle,
430 							    event_buf,
431 							    reg_info, len);
432 	if (!QDF_IS_STATUS_SUCCESS(status)) {
433 		target_if_err("Extraction of ext channel list event failed");
434 		ret_val = -EFAULT;
435 		goto clean;
436 	}
437 
438 	if (reg_info->phy_id >= PSOC_MAX_PHY_REG_CAP) {
439 		target_if_err_rl("phy_id %d is out of bounds",
440 				 reg_info->phy_id);
441 		ret_val = -EFAULT;
442 		goto clean;
443 	}
444 
445 	reg_info->psoc = psoc;
446 
447 	status = reg_rx_ops->master_list_ext_handler(reg_info);
448 	if (!QDF_IS_STATUS_SUCCESS(status)) {
449 		target_if_err("Failed to process master ext channel list handler");
450 		ret_val = -EFAULT;
451 	}
452 
453 clean:
454 	qdf_mem_free(reg_info->reg_rules_2g_ptr);
455 	qdf_mem_free(reg_info->reg_rules_5g_ptr);
456 	tgt_reg_mem_free_fcc_rules(reg_info);
457 
458 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
459 		qdf_mem_free(reg_info->reg_rules_6g_ap_ptr[i]);
460 		qdf_mem_free(reg_info->
461 			reg_rules_6g_client_ptr[i][REG_DEFAULT_CLIENT]);
462 		qdf_mem_free(reg_info->
463 			reg_rules_6g_client_ptr[i][REG_SUBORDINATE_CLIENT]);
464 	}
465 
466 	qdf_mem_free(reg_info);
467 
468 	TARGET_IF_EXIT();
469 
470 	return ret_val;
471 }
472 
473 /**
474  * tgt_if_regulatory_register_master_list_ext_handler() - Register extended
475  * master channel list event handler
476  * @psoc: Pointer to psoc
477  * @arg: Pointer to argument list
478  *
479  * Return: QDF_STATUS
480  */
tgt_if_regulatory_register_master_list_ext_handler(struct wlan_objmgr_psoc * psoc,void * arg)481 static QDF_STATUS tgt_if_regulatory_register_master_list_ext_handler(
482 	struct wlan_objmgr_psoc *psoc, void *arg)
483 {
484 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
485 
486 	if (!wmi_handle)
487 		return QDF_STATUS_E_FAILURE;
488 
489 	return wmi_unified_register_event_handler(
490 			wmi_handle, wmi_reg_chan_list_cc_ext_event_id,
491 			tgt_reg_chan_list_ext_update_handler, WMI_RX_WORK_CTX);
492 }
493 
494 /**
495  * tgt_if_regulatory_unregister_master_list_ext_handler() - Unregister extended
496  * master channel list event handler
497  * @psoc: Pointer to psoc
498  * @arg: Pointer to argument list
499  *
500  * Return: QDF_STATUS
501  */
tgt_if_regulatory_unregister_master_list_ext_handler(struct wlan_objmgr_psoc * psoc,void * arg)502 static QDF_STATUS tgt_if_regulatory_unregister_master_list_ext_handler(
503 	struct wlan_objmgr_psoc *psoc, void *arg)
504 {
505 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
506 
507 	if (!wmi_handle)
508 		return QDF_STATUS_E_FAILURE;
509 
510 	return wmi_unified_unregister_event_handler(
511 			wmi_handle, wmi_reg_chan_list_cc_ext_event_id);
512 }
513 
514 #ifdef CONFIG_AFC_SUPPORT
515 /**
516  * tgt_afc_event_handler() - Handler for AFC Event
517  * @handle: scn handle
518  * @event_buf: pointer to event buffer
519  * @len: buffer length
520  *
521  * Return: 0 on success
522  */
523 static int
tgt_afc_event_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)524 tgt_afc_event_handler(ol_scn_t handle, uint8_t *event_buf, uint32_t len)
525 {
526 	struct wlan_objmgr_psoc *psoc;
527 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
528 	struct afc_regulatory_info *afc_info;
529 	QDF_STATUS status;
530 	struct wmi_unified *wmi_handle;
531 	int ret_val = 0;
532 
533 	TARGET_IF_ENTER();
534 
535 	psoc = target_if_get_psoc_from_scn_hdl(handle);
536 	if (!psoc) {
537 		target_if_err("psoc ptr is NULL");
538 		return -EINVAL;
539 	}
540 
541 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
542 	if (!reg_rx_ops) {
543 		target_if_err("reg_rx_ops is NULL");
544 		return -EINVAL;
545 	}
546 
547 	if (!reg_rx_ops->afc_event_handler) {
548 		target_if_err("afc_event_handler is NULL");
549 		return -EINVAL;
550 	}
551 
552 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
553 	if (!wmi_handle) {
554 		target_if_err("invalid wmi handle");
555 		return -EINVAL;
556 	}
557 
558 	afc_info = qdf_mem_malloc(sizeof(*afc_info));
559 	if (!afc_info)
560 		return -ENOMEM;
561 
562 	status = wmi_extract_afc_event(wmi_handle, event_buf, afc_info, len);
563 	if (!QDF_IS_STATUS_SUCCESS(status)) {
564 		target_if_err("Extraction of AFC event failed");
565 		ret_val = -EFAULT;
566 		goto clean;
567 	}
568 
569 	if (afc_info->phy_id >= PSOC_MAX_PHY_REG_CAP) {
570 		target_if_err_rl("phy_id %d is out of bounds",
571 				 afc_info->phy_id);
572 		ret_val = -EFAULT;
573 		goto clean;
574 	}
575 
576 	afc_info->psoc = psoc;
577 
578 	status = reg_rx_ops->afc_event_handler(afc_info);
579 	if (!QDF_IS_STATUS_SUCCESS(status)) {
580 		target_if_err("Failed to process AFC event handler");
581 		ret_val = -EFAULT;
582 		goto clean;
583 	}
584 
585 clean:
586 	qdf_mem_free(afc_info);
587 	TARGET_IF_EXIT();
588 
589 	return ret_val;
590 }
591 
592 /**
593  * tgt_if_regulatory_register_afc_event_handler() - Register AFC event
594  * handler
595  * @psoc: Pointer to psoc
596  * @arg: Pointer to argument list
597  *
598  * Return: QDF_STATUS
599  */
tgt_if_regulatory_register_afc_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)600 static QDF_STATUS tgt_if_regulatory_register_afc_event_handler(
601 	struct wlan_objmgr_psoc *psoc, void *arg)
602 {
603 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
604 
605 	if (!wmi_handle)
606 		return QDF_STATUS_E_FAILURE;
607 
608 	return wmi_unified_register_event_handler(
609 			wmi_handle, wmi_afc_event_id,
610 			tgt_afc_event_handler, WMI_RX_WORK_CTX);
611 }
612 
613 /**
614  * tgt_if_regulatory_unregister_afc_event_handler() - Unregister AFC event
615  * handler
616  * @psoc: Pointer to psoc
617  * @arg: Pointer to argument list
618  *
619  * Return: QDF_STATUS
620  */
621 static QDF_STATUS
tgt_if_regulatory_unregister_afc_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)622 tgt_if_regulatory_unregister_afc_event_handler(struct wlan_objmgr_psoc *psoc,
623 					       void *arg)
624 {
625 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
626 
627 	if (!wmi_handle)
628 		return QDF_STATUS_E_FAILURE;
629 
630 	return wmi_unified_unregister_event_handler(
631 			wmi_handle, wmi_afc_event_id);
632 }
633 #endif
634 #endif
635 
636 /**
637  * tgt_if_regulatory_set_country_code() - Set country code
638  * @psoc: Pointer to psoc
639  * @arg: Pointer to argument list
640  *
641  * Return: QDF_STATUS
642  */
tgt_if_regulatory_set_country_code(struct wlan_objmgr_psoc * psoc,void * arg)643 static QDF_STATUS tgt_if_regulatory_set_country_code(
644 	struct wlan_objmgr_psoc *psoc, void *arg)
645 {
646 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
647 
648 	if (!wmi_handle)
649 		return QDF_STATUS_E_FAILURE;
650 
651 	return wmi_unified_set_country_cmd_send(wmi_handle, arg);
652 }
653 
654 /**
655  * tgt_if_regulatory_set_user_country_code() - Set user country code
656  * @psoc: Pointer to psoc
657  * @pdev_id: Pdev id
658  * @rd: Pointer to regdomain structure
659  *
660  * Return: QDF_STATUS
661  */
tgt_if_regulatory_set_user_country_code(struct wlan_objmgr_psoc * psoc,uint8_t pdev_id,struct cc_regdmn_s * rd)662 static QDF_STATUS tgt_if_regulatory_set_user_country_code(
663 	struct wlan_objmgr_psoc *psoc, uint8_t pdev_id, struct cc_regdmn_s *rd)
664 {
665 	struct wlan_objmgr_pdev *pdev;
666 	wmi_unified_t wmi_handle;
667 	QDF_STATUS status;
668 
669 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id,
670 					  WLAN_REGULATORY_NB_ID);
671 
672 	wmi_handle = get_wmi_unified_hdl_from_pdev(pdev);
673 
674 	if (!wmi_handle) {
675 		status = QDF_STATUS_E_FAILURE;
676 		goto free_pdevref;
677 	}
678 
679 	status = wmi_unified_set_user_country_code_cmd_send(wmi_handle,
680 							    pdev_id, rd);
681 	if (QDF_IS_STATUS_ERROR(status))
682 		target_if_err("Set user country code failed,status %d",
683 			      status);
684 free_pdevref:
685 	wlan_objmgr_pdev_release_ref(pdev, WLAN_REGULATORY_NB_ID);
686 
687 	return status;
688 }
689 
tgt_if_regulatory_modify_freq_range(struct wlan_objmgr_psoc * psoc)690 QDF_STATUS tgt_if_regulatory_modify_freq_range(struct wlan_objmgr_psoc *psoc)
691 {
692 	struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap;
693 
694 	reg_cap = ucfg_reg_get_hal_reg_cap(psoc);
695 	if (!reg_cap) {
696 		target_if_err("reg cap is NULL");
697 		return QDF_STATUS_E_FAILURE;
698 	}
699 
700 	if (!(reg_cap->wireless_modes & HOST_REGDMN_MODE_11A)) {
701 		reg_cap->low_5ghz_chan = 0;
702 		reg_cap->high_5ghz_chan = 0;
703 	}
704 
705 	if (!(reg_cap->wireless_modes &
706 	     (HOST_REGDMN_MODE_11B | HOST_REGDMN_MODE_PUREG))) {
707 		reg_cap->low_2ghz_chan = 0;
708 		reg_cap->high_2ghz_chan = 0;
709 	}
710 
711 	target_if_debug("phy_id = %d - low_2ghz_chan = %d high_2ghz_chan = %d low_5ghz_chan = %d high_5ghz_chan = %d",
712 			reg_cap->phy_id,
713 			reg_cap->low_2ghz_chan,
714 			reg_cap->high_2ghz_chan,
715 			reg_cap->low_5ghz_chan,
716 			reg_cap->high_5ghz_chan);
717 
718 	return QDF_STATUS_SUCCESS;
719 }
720 
721 #ifdef CONFIG_REG_CLIENT
722 /**
723  * tgt_if_regulatory_send_ctl_info() - Send CTL info to firmware
724  * @psoc: Pointer to psoc
725  * @params: Pointer to reg control params
726  *
727  * Return: QDF_STATUS
728  */
729 static QDF_STATUS
tgt_if_regulatory_send_ctl_info(struct wlan_objmgr_psoc * psoc,struct reg_ctl_params * params)730 tgt_if_regulatory_send_ctl_info(struct wlan_objmgr_psoc *psoc,
731 				struct reg_ctl_params *params)
732 {
733 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
734 
735 	if (!wmi_handle)
736 		return QDF_STATUS_E_FAILURE;
737 
738 	return wmi_unified_send_regdomain_info_to_fw_cmd(wmi_handle,
739 							 params->regd,
740 							 params->regd_2g,
741 							 params->regd_5g,
742 							 params->ctl_2g,
743 							 params->ctl_5g);
744 }
745 #else
746 static QDF_STATUS
tgt_if_regulatory_send_ctl_info(struct wlan_objmgr_psoc * psoc,struct reg_ctl_params * params)747 tgt_if_regulatory_send_ctl_info(struct wlan_objmgr_psoc *psoc,
748 				struct reg_ctl_params *params)
749 {
750 	return QDF_STATUS_SUCCESS;
751 }
752 #endif
753 
754 /**
755  * tgt_if_regulatory_get_phy_id_from_pdev_id() - Get phy_id from pdev_id
756  * @psoc: Pointer to psoc
757  * @pdev_id: Pdev id
758  * @phy_id: phy_id
759  *
760  * Return: QDF_STATUS
761  */
tgt_if_regulatory_get_phy_id_from_pdev_id(struct wlan_objmgr_psoc * psoc,uint8_t pdev_id,uint8_t * phy_id)762 static QDF_STATUS tgt_if_regulatory_get_phy_id_from_pdev_id(
763 	struct wlan_objmgr_psoc *psoc, uint8_t pdev_id, uint8_t *phy_id)
764 {
765 	struct target_psoc_info *tgt_if_handle = psoc->tgt_if_handle;
766 	uint8_t ret;
767 
768 	if (pdev_id >= WLAN_UMAC_MAX_PDEVS) {
769 		target_if_err("pdev_id is greater than WLAN_UMAC_MAX_PDEVS");
770 		return QDF_STATUS_E_FAILURE;
771 	}
772 
773 	/* By default pdev_id and phy_id have one to one mapping */
774 	*phy_id = pdev_id;
775 
776 	if (!(tgt_if_handle &&
777 	      tgt_if_handle->info.is_pdevid_to_phyid_map))
778 		return QDF_STATUS_SUCCESS;
779 
780 	ret = tgt_if_handle->info.pdev_id_to_phy_id_map[pdev_id];
781 
782 	if (ret < PSOC_MAX_PHY_REG_CAP) {
783 		*phy_id = ret;
784 	} else {
785 		target_if_err("phy_id is greater than PSOC_MAX_PHY_REG_CAP");
786 		return QDF_STATUS_E_FAILURE;
787 	}
788 
789 	return QDF_STATUS_SUCCESS;
790 }
791 
792 /**
793  * tgt_if_regulatory_get_pdev_id_from_phy_id() - Get pdev_id for phy_id
794  * @psoc: Pointer to psoc
795  * @phy_id: Phy id
796  * @pdev_id: Pdev id
797  *
798  * Return: QDF_STATUS
799  */
tgt_if_regulatory_get_pdev_id_from_phy_id(struct wlan_objmgr_psoc * psoc,uint8_t phy_id,uint8_t * pdev_id)800 static QDF_STATUS tgt_if_regulatory_get_pdev_id_from_phy_id(
801 	struct wlan_objmgr_psoc *psoc, uint8_t phy_id, uint8_t *pdev_id)
802 {
803 	struct target_psoc_info *tgt_if_handle = psoc->tgt_if_handle;
804 	uint8_t i;
805 
806 	if (phy_id >= PSOC_MAX_PHY_REG_CAP) {
807 		target_if_err("phy_id is greater than PSOC_MAX_PHY_REG_CAP");
808 		return QDF_STATUS_E_FAILURE;
809 	}
810 
811 	/* By default pdev_id and phy_id have one to one mapping */
812 	*pdev_id = phy_id;
813 
814 	if (!(tgt_if_handle &&
815 	      tgt_if_handle->info.is_pdevid_to_phyid_map))
816 		return QDF_STATUS_SUCCESS;
817 
818 	for (i = 0; i < WLAN_UMAC_MAX_PDEVS; i++) {
819 		if (tgt_if_handle->info.pdev_id_to_phy_id_map[i] == phy_id)
820 			break;
821 	}
822 
823 	if (i < WLAN_UMAC_MAX_PDEVS) {
824 		*pdev_id = i;
825 	} else {
826 		target_if_err("pdev_id is greater than WLAN_UMAC_MAX_PDEVS");
827 		return QDF_STATUS_E_FAILURE;
828 	}
829 
830 	return QDF_STATUS_SUCCESS;
831 }
832 
833 #ifdef CONFIG_BAND_6GHZ
target_if_register_master_ext_handler(struct wlan_lmac_if_reg_tx_ops * reg_ops)834 static void target_if_register_master_ext_handler(
835 				struct wlan_lmac_if_reg_tx_ops *reg_ops)
836 {
837 	reg_ops->register_master_ext_handler =
838 		tgt_if_regulatory_register_master_list_ext_handler;
839 
840 	reg_ops->unregister_master_ext_handler =
841 		tgt_if_regulatory_unregister_master_list_ext_handler;
842 }
843 
844 #ifdef CONFIG_AFC_SUPPORT
target_if_register_afc_event_handler(struct wlan_lmac_if_reg_tx_ops * reg_ops)845 static void target_if_register_afc_event_handler(
846 				struct wlan_lmac_if_reg_tx_ops *reg_ops)
847 {
848 	reg_ops->register_afc_event_handler =
849 		tgt_if_regulatory_register_afc_event_handler;
850 
851 	reg_ops->unregister_afc_event_handler =
852 		tgt_if_regulatory_unregister_afc_event_handler;
853 }
854 
855 #ifdef CONFIG_REG_CLIENT
target_if_register_acs_trigger_for_afc(struct wlan_lmac_if_reg_tx_ops * reg_ops)856 static void target_if_register_acs_trigger_for_afc
857 				(struct wlan_lmac_if_reg_tx_ops *reg_ops)
858 {
859 	reg_ops->trigger_acs_for_afc = tgt_afc_trigger_dcs;
860 }
861 #else
target_if_register_acs_trigger_for_afc(struct wlan_lmac_if_reg_tx_ops * reg_ops)862 static void target_if_register_acs_trigger_for_afc
863 				(struct wlan_lmac_if_reg_tx_ops *reg_ops)
864 {
865 	reg_ops->trigger_acs_for_afc = NULL;
866 }
867 #endif
868 #else
target_if_register_afc_event_handler(struct wlan_lmac_if_reg_tx_ops * reg_ops)869 static void target_if_register_afc_event_handler(
870 				struct wlan_lmac_if_reg_tx_ops *reg_ops)
871 {
872 }
873 
target_if_register_acs_trigger_for_afc(struct wlan_lmac_if_reg_tx_ops * reg_ops)874 static void target_if_register_acs_trigger_for_afc
875 				(struct wlan_lmac_if_reg_tx_ops *reg_ops)
876 {
877 }
878 #endif
879 #else
880 static inline void
target_if_register_master_ext_handler(struct wlan_lmac_if_reg_tx_ops * reg_ops)881 target_if_register_master_ext_handler(struct wlan_lmac_if_reg_tx_ops *reg_ops)
882 {
883 }
884 
target_if_register_afc_event_handler(struct wlan_lmac_if_reg_tx_ops * reg_ops)885 static void target_if_register_afc_event_handler(
886 				struct wlan_lmac_if_reg_tx_ops *reg_ops)
887 {
888 }
889 
target_if_register_acs_trigger_for_afc(struct wlan_lmac_if_reg_tx_ops * reg_ops)890 static void target_if_register_acs_trigger_for_afc
891 				(struct wlan_lmac_if_reg_tx_ops *reg_ops)
892 {
893 }
894 #endif
895 
896 static QDF_STATUS
tgt_if_regulatory_set_tpc_power(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id,struct reg_tpc_power_info * param)897 tgt_if_regulatory_set_tpc_power(struct wlan_objmgr_psoc *psoc,
898 				uint8_t vdev_id,
899 				struct reg_tpc_power_info *param)
900 {
901 	wmi_unified_t wmi_handle;
902 	uint8_t pdev_id;
903 	struct wlan_objmgr_pdev *pdev;
904 	QDF_STATUS status;
905 
906 	pdev_id = wlan_get_pdev_id_from_vdev_id(psoc,
907 						vdev_id, WLAN_REGULATORY_NB_ID);
908 
909 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id,
910 					  WLAN_REGULATORY_NB_ID);
911 
912 	wmi_handle = get_wmi_unified_hdl_from_pdev(pdev);
913 
914 	if (!wmi_handle) {
915 		status = QDF_STATUS_E_FAILURE;
916 		goto free_pdevref;
917 	}
918 	status = wmi_unified_send_set_tpc_power_cmd(wmi_handle, vdev_id, param);
919 	if (QDF_IS_STATUS_ERROR(status))
920 		target_if_err("send tpc power cmd failed, status: %d", status);
921 
922 free_pdevref:
923 	wlan_objmgr_pdev_release_ref(pdev, WLAN_REGULATORY_NB_ID);
924 
925 	return status;
926 }
927 
928 #ifdef CONFIG_AFC_SUPPORT
929 /**
930  * tgt_if_regulatory_send_afc_cmd() - Send AFC command to the FW
931  *
932  * @psoc: Pointer to psoc
933  * @pdev_id: Pdev id
934  * @param: Pointer to hold AFC indication.
935  *
936  * Return: QDF_STATUS_SUCCESS if WMI_AFC_CMD is sent, else QDF_STATUS_E_FAILURE
937  */
938 static QDF_STATUS
tgt_if_regulatory_send_afc_cmd(struct wlan_objmgr_psoc * psoc,uint8_t pdev_id,struct reg_afc_resp_rx_ind_info * param)939 tgt_if_regulatory_send_afc_cmd(struct wlan_objmgr_psoc *psoc,
940 			       uint8_t pdev_id,
941 			       struct reg_afc_resp_rx_ind_info *param)
942 {
943 	struct wlan_objmgr_pdev *pdev;
944 	wmi_unified_t wmi_handle;
945 	QDF_STATUS status;
946 
947 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id,
948 					  WLAN_REGULATORY_NB_ID);
949 
950 	wmi_handle = get_wmi_unified_hdl_from_pdev(pdev);
951 
952 	if (!wmi_handle) {
953 		status = QDF_STATUS_E_FAILURE;
954 		goto free_pdevref;
955 	}
956 
957 	status = wmi_unified_send_afc_cmd(wmi_handle, pdev_id, param);
958 
959 	if (QDF_IS_STATUS_ERROR(status))
960 		target_if_err("send afc  cmd failed, status: %d", status);
961 
962 free_pdevref:
963 	wlan_objmgr_pdev_release_ref(pdev, WLAN_REGULATORY_NB_ID);
964 
965 	return status;
966 }
967 
968 static void
tgt_if_register_afc_callback(struct wlan_lmac_if_reg_tx_ops * reg_ops)969 tgt_if_register_afc_callback(struct wlan_lmac_if_reg_tx_ops *reg_ops)
970 {
971 	reg_ops->send_afc_ind = tgt_if_regulatory_send_afc_cmd;
972 	reg_ops->reg_get_min_psd = NULL;
973 	reg_ops->trigger_update_channel_list = NULL;
974 }
975 #else
976 static void
tgt_if_register_afc_callback(struct wlan_lmac_if_reg_tx_ops * reg_ops)977 tgt_if_register_afc_callback(struct wlan_lmac_if_reg_tx_ops *reg_ops)
978 {
979 }
980 #endif
981 
982 /**
983  * tgt_if_regulatory_is_ext_tpc_supported() - Check if FW supports new
984  * WMI command for TPC power
985  *
986  * @psoc: Pointer to psoc
987  *
988  * Return: true if FW supports new WMI command for TPC, else false
989  */
990 static bool
tgt_if_regulatory_is_ext_tpc_supported(struct wlan_objmgr_psoc * psoc)991 tgt_if_regulatory_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc)
992 {
993 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
994 
995 	if (!wmi_handle)
996 		return false;
997 
998 	return wmi_service_enabled(wmi_handle,
999 				   wmi_service_ext_tpc_reg_support);
1000 }
1001 
target_if_regulatory_set_ext_tpc(struct wlan_objmgr_psoc * psoc)1002 QDF_STATUS target_if_regulatory_set_ext_tpc(struct wlan_objmgr_psoc *psoc)
1003 {
1004 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1005 
1006 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1007 	if (!reg_rx_ops) {
1008 		target_if_err("reg_rx_ops is NULL");
1009 		return QDF_STATUS_E_FAILURE;
1010 	}
1011 
1012 	if (reg_rx_ops->reg_set_ext_tpc_supported)
1013 		reg_rx_ops->reg_set_ext_tpc_supported(
1014 			psoc,
1015 			tgt_if_regulatory_is_ext_tpc_supported(psoc));
1016 
1017 	return QDF_STATUS_SUCCESS;
1018 }
1019 
1020 #if defined(CONFIG_BAND_6GHZ) && defined(CONFIG_AFC_SUPPORT)
tgt_if_set_reg_afc_configure(struct target_psoc_info * tgt_hdl,struct wlan_objmgr_psoc * psoc)1021 void tgt_if_set_reg_afc_configure(struct target_psoc_info *tgt_hdl,
1022 				  struct wlan_objmgr_psoc *psoc)
1023 {
1024 	struct tgt_info *info;
1025 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1026 
1027 	if (!wmi_handle || !tgt_hdl)
1028 		return;
1029 
1030 	if (!wmi_service_enabled(wmi_handle, wmi_service_afc_support)) {
1031 		target_if_err("service afc support not enable");
1032 		return;
1033 	}
1034 
1035 	info = (&tgt_hdl->info);
1036 
1037 	info->wlan_res_cfg.is_6ghz_sp_pwrmode_supp_enabled =
1038 		ucfg_reg_get_enable_6ghz_sp_mode_support(psoc);
1039 	info->wlan_res_cfg.afc_timer_check_disable =
1040 		ucfg_reg_get_afc_disable_timer_check(psoc);
1041 	info->wlan_res_cfg.afc_req_id_check_disable =
1042 		ucfg_reg_get_afc_disable_request_id_check(psoc);
1043 }
1044 #endif
1045 
1046 #if defined(CONFIG_BAND_6GHZ)
1047 /**
1048  * tgt_if_regulatory_is_lower_6g_edge_ch_supp() - Check if lower 6 GHz
1049  * edge channel (5935 MHz) is supported
1050  * @psoc: Pointer to psoc
1051  *
1052  * Return: true if channel is supported, else false
1053  */
1054 static bool
tgt_if_regulatory_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc * psoc)1055 tgt_if_regulatory_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc)
1056 {
1057 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1058 
1059 	if (!wmi_handle)
1060 		return false;
1061 
1062 	return wmi_service_enabled(wmi_handle,
1063 				   wmi_service_lower_6g_edge_ch_supp);
1064 }
1065 
1066 /**
1067  * tgt_if_regulatory_is_upper_6g_edge_ch_disabled() - Check if upper
1068  * 6 GHz edge channel (7115 MHz) is disabled
1069  * @psoc: Pointer to psoc
1070  *
1071  * Return: true if channel is disabled, else false
1072  */
1073 static bool
tgt_if_regulatory_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc * psoc)1074 tgt_if_regulatory_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc)
1075 {
1076 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1077 
1078 	if (!wmi_handle)
1079 		return false;
1080 
1081 	return wmi_service_enabled(wmi_handle,
1082 				   wmi_service_disable_upper_6g_edge_ch_supp);
1083 }
1084 
1085 QDF_STATUS
target_if_reg_set_lower_6g_edge_ch_info(struct wlan_objmgr_psoc * psoc)1086 target_if_reg_set_lower_6g_edge_ch_info(struct wlan_objmgr_psoc *psoc)
1087 {
1088 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1089 
1090 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1091 	if (!reg_rx_ops) {
1092 		target_if_err("reg_rx_ops is NULL");
1093 		return QDF_STATUS_E_FAILURE;
1094 	}
1095 
1096 	if (reg_rx_ops->reg_set_lower_6g_edge_ch_supp)
1097 		reg_rx_ops->reg_set_lower_6g_edge_ch_supp(
1098 			psoc,
1099 			tgt_if_regulatory_is_lower_6g_edge_ch_supp(psoc));
1100 
1101 	return QDF_STATUS_SUCCESS;
1102 }
1103 
1104 QDF_STATUS
target_if_reg_set_disable_upper_6g_edge_ch_info(struct wlan_objmgr_psoc * psoc)1105 target_if_reg_set_disable_upper_6g_edge_ch_info(struct wlan_objmgr_psoc *psoc)
1106 {
1107 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1108 
1109 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1110 	if (!reg_rx_ops) {
1111 		target_if_err("reg_rx_ops is NULL");
1112 		return QDF_STATUS_E_FAILURE;
1113 	}
1114 
1115 	if (reg_rx_ops->reg_set_disable_upper_6g_edge_ch_supp)
1116 		reg_rx_ops->reg_set_disable_upper_6g_edge_ch_supp(
1117 			psoc,
1118 			tgt_if_regulatory_is_upper_6g_edge_ch_disabled(psoc));
1119 
1120 	return QDF_STATUS_SUCCESS;
1121 }
1122 #else
1123 static inline bool
tgt_if_regulatory_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc * psoc)1124 tgt_if_regulatory_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc)
1125 {
1126 	return false;
1127 }
1128 
1129 static inline bool
tgt_if_regulatory_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc * psoc)1130 tgt_if_regulatory_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc)
1131 {
1132 	return false;
1133 }
1134 #endif
1135 
1136 #if defined(CONFIG_AFC_SUPPORT)
1137 QDF_STATUS
target_if_reg_set_afc_dev_type(struct wlan_objmgr_psoc * psoc,struct target_psoc_info * tgt_hdl)1138 target_if_reg_set_afc_dev_type(struct wlan_objmgr_psoc *psoc,
1139 			       struct target_psoc_info *tgt_hdl)
1140 {
1141 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1142 	struct tgt_info *info;
1143 
1144 	if (!tgt_hdl) {
1145 		target_if_err("target_psoc_info is null");
1146 		return QDF_STATUS_E_FAILURE;
1147 	}
1148 
1149 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1150 	if (!reg_rx_ops) {
1151 		target_if_err("reg_rx_ops is NULL");
1152 		return QDF_STATUS_E_FAILURE;
1153 	}
1154 
1155 	info = (&tgt_hdl->info);
1156 
1157 	if (reg_rx_ops->reg_set_afc_dev_type)
1158 		reg_rx_ops->reg_set_afc_dev_type(
1159 			psoc,
1160 			info->service_ext2_param.afc_dev_type);
1161 
1162 	return QDF_STATUS_SUCCESS;
1163 }
1164 
1165 QDF_STATUS
target_if_reg_get_afc_dev_type(struct wlan_objmgr_psoc * psoc,enum reg_afc_dev_deploy_type * reg_afc_dev_type)1166 target_if_reg_get_afc_dev_type(struct wlan_objmgr_psoc *psoc,
1167 			       enum reg_afc_dev_deploy_type *reg_afc_dev_type)
1168 {
1169 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1170 
1171 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1172 	if (!reg_rx_ops) {
1173 		target_if_err("reg_rx_ops is NULL");
1174 		return QDF_STATUS_E_FAILURE;
1175 	}
1176 
1177 	if (reg_rx_ops->reg_get_afc_dev_type)
1178 		reg_rx_ops->reg_get_afc_dev_type(
1179 			psoc,
1180 			reg_afc_dev_type);
1181 
1182 	return QDF_STATUS_SUCCESS;
1183 }
1184 
1185 /**
1186  * target_if_regulatory_is_eirp_preferred_support() - Check if FW prefers EIRP
1187  * support for TPC power command.
1188  * @psoc: Pointer to psoc
1189  *
1190  * Return: true if FW prefers EIRP format for TPC, else false
1191  */
1192 static bool
target_if_regulatory_is_eirp_preferred_support(struct wlan_objmgr_psoc * psoc)1193 target_if_regulatory_is_eirp_preferred_support(struct wlan_objmgr_psoc *psoc)
1194 {
1195 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1196 
1197 	if (!wmi_handle)
1198 		return false;
1199 
1200 	return wmi_service_enabled(wmi_handle,
1201 				   wmi_service_eirp_preferred_support);
1202 }
1203 
1204 QDF_STATUS
target_if_set_regulatory_eirp_preferred_support(struct wlan_objmgr_psoc * psoc)1205 target_if_set_regulatory_eirp_preferred_support(struct wlan_objmgr_psoc *psoc)
1206 {
1207 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1208 
1209 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1210 	if (!reg_rx_ops) {
1211 		target_if_err("reg_rx_ops is NULL");
1212 		return QDF_STATUS_E_FAILURE;
1213 	}
1214 
1215 	if (reg_rx_ops->reg_set_eirp_preferred_support)
1216 		reg_rx_ops->reg_set_eirp_preferred_support(
1217 			psoc,
1218 			target_if_regulatory_is_eirp_preferred_support(psoc));
1219 
1220 	return QDF_STATUS_SUCCESS;
1221 }
1222 #endif
1223 
1224 /**
1225  * tgt_if_reg_is_chip_11be_cap() - Finds out if the hardware is capable
1226  * of 11BE. The capability bit is read from mac_phy_cap populated by the
1227  * FW per pdev.
1228  * @psoc: Pointer to psoc
1229  * @phy_id: phy_id
1230  *
1231  * Return: True if chip is 11BE capable, false otherwise.
1232  */
1233 #ifdef WLAN_FEATURE_11BE
tgt_if_reg_is_chip_11be_cap(struct wlan_objmgr_psoc * psoc,uint16_t phy_id)1234 static bool tgt_if_reg_is_chip_11be_cap(struct wlan_objmgr_psoc *psoc,
1235 					uint16_t phy_id)
1236 {
1237 	struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr, *mac_phy_cap;
1238 	struct target_psoc_info *tgt_hdl;
1239 	uint8_t pdev_id;
1240 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
1241 
1242 	reg_tx_ops = target_if_regulatory_get_tx_ops(psoc);
1243 
1244 	if (!reg_tx_ops) {
1245 		target_if_err("reg_tx_ops is NULL");
1246 		return false;
1247 	}
1248 
1249 	if (reg_tx_ops->get_pdev_id_from_phy_id)
1250 		reg_tx_ops->get_pdev_id_from_phy_id(psoc, phy_id, &pdev_id);
1251 	else
1252 		pdev_id = phy_id;
1253 
1254 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1255 	if (tgt_hdl) {
1256 		mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_hdl);
1257 		if (!mac_phy_cap_arr)
1258 			return false;
1259 		mac_phy_cap = &mac_phy_cap_arr[pdev_id];
1260 		if (mac_phy_cap && mac_phy_cap->supports_11be)
1261 			return true;
1262 	}
1263 	return false;
1264 }
1265 #else
tgt_if_reg_is_chip_11be_cap(struct wlan_objmgr_psoc * psoc,uint16_t phy_id)1266 static bool tgt_if_reg_is_chip_11be_cap(struct wlan_objmgr_psoc *psoc,
1267 					uint16_t phy_id)
1268 {
1269 	return false;
1270 }
1271 #endif
1272 
1273 static int
tgt_rate_to_power_complete_handler(ol_scn_t handle,uint8_t * event_buf,uint32_t len)1274 tgt_rate_to_power_complete_handler(ol_scn_t handle, uint8_t *event_buf,
1275 				   uint32_t len)
1276 {
1277 	int ret_val = 0;
1278 	struct wlan_objmgr_psoc *psoc;
1279 	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
1280 	QDF_STATUS status;
1281 	struct wmi_unified *wmi_handle;
1282 	struct r2p_table_update_status_obj *update_status_obj = NULL;
1283 	uint32_t pdev_id;
1284 
1285 	TARGET_IF_ENTER();
1286 
1287 	psoc = target_if_get_psoc_from_scn_hdl(handle);
1288 	if (!psoc) {
1289 		target_if_err("psoc ptr is NULL");
1290 		ret_val = -EINVAL;
1291 		goto clean;
1292 	}
1293 
1294 	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
1295 	if (!reg_rx_ops) {
1296 		target_if_err("reg_rx_ops is NULL");
1297 		ret_val = -EINVAL;
1298 		goto clean;
1299 	}
1300 
1301 	if (!reg_rx_ops->reg_r2p_table_update_response_handler) {
1302 		target_if_err("reg_r2p_table_update_response_handler is NULL");
1303 		ret_val = -EINVAL;
1304 		goto clean;
1305 	}
1306 
1307 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1308 	if (!wmi_handle) {
1309 		target_if_err("invalid wmi handle");
1310 		ret_val = -EINVAL;
1311 		goto clean;
1312 	}
1313 
1314 	update_status_obj = qdf_mem_malloc(sizeof(*update_status_obj));
1315 	if (!update_status_obj) {
1316 		ret_val = -ENOMEM;
1317 		goto clean;
1318 	}
1319 
1320 	status = wmi_extract_tgtr2p_table_event(wmi_handle, event_buf,
1321 						update_status_obj, len);
1322 	if (!QDF_IS_STATUS_SUCCESS(status)) {
1323 		target_if_err("Extraction of r2p update response event failed");
1324 		ret_val = -EFAULT;
1325 		goto clean;
1326 	}
1327 
1328 	pdev_id = update_status_obj->pdev_id;
1329 	status = reg_rx_ops->reg_r2p_table_update_response_handler(psoc,
1330 								   pdev_id);
1331 	if (!QDF_IS_STATUS_SUCCESS(status)) {
1332 		target_if_err("Failed to process r2p update response");
1333 		ret_val = -EFAULT;
1334 		goto clean;
1335 	}
1336 clean:
1337 	qdf_mem_free(update_status_obj);
1338 	TARGET_IF_EXIT();
1339 
1340 	return ret_val;
1341 }
1342 
1343 /**
1344  * tgt_if_regulatory_register_rate2power_table_update_handler() - Register
1345  * rate2power table update handler
1346  * @psoc: Pointer to psoc
1347  * @arg: Pointer to argument list
1348  *
1349  * Return: QDF_STATUS
1350  */
1351 static QDF_STATUS
tgt_if_regulatory_register_rate2power_table_update_handler(struct wlan_objmgr_psoc * psoc,void * arg)1352 tgt_if_regulatory_register_rate2power_table_update_handler(
1353 						struct wlan_objmgr_psoc *psoc,
1354 						void *arg)
1355 {
1356 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1357 
1358 	if (!wmi_handle)
1359 		return QDF_STATUS_E_FAILURE;
1360 
1361 	return wmi_unified_register_event_handler(
1362 			wmi_handle, wmi_pdev_set_tgtr2p_table_eventid,
1363 			tgt_rate_to_power_complete_handler, WMI_RX_WORK_CTX);
1364 }
1365 
1366 /**
1367  * tgt_if_regulatory_unregister_rate2power_table_update_handler() - Unregister
1368  * rate2power table update handler
1369  * @psoc: Pointer to psoc
1370  * @arg: Pointer to argument list
1371  *
1372  * Return: QDF_STATUS
1373  */
1374 static QDF_STATUS
tgt_if_regulatory_unregister_rate2power_table_update_handler(struct wlan_objmgr_psoc * psoc,void * arg)1375 tgt_if_regulatory_unregister_rate2power_table_update_handler(
1376 						struct wlan_objmgr_psoc *psoc,
1377 						void *arg)
1378 {
1379 	wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
1380 
1381 	if (!wmi_handle)
1382 		return QDF_STATUS_E_FAILURE;
1383 
1384 	return wmi_unified_unregister_event_handler(
1385 			wmi_handle, wmi_pdev_set_tgtr2p_table_eventid);
1386 }
1387 
target_if_register_regulatory_tx_ops(struct wlan_lmac_if_tx_ops * tx_ops)1388 QDF_STATUS target_if_register_regulatory_tx_ops(
1389 		struct wlan_lmac_if_tx_ops *tx_ops)
1390 {
1391 	struct wlan_lmac_if_reg_tx_ops *reg_ops = &tx_ops->reg_ops;
1392 
1393 	reg_ops->register_master_handler =
1394 		tgt_if_regulatory_register_master_list_handler;
1395 
1396 	reg_ops->unregister_master_handler =
1397 		tgt_if_regulatory_unregister_master_list_handler;
1398 
1399 	target_if_register_master_ext_handler(reg_ops);
1400 
1401 	target_if_register_afc_event_handler(reg_ops);
1402 
1403 	reg_ops->set_country_code = tgt_if_regulatory_set_country_code;
1404 
1405 	reg_ops->fill_umac_legacy_chanlist = NULL;
1406 
1407 	reg_ops->set_wait_for_init_cc_response_event = NULL;
1408 
1409 	target_if_register_acs_trigger_for_afc(reg_ops);
1410 
1411 	reg_ops->register_11d_new_cc_handler =
1412 		tgt_if_regulatory_register_11d_new_cc_handler;
1413 
1414 	reg_ops->unregister_11d_new_cc_handler =
1415 		tgt_if_regulatory_unregister_11d_new_cc_handler;
1416 
1417 	reg_ops->start_11d_scan = tgt_if_regulatory_start_11d_scan;
1418 
1419 	reg_ops->stop_11d_scan = tgt_if_regulatory_stop_11d_scan;
1420 
1421 	reg_ops->is_there_serv_ready_extn =
1422 		tgt_if_regulatory_is_there_serv_ready_extn;
1423 
1424 	reg_ops->set_user_country_code =
1425 		tgt_if_regulatory_set_user_country_code;
1426 
1427 	reg_ops->register_ch_avoid_event_handler =
1428 		tgt_if_regulatory_register_ch_avoid_event_handler;
1429 
1430 	reg_ops->unregister_ch_avoid_event_handler =
1431 		tgt_if_regulatory_unregister_ch_avoid_event_handler;
1432 
1433 	reg_ops->send_ctl_info = tgt_if_regulatory_send_ctl_info;
1434 
1435 	reg_ops->get_phy_id_from_pdev_id =
1436 			tgt_if_regulatory_get_phy_id_from_pdev_id;
1437 
1438 	reg_ops->get_pdev_id_from_phy_id =
1439 			tgt_if_regulatory_get_pdev_id_from_phy_id;
1440 
1441 	reg_ops->set_tpc_power = tgt_if_regulatory_set_tpc_power;
1442 
1443 	reg_ops->get_opclass_tbl_idx = NULL;
1444 
1445 	tgt_if_register_afc_callback(reg_ops);
1446 
1447 	reg_ops->is_chip_11be = tgt_if_reg_is_chip_11be_cap;
1448 
1449 	reg_ops->register_rate2power_table_update_event_handler =
1450 		tgt_if_regulatory_register_rate2power_table_update_handler;
1451 
1452 	reg_ops->unregister_rate2power_table_update_event_handler =
1453 		tgt_if_regulatory_unregister_rate2power_table_update_handler;
1454 
1455 	reg_ops->end_r2p_table_update_wait = NULL;
1456 
1457 	reg_ops->is_80p80_supported = NULL;
1458 
1459 	reg_ops->is_freq_80p80_supported = NULL;
1460 
1461 	return QDF_STATUS_SUCCESS;
1462 }
1463