[][mac80211][wed][add per-bss counter in mt76]
[Description]
Add per-bss counter in mt76
[Release-log]
N/A
Change-Id: Iafd4ec60b94d27d980ccc149abbdc8181a3f0892
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7678159
diff --git a/autobuild_mac80211_release/package/kernel/mac80211/patches/subsys/mtk-9903-mac80211-add-per-bss-flag-to-support-vendors-cou.patch b/autobuild_mac80211_release/package/kernel/mac80211/patches/subsys/mtk-9903-mac80211-add-per-bss-flag-to-support-vendors-cou.patch
new file mode 100644
index 0000000..9c3586c
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mac80211/patches/subsys/mtk-9903-mac80211-add-per-bss-flag-to-support-vendors-cou.patch
@@ -0,0 +1,91 @@
+From 0d9e675842ae495da9412694f4dc6b3cfa897140 Mon Sep 17 00:00:00 2001
+From: "sujuan.chen" <sujuan.chen@mediatek.com>
+Date: Tue, 30 May 2023 15:36:33 +0800
+Subject: [PATCH] mtk: mac80211: add per-bss flag to support vendors counter
+
+Signed-off-by: sujuan.chen <sujuan.chen@mediatek.com>
+---
+ include/uapi/linux/nl80211.h | 1 +
+ net/mac80211/rx.c | 8 ++++++--
+ net/mac80211/tx.c | 13 ++++++++++---
+ 3 files changed, 17 insertions(+), 5 deletions(-)
+
+diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
+index 3e348a5..659ae8d 100644
+--- a/include/uapi/linux/nl80211.h
++++ b/include/uapi/linux/nl80211.h
+@@ -6102,6 +6102,7 @@ enum nl80211_ext_feature_index {
+ NL80211_EXT_FEATURE_BSS_COLOR,
+ NL80211_EXT_FEATURE_FILS_CRYPTO_OFFLOAD,
+ NL80211_EXT_FEATURE_RADAR_BACKGROUND,
++ NL80211_EXT_FEATURE_STAS_COUNT,
+
+ /* add new features before the definition below */
+ NUM_NL80211_EXT_FEATURES,
+diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
+index 838085f..e165ac6 100644
+--- a/net/mac80211/rx.c
++++ b/net/mac80211/rx.c
+@@ -2641,7 +2641,9 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
+ skb = rx->skb;
+ xmit_skb = NULL;
+
+- dev_sw_netstats_rx_add(dev, skb->len);
++ if (!wiphy_ext_feature_isset(sdata->local->hw.wiphy,
++ NL80211_EXT_FEATURE_STAS_COUNT) || !rx->sta)
++ dev_sw_netstats_rx_add(dev, skb->len);
+
+ if (rx->sta) {
+ /* The seqno index has the same property as needed
+@@ -4544,7 +4546,9 @@ static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
+
+ skb->dev = fast_rx->dev;
+
+- dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
++ if (!wiphy_ext_feature_isset(sta->local->hw.wiphy,
++ NL80211_EXT_FEATURE_STAS_COUNT))
++ dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
+
+ /* The seqno index has the same property as needed
+ * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
+diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
+index 9b66cc0..5fb51fc 100644
+--- a/net/mac80211/tx.c
++++ b/net/mac80211/tx.c
+@@ -3454,7 +3454,9 @@ ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
+ if (key)
+ info->control.hw_key = &key->conf;
+
+- dev_sw_netstats_tx_add(skb->dev, 1, skb->len);
++ if (!wiphy_ext_feature_isset(sta->local->hw.wiphy,
++ NL80211_EXT_FEATURE_STAS_COUNT))
++ dev_sw_netstats_tx_add(skb->dev, 1, skb->len);
+
+ if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
+ tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
+@@ -4219,7 +4221,9 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
+ goto out;
+ }
+
+- dev_sw_netstats_tx_add(dev, 1, skb->len);
++ if (!wiphy_ext_feature_isset(sdata->local->hw.wiphy,
++ NL80211_EXT_FEATURE_STAS_COUNT) || !sta)
++ dev_sw_netstats_tx_add(dev, 1, skb->len);
+
+ ieee80211_xmit(sdata, sta, skb);
+ }
+@@ -4497,7 +4501,10 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
+ info->ack_frame_id = ieee80211_store_ack_skb(local, skb,
+ &info->flags, NULL);
+
+- dev_sw_netstats_tx_add(dev, skbs, len);
++ if (!wiphy_ext_feature_isset(sta->local->hw.wiphy,
++ NL80211_EXT_FEATURE_STAS_COUNT))
++ dev_sw_netstats_tx_add(dev, skbs, len);
++
+ sta->tx_stats.packets[queue] += skbs;
+ sta->tx_stats.bytes[queue] += len;
+
+--
+2.18.0
+
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/2010-wifi-mt76-mt7915-wed-add-per-bss-statistic-info.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/2010-wifi-mt76-mt7915-wed-add-per-bss-statistic-info.patch
new file mode 100644
index 0000000..90379bc
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/2010-wifi-mt76-mt7915-wed-add-per-bss-statistic-info.patch
@@ -0,0 +1,211 @@
+From 9aa119df0e10be31197485fbd3fb499e13ff93cd Mon Sep 17 00:00:00 2001
+From: "sujuan.chen" <sujuan.chen@mediatek.com>
+Date: Wed, 28 Jun 2023 17:11:18 +0800
+Subject: [PATCH 1/2] wifi: mt76: mt7915: wed: add per bss statistic info
+
+Signed-off-by: sujuan.chen <sujuan.chen@mediatek.com>
+---
+ mt7915/init.c | 1 +
+ mt7915/mac.c | 19 +++++++++++++++++++
+ mt7915/main.c | 2 +-
+ mt7915/mcu.c | 29 ++++++++++++++++++++++++++---
+ mt7915/mmio.c | 26 ++++++++++++++++++++++++++
+ mt7915/mt7915.h | 3 ++-
+ mt7915/mtk_debugfs.c | 2 +-
+ 7 files changed, 76 insertions(+), 6 deletions(-)
+
+diff --git a/mt7915/init.c b/mt7915/init.c
+index cf576ed3..3d933592 100644
+--- a/mt7915/init.c
++++ b/mt7915/init.c
+@@ -373,6 +373,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 a0d1f893..af9f6a19 100644
+--- a/mt7915/mac.c
++++ b/mt7915/mac.c
+@@ -1048,6 +1048,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;
+
+@@ -1066,6 +1067,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 (pid == MT_PACKET_ID_WED)
+@@ -1076,6 +1078,22 @@ 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;
++ struct pcpu_sw_netstats *tstats;
++
++ vif = container_of((void *)msta->vif, struct ieee80211_vif,
++ drv_priv);
++ if (!vif)
++ goto out;
++
++ wdev = ieee80211_vif_to_wdev(vif);
++ tstats = this_cpu_ptr(wdev->netdev->tstats);
++
++ tstats->tx_bytes += 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);
+@@ -2053,6 +2071,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 7b341627..9ca76c42 100644
+--- a/mt7915/main.c
++++ b/mt7915/main.c
+@@ -1141,7 +1141,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 07a4b085..2334128e 100644
+--- a/mt7915/mcu.c
++++ b/mt7915/mcu.c
+@@ -4396,7 +4396,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;
+@@ -4440,11 +4441,33 @@ 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;
++ struct pcpu_sw_netstats *tstats;
++
+ 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);
++
++ tstats = this_cpu_ptr(wdev->netdev->tstats);
++ tstats->tx_packets += le32_to_cpu(res->tx_packets);
++ } else {
+ ret = -EINVAL;
++ }
+
++unlock:
+ rcu_read_unlock();
+ out:
+ dev_kfree_skb(skb);
+diff --git a/mt7915/mmio.c b/mt7915/mmio.c
+index 25893bd2..019507d3 100644
+--- a/mt7915/mmio.c
++++ b/mt7915/mmio.c
+@@ -699,8 +699,34 @@ 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;
++ struct pcpu_sw_netstats *tstats;
++
++ msta = container_of(wcid, struct mt7915_sta, wcid);
++
++ if (!msta || !msta->vif)
++ goto unlock;
++
++ vif = container_of((void *)msta->vif,
++ struct ieee80211_vif,
++ drv_priv);
++ if (!vif)
++ goto unlock;
++
++ wdev = ieee80211_vif_to_wdev(vif);
++ tstats = this_cpu_ptr(wdev->netdev->tstats);
++
++ tstats->rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
++ tstats->rx_bytes += le32_to_cpu(stats->rx_byte_cnt);
++ }
+ }
+
++unlock:
+ rcu_read_unlock();
+ }
+
+diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
+index 85c5c95c..424596fd 100644
+--- a/mt7915/mt7915.h
++++ b/mt7915/mt7915.h
+@@ -660,7 +660,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 da33578c..27592d71 100644
+--- a/mt7915/mtk_debugfs.c
++++ b/mt7915/mtk_debugfs.c
+@@ -3797,7 +3797,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
+