debugfs.c 12 KB

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