2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 * Copyright (c) 2011 Neratec Solutions AG
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.
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.
18 #include <linux/debugfs.h>
19 #include <linux/export.h>
22 #include "dfs_debug.h"
25 struct ath_dfs_pool_stats global_dfs_pool_stats
= { 0 };
27 #define ATH9K_DFS_STAT(s, p) \
28 len += snprintf(buf + len, size - len, "%28s : %10u\n", s, \
29 sc->debug.stats.dfs_stats.p);
30 #define ATH9K_DFS_POOL_STAT(s, p) \
31 len += snprintf(buf + len, size - len, "%28s : %10u\n", s, \
32 global_dfs_pool_stats.p);
34 static ssize_t
read_file_dfs(struct file
*file
, char __user
*user_buf
,
35 size_t count
, loff_t
*ppos
)
37 struct ath_softc
*sc
= file
->private_data
;
38 struct ath9k_hw_version
*hw_ver
= &sc
->sc_ah
->hw_version
;
40 unsigned int len
= 0, size
= 8000;
43 buf
= kzalloc(size
, GFP_KERNEL
);
47 len
+= snprintf(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
) ?
51 "enabled" : "disabled");
52 len
+= snprintf(buf
+ len
, size
- len
, "Pulse detector statistics:\n");
53 ATH9K_DFS_STAT("pulse events reported ", pulses_total
);
54 ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs
);
55 ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected
);
56 ATH9K_DFS_STAT("Datalen discards ", datalen_discards
);
57 ATH9K_DFS_STAT("RSSI discards ", rssi_discards
);
58 ATH9K_DFS_STAT("BW info discards ", bwinfo_discards
);
59 ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors
);
60 ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors
);
61 ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors
);
62 len
+= snprintf(buf
+ len
, size
- len
, "Radar detector statistics "
63 "(current DFS region: %d)\n", sc
->dfs_detector
->region
);
64 ATH9K_DFS_STAT("Pulse events processed ", pulses_processed
);
65 ATH9K_DFS_STAT("Radars detected ", radar_detected
);
66 len
+= snprintf(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
);
78 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
84 /* magic number to prevent accidental reset of DFS statistics */
85 #define DFS_STATS_RESET_MAGIC 0x80000000
86 static ssize_t
write_file_dfs(struct file
*file
, const char __user
*user_buf
,
87 size_t count
, loff_t
*ppos
)
89 struct ath_softc
*sc
= file
->private_data
;
94 len
= min(count
, sizeof(buf
) - 1);
95 if (copy_from_user(buf
, user_buf
, len
))
99 if (kstrtoul(buf
, 0, &val
))
102 if (val
== DFS_STATS_RESET_MAGIC
)
103 memset(&sc
->debug
.stats
.dfs_stats
, 0,
104 sizeof(sc
->debug
.stats
.dfs_stats
));
108 static ssize_t
write_file_simulate_radar(struct file
*file
,
109 const char __user
*user_buf
,
110 size_t count
, loff_t
*ppos
)
112 struct ath_softc
*sc
= file
->private_data
;
114 ieee80211_radar_detected(sc
->hw
);
119 static const struct file_operations fops_simulate_radar
= {
120 .write
= write_file_simulate_radar
,
122 .owner
= THIS_MODULE
,
123 .llseek
= default_llseek
,
126 static const struct file_operations fops_dfs_stats
= {
127 .read
= read_file_dfs
,
128 .write
= write_file_dfs
,
130 .owner
= THIS_MODULE
,
131 .llseek
= default_llseek
,
134 void ath9k_dfs_init_debug(struct ath_softc
*sc
)
136 debugfs_create_file("dfs_stats", S_IRUSR
,
137 sc
->debug
.debugfs_phy
, sc
, &fops_dfs_stats
);
138 debugfs_create_file("dfs_simulate_radar", S_IWUSR
,
139 sc
->debug
.debugfs_phy
, sc
, &fops_simulate_radar
);