Home | History | Annotate | Download | only in wifi_hal
      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_MAX             11
     49 #define BW_OFFSET 8
     50 #define INVALID_RSSI 255
     51 
     52 #define PKT_INFO_FLG_TX_LOCAL_S          0x1
     53 #define PKT_INFO_FLG_RX_HOST_RXD         0x2
     54 #define PKT_INFO_FLG_TX_REMOTE_S         0x4
     55 #define PKT_INFO_FLG_RX_LOCAL_S          0x8
     56 #define PKT_INFO_FLG_RX_REMOTE_S         0x10
     57 #define PKT_INFO_FLG_RX_LOCAL_DISCARD_S  0x20
     58 #define PKT_INFO_FLG_RX_REMOTE_DISCARD_S 0x40
     59 #define PKT_INFO_FLG_RX_REORDER_STORE_S  0x80
     60 #define PKT_INFO_FLG_RX_REORDER_DROP_S   0x100
     61 #define PKT_INFO_FLG_RX_PEER_INFO_S      0x200
     62 #define PKT_INFO_FLG_UNKNOWN_S           0x400
     63 
     64 /* MASK value of flags based on RX_STAT content.
     65  * These are the events that carry Rx decriptor
     66  */
     67 #define PKT_INFO_FLG_RX_RXDESC_MASK \
     68         (PKT_INFO_FLG_RX_HOST_RXD | \
     69          PKT_INFO_FLG_RX_LOCAL_S | \
     70          PKT_INFO_FLG_RX_REMOTE_S | \
     71          PKT_INFO_FLG_RX_LOCAL_DISCARD_S | \
     72          PKT_INFO_FLG_RX_REMOTE_DISCARD_S)
     73 
     74 /* Format of the packet stats event*/
     75 typedef struct {
     76     u16 flags;
     77     u16 missed_cnt;
     78     u16 log_type;
     79     u16 size;
     80     u32 timestamp;
     81 } __attribute__((packed)) wh_pktlog_hdr_t;
     82 
     83 /*Rx stats specific structures. */
     84 struct rx_attention {
     85     u32 first_mpdu                      :  1; //[0]
     86     u32 last_mpdu                       :  1; //[1]
     87     u32 reserved1                       :  6; //[7:2]
     88     u32 mgmt_type                       :  1; //[8]
     89     u32 ctrl_type                       :  1; //[9]
     90     u32 reserved2                       :  6; //[15:10]
     91     u32 overflow_err                    :  1; //[16]
     92     u32 msdu_length_err                 :  1; //[17]
     93     u32 tcp_udp_chksum_fail             :  1; //[18]
     94     u32 ip_chksum_fail                  :  1; //[19]
     95     u32 reserved3                       :  7; //[26:20]
     96     u32 mpdu_length_err                 :  1; //[27]
     97     u32 tkip_mic_err                    :  1; //[28]
     98     u32 decrypt_err                     :  1; //[29]
     99     u32 fcs_err                         :  1; //[30]
    100     u32 msdu_done                       :  1; //[31]
    101 } __attribute__((packed));
    102 
    103 struct rx_mpdu_start {
    104     u32 reserved1                       : 13; //[12:0]
    105     u32 encrypted                       :  1; //[13]
    106     u32 retry                           :  1; //[14]
    107     u32 reserved2                       :  1; //[15]
    108     u32 seq_num                         : 12; //[27:16]
    109     u32 reserved3                       :  4; //[31:28]
    110     u32 reserved4;
    111     u32 reserved5                       : 28; //[27:0]
    112     u32 tid                             :  4; //[31:28]
    113 } __attribute__((packed));
    114 
    115 /*Indicates the decap-format of the packet*/
    116 enum {
    117     RAW=0,      // RAW: No decapsulation
    118     NATIVEWIFI,
    119     ETHERNET2,  // (DIX)
    120     ETHERNET    // (SNAP/LLC)
    121 };
    122 
    123 struct rx_msdu_start {
    124     u32 reserved1[2];
    125     u32 reserved2                       :  8; //[7:0]
    126     u32 decap_format                    :  2; //[9:8]
    127     u32 reserved3                       : 22; //[31:10]
    128 } __attribute__((packed));
    129 
    130 struct rx_msdu_end {
    131     u32 reserved1[4];
    132     u32 reserved2                       : 15;
    133     u32 last_msdu                       :  1; //[15]
    134     u32 reserved3                       : 16; //[31:16]
    135 } __attribute__((packed));
    136 
    137 struct rx_mpdu_end {
    138     u32 reserved1                       : 13; //[12:0]
    139     u32 overflow_err                    :  1; //[13]
    140     u32 last_mpdu                       :  1; //[14]
    141     u32 post_delim_err                  :  1; //[15]
    142     u32 reserved2                       : 12; //[27:16]
    143     u32 mpdu_length_err                 :  1; //[28]
    144     u32 tkip_mic_err                    :  1; //[29]
    145     u32 decrypt_err                     :  1; //[30]
    146     u32 fcs_err                         :  1; //[31]
    147 } __attribute__((packed));
    148 
    149 #define PREAMBLE_L_SIG_RATE     0x04
    150 #define PREAMBLE_VHT_SIG_A_1    0x08
    151 #define PREAMBLE_VHT_SIG_A_2    0x0c
    152 
    153 /* Wifi Logger preamble */
    154 #define WL_PREAMBLE_CCK  0
    155 #define WL_PREAMBLE_OFDM 1
    156 #define WL_PREAMBLE_HT   2
    157 #define WL_PREAMBLE_VHT  3
    158 
    159 #define BITMASK(x) ((1<<(x)) - 1 )
    160 #define MAX_BA_WINDOW_SIZE 64
    161 #define SEQ_NUM_RANGE 4096
    162 #define BITMAP_VAR_SIZE 32
    163 
    164 /* Contains MCS related stats */
    165 struct rx_ppdu_start {
    166     u32 reserved1[4];
    167     u32 rssi_comb                       :  8; //[7:0]
    168     u32 reserved2                       : 24; //[31:8]
    169     u32 l_sig_rate                      :  4; //[3:0]
    170     u32 l_sig_rate_select               :  1; //[4]
    171     u32 reserved3                       : 19; //[23:5]
    172     u32 preamble_type                   :  8; //[31:24]
    173     u32 ht_sig_vht_sig_a_1              : 24; //[23:0]
    174     u32 reserved4                       :  8; //[31:24]
    175     u32 ht_sig_vht_sig_a_2              : 24; //[23:0]
    176     u32 reserved5                       :  8; //[31:25]
    177     u32 reserved6[2];
    178 } __attribute__((packed));
    179 
    180 struct rx_ppdu_end {
    181     u32 reserved1[16];
    182     u32 tsf_timestamp;
    183     u32 reserved2[5];
    184 } __attribute__((packed));
    185 
    186 #define MAX_MSDUS_PER_MPDU 3
    187 #define MAX_RXMPDUS_PER_AMPDU 64
    188 #define RX_HTT_HDR_STATUS_LEN 64
    189 typedef struct {
    190     struct rx_attention attention;
    191     u32 reserved1;
    192     struct rx_mpdu_start mpdu_start;
    193     struct rx_msdu_start msdu_start;
    194     struct rx_msdu_end   msdu_end;
    195     struct rx_mpdu_end   mpdu_end;
    196     struct rx_ppdu_start ppdu_start;
    197     struct rx_ppdu_end   ppdu_end;
    198     char rx_hdr_status[RX_HTT_HDR_STATUS_LEN];
    199 }__attribute__((packed)) rb_pkt_stats_t;
    200 
    201 /*Tx stats specific structures. */
    202 struct ppdu_status {
    203     u32 ba_start_seq_num                : 12; //[11:0]
    204     u32 reserved1                       :  3; //[14:12]
    205     u32 ba_status                       :  1; //[15]
    206     u32 reserved2                       : 15; //[30:16]
    207     u32 tx_ok                           :  1; //[31]
    208     u32 ba_bitmap_31_0                  : 32; //[31:0]
    209     u32 ba_bitmap_63_32                 : 32; //[31:0]
    210     u32 reserved3[8];
    211     u32 ack_rssi_ave                    :  8; //[7:0]
    212     u32 reserved4                       : 16; //[23:8]
    213     u32 total_tries                     :  5; //[28:24]
    214     u32 reserved5                       :  3; //[31:29]
    215     u32 reserved6[4];
    216 } __attribute__((packed));
    217 
    218 /*Contains tx timestamp*/
    219 struct try_status {
    220     u32 timestamp                       : 23; //[22:0]
    221     u32 reserved1                       :  1; //[23]
    222     u32 series                          :  1; //[24]
    223     u32 reserved2                       :  3; //[27:25]
    224     u32 packet_bw                       :  2; //[29:28]
    225     u32 reserved3                       :  1; //[30]
    226     u32 tx_packet                       :  1; //[31]
    227 } __attribute__((packed));
    228 
    229 struct try_list {
    230     struct try_status try_st[16];
    231 } __attribute__((packed));
    232 
    233 
    234 struct tx_ppdu_end {
    235     struct try_list try_list;
    236     struct ppdu_status stat;
    237 } __attribute__((packed));
    238 
    239 /*Tx MCS and data rate ralated stats */
    240 struct series_bw {
    241     u32 reserved1                       : 28; //[27:0]
    242     u32 short_gi                        :  1; //[28]
    243     u32 reserved2                       :  3; //[31:29]
    244     u32 reserved3                       : 24; //[23:21]
    245     u32 rate                            :  4; //[27:24]
    246     u32 nss                             :  2; //[29:28]
    247     u32 preamble_type                   :  2; //[31:30]
    248     u32 reserved4[2];
    249 } __attribute__((packed));
    250 
    251 enum tx_bw {
    252     BW_20_MHZ,
    253     BW_40_MHZ,
    254     BW_80_MHZ,
    255     BW_160_MHZ
    256 };
    257 
    258 #define DATA_PROTECTED 14
    259 struct tx_ppdu_start {
    260     u32 reserved1[2];
    261     u32 start_seq_num                   : 12; //[11:0]
    262     u32 reserved2                       : 20; //[31:12]
    263     u32 seqnum_bitmap_31_0              : 32; //[31:0]
    264     u32 seqnum_bitmap_63_32             : 32; //[31:0]
    265     u32 reserved3[8];
    266     u32 reserved4                       : 15; //[14:0]
    267     u32 ampdu                           :  1; //[15]
    268     u32 no_ack                          :  1; //[16]
    269     u32 reserved5                       : 15; //[31:17]
    270     u32 reserved6                       : 16; //[15:0]
    271     u32 frame_control                   : 16; //[31:16]
    272     u32 reserved7                       : 16; //[23:21]
    273     u32 qos_ctl                         : 16; //[31:16]
    274     u32 reserved8[4];
    275     u32 reserved9                       : 24; //[23:21]
    276     u32 valid_s0_bw20                   :  1; //[24]
    277     u32 valid_s0_bw40                   :  1; //[25]
    278     u32 valid_s0_bw80                   :  1; //[26]
    279     u32 valid_s0_bw160                  :  1; //[27]
    280     u32 valid_s1_bw20                   :  1; //[28]
    281     u32 valid_s1_bw40                   :  1; //[29]
    282     u32 valid_s1_bw80                   :  1; //[30]
    283     u32 valid_s1_bw160                  :  1; //[31]
    284     struct series_bw s0_bw20;
    285     struct series_bw s0_bw40;
    286     struct series_bw s0_bw80;
    287     struct series_bw s0_bw160;
    288     struct series_bw s1_bw20;
    289     struct series_bw s1_bw40;
    290     struct series_bw s1_bw80;
    291     struct series_bw s1_bw160;
    292     u32 reserved10[3];
    293 } __attribute__((packed));
    294 
    295 #define PKTLOG_MAX_TXCTL_WORDS 57 /* +2 words for bitmap */
    296 typedef struct {
    297     u32 reserved1[3];
    298     union {
    299         u32 txdesc_ctl[PKTLOG_MAX_TXCTL_WORDS];
    300         struct tx_ppdu_start ppdu_start;
    301     }u;
    302 } __attribute__((packed)) wh_pktlog_txctl;
    303 
    304 /* Required stats are spread across multiple
    305  * events(PKTLOG_TYPE_TX_CTRL and PKTLOG_TYPE_TX_STAT here).
    306  * Need to aggregate the stats collected in each event and write to the
    307  * ring buffer only after receiving all the expected stats.
    308  * Need to preserve the stats in hal_info till then and use tx_stats_events
    309  * flag to track the events.
    310  * prev_seq_no: Can used to track the events that come from driver and identify
    311  * if any event is missed.
    312  */
    313 
    314 #define RING_BUF_ENTRY_SIZE 512
    315 #define PKT_STATS_BUF_SIZE 128
    316 struct pkt_stats_s {
    317     u8 tx_stats_events;
    318     /* TODO: Need to handle the case if size of the stats are more
    319      * than 512 bytes. Currently, the tx size is 34 bytes and ring buffer entry
    320      * size is 12 bytes.
    321      */
    322     u8 tx_stats[PKT_STATS_BUF_SIZE];
    323     u8 num_msdu;
    324     u16 start_seq_num;
    325     u16 ba_seq_num;
    326     u32 ba_bitmap_31_0;
    327     u32 ba_bitmap_63_32;
    328     u32 tx_seqnum_bitmap_31_0;
    329     u32 tx_seqnum_bitmap_63_32;
    330     u32 shifted_bitmap_31_0;
    331     u32 shifted_bitmap_63_32;
    332     bool isBlockAck;
    333     u8 tx_bandwidth;
    334     u8 series;
    335 };
    336 
    337 typedef union {
    338     struct {
    339         u16 rate                            :  4;
    340         u16 nss                             :  2;
    341         u16 preamble                        :  2;
    342         u16 bw                              :  2;
    343         u16 short_gi                        :  1;
    344         u16 reserved                        :  5;
    345     } mcs_s;
    346     u16 mcs;
    347 } MCS;
    348 
    349 typedef struct {
    350     MCS RxMCS;
    351     u16 last_transmit_rate;
    352     u16 rssi;
    353     u32 timestamp;
    354     u8  tid;
    355 } rx_aggr_stats;
    356 
    357 
    358 typedef struct drv_msg_s
    359 {
    360     u16 length;
    361     u16 event_type;
    362     u32 timestamp_low;
    363     u32 timestamp_high;
    364     union {
    365         struct {
    366             u32 version;
    367             u32 msg_seq_no;
    368             u32 payload_len;
    369             u8  payload[0];
    370         } __attribute__((packed)) pkt_stats_event;
    371     } u;
    372 } __attribute__((packed)) drv_msg_t;
    373 
    374 typedef enum {
    375     START_MONITOR = 1,
    376     STOP_MONITOR,
    377     TX_MGMT_PKT,
    378     TX_DATA_PKT,
    379     RX_MGMT_PKT,
    380     RX_DATA_PKT,
    381 } pktdump_event_type;
    382 
    383 typedef struct {
    384     u8 status;
    385     u8 type;
    386     u32 driver_ts;
    387     u16 fw_ts;
    388 } __attribute__((packed)) pktdump_hdr;
    389 
    390 typedef struct {
    391     frame_type payload_type;
    392     u32 driver_timestamp_usec;
    393     u32 firmware_timestamp_usec;
    394     size_t frame_len;
    395     char *frame_content;
    396 } frame_info_i;
    397 
    398 typedef struct {
    399     // Prefix of MD5 hash of |frame_inf.frame_content|. If frame
    400     // content is not provided, prefix of MD5 hash over the same data
    401     // that would be in frame_content, if frame content were provided.
    402     char md5_prefix[MD5_PREFIX_LEN];  // Prefix of MD5 hash of packet bytes
    403     wifi_tx_packet_fate fate;
    404     frame_info_i frame_inf;
    405 } wifi_tx_report_i;
    406 
    407 typedef struct {
    408     // Prefix of MD5 hash of |frame_inf.frame_content|. If frame
    409     // content is not provided, prefix of MD5 hash over the same data
    410     // that would be in frame_content, if frame content were provided.
    411     char md5_prefix[MD5_PREFIX_LEN];
    412     wifi_rx_packet_fate fate;
    413     frame_info_i frame_inf;
    414 } wifi_rx_report_i;
    415 
    416 typedef struct {
    417     wifi_tx_report_i tx_fate_stats[MAX_FATE_LOG_LEN];
    418     size_t n_tx_stats_collected;
    419     wifi_rx_report_i rx_fate_stats[MAX_FATE_LOG_LEN];
    420     size_t n_rx_stats_collected;
    421 } packet_fate_monitor_info;
    422 
    423 #endif
    424