From 32cb4792062d8b399eceb477b471bc2a321967a9 Mon Sep 17 00:00:00 2001 From: Dustin Brown Date: Thu, 15 Jun 2017 15:33:42 -0700 Subject: [PATCH] qcacld-3.0: Refactor __wlan_hdd_cfg80211_get_station __wlan_hdd_cfg80211_get_station() is notoriously overly complicated. Begin refactoring this function by factoring out some of the conditional compilation. Change-Id: I8a0e66a8dc4bf320080f417b196ead6df06d0995 CRs-Fixed: 2071619 --- core/hdd/src/wlan_hdd_cfg80211.c | 61 +++++++++++++ core/hdd/src/wlan_hdd_cfg80211.h | 25 ++++++ core/hdd/src/wlan_hdd_stats.c | 143 ++++++++++--------------------- 3 files changed, 129 insertions(+), 100 deletions(-) diff --git a/core/hdd/src/wlan_hdd_cfg80211.c b/core/hdd/src/wlan_hdd_cfg80211.c index cf85f57c66b8..cd80c1375b44 100644 --- a/core/hdd/src/wlan_hdd_cfg80211.c +++ b/core/hdd/src/wlan_hdd_cfg80211.c @@ -17919,6 +17919,67 @@ void wlan_hdd_deinit_chan_info(hdd_context_t *hdd_ctx) qdf_mem_free(chan); } +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) +static enum rate_info_bw hdd_map_hdd_bw_to_os(enum hdd_rate_info_bw hdd_bw) +{ + switch (hdd_bw) { + case HDD_RATE_BW_5: + return RATE_INFO_BW_5; + case HDD_RATE_BW_10: + return RATE_INFO_BW_10; + case HDD_RATE_BW_20: + return RATE_INFO_BW_20; + case HDD_RATE_BW_40: + return RATE_INFO_BW_40; + case HDD_RATE_BW_80: + return RATE_INFO_BW_80; + case HDD_RATE_BW_160: + return RATE_INFO_BW_160; + } + + hdd_err("Unhandled HDD_RATE_BW: %d", hdd_bw); + + return RATE_INFO_BW_20; +} + +void hdd_set_rate_bw(struct rate_info *info, enum hdd_rate_info_bw hdd_bw) +{ + info->bw = hdd_map_hdd_bw_to_os(hdd_bw); +} +#else +static enum rate_info_flags hdd_map_hdd_bw_to_os(enum hdd_rate_info_bw hdd_bw) +{ + switch (hdd_bw) { + case HDD_RATE_BW_5: + case HDD_RATE_BW_10: + case HDD_RATE_BW_20: + return (enum rate_info_flags)0; + case HDD_RATE_BW_40: + return RATE_INFO_FLAGS_40_MHZ_WIDTH; + case HDD_RATE_BW_80: + return RATE_INFO_FLAGS_80_MHZ_WIDTH; + case HDD_RATE_BW_160: + return RATE_INFO_FLAGS_160_MHZ_WIDTH; + } + + hdd_err("Unhandled HDD_RATE_BW: %d", hdd_bw); + + return (enum rate_info_flags)0; +} + +void hdd_set_rate_bw(struct rate_info *info, enum hdd_rate_info_bw hdd_bw) +{ + const enum rate_info_flags all_bws = + RATE_INFO_FLAGS_40_MHZ_WIDTH | + RATE_INFO_FLAGS_80_MHZ_WIDTH | + RATE_INFO_FLAGS_80P80_MHZ_WIDTH | + RATE_INFO_FLAGS_160_MHZ_WIDTH; + + info->flags &= ~all_bws; + info->flags |= hdd_map_hdd_bw_to_os(hdd_bw); +} +#endif + /** * struct cfg80211_ops - cfg80211_ops * diff --git a/core/hdd/src/wlan_hdd_cfg80211.h b/core/hdd/src/wlan_hdd_cfg80211.h index 1802c5f0f5f5..ff9893d9ebb5 100644 --- a/core/hdd/src/wlan_hdd_cfg80211.h +++ b/core/hdd/src/wlan_hdd_cfg80211.h @@ -407,6 +407,31 @@ struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter, #define NUM_NL80211_BANDS ((enum nl80211_band)IEEE80211_NUM_BANDS) #endif +/** + * hdd_rate_info_bw: an HDD internal rate bandwidth representation + * @HDD_RATE_BW_5: 5MHz + * @HDD_RATE_BW_10: 10MHz + * @HDD_RATE_BW_20: 20MHz + * @HDD_RATE_BW_40: 40MHz + * @HDD_RATE_BW_80: 80MHz + * @HDD_RATE_BW_160: 160 MHz + */ +enum hdd_rate_info_bw { + HDD_RATE_BW_5, + HDD_RATE_BW_10, + HDD_RATE_BW_20, + HDD_RATE_BW_40, + HDD_RATE_BW_80, + HDD_RATE_BW_160, +}; + +/** + * hdd_set_rate_bw(): Set the bandwidth for the given rate_info + * @info: The rate info for which the bandwidth should be set + * @hdd_bw: HDD representation of a rate info bandwidth + */ +void hdd_set_rate_bw(struct rate_info *info, enum hdd_rate_info_bw hdd_bw); + /** * hdd_lost_link_info_cb() - callback function to get lost link information * @context: HDD context diff --git a/core/hdd/src/wlan_hdd_stats.c b/core/hdd/src/wlan_hdd_stats.c index f59204beea66..057ff90f289a 100644 --- a/core/hdd/src/wlan_hdd_stats.c +++ b/core/hdd/src/wlan_hdd_stats.c @@ -3001,6 +3001,12 @@ static inline void wlan_hdd_fill_station_info_signal(struct station_info } #endif +#ifdef LINKSPEED_DEBUG_ENABLED +#define linkspeed_dbg(format, args...) pr_info(format, ## args) +#else +#define linkspeed_dbg(format, args...) +#endif /* LINKSPEED_DEBUG_ENABLED */ + /** * __wlan_hdd_cfg80211_get_station() - get station statistics * @wiphy: Pointer to wiphy @@ -3129,10 +3135,8 @@ static int __wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, (int)pCfg->linkSpeedRssiHigh, (int)pCfg->linkSpeedRssiMid, (int)pCfg->linkSpeedRssiLow, (int)rate_flags, (int)mcs_index); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) /* assume basic BW. anything else will override this later */ - sinfo->txrate.bw = RATE_INFO_BW_20; -#endif + hdd_set_rate_bw(&sinfo->txrate, HDD_RATE_BW_20); if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed) { /* we do not want to necessarily report the current speed */ @@ -3257,26 +3261,13 @@ static int __wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, (vht_mcs_map & DATA_RATE_11AC_MCS_MASK); if (rate_flags & eHAL_TX_RATE_SGI) rateFlag |= 1; + if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs) maxMCSIdx = 7; - else if (DATA_RATE_11AC_MAX_MCS_8 == - vhtMaxMcs) + else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs) maxMCSIdx = 8; - else if (DATA_RATE_11AC_MAX_MCS_9 == - vhtMaxMcs) { - /* - * IEEE_P802.11ac_2013.pdf page 325, 326 - * - MCS9 is valid for VHT20 when - * Nss = 3 or Nss = 6 - * - MCS9 is not valid for VHT20 when - * Nss = 1,2,4,5,7,8 - */ - if ((rate_flags & eHAL_TX_RATE_VHT20) && - (nss != 3 && nss != 6)) - maxMCSIdx = 8; - else - maxMCSIdx = 9; - } + else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs) + maxMCSIdx = 9; if (rssidx != 0) { for (i = 0; i <= maxMCSIdx; i++) { @@ -3376,62 +3367,31 @@ static int __wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, } else { maxSpeedMCS = 1; maxMCSIdx = mcs_index; - /* - * IEEE_P802.11ac_2013.pdf page 325, 326 - * - MCS9 is valid for VHT20 when - * Nss = 3 or Nss = 6 - * - MCS9 is not valid for VHT20 when - * Nss = 1,2,4,5,7,8 - */ - if ((rate_flags & eHAL_TX_RATE_VHT20) && - (maxMCSIdx > 8) && - (nss != 3 && nss != 6)) { - maxMCSIdx = 8; - } } } if (rate_flags & eHAL_TX_RATE_LEGACY) { sinfo->txrate.legacy = maxRate; -#ifdef LINKSPEED_DEBUG_ENABLED - pr_info("Reporting legacy rate %d\n", - sinfo->txrate.legacy); -#endif /* LINKSPEED_DEBUG_ENABLED */ + linkspeed_dbg("Reporting legacy rate %d\n", + sinfo->txrate.legacy); } else { sinfo->txrate.mcs = maxMCSIdx; sinfo->txrate.nss = nss; - if (rate_flags & eHAL_TX_RATE_VHT80) { - sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) - sinfo->txrate.bw = RATE_INFO_BW_80; -#else - sinfo->txrate.flags |= - RATE_INFO_FLAGS_80_MHZ_WIDTH; -#endif - } else if (rate_flags & eHAL_TX_RATE_VHT40) { - sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) - sinfo->txrate.bw = RATE_INFO_BW_40; -#else - sinfo->txrate.flags |= - RATE_INFO_FLAGS_40_MHZ_WIDTH; -#endif - } else if (rate_flags & eHAL_TX_RATE_VHT20) { - sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS; - } else - sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS; + sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS; + + if (rate_flags & eHAL_TX_RATE_VHT80) + hdd_set_rate_bw(&sinfo->txrate, HDD_RATE_BW_80); + else if (rate_flags & eHAL_TX_RATE_VHT40) + hdd_set_rate_bw(&sinfo->txrate, HDD_RATE_BW_40); + if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40)) { sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; - if (rate_flags & eHAL_TX_RATE_HT40) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) - sinfo->txrate.bw = RATE_INFO_BW_40; -#else - sinfo->txrate.flags |= - RATE_INFO_FLAGS_40_MHZ_WIDTH; -#endif - } + if (rate_flags & eHAL_TX_RATE_HT40) + hdd_set_rate_bw(&sinfo->txrate, + HDD_RATE_BW_40); } + if (rate_flags & eHAL_TX_RATE_SGI) { if (! (sinfo->txrate. @@ -3440,10 +3400,8 @@ static int __wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, RATE_INFO_FLAGS_MCS; sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; } -#ifdef LINKSPEED_DEBUG_ENABLED - pr_info("Reporting MCS rate %d flags %x\n", - sinfo->txrate.mcs, sinfo->txrate.flags); -#endif /* LINKSPEED_DEBUG_ENABLED */ + linkspeed_dbg("Reporting MCS rate %d flags %x\n", + sinfo->txrate.mcs, sinfo->txrate.flags); } } else { /* report current rate instead of max rate */ @@ -3451,50 +3409,34 @@ static int __wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, if (rate_flags & eHAL_TX_RATE_LEGACY) { /* provide to the UI in units of 100kbps */ sinfo->txrate.legacy = myRate; -#ifdef LINKSPEED_DEBUG_ENABLED - pr_info("Reporting actual legacy rate %d\n", - sinfo->txrate.legacy); -#endif /* LINKSPEED_DEBUG_ENABLED */ + linkspeed_dbg("Reporting actual legacy rate %d\n", + sinfo->txrate.legacy); } else { /* must be MCS */ sinfo->txrate.mcs = mcs_index; sinfo->txrate.nss = nss; sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS; - if (rate_flags & eHAL_TX_RATE_VHT80) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) - sinfo->txrate.bw = RATE_INFO_BW_80; -#else - sinfo->txrate.flags |= - RATE_INFO_FLAGS_80_MHZ_WIDTH; -#endif - } else if (rate_flags & eHAL_TX_RATE_VHT40) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) - sinfo->txrate.bw = RATE_INFO_BW_40; -#else - sinfo->txrate.flags |= - RATE_INFO_FLAGS_40_MHZ_WIDTH; -#endif - } + + if (rate_flags & eHAL_TX_RATE_VHT80) + hdd_set_rate_bw(&sinfo->txrate, HDD_RATE_BW_80); + else if (rate_flags & eHAL_TX_RATE_VHT40) + hdd_set_rate_bw(&sinfo->txrate, HDD_RATE_BW_40); + if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40)) { sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; - if (rate_flags & eHAL_TX_RATE_HT40) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) || defined(WITH_BACKPORTS) - sinfo->txrate.bw = RATE_INFO_BW_40; -#else - sinfo->txrate.flags |= - RATE_INFO_FLAGS_40_MHZ_WIDTH; -#endif - } + if (rate_flags & eHAL_TX_RATE_HT40) + hdd_set_rate_bw(&sinfo->txrate, + HDD_RATE_BW_40); } + if (rate_flags & eHAL_TX_RATE_SGI) { sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; } -#ifdef LINKSPEED_DEBUG_ENABLED - pr_info("Reporting actual MCS rate %d flags %x\n", - sinfo->txrate.mcs, sinfo->txrate.flags); -#endif /* LINKSPEED_DEBUG_ENABLED */ + + linkspeed_dbg("Reporting actual MCS rate %d flags %x\n", + sinfo->txrate.mcs, sinfo->txrate.flags); } } @@ -3579,11 +3521,12 @@ static int __wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, } #endif - MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_CFG80211_GET_STA, pAdapter->sessionId, maxRate)); + EXIT(); + return 0; }