xref: /wlan-dirver/qca-wifi-host-cmn/target_if/core/src/target_if_main.c (revision 97f44cd39e4ff816eaa1710279d28cf6b9e65ad9)
1 /*
2  * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: API for interacting with target interface.
21  *
22  */
23 
24 #include "target_if.h"
25 #include "target_type.h"
26 #ifdef WLAN_ATF_ENABLE
27 #include "target_if_atf.h"
28 #endif
29 #ifdef WLAN_SA_API_ENABLE
30 #include "target_if_sa_api.h"
31 #endif
32 #ifdef WLAN_CFR_ENABLE
33 #include "target_if_cfr.h"
34 #endif
35 #ifdef WLAN_CONV_SPECTRAL_ENABLE
36 #include "target_if_spectral.h"
37 #endif
38 
39 #ifdef WLAN_IOT_SIM_SUPPORT
40 #include <target_if_iot_sim.h>
41 #endif
42 #include <target_if_reg.h>
43 #include <target_if_scan.h>
44 #include <target_if_ftm.h>
45 #ifdef DFS_COMPONENT_ENABLE
46 #include <target_if_dfs.h>
47 #endif
48 
49 #ifdef CONVERGED_P2P_ENABLE
50 #include "target_if_p2p.h"
51 #endif
52 
53 #ifdef WIFI_POS_CONVERGED
54 #include "target_if_wifi_pos.h"
55 #endif
56 
57 #ifdef FEATURE_WLAN_TDLS
58 #include "target_if_tdls.h"
59 #endif
60 #ifdef QCA_SUPPORT_SON
61 #include <target_if_son.h>
62 #endif
63 #ifdef WLAN_OFFCHAN_TXRX_ENABLE
64 #include <target_if_offchan_txrx_api.h>
65 #endif
66 #ifdef WLAN_SUPPORT_GREEN_AP
67 #include <target_if_green_ap.h>
68 #endif
69 #include <init_deinit_lmac.h>
70 #include <service_ready_util.h>
71 
72 #ifdef DIRECT_BUF_RX_ENABLE
73 #include <target_if_direct_buf_rx_api.h>
74 #endif
75 
76 #ifdef WLAN_SUPPORT_FILS
77 #include <target_if_fd.h>
78 #endif
79 #include "qdf_module.h"
80 
81 #include <target_if_cp_stats.h>
82 #ifdef CRYPTO_SET_KEY_CONVERGED
83 #include <target_if_crypto.h>
84 #endif
85 #include <target_if_vdev_mgr_tx_ops.h>
86 
87 #ifdef FEATURE_COEX
88 #include <target_if_coex.h>
89 #endif
90 #include <wlan_utility.h>
91 
92 #ifdef DCS_INTERFERENCE_DETECTION
93 #include <target_if_dcs.h>
94 #endif
95 
96 #include <target_if_gpio.h>
97 
98 static struct target_if_ctx *g_target_if_ctx;
99 
100 struct target_if_ctx *target_if_get_ctx()
101 {
102 	return g_target_if_ctx;
103 }
104 
105 struct wlan_objmgr_psoc *target_if_get_psoc_from_scn_hdl(void *scn_handle)
106 {
107 	struct wlan_objmgr_psoc *psoc;
108 
109 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
110 	if (scn_handle && g_target_if_ctx->get_psoc_hdl_cb)
111 		psoc = g_target_if_ctx->get_psoc_hdl_cb(scn_handle);
112 	else
113 		psoc = NULL;
114 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
115 
116 	return psoc;
117 }
118 
119 struct wlan_objmgr_pdev *target_if_get_pdev_from_scn_hdl(void *scn_handle)
120 {
121 	struct wlan_objmgr_pdev *pdev;
122 
123 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
124 	if (scn_handle && g_target_if_ctx->get_pdev_hdl_cb)
125 		pdev = g_target_if_ctx->get_pdev_hdl_cb(scn_handle);
126 	else
127 		pdev = NULL;
128 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
129 
130 	return pdev;
131 }
132 
133 #ifdef DIRECT_BUF_RX_ENABLE
134 static QDF_STATUS target_if_direct_buf_rx_init(void)
135 {
136 	return direct_buf_rx_init();
137 }
138 
139 static QDF_STATUS target_if_direct_buf_rx_deinit(void)
140 {
141 	return direct_buf_rx_deinit();
142 }
143 #else
144 static QDF_STATUS target_if_direct_buf_rx_init(void)
145 {
146 	return QDF_STATUS_SUCCESS;
147 }
148 
149 static QDF_STATUS target_if_direct_buf_rx_deinit(void)
150 {
151 	return QDF_STATUS_SUCCESS;
152 }
153 #endif /* DIRECT_BUF_RX_ENABLE */
154 
155 QDF_STATUS target_if_init(get_psoc_handle_callback psoc_hdl_cb)
156 {
157 	g_target_if_ctx = qdf_mem_malloc(sizeof(*g_target_if_ctx));
158 	if (!g_target_if_ctx) {
159 		QDF_ASSERT(0);
160 		return QDF_STATUS_E_NOMEM;
161 	}
162 
163 	qdf_spinlock_create(&g_target_if_ctx->lock);
164 
165 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
166 	g_target_if_ctx->magic = TGT_MAGIC;
167 	g_target_if_ctx->get_psoc_hdl_cb = psoc_hdl_cb;
168 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
169 
170 	target_if_direct_buf_rx_init();
171 
172 	return QDF_STATUS_SUCCESS;
173 }
174 
175 QDF_STATUS target_if_deinit(void)
176 {
177 	if (!g_target_if_ctx) {
178 		QDF_ASSERT(0);
179 		target_if_err("target if ctx is null");
180 		return QDF_STATUS_E_INVAL;
181 	}
182 
183 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
184 	g_target_if_ctx->magic = 0;
185 	g_target_if_ctx->get_psoc_hdl_cb = NULL;
186 	g_target_if_ctx->get_pdev_hdl_cb = NULL;
187 	g_target_if_ctx->service_ready_cb = NULL;
188 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
189 
190 	qdf_spinlock_destroy(&g_target_if_ctx->lock);
191 	qdf_mem_free(g_target_if_ctx);
192 	g_target_if_ctx = NULL;
193 
194 	target_if_direct_buf_rx_deinit();
195 
196 	return QDF_STATUS_SUCCESS;
197 }
198 
199 qdf_export_symbol(target_if_deinit);
200 
201 QDF_STATUS target_if_store_pdev_target_if_ctx(
202 		get_pdev_handle_callback pdev_hdl_cb)
203 {
204 	if (!g_target_if_ctx) {
205 		QDF_ASSERT(0);
206 		target_if_err("target if ctx is null");
207 		return QDF_STATUS_E_INVAL;
208 	}
209 
210 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
211 	g_target_if_ctx->get_pdev_hdl_cb = pdev_hdl_cb;
212 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
213 
214 	return QDF_STATUS_SUCCESS;
215 }
216 
217 #ifndef WLAN_OFFCHAN_TXRX_ENABLE
218 static void target_if_offchan_txrx_ops_register(
219 					struct wlan_lmac_if_tx_ops *tx_ops)
220 {
221 }
222 #endif /* WLAN_OFFCHAN_TXRX_ENABLE */
223 
224 #ifndef WLAN_ATF_ENABLE
225 static void target_if_atf_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
226 {
227 }
228 #endif /* WLAN_ATF_ENABLE */
229 
230 #ifndef WLAN_SA_API_ENABLE
231 static void target_if_sa_api_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
232 {
233 }
234 #endif /* WLAN_SA_API_ENABLE */
235 
236 #ifndef WLAN_CFR_ENABLE
237 static void target_if_cfr_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
238 {
239 }
240 #endif
241 
242 #ifdef WLAN_SUPPORT_FILS
243 static void target_if_fd_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
244 {
245 	target_if_fd_register_tx_ops(tx_ops);
246 }
247 #else
248 static void target_if_fd_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
249 {
250 }
251 #endif
252 
253 #ifdef WIFI_POS_CONVERGED
254 static void target_if_wifi_pos_tx_ops_register(
255 			struct wlan_lmac_if_tx_ops *tx_ops)
256 {
257 	target_if_wifi_pos_register_tx_ops(tx_ops);
258 }
259 #else
260 static void target_if_wifi_pos_tx_ops_register(
261 			struct wlan_lmac_if_tx_ops *tx_ops)
262 {
263 }
264 #endif
265 #ifdef QCA_SUPPORT_SON
266 static void target_if_son_tx_ops_register(
267 			struct wlan_lmac_if_tx_ops *tx_ops)
268 {
269 	target_if_son_register_tx_ops(tx_ops);
270 	return;
271 }
272 #else
273 static void target_if_son_tx_ops_register(
274 			struct wlan_lmac_if_tx_ops *tx_ops)
275 {
276 	return;
277 }
278 #endif
279 
280 #ifdef FEATURE_WLAN_TDLS
281 static void target_if_tdls_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
282 {
283 	target_if_tdls_register_tx_ops(tx_ops);
284 }
285 #else
286 static void target_if_tdls_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
287 {
288 }
289 #endif /* FEATURE_WLAN_TDLS */
290 
291 #ifdef DFS_COMPONENT_ENABLE
292 static void target_if_dfs_tx_ops_register(
293 				struct wlan_lmac_if_tx_ops *tx_ops)
294 {
295 	target_if_register_dfs_tx_ops(tx_ops);
296 }
297 #else
298 static void target_if_dfs_tx_ops_register(
299 				struct wlan_lmac_if_tx_ops *tx_ops)
300 {
301 }
302 #endif /* DFS_COMPONENT_ENABLE */
303 
304 #ifdef WLAN_CONV_SPECTRAL_ENABLE
305 static void target_if_sptrl_tx_ops_register(
306 				struct wlan_lmac_if_tx_ops *tx_ops)
307 {
308 	target_if_sptrl_register_tx_ops(tx_ops);
309 }
310 #else
311 static void target_if_sptrl_tx_ops_register(
312 				struct wlan_lmac_if_tx_ops *tx_ops)
313 {
314 }
315 #endif /* WLAN_CONV_SPECTRAL_ENABLE */
316 
317 #ifdef WLAN_IOT_SIM_SUPPORT
318 static void target_if_iot_sim_tx_ops_register(
319 				struct wlan_lmac_if_tx_ops *tx_ops)
320 {
321 	target_if_iot_sim_register_tx_ops(tx_ops);
322 }
323 #else
324 static void target_if_iot_sim_tx_ops_register(
325 				struct wlan_lmac_if_tx_ops *tx_ops)
326 {
327 }
328 #endif
329 
330 #ifdef DIRECT_BUF_RX_ENABLE
331 static void target_if_direct_buf_rx_tx_ops_register(
332 				struct wlan_lmac_if_tx_ops *tx_ops)
333 {
334 	target_if_direct_buf_rx_register_tx_ops(tx_ops);
335 }
336 #else
337 static void target_if_direct_buf_rx_tx_ops_register(
338 				struct wlan_lmac_if_tx_ops *tx_ops)
339 {
340 }
341 #endif /* DIRECT_BUF_RX_ENABLE */
342 
343 #ifdef WLAN_SUPPORT_GREEN_AP
344 static QDF_STATUS target_if_green_ap_tx_ops_register(
345 				struct wlan_lmac_if_tx_ops *tx_ops)
346 {
347 	return target_if_register_green_ap_tx_ops(tx_ops);
348 }
349 #else
350 static QDF_STATUS target_if_green_ap_tx_ops_register(
351 				struct wlan_lmac_if_tx_ops *tx_ops)
352 {
353 	return QDF_STATUS_SUCCESS;
354 }
355 #endif /* WLAN_SUPPORT_GREEN_AP */
356 #if defined(WLAN_CONV_CRYPTO_SUPPORTED) && defined(CRYPTO_SET_KEY_CONVERGED)
357 static void target_if_crypto_tx_ops_register(
358 				struct wlan_lmac_if_tx_ops *tx_ops)
359 {
360 	target_if_crypto_register_tx_ops(tx_ops);
361 }
362 #else
363 static inline void target_if_crypto_tx_ops_register(
364 				struct wlan_lmac_if_tx_ops *tx_ops)
365 {
366 }
367 #endif
368 
369 #ifdef FEATURE_COEX
370 static QDF_STATUS
371 target_if_coex_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
372 {
373 	return target_if_coex_register_tx_ops(tx_ops);
374 }
375 #else
376 static inline QDF_STATUS
377 target_if_coex_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
378 {
379 	return QDF_STATUS_SUCCESS;
380 }
381 #endif
382 
383 static void target_if_target_tx_ops_register(
384 		struct wlan_lmac_if_tx_ops *tx_ops)
385 {
386 	struct wlan_lmac_if_target_tx_ops *target_tx_ops;
387 
388 	if (!tx_ops) {
389 		target_if_err("invalid tx_ops");
390 		return;
391 	}
392 
393 	target_tx_ops = &tx_ops->target_tx_ops;
394 
395 	target_tx_ops->tgt_is_tgt_type_ar900b =
396 		target_is_tgt_type_ar900b;
397 
398 	target_tx_ops->tgt_is_tgt_type_ipq4019 =
399 		target_is_tgt_type_ipq4019;
400 
401 	target_tx_ops->tgt_is_tgt_type_qca9984 =
402 		target_is_tgt_type_qca9984;
403 
404 	target_tx_ops->tgt_is_tgt_type_qca9888 =
405 		target_is_tgt_type_qca9888;
406 
407 	target_tx_ops->tgt_is_tgt_type_adrastea =
408 		target_is_tgt_type_adrastea;
409 
410 	target_tx_ops->tgt_is_tgt_type_qcn9000 =
411 		target_is_tgt_type_qcn9000;
412 
413 	target_tx_ops->tgt_is_tgt_type_qcn9100 =
414 		target_is_tgt_type_qcn9100;
415 
416 	target_tx_ops->tgt_get_tgt_type =
417 		lmac_get_tgt_type;
418 
419 	target_tx_ops->tgt_get_tgt_version =
420 		lmac_get_tgt_version;
421 
422 	target_tx_ops->tgt_get_tgt_revision =
423 		lmac_get_tgt_revision;
424 }
425 
426 static QDF_STATUS
427 target_if_cp_stats_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
428 {
429 	return target_if_cp_stats_register_tx_ops(tx_ops);
430 }
431 
432 #ifdef DCS_INTERFERENCE_DETECTION
433 static QDF_STATUS
434 target_if_dcs_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
435 {
436 	return target_if_dcs_register_tx_ops(tx_ops);
437 }
438 #else
439 static QDF_STATUS
440 target_if_dcs_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
441 {
442 	return QDF_STATUS_SUCCESS;
443 }
444 #endif
445 
446 static QDF_STATUS
447 target_if_vdev_mgr_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
448 {
449 	return target_if_vdev_mgr_register_tx_ops(tx_ops);
450 }
451 
452 #ifdef QCA_WIFI_FTM
453 static
454 void target_if_ftm_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
455 {
456 	target_if_ftm_register_tx_ops(tx_ops);
457 }
458 #else
459 static
460 void target_if_ftm_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
461 {
462 }
463 #endif
464 
465 #ifdef WLAN_FEATURE_GPIO_CFG
466 static
467 void target_if_gpio_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
468 {
469 	target_if_gpio_register_tx_ops(tx_ops);
470 }
471 #else
472 static
473 void target_if_gpio_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
474 {
475 }
476 #endif
477 
478 static
479 QDF_STATUS target_if_register_umac_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
480 {
481 	/* call regulatory callback to register tx ops */
482 	target_if_register_regulatory_tx_ops(tx_ops);
483 
484 	/* call umac callback to register legacy tx ops */
485 	wlan_lmac_if_umac_tx_ops_register(tx_ops);
486 
487 	/* Register scan tx ops */
488 	target_if_scan_tx_ops_register(tx_ops);
489 
490 	target_if_atf_tx_ops_register(tx_ops);
491 
492 	target_if_sa_api_tx_ops_register(tx_ops);
493 
494 	target_if_cfr_tx_ops_register(tx_ops);
495 
496 	target_if_wifi_pos_tx_ops_register(tx_ops);
497 
498 	target_if_dfs_tx_ops_register(tx_ops);
499 
500 	target_if_son_tx_ops_register(tx_ops);
501 
502 	target_if_tdls_tx_ops_register(tx_ops);
503 
504 	target_if_fd_tx_ops_register(tx_ops);
505 
506 	target_if_target_tx_ops_register(tx_ops);
507 
508 	target_if_offchan_txrx_ops_register(tx_ops);
509 
510 	target_if_green_ap_tx_ops_register(tx_ops);
511 
512 	target_if_ftm_tx_ops_register(tx_ops);
513 
514 	target_if_cp_stats_tx_ops_register(tx_ops);
515 
516 	target_if_dcs_tx_ops_register(tx_ops);
517 
518 	target_if_crypto_tx_ops_register(tx_ops);
519 
520 	target_if_vdev_mgr_tx_ops_register(tx_ops);
521 
522 	target_if_coex_tx_ops_register(tx_ops);
523 
524 	target_if_gpio_tx_ops_register(tx_ops);
525 
526 	/* Converged UMAC components to register their TX-ops here */
527 	return QDF_STATUS_SUCCESS;
528 }
529 
530 QDF_STATUS target_if_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
531 {
532 	/* Converged UMAC components to register their TX-ops */
533 	target_if_register_umac_tx_ops(tx_ops);
534 
535 	/* Components parallel to UMAC to register their TX-ops here */
536 	target_if_sptrl_tx_ops_register(tx_ops);
537 
538 	target_if_iot_sim_tx_ops_register(tx_ops);
539 
540 	/* Register direct buffer rx component tx ops here */
541 	target_if_direct_buf_rx_tx_ops_register(tx_ops);
542 
543 #ifdef CONVERGED_P2P_ENABLE
544 	/* Converged UMAC components to register P2P TX-ops */
545 	target_if_p2p_register_tx_ops(tx_ops);
546 #endif
547 
548 	return QDF_STATUS_SUCCESS;
549 }
550 qdf_export_symbol(target_if_register_tx_ops);
551 
552 wmi_legacy_service_ready_callback
553 target_if_get_psoc_legacy_service_ready_cb(void)
554 {
555 	wmi_legacy_service_ready_callback service_ready_cb;
556 
557 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
558 	if (g_target_if_ctx->service_ready_cb)
559 		service_ready_cb = g_target_if_ctx->service_ready_cb;
560 	else
561 		service_ready_cb = NULL;
562 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
563 
564 	return service_ready_cb;
565 }
566 qdf_export_symbol(target_if_get_psoc_legacy_service_ready_cb);
567 
568 QDF_STATUS target_if_register_legacy_service_ready_cb(
569 	wmi_legacy_service_ready_callback service_ready_cb)
570 {
571 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
572 	g_target_if_ctx->service_ready_cb = service_ready_cb;
573 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
574 
575 	return QDF_STATUS_SUCCESS;
576 }
577 qdf_export_symbol(target_if_register_legacy_service_ready_cb);
578 
579 QDF_STATUS target_if_alloc_pdev_tgt_info(struct wlan_objmgr_pdev *pdev)
580 {
581 	struct target_pdev_info *tgt_pdev_info;
582 
583 	if (!pdev) {
584 		target_if_err("pdev is null");
585 		return QDF_STATUS_E_INVAL;
586 	}
587 
588 	tgt_pdev_info = qdf_mem_malloc(sizeof(*tgt_pdev_info));
589 
590 	if (!tgt_pdev_info)
591 		return QDF_STATUS_E_NOMEM;
592 
593 	wlan_pdev_set_tgt_if_handle(pdev, tgt_pdev_info);
594 
595 	return QDF_STATUS_SUCCESS;
596 }
597 
598 QDF_STATUS target_if_free_pdev_tgt_info(struct wlan_objmgr_pdev *pdev)
599 {
600 	struct target_pdev_info *tgt_pdev_info;
601 
602 	if (!pdev) {
603 		target_if_err("pdev is null");
604 		return QDF_STATUS_E_INVAL;
605 	}
606 
607 	tgt_pdev_info = wlan_pdev_get_tgt_if_handle(pdev);
608 
609 	wlan_pdev_set_tgt_if_handle(pdev, NULL);
610 
611 	qdf_mem_free(tgt_pdev_info);
612 
613 	return QDF_STATUS_SUCCESS;
614 }
615 
616 QDF_STATUS target_if_alloc_psoc_tgt_info(struct wlan_objmgr_psoc *psoc)
617 {
618 	struct target_psoc_info *tgt_psoc_info;
619 
620 	if (!psoc) {
621 		target_if_err("psoc is null");
622 		return QDF_STATUS_E_INVAL;
623 	}
624 
625 	tgt_psoc_info = qdf_mem_malloc(sizeof(*tgt_psoc_info));
626 
627 	if (!tgt_psoc_info)
628 		return QDF_STATUS_E_NOMEM;
629 
630 	wlan_psoc_set_tgt_if_handle(psoc, tgt_psoc_info);
631 	target_psoc_set_preferred_hw_mode(tgt_psoc_info, WMI_HOST_HW_MODE_MAX);
632 	wlan_minidump_log(tgt_psoc_info,
633 			  sizeof(*tgt_psoc_info), psoc,
634 			  WLAN_MD_OBJMGR_PSOC_TGT_INFO, "target_psoc_info");
635 
636 	qdf_event_create(&tgt_psoc_info->info.event);
637 
638 	return QDF_STATUS_SUCCESS;
639 }
640 
641 QDF_STATUS target_if_free_psoc_tgt_info(struct wlan_objmgr_psoc *psoc)
642 {
643 	struct target_psoc_info *tgt_psoc_info;
644 	struct wlan_psoc_host_service_ext_param *ext_param;
645 
646 	if (!psoc) {
647 		target_if_err("psoc is null");
648 		return QDF_STATUS_E_INVAL;
649 	}
650 
651 	tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
652 
653 	ext_param = target_psoc_get_service_ext_param(tgt_psoc_info);
654 	if (!ext_param) {
655 		target_if_err("tgt_psoc_info is NULL");
656 		return QDF_STATUS_E_INVAL;
657 	}
658 	init_deinit_chainmask_table_free(ext_param);
659 	init_deinit_dbr_ring_cap_free(tgt_psoc_info);
660 	init_deinit_spectral_scaling_params_free(tgt_psoc_info);
661 	init_deinit_scan_radio_cap_free(tgt_psoc_info);
662 
663 	qdf_event_destroy(&tgt_psoc_info->info.event);
664 
665 	wlan_psoc_set_tgt_if_handle(psoc, NULL);
666 
667 	wlan_minidump_remove(tgt_psoc_info);
668 	qdf_mem_free(tgt_psoc_info);
669 
670 	return QDF_STATUS_SUCCESS;
671 }
672 
673 bool target_is_tgt_type_ar900b(uint32_t target_type)
674 {
675 	return target_type == TARGET_TYPE_AR900B;
676 }
677 
678 bool target_is_tgt_type_ipq4019(uint32_t target_type)
679 {
680 	return target_type == TARGET_TYPE_IPQ4019;
681 }
682 
683 bool target_is_tgt_type_qca9984(uint32_t target_type)
684 {
685 	return target_type == TARGET_TYPE_QCA9984;
686 }
687 
688 bool target_is_tgt_type_qca9888(uint32_t target_type)
689 {
690 	return target_type == TARGET_TYPE_QCA9888;
691 }
692 
693 bool target_is_tgt_type_adrastea(uint32_t target_type)
694 {
695 	return target_type == TARGET_TYPE_ADRASTEA;
696 }
697 
698 bool target_is_tgt_type_qcn9000(uint32_t target_type)
699 {
700 	return target_type == TARGET_TYPE_QCN9000;
701 }
702 
703 bool target_is_tgt_type_qcn9100(uint32_t target_type)
704 {
705 	return target_type == TARGET_TYPE_QCN9100;
706 }
707 
708 QDF_STATUS
709 target_pdev_is_scan_radio_supported(struct wlan_objmgr_pdev *pdev,
710 				    bool *is_scan_radio_supported)
711 {
712 	struct wlan_objmgr_psoc *psoc;
713 	struct wlan_psoc_host_scan_radio_caps *scan_radio_caps;
714 	uint8_t cap_idx;
715 	uint32_t num_scan_radio_caps;
716 	int32_t phy_id;
717 	struct target_psoc_info *tgt_psoc_info;
718 	struct target_pdev_info *tgt_pdev;
719 
720 	if (!is_scan_radio_supported) {
721 		target_if_err("input argument is null");
722 		return QDF_STATUS_E_INVAL;
723 	}
724 	*is_scan_radio_supported = false;
725 
726 	if (!pdev) {
727 		target_if_err("pdev is null");
728 		return QDF_STATUS_E_INVAL;
729 	}
730 
731 	psoc = wlan_pdev_get_psoc(pdev);
732 	if (!psoc) {
733 		target_if_err("psoc is null");
734 		return QDF_STATUS_E_INVAL;
735 	}
736 
737 	tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
738 	if (!tgt_psoc_info) {
739 		target_if_err("target_psoc_info is null");
740 		return QDF_STATUS_E_INVAL;
741 	}
742 
743 	num_scan_radio_caps =
744 		target_psoc_get_num_scan_radio_caps(tgt_psoc_info);
745 	if (!num_scan_radio_caps)
746 		return QDF_STATUS_SUCCESS;
747 
748 	scan_radio_caps = target_psoc_get_scan_radio_caps(tgt_psoc_info);
749 	if (!scan_radio_caps) {
750 		target_if_err("scan radio capabilities is null");
751 		return QDF_STATUS_E_INVAL;
752 	}
753 
754 	tgt_pdev = (struct target_pdev_info *)wlan_pdev_get_tgt_if_handle(pdev);
755 	if (!tgt_pdev) {
756 		target_if_err("target_pdev_info is null");
757 		return QDF_STATUS_E_INVAL;
758 	}
759 
760 	phy_id = target_pdev_get_phy_idx(tgt_pdev);
761 	if (phy_id < 0) {
762 		target_if_err("phy_id is invalid");
763 		return QDF_STATUS_E_INVAL;
764 	}
765 
766 	for (cap_idx = 0; cap_idx < num_scan_radio_caps; cap_idx++)
767 		if (scan_radio_caps[cap_idx].phy_id == phy_id)
768 			*is_scan_radio_supported =
769 				scan_radio_caps[cap_idx].scan_radio_supported;
770 
771 	return QDF_STATUS_SUCCESS;
772 }
773 
774 QDF_STATUS
775 target_pdev_scan_radio_is_dfs_enabled(struct wlan_objmgr_pdev *pdev,
776 				      bool *is_dfs_en)
777 {
778 	struct wlan_objmgr_psoc *psoc;
779 	struct wlan_psoc_host_scan_radio_caps *scan_radio_caps;
780 	uint8_t cap_idx;
781 	uint32_t num_scan_radio_caps, pdev_id;
782 	int32_t phy_id;
783 	struct target_psoc_info *tgt_psoc_info;
784 	struct target_pdev_info *tgt_pdev;
785 
786 	if (!is_dfs_en) {
787 		target_if_err("input argument is null");
788 		return QDF_STATUS_E_INVAL;
789 	}
790 	*is_dfs_en = true;
791 
792 	if (!pdev) {
793 		target_if_err("pdev is null");
794 		return QDF_STATUS_E_INVAL;
795 	}
796 
797 	psoc = wlan_pdev_get_psoc(pdev);
798 	if (!psoc) {
799 		target_if_err("psoc is null");
800 		return QDF_STATUS_E_INVAL;
801 	}
802 
803 	tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
804 	if (!tgt_psoc_info) {
805 		target_if_err("target_psoc_info is null");
806 		return QDF_STATUS_E_INVAL;
807 	}
808 
809 	num_scan_radio_caps =
810 		target_psoc_get_num_scan_radio_caps(tgt_psoc_info);
811 	if (!num_scan_radio_caps) {
812 		target_if_err("scan radio not supported for psoc");
813 		return QDF_STATUS_E_INVAL;
814 	}
815 
816 	scan_radio_caps = target_psoc_get_scan_radio_caps(tgt_psoc_info);
817 	if (!scan_radio_caps) {
818 		target_if_err("scan radio capabilities is null");
819 		return QDF_STATUS_E_INVAL;
820 	}
821 
822 	tgt_pdev = (struct target_pdev_info *)wlan_pdev_get_tgt_if_handle(pdev);
823 	if (!tgt_pdev) {
824 		target_if_err("target_pdev_info is null");
825 		return QDF_STATUS_E_INVAL;
826 	}
827 
828 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
829 	phy_id = target_pdev_get_phy_idx(tgt_pdev);
830 	if (phy_id < 0) {
831 		target_if_err("phy_id is invalid");
832 		return QDF_STATUS_E_INVAL;
833 	}
834 
835 	for (cap_idx = 0; cap_idx < num_scan_radio_caps; cap_idx++)
836 		if (scan_radio_caps[cap_idx].phy_id == phy_id) {
837 			*is_dfs_en = scan_radio_caps[cap_idx].dfs_en;
838 			return QDF_STATUS_SUCCESS;
839 		}
840 
841 	target_if_err("No scan radio cap found in pdev %d", pdev_id);
842 
843 	return QDF_STATUS_E_INVAL;
844 }
845