debugfs.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/debugfs.h>
  15. #include "mt7601u.h"
  16. #include "eeprom.h"
  17. static int
  18. mt76_reg_set(void *data, u64 val)
  19. {
  20. struct mt7601u_dev *dev = data;
  21. mt76_wr(dev, dev->debugfs_reg, val);
  22. return 0;
  23. }
  24. static int
  25. mt76_reg_get(void *data, u64 *val)
  26. {
  27. struct mt7601u_dev *dev = data;
  28. *val = mt76_rr(dev, dev->debugfs_reg);
  29. return 0;
  30. }
  31. DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n");
  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. #define stat_printf(grp, off, name) \
  38. seq_printf(file, #name ":\t%llu\n", dev->stats.grp[off])
  39. stat_printf(rx_stat, 0, rx_crc_err);
  40. stat_printf(rx_stat, 1, rx_phy_err);
  41. stat_printf(rx_stat, 2, rx_false_cca);
  42. stat_printf(rx_stat, 3, rx_plcp_err);
  43. stat_printf(rx_stat, 4, rx_fifo_overflow);
  44. stat_printf(rx_stat, 5, rx_duplicate);
  45. stat_printf(tx_stat, 0, tx_fail_cnt);
  46. stat_printf(tx_stat, 1, tx_bcn_cnt);
  47. stat_printf(tx_stat, 2, tx_success);
  48. stat_printf(tx_stat, 3, tx_retransmit);
  49. stat_printf(tx_stat, 4, tx_zero_len);
  50. stat_printf(tx_stat, 5, tx_underflow);
  51. stat_printf(aggr_stat, 0, non_aggr_tx);
  52. stat_printf(aggr_stat, 1, aggr_tx);
  53. stat_printf(zero_len_del, 0, tx_zero_len_del);
  54. stat_printf(zero_len_del, 1, rx_zero_len_del);
  55. #undef stat_printf
  56. seq_puts(file, "Aggregations stats:\n");
  57. for (i = 0; i < 4; i++) {
  58. for (j = 0; j < 8; j++)
  59. seq_printf(file, "%08llx ",
  60. dev->stats.aggr_n[i * 8 + j]);
  61. seq_putc(file, '\n');
  62. }
  63. seq_printf(file, "recent average AMPDU len: %d\n",
  64. atomic_read(&dev->avg_ampdu_len));
  65. return 0;
  66. }
  67. static int
  68. mt7601u_ampdu_stat_open(struct inode *inode, struct file *f)
  69. {
  70. return single_open(f, mt7601u_ampdu_stat_read, inode->i_private);
  71. }
  72. static const struct file_operations fops_ampdu_stat = {
  73. .open = mt7601u_ampdu_stat_open,
  74. .read = seq_read,
  75. .llseek = seq_lseek,
  76. .release = single_release,
  77. };
  78. static int
  79. mt7601u_eeprom_param_read(struct seq_file *file, void *data)
  80. {
  81. struct mt7601u_dev *dev = file->private;
  82. struct mt7601u_rate_power *rp = &dev->ee->power_rate_table;
  83. struct tssi_data *td = &dev->ee->tssi_data;
  84. int i;
  85. seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off);
  86. seq_printf(file, "RSSI offset: %hhx %hhx\n",
  87. dev->ee->rssi_offset[0], dev->ee->rssi_offset[1]);
  88. seq_printf(file, "Reference temp: %hhx\n", dev->ee->ref_temp);
  89. seq_printf(file, "LNA gain: %hhx\n", dev->ee->lna_gain);
  90. seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start,
  91. dev->ee->reg.start + dev->ee->reg.num - 1);
  92. seq_puts(file, "Per rate power:\n");
  93. for (i = 0; i < 2; i++)
  94. seq_printf(file, "\t raw:%02hhx bw20:%02hhx bw40:%02hhx\n",
  95. rp->cck[i].raw, rp->cck[i].bw20, rp->cck[i].bw40);
  96. for (i = 0; i < 4; i++)
  97. seq_printf(file, "\t raw:%02hhx bw20:%02hhx bw40:%02hhx\n",
  98. rp->ofdm[i].raw, rp->ofdm[i].bw20, rp->ofdm[i].bw40);
  99. for (i = 0; i < 4; i++)
  100. seq_printf(file, "\t raw:%02hhx bw20:%02hhx bw40:%02hhx\n",
  101. rp->ht[i].raw, rp->ht[i].bw20, rp->ht[i].bw40);
  102. seq_puts(file, "Per channel power:\n");
  103. for (i = 0; i < 7; i++)
  104. seq_printf(file, "\t tx_power ch%u:%02hhx ch%u:%02hhx\n",
  105. i * 2 + 1, dev->ee->chan_pwr[i * 2],
  106. i * 2 + 2, dev->ee->chan_pwr[i * 2 + 1]);
  107. if (!dev->ee->tssi_enabled)
  108. return 0;
  109. seq_puts(file, "TSSI:\n");
  110. seq_printf(file, "\t slope:%02hhx\n", td->slope);
  111. seq_printf(file, "\t offset=%02hhx %02hhx %02hhx\n",
  112. td->offset[0], td->offset[1], td->offset[2]);
  113. seq_printf(file, "\t delta_off:%08x\n", td->tx0_delta_offset);
  114. return 0;
  115. }
  116. static int
  117. mt7601u_eeprom_param_open(struct inode *inode, struct file *f)
  118. {
  119. return single_open(f, mt7601u_eeprom_param_read, inode->i_private);
  120. }
  121. static const struct file_operations fops_eeprom_param = {
  122. .open = mt7601u_eeprom_param_open,
  123. .read = seq_read,
  124. .llseek = seq_lseek,
  125. .release = single_release,
  126. };
  127. void mt7601u_init_debugfs(struct mt7601u_dev *dev)
  128. {
  129. struct dentry *dir;
  130. dir = debugfs_create_dir("mt7601u", dev->hw->wiphy->debugfsdir);
  131. if (!dir)
  132. return;
  133. debugfs_create_u8("temperature", S_IRUSR, dir, &dev->raw_temp);
  134. debugfs_create_u32("temp_mode", S_IRUSR, dir, &dev->temp_mode);
  135. debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg);
  136. debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev,
  137. &fops_regval);
  138. debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat);
  139. debugfs_create_file("eeprom_param", S_IRUSR, dir, dev,
  140. &fops_eeprom_param);
  141. }