debugfs.c 10 KB

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