blob: 9e29a408b14d7e38d65a06e87ff06f18b3b5b8cc [file] [log] [blame]
developerbbd45e12023-05-19 08:22:06 +08001From 7624f0f425a72927b29178227f92d9bb88d5202c Mon Sep 17 00:00:00 2001
developer33554a22023-01-30 14:11:29 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Wed, 11 Jan 2023 10:56:27 +0800
developerbbd45e12023-05-19 08:22:06 +08004Subject: [PATCH 3007/3012] wifi: mt76: get tx count and tx failed from mcu
developer33554a22023-01-30 14:11:29 +08005 command
6
7---
8 mt76.h | 1 +
9 mt76_connac_mac.c | 2 -
10 mt76_connac_mcu.h | 1 +
11 mt7915/main.c | 8 ++--
12 mt7915/mcu.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++
developer5bea7322023-04-13 18:50:55 +080013 mt7915/mcu.h | 21 ++++++++-
developer33554a22023-01-30 14:11:29 +080014 mt7915/mt7915.h | 1 +
developer5bea7322023-04-13 18:50:55 +080015 7 files changed, 136 insertions(+), 6 deletions(-)
developer33554a22023-01-30 14:11:29 +080016
17diff --git a/mt76.h b/mt76.h
developerbbd45e12023-05-19 08:22:06 +080018index 4794b6a..e0bb41e 100644
developer33554a22023-01-30 14:11:29 +080019--- a/mt76.h
20+++ b/mt76.h
developer5bea7322023-04-13 18:50:55 +080021@@ -289,6 +289,7 @@ struct mt76_sta_stats {
developer33554a22023-01-30 14:11:29 +080022 u64 tx_bytes;
23 /* WED TX */
24 u32 tx_packets; /* unit: MSDU */
25+ u32 tx_mpdu_cnt;
26 u32 tx_retries;
27 u32 tx_failed;
28 /* WED RX */
29diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c
developerbbd45e12023-05-19 08:22:06 +080030index ee37fe5..6cd8c27 100644
developer33554a22023-01-30 14:11:29 +080031--- a/mt76_connac_mac.c
32+++ b/mt76_connac_mac.c
developerbbd45e12023-05-19 08:22:06 +080033@@ -612,8 +612,6 @@ bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
developer33554a22023-01-30 14:11:29 +080034 stats->tx_bytes +=
35 le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) -
36 le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE);
37- stats->tx_failed +=
38- le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT);
39 stats->tx_retries +=
40 le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_CNT);
developer4f0d84b2023-03-03 14:21:44 +080041
developer33554a22023-01-30 14:11:29 +080042diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developerbbd45e12023-05-19 08:22:06 +080043index 97d732a..b299a54 100644
developer33554a22023-01-30 14:11:29 +080044--- a/mt76_connac_mcu.h
45+++ b/mt76_connac_mcu.h
developer4f0d84b2023-03-03 14:21:44 +080046@@ -1160,6 +1160,7 @@ enum {
developer33554a22023-01-30 14:11:29 +080047 MCU_EXT_CMD_EDCA_UPDATE = 0x27,
48 MCU_EXT_CMD_DEV_INFO_UPDATE = 0x2A,
49 MCU_EXT_CMD_THERMAL_CTRL = 0x2c,
50+ MCU_EXT_CMD_GET_TX_STAT = 0x30,
51 MCU_EXT_CMD_WTBL_UPDATE = 0x32,
52 MCU_EXT_CMD_SET_DRR_CTRL = 0x36,
53 MCU_EXT_CMD_SET_FEATURE_CTRL = 0x38,
54diff --git a/mt7915/main.c b/mt7915/main.c
developerbbd45e12023-05-19 08:22:06 +080055index ccdb148..c377ef2 100644
developer33554a22023-01-30 14:11:29 +080056--- a/mt7915/main.c
57+++ b/mt7915/main.c
developerbbd45e12023-05-19 08:22:06 +080058@@ -1116,9 +1116,6 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer33554a22023-01-30 14:11:29 +080059 sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
60 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
61
62- sinfo->tx_failed = msta->wcid.stats.tx_failed;
63- sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
64-
65 sinfo->tx_retries = msta->wcid.stats.tx_retries;
66 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
67
developerbbd45e12023-05-19 08:22:06 +080068@@ -1136,6 +1133,11 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer33554a22023-01-30 14:11:29 +080069 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
70 }
71
72+ if (!mt7915_get_tx_stat(phy, msta->wcid.idx)) {
73+ sinfo->tx_failed = msta->wcid.stats.tx_failed;
74+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
75+ }
76+
77 sinfo->ack_signal = (s8)msta->ack_signal;
78 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
79
80diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerbbd45e12023-05-19 08:22:06 +080081index c27b8f9..2c6dddc 100644
developer33554a22023-01-30 14:11:29 +080082--- a/mt7915/mcu.c
83+++ b/mt7915/mcu.c
developerbbd45e12023-05-19 08:22:06 +080084@@ -4224,6 +4224,114 @@ out:
developer33554a22023-01-30 14:11:29 +080085 return ret;
86 }
87
88+static int mt7915_mcu_get_tx_stat_v1(struct mt7915_phy *phy,
89+ u16 wlan_idx)
90+{
91+#define to_wcid(hi, lo) (hi << 8 | lo)
92+ struct mt7915_dev *dev = phy->dev;
93+ struct mt76_phy *mphy = phy->mt76;
94+ struct mt7915_mcu_tx_stat_v1 *res;
95+ struct mt76_wcid *wcid;
96+ struct sk_buff *skb;
97+ struct {
98+ __le32 category;
99+ u8 wlan_idx_lo;
100+ u8 band;
101+ u8 wlan_idx_hi;
102+ u8 __rsv[5];
103+ } __packed req = {
104+ .category = cpu_to_le32(MCU_GET_TX_STAT_CNT),
105+ .band = mphy->band_idx,
106+ .wlan_idx_lo = to_wcid_lo(wlan_idx),
107+ .wlan_idx_hi = to_wcid_hi(wlan_idx),
108+ };
109+ int ret;
110+
111+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
112+ &req, sizeof(req), true, &skb);
113+ if (ret)
114+ return ret;
115+
116+ res = (struct mt7915_mcu_tx_stat_v1 *)skb->data;
117+
118+ if (to_wcid(res->wlan_idx_hi, res->wlan_idx_lo) != wlan_idx) {
119+ ret = -EINVAL;
120+ goto out;
121+ }
122+
123+ rcu_read_lock();
124+
125+ wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
126+ if (wcid) {
127+ wcid->stats.tx_mpdu_cnt += le32_to_cpu(res->tx_cnt);
128+ wcid->stats.tx_failed += le32_to_cpu(res->tx_failed);
129+ } else {
130+ ret = -EINVAL;
131+ }
132+
133+ rcu_read_unlock();
134+out:
135+ dev_kfree_skb(skb);
136+
137+ return ret;
138+}
139+
140+static int mt7915_mcu_get_tx_stat_v2(struct mt7915_phy *phy,
141+ u16 wlan_idx)
142+{
143+ struct mt7915_dev *dev = phy->dev;
144+ struct mt76_phy *mphy = phy->mt76;
145+ struct mt7915_mcu_tx_stat_v2 *res;
146+ struct mt76_wcid *wcid;
147+ struct sk_buff *skb;
148+ struct {
149+ u8 category;
150+ u8 band;
151+ __le16 wcid;
152+ } __packed req = {
153+ .category = MCU_GET_TX_STAT_CNT,
154+ .band = mphy->band_idx,
155+ .wcid = cpu_to_le16(wlan_idx),
156+ };
157+ int ret;
158+
159+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
160+ &req, sizeof(req), true, &skb);
161+ if (ret)
162+ return ret;
163+
164+ res = (struct mt7915_mcu_tx_stat_v2 *)skb->data;
165+
166+ if (le16_to_cpu(res->wlan_idx) != wlan_idx) {
167+ ret = -EINVAL;
168+ goto out;
169+ }
170+
171+ rcu_read_lock();
172+
173+ wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
174+ if (wcid) {
175+ wcid->stats.tx_mpdu_cnt += le32_to_cpu(res->tx_cnt);
176+ wcid->stats.tx_failed += le32_to_cpu(res->tx_failed);
177+ } else {
178+ ret = -EINVAL;
179+ }
180+
181+ rcu_read_unlock();
182+out:
183+ dev_kfree_skb(skb);
184+
185+ return ret;
186+}
187+
188+int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx)
189+{
190+ if (is_mt7915(&phy->dev->mt76))
191+ return mt7915_mcu_get_tx_stat_v1(phy, wlan_idx);
192+
193+ return mt7915_mcu_get_tx_stat_v2(phy, wlan_idx);
194+}
195+
196 int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif,
197 struct cfg80211_he_bss_color *he_bss_color)
198 {
199diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developerbbd45e12023-05-19 08:22:06 +0800200index eca028b..c712dbb 100644
developer33554a22023-01-30 14:11:29 +0800201--- a/mt7915/mcu.h
202+++ b/mt7915/mcu.h
developerbbd45e12023-05-19 08:22:06 +0800203@@ -797,7 +797,8 @@ mt7915_get_power_bound(struct mt7915_phy *phy, s8 txpower)
developer5bea7322023-04-13 18:50:55 +0800204 }
205
206 enum {
207- MCU_GET_TX_RATE = 4
208+ MCU_GET_TX_RATE = 4,
209+ MCU_GET_TX_STAT_CNT = 8
210 };
211
212 #ifdef CONFIG_MTK_VENDOR
developerbbd45e12023-05-19 08:22:06 +0800213@@ -1076,6 +1077,24 @@ struct mt7915_muru {
developer33554a22023-01-30 14:11:29 +0800214 /* DL&UL User config */
215 #define MURU_USER_CNT BIT(4)
216
217+struct mt7915_mcu_tx_stat_v1 {
218+ u8 wlan_idx_lo;
219+ u8 band_idx;
220+ u8 wlan_idx_hi;
221+ u8 __rsv1[29];
222+ __le32 tx_cnt;
223+ __le32 tx_failed;
224+ u8 __rsv2[26];
225+};
226+
227+struct mt7915_mcu_tx_stat_v2 {
228+ u8 __rsv1[4];
229+ __le16 wlan_idx;
230+ u8 __rsv2[2];
231+ __le32 tx_cnt;
232+ __le32 tx_failed;
233+};
234+
developer33554a22023-01-30 14:11:29 +0800235 enum {
236 CAPI_SU,
237 CAPI_MU,
238diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerbbd45e12023-05-19 08:22:06 +0800239index ef9b0e1..52cf748 100644
developer33554a22023-01-30 14:11:29 +0800240--- a/mt7915/mt7915.h
241+++ b/mt7915/mt7915.h
developerbbd45e12023-05-19 08:22:06 +0800242@@ -715,6 +715,7 @@ int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx);
developer33554a22023-01-30 14:11:29 +0800243 int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
244 struct ieee80211_sta *sta, struct rate_info *rate);
245 int mt7915_mcu_get_tx_stat_wa(struct mt7915_dev *dev, u16 wcid);
246+int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx);
247 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
248 struct cfg80211_chan_def *chandef);
249 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
250--
developer2324aa22023-04-12 11:30:15 +08002512.18.0
developer33554a22023-01-30 14:11:29 +0800252