mt76x2_debugfs.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #include <linux/debugfs.h>
  17. #include "mt76x2.h"
  18. static int
  19. mt76x2_ampdu_stat_read(struct seq_file *file, void *data)
  20. {
  21. struct mt76x2_dev *dev = file->private;
  22. int i, j;
  23. for (i = 0; i < 4; i++) {
  24. seq_puts(file, "Length: ");
  25. for (j = 0; j < 8; j++)
  26. seq_printf(file, "%8d | ", i * 8 + j + 1);
  27. seq_puts(file, "\n");
  28. seq_puts(file, "Count: ");
  29. for (j = 0; j < 8; j++)
  30. seq_printf(file, "%8d | ", dev->aggr_stats[i * 8 + j]);
  31. seq_puts(file, "\n");
  32. seq_puts(file, "--------");
  33. for (j = 0; j < 8; j++)
  34. seq_puts(file, "-----------");
  35. seq_puts(file, "\n");
  36. }
  37. return 0;
  38. }
  39. static int
  40. mt76x2_ampdu_stat_open(struct inode *inode, struct file *f)
  41. {
  42. return single_open(f, mt76x2_ampdu_stat_read, inode->i_private);
  43. }
  44. static void
  45. seq_puts_array(struct seq_file *file, const char *str, s8 *val, int len)
  46. {
  47. int i;
  48. seq_printf(file, "%10s:", str);
  49. for (i = 0; i < len; i++)
  50. seq_printf(file, " %2d", val[i]);
  51. seq_puts(file, "\n");
  52. }
  53. static int read_txpower(struct seq_file *file, void *data)
  54. {
  55. struct mt76x2_dev *dev = dev_get_drvdata(file->private);
  56. seq_printf(file, "Target power: %d\n", dev->target_power);
  57. seq_puts_array(file, "Delta", dev->target_power_delta,
  58. ARRAY_SIZE(dev->target_power_delta));
  59. seq_puts_array(file, "CCK", dev->rate_power.cck,
  60. ARRAY_SIZE(dev->rate_power.cck));
  61. seq_puts_array(file, "OFDM", dev->rate_power.ofdm,
  62. ARRAY_SIZE(dev->rate_power.ofdm));
  63. seq_puts_array(file, "HT", dev->rate_power.ht,
  64. ARRAY_SIZE(dev->rate_power.ht));
  65. seq_puts_array(file, "VHT", dev->rate_power.vht,
  66. ARRAY_SIZE(dev->rate_power.vht));
  67. return 0;
  68. }
  69. static const struct file_operations fops_ampdu_stat = {
  70. .open = mt76x2_ampdu_stat_open,
  71. .read = seq_read,
  72. .llseek = seq_lseek,
  73. .release = single_release,
  74. };
  75. static int
  76. mt76x2_dfs_stat_read(struct seq_file *file, void *data)
  77. {
  78. int i;
  79. struct mt76x2_dev *dev = file->private;
  80. struct mt76x2_dfs_pattern_detector *dfs_pd = &dev->dfs_pd;
  81. seq_printf(file, "allocated sequences:\t%d\n",
  82. dfs_pd->seq_stats.seq_pool_len);
  83. seq_printf(file, "used sequences:\t\t%d\n",
  84. dfs_pd->seq_stats.seq_len);
  85. seq_puts(file, "\n");
  86. for (i = 0; i < MT_DFS_NUM_ENGINES; i++) {
  87. seq_printf(file, "engine: %d\n", i);
  88. seq_printf(file, " hw pattern detected:\t%d\n",
  89. dfs_pd->stats[i].hw_pattern);
  90. seq_printf(file, " hw pulse discarded:\t%d\n",
  91. dfs_pd->stats[i].hw_pulse_discarded);
  92. seq_printf(file, " sw pattern detected:\t%d\n",
  93. dfs_pd->stats[i].sw_pattern);
  94. }
  95. return 0;
  96. }
  97. static int
  98. mt76x2_dfs_stat_open(struct inode *inode, struct file *f)
  99. {
  100. return single_open(f, mt76x2_dfs_stat_read, inode->i_private);
  101. }
  102. static const struct file_operations fops_dfs_stat = {
  103. .open = mt76x2_dfs_stat_open,
  104. .read = seq_read,
  105. .llseek = seq_lseek,
  106. .release = single_release,
  107. };
  108. static int read_agc(struct seq_file *file, void *data)
  109. {
  110. struct mt76x2_dev *dev = dev_get_drvdata(file->private);
  111. seq_printf(file, "avg_rssi: %d\n", dev->cal.avg_rssi_all);
  112. seq_printf(file, "low_gain: %d\n", dev->cal.low_gain);
  113. seq_printf(file, "false_cca: %d\n", dev->cal.false_cca);
  114. seq_printf(file, "agc_gain_adjust: %d\n", dev->cal.agc_gain_adjust);
  115. return 0;
  116. }
  117. void mt76x2_init_debugfs(struct mt76x2_dev *dev)
  118. {
  119. struct dentry *dir;
  120. dir = mt76_register_debugfs(&dev->mt76);
  121. if (!dir)
  122. return;
  123. debugfs_create_u8("temperature", 0400, dir, &dev->cal.temp);
  124. debugfs_create_bool("tpc", 0600, dir, &dev->enable_tpc);
  125. debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat);
  126. debugfs_create_file("dfs_stats", 0400, dir, dev, &fops_dfs_stat);
  127. debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir,
  128. read_txpower);
  129. debugfs_create_devm_seqfile(dev->mt76.dev, "agc", dir, read_agc);
  130. }
  131. EXPORT_SYMBOL_GPL(mt76x2_init_debugfs);