debugfs.c 11 KB

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