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