2 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
4 * Copyright (C) 2018 Stanislaw Gruszka <stf_xl@wp.pl>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/debugfs.h>
22 mt76_reg_set(void *data, u64 val)
24 struct mt76x0_dev *dev = data;
26 mt76_wr(dev, dev->debugfs_reg, val);
31 mt76_reg_get(void *data, u64 *val)
33 struct mt76x0_dev *dev = data;
35 *val = mt76_rr(dev, dev->debugfs_reg);
39 DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n");
42 mt76x0_ampdu_stat_read(struct seq_file *file, void *data)
44 struct mt76x0_dev *dev = file->private;
47 #define stat_printf(grp, off, name) \
48 seq_printf(file, #name ":\t%llu\n", dev->stats.grp[off])
50 stat_printf(rx_stat, 0, rx_crc_err);
51 stat_printf(rx_stat, 1, rx_phy_err);
52 stat_printf(rx_stat, 2, rx_false_cca);
53 stat_printf(rx_stat, 3, rx_plcp_err);
54 stat_printf(rx_stat, 4, rx_fifo_overflow);
55 stat_printf(rx_stat, 5, rx_duplicate);
57 stat_printf(tx_stat, 0, tx_fail_cnt);
58 stat_printf(tx_stat, 1, tx_bcn_cnt);
59 stat_printf(tx_stat, 2, tx_success);
60 stat_printf(tx_stat, 3, tx_retransmit);
61 stat_printf(tx_stat, 4, tx_zero_len);
62 stat_printf(tx_stat, 5, tx_underflow);
64 stat_printf(aggr_stat, 0, non_aggr_tx);
65 stat_printf(aggr_stat, 1, aggr_tx);
67 stat_printf(zero_len_del, 0, tx_zero_len_del);
68 stat_printf(zero_len_del, 1, rx_zero_len_del);
71 seq_puts(file, "Aggregations stats:\n");
72 for (i = 0; i < 4; i++) {
73 for (j = 0; j < 8; j++)
74 seq_printf(file, "%08llx ",
75 dev->stats.aggr_n[i * 8 + j]);
79 seq_printf(file, "recent average AMPDU len: %d\n",
80 atomic_read(&dev->avg_ampdu_len));
86 mt76x0_ampdu_stat_open(struct inode *inode, struct file *f)
88 return single_open(f, mt76x0_ampdu_stat_read, inode->i_private);
91 static const struct file_operations fops_ampdu_stat = {
92 .open = mt76x0_ampdu_stat_open,
95 .release = single_release,
99 mt76x0_eeprom_param_read(struct seq_file *file, void *data)
101 struct mt76x0_dev *dev = file->private;
104 seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off);
105 seq_printf(file, "RSSI offset 2GHz: %hhx %hhx\n",
106 dev->ee->rssi_offset_2ghz[0], dev->ee->rssi_offset_2ghz[1]);
107 seq_printf(file, "RSSI offset 5GHz: %hhx %hhx %hhx\n",
108 dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1],
109 dev->ee->rssi_offset_5ghz[2]);
110 seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off);
111 seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz);
112 seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n",
113 dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1],
114 dev->ee->lna_gain_5ghz[2]);
115 seq_printf(file, "Power Amplifier type %hhx\n", dev->ee->pa_type);
116 seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start,
117 dev->ee->reg.start + dev->ee->reg.num - 1);
119 seq_puts(file, "Per channel power:\n");
120 for (i = 0; i < 58; i++)
121 seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i,
122 dev->ee->tx_pwr_per_chan[i]);
124 seq_puts(file, "Per rate power 2GHz:\n");
125 for (i = 0; i < 5; i++)
126 seq_printf(file, "\t %d bw20:%d bw40:%d\n",
127 i, dev->ee->tx_pwr_cfg_2g[i][0],
128 dev->ee->tx_pwr_cfg_5g[i][1]);
130 seq_puts(file, "Per rate power 5GHz:\n");
131 for (i = 0; i < 5; i++)
132 seq_printf(file, "\t %d bw20:%d bw40:%d\n",
133 i, dev->ee->tx_pwr_cfg_5g[i][0],
134 dev->ee->tx_pwr_cfg_5g[i][1]);
140 mt76x0_eeprom_param_open(struct inode *inode, struct file *f)
142 return single_open(f, mt76x0_eeprom_param_read, inode->i_private);
145 static const struct file_operations fops_eeprom_param = {
146 .open = mt76x0_eeprom_param_open,
149 .release = single_release,
152 void mt76x0_init_debugfs(struct mt76x0_dev *dev)
156 dir = debugfs_create_dir("mt76x0", dev->mt76.hw->wiphy->debugfsdir);
160 debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg);
161 debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev,
163 debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat);
164 debugfs_create_file("eeprom_param", S_IRUSR, dir, dev,