xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/wifi_stats.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Common stats definitions for clients of dongle
3  * ports
4  *
5  * Copyright (C) 2020, Broadcom.
6  *
7  *      Unless you and Broadcom execute a separate written software license
8  * agreement governing use of this software, this software is licensed to you
9  * under the terms of the GNU General Public License version 2 (the "GPL"),
10  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11  * following added to such license:
12  *
13  *      As a special exception, the copyright holders of this software give you
14  * permission to link this software with independent modules, and to copy and
15  * distribute the resulting executable under terms of your choice, provided that
16  * you also meet, for each linked independent module, the terms and conditions of
17  * the license of that module.  An independent module is a module which is not
18  * derived from this software.  The special exception does not apply to any
19  * modifications of the software.
20  *
21  *
22  * <<Broadcom-WL-IPTag/Dual:>>
23  */
24 
25 #ifndef _wifi_stats_h_
26 #define _wifi_stats_h_
27 
28 // remove the conditional after moving all branches to use the new code
29 #ifdef USE_WIFI_STATS_H
30 
31 #include <ethernet.h>
32 #include <802.11.h>
33 
34 typedef int32 wifi_radio;
35 typedef int32 wifi_channel;
36 typedef int32 wifi_rssi;
37 typedef struct { uint16 version; uint16 length; } ver_len;
38 
39 typedef enum wifi_channel_width {
40 	WIFI_CHAN_WIDTH_20	  = 0,
41 	WIFI_CHAN_WIDTH_40	  = 1,
42 	WIFI_CHAN_WIDTH_80	  = 2,
43 	WIFI_CHAN_WIDTH_160   = 3,
44 	WIFI_CHAN_WIDTH_80P80 = 4,
45 	WIFI_CHAN_WIDTH_5	  = 5,
46 	WIFI_CHAN_WIDTH_10	  = 6,
47 	WIFI_CHAN_WIDTH_INVALID = -1
48 } wifi_channel_width_t;
49 
50 typedef enum {
51 	WIFI_DISCONNECTED = 0,
52 	WIFI_AUTHENTICATING = 1,
53 	WIFI_ASSOCIATING = 2,
54 	WIFI_ASSOCIATED = 3,
55 	WIFI_EAPOL_STARTED = 4,   /* if done by firmware/driver */
56 	WIFI_EAPOL_COMPLETED = 5, /* if done by firmware/driver */
57 } wifi_connection_state;
58 
59 typedef enum {
60 	WIFI_ROAMING_IDLE = 0,
61 	WIFI_ROAMING_ACTIVE = 1
62 } wifi_roam_state;
63 
64 typedef enum {
65 	WIFI_INTERFACE_STA = 0,
66 	WIFI_INTERFACE_SOFTAP = 1,
67 	WIFI_INTERFACE_IBSS = 2,
68 	WIFI_INTERFACE_P2P_CLIENT = 3,
69 	WIFI_INTERFACE_P2P_GO = 4,
70 	WIFI_INTERFACE_NAN = 5,
71 	WIFI_INTERFACE_MESH = 6
72 } wifi_interface_mode;
73 
74 #define WIFI_CAPABILITY_QOS          0x00000001     /* set for QOS association */
75 #define WIFI_CAPABILITY_PROTECTED    0x00000002     /* set for protected association (802.11
76 						     * beacon frame control protected bit set)
77 						     */
78 #define WIFI_CAPABILITY_INTERWORKING 0x00000004     /* set if 802.11 Extended Capabilities
79 						     * element interworking bit is set
80 						     */
81 #define WIFI_CAPABILITY_HS20         0x00000008     /* set for HS20 association */
82 #define WIFI_CAPABILITY_SSID_UTF8    0x00000010     /* set is 802.11 Extended Capabilities
83 						     * element UTF-8 SSID bit is set
84 						     */
85 #define WIFI_CAPABILITY_COUNTRY      0x00000020     /* set is 802.11 Country Element is present */
86 #if defined(__linux__)
87 #define PACK_ATTRIBUTE __attribute__ ((packed))
88 #else
89 #define PACK_ATTRIBUTE
90 #endif
91 typedef struct {
92 	wifi_interface_mode mode;     /* interface mode */
93 	uint8 mac_addr[6];               /* interface mac address (self) */
94 	uint8 PAD[2];
95 	wifi_connection_state state;  /* connection state (valid for STA, CLI only) */
96 	wifi_roam_state roaming;      /* roaming state */
97 	uint32 capabilities;             /* WIFI_CAPABILITY_XXX (self) */
98 	uint8 ssid[DOT11_MAX_SSID_LEN+1]; /* null terminated SSID */
99 	uint8 bssid[ETHER_ADDR_LEN];     /* bssid */
100 	uint8 PAD[1];
101 	uint8 ap_country_str[3];         /* country string advertised by AP */
102 	uint8 country_str[3];            /* country string for this association */
103 	uint8 PAD[2];
104 } wifi_interface_info;
105 
106 typedef wifi_interface_info *wifi_interface_handle;
107 
108 /* channel information */
109 typedef struct {
110 	wifi_channel_width_t width;   /* channel width (20, 40, 80, 80+80, 160) */
111 	wifi_channel center_freq;   /* primary 20 MHz channel */
112 	wifi_channel center_freq0;  /* center frequency (MHz) first segment */
113 	wifi_channel center_freq1;  /* center frequency (MHz) second segment */
114 } wifi_channel_info;
115 
116 /* wifi rate */
117 typedef struct {
118 	uint32 preamble;   /* 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved */
119 	uint32 nss;   	/* 0:1x1, 1:2x2, 3:3x3, 4:4x4 */
120 	uint32 bw;   	/* 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz */
121 	uint32 rateMcsIdx; /* OFDM/CCK rate code would be as per ieee std
122 			    * in the units of 0.5mbps
123 			    */
124 			/* HT/VHT it would be mcs index */
125 	uint32 reserved;   /* reserved */
126 	uint32 bitrate;    /* units of 100 Kbps */
127 } wifi_rate;
128 
129 typedef struct {
130 	uint32 preamble   :3;   /* 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved */
131 	uint32 nss        :2;   /* 0:1x1, 1:2x2, 3:3x3, 4:4x4 */
132 	uint32 bw         :3;   /* 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz */
133 	uint32 rateMcsIdx :8;   /* OFDM/CCK rate code would be as per ieee std
134 					* in the units of 0.5mbps HT/VHT it would be
135 					* mcs index
136 					*/
137 	uint32 reserved  :16;   /* reserved */
138 	uint32 bitrate;         /* units of 100 Kbps */
139 } wifi_rate_v1;
140 
141 /* channel statistics */
142 typedef struct {
143 	wifi_channel_info channel;  /* channel */
144 	uint32 on_time;			/* msecs the radio is awake (32 bits number
145 				         * accruing over time)
146 					 */
147 	uint32 cca_busy_time;          /* msecs the CCA register is busy (32 bits number
148 					* accruing over time)
149 					*/
150 } wifi_channel_stat;
151 
152 /* radio statistics */
153 typedef struct {
154 	struct {
155 		uint16 version;
156 		uint16 length;
157 	};
158 	wifi_radio radio;               /* wifi radio (if multiple radio supported) */
159 	uint32 on_time;                    /* msecs the radio is awake (32 bits number
160 					    * accruing over time)
161 					    */
162 	uint32 tx_time;                    /* msecs the radio is transmitting (32 bits
163 					    * number accruing over time)
164 					    */
165 	uint32 rx_time;                    /* msecs the radio is in active receive (32 bits
166 					    * number accruing over time)
167 					    */
168 	uint32 on_time_scan;               /* msecs the radio is awake due to all scan (32 bits
169 					    * number accruing over time)
170 					    */
171 	uint32 on_time_nbd;                /* msecs the radio is awake due to NAN (32 bits
172 					    * number accruing over time)
173 					    */
174 	uint32 on_time_gscan;              /* msecs the radio is awake due to G?scan (32 bits
175 					    * number accruing over time)
176 					    */
177 	uint32 on_time_roam_scan;          /* msecs the radio is awake due to roam?scan (32 bits
178 					    * number accruing over time)
179 					    */
180 	uint32 on_time_pno_scan;           /* msecs the radio is awake due to PNO scan (32 bits
181 					    * number accruing over time)
182 					    */
183 	uint32 on_time_hs20;               /* msecs the radio is awake due to HS2.0 scans and
184 					    * GAS exchange (32 bits number accruing over time)
185 					    */
186 	uint32 num_channels;               /* number of channels */
187 	wifi_channel_stat channels[1];   /* channel statistics */
188 } wifi_radio_stat;
189 
190 typedef struct {
191 	wifi_radio radio;
192 	uint32 on_time;
193 	uint32 tx_time;
194 	uint32 rx_time;
195 	uint32 on_time_scan;
196 	uint32 on_time_nbd;
197 	uint32 on_time_gscan;
198 	uint32 on_time_roam_scan;
199 	uint32 on_time_pno_scan;
200 	uint32 on_time_hs20;
201 	uint32 num_channels;
202 } wifi_radio_stat_h;
203 
204 /* per rate statistics */
205 typedef struct {
206 	wifi_rate_v1 rate;     /* rate information */
207 	uint32 tx_mpdu;        /* number of successfully transmitted data pkts (ACK rcvd) */
208 	uint32 rx_mpdu;        /* number of received data pkts */
209 	uint32 mpdu_lost;      /* number of data packet losses (no ACK) */
210 	uint32 retries;        /* total number of data pkt retries */
211 	uint32 retries_short;  /* number of short data pkt retries */
212 	uint32 retries_long;   /* number of long data pkt retries */
213 } wifi_rate_stat_v1;
214 
215 typedef struct {
216 	uint16 version;
217 	uint16 length;
218 	uint32 tx_mpdu;        /* number of successfully transmitted data pkts (ACK rcvd) */
219 	uint32 rx_mpdu;        /* number of received data pkts */
220 	uint32 mpdu_lost;      /* number of data packet losses (no ACK) */
221 	uint32 retries;        /* total number of data pkt retries */
222 	uint32 retries_short;  /* number of short data pkt retries */
223 	uint32 retries_long;   /* number of long data pkt retries */
224 	wifi_rate rate;
225 } wifi_rate_stat;
226 
227 /* access categories */
228 typedef enum {
229 	WIFI_AC_VO  = 0,
230 	WIFI_AC_VI  = 1,
231 	WIFI_AC_BE  = 2,
232 	WIFI_AC_BK  = 3,
233 	WIFI_AC_MAX = 4
234 } wifi_traffic_ac;
235 
236 /* wifi peer type */
237 typedef enum
238 {
239 	WIFI_PEER_STA,
240 	WIFI_PEER_AP,
241 	WIFI_PEER_P2P_GO,
242 	WIFI_PEER_P2P_CLIENT,
243 	WIFI_PEER_NAN,
244 	WIFI_PEER_TDLS,
245 	WIFI_PEER_INVALID
246 } wifi_peer_type;
247 
248 /* per peer statistics */
249 typedef struct {
250 	wifi_peer_type type;           /* peer type (AP, TDLS, GO etc.) */
251 	uint8 peer_mac_address[6];        /* mac address */
252 	uint32 capabilities;              /* peer WIFI_CAPABILITY_XXX */
253 	uint32 num_rate;                  /* number of rates */
254 	wifi_rate_stat rate_stats[1];   /* per rate statistics, number of entries  = num_rate */
255 } wifi_peer_info;
256 
257 /* per access category statistics */
258 typedef struct {
259 	wifi_traffic_ac ac;             /* access category (VI, VO, BE, BK) */
260 	uint32 tx_mpdu;                    /* number of successfully transmitted unicast data pkts
261 					    * (ACK rcvd)
262 					    */
263 	uint32 rx_mpdu;                    /* number of received unicast mpdus */
264 	uint32 tx_mcast;                   /* number of succesfully transmitted multicast
265 					    * data packets
266 					    */
267 					   /* STA case: implies ACK received from AP for the
268 					    * unicast packet in which mcast pkt was sent
269 					    */
270 	uint32 rx_mcast;                   /* number of received multicast data packets */
271 	uint32 rx_ampdu;                   /* number of received unicast a-mpdus */
272 	uint32 tx_ampdu;                   /* number of transmitted unicast a-mpdus */
273 	uint32 mpdu_lost;                  /* number of data pkt losses (no ACK) */
274 	uint32 retries;                    /* total number of data pkt retries */
275 	uint32 retries_short;              /* number of short data pkt retries */
276 	uint32 retries_long;               /* number of long data pkt retries */
277 	uint32 contention_time_min;        /* data pkt min contention time (usecs) */
278 	uint32 contention_time_max;        /* data pkt max contention time (usecs) */
279 	uint32 contention_time_avg;        /* data pkt avg contention time (usecs) */
280 	uint32 contention_num_samples;     /* num of data pkts used for contention statistics */
281 } wifi_wmm_ac_stat;
282 
283 /* interface statistics */
284 typedef struct {
285 	wifi_interface_handle iface;          /* wifi interface */
286 	wifi_interface_info info;             /* current state of the interface */
287 	uint32 beacon_rx;                     /* access point beacon received count from
288 					       * connected AP
289 					       */
290 	uint64 average_tsf_offset;	/* average beacon offset encountered (beacon_TSF - TBTT)
291 					* The average_tsf_offset field is used so as to calculate
292 					* the typical beacon contention time on the channel as well
293 					* may be used to debug beacon synchronization and related
294 					* power consumption issue
295 					*/
296 	uint32 leaky_ap_detected;	/* indicate that this AP
297 					* typically leaks packets beyond
298 					* the driver guard time.
299 					*/
300 	uint32 leaky_ap_avg_num_frames_leaked;	/* average number of frame leaked by AP after
301 					* frame with PM bit set was ACK'ed by AP
302 					*/
303 	uint32 leaky_ap_guard_time;		/* guard time currently in force
304 					* (when implementing IEEE power management
305 					* based on frame control PM bit), How long
306 					* driver waits before shutting down the radio and after
307 					* receiving an ACK for a data frame with PM bit set)
308 					*/
309 	uint32 mgmt_rx;                       /* access point mgmt frames received count from
310 				       * connected AP (including Beacon)
311 				       */
312 	uint32 mgmt_action_rx;                /* action frames received count */
313 	uint32 mgmt_action_tx;                /* action frames transmit count */
314 	wifi_rssi rssi_mgmt;                  /* access Point Beacon and Management frames RSSI
315 					       * (averaged)
316 					       */
317 	wifi_rssi rssi_data;                  /* access Point Data Frames RSSI (averaged) from
318 					       * connected AP
319 					       */
320 	wifi_rssi rssi_ack;                   /* access Point ACK RSSI (averaged) from
321 					       * connected AP
322 					       */
323 	wifi_wmm_ac_stat ac[WIFI_AC_MAX];     /* per ac data packet statistics */
324 	uint32 num_peers;                        /* number of peers */
325 	wifi_peer_info peer_info[1];           /* per peer statistics */
326 } wifi_iface_stat;
327 
328 #ifdef CONFIG_COMPAT
329 /* interface statistics */
330 typedef struct {
331 	compat_uptr_t iface;          /* wifi interface */
332 	wifi_interface_info info;             /* current state of the interface */
333 	uint32 beacon_rx;                     /* access point beacon received count from
334 					       * connected AP
335 					       */
336 	uint64 average_tsf_offset;	/* average beacon offset encountered (beacon_TSF - TBTT)
337 					* The average_tsf_offset field is used so as to calculate
338 					* the typical beacon contention time on the channel as well
339 					* may be used to debug beacon synchronization and related
340 					* power consumption issue
341 					*/
342 	uint32 leaky_ap_detected;	/* indicate that this AP
343 					* typically leaks packets beyond
344 					* the driver guard time.
345 					*/
346 	uint32 leaky_ap_avg_num_frames_leaked;	/* average number of frame leaked by AP after
347 					* frame with PM bit set was ACK'ed by AP
348 					*/
349 	uint32 leaky_ap_guard_time;		/* guard time currently in force
350 					* (when implementing IEEE power management
351 					* based on frame control PM bit), How long
352 					* driver waits before shutting down the radio and after
353 					* receiving an ACK for a data frame with PM bit set)
354 					*/
355 	uint32 mgmt_rx;                       /* access point mgmt frames received count from
356 				       * connected AP (including Beacon)
357 				       */
358 	uint32 mgmt_action_rx;                /* action frames received count */
359 	uint32 mgmt_action_tx;                /* action frames transmit count */
360 	wifi_rssi rssi_mgmt;                  /* access Point Beacon and Management frames RSSI
361 					       * (averaged)
362 					       */
363 	wifi_rssi rssi_data;                  /* access Point Data Frames RSSI (averaged) from
364 					       * connected AP
365 					       */
366 	wifi_rssi rssi_ack;                   /* access Point ACK RSSI (averaged) from
367 					       * connected AP
368 					       */
369 	wifi_wmm_ac_stat ac[WIFI_AC_MAX];     /* per ac data packet statistics */
370 	uint32 num_peers;                        /* number of peers */
371 	wifi_peer_info peer_info[1];           /* per peer statistics */
372 } compat_wifi_iface_stat;
373 #endif /* CONFIG_COMPAT */
374 
375 #endif /* USE_WIFI_STATS_H */
376 
377 #endif /* _wifi_stats_h_ */
378