blob: 990c376307259b6bd9b65428016d923f27701657 [file] [log] [blame]
Zefir Kurtisi29942bc2011-12-14 20:16:34 -08001/*
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 Dziedzicd2652142013-10-14 11:06:04 +020023#include "dfs_pattern_detector.h"
Zefir Kurtisi29942bc2011-12-14 20:16:34 -080024
Janusz Dziedzicd2652142013-10-14 11:06:04 +020025static struct ath_dfs_pool_stats dfs_pool_stats = { 0 };
Zefir Kurtisib96f20b2012-04-20 17:20:34 +020026
Zefir Kurtisi29942bc2011-12-14 20:16:34 -080027#define ATH9K_DFS_STAT(s, p) \
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +020028 len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
29 sc->debug.stats.dfs_stats.p);
Zefir Kurtisib96f20b2012-04-20 17:20:34 +020030#define ATH9K_DFS_POOL_STAT(s, p) \
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +020031 len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
Janusz Dziedzicd2652142013-10-14 11:06:04 +020032 dfs_pool_stats.p);
Zefir Kurtisi29942bc2011-12-14 20:16:34 -080033
34static 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
Janusz Dziedzicd2652142013-10-14 11:06:04 +020047 if (sc->dfs_detector)
48 dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
49
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +020050 len += scnprintf(buf + len, size - len, "DFS support for "
51 "macVersion = 0x%x, macRev = 0x%x: %s\n",
52 hw_ver->macVersion, hw_ver->macRev,
53 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
Zefir Kurtisi29942bc2011-12-14 20:16:34 -080054 "enabled" : "disabled");
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +020055 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
Zefir Kurtisib96f20b2012-04-20 17:20:34 +020056 ATH9K_DFS_STAT("pulse events reported ", pulses_total);
57 ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs);
Zefir Kurtisi29942bc2011-12-14 20:16:34 -080058 ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected);
59 ATH9K_DFS_STAT("Datalen discards ", datalen_discards);
60 ATH9K_DFS_STAT("RSSI discards ", rssi_discards);
61 ATH9K_DFS_STAT("BW info discards ", bwinfo_discards);
62 ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors);
63 ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors);
64 ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +020065 len += scnprintf(buf + len, size - len, "Radar detector statistics "
66 "(current DFS region: %d)\n",
67 sc->dfs_detector->region);
Zefir Kurtisib96f20b2012-04-20 17:20:34 +020068 ATH9K_DFS_STAT("Pulse events processed ", pulses_processed);
69 ATH9K_DFS_STAT("Radars detected ", radar_detected);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +020070 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
Zefir Kurtisib96f20b2012-04-20 17:20:34 +020071 ATH9K_DFS_POOL_STAT("Pool references ", pool_reference);
72 ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated);
73 ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error);
74 ATH9K_DFS_POOL_STAT("Pulses in use ", pulse_used);
75 ATH9K_DFS_POOL_STAT("Seqs. allocated ", pseq_allocated);
76 ATH9K_DFS_POOL_STAT("Seqs. alloc error ", pseq_alloc_error);
77 ATH9K_DFS_POOL_STAT("Seqs. in use ", pseq_used);
Zefir Kurtisi29942bc2011-12-14 20:16:34 -080078
79 if (len > size)
80 len = size;
81
82 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
83 kfree(buf);
84
85 return retval;
86}
87
Zefir Kurtisib96f20b2012-04-20 17:20:34 +020088/* magic number to prevent accidental reset of DFS statistics */
89#define DFS_STATS_RESET_MAGIC 0x80000000
90static ssize_t write_file_dfs(struct file *file, const char __user *user_buf,
91 size_t count, loff_t *ppos)
92{
93 struct ath_softc *sc = file->private_data;
94 unsigned long val;
95 char buf[32];
96 ssize_t len;
97
98 len = min(count, sizeof(buf) - 1);
99 if (copy_from_user(buf, user_buf, len))
100 return -EFAULT;
101
102 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +0000103 if (kstrtoul(buf, 0, &val))
Zefir Kurtisib96f20b2012-04-20 17:20:34 +0200104 return -EINVAL;
105
106 if (val == DFS_STATS_RESET_MAGIC)
107 memset(&sc->debug.stats.dfs_stats, 0,
108 sizeof(sc->debug.stats.dfs_stats));
109 return count;
110}
111
Zefir Kurtisie39282e2013-04-03 18:31:30 +0200112static ssize_t write_file_simulate_radar(struct file *file,
113 const char __user *user_buf,
114 size_t count, loff_t *ppos)
115{
116 struct ath_softc *sc = file->private_data;
117
118 ieee80211_radar_detected(sc->hw);
119
120 return count;
121}
122
123static const struct file_operations fops_simulate_radar = {
124 .write = write_file_simulate_radar,
125 .open = simple_open,
126 .owner = THIS_MODULE,
127 .llseek = default_llseek,
128};
129
Zefir Kurtisi29942bc2011-12-14 20:16:34 -0800130static const struct file_operations fops_dfs_stats = {
131 .read = read_file_dfs,
Zefir Kurtisib96f20b2012-04-20 17:20:34 +0200132 .write = write_file_dfs,
Stephen Boyd234e3402012-04-05 14:25:11 -0700133 .open = simple_open,
Zefir Kurtisi29942bc2011-12-14 20:16:34 -0800134 .owner = THIS_MODULE,
135 .llseek = default_llseek,
136};
137
138void ath9k_dfs_init_debug(struct ath_softc *sc)
139{
140 debugfs_create_file("dfs_stats", S_IRUSR,
141 sc->debug.debugfs_phy, sc, &fops_dfs_stats);
Zefir Kurtisie39282e2013-04-03 18:31:30 +0200142 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
143 sc->debug.debugfs_phy, sc, &fops_simulate_radar);
Zefir Kurtisi29942bc2011-12-14 20:16:34 -0800144}