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