at v4.2 291 lines 8.3 kB view raw
1/* 2 * mac80211 debugfs for wireless PHYs 3 * 4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 5 * Copyright 2013-2014 Intel Mobile Communications GmbH 6 * 7 * GPLv2 8 * 9 */ 10 11#include <linux/debugfs.h> 12#include <linux/rtnetlink.h> 13#include "ieee80211_i.h" 14#include "driver-ops.h" 15#include "rate.h" 16#include "debugfs.h" 17 18#define DEBUGFS_FORMAT_BUFFER_SIZE 100 19 20int mac80211_format_buffer(char __user *userbuf, size_t count, 21 loff_t *ppos, char *fmt, ...) 22{ 23 va_list args; 24 char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; 25 int res; 26 27 va_start(args, fmt); 28 res = vscnprintf(buf, sizeof(buf), fmt, args); 29 va_end(args); 30 31 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 32} 33 34#define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \ 35static ssize_t name## _read(struct file *file, char __user *userbuf, \ 36 size_t count, loff_t *ppos) \ 37{ \ 38 struct ieee80211_local *local = file->private_data; \ 39 \ 40 return mac80211_format_buffer(userbuf, count, ppos, \ 41 fmt "\n", ##value); \ 42} 43 44#define DEBUGFS_READONLY_FILE_OPS(name) \ 45static const struct file_operations name## _ops = { \ 46 .read = name## _read, \ 47 .open = simple_open, \ 48 .llseek = generic_file_llseek, \ 49}; 50 51#define DEBUGFS_READONLY_FILE(name, fmt, value...) \ 52 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \ 53 DEBUGFS_READONLY_FILE_OPS(name) 54 55#define DEBUGFS_ADD(name) \ 56 debugfs_create_file(#name, 0400, phyd, local, &name## _ops); 57 58#define DEBUGFS_ADD_MODE(name, mode) \ 59 debugfs_create_file(#name, mode, phyd, local, &name## _ops); 60 61 62DEBUGFS_READONLY_FILE(user_power, "%d", 63 local->user_power_level); 64DEBUGFS_READONLY_FILE(power, "%d", 65 local->hw.conf.power_level); 66DEBUGFS_READONLY_FILE(total_ps_buffered, "%d", 67 local->total_ps_buffered); 68DEBUGFS_READONLY_FILE(wep_iv, "%#08x", 69 local->wep_iv & 0xffffff); 70DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s", 71 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); 72 73#ifdef CONFIG_PM 74static ssize_t reset_write(struct file *file, const char __user *user_buf, 75 size_t count, loff_t *ppos) 76{ 77 struct ieee80211_local *local = file->private_data; 78 79 rtnl_lock(); 80 __ieee80211_suspend(&local->hw, NULL); 81 __ieee80211_resume(&local->hw); 82 rtnl_unlock(); 83 84 return count; 85} 86 87static const struct file_operations reset_ops = { 88 .write = reset_write, 89 .open = simple_open, 90 .llseek = noop_llseek, 91}; 92#endif 93 94static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = { 95#define FLAG(F) [IEEE80211_HW_##F] = #F 96 FLAG(HAS_RATE_CONTROL), 97 FLAG(RX_INCLUDES_FCS), 98 FLAG(HOST_BROADCAST_PS_BUFFERING), 99 FLAG(SIGNAL_UNSPEC), 100 FLAG(SIGNAL_DBM), 101 FLAG(NEED_DTIM_BEFORE_ASSOC), 102 FLAG(SPECTRUM_MGMT), 103 FLAG(AMPDU_AGGREGATION), 104 FLAG(SUPPORTS_PS), 105 FLAG(PS_NULLFUNC_STACK), 106 FLAG(SUPPORTS_DYNAMIC_PS), 107 FLAG(MFP_CAPABLE), 108 FLAG(WANT_MONITOR_VIF), 109 FLAG(NO_AUTO_VIF), 110 FLAG(SW_CRYPTO_CONTROL), 111 FLAG(SUPPORT_FAST_XMIT), 112 FLAG(REPORTS_TX_ACK_STATUS), 113 FLAG(CONNECTION_MONITOR), 114 FLAG(QUEUE_CONTROL), 115 FLAG(SUPPORTS_PER_STA_GTK), 116 FLAG(AP_LINK_PS), 117 FLAG(TX_AMPDU_SETUP_IN_HW), 118 FLAG(SUPPORTS_RC_TABLE), 119 FLAG(P2P_DEV_ADDR_FOR_INTF), 120 FLAG(TIMING_BEACON_ONLY), 121 FLAG(SUPPORTS_HT_CCK_RATES), 122 FLAG(CHANCTX_STA_CSA), 123 FLAG(SUPPORTS_CLONED_SKBS), 124 FLAG(SINGLE_SCAN_ON_ALL_BANDS), 125 126 /* keep last for the build bug below */ 127 (void *)0x1 128#undef FLAG 129}; 130 131static ssize_t hwflags_read(struct file *file, char __user *user_buf, 132 size_t count, loff_t *ppos) 133{ 134 struct ieee80211_local *local = file->private_data; 135 size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS; 136 char *buf = kzalloc(bufsz, GFP_KERNEL); 137 char *pos = buf, *end = buf + bufsz - 1; 138 ssize_t rv; 139 int i; 140 141 if (!buf) 142 return -ENOMEM; 143 144 /* fail compilation if somebody adds or removes 145 * a flag without updating the name array above 146 */ 147 BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1); 148 149 for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) { 150 if (test_bit(i, local->hw.flags)) 151 pos += scnprintf(pos, end - pos, "%s", 152 hw_flag_names[i]); 153 } 154 155 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); 156 kfree(buf); 157 return rv; 158} 159 160static ssize_t queues_read(struct file *file, char __user *user_buf, 161 size_t count, loff_t *ppos) 162{ 163 struct ieee80211_local *local = file->private_data; 164 unsigned long flags; 165 char buf[IEEE80211_MAX_QUEUES * 20]; 166 int q, res = 0; 167 168 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 169 for (q = 0; q < local->hw.queues; q++) 170 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q, 171 local->queue_stop_reasons[q], 172 skb_queue_len(&local->pending[q])); 173 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 174 175 return simple_read_from_buffer(user_buf, count, ppos, buf, res); 176} 177 178DEBUGFS_READONLY_FILE_OPS(hwflags); 179DEBUGFS_READONLY_FILE_OPS(queues); 180 181/* statistics stuff */ 182 183static ssize_t format_devstat_counter(struct ieee80211_local *local, 184 char __user *userbuf, 185 size_t count, loff_t *ppos, 186 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, 187 int buflen)) 188{ 189 struct ieee80211_low_level_stats stats; 190 char buf[20]; 191 int res; 192 193 rtnl_lock(); 194 res = drv_get_stats(local, &stats); 195 rtnl_unlock(); 196 if (res) 197 return res; 198 res = printvalue(&stats, buf, sizeof(buf)); 199 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 200} 201 202#define DEBUGFS_DEVSTATS_FILE(name) \ 203static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ 204 char *buf, int buflen) \ 205{ \ 206 return scnprintf(buf, buflen, "%u\n", stats->name); \ 207} \ 208static ssize_t stats_ ##name## _read(struct file *file, \ 209 char __user *userbuf, \ 210 size_t count, loff_t *ppos) \ 211{ \ 212 return format_devstat_counter(file->private_data, \ 213 userbuf, \ 214 count, \ 215 ppos, \ 216 print_devstats_##name); \ 217} \ 218 \ 219static const struct file_operations stats_ ##name## _ops = { \ 220 .read = stats_ ##name## _read, \ 221 .open = simple_open, \ 222 .llseek = generic_file_llseek, \ 223}; 224 225#define DEBUGFS_STATS_ADD(name) \ 226 debugfs_create_u32(#name, 0400, statsd, &local->name); 227#define DEBUGFS_DEVSTATS_ADD(name) \ 228 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops); 229 230DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); 231DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); 232DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); 233DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); 234 235void debugfs_hw_add(struct ieee80211_local *local) 236{ 237 struct dentry *phyd = local->hw.wiphy->debugfsdir; 238 struct dentry *statsd; 239 240 if (!phyd) 241 return; 242 243 local->debugfs.keys = debugfs_create_dir("keys", phyd); 244 245 DEBUGFS_ADD(total_ps_buffered); 246 DEBUGFS_ADD(wep_iv); 247 DEBUGFS_ADD(queues); 248#ifdef CONFIG_PM 249 DEBUGFS_ADD_MODE(reset, 0200); 250#endif 251 DEBUGFS_ADD(hwflags); 252 DEBUGFS_ADD(user_power); 253 DEBUGFS_ADD(power); 254 255 statsd = debugfs_create_dir("statistics", phyd); 256 257 /* if the dir failed, don't put all the other things into the root! */ 258 if (!statsd) 259 return; 260 261#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 262 DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount); 263 DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount); 264 DEBUGFS_STATS_ADD(dot11FailedCount); 265 DEBUGFS_STATS_ADD(dot11RetryCount); 266 DEBUGFS_STATS_ADD(dot11MultipleRetryCount); 267 DEBUGFS_STATS_ADD(dot11FrameDuplicateCount); 268 DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount); 269 DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount); 270 DEBUGFS_STATS_ADD(dot11TransmittedFrameCount); 271 DEBUGFS_STATS_ADD(tx_handlers_drop); 272 DEBUGFS_STATS_ADD(tx_handlers_queued); 273 DEBUGFS_STATS_ADD(tx_handlers_drop_wep); 274 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc); 275 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port); 276 DEBUGFS_STATS_ADD(rx_handlers_drop); 277 DEBUGFS_STATS_ADD(rx_handlers_queued); 278 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc); 279 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag); 280 DEBUGFS_STATS_ADD(rx_handlers_drop_short); 281 DEBUGFS_STATS_ADD(tx_expand_skb_head); 282 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned); 283 DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag); 284 DEBUGFS_STATS_ADD(rx_handlers_fragments); 285 DEBUGFS_STATS_ADD(tx_status_drop); 286#endif 287 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount); 288 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); 289 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); 290 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); 291}