Skip to content

Commit e57b790

Browse files
ryderlee1110nbd168
authored andcommitted
mt76: add mac80211 driver for MT7915 PCIe-based chipsets
Add support for the MediaTek latest generation IEEE 802.11ax 4x4 device MT7915E, which supports concurrent dual-band operation at both 5GHz and 2.4GHz. Note that this patch just add basic part and will add more HE capabilities support in the further patches. The driver supports AP, Station, Mesh and monitor mode. Signed-off-by: Ryder Lee <[email protected]> Signed-off-by: Shayne Chen <[email protected]> Signed-off-by: Chih-Min Chen <[email protected]> Suggested-by: Shihwei Lin <[email protected]> Tested-by: Evelyn Tsai <[email protected]> Acked-by: Yiwei Chung <[email protected]> Acked-by: YF Luo <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent d3377b7 commit e57b790

File tree

17 files changed

+7616
-0
lines changed

17 files changed

+7616
-0
lines changed

drivers/net/wireless/mediatek/mt76/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ source "drivers/net/wireless/mediatek/mt76/mt76x0/Kconfig"
2424
source "drivers/net/wireless/mediatek/mt76/mt76x2/Kconfig"
2525
source "drivers/net/wireless/mediatek/mt76/mt7603/Kconfig"
2626
source "drivers/net/wireless/mediatek/mt76/mt7615/Kconfig"
27+
source "drivers/net/wireless/mediatek/mt76/mt7915/Kconfig"

drivers/net/wireless/mediatek/mt76/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ obj-$(CONFIG_MT76x0_COMMON) += mt76x0/
2727
obj-$(CONFIG_MT76x2_COMMON) += mt76x2/
2828
obj-$(CONFIG_MT7603E) += mt7603/
2929
obj-$(CONFIG_MT7615_COMMON) += mt7615/
30+
obj-$(CONFIG_MT7915E) += mt7915/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: ISC
2+
config MT7915E
3+
tristate "MediaTek MT7915E (PCIe) support"
4+
select MT76_CORE
5+
depends on MAC80211
6+
depends on PCI
7+
help
8+
This adds support for MT7915-based wireless PCIe devices,
9+
which support concurrent dual-band operation at both 5GHz
10+
and 2.4GHz IEEE 802.11ax 4x4:4SS 1024-QAM, 160MHz channels,
11+
OFDMA, spatial reuse and dual carrier modulation.
12+
13+
To compile this driver as a module, choose M here.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#SPDX-License-Identifier: ISC
2+
3+
obj-$(CONFIG_MT7915E) += mt7915e.o
4+
5+
mt7915e-y := pci.o init.o dma.o eeprom.o main.o mcu.o mac.o \
6+
debugfs.o
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
// SPDX-License-Identifier: ISC
2+
/* Copyright (C) 2020 MediaTek Inc. */
3+
4+
#include "mt7915.h"
5+
#include "eeprom.h"
6+
7+
/** global debugfs **/
8+
9+
/* test knob of system layer 1/2 error recovery */
10+
static int mt7915_ser_trigger_set(void *data, u64 val)
11+
{
12+
enum {
13+
SER_SET_RECOVER_L1 = 1,
14+
SER_SET_RECOVER_L2,
15+
SER_ENABLE = 2,
16+
SER_RECOVER
17+
};
18+
struct mt7915_dev *dev = data;
19+
int ret = 0;
20+
21+
switch (val) {
22+
case SER_SET_RECOVER_L1:
23+
case SER_SET_RECOVER_L2:
24+
/* fall through */
25+
ret = mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), 0);
26+
if (ret)
27+
return ret;
28+
29+
return mt7915_mcu_set_ser(dev, SER_RECOVER, val, 0);
30+
default:
31+
break;
32+
}
33+
34+
return ret;
35+
}
36+
37+
DEFINE_DEBUGFS_ATTRIBUTE(fops_ser_trigger, NULL,
38+
mt7915_ser_trigger_set, "%lld\n");
39+
40+
static int
41+
mt7915_radar_trigger(void *data, u64 val)
42+
{
43+
struct mt7915_dev *dev = data;
44+
45+
return mt7915_mcu_rdd_cmd(dev, RDD_RADAR_EMULATE, 1, 0, 0);
46+
}
47+
48+
DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_trigger, NULL,
49+
mt7915_radar_trigger, "%lld\n");
50+
51+
static int
52+
mt7915_dbdc_set(void *data, u64 val)
53+
{
54+
struct mt7915_dev *dev = data;
55+
56+
if (val)
57+
mt7915_register_ext_phy(dev);
58+
else
59+
mt7915_unregister_ext_phy(dev);
60+
61+
return 0;
62+
}
63+
64+
static int
65+
mt7915_dbdc_get(void *data, u64 *val)
66+
{
67+
struct mt7915_dev *dev = data;
68+
69+
*val = !!mt7915_ext_phy(dev);
70+
71+
return 0;
72+
}
73+
74+
DEFINE_DEBUGFS_ATTRIBUTE(fops_dbdc, mt7915_dbdc_get,
75+
mt7915_dbdc_set, "%lld\n");
76+
77+
static void
78+
mt7915_ampdu_stat_read_phy(struct mt7915_phy *phy,
79+
struct seq_file *file)
80+
{
81+
struct mt7915_dev *dev = file->private;
82+
bool ext_phy = phy != &dev->phy;
83+
int bound[15], range[4], i, n;
84+
85+
if (!phy)
86+
return;
87+
88+
/* Tx ampdu stat */
89+
for (i = 0; i < ARRAY_SIZE(range); i++)
90+
range[i] = mt76_rr(dev, MT_MIB_ARNG(ext_phy, i));
91+
92+
for (i = 0; i < ARRAY_SIZE(bound); i++)
93+
bound[i] = MT_MIB_ARNCR_RANGE(range[i / 4], i) + 1;
94+
95+
seq_printf(file, "\nPhy %d\n", ext_phy);
96+
97+
seq_printf(file, "Length: %8d | ", bound[0]);
98+
for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
99+
seq_printf(file, "%3d -%3d | ",
100+
bound[i] + 1, bound[i + 1]);
101+
102+
seq_puts(file, "\nCount: ");
103+
n = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
104+
for (i = 0; i < ARRAY_SIZE(bound); i++)
105+
seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i + n]);
106+
seq_puts(file, "\n");
107+
108+
seq_printf(file, "BA miss count: %d\n", phy->mib.ba_miss_cnt);
109+
}
110+
111+
static int
112+
mt7915_tx_stats_read(struct seq_file *file, void *data)
113+
{
114+
struct mt7915_dev *dev = file->private;
115+
int stat[8], i, n;
116+
117+
mt7915_ampdu_stat_read_phy(&dev->phy, file);
118+
mt7915_ampdu_stat_read_phy(mt7915_ext_phy(dev), file);
119+
120+
/* Tx amsdu info */
121+
seq_puts(file, "Tx MSDU stat:\n");
122+
for (i = 0, n = 0; i < ARRAY_SIZE(stat); i++) {
123+
stat[i] = mt76_rr(dev, MT_PLE_AMSDU_PACK_MSDU_CNT(i));
124+
n += stat[i];
125+
}
126+
127+
for (i = 0; i < ARRAY_SIZE(stat); i++) {
128+
seq_printf(file, "AMSDU pack count of %d MSDU in TXD: 0x%x ",
129+
i + 1, stat[i]);
130+
if (n != 0)
131+
seq_printf(file, "(%d%%)\n", stat[i] * 100 / n);
132+
else
133+
seq_puts(file, "\n");
134+
}
135+
136+
return 0;
137+
}
138+
139+
static int
140+
mt7915_tx_stats_open(struct inode *inode, struct file *f)
141+
{
142+
return single_open(f, mt7915_tx_stats_read, inode->i_private);
143+
}
144+
145+
static const struct file_operations fops_tx_stats = {
146+
.open = mt7915_tx_stats_open,
147+
.read = seq_read,
148+
.llseek = seq_lseek,
149+
.release = single_release,
150+
};
151+
152+
static int mt7915_read_temperature(struct seq_file *s, void *data)
153+
{
154+
struct mt7915_dev *dev = dev_get_drvdata(s->private);
155+
int temp;
156+
157+
/* cpu */
158+
temp = mt7915_mcu_get_temperature(dev, 0);
159+
seq_printf(s, "Temperature: %d\n", temp);
160+
161+
return 0;
162+
}
163+
164+
static int
165+
mt7915_queues_acq(struct seq_file *s, void *data)
166+
{
167+
struct mt7915_dev *dev = dev_get_drvdata(s->private);
168+
int i;
169+
170+
for (i = 0; i < 16; i++) {
171+
int j, acs = i / 4, index = i % 4;
172+
u32 ctrl, val, qlen = 0;
173+
174+
val = mt76_rr(dev, MT_PLE_AC_QEMPTY(acs, index));
175+
ctrl = BIT(31) | BIT(15) | (acs << 8);
176+
177+
for (j = 0; j < 32; j++) {
178+
if (val & BIT(j))
179+
continue;
180+
181+
mt76_wr(dev, MT_PLE_FL_Q0_CTRL,
182+
ctrl | (j + (index << 5)));
183+
qlen += mt76_get_field(dev, MT_PLE_FL_Q3_CTRL,
184+
GENMASK(11, 0));
185+
}
186+
seq_printf(s, "AC%d%d: queued=%d\n", acs, index, qlen);
187+
}
188+
189+
return 0;
190+
}
191+
192+
static int
193+
mt7915_queues_read(struct seq_file *s, void *data)
194+
{
195+
struct mt7915_dev *dev = dev_get_drvdata(s->private);
196+
static const struct {
197+
char *queue;
198+
int id;
199+
} queue_map[] = {
200+
{ "WFDMA0", MT_TXQ_BE },
201+
{ "MCUWM", MT_TXQ_MCU },
202+
{ "MCUWA", MT_TXQ_MCU_WA },
203+
{ "MCUFWQ", MT_TXQ_FWDL },
204+
};
205+
int i;
206+
207+
for (i = 0; i < ARRAY_SIZE(queue_map); i++) {
208+
struct mt76_sw_queue *q = &dev->mt76.q_tx[queue_map[i].id];
209+
210+
if (!q->q)
211+
continue;
212+
213+
seq_printf(s,
214+
"%s: queued=%d head=%d tail=%d\n",
215+
queue_map[i].queue, q->q->queued, q->q->head,
216+
q->q->tail);
217+
}
218+
219+
return 0;
220+
}
221+
222+
int mt7915_init_debugfs(struct mt7915_dev *dev)
223+
{
224+
struct dentry *dir;
225+
226+
dir = mt76_register_debugfs(&dev->mt76);
227+
if (!dir)
228+
return -ENOMEM;
229+
230+
debugfs_create_devm_seqfile(dev->mt76.dev, "queues", dir,
231+
mt7915_queues_read);
232+
debugfs_create_devm_seqfile(dev->mt76.dev, "acq", dir,
233+
mt7915_queues_acq);
234+
debugfs_create_file("tx_stats", 0400, dir, dev, &fops_tx_stats);
235+
debugfs_create_file("dbdc", 0600, dir, dev, &fops_dbdc);
236+
debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern);
237+
/* test knobs */
238+
debugfs_create_file("radar_trigger", 0200, dir, dev,
239+
&fops_radar_trigger);
240+
debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger);
241+
debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir,
242+
mt7915_read_temperature);
243+
244+
return 0;
245+
}

0 commit comments

Comments
 (0)