dfs_debug.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. if (sc->dfs_detector)
  41. dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
  42. len += scnprintf(buf + len, size - len, "DFS support for "
  43. "macVersion = 0x%x, macRev = 0x%x: %s\n",
  44. hw_ver->macVersion, hw_ver->macRev,
  45. (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
  46. "enabled" : "disabled");
  47. len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
  48. ATH9K_DFS_STAT("pulse events reported ", pulses_total);
  49. ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs);
  50. ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected);
  51. ATH9K_DFS_STAT("Datalen discards ", datalen_discards);
  52. ATH9K_DFS_STAT("RSSI discards ", rssi_discards);
  53. ATH9K_DFS_STAT("BW info discards ", bwinfo_discards);
  54. ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors);
  55. ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors);
  56. ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors);
  57. len += scnprintf(buf + len, size - len, "Radar detector statistics "
  58. "(current DFS region: %d)\n",
  59. sc->dfs_detector->region);
  60. ATH9K_DFS_STAT("Pulse events processed ", pulses_processed);
  61. ATH9K_DFS_STAT("Radars detected ", radar_detected);
  62. len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
  63. ATH9K_DFS_POOL_STAT("Pool references ", pool_reference);
  64. ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated);
  65. ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error);
  66. ATH9K_DFS_POOL_STAT("Pulses in use ", pulse_used);
  67. ATH9K_DFS_POOL_STAT("Seqs. allocated ", pseq_allocated);
  68. ATH9K_DFS_POOL_STAT("Seqs. alloc error ", pseq_alloc_error);
  69. ATH9K_DFS_POOL_STAT("Seqs. in use ", pseq_used);
  70. if (len > size)
  71. len = size;
  72. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  73. kfree(buf);
  74. return retval;
  75. }
  76. /* magic number to prevent accidental reset of DFS statistics */
  77. #define DFS_STATS_RESET_MAGIC 0x80000000
  78. static ssize_t write_file_dfs(struct file *file, const char __user *user_buf,
  79. size_t count, loff_t *ppos)
  80. {
  81. struct ath_softc *sc = file->private_data;
  82. unsigned long val;
  83. char buf[32];
  84. ssize_t len;
  85. len = min(count, sizeof(buf) - 1);
  86. if (copy_from_user(buf, user_buf, len))
  87. return -EFAULT;
  88. buf[len] = '\0';
  89. if (kstrtoul(buf, 0, &val))
  90. return -EINVAL;
  91. if (val == DFS_STATS_RESET_MAGIC)
  92. memset(&sc->debug.stats.dfs_stats, 0,
  93. sizeof(sc->debug.stats.dfs_stats));
  94. return count;
  95. }
  96. static ssize_t write_file_simulate_radar(struct file *file,
  97. const char __user *user_buf,
  98. size_t count, loff_t *ppos)
  99. {
  100. struct ath_softc *sc = file->private_data;
  101. ieee80211_radar_detected(sc->hw);
  102. return count;
  103. }
  104. static const struct file_operations fops_simulate_radar = {
  105. .write = write_file_simulate_radar,
  106. .open = simple_open,
  107. .owner = THIS_MODULE,
  108. .llseek = default_llseek,
  109. };
  110. static const struct file_operations fops_dfs_stats = {
  111. .read = read_file_dfs,
  112. .write = write_file_dfs,
  113. .open = simple_open,
  114. .owner = THIS_MODULE,
  115. .llseek = default_llseek,
  116. };
  117. void ath9k_dfs_init_debug(struct ath_softc *sc)
  118. {
  119. debugfs_create_file("dfs_stats", S_IRUSR,
  120. sc->debug.debugfs_phy, sc, &fops_dfs_stats);
  121. debugfs_create_file("dfs_simulate_radar", S_IWUSR,
  122. sc->debug.debugfs_phy, sc, &fops_simulate_radar);
  123. }