mt76x02_debugfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  4. */
  5. #include <linux/debugfs.h>
  6. #include "mt76x02.h"
  7. static int
  8. mt76x02_ampdu_stat_show(struct seq_file *file, void *data)
  9. {
  10. struct mt76x02_dev *dev = file->private;
  11. int i, j;
  12. for (i = 0; i < 4; i++) {
  13. seq_puts(file, "Length: ");
  14. for (j = 0; j < 8; j++)
  15. seq_printf(file, "%8d | ", i * 8 + j + 1);
  16. seq_puts(file, "\n");
  17. seq_puts(file, "Count: ");
  18. for (j = 0; j < 8; j++)
  19. seq_printf(file, "%8d | ",
  20. dev->mt76.aggr_stats[i * 8 + j]);
  21. seq_puts(file, "\n");
  22. seq_puts(file, "--------");
  23. for (j = 0; j < 8; j++)
  24. seq_puts(file, "-----------");
  25. seq_puts(file, "\n");
  26. }
  27. return 0;
  28. }
  29. DEFINE_SHOW_ATTRIBUTE(mt76x02_ampdu_stat);
  30. static int read_txpower(struct seq_file *file, void *data)
  31. {
  32. struct mt76x02_dev *dev = dev_get_drvdata(file->private);
  33. seq_printf(file, "Target power: %d\n", dev->target_power);
  34. mt76_seq_puts_array(file, "Delta", dev->target_power_delta,
  35. ARRAY_SIZE(dev->target_power_delta));
  36. return 0;
  37. }
  38. static int
  39. mt76x02_dfs_stat_show(struct seq_file *file, void *data)
  40. {
  41. struct mt76x02_dev *dev = file->private;
  42. struct mt76x02_dfs_pattern_detector *dfs_pd = &dev->dfs_pd;
  43. int i;
  44. seq_printf(file, "allocated sequences:\t%d\n",
  45. dfs_pd->seq_stats.seq_pool_len);
  46. seq_printf(file, "used sequences:\t\t%d\n",
  47. dfs_pd->seq_stats.seq_len);
  48. seq_puts(file, "\n");
  49. for (i = 0; i < MT_DFS_NUM_ENGINES; i++) {
  50. seq_printf(file, "engine: %d\n", i);
  51. seq_printf(file, " hw pattern detected:\t%d\n",
  52. dfs_pd->stats[i].hw_pattern);
  53. seq_printf(file, " hw pulse discarded:\t%d\n",
  54. dfs_pd->stats[i].hw_pulse_discarded);
  55. seq_printf(file, " sw pattern detected:\t%d\n",
  56. dfs_pd->stats[i].sw_pattern);
  57. }
  58. return 0;
  59. }
  60. DEFINE_SHOW_ATTRIBUTE(mt76x02_dfs_stat);
  61. static int read_agc(struct seq_file *file, void *data)
  62. {
  63. struct mt76x02_dev *dev = dev_get_drvdata(file->private);
  64. seq_printf(file, "avg_rssi: %d\n", dev->cal.avg_rssi_all);
  65. seq_printf(file, "low_gain: %d\n", dev->cal.low_gain);
  66. seq_printf(file, "false_cca: %d\n", dev->cal.false_cca);
  67. seq_printf(file, "agc_gain_adjust: %d\n", dev->cal.agc_gain_adjust);
  68. return 0;
  69. }
  70. static int
  71. mt76_edcca_set(void *data, u64 val)
  72. {
  73. struct mt76x02_dev *dev = data;
  74. enum nl80211_dfs_regions region = dev->mt76.region;
  75. mutex_lock(&dev->mt76.mutex);
  76. dev->ed_monitor_enabled = !!val;
  77. dev->ed_monitor = dev->ed_monitor_enabled &&
  78. region == NL80211_DFS_ETSI;
  79. mt76x02_edcca_init(dev);
  80. mutex_unlock(&dev->mt76.mutex);
  81. return 0;
  82. }
  83. static int
  84. mt76_edcca_get(void *data, u64 *val)
  85. {
  86. struct mt76x02_dev *dev = data;
  87. *val = dev->ed_monitor_enabled;
  88. return 0;
  89. }
  90. DEFINE_DEBUGFS_ATTRIBUTE(fops_edcca, mt76_edcca_get, mt76_edcca_set,
  91. "%lld\n");
  92. void mt76x02_init_debugfs(struct mt76x02_dev *dev)
  93. {
  94. struct dentry *dir;
  95. dir = mt76_register_debugfs(&dev->mt76);
  96. if (!dir)
  97. return;
  98. debugfs_create_devm_seqfile(dev->mt76.dev, "xmit-queues", dir,
  99. mt76_queues_read);
  100. debugfs_create_u8("temperature", 0400, dir, &dev->cal.temp);
  101. debugfs_create_bool("tpc", 0600, dir, &dev->enable_tpc);
  102. debugfs_create_file("edcca", 0600, dir, dev, &fops_edcca);
  103. debugfs_create_file("ampdu_stat", 0400, dir, dev, &mt76x02_ampdu_stat_fops);
  104. debugfs_create_file("dfs_stats", 0400, dir, dev, &mt76x02_dfs_stat_fops);
  105. debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir,
  106. read_txpower);
  107. debugfs_create_devm_seqfile(dev->mt76.dev, "agc", dir, read_agc);
  108. debugfs_create_u32("tx_hang_reset", 0400, dir, &dev->tx_hang_reset);
  109. }
  110. EXPORT_SYMBOL_GPL(mt76x02_init_debugfs);