blob: 1e06935174ca951734d7dd3fb6c0ba9113c445e4 [file] [log] [blame]
developerf4b11c42023-04-28 11:44:16 +08001From 4f1290c149c6cc3ef2f2623ca09f23fe9bb4c133 Mon Sep 17 00:00:00 2001
developer33554a22023-01-30 14:11:29 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Wed, 18 Jan 2023 16:37:22 +0800
developerf4b11c42023-04-28 11:44:16 +08004Subject: [PATCH] wifi: mt76: mt7915: add wa command to get tx msdu count
developer33554a22023-01-30 14:11:29 +08005
6---
7 mt76.h | 2 +-
8 mt76_connac2_mac.h | 1 +
developer5bea7322023-04-13 18:50:55 +08009 mt76_connac_mac.c | 9 +++----
developer33554a22023-01-30 14:11:29 +080010 mt76_connac_mcu.h | 1 +
11 mt7915/main.c | 8 ++++---
developer5bea7322023-04-13 18:50:55 +080012 mt7915/mcu.c | 58 ++++++++++++++++++++++++++++++++++++++++++----
developer33554a22023-01-30 14:11:29 +080013 mt7915/mcu.h | 11 +++++++++
14 mt7915/mt7915.h | 1 +
developer5bea7322023-04-13 18:50:55 +080015 8 files changed, 79 insertions(+), 12 deletions(-)
developer33554a22023-01-30 14:11:29 +080016
17diff --git a/mt76.h b/mt76.h
developerf4b11c42023-04-28 11:44:16 +080018index a215d2f1..c7bd147f 100644
developer33554a22023-01-30 14:11:29 +080019--- a/mt76.h
20+++ b/mt76.h
developer5bea7322023-04-13 18:50:55 +080021@@ -288,7 +288,7 @@ struct mt76_sta_stats {
developer33554a22023-01-30 14:11:29 +080022 u64 tx_mcs[16]; /* mcs idx */
23 u64 tx_bytes;
24 /* WED TX */
25- u32 tx_packets;
26+ u32 tx_packets; /* unit: MSDU */
27 u32 tx_retries;
28 u32 tx_failed;
29 /* WED RX */
30diff --git a/mt76_connac2_mac.h b/mt76_connac2_mac.h
developerf4b11c42023-04-28 11:44:16 +080031index f33171bc..101e7602 100644
developer33554a22023-01-30 14:11:29 +080032--- a/mt76_connac2_mac.h
33+++ b/mt76_connac2_mac.h
34@@ -164,6 +164,7 @@ enum {
35
36 #define MT_TXS6_MPDU_FAIL_CNT GENMASK(31, 23)
37
38+#define MT_TXS7_MPDU_RETRY_BYTE GENMASK(22, 0)
39 #define MT_TXS7_MPDU_RETRY_CNT GENMASK(31, 23)
40
41 /* RXD DW1 */
42diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c
developerf4b11c42023-04-28 11:44:16 +080043index 8d316d3a..1816bcbc 100644
developer33554a22023-01-30 14:11:29 +080044--- a/mt76_connac_mac.c
45+++ b/mt76_connac_mac.c
46@@ -491,7 +491,9 @@ void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
47
48 /* counting non-offloading skbs */
49 wcid->stats.tx_bytes += skb->len;
50- wcid->stats.tx_packets++;
51+
52+ if (is_mt7915(dev))
53+ wcid->stats.tx_packets++;
54 }
55
56 val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) |
57@@ -575,9 +577,8 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
58 /* PPDU based reporting */
59 if (FIELD_GET(MT_TXS0_TXS_FORMAT, txs) > 1) {
60 stats->tx_bytes +=
61- le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE);
62- stats->tx_packets +=
63- le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_CNT);
64+ le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) -
65+ le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE);
66 stats->tx_failed +=
67 le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT);
68 stats->tx_retries +=
69diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developerf4b11c42023-04-28 11:44:16 +080070index 8e559efb..dd7ee32f 100644
developer33554a22023-01-30 14:11:29 +080071--- a/mt76_connac_mcu.h
72+++ b/mt76_connac_mcu.h
developer4f0d84b2023-03-03 14:21:44 +080073@@ -1000,6 +1000,7 @@ enum {
developer33554a22023-01-30 14:11:29 +080074 MCU_EXT_EVENT_BF_STATUS_READ = 0x35,
75 MCU_EXT_EVENT_RDD_REPORT = 0x3a,
76 MCU_EXT_EVENT_CSA_NOTIFY = 0x4f,
77+ MCU_EXT_EVENT_WA_TX_STAT = 0x74,
78 MCU_EXT_EVENT_BCC_NOTIFY = 0x75,
79 MCU_EXT_EVENT_MURU_CTRL = 0x9f,
80 MCU_EXT_EVENT_CSI_REPORT = 0xc2,
81diff --git a/mt7915/main.c b/mt7915/main.c
developerf4b11c42023-04-28 11:44:16 +080082index da49e318..6714f635 100644
developer33554a22023-01-30 14:11:29 +080083--- a/mt7915/main.c
84+++ b/mt7915/main.c
developerf4b11c42023-04-28 11:44:16 +080085@@ -1117,9 +1117,6 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer33554a22023-01-30 14:11:29 +080086 sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
87 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
88
89- sinfo->tx_packets = msta->wcid.stats.tx_packets;
90- sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
91-
92 sinfo->tx_failed = msta->wcid.stats.tx_failed;
93 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
94
developerf4b11c42023-04-28 11:44:16 +080095@@ -1135,6 +1132,11 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer33554a22023-01-30 14:11:29 +080096 }
97 }
98
99+ if (!mt7915_mcu_get_tx_stat_wa(phy->dev, msta->wcid.idx)) {
100+ sinfo->tx_packets = msta->wcid.stats.tx_packets;
101+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
102+ }
103+
104 sinfo->ack_signal = (s8)msta->ack_signal;
105 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
106
107diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerf4b11c42023-04-28 11:44:16 +0800108index b5d1e637..29b2486c 100644
developer33554a22023-01-30 14:11:29 +0800109--- a/mt7915/mcu.c
110+++ b/mt7915/mcu.c
developerc9233442023-04-04 06:06:17 +0800111@@ -169,7 +169,9 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
developer33554a22023-01-30 14:11:29 +0800112 }
113
114 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
115- if (seq != rxd->seq)
116+
117+ if (seq != rxd->seq &&
118+ !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
119 return -EAGAIN;
120
121 if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) {
developerc9233442023-04-04 06:06:17 +0800122@@ -421,13 +423,14 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
developer33554a22023-01-30 14:11:29 +0800123 struct mt76_connac2_mcu_rxd *rxd;
124
125 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
126- if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
127+ if ((rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
128 rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST ||
129 rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
130 rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
131 rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
132 rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ ||
133- !rxd->seq)
134+ !rxd->seq) &&
135+ !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
136 mt7915_mcu_rx_unsolicited_event(dev, skb);
137 else
138 mt76_mcu_rx_event(&dev->mt76, skb);
developerf4b11c42023-04-28 11:44:16 +0800139@@ -4272,7 +4275,7 @@ int mt7915_mcu_get_tx_rate_v2(struct mt7915_phy *phy, u16 wcidx)
developer5bea7322023-04-13 18:50:55 +0800140 };
141
142 ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
143- &req, sizeof(req), true, &skb);
144+ &req, sizeof(req), true, &skb);
145 if (ret)
146 return ret;
147
developerf4b11c42023-04-28 11:44:16 +0800148@@ -4316,6 +4319,53 @@ int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx)
149 return mt7915_mcu_get_tx_rate_v2(phy, wcidx);
developer33554a22023-01-30 14:11:29 +0800150 }
151
152+int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wlan_idx)
153+{
154+ struct {
155+ __le32 cmd;
156+ __le32 num;
157+ __le32 __rsv;
158+ __le16 wlan_idx;
159+ } req = {
160+ .cmd = cpu_to_le32(MCU_WA_QUERY_GET_TX_STAT),
161+ .num = cpu_to_le32(1),
162+ .wlan_idx = cpu_to_le16(wlan_idx),
163+ };
164+ struct mt7915_mcu_wa_tx_stat *res;
165+ struct mt76_wcid *wcid;
166+ struct sk_buff *skb;
167+ int ret;
168+
169+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY),
170+ &req, sizeof(req), true, &skb);
171+ if (ret)
172+ return ret;
173+
174+ if (!is_mt7915(&dev->mt76))
175+ skb_pull(skb, 4);
176+
177+ res = (struct mt7915_mcu_wa_tx_stat *)skb->data;
178+
179+ if (le16_to_cpu(res->wlan_idx) != wlan_idx) {
180+ ret = -EINVAL;
181+ goto out;
182+ }
183+
184+ rcu_read_lock();
185+
186+ wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
187+ if (wcid)
188+ wcid->stats.tx_packets += le32_to_cpu(res->tx_msdu_cnt);
189+ else
190+ ret = -EINVAL;
191+
192+ rcu_read_unlock();
193+out:
194+ dev_kfree_skb(skb);
195+
196+ return ret;
197+}
198+
199 int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif,
200 struct cfg80211_he_bss_color *he_bss_color)
201 {
202diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developerf4b11c42023-04-28 11:44:16 +0800203index d3cbe160..a7098427 100644
developer33554a22023-01-30 14:11:29 +0800204--- a/mt7915/mcu.h
205+++ b/mt7915/mcu.h
developerf4b11c42023-04-28 11:44:16 +0800206@@ -347,6 +347,17 @@ enum {
developer33554a22023-01-30 14:11:29 +0800207 MCU_WA_PARAM_RED_SETTING = 0x40,
208 };
209
210+enum {
211+ MCU_WA_QUERY_GET_TX_STAT = 0x15,
212+};
213+
214+struct mt7915_mcu_wa_tx_stat {
215+ __le16 wlan_idx;
216+ u8 __rsv2[2];
217+ __le32 tx_bytes;
218+ __le32 tx_msdu_cnt;
219+};
220+
221 enum mcu_mmps_mode {
222 MCU_MMPS_STATIC,
223 MCU_MMPS_DYNAMIC,
224diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerf4b11c42023-04-28 11:44:16 +0800225index 8a1be2db..28a2416c 100644
developer33554a22023-01-30 14:11:29 +0800226--- a/mt7915/mt7915.h
227+++ b/mt7915/mt7915.h
developer5bea7322023-04-13 18:50:55 +0800228@@ -722,6 +722,7 @@ int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy);
229 int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx);
developer33554a22023-01-30 14:11:29 +0800230 int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
231 struct ieee80211_sta *sta, struct rate_info *rate);
232+int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wcid);
233 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
234 struct cfg80211_chan_def *chandef);
235 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
236--
developer2324aa22023-04-12 11:30:15 +08002372.18.0
developer33554a22023-01-30 14:11:29 +0800238