developer | 5eddc51 | 2023-02-13 16:01:56 +0800 | [diff] [blame] | 1 | From aecf943a183c8b1e0ea7d503e406b88ebed57d06 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 3 | Date: Wed, 18 Jan 2023 16:37:22 +0800 |
| 4 | Subject: [PATCH 3010/3015] wifi: mt76: mt7915: add wa command to get tx msdu |
| 5 | count |
| 6 | |
| 7 | --- |
| 8 | mt76.h | 2 +- |
| 9 | mt76_connac2_mac.h | 1 + |
| 10 | mt76_connac_mac.c | 9 ++++---- |
| 11 | mt76_connac_mcu.h | 1 + |
| 12 | mt7915/main.c | 8 ++++--- |
| 13 | mt7915/mcu.c | 56 +++++++++++++++++++++++++++++++++++++++++++--- |
| 14 | mt7915/mcu.h | 11 +++++++++ |
| 15 | mt7915/mt7915.h | 1 + |
| 16 | 8 files changed, 78 insertions(+), 11 deletions(-) |
| 17 | |
| 18 | diff --git a/mt76.h b/mt76.h |
| 19 | index a36a978b..0d1f3cbf 100644 |
| 20 | --- a/mt76.h |
| 21 | +++ b/mt76.h |
| 22 | @@ -285,7 +285,7 @@ struct mt76_sta_stats { |
| 23 | u64 tx_mcs[16]; /* mcs idx */ |
| 24 | u64 tx_bytes; |
| 25 | /* WED TX */ |
| 26 | - u32 tx_packets; |
| 27 | + u32 tx_packets; /* unit: MSDU */ |
| 28 | u32 tx_retries; |
| 29 | u32 tx_failed; |
| 30 | /* WED RX */ |
| 31 | diff --git a/mt76_connac2_mac.h b/mt76_connac2_mac.h |
| 32 | index f33171bc..101e7602 100644 |
| 33 | --- a/mt76_connac2_mac.h |
| 34 | +++ b/mt76_connac2_mac.h |
| 35 | @@ -164,6 +164,7 @@ enum { |
| 36 | |
| 37 | #define MT_TXS6_MPDU_FAIL_CNT GENMASK(31, 23) |
| 38 | |
| 39 | +#define MT_TXS7_MPDU_RETRY_BYTE GENMASK(22, 0) |
| 40 | #define MT_TXS7_MPDU_RETRY_CNT GENMASK(31, 23) |
| 41 | |
| 42 | /* RXD DW1 */ |
| 43 | diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c |
| 44 | index 614df85e..57e02aec 100644 |
| 45 | --- a/mt76_connac_mac.c |
| 46 | +++ b/mt76_connac_mac.c |
| 47 | @@ -491,7 +491,9 @@ void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi, |
| 48 | |
| 49 | /* counting non-offloading skbs */ |
| 50 | wcid->stats.tx_bytes += skb->len; |
| 51 | - wcid->stats.tx_packets++; |
| 52 | + |
| 53 | + if (is_mt7915(dev)) |
| 54 | + wcid->stats.tx_packets++; |
| 55 | } |
| 56 | |
| 57 | val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) | |
| 58 | @@ -575,9 +577,8 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid, |
| 59 | /* PPDU based reporting */ |
| 60 | if (FIELD_GET(MT_TXS0_TXS_FORMAT, txs) > 1) { |
| 61 | stats->tx_bytes += |
| 62 | - le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE); |
| 63 | - stats->tx_packets += |
| 64 | - le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_CNT); |
| 65 | + le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) - |
| 66 | + le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE); |
| 67 | stats->tx_failed += |
| 68 | le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT); |
| 69 | stats->tx_retries += |
| 70 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
| 71 | index 130a8d25..34df625a 100644 |
| 72 | --- a/mt76_connac_mcu.h |
| 73 | +++ b/mt76_connac_mcu.h |
| 74 | @@ -1003,6 +1003,7 @@ enum { |
| 75 | MCU_EXT_EVENT_BF_STATUS_READ = 0x35, |
| 76 | MCU_EXT_EVENT_RDD_REPORT = 0x3a, |
| 77 | MCU_EXT_EVENT_CSA_NOTIFY = 0x4f, |
| 78 | + MCU_EXT_EVENT_WA_TX_STAT = 0x74, |
| 79 | MCU_EXT_EVENT_BCC_NOTIFY = 0x75, |
| 80 | MCU_EXT_EVENT_MURU_CTRL = 0x9f, |
| 81 | MCU_EXT_EVENT_CSI_REPORT = 0xc2, |
| 82 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 83 | index 8ebea612..dca93cd8 100644 |
| 84 | --- a/mt7915/main.c |
| 85 | +++ b/mt7915/main.c |
| 86 | @@ -1103,9 +1103,6 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| 87 | sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| 88 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| 89 | |
| 90 | - sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| 91 | - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| 92 | - |
| 93 | sinfo->tx_failed = msta->wcid.stats.tx_failed; |
| 94 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
| 95 | |
| 96 | @@ -1121,6 +1118,11 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | + if (!mt7915_mcu_get_tx_stat_wa(phy->dev, msta->wcid.idx)) { |
| 101 | + sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| 102 | + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| 103 | + } |
| 104 | + |
| 105 | sinfo->ack_signal = (s8)msta->ack_signal; |
| 106 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL); |
| 107 | |
| 108 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| 109 | index b5a0967b..07681902 100644 |
| 110 | --- a/mt7915/mcu.c |
| 111 | +++ b/mt7915/mcu.c |
| 112 | @@ -168,7 +168,9 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd, |
| 113 | } |
| 114 | |
| 115 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 116 | - if (seq != rxd->seq) |
| 117 | + |
| 118 | + if (seq != rxd->seq && |
| 119 | + !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT)) |
| 120 | return -EAGAIN; |
| 121 | |
| 122 | if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) { |
| 123 | @@ -420,13 +422,14 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| 124 | struct mt76_connac2_mcu_rxd *rxd; |
| 125 | |
| 126 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 127 | - if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT || |
| 128 | + if ((rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT || |
| 129 | rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST || |
| 130 | rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP || |
| 131 | rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC || |
| 132 | rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY || |
| 133 | rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ || |
| 134 | - !rxd->seq) |
| 135 | + !rxd->seq) && |
| 136 | + !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT)) |
| 137 | mt7915_mcu_rx_unsolicited_event(dev, skb); |
| 138 | else |
| 139 | mt76_mcu_rx_event(&dev->mt76, skb); |
| 140 | @@ -4086,6 +4089,53 @@ out: |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | +int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wlan_idx) |
| 145 | +{ |
| 146 | + struct { |
| 147 | + __le32 cmd; |
| 148 | + __le32 num; |
| 149 | + __le32 __rsv; |
| 150 | + __le16 wlan_idx; |
| 151 | + } req = { |
| 152 | + .cmd = cpu_to_le32(MCU_WA_QUERY_GET_TX_STAT), |
| 153 | + .num = cpu_to_le32(1), |
| 154 | + .wlan_idx = cpu_to_le16(wlan_idx), |
| 155 | + }; |
| 156 | + struct mt7915_mcu_wa_tx_stat *res; |
| 157 | + struct mt76_wcid *wcid; |
| 158 | + struct sk_buff *skb; |
| 159 | + int ret; |
| 160 | + |
| 161 | + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY), |
| 162 | + &req, sizeof(req), true, &skb); |
| 163 | + if (ret) |
| 164 | + return ret; |
| 165 | + |
| 166 | + if (!is_mt7915(&dev->mt76)) |
| 167 | + skb_pull(skb, 4); |
| 168 | + |
| 169 | + res = (struct mt7915_mcu_wa_tx_stat *)skb->data; |
| 170 | + |
| 171 | + if (le16_to_cpu(res->wlan_idx) != wlan_idx) { |
| 172 | + ret = -EINVAL; |
| 173 | + goto out; |
| 174 | + } |
| 175 | + |
| 176 | + rcu_read_lock(); |
| 177 | + |
| 178 | + wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| 179 | + if (wcid) |
| 180 | + wcid->stats.tx_packets += le32_to_cpu(res->tx_msdu_cnt); |
| 181 | + else |
| 182 | + ret = -EINVAL; |
| 183 | + |
| 184 | + rcu_read_unlock(); |
| 185 | +out: |
| 186 | + dev_kfree_skb(skb); |
| 187 | + |
| 188 | + return ret; |
| 189 | +} |
| 190 | + |
| 191 | int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 192 | struct cfg80211_he_bss_color *he_bss_color) |
| 193 | { |
| 194 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
| 195 | index 24d0efd3..5f6c7c80 100644 |
| 196 | --- a/mt7915/mcu.h |
| 197 | +++ b/mt7915/mcu.h |
| 198 | @@ -292,6 +292,17 @@ enum { |
| 199 | MCU_WA_PARAM_RED_SETTING = 0x40, |
| 200 | }; |
| 201 | |
| 202 | +enum { |
| 203 | + MCU_WA_QUERY_GET_TX_STAT = 0x15, |
| 204 | +}; |
| 205 | + |
| 206 | +struct mt7915_mcu_wa_tx_stat { |
| 207 | + __le16 wlan_idx; |
| 208 | + u8 __rsv2[2]; |
| 209 | + __le32 tx_bytes; |
| 210 | + __le32 tx_msdu_cnt; |
| 211 | +}; |
| 212 | + |
| 213 | enum mcu_mmps_mode { |
| 214 | MCU_MMPS_STATIC, |
| 215 | MCU_MMPS_DYNAMIC, |
| 216 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 217 | index 594dfcd5..d76ca390 100644 |
| 218 | --- a/mt7915/mt7915.h |
| 219 | +++ b/mt7915/mt7915.h |
| 220 | @@ -712,6 +712,7 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state); |
| 221 | int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy); |
| 222 | int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 223 | struct ieee80211_sta *sta, struct rate_info *rate); |
| 224 | +int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wcid); |
| 225 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 226 | struct cfg80211_chan_def *chandef); |
| 227 | int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| 228 | -- |
| 229 | 2.18.0 |
| 230 | |