xref: /wlan-driver/qcacld-3.0/components/disa/dispatcher/src/wlan_disa_obj_mgmt_api.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2018-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  * DOC: define utility API related to the DISA component
20  * called by other components
21  */
22 
23 #include "wlan_disa_obj_mgmt_api.h"
24 #include "wlan_disa_main.h"
25 #include "target_if_disa.h"
26 #include "wlan_disa_tgt_api.h"
27 #include "wlan_objmgr_global_obj.h"
28 
29 /**
30  * disa_init() - register disa notification handlers.
31  *
32  * This function registers disa related notification handlers and
33  * allocates disa context.
34  *
35  * Return: QDF_STATUS_SUCCESS - in case of success else return error
36  */
disa_init(void)37 QDF_STATUS disa_init(void)
38 {
39 	QDF_STATUS status;
40 
41 	DISA_ENTER();
42 
43 	if (disa_allocate_ctx() != QDF_STATUS_SUCCESS) {
44 		disa_err("unable to allocate disa ctx");
45 		status = QDF_STATUS_E_FAULT;
46 		goto out;
47 	}
48 
49 	status = wlan_objmgr_register_psoc_create_handler(
50 			WLAN_UMAC_COMP_DISA,
51 			disa_psoc_object_created_notification,
52 			NULL);
53 	if (status != QDF_STATUS_SUCCESS) {
54 		disa_err("unable to register psoc create handler");
55 		goto err_free_ctx;
56 	}
57 
58 	status = wlan_objmgr_register_psoc_destroy_handler(
59 			WLAN_UMAC_COMP_DISA,
60 			disa_psoc_object_destroyed_notification,
61 			NULL);
62 	if (status != QDF_STATUS_SUCCESS) {
63 		disa_err("unable to register psoc destroy handler");
64 		wlan_objmgr_unregister_psoc_create_handler(
65 				WLAN_UMAC_COMP_DISA,
66 				disa_psoc_object_created_notification,
67 				NULL);
68 	} else {
69 		goto out;
70 	}
71 
72 err_free_ctx:
73 	disa_free_ctx();
74 out:
75 	DISA_EXIT();
76 
77 	return status;
78 }
79 
80 /**
81  * disa_deinit() - unregister disa notification handlers.
82  *
83  * This function unregisters disa related notification handlers and
84  * frees disa context.
85  *
86  * Return: QDF_STATUS_SUCCESS - in case of success else return error
87  */
disa_deinit(void)88 QDF_STATUS disa_deinit(void)
89 {
90 	QDF_STATUS status;
91 
92 	DISA_ENTER();
93 	status = wlan_objmgr_unregister_psoc_destroy_handler(
94 			WLAN_UMAC_COMP_DISA,
95 			disa_psoc_object_destroyed_notification,
96 			NULL);
97 	if (status != QDF_STATUS_SUCCESS)
98 		disa_err("unable to unregister psoc create handle");
99 
100 	status = wlan_objmgr_unregister_psoc_create_handler(
101 			WLAN_UMAC_COMP_DISA,
102 			disa_psoc_object_created_notification,
103 			NULL);
104 	if (status != QDF_STATUS_SUCCESS)
105 		disa_err("unable to unregister psoc create handle");
106 
107 	disa_free_ctx();
108 	DISA_EXIT();
109 
110 	return status;
111 }
112 
113 /**
114  * disa_psoc_object_created_notification(): disa psoc create handler
115  * @psoc: psoc which is going to created by objmgr
116  * @arg: argument for psoc create handler
117  *
118  * Attach psoc private object, register rx/tx ops and event handlers
119  *
120  * Return QDF_STATUS status in case of success else return error
121  */
disa_psoc_object_created_notification(struct wlan_objmgr_psoc * psoc,void * arg)122 QDF_STATUS disa_psoc_object_created_notification(
123 		struct wlan_objmgr_psoc *psoc, void *arg)
124 {
125 	struct disa_psoc_priv_obj *disa_priv;
126 	QDF_STATUS status;
127 
128 	DISA_ENTER();
129 
130 	disa_priv = qdf_mem_malloc(sizeof(*disa_priv));
131 	if (!disa_priv) {
132 		status = QDF_STATUS_E_NOMEM;
133 		goto out;
134 	}
135 
136 	status = wlan_objmgr_psoc_component_obj_attach(psoc,
137 			 WLAN_UMAC_COMP_DISA,
138 			(void *)disa_priv, QDF_STATUS_SUCCESS);
139 	if (status != QDF_STATUS_SUCCESS) {
140 		disa_err("Failed to attach disa_priv with psoc");
141 		qdf_mem_free(disa_priv);
142 		goto out;
143 	}
144 
145 	qdf_spinlock_create(&disa_priv->lock);
146 	target_if_disa_register_tx_ops(&disa_priv->disa_tx_ops);
147 
148 out:
149 	DISA_EXIT();
150 
151 	return status;
152 }
153 
154 /**
155  * disa_psoc_object_destroyed_notification(): disa psoc destroy handler
156  * @psoc: objmgr object corresponding to psoc which is going to be destroyed
157  * @arg: argument for psoc destroy handler
158  *
159  * Detach and free psoc private object, unregister event handlers
160  *
161  * Return QDF_STATUS status in case of success else return error
162  */
disa_psoc_object_destroyed_notification(struct wlan_objmgr_psoc * psoc,void * arg)163 QDF_STATUS disa_psoc_object_destroyed_notification(
164 		struct wlan_objmgr_psoc *psoc, void *arg)
165 {
166 	struct disa_psoc_priv_obj *disa_priv = NULL;
167 	QDF_STATUS status = QDF_STATUS_SUCCESS;
168 
169 	DISA_ENTER();
170 
171 	disa_priv = disa_psoc_get_priv(psoc);
172 
173 	status = wlan_objmgr_psoc_component_obj_detach(psoc,
174 			 WLAN_UMAC_COMP_DISA,
175 			(void *)disa_priv);
176 
177 	if (status != QDF_STATUS_SUCCESS)
178 		disa_err("Failed to detach disa_priv with psoc");
179 
180 	qdf_spinlock_destroy(&disa_priv->lock);
181 	qdf_mem_free(disa_priv);
182 	DISA_EXIT();
183 
184 	return status;
185 }
186 
187 /**
188  * disa_psoc_enable() - Trigger psoc enable for DISA
189  * @psoc: objmgr psoc object
190  *
191  * Return: QDF status success or failure
192  */
disa_psoc_enable(struct wlan_objmgr_psoc * psoc)193 QDF_STATUS disa_psoc_enable(struct wlan_objmgr_psoc *psoc)
194 {
195 	return tgt_disa_register_ev_handlers(psoc);
196 }
197 
198 /**
199  * disa_psoc_disable() - Trigger psoc disable for DISA
200  * @psoc: objmgr psoc object
201  *
202  * Return: QDF status success or failure
203  */
disa_psoc_disable(struct wlan_objmgr_psoc * psoc)204 QDF_STATUS disa_psoc_disable(struct wlan_objmgr_psoc *psoc)
205 {
206 	return tgt_disa_unregister_ev_handlers(psoc);
207 
208 }
209 
210