2019-11-12 11:47:01

by Yu Wang

[permalink] [raw]
Subject: [PATCH 0/2] ath10k: correct tx bitrate for QCA6174/QCA9377/QCA9888

Tx bitrate got by command 'iw wlan0 link' is incorrect.
These 2 patches will fix the issue.

Yu Wang (2):
ath10k: add ppdu stats support for QCA6174/QCA9377
ath10k: correct legacy rate in tx stats

drivers/net/wireless/ath/ath10k/htt.c | 2 +
drivers/net/wireless/ath/ath10k/htt.h | 30 ++++++++
drivers/net/wireless/ath/ath10k/htt_rx.c | 113 ++++++++++++++++++++++--------
drivers/net/wireless/ath/ath10k/mac.c | 13 ----
drivers/net/wireless/ath/ath10k/mac.h | 11 +++
drivers/net/wireless/ath/ath10k/wmi-ops.h | 15 +++-
drivers/net/wireless/ath/ath10k/wmi-tlv.c | 42 +++++++++++
drivers/net/wireless/ath/ath10k/wmi-tlv.h | 3 +
drivers/net/wireless/ath/ath10k/wmi.c | 46 ++++++++++++
9 files changed, 232 insertions(+), 43 deletions(-)

--
2.7.4


2019-11-12 11:47:02

by Yu Wang

[permalink] [raw]
Subject: [PATCH 1/2] ath10k: add ppdu stats support for QCA6174/QCA9377

When QCA6174/QCA9377 working in station mode, after connected
to AP, tx bitrate is always '1.0 MBit/s' in output of command
'iw wlan0 link'.

That's because the parameters to calculate the tx bitrate are
not well updated for QCA6174/QCA9377.

To fix this issue:
1. Add processing for HTT_T2H_MSG_TYPE_PPDU_STATS_IND which includes
the peer tx stats;
2. Map WMI_TLV_SERVICE_PEER_STATS_INFO to WMI_SERVICE_PEER_STATS to
enable the feature.

Tested with QCA6174 PCIe with firmware WLAN.RM.4.4.1.c3-00031.
Tested with QCA6174 SDIO with firmware WLAN.RMH.4.4.1-00029.

Signed-off-by: Yu Wang <[email protected]>
---
drivers/net/wireless/ath/ath10k/htt.c | 2 +
drivers/net/wireless/ath/ath10k/htt.h | 30 ++++++++++++++
drivers/net/wireless/ath/ath10k/htt_rx.c | 65 +++++++++++++++++++++++++++++++
drivers/net/wireless/ath/ath10k/wmi-tlv.c | 4 ++
drivers/net/wireless/ath/ath10k/wmi-tlv.h | 3 ++
5 files changed, 104 insertions(+)

diff --git a/drivers/net/wireless/ath/ath10k/htt.c b/drivers/net/wireless/ath/ath10k/htt.c
index 7b75200..c32ab07 100644
--- a/drivers/net/wireless/ath/ath10k/htt.c
+++ b/drivers/net/wireless/ath/ath10k/htt.c
@@ -89,6 +89,8 @@ static const enum htt_t2h_msg_type htt_tlv_t2h_msg_types[] = {
[HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR] =
HTT_T2H_MSG_TYPE_RX_OFLD_PKT_ERR,
[HTT_TLV_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
+ [HTT_TLV_T2H_MSG_TYPE_PPDU_STATS_IND] =
+ HTT_T2H_MSG_TYPE_PPDU_STATS_IND,
};

static const enum htt_t2h_msg_type htt_10_4_t2h_msg_types[] = {
diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/ath/ath10k/htt.h
index 30c0800..e2aae263 100644
--- a/drivers/net/wireless/ath/ath10k/htt.h
+++ b/drivers/net/wireless/ath/ath10k/htt.h
@@ -450,6 +450,13 @@ enum htt_tlv_t2h_msg_type {
HTT_TLV_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE = 0x14,
HTT_TLV_T2H_MSG_TYPE_CHAN_CHANGE = 0x15,
HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR = 0x16,
+ HTT_TLV_T2H_MSG_TYPE_RATE_REPORT = 0x17,
+ HTT_TLV_T2H_MSG_TYPE_FLOW_POOL_MAP = 0x18,
+ HTT_TLV_T2H_MSG_TYPE_FLOW_POOL_UNMAP = 0x19,
+ HTT_TLV_T2H_MSG_TYPE_SRING_SETUP_DONE = 0x1a,
+ HTT_TLV_T2H_MSG_TYPE_MAP_FLOW_INFO = 0x1b,
+ HTT_TLV_T2H_MSG_TYPE_EXT_STATS_CONF = 0x1c,
+ HTT_TLV_T2H_MSG_TYPE_PPDU_STATS_IND = 0x1d,
HTT_TLV_T2H_MSG_TYPE_TEST,
/* keep this last */
HTT_TLV_T2H_NUM_MSGS
@@ -519,6 +526,7 @@ enum htt_t2h_msg_type {
HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM,
HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND,
HTT_T2H_MSG_TYPE_PEER_STATS,
+ HTT_T2H_MSG_TYPE_PPDU_STATS_IND,
/* keep this last */
HTT_T2H_NUM_MSGS
};
@@ -1750,6 +1758,27 @@ struct htt_peer_tx_stats {
u8 payload[0];
} __packed;

+struct htt_tx_ppdu_stats_info {
+ __le32 tlv_hdr;
+ __le32 tx_success_bytes;
+ __le32 tx_retry_bytes;
+ __le32 tx_failed_bytes;
+ u8 tx_ratecode;
+ u8 flags;
+ __le16 peer_id;
+ __le16 tx_success_msdus;
+ __le16 tx_retry_msdus;
+ __le16 tx_failed_msdus;
+ __le16 tx_duration;
+} __packed;
+
+struct htt_ppdu_stats {
+ u8 pad[3];
+ __le32 tlv_hdr;
+ __le32 num_ppdu;
+ struct htt_tx_ppdu_stats_info tx_ppdu_stats[0];
+} __packed;
+
#define ATH10K_10_2_TX_STATS_OFFSET 136
#define PEER_STATS_FOR_NO_OF_PPDUS 4

@@ -1823,6 +1852,7 @@ struct htt_resp {
struct htt_tx_mode_switch_ind tx_mode_switch_ind;
struct htt_channel_change chan_change;
struct htt_peer_tx_stats peer_tx_stats;
+ struct htt_ppdu_stats ppdu_stats;
};
} __packed;

diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index d95b63f..cde2d9b 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -3723,6 +3723,68 @@ static void ath10k_htt_rx_sec_ind_handler(struct ath10k *ar,
spin_unlock_bh(&ar->data_lock);
}

+static void
+ath10k_htt_process_ppdu_stats(struct ath10k *ar, struct sk_buff *skb)
+{
+ struct htt_resp *resp = (struct htt_resp *)skb->data;
+ struct ath10k_per_peer_tx_stats *p_tx_stats = &ar->peer_tx_stats;
+ struct htt_tx_ppdu_stats_info *tx_stats;
+ struct ieee80211_sta *sta;
+ struct ath10k_sta *arsta;
+ struct ath10k_peer *peer;
+ u32 peer_id, i;
+ u8 num_ppdu;
+
+ num_ppdu = resp->ppdu_stats.num_ppdu;
+ tx_stats = &resp->ppdu_stats.tx_ppdu_stats[0];
+ peer_id = __le16_to_cpu(tx_stats->peer_id);
+
+ rcu_read_lock();
+ spin_lock_bh(&ar->data_lock);
+
+ peer = ath10k_peer_find_by_id(ar, peer_id);
+ if (!peer)
+ goto err;
+
+ sta = peer->sta;
+ if (!sta)
+ goto err;
+
+ for (i = 0; i < num_ppdu; i++) {
+ tx_stats = &resp->ppdu_stats.tx_ppdu_stats[i];
+ arsta = (struct ath10k_sta *)sta->drv_priv;
+
+ p_tx_stats->succ_bytes =
+ __le32_to_cpu(tx_stats->tx_success_bytes);
+ p_tx_stats->retry_bytes =
+ __le32_to_cpu(tx_stats->tx_retry_bytes);
+ p_tx_stats->failed_bytes =
+ __le32_to_cpu(tx_stats->tx_failed_bytes);
+ p_tx_stats->ratecode = tx_stats->tx_ratecode;
+ p_tx_stats->flags = tx_stats->flags;
+ p_tx_stats->succ_pkts =
+ __le16_to_cpu(tx_stats->tx_success_msdus);
+ p_tx_stats->retry_pkts =
+ __le16_to_cpu(tx_stats->tx_retry_msdus);
+ p_tx_stats->failed_pkts =
+ __le16_to_cpu(tx_stats->tx_failed_msdus);
+ p_tx_stats->duration =
+ __le16_to_cpu(tx_stats->tx_duration);
+
+ ath10k_update_per_peer_tx_stats(ar, sta, p_tx_stats);
+ }
+
+ spin_unlock_bh(&ar->data_lock);
+ rcu_read_unlock();
+
+ return;
+
+err:
+ spin_unlock_bh(&ar->data_lock);
+ rcu_read_unlock();
+ ath10k_warn(ar, "invalid ppdu stats received\n");
+}
+
bool ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
{
struct ath10k_htt *htt = &ar->htt;
@@ -3910,6 +3972,9 @@ bool ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
case HTT_T2H_MSG_TYPE_PEER_STATS:
ath10k_htt_fetch_peer_stats(ar, skb);
break;
+ case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
+ ath10k_htt_process_ppdu_stats(ar, skb);
+ break;
case HTT_T2H_MSG_TYPE_EN_STATS:
default:
ath10k_warn(ar, "htt event (%d) not handled\n",
diff --git a/drivers/net/wireless/ath/ath10k/wmi-tlv.c b/drivers/net/wireless/ath/ath10k/wmi-tlv.c
index 69a1ec5..ae12a58 100644
--- a/drivers/net/wireless/ath/ath10k/wmi-tlv.c
+++ b/drivers/net/wireless/ath/ath10k/wmi-tlv.c
@@ -1849,6 +1849,10 @@ static struct sk_buff *ath10k_wmi_tlv_op_gen_init(struct ath10k *ar)
if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
cfg->host_capab |= __cpu_to_le32(WMI_RSRC_CFG_FLAG_TX_ACK_RSSI);

+ if (ath10k_peer_stats_enabled(ar))
+ cfg->host_capab |=
+ __cpu_to_le32(WMI_RSRC_CFG_FLAG_TX_PPDU_STATS);
+
ath10k_wmi_tlv_put_host_mem_chunks(ar, chunks);

ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv init\n");
diff --git a/drivers/net/wireless/ath/ath10k/wmi-tlv.h b/drivers/net/wireless/ath/ath10k/wmi-tlv.h
index 4972dc1..6635d96 100644
--- a/drivers/net/wireless/ath/ath10k/wmi-tlv.h
+++ b/drivers/net/wireless/ath/ath10k/wmi-tlv.h
@@ -16,6 +16,7 @@
#define WMI_TLV_VDEV_PARAM_UNSUPPORTED 0
#define WMI_TLV_MGMT_TX_FRAME_MAX_LEN 64

+#define WMI_RSRC_CFG_FLAG_TX_PPDU_STATS BIT(11)
#define WMI_RSRC_CFG_FLAG_TX_ACK_RSSI BIT(18)

enum wmi_tlv_grp_id {
@@ -1600,6 +1601,8 @@ wmi_tlv_svc_map(const __le32 *in, unsigned long *out, size_t len)
WMI_SERVICE_MESH_11S, len);
SVCMAP(WMI_TLV_SERVICE_SYNC_DELETE_CMDS,
WMI_SERVICE_SYNC_DELETE_CMDS, len);
+ SVCMAP(WMI_TLV_SERVICE_PEER_STATS_INFO,
+ WMI_SERVICE_PEER_STATS, len);
}

static inline void
--
2.7.4

2019-11-12 11:49:45

by Yu Wang

[permalink] [raw]
Subject: [PATCH 2/2] ath10k: correct legacy rate in tx stats

When working in station mode, after connected to a legacy
AP, 11g only, for example, the tx bitrate is incorrect in
output of command 'iw wlan0 link'.

That's because the legacy tx bitrate value reported by
firmware is not well handled:
For QCA6174, the value represents rate index, but treated
as a real rate;
For QCA9888, the value is real rate, with unit 'Mbps', but
treated as '100kbps'.

To fix this issue:
1. Translate the rate index to real rate for QCA6174;
2. Translate the rate from 'Mbps' to 'kbps' for QCA9888.

Tested with:
QCA6174 PCIe with firmware WLAN.RM.4.4.1.c3-00031.
QCA6174 SDIO with firmware WLAN.RMH.4.4.1-00029.
QCA9888 PCIe with firmware 10.4-3.9.0.2-00040.

Signed-off-by: Yu Wang <[email protected]>
---
drivers/net/wireless/ath/ath10k/htt_rx.c | 48 ++++++++++++-------------------
drivers/net/wireless/ath/ath10k/mac.c | 13 ---------
drivers/net/wireless/ath/ath10k/mac.h | 11 +++++++
drivers/net/wireless/ath/ath10k/wmi-ops.h | 15 +++++++++-
drivers/net/wireless/ath/ath10k/wmi-tlv.c | 38 ++++++++++++++++++++++++
drivers/net/wireless/ath/ath10k/wmi.c | 46 +++++++++++++++++++++++++++++
6 files changed, 128 insertions(+), 43 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index cde2d9b..e0b6aff 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -12,6 +12,7 @@
#include "debug.h"
#include "trace.h"
#include "mac.h"
+#include "wmi-ops.h"

#include <linux/log2.h>
#include <linux/bitfield.h>
@@ -3310,21 +3311,6 @@ void ath10k_htt_htc_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
dev_kfree_skb_any(skb);
}

-static inline s8 ath10k_get_legacy_rate_idx(struct ath10k *ar, u8 rate)
-{
- static const u8 legacy_rates[] = {1, 2, 5, 11, 6, 9, 12,
- 18, 24, 36, 48, 54};
- int i;
-
- for (i = 0; i < ARRAY_SIZE(legacy_rates); i++) {
- if (rate == legacy_rates[i])
- return i;
- }
-
- ath10k_warn(ar, "Invalid legacy rate %hhd peer stats", rate);
- return -EINVAL;
-}
-
static void
ath10k_accumulate_per_peer_tx_stats(struct ath10k *ar,
struct ath10k_sta *arsta,
@@ -3454,10 +3440,12 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
{
struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
struct ieee80211_chanctx_conf *conf = NULL;
- u8 rate = 0, sgi;
- s8 rate_idx = 0;
+ u8 sgi;
+ s8 rate_idx = -1;
bool skip_auto_rate;
struct rate_info txrate;
+ enum nl80211_band band;
+ struct ieee80211_supported_band *sband;

lockdep_assert_held(&ar->data_lock);

@@ -3475,7 +3463,7 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
return;

if (txrate.flags == WMI_RATE_PREAMBLE_VHT && txrate.mcs > 9) {
- ath10k_warn(ar, "Invalid VHT mcs %hhd peer stats", txrate.mcs);
+ ath10k_warn(ar, "Invalid VHT mcs %hhd peer stats", txrate.mcs);
return;
}

@@ -3490,14 +3478,19 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
memset(&arsta->tx_info.status, 0, sizeof(arsta->tx_info.status));
if (txrate.flags == WMI_RATE_PREAMBLE_CCK ||
txrate.flags == WMI_RATE_PREAMBLE_OFDM) {
- rate = ATH10K_HW_LEGACY_RATE(peer_stats->ratecode);
- /* This is hacky, FW sends CCK rate 5.5Mbps as 6 */
- if (rate == 6 && txrate.flags == WMI_RATE_PREAMBLE_CCK)
- rate = 5;
- rate_idx = ath10k_get_legacy_rate_idx(ar, rate);
- if (rate_idx < 0)
+ if (!arsta->arvif || !arsta->arvif->vif)
+ return;
+
+ conf = rcu_dereference(arsta->arvif->vif->chanctx_conf);
+ if (!conf)
+ return;
+
+ band = conf->def.chan->band;
+ sband = &ar->mac.sbands[band];
+ if (ath10k_wmi_get_legacy_rate(ar, sband, peer_stats->ratecode,
+ &arsta->txrate.legacy,
+ &rate_idx))
return;
- arsta->txrate.legacy = rate;
} else if (txrate.flags == WMI_RATE_PREAMBLE_HT) {
arsta->txrate.flags = RATE_INFO_FLAGS_MCS;
arsta->txrate.mcs = txrate.mcs + 8 * (txrate.nss - 1);
@@ -3508,10 +3501,7 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,

switch (txrate.flags) {
case WMI_RATE_PREAMBLE_OFDM:
- if (arsta->arvif && arsta->arvif->vif)
- conf = rcu_dereference(arsta->arvif->vif->chanctx_conf);
- if (conf && conf->def.chan->band == NL80211_BAND_5GHZ)
- arsta->tx_info.status.rates[0].idx = rate_idx - 4;
+ arsta->tx_info.status.rates[0].idx = rate_idx;
break;
case WMI_RATE_PREAMBLE_CCK:
arsta->tx_info.status.rates[0].idx = rate_idx;
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 5e3450c..555f850 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -94,19 +94,6 @@ static struct ieee80211_rate ath10k_rates_rev2[] = {

#define ath10k_wmi_legacy_rates ath10k_rates

-static bool ath10k_mac_bitrate_is_cck(int bitrate)
-{
- switch (bitrate) {
- case 10:
- case 20:
- case 55:
- case 110:
- return true;
- }
-
- return false;
-}
-
static u8 ath10k_mac_bitrate_to_rate(int bitrate)
{
return DIV_ROUND_UP(bitrate, 5) |
diff --git a/drivers/net/wireless/ath/ath10k/mac.h b/drivers/net/wireless/ath/ath10k/mac.h
index 98d83a2..ce700ed 100644
--- a/drivers/net/wireless/ath/ath10k/mac.h
+++ b/drivers/net/wireless/ath/ath10k/mac.h
@@ -92,4 +92,15 @@ static inline void ath10k_tx_h_seq_no(struct ieee80211_vif *vif,
}
}

+static inline bool ath10k_mac_bitrate_is_cck(int bitrate)
+{
+ switch (bitrate) {
+ case 10:
+ case 20:
+ case 55:
+ case 110:
+ return true;
+ }
+ return false;
+}
#endif /* _MAC_H_ */
diff --git a/drivers/net/wireless/ath/ath10k/wmi-ops.h b/drivers/net/wireless/ath/ath10k/wmi-ops.h
index 1491c25..aa20e1c 100644
--- a/drivers/net/wireless/ath/ath10k/wmi-ops.h
+++ b/drivers/net/wireless/ath/ath10k/wmi-ops.h
@@ -216,7 +216,9 @@ struct wmi_ops {
struct sk_buff *(*gen_bb_timing)
(struct ath10k *ar,
const struct wmi_bb_timing_cfg_arg *arg);
-
+ int (*get_legacy_rate)(struct ath10k *ar,
+ struct ieee80211_supported_band *sband,
+ u8 ratecode, u16 *rate, s8 *idx);
};

int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
@@ -1616,4 +1618,15 @@ ath10k_wmi_pdev_bb_timing(struct ath10k *ar,
return ath10k_wmi_cmd_send(ar, skb,
ar->wmi.cmd->set_bb_timing_cmdid);
}
+
+static inline int
+ath10k_wmi_get_legacy_rate(struct ath10k *ar,
+ struct ieee80211_supported_band *sband,
+ u8 ratecode, u16 *rate, s8 *idx)
+{
+ if (!ar->wmi.ops->get_legacy_rate)
+ return -EOPNOTSUPP;
+
+ return ar->wmi.ops->get_legacy_rate(ar, sband, ratecode, rate, idx);
+}
#endif
diff --git a/drivers/net/wireless/ath/ath10k/wmi-tlv.c b/drivers/net/wireless/ath/ath10k/wmi-tlv.c
index ae12a58..8964fa8 100644
--- a/drivers/net/wireless/ath/ath10k/wmi-tlv.c
+++ b/drivers/net/wireless/ath/ath10k/wmi-tlv.c
@@ -4009,6 +4009,43 @@ ath10k_wmi_tlv_op_gen_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id,
return skb;
}

+static int
+ath10k_wmi_tlv_op_get_legacy_rate(struct ath10k *ar,
+ struct ieee80211_supported_band *sband,
+ u8 ratecode, u16 *rate, s8 *idx)
+{
+ u8 hw_rate = ATH10K_HW_LEGACY_RATE(ratecode);
+ u8 preamble = ATH10K_HW_PREAMBLE(ratecode);
+ int i;
+ const struct ieee80211_rate *bitrates;
+ bool cck;
+
+ if (!sband || !sband->bitrates || !rate || !idx)
+ return -EINVAL;
+
+ if (WARN_ON_ONCE(sband->n_bitrates > S8_MAX))
+ return -EINVAL;
+
+ cck = (preamble == WMI_RATE_PREAMBLE_CCK);
+ for (i = 0; i < sband->n_bitrates; i++) {
+ bitrates = &sband->bitrates[i];
+
+ if (ath10k_mac_bitrate_is_cck(bitrates->bitrate) != cck)
+ continue;
+
+ if (bitrates->hw_value == hw_rate ||
+ (bitrates->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
+ bitrates->hw_value_short == hw_rate)) {
+ *rate = bitrates->bitrate;
+ *idx = i;
+ return 0;
+ }
+ }
+
+ ath10k_warn(ar, "Invalid legacy ratecode %hhd peer stats", ratecode);
+ return -EINVAL;
+}
+
/****************/
/* TLV mappings */
/****************/
@@ -4445,6 +4482,7 @@ static const struct wmi_ops wmi_tlv_ops = {
.gen_echo = ath10k_wmi_tlv_op_gen_echo,
.gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
.gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
+ .get_legacy_rate = ath10k_wmi_tlv_op_get_legacy_rate,
};

static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index 9f564e2..304e09f 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -9016,6 +9016,47 @@ ath10k_wmi_10_2_4_op_gen_bb_timing(struct ath10k *ar,
return skb;
}

+static int
+ath10k_wmi_op_get_legacy_rate(struct ath10k *ar,
+ struct ieee80211_supported_band *sband,
+ u8 ratecode, u16 *rate, s8 *idx)
+{
+ u16 hw_rate = ATH10K_HW_LEGACY_RATE(ratecode);
+ u8 preamble = ATH10K_HW_PREAMBLE(ratecode);
+ int i;
+ const struct ieee80211_rate *bitrates;
+ bool cck;
+
+ if (!sband || !sband->bitrates || !rate || !idx)
+ return -EINVAL;
+
+ if (WARN_ON_ONCE(sband->n_bitrates > S8_MAX))
+ return -EINVAL;
+
+ cck = (preamble == WMI_RATE_PREAMBLE_CCK);
+
+ /* From Mbps to 100kbps */
+ hw_rate *= 10;
+
+ /* This is hacky, FW sends CCK rate 5.5Mbps as 6 */
+ if (cck && hw_rate == 60)
+ hw_rate = 55;
+
+ for (i = 0; i < sband->n_bitrates; i++) {
+ bitrates = &sband->bitrates[i];
+ if (ath10k_mac_bitrate_is_cck(bitrates->bitrate) != cck)
+ continue;
+
+ if (bitrates->bitrate == hw_rate) {
+ *rate = bitrates->bitrate;
+ *idx = i;
+ return 0;
+ }
+ }
+ ath10k_warn(ar, "Invalid legacy ratecode %hhd peer stats", ratecode);
+ return -EINVAL;
+}
+
static const struct wmi_ops wmi_ops = {
.rx = ath10k_wmi_op_rx,
.map_svc = wmi_main_svc_map,
@@ -9083,6 +9124,7 @@ static const struct wmi_ops wmi_ops = {
/* .gen_p2p_go_bcn_ie not implemented */
/* .gen_adaptive_qcs not implemented */
/* .gen_pdev_enable_adaptive_cca not implemented */
+ .get_legacy_rate = ath10k_wmi_op_get_legacy_rate,
};

static const struct wmi_ops wmi_10_1_ops = {
@@ -9153,6 +9195,7 @@ static const struct wmi_ops wmi_10_1_ops = {
/* .gen_p2p_go_bcn_ie not implemented */
/* .gen_adaptive_qcs not implemented */
/* .gen_pdev_enable_adaptive_cca not implemented */
+ .get_legacy_rate = ath10k_wmi_op_get_legacy_rate,
};

static const struct wmi_ops wmi_10_2_ops = {
@@ -9221,6 +9264,7 @@ static const struct wmi_ops wmi_10_2_ops = {
.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
/* .gen_pdev_enable_adaptive_cca not implemented */
+ .get_legacy_rate = ath10k_wmi_op_get_legacy_rate,
};

static const struct wmi_ops wmi_10_2_4_ops = {
@@ -9295,6 +9339,7 @@ static const struct wmi_ops wmi_10_2_4_ops = {
/* .gen_prb_tmpl not implemented */
/* .gen_p2p_go_bcn_ie not implemented */
/* .gen_adaptive_qcs not implemented */
+ .get_legacy_rate = ath10k_wmi_op_get_legacy_rate,
};

static const struct wmi_ops wmi_10_4_ops = {
@@ -9371,6 +9416,7 @@ static const struct wmi_ops wmi_10_4_ops = {
.gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
.gen_echo = ath10k_wmi_op_gen_echo,
.gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
+ .get_legacy_rate = ath10k_wmi_op_get_legacy_rate,
};

int ath10k_wmi_attach(struct ath10k *ar)
--
2.7.4

2019-11-12 18:15:25

by Peter Oh

[permalink] [raw]
Subject: Re: [PATCH 2/2] ath10k: correct legacy rate in tx stats


On 11/12/19 3:45 AM, Yu Wang wrote:
> When working in station mode, after connected to a legacy
> AP, 11g only, for example, the tx bitrate is incorrect in
> output of command 'iw wlan0 link'.
>
> That's because the legacy tx bitrate value reported by
> firmware is not well handled:
> For QCA6174, the value represents rate index, but treated
> as a real rate;
> For QCA9888, the value is real rate, with unit 'Mbps', but
> treated as '100kbps'.
>
> To fix this issue:
> 1. Translate the rate index to real rate for QCA6174;
> 2. Translate the rate from 'Mbps' to 'kbps' for QCA9888.
>
> Tested with:
> QCA6174 PCIe with firmware WLAN.RM.4.4.1.c3-00031.
> QCA6174 SDIO with firmware WLAN.RMH.4.4.1-00029.
> QCA9888 PCIe with firmware 10.4-3.9.0.2-00040.
>
> Signed-off-by: Yu Wang <[email protected]>
> ---
>
> diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
> @@ -3454,10 +3440,12 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
> {
> struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
> struct ieee80211_chanctx_conf *conf = NULL;
> - u8 rate = 0, sgi;
> - s8 rate_idx = 0;
> + u8 sgi;
> + s8 rate_idx = -1;
> bool skip_auto_rate;
> struct rate_info txrate;
> + enum nl80211_band band;
> + struct ieee80211_supported_band *sband;
>
> lockdep_assert_held(&ar->data_lock);
>
> @@ -3475,7 +3463,7 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
> return;
>
> if (txrate.flags == WMI_RATE_PREAMBLE_VHT && txrate.mcs > 9) {
> - ath10k_warn(ar, "Invalid VHT mcs %hhd peer stats", txrate.mcs);
> + ath10k_warn(ar, "Invalid VHT mcs %hhd peer stats", txrate.mcs);
> return;
> }
>
> @@ -3490,14 +3478,19 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
> memset(&arsta->tx_info.status, 0, sizeof(arsta->tx_info.status));
> if (txrate.flags == WMI_RATE_PREAMBLE_CCK ||
> txrate.flags == WMI_RATE_PREAMBLE_OFDM) {
> - rate = ATH10K_HW_LEGACY_RATE(peer_stats->ratecode);
> - /* This is hacky, FW sends CCK rate 5.5Mbps as 6 */
> - if (rate == 6 && txrate.flags == WMI_RATE_PREAMBLE_CCK)
> - rate = 5;
> - rate_idx = ath10k_get_legacy_rate_idx(ar, rate);
> - if (rate_idx < 0)
> + if (!arsta->arvif || !arsta->arvif->vif)
> + return;
> +
> + conf = rcu_dereference(arsta->arvif->vif->chanctx_conf);
> + if (!conf)
> + return;
> +
> + band = conf->def.chan->band;
> + sband = &ar->mac.sbands[band];
> + if (ath10k_wmi_get_legacy_rate(ar, sband, peer_stats->ratecode,
> + &arsta->txrate.legacy,
> + &rate_idx))

Using wmi ops to parse rate info breaks ath10k driver architecture,
since the rate info comes from htt layer and nothing related to wmi.


Thanks,

Peter