[][[mt76] Add statistic for H/W Rx path]

[Description]
Add statistic for H/W Rx path

[Release-log]
N/A

Change-Id: Ibec5e161ae1a9264797ddb59d90ba7d6e8f22367
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6366236
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-add-statistic-for-HW-Rx-Path.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-add-statistic-for-HW-Rx-Path.patch
new file mode 100644
index 0000000..e91955f
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-add-statistic-for-HW-Rx-Path.patch
@@ -0,0 +1,252 @@
+From 12b7c7a035359298fc7d14ae3a6dbc16ec0b70ad Mon Sep 17 00:00:00 2001
+From: Yi-Chia Hsieh <Yi-Chia.Hsieh@mediatek.com>
+Date: Fri, 5 Aug 2022 13:58:11 -0700
+Subject: [PATCH] mt76: mt7915: add statistic for H/W Rx Path
+
+Change-Id: Id94d663f08e91c83d296bd57e5e9b65a505ae1c7
+---
+ mt76.h            |  4 ++++
+ mt76_connac.h     |  5 +++++
+ mt76_connac_mcu.h | 35 +++++++++++++++++++++++++++++++++++
+ mt7915/mac.c      | 26 ++++++++++++++++++++++++++
+ mt7915/main.c     |  9 ++++++++-
+ mt7915/mcu.c      | 21 +++++++++++++++++++++
+ mt7915/mmio.c     |  6 ++++++
+ mt7915/mt7915.h   |  3 +++
+ 8 files changed, 108 insertions(+), 1 deletion(-)
+
+diff --git a/mt76.h b/mt76.h
+index a65e7a3..e56fd58 100644
+--- a/mt76.h
++++ b/mt76.h
+@@ -289,6 +289,10 @@ struct mt76_sta_stats {
+ 	u32 tx_packets;
+ 	u32 tx_retries;
+ 	u32 tx_failed;
++	u64 rx_bytes;
++	u32 rx_packets;
++	u32 rx_error;
++	u32 rx_drop;
+ };
+ 
+ struct mt76_wcid {
+diff --git a/mt76_connac.h b/mt76_connac.h
+index 8f78d12..41d6525 100644
+--- a/mt76_connac.h
++++ b/mt76_connac.h
+@@ -218,6 +218,11 @@ static inline bool is_mt76_fw_txp(struct mt76_dev *dev)
+ 	}
+ }
+ 
++static inline bool is_wo_mcu(struct mt76_dev *dev)
++{
++	return is_mt7986(dev);
++}
++
+ static inline u8 mt76_connac_chan_bw(struct cfg80211_chan_def *chandef)
+ {
+ 	static const u8 width_to_bw[] = {
+diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
+index ca68172..722e859 100644
+--- a/mt76_connac_mcu.h
++++ b/mt76_connac_mcu.h
+@@ -1200,6 +1200,41 @@ enum {
+ 	MCU_CE_CMD_GET_TXPWR = 0xd0,
+ };
+ 
++enum wo_event_id {
++	WO_EVT_LOG_DUMP = 0x1,
++	WO_EVT_PROFILING = 0x2,
++	WO_EVT_RXCNT_INFO = 0x3
++};
++
++enum wo_cmd_id {
++	WO_CMD_WED_CFG = 0,
++	WO_CMD_WED_RX_STAT,
++	WO_CMD_RRO_SER,
++	WO_CMD_DBG_INFO,
++	WO_CMD_DEV_INFO,
++	WO_CMD_BSS_INFO,
++	WO_CMD_STA_REC,
++	WO_CMD_DEV_INFO_DUMP,
++	WO_CMD_BSS_INFO_DUMP,
++	WO_CMD_STA_REC_DUMP,
++	WO_CMD_BA_INFO_DUMP,
++	WO_CMD_FBCMD_Q_DUMP,
++	WO_CMD_FW_LOG_CTRL,
++	WO_CMD_LOG_FLUSH,
++	WO_CMD_CHANGE_STATE,
++	WO_CMD_CPU_STATS_ENABLE,
++	WO_CMD_CPU_STATS_DUMP,
++	WO_CMD_EXCEPTION_INIT,
++	WO_CMD_PROF_CTRL,
++	WO_CMD_STA_BA_DUMP,
++	WO_CMD_BA_CTRL_DUMP,
++	WO_CMD_RXCNT_CTRL,
++	WO_CMD_RXCNT_INFO,
++	WO_CMD_SET_CAP,
++	WO_CMD_CCIF_RING_DUMP,
++	WO_CMD_WED_END
++};
++
+ enum {
+ 	PATCH_SEM_RELEASE,
+ 	PATCH_SEM_GET
+diff --git a/mt7915/mac.c b/mt7915/mac.c
+index 5ee9bb2..9ce5a60 100644
+--- a/mt7915/mac.c
++++ b/mt7915/mac.c
+@@ -938,6 +938,31 @@ void mt7915_wed_trigger_ser(struct mtk_wed_device *wed)
+ 	return;
+ }
+ 
++void mt7915_wed_update_wo_rxcnt(struct mtk_wed_device *wed,
++				    struct wo_cmd_rxcnt_t *rxcnt)
++{
++	struct mt7915_dev *dev;
++	struct mt76_wcid *wcid;
++
++	dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
++	if (rxcnt->wlan_idx >= mt7915_wtbl_size(dev))
++		return;
++
++	rcu_read_lock();
++
++	wcid = rcu_dereference(dev->mt76.wcid[rxcnt->wlan_idx]);
++	if (!wcid)
++		goto out;
++
++	wcid->stats.rx_bytes += rxcnt->rx_byte_cnt;
++	wcid->stats.rx_packets += rxcnt->rx_pkt_cnt;
++	wcid->stats.rx_error += rxcnt->rx_err_cnt;
++	wcid->stats.rx_drop += rxcnt->rx_drop_cnt;
++
++out:
++	rcu_read_unlock();
++}
++
+ static void
+ mt7915_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
+ {
+@@ -1173,6 +1198,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
+ 					  &msta->wcid.stats);
+ 	else
+ 		mt76_connac2_mac_add_txs_skb(&dev->mt76, wcid, pid, txs_data);
++
+ 	if (!wcid->sta)
+ 		goto out;
+ 
+diff --git a/mt7915/main.c b/mt7915/main.c
+index 7935774..a73c488 100644
+--- a/mt7915/main.c
++++ b/mt7915/main.c
+@@ -1028,7 +1028,8 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
+ 	struct rate_info *txrate = &msta->wcid.rate;
+ 	struct rate_info rxrate = {};
+ 
+-	if (is_mt7915(&phy->dev->mt76) &&
++	if ((is_mt7915(&phy->dev->mt76) ||
++	    mtk_wed_device_active(&phy->dev->mt76.mmio.wed)) &&
+ 	    !mt7915_mcu_get_rx_rate(phy, vif, sta, &rxrate)) {
+ 		sinfo->rxrate = rxrate;
+ 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
+@@ -1062,6 +1063,12 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
+ 
+ 		sinfo->tx_retries = msta->wcid.stats.tx_retries;
+ 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
++
++		sinfo->rx_bytes = msta->wcid.stats.rx_bytes;
++		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
++
++		sinfo->rx_packets = msta->wcid.stats.rx_packets;
++		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
+ 	}
+ }
+ 
+diff --git a/mt7915/mcu.c b/mt7915/mcu.c
+index 1272bee..8536b1e 100644
+--- a/mt7915/mcu.c
++++ b/mt7915/mcu.c
+@@ -293,6 +293,27 @@ int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3)
+ 	return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), false);
+ }
+ 
++int mt7915_mcu_wo_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2)
++{
++	struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
++	struct {
++		__le32 args[2];
++	} req = {
++		.args = {
++			cpu_to_le32(a1),
++			cpu_to_le32(a2),
++		},
++	};
++
++	if (!mtk_wed_device_active(wed))
++		return -1;
++
++	if (!is_wo_mcu(&dev->mt76))
++		return -1;
++
++	return mtk_soc_wed_ops->msg_update(wed, cmd, (void *)&req, sizeof(req));
++}
++
+ static void
+ mt7915_mcu_csa_finish(void *priv, u8 *mac, struct ieee80211_vif *vif)
+ {
+diff --git a/mt7915/mmio.c b/mt7915/mmio.c
+index f8dd553..bd80315 100644
+--- a/mt7915/mmio.c
++++ b/mt7915/mmio.c
+@@ -9,6 +9,7 @@
+ #include "mt7915.h"
+ #include "mac.h"
+ #include "../trace.h"
++#include "../mt76_connac_mcu.h"
+ 
+ static bool wed_enable = true;
+ module_param(wed_enable, bool, 0644);
+@@ -781,6 +782,8 @@ mt7915_pci_wed_init(struct mt7915_dev *dev, struct device *pdev, int *irq)
+ 
+ 	wed->wlan.ser_trigger = mt7915_wed_trigger_ser;
+ 
++	wed->wlan.update_wo_rxcnt = mt7915_wed_update_wo_rxcnt;
++
+ 	dev->mt76.rx_token_size = wed->wlan.rx_pkt;
+ 	if (mtk_wed_device_attach(wed) != 0)
+ 		return 0;
+@@ -792,6 +795,9 @@ mt7915_pci_wed_init(struct mt7915_dev *dev, struct device *pdev, int *irq)
+ 	if (ret)
+ 		return ret;
+ 
++	if (is_wo_mcu(&dev->mt76))
++		mt7915_mcu_wo_cmd(dev, WO_CMD_RXCNT_CTRL, 1, 6);
++
+ 	return 1;
+ #else
+ 	return 0;
+diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
+index b4d6b55..c02cc87 100644
+--- a/mt7915/mt7915.h
++++ b/mt7915/mt7915.h
+@@ -546,6 +546,8 @@ u32 mt7915_wed_init_rx_buf(struct mtk_wed_device *wed,
+ 				int pkt_num);
+ void mt7915_wed_release_rx_buf(struct mtk_wed_device *wed);
+ void mt7915_wed_trigger_ser(struct mtk_wed_device *wed);
++void mt7915_wed_update_wo_rxcnt(struct mtk_wed_device *wed,
++				struct wo_cmd_rxcnt_t *rxcnt);
+ int mt7915_register_device(struct mt7915_dev *dev);
+ void mt7915_unregister_device(struct mt7915_dev *dev);
+ int mt7915_eeprom_init(struct mt7915_dev *dev);
+@@ -630,6 +632,7 @@ int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
+ 				     struct cfg80211_chan_def *chandef);
+ 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);
++int mt7915_mcu_wo_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2);
+ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
+ int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level);
+ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb);
+-- 
+2.32.0
+