xref: /wlan-driver/qca-wifi-host-cmn/umac/cp_stats/core/src/wlan_cp_stats_defs.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2018-2019, 2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2024 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_defs.h
22  *
23  * This header file maintains core definitions of control plane statistics
24  * component
25  */
26 
27 #ifndef __WLAN_CP_STATS_DEFS_H__
28 #define __WLAN_CP_STATS_DEFS_H__
29 
30 #ifdef QCA_SUPPORT_CP_STATS
31 #include <wlan_objmgr_cmn.h>
32 #include <wlan_objmgr_global_obj.h>
33 #include <wlan_objmgr_psoc_obj.h>
34 #include <wlan_objmgr_pdev_obj.h>
35 #include <wlan_objmgr_vdev_obj.h>
36 #include <wlan_objmgr_peer_obj.h>
37 #include "wlan_cp_stats_cmn_defs.h"
38 #include <wlan_cp_stats_utils_api.h>
39 #include <wlan_cp_stats_ext_type.h>
40 #include <wlan_cp_stats_public_structs.h>
41 #include <wlan_twt_public_structs.h>
42 
43 /* noise floor */
44 #define CP_STATS_TGT_NOISE_FLOOR_DBM (-96)
45 
46 #ifdef WLAN_SUPPORT_INFRA_CTRL_PATH_STATS
47 typedef void (*get_infra_cp_stats_cb)(struct infra_cp_stats_event *ev,
48 				      void *cookie);
49 #endif
50 
51 /**
52  * struct psoc_cp_stats - defines cp stats at psoc object
53  * @psoc_obj: pointer to psoc
54  * @psoc_comp_priv_obj: component's private object pointers
55  * @psoc_cp_stats_lock: lock to protect object
56  * @cmn_stats: stats common for AP and STA devices
57  * @obj_stats: stats specific to AP or STA devices
58  * @legacy_stats_cb: callback to update the stats received from FW through
59  * asynchronous events.
60  * @get_infra_cp_stats: callback to update infra CP stats
61  * @infra_cp_stats_req_context: context to pass @get_infra_cp_stats
62  */
63 struct psoc_cp_stats {
64 	struct wlan_objmgr_psoc *psoc_obj;
65 	void *psoc_comp_priv_obj[WLAN_CP_STATS_MAX_COMPONENTS];
66 	qdf_spinlock_t psoc_cp_stats_lock;
67 	struct psoc_cmn_cp_stats *cmn_stats;
68 	psoc_ext_cp_stats_t *obj_stats;
69 	void (*legacy_stats_cb)(void *stats);
70 #ifdef WLAN_SUPPORT_INFRA_CTRL_PATH_STATS
71 	void (*get_infra_cp_stats)(struct infra_cp_stats_event *ev,
72 				   void *cookie);
73 	void *infra_cp_stats_req_context;
74 #endif
75 };
76 
77 /**
78  * struct pdev_cp_stats - defines cp stats at pdev object
79  * @pdev_obj: pointer to pdev
80  * @pdev_stats: pointer to ic/mc specific stats
81  * @pdev_comp_priv_obj: component's private object pointers
82  * @pdev_cp_stats_lock: lock to protect object
83  */
84 struct pdev_cp_stats {
85 	struct wlan_objmgr_pdev  *pdev_obj;
86 	pdev_ext_cp_stats_t *pdev_stats;
87 	void *pdev_comp_priv_obj[WLAN_CP_STATS_MAX_COMPONENTS];
88 	qdf_spinlock_t pdev_cp_stats_lock;
89 };
90 
91 /**
92  * struct vdev_cp_stats - defines cp stats at vdev object
93  * @vdev_obj: pointer to vdev
94  * @vdev_stats: pointer to ic/mc specific stats
95  * @vdev_comp_priv_obj: component's private object pointers
96  * @vdev_cp_stats_lock:	lock to protect object
97  * @mcast_rx_pnerr_stats_inc: callback function to update rx PN error stats
98  */
99 struct vdev_cp_stats {
100 	struct wlan_objmgr_vdev *vdev_obj;
101 	vdev_ext_cp_stats_t *vdev_stats;
102 	void *vdev_comp_priv_obj[WLAN_CP_STATS_MAX_COMPONENTS];
103 	qdf_spinlock_t vdev_cp_stats_lock;
104 	void (*mcast_rx_pnerr_stats_inc)(
105 			struct wlan_objmgr_vdev *vdev,
106 			uint64_t val);
107 };
108 
109 /**
110  * struct peer_cp_stats - defines cp stats at peer object
111  * @peer_obj: pointer to peer
112  * @peer_stats: pointer to ic/mc specific stats
113  * @peer_comp_priv_obj: component's private object pointers
114  * @peer_cp_stats_lock:	lock to protect object
115  * @rx_pnerr_stats_inc: callback function to update rx PN error stats
116  * @twt_param: Pointer to peer twt session parameters
117  */
118 struct peer_cp_stats {
119 	struct wlan_objmgr_peer *peer_obj;
120 	peer_ext_cp_stats_t *peer_stats;
121 	void *peer_comp_priv_obj[WLAN_CP_STATS_MAX_COMPONENTS];
122 	qdf_spinlock_t peer_cp_stats_lock;
123 	void (*rx_pnerr_stats_inc)(struct wlan_objmgr_peer *peer, uint32_t val);
124 #if defined(WLAN_SUPPORT_TWT) && defined(WLAN_TWT_CONV_SUPPORTED)
125 	struct twt_session_stats_info twt_param[WLAN_MAX_TWT_SESSIONS_PER_PEER];
126 #endif
127 };
128 
129 /**
130  * struct cp_stats_cfg_params - define CP stats INI configuration parameters
131  * @chipset_stats_enable: CP stats enable chipset stats logging from ini config
132  */
133 struct cp_stats_cfg_params {
134 	bool chipset_stats_enable;
135 };
136 
137 /**
138  * struct cp_stats_context - defines cp stats global context object
139  * @csc_lock: lock to protect object
140  * @psoc_obj: pointer to psoc
141  * @psoc_cs: pointer to cp stats at psoc
142  * @host_params: Structure for INI variables
143  * @cp_stats_ctx_init: callback pointer to init cp stats global ctx
144  * @cp_stats_ctx_deinit: callback pointer to deinit cp stats global ctx
145  * @cp_stats_psoc_obj_init:callback pointer to init cp stats obj on psoc create
146  * @cp_stats_psoc_obj_deinit:callback pointer to deinit cp stats obj on psoc
147  * destroy
148  * @cp_stats_pdev_obj_init:callback pointer to init cp stats obj on pdev create
149  * @cp_stats_pdev_obj_deinit:callback pointer to deinit cp stats obj on pdev
150  * destroy
151  * @cp_stats_vdev_obj_init:callback pointer to init cp stats obj on vdev create
152  * @cp_stats_vdev_obj_deinit:callback pointer to deinit cp stats obj on vdev
153  * destroy
154  * @cp_stats_peer_obj_init:callback pointer to init cp stats obj on peer create
155  * @cp_stats_peer_obj_deinit:callback pointer to deinit cp stats obj on peer
156  * destroy
157  * @cp_stats_comp_obj_config:callback pointer to attach/detach other umac comp
158  * @cp_stats_open: callback pointer for cp stats on psoc open
159  * @cp_stats_close: callback pointer for cp stats on psoc close
160  * @cp_stats_enable: callback pointer for cp stats on psoc enable
161  * @cp_stats_disable: callback pointer for cp stats on psoc disable
162  */
163 struct cp_stats_context {
164 	qdf_spinlock_t csc_lock;
165 	struct wlan_objmgr_psoc *psoc_obj;
166 	struct psoc_cp_stats    *psoc_cs;
167 	struct cp_stats_cfg_params host_params;
168 	QDF_STATUS (*cp_stats_ctx_init)(struct cp_stats_context *ctx);
169 	QDF_STATUS (*cp_stats_ctx_deinit)(struct cp_stats_context *ctx);
170 	QDF_STATUS (*cp_stats_psoc_obj_init)(struct psoc_cp_stats *psoc_cs);
171 	QDF_STATUS (*cp_stats_psoc_obj_deinit)(struct psoc_cp_stats *psoc_cs);
172 	QDF_STATUS (*cp_stats_pdev_obj_init)(struct pdev_cp_stats *pdev_cs);
173 	QDF_STATUS (*cp_stats_pdev_obj_deinit)(struct pdev_cp_stats *pdev_cs);
174 	QDF_STATUS (*cp_stats_vdev_obj_init)(struct vdev_cp_stats *vdev_cs);
175 	QDF_STATUS (*cp_stats_vdev_obj_deinit)(struct vdev_cp_stats *vdev_cs);
176 	QDF_STATUS (*cp_stats_peer_obj_init)(struct peer_cp_stats *peer_cs);
177 	QDF_STATUS (*cp_stats_peer_obj_deinit)(struct peer_cp_stats *peer_cs);
178 	QDF_STATUS (*cp_stats_comp_obj_config)(
179 			enum wlan_objmgr_obj_type obj_type,
180 			enum wlan_cp_stats_cfg_state cfg_state,
181 			enum wlan_cp_stats_comp_id comp_id,
182 			void *cmn_obj,
183 			void *data);
184 	QDF_STATUS (*cp_stats_open)(struct wlan_objmgr_psoc *psoc);
185 	QDF_STATUS (*cp_stats_close)(struct wlan_objmgr_psoc *psoc);
186 	QDF_STATUS (*cp_stats_enable)(struct wlan_objmgr_psoc *psoc);
187 	QDF_STATUS (*cp_stats_disable)(struct wlan_objmgr_psoc *psoc);
188 };
189 
190 /**
191  * wlan_cp_stats_psoc_obj_lock() - private API to acquire spinlock at psoc
192  * @psoc: pointer to psoc cp stats object
193  *
194  * Return: void
195  */
wlan_cp_stats_psoc_obj_lock(struct psoc_cp_stats * psoc)196 static inline void wlan_cp_stats_psoc_obj_lock(struct psoc_cp_stats *psoc)
197 {
198 	qdf_spin_lock_bh(&psoc->psoc_cp_stats_lock);
199 }
200 
201 /**
202  * wlan_cp_stats_psoc_obj_unlock() - private API to release spinlock at psoc
203  * @psoc: pointer to psoc cp stats object
204  *
205  * Return: void
206  */
wlan_cp_stats_psoc_obj_unlock(struct psoc_cp_stats * psoc)207 static inline void wlan_cp_stats_psoc_obj_unlock(struct psoc_cp_stats *psoc)
208 {
209 	qdf_spin_unlock_bh(&psoc->psoc_cp_stats_lock);
210 }
211 
212 /**
213  * wlan_cp_stats_pdev_obj_lock() - private API to acquire spinlock at pdev
214  * @pdev: pointer to pdev cp stats object
215  *
216  * Return: void
217  */
wlan_cp_stats_pdev_obj_lock(struct pdev_cp_stats * pdev)218 static inline void wlan_cp_stats_pdev_obj_lock(struct pdev_cp_stats *pdev)
219 {
220 	qdf_spin_lock_bh(&pdev->pdev_cp_stats_lock);
221 }
222 
223 /**
224  * wlan_cp_stats_pdev_obj_unlock() - private api to release spinlock at pdev
225  * @pdev: pointer to pdev cp stats object
226  *
227  * Return: void
228  */
wlan_cp_stats_pdev_obj_unlock(struct pdev_cp_stats * pdev)229 static inline void wlan_cp_stats_pdev_obj_unlock(struct pdev_cp_stats *pdev)
230 {
231 	qdf_spin_unlock_bh(&pdev->pdev_cp_stats_lock);
232 }
233 
234 /**
235  * wlan_cp_stats_vdev_obj_lock() - private api to acquire spinlock at vdev
236  * @vdev: pointer to vdev cp stats object
237  *
238  * Return: void
239  */
wlan_cp_stats_vdev_obj_lock(struct vdev_cp_stats * vdev)240 static inline void wlan_cp_stats_vdev_obj_lock(struct vdev_cp_stats *vdev)
241 {
242 	qdf_spin_lock_bh(&vdev->vdev_cp_stats_lock);
243 }
244 
245 /**
246  * wlan_cp_stats_vdev_obj_unlock() - private api to release spinlock at vdev
247  * @vdev: pointer to vdev cp stats object
248  *
249  * Return: void
250  */
wlan_cp_stats_vdev_obj_unlock(struct vdev_cp_stats * vdev)251 static inline void wlan_cp_stats_vdev_obj_unlock(struct vdev_cp_stats *vdev)
252 {
253 	qdf_spin_unlock_bh(&vdev->vdev_cp_stats_lock);
254 }
255 
256 /**
257  * wlan_cp_stats_peer_obj_lock() - private api to acquire spinlock at peer
258  * @peer: pointer to peer cp stats object
259  *
260  * Return: void
261  */
wlan_cp_stats_peer_obj_lock(struct peer_cp_stats * peer)262 static inline void wlan_cp_stats_peer_obj_lock(struct peer_cp_stats *peer)
263 {
264 	qdf_spin_lock_bh(&peer->peer_cp_stats_lock);
265 }
266 
267 /**
268  * wlan_cp_stats_peer_obj_unlock() - private api to release spinlock at peer
269  * @peer: pointer to peer cp stats object
270  *
271  * Return: void
272  */
wlan_cp_stats_peer_obj_unlock(struct peer_cp_stats * peer)273 static inline void wlan_cp_stats_peer_obj_unlock(struct peer_cp_stats *peer)
274 {
275 	qdf_spin_unlock_bh(&peer->peer_cp_stats_lock);
276 }
277 
278 /**
279  * wlan_cp_stats_get_psoc_stats_obj() - API to get psoc_cp_stats from psoc
280  * @psoc: Reference to psoc global object
281  *
282  * This API used to get psoc specific cp_stats object from global psoc
283  * reference.
284  *
285  * Return : Reference to psoc_cp_stats object on success or NULL on failure
286  */
287 static inline
wlan_cp_stats_get_psoc_stats_obj(struct wlan_objmgr_psoc * psoc)288 struct psoc_cp_stats *wlan_cp_stats_get_psoc_stats_obj(struct wlan_objmgr_psoc
289 							*psoc)
290 {
291 	struct cp_stats_context *csc;
292 
293 	if (!psoc)
294 		return NULL;
295 
296 	csc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
297 						    WLAN_UMAC_COMP_CP_STATS);
298 
299 	if (!csc)
300 		return NULL;
301 
302 	return csc->psoc_cs;
303 }
304 
305 /**
306  * wlan_cp_stats_get_pdev_stats_obj() - API to get pdev_cp_stats from pdev
307  * @pdev: Reference to pdev global object
308  *
309  * This API used to get pdev specific cp_stats object from global pdev
310  * reference.
311  *
312  * Return : Reference to pdev_cp_stats object on success or NULL on failure
313  */
314 static inline
wlan_cp_stats_get_pdev_stats_obj(struct wlan_objmgr_pdev * pdev)315 struct pdev_cp_stats *wlan_cp_stats_get_pdev_stats_obj(struct wlan_objmgr_pdev
316 							*pdev)
317 {
318 	struct pdev_cp_stats *pdev_cs = NULL;
319 
320 	if (pdev) {
321 		pdev_cs = wlan_objmgr_pdev_get_comp_private_obj
322 				(pdev, WLAN_UMAC_COMP_CP_STATS);
323 	}
324 
325 	return pdev_cs;
326 }
327 
328 /**
329  * wlan_cp_stats_get_vdev_stats_obj() - API to get vdev_cp_stats from vdev
330  * @vdev : Reference to vdev global object
331  *
332  * This API used to get vdev specific cp_stats object from global vdev
333  * reference.
334  *
335  * Return : Reference to vdev_cp_stats object on success or NULL on failure
336  */
337 static inline
wlan_cp_stats_get_vdev_stats_obj(struct wlan_objmgr_vdev * vdev)338 struct vdev_cp_stats *wlan_cp_stats_get_vdev_stats_obj(struct wlan_objmgr_vdev
339 							*vdev)
340 {
341 	struct vdev_cp_stats *vdev_cs = NULL;
342 
343 	if (vdev) {
344 		vdev_cs = wlan_objmgr_vdev_get_comp_private_obj
345 				(vdev, WLAN_UMAC_COMP_CP_STATS);
346 	}
347 
348 	return vdev_cs;
349 }
350 
351 /**
352  * wlan_cp_stats_get_peer_stats_obj() - API to get peer_cp_stats from peer
353  * @peer: Reference to peer global object
354  *
355  * This API used to get peer specific cp_stats object from global peer
356  * reference.
357  *
358  * Return : Reference to peer_cp_stats object on success or NULL on failure
359  */
360 static inline
wlan_cp_stats_get_peer_stats_obj(struct wlan_objmgr_peer * peer)361 struct peer_cp_stats *wlan_cp_stats_get_peer_stats_obj(struct wlan_objmgr_peer
362 							*peer)
363 {
364 	struct peer_cp_stats *peer_cs = NULL;
365 
366 	if (peer) {
367 		peer_cs = wlan_objmgr_peer_get_comp_private_obj
368 				(peer, WLAN_UMAC_COMP_CP_STATS);
369 	}
370 
371 	return peer_cs;
372 }
373 
374 /**
375  * wlan_cp_stats_get_pdev_from_vdev() - API to get pdev_cp_stats obj from vdev
376  * @vdev: Reference to vdev global object
377  *
378  * This API used to get pdev specific cp_stats object from global vdev
379  * reference.
380  *
381  * Return: Reference to pdev_cp_stats object on success or NULL on failure
382  */
383 static inline
wlan_cp_stats_get_pdev_from_vdev(struct wlan_objmgr_vdev * vdev)384 struct pdev_cp_stats *wlan_cp_stats_get_pdev_from_vdev(struct wlan_objmgr_vdev
385 							*vdev)
386 {
387 	struct wlan_objmgr_pdev *pdev;
388 	struct pdev_cp_stats *pdev_cs = NULL;
389 
390 	pdev = wlan_vdev_get_pdev(vdev);
391 	if (pdev) {
392 		pdev_cs = wlan_objmgr_pdev_get_comp_private_obj
393 				(pdev, WLAN_UMAC_COMP_CP_STATS);
394 	}
395 
396 	return pdev_cs;
397 }
398 
399 /**
400  * wlan_cp_stats_ctx_get_from_pdev() - API to get cp_stats ctx obj from pdev
401  * @pdev: Reference to pdev global object
402  *
403  * This API used to get cp_stats context object from global pdev reference.
404  *
405  * Return: Reference to cp_stats_context object on success or NULL on failure
406  */
407 static inline
wlan_cp_stats_ctx_get_from_pdev(struct wlan_objmgr_pdev * pdev)408 struct cp_stats_context *wlan_cp_stats_ctx_get_from_pdev(struct wlan_objmgr_pdev
409 							*pdev)
410 {
411 	struct wlan_objmgr_psoc *psoc;
412 	struct cp_stats_context *csc = NULL;
413 
414 	if (!pdev)
415 		return NULL;
416 
417 	psoc = wlan_pdev_get_psoc(pdev);
418 	if (psoc) {
419 		csc = wlan_objmgr_psoc_get_comp_private_obj
420 				(psoc, WLAN_UMAC_COMP_CP_STATS);
421 	}
422 	return csc;
423 }
424 
425 /**
426  * wlan_cp_stats_ctx_get_from_vdev() - API to get cp_stats ctx obj from vdev
427  * @vdev: Reference to vdev global object
428  *
429  * This API used to get cp_stats context object from global vdev reference.
430  *
431  * Return: Reference to cp_stats_context object on success or NULL on failure
432  */
433 static inline
wlan_cp_stats_ctx_get_from_vdev(struct wlan_objmgr_vdev * vdev)434 struct cp_stats_context *wlan_cp_stats_ctx_get_from_vdev(struct wlan_objmgr_vdev
435 							*vdev)
436 {
437 	struct wlan_objmgr_pdev *pdev;
438 
439 	if (!vdev)
440 		return NULL;
441 
442 	pdev = wlan_vdev_get_pdev(vdev);
443 	return wlan_cp_stats_ctx_get_from_pdev(pdev);
444 }
445 
446 /**
447  * wlan_cp_stats_ctx_get_from_peer() - API to get cp_stats ctx object from peer
448  * @peer: Reference to peer object
449  *
450  * This API used to get cp_stats context object from global peer reference.
451  *
452  * Return: Reference to cp_stats_context object on success or NULL on failure
453  */
454 static inline
wlan_cp_stats_ctx_get_from_peer(struct wlan_objmgr_peer * peer)455 struct cp_stats_context *wlan_cp_stats_ctx_get_from_peer(struct wlan_objmgr_peer
456 							*peer)
457 {
458 	struct wlan_objmgr_vdev *vdev;
459 
460 	vdev = wlan_peer_get_vdev(peer);
461 	return wlan_cp_stats_ctx_get_from_vdev(vdev);
462 }
463 
464 /**
465  * wlan_cp_stats_get_comp_id() - API to get cp_stats component id from umac
466  * component id
467  * @comp_id: umac comp id
468  *
469  * Return: wlan_cp_stats_comp_id
470  */
471 static inline enum wlan_cp_stats_comp_id
wlan_cp_stats_get_comp_id(enum wlan_umac_comp_id comp_id)472 wlan_cp_stats_get_comp_id(enum wlan_umac_comp_id comp_id)
473 {
474 	enum wlan_cp_stats_comp_id cp_stats_comp_id =
475 		WLAN_CP_STATS_MAX_COMPONENTS;
476 
477 	if (comp_id == WLAN_UMAC_COMP_ATF)
478 		cp_stats_comp_id = WLAN_CP_STATS_ATF;
479 
480 	return cp_stats_comp_id;
481 }
482 
483 #endif /* QCA_SUPPORT_CP_STATS */
484 #endif /* __WLAN_CP_STATS_DEFS_H__ */
485