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