blob: 222353c11abe427ecb8d299de75ec5a1e28d696e [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 32991b1ffa0cefe38be1adc97c2effb4a27bcc28 Mon Sep 17 00:00:00 2001
2From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Wed, 17 Jul 2024 16:57:24 +0800
4Subject: [PATCH 185/199] mtk: mt76: mt7996: add debugfs knob to set and dump
5 txop
6
7Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
8---
9 mt7996/mtk_debug_i.h | 8 ++++
10 mt7996/mtk_debugfs_i.c | 104 +++++++++++++++++++++++++++++++++++++++++
11 2 files changed, 112 insertions(+)
12
13diff --git a/mt7996/mtk_debug_i.h b/mt7996/mtk_debug_i.h
14index cec8d57e..01023e16 100644
15--- a/mt7996/mtk_debug_i.h
16+++ b/mt7996/mtk_debug_i.h
17@@ -1006,6 +1006,14 @@
18 /* AGG */
19 #define MT_AGG_REMAP_CTRL(_band) MT_WF_AGG(_band, 0x094)
20 #define MT_AGG_REMAP_CTRL_OM_REMAP GENMASK(5, 0)
21+
22+/* TMAC */
23+#define MT_WF_TMAC_WMM0_OFFSET 0x0c4
24+#define MT_WF_TMAC_WMM1_OFFSET 0x364
25+#define MT_WF_TMAC_WMM2_OFFSET 0x36c
26+#define MT_WF_TMAC_WMM3_OFFSET 0x374
27+#define MT_WF_TMAC_WMM_TXOP_MASK GENMASK(31, 16)
28+#define MT_WF_TMAC_WMM_TXOP_SHIFT 16
29 #endif
30
31 #endif
32diff --git a/mt7996/mtk_debugfs_i.c b/mt7996/mtk_debugfs_i.c
33index 852d1b12..c9224eee 100644
34--- a/mt7996/mtk_debugfs_i.c
35+++ b/mt7996/mtk_debugfs_i.c
36@@ -824,6 +824,109 @@ static const struct file_operations fops_mlo_agc_tx = {
37 .llseek = default_llseek,
38 };
39
40+static ssize_t mt7996_be_txop_set(struct file *file,
41+ const char __user *user_buf,
42+ size_t count, loff_t *ppos)
43+{
44+ struct mt7996_dev *dev = file->private_data;
45+ char buf[100], role[4];
46+ u32 ofs;
47+ u16 txop, decimal;
48+ int i = 0;
49+
50+ if (count >= sizeof(buf))
51+ return -EINVAL;
52+
53+ if (copy_from_user(buf, user_buf, count))
54+ return -EFAULT;
55+
56+ if (count && buf[count - 1] == '\n')
57+ buf[count - 1] = '\0';
58+ else
59+ buf[count] = '\0';
60+
61+ if (sscanf(buf, "%3s %hu.%hu", role, &txop, &decimal) != 3)
62+ goto err;
63+
64+ if (!strncmp(role, "ap", 2))
65+ ofs = MT_WF_TMAC_WMM0_OFFSET;
66+ else if (!strncmp(role, "sta", 3))
67+ ofs = MT_WF_TMAC_WMM3_OFFSET;
68+ else
69+ goto err;
70+
71+ /* Change unit to 32 us */
72+ txop = (txop * 1000 + decimal * 100 + 16) >> 5;
73+
74+ for (i = 0; i < __MT_MAX_BAND; i++) {
75+ if (!dev->mt76.phys[i])
76+ continue;
77+
78+ mt76_rmw(dev, MT_WF_TMAC(i, ofs), MT_WF_TMAC_WMM_TXOP_MASK,
79+ txop << MT_WF_TMAC_WMM_TXOP_SHIFT);
80+ }
81+
82+ return count;
83+err:
84+ dev_warn(dev->mt76.dev,
85+ "format: [ap|sta] [tx_queue_data2_burst]\n");
86+ return -EINVAL;
87+}
88+
89+static ssize_t mt7996_be_txop_dump(struct file *file, char __user *user_buf,
90+ size_t count, loff_t *ppos)
91+{
92+ struct mt7996_dev *dev = file->private_data;
93+ static const size_t size = 2048;
94+ int len = 0, i, ret;
95+ char *buf;
96+ enum {
97+ AP,
98+ STA,
99+ MAX_IF_TYPE,
100+ };
101+
102+ buf = kzalloc(size, GFP_KERNEL);
103+ if (!buf)
104+ return -ENOMEM;
105+
106+ len += scnprintf(buf + len, size - len, "Band\tAP (WMM0)\t\tSTA (WMM3)\n");
107+
108+ for (i = 0; i < __MT_MAX_BAND; i++) {
109+ u32 txop[MAX_IF_TYPE], tx_burst[MAX_IF_TYPE];
110+
111+ if (!dev->mt76.phys[i])
112+ continue;
113+
114+#define MT7996_READ_TXOP(role, base) \
115+do { \
116+ txop[role] = mt76_rr(dev, MT_WF_TMAC(i, base)); \
117+ tx_burst[role] = u32_get_bits(txop[role], MT_WF_TMAC_WMM_TXOP_MASK); \
118+ tx_burst[role] = tx_burst[role] ? ((tx_burst[role] << 5) - 16) / 100 : 0;\
119+} while (0)
120+ MT7996_READ_TXOP(AP, MT_WF_TMAC_WMM0_OFFSET);
121+ MT7996_READ_TXOP(STA, MT_WF_TMAC_WMM3_OFFSET);
122+#undef MT7996_READ_TXOP
123+
124+ len += scnprintf(buf + len, size - len,
125+ "%d\t0x%08x (%1u.%1u) \t0x%08x (%1u.%1u)\n", i,
126+ txop[AP], tx_burst[AP] / 10, tx_burst[AP] % 10,
127+ txop[STA], tx_burst[STA] / 10, tx_burst[STA] % 10);
128+ }
129+ ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
130+
131+ kfree(buf);
132+ return ret;
133+}
134+
135+static const struct file_operations fops_mt7996_txop = {
136+ .write = mt7996_be_txop_set,
137+ .read = mt7996_be_txop_dump,
138+ .open = simple_open,
139+ .owner = THIS_MODULE,
140+ .llseek = default_llseek,
141+};
142+
143 static ssize_t mt7996_mlo_agc_trig_set(struct file *file,
144 const char __user *user_buf,
145 size_t count, loff_t *ppos)
146@@ -893,6 +996,7 @@ int mt7996_mtk_init_dev_debugfs_internal(struct mt7996_phy *phy, struct dentry *
147 mt7996_pse_fid_read);
148
149 debugfs_create_u8("dump_ple_txd", 0600, dir, &dev->dbg.dump_ple_txd);
150+ debugfs_create_file("txop", 0600, dir, dev, &fops_mt7996_txop);
151
152 /* MLO related Table */
153 debugfs_create_file("mat_table", 0400, dir, dev, &mt7996_mat_table_fops);
154--
1552.18.0
156