Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 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 | |
| 18 | #include <linux/debugfs.h> |
| 19 | #include <linux/export.h> |
| 20 | |
| 21 | #include "ath9k.h" |
| 22 | #include "dfs_debug.h" |
Janusz Dziedzic | ad40d3d | 2013-10-14 11:06:06 +0200 | [diff] [blame] | 23 | #include "../dfs_pattern_detector.h" |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 24 | |
Janusz Dziedzic | d265214 | 2013-10-14 11:06:04 +0200 | [diff] [blame] | 25 | static struct ath_dfs_pool_stats dfs_pool_stats = { 0 }; |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 26 | |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 27 | #define ATH9K_DFS_STAT(s, p) \ |
Zefir Kurtisi | 5e88ba6 | 2013-09-05 14:11:57 +0200 | [diff] [blame] | 28 | len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \ |
| 29 | sc->debug.stats.dfs_stats.p); |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 30 | #define ATH9K_DFS_POOL_STAT(s, p) \ |
Zefir Kurtisi | 5e88ba6 | 2013-09-05 14:11:57 +0200 | [diff] [blame] | 31 | len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \ |
Janusz Dziedzic | d265214 | 2013-10-14 11:06:04 +0200 | [diff] [blame] | 32 | dfs_pool_stats.p); |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 33 | |
| 34 | static ssize_t read_file_dfs(struct file *file, char __user *user_buf, |
| 35 | size_t count, loff_t *ppos) |
| 36 | { |
| 37 | struct ath_softc *sc = file->private_data; |
| 38 | struct ath9k_hw_version *hw_ver = &sc->sc_ah->hw_version; |
| 39 | char *buf; |
| 40 | unsigned int len = 0, size = 8000; |
| 41 | ssize_t retval = 0; |
| 42 | |
| 43 | buf = kzalloc(size, GFP_KERNEL); |
| 44 | if (buf == NULL) |
| 45 | return -ENOMEM; |
| 46 | |
Zefir Kurtisi | 5e88ba6 | 2013-09-05 14:11:57 +0200 | [diff] [blame] | 47 | len += scnprintf(buf + len, size - len, "DFS support for " |
| 48 | "macVersion = 0x%x, macRev = 0x%x: %s\n", |
| 49 | hw_ver->macVersion, hw_ver->macRev, |
| 50 | (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ? |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 51 | "enabled" : "disabled"); |
Janusz Dziedzic | 4be6718c | 2013-11-01 21:05:28 +0100 | [diff] [blame] | 52 | |
| 53 | if (!sc->dfs_detector) { |
| 54 | len += scnprintf(buf + len, size - len, |
| 55 | "DFS detector not enabled\n"); |
| 56 | goto exit; |
| 57 | } |
| 58 | |
| 59 | dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector); |
| 60 | |
Zefir Kurtisi | 5e88ba6 | 2013-09-05 14:11:57 +0200 | [diff] [blame] | 61 | len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n"); |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 62 | ATH9K_DFS_STAT("pulse events reported ", pulses_total); |
| 63 | ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs); |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 64 | ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected); |
| 65 | ATH9K_DFS_STAT("Datalen discards ", datalen_discards); |
| 66 | ATH9K_DFS_STAT("RSSI discards ", rssi_discards); |
| 67 | ATH9K_DFS_STAT("BW info discards ", bwinfo_discards); |
| 68 | ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors); |
| 69 | ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors); |
| 70 | ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors); |
Zefir Kurtisi | 5e88ba6 | 2013-09-05 14:11:57 +0200 | [diff] [blame] | 71 | len += scnprintf(buf + len, size - len, "Radar detector statistics " |
| 72 | "(current DFS region: %d)\n", |
| 73 | sc->dfs_detector->region); |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 74 | ATH9K_DFS_STAT("Pulse events processed ", pulses_processed); |
| 75 | ATH9K_DFS_STAT("Radars detected ", radar_detected); |
Zefir Kurtisi | 5e88ba6 | 2013-09-05 14:11:57 +0200 | [diff] [blame] | 76 | len += scnprintf(buf + len, size - len, "Global Pool statistics:\n"); |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 77 | ATH9K_DFS_POOL_STAT("Pool references ", pool_reference); |
| 78 | ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated); |
| 79 | ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error); |
| 80 | ATH9K_DFS_POOL_STAT("Pulses in use ", pulse_used); |
| 81 | ATH9K_DFS_POOL_STAT("Seqs. allocated ", pseq_allocated); |
| 82 | ATH9K_DFS_POOL_STAT("Seqs. alloc error ", pseq_alloc_error); |
| 83 | ATH9K_DFS_POOL_STAT("Seqs. in use ", pseq_used); |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 84 | |
Janusz Dziedzic | 4be6718c | 2013-11-01 21:05:28 +0100 | [diff] [blame] | 85 | exit: |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 86 | if (len > size) |
| 87 | len = size; |
| 88 | |
| 89 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 90 | kfree(buf); |
| 91 | |
| 92 | return retval; |
| 93 | } |
| 94 | |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 95 | /* magic number to prevent accidental reset of DFS statistics */ |
| 96 | #define DFS_STATS_RESET_MAGIC 0x80000000 |
| 97 | static ssize_t write_file_dfs(struct file *file, const char __user *user_buf, |
| 98 | size_t count, loff_t *ppos) |
| 99 | { |
| 100 | struct ath_softc *sc = file->private_data; |
| 101 | unsigned long val; |
| 102 | char buf[32]; |
| 103 | ssize_t len; |
| 104 | |
| 105 | len = min(count, sizeof(buf) - 1); |
| 106 | if (copy_from_user(buf, user_buf, len)) |
| 107 | return -EFAULT; |
| 108 | |
| 109 | buf[len] = '\0'; |
Jingoo Han | 27d7f47 | 2013-05-31 21:24:06 +0000 | [diff] [blame] | 110 | if (kstrtoul(buf, 0, &val)) |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 111 | return -EINVAL; |
| 112 | |
| 113 | if (val == DFS_STATS_RESET_MAGIC) |
| 114 | memset(&sc->debug.stats.dfs_stats, 0, |
| 115 | sizeof(sc->debug.stats.dfs_stats)); |
| 116 | return count; |
| 117 | } |
| 118 | |
Zefir Kurtisi | e39282e | 2013-04-03 18:31:30 +0200 | [diff] [blame] | 119 | static ssize_t write_file_simulate_radar(struct file *file, |
| 120 | const char __user *user_buf, |
| 121 | size_t count, loff_t *ppos) |
| 122 | { |
| 123 | struct ath_softc *sc = file->private_data; |
| 124 | |
| 125 | ieee80211_radar_detected(sc->hw); |
| 126 | |
| 127 | return count; |
| 128 | } |
| 129 | |
| 130 | static const struct file_operations fops_simulate_radar = { |
| 131 | .write = write_file_simulate_radar, |
| 132 | .open = simple_open, |
| 133 | .owner = THIS_MODULE, |
| 134 | .llseek = default_llseek, |
| 135 | }; |
| 136 | |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 137 | static const struct file_operations fops_dfs_stats = { |
| 138 | .read = read_file_dfs, |
Zefir Kurtisi | b96f20b | 2012-04-20 17:20:34 +0200 | [diff] [blame] | 139 | .write = write_file_dfs, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 140 | .open = simple_open, |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 141 | .owner = THIS_MODULE, |
| 142 | .llseek = default_llseek, |
| 143 | }; |
| 144 | |
| 145 | void ath9k_dfs_init_debug(struct ath_softc *sc) |
| 146 | { |
| 147 | debugfs_create_file("dfs_stats", S_IRUSR, |
| 148 | sc->debug.debugfs_phy, sc, &fops_dfs_stats); |
Zefir Kurtisi | e39282e | 2013-04-03 18:31:30 +0200 | [diff] [blame] | 149 | debugfs_create_file("dfs_simulate_radar", S_IWUSR, |
| 150 | sc->debug.debugfs_phy, sc, &fops_simulate_radar); |
Zefir Kurtisi | 29942bc | 2011-12-14 20:16:34 -0800 | [diff] [blame] | 151 | } |