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