1 /* Copyright (c) 2015, The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions 5 * are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef _PKT_STATS_H_ 30 #define _PKT_STATS_H_ 31 32 /* Types of packet log events. 33 * Tx stats will be sent from driver with the help of multiple events. 34 * Need to parse the events PKTLOG_TYPE_TX_CTRL and PKTLOG_TYPE_TX_STAT 35 * as of now for the required stats. Rest of the events can ignored. 36 */ 37 #define PKTLOG_TYPE_TX_CTRL 1 38 #define PKTLOG_TYPE_TX_STAT 2 39 #define PKTLOG_TYPE_TX_MSDU_ID 3 40 #define PKTLOG_TYPE_TX_FRM_HDR 4 41 /* Rx stats will be sent from driver with event ID- PKTLOG_TYPE_RX_STAT */ 42 #define PKTLOG_TYPE_RX_STAT 5 43 #define PKTLOG_TYPE_RC_FIND 6 44 #define PKTLOG_TYPE_RC_UPDATE 7 45 #define PKTLOG_TYPE_TX_VIRT_ADDR 8 46 #define PKTLOG_TYPE_MAX 9 47 #define BW_OFFSET 8 48 #define INVALID_RSSI 255 49 50 #define PKT_INFO_FLG_TX_LOCAL_S 0x1 51 #define PKT_INFO_FLG_RX_HOST_RXD 0x2 52 #define PKT_INFO_FLG_TX_REMOTE_S 0x4 53 #define PKT_INFO_FLG_RX_LOCAL_S 0x8 54 #define PKT_INFO_FLG_RX_REMOTE_S 0x10 55 #define PKT_INFO_FLG_RX_LOCAL_DISCARD_S 0x20 56 #define PKT_INFO_FLG_RX_REMOTE_DISCARD_S 0x40 57 #define PKT_INFO_FLG_RX_REORDER_STORE_S 0x80 58 #define PKT_INFO_FLG_RX_REORDER_DROP_S 0x100 59 #define PKT_INFO_FLG_RX_PEER_INFO_S 0x200 60 #define PKT_INFO_FLG_UNKNOWN_S 0x400 61 62 /* MASK value of flags based on RX_STAT content. 63 * These are the events that carry Rx decriptor 64 */ 65 #define PKT_INFO_FLG_RX_RXDESC_MASK \ 66 (PKT_INFO_FLG_RX_HOST_RXD | \ 67 PKT_INFO_FLG_RX_LOCAL_S | \ 68 PKT_INFO_FLG_RX_REMOTE_S | \ 69 PKT_INFO_FLG_RX_LOCAL_DISCARD_S | \ 70 PKT_INFO_FLG_RX_REMOTE_DISCARD_S) 71 72 /* Format of the packet stats event*/ 73 typedef struct { 74 u16 flags; 75 u16 missed_cnt; 76 u16 log_type; 77 u16 size; 78 u32 timestamp; 79 } __attribute__((packed)) wh_pktlog_hdr_t; 80 81 /*Rx stats specific structures. */ 82 struct rx_attention { 83 u32 first_mpdu : 1; //[0] 84 u32 last_mpdu : 1; //[1] 85 u32 reserved1 : 6; //[7:2] 86 u32 mgmt_type : 1; //[8] 87 u32 ctrl_type : 1; //[9] 88 u32 reserved2 : 6; //[15:10] 89 u32 overflow_err : 1; //[16] 90 u32 msdu_length_err : 1; //[17] 91 u32 tcp_udp_chksum_fail : 1; //[18] 92 u32 ip_chksum_fail : 1; //[19] 93 u32 reserved3 : 7; //[26:20] 94 u32 mpdu_length_err : 1; //[27] 95 u32 tkip_mic_err : 1; //[28] 96 u32 decrypt_err : 1; //[29] 97 u32 fcs_err : 1; //[30] 98 u32 msdu_done : 1; //[31] 99 } __attribute__((packed)); 100 101 struct rx_mpdu_start { 102 u32 reserved1 : 13; //[12:0] 103 u32 encrypted : 1; //[13] 104 u32 retry : 1; //[14] 105 u32 reserved2 : 1; //[15] 106 u32 seq_num : 12; //[27:16] 107 u32 reserved3 : 4; //[31:28] 108 u32 reserved4; 109 u32 reserved5 : 28; //[27:0] 110 u32 tid : 4; //[31:28] 111 } __attribute__((packed)); 112 113 /*Indicates the decap-format of the packet*/ 114 enum { 115 RAW=0, // RAW: No decapsulation 116 NATIVEWIFI, 117 ETHERNET2, // (DIX) 118 ETHERNET // (SNAP/LLC) 119 }; 120 121 struct rx_msdu_start { 122 u32 reserved1[2]; 123 u32 reserved2 : 8; //[7:0] 124 u32 decap_format : 2; //[9:8] 125 u32 reserved3 : 22; //[31:10] 126 } __attribute__((packed)); 127 128 struct rx_msdu_end { 129 u32 reserved1[4]; 130 u32 reserved2 : 15; 131 u32 last_msdu : 1; //[15] 132 u32 reserved3 : 16; //[31:16] 133 } __attribute__((packed)); 134 135 struct rx_mpdu_end { 136 u32 reserved1 : 13; //[12:0] 137 u32 overflow_err : 1; //[13] 138 u32 last_mpdu : 1; //[14] 139 u32 post_delim_err : 1; //[15] 140 u32 reserved2 : 12; //[27:16] 141 u32 mpdu_length_err : 1; //[28] 142 u32 tkip_mic_err : 1; //[29] 143 u32 decrypt_err : 1; //[30] 144 u32 fcs_err : 1; //[31] 145 } __attribute__((packed)); 146 147 #define PREAMBLE_L_SIG_RATE 0x04 148 #define PREAMBLE_VHT_SIG_A_1 0x08 149 #define PREAMBLE_VHT_SIG_A_2 0x0c 150 151 /* Wifi Logger preamble */ 152 #define WL_PREAMBLE_CCK 0 153 #define WL_PREAMBLE_OFDM 1 154 #define WL_PREAMBLE_HT 2 155 #define WL_PREAMBLE_VHT 3 156 157 #define BITMASK(x) ((1<<(x)) - 1 ) 158 #define MAX_BA_WINDOW_SIZE 64 159 #define SEQ_NUM_RANGE 4096 160 #define BITMAP_VAR_SIZE 32 161 162 /* Contains MCS related stats */ 163 struct rx_ppdu_start { 164 u32 reserved1[4]; 165 u32 rssi_comb : 8; //[7:0] 166 u32 reserved2 : 24; //[31:8] 167 u32 l_sig_rate : 4; //[3:0] 168 u32 l_sig_rate_select : 1; //[4] 169 u32 reserved3 : 19; //[23:5] 170 u32 preamble_type : 8; //[31:24] 171 u32 ht_sig_vht_sig_a_1 : 24; //[23:0] 172 u32 reserved4 : 8; //[31:24] 173 u32 ht_sig_vht_sig_a_2 : 24; //[23:0] 174 u32 reserved5 : 8; //[31:25] 175 u32 reserved6[2]; 176 } __attribute__((packed)); 177 178 struct rx_ppdu_end { 179 u32 reserved1[16]; 180 u32 tsf_timestamp; 181 u32 reserved2[5]; 182 } __attribute__((packed)); 183 184 #define MAX_MSDUS_PER_MPDU 3 185 #define MAX_RXMPDUS_PER_AMPDU 64 186 #define RX_HTT_HDR_STATUS_LEN 64 187 typedef struct { 188 struct rx_attention attention; 189 u32 reserved1; 190 struct rx_mpdu_start mpdu_start; 191 struct rx_msdu_start msdu_start; 192 struct rx_msdu_end msdu_end; 193 struct rx_mpdu_end mpdu_end; 194 struct rx_ppdu_start ppdu_start; 195 struct rx_ppdu_end ppdu_end; 196 char rx_hdr_status[RX_HTT_HDR_STATUS_LEN]; 197 }__attribute__((packed)) rb_pkt_stats_t; 198 199 /*Tx stats specific structures. */ 200 struct ppdu_status { 201 u32 ba_start_seq_num : 12; //[11:0] 202 u32 reserved1 : 3; //[14:12] 203 u32 ba_status : 1; //[15] 204 u32 reserved2 : 15; //[30:16] 205 u32 tx_ok : 1; //[31] 206 u32 ba_bitmap_31_0 : 32; //[31:0] 207 u32 ba_bitmap_63_32 : 32; //[31:0] 208 u32 reserved3[8]; 209 u32 ack_rssi_ave : 8; //[7:0] 210 u32 reserved4 : 16; //[23:8] 211 u32 total_tries : 5; //[28:24] 212 u32 reserved5 : 3; //[31:29] 213 u32 reserved6[4]; 214 } __attribute__((packed)); 215 216 /*Contains tx timestamp*/ 217 struct try_status { 218 u32 timestamp : 23; //[22:0] 219 u32 reserved1 : 1; //[23] 220 u32 series : 1; //[24] 221 u32 reserved2 : 3; //[27:25] 222 u32 packet_bw : 2; //[29:28] 223 u32 reserved3 : 1; //[30] 224 u32 tx_packet : 1; //[31] 225 } __attribute__((packed)); 226 227 struct try_list { 228 struct try_status try_st[16]; 229 } __attribute__((packed)); 230 231 232 struct tx_ppdu_end { 233 struct try_list try_list; 234 struct ppdu_status stat; 235 } __attribute__((packed)); 236 237 /*Tx MCS and data rate ralated stats */ 238 struct series_bw { 239 u32 reserved1 : 28; //[27:0] 240 u32 short_gi : 1; //[28] 241 u32 reserved2 : 3; //[31:29] 242 u32 reserved3 : 24; //[23:21] 243 u32 rate : 4; //[27:24] 244 u32 nss : 2; //[29:28] 245 u32 preamble_type : 2; //[31:30] 246 u32 reserved4[2]; 247 } __attribute__((packed)); 248 249 enum tx_bw { 250 BW_20_MHZ, 251 BW_40_MHZ, 252 BW_80_MHZ, 253 BW_160_MHZ 254 }; 255 256 #define DATA_PROTECTED 14 257 struct tx_ppdu_start { 258 u32 reserved1[2]; 259 u32 start_seq_num : 12; //[11:0] 260 u32 reserved2 : 20; //[31:12] 261 u32 seqnum_bitmap_31_0 : 32; //[31:0] 262 u32 seqnum_bitmap_63_32 : 32; //[31:0] 263 u32 reserved3[8]; 264 u32 reserved4 : 15; //[14:0] 265 u32 ampdu : 1; //[15] 266 u32 no_ack : 1; //[16] 267 u32 reserved5 : 15; //[31:17] 268 u32 reserved6 : 16; //[15:0] 269 u32 frame_control : 16; //[31:16] 270 u32 reserved7 : 16; //[23:21] 271 u32 qos_ctl : 16; //[31:16] 272 u32 reserved8[4]; 273 u32 reserved9 : 24; //[23:21] 274 u32 valid_s0_bw20 : 1; //[24] 275 u32 valid_s0_bw40 : 1; //[25] 276 u32 valid_s0_bw80 : 1; //[26] 277 u32 valid_s0_bw160 : 1; //[27] 278 u32 valid_s1_bw20 : 1; //[28] 279 u32 valid_s1_bw40 : 1; //[29] 280 u32 valid_s1_bw80 : 1; //[30] 281 u32 valid_s1_bw160 : 1; //[31] 282 struct series_bw s0_bw20; 283 struct series_bw s0_bw40; 284 struct series_bw s0_bw80; 285 struct series_bw s0_bw160; 286 struct series_bw s1_bw20; 287 struct series_bw s1_bw40; 288 struct series_bw s1_bw80; 289 struct series_bw s1_bw160; 290 u32 reserved10[3]; 291 } __attribute__((packed)); 292 293 #define PKTLOG_MAX_TXCTL_WORDS 57 /* +2 words for bitmap */ 294 typedef struct { 295 u32 reserved1[3]; 296 union { 297 u32 txdesc_ctl[PKTLOG_MAX_TXCTL_WORDS]; 298 struct tx_ppdu_start ppdu_start; 299 }u; 300 } __attribute__((packed)) wh_pktlog_txctl; 301 302 /* Required stats are spread across multiple 303 * events(PKTLOG_TYPE_TX_CTRL and PKTLOG_TYPE_TX_STAT here). 304 * Need to aggregate the stats collected in each event and write to the 305 * ring buffer only after receiving all the expected stats. 306 * Need to preserve the stats in hal_info till then and use tx_stats_events 307 * flag to track the events. 308 * prev_seq_no: Can used to track the events that come from driver and identify 309 * if any event is missed. 310 */ 311 312 #define RING_BUF_ENTRY_SIZE 512 313 #define PKT_STATS_BUF_SIZE 128 314 struct pkt_stats_s { 315 u8 tx_stats_events; 316 /* TODO: Need to handle the case if size of the stats are more 317 * than 512 bytes. Currently, the tx size is 34 bytes and ring buffer entry 318 * size is 12 bytes. 319 */ 320 u8 tx_stats[PKT_STATS_BUF_SIZE]; 321 u8 num_msdu; 322 u16 start_seq_num; 323 u16 ba_seq_num; 324 u32 ba_bitmap_31_0; 325 u32 ba_bitmap_63_32; 326 u32 tx_seqnum_bitmap_31_0; 327 u32 tx_seqnum_bitmap_63_32; 328 u32 shifted_bitmap_31_0; 329 u32 shifted_bitmap_63_32; 330 bool isBlockAck; 331 u8 tx_bandwidth; 332 u8 series; 333 }; 334 335 typedef union { 336 struct { 337 u16 rate : 4; 338 u16 nss : 2; 339 u16 preamble : 2; 340 u16 bw : 2; 341 u16 short_gi : 1; 342 u16 reserved : 5; 343 } mcs_s; 344 u16 mcs; 345 } MCS; 346 347 typedef struct { 348 MCS RxMCS; 349 u16 last_transmit_rate; 350 u16 rssi; 351 u32 timestamp; 352 u8 tid; 353 } rx_aggr_stats; 354 355 356 typedef struct drv_msg_s 357 { 358 u16 length; 359 u16 event_type; 360 u32 timestamp_low; 361 u32 timestamp_high; 362 union { 363 struct { 364 u32 version; 365 u32 msg_seq_no; 366 u32 payload_len; 367 u8 payload[0]; 368 } __attribute__((packed)) pkt_stats_event; 369 } u; 370 } __attribute__((packed)) drv_msg_t; 371 372 #endif 373