blob: 1b2680356f8baa80ce4a2c78e4a35155329b2430 [file] [log] [blame]
developerbbd45e12023-05-19 08:22:06 +08001From 13f5dc38354525add94b7c60ee289fd011ae5dbc 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
developerbbd45e12023-05-19 08:22:06 +08004Subject: [PATCH 3006/3012] wifi: mt76: mt7915: add wa command to get tx msdu
5 count
developer33554a22023-01-30 14:11:29 +08006
7---
8 mt76.h | 2 +-
9 mt76_connac2_mac.h | 1 +
developer5bea7322023-04-13 18:50:55 +080010 mt76_connac_mac.c | 9 +++----
developer33554a22023-01-30 14:11:29 +080011 mt76_connac_mcu.h | 1 +
12 mt7915/main.c | 8 ++++---
developer5bea7322023-04-13 18:50:55 +080013 mt7915/mcu.c | 58 ++++++++++++++++++++++++++++++++++++++++++----
developer33554a22023-01-30 14:11:29 +080014 mt7915/mcu.h | 11 +++++++++
15 mt7915/mt7915.h | 1 +
developer5bea7322023-04-13 18:50:55 +080016 8 files changed, 79 insertions(+), 12 deletions(-)
developer33554a22023-01-30 14:11:29 +080017
18diff --git a/mt76.h b/mt76.h
developerbbd45e12023-05-19 08:22:06 +080019index b178b95..4794b6a 100644
developer33554a22023-01-30 14:11:29 +080020--- a/mt76.h
21+++ b/mt76.h
developer5bea7322023-04-13 18:50:55 +080022@@ -288,7 +288,7 @@ struct mt76_sta_stats {
developer33554a22023-01-30 14:11:29 +080023 u64 tx_mcs[16]; /* mcs idx */
24 u64 tx_bytes;
25 /* WED TX */
26- u32 tx_packets;
27+ u32 tx_packets; /* unit: MSDU */
28 u32 tx_retries;
29 u32 tx_failed;
30 /* WED RX */
31diff --git a/mt76_connac2_mac.h b/mt76_connac2_mac.h
developerbbd45e12023-05-19 08:22:06 +080032index a5ec0f6..e7a4019 100644
developer33554a22023-01-30 14:11:29 +080033--- a/mt76_connac2_mac.h
34+++ b/mt76_connac2_mac.h
developerbbd45e12023-05-19 08:22:06 +080035@@ -174,6 +174,7 @@ enum {
developer33554a22023-01-30 14:11:29 +080036
37 #define MT_TXS6_MPDU_FAIL_CNT GENMASK(31, 23)
38
39+#define MT_TXS7_MPDU_RETRY_BYTE GENMASK(22, 0)
40 #define MT_TXS7_MPDU_RETRY_CNT GENMASK(31, 23)
41
developerbbd45e12023-05-19 08:22:06 +080042 /* RXD DW0 */
developer33554a22023-01-30 14:11:29 +080043diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c
developerbbd45e12023-05-19 08:22:06 +080044index ee0fbfc..ee37fe5 100644
developer33554a22023-01-30 14:11:29 +080045--- a/mt76_connac_mac.c
46+++ b/mt76_connac_mac.c
developerbbd45e12023-05-19 08:22:06 +080047@@ -523,7 +523,9 @@ void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
developer33554a22023-01-30 14:11:29 +080048
49 /* counting non-offloading skbs */
50 wcid->stats.tx_bytes += skb->len;
51- wcid->stats.tx_packets++;
52+
53+ if (is_mt7915(dev))
54+ wcid->stats.tx_packets++;
55 }
56
57 val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) |
developerbbd45e12023-05-19 08:22:06 +080058@@ -608,9 +610,8 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
developer33554a22023-01-30 14:11:29 +080059 /* PPDU based reporting */
60 if (FIELD_GET(MT_TXS0_TXS_FORMAT, txs) > 1) {
61 stats->tx_bytes +=
62- le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE);
63- stats->tx_packets +=
64- le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_CNT);
65+ le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) -
66+ le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE);
67 stats->tx_failed +=
68 le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT);
69 stats->tx_retries +=
70diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developerbbd45e12023-05-19 08:22:06 +080071index fd5aecb..97d732a 100644
developer33554a22023-01-30 14:11:29 +080072--- a/mt76_connac_mcu.h
73+++ b/mt76_connac_mcu.h
developer4f0d84b2023-03-03 14:21:44 +080074@@ -1000,6 +1000,7 @@ enum {
developer33554a22023-01-30 14:11:29 +080075 MCU_EXT_EVENT_BF_STATUS_READ = 0x35,
76 MCU_EXT_EVENT_RDD_REPORT = 0x3a,
77 MCU_EXT_EVENT_CSA_NOTIFY = 0x4f,
78+ MCU_EXT_EVENT_WA_TX_STAT = 0x74,
79 MCU_EXT_EVENT_BCC_NOTIFY = 0x75,
80 MCU_EXT_EVENT_MURU_CTRL = 0x9f,
81 MCU_EXT_EVENT_CSI_REPORT = 0xc2,
82diff --git a/mt7915/main.c b/mt7915/main.c
developerbbd45e12023-05-19 08:22:06 +080083index 2ba36da..ccdb148 100644
developer33554a22023-01-30 14:11:29 +080084--- a/mt7915/main.c
85+++ b/mt7915/main.c
developerbbd45e12023-05-19 08:22:06 +080086@@ -1116,9 +1116,6 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer33554a22023-01-30 14:11:29 +080087 sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
88 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
89
90- sinfo->tx_packets = msta->wcid.stats.tx_packets;
91- sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
92-
93 sinfo->tx_failed = msta->wcid.stats.tx_failed;
94 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
95
developerbbd45e12023-05-19 08:22:06 +080096@@ -1134,6 +1131,11 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer33554a22023-01-30 14:11:29 +080097 }
98 }
99
100+ if (!mt7915_mcu_get_tx_stat_wa(phy->dev, msta->wcid.idx)) {
101+ sinfo->tx_packets = msta->wcid.stats.tx_packets;
102+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
103+ }
104+
105 sinfo->ack_signal = (s8)msta->ack_signal;
106 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
107
108diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerbbd45e12023-05-19 08:22:06 +0800109index 3b0ba5c..c27b8f9 100644
developer33554a22023-01-30 14:11:29 +0800110--- a/mt7915/mcu.c
111+++ b/mt7915/mcu.c
developerbbd45e12023-05-19 08:22:06 +0800112@@ -172,7 +172,9 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
developer33554a22023-01-30 14:11:29 +0800113 }
114
115 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
116- if (seq != rxd->seq)
117+
118+ if (seq != rxd->seq &&
119+ !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
120 return -EAGAIN;
121
122 if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) {
developerbbd45e12023-05-19 08:22:06 +0800123@@ -424,13 +426,14 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
developer33554a22023-01-30 14:11:29 +0800124 struct mt76_connac2_mcu_rxd *rxd;
125
126 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
127- if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
128+ if ((rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
129 rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST ||
130 rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
131 rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
132 rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
133 rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ ||
134- !rxd->seq)
135+ !rxd->seq) &&
136+ !(rxd->eid == MCU_CMD_EXT_CID && rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
137 mt7915_mcu_rx_unsolicited_event(dev, skb);
138 else
139 mt76_mcu_rx_event(&dev->mt76, skb);
developerbbd45e12023-05-19 08:22:06 +0800140@@ -4139,7 +4142,7 @@ int mt7915_mcu_get_tx_rate_v2(struct mt7915_phy *phy, u16 wcidx)
developer5bea7322023-04-13 18:50:55 +0800141 };
142
143 ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
144- &req, sizeof(req), true, &skb);
145+ &req, sizeof(req), true, &skb);
146 if (ret)
147 return ret;
148
developerbbd45e12023-05-19 08:22:06 +0800149@@ -4174,6 +4177,53 @@ int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx)
developerf4b11c42023-04-28 11:44:16 +0800150 return mt7915_mcu_get_tx_rate_v2(phy, wcidx);
developer33554a22023-01-30 14:11:29 +0800151 }
152
153+int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wlan_idx)
154+{
155+ struct {
156+ __le32 cmd;
157+ __le32 num;
158+ __le32 __rsv;
159+ __le16 wlan_idx;
160+ } req = {
161+ .cmd = cpu_to_le32(MCU_WA_QUERY_GET_TX_STAT),
162+ .num = cpu_to_le32(1),
163+ .wlan_idx = cpu_to_le16(wlan_idx),
164+ };
165+ struct mt7915_mcu_wa_tx_stat *res;
166+ struct mt76_wcid *wcid;
167+ struct sk_buff *skb;
168+ int ret;
169+
170+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY),
171+ &req, sizeof(req), true, &skb);
172+ if (ret)
173+ return ret;
174+
175+ if (!is_mt7915(&dev->mt76))
176+ skb_pull(skb, 4);
177+
178+ res = (struct mt7915_mcu_wa_tx_stat *)skb->data;
179+
180+ if (le16_to_cpu(res->wlan_idx) != wlan_idx) {
181+ ret = -EINVAL;
182+ goto out;
183+ }
184+
185+ rcu_read_lock();
186+
187+ wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
188+ if (wcid)
189+ wcid->stats.tx_packets += le32_to_cpu(res->tx_msdu_cnt);
190+ else
191+ ret = -EINVAL;
192+
193+ rcu_read_unlock();
194+out:
195+ dev_kfree_skb(skb);
196+
197+ return ret;
198+}
199+
200 int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif,
201 struct cfg80211_he_bss_color *he_bss_color)
202 {
203diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developerbbd45e12023-05-19 08:22:06 +0800204index c533a7d..eca028b 100644
developer33554a22023-01-30 14:11:29 +0800205--- a/mt7915/mcu.h
206+++ b/mt7915/mcu.h
developerf4b11c42023-04-28 11:44:16 +0800207@@ -347,6 +347,17 @@ enum {
developer33554a22023-01-30 14:11:29 +0800208 MCU_WA_PARAM_RED_SETTING = 0x40,
209 };
210
211+enum {
212+ MCU_WA_QUERY_GET_TX_STAT = 0x15,
213+};
214+
215+struct mt7915_mcu_wa_tx_stat {
216+ __le16 wlan_idx;
217+ u8 __rsv2[2];
218+ __le32 tx_bytes;
219+ __le32 tx_msdu_cnt;
220+};
221+
222 enum mcu_mmps_mode {
223 MCU_MMPS_STATIC,
224 MCU_MMPS_DYNAMIC,
225diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerbbd45e12023-05-19 08:22:06 +0800226index 646f3e8..ef9b0e1 100644
developer33554a22023-01-30 14:11:29 +0800227--- a/mt7915/mt7915.h
228+++ b/mt7915/mt7915.h
developerbbd45e12023-05-19 08:22:06 +0800229@@ -714,6 +714,7 @@ int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy);
developer5bea7322023-04-13 18:50:55 +0800230 int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx);
developer33554a22023-01-30 14:11:29 +0800231 int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
232 struct ieee80211_sta *sta, struct rate_info *rate);
233+int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wcid);
234 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
235 struct cfg80211_chan_def *chandef);
236 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
237--
developer2324aa22023-04-12 11:30:15 +08002382.18.0
developer33554a22023-01-30 14:11:29 +0800239