1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org> 4 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl> 5 */ 6 7 #include <linux/debugfs.h> 8 9 #include "mt7601u.h" 10 #include "eeprom.h" 11 12 static int 13 mt76_reg_set(void *data, u64 val) 14 { 15 struct mt7601u_dev *dev = data; 16 17 mt76_wr(dev, dev->debugfs_reg, val); 18 return 0; 19 } 20 21 static int 22 mt76_reg_get(void *data, u64 *val) 23 { 24 struct mt7601u_dev *dev = data; 25 26 *val = mt76_rr(dev, dev->debugfs_reg); 27 return 0; 28 } 29 30 DEFINE_DEBUGFS_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n"); 31 32 static int 33 mt7601u_ampdu_stat_read(struct seq_file *file, void *data) 34 { 35 struct mt7601u_dev *dev = file->private; 36 int i, j; 37 38 #define stat_printf(grp, off, name) \ 39 seq_printf(file, #name ":\t%llu\n", dev->stats.grp[off]) 40 41 stat_printf(rx_stat, 0, rx_crc_err); 42 stat_printf(rx_stat, 1, rx_phy_err); 43 stat_printf(rx_stat, 2, rx_false_cca); 44 stat_printf(rx_stat, 3, rx_plcp_err); 45 stat_printf(rx_stat, 4, rx_fifo_overflow); 46 stat_printf(rx_stat, 5, rx_duplicate); 47 48 stat_printf(tx_stat, 0, tx_fail_cnt); 49 stat_printf(tx_stat, 1, tx_bcn_cnt); 50 stat_printf(tx_stat, 2, tx_success); 51 stat_printf(tx_stat, 3, tx_retransmit); 52 stat_printf(tx_stat, 4, tx_zero_len); 53 stat_printf(tx_stat, 5, tx_underflow); 54 55 stat_printf(aggr_stat, 0, non_aggr_tx); 56 stat_printf(aggr_stat, 1, aggr_tx); 57 58 stat_printf(zero_len_del, 0, tx_zero_len_del); 59 stat_printf(zero_len_del, 1, rx_zero_len_del); 60 #undef stat_printf 61 62 seq_puts(file, "Aggregations stats:\n"); 63 for (i = 0; i < 4; i++) { 64 for (j = 0; j < 8; j++) 65 seq_printf(file, "%08llx ", 66 dev->stats.aggr_n[i * 8 + j]); 67 seq_putc(file, '\n'); 68 } 69 70 seq_printf(file, "recent average AMPDU len: %d\n", 71 atomic_read(&dev->avg_ampdu_len)); 72 73 return 0; 74 } 75 76 static int 77 mt7601u_ampdu_stat_open(struct inode *inode, struct file *f) 78 { 79 return single_open(f, mt7601u_ampdu_stat_read, inode->i_private); 80 } 81 82 static const struct file_operations fops_ampdu_stat = { 83 .open = mt7601u_ampdu_stat_open, 84 .read = seq_read, 85 .llseek = seq_lseek, 86 .release = single_release, 87 }; 88 89 static int 90 mt7601u_eeprom_param_read(struct seq_file *file, void *data) 91 { 92 struct mt7601u_dev *dev = file->private; 93 struct mt7601u_rate_power *rp = &dev->ee->power_rate_table; 94 struct tssi_data *td = &dev->ee->tssi_data; 95 int i; 96 97 seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); 98 seq_printf(file, "RSSI offset: %hhx %hhx\n", 99 dev->ee->rssi_offset[0], dev->ee->rssi_offset[1]); 100 seq_printf(file, "Reference temp: %hhx\n", dev->ee->ref_temp); 101 seq_printf(file, "LNA gain: %hhx\n", dev->ee->lna_gain); 102 seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start, 103 dev->ee->reg.start + dev->ee->reg.num - 1); 104 105 seq_puts(file, "Per rate power:\n"); 106 for (i = 0; i < 2; i++) 107 seq_printf(file, "\t raw:%02hhx bw20:%02hhx bw40:%02hhx\n", 108 rp->cck[i].raw, rp->cck[i].bw20, rp->cck[i].bw40); 109 for (i = 0; i < 4; i++) 110 seq_printf(file, "\t raw:%02hhx bw20:%02hhx bw40:%02hhx\n", 111 rp->ofdm[i].raw, rp->ofdm[i].bw20, rp->ofdm[i].bw40); 112 for (i = 0; i < 4; i++) 113 seq_printf(file, "\t raw:%02hhx bw20:%02hhx bw40:%02hhx\n", 114 rp->ht[i].raw, rp->ht[i].bw20, rp->ht[i].bw40); 115 116 seq_puts(file, "Per channel power:\n"); 117 for (i = 0; i < 7; i++) 118 seq_printf(file, "\t tx_power ch%u:%02hhx ch%u:%02hhx\n", 119 i * 2 + 1, dev->ee->chan_pwr[i * 2], 120 i * 2 + 2, dev->ee->chan_pwr[i * 2 + 1]); 121 122 if (!dev->ee->tssi_enabled) 123 return 0; 124 125 seq_puts(file, "TSSI:\n"); 126 seq_printf(file, "\t slope:%02hhx\n", td->slope); 127 seq_printf(file, "\t offset=%02hhx %02hhx %02hhx\n", 128 td->offset[0], td->offset[1], td->offset[2]); 129 seq_printf(file, "\t delta_off:%08x\n", td->tx0_delta_offset); 130 131 return 0; 132 } 133 134 static int 135 mt7601u_eeprom_param_open(struct inode *inode, struct file *f) 136 { 137 return single_open(f, mt7601u_eeprom_param_read, inode->i_private); 138 } 139 140 static const struct file_operations fops_eeprom_param = { 141 .open = mt7601u_eeprom_param_open, 142 .read = seq_read, 143 .llseek = seq_lseek, 144 .release = single_release, 145 }; 146 147 void mt7601u_init_debugfs(struct mt7601u_dev *dev) 148 { 149 struct dentry *dir; 150 151 dir = debugfs_create_dir("mt7601u", dev->hw->wiphy->debugfsdir); 152 if (!dir) 153 return; 154 155 debugfs_create_u8("temperature", 0400, dir, &dev->raw_temp); 156 debugfs_create_u32("temp_mode", 0400, dir, &dev->temp_mode); 157 158 debugfs_create_u32("regidx", 0600, dir, &dev->debugfs_reg); 159 debugfs_create_file("regval", 0600, dir, dev, &fops_regval); 160 debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat); 161 debugfs_create_file("eeprom_param", 0400, dir, dev, &fops_eeprom_param); 162 } 163