0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <linux/debugfs.h>
0019 #include <linux/export.h>
0020
0021 #include "ath9k.h"
0022 #include "dfs_debug.h"
0023 #include "../dfs_pattern_detector.h"
0024
0025 static struct ath_dfs_pool_stats dfs_pool_stats = { 0 };
0026
0027 #define ATH9K_DFS_STAT(s, p) \
0028 len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
0029 sc->debug.stats.dfs_stats.p)
0030 #define ATH9K_DFS_POOL_STAT(s, p) \
0031 len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
0032 dfs_pool_stats.p);
0033
0034 static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
0035 size_t count, loff_t *ppos)
0036 {
0037 struct ath_softc *sc = file->private_data;
0038 struct ath9k_hw_version *hw_ver = &sc->sc_ah->hw_version;
0039 char *buf;
0040 unsigned int len = 0, size = 8000;
0041 ssize_t retval = 0;
0042
0043 buf = kzalloc(size, GFP_KERNEL);
0044 if (buf == NULL)
0045 return -ENOMEM;
0046
0047 len += scnprintf(buf + len, size - len, "DFS support for "
0048 "macVersion = 0x%x, macRev = 0x%x: %s\n",
0049 hw_ver->macVersion, hw_ver->macRev,
0050 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
0051 "enabled" : "disabled");
0052
0053 if (!sc->dfs_detector) {
0054 len += scnprintf(buf + len, size - len,
0055 "DFS detector not enabled\n");
0056 goto exit;
0057 }
0058
0059 dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
0060
0061 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
0062 ATH9K_DFS_STAT("pulse events reported ", pulses_total);
0063 ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs);
0064 ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected);
0065 ATH9K_DFS_STAT("Datalen discards ", datalen_discards);
0066 ATH9K_DFS_STAT("RSSI discards ", rssi_discards);
0067 ATH9K_DFS_STAT("BW info discards ", bwinfo_discards);
0068 ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors);
0069 ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors);
0070 ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors);
0071 len += scnprintf(buf + len, size - len, "Radar detector statistics "
0072 "(current DFS region: %d)\n",
0073 sc->dfs_detector->region);
0074 ATH9K_DFS_STAT("Pulse events processed ", pulses_processed);
0075 ATH9K_DFS_STAT("Radars detected ", radar_detected);
0076 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
0077 ATH9K_DFS_POOL_STAT("Pool references ", pool_reference);
0078 ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated);
0079 ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error);
0080 ATH9K_DFS_POOL_STAT("Pulses in use ", pulse_used);
0081 ATH9K_DFS_POOL_STAT("Seqs. allocated ", pseq_allocated);
0082 ATH9K_DFS_POOL_STAT("Seqs. alloc error ", pseq_alloc_error);
0083 ATH9K_DFS_POOL_STAT("Seqs. in use ", pseq_used);
0084
0085 exit:
0086 if (len > size)
0087 len = size;
0088
0089 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
0090 kfree(buf);
0091
0092 return retval;
0093 }
0094
0095
0096 #define DFS_STATS_RESET_MAGIC 0x80000000
0097 static ssize_t write_file_dfs(struct file *file, const char __user *user_buf,
0098 size_t count, loff_t *ppos)
0099 {
0100 struct ath_softc *sc = file->private_data;
0101 unsigned long val;
0102 char buf[32];
0103 ssize_t len;
0104
0105 len = min(count, sizeof(buf) - 1);
0106 if (copy_from_user(buf, user_buf, len))
0107 return -EFAULT;
0108
0109 buf[len] = '\0';
0110 if (kstrtoul(buf, 0, &val))
0111 return -EINVAL;
0112
0113 if (val == DFS_STATS_RESET_MAGIC)
0114 memset(&sc->debug.stats.dfs_stats, 0,
0115 sizeof(sc->debug.stats.dfs_stats));
0116 return count;
0117 }
0118
0119 static ssize_t write_file_simulate_radar(struct file *file,
0120 const char __user *user_buf,
0121 size_t count, loff_t *ppos)
0122 {
0123 struct ath_softc *sc = file->private_data;
0124
0125 ieee80211_radar_detected(sc->hw);
0126
0127 return count;
0128 }
0129
0130 static const struct file_operations fops_simulate_radar = {
0131 .write = write_file_simulate_radar,
0132 .open = simple_open,
0133 .owner = THIS_MODULE,
0134 .llseek = default_llseek,
0135 };
0136
0137 static const struct file_operations fops_dfs_stats = {
0138 .read = read_file_dfs,
0139 .write = write_file_dfs,
0140 .open = simple_open,
0141 .owner = THIS_MODULE,
0142 .llseek = default_llseek,
0143 };
0144
0145 void ath9k_dfs_init_debug(struct ath_softc *sc)
0146 {
0147 debugfs_create_file("dfs_stats", 0400,
0148 sc->debug.debugfs_phy, sc, &fops_dfs_stats);
0149 debugfs_create_file("dfs_simulate_radar", 0200,
0150 sc->debug.debugfs_phy, sc, &fops_simulate_radar);
0151 }