1 /* 2 * mac80211 debugfs for wireless PHYs 3 * 4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 5 * 6 * GPLv2 7 * 8 */ 9 10 #include <linux/debugfs.h> 11 #include <linux/rtnetlink.h> 12 #include "ieee80211_i.h" 13 #include "driver-ops.h" 14 #include "rate.h" 15 #include "debugfs.h" 16 17 int mac80211_open_file_generic(struct inode *inode, struct file *file) 18 { 19 file->private_data = inode->i_private; 20 return 0; 21 } 22 23 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ 24 static ssize_t name## _read(struct file *file, char __user *userbuf, \ 25 size_t count, loff_t *ppos) \ 26 { \ 27 struct ieee80211_local *local = file->private_data; \ 28 char buf[buflen]; \ 29 int res; \ 30 \ 31 res = scnprintf(buf, buflen, fmt "\n", ##value); \ 32 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ 33 } \ 34 \ 35 static const struct file_operations name## _ops = { \ 36 .read = name## _read, \ 37 .open = mac80211_open_file_generic, \ 38 }; 39 40 #define DEBUGFS_ADD(name) \ 41 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \ 42 local, &name## _ops); 43 44 #define DEBUGFS_ADD_MODE(name, mode) \ 45 local->debugfs.name = debugfs_create_file(#name, mode, phyd, \ 46 local, &name## _ops); 47 48 #define DEBUGFS_DEL(name) \ 49 debugfs_remove(local->debugfs.name); \ 50 local->debugfs.name = NULL; 51 52 53 DEBUGFS_READONLY_FILE(frequency, 20, "%d", 54 local->hw.conf.channel->center_freq); 55 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 56 local->total_ps_buffered); 57 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", 58 local->wep_iv & 0xffffff); 59 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", 60 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>"); 61 62 static ssize_t tsf_read(struct file *file, char __user *user_buf, 63 size_t count, loff_t *ppos) 64 { 65 struct ieee80211_local *local = file->private_data; 66 u64 tsf; 67 char buf[100]; 68 69 tsf = drv_get_tsf(local); 70 71 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf); 72 73 return simple_read_from_buffer(user_buf, count, ppos, buf, 19); 74 } 75 76 static ssize_t tsf_write(struct file *file, 77 const char __user *user_buf, 78 size_t count, loff_t *ppos) 79 { 80 struct ieee80211_local *local = file->private_data; 81 unsigned long long tsf; 82 char buf[100]; 83 size_t len; 84 85 len = min(count, sizeof(buf) - 1); 86 if (copy_from_user(buf, user_buf, len)) 87 return -EFAULT; 88 buf[len] = '\0'; 89 90 if (strncmp(buf, "reset", 5) == 0) { 91 if (local->ops->reset_tsf) { 92 drv_reset_tsf(local); 93 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy)); 94 } 95 } else { 96 tsf = simple_strtoul(buf, NULL, 0); 97 if (local->ops->set_tsf) { 98 drv_set_tsf(local, tsf); 99 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf); 100 } 101 } 102 103 return count; 104 } 105 106 static const struct file_operations tsf_ops = { 107 .read = tsf_read, 108 .write = tsf_write, 109 .open = mac80211_open_file_generic 110 }; 111 112 static ssize_t reset_write(struct file *file, const char __user *user_buf, 113 size_t count, loff_t *ppos) 114 { 115 struct ieee80211_local *local = file->private_data; 116 117 rtnl_lock(); 118 __ieee80211_suspend(&local->hw); 119 __ieee80211_resume(&local->hw); 120 rtnl_unlock(); 121 122 return count; 123 } 124 125 static const struct file_operations reset_ops = { 126 .write = reset_write, 127 .open = mac80211_open_file_generic, 128 }; 129 130 static ssize_t noack_read(struct file *file, char __user *user_buf, 131 size_t count, loff_t *ppos) 132 { 133 struct ieee80211_local *local = file->private_data; 134 int res; 135 char buf[10]; 136 137 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test); 138 139 return simple_read_from_buffer(user_buf, count, ppos, buf, res); 140 } 141 142 static ssize_t noack_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; 147 char buf[10]; 148 size_t len; 149 150 len = min(count, sizeof(buf) - 1); 151 if (copy_from_user(buf, user_buf, len)) 152 return -EFAULT; 153 buf[len] = '\0'; 154 155 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0); 156 157 return count; 158 } 159 160 static const struct file_operations noack_ops = { 161 .read = noack_read, 162 .write = noack_write, 163 .open = mac80211_open_file_generic 164 }; 165 166 /* statistics stuff */ 167 168 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ 169 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value) 170 171 static ssize_t format_devstat_counter(struct ieee80211_local *local, 172 char __user *userbuf, 173 size_t count, loff_t *ppos, 174 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, 175 int buflen)) 176 { 177 struct ieee80211_low_level_stats stats; 178 char buf[20]; 179 int res; 180 181 rtnl_lock(); 182 res = drv_get_stats(local, &stats); 183 rtnl_unlock(); 184 if (res) 185 return res; 186 res = printvalue(&stats, buf, sizeof(buf)); 187 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 188 } 189 190 #define DEBUGFS_DEVSTATS_FILE(name) \ 191 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ 192 char *buf, int buflen) \ 193 { \ 194 return scnprintf(buf, buflen, "%u\n", stats->name); \ 195 } \ 196 static ssize_t stats_ ##name## _read(struct file *file, \ 197 char __user *userbuf, \ 198 size_t count, loff_t *ppos) \ 199 { \ 200 return format_devstat_counter(file->private_data, \ 201 userbuf, \ 202 count, \ 203 ppos, \ 204 print_devstats_##name); \ 205 } \ 206 \ 207 static const struct file_operations stats_ ##name## _ops = { \ 208 .read = stats_ ##name## _read, \ 209 .open = mac80211_open_file_generic, \ 210 }; 211 212 #define DEBUGFS_STATS_ADD(name) \ 213 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\ 214 local, &stats_ ##name## _ops); 215 216 #define DEBUGFS_STATS_DEL(name) \ 217 debugfs_remove(local->debugfs.stats.name); \ 218 local->debugfs.stats.name = NULL; 219 220 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u", 221 local->dot11TransmittedFragmentCount); 222 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u", 223 local->dot11MulticastTransmittedFrameCount); 224 DEBUGFS_STATS_FILE(failed_count, 20, "%u", 225 local->dot11FailedCount); 226 DEBUGFS_STATS_FILE(retry_count, 20, "%u", 227 local->dot11RetryCount); 228 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u", 229 local->dot11MultipleRetryCount); 230 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u", 231 local->dot11FrameDuplicateCount); 232 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u", 233 local->dot11ReceivedFragmentCount); 234 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u", 235 local->dot11MulticastReceivedFrameCount); 236 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u", 237 local->dot11TransmittedFrameCount); 238 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS 239 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u", 240 local->tx_handlers_drop); 241 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u", 242 local->tx_handlers_queued); 243 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u", 244 local->tx_handlers_drop_unencrypted); 245 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u", 246 local->tx_handlers_drop_fragment); 247 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u", 248 local->tx_handlers_drop_wep); 249 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u", 250 local->tx_handlers_drop_not_assoc); 251 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u", 252 local->tx_handlers_drop_unauth_port); 253 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u", 254 local->rx_handlers_drop); 255 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u", 256 local->rx_handlers_queued); 257 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u", 258 local->rx_handlers_drop_nullfunc); 259 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u", 260 local->rx_handlers_drop_defrag); 261 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u", 262 local->rx_handlers_drop_short); 263 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u", 264 local->rx_handlers_drop_passive_scan); 265 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u", 266 local->tx_expand_skb_head); 267 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u", 268 local->tx_expand_skb_head_cloned); 269 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u", 270 local->rx_expand_skb_head); 271 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u", 272 local->rx_expand_skb_head2); 273 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u", 274 local->rx_handlers_fragments); 275 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u", 276 local->tx_status_drop); 277 278 #endif 279 280 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); 281 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); 282 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); 283 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); 284 285 286 void debugfs_hw_add(struct ieee80211_local *local) 287 { 288 struct dentry *phyd = local->hw.wiphy->debugfsdir; 289 struct dentry *statsd; 290 291 if (!phyd) 292 return; 293 294 local->debugfs.stations = debugfs_create_dir("stations", phyd); 295 local->debugfs.keys = debugfs_create_dir("keys", phyd); 296 297 DEBUGFS_ADD(frequency); 298 DEBUGFS_ADD(total_ps_buffered); 299 DEBUGFS_ADD(wep_iv); 300 DEBUGFS_ADD(tsf); 301 DEBUGFS_ADD_MODE(reset, 0200); 302 DEBUGFS_ADD(noack); 303 304 statsd = debugfs_create_dir("statistics", phyd); 305 local->debugfs.statistics = statsd; 306 307 /* if the dir failed, don't put all the other things into the root! */ 308 if (!statsd) 309 return; 310 311 DEBUGFS_STATS_ADD(transmitted_fragment_count); 312 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count); 313 DEBUGFS_STATS_ADD(failed_count); 314 DEBUGFS_STATS_ADD(retry_count); 315 DEBUGFS_STATS_ADD(multiple_retry_count); 316 DEBUGFS_STATS_ADD(frame_duplicate_count); 317 DEBUGFS_STATS_ADD(received_fragment_count); 318 DEBUGFS_STATS_ADD(multicast_received_frame_count); 319 DEBUGFS_STATS_ADD(transmitted_frame_count); 320 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS 321 DEBUGFS_STATS_ADD(tx_handlers_drop); 322 DEBUGFS_STATS_ADD(tx_handlers_queued); 323 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted); 324 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment); 325 DEBUGFS_STATS_ADD(tx_handlers_drop_wep); 326 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc); 327 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port); 328 DEBUGFS_STATS_ADD(rx_handlers_drop); 329 DEBUGFS_STATS_ADD(rx_handlers_queued); 330 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc); 331 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag); 332 DEBUGFS_STATS_ADD(rx_handlers_drop_short); 333 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan); 334 DEBUGFS_STATS_ADD(tx_expand_skb_head); 335 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned); 336 DEBUGFS_STATS_ADD(rx_expand_skb_head); 337 DEBUGFS_STATS_ADD(rx_expand_skb_head2); 338 DEBUGFS_STATS_ADD(rx_handlers_fragments); 339 DEBUGFS_STATS_ADD(tx_status_drop); 340 #endif 341 DEBUGFS_STATS_ADD(dot11ACKFailureCount); 342 DEBUGFS_STATS_ADD(dot11RTSFailureCount); 343 DEBUGFS_STATS_ADD(dot11FCSErrorCount); 344 DEBUGFS_STATS_ADD(dot11RTSSuccessCount); 345 } 346 347 void debugfs_hw_del(struct ieee80211_local *local) 348 { 349 DEBUGFS_DEL(frequency); 350 DEBUGFS_DEL(total_ps_buffered); 351 DEBUGFS_DEL(wep_iv); 352 DEBUGFS_DEL(tsf); 353 DEBUGFS_DEL(reset); 354 DEBUGFS_DEL(noack); 355 356 DEBUGFS_STATS_DEL(transmitted_fragment_count); 357 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); 358 DEBUGFS_STATS_DEL(failed_count); 359 DEBUGFS_STATS_DEL(retry_count); 360 DEBUGFS_STATS_DEL(multiple_retry_count); 361 DEBUGFS_STATS_DEL(frame_duplicate_count); 362 DEBUGFS_STATS_DEL(received_fragment_count); 363 DEBUGFS_STATS_DEL(multicast_received_frame_count); 364 DEBUGFS_STATS_DEL(transmitted_frame_count); 365 DEBUGFS_STATS_DEL(num_scans); 366 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS 367 DEBUGFS_STATS_DEL(tx_handlers_drop); 368 DEBUGFS_STATS_DEL(tx_handlers_queued); 369 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted); 370 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment); 371 DEBUGFS_STATS_DEL(tx_handlers_drop_wep); 372 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc); 373 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port); 374 DEBUGFS_STATS_DEL(rx_handlers_drop); 375 DEBUGFS_STATS_DEL(rx_handlers_queued); 376 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc); 377 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag); 378 DEBUGFS_STATS_DEL(rx_handlers_drop_short); 379 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan); 380 DEBUGFS_STATS_DEL(tx_expand_skb_head); 381 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned); 382 DEBUGFS_STATS_DEL(rx_expand_skb_head); 383 DEBUGFS_STATS_DEL(rx_expand_skb_head2); 384 DEBUGFS_STATS_DEL(rx_handlers_fragments); 385 DEBUGFS_STATS_DEL(tx_status_drop); 386 #endif 387 DEBUGFS_STATS_DEL(dot11ACKFailureCount); 388 DEBUGFS_STATS_DEL(dot11RTSFailureCount); 389 DEBUGFS_STATS_DEL(dot11FCSErrorCount); 390 DEBUGFS_STATS_DEL(dot11RTSSuccessCount); 391 392 debugfs_remove(local->debugfs.statistics); 393 local->debugfs.statistics = NULL; 394 debugfs_remove(local->debugfs.stations); 395 local->debugfs.stations = NULL; 396 debugfs_remove(local->debugfs.keys); 397 local->debugfs.keys = NULL; 398 } 399