blob: efb183d3e612e6b48e61911cdcbad61d17070ad7 [file] [log] [blame]
developer1f55fcf2024-10-17 14:52:33 +08001From 1fbcac2b37824b62ebbd3c1e6d8dd00e7d3d585f Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Mon, 10 Jul 2023 11:47:29 +0800
developer1f55fcf2024-10-17 14:52:33 +08004Subject: [PATCH 028/193] mtk: mt76: mt7996: add support spatial reuse debug
developer05f3b2b2024-08-19 19:17:34 +08005 commands
developer66e89bc2024-04-23 14:50:01 +08006
7This commit adds the following debug commands in debugfs:
81. sr_enable: enable/disable spatial reuse feature. Default is on.
92. sr_enhanced_enable: enable/disable enhanced spatial reuse feature.
10Default is on. This feature is mtk proprietary feature.
113. sr_stats: Check the Spatial reuse tx statistics.
124. sr_scene_cond: Check the result of mtk scene detection algorithm. Mtk
13scene detection algorithm in firmware may decide whether current
14environment can SR Tx or not.
15
16To learn more details of these commands, please check:
17https://wiki.mediatek.inc/display/APKB/mt76+Phy+feature+debug+Cheetsheet#mt76PhyfeaturedebugCheetsheet-SpatialReuse
developer05f3b2b2024-08-19 19:17:34 +080018
developerd0c89452024-10-11 16:53:27 +080019Change-Id: I5bf83013ea2788dfc93caaaef08486a4f97a3649
developer66e89bc2024-04-23 14:50:01 +080020---
21 mt76_connac_mcu.h | 1 +
22 mt7996/main.c | 6 +++
23 mt7996/mcu.c | 8 ++++
24 mt7996/mt7996.h | 6 +++
25 mt7996/mtk_debugfs.c | 82 ++++++++++++++++++++++++++++++++
26 mt7996/mtk_mcu.c | 111 +++++++++++++++++++++++++++++++++++++++++++
27 mt7996/mtk_mcu.h | 56 ++++++++++++++++++++++
28 7 files changed, 270 insertions(+)
29
30diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer1f55fcf2024-10-17 14:52:33 +080031index e9afc27..dd63d4a 100644
developer66e89bc2024-04-23 14:50:01 +080032--- a/mt76_connac_mcu.h
33+++ b/mt76_connac_mcu.h
developerd0c89452024-10-11 16:53:27 +080034@@ -1056,6 +1056,7 @@ enum {
developer66e89bc2024-04-23 14:50:01 +080035 MCU_UNI_EVENT_BSS_BEACON_LOSS = 0x0c,
36 MCU_UNI_EVENT_SCAN_DONE = 0x0e,
37 MCU_UNI_EVENT_RDD_REPORT = 0x11,
38+ MCU_UNI_EVENT_SR = 0x25,
39 MCU_UNI_EVENT_ROC = 0x27,
40 MCU_UNI_EVENT_TX_DONE = 0x2d,
41 MCU_UNI_EVENT_BF = 0x33,
42diff --git a/mt7996/main.c b/mt7996/main.c
developer1f55fcf2024-10-17 14:52:33 +080043index 915b86e..359ea91 100644
developer66e89bc2024-04-23 14:50:01 +080044--- a/mt7996/main.c
45+++ b/mt7996/main.c
46@@ -6,6 +6,9 @@
47 #include "mt7996.h"
48 #include "mcu.h"
49 #include "mac.h"
50+#ifdef CONFIG_MTK_DEBUG
51+#include "mtk_mcu.h"
52+#endif
53
54 static bool mt7996_dev_running(struct mt7996_dev *dev)
55 {
56@@ -86,6 +89,9 @@ int mt7996_run(struct ieee80211_hw *hw)
57 goto out;
58
59 #ifdef CONFIG_MTK_DEBUG
60+ phy->sr_enable = true;
61+ phy->enhanced_sr_enable = true;
62+
63 ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL,
64 dev->dbg.sku_disable ? 0 : phy->sku_limit_en);
65
66diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developer1f55fcf2024-10-17 14:52:33 +080067index f451bf5..febd004 100644
developer66e89bc2024-04-23 14:50:01 +080068--- a/mt7996/mcu.c
69+++ b/mt7996/mcu.c
developerd0c89452024-10-11 16:53:27 +080070@@ -727,6 +727,14 @@ mt7996_mcu_uni_rx_unsolicited_event(struct mt7996_dev *dev, struct sk_buff *skb)
developer66e89bc2024-04-23 14:50:01 +080071 case MCU_UNI_EVENT_WED_RRO:
72 mt7996_mcu_wed_rro_event(dev, skb);
73 break;
74+#ifdef CONFIG_MTK_DEBUG
75+ case MCU_UNI_EVENT_SR:
76+ mt7996_mcu_rx_sr_event(dev, skb);
77+ break;
78+#endif
79+ case MCU_UNI_EVENT_THERMAL:
80+ mt7996_mcu_rx_thermal_notify(dev, skb);
81+ break;
82 #ifdef CONFIG_NL80211_TESTMODE
83 case MCU_UNI_EVENT_TESTMODE_CTRL:
84 mt7996_tm_rf_test_event(dev, skb);
85diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer1f55fcf2024-10-17 14:52:33 +080086index c011e8e..356935b 100644
developer66e89bc2024-04-23 14:50:01 +080087--- a/mt7996/mt7996.h
88+++ b/mt7996/mt7996.h
developerd0c89452024-10-11 16:53:27 +080089@@ -366,6 +366,10 @@ struct mt7996_phy {
developer66e89bc2024-04-23 14:50:01 +080090 spinlock_t amnt_lock;
91 struct mt7996_air_monitor_ctrl amnt_ctrl;
92 #endif
93+#ifdef CONFIG_MTK_DEBUG
94+ bool sr_enable:1;
95+ bool enhanced_sr_enable:1;
96+#endif
97 };
98
99 struct mt7996_dev {
developerd0c89452024-10-11 16:53:27 +0800100@@ -838,6 +842,8 @@ enum edcca_bw_id {
developer66e89bc2024-04-23 14:50:01 +0800101 #ifdef CONFIG_MTK_DEBUG
102 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir);
103 int mt7996_mcu_muru_dbg_info(struct mt7996_dev *dev, u16 item, u8 val);
104+int mt7996_mcu_set_sr_enable(struct mt7996_phy *phy, u8 action, u64 val, bool set);
105+void mt7996_mcu_rx_sr_event(struct mt7996_dev *dev, struct sk_buff *skb);
106 #endif
107
108 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
109diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developer1f55fcf2024-10-17 14:52:33 +0800110index 60ec6bd..13ea627 100644
developer66e89bc2024-04-23 14:50:01 +0800111--- a/mt7996/mtk_debugfs.c
112+++ b/mt7996/mtk_debugfs.c
developerd0c89452024-10-11 16:53:27 +0800113@@ -2834,6 +2834,83 @@ static int mt7996_show_eeprom_mode(struct seq_file *s, void *data)
developer66e89bc2024-04-23 14:50:01 +0800114 return 0;
115 }
116
117+static int
118+mt7996_sr_enable_get(void *data, u64 *val)
119+{
120+ struct mt7996_phy *phy = data;
121+
122+ *val = phy->sr_enable;
123+
124+ return 0;
125+}
126+
127+static int
128+mt7996_sr_enable_set(void *data, u64 val)
129+{
130+ struct mt7996_phy *phy = data;
131+ int ret;
132+
133+ if (!!val == phy->sr_enable)
134+ return 0;
135+
136+ ret = mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_CFG_SR_ENABLE, val, true);
137+ if (ret)
138+ return ret;
139+
140+ return mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_CFG_SR_ENABLE, 0, false);
141+}
142+DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enable, mt7996_sr_enable_get,
143+ mt7996_sr_enable_set, "%lld\n");
144+static int
145+mt7996_sr_enhanced_enable_get(void *data, u64 *val)
146+{
147+ struct mt7996_phy *phy = data;
148+
149+ *val = phy->enhanced_sr_enable;
150+
151+ return 0;
152+}
153+
154+static int
155+mt7996_sr_enhanced_enable_set(void *data, u64 val)
156+{
157+ struct mt7996_phy *phy = data;
158+ int ret;
159+
160+ if (!!val == phy->enhanced_sr_enable)
161+ return 0;
162+
163+ ret = mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_ENHANCE_SR_ENABLE, val, true);
164+ if (ret)
165+ return ret;
166+
167+ return mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_ENHANCE_SR_ENABLE, 0, false);
168+}
169+DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enhanced_enable, mt7996_sr_enhanced_enable_get,
170+ mt7996_sr_enhanced_enable_set, "%lld\n");
171+
172+static int
173+mt7996_sr_stats_show(struct seq_file *file, void *data)
174+{
175+ struct mt7996_phy *phy = file->private;
176+
177+ mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_IND, 0, false);
178+
179+ return 0;
180+}
181+DEFINE_SHOW_ATTRIBUTE(mt7996_sr_stats);
182+
183+static int
184+mt7996_sr_scene_cond_show(struct seq_file *file, void *data)
185+{
186+ struct mt7996_phy *phy = file->private;
187+
188+ mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_SW_SD, 0, false);
189+
190+ return 0;
191+}
192+DEFINE_SHOW_ATTRIBUTE(mt7996_sr_scene_cond);
193+
194 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
195 {
196 struct mt7996_dev *dev = phy->dev;
developerd0c89452024-10-11 16:53:27 +0800197@@ -2914,6 +2991,11 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
developer66e89bc2024-04-23 14:50:01 +0800198 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
199 debugfs_create_file("scs_enable", 0200, dir, phy, &fops_scs_enable);
200
201+ debugfs_create_file("sr_enable", 0600, dir, phy, &fops_sr_enable);
202+ debugfs_create_file("sr_enhanced_enable", 0600, dir, phy, &fops_sr_enhanced_enable);
203+ debugfs_create_file("sr_stats", 0400, dir, phy, &mt7996_sr_stats_fops);
204+ debugfs_create_file("sr_scene_cond", 0400, dir, phy, &mt7996_sr_scene_cond_fops);
205+
206 return 0;
207 }
208
209diff --git a/mt7996/mtk_mcu.c b/mt7996/mtk_mcu.c
developer1f55fcf2024-10-17 14:52:33 +0800210index 5c54d02..dbdf8d8 100644
developer66e89bc2024-04-23 14:50:01 +0800211--- a/mt7996/mtk_mcu.c
212+++ b/mt7996/mtk_mcu.c
213@@ -146,4 +146,115 @@ int mt7996_mcu_edcca_threshold_ctrl(struct mt7996_phy *phy, u8 *value, bool set)
214 return 0;
215 }
216
217+int mt7996_mcu_set_sr_enable(struct mt7996_phy *phy, u8 action, u64 val, bool set)
218+{
219+ struct {
220+ u8 band_idx;
221+ u8 _rsv[3];
222+
223+ __le16 tag;
224+ __le16 len;
225+
226+ __le32 val;
227+
228+ } __packed req = {
229+ .band_idx = phy->mt76->band_idx,
230+
231+ .tag = cpu_to_le16(action),
232+ .len = cpu_to_le16(sizeof(req) - 4),
233+
234+ .val = cpu_to_le32((u32) val),
235+ };
236+
237+ if (set)
238+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(SR), &req,
239+ sizeof(req), false);
240+ else
241+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD_QUERY(SR), &req,
242+ sizeof(req), false);
243+}
244+
245+void mt7996_mcu_rx_sr_swsd(struct mt7996_dev *dev, struct sk_buff *skb)
246+{
247+#define SR_SCENE_DETECTION_TIMER_PERIOD_MS 500
248+ struct mt7996_mcu_sr_swsd_event *event;
249+ static const char * const rules[] = {"1 - NO CONNECTED", "2 - NO CONGESTION",
250+ "3 - NO INTERFERENCE", "4 - SR ON"};
251+ u8 idx;
252+
253+ event = (struct mt7996_mcu_sr_swsd_event *)skb->data;
254+ idx = event->basic.band_idx;
255+
256+ dev_info(dev->mt76.dev, "Band index = %u\n", le16_to_cpu(event->basic.band_idx));
257+ dev_info(dev->mt76.dev, "Hit Rule = %s\n", rules[event->tlv[idx].rule]);
258+ dev_info(dev->mt76.dev, "Timer Period = %d(us)\n"
259+ "Congestion Ratio = %d.%1d%%\n",
260+ SR_SCENE_DETECTION_TIMER_PERIOD_MS * 1000,
261+ le32_to_cpu(event->tlv[idx].total_airtime_ratio) / 10,
262+ le32_to_cpu(event->tlv[idx].total_airtime_ratio) % 10);
263+ dev_info(dev->mt76.dev,
264+ "Total Airtime = %d(us)\n"
265+ "ChBusy = %d\n"
266+ "SrTx = %d\n"
267+ "OBSS = %d\n"
268+ "MyTx = %d\n"
269+ "MyRx = %d\n"
270+ "Interference Ratio = %d.%1d%%\n",
271+ le32_to_cpu(event->tlv[idx].total_airtime),
272+ le32_to_cpu(event->tlv[idx].channel_busy_time),
273+ le32_to_cpu(event->tlv[idx].sr_tx_airtime),
274+ le32_to_cpu(event->tlv[idx].obss_airtime),
275+ le32_to_cpu(event->tlv[idx].my_tx_airtime),
276+ le32_to_cpu(event->tlv[idx].my_rx_airtime),
277+ le32_to_cpu(event->tlv[idx].obss_airtime_ratio) / 10,
278+ le32_to_cpu(event->tlv[idx].obss_airtime_ratio) % 10);
279+}
280+
281+void mt7996_mcu_rx_sr_hw_indicator(struct mt7996_dev *dev, struct sk_buff *skb)
282+{
283+ struct mt7996_mcu_sr_hw_ind_event *event;
284+
285+ event = (struct mt7996_mcu_sr_hw_ind_event *)skb->data;
286+
287+ dev_info(dev->mt76.dev, "Inter PPDU Count = %u\n",
288+ le16_to_cpu(event->inter_bss_ppdu_cnt));
289+ dev_info(dev->mt76.dev, "SR Valid Count = %u\n",
290+ le16_to_cpu(event->non_srg_valid_cnt));
291+ dev_info(dev->mt76.dev, "SR Tx Count = %u\n",
292+ le32_to_cpu(event->sr_ampdu_mpdu_cnt));
293+ dev_info(dev->mt76.dev, "SR Tx Acked Count = %u\n",
294+ le32_to_cpu(event->sr_ampdu_mpdu_acked_cnt));
295+}
296+
297+void mt7996_mcu_rx_sr_event(struct mt7996_dev *dev, struct sk_buff *skb)
298+{
299+ struct mt76_phy *mphy = &dev->mt76.phy;
300+ struct mt7996_phy *phy;
301+ struct mt7996_mcu_sr_common_event *event;
302+
303+ event = (struct mt7996_mcu_sr_common_event *)skb->data;
304+ mphy = dev->mt76.phys[event->basic.band_idx];
305+ if (!mphy)
306+ return;
307+
308+ phy = (struct mt7996_phy *)mphy->priv;
309+
310+ switch (le16_to_cpu(event->basic.tag)) {
311+ case UNI_EVENT_SR_CFG_SR_ENABLE:
312+ phy->sr_enable = le32_to_cpu(event->value) ? true : false;
313+ break;
314+ case UNI_EVENT_SR_HW_ESR_ENABLE:
315+ phy->enhanced_sr_enable = le32_to_cpu(event->value) ? true : false;
316+ break;
317+ case UNI_EVENT_SR_SW_SD:
318+ mt7996_mcu_rx_sr_swsd(dev, skb);
319+ break;
320+ case UNI_EVENT_SR_HW_IND:
321+ mt7996_mcu_rx_sr_hw_indicator(dev, skb);
322+ break;
323+ default:
324+ dev_info(dev->mt76.dev, "Unknown SR event tag %d\n",
325+ le16_to_cpu(event->basic.tag));
326+ }
327+}
328 #endif
329diff --git a/mt7996/mtk_mcu.h b/mt7996/mtk_mcu.h
developer1f55fcf2024-10-17 14:52:33 +0800330index 36a58ad..098e63a 100644
developer66e89bc2024-04-23 14:50:01 +0800331--- a/mt7996/mtk_mcu.h
332+++ b/mt7996/mtk_mcu.h
333@@ -121,6 +121,62 @@ enum {
334 EDCCA_JAPAN = 3
335 };
336
337+enum {
338+ UNI_EVENT_SR_CFG_SR_ENABLE = 0x1,
339+ UNI_EVENT_SR_SW_SD = 0x83,
340+ UNI_EVENT_SR_HW_IND = 0xC9,
341+ UNI_EVENT_SR_HW_ESR_ENABLE = 0xD8,
342+};
343+enum {
344+ UNI_CMD_SR_CFG_SR_ENABLE = 0x1,
345+ UNI_CMD_SR_SW_SD = 0x84,
346+ UNI_CMD_SR_HW_IND = 0xCB,
347+ UNI_CMD_SR_HW_ENHANCE_SR_ENABLE = 0xDA,
348+};
349+
350+struct mt7996_mcu_sr_basic_event {
351+ struct mt7996_mcu_rxd rxd;
352+
353+ u8 band_idx;
354+ u8 _rsv[3];
355+
356+ __le16 tag;
357+ __le16 len;
358+};
359+
360+struct sr_sd_tlv {
361+ u8 _rsv[16];
362+ __le32 sr_tx_airtime;
363+ __le32 obss_airtime;
364+ __le32 my_tx_airtime;
365+ __le32 my_rx_airtime;
366+ __le32 channel_busy_time;
367+ __le32 total_airtime;
368+ __le32 total_airtime_ratio;
369+ __le32 obss_airtime_ratio;
370+ u8 rule;
371+ u8 _rsv2[59];
372+} __packed;
373+
374+struct mt7996_mcu_sr_swsd_event {
375+ struct mt7996_mcu_sr_basic_event basic;
376+ struct sr_sd_tlv tlv[3];
377+} __packed;
378+
379+struct mt7996_mcu_sr_common_event {
380+ struct mt7996_mcu_sr_basic_event basic;
381+ __le32 value;
382+};
383+
384+struct mt7996_mcu_sr_hw_ind_event {
385+ struct mt7996_mcu_sr_basic_event basic;
386+ __le16 non_srg_valid_cnt;
387+ u8 _rsv[4];
388+ __le16 inter_bss_ppdu_cnt;
389+ u8 _rsv2[4];
390+ __le32 sr_ampdu_mpdu_cnt;
391+ __le32 sr_ampdu_mpdu_acked_cnt;
392+};
393 #endif
394
395 #endif
396--
developerd0c89452024-10-11 16:53:27 +08003972.45.2
developer66e89bc2024-04-23 14:50:01 +0800398