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 "rate.h" 14 #include "debugfs.h" 15 16 int mac80211_open_file_generic(struct inode *inode, struct file *file) 17 { 18 file->private_data = inode->i_private; 19 return 0; 20 } 21 22 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ 23 static ssize_t name## _read(struct file *file, char __user *userbuf, \ 24 size_t count, loff_t *ppos) \ 25 { \ 26 struct ieee80211_local *local = file->private_data; \ 27 char buf[buflen]; \ 28 int res; \ 29 \ 30 res = scnprintf(buf, buflen, fmt "\n", ##value); \ 31 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ 32 } \ 33 \ 34 static const struct file_operations name## _ops = { \ 35 .read = name## _read, \ 36 .open = mac80211_open_file_generic, \ 37 }; 38 39 #define DEBUGFS_ADD(name) \ 40 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \ 41 local, &name## _ops); 42 43 #define DEBUGFS_DEL(name) \ 44 debugfs_remove(local->debugfs.name); \ 45 local->debugfs.name = NULL; 46 47 48 DEBUGFS_READONLY_FILE(frequency, 20, "%d", 49 local->hw.conf.channel->center_freq); 50 DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d", 51 local->hw.conf.antenna_sel_tx); 52 DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d", 53 local->hw.conf.antenna_sel_rx); 54 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", 55 local->rts_threshold); 56 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", 57 local->fragmentation_threshold); 58 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", 59 local->short_retry_limit); 60 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", 61 local->long_retry_limit); 62 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 63 local->total_ps_buffered); 64 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x", 65 local->wep_iv & 0xffffff); 66 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", 67 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>"); 68 69 /* statistics stuff */ 70 71 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ 72 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value) 73 74 static ssize_t format_devstat_counter(struct ieee80211_local *local, 75 char __user *userbuf, 76 size_t count, loff_t *ppos, 77 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, 78 int buflen)) 79 { 80 struct ieee80211_low_level_stats stats; 81 char buf[20]; 82 int res; 83 84 if (!local->ops->get_stats) 85 return -EOPNOTSUPP; 86 87 rtnl_lock(); 88 res = local->ops->get_stats(local_to_hw(local), &stats); 89 rtnl_unlock(); 90 if (!res) 91 res = printvalue(&stats, buf, sizeof(buf)); 92 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 93 } 94 95 #define DEBUGFS_DEVSTATS_FILE(name) \ 96 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ 97 char *buf, int buflen) \ 98 { \ 99 return scnprintf(buf, buflen, "%u\n", stats->name); \ 100 } \ 101 static ssize_t stats_ ##name## _read(struct file *file, \ 102 char __user *userbuf, \ 103 size_t count, loff_t *ppos) \ 104 { \ 105 return format_devstat_counter(file->private_data, \ 106 userbuf, \ 107 count, \ 108 ppos, \ 109 print_devstats_##name); \ 110 } \ 111 \ 112 static const struct file_operations stats_ ##name## _ops = { \ 113 .read = stats_ ##name## _read, \ 114 .open = mac80211_open_file_generic, \ 115 }; 116 117 #define DEBUGFS_STATS_ADD(name) \ 118 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\ 119 local, &stats_ ##name## _ops); 120 121 #define DEBUGFS_STATS_DEL(name) \ 122 debugfs_remove(local->debugfs.stats.name); \ 123 local->debugfs.stats.name = NULL; 124 125 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u", 126 local->dot11TransmittedFragmentCount); 127 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u", 128 local->dot11MulticastTransmittedFrameCount); 129 DEBUGFS_STATS_FILE(failed_count, 20, "%u", 130 local->dot11FailedCount); 131 DEBUGFS_STATS_FILE(retry_count, 20, "%u", 132 local->dot11RetryCount); 133 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u", 134 local->dot11MultipleRetryCount); 135 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u", 136 local->dot11FrameDuplicateCount); 137 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u", 138 local->dot11ReceivedFragmentCount); 139 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u", 140 local->dot11MulticastReceivedFrameCount); 141 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u", 142 local->dot11TransmittedFrameCount); 143 DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u", 144 local->dot11WEPUndecryptableCount); 145 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS 146 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u", 147 local->tx_handlers_drop); 148 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u", 149 local->tx_handlers_queued); 150 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u", 151 local->tx_handlers_drop_unencrypted); 152 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u", 153 local->tx_handlers_drop_fragment); 154 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u", 155 local->tx_handlers_drop_wep); 156 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u", 157 local->tx_handlers_drop_not_assoc); 158 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u", 159 local->tx_handlers_drop_unauth_port); 160 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u", 161 local->rx_handlers_drop); 162 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u", 163 local->rx_handlers_queued); 164 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u", 165 local->rx_handlers_drop_nullfunc); 166 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u", 167 local->rx_handlers_drop_defrag); 168 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u", 169 local->rx_handlers_drop_short); 170 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u", 171 local->rx_handlers_drop_passive_scan); 172 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u", 173 local->tx_expand_skb_head); 174 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u", 175 local->tx_expand_skb_head_cloned); 176 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u", 177 local->rx_expand_skb_head); 178 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u", 179 local->rx_expand_skb_head2); 180 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u", 181 local->rx_handlers_fragments); 182 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u", 183 local->tx_status_drop); 184 185 #endif 186 187 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); 188 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); 189 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); 190 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); 191 192 193 void debugfs_hw_add(struct ieee80211_local *local) 194 { 195 struct dentry *phyd = local->hw.wiphy->debugfsdir; 196 struct dentry *statsd; 197 198 if (!phyd) 199 return; 200 201 local->debugfs.stations = debugfs_create_dir("stations", phyd); 202 local->debugfs.keys = debugfs_create_dir("keys", phyd); 203 204 DEBUGFS_ADD(frequency); 205 DEBUGFS_ADD(antenna_sel_tx); 206 DEBUGFS_ADD(antenna_sel_rx); 207 DEBUGFS_ADD(rts_threshold); 208 DEBUGFS_ADD(fragmentation_threshold); 209 DEBUGFS_ADD(short_retry_limit); 210 DEBUGFS_ADD(long_retry_limit); 211 DEBUGFS_ADD(total_ps_buffered); 212 DEBUGFS_ADD(wep_iv); 213 214 statsd = debugfs_create_dir("statistics", phyd); 215 local->debugfs.statistics = statsd; 216 217 /* if the dir failed, don't put all the other things into the root! */ 218 if (!statsd) 219 return; 220 221 DEBUGFS_STATS_ADD(transmitted_fragment_count); 222 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count); 223 DEBUGFS_STATS_ADD(failed_count); 224 DEBUGFS_STATS_ADD(retry_count); 225 DEBUGFS_STATS_ADD(multiple_retry_count); 226 DEBUGFS_STATS_ADD(frame_duplicate_count); 227 DEBUGFS_STATS_ADD(received_fragment_count); 228 DEBUGFS_STATS_ADD(multicast_received_frame_count); 229 DEBUGFS_STATS_ADD(transmitted_frame_count); 230 DEBUGFS_STATS_ADD(wep_undecryptable_count); 231 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS 232 DEBUGFS_STATS_ADD(tx_handlers_drop); 233 DEBUGFS_STATS_ADD(tx_handlers_queued); 234 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted); 235 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment); 236 DEBUGFS_STATS_ADD(tx_handlers_drop_wep); 237 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc); 238 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port); 239 DEBUGFS_STATS_ADD(rx_handlers_drop); 240 DEBUGFS_STATS_ADD(rx_handlers_queued); 241 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc); 242 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag); 243 DEBUGFS_STATS_ADD(rx_handlers_drop_short); 244 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan); 245 DEBUGFS_STATS_ADD(tx_expand_skb_head); 246 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned); 247 DEBUGFS_STATS_ADD(rx_expand_skb_head); 248 DEBUGFS_STATS_ADD(rx_expand_skb_head2); 249 DEBUGFS_STATS_ADD(rx_handlers_fragments); 250 DEBUGFS_STATS_ADD(tx_status_drop); 251 #endif 252 DEBUGFS_STATS_ADD(dot11ACKFailureCount); 253 DEBUGFS_STATS_ADD(dot11RTSFailureCount); 254 DEBUGFS_STATS_ADD(dot11FCSErrorCount); 255 DEBUGFS_STATS_ADD(dot11RTSSuccessCount); 256 } 257 258 void debugfs_hw_del(struct ieee80211_local *local) 259 { 260 DEBUGFS_DEL(frequency); 261 DEBUGFS_DEL(antenna_sel_tx); 262 DEBUGFS_DEL(antenna_sel_rx); 263 DEBUGFS_DEL(rts_threshold); 264 DEBUGFS_DEL(fragmentation_threshold); 265 DEBUGFS_DEL(short_retry_limit); 266 DEBUGFS_DEL(long_retry_limit); 267 DEBUGFS_DEL(total_ps_buffered); 268 DEBUGFS_DEL(wep_iv); 269 270 DEBUGFS_STATS_DEL(transmitted_fragment_count); 271 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); 272 DEBUGFS_STATS_DEL(failed_count); 273 DEBUGFS_STATS_DEL(retry_count); 274 DEBUGFS_STATS_DEL(multiple_retry_count); 275 DEBUGFS_STATS_DEL(frame_duplicate_count); 276 DEBUGFS_STATS_DEL(received_fragment_count); 277 DEBUGFS_STATS_DEL(multicast_received_frame_count); 278 DEBUGFS_STATS_DEL(transmitted_frame_count); 279 DEBUGFS_STATS_DEL(wep_undecryptable_count); 280 DEBUGFS_STATS_DEL(num_scans); 281 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS 282 DEBUGFS_STATS_DEL(tx_handlers_drop); 283 DEBUGFS_STATS_DEL(tx_handlers_queued); 284 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted); 285 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment); 286 DEBUGFS_STATS_DEL(tx_handlers_drop_wep); 287 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc); 288 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port); 289 DEBUGFS_STATS_DEL(rx_handlers_drop); 290 DEBUGFS_STATS_DEL(rx_handlers_queued); 291 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc); 292 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag); 293 DEBUGFS_STATS_DEL(rx_handlers_drop_short); 294 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan); 295 DEBUGFS_STATS_DEL(tx_expand_skb_head); 296 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned); 297 DEBUGFS_STATS_DEL(rx_expand_skb_head); 298 DEBUGFS_STATS_DEL(rx_expand_skb_head2); 299 DEBUGFS_STATS_DEL(rx_handlers_fragments); 300 DEBUGFS_STATS_DEL(tx_status_drop); 301 #endif 302 DEBUGFS_STATS_DEL(dot11ACKFailureCount); 303 DEBUGFS_STATS_DEL(dot11RTSFailureCount); 304 DEBUGFS_STATS_DEL(dot11FCSErrorCount); 305 DEBUGFS_STATS_DEL(dot11RTSSuccessCount); 306 307 debugfs_remove(local->debugfs.statistics); 308 local->debugfs.statistics = NULL; 309 debugfs_remove(local->debugfs.stations); 310 local->debugfs.stations = NULL; 311 debugfs_remove(local->debugfs.keys); 312 local->debugfs.keys = NULL; 313 } 314