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