developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 1 | From ba04dd5323962bbed89405ceb8d7fd9c6796f09a 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 | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 2012/2014] 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 +++++++++++++++++++++ |
| 9 | mt7915/main.c | 2 +- |
| 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 | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 14 | 7 files changed, 78 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 | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 17 | index 16c3632..e5327be 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 | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 82 | index 199ce82..17a380b 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 83 | --- a/mt7915/main.c |
| 84 | +++ b/mt7915/main.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 85 | @@ -1245,7 +1245,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 86 | sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| 87 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| 88 | |
| 89 | - if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) { |
| 90 | + if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) { |
| 91 | sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| 92 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| 93 | } |
| 94 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 95 | index d9d4fea..f0273fe 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 96 | --- a/mt7915/mcu.c |
| 97 | +++ b/mt7915/mcu.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 98 | @@ -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] | 99 | &req, sizeof(req), true); |
| 100 | } |
| 101 | |
| 102 | -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
| 103 | +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx, |
| 104 | + struct mt7915_sta *sta) |
| 105 | { |
| 106 | struct { |
| 107 | __le32 cmd; |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 108 | @@ -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] | 109 | rcu_read_lock(); |
| 110 | |
| 111 | wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| 112 | - if (wcid) |
| 113 | + if (wcid) { |
| 114 | + struct ieee80211_vif *vif; |
| 115 | + struct wireless_dev *wdev; |
| 116 | + |
| 117 | wcid->stats.tx_packets += le32_to_cpu(res->tx_packets); |
| 118 | - else |
| 119 | + |
| 120 | + if (!wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 121 | + NL80211_EXT_FEATURE_STAS_COUNT) || |
| 122 | + !sta) |
| 123 | + goto unlock; |
| 124 | + |
| 125 | + vif = container_of((void *)sta->vif, |
| 126 | + struct ieee80211_vif, |
| 127 | + drv_priv); |
| 128 | + if (!vif) |
| 129 | + goto unlock; |
| 130 | + |
| 131 | + wdev = ieee80211_vif_to_wdev(vif); |
| 132 | + |
| 133 | + if (vif->type == NL80211_IFTYPE_MONITOR) |
| 134 | + goto unlock; |
| 135 | + |
| 136 | + dev_sw_netstats_tx_add(wdev->netdev, le32_to_cpu(res->tx_packets), 0); |
| 137 | + } else { |
| 138 | ret = -EINVAL; |
| 139 | + } |
| 140 | |
| 141 | +unlock: |
| 142 | rcu_read_unlock(); |
| 143 | out: |
| 144 | dev_kfree_skb(skb); |
| 145 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 146 | index 6309dd9..142f308 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 147 | --- a/mt7915/mmio.c |
| 148 | +++ b/mt7915/mmio.c |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 149 | @@ -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] | 150 | |
| 151 | dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 152 | |
| 153 | - if (idx >= mt7915_wtbl_size(dev)) |
| 154 | + if (idx <= 0 || idx >= mt7915_wtbl_size(dev)) |
| 155 | return; |
| 156 | |
| 157 | rcu_read_lock(); |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 158 | @@ -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] | 159 | wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt); |
| 160 | wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt); |
| 161 | wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt); |
| 162 | + |
| 163 | + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 164 | + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| 165 | + struct mt7915_sta *msta; |
| 166 | + struct ieee80211_vif *vif; |
| 167 | + struct wireless_dev *wdev; |
| 168 | + |
| 169 | + msta = container_of(wcid, struct mt7915_sta, wcid); |
| 170 | + |
| 171 | + vif = container_of((void *)msta->vif, |
| 172 | + struct ieee80211_vif, |
| 173 | + drv_priv); |
| 174 | + if (!vif) |
| 175 | + goto unlock; |
| 176 | + |
| 177 | + wdev = ieee80211_vif_to_wdev(vif); |
| 178 | + |
| 179 | + if (vif->type == NL80211_IFTYPE_MONITOR) |
| 180 | + goto unlock; |
| 181 | + |
| 182 | + dev_sw_netstats_rx_add(wdev->netdev, le32_to_cpu(stats->rx_pkt_cnt), |
| 183 | + le32_to_cpu(stats->rx_byte_cnt)); |
| 184 | + } |
| 185 | } |
| 186 | |
| 187 | +unlock: |
| 188 | rcu_read_unlock(); |
| 189 | } |
| 190 | |
| 191 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 192 | index c5bacf8..696b64e 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 193 | --- a/mt7915/mt7915.h |
| 194 | +++ b/mt7915/mt7915.h |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 195 | @@ -754,7 +754,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] | 196 | struct ieee80211_sta *sta, struct rate_info *rate); |
| 197 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 198 | struct cfg80211_chan_def *chandef); |
| 199 | -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid); |
| 200 | +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid, |
| 201 | + struct mt7915_sta *sta); |
| 202 | int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx); |
| 203 | int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| 204 | int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3); |
| 205 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame^] | 206 | index a80ddeb..129a4dd 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 207 | --- a/mt7915/mtk_debugfs.c |
| 208 | +++ b/mt7915/mtk_debugfs.c |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 209 | @@ -4034,7 +4034,7 @@ static int mt7915_reset_counter(void *data, u64 val) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 210 | struct mt76_wcid *wcid; |
| 211 | |
| 212 | /* Clear the firmware counters */ |
| 213 | - mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx); |
| 214 | + mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL); |
| 215 | mt7915_get_tx_stat(phy, dev->wlan_idx); |
| 216 | |
| 217 | rcu_read_lock(); |
| 218 | -- |
| 219 | 2.18.0 |
| 220 | |