1 /*
2 * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
3 * SPDX-License-Identifier: ISC
4 */
5
6 /**
7 * DOC: This file contains chipset stats implementstion
8 */
9
10 #ifndef __WLAN_CP_STATS_CHIPSET_STATS__
11 #define __WLAN_CP_STATS_CHIPSET_STATS__
12
13 #include <wlan_cmn.h>
14 #include <qdf_status.h>
15 #include <qdf_trace.h>
16 #include "wlan_cp_stats_chipset_stats_events.h"
17
18 #define MAX_CSTATS_NODE_LENGTH 2048
19 #define MAX_CSTATS_NODE_COUNT 256
20 #define MAX_CSTATS_VERSION_BUFF_LENGTH 100
21
22 #define CSTATS_QMI_EVENT_TYPE 1
23
24 #define ANI_NL_MSG_CSTATS_HOST_LOG_TYPE 110
25 #define ANI_NL_MSG_CSTATS_FW_LOG_TYPE 111
26
27 #define CSTATS_MARKER_SZ 6
28 #define CSTATS_HOST_START_MARKER "CS_HSM"
29 #define CSTATS_HOST_END_MARKER "CS_HEM"
30 #define CSTATS_FW_START_MARKER "CS_FSM"
31 #define CSTATS_FW_END_MARKER "CS_FEM"
32
33 #ifdef QDF_LITTLE_ENDIAN_MACHINE
34 #define CHIPSET_STATS_MACHINE_ENDIANNESS (0)
35 #else
36 #define CHIPSET_STATS_MACHINE_ENDIANNESS (1)
37 #endif
38
39 #define CSTATS_SET_BIT(value, mask) ((value) |= (1 << (mask)))
40
41 #define CSTATS_MAC_COPY(to, from) \
42 do {\
43 to[0] = from[0]; \
44 to[1] = from[1]; \
45 to[2] = from[2]; \
46 to[3] = from[5]; \
47 } while (0)
48
49 /**
50 * enum cstats_types - Types of chipset stats
51 * @CSTATS_HOST_TYPE : Host related chipset stats
52 * @CSTATS_FW_TYPE : Firmware related chipset stats
53 * @CSTATS_MAX_TYPE : Invalid
54 */
55 enum cstats_types {
56 CSTATS_HOST_TYPE,
57 CSTATS_FW_TYPE,
58 CSTATS_MAX_TYPE,
59 };
60
61 struct cstats_tx_rx_ops {
62 int (*cstats_send_data_to_usr)(char *buff, unsigned int len,
63 enum cstats_types type);
64 };
65
66 struct cstats_node {
67 qdf_list_node_t node;
68 unsigned int radio;
69 unsigned int index;
70 unsigned int filled_length;
71 char logbuf[MAX_CSTATS_NODE_LENGTH];
72 };
73
74 struct chipset_stats {
75 qdf_list_t cstat_free_list[CSTATS_MAX_TYPE];
76 qdf_list_t cstat_filled_list[CSTATS_MAX_TYPE];
77
78 /* Lock to synchronize access to shared cstats resource */
79 qdf_spinlock_t cstats_lock[CSTATS_MAX_TYPE];
80 struct cstats_node *ccur_node[CSTATS_MAX_TYPE];
81 unsigned int cstat_drop_cnt[CSTATS_MAX_TYPE];
82
83 /* Dont move filled list nodes to free list after flush to user space */
84 bool cstats_no_flush[CSTATS_MAX_TYPE];
85 struct cstats_tx_rx_ops ops;
86 bool is_cstats_ini_enabled;
87 };
88
89 #define wlan_cstats_fw_stats(len, buf) \
90 wlan_cp_stats_cstats_write_to_buff(CSTATS_FW_TYPE, buf, len)
91 #define wlan_cstats_host_stats(len, buf) \
92 wlan_cp_stats_cstats_write_to_buff(CSTATS_HOST_TYPE, buf, len)
93
94 #ifdef WLAN_CHIPSET_STATS
95 /**
96 * wlan_cp_stats_cstats_init() - Initialize chipset stats infra
97 *
98 * @psoc: pointer to psoc object
99 *
100 * Return: QDF_STATUS
101 */
102 QDF_STATUS wlan_cp_stats_cstats_init(struct wlan_objmgr_psoc *psoc);
103
104 /**
105 * wlan_cp_stats_cstats_deinit() - Deinitialize chipset stats infra
106 *
107 * Return: void
108 */
109 void wlan_cp_stats_cstats_deinit(void);
110
111 /**
112 * wlan_cp_stats_cstats_register_tx_rx_ops() - Register chipset stats ops
113 *
114 * @ops : tx rx ops
115 *
116 * Return: void
117 */
118 void wlan_cp_stats_cstats_register_tx_rx_ops(struct cstats_tx_rx_ops *ops);
119
120 /*
121 * wlan_cp_stats_cstats_write_to_buff() - Write stats to the chipset stats
122 * buffer
123 * @type: Type of chipset stats to be written
124 * @to_be_sent: Pointer to stats payload which is to be write to cstats buffer
125 * @length: Length of the payload
126 *
127 * Return : void
128 */
129 void wlan_cp_stats_cstats_write_to_buff(enum cstats_types type,
130 void *to_be_sent,
131 uint32_t length);
132
133 /**
134 * wlan_cp_stats_cstats_send_buffer_to_user() - Flush chipset stats to the
135 * middleware
136 * @type: Type of chipset stats to be sent
137 *
138 * Return : 0 on success and errno on failure
139 */
140 int wlan_cp_stats_cstats_send_buffer_to_user(enum cstats_types type);
141
142 /*
143 * wlan_cp_stats_cstats_pkt_log() - Data packets stats
144 * @sa - Source addr
145 * @da - Destination addr
146 * @pkt_type - Packet type
147 * @subtype - Subtype
148 * @dir - Direction
149 * @status - Status
150 * @vdev_id - Vdev iD
151 * @op_mode - opmode
152 *
153 * Return : void
154 */
155 void wlan_cp_stats_cstats_pkt_log(uint8_t *sa, uint8_t *da,
156 enum qdf_proto_type pkt_type,
157 enum qdf_proto_subtype subtype,
158 enum qdf_proto_dir dir,
159 enum qdf_dp_tx_rx_status status,
160 uint8_t vdev_id, enum QDF_OPMODE op_mode);
161 #else
162 static inline QDF_STATUS
wlan_cp_stats_cstats_init(struct wlan_objmgr_psoc * psoc)163 wlan_cp_stats_cstats_init(struct wlan_objmgr_psoc *psoc)
164 {
165 return 0;
166 }
167
wlan_cp_stats_cstats_deinit(void)168 static inline void wlan_cp_stats_cstats_deinit(void)
169 {
170 }
171
172 static inline void
wlan_cp_stats_cstats_register_tx_rx_ops(struct cstats_tx_rx_ops * ops)173 wlan_cp_stats_cstats_register_tx_rx_ops(struct cstats_tx_rx_ops *ops)
174 {
175 }
176
177 static inline void
wlan_cp_stats_cstats_write_to_buff(enum cstats_types type,void * to_be_sent,uint32_t length)178 wlan_cp_stats_cstats_write_to_buff(enum cstats_types type, void *to_be_sent,
179 uint32_t length)
180 {
181 }
182
183 static inline int
wlan_cp_stats_cstats_send_buffer_to_user(enum cstats_types type)184 wlan_cp_stats_cstats_send_buffer_to_user(enum cstats_types type)
185 {
186 return 0;
187 }
188 #endif /* WLAN_CHIPSET_STATS */
189 #endif /* __WLAN_CP_STATS_CHIPSET_STATS__ */
190