debugfs.c 12 KB

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