Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 1 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 2 | /* |
| 3 | * mac80211 debugfs for wireless PHYs |
| 4 | * |
| 5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame^] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 7 | * |
| 8 | * GPLv2 |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/debugfs.h> |
| 13 | #include <linux/rtnetlink.h> |
| 14 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 15 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 16 | #include "rate.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 17 | #include "debugfs.h" |
| 18 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 19 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 |
| 20 | |
Matti Gottlieb | ad38bfc | 2013-11-18 19:06:45 +0200 | [diff] [blame] | 21 | #define TX_LATENCY_BIN_DELIMTER_C ',' |
| 22 | #define TX_LATENCY_BIN_DELIMTER_S "," |
| 23 | #define TX_LATENCY_BINS_DISABLED "enable(bins disabled)\n" |
| 24 | #define TX_LATENCY_DISABLED "disable\n" |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * Display if Tx latency statistics & bins are enabled/disabled |
| 29 | */ |
| 30 | static ssize_t sta_tx_latency_stat_read(struct file *file, |
| 31 | char __user *userbuf, |
| 32 | size_t count, loff_t *ppos) |
| 33 | { |
| 34 | struct ieee80211_local *local = file->private_data; |
| 35 | struct ieee80211_tx_latency_bin_ranges *tx_latency; |
| 36 | char *buf; |
| 37 | int bufsz, i, ret; |
| 38 | int pos = 0; |
| 39 | |
| 40 | rcu_read_lock(); |
| 41 | |
| 42 | tx_latency = rcu_dereference(local->tx_latency); |
| 43 | |
| 44 | if (tx_latency && tx_latency->n_ranges) { |
| 45 | bufsz = tx_latency->n_ranges * 15; |
| 46 | buf = kzalloc(bufsz, GFP_ATOMIC); |
| 47 | if (!buf) |
| 48 | goto err; |
| 49 | |
| 50 | for (i = 0; i < tx_latency->n_ranges; i++) |
| 51 | pos += scnprintf(buf + pos, bufsz - pos, "%d,", |
| 52 | tx_latency->ranges[i]); |
| 53 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); |
| 54 | } else if (tx_latency) { |
| 55 | bufsz = sizeof(TX_LATENCY_BINS_DISABLED) + 1; |
| 56 | buf = kzalloc(bufsz, GFP_ATOMIC); |
| 57 | if (!buf) |
| 58 | goto err; |
| 59 | |
| 60 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", |
| 61 | TX_LATENCY_BINS_DISABLED); |
| 62 | } else { |
| 63 | bufsz = sizeof(TX_LATENCY_DISABLED) + 1; |
| 64 | buf = kzalloc(bufsz, GFP_ATOMIC); |
| 65 | if (!buf) |
| 66 | goto err; |
| 67 | |
| 68 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", |
| 69 | TX_LATENCY_DISABLED); |
| 70 | } |
| 71 | |
| 72 | rcu_read_unlock(); |
| 73 | |
| 74 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 75 | kfree(buf); |
| 76 | |
| 77 | return ret; |
| 78 | err: |
| 79 | rcu_read_unlock(); |
| 80 | return -ENOMEM; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Receive input from user regarding Tx latency statistics |
| 85 | * The input should indicate if Tx latency statistics and bins are |
| 86 | * enabled/disabled. |
| 87 | * If bins are enabled input should indicate the amount of different bins and |
| 88 | * their ranges. Each bin will count how many Tx frames transmitted within the |
| 89 | * appropriate latency. |
| 90 | * Legal input is: |
| 91 | * a) "enable(bins disabled)" - to enable only general statistics |
| 92 | * b) "a,b,c,d,...z" - to enable general statistics and bins, where all are |
| 93 | * numbers and a < b < c < d.. < z |
| 94 | * c) "disable" - disable all statistics |
| 95 | * NOTE: must configure Tx latency statistics bins before stations connected. |
| 96 | */ |
| 97 | |
| 98 | static ssize_t sta_tx_latency_stat_write(struct file *file, |
| 99 | const char __user *userbuf, |
| 100 | size_t count, loff_t *ppos) |
| 101 | { |
| 102 | struct ieee80211_local *local = file->private_data; |
| 103 | char buf[128] = {}; |
| 104 | char *bins = buf; |
| 105 | char *token; |
| 106 | int buf_size, i, alloc_size; |
| 107 | int prev_bin = 0; |
| 108 | int n_ranges = 0; |
| 109 | int ret = count; |
| 110 | struct ieee80211_tx_latency_bin_ranges *tx_latency; |
| 111 | |
| 112 | if (sizeof(buf) <= count) |
| 113 | return -EINVAL; |
| 114 | buf_size = count; |
| 115 | if (copy_from_user(buf, userbuf, buf_size)) |
| 116 | return -EFAULT; |
| 117 | |
| 118 | mutex_lock(&local->sta_mtx); |
| 119 | |
| 120 | /* cannot change config once we have stations */ |
| 121 | if (local->num_sta) |
| 122 | goto unlock; |
| 123 | |
| 124 | tx_latency = |
| 125 | rcu_dereference_protected(local->tx_latency, |
| 126 | lockdep_is_held(&local->sta_mtx)); |
| 127 | |
| 128 | /* disable Tx statistics */ |
| 129 | if (!strcmp(buf, TX_LATENCY_DISABLED)) { |
| 130 | if (!tx_latency) |
| 131 | goto unlock; |
Monam Agarwal | 0c2bef46 | 2014-03-24 00:51:43 +0530 | [diff] [blame] | 132 | RCU_INIT_POINTER(local->tx_latency, NULL); |
Matti Gottlieb | ad38bfc | 2013-11-18 19:06:45 +0200 | [diff] [blame] | 133 | synchronize_rcu(); |
| 134 | kfree(tx_latency); |
| 135 | goto unlock; |
| 136 | } |
| 137 | |
| 138 | /* Tx latency already enabled */ |
| 139 | if (tx_latency) |
| 140 | goto unlock; |
| 141 | |
| 142 | if (strcmp(TX_LATENCY_BINS_DISABLED, buf)) { |
| 143 | /* check how many bins and between what ranges user requested */ |
| 144 | token = buf; |
| 145 | while (*token != '\0') { |
| 146 | if (*token == TX_LATENCY_BIN_DELIMTER_C) |
| 147 | n_ranges++; |
| 148 | token++; |
| 149 | } |
| 150 | n_ranges++; |
| 151 | } |
| 152 | |
| 153 | alloc_size = sizeof(struct ieee80211_tx_latency_bin_ranges) + |
| 154 | n_ranges * sizeof(u32); |
| 155 | tx_latency = kzalloc(alloc_size, GFP_ATOMIC); |
| 156 | if (!tx_latency) { |
| 157 | ret = -ENOMEM; |
| 158 | goto unlock; |
| 159 | } |
| 160 | tx_latency->n_ranges = n_ranges; |
| 161 | for (i = 0; i < n_ranges; i++) { /* setting bin ranges */ |
| 162 | token = strsep(&bins, TX_LATENCY_BIN_DELIMTER_S); |
| 163 | sscanf(token, "%d", &tx_latency->ranges[i]); |
| 164 | /* bins values should be in ascending order */ |
| 165 | if (prev_bin >= tx_latency->ranges[i]) { |
| 166 | ret = -EINVAL; |
| 167 | kfree(tx_latency); |
| 168 | goto unlock; |
| 169 | } |
| 170 | prev_bin = tx_latency->ranges[i]; |
| 171 | } |
| 172 | rcu_assign_pointer(local->tx_latency, tx_latency); |
| 173 | |
| 174 | unlock: |
| 175 | mutex_unlock(&local->sta_mtx); |
| 176 | |
| 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | static const struct file_operations stats_tx_latency_ops = { |
| 181 | .write = sta_tx_latency_stat_write, |
| 182 | .read = sta_tx_latency_stat_read, |
| 183 | .open = simple_open, |
| 184 | .llseek = generic_file_llseek, |
| 185 | }; |
| 186 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 187 | int mac80211_format_buffer(char __user *userbuf, size_t count, |
| 188 | loff_t *ppos, char *fmt, ...) |
| 189 | { |
| 190 | va_list args; |
| 191 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; |
| 192 | int res; |
| 193 | |
| 194 | va_start(args, fmt); |
| 195 | res = vscnprintf(buf, sizeof(buf), fmt, args); |
| 196 | va_end(args); |
| 197 | |
| 198 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
| 199 | } |
| 200 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 201 | #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 202 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ |
| 203 | size_t count, loff_t *ppos) \ |
| 204 | { \ |
| 205 | struct ieee80211_local *local = file->private_data; \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 206 | \ |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 207 | return mac80211_format_buffer(userbuf, count, ppos, \ |
| 208 | fmt "\n", ##value); \ |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | #define DEBUGFS_READONLY_FILE_OPS(name) \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 212 | static const struct file_operations name## _ops = { \ |
| 213 | .read = name## _read, \ |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 214 | .open = simple_open, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 215 | .llseek = generic_file_llseek, \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 218 | #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ |
| 219 | DEBUGFS_READONLY_FILE_FN(name, fmt, value) \ |
| 220 | DEBUGFS_READONLY_FILE_OPS(name) |
| 221 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 222 | #define DEBUGFS_ADD(name) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 223 | debugfs_create_file(#name, 0400, phyd, local, &name## _ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 224 | |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 225 | #define DEBUGFS_ADD_MODE(name, mode) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 226 | debugfs_create_file(#name, mode, phyd, local, &name## _ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 227 | |
| 228 | |
Ben Greear | 83bdf2a | 2011-02-15 13:11:22 -0800 | [diff] [blame] | 229 | DEBUGFS_READONLY_FILE(user_power, "%d", |
| 230 | local->user_power_level); |
| 231 | DEBUGFS_READONLY_FILE(power, "%d", |
| 232 | local->hw.conf.power_level); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 233 | DEBUGFS_READONLY_FILE(total_ps_buffered, "%d", |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 234 | local->total_ps_buffered); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 235 | DEBUGFS_READONLY_FILE(wep_iv, "%#08x", |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 236 | local->wep_iv & 0xffffff); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 237 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s", |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 238 | local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 239 | |
Johannes Berg | 2ad4814 | 2012-09-19 08:20:24 +0200 | [diff] [blame] | 240 | #ifdef CONFIG_PM |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 241 | static ssize_t reset_write(struct file *file, const char __user *user_buf, |
| 242 | size_t count, loff_t *ppos) |
| 243 | { |
| 244 | struct ieee80211_local *local = file->private_data; |
| 245 | |
| 246 | rtnl_lock(); |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 247 | __ieee80211_suspend(&local->hw, NULL); |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 248 | __ieee80211_resume(&local->hw); |
| 249 | rtnl_unlock(); |
| 250 | |
| 251 | return count; |
| 252 | } |
| 253 | |
| 254 | static const struct file_operations reset_ops = { |
| 255 | .write = reset_write, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 256 | .open = simple_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 257 | .llseek = noop_llseek, |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 258 | }; |
Johannes Berg | 2ad4814 | 2012-09-19 08:20:24 +0200 | [diff] [blame] | 259 | #endif |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 260 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 261 | static ssize_t hwflags_read(struct file *file, char __user *user_buf, |
| 262 | size_t count, loff_t *ppos) |
| 263 | { |
| 264 | struct ieee80211_local *local = file->private_data; |
| 265 | int mxln = 500; |
| 266 | ssize_t rv; |
| 267 | char *buf = kzalloc(mxln, GFP_KERNEL); |
| 268 | int sf = 0; /* how many written so far */ |
| 269 | |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 270 | if (!buf) |
| 271 | return 0; |
| 272 | |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 273 | sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 274 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 275 | sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 276 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 277 | sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 278 | if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 279 | sf += scnprintf(buf + sf, mxln - sf, |
| 280 | "HOST_BCAST_PS_BUFFERING\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 281 | if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 282 | sf += scnprintf(buf + sf, mxln - sf, |
| 283 | "2GHZ_SHORT_SLOT_INCAPABLE\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 284 | if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 285 | sf += scnprintf(buf + sf, mxln - sf, |
| 286 | "2GHZ_SHORT_PREAMBLE_INCAPABLE\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 287 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 288 | sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 289 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 290 | sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n"); |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 291 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 292 | sf += scnprintf(buf + sf, mxln - sf, |
| 293 | "NEED_DTIM_BEFORE_ASSOC\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 294 | if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 295 | sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 296 | if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 297 | sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 298 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 299 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 300 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 301 | sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 302 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 303 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 304 | if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 305 | sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 306 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 307 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 308 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 309 | sf += scnprintf(buf + sf, mxln - sf, |
| 310 | "SUPPORTS_DYNAMIC_SMPS\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 311 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 312 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 313 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 314 | sf += scnprintf(buf + sf, mxln - sf, |
| 315 | "REPORTS_TX_ACK_STATUS\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 316 | if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 317 | sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 318 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 319 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 320 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 321 | sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n"); |
Arik Nemtsov | edf6b78 | 2011-08-30 09:32:38 +0300 | [diff] [blame] | 322 | if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW) |
Eliad Peller | f364ef9 | 2013-08-27 12:40:15 +0300 | [diff] [blame] | 323 | sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 324 | |
| 325 | rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 326 | kfree(buf); |
| 327 | return rv; |
| 328 | } |
Benoit Papillault | 199d69f | 2010-02-04 22:00:20 +0100 | [diff] [blame] | 329 | |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 330 | static ssize_t queues_read(struct file *file, char __user *user_buf, |
| 331 | size_t count, loff_t *ppos) |
| 332 | { |
| 333 | struct ieee80211_local *local = file->private_data; |
| 334 | unsigned long flags; |
| 335 | char buf[IEEE80211_MAX_QUEUES * 20]; |
| 336 | int q, res = 0; |
| 337 | |
| 338 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 339 | for (q = 0; q < local->hw.queues; q++) |
| 340 | res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q, |
| 341 | local->queue_stop_reasons[q], |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 342 | skb_queue_len(&local->pending[q])); |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 343 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 344 | |
| 345 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); |
| 346 | } |
| 347 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 348 | DEBUGFS_READONLY_FILE_OPS(hwflags); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 349 | DEBUGFS_READONLY_FILE_OPS(queues); |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 350 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 351 | /* statistics stuff */ |
| 352 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 353 | static ssize_t format_devstat_counter(struct ieee80211_local *local, |
| 354 | char __user *userbuf, |
| 355 | size_t count, loff_t *ppos, |
| 356 | int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, |
| 357 | int buflen)) |
| 358 | { |
| 359 | struct ieee80211_low_level_stats stats; |
| 360 | char buf[20]; |
| 361 | int res; |
| 362 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 363 | rtnl_lock(); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 364 | res = drv_get_stats(local, &stats); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 365 | rtnl_unlock(); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 366 | if (res) |
| 367 | return res; |
| 368 | res = printvalue(&stats, buf, sizeof(buf)); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 369 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
| 370 | } |
| 371 | |
| 372 | #define DEBUGFS_DEVSTATS_FILE(name) \ |
| 373 | static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ |
| 374 | char *buf, int buflen) \ |
| 375 | { \ |
| 376 | return scnprintf(buf, buflen, "%u\n", stats->name); \ |
| 377 | } \ |
| 378 | static ssize_t stats_ ##name## _read(struct file *file, \ |
| 379 | char __user *userbuf, \ |
| 380 | size_t count, loff_t *ppos) \ |
| 381 | { \ |
| 382 | return format_devstat_counter(file->private_data, \ |
| 383 | userbuf, \ |
| 384 | count, \ |
| 385 | ppos, \ |
| 386 | print_devstats_##name); \ |
| 387 | } \ |
| 388 | \ |
| 389 | static const struct file_operations stats_ ##name## _ops = { \ |
| 390 | .read = stats_ ##name## _read, \ |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 391 | .open = simple_open, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 392 | .llseek = generic_file_llseek, \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 393 | }; |
| 394 | |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 395 | #define DEBUGFS_STATS_ADD(name, field) \ |
| 396 | debugfs_create_u32(#name, 0400, statsd, (u32 *) &field); |
| 397 | #define DEBUGFS_DEVSTATS_ADD(name) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 398 | debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 399 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 400 | DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); |
| 401 | DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); |
| 402 | DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); |
| 403 | DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); |
| 404 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 405 | void debugfs_hw_add(struct ieee80211_local *local) |
| 406 | { |
| 407 | struct dentry *phyd = local->hw.wiphy->debugfsdir; |
| 408 | struct dentry *statsd; |
| 409 | |
| 410 | if (!phyd) |
| 411 | return; |
| 412 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 413 | local->debugfs.keys = debugfs_create_dir("keys", phyd); |
| 414 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 415 | DEBUGFS_ADD(total_ps_buffered); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 416 | DEBUGFS_ADD(wep_iv); |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 417 | DEBUGFS_ADD(queues); |
Johannes Berg | 2ad4814 | 2012-09-19 08:20:24 +0200 | [diff] [blame] | 418 | #ifdef CONFIG_PM |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 419 | DEBUGFS_ADD_MODE(reset, 0200); |
Johannes Berg | 2ad4814 | 2012-09-19 08:20:24 +0200 | [diff] [blame] | 420 | #endif |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 421 | DEBUGFS_ADD(hwflags); |
Ben Greear | 83bdf2a | 2011-02-15 13:11:22 -0800 | [diff] [blame] | 422 | DEBUGFS_ADD(user_power); |
| 423 | DEBUGFS_ADD(power); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 424 | |
| 425 | statsd = debugfs_create_dir("statistics", phyd); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 426 | |
| 427 | /* if the dir failed, don't put all the other things into the root! */ |
| 428 | if (!statsd) |
| 429 | return; |
| 430 | |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 431 | DEBUGFS_STATS_ADD(transmitted_fragment_count, |
| 432 | local->dot11TransmittedFragmentCount); |
| 433 | DEBUGFS_STATS_ADD(multicast_transmitted_frame_count, |
| 434 | local->dot11MulticastTransmittedFrameCount); |
| 435 | DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount); |
| 436 | DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount); |
| 437 | DEBUGFS_STATS_ADD(multiple_retry_count, |
| 438 | local->dot11MultipleRetryCount); |
| 439 | DEBUGFS_STATS_ADD(frame_duplicate_count, |
| 440 | local->dot11FrameDuplicateCount); |
| 441 | DEBUGFS_STATS_ADD(received_fragment_count, |
| 442 | local->dot11ReceivedFragmentCount); |
| 443 | DEBUGFS_STATS_ADD(multicast_received_frame_count, |
| 444 | local->dot11MulticastReceivedFrameCount); |
| 445 | DEBUGFS_STATS_ADD(transmitted_frame_count, |
| 446 | local->dot11TransmittedFrameCount); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 447 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 448 | DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop); |
| 449 | DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued); |
| 450 | DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted, |
| 451 | local->tx_handlers_drop_unencrypted); |
| 452 | DEBUGFS_STATS_ADD(tx_handlers_drop_fragment, |
| 453 | local->tx_handlers_drop_fragment); |
| 454 | DEBUGFS_STATS_ADD(tx_handlers_drop_wep, |
| 455 | local->tx_handlers_drop_wep); |
| 456 | DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc, |
| 457 | local->tx_handlers_drop_not_assoc); |
| 458 | DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port, |
| 459 | local->tx_handlers_drop_unauth_port); |
| 460 | DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop); |
| 461 | DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued); |
| 462 | DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc, |
| 463 | local->rx_handlers_drop_nullfunc); |
| 464 | DEBUGFS_STATS_ADD(rx_handlers_drop_defrag, |
| 465 | local->rx_handlers_drop_defrag); |
| 466 | DEBUGFS_STATS_ADD(rx_handlers_drop_short, |
| 467 | local->rx_handlers_drop_short); |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 468 | DEBUGFS_STATS_ADD(tx_expand_skb_head, |
| 469 | local->tx_expand_skb_head); |
| 470 | DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned, |
| 471 | local->tx_expand_skb_head_cloned); |
| 472 | DEBUGFS_STATS_ADD(rx_expand_skb_head, |
| 473 | local->rx_expand_skb_head); |
| 474 | DEBUGFS_STATS_ADD(rx_expand_skb_head2, |
| 475 | local->rx_expand_skb_head2); |
| 476 | DEBUGFS_STATS_ADD(rx_handlers_fragments, |
| 477 | local->rx_handlers_fragments); |
| 478 | DEBUGFS_STATS_ADD(tx_status_drop, |
| 479 | local->tx_status_drop); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 480 | #endif |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 481 | DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount); |
| 482 | DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); |
| 483 | DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); |
| 484 | DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); |
Matti Gottlieb | ad38bfc | 2013-11-18 19:06:45 +0200 | [diff] [blame] | 485 | |
| 486 | DEBUGFS_DEVSTATS_ADD(tx_latency); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 487 | } |