blob: 142193f75d7edbd35907d10b62d900362730cee2 [file] [log] [blame]
developerbd9fa1e2023-10-16 11:04:00 +08001From 86906513b2597a79c26b72a6a9dc0ecf8b0ce1ed Mon Sep 17 00:00:00 2001
2From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Mon, 10 Jul 2023 11:47:29 +0800
4Subject: [PATCH 54/98] wifi: mt76: mt7996: add support spatial reuse debug
5 commands
6
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
18---
19 mt76_connac_mcu.h | 1 +
20 mt7996/main.c | 6 +++
21 mt7996/mcu.c | 5 ++
22 mt7996/mt7996.h | 6 +++
23 mt7996/mtk_debugfs.c | 82 ++++++++++++++++++++++++++++++++
24 mt7996/mtk_mcu.c | 111 +++++++++++++++++++++++++++++++++++++++++++
25 mt7996/mtk_mcu.h | 56 ++++++++++++++++++++++
26 7 files changed, 267 insertions(+)
27
28diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
29index 42eb64c..e904ebc 100644
30--- a/mt76_connac_mcu.h
31+++ b/mt76_connac_mcu.h
32@@ -1031,6 +1031,7 @@ enum {
33 MCU_UNI_EVENT_BSS_BEACON_LOSS = 0x0c,
34 MCU_UNI_EVENT_SCAN_DONE = 0x0e,
35 MCU_UNI_EVENT_RDD_REPORT = 0x11,
36+ MCU_UNI_EVENT_SR = 0x25,
37 MCU_UNI_EVENT_ROC = 0x27,
38 MCU_UNI_EVENT_TX_DONE = 0x2d,
39 MCU_UNI_EVENT_BF = 0x33,
40diff --git a/mt7996/main.c b/mt7996/main.c
41index d928564..35f8fee 100644
42--- a/mt7996/main.c
43+++ b/mt7996/main.c
44@@ -6,6 +6,9 @@
45 #include "mt7996.h"
46 #include "mcu.h"
47 #include "mac.h"
48+#ifdef CONFIG_MTK_DEBUG
49+#include "mtk_mcu.h"
50+#endif
51
52 static bool mt7996_dev_running(struct mt7996_dev *dev)
53 {
54@@ -78,6 +81,9 @@ int mt7996_run(struct ieee80211_hw *hw)
55 goto out;
56
57 #ifdef CONFIG_MTK_DEBUG
58+ phy->sr_enable = true;
59+ phy->enhanced_sr_enable = true;
60+
61 ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL,
62 !dev->dbg.sku_disable);
63 #else
64diff --git a/mt7996/mcu.c b/mt7996/mcu.c
65index 722c435..2dbec1e 100644
66--- a/mt7996/mcu.c
67+++ b/mt7996/mcu.c
68@@ -617,6 +617,11 @@ mt7996_mcu_uni_rx_unsolicited_event(struct mt7996_dev *dev, struct sk_buff *skb)
69 case MCU_UNI_EVENT_RDD_REPORT:
70 mt7996_mcu_rx_radar_detected(dev, skb);
71 break;
72+#ifdef CONFIG_MTK_DEBUG
73+ case MCU_UNI_EVENT_SR:
74+ mt7996_mcu_rx_sr_event(dev, skb);
75+ break;
76+#endif
77 case MCU_UNI_EVENT_THERMAL:
78 mt7996_mcu_rx_thermal_notify(dev, skb);
79 break;
80diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
81index 8fd29d7..1fac783 100644
82--- a/mt7996/mt7996.h
83+++ b/mt7996/mt7996.h
84@@ -306,6 +306,10 @@ struct mt7996_phy {
85 spinlock_t amnt_lock;
86 struct mt7996_air_monitor_ctrl amnt_ctrl;
87 #endif
88+#ifdef CONFIG_MTK_DEBUG
89+ bool sr_enable:1;
90+ bool enhanced_sr_enable:1;
91+#endif
92 };
93
94 struct mt7996_dev {
95@@ -763,6 +767,8 @@ enum edcca_bw_id {
96
97 #ifdef CONFIG_MTK_DEBUG
98 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir);
99+int mt7996_mcu_set_sr_enable(struct mt7996_phy *phy, u8 action, u64 val, bool set);
100+void mt7996_mcu_rx_sr_event(struct mt7996_dev *dev, struct sk_buff *skb);
101 #endif
102
103 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
104diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
105index 82b2785..f56ad88 100644
106--- a/mt7996/mtk_debugfs.c
107+++ b/mt7996/mtk_debugfs.c
108@@ -2589,6 +2589,83 @@ static int mt7996_show_eeprom_mode(struct seq_file *s, void *data)
109 return 0;
110 }
111
112+static int
113+mt7996_sr_enable_get(void *data, u64 *val)
114+{
115+ struct mt7996_phy *phy = data;
116+
117+ *val = phy->sr_enable;
118+
119+ return 0;
120+}
121+
122+static int
123+mt7996_sr_enable_set(void *data, u64 val)
124+{
125+ struct mt7996_phy *phy = data;
126+ int ret;
127+
128+ if (!!val == phy->sr_enable)
129+ return 0;
130+
131+ ret = mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_CFG_SR_ENABLE, val, true);
132+ if (ret)
133+ return ret;
134+
135+ return mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_CFG_SR_ENABLE, 0, false);
136+}
137+DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enable, mt7996_sr_enable_get,
138+ mt7996_sr_enable_set, "%lld\n");
139+static int
140+mt7996_sr_enhanced_enable_get(void *data, u64 *val)
141+{
142+ struct mt7996_phy *phy = data;
143+
144+ *val = phy->enhanced_sr_enable;
145+
146+ return 0;
147+}
148+
149+static int
150+mt7996_sr_enhanced_enable_set(void *data, u64 val)
151+{
152+ struct mt7996_phy *phy = data;
153+ int ret;
154+
155+ if (!!val == phy->enhanced_sr_enable)
156+ return 0;
157+
158+ ret = mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_ENHANCE_SR_ENABLE, val, true);
159+ if (ret)
160+ return ret;
161+
162+ return mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_ENHANCE_SR_ENABLE, 0, false);
163+}
164+DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enhanced_enable, mt7996_sr_enhanced_enable_get,
165+ mt7996_sr_enhanced_enable_set, "%lld\n");
166+
167+static int
168+mt7996_sr_stats_show(struct seq_file *file, void *data)
169+{
170+ struct mt7996_phy *phy = file->private;
171+
172+ mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_IND, 0, false);
173+
174+ return 0;
175+}
176+DEFINE_SHOW_ATTRIBUTE(mt7996_sr_stats);
177+
178+static int
179+mt7996_sr_scene_cond_show(struct seq_file *file, void *data)
180+{
181+ struct mt7996_phy *phy = file->private;
182+
183+ mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_SW_SD, 0, false);
184+
185+ return 0;
186+}
187+DEFINE_SHOW_ATTRIBUTE(mt7996_sr_scene_cond);
188+
189 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
190 {
191 struct mt7996_dev *dev = phy->dev;
192@@ -2642,6 +2719,11 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
193
194 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
195
196+ debugfs_create_file("sr_enable", 0600, dir, phy, &fops_sr_enable);
197+ debugfs_create_file("sr_enhanced_enable", 0600, dir, phy, &fops_sr_enhanced_enable);
198+ debugfs_create_file("sr_stats", 0400, dir, phy, &mt7996_sr_stats_fops);
199+ debugfs_create_file("sr_scene_cond", 0400, dir, phy, &mt7996_sr_scene_cond_fops);
200+
201 return 0;
202 }
203
204diff --git a/mt7996/mtk_mcu.c b/mt7996/mtk_mcu.c
205index 048c534..3256de7 100644
206--- a/mt7996/mtk_mcu.c
207+++ b/mt7996/mtk_mcu.c
208@@ -124,4 +124,115 @@ int mt7996_mcu_edcca_threshold_ctrl(struct mt7996_phy *phy, u8 *value, bool set)
209 return 0;
210 }
211
212+int mt7996_mcu_set_sr_enable(struct mt7996_phy *phy, u8 action, u64 val, bool set)
213+{
214+ struct {
215+ u8 band_idx;
216+ u8 _rsv[3];
217+
218+ __le16 tag;
219+ __le16 len;
220+
221+ __le32 val;
222+
223+ } __packed req = {
224+ .band_idx = phy->mt76->band_idx,
225+
226+ .tag = cpu_to_le16(action),
227+ .len = cpu_to_le16(sizeof(req) - 4),
228+
229+ .val = cpu_to_le32((u32) val),
230+ };
231+
232+ if (set)
233+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(SR), &req,
234+ sizeof(req), false);
235+ else
236+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD_QUERY(SR), &req,
237+ sizeof(req), false);
238+}
239+
240+void mt7996_mcu_rx_sr_swsd(struct mt7996_dev *dev, struct sk_buff *skb)
241+{
242+#define SR_SCENE_DETECTION_TIMER_PERIOD_MS 500
243+ struct mt7996_mcu_sr_swsd_event *event;
244+ static const char * const rules[] = {"1 - NO CONNECTED", "2 - NO CONGESTION",
245+ "3 - NO INTERFERENCE", "4 - SR ON"};
246+ u8 idx;
247+
248+ event = (struct mt7996_mcu_sr_swsd_event *)skb->data;
249+ idx = event->basic.band_idx;
250+
251+ dev_info(dev->mt76.dev, "Band index = %u\n", le16_to_cpu(event->basic.band_idx));
252+ dev_info(dev->mt76.dev, "Hit Rule = %s\n", rules[event->tlv[idx].rule]);
253+ dev_info(dev->mt76.dev, "Timer Period = %d(us)\n"
254+ "Congestion Ratio = %d.%1d%%\n",
255+ SR_SCENE_DETECTION_TIMER_PERIOD_MS * 1000,
256+ le32_to_cpu(event->tlv[idx].total_airtime_ratio) / 10,
257+ le32_to_cpu(event->tlv[idx].total_airtime_ratio) % 10);
258+ dev_info(dev->mt76.dev,
259+ "Total Airtime = %d(us)\n"
260+ "ChBusy = %d\n"
261+ "SrTx = %d\n"
262+ "OBSS = %d\n"
263+ "MyTx = %d\n"
264+ "MyRx = %d\n"
265+ "Interference Ratio = %d.%1d%%\n",
266+ le32_to_cpu(event->tlv[idx].total_airtime),
267+ le32_to_cpu(event->tlv[idx].channel_busy_time),
268+ le32_to_cpu(event->tlv[idx].sr_tx_airtime),
269+ le32_to_cpu(event->tlv[idx].obss_airtime),
270+ le32_to_cpu(event->tlv[idx].my_tx_airtime),
271+ le32_to_cpu(event->tlv[idx].my_rx_airtime),
272+ le32_to_cpu(event->tlv[idx].obss_airtime_ratio) / 10,
273+ le32_to_cpu(event->tlv[idx].obss_airtime_ratio) % 10);
274+}
275+
276+void mt7996_mcu_rx_sr_hw_indicator(struct mt7996_dev *dev, struct sk_buff *skb)
277+{
278+ struct mt7996_mcu_sr_hw_ind_event *event;
279+
280+ event = (struct mt7996_mcu_sr_hw_ind_event *)skb->data;
281+
282+ dev_info(dev->mt76.dev, "Inter PPDU Count = %u\n",
283+ le16_to_cpu(event->inter_bss_ppdu_cnt));
284+ dev_info(dev->mt76.dev, "SR Valid Count = %u\n",
285+ le16_to_cpu(event->non_srg_valid_cnt));
286+ dev_info(dev->mt76.dev, "SR Tx Count = %u\n",
287+ le32_to_cpu(event->sr_ampdu_mpdu_cnt));
288+ dev_info(dev->mt76.dev, "SR Tx Acked Count = %u\n",
289+ le32_to_cpu(event->sr_ampdu_mpdu_acked_cnt));
290+}
291+
292+void mt7996_mcu_rx_sr_event(struct mt7996_dev *dev, struct sk_buff *skb)
293+{
294+ struct mt76_phy *mphy = &dev->mt76.phy;
295+ struct mt7996_phy *phy;
296+ struct mt7996_mcu_sr_common_event *event;
297+
298+ event = (struct mt7996_mcu_sr_common_event *)skb->data;
299+ mphy = dev->mt76.phys[event->basic.band_idx];
300+ if (!mphy)
301+ return;
302+
303+ phy = (struct mt7996_phy *)mphy->priv;
304+
305+ switch (le16_to_cpu(event->basic.tag)) {
306+ case UNI_EVENT_SR_CFG_SR_ENABLE:
307+ phy->sr_enable = le32_to_cpu(event->value) ? true : false;
308+ break;
309+ case UNI_EVENT_SR_HW_ESR_ENABLE:
310+ phy->enhanced_sr_enable = le32_to_cpu(event->value) ? true : false;
311+ break;
312+ case UNI_EVENT_SR_SW_SD:
313+ mt7996_mcu_rx_sr_swsd(dev, skb);
314+ break;
315+ case UNI_EVENT_SR_HW_IND:
316+ mt7996_mcu_rx_sr_hw_indicator(dev, skb);
317+ break;
318+ default:
319+ dev_info(dev->mt76.dev, "Unknown SR event tag %d\n",
320+ le16_to_cpu(event->basic.tag));
321+ }
322+}
323 #endif
324diff --git a/mt7996/mtk_mcu.h b/mt7996/mtk_mcu.h
325index 9c0db87..a5bdb88 100644
326--- a/mt7996/mtk_mcu.h
327+++ b/mt7996/mtk_mcu.h
328@@ -104,6 +104,62 @@ enum {
329 EDCCA_JAPAN = 3
330 };
331
332+enum {
333+ UNI_EVENT_SR_CFG_SR_ENABLE = 0x1,
334+ UNI_EVENT_SR_SW_SD = 0x83,
335+ UNI_EVENT_SR_HW_IND = 0xC9,
336+ UNI_EVENT_SR_HW_ESR_ENABLE = 0xD8,
337+};
338+enum {
339+ UNI_CMD_SR_CFG_SR_ENABLE = 0x1,
340+ UNI_CMD_SR_SW_SD = 0x84,
341+ UNI_CMD_SR_HW_IND = 0xCB,
342+ UNI_CMD_SR_HW_ENHANCE_SR_ENABLE = 0xDA,
343+};
344+
345+struct mt7996_mcu_sr_basic_event {
346+ struct mt7996_mcu_rxd rxd;
347+
348+ u8 band_idx;
349+ u8 _rsv[3];
350+
351+ __le16 tag;
352+ __le16 len;
353+};
354+
355+struct sr_sd_tlv {
356+ u8 _rsv[16];
357+ __le32 sr_tx_airtime;
358+ __le32 obss_airtime;
359+ __le32 my_tx_airtime;
360+ __le32 my_rx_airtime;
361+ __le32 channel_busy_time;
362+ __le32 total_airtime;
363+ __le32 total_airtime_ratio;
364+ __le32 obss_airtime_ratio;
365+ u8 rule;
366+ u8 _rsv2[59];
367+} __packed;
368+
369+struct mt7996_mcu_sr_swsd_event {
370+ struct mt7996_mcu_sr_basic_event basic;
371+ struct sr_sd_tlv tlv[3];
372+} __packed;
373+
374+struct mt7996_mcu_sr_common_event {
375+ struct mt7996_mcu_sr_basic_event basic;
376+ __le32 value;
377+};
378+
379+struct mt7996_mcu_sr_hw_ind_event {
380+ struct mt7996_mcu_sr_basic_event basic;
381+ __le16 non_srg_valid_cnt;
382+ u8 _rsv[4];
383+ __le16 inter_bss_ppdu_cnt;
384+ u8 _rsv2[4];
385+ __le32 sr_ampdu_mpdu_cnt;
386+ __le32 sr_ampdu_mpdu_acked_cnt;
387+};
388 #endif
389
390 #endif
391--
3922.18.0
393