blob: 482d43ac592c3ba5949671ef20e4c66c2aca5305 [file] [log] [blame]
developer2157bf82023-06-26 02:27:49 +08001From 558ea0b82f413e4774e1357e4bb5717fb3bd81a0 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
developer2157bf82023-06-26 02:27:49 +08004Subject: [PATCH 2006/2009] 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
developer2157bf82023-06-26 02:27:49 +080018index 6c488bd..a02d304 100644
developer33554a22023-01-30 14:11:29 +080019--- a/mt76.h
20+++ b/mt76.h
developer2157bf82023-06-26 02:27:49 +080021@@ -297,6 +297,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
developer2157bf82023-06-26 02:27:49 +080030index ee5177f..5edf912 100644
developer33554a22023-01-30 14:11:29 +080031--- a/mt76_connac_mac.c
32+++ b/mt76_connac_mac.c
developer2157bf82023-06-26 02:27:49 +080033@@ -614,8 +614,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
developer2157bf82023-06-26 02:27:49 +080043index 1257dfa..cfdee7c 100644
developer33554a22023-01-30 14:11:29 +080044--- a/mt76_connac_mcu.h
45+++ b/mt76_connac_mcu.h
developer2157bf82023-06-26 02:27:49 +080046@@ -1162,6 +1162,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
developer2157bf82023-06-26 02:27:49 +080055index 7b34162..5db7e6a 100644
developer33554a22023-01-30 14:11:29 +080056--- a/mt7915/main.c
57+++ b/mt7915/main.c
developer2157bf82023-06-26 02:27:49 +080058@@ -1155,12 +1155,14 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
59 }
60 }
developer33554a22023-01-30 14:11:29 +080061
developer2157bf82023-06-26 02:27:49 +080062- sinfo->tx_failed = msta->wcid.stats.tx_failed;
63- sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
developer33554a22023-01-30 14:11:29 +080064-
developer2157bf82023-06-26 02:27:49 +080065 sinfo->tx_retries = msta->wcid.stats.tx_retries;
66 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
developer33554a22023-01-30 14:11:29 +080067
68+ if (!mt7915_get_tx_stat(phy, msta->wcid.idx)) {
69+ sinfo->tx_failed = msta->wcid.stats.tx_failed;
70+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
71+ }
72+
73 sinfo->ack_signal = (s8)msta->ack_signal;
74 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
75
76diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer2157bf82023-06-26 02:27:49 +080077index 7472825..26d2964 100644
developer33554a22023-01-30 14:11:29 +080078--- a/mt7915/mcu.c
79+++ b/mt7915/mcu.c
developer2157bf82023-06-26 02:27:49 +080080@@ -4214,6 +4214,114 @@ int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx)
81 return mt7915_mcu_get_tx_rate_v2(phy, wcidx);
developer33554a22023-01-30 14:11:29 +080082 }
83
84+static int mt7915_mcu_get_tx_stat_v1(struct mt7915_phy *phy,
85+ u16 wlan_idx)
86+{
87+#define to_wcid(hi, lo) (hi << 8 | lo)
88+ struct mt7915_dev *dev = phy->dev;
89+ struct mt76_phy *mphy = phy->mt76;
90+ struct mt7915_mcu_tx_stat_v1 *res;
91+ struct mt76_wcid *wcid;
92+ struct sk_buff *skb;
93+ struct {
94+ __le32 category;
95+ u8 wlan_idx_lo;
96+ u8 band;
97+ u8 wlan_idx_hi;
98+ u8 __rsv[5];
99+ } __packed req = {
100+ .category = cpu_to_le32(MCU_GET_TX_STAT_CNT),
101+ .band = mphy->band_idx,
102+ .wlan_idx_lo = to_wcid_lo(wlan_idx),
103+ .wlan_idx_hi = to_wcid_hi(wlan_idx),
104+ };
105+ int ret;
106+
107+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
108+ &req, sizeof(req), true, &skb);
109+ if (ret)
110+ return ret;
111+
112+ res = (struct mt7915_mcu_tx_stat_v1 *)skb->data;
113+
114+ if (to_wcid(res->wlan_idx_hi, res->wlan_idx_lo) != wlan_idx) {
115+ ret = -EINVAL;
116+ goto out;
117+ }
118+
119+ rcu_read_lock();
120+
121+ wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
122+ if (wcid) {
123+ wcid->stats.tx_mpdu_cnt += le32_to_cpu(res->tx_cnt);
124+ wcid->stats.tx_failed += le32_to_cpu(res->tx_failed);
125+ } else {
126+ ret = -EINVAL;
127+ }
128+
129+ rcu_read_unlock();
130+out:
131+ dev_kfree_skb(skb);
132+
133+ return ret;
134+}
135+
136+static int mt7915_mcu_get_tx_stat_v2(struct mt7915_phy *phy,
137+ u16 wlan_idx)
138+{
139+ struct mt7915_dev *dev = phy->dev;
140+ struct mt76_phy *mphy = phy->mt76;
141+ struct mt7915_mcu_tx_stat_v2 *res;
142+ struct mt76_wcid *wcid;
143+ struct sk_buff *skb;
144+ struct {
145+ u8 category;
146+ u8 band;
147+ __le16 wcid;
148+ } __packed req = {
149+ .category = MCU_GET_TX_STAT_CNT,
150+ .band = mphy->band_idx,
151+ .wcid = cpu_to_le16(wlan_idx),
152+ };
153+ int ret;
154+
155+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
156+ &req, sizeof(req), true, &skb);
157+ if (ret)
158+ return ret;
159+
160+ res = (struct mt7915_mcu_tx_stat_v2 *)skb->data;
161+
162+ if (le16_to_cpu(res->wlan_idx) != wlan_idx) {
163+ ret = -EINVAL;
164+ goto out;
165+ }
166+
167+ rcu_read_lock();
168+
169+ wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
170+ if (wcid) {
171+ wcid->stats.tx_mpdu_cnt += le32_to_cpu(res->tx_cnt);
172+ wcid->stats.tx_failed += le32_to_cpu(res->tx_failed);
173+ } else {
174+ ret = -EINVAL;
175+ }
176+
177+ rcu_read_unlock();
178+out:
179+ dev_kfree_skb(skb);
180+
181+ return ret;
182+}
183+
184+int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx)
185+{
186+ if (is_mt7915(&phy->dev->mt76))
187+ return mt7915_mcu_get_tx_stat_v1(phy, wlan_idx);
188+
189+ return mt7915_mcu_get_tx_stat_v2(phy, wlan_idx);
190+}
191+
192 int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif,
193 struct cfg80211_he_bss_color *he_bss_color)
194 {
195diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer2157bf82023-06-26 02:27:49 +0800196index 82b0847..d684979 100644
developer33554a22023-01-30 14:11:29 +0800197--- a/mt7915/mcu.h
198+++ b/mt7915/mcu.h
developer2157bf82023-06-26 02:27:49 +0800199@@ -790,7 +790,8 @@ mt7915_get_power_bound(struct mt7915_phy *phy, s8 txpower)
developer5bea7322023-04-13 18:50:55 +0800200 }
201
202 enum {
203- MCU_GET_TX_RATE = 4
204+ MCU_GET_TX_RATE = 4,
205+ MCU_GET_TX_STAT_CNT = 8
206 };
207
208 #ifdef CONFIG_MTK_VENDOR
developer2157bf82023-06-26 02:27:49 +0800209@@ -1069,6 +1070,24 @@ struct mt7915_muru {
developer33554a22023-01-30 14:11:29 +0800210 /* DL&UL User config */
211 #define MURU_USER_CNT BIT(4)
212
213+struct mt7915_mcu_tx_stat_v1 {
214+ u8 wlan_idx_lo;
215+ u8 band_idx;
216+ u8 wlan_idx_hi;
217+ u8 __rsv1[29];
218+ __le32 tx_cnt;
219+ __le32 tx_failed;
220+ u8 __rsv2[26];
221+};
222+
223+struct mt7915_mcu_tx_stat_v2 {
224+ u8 __rsv1[4];
225+ __le16 wlan_idx;
226+ u8 __rsv2[2];
227+ __le32 tx_cnt;
228+ __le32 tx_failed;
229+};
230+
developer33554a22023-01-30 14:11:29 +0800231 enum {
232 CAPI_SU,
233 CAPI_MU,
234diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer2157bf82023-06-26 02:27:49 +0800235index 0153e5f..85c5c95 100644
developer33554a22023-01-30 14:11:29 +0800236--- a/mt7915/mt7915.h
237+++ b/mt7915/mt7915.h
developer2157bf82023-06-26 02:27:49 +0800238@@ -661,6 +661,7 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
developer33554a22023-01-30 14:11:29 +0800239 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
240 struct cfg80211_chan_def *chandef);
developer2157bf82023-06-26 02:27:49 +0800241 int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid);
242+int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx);
developer33554a22023-01-30 14:11:29 +0800243 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
developer2157bf82023-06-26 02:27:49 +0800244 int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
245 int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
developer33554a22023-01-30 14:11:29 +0800246--
developer2324aa22023-04-12 11:30:15 +08002472.18.0
developer33554a22023-01-30 14:11:29 +0800248