[][mac80211][wifi6][mt76][Fix tx statistics]
[Description]
Fix Tx statistics
1. Fix mcu command for mt7915 tx counts.
2. Read PPDU txs to get correct tx retry and tx fail.
[Release-log]
N/A
Change-Id: Iba07bffe05eff1e69d3e644adba655c614bb44ee
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8605332
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/0014-wifi-mt76-mt7915-fix-mcu-command-format-for-mt7915-t.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/0014-wifi-mt76-mt7915-fix-mcu-command-format-for-mt7915-t.patch
new file mode 100644
index 0000000..aac1ce3
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/0014-wifi-mt76-mt7915-fix-mcu-command-format-for-mt7915-t.patch
@@ -0,0 +1,90 @@
+From 1ce20111294e5acdd363d7108083e51e4c3efd12 Mon Sep 17 00:00:00 2001
+From: Peter Chiu <chui-hao.chiu@mediatek.com>
+Date: Mon, 29 Jan 2024 10:38:35 +0800
+Subject: [PATCH 14/15] wifi: mt76: mt7915: fix mcu command format for mt7915
+ tx stats
+
+The mcu command format are different for mt7915 and mt7986.
+Fix the mt7915_mcu_wed_wa_tx_stats to support mt7915 and mt7986.
+
+Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
+---
+ mt7915/mcu.c | 42 ++++++++++++++++++++++++++++++------------
+ 1 file changed, 30 insertions(+), 12 deletions(-)
+
+diff --git a/mt7915/mcu.c b/mt7915/mcu.c
+index 7a2a537d..f27ef673 100644
+--- a/mt7915/mcu.c
++++ b/mt7915/mcu.c
+@@ -3960,30 +3960,46 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
+ {
+ struct {
+ __le32 cmd;
+- __le32 num;
+- __le32 __rsv;
+- __le16 wlan_idx;
+- } req = {
++ __le32 arg0;
++ __le32 arg1;
++ __le16 arg2;
++ } __packed req = {
+ .cmd = cpu_to_le32(0x15),
+- .num = cpu_to_le32(1),
+- .wlan_idx = cpu_to_le16(wlan_idx),
+ };
+ struct mt7915_mcu_wa_tx_stat {
+- __le16 wlan_idx;
+- u8 __rsv[2];
++ union {
++ struct {
++ u8 wcid;
++ u8 __rsv[3];
++ } __packed mt7915_hdr;
++ struct {
++ u16 wcid;
++ u8 __rsv2[2];
++ } __packed mt7986_hdr;
++ } u;
+
+ /* tx_bytes is deprecated since WA byte counter uses u32,
+ * which easily leads to overflow.
+ */
+ __le32 tx_bytes;
+ __le32 tx_packets;
+- } *res;
++ } __packed *res;
+ struct mt76_wcid *wcid;
+ struct sk_buff *skb;
+- int ret;
++ int ret, len;
++ u16 ret_wcid;
++
++ if (is_mt7915(&dev->mt76)) {
++ req.arg0 = cpu_to_le32(wlan_idx);
++ len = sizeof(req) - sizeof(req.arg2);
++ } else {
++ req.arg0 = cpu_to_le32(1);
++ req.arg2 = cpu_to_le16(wlan_idx);
++ len = sizeof(req);
++ }
+
+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY),
+- &req, sizeof(req), true, &skb);
++ &req, len, true, &skb);
+ if (ret)
+ return ret;
+
+@@ -3992,7 +4008,9 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
+
+ res = (struct mt7915_mcu_wa_tx_stat *)skb->data;
+
+- if (le16_to_cpu(res->wlan_idx) != wlan_idx) {
++ ret_wcid = is_mt7915(&dev->mt76) ? res->u.mt7915_hdr.wcid :
++ le16_to_cpu(res->u.mt7986_hdr.wcid);
++ if (ret_wcid != wlan_idx) {
+ ret = -EINVAL;
+ goto out;
+ }
+--
+2.18.0
+
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/0015-wifi-mt76-fix-tx-statistics-about-tx-retry-and-tx-fa.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/0015-wifi-mt76-fix-tx-statistics-about-tx-retry-and-tx-fa.patch
new file mode 100644
index 0000000..966d623
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/0015-wifi-mt76-fix-tx-statistics-about-tx-retry-and-tx-fa.patch
@@ -0,0 +1,44 @@
+From 01820e36780c58fbb8fa58c6fa669a22f0ae6bab Mon Sep 17 00:00:00 2001
+From: Peter Chiu <chui-hao.chiu@mediatek.com>
+Date: Mon, 29 Jan 2024 11:02:06 +0800
+Subject: [PATCH 15/15] wifi: mt76: fix tx statistics about tx retry and tx
+ fail
+
+The tx retry and tx failed are reported by PPDU TxS.
+
+Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
+---
+ mt76_connac_mac.c | 3 ---
+ mt7915/mac.c | 2 +-
+ 2 files changed, 1 insertion(+), 4 deletions(-)
+
+diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c
+index b841bf62..630c6402 100644
+--- a/mt76_connac_mac.c
++++ b/mt76_connac_mac.c
+@@ -716,9 +716,6 @@ bool mt76_connac2_mac_add_txs_skb(struct mt76_dev *dev, struct mt76_wcid *wcid,
+ struct sk_buff_head list;
+ struct sk_buff *skb;
+
+- if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) == MT_TXS_PPDU_FMT)
+- return false;
+-
+ mt76_tx_status_lock(dev, &list);
+ skb = mt76_tx_status_skb_get(dev, wcid, pid, &list);
+ if (skb) {
+diff --git a/mt7915/mac.c b/mt7915/mac.c
+index 37368536..7ee3ba39 100644
+--- a/mt7915/mac.c
++++ b/mt7915/mac.c
+@@ -1014,7 +1014,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
+
+ msta = container_of(wcid, struct mt7915_sta, wcid);
+
+- if (pid == MT_PACKET_ID_WED)
++ if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) == MT_TXS_PPDU_FMT)
+ mt76_connac2_mac_fill_txs(&dev->mt76, wcid, txs_data);
+ else
+ mt76_connac2_mac_add_txs_skb(&dev->mt76, wcid, pid, txs_data);
+--
+2.18.0
+