| From 4e0a12871b8c134c99bd702f425c492ddc1f50b6 Mon Sep 17 00:00:00 2001 |
| From: Evelyn Tsai <evelyn.tsai@mediatek.com> |
| Date: Wed, 1 Nov 2023 07:50:08 +0800 |
| Subject: [PATCH 1/5] wifi: mt76: mt7915: wed: add per bss statistic info |
| |
| --- |
| mt7915/init.c | 1 + |
| mt7915/mac.c | 21 +++++++++++++++++++++ |
| mt7915/main.c | 5 ++++- |
| mt7915/mcu.c | 30 +++++++++++++++++++++++++++--- |
| mt7915/mmio.c | 26 +++++++++++++++++++++++++- |
| mt7915/mt7915.h | 3 ++- |
| mt7915/mtk_debugfs.c | 2 +- |
| 7 files changed, 81 insertions(+), 7 deletions(-) |
| |
| diff --git a/mt7915/init.c b/mt7915/init.c |
| index f38c8a1..7bc8039 100644 |
| --- a/mt7915/init.c |
| +++ b/mt7915/init.c |
| @@ -400,6 +400,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy) |
| wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY); |
| wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); |
| wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); |
| + wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STAS_COUNT); |
| |
| if (!is_mt7915(&dev->mt76)) |
| wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); |
| diff --git a/mt7915/mac.c b/mt7915/mac.c |
| index 02f794d..0c12170 100644 |
| --- a/mt7915/mac.c |
| +++ b/mt7915/mac.c |
| @@ -1071,6 +1071,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
| struct mt7915_phy *phy; |
| struct mt76_wcid *wcid; |
| __le32 *txs_data = data; |
| + u64 last_bytes; |
| u16 wcidx; |
| u8 pid; |
| |
| @@ -1089,6 +1090,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
| if (!wcid) |
| goto out; |
| |
| + last_bytes = wcid->stats.tx_bytes; |
| msta = container_of(wcid, struct mt7915_sta, wcid); |
| |
| if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) == MT_TXS_PPDU_FMT) |
| @@ -1099,6 +1101,24 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data) |
| if (!wcid->sta) |
| goto out; |
| |
| + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| + struct ieee80211_vif *vif; |
| + struct wireless_dev *wdev; |
| + |
| + vif = container_of((void *)msta->vif, struct ieee80211_vif, |
| + drv_priv); |
| + if (!vif) |
| + goto out; |
| + |
| + wdev = ieee80211_vif_to_wdev(vif); |
| + |
| + if (vif->type == NL80211_IFTYPE_MONITOR) |
| + goto out; |
| + |
| + dev_sw_netstats_tx_add(wdev->netdev, 0, (wcid->stats.tx_bytes - last_bytes)); |
| + } |
| + |
| spin_lock_bh(&dev->mt76.sta_poll_lock); |
| if (list_empty(&msta->wcid.poll_list)) |
| list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); |
| @@ -2043,6 +2063,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy) |
| spin_unlock_bh(&phy->stats_lock); |
| |
| mt7915_mcu_get_tx_rate(phy, sta->wcid.idx); |
| + mt7915_mcu_wed_wa_tx_stats(phy->dev, sta->wcid.idx, sta); |
| |
| spin_lock_bh(&phy->stats_lock); |
| } |
| diff --git a/mt7915/main.c b/mt7915/main.c |
| index feb2c89..722635e 100644 |
| --- a/mt7915/main.c |
| +++ b/mt7915/main.c |
| @@ -1219,6 +1219,9 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| struct rate_info *txrate = &msta->wcid.rate; |
| struct rate_info rxrate = {}; |
| |
| + if (msta->wcid.idx == 0) |
| + return; |
| + |
| if (is_connac_v2(&phy->dev->mt76) && |
| !mt7915_mcu_get_rx_rate(phy, vif, sta, &rxrate)) { |
| sinfo->rxrate = rxrate; |
| @@ -1247,7 +1250,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw, |
| sinfo->tx_bytes = msta->wcid.stats.tx_bytes; |
| sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64); |
| |
| - if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) { |
| + if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) { |
| sinfo->tx_packets = msta->wcid.stats.tx_packets; |
| sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
| } |
| diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| index 708e7cd..342fe42 100644 |
| --- a/mt7915/mcu.c |
| +++ b/mt7915/mcu.c |
| @@ -4750,7 +4750,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev, |
| &req, sizeof(req), true); |
| } |
| |
| -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
| +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx, |
| + struct mt7915_sta *sta) |
| { |
| struct { |
| __le32 cmd; |
| @@ -4806,11 +4807,34 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx) |
| rcu_read_lock(); |
| |
| wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]); |
| - if (wcid) |
| + if (wcid) { |
| + struct ieee80211_vif *vif; |
| + struct wireless_dev *wdev; |
| + |
| wcid->stats.tx_packets += le32_to_cpu(res->tx_packets); |
| - else |
| + |
| + if (!wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| + NL80211_EXT_FEATURE_STAS_COUNT) || |
| + !sta) |
| + goto unlock; |
| + |
| + vif = container_of((void *)sta->vif, |
| + struct ieee80211_vif, |
| + drv_priv); |
| + if (!vif) |
| + goto unlock; |
| + |
| + wdev = ieee80211_vif_to_wdev(vif); |
| + |
| + if (vif->type == NL80211_IFTYPE_MONITOR) |
| + goto unlock; |
| + |
| + dev_sw_netstats_tx_add(wdev->netdev, le32_to_cpu(res->tx_packets), 0); |
| + } else { |
| ret = -EINVAL; |
| + } |
| |
| +unlock: |
| rcu_read_unlock(); |
| out: |
| dev_kfree_skb(skb); |
| diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
| index 6309dd9..142f308 100644 |
| --- a/mt7915/mmio.c |
| +++ b/mt7915/mmio.c |
| @@ -592,7 +592,7 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed, |
| |
| dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| |
| - if (idx >= mt7915_wtbl_size(dev)) |
| + if (idx <= 0 || idx >= mt7915_wtbl_size(dev)) |
| return; |
| |
| rcu_read_lock(); |
| @@ -607,8 +607,32 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed, |
| wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt); |
| wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt); |
| wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt); |
| + |
| + if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy, |
| + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| + struct mt7915_sta *msta; |
| + struct ieee80211_vif *vif; |
| + struct wireless_dev *wdev; |
| + |
| + msta = container_of(wcid, struct mt7915_sta, wcid); |
| + |
| + vif = container_of((void *)msta->vif, |
| + struct ieee80211_vif, |
| + drv_priv); |
| + if (!vif) |
| + goto unlock; |
| + |
| + wdev = ieee80211_vif_to_wdev(vif); |
| + |
| + if (vif->type == NL80211_IFTYPE_MONITOR) |
| + goto unlock; |
| + |
| + dev_sw_netstats_rx_add(wdev->netdev, le32_to_cpu(stats->rx_pkt_cnt), |
| + le32_to_cpu(stats->rx_byte_cnt)); |
| + } |
| } |
| |
| +unlock: |
| rcu_read_unlock(); |
| } |
| |
| diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| index 945c82e..6e7ed9e 100644 |
| --- a/mt7915/mt7915.h |
| +++ b/mt7915/mt7915.h |
| @@ -756,7 +756,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| struct ieee80211_sta *sta, struct rate_info *rate); |
| int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| struct cfg80211_chan_def *chandef); |
| -int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid); |
| +int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid, |
| + struct mt7915_sta *sta); |
| int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx); |
| int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set); |
| int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3); |
| diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
| index c63bf90..2c9f198 100644 |
| --- a/mt7915/mtk_debugfs.c |
| +++ b/mt7915/mtk_debugfs.c |
| @@ -4034,7 +4034,7 @@ static int mt7915_reset_counter(void *data, u64 val) |
| struct mt76_wcid *wcid; |
| |
| /* Clear the firmware counters */ |
| - mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx); |
| + mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL); |
| mt7915_get_tx_stat(phy, dev->wlan_idx); |
| |
| rcu_read_lock(); |
| -- |
| 2.18.0 |
| |