xref: /wlan-dirver/qca-wifi-host-cmn/umac/cp_stats/dispatcher/src/wlan_cp_stats_utils_api.c (revision 6ecd284e5a94a1c96e26d571dd47419ac305990d)
1 /*
2  * Copyright (c) 2018 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: wlan_cp_stats_utils_api.c
21  *
22  * This file provide public API definitions for other accessing other UMAC
23  * components
24  */
25 #include "../../core/src/wlan_cp_stats_defs.h"
26 #include "../../core/src/wlan_cp_stats_obj_mgr_handler.h"
27 #include <wlan_cp_stats_utils_api.h>
28 #include <wlan_cp_stats_ucfg_api.h>
29 
30 QDF_STATUS wlan_cp_stats_init(void)
31 {
32 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
33 
34 	status = wlan_objmgr_register_psoc_create_handler
35 				(WLAN_UMAC_COMP_CP_STATS,
36 				 wlan_cp_stats_psoc_obj_create_handler,
37 				 NULL);
38 	if (QDF_IS_STATUS_ERROR(status)) {
39 		cp_stats_err("Failed to register psoc create handler");
40 		goto wlan_cp_stats_psoc_init_fail1;
41 	}
42 
43 	status = wlan_objmgr_register_psoc_destroy_handler
44 				(WLAN_UMAC_COMP_CP_STATS,
45 				 wlan_cp_stats_psoc_obj_destroy_handler,
46 				 NULL);
47 	if (QDF_IS_STATUS_ERROR(status)) {
48 		cp_stats_err("Failed to register psoc destroy handler");
49 		goto wlan_cp_stats_psoc_init_fail2;
50 	}
51 
52 	status = wlan_objmgr_register_pdev_create_handler
53 				(WLAN_UMAC_COMP_CP_STATS,
54 				 wlan_cp_stats_pdev_obj_create_handler,
55 				 NULL);
56 	if (QDF_IS_STATUS_ERROR(status)) {
57 		cp_stats_err("Failed to register pdev create handler");
58 		goto wlan_cp_stats_pdev_init_fail1;
59 	}
60 
61 	status = wlan_objmgr_register_pdev_destroy_handler
62 				(WLAN_UMAC_COMP_CP_STATS,
63 				 wlan_cp_stats_pdev_obj_destroy_handler,
64 				 NULL);
65 	if (QDF_IS_STATUS_ERROR(status)) {
66 		cp_stats_err("Failed to register pdev destroy handler");
67 		goto wlan_cp_stats_pdev_init_fail2;
68 	}
69 
70 	status = wlan_objmgr_register_vdev_create_handler
71 				(WLAN_UMAC_COMP_CP_STATS,
72 				 wlan_cp_stats_vdev_obj_create_handler,
73 				 NULL);
74 	if (QDF_IS_STATUS_ERROR(status)) {
75 		cp_stats_err("Failed to register vdev create handler");
76 		goto wlan_cp_stats_vdev_init_fail1;
77 	}
78 
79 	status = wlan_objmgr_register_vdev_destroy_handler
80 				(WLAN_UMAC_COMP_CP_STATS,
81 				 wlan_cp_stats_vdev_obj_destroy_handler,
82 				 NULL);
83 	if (QDF_IS_STATUS_ERROR(status)) {
84 		cp_stats_err("Failed to register vdev destroy handler");
85 		goto wlan_cp_stats_vdev_init_fail2;
86 	}
87 
88 	status = wlan_objmgr_register_peer_create_handler
89 				(WLAN_UMAC_COMP_CP_STATS,
90 				 wlan_cp_stats_peer_obj_create_handler,
91 				 NULL);
92 	if (QDF_IS_STATUS_ERROR(status)) {
93 		cp_stats_err("Failed to register peer create handler");
94 		goto wlan_cp_stats_peer_init_fail1;
95 	}
96 
97 	status = wlan_objmgr_register_peer_destroy_handler
98 				(WLAN_UMAC_COMP_CP_STATS,
99 				 wlan_cp_stats_peer_obj_destroy_handler,
100 				 NULL);
101 	if (QDF_IS_STATUS_ERROR(status)) {
102 		cp_stats_err("Failed to register peer destroy handler");
103 		goto wlan_cp_stats_peer_init_fail2;
104 	}
105 
106 	return QDF_STATUS_SUCCESS;
107 
108 wlan_cp_stats_peer_init_fail2:
109 	wlan_objmgr_unregister_peer_create_handler
110 		(WLAN_UMAC_COMP_CP_STATS,
111 		 wlan_cp_stats_peer_obj_create_handler,
112 		 NULL);
113 wlan_cp_stats_peer_init_fail1:
114 	wlan_objmgr_unregister_vdev_destroy_handler
115 		(WLAN_UMAC_COMP_CP_STATS,
116 		 wlan_cp_stats_vdev_obj_destroy_handler,
117 		 NULL);
118 wlan_cp_stats_vdev_init_fail2:
119 	wlan_objmgr_unregister_vdev_create_handler
120 		(WLAN_UMAC_COMP_CP_STATS,
121 		 wlan_cp_stats_vdev_obj_create_handler,
122 		 NULL);
123 wlan_cp_stats_vdev_init_fail1:
124 	wlan_objmgr_unregister_pdev_destroy_handler
125 		(WLAN_UMAC_COMP_CP_STATS,
126 		 wlan_cp_stats_pdev_obj_destroy_handler,
127 		 NULL);
128 wlan_cp_stats_pdev_init_fail2:
129 	wlan_objmgr_unregister_pdev_create_handler
130 		(WLAN_UMAC_COMP_CP_STATS,
131 		 wlan_cp_stats_pdev_obj_create_handler,
132 		 NULL);
133 wlan_cp_stats_pdev_init_fail1:
134 	wlan_objmgr_unregister_psoc_destroy_handler
135 		(WLAN_UMAC_COMP_CP_STATS,
136 		 wlan_cp_stats_psoc_obj_destroy_handler,
137 		 NULL);
138 wlan_cp_stats_psoc_init_fail2:
139 	wlan_objmgr_unregister_psoc_create_handler
140 		(WLAN_UMAC_COMP_CP_STATS,
141 		 wlan_cp_stats_psoc_obj_create_handler,
142 		 NULL);
143 wlan_cp_stats_psoc_init_fail1:
144 	return status;
145 }
146 
147 QDF_STATUS wlan_cp_stats_deinit(void)
148 {
149 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
150 
151 	status = wlan_objmgr_unregister_psoc_create_handler
152 				(WLAN_UMAC_COMP_CP_STATS,
153 				 wlan_cp_stats_psoc_obj_create_handler,
154 				 NULL);
155 	if (QDF_IS_STATUS_ERROR(status))
156 		cp_stats_err("Failed to unregister psoc create handler");
157 
158 	status = wlan_objmgr_unregister_psoc_destroy_handler
159 				(WLAN_UMAC_COMP_CP_STATS,
160 				 wlan_cp_stats_psoc_obj_destroy_handler,
161 				 NULL);
162 	if (QDF_IS_STATUS_ERROR(status))
163 		cp_stats_err("Failed to unregister psoc destroy handler");
164 
165 	status = wlan_objmgr_unregister_pdev_create_handler
166 				(WLAN_UMAC_COMP_CP_STATS,
167 				 wlan_cp_stats_pdev_obj_create_handler,
168 				 NULL);
169 	if (QDF_IS_STATUS_ERROR(status))
170 		cp_stats_err("Failed to unregister pdev create handler");
171 
172 	status = wlan_objmgr_unregister_pdev_destroy_handler
173 				(WLAN_UMAC_COMP_CP_STATS,
174 				 wlan_cp_stats_pdev_obj_destroy_handler,
175 				 NULL);
176 	if (QDF_IS_STATUS_ERROR(status))
177 		cp_stats_err("Failed to unregister pdev destroy handler");
178 
179 	status = wlan_objmgr_unregister_vdev_create_handler
180 				(WLAN_UMAC_COMP_CP_STATS,
181 				 wlan_cp_stats_vdev_obj_create_handler,
182 				 NULL);
183 	if (QDF_IS_STATUS_ERROR(status))
184 		cp_stats_err("Failed to unregister vdev create handler");
185 
186 	status = wlan_objmgr_unregister_vdev_destroy_handler
187 				(WLAN_UMAC_COMP_CP_STATS,
188 				 wlan_cp_stats_vdev_obj_destroy_handler,
189 				 NULL);
190 	if (QDF_IS_STATUS_ERROR(status))
191 		cp_stats_err("Failed to unregister vdev destroy handler");
192 
193 	status = wlan_objmgr_unregister_peer_create_handler
194 				(WLAN_UMAC_COMP_CP_STATS,
195 				 wlan_cp_stats_peer_obj_create_handler,
196 				 NULL);
197 	if (QDF_IS_STATUS_ERROR(status))
198 		cp_stats_err("Failed to unregister peer create handler");
199 
200 	status = wlan_objmgr_unregister_peer_destroy_handler
201 				(WLAN_UMAC_COMP_CP_STATS,
202 				 wlan_cp_stats_peer_obj_destroy_handler,
203 				 NULL);
204 	if (QDF_IS_STATUS_ERROR(status))
205 		cp_stats_err("Failed to unregister peer destroy handler");
206 
207 	return status;
208 }
209 
210 /* DA/OL specific call back initialization */
211 QDF_STATUS wlan_cp_stats_open(struct wlan_objmgr_psoc *psoc)
212 {
213 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
214 	struct cp_stats_context *csc;
215 
216 	if (!psoc) {
217 		cp_stats_err("PSOC is null!");
218 		return QDF_STATUS_E_INVAL;
219 	}
220 	csc =
221 	wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS);
222 	if (!csc) {
223 		cp_stats_err("cp_stats_context is null!");
224 		return QDF_STATUS_E_FAILURE;
225 	}
226 
227 	if (csc->cp_stats_open)
228 		status = csc->cp_stats_open(psoc);
229 
230 	qdf_spinlock_create(&csc->csc_lock);
231 	return status;
232 }
233 
234 QDF_STATUS wlan_cp_stats_close(struct wlan_objmgr_psoc *psoc)
235 {
236 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
237 	struct cp_stats_context *csc;
238 
239 	if (!psoc) {
240 		cp_stats_err("PSOC is null!");
241 		return QDF_STATUS_E_INVAL;
242 	}
243 	csc =
244 	wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS);
245 	if (!csc) {
246 		cp_stats_err("cp_stats_context is null!");
247 		return QDF_STATUS_E_FAILURE;
248 	}
249 
250 	if (csc->cp_stats_close)
251 		status = csc->cp_stats_close(psoc);
252 
253 	qdf_spinlock_destroy(&csc->csc_lock);
254 	return status;
255 }
256 
257 /* WMI registrations stage */
258 QDF_STATUS wlan_cp_stats_enable(struct wlan_objmgr_psoc *psoc)
259 {
260 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
261 	struct cp_stats_context *csc;
262 
263 	if (!psoc) {
264 		cp_stats_err("PSOC is null!\n");
265 		return QDF_STATUS_E_INVAL;
266 	}
267 	csc =
268 	wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS);
269 	if (!csc) {
270 		cp_stats_err("cp_stats_context is null!\n");
271 		return QDF_STATUS_E_FAILURE;
272 	}
273 
274 	if (csc->cp_stats_enable)
275 		status = csc->cp_stats_enable(psoc);
276 
277 	return status;
278 }
279 
280 QDF_STATUS wlan_cp_stats_disable(struct wlan_objmgr_psoc *psoc)
281 {
282 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
283 	struct cp_stats_context *csc;
284 
285 	if (!psoc) {
286 		cp_stats_err("PSOC is null!\n");
287 		return QDF_STATUS_E_INVAL;
288 	}
289 	csc =
290 	wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS);
291 	if (!csc) {
292 		cp_stats_err("cp_stats_context is null!\n");
293 		return QDF_STATUS_E_FAILURE;
294 	}
295 
296 	if (csc->cp_stats_disable)
297 		status = csc->cp_stats_disable(psoc);
298 
299 	return status;
300 }
301 
302 QDF_STATUS
303 wlan_cp_stats_comp_obj_configure(enum wlan_objmgr_obj_type obj_type,
304 				enum wlan_cp_stats_cfg_state cfg_state,
305 				enum wlan_umac_comp_id comp_id,
306 				void *cmn_obj, void *data)
307 {
308 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
309 	struct cp_stats_context *csc;
310 	struct wlan_objmgr_psoc *psoc;
311 	struct wlan_objmgr_pdev *pdev;
312 	struct wlan_objmgr_vdev *vdev;
313 	struct wlan_objmgr_peer *peer;
314 	enum wlan_cp_stats_comp_id cp_stats_comp_id;
315 
316 	if (!cmn_obj) {
317 		cp_stats_err("common object is null!");
318 		return QDF_STATUS_E_INVAL;
319 	}
320 
321 	cp_stats_comp_id = wlan_cp_stats_get_comp_id(comp_id);
322 	if (cp_stats_comp_id >= WLAN_CP_STATS_MAX_COMPONENTS) {
323 		cp_stats_err("Invalid UMAC id provided to cp_stats");
324 		return QDF_STATUS_E_INVAL;
325 	}
326 
327 	switch (obj_type) {
328 	case WLAN_PSOC_OP:
329 		psoc = (struct wlan_objmgr_psoc *)cmn_obj;
330 		csc =
331 		wlan_objmgr_psoc_get_comp_private_obj
332 				(psoc, WLAN_UMAC_COMP_CP_STATS);
333 		break;
334 	case WLAN_PDEV_OP:
335 		pdev = (struct wlan_objmgr_pdev *)cmn_obj;
336 		csc = wlan_cp_stats_ctx_get_from_pdev(pdev);
337 		break;
338 	case WLAN_VDEV_OP:
339 		vdev = (struct wlan_objmgr_vdev *)cmn_obj;
340 		csc = wlan_cp_stats_ctx_get_from_vdev(vdev);
341 		break;
342 	case WLAN_PEER_OP:
343 		peer = (struct wlan_objmgr_peer *)cmn_obj;
344 		csc = wlan_cp_stats_ctx_get_from_peer(peer);
345 		break;
346 	default:
347 		cp_stats_err("Invalid common object type");
348 		return QDF_STATUS_E_INVAL;
349 	}
350 
351 	if (!csc) {
352 		cp_stats_err("cp_stats_context is null!");
353 		return QDF_STATUS_E_FAILURE;
354 	}
355 
356 	if (csc->cp_stats_comp_obj_config)
357 		status = csc->cp_stats_comp_obj_config(obj_type, cfg_state,
358 							cp_stats_comp_id,
359 							cmn_obj, data);
360 
361 	return status;
362 }
363