developer | 12a4279 | 2023-07-29 05:30:55 +0800 | [diff] [blame^] | 1 | From bb02860dfac990696f157984a8c09b6859770bba Mon Sep 17 00:00:00 2001 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 2 | From: "sujuan.chen" <sujuan.chen@mediatek.com> |
| 3 | Date: Wed, 28 Jun 2023 17:11:18 +0800 |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 4 | Subject: [PATCH 2009/2009] wifi: mt76: mt7915: wed: add per bss statistic info |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: sujuan.chen <sujuan.chen@mediatek.com> |
| 7 | --- |
| 8 | mt7915/init.c | 1 + |
| 9 | mt7915/mac.c | 19 +++++++++++++++++++ |
| 10 | mt7915/main.c | 2 +- |
| 11 | mt7915/mcu.c | 29 ++++++++++++++++++++++++++--- |
| 12 | mt7915/mmio.c | 26 ++++++++++++++++++++++++++ |
| 13 | mt7915/mt7915.h | 3 ++- |
| 14 | mt7915/mtk_debugfs.c | 2 +- |
| 15 | 7 files changed, 76 insertions(+), 6 deletions(-) |
| 16 | |
| 17 | diff --git a/mt7915/init.c b/mt7915/init.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 18 | index d8df8ba..b519c04 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 19 | --- a/mt7915/init.c |
| 20 | +++ b/mt7915/init.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 21 | @@ -374,6 +374,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy) |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 22 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY); |
| 23 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); |
| 24 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); |
| 25 | + wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STAS_COUNT); |
| 26 | |
| 27 | if (!is_mt7915(&dev->mt76)) |
| 28 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); |
| 29 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 30 | index a0d1f89..76239a1 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 31 | --- a/mt7915/mac.c |
| 32 | +++ b/mt7915/mac.c |
| 33 | @@ -1048,6 +1048,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
| 34 | struct mt7915_phy *phy; |
| 35 | struct mt76_wcid *wcid; |
| 36 | __le32 *txs_data = data; |
| 37 | + u64 last_bytes; |
| 38 | u16 wcidx; |
| 39 | u8 pid; |
| 40 | |
| 41 | @@ -1066,6 +1067,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
| 42 | if (!wcid) |
| 43 | goto out; |
| 44 | |
| 45 | + last_bytes = wcid->stats.tx_bytes; |
| 46 | msta = container_of(wcid, struct mt7915_sta, wcid); |
| 47 | |
| 48 | if (pid == MT_PACKET_ID_WED) |
| 49 | @@ -1076,6 +1078,22 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
| 50 | if (!wcid->sta) |
| 51 | goto out; |
| 52 | |
| 53 | + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 54 | + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| 55 | + struct ieee80211_vif *vif; |
| 56 | + struct wireless_dev *wdev; |
| 57 | + struct pcpu_sw_netstats *tstats; |
| 58 | + |
| 59 | + vif = container_of((void *)msta->vif, struct ieee80211_vif, |
| 60 | + drv_priv); |
| 61 | + if (!vif) |
| 62 | + goto out; |
| 63 | + |
| 64 | + wdev = ieee80211_vif_to_wdev(vif); |
| 65 | + tstats = this_cpu_ptr(wdev->netdev->tstats); |
| 66 | + |
| 67 | + tstats->tx_bytes += wcid->stats.tx_bytes - last_bytes; |
| 68 | + } |
| 69 | spin_lock_bh(&dev->mt76.sta_poll_lock); |
| 70 | if (list_empty(&msta->wcid.poll_list)) |
| 71 | list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); |
| 72 | @@ -2053,6 +2071,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy) |
| 73 | spin_unlock_bh(&phy->stats_lock); |
| 74 | |
| 75 | mt7915_mcu_get_tx_rate(phy, sta->wcid.idx); |
| 76 | + mt7915_mcu_wed_wa_tx_stats(phy->dev, sta->wcid.idx, sta); |
| 77 | |
| 78 | spin_lock_bh(&phy->stats_lock); |
| 79 | } |
| 80 | diff --git a/mt7915/main.c b/mt7915/main.c |
developer | 12a4279 | 2023-07-29 05:30:55 +0800 | [diff] [blame^] | 81 | index 1a7bcc5..61609f2 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 82 | --- a/mt7915/main.c |
| 83 | +++ b/mt7915/main.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 84 | @@ -1172,7 +1172,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 85 | sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| 86 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| 87 | |
| 88 | - if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) { |
| 89 | + if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) { |
| 90 | sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| 91 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| 92 | } |
| 93 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 94 | index a422567..6f93b3b 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 95 | --- a/mt7915/mcu.c |
| 96 | +++ b/mt7915/mcu.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 97 | @@ -4408,7 +4408,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev, |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 98 | &req, sizeof(req), true); |
| 99 | } |
| 100 | |
| 101 | -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
| 102 | +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx, |
| 103 | + struct mt7915_sta *sta) |
| 104 | { |
| 105 | struct { |
| 106 | __le32 cmd; |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 107 | @@ -4452,11 +4453,33 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 108 | rcu_read_lock(); |
| 109 | |
| 110 | wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| 111 | - if (wcid) |
| 112 | + if (wcid) { |
| 113 | + struct ieee80211_vif *vif; |
| 114 | + struct wireless_dev *wdev; |
| 115 | + struct pcpu_sw_netstats *tstats; |
| 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 | + tstats = this_cpu_ptr(wdev->netdev->tstats); |
| 134 | + tstats->tx_packets += le32_to_cpu(res->tx_packets); |
| 135 | + } else { |
| 136 | ret = -EINVAL; |
| 137 | + } |
| 138 | |
| 139 | +unlock: |
| 140 | rcu_read_unlock(); |
| 141 | out: |
| 142 | dev_kfree_skb(skb); |
| 143 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 144 | index 89523a5..00c190c 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 145 | --- a/mt7915/mmio.c |
| 146 | +++ b/mt7915/mmio.c |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 147 | @@ -704,8 +704,34 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed, |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 148 | wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt); |
| 149 | wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt); |
| 150 | wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt); |
| 151 | + |
| 152 | + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| 153 | + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| 154 | + struct mt7915_sta *msta; |
| 155 | + struct ieee80211_vif *vif; |
| 156 | + struct wireless_dev *wdev; |
| 157 | + struct pcpu_sw_netstats *tstats; |
| 158 | + |
| 159 | + msta = container_of(wcid, struct mt7915_sta, wcid); |
| 160 | + |
| 161 | + if (!msta || !msta->vif) |
| 162 | + goto unlock; |
| 163 | + |
| 164 | + vif = container_of((void *)msta->vif, |
| 165 | + struct ieee80211_vif, |
| 166 | + drv_priv); |
| 167 | + if (!vif) |
| 168 | + goto unlock; |
| 169 | + |
| 170 | + wdev = ieee80211_vif_to_wdev(vif); |
| 171 | + tstats = this_cpu_ptr(wdev->netdev->tstats); |
| 172 | + |
| 173 | + tstats->rx_packets += le32_to_cpu(stats->rx_pkt_cnt); |
| 174 | + tstats->rx_bytes += le32_to_cpu(stats->rx_byte_cnt); |
| 175 | + } |
| 176 | } |
| 177 | |
| 178 | +unlock: |
| 179 | rcu_read_unlock(); |
| 180 | } |
| 181 | |
| 182 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 183 | index 04fc539..faa1ca2 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 184 | --- a/mt7915/mt7915.h |
| 185 | +++ b/mt7915/mt7915.h |
developer | 8f0d89b | 2023-07-28 07:16:44 +0800 | [diff] [blame] | 186 | @@ -674,7 +674,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 187 | struct ieee80211_sta *sta, struct rate_info *rate); |
| 188 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 189 | struct cfg80211_chan_def *chandef); |
| 190 | -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid); |
| 191 | +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid, |
| 192 | + struct mt7915_sta *sta); |
| 193 | int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx); |
| 194 | int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| 195 | int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3); |
| 196 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | 12a4279 | 2023-07-29 05:30:55 +0800 | [diff] [blame^] | 197 | index 401b4dd..7a641b1 100644 |
developer | 7be2954 | 2023-06-28 17:30:38 +0800 | [diff] [blame] | 198 | --- a/mt7915/mtk_debugfs.c |
| 199 | +++ b/mt7915/mtk_debugfs.c |
| 200 | @@ -3797,7 +3797,7 @@ static int mt7915_reset_counter(void *data, u64 val) |
| 201 | struct mt76_wcid *wcid; |
| 202 | |
| 203 | /* Clear the firmware counters */ |
| 204 | - mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx); |
| 205 | + mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL); |
| 206 | mt7915_get_tx_stat(phy, dev->wlan_idx); |
| 207 | |
| 208 | rcu_read_lock(); |
| 209 | -- |
| 210 | 2.18.0 |
| 211 | |