Commit | Line | Data |
---|---|---|
7bc04215 FF |
1 | /* |
2 | * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include <linux/debugfs.h> | |
18 | #include "mt76x2.h" | |
19 | ||
20 | static int | |
21 | mt76x2_ampdu_stat_read(struct seq_file *file, void *data) | |
22 | { | |
23 | struct mt76x2_dev *dev = file->private; | |
24 | int i, j; | |
25 | ||
26 | for (i = 0; i < 4; i++) { | |
27 | seq_puts(file, "Length: "); | |
28 | for (j = 0; j < 8; j++) | |
29 | seq_printf(file, "%8d | ", i * 8 + j + 1); | |
30 | seq_puts(file, "\n"); | |
31 | seq_puts(file, "Count: "); | |
32 | for (j = 0; j < 8; j++) | |
33 | seq_printf(file, "%8d | ", dev->aggr_stats[i * 8 + j]); | |
34 | seq_puts(file, "\n"); | |
35 | seq_puts(file, "--------"); | |
36 | for (j = 0; j < 8; j++) | |
37 | seq_puts(file, "-----------"); | |
38 | seq_puts(file, "\n"); | |
39 | } | |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
44 | static int | |
45 | mt76x2_ampdu_stat_open(struct inode *inode, struct file *f) | |
46 | { | |
47 | return single_open(f, mt76x2_ampdu_stat_read, inode->i_private); | |
48 | } | |
49 | ||
50 | static void | |
51 | seq_puts_array(struct seq_file *file, const char *str, s8 *val, int len) | |
52 | { | |
53 | int i; | |
54 | ||
55 | seq_printf(file, "%10s:", str); | |
56 | for (i = 0; i < len; i++) | |
57 | seq_printf(file, " %2d", val[i]); | |
58 | seq_puts(file, "\n"); | |
59 | } | |
60 | ||
61 | static int read_txpower(struct seq_file *file, void *data) | |
62 | { | |
63 | struct mt76x2_dev *dev = dev_get_drvdata(file->private); | |
64 | ||
65 | seq_printf(file, "Target power: %d\n", dev->target_power); | |
66 | ||
67 | seq_puts_array(file, "Delta", dev->target_power_delta, | |
68 | ARRAY_SIZE(dev->target_power_delta)); | |
69 | seq_puts_array(file, "CCK", dev->rate_power.cck, | |
70 | ARRAY_SIZE(dev->rate_power.cck)); | |
71 | seq_puts_array(file, "OFDM", dev->rate_power.ofdm, | |
72 | ARRAY_SIZE(dev->rate_power.ofdm)); | |
73 | seq_puts_array(file, "HT", dev->rate_power.ht, | |
74 | ARRAY_SIZE(dev->rate_power.ht)); | |
75 | seq_puts_array(file, "VHT", dev->rate_power.vht, | |
76 | ARRAY_SIZE(dev->rate_power.vht)); | |
77 | return 0; | |
78 | } | |
79 | ||
80 | static const struct file_operations fops_ampdu_stat = { | |
81 | .open = mt76x2_ampdu_stat_open, | |
82 | .read = seq_read, | |
83 | .llseek = seq_lseek, | |
84 | .release = single_release, | |
85 | }; | |
86 | ||
87 | static int | |
88 | mt76x2_dfs_stat_read(struct seq_file *file, void *data) | |
89 | { | |
90 | int i; | |
91 | struct mt76x2_dev *dev = file->private; | |
92 | struct mt76x2_dfs_pattern_detector *dfs_pd = &dev->dfs_pd; | |
93 | ||
94 | for (i = 0; i < MT_DFS_NUM_ENGINES; i++) { | |
95 | seq_printf(file, "engine: %d\n", i); | |
96 | seq_printf(file, " hw pattern detected:\t%d\n", | |
97 | dfs_pd->stats[i].hw_pattern); | |
98 | seq_printf(file, " hw pulse discarded:\t%d\n", | |
99 | dfs_pd->stats[i].hw_pulse_discarded); | |
100 | } | |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | static int | |
106 | mt76x2_dfs_stat_open(struct inode *inode, struct file *f) | |
107 | { | |
108 | return single_open(f, mt76x2_dfs_stat_read, inode->i_private); | |
109 | } | |
110 | ||
111 | static const struct file_operations fops_dfs_stat = { | |
112 | .open = mt76x2_dfs_stat_open, | |
113 | .read = seq_read, | |
114 | .llseek = seq_lseek, | |
115 | .release = single_release, | |
116 | }; | |
117 | ||
118 | void mt76x2_init_debugfs(struct mt76x2_dev *dev) | |
119 | { | |
120 | struct dentry *dir; | |
121 | ||
122 | dir = mt76_register_debugfs(&dev->mt76); | |
123 | if (!dir) | |
124 | return; | |
125 | ||
126 | debugfs_create_u8("temperature", S_IRUSR, dir, &dev->cal.temp); | |
127 | debugfs_create_bool("tpc", S_IRUSR | S_IWUSR, dir, &dev->enable_tpc); | |
128 | ||
129 | debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat); | |
130 | debugfs_create_file("dfs_stats", S_IRUSR, dir, dev, &fops_dfs_stat); | |
131 | debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir, | |
132 | read_txpower); | |
133 | } |