wlan: HDD: Link Layer Statistics Implementation

This commit introduces the link layer statistics implementation
in HDD and SME layers.

Change-Id: I8240243aa87999fc14fbd7e3f23b9612b7aca4d6
CRs-Fixed: 665003
diff --git a/CORE/HDD/inc/wlan_hdd_cfg80211.h b/CORE/HDD/inc/wlan_hdd_cfg80211.h
index ed1a2e7..4180469 100644
--- a/CORE/HDD/inc/wlan_hdd_cfg80211.h
+++ b/CORE/HDD/inc/wlan_hdd_cfg80211.h
@@ -30,22 +30,18 @@
 
 
 /**===========================================================================
-  
+
   \file  wlan_hdd_cfg80211.h
-  
+
   \brief cfg80211 functions declarations
-    
-               Copyright 2008 (c) Qualcomm, Incorporated.
-               All Rights Reserved.
-               Qualcomm Confidential and Proprietary.
-  
+
   ==========================================================================*/
-  
+
 /* $HEADER$ */
 
 
 //value for initial part of frames and number of bytes to be compared
-#define GAS_INITIAL_REQ "\x04\x0a"  
+#define GAS_INITIAL_REQ "\x04\x0a"
 #define GAS_INITIAL_REQ_SIZE 2
 
 #define GAS_INITIAL_RSP "\x04\x0b"
@@ -57,7 +53,7 @@
 #define GAS_COMEBACK_RSP "\x04\x0d"
 #define GAS_COMEBACK_RSP_SIZE 2
 
-#define P2P_PUBLIC_ACTION_FRAME "\x04\x09\x50\x6f\x9a\x09" 
+#define P2P_PUBLIC_ACTION_FRAME "\x04\x09\x50\x6f\x9a\x09"
 #define P2P_PUBLIC_ACTION_FRAME_SIZE 6
 
 #define P2P_ACTION_FRAME "\x7f\x50\x6f\x9a\x09"
@@ -117,16 +113,335 @@
 }__attribute__((packed)) qcom_ie_age ;
 #endif
 
+enum qca_nl80211_vendor_subcmds {
+    QCA_NL80211_VENDOR_SUBCMD_UNSPEC = 0,
+    QCA_NL80211_VENDOR_SUBCMD_TEST = 1,
+    /* subcmds 2..9 not yet allocated */
+    QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY = 10,
+    QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY =  11,
+    QCA_NL80211_VENDOR_SUBCMD_NAN =  12,
+    QCA_NL80211_VENDOR_SUBCMD_STATS_EXT = 13,
+
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET = 14,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET = 15,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR = 16,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_RADIO_RESULTS = 17,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_IFACE_RESULTS = 18,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_PEERS_RESULTS = 19,
+};
+
+enum qca_nl80211_vendor_subcmds_index {
+    QCA_NL80211_VENDOR_SUBCMD_NAN_INDEX = 0,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_SET_INDEX,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_GET_INDEX,
+    QCA_NL80211_VENDOR_SUBCMD_LL_STATS_CLR_INDEX,
+    QCA_NL80211_VENDOR_SUBCMD_LL_RADIO_STATS_INDEX,
+    QCA_NL80211_VENDOR_SUBCMD_LL_IFACE_STATS_INDEX,
+    QCA_NL80211_VENDOR_SUBCMD_LL_PEER_INFO_STATS_INDEX,
+};
+
+enum qca_wlan_vendor_attr
+{
+    QCA_WLAN_VENDOR_ATTR_INVALID = 0,
+    /* used by QCOM_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY */
+    QCA_WLAN_VENDOR_ATTR_DFS     = 1,
+    /* used by QCOM_NL80211_VENDOR_SUBCMD_NAN */
+    QCA_WLAN_VENDOR_ATTR_NAN     = 2,
+
+    /* keep last */
+    QCA_WLAN_VENDOR_ATTR_AFTER_LAST,
+    QCA_WLAN_VENDOR_ATTR_MAX       = QCA_WLAN_VENDOR_ATTR_AFTER_LAST - 1,
+};
+
+#ifdef WLAN_FEATURE_LINK_LAYER_STATS
+
+enum qca_wlan_vendor_attr_ll_stats_set
+{
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_INVALID = 0,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_CONFIG_MPDU_SIZE_THRESHOLD = 1,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_CONFIG_AGGRESSIVE_STATS_GATHERING,
+    /* keep last */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_AFTER_LAST,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_MAX =
+                    QCA_WLAN_VENDOR_ATTR_LL_STATS_SET_AFTER_LAST - 1,
+};
+
+enum qca_wlan_vendor_attr_ll_stats_get
+{
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_INVALID = 0,
+    /* Unsigned 32bit value provided by the caller issuing the GET stats
+     * command. When reporting the stats results, the driver uses the same
+     * value to indicate which GET request the results correspond to.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_CONFIG_REQ_ID,
+    /* Unsigned 34bit value - bit mask to identify what
+     * statistics are requested for retrieval.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_CONFIG_REQ_MASK,
+    /* keep last */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_AFTER_LAST,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_MAX =
+                  QCA_WLAN_VENDOR_ATTR_LL_STATS_GET_AFTER_LAST - 1,
+};
+
+enum qca_wlan_vendor_attr_ll_stats_clr
+{
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_INVALID = 0,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_CONFIG_REQ_MASK,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_CONFIG_STOP_REQ,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_CONFIG_RSP_MASK,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_CONFIG_STOP_RSP,
+
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_AFTER_LAST,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_MAX       =
+                        QCA_WLAN_VENDOR_ATTR_LL_STATS_CLR_AFTER_LAST - 1,
+};
+
+enum qca_wlan_vendor_attr_ll_stats_results
+{
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_INVALID = 0,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RESULTS_REQ_ID = 1,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_BEACON_RX,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_MGMT_RX,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_MGMT_ACTION_RX,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_MGMT_ACTION_TX,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_RSSI_MGMT,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_RSSI_DATA,
+    /* Unsigned 32bit value */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_RSSI_ACK,
+    /* Attributes of type QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_* are
+     * nested within the interface stats.
+     */
+
+    /* Interface mode, e.g., STA, SOFTAP, IBSS, etc.
+     * Type = enum wifi_interface_mode */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_MODE,
+    /* Interface MAC address. An array of 6 Unsigned int8 */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_MAC_ADDR,
+    /* Type = enum wifi_connection_state,
+     * e.g., DISCONNECTED, AUTHENTICATING, etc.
+     * valid for STA, CLI only.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_STATE,
+    /* Type = enum wifi_roam_state. Roaming state,
+     * e.g., IDLE or ACTIVE (is that valid for STA only?)
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_ROAMING,
+    /* Unsigned 32bit value. WIFI_CAPABILITY_XXX */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_CAPABILITIES,
+    /* NULL terminated SSID. An array of 33 Unsigned 8bit values */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_SSID,
+    /* BSSID. An array of 6 Unsigned 8bit values */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_BSSID,
+    /* Country string advertised by AP. An array of 3 Unsigned 8bit values */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_AP_COUNTRY_STR,
+    /* Country string for this association. An array of 3 Unsigned 8bit values*/
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_INFO_COUNTRY_STR,
+
+    /* Attributes of type QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_* could
+     * be nested within the interface stats.
+     */
+
+    /* Type = enum wifi_traffic_ac, e.g., V0, VI, BE and BK */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_AC,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_TX_MPDU,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_RX_MPDU,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_TX_MCAST,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_RX_MCAST,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_RX_AMPDU,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_TX_AMPDU,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_MPDU_LOST,
+    /* Unsigned int 32 value corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_RETRIES,
+    /* Unsigned int 32 value corresponding to respective AC  */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_RETRIES_SHORT,
+    /* Unsigned int 32 values corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_RETRIES_LONG,
+    /* Unsigned int 32 values corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_CONTENTION_TIME_MIN,
+    /* Unsigned int 32 values corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_CONTENTION_TIME_MAX,
+    /* Unsigned int 32 values corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_CONTENTION_TIME_AVG,
+    /* Unsigned int 32 values corresponding to respective AC */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_AC_CONTENTION_NUM_SAMPLES,
+    /* Unsigned 32bit value. Number of peers */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_IFACE_NUM_PEERS,
+
+    /* Attributes of type QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO_* are
+     * nested within the interface stats.
+     */
+
+    /* Type = enum wifi_peer_type. Peer type, e.g., STA, AP, P2P GO etc. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO_TYPE,
+    /* MAC addr corresponding to respective peer.
+     *  An array of 6 Unsigned 8bit values.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO_MAC_ADDRESS,
+    /* Unsigned int 32bit value representing capabilities
+     * corresponding to respective peer.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO_CAPABILITIES,
+    /* Unsigned 32bit value. Number of rates */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO_NUM_RATES,
+
+    /* Attributes nested within the rate stats.*/
+    /* Unsigned 8bit value */
+    /* Unsigned int 8bit value; 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_PREAMBLE,
+    /* Unsigned int 8bit value; 0:1x1, 1:2x2, 3:3x3, 4:4x4 */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_NSS,
+    /* Unsigned int 8bit value; 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_BW,
+    /* Unsigned int 8bit value; OFDM/CCK rate code would be as per IEEE Std
+     * in the units of 0.5mbps HT/VHT it would be mcs index */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_MCS_INDEX,
+
+    /* Unsigned 32bit value. Bit rate in units of 100Kbps */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_BIT_RATE,
+
+    /* Attributes of type QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_* could be
+     * nested within the peer info stats.
+     */
+
+    /* Unsigned int 32bit value. Number of successfully transmitted data pkts,
+     * i.e., with ACK received  *corresponding to the respective rate.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_TX_MPDU,
+    /* Unsigned int 32bit value. Number of received data pkts
+     * corresponding to the respective rate. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_RX_MPDU,
+    /* Unsigned int 32bit value. Number of data pkts losses, i.e.,
+     * no ACK received corresponding to *the respective rate.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_MPDU_LOST,
+    /* Unsigned int 32bit value. Total number of data pkt retries for
+     *   the respective rate.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_RETRIES,
+    /* Unsigned int 32bit value. Total number of short data pkt retries for
+      the respective rate. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_RETRIES_SHORT,
+    /* Unsigned int 32bit value. Total number of long data pkt retries for
+     * the respective rate.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RATE_RETRIES_LONG,
+
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ID,
+    /* Unsigned 32bit value. Total number of msecs the radio is awake
+     *  accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * transmitting accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_TX_TIME,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * in active receive accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_RX_TIME,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * awake due to all scan accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME_SCAN,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     *   awake due to NAN accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME_NBD,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * awake due to GSCAN accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME_GSCAN,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * awake due to roam scan accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME_ROAM_SCAN,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * awake due to PNO scan accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME_PNO_SCAN,
+    /* Unsigned 32bit value. Total number of msecs the radio is
+     * awake due to HS2.0 scans and GAS exchange accruing over time.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_ON_TIME_HS20,
+    /* Unsigned 32bit value. Number of channels. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RADIO_NUM_CHANNELS,
+
+    /* Attributes of type QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_INFO_
+     * could be nested within the channel stats.
+     */
+
+    /* Type = enum wifi_channel_width. Channel width, e.g., 20, 40, 80, etc.*/
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_INFO_WIDTH,
+    /* Unsigned 32bit value. Primary 20MHz channel. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_INFO_CENTER_FREQ,
+    /* Unsigned 32bit value. Center frequency (MHz) first segment. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_INFO_CENTER_FREQ0,
+    /* Unsigned 32bit value. Center frequency (MHz) second segment. */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_INFO_CENTER_FREQ1,
+
+    /* Attributes of type QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_ could be
+     * nested within the radio stats.
+     */
+
+    /* Unsigned int 32bit value representing total number of msecs the radio
+     * s awake on that *channel accruing over time, corresponding to
+     * the respective channel.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_ON_TIME,
+    /* Unsigned int 32bit value representing total number of msecs the
+     * CCA register is busy accruing  *over time corresponding to the
+     * respective channel.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CHANNEL_CCA_BUSY_TIME,
+
+
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_NUM_RADIOS,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_CH_INFO,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_PEER_INFO_RATE_INFO,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_WMM_INFO,
+
+    /* Unsigned 8bit value. Used by the driver; if set to 1, it indicates that
+     * more stats, e.g., peers or radio, are to follow in the next
+     * QCA_NL80211_VENDOR_SUBCMD_LL_STATS_*_RESULTS event.
+     * Otherwise, it is set to 0.
+     */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_RESULTS_MORE_DATA,
+
+    /* keep last */
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_AFTER_LAST,
+    QCA_WLAN_VENDOR_ATTR_LL_STATS_MAX   =
+                        QCA_WLAN_VENDOR_ATTR_LL_STATS_AFTER_LAST -1,
+};
+
+
+#endif /* WLAN_FEATURE_LINK_LAYER_STATS */
+
+
 /* Vendor id to be used in vendor specific command and events
  * to user space. Use QCA OUI 00:13:74 to match with define in
  * supplicant code.
  */
-#define QCOM_NL80211_VENDOR_ID                0x001374
+#define QCA_NL80211_VENDOR_ID                0x001374
 
 /* Vendor speicific sub-command id and their index */
 #ifdef FEATURE_WLAN_CH_AVOID
-#define QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY         10
-#define QCOM_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX   0
+#define QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY_INDEX   0
 #endif /* FEATURE_WLAN_CH_AVOID */
 
 #ifdef FEATURE_WLAN_CH_AVOID