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