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_PKT_STATS       9
47 #define PKTLOG_TYPE_PKT_DUMP        10
48 #define PKTLOG_TYPE_PKT_DUMP_V2     11
49 #define PKTLOG_TYPE_MAX             12
50 #define BW_OFFSET 8
51 #define INVALID_RSSI 255
52 #define INVALID_RATE_CODE 0xff
53 
54 /* Based on pkt log V2, this type of event will triggered */
55 #define PKTLOG_TYPE_PKT_SW_EVENT    10
56 
57 #define PKT_INFO_FLG_TX_LOCAL_S          0x1
58 #define PKT_INFO_FLG_RX_HOST_RXD         0x2
59 #define PKT_INFO_FLG_TX_REMOTE_S         0x4
60 #define PKT_INFO_FLG_RX_LOCAL_S          0x8
61 #define PKT_INFO_FLG_RX_REMOTE_S         0x10
62 #define PKT_INFO_FLG_RX_LOCAL_DISCARD_S  0x20
63 #define PKT_INFO_FLG_RX_REMOTE_DISCARD_S 0x40
64 #define PKT_INFO_FLG_RX_REORDER_STORE_S  0x80
65 #define PKT_INFO_FLG_RX_REORDER_DROP_S   0x100
66 #define PKT_INFO_FLG_RX_PEER_INFO_S      0x200
67 #define PKT_INFO_FLG_UNKNOWN_S           0x400
68 #define PKT_INFO_FLG_PKT_DUMP_V2         0x8000
69 
70 /* Depend on packet log version V2 this
71  * offset are define, for more info need to
72  * check from firmware side.
73  */
74 #define TX_SUCCESS_TMS_OFFSET 56
75 #define LINK_LAYER_TX_SQN_OFFSET 66
76 #define RATE_CODE_OFFSET 68
77 #define TX_STATUS_OFFSET 70
78 #define TX_RSSI_OFFSET 71
79 #define NO_RETRIES_OFFSET 75
80 #define EXT_FLAGS_OFFSET 76
81 #define BMAP_FAILED_OFFSET 84
82 #define BMAP_ENQUEUED_OFFSET 92
83 #define FRAME_CTRL_OFFSET 216
84 #define QOS_CTRL_OFFSET 218
85 
86 /* MAX HT/VHT mcs index */
87 #define MAX_VHT_MCS_IDX 10
88 #define MAX_HT_MCS_IDX 8
89 
90 /* MAX CCK/OFDM rate index */
91 #define MAX_CCK_MCS_IDX 4
92 #define MAX_OFDM_MCS_IDX 8
93 
94 /* MASK value of flags based on RX_STAT content.
95  * These are the events that carry Rx decriptor
96  */
97 #define PKT_INFO_FLG_RX_RXDESC_MASK \
98         (PKT_INFO_FLG_RX_HOST_RXD | \
99          PKT_INFO_FLG_RX_LOCAL_S | \
100          PKT_INFO_FLG_RX_REMOTE_S | \
101          PKT_INFO_FLG_RX_LOCAL_DISCARD_S | \
102          PKT_INFO_FLG_RX_REMOTE_DISCARD_S)
103 
104 /* Format of the packet stats event*/
105 typedef struct {
106     u16 flags;
107     u16 missed_cnt;
108     u16 log_type;
109     u16 size;
110     u32 timestamp;
111 } __attribute__((packed)) wh_pktlog_hdr_t;
112 
113 /* Format of the v2 packet stats event*/
114 typedef struct {
115     u16 flags;
116     u16 missed_cnt;
117     u16 log_type        : 8; //[7:0]
118     u16 mac_id          : 8; //[15:8]
119     u16 size;
120     u32 timestamp;
121     u32 reserved;
122 } __attribute__((packed)) wh_pktlog_hdr_v2_t;
123 
124 /*Rx stats specific structures. */
125 struct rx_attention {
126     u32 first_mpdu                      :  1; //[0]
127     u32 last_mpdu                       :  1; //[1]
128     u32 reserved1                       :  6; //[7:2]
129     u32 mgmt_type                       :  1; //[8]
130     u32 ctrl_type                       :  1; //[9]
131     u32 reserved2                       :  6; //[15:10]
132     u32 overflow_err                    :  1; //[16]
133     u32 msdu_length_err                 :  1; //[17]
134     u32 tcp_udp_chksum_fail             :  1; //[18]
135     u32 ip_chksum_fail                  :  1; //[19]
136     u32 reserved3                       :  7; //[26:20]
137     u32 mpdu_length_err                 :  1; //[27]
138     u32 tkip_mic_err                    :  1; //[28]
139     u32 decrypt_err                     :  1; //[29]
140     u32 fcs_err                         :  1; //[30]
141     u32 msdu_done                       :  1; //[31]
142 } __attribute__((packed));
143 
144 struct rx_mpdu_start {
145     u32 reserved1                       : 13; //[12:0]
146     u32 encrypted                       :  1; //[13]
147     u32 retry                           :  1; //[14]
148     u32 reserved2                       :  1; //[15]
149     u32 seq_num                         : 12; //[27:16]
150     u32 reserved3                       :  4; //[31:28]
151     u32 reserved4;
152     u32 reserved5                       : 28; //[27:0]
153     u32 tid                             :  4; //[31:28]
154 } __attribute__((packed));
155 
156 /*Indicates the decap-format of the packet*/
157 enum {
158     RAW=0,      // RAW: No decapsulation
159     NATIVEWIFI,
160     ETHERNET2,  // (DIX)
161     ETHERNET    // (SNAP/LLC)
162 };
163 
164 struct rx_msdu_start {
165     u32 reserved1[2];
166     u32 reserved2                       :  8; //[7:0]
167     u32 decap_format                    :  2; //[9:8]
168     u32 reserved3                       : 22; //[31:10]
169 } __attribute__((packed));
170 
171 struct rx_msdu_end {
172     u32 reserved1[4];
173     u32 reserved2                       : 15;
174     u32 last_msdu                       :  1; //[15]
175     u32 reserved3                       : 16; //[31:16]
176 } __attribute__((packed));
177 
178 struct rx_mpdu_end {
179     u32 reserved1                       : 13; //[12:0]
180     u32 overflow_err                    :  1; //[13]
181     u32 last_mpdu                       :  1; //[14]
182     u32 post_delim_err                  :  1; //[15]
183     u32 reserved2                       : 12; //[27:16]
184     u32 mpdu_length_err                 :  1; //[28]
185     u32 tkip_mic_err                    :  1; //[29]
186     u32 decrypt_err                     :  1; //[30]
187     u32 fcs_err                         :  1; //[31]
188 } __attribute__((packed));
189 
190 /* structure implemented w.r.t PKT_LOG_V2 Version */
191 struct rx_msdu_start_v1 {
192     u32 reserved1[2];
193     u32 reserved2                       :  8; //[7:0]
194     u32 decap_format                    :  2; //[9:8]
195     u32 reserved3                       : 22; //[31:10]
196     u32 reserved4[2];
197 } __attribute__((packed));
198 
199 struct rx_msdu_end_v1 {
200     u32 reserved1[4];
201     u32 reserved2                       : 15; //[14:0]
202     u32 last_msdu                       :  1; //[15]
203     u32 reserved3                       : 16; //[31:16]
204     u32 reserved4[9];
205 } __attribute__((packed));
206 /************************************************************/
207 
208 #define PREAMBLE_L_SIG_RATE     0x04
209 #define PREAMBLE_VHT_SIG_A_1    0x08
210 #define PREAMBLE_VHT_SIG_A_2    0x0c
211 
212 /* Wifi Logger preamble */
213 #define WL_PREAMBLE_CCK  0
214 #define WL_PREAMBLE_OFDM 1
215 #define WL_PREAMBLE_HT   2
216 #define WL_PREAMBLE_VHT  3
217 
218 #define BITMASK(x) ((1<<(x)) - 1 )
219 #define MAX_BA_WINDOW_SIZE 64
220 #define SEQ_NUM_RANGE 4096
221 #define BITMAP_VAR_SIZE 32
222 
223 /* Contains MCS related stats */
224 struct rx_ppdu_start {
225     u32 reserved1[4];
226     u32 rssi_comb                       :  8; //[7:0]
227     u32 reserved2                       : 24; //[31:8]
228     u32 l_sig_rate                      :  4; //[3:0]
229     u32 l_sig_rate_select               :  1; //[4]
230     u32 reserved3                       : 19; //[23:5]
231     u32 preamble_type                   :  8; //[31:24]
232     u32 ht_sig_vht_sig_a_1              : 24; //[23:0]
233     u32 reserved4                       :  8; //[31:24]
234     u32 ht_sig_vht_sig_a_2              : 24; //[23:0]
235     u32 reserved5                       :  8; //[31:25]
236     u32 reserved6[2];
237 } __attribute__((packed));
238 
239 struct rx_ppdu_end {
240     u32 reserved1[16];
241     u32 tsf_timestamp;
242     u32 reserved2[5];
243 } __attribute__((packed));
244 
245 struct rx_ppdu_end_V1 {
246     u32 reserved1[18];
247     u32 wb_timestamp_lower_32;
248     u32 reserved2[18];
249 } __attribute__((packed));
250 
251 #define MAX_MSDUS_PER_MPDU 3
252 #define MAX_RXMPDUS_PER_AMPDU 64
253 #define RX_HTT_HDR_STATUS_LEN 64
254 /* RX Data length is 256 for PKT_LOG_V2 Version */
255 #define RX_HTT_HDR_STATUS_LEN_V1 256
256 
257 typedef struct {
258     struct rx_attention attention;
259     u32 reserved1;
260     struct rx_mpdu_start mpdu_start;
261     struct rx_msdu_start msdu_start;
262     struct rx_msdu_end   msdu_end;
263     struct rx_mpdu_end   mpdu_end;
264     struct rx_ppdu_start ppdu_start;
265     struct rx_ppdu_end   ppdu_end;
266     char rx_hdr_status[RX_HTT_HDR_STATUS_LEN];
267 }__attribute__((packed)) rb_pkt_stats_t;
268 
269 /* structure implemented w.r.t PKT_LOG_V2 Version */
270 typedef struct {
271     struct rx_attention attention;
272     u32 reserved1[2];
273     struct rx_mpdu_start    mpdu_start;
274     struct rx_msdu_start_v1 msdu_start;
275     struct rx_msdu_end_v1   msdu_end;
276     struct rx_mpdu_end      mpdu_end;
277     struct rx_ppdu_start    ppdu_start;
278     struct rx_ppdu_end_V1    ppdu_end;
279     char rx_hdr_status[RX_HTT_HDR_STATUS_LEN_V1];
280 }__attribute__((packed)) rb_pkt_stats_t_v1;
281 /************************************************************/
282 
283 /*Tx stats specific structures. */
284 struct ppdu_status {
285     u32 ba_start_seq_num                : 12; //[11:0]
286     u32 reserved1                       :  3; //[14:12]
287     u32 ba_status                       :  1; //[15]
288     u32 reserved2                       : 15; //[30:16]
289     u32 tx_ok                           :  1; //[31]
290     u32 ba_bitmap_31_0                  : 32; //[31:0]
291     u32 ba_bitmap_63_32                 : 32; //[31:0]
292     u32 reserved3[8];
293     u32 ack_rssi_ave                    :  8; //[7:0]
294     u32 reserved4                       : 16; //[23:8]
295     u32 total_tries                     :  5; //[28:24]
296     u32 reserved5                       :  3; //[31:29]
297     u32 reserved6[4];
298 } __attribute__((packed));
299 
300 /*Contains tx timestamp*/
301 struct try_status {
302     u32 timestamp                       : 23; //[22:0]
303     u32 reserved1                       :  1; //[23]
304     u32 series                          :  1; //[24]
305     u32 reserved2                       :  3; //[27:25]
306     u32 packet_bw                       :  2; //[29:28]
307     u32 reserved3                       :  1; //[30]
308     u32 tx_packet                       :  1; //[31]
309 } __attribute__((packed));
310 
311 struct try_list {
312     struct try_status try_st[16];
313 } __attribute__((packed));
314 
315 
316 struct tx_ppdu_end {
317     struct try_list try_list;
318     struct ppdu_status stat;
319 } __attribute__((packed));
320 
321 /*Tx MCS and data rate ralated stats */
322 struct series_bw {
323     u32 reserved1                       : 28; //[27:0]
324     u32 short_gi                        :  1; //[28]
325     u32 reserved2                       :  3; //[31:29]
326     u32 reserved3                       : 24; //[23:21]
327     u32 rate                            :  4; //[27:24]
328     u32 nss                             :  2; //[29:28]
329     u32 preamble_type                   :  2; //[31:30]
330     u32 reserved4[2];
331 } __attribute__((packed));
332 
333 enum tx_bw {
334     BW_20_MHZ,
335     BW_40_MHZ,
336     BW_80_MHZ,
337     BW_160_MHZ
338 };
339 
340 #define DATA_PROTECTED 14
341 struct tx_ppdu_start {
342     u32 reserved1[2];
343     u32 start_seq_num                   : 12; //[11:0]
344     u32 reserved2                       : 20; //[31:12]
345     u32 seqnum_bitmap_31_0              : 32; //[31:0]
346     u32 seqnum_bitmap_63_32             : 32; //[31:0]
347     u32 reserved3[8];
348     u32 reserved4                       : 15; //[14:0]
349     u32 ampdu                           :  1; //[15]
350     u32 no_ack                          :  1; //[16]
351     u32 reserved5                       : 15; //[31:17]
352     u32 reserved6                       : 16; //[15:0]
353     u32 frame_control                   : 16; //[31:16]
354     u32 reserved7                       : 16; //[23:21]
355     u32 qos_ctl                         : 16; //[31:16]
356     u32 reserved8[4];
357     u32 reserved9                       : 24; //[23:21]
358     u32 valid_s0_bw20                   :  1; //[24]
359     u32 valid_s0_bw40                   :  1; //[25]
360     u32 valid_s0_bw80                   :  1; //[26]
361     u32 valid_s0_bw160                  :  1; //[27]
362     u32 valid_s1_bw20                   :  1; //[28]
363     u32 valid_s1_bw40                   :  1; //[29]
364     u32 valid_s1_bw80                   :  1; //[30]
365     u32 valid_s1_bw160                  :  1; //[31]
366     struct series_bw s0_bw20;
367     struct series_bw s0_bw40;
368     struct series_bw s0_bw80;
369     struct series_bw s0_bw160;
370     struct series_bw s1_bw20;
371     struct series_bw s1_bw40;
372     struct series_bw s1_bw80;
373     struct series_bw s1_bw160;
374     u32 reserved10[3];
375 } __attribute__((packed));
376 
377 #define PKTLOG_MAX_TXCTL_WORDS 57 /* +2 words for bitmap */
378 typedef struct {
379     u32 reserved1[3];
380     union {
381         u32 txdesc_ctl[PKTLOG_MAX_TXCTL_WORDS];
382         struct tx_ppdu_start ppdu_start;
383     }u;
384 } __attribute__((packed)) wh_pktlog_txctl;
385 
386 /* Required stats are spread across multiple
387  * events(PKTLOG_TYPE_TX_CTRL and PKTLOG_TYPE_TX_STAT here).
388  * Need to aggregate the stats collected in each event and write to the
389  * ring buffer only after receiving all the expected stats.
390  * Need to preserve the stats in hal_info till then and use tx_stats_events
391  * flag to track the events.
392  * prev_seq_no: Can used to track the events that come from driver and identify
393  * if any event is missed.
394  */
395 
396 /* PKT_LOG_V2 Base strcuture used to parse buffer */
397 typedef struct {
398     u16 frm_ctrl;
399     u8  tx_ok;
400     u16 qos_ctrl;
401     u64 bmap_failed;
402     u64 bmap_enqueued;
403 } __attribute__((packed)) node_pkt_stats;
404 
405 typedef u8 A_RATECODE;
406 
407 /* Rate Code as per PKT_LOG_V2 Version */
408 typedef struct {
409     A_RATECODE rateCode;
410     u8 flags;
411 } RATE_CODE;
412 
413 /* bandwidht type*/
414 typedef enum {
415     BW_20MHZ,
416     BW_40MHZ,
417     BW_80MHZ,
418     BW_160MHZ,
419 } bandwidth;
420 
421 /* Preamble type*/
422 typedef enum {
423     WIFI_HW_RATECODE_PREAM_OFDM = 0,
424     WIFI_HW_RATECODE_PREAM_CCK  = 1,
425     WIFI_HW_RATECODE_PREAM_HT   = 2,
426     WIFI_HW_RATECODE_PREAM_VHT  = 3,
427     WIFI_HW_RATECODE_PREAM_COUNT,
428 } WIFI_HW_RATECODE_PREAM_TYPE;
429 
430 /**
431  * struct index_data_rate_type - non vht data rate type
432  * @rate_index: cck  rate index
433  * @cck_rate: CCK supported rate table
434  */
435 struct index_data_rate_cck_type {
436     uint8_t  rate_index;
437     uint16_t cck_rate[2];
438 };
439 
440 /**
441  * struct index_data_rate_type - non vht data rate type
442  * @rate_index: ofdm  rate index
443  * @ofdm__rate: OFDM supported rate table
444  */
445 struct index_data_rate_ofdm_type {
446     uint8_t  rate_index;
447     uint16_t ofdm_rate[2];
448 };
449 
450 /*Below CCK/OFDM table refer from firmware Arch */
451 /* Rate Table Based on CCK */
452 static struct index_data_rate_cck_type cck_mcs_nss1[] = {
453     /*RC     LKbps   SKbps */
454     {0x40,  {11000,  11000} },
455     {0x41,  {5500,   5500} },
456     {0x42,  {2000,   2000} },
457     {0x43,  {1000,   1000} }
458 };
459 
460 /* Rate Table Based on OFDM */
461 static struct index_data_rate_ofdm_type ofdm_mcs_nss1[] = {
462     /*RC     LKbps   SKbps */
463     {0x00,  {48000,  48000} },
464     {0x01,  {34000,  24000} },
465     {0x02,  {12000,  12000} },
466     {0x03,  {6000,   6000} },
467     {0x04,  {54000,  54000} },
468     {0x05,  {36000,  36000} },
469     {0x06,  {18000,  18000} },
470     {0x07,  {9000,   9000} }
471 };
472 
473 /**
474  * struct index_data_rate_type - non vht data rate type
475  * @mcs_index: mcs rate index
476  * @ht20_rate: HT20 supported rate table
477  * @ht40_rate: HT40 supported rate table
478  */
479 struct index_data_rate_type {
480     uint8_t  mcs_index;
481     uint16_t ht20_rate[2];
482     uint16_t ht40_rate[2];
483 };
484 
485 /**
486  * struct index_vht_data_rate_type - vht data rate type
487  * @mcs_index: mcs rate index
488  * @ht20_rate: VHT20 supported rate table
489  * @ht40_rate: VHT40 supported rate table
490  * @ht80_rate: VHT80 supported rate table
491  */
492 struct index_vht_data_rate_type {
493     uint8_t mcs_index;
494     uint16_t ht20_rate[2];
495     uint16_t ht40_rate[2];
496     uint16_t ht80_rate[2];
497 };
498 
499 /*Below HT/VHT table refer from Host Driver
500  * MCS Based rate table
501  * HT MCS parameters with Nss = 1
502  */
503 static struct index_data_rate_type mcs_nss1[] = {
504     /* MCS L20  S20   L40   S40 */
505     {0,  {65,  72},  {135,  150 } },
506     {1,  {130, 144}, {270,  300 } },
507     {2,  {195, 217}, {405,  450 } },
508     {3,  {260, 289}, {540,  600 } },
509     {4,  {390, 433}, {815,  900 } },
510     {5,  {520, 578}, {1080, 1200} },
511     {6,  {585, 650}, {1215, 1350} },
512     {7,  {650, 722}, {1350, 1500} }
513 };
514 
515 /* HT MCS parameters with Nss = 2 */
516 static struct index_data_rate_type mcs_nss2[] = {
517     /* MCS L20  S20    L40   S40 */
518     {0,  {130,  144},  {270,  300 } },
519     {1,  {260,  289},  {540,  600 } },
520     {2,  {390,  433},  {810,  900 } },
521     {3,  {520,  578},  {1080, 1200} },
522     {4,  {780,  867},  {1620, 1800} },
523     {5,  {1040, 1156}, {2160, 2400} },
524     {6,  {1170, 1300}, {2430, 2700} },
525     {7,  {1300, 1440}, {2700, 3000} }
526 };
527 
528 /* MCS Based VHT rate table
529  * MCS parameters with Nss = 1
530  */
531 static struct index_vht_data_rate_type vht_mcs_nss1[] = {
532     /* MCS L20  S20    L40   S40    L80   S80 */
533     {0,  {65,   72 }, {135,  150},  {293,  325} },
534     {1,  {130,  144}, {270,  300},  {585,  650} },
535     {2,  {195,  217}, {405,  450},  {878,  975} },
536     {3,  {260,  289}, {540,  600},  {1170, 1300} },
537     {4,  {390,  433}, {810,  900},  {1755, 1950} },
538     {5,  {520,  578}, {1080, 1200}, {2340, 2600} },
539     {6,  {585,  650}, {1215, 1350}, {2633, 2925} },
540     {7,  {650,  722}, {1350, 1500}, {2925, 3250} },
541     {8,  {780,  867}, {1620, 1800}, {3510, 3900} },
542     {9,  {865,  960}, {1800, 2000}, {3900, 4333} }
543 };
544 
545 /*MCS parameters with Nss = 2*/
546 static struct index_vht_data_rate_type vht_mcs_nss2[] = {
547     /* MCS L20  S20    L40    S40    L80    S80 */
548     {0,  {130,  144},  {270,  300},  { 585,  650} },
549     {1,  {260,  289},  {540,  600},  {1170, 1300} },
550     {2,  {390,  433},  {810,  900},  {1755, 1950} },
551     {3,  {520,  578},  {1080, 1200}, {2340, 2600} },
552     {4,  {780,  867},  {1620, 1800}, {3510, 3900} },
553     {5,  {1040, 1156}, {2160, 2400}, {4680, 5200} },
554     {6,  {1170, 1300}, {2430, 2700}, {5265, 5850} },
555     {7,  {1300, 1444}, {2700, 3000}, {5850, 6500} },
556     {8,  {1560, 1733}, {3240, 3600}, {7020, 7800} },
557     {9,  {1730, 1920}, {3600, 4000}, {7800, 8667} }
558 };
559 /*********************************************************/
560 
561 #define RING_BUF_ENTRY_SIZE 512
562 #define PKT_STATS_BUF_SIZE 128
563 struct pkt_stats_s {
564     u8 tx_stats_events;
565     /* TODO: Need to handle the case if size of the stats are more
566      * than 512 bytes. Currently, the tx size is 34 bytes and ring buffer entry
567      * size is 12 bytes.
568      */
569     u8 tx_stats[PKT_STATS_BUF_SIZE];
570     u8 num_msdu;
571     u16 start_seq_num;
572     u16 ba_seq_num;
573     u32 ba_bitmap_31_0;
574     u32 ba_bitmap_63_32;
575     u32 tx_seqnum_bitmap_31_0;
576     u32 tx_seqnum_bitmap_63_32;
577     u32 shifted_bitmap_31_0;
578     u32 shifted_bitmap_63_32;
579     bool isBlockAck;
580     u8 tx_bandwidth;
581     u8 series;
582 };
583 
584 typedef union {
585     struct {
586         u16 rate                            :  4;
587         u16 nss                             :  2;
588         u16 preamble                        :  2;
589         u16 bw                              :  2;
590         u16 short_gi                        :  1;
591         u16 reserved                        :  5;
592     } mcs_s;
593     u16 mcs;
594 } MCS;
595 
596 typedef struct {
597     MCS RxMCS;
598     u16 last_transmit_rate;
599     u16 rssi;
600     u32 timestamp;
601     u8  tid;
602 } rx_aggr_stats;
603 
604 
605 typedef struct drv_msg_s
606 {
607     u16 length;
608     u16 event_type;
609     u32 timestamp_low;
610     u32 timestamp_high;
611     union {
612         struct {
613             u32 version;
614             u32 msg_seq_no;
615             u32 payload_len;
616             u8  payload[0];
617         } __attribute__((packed)) pkt_stats_event;
618     } u;
619 } __attribute__((packed)) drv_msg_t;
620 
621 typedef enum {
622     START_MONITOR = 1,
623     STOP_MONITOR,
624     TX_MGMT_PKT,
625     TX_DATA_PKT,
626     RX_MGMT_PKT,
627     RX_DATA_PKT,
628 } pktdump_event_type;
629 
630 typedef struct {
631     u8 status;
632     u8 type;
633     u32 driver_ts;
634     u16 fw_ts;
635 } __attribute__((packed)) pktdump_hdr;
636 
637 typedef struct {
638     frame_type payload_type;
639     u32 driver_timestamp_usec;
640     u32 firmware_timestamp_usec;
641     size_t frame_len;
642     char *frame_content;
643 } frame_info_i;
644 
645 typedef struct {
646     // Prefix of MD5 hash of |frame_inf.frame_content|. If frame
647     // content is not provided, prefix of MD5 hash over the same data
648     // that would be in frame_content, if frame content were provided.
649     char md5_prefix[MD5_PREFIX_LEN];  // Prefix of MD5 hash of packet bytes
650     wifi_tx_packet_fate fate;
651     frame_info_i frame_inf;
652 } wifi_tx_report_i;
653 
654 typedef struct {
655     // Prefix of MD5 hash of |frame_inf.frame_content|. If frame
656     // content is not provided, prefix of MD5 hash over the same data
657     // that would be in frame_content, if frame content were provided.
658     char md5_prefix[MD5_PREFIX_LEN];
659     wifi_rx_packet_fate fate;
660     frame_info_i frame_inf;
661 } wifi_rx_report_i;
662 
663 typedef struct {
664     wifi_tx_report_i tx_fate_stats[MAX_FATE_LOG_LEN];
665     size_t n_tx_stats_collected;
666     wifi_rx_report_i rx_fate_stats[MAX_FATE_LOG_LEN];
667     size_t n_rx_stats_collected;
668 } packet_fate_monitor_info;
669 
670 #endif
671