1 /*
2  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: wlan_coex_utils_api.c
20  *
21  * This file provides definitions of public APIs exposed to other UMAC
22  * components.
23  */
24 
25 #include <wlan_coex_main.h>
26 #include <wlan_objmgr_global_obj.h>
27 #include <wlan_coex_utils_api.h>
28 #include "cfg_ucfg_api.h"
29 
wlan_coex_init(void)30 QDF_STATUS wlan_coex_init(void)
31 {
32 	QDF_STATUS status;
33 
34 	status = wlan_objmgr_register_psoc_create_handler(
35 			WLAN_UMAC_COMP_COEX,
36 			wlan_coex_psoc_created_notification, NULL);
37 	if (QDF_IS_STATUS_ERROR(status)) {
38 		coex_err("Failed to register psoc create handler");
39 		goto fail_create_psoc;
40 	}
41 
42 	status = wlan_objmgr_register_psoc_destroy_handler(
43 			WLAN_UMAC_COMP_COEX,
44 			wlan_coex_psoc_destroyed_notification, NULL);
45 	if (QDF_IS_STATUS_ERROR(status)) {
46 		coex_err("Failed to create psoc delete handler");
47 		goto fail_psoc_destroy;
48 	}
49 
50 	coex_debug("coex psoc create and delete handler registered");
51 	return status;
52 
53 fail_psoc_destroy:
54 	wlan_objmgr_unregister_psoc_create_handler(
55 			WLAN_UMAC_COMP_COEX,
56 			wlan_coex_psoc_created_notification, NULL);
57 fail_create_psoc:
58 	return status;
59 }
60 
wlan_coex_deinit(void)61 QDF_STATUS wlan_coex_deinit(void)
62 {
63 	QDF_STATUS status;
64 
65 	status = wlan_objmgr_unregister_psoc_destroy_handler(
66 			WLAN_UMAC_COMP_COEX,
67 			wlan_coex_psoc_destroyed_notification, NULL);
68 	if (status != QDF_STATUS_SUCCESS)
69 		coex_err("Failed to unregister psoc delete handler");
70 
71 	status = wlan_objmgr_unregister_psoc_create_handler(
72 			WLAN_UMAC_COMP_COEX,
73 			wlan_coex_psoc_created_notification, NULL);
74 	if (status != QDF_STATUS_SUCCESS)
75 		coex_err("Failed to unregister psoc create handler");
76 
77 	return status;
78 }
79 
80 #ifdef FEATURE_BTC_CHAIN_MODE
81 /**
82  * wlan_coex_set_btc_chain_mode_with_ini() - set BTC init chain mode
83  * with ini
84  * @psoc: pointer to psoc object
85  *
86  * This function is used to set BTC init chain mode with ini
87  *
88  * Return: None
89  */
90 static void
wlan_coex_set_btc_chain_mode_with_ini(struct wlan_objmgr_psoc * psoc)91 wlan_coex_set_btc_chain_mode_with_ini(struct wlan_objmgr_psoc *psoc)
92 {
93 	enum coex_btc_chain_mode btc_chain_mode;
94 	QDF_STATUS status;
95 
96 	status = wlan_coex_psoc_get_btc_chain_mode(psoc, &btc_chain_mode);
97 	if (QDF_IS_STATUS_ERROR(status)) {
98 		coex_err("error for getting btc chain mode");
99 		return;
100 	}
101 
102 	if (btc_chain_mode == WLAN_COEX_BTC_CHAIN_MODE_UNSETTLED) {
103 		btc_chain_mode = cfg_get(psoc, CFG_SET_INIT_CHAIN_MODE_FOR_BTC);
104 		if (btc_chain_mode > WLAN_COEX_BTC_CHAIN_MODE_HYBRID &&
105 		    btc_chain_mode != WLAN_COEX_BTC_CHAIN_MODE_UNSETTLED) {
106 			coex_err("invalid ini config %d for btc chain mode",
107 				 btc_chain_mode);
108 			return;
109 		}
110 
111 		status = wlan_coex_psoc_set_btc_chain_mode(psoc,
112 							   btc_chain_mode);
113 		if (QDF_IS_STATUS_ERROR(status))
114 			coex_err("error for setting btc init chain mode from ini");
115 	}
116 }
117 #else
118 static void
wlan_coex_set_btc_chain_mode_with_ini(struct wlan_objmgr_psoc * psoc)119 wlan_coex_set_btc_chain_mode_with_ini(struct wlan_objmgr_psoc *psoc)
120 {
121 }
122 #endif
123 
124 QDF_STATUS
wlan_coex_psoc_open(struct wlan_objmgr_psoc * psoc)125 wlan_coex_psoc_open(struct wlan_objmgr_psoc *psoc)
126 {
127 	wlan_coex_set_btc_chain_mode_with_ini(psoc);
128 	return wlan_coex_psoc_init(psoc);
129 }
130 
131 QDF_STATUS
wlan_coex_psoc_close(struct wlan_objmgr_psoc * psoc)132 wlan_coex_psoc_close(struct wlan_objmgr_psoc *psoc)
133 {
134 	return wlan_coex_psoc_deinit(psoc);
135 }
136 
137 #ifdef WLAN_FEATURE_DBAM_CONFIG
wlan_dbam_psoc_enable(struct wlan_objmgr_psoc * psoc)138 QDF_STATUS wlan_dbam_psoc_enable(struct wlan_objmgr_psoc *psoc)
139 {
140 	return wlan_dbam_attach(psoc);
141 }
142 
wlan_dbam_psoc_disable(struct wlan_objmgr_psoc * psoc)143 QDF_STATUS wlan_dbam_psoc_disable(struct wlan_objmgr_psoc *psoc)
144 {
145 	return wlan_dbam_detach(psoc);
146 }
147 #endif
148