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> |
| 6 | * |
| 7 | * GPLv2 |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/debugfs.h> |
| 12 | #include <linux/rtnetlink.h> |
| 13 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 14 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 15 | #include "rate.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 16 | #include "debugfs.h" |
| 17 | |
| 18 | int mac80211_open_file_generic(struct inode *inode, struct file *file) |
| 19 | { |
| 20 | file->private_data = inode->i_private; |
| 21 | return 0; |
| 22 | } |
| 23 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 24 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 |
| 25 | |
| 26 | int mac80211_format_buffer(char __user *userbuf, size_t count, |
| 27 | loff_t *ppos, char *fmt, ...) |
| 28 | { |
| 29 | va_list args; |
| 30 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; |
| 31 | int res; |
| 32 | |
| 33 | va_start(args, fmt); |
| 34 | res = vscnprintf(buf, sizeof(buf), fmt, args); |
| 35 | va_end(args); |
| 36 | |
| 37 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
| 38 | } |
| 39 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 40 | #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 41 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ |
| 42 | size_t count, loff_t *ppos) \ |
| 43 | { \ |
| 44 | struct ieee80211_local *local = file->private_data; \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 45 | \ |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 46 | return mac80211_format_buffer(userbuf, count, ppos, \ |
| 47 | fmt "\n", ##value); \ |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | #define DEBUGFS_READONLY_FILE_OPS(name) \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 51 | static const struct file_operations name## _ops = { \ |
| 52 | .read = name## _read, \ |
| 53 | .open = mac80211_open_file_generic, \ |
Arnd Bergmann | 2b18ab3 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 54 | .llseek = generic_file_llseek, \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 57 | #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ |
| 58 | DEBUGFS_READONLY_FILE_FN(name, fmt, value) \ |
| 59 | DEBUGFS_READONLY_FILE_OPS(name) |
| 60 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 61 | #define DEBUGFS_ADD(name) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 62 | debugfs_create_file(#name, 0400, phyd, local, &name## _ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 63 | |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 64 | #define DEBUGFS_ADD_MODE(name, mode) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 65 | debugfs_create_file(#name, mode, phyd, local, &name## _ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 66 | |
| 67 | |
Ben Greear | 83bdf2a | 2011-02-15 13:11:22 -0800 | [diff] [blame] | 68 | DEBUGFS_READONLY_FILE(user_power, "%d", |
| 69 | local->user_power_level); |
| 70 | DEBUGFS_READONLY_FILE(power, "%d", |
| 71 | local->hw.conf.power_level); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 72 | DEBUGFS_READONLY_FILE(frequency, "%d", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 73 | local->hw.conf.channel->center_freq); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 74 | DEBUGFS_READONLY_FILE(total_ps_buffered, "%d", |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 75 | local->total_ps_buffered); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 76 | DEBUGFS_READONLY_FILE(wep_iv, "%#08x", |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 77 | local->wep_iv & 0xffffff); |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 78 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s", |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 79 | local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 80 | |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 81 | static ssize_t reset_write(struct file *file, const char __user *user_buf, |
| 82 | size_t count, loff_t *ppos) |
| 83 | { |
| 84 | struct ieee80211_local *local = file->private_data; |
| 85 | |
| 86 | rtnl_lock(); |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 87 | __ieee80211_suspend(&local->hw, NULL); |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 88 | __ieee80211_resume(&local->hw); |
| 89 | rtnl_unlock(); |
| 90 | |
| 91 | return count; |
| 92 | } |
| 93 | |
| 94 | static const struct file_operations reset_ops = { |
| 95 | .write = reset_write, |
| 96 | .open = mac80211_open_file_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 97 | .llseek = noop_llseek, |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Johannes Berg | d3707d9 | 2009-05-12 22:05:40 +0200 | [diff] [blame] | 100 | static ssize_t noack_read(struct file *file, char __user *user_buf, |
| 101 | size_t count, loff_t *ppos) |
| 102 | { |
| 103 | struct ieee80211_local *local = file->private_data; |
Johannes Berg | d3707d9 | 2009-05-12 22:05:40 +0200 | [diff] [blame] | 104 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 105 | return mac80211_format_buffer(user_buf, count, ppos, "%d\n", |
| 106 | local->wifi_wme_noack_test); |
Johannes Berg | d3707d9 | 2009-05-12 22:05:40 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static ssize_t noack_write(struct file *file, |
| 110 | const char __user *user_buf, |
| 111 | size_t count, loff_t *ppos) |
| 112 | { |
| 113 | struct ieee80211_local *local = file->private_data; |
| 114 | char buf[10]; |
| 115 | size_t len; |
| 116 | |
| 117 | len = min(count, sizeof(buf) - 1); |
| 118 | if (copy_from_user(buf, user_buf, len)) |
| 119 | return -EFAULT; |
| 120 | buf[len] = '\0'; |
| 121 | |
| 122 | local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0); |
| 123 | |
| 124 | return count; |
| 125 | } |
| 126 | |
| 127 | static const struct file_operations noack_ops = { |
| 128 | .read = noack_read, |
| 129 | .write = noack_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 130 | .open = mac80211_open_file_generic, |
| 131 | .llseek = default_llseek, |
Johannes Berg | d3707d9 | 2009-05-12 22:05:40 +0200 | [diff] [blame] | 132 | }; |
| 133 | |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 134 | static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf, |
| 135 | size_t count, loff_t *ppos) |
| 136 | { |
| 137 | struct ieee80211_local *local = file->private_data; |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 138 | return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n", |
| 139 | local->uapsd_queues); |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static ssize_t uapsd_queues_write(struct file *file, |
| 143 | const char __user *user_buf, |
| 144 | size_t count, loff_t *ppos) |
| 145 | { |
| 146 | struct ieee80211_local *local = file->private_data; |
Peter Huewe | b38de31 | 2011-06-07 22:36:14 +0200 | [diff] [blame] | 147 | u8 val; |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 148 | int ret; |
| 149 | |
Peter Huewe | b38de31 | 2011-06-07 22:36:14 +0200 | [diff] [blame] | 150 | ret = kstrtou8_from_user(user_buf, count, 0, &val); |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 151 | if (ret) |
Peter Huewe | b38de31 | 2011-06-07 22:36:14 +0200 | [diff] [blame] | 152 | return ret; |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 153 | |
| 154 | if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 155 | return -ERANGE; |
| 156 | |
| 157 | local->uapsd_queues = val; |
| 158 | |
| 159 | return count; |
| 160 | } |
| 161 | |
| 162 | static const struct file_operations uapsd_queues_ops = { |
| 163 | .read = uapsd_queues_read, |
| 164 | .write = uapsd_queues_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 165 | .open = mac80211_open_file_generic, |
| 166 | .llseek = default_llseek, |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf, |
| 170 | size_t count, loff_t *ppos) |
| 171 | { |
| 172 | struct ieee80211_local *local = file->private_data; |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 173 | |
Eliad Peller | 07caf9d | 2010-10-27 14:58:29 +0200 | [diff] [blame] | 174 | return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n", |
| 175 | local->uapsd_max_sp_len); |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static ssize_t uapsd_max_sp_len_write(struct file *file, |
| 179 | const char __user *user_buf, |
| 180 | size_t count, loff_t *ppos) |
| 181 | { |
| 182 | struct ieee80211_local *local = file->private_data; |
| 183 | unsigned long val; |
| 184 | char buf[10]; |
| 185 | size_t len; |
| 186 | int ret; |
| 187 | |
| 188 | len = min(count, sizeof(buf) - 1); |
| 189 | if (copy_from_user(buf, user_buf, len)) |
| 190 | return -EFAULT; |
| 191 | buf[len] = '\0'; |
| 192 | |
| 193 | ret = strict_strtoul(buf, 0, &val); |
| 194 | |
| 195 | if (ret) |
| 196 | return -EINVAL; |
| 197 | |
| 198 | if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 199 | return -ERANGE; |
| 200 | |
| 201 | local->uapsd_max_sp_len = val; |
| 202 | |
| 203 | return count; |
| 204 | } |
| 205 | |
| 206 | static const struct file_operations uapsd_max_sp_len_ops = { |
| 207 | .read = uapsd_max_sp_len_read, |
| 208 | .write = uapsd_max_sp_len_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 209 | .open = mac80211_open_file_generic, |
| 210 | .llseek = default_llseek, |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 211 | }; |
| 212 | |
Benoit Papillault | 199d69f | 2010-02-04 22:00:20 +0100 | [diff] [blame] | 213 | static ssize_t channel_type_read(struct file *file, char __user *user_buf, |
| 214 | size_t count, loff_t *ppos) |
| 215 | { |
| 216 | struct ieee80211_local *local = file->private_data; |
| 217 | const char *buf; |
| 218 | |
| 219 | switch (local->hw.conf.channel_type) { |
| 220 | case NL80211_CHAN_NO_HT: |
| 221 | buf = "no ht\n"; |
| 222 | break; |
| 223 | case NL80211_CHAN_HT20: |
| 224 | buf = "ht20\n"; |
| 225 | break; |
| 226 | case NL80211_CHAN_HT40MINUS: |
| 227 | buf = "ht40-\n"; |
| 228 | break; |
| 229 | case NL80211_CHAN_HT40PLUS: |
| 230 | buf = "ht40+\n"; |
| 231 | break; |
| 232 | default: |
| 233 | buf = "???"; |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 238 | } |
| 239 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 240 | static ssize_t hwflags_read(struct file *file, char __user *user_buf, |
| 241 | size_t count, loff_t *ppos) |
| 242 | { |
| 243 | struct ieee80211_local *local = file->private_data; |
| 244 | int mxln = 500; |
| 245 | ssize_t rv; |
| 246 | char *buf = kzalloc(mxln, GFP_KERNEL); |
| 247 | int sf = 0; /* how many written so far */ |
| 248 | |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 249 | if (!buf) |
| 250 | return 0; |
| 251 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 252 | sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags); |
| 253 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
| 254 | sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n"); |
| 255 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
| 256 | sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n"); |
| 257 | if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) |
| 258 | sf += snprintf(buf + sf, mxln - sf, |
| 259 | "HOST_BCAST_PS_BUFFERING\n"); |
| 260 | if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE) |
| 261 | sf += snprintf(buf + sf, mxln - sf, |
| 262 | "2GHZ_SHORT_SLOT_INCAPABLE\n"); |
| 263 | if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE) |
| 264 | sf += snprintf(buf + sf, mxln - sf, |
| 265 | "2GHZ_SHORT_PREAMBLE_INCAPABLE\n"); |
| 266 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) |
| 267 | sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n"); |
| 268 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
| 269 | sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n"); |
| 270 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
| 271 | sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n"); |
| 272 | if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT) |
| 273 | sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n"); |
| 274 | if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) |
| 275 | sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n"); |
| 276 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS) |
| 277 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n"); |
| 278 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 279 | sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n"); |
| 280 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
| 281 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n"); |
| 282 | if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE) |
| 283 | sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n"); |
| 284 | if (local->hw.flags & IEEE80211_HW_BEACON_FILTER) |
| 285 | sf += snprintf(buf + sf, mxln - sf, "BEACON_FILTER\n"); |
| 286 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) |
| 287 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n"); |
| 288 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) |
| 289 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n"); |
| 290 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) |
| 291 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n"); |
| 292 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
| 293 | sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n"); |
| 294 | if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 295 | sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n"); |
| 296 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) |
| 297 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_CQM_RSSI\n"); |
| 298 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK) |
| 299 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n"); |
| 300 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) |
| 301 | sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n"); |
Arik Nemtsov | edf6b78 | 2011-08-30 09:32:38 +0300 | [diff] [blame] | 302 | if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW) |
| 303 | sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n"); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 304 | |
| 305 | rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 306 | kfree(buf); |
| 307 | return rv; |
| 308 | } |
Benoit Papillault | 199d69f | 2010-02-04 22:00:20 +0100 | [diff] [blame] | 309 | |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 310 | static ssize_t queues_read(struct file *file, char __user *user_buf, |
| 311 | size_t count, loff_t *ppos) |
| 312 | { |
| 313 | struct ieee80211_local *local = file->private_data; |
| 314 | unsigned long flags; |
| 315 | char buf[IEEE80211_MAX_QUEUES * 20]; |
| 316 | int q, res = 0; |
| 317 | |
| 318 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 319 | for (q = 0; q < local->hw.queues; q++) |
| 320 | res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q, |
| 321 | local->queue_stop_reasons[q], |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 322 | skb_queue_len(&local->pending[q])); |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 323 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 324 | |
| 325 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); |
| 326 | } |
| 327 | |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 328 | DEBUGFS_READONLY_FILE_OPS(hwflags); |
| 329 | DEBUGFS_READONLY_FILE_OPS(channel_type); |
| 330 | DEBUGFS_READONLY_FILE_OPS(queues); |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 331 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 332 | /* statistics stuff */ |
| 333 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 334 | static ssize_t format_devstat_counter(struct ieee80211_local *local, |
| 335 | char __user *userbuf, |
| 336 | size_t count, loff_t *ppos, |
| 337 | int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, |
| 338 | int buflen)) |
| 339 | { |
| 340 | struct ieee80211_low_level_stats stats; |
| 341 | char buf[20]; |
| 342 | int res; |
| 343 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 344 | rtnl_lock(); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 345 | res = drv_get_stats(local, &stats); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 346 | rtnl_unlock(); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 347 | if (res) |
| 348 | return res; |
| 349 | res = printvalue(&stats, buf, sizeof(buf)); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 350 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
| 351 | } |
| 352 | |
| 353 | #define DEBUGFS_DEVSTATS_FILE(name) \ |
| 354 | static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ |
| 355 | char *buf, int buflen) \ |
| 356 | { \ |
| 357 | return scnprintf(buf, buflen, "%u\n", stats->name); \ |
| 358 | } \ |
| 359 | static ssize_t stats_ ##name## _read(struct file *file, \ |
| 360 | char __user *userbuf, \ |
| 361 | size_t count, loff_t *ppos) \ |
| 362 | { \ |
| 363 | return format_devstat_counter(file->private_data, \ |
| 364 | userbuf, \ |
| 365 | count, \ |
| 366 | ppos, \ |
| 367 | print_devstats_##name); \ |
| 368 | } \ |
| 369 | \ |
| 370 | static const struct file_operations stats_ ##name## _ops = { \ |
| 371 | .read = stats_ ##name## _read, \ |
| 372 | .open = mac80211_open_file_generic, \ |
Arnd Bergmann | 2b18ab3 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 373 | .llseek = generic_file_llseek, \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 376 | #define DEBUGFS_STATS_ADD(name, field) \ |
| 377 | debugfs_create_u32(#name, 0400, statsd, (u32 *) &field); |
| 378 | #define DEBUGFS_DEVSTATS_ADD(name) \ |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 379 | debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 380 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 381 | DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); |
| 382 | DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); |
| 383 | DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); |
| 384 | DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); |
| 385 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 386 | void debugfs_hw_add(struct ieee80211_local *local) |
| 387 | { |
| 388 | struct dentry *phyd = local->hw.wiphy->debugfsdir; |
| 389 | struct dentry *statsd; |
| 390 | |
| 391 | if (!phyd) |
| 392 | return; |
| 393 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 394 | local->debugfs.keys = debugfs_create_dir("keys", phyd); |
| 395 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 396 | DEBUGFS_ADD(frequency); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 397 | DEBUGFS_ADD(total_ps_buffered); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 398 | DEBUGFS_ADD(wep_iv); |
Johannes Berg | db2e6bd | 2009-06-14 17:37:39 +0200 | [diff] [blame] | 399 | DEBUGFS_ADD(queues); |
Johannes Berg | 827b1fb | 2009-03-13 11:44:18 +0100 | [diff] [blame] | 400 | DEBUGFS_ADD_MODE(reset, 0200); |
Johannes Berg | d3707d9 | 2009-05-12 22:05:40 +0200 | [diff] [blame] | 401 | DEBUGFS_ADD(noack); |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 402 | DEBUGFS_ADD(uapsd_queues); |
| 403 | DEBUGFS_ADD(uapsd_max_sp_len); |
Benoit Papillault | 199d69f | 2010-02-04 22:00:20 +0100 | [diff] [blame] | 404 | DEBUGFS_ADD(channel_type); |
Ben Greear | 279daf6 | 2011-03-23 14:04:31 -0700 | [diff] [blame] | 405 | DEBUGFS_ADD(hwflags); |
Ben Greear | 83bdf2a | 2011-02-15 13:11:22 -0800 | [diff] [blame] | 406 | DEBUGFS_ADD(user_power); |
| 407 | DEBUGFS_ADD(power); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 408 | |
| 409 | statsd = debugfs_create_dir("statistics", phyd); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 410 | |
| 411 | /* if the dir failed, don't put all the other things into the root! */ |
| 412 | if (!statsd) |
| 413 | return; |
| 414 | |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 415 | DEBUGFS_STATS_ADD(transmitted_fragment_count, |
| 416 | local->dot11TransmittedFragmentCount); |
| 417 | DEBUGFS_STATS_ADD(multicast_transmitted_frame_count, |
| 418 | local->dot11MulticastTransmittedFrameCount); |
| 419 | DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount); |
| 420 | DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount); |
| 421 | DEBUGFS_STATS_ADD(multiple_retry_count, |
| 422 | local->dot11MultipleRetryCount); |
| 423 | DEBUGFS_STATS_ADD(frame_duplicate_count, |
| 424 | local->dot11FrameDuplicateCount); |
| 425 | DEBUGFS_STATS_ADD(received_fragment_count, |
| 426 | local->dot11ReceivedFragmentCount); |
| 427 | DEBUGFS_STATS_ADD(multicast_received_frame_count, |
| 428 | local->dot11MulticastReceivedFrameCount); |
| 429 | DEBUGFS_STATS_ADD(transmitted_frame_count, |
| 430 | local->dot11TransmittedFrameCount); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 431 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 432 | DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop); |
| 433 | DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued); |
| 434 | DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted, |
| 435 | local->tx_handlers_drop_unencrypted); |
| 436 | DEBUGFS_STATS_ADD(tx_handlers_drop_fragment, |
| 437 | local->tx_handlers_drop_fragment); |
| 438 | DEBUGFS_STATS_ADD(tx_handlers_drop_wep, |
| 439 | local->tx_handlers_drop_wep); |
| 440 | DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc, |
| 441 | local->tx_handlers_drop_not_assoc); |
| 442 | DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port, |
| 443 | local->tx_handlers_drop_unauth_port); |
| 444 | DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop); |
| 445 | DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued); |
| 446 | DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc, |
| 447 | local->rx_handlers_drop_nullfunc); |
| 448 | DEBUGFS_STATS_ADD(rx_handlers_drop_defrag, |
| 449 | local->rx_handlers_drop_defrag); |
| 450 | DEBUGFS_STATS_ADD(rx_handlers_drop_short, |
| 451 | local->rx_handlers_drop_short); |
| 452 | DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan, |
| 453 | local->rx_handlers_drop_passive_scan); |
| 454 | DEBUGFS_STATS_ADD(tx_expand_skb_head, |
| 455 | local->tx_expand_skb_head); |
| 456 | DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned, |
| 457 | local->tx_expand_skb_head_cloned); |
| 458 | DEBUGFS_STATS_ADD(rx_expand_skb_head, |
| 459 | local->rx_expand_skb_head); |
| 460 | DEBUGFS_STATS_ADD(rx_expand_skb_head2, |
| 461 | local->rx_expand_skb_head2); |
| 462 | DEBUGFS_STATS_ADD(rx_handlers_fragments, |
| 463 | local->rx_handlers_fragments); |
| 464 | DEBUGFS_STATS_ADD(tx_status_drop, |
| 465 | local->tx_status_drop); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 466 | #endif |
Felix Fietkau | 2826bcd | 2010-06-02 02:57:34 +0200 | [diff] [blame] | 467 | DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount); |
| 468 | DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); |
| 469 | DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); |
| 470 | DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 471 | } |