developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 1 | From 4e0a12871b8c134c99bd702f425c492ddc1f50b6 Mon Sep 17 00:00:00 2001 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 2 | From: Evelyn Tsai <evelyn.tsai@mediatek.com> |
| 3 | Date: Wed, 1 Nov 2023 07:50:08 +0800 |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1/5] wifi: mt76: mt7915: wed: add per bss statistic info |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 5 | |
| 6 | --- |
| 7 | mt7915/init.c | 1 + |
| 8 | mt7915/mac.c | 21 +++++++++++++++++++++ |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 9 | mt7915/main.c | 5 ++++- |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 10 | mt7915/mcu.c | 30 +++++++++++++++++++++++++++--- |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 11 | mt7915/mmio.c | 26 +++++++++++++++++++++++++- |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 12 | mt7915/mt7915.h | 3 ++- |
| 13 | mt7915/mtk_debugfs.c | 2 +- |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 14 | 7 files changed, 81 insertions(+), 7 deletions(-) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 15 | |
| 16 | diff --git a/mt7915/init.c b/mt7915/init.c |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 17 | index f38c8a1..7bc8039 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 18 | --- a/mt7915/init.c |
| 19 | +++ b/mt7915/init.c |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 20 | @@ -400,6 +400,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 21 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY); |
| 22 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); |
| 23 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); |
| 24 | + wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STAS_COUNT); |
| 25 | |
| 26 | if (!is_mt7915(&dev->mt76)) |
| 27 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); |
| 28 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 29 | index 02f794d..0c12170 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 30 | --- a/mt7915/mac.c |
| 31 | +++ b/mt7915/mac.c |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 32 | @@ -1071,6 +1071,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 33 | struct mt7915_phy *phy; |
| 34 | struct mt76_wcid *wcid; |
| 35 | __le32 *txs_data = data; |
| 36 | + u64 last_bytes; |
| 37 | u16 wcidx; |
| 38 | u8 pid; |
| 39 | |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 40 | @@ -1089,6 +1090,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 41 | if (!wcid) |
| 42 | goto out; |
| 43 | |
| 44 | + last_bytes = wcid->stats.tx_bytes; |
| 45 | msta = container_of(wcid, struct mt7915_sta, wcid); |
| 46 | |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 47 | if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) == MT_TXS_PPDU_FMT) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 48 | @@ -1099,6 +1101,24 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 49 | if (!wcid->sta) |
| 50 | goto out; |
| 51 | |
| 52 | + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 53 | + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| 54 | + struct ieee80211_vif *vif; |
| 55 | + struct wireless_dev *wdev; |
| 56 | + |
| 57 | + vif = container_of((void *)msta->vif, struct ieee80211_vif, |
| 58 | + drv_priv); |
| 59 | + if (!vif) |
| 60 | + goto out; |
| 61 | + |
| 62 | + wdev = ieee80211_vif_to_wdev(vif); |
| 63 | + |
| 64 | + if (vif->type == NL80211_IFTYPE_MONITOR) |
| 65 | + goto out; |
| 66 | + |
| 67 | + dev_sw_netstats_tx_add(wdev->netdev, 0, (wcid->stats.tx_bytes - last_bytes)); |
| 68 | + } |
| 69 | + |
| 70 | spin_lock_bh(&dev->mt76.sta_poll_lock); |
| 71 | if (list_empty(&msta->wcid.poll_list)) |
| 72 | list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 73 | @@ -2043,6 +2063,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 74 | spin_unlock_bh(&phy->stats_lock); |
| 75 | |
| 76 | mt7915_mcu_get_tx_rate(phy, sta->wcid.idx); |
| 77 | + mt7915_mcu_wed_wa_tx_stats(phy->dev, sta->wcid.idx, sta); |
| 78 | |
| 79 | spin_lock_bh(&phy->stats_lock); |
| 80 | } |
| 81 | diff --git a/mt7915/main.c b/mt7915/main.c |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 82 | index feb2c89..722635e 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 83 | --- a/mt7915/main.c |
| 84 | +++ b/mt7915/main.c |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 85 | @@ -1219,6 +1219,9 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| 86 | struct rate_info *txrate = &msta->wcid.rate; |
| 87 | struct rate_info rxrate = {}; |
| 88 | |
| 89 | + if (msta->wcid.idx == 0) |
| 90 | + return; |
| 91 | + |
| 92 | if (is_connac_v2(&phy->dev->mt76) && |
| 93 | !mt7915_mcu_get_rx_rate(phy, vif, sta, &rxrate)) { |
| 94 | sinfo->rxrate = rxrate; |
| 95 | @@ -1247,7 +1250,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 96 | sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| 97 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| 98 | |
| 99 | - if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) { |
| 100 | + if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) { |
| 101 | sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| 102 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| 103 | } |
| 104 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 105 | index 708e7cd..342fe42 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 106 | --- a/mt7915/mcu.c |
| 107 | +++ b/mt7915/mcu.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 108 | @@ -4750,7 +4750,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev, |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 109 | &req, sizeof(req), true); |
| 110 | } |
| 111 | |
| 112 | -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
| 113 | +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx, |
| 114 | + struct mt7915_sta *sta) |
| 115 | { |
| 116 | struct { |
| 117 | __le32 cmd; |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 118 | @@ -4806,11 +4807,34 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 119 | rcu_read_lock(); |
| 120 | |
| 121 | wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| 122 | - if (wcid) |
| 123 | + if (wcid) { |
| 124 | + struct ieee80211_vif *vif; |
| 125 | + struct wireless_dev *wdev; |
| 126 | + |
| 127 | wcid->stats.tx_packets += le32_to_cpu(res->tx_packets); |
| 128 | - else |
| 129 | + |
| 130 | + if (!wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 131 | + NL80211_EXT_FEATURE_STAS_COUNT) || |
| 132 | + !sta) |
| 133 | + goto unlock; |
| 134 | + |
| 135 | + vif = container_of((void *)sta->vif, |
| 136 | + struct ieee80211_vif, |
| 137 | + drv_priv); |
| 138 | + if (!vif) |
| 139 | + goto unlock; |
| 140 | + |
| 141 | + wdev = ieee80211_vif_to_wdev(vif); |
| 142 | + |
| 143 | + if (vif->type == NL80211_IFTYPE_MONITOR) |
| 144 | + goto unlock; |
| 145 | + |
| 146 | + dev_sw_netstats_tx_add(wdev->netdev, le32_to_cpu(res->tx_packets), 0); |
| 147 | + } else { |
| 148 | ret = -EINVAL; |
| 149 | + } |
| 150 | |
| 151 | +unlock: |
| 152 | rcu_read_unlock(); |
| 153 | out: |
| 154 | dev_kfree_skb(skb); |
| 155 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 156 | index 6309dd9..142f308 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 157 | --- a/mt7915/mmio.c |
| 158 | +++ b/mt7915/mmio.c |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 159 | @@ -592,7 +592,7 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed, |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 160 | |
| 161 | dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 162 | |
| 163 | - if (idx >= mt7915_wtbl_size(dev)) |
| 164 | + if (idx <= 0 || idx >= mt7915_wtbl_size(dev)) |
| 165 | return; |
| 166 | |
| 167 | rcu_read_lock(); |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 168 | @@ -607,8 +607,32 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed, |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 169 | wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt); |
| 170 | wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt); |
| 171 | wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt); |
| 172 | + |
| 173 | + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 174 | + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| 175 | + struct mt7915_sta *msta; |
| 176 | + struct ieee80211_vif *vif; |
| 177 | + struct wireless_dev *wdev; |
| 178 | + |
| 179 | + msta = container_of(wcid, struct mt7915_sta, wcid); |
| 180 | + |
| 181 | + vif = container_of((void *)msta->vif, |
| 182 | + struct ieee80211_vif, |
| 183 | + drv_priv); |
| 184 | + if (!vif) |
| 185 | + goto unlock; |
| 186 | + |
| 187 | + wdev = ieee80211_vif_to_wdev(vif); |
| 188 | + |
| 189 | + if (vif->type == NL80211_IFTYPE_MONITOR) |
| 190 | + goto unlock; |
| 191 | + |
| 192 | + dev_sw_netstats_rx_add(wdev->netdev, le32_to_cpu(stats->rx_pkt_cnt), |
| 193 | + le32_to_cpu(stats->rx_byte_cnt)); |
| 194 | + } |
| 195 | } |
| 196 | |
| 197 | +unlock: |
| 198 | rcu_read_unlock(); |
| 199 | } |
| 200 | |
| 201 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 202 | index 945c82e..6e7ed9e 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 203 | --- a/mt7915/mt7915.h |
| 204 | +++ b/mt7915/mt7915.h |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 205 | @@ -756,7 +756,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 206 | struct ieee80211_sta *sta, struct rate_info *rate); |
| 207 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 208 | struct cfg80211_chan_def *chandef); |
| 209 | -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid); |
| 210 | +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid, |
| 211 | + struct mt7915_sta *sta); |
| 212 | int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx); |
| 213 | int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| 214 | int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3); |
| 215 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame] | 216 | index c63bf90..2c9f198 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 217 | --- a/mt7915/mtk_debugfs.c |
| 218 | +++ b/mt7915/mtk_debugfs.c |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 219 | @@ -4034,7 +4034,7 @@ static int mt7915_reset_counter(void *data, u64 val) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 220 | struct mt76_wcid *wcid; |
| 221 | |
| 222 | /* Clear the firmware counters */ |
| 223 | - mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx); |
| 224 | + mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL); |
| 225 | mt7915_get_tx_stat(phy, dev->wlan_idx); |
| 226 | |
| 227 | rcu_read_lock(); |
| 228 | -- |
| 229 | 2.18.0 |
| 230 | |