mt76x2_debugfs.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. for (i = 0; i < MT_DFS_NUM_ENGINES; i++) {
  82. seq_printf(file, "engine: %d\n", i);
  83. seq_printf(file, " hw pattern detected:\t%d\n",
  84. dfs_pd->stats[i].hw_pattern);
  85. seq_printf(file, " hw pulse discarded:\t%d\n",
  86. dfs_pd->stats[i].hw_pulse_discarded);
  87. }
  88. return 0;
  89. }
  90. static int
  91. mt76x2_dfs_stat_open(struct inode *inode, struct file *f)
  92. {
  93. return single_open(f, mt76x2_dfs_stat_read, inode->i_private);
  94. }
  95. static const struct file_operations fops_dfs_stat = {
  96. .open = mt76x2_dfs_stat_open,
  97. .read = seq_read,
  98. .llseek = seq_lseek,
  99. .release = single_release,
  100. };
  101. void mt76x2_init_debugfs(struct mt76x2_dev *dev)
  102. {
  103. struct dentry *dir;
  104. dir = mt76_register_debugfs(&dev->mt76);
  105. if (!dir)
  106. return;
  107. debugfs_create_u8("temperature", 0400, dir, &dev->cal.temp);
  108. debugfs_create_bool("tpc", 0600, dir, &dev->enable_tpc);
  109. debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat);
  110. debugfs_create_file("dfs_stats", 0400, dir, dev, &fops_dfs_stat);
  111. debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir,
  112. read_txpower);
  113. }