debugfs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  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>
  5. *
  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
  9. *
  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.
  14. */
  15. #include <linux/debugfs.h>
  16. #include "mt76x0.h"
  17. #include "eeprom.h"
  18. static int
  19. mt76_reg_set(void *data, u64 val)
  20. {
  21. struct mt76x0_dev *dev = data;
  22. mt76_wr(dev, dev->debugfs_reg, val);
  23. return 0;
  24. }
  25. static int
  26. mt76_reg_get(void *data, u64 *val)
  27. {
  28. struct mt76x0_dev *dev = data;
  29. *val = mt76_rr(dev, dev->debugfs_reg);
  30. return 0;
  31. }
  32. DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n");
  33. static int
  34. mt76x0_ampdu_stat_read(struct seq_file *file, void *data)
  35. {
  36. struct mt76x0_dev *dev = file->private;
  37. int i, j;
  38. #define stat_printf(grp, off, name) \
  39. seq_printf(file, #name ":\t%llu\n", dev->stats.grp[off])
  40. stat_printf(rx_stat, 0, rx_crc_err);
  41. stat_printf(rx_stat, 1, rx_phy_err);
  42. stat_printf(rx_stat, 2, rx_false_cca);
  43. stat_printf(rx_stat, 3, rx_plcp_err);
  44. stat_printf(rx_stat, 4, rx_fifo_overflow);
  45. stat_printf(rx_stat, 5, rx_duplicate);
  46. stat_printf(tx_stat, 0, tx_fail_cnt);
  47. stat_printf(tx_stat, 1, tx_bcn_cnt);
  48. stat_printf(tx_stat, 2, tx_success);
  49. stat_printf(tx_stat, 3, tx_retransmit);
  50. stat_printf(tx_stat, 4, tx_zero_len);
  51. stat_printf(tx_stat, 5, tx_underflow);
  52. stat_printf(aggr_stat, 0, non_aggr_tx);
  53. stat_printf(aggr_stat, 1, aggr_tx);
  54. stat_printf(zero_len_del, 0, tx_zero_len_del);
  55. stat_printf(zero_len_del, 1, rx_zero_len_del);
  56. #undef stat_printf
  57. seq_puts(file, "Aggregations stats:\n");
  58. for (i = 0; i < 4; i++) {
  59. for (j = 0; j < 8; j++)
  60. seq_printf(file, "%08llx ",
  61. dev->stats.aggr_n[i * 8 + j]);
  62. seq_putc(file, '\n');
  63. }
  64. seq_printf(file, "recent average AMPDU len: %d\n",
  65. atomic_read(&dev->avg_ampdu_len));
  66. return 0;
  67. }
  68. static int
  69. mt76x0_ampdu_stat_open(struct inode *inode, struct file *f)
  70. {
  71. return single_open(f, mt76x0_ampdu_stat_read, inode->i_private);
  72. }
  73. static const struct file_operations fops_ampdu_stat = {
  74. .open = mt76x0_ampdu_stat_open,
  75. .read = seq_read,
  76. .llseek = seq_lseek,
  77. .release = single_release,
  78. };
  79. static int
  80. mt76x0_eeprom_param_read(struct seq_file *file, void *data)
  81. {
  82. struct mt76x0_dev *dev = file->private;
  83. int i;
  84. seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off);
  85. seq_printf(file, "RSSI offset 2GHz: %hhx %hhx\n",
  86. dev->ee->rssi_offset_2ghz[0], dev->ee->rssi_offset_2ghz[1]);
  87. seq_printf(file, "RSSI offset 5GHz: %hhx %hhx %hhx\n",
  88. dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1],
  89. dev->ee->rssi_offset_5ghz[2]);
  90. seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off);
  91. seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz);
  92. seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n",
  93. dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1],
  94. dev->ee->lna_gain_5ghz[2]);
  95. seq_printf(file, "Power Amplifier type %hhx\n", dev->ee->pa_type);
  96. seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start,
  97. dev->ee->reg.start + dev->ee->reg.num - 1);
  98. seq_puts(file, "Per channel power:\n");
  99. for (i = 0; i < 58; i++)
  100. seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i,
  101. dev->ee->tx_pwr_per_chan[i]);
  102. seq_puts(file, "Per rate power 2GHz:\n");
  103. for (i = 0; i < 5; i++)
  104. seq_printf(file, "\t %d bw20:%d bw40:%d\n",
  105. i, dev->ee->tx_pwr_cfg_2g[i][0],
  106. dev->ee->tx_pwr_cfg_5g[i][1]);
  107. seq_puts(file, "Per rate power 5GHz:\n");
  108. for (i = 0; i < 5; i++)
  109. seq_printf(file, "\t %d bw20:%d bw40:%d\n",
  110. i, dev->ee->tx_pwr_cfg_5g[i][0],
  111. dev->ee->tx_pwr_cfg_5g[i][1]);
  112. return 0;
  113. }
  114. static int
  115. mt76x0_eeprom_param_open(struct inode *inode, struct file *f)
  116. {
  117. return single_open(f, mt76x0_eeprom_param_read, inode->i_private);
  118. }
  119. static const struct file_operations fops_eeprom_param = {
  120. .open = mt76x0_eeprom_param_open,
  121. .read = seq_read,
  122. .llseek = seq_lseek,
  123. .release = single_release,
  124. };
  125. void mt76x0_init_debugfs(struct mt76x0_dev *dev)
  126. {
  127. struct dentry *dir;
  128. dir = debugfs_create_dir("mt76x0", dev->mt76.hw->wiphy->debugfsdir);
  129. if (!dir)
  130. return;
  131. debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg);
  132. debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev,
  133. &fops_regval);
  134. debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat);
  135. debugfs_create_file("eeprom_param", S_IRUSR, dir, dev,
  136. &fops_eeprom_param);
  137. }