| From 13f5dc38354525add94b7c60ee289fd011ae5dbc Mon Sep 17 00:00:00 2001 |
| From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| Date: Wed, 18 Jan 2023 16:37:22 +0800 |
| Subject: [PATCH 3006/3012] wifi: mt76: mt7915: add wa command to get tx msdu |
| count |
| |
| --- |
| mt76.h | 2 +- |
| mt76_connac2_mac.h | 1 + |
| mt76_connac_mac.c | 9 +++---- |
| mt76_connac_mcu.h | 1 + |
| mt7915/main.c | 8 ++++--- |
| mt7915/mcu.c | 58 ++++++++++++++++++++++++++++++++++++++++++---- |
| mt7915/mcu.h | 11 +++++++++ |
| mt7915/mt7915.h | 1 + |
| 8 files changed, 79 insertions(+), 12 deletions(-) |
| |
| diff --git a/mt76.h b/mt76.h |
| index b178b95..4794b6a 100644 |
| --- a/mt76.h |
| +++ b/mt76.h |
| @@ -288,7 +288,7 @@ struct mt76_sta_stats { |
| u64 tx_mcs[16]; /* mcs idx */ |
| u64 tx_bytes; |
| /* WED TX */ |
| - u32 tx_packets; |
| + u32 tx_packets; /* unit: MSDU */ |
| u32 tx_retries; |
| u32 tx_failed; |
| /* WED RX */ |
| diff --git a/mt76_connac2_mac.h b/mt76_connac2_mac.h |
| index a5ec0f6..e7a4019 100644 |
| --- a/mt76_connac2_mac.h |
| +++ b/mt76_connac2_mac.h |
| @@ -174,6 +174,7 @@ enum { |
| |
| #define MT_TXS6_MPDU_FAIL_CNT GENMASK(31, 23) |
| |
| +#define MT_TXS7_MPDU_RETRY_BYTE GENMASK(22, 0) |
| #define MT_TXS7_MPDU_RETRY_CNT GENMASK(31, 23) |
| |
| /* RXD DW0 */ |
| diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c |
| index ee0fbfc..ee37fe5 100644 |
| --- a/mt76_connac_mac.c |
| +++ b/mt76_connac_mac.c |
| @@ -523,7 +523,9 @@ void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi, |
| |
| /* counting non-offloading skbs */ |
| wcid->stats.tx_bytes += skb->len; |
| - wcid->stats.tx_packets++; |
| + |
| + if (is_mt7915(dev)) |
| + wcid->stats.tx_packets++; |
| } |
| |
| val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) | |
| @@ -608,9 +610,8 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid, |
| /* PPDU based reporting */ |
| if (FIELD_GET(MT_TXS0_TXS_FORMAT, txs) > 1) { |
| stats->tx_bytes += |
| - le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE); |
| - stats->tx_packets += |
| - le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_CNT); |
| + le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) - |
| + le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE); |
| stats->tx_failed += |
| le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT); |
| stats->tx_retries += |
| diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
| index fd5aecb..97d732a 100644 |
| --- a/mt76_connac_mcu.h |
| +++ b/mt76_connac_mcu.h |
| @@ -1000,6 +1000,7 @@ enum { |
| MCU_EXT_EVENT_BF_STATUS_READ = 0x35, |
| MCU_EXT_EVENT_RDD_REPORT = 0x3a, |
| MCU_EXT_EVENT_CSA_NOTIFY = 0x4f, |
| + MCU_EXT_EVENT_WA_TX_STAT = 0x74, |
| MCU_EXT_EVENT_BCC_NOTIFY = 0x75, |
| MCU_EXT_EVENT_MURU_CTRL = 0x9f, |
| MCU_EXT_EVENT_CSI_REPORT = 0xc2, |
| diff --git a/mt7915/main.c b/mt7915/main.c |
| index 2ba36da..ccdb148 100644 |
| --- a/mt7915/main.c |
| +++ b/mt7915/main.c |
| @@ -1116,9 +1116,6 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| |
| - sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| - |
| sinfo->tx_failed = msta->wcid.stats.tx_failed; |
| sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
| |
| @@ -1134,6 +1131,11 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| } |
| } |
| |
| + if (!mt7915_mcu_get_tx_stat_wa(phy->dev, msta->wcid.idx)) { |
| + sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| + } |
| + |
| sinfo->ack_signal = (s8)msta->ack_signal; |
| sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL); |
| |
| diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| index 3b0ba5c..c27b8f9 100644 |
| --- a/mt7915/mcu.c |
| +++ b/mt7915/mcu.c |
| @@ -172,7 +172,9 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd, |
| } |
| |
| rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| - if (seq != rxd->seq) |
| + |
| + if (seq != rxd->seq && |
| + !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT)) |
| return -EAGAIN; |
| |
| if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) { |
| @@ -424,13 +426,14 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| struct mt76_connac2_mcu_rxd *rxd; |
| |
| rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| - if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT || |
| + if ((rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT || |
| rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST || |
| rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP || |
| rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC || |
| rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY || |
| rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ || |
| - !rxd->seq) |
| + !rxd->seq) && |
| + !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT)) |
| mt7915_mcu_rx_unsolicited_event(dev, skb); |
| else |
| mt76_mcu_rx_event(&dev->mt76, skb); |
| @@ -4139,7 +4142,7 @@ int mt7915_mcu_get_tx_rate_v2(struct mt7915_phy *phy, u16 wcidx) |
| }; |
| |
| ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT), |
| - &req, sizeof(req), true, &skb); |
| + &req, sizeof(req), true, &skb); |
| if (ret) |
| return ret; |
| |
| @@ -4174,6 +4177,53 @@ int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx) |
| return mt7915_mcu_get_tx_rate_v2(phy, wcidx); |
| } |
| |
| +int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wlan_idx) |
| +{ |
| + struct { |
| + __le32 cmd; |
| + __le32 num; |
| + __le32 __rsv; |
| + __le16 wlan_idx; |
| + } req = { |
| + .cmd = cpu_to_le32(MCU_WA_QUERY_GET_TX_STAT), |
| + .num = cpu_to_le32(1), |
| + .wlan_idx = cpu_to_le16(wlan_idx), |
| + }; |
| + struct mt7915_mcu_wa_tx_stat *res; |
| + struct mt76_wcid *wcid; |
| + struct sk_buff *skb; |
| + int ret; |
| + |
| + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY), |
| + &req, sizeof(req), true, &skb); |
| + if (ret) |
| + return ret; |
| + |
| + if (!is_mt7915(&dev->mt76)) |
| + skb_pull(skb, 4); |
| + |
| + res = (struct mt7915_mcu_wa_tx_stat *)skb->data; |
| + |
| + if (le16_to_cpu(res->wlan_idx) != wlan_idx) { |
| + ret = -EINVAL; |
| + goto out; |
| + } |
| + |
| + rcu_read_lock(); |
| + |
| + wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| + if (wcid) |
| + wcid->stats.tx_packets += le32_to_cpu(res->tx_msdu_cnt); |
| + else |
| + ret = -EINVAL; |
| + |
| + rcu_read_unlock(); |
| +out: |
| + dev_kfree_skb(skb); |
| + |
| + return ret; |
| +} |
| + |
| int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| struct cfg80211_he_bss_color *he_bss_color) |
| { |
| diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
| index c533a7d..eca028b 100644 |
| --- a/mt7915/mcu.h |
| +++ b/mt7915/mcu.h |
| @@ -347,6 +347,17 @@ enum { |
| MCU_WA_PARAM_RED_SETTING = 0x40, |
| }; |
| |
| +enum { |
| + MCU_WA_QUERY_GET_TX_STAT = 0x15, |
| +}; |
| + |
| +struct mt7915_mcu_wa_tx_stat { |
| + __le16 wlan_idx; |
| + u8 __rsv2[2]; |
| + __le32 tx_bytes; |
| + __le32 tx_msdu_cnt; |
| +}; |
| + |
| enum mcu_mmps_mode { |
| MCU_MMPS_STATIC, |
| MCU_MMPS_DYNAMIC, |
| diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| index 646f3e8..ef9b0e1 100644 |
| --- a/mt7915/mt7915.h |
| +++ b/mt7915/mt7915.h |
| @@ -714,6 +714,7 @@ int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy); |
| int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx); |
| int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| struct ieee80211_sta *sta, struct rate_info *rate); |
| +int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wcid); |
| int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| struct cfg80211_chan_def *chandef); |
| int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| -- |
| 2.18.0 |
| |