dfs_debug.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011 Neratec Solutions AG
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/debugfs.h>
  18. #include <linux/export.h>
  19. #include "ath9k.h"
  20. #include "dfs_debug.h"
  21. #include "../dfs_pattern_detector.h"
  22. static struct ath_dfs_pool_stats dfs_pool_stats = { 0 };
  23. #define ATH9K_DFS_STAT(s, p) \
  24. len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
  25. sc->debug.stats.dfs_stats.p);
  26. #define ATH9K_DFS_POOL_STAT(s, p) \
  27. len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
  28. dfs_pool_stats.p);
  29. static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
  30. size_t count, loff_t *ppos)
  31. {
  32. struct ath_softc *sc = file->private_data;
  33. struct ath9k_hw_version *hw_ver = &sc->sc_ah->hw_version;
  34. char *buf;
  35. unsigned int len = 0, size = 8000;
  36. ssize_t retval = 0;
  37. buf = kzalloc(size, GFP_KERNEL);
  38. if (buf == NULL)
  39. return -ENOMEM;
  40. len += scnprintf(buf + len, size - len, "DFS support for "
  41. "macVersion = 0x%x, macRev = 0x%x: %s\n",
  42. hw_ver->macVersion, hw_ver->macRev,
  43. (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
  44. "enabled" : "disabled");
  45. if (!sc->dfs_detector) {
  46. len += scnprintf(buf + len, size - len,
  47. "DFS detector not enabled\n");
  48. goto exit;
  49. }
  50. dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
  51. len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
  52. ATH9K_DFS_STAT("pulse events reported ", pulses_total);
  53. ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs);
  54. ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected);
  55. ATH9K_DFS_STAT("Datalen discards ", datalen_discards);
  56. ATH9K_DFS_STAT("RSSI discards ", rssi_discards);
  57. ATH9K_DFS_STAT("BW info discards ", bwinfo_discards);
  58. ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors);
  59. ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors);
  60. ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors);
  61. len += scnprintf(buf + len, size - len, "Radar detector statistics "
  62. "(current DFS region: %d)\n",
  63. sc->dfs_detector->region);
  64. ATH9K_DFS_STAT("Pulse events processed ", pulses_processed);
  65. ATH9K_DFS_STAT("Radars detected ", radar_detected);
  66. len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
  67. ATH9K_DFS_POOL_STAT("Pool references ", pool_reference);
  68. ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated);
  69. ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error);
  70. ATH9K_DFS_POOL_STAT("Pulses in use ", pulse_used);
  71. ATH9K_DFS_POOL_STAT("Seqs. allocated ", pseq_allocated);
  72. ATH9K_DFS_POOL_STAT("Seqs. alloc error ", pseq_alloc_error);
  73. ATH9K_DFS_POOL_STAT("Seqs. in use ", pseq_used);
  74. exit:
  75. if (len > size)
  76. len = size;
  77. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  78. kfree(buf);
  79. return retval;
  80. }
  81. /* magic number to prevent accidental reset of DFS statistics */
  82. #define DFS_STATS_RESET_MAGIC 0x80000000
  83. static ssize_t write_file_dfs(struct file *file, const char __user *user_buf,
  84. size_t count, loff_t *ppos)
  85. {
  86. struct ath_softc *sc = file->private_data;
  87. unsigned long val;
  88. char buf[32];
  89. ssize_t len;
  90. len = min(count, sizeof(buf) - 1);
  91. if (copy_from_user(buf, user_buf, len))
  92. return -EFAULT;
  93. buf[len] = '\0';
  94. if (kstrtoul(buf, 0, &val))
  95. return -EINVAL;
  96. if (val == DFS_STATS_RESET_MAGIC)
  97. memset(&sc->debug.stats.dfs_stats, 0,
  98. sizeof(sc->debug.stats.dfs_stats));
  99. return count;
  100. }
  101. static ssize_t write_file_simulate_radar(struct file *file,
  102. const char __user *user_buf,
  103. size_t count, loff_t *ppos)
  104. {
  105. struct ath_softc *sc = file->private_data;
  106. ieee80211_radar_detected(sc->hw);
  107. return count;
  108. }
  109. static const struct file_operations fops_simulate_radar = {
  110. .write = write_file_simulate_radar,
  111. .open = simple_open,
  112. .owner = THIS_MODULE,
  113. .llseek = default_llseek,
  114. };
  115. static const struct file_operations fops_dfs_stats = {
  116. .read = read_file_dfs,
  117. .write = write_file_dfs,
  118. .open = simple_open,
  119. .owner = THIS_MODULE,
  120. .llseek = default_llseek,
  121. };
  122. void ath9k_dfs_init_debug(struct ath_softc *sc)
  123. {
  124. debugfs_create_file("dfs_stats", S_IRUSR,
  125. sc->debug.debugfs_phy, sc, &fops_dfs_stats);
  126. debugfs_create_file("dfs_simulate_radar", S_IWUSR,
  127. sc->debug.debugfs_phy, sc, &fops_simulate_radar);
  128. }