blob: 9c80261b916efe32d239a5ad6c9b9b2a4e3e1b3b [file] [log] [blame]
developer9237f442024-06-14 17:13:04 +08001From 5e5d779286a2c289480469f3b6d1b93479a4762c 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
developer9237f442024-06-14 17:13:04 +08004Subject: [PATCH 034/116] mtk: wifi: mt76: mt7996: add support spatial reuse
developer66e89bc2024-04-23 14:50:01 +08005 debug 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
developer66e89bc2024-04-23 14:50:01 +080018---
19 mt76_connac_mcu.h | 1 +
20 mt7996/main.c | 6 +++
21 mt7996/mcu.c | 8 ++++
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, 270 insertions(+)
27
28diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer9237f442024-06-14 17:13:04 +080029index 750bb93..7f2daf7 100644
developer66e89bc2024-04-23 14:50:01 +080030--- a/mt76_connac_mcu.h
31+++ b/mt76_connac_mcu.h
developer9237f442024-06-14 17:13:04 +080032@@ -1041,6 +1041,7 @@ enum {
developer66e89bc2024-04-23 14:50:01 +080033 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
developer9237f442024-06-14 17:13:04 +080041index 003bf3f..92b2834 100644
developer66e89bc2024-04-23 14:50:01 +080042--- 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@@ -86,6 +89,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 ? 0 : phy->sku_limit_en);
63
64diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developer9237f442024-06-14 17:13:04 +080065index 51c771b..7318842 100644
developer66e89bc2024-04-23 14:50:01 +080066--- a/mt7996/mcu.c
67+++ b/mt7996/mcu.c
68@@ -717,6 +717,14 @@ mt7996_mcu_uni_rx_unsolicited_event(struct mt7996_dev *dev, struct sk_buff *skb)
69 case MCU_UNI_EVENT_WED_RRO:
70 mt7996_mcu_wed_rro_event(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;
80 #ifdef CONFIG_NL80211_TESTMODE
81 case MCU_UNI_EVENT_TESTMODE_CTRL:
82 mt7996_tm_rf_test_event(dev, skb);
83diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer9237f442024-06-14 17:13:04 +080084index 97425a0..c06aae9 100644
developer66e89bc2024-04-23 14:50:01 +080085--- a/mt7996/mt7996.h
86+++ b/mt7996/mt7996.h
87@@ -357,6 +357,10 @@ struct mt7996_phy {
88 spinlock_t amnt_lock;
89 struct mt7996_air_monitor_ctrl amnt_ctrl;
90 #endif
91+#ifdef CONFIG_MTK_DEBUG
92+ bool sr_enable:1;
93+ bool enhanced_sr_enable:1;
94+#endif
95 };
96
97 struct mt7996_dev {
98@@ -807,6 +811,8 @@ enum edcca_bw_id {
99 #ifdef CONFIG_MTK_DEBUG
100 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir);
101 int mt7996_mcu_muru_dbg_info(struct mt7996_dev *dev, u16 item, u8 val);
102+int mt7996_mcu_set_sr_enable(struct mt7996_phy *phy, u8 action, u64 val, bool set);
103+void mt7996_mcu_rx_sr_event(struct mt7996_dev *dev, struct sk_buff *skb);
104 #endif
105
106 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
107diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developer9237f442024-06-14 17:13:04 +0800108index 2a9f213..3eb55a3 100644
developer66e89bc2024-04-23 14:50:01 +0800109--- a/mt7996/mtk_debugfs.c
110+++ b/mt7996/mtk_debugfs.c
111@@ -2836,6 +2836,83 @@ static int mt7996_show_eeprom_mode(struct seq_file *s, void *data)
112 return 0;
113 }
114
115+static int
116+mt7996_sr_enable_get(void *data, u64 *val)
117+{
118+ struct mt7996_phy *phy = data;
119+
120+ *val = phy->sr_enable;
121+
122+ return 0;
123+}
124+
125+static int
126+mt7996_sr_enable_set(void *data, u64 val)
127+{
128+ struct mt7996_phy *phy = data;
129+ int ret;
130+
131+ if (!!val == phy->sr_enable)
132+ return 0;
133+
134+ ret = mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_CFG_SR_ENABLE, val, true);
135+ if (ret)
136+ return ret;
137+
138+ return mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_CFG_SR_ENABLE, 0, false);
139+}
140+DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enable, mt7996_sr_enable_get,
141+ mt7996_sr_enable_set, "%lld\n");
142+static int
143+mt7996_sr_enhanced_enable_get(void *data, u64 *val)
144+{
145+ struct mt7996_phy *phy = data;
146+
147+ *val = phy->enhanced_sr_enable;
148+
149+ return 0;
150+}
151+
152+static int
153+mt7996_sr_enhanced_enable_set(void *data, u64 val)
154+{
155+ struct mt7996_phy *phy = data;
156+ int ret;
157+
158+ if (!!val == phy->enhanced_sr_enable)
159+ return 0;
160+
161+ ret = mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_ENHANCE_SR_ENABLE, val, true);
162+ if (ret)
163+ return ret;
164+
165+ return mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_ENHANCE_SR_ENABLE, 0, false);
166+}
167+DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enhanced_enable, mt7996_sr_enhanced_enable_get,
168+ mt7996_sr_enhanced_enable_set, "%lld\n");
169+
170+static int
171+mt7996_sr_stats_show(struct seq_file *file, void *data)
172+{
173+ struct mt7996_phy *phy = file->private;
174+
175+ mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_HW_IND, 0, false);
176+
177+ return 0;
178+}
179+DEFINE_SHOW_ATTRIBUTE(mt7996_sr_stats);
180+
181+static int
182+mt7996_sr_scene_cond_show(struct seq_file *file, void *data)
183+{
184+ struct mt7996_phy *phy = file->private;
185+
186+ mt7996_mcu_set_sr_enable(phy, UNI_CMD_SR_SW_SD, 0, false);
187+
188+ return 0;
189+}
190+DEFINE_SHOW_ATTRIBUTE(mt7996_sr_scene_cond);
191+
192 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
193 {
194 struct mt7996_dev *dev = phy->dev;
195@@ -2915,6 +2992,11 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
196 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
197 debugfs_create_file("scs_enable", 0200, dir, phy, &fops_scs_enable);
198
199+ debugfs_create_file("sr_enable", 0600, dir, phy, &fops_sr_enable);
200+ debugfs_create_file("sr_enhanced_enable", 0600, dir, phy, &fops_sr_enhanced_enable);
201+ debugfs_create_file("sr_stats", 0400, dir, phy, &mt7996_sr_stats_fops);
202+ debugfs_create_file("sr_scene_cond", 0400, dir, phy, &mt7996_sr_scene_cond_fops);
203+
204 return 0;
205 }
206
207diff --git a/mt7996/mtk_mcu.c b/mt7996/mtk_mcu.c
developer9237f442024-06-14 17:13:04 +0800208index 5c54d02..dbdf8d8 100644
developer66e89bc2024-04-23 14:50:01 +0800209--- a/mt7996/mtk_mcu.c
210+++ b/mt7996/mtk_mcu.c
211@@ -146,4 +146,115 @@ int mt7996_mcu_edcca_threshold_ctrl(struct mt7996_phy *phy, u8 *value, bool set)
212 return 0;
213 }
214
215+int mt7996_mcu_set_sr_enable(struct mt7996_phy *phy, u8 action, u64 val, bool set)
216+{
217+ struct {
218+ u8 band_idx;
219+ u8 _rsv[3];
220+
221+ __le16 tag;
222+ __le16 len;
223+
224+ __le32 val;
225+
226+ } __packed req = {
227+ .band_idx = phy->mt76->band_idx,
228+
229+ .tag = cpu_to_le16(action),
230+ .len = cpu_to_le16(sizeof(req) - 4),
231+
232+ .val = cpu_to_le32((u32) val),
233+ };
234+
235+ if (set)
236+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(SR), &req,
237+ sizeof(req), false);
238+ else
239+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD_QUERY(SR), &req,
240+ sizeof(req), false);
241+}
242+
243+void mt7996_mcu_rx_sr_swsd(struct mt7996_dev *dev, struct sk_buff *skb)
244+{
245+#define SR_SCENE_DETECTION_TIMER_PERIOD_MS 500
246+ struct mt7996_mcu_sr_swsd_event *event;
247+ static const char * const rules[] = {"1 - NO CONNECTED", "2 - NO CONGESTION",
248+ "3 - NO INTERFERENCE", "4 - SR ON"};
249+ u8 idx;
250+
251+ event = (struct mt7996_mcu_sr_swsd_event *)skb->data;
252+ idx = event->basic.band_idx;
253+
254+ dev_info(dev->mt76.dev, "Band index = %u\n", le16_to_cpu(event->basic.band_idx));
255+ dev_info(dev->mt76.dev, "Hit Rule = %s\n", rules[event->tlv[idx].rule]);
256+ dev_info(dev->mt76.dev, "Timer Period = %d(us)\n"
257+ "Congestion Ratio = %d.%1d%%\n",
258+ SR_SCENE_DETECTION_TIMER_PERIOD_MS * 1000,
259+ le32_to_cpu(event->tlv[idx].total_airtime_ratio) / 10,
260+ le32_to_cpu(event->tlv[idx].total_airtime_ratio) % 10);
261+ dev_info(dev->mt76.dev,
262+ "Total Airtime = %d(us)\n"
263+ "ChBusy = %d\n"
264+ "SrTx = %d\n"
265+ "OBSS = %d\n"
266+ "MyTx = %d\n"
267+ "MyRx = %d\n"
268+ "Interference Ratio = %d.%1d%%\n",
269+ le32_to_cpu(event->tlv[idx].total_airtime),
270+ le32_to_cpu(event->tlv[idx].channel_busy_time),
271+ le32_to_cpu(event->tlv[idx].sr_tx_airtime),
272+ le32_to_cpu(event->tlv[idx].obss_airtime),
273+ le32_to_cpu(event->tlv[idx].my_tx_airtime),
274+ le32_to_cpu(event->tlv[idx].my_rx_airtime),
275+ le32_to_cpu(event->tlv[idx].obss_airtime_ratio) / 10,
276+ le32_to_cpu(event->tlv[idx].obss_airtime_ratio) % 10);
277+}
278+
279+void mt7996_mcu_rx_sr_hw_indicator(struct mt7996_dev *dev, struct sk_buff *skb)
280+{
281+ struct mt7996_mcu_sr_hw_ind_event *event;
282+
283+ event = (struct mt7996_mcu_sr_hw_ind_event *)skb->data;
284+
285+ dev_info(dev->mt76.dev, "Inter PPDU Count = %u\n",
286+ le16_to_cpu(event->inter_bss_ppdu_cnt));
287+ dev_info(dev->mt76.dev, "SR Valid Count = %u\n",
288+ le16_to_cpu(event->non_srg_valid_cnt));
289+ dev_info(dev->mt76.dev, "SR Tx Count = %u\n",
290+ le32_to_cpu(event->sr_ampdu_mpdu_cnt));
291+ dev_info(dev->mt76.dev, "SR Tx Acked Count = %u\n",
292+ le32_to_cpu(event->sr_ampdu_mpdu_acked_cnt));
293+}
294+
295+void mt7996_mcu_rx_sr_event(struct mt7996_dev *dev, struct sk_buff *skb)
296+{
297+ struct mt76_phy *mphy = &dev->mt76.phy;
298+ struct mt7996_phy *phy;
299+ struct mt7996_mcu_sr_common_event *event;
300+
301+ event = (struct mt7996_mcu_sr_common_event *)skb->data;
302+ mphy = dev->mt76.phys[event->basic.band_idx];
303+ if (!mphy)
304+ return;
305+
306+ phy = (struct mt7996_phy *)mphy->priv;
307+
308+ switch (le16_to_cpu(event->basic.tag)) {
309+ case UNI_EVENT_SR_CFG_SR_ENABLE:
310+ phy->sr_enable = le32_to_cpu(event->value) ? true : false;
311+ break;
312+ case UNI_EVENT_SR_HW_ESR_ENABLE:
313+ phy->enhanced_sr_enable = le32_to_cpu(event->value) ? true : false;
314+ break;
315+ case UNI_EVENT_SR_SW_SD:
316+ mt7996_mcu_rx_sr_swsd(dev, skb);
317+ break;
318+ case UNI_EVENT_SR_HW_IND:
319+ mt7996_mcu_rx_sr_hw_indicator(dev, skb);
320+ break;
321+ default:
322+ dev_info(dev->mt76.dev, "Unknown SR event tag %d\n",
323+ le16_to_cpu(event->basic.tag));
324+ }
325+}
326 #endif
327diff --git a/mt7996/mtk_mcu.h b/mt7996/mtk_mcu.h
developer9237f442024-06-14 17:13:04 +0800328index 36a58ad..098e63a 100644
developer66e89bc2024-04-23 14:50:01 +0800329--- a/mt7996/mtk_mcu.h
330+++ b/mt7996/mtk_mcu.h
331@@ -121,6 +121,62 @@ enum {
332 EDCCA_JAPAN = 3
333 };
334
335+enum {
336+ UNI_EVENT_SR_CFG_SR_ENABLE = 0x1,
337+ UNI_EVENT_SR_SW_SD = 0x83,
338+ UNI_EVENT_SR_HW_IND = 0xC9,
339+ UNI_EVENT_SR_HW_ESR_ENABLE = 0xD8,
340+};
341+enum {
342+ UNI_CMD_SR_CFG_SR_ENABLE = 0x1,
343+ UNI_CMD_SR_SW_SD = 0x84,
344+ UNI_CMD_SR_HW_IND = 0xCB,
345+ UNI_CMD_SR_HW_ENHANCE_SR_ENABLE = 0xDA,
346+};
347+
348+struct mt7996_mcu_sr_basic_event {
349+ struct mt7996_mcu_rxd rxd;
350+
351+ u8 band_idx;
352+ u8 _rsv[3];
353+
354+ __le16 tag;
355+ __le16 len;
356+};
357+
358+struct sr_sd_tlv {
359+ u8 _rsv[16];
360+ __le32 sr_tx_airtime;
361+ __le32 obss_airtime;
362+ __le32 my_tx_airtime;
363+ __le32 my_rx_airtime;
364+ __le32 channel_busy_time;
365+ __le32 total_airtime;
366+ __le32 total_airtime_ratio;
367+ __le32 obss_airtime_ratio;
368+ u8 rule;
369+ u8 _rsv2[59];
370+} __packed;
371+
372+struct mt7996_mcu_sr_swsd_event {
373+ struct mt7996_mcu_sr_basic_event basic;
374+ struct sr_sd_tlv tlv[3];
375+} __packed;
376+
377+struct mt7996_mcu_sr_common_event {
378+ struct mt7996_mcu_sr_basic_event basic;
379+ __le32 value;
380+};
381+
382+struct mt7996_mcu_sr_hw_ind_event {
383+ struct mt7996_mcu_sr_basic_event basic;
384+ __le16 non_srg_valid_cnt;
385+ u8 _rsv[4];
386+ __le16 inter_bss_ppdu_cnt;
387+ u8 _rsv2[4];
388+ __le32 sr_ampdu_mpdu_cnt;
389+ __le32 sr_ampdu_mpdu_acked_cnt;
390+};
391 #endif
392
393 #endif
394--
developer9237f442024-06-14 17:13:04 +08003952.18.0
developer66e89bc2024-04-23 14:50:01 +0800396