developer | 5eddc51 | 2023-02-13 16:01:56 +0800 | [diff] [blame] | 1 | From 08fd3173f9a7e7b7ae1112f43358068ea83faa56 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| 3 | Date: Wed, 11 Jan 2023 10:56:27 +0800 |
| 4 | Subject: [PATCH 3011/3015] wifi: mt76: get tx count and tx failed from mcu |
| 5 | command |
| 6 | |
| 7 | --- |
| 8 | mt76.h | 1 + |
| 9 | mt76_connac_mac.c | 2 - |
| 10 | mt76_connac_mcu.h | 1 + |
| 11 | mt7915/main.c | 8 ++-- |
| 12 | mt7915/mcu.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++ |
| 13 | mt7915/mcu.h | 22 ++++++++++ |
| 14 | mt7915/mt7915.h | 1 + |
| 15 | 7 files changed, 138 insertions(+), 5 deletions(-) |
| 16 | |
| 17 | diff --git a/mt76.h b/mt76.h |
| 18 | index 0d1f3cbf..22c6531a 100644 |
| 19 | --- a/mt76.h |
| 20 | +++ b/mt76.h |
| 21 | @@ -286,6 +286,7 @@ struct mt76_sta_stats { |
| 22 | u64 tx_bytes; |
| 23 | /* WED TX */ |
| 24 | u32 tx_packets; /* unit: MSDU */ |
| 25 | + u32 tx_mpdu_cnt; |
| 26 | u32 tx_retries; |
| 27 | u32 tx_failed; |
| 28 | /* WED RX */ |
| 29 | diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c |
| 30 | index 57e02aec..05a7a215 100644 |
| 31 | --- a/mt76_connac_mac.c |
| 32 | +++ b/mt76_connac_mac.c |
| 33 | @@ -579,8 +579,6 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid, |
| 34 | stats->tx_bytes += |
| 35 | le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) - |
| 36 | le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE); |
| 37 | - stats->tx_failed += |
| 38 | - le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT); |
| 39 | stats->tx_retries += |
| 40 | le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_CNT); |
| 41 | } |
| 42 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
| 43 | index 34df625a..747ae7e9 100644 |
| 44 | --- a/mt76_connac_mcu.h |
| 45 | +++ b/mt76_connac_mcu.h |
| 46 | @@ -1163,6 +1163,7 @@ enum { |
| 47 | MCU_EXT_CMD_EDCA_UPDATE = 0x27, |
| 48 | MCU_EXT_CMD_DEV_INFO_UPDATE = 0x2A, |
| 49 | MCU_EXT_CMD_THERMAL_CTRL = 0x2c, |
| 50 | + MCU_EXT_CMD_GET_TX_STAT = 0x30, |
| 51 | MCU_EXT_CMD_WTBL_UPDATE = 0x32, |
| 52 | MCU_EXT_CMD_SET_DRR_CTRL = 0x36, |
| 53 | MCU_EXT_CMD_SET_FEATURE_CTRL = 0x38, |
| 54 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 55 | index dca93cd8..51129341 100644 |
| 56 | --- a/mt7915/main.c |
| 57 | +++ b/mt7915/main.c |
| 58 | @@ -1103,9 +1103,6 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| 59 | sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| 60 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| 61 | |
| 62 | - sinfo->tx_failed = msta->wcid.stats.tx_failed; |
| 63 | - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
| 64 | - |
| 65 | sinfo->tx_retries = msta->wcid.stats.tx_retries; |
| 66 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES); |
| 67 | |
| 68 | @@ -1123,6 +1120,11 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| 69 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| 70 | } |
| 71 | |
| 72 | + if (!mt7915_get_tx_stat(phy, msta->wcid.idx)) { |
| 73 | + sinfo->tx_failed = msta->wcid.stats.tx_failed; |
| 74 | + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
| 75 | + } |
| 76 | + |
| 77 | sinfo->ack_signal = (s8)msta->ack_signal; |
| 78 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL); |
| 79 | |
| 80 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| 81 | index 07681902..e9856c1b 100644 |
| 82 | --- a/mt7915/mcu.c |
| 83 | +++ b/mt7915/mcu.c |
| 84 | @@ -4136,6 +4136,114 @@ out: |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | +static int mt7915_mcu_get_tx_stat_v1(struct mt7915_phy *phy, |
| 89 | + u16 wlan_idx) |
| 90 | +{ |
| 91 | +#define to_wcid(hi, lo) (hi << 8 | lo) |
| 92 | + struct mt7915_dev *dev = phy->dev; |
| 93 | + struct mt76_phy *mphy = phy->mt76; |
| 94 | + struct mt7915_mcu_tx_stat_v1 *res; |
| 95 | + struct mt76_wcid *wcid; |
| 96 | + struct sk_buff *skb; |
| 97 | + struct { |
| 98 | + __le32 category; |
| 99 | + u8 wlan_idx_lo; |
| 100 | + u8 band; |
| 101 | + u8 wlan_idx_hi; |
| 102 | + u8 __rsv[5]; |
| 103 | + } __packed req = { |
| 104 | + .category = cpu_to_le32(MCU_GET_TX_STAT_CNT), |
| 105 | + .band = mphy->band_idx, |
| 106 | + .wlan_idx_lo = to_wcid_lo(wlan_idx), |
| 107 | + .wlan_idx_hi = to_wcid_hi(wlan_idx), |
| 108 | + }; |
| 109 | + int ret; |
| 110 | + |
| 111 | + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT), |
| 112 | + &req, sizeof(req), true, &skb); |
| 113 | + if (ret) |
| 114 | + return ret; |
| 115 | + |
| 116 | + res = (struct mt7915_mcu_tx_stat_v1 *)skb->data; |
| 117 | + |
| 118 | + if (to_wcid(res->wlan_idx_hi, res->wlan_idx_lo) != wlan_idx) { |
| 119 | + ret = -EINVAL; |
| 120 | + goto out; |
| 121 | + } |
| 122 | + |
| 123 | + rcu_read_lock(); |
| 124 | + |
| 125 | + wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| 126 | + if (wcid) { |
| 127 | + wcid->stats.tx_mpdu_cnt += le32_to_cpu(res->tx_cnt); |
| 128 | + wcid->stats.tx_failed += le32_to_cpu(res->tx_failed); |
| 129 | + } else { |
| 130 | + ret = -EINVAL; |
| 131 | + } |
| 132 | + |
| 133 | + rcu_read_unlock(); |
| 134 | +out: |
| 135 | + dev_kfree_skb(skb); |
| 136 | + |
| 137 | + return ret; |
| 138 | +} |
| 139 | + |
| 140 | +static int mt7915_mcu_get_tx_stat_v2(struct mt7915_phy *phy, |
| 141 | + u16 wlan_idx) |
| 142 | +{ |
| 143 | + struct mt7915_dev *dev = phy->dev; |
| 144 | + struct mt76_phy *mphy = phy->mt76; |
| 145 | + struct mt7915_mcu_tx_stat_v2 *res; |
| 146 | + struct mt76_wcid *wcid; |
| 147 | + struct sk_buff *skb; |
| 148 | + struct { |
| 149 | + u8 category; |
| 150 | + u8 band; |
| 151 | + __le16 wcid; |
| 152 | + } __packed req = { |
| 153 | + .category = MCU_GET_TX_STAT_CNT, |
| 154 | + .band = mphy->band_idx, |
| 155 | + .wcid = cpu_to_le16(wlan_idx), |
| 156 | + }; |
| 157 | + int ret; |
| 158 | + |
| 159 | + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT), |
| 160 | + &req, sizeof(req), true, &skb); |
| 161 | + if (ret) |
| 162 | + return ret; |
| 163 | + |
| 164 | + res = (struct mt7915_mcu_tx_stat_v2 *)skb->data; |
| 165 | + |
| 166 | + if (le16_to_cpu(res->wlan_idx) != wlan_idx) { |
| 167 | + ret = -EINVAL; |
| 168 | + goto out; |
| 169 | + } |
| 170 | + |
| 171 | + rcu_read_lock(); |
| 172 | + |
| 173 | + wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| 174 | + if (wcid) { |
| 175 | + wcid->stats.tx_mpdu_cnt += le32_to_cpu(res->tx_cnt); |
| 176 | + wcid->stats.tx_failed += le32_to_cpu(res->tx_failed); |
| 177 | + } else { |
| 178 | + ret = -EINVAL; |
| 179 | + } |
| 180 | + |
| 181 | + rcu_read_unlock(); |
| 182 | +out: |
| 183 | + dev_kfree_skb(skb); |
| 184 | + |
| 185 | + return ret; |
| 186 | +} |
| 187 | + |
| 188 | +int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx) |
| 189 | +{ |
| 190 | + if (is_mt7915(&phy->dev->mt76)) |
| 191 | + return mt7915_mcu_get_tx_stat_v1(phy, wlan_idx); |
| 192 | + |
| 193 | + return mt7915_mcu_get_tx_stat_v2(phy, wlan_idx); |
| 194 | +} |
| 195 | + |
| 196 | int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 197 | struct cfg80211_he_bss_color *he_bss_color) |
| 198 | { |
| 199 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
| 200 | index 5f6c7c80..7b611fb7 100644 |
| 201 | --- a/mt7915/mcu.h |
| 202 | +++ b/mt7915/mcu.h |
| 203 | @@ -1018,6 +1018,28 @@ struct mt7915_muru { |
| 204 | /* DL&UL User config */ |
| 205 | #define MURU_USER_CNT BIT(4) |
| 206 | |
| 207 | +struct mt7915_mcu_tx_stat_v1 { |
| 208 | + u8 wlan_idx_lo; |
| 209 | + u8 band_idx; |
| 210 | + u8 wlan_idx_hi; |
| 211 | + u8 __rsv1[29]; |
| 212 | + __le32 tx_cnt; |
| 213 | + __le32 tx_failed; |
| 214 | + u8 __rsv2[26]; |
| 215 | +}; |
| 216 | + |
| 217 | +struct mt7915_mcu_tx_stat_v2 { |
| 218 | + u8 __rsv1[4]; |
| 219 | + __le16 wlan_idx; |
| 220 | + u8 __rsv2[2]; |
| 221 | + __le32 tx_cnt; |
| 222 | + __le32 tx_failed; |
| 223 | +}; |
| 224 | + |
| 225 | +enum { |
| 226 | + MCU_GET_TX_STAT_CNT = 8, |
| 227 | +}; |
| 228 | + |
| 229 | enum { |
| 230 | CAPI_SU, |
| 231 | CAPI_MU, |
| 232 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 233 | index d76ca390..ac019270 100644 |
| 234 | --- a/mt7915/mt7915.h |
| 235 | +++ b/mt7915/mt7915.h |
| 236 | @@ -713,6 +713,7 @@ int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy); |
| 237 | int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 238 | struct ieee80211_sta *sta, struct rate_info *rate); |
| 239 | int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wcid); |
| 240 | +int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx); |
| 241 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 242 | struct cfg80211_chan_def *chandef); |
| 243 | int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| 244 | -- |
| 245 | 2.18.0 |
| 246 | |