xref: /wlan-dirver/qca-wifi-host-cmn/target_if/core/src/target_if_main.c (revision d0c05845839e5f2ba5a8dcebe0cd3e4cd4e8dfcf)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: API for interacting with target interface.
22  *
23  */
24 
25 #include "target_if.h"
26 #include "target_type.h"
27 #ifdef WLAN_ATF_ENABLE
28 #include "target_if_atf.h"
29 #endif
30 #ifdef WLAN_SA_API_ENABLE
31 #include "target_if_sa_api.h"
32 #endif
33 #ifdef WLAN_CFR_ENABLE
34 #include "target_if_cfr.h"
35 #endif
36 #ifdef WLAN_CONV_SPECTRAL_ENABLE
37 #include "target_if_spectral.h"
38 #endif
39 
40 #ifdef WLAN_IOT_SIM_SUPPORT
41 #include <target_if_iot_sim.h>
42 #endif
43 #include <target_if_reg.h>
44 #include <target_if_scan.h>
45 #include <target_if_ftm.h>
46 #ifdef DFS_COMPONENT_ENABLE
47 #include <target_if_dfs.h>
48 #endif
49 
50 #ifdef CONVERGED_P2P_ENABLE
51 #include "target_if_p2p.h"
52 #endif
53 
54 #ifdef WIFI_POS_CONVERGED
55 #include "target_if_wifi_pos.h"
56 #include "target_if_wifi_pos_rx_ops.h"
57 #include "target_if_wifi_pos_tx_ops.h"
58 #endif
59 
60 #ifdef FEATURE_WLAN_TDLS
61 #include "target_if_tdls.h"
62 #endif
63 #if defined(QCA_SUPPORT_SON) || defined(WLAN_FEATURE_SON)
64 #include <target_if_son.h>
65 #endif
66 #if defined WLAN_FEATURE_11AX
67 #include <target_if_spatial_reuse.h>
68 #endif
69 #ifdef WLAN_OFFCHAN_TXRX_ENABLE
70 #include <target_if_offchan_txrx_api.h>
71 #endif
72 #ifdef WLAN_SUPPORT_GREEN_AP
73 #include <target_if_green_ap.h>
74 #endif
75 #include <init_deinit_lmac.h>
76 #include <service_ready_util.h>
77 
78 #ifdef DIRECT_BUF_RX_ENABLE
79 #include <target_if_direct_buf_rx_api.h>
80 #endif
81 
82 #ifdef WLAN_SUPPORT_FILS
83 #include <target_if_fd.h>
84 #endif
85 #include "qdf_module.h"
86 
87 #include <target_if_cp_stats.h>
88 #ifdef CRYPTO_SET_KEY_CONVERGED
89 #include <target_if_crypto.h>
90 #endif
91 #include <target_if_vdev_mgr_tx_ops.h>
92 
93 #ifdef FEATURE_COEX
94 #include <target_if_coex.h>
95 #endif
96 #include <wlan_utility.h>
97 
98 #ifdef DCS_INTERFERENCE_DETECTION
99 #include <target_if_dcs.h>
100 #endif
101 
102 #include <target_if_gpio.h>
103 #ifdef IPA_OFFLOAD
104 #include <target_if_ipa.h>
105 #endif
106 
107 #ifdef WLAN_MGMT_RX_REO_SUPPORT
108 #include <target_if_mgmt_txrx.h>
109 #endif /* WLAN_MGMT_RX_REO_SUPPORT */
110 
111 #include "wmi_unified_api.h"
112 #include <target_if_twt.h>
113 
114 #ifdef WLAN_FEATURE_11BE_MLO
115 #include <target_if_mlo_mgr.h>
116 #endif
117 
118 static struct target_if_ctx *g_target_if_ctx;
119 
120 struct target_if_ctx *target_if_get_ctx()
121 {
122 	return g_target_if_ctx;
123 }
124 
125 struct wlan_objmgr_psoc *target_if_get_psoc_from_scn_hdl(void *scn_handle)
126 {
127 	struct wlan_objmgr_psoc *psoc;
128 
129 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
130 	if (scn_handle && g_target_if_ctx->get_psoc_hdl_cb)
131 		psoc = g_target_if_ctx->get_psoc_hdl_cb(scn_handle);
132 	else
133 		psoc = NULL;
134 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
135 
136 	return psoc;
137 }
138 
139 struct wlan_objmgr_pdev *target_if_get_pdev_from_scn_hdl(void *scn_handle)
140 {
141 	struct wlan_objmgr_pdev *pdev;
142 
143 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
144 	if (scn_handle && g_target_if_ctx->get_pdev_hdl_cb)
145 		pdev = g_target_if_ctx->get_pdev_hdl_cb(scn_handle);
146 	else
147 		pdev = NULL;
148 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
149 
150 	return pdev;
151 }
152 
153 #ifdef DIRECT_BUF_RX_ENABLE
154 static QDF_STATUS target_if_direct_buf_rx_init(void)
155 {
156 	return direct_buf_rx_init();
157 }
158 
159 static QDF_STATUS target_if_direct_buf_rx_deinit(void)
160 {
161 	return direct_buf_rx_deinit();
162 }
163 #else
164 static QDF_STATUS target_if_direct_buf_rx_init(void)
165 {
166 	return QDF_STATUS_SUCCESS;
167 }
168 
169 static QDF_STATUS target_if_direct_buf_rx_deinit(void)
170 {
171 	return QDF_STATUS_SUCCESS;
172 }
173 #endif /* DIRECT_BUF_RX_ENABLE */
174 
175 QDF_STATUS target_if_init(get_psoc_handle_callback psoc_hdl_cb)
176 {
177 	g_target_if_ctx = qdf_mem_malloc(sizeof(*g_target_if_ctx));
178 	if (!g_target_if_ctx) {
179 		QDF_ASSERT(0);
180 		return QDF_STATUS_E_NOMEM;
181 	}
182 
183 	qdf_spinlock_create(&g_target_if_ctx->lock);
184 
185 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
186 	g_target_if_ctx->magic = TGT_MAGIC;
187 	g_target_if_ctx->get_psoc_hdl_cb = psoc_hdl_cb;
188 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
189 
190 	target_if_direct_buf_rx_init();
191 
192 	return QDF_STATUS_SUCCESS;
193 }
194 
195 QDF_STATUS target_if_deinit(void)
196 {
197 	if (!g_target_if_ctx) {
198 		QDF_ASSERT(0);
199 		target_if_err("target if ctx is null");
200 		return QDF_STATUS_E_INVAL;
201 	}
202 
203 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
204 	g_target_if_ctx->magic = 0;
205 	g_target_if_ctx->get_psoc_hdl_cb = NULL;
206 	g_target_if_ctx->get_pdev_hdl_cb = NULL;
207 	g_target_if_ctx->service_ready_cb = NULL;
208 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
209 
210 	qdf_spinlock_destroy(&g_target_if_ctx->lock);
211 	qdf_mem_free(g_target_if_ctx);
212 	g_target_if_ctx = NULL;
213 
214 	target_if_direct_buf_rx_deinit();
215 
216 	return QDF_STATUS_SUCCESS;
217 }
218 
219 qdf_export_symbol(target_if_deinit);
220 
221 QDF_STATUS target_if_store_pdev_target_if_ctx(
222 		get_pdev_handle_callback pdev_hdl_cb)
223 {
224 	if (!g_target_if_ctx) {
225 		QDF_ASSERT(0);
226 		target_if_err("target if ctx is null");
227 		return QDF_STATUS_E_INVAL;
228 	}
229 
230 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
231 	g_target_if_ctx->get_pdev_hdl_cb = pdev_hdl_cb;
232 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
233 
234 	return QDF_STATUS_SUCCESS;
235 }
236 
237 #ifndef WLAN_OFFCHAN_TXRX_ENABLE
238 static void target_if_offchan_txrx_ops_register(
239 					struct wlan_lmac_if_tx_ops *tx_ops)
240 {
241 }
242 #endif /* WLAN_OFFCHAN_TXRX_ENABLE */
243 
244 #ifndef WLAN_ATF_ENABLE
245 static void target_if_atf_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
246 {
247 }
248 #endif /* WLAN_ATF_ENABLE */
249 
250 #ifndef WLAN_SA_API_ENABLE
251 static void target_if_sa_api_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
252 {
253 }
254 #endif /* WLAN_SA_API_ENABLE */
255 
256 #ifndef WLAN_CFR_ENABLE
257 static void target_if_cfr_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
258 {
259 }
260 #endif
261 
262 #ifdef WLAN_SUPPORT_FILS
263 static void target_if_fd_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
264 {
265 	target_if_fd_register_tx_ops(tx_ops);
266 }
267 #else
268 static void target_if_fd_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
269 {
270 }
271 #endif
272 
273 #ifdef WIFI_POS_CONVERGED
274 static void
275 target_if_wifi_pos_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
276 {
277 	target_if_wifi_pos_register_tx_ops(tx_ops);
278 }
279 #else
280 static void
281 target_if_wifi_pos_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
282 {
283 }
284 #endif
285 
286 #if defined(QCA_SUPPORT_SON) || defined(WLAN_FEATURE_SON)
287 static void target_if_son_tx_ops_register(
288 			struct wlan_lmac_if_tx_ops *tx_ops)
289 {
290 	target_if_son_register_tx_ops(tx_ops);
291 	return;
292 }
293 #else
294 static void target_if_son_tx_ops_register(
295 			struct wlan_lmac_if_tx_ops *tx_ops)
296 {
297 	return;
298 }
299 #endif
300 
301 #if defined WLAN_FEATURE_11AX
302 static void target_if_spatial_reuse_tx_ops_register(
303 			struct wlan_lmac_if_tx_ops *tx_ops)
304 {
305 	target_if_spatial_reuse_register_tx_ops(tx_ops);
306 }
307 
308 #else
309 static void target_if_spatial_reuse_tx_ops_register(
310 			struct wlan_lmac_if_tx_ops *tx_ops)
311 {
312 }
313 
314 #endif
315 
316 #ifdef FEATURE_WLAN_TDLS
317 static void target_if_tdls_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
318 {
319 	target_if_tdls_register_tx_ops(tx_ops);
320 }
321 #else
322 static void target_if_tdls_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
323 {
324 }
325 #endif /* FEATURE_WLAN_TDLS */
326 
327 #ifdef DFS_COMPONENT_ENABLE
328 static void target_if_dfs_tx_ops_register(
329 				struct wlan_lmac_if_tx_ops *tx_ops)
330 {
331 	target_if_register_dfs_tx_ops(tx_ops);
332 }
333 #else
334 static void target_if_dfs_tx_ops_register(
335 				struct wlan_lmac_if_tx_ops *tx_ops)
336 {
337 }
338 #endif /* DFS_COMPONENT_ENABLE */
339 
340 #ifdef WLAN_CONV_SPECTRAL_ENABLE
341 static void target_if_sptrl_tx_ops_register(
342 				struct wlan_lmac_if_tx_ops *tx_ops)
343 {
344 	target_if_sptrl_register_tx_ops(tx_ops);
345 }
346 #else
347 static void target_if_sptrl_tx_ops_register(
348 				struct wlan_lmac_if_tx_ops *tx_ops)
349 {
350 }
351 #endif /* WLAN_CONV_SPECTRAL_ENABLE */
352 
353 #ifdef WLAN_IOT_SIM_SUPPORT
354 static void target_if_iot_sim_tx_ops_register(
355 				struct wlan_lmac_if_tx_ops *tx_ops)
356 {
357 	target_if_iot_sim_register_tx_ops(tx_ops);
358 }
359 #else
360 static void target_if_iot_sim_tx_ops_register(
361 				struct wlan_lmac_if_tx_ops *tx_ops)
362 {
363 }
364 #endif
365 
366 #ifdef DIRECT_BUF_RX_ENABLE
367 static void target_if_direct_buf_rx_tx_ops_register(
368 				struct wlan_lmac_if_tx_ops *tx_ops)
369 {
370 	target_if_direct_buf_rx_register_tx_ops(tx_ops);
371 }
372 #else
373 static void target_if_direct_buf_rx_tx_ops_register(
374 				struct wlan_lmac_if_tx_ops *tx_ops)
375 {
376 }
377 #endif /* DIRECT_BUF_RX_ENABLE */
378 
379 #ifdef WLAN_SUPPORT_GREEN_AP
380 static QDF_STATUS target_if_green_ap_tx_ops_register(
381 				struct wlan_lmac_if_tx_ops *tx_ops)
382 {
383 	return target_if_register_green_ap_tx_ops(tx_ops);
384 }
385 #else
386 static QDF_STATUS target_if_green_ap_tx_ops_register(
387 				struct wlan_lmac_if_tx_ops *tx_ops)
388 {
389 	return QDF_STATUS_SUCCESS;
390 }
391 #endif /* WLAN_SUPPORT_GREEN_AP */
392 #if defined(CRYPTO_SET_KEY_CONVERGED)
393 static void target_if_crypto_tx_ops_register(
394 				struct wlan_lmac_if_tx_ops *tx_ops)
395 {
396 	target_if_crypto_register_tx_ops(tx_ops);
397 }
398 #else
399 static inline void target_if_crypto_tx_ops_register(
400 				struct wlan_lmac_if_tx_ops *tx_ops)
401 {
402 }
403 #endif
404 
405 #ifdef FEATURE_COEX
406 static QDF_STATUS
407 target_if_coex_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
408 {
409 	return target_if_coex_register_tx_ops(tx_ops);
410 }
411 #else
412 static inline QDF_STATUS
413 target_if_coex_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
414 {
415 	return QDF_STATUS_SUCCESS;
416 }
417 #endif
418 
419 #ifdef WLAN_FEATURE_DBAM_CONFIG
420 static QDF_STATUS
421 target_if_dbam_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
422 {
423 	return target_if_dbam_register_tx_ops(tx_ops);
424 }
425 #else
426 static inline QDF_STATUS
427 target_if_dbam_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
428 {
429 	return QDF_STATUS_SUCCESS;
430 }
431 #endif
432 
433 static void target_if_target_tx_ops_register(
434 		struct wlan_lmac_if_tx_ops *tx_ops)
435 {
436 	struct wlan_lmac_if_target_tx_ops *target_tx_ops;
437 
438 	if (!tx_ops) {
439 		target_if_err("invalid tx_ops");
440 		return;
441 	}
442 
443 	target_tx_ops = &tx_ops->target_tx_ops;
444 
445 	target_tx_ops->tgt_is_tgt_type_ar900b =
446 		target_is_tgt_type_ar900b;
447 
448 	target_tx_ops->tgt_is_tgt_type_qca9984 =
449 		target_is_tgt_type_qca9984;
450 
451 	target_tx_ops->tgt_is_tgt_type_qca9888 =
452 		target_is_tgt_type_qca9888;
453 
454 	target_tx_ops->tgt_is_tgt_type_adrastea =
455 		target_is_tgt_type_adrastea;
456 
457 	target_tx_ops->tgt_is_tgt_type_qcn9000 =
458 		target_is_tgt_type_qcn9000;
459 
460 	target_tx_ops->tgt_is_tgt_type_qcn6122 =
461 		target_is_tgt_type_qcn6122;
462 
463 	target_tx_ops->tgt_is_tgt_type_qcn7605 =
464 		target_is_tgt_type_qcn7605;
465 
466 	target_tx_ops->tgt_get_tgt_type =
467 		lmac_get_tgt_type;
468 
469 	target_tx_ops->tgt_get_tgt_version =
470 		lmac_get_tgt_version;
471 
472 	target_tx_ops->tgt_get_tgt_revision =
473 		lmac_get_tgt_revision;
474 }
475 
476 static QDF_STATUS
477 target_if_cp_stats_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
478 {
479 	return target_if_cp_stats_register_tx_ops(tx_ops);
480 }
481 
482 #ifdef DCS_INTERFERENCE_DETECTION
483 static QDF_STATUS
484 target_if_dcs_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
485 {
486 	return target_if_dcs_register_tx_ops(tx_ops);
487 }
488 #else
489 static QDF_STATUS
490 target_if_dcs_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
491 {
492 	return QDF_STATUS_SUCCESS;
493 }
494 #endif
495 
496 static QDF_STATUS
497 target_if_vdev_mgr_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
498 {
499 	return target_if_vdev_mgr_register_tx_ops(tx_ops);
500 }
501 
502 #ifdef QCA_WIFI_FTM
503 static
504 void target_if_ftm_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
505 {
506 	target_if_ftm_register_tx_ops(tx_ops);
507 }
508 #else
509 static
510 void target_if_ftm_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
511 {
512 }
513 #endif
514 
515 #ifdef WLAN_FEATURE_GPIO_CFG
516 static
517 void target_if_gpio_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
518 {
519 	target_if_gpio_register_tx_ops(tx_ops);
520 }
521 #else
522 static
523 void target_if_gpio_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
524 {
525 }
526 #endif
527 
528 #ifdef WLAN_MGMT_RX_REO_SUPPORT
529 static
530 void target_if_mgmt_txrx_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
531 {
532 	target_if_mgmt_txrx_tx_ops_register(tx_ops);
533 }
534 #else
535 static
536 void target_if_mgmt_txrx_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
537 {
538 }
539 #endif /* WLAN_MGMT_RX_REO_SUPPORT */
540 
541 #ifdef WLAN_FEATURE_11BE_MLO
542 static QDF_STATUS
543 target_if_mlo_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
544 {
545 	return target_if_mlo_register_tx_ops(tx_ops);
546 }
547 #else
548 static QDF_STATUS
549 target_if_mlo_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
550 {
551 	return QDF_STATUS_SUCCESS;
552 }
553 #endif
554 
555 #ifdef IPA_OFFLOAD
556 static void target_if_ipa_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
557 {
558 	target_if_ipa_register_tx_ops(tx_ops);
559 }
560 #else
561 static void target_if_ipa_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
562 { }
563 #endif
564 
565 #if defined(WLAN_SUPPORT_TWT) && defined(WLAN_TWT_CONV_SUPPORTED)
566 static
567 void target_if_twt_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
568 {
569 	target_if_twt_register_tx_ops(tx_ops);
570 }
571 #else
572 static
573 void target_if_twt_tx_ops_register(struct wlan_lmac_if_tx_ops *tx_ops)
574 {
575 }
576 #endif /* WLAN_SUPPORT_TWT && WLAN_TWT_CONV_SUPPORTED */
577 
578 static
579 QDF_STATUS target_if_register_umac_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
580 {
581 	/* call regulatory callback to register tx ops */
582 	target_if_register_regulatory_tx_ops(tx_ops);
583 
584 	/* call umac callback to register legacy tx ops */
585 	wlan_lmac_if_umac_tx_ops_register(tx_ops);
586 
587 	/* Register scan tx ops */
588 	target_if_scan_tx_ops_register(tx_ops);
589 
590 	target_if_atf_tx_ops_register(tx_ops);
591 
592 	target_if_sa_api_tx_ops_register(tx_ops);
593 
594 	target_if_cfr_tx_ops_register(tx_ops);
595 
596 	target_if_wifi_pos_tx_ops_register(tx_ops);
597 
598 	target_if_dfs_tx_ops_register(tx_ops);
599 
600 	target_if_son_tx_ops_register(tx_ops);
601 
602 	target_if_spatial_reuse_tx_ops_register(tx_ops);
603 
604 	target_if_tdls_tx_ops_register(tx_ops);
605 
606 	target_if_fd_tx_ops_register(tx_ops);
607 
608 	target_if_target_tx_ops_register(tx_ops);
609 
610 	target_if_offchan_txrx_ops_register(tx_ops);
611 
612 	target_if_green_ap_tx_ops_register(tx_ops);
613 
614 	target_if_ftm_tx_ops_register(tx_ops);
615 
616 	target_if_cp_stats_tx_ops_register(tx_ops);
617 
618 	target_if_dcs_tx_ops_register(tx_ops);
619 
620 	target_if_crypto_tx_ops_register(tx_ops);
621 
622 	target_if_vdev_mgr_tx_ops_register(tx_ops);
623 
624 	target_if_coex_tx_ops_register(tx_ops);
625 
626 	target_if_gpio_tx_ops_register(tx_ops);
627 
628 	target_if_mgmt_txrx_register_tx_ops(tx_ops);
629 
630 	target_if_mlo_tx_ops_register(tx_ops);
631 
632 	target_if_ipa_tx_ops_register(tx_ops);
633 
634 	target_if_twt_tx_ops_register(tx_ops);
635 
636 	target_if_dbam_tx_ops_register(tx_ops);
637 
638 	/* Converged UMAC components to register their TX-ops here */
639 	return QDF_STATUS_SUCCESS;
640 }
641 
642 QDF_STATUS target_if_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
643 {
644 	/* Converged UMAC components to register their TX-ops */
645 	target_if_register_umac_tx_ops(tx_ops);
646 
647 	/* Components parallel to UMAC to register their TX-ops here */
648 	target_if_sptrl_tx_ops_register(tx_ops);
649 
650 	target_if_iot_sim_tx_ops_register(tx_ops);
651 
652 	/* Register direct buffer rx component tx ops here */
653 	target_if_direct_buf_rx_tx_ops_register(tx_ops);
654 
655 #ifdef CONVERGED_P2P_ENABLE
656 	/* Converged UMAC components to register P2P TX-ops */
657 	target_if_p2p_register_tx_ops(tx_ops);
658 #endif
659 
660 	return QDF_STATUS_SUCCESS;
661 }
662 qdf_export_symbol(target_if_register_tx_ops);
663 
664 wmi_legacy_service_ready_callback
665 target_if_get_psoc_legacy_service_ready_cb(void)
666 {
667 	wmi_legacy_service_ready_callback service_ready_cb;
668 
669 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
670 	if (g_target_if_ctx->service_ready_cb)
671 		service_ready_cb = g_target_if_ctx->service_ready_cb;
672 	else
673 		service_ready_cb = NULL;
674 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
675 
676 	return service_ready_cb;
677 }
678 qdf_export_symbol(target_if_get_psoc_legacy_service_ready_cb);
679 
680 QDF_STATUS target_if_register_legacy_service_ready_cb(
681 	wmi_legacy_service_ready_callback service_ready_cb)
682 {
683 	qdf_spin_lock_bh(&g_target_if_ctx->lock);
684 	g_target_if_ctx->service_ready_cb = service_ready_cb;
685 	qdf_spin_unlock_bh(&g_target_if_ctx->lock);
686 
687 	return QDF_STATUS_SUCCESS;
688 }
689 qdf_export_symbol(target_if_register_legacy_service_ready_cb);
690 
691 QDF_STATUS target_if_alloc_pdev_tgt_info(struct wlan_objmgr_pdev *pdev)
692 {
693 	struct target_pdev_info *tgt_pdev_info;
694 
695 	if (!pdev) {
696 		target_if_err("pdev is null");
697 		return QDF_STATUS_E_INVAL;
698 	}
699 
700 	tgt_pdev_info = qdf_mem_malloc(sizeof(*tgt_pdev_info));
701 
702 	if (!tgt_pdev_info)
703 		return QDF_STATUS_E_NOMEM;
704 
705 	wlan_pdev_set_tgt_if_handle(pdev, tgt_pdev_info);
706 
707 	return QDF_STATUS_SUCCESS;
708 }
709 
710 QDF_STATUS target_if_free_pdev_tgt_info(struct wlan_objmgr_pdev *pdev)
711 {
712 	struct target_pdev_info *tgt_pdev_info;
713 
714 	if (!pdev) {
715 		target_if_err("pdev is null");
716 		return QDF_STATUS_E_INVAL;
717 	}
718 
719 	tgt_pdev_info = wlan_pdev_get_tgt_if_handle(pdev);
720 
721 	wlan_pdev_set_tgt_if_handle(pdev, NULL);
722 
723 	qdf_mem_free(tgt_pdev_info);
724 
725 	return QDF_STATUS_SUCCESS;
726 }
727 
728 QDF_STATUS target_if_alloc_psoc_tgt_info(struct wlan_objmgr_psoc *psoc)
729 {
730 	struct target_psoc_info *tgt_psoc_info;
731 
732 	if (!psoc) {
733 		target_if_err("psoc is null");
734 		return QDF_STATUS_E_INVAL;
735 	}
736 
737 	tgt_psoc_info = qdf_mem_malloc(sizeof(*tgt_psoc_info));
738 
739 	if (!tgt_psoc_info)
740 		return QDF_STATUS_E_NOMEM;
741 
742 	wlan_psoc_set_tgt_if_handle(psoc, tgt_psoc_info);
743 	target_psoc_set_preferred_hw_mode(tgt_psoc_info, WMI_HOST_HW_MODE_MAX);
744 	wlan_minidump_log(tgt_psoc_info,
745 			  sizeof(*tgt_psoc_info), psoc,
746 			  WLAN_MD_OBJMGR_PSOC_TGT_INFO, "target_psoc_info");
747 
748 	qdf_event_create(&tgt_psoc_info->info.event);
749 
750 	return QDF_STATUS_SUCCESS;
751 }
752 
753 QDF_STATUS target_if_free_psoc_tgt_info(struct wlan_objmgr_psoc *psoc)
754 {
755 	struct target_psoc_info *tgt_psoc_info;
756 	struct wlan_psoc_host_service_ext_param *ext_param;
757 
758 	if (!psoc) {
759 		target_if_err("psoc is null");
760 		return QDF_STATUS_E_INVAL;
761 	}
762 
763 	tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
764 
765 	ext_param = target_psoc_get_service_ext_param(tgt_psoc_info);
766 	if (!ext_param) {
767 		target_if_err("tgt_psoc_info is NULL");
768 		return QDF_STATUS_E_INVAL;
769 	}
770 	init_deinit_chainmask_table_free(ext_param);
771 	init_deinit_dbr_ring_cap_free(tgt_psoc_info);
772 	init_deinit_spectral_scaling_params_free(tgt_psoc_info);
773 	init_deinit_scan_radio_cap_free(tgt_psoc_info);
774 
775 	qdf_event_destroy(&tgt_psoc_info->info.event);
776 
777 	wlan_psoc_set_tgt_if_handle(psoc, NULL);
778 
779 	wlan_minidump_remove(tgt_psoc_info,
780 			     sizeof(*tgt_psoc_info), psoc,
781 			     WLAN_MD_OBJMGR_PSOC_TGT_INFO, "target_psoc_info");
782 	qdf_mem_free(tgt_psoc_info);
783 
784 	return QDF_STATUS_SUCCESS;
785 }
786 
787 bool target_is_tgt_type_ar900b(uint32_t target_type)
788 {
789 	return target_type == TARGET_TYPE_AR900B;
790 }
791 
792 bool target_is_tgt_type_qca9984(uint32_t target_type)
793 {
794 	return target_type == TARGET_TYPE_QCA9984;
795 }
796 
797 bool target_is_tgt_type_qca9888(uint32_t target_type)
798 {
799 	return target_type == TARGET_TYPE_QCA9888;
800 }
801 
802 bool target_is_tgt_type_adrastea(uint32_t target_type)
803 {
804 	return target_type == TARGET_TYPE_ADRASTEA;
805 }
806 
807 bool target_is_tgt_type_qcn9000(uint32_t target_type)
808 {
809 	return target_type == TARGET_TYPE_QCN9000;
810 }
811 
812 bool target_is_tgt_type_qcn6122(uint32_t target_type)
813 {
814 	return target_type == TARGET_TYPE_QCN6122;
815 }
816 
817 bool target_is_tgt_type_qcn7605(uint32_t target_type)
818 {
819 	return target_type == TARGET_TYPE_QCN7605;
820 }
821 
822 QDF_STATUS
823 target_pdev_is_scan_radio_supported(struct wlan_objmgr_pdev *pdev,
824 				    bool *is_scan_radio_supported)
825 {
826 	struct wlan_objmgr_psoc *psoc;
827 	struct wlan_psoc_host_scan_radio_caps *scan_radio_caps;
828 	uint8_t cap_idx;
829 	uint32_t num_scan_radio_caps;
830 	int32_t phy_id;
831 	struct target_psoc_info *tgt_psoc_info;
832 	struct target_pdev_info *tgt_pdev;
833 
834 	if (!is_scan_radio_supported) {
835 		target_if_err("input argument is null");
836 		return QDF_STATUS_E_INVAL;
837 	}
838 	*is_scan_radio_supported = false;
839 
840 	if (!pdev) {
841 		target_if_err("pdev is null");
842 		return QDF_STATUS_E_INVAL;
843 	}
844 
845 	psoc = wlan_pdev_get_psoc(pdev);
846 	if (!psoc) {
847 		target_if_err("psoc is null");
848 		return QDF_STATUS_E_INVAL;
849 	}
850 
851 	tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
852 	if (!tgt_psoc_info) {
853 		target_if_err("target_psoc_info is null");
854 		return QDF_STATUS_E_INVAL;
855 	}
856 
857 	num_scan_radio_caps =
858 		target_psoc_get_num_scan_radio_caps(tgt_psoc_info);
859 	if (!num_scan_radio_caps)
860 		return QDF_STATUS_SUCCESS;
861 
862 	scan_radio_caps = target_psoc_get_scan_radio_caps(tgt_psoc_info);
863 	if (!scan_radio_caps) {
864 		target_if_err("scan radio capabilities is null");
865 		return QDF_STATUS_E_INVAL;
866 	}
867 
868 	tgt_pdev = (struct target_pdev_info *)wlan_pdev_get_tgt_if_handle(pdev);
869 	if (!tgt_pdev) {
870 		target_if_err("target_pdev_info is null");
871 		return QDF_STATUS_E_INVAL;
872 	}
873 
874 	phy_id = target_pdev_get_phy_idx(tgt_pdev);
875 	if (phy_id < 0) {
876 		target_if_err("phy_id is invalid");
877 		return QDF_STATUS_E_INVAL;
878 	}
879 
880 	for (cap_idx = 0; cap_idx < num_scan_radio_caps; cap_idx++)
881 		if (scan_radio_caps[cap_idx].phy_id == phy_id)
882 			*is_scan_radio_supported =
883 				scan_radio_caps[cap_idx].scan_radio_supported;
884 
885 	return QDF_STATUS_SUCCESS;
886 }
887 
888 QDF_STATUS
889 target_pdev_scan_radio_is_dfs_enabled(struct wlan_objmgr_pdev *pdev,
890 				      bool *is_dfs_en)
891 {
892 	struct wlan_objmgr_psoc *psoc;
893 	struct wlan_psoc_host_scan_radio_caps *scan_radio_caps;
894 	uint8_t cap_idx;
895 	uint32_t num_scan_radio_caps, pdev_id;
896 	int32_t phy_id;
897 	struct target_psoc_info *tgt_psoc_info;
898 	struct target_pdev_info *tgt_pdev;
899 
900 	if (!is_dfs_en) {
901 		target_if_err("input argument is null");
902 		return QDF_STATUS_E_INVAL;
903 	}
904 	*is_dfs_en = true;
905 
906 	if (!pdev) {
907 		target_if_err("pdev is null");
908 		return QDF_STATUS_E_INVAL;
909 	}
910 
911 	psoc = wlan_pdev_get_psoc(pdev);
912 	if (!psoc) {
913 		target_if_err("psoc is null");
914 		return QDF_STATUS_E_INVAL;
915 	}
916 
917 	tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
918 	if (!tgt_psoc_info) {
919 		target_if_err("target_psoc_info is null");
920 		return QDF_STATUS_E_INVAL;
921 	}
922 
923 	num_scan_radio_caps =
924 		target_psoc_get_num_scan_radio_caps(tgt_psoc_info);
925 	if (!num_scan_radio_caps) {
926 		target_if_err("scan radio not supported for psoc");
927 		return QDF_STATUS_E_INVAL;
928 	}
929 
930 	scan_radio_caps = target_psoc_get_scan_radio_caps(tgt_psoc_info);
931 	if (!scan_radio_caps) {
932 		target_if_err("scan radio capabilities is null");
933 		return QDF_STATUS_E_INVAL;
934 	}
935 
936 	tgt_pdev = (struct target_pdev_info *)wlan_pdev_get_tgt_if_handle(pdev);
937 	if (!tgt_pdev) {
938 		target_if_err("target_pdev_info is null");
939 		return QDF_STATUS_E_INVAL;
940 	}
941 
942 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
943 	phy_id = target_pdev_get_phy_idx(tgt_pdev);
944 	if (phy_id < 0) {
945 		target_if_err("phy_id is invalid");
946 		return QDF_STATUS_E_INVAL;
947 	}
948 
949 	for (cap_idx = 0; cap_idx < num_scan_radio_caps; cap_idx++)
950 		if (scan_radio_caps[cap_idx].phy_id == phy_id) {
951 			*is_dfs_en = scan_radio_caps[cap_idx].dfs_en;
952 			return QDF_STATUS_SUCCESS;
953 		}
954 
955 	target_if_err("No scan radio cap found in pdev %d", pdev_id);
956 
957 	return QDF_STATUS_E_INVAL;
958 }
959 
960 void target_if_set_reg_cc_ext_supp(struct target_psoc_info *tgt_hdl,
961 				   struct wlan_objmgr_psoc *psoc)
962 {
963 	struct tgt_info *info;
964 
965 	if (!tgt_hdl)
966 		return;
967 
968 	info = (&tgt_hdl->info);
969 
970 	info->wlan_res_cfg.is_reg_cc_ext_event_supported =
971 		target_if_reg_is_reg_cc_ext_event_host_supported(psoc);
972 }
973 
974 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
975 uint16_t  target_if_pdev_get_hw_link_id(struct wlan_objmgr_pdev *pdev)
976 {
977 	struct target_pdev_info *tgt_pdev_info;
978 
979 	if (!pdev)
980 		return PDEV_INVALID_HW_LINK_ID;
981 
982 	tgt_pdev_info = wlan_pdev_get_tgt_if_handle(pdev);
983 	if (!tgt_pdev_info)
984 		return PDEV_INVALID_HW_LINK_ID;
985 
986 	return tgt_pdev_info->hw_link_id;
987 }
988 
989 void target_pdev_set_hw_link_id(struct wlan_objmgr_pdev *pdev,
990 				uint16_t hw_link_id)
991 {
992 	struct target_pdev_info *tgt_pdev_info;
993 
994 	if (!pdev)
995 		return;
996 
997 	tgt_pdev_info = wlan_pdev_get_tgt_if_handle(pdev);
998 	if (!tgt_pdev_info)
999 		return;
1000 
1001 	tgt_pdev_info->hw_link_id  = hw_link_id;
1002 }
1003 
1004 static QDF_STATUS target_if_mlo_setup_send(struct wlan_objmgr_pdev *pdev,
1005 					   struct wlan_objmgr_pdev **pdev_list,
1006 					   uint8_t num_links, uint8_t grp_id)
1007 {
1008 	wmi_unified_t wmi_handle;
1009 	struct wmi_mlo_setup_params params = {0};
1010 	uint8_t idx, num_valid_links = 0;
1011 
1012 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
1013 	if (!wmi_handle)
1014 		return QDF_STATUS_E_INVAL;
1015 
1016 	params.mld_grp_id = grp_id;
1017 	params.pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1018 
1019 	for (idx = 0; idx < num_links; idx++) {
1020 		if (pdev == pdev_list[idx])
1021 			continue;
1022 
1023 		params.partner_links[num_valid_links] =
1024 			target_if_pdev_get_hw_link_id(pdev_list[idx]);
1025 		num_valid_links++;
1026 	}
1027 	params.num_valid_hw_links = num_valid_links;
1028 
1029 	return wmi_mlo_setup_cmd_send(wmi_handle, &params);
1030 }
1031 
1032 QDF_STATUS target_if_mlo_setup_req(struct wlan_objmgr_pdev **pdev,
1033 				   uint8_t num_pdevs, uint8_t grp_id)
1034 {
1035 	uint8_t idx;
1036 
1037 	for (idx = 0; idx < num_pdevs; idx++)
1038 		target_if_mlo_setup_send(pdev[idx], pdev, num_pdevs, grp_id);
1039 
1040 	return QDF_STATUS_SUCCESS;
1041 }
1042 
1043 static QDF_STATUS target_if_mlo_ready_send(struct wlan_objmgr_pdev *pdev)
1044 {
1045 	wmi_unified_t wmi_handle;
1046 	struct wmi_mlo_ready_params params = {0};
1047 
1048 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
1049 	if (!wmi_handle)
1050 		return QDF_STATUS_E_INVAL;
1051 
1052 	params.pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1053 
1054 	return wmi_mlo_ready_cmd_send(wmi_handle, &params);
1055 }
1056 
1057 QDF_STATUS target_if_mlo_ready(struct wlan_objmgr_pdev **pdev,
1058 			       uint8_t num_pdevs)
1059 {
1060 	uint8_t idx;
1061 
1062 	for (idx = 0; idx < num_pdevs; idx++)
1063 		target_if_mlo_ready_send(pdev[idx]);
1064 
1065 	return QDF_STATUS_SUCCESS;
1066 }
1067 
1068 static QDF_STATUS
1069 target_if_mlo_teardown_send(struct wlan_objmgr_pdev *pdev,
1070 			    enum wmi_mlo_teardown_reason reason)
1071 {
1072 	wmi_unified_t wmi_handle;
1073 	struct wmi_mlo_teardown_params params = {0};
1074 
1075 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
1076 	if (!wmi_handle)
1077 		return QDF_STATUS_E_INVAL;
1078 
1079 	params.pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1080 	params.reason = reason;
1081 
1082 	return wmi_mlo_teardown_cmd_send(wmi_handle, &params);
1083 }
1084 
1085 QDF_STATUS target_if_mlo_teardown_req(struct wlan_objmgr_pdev **pdev,
1086 				      uint8_t num_pdevs,
1087 				      enum wmi_mlo_teardown_reason reason)
1088 {
1089 	uint8_t idx;
1090 
1091 	for (idx = 0; idx < num_pdevs; idx++)
1092 		target_if_mlo_teardown_send(pdev[idx], reason);
1093 
1094 	return QDF_STATUS_SUCCESS;
1095 }
1096 #endif /*WLAN_FEATURE_11BE_MLO && WLAN_MLO_MULTI_CHIP*/
1097