debugfs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 "driver-ops.h"
  13. #include "rate.h"
  14. #include "debugfs.h"
  15. int mac80211_open_file_generic(struct inode *inode, struct file *file)
  16. {
  17. file->private_data = inode->i_private;
  18. return 0;
  19. }
  20. #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
  21. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  22. size_t count, loff_t *ppos) \
  23. { \
  24. struct ieee80211_local *local = file->private_data; \
  25. char buf[buflen]; \
  26. int res; \
  27. \
  28. res = scnprintf(buf, buflen, fmt "\n", ##value); \
  29. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  30. } \
  31. \
  32. static const struct file_operations name## _ops = { \
  33. .read = name## _read, \
  34. .open = mac80211_open_file_generic, \
  35. };
  36. #define DEBUGFS_ADD(name) \
  37. local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
  38. local, &name## _ops);
  39. #define DEBUGFS_ADD_MODE(name, mode) \
  40. local->debugfs.name = debugfs_create_file(#name, mode, phyd, \
  41. local, &name## _ops);
  42. #define DEBUGFS_DEL(name) \
  43. debugfs_remove(local->debugfs.name); \
  44. local->debugfs.name = NULL;
  45. DEBUGFS_READONLY_FILE(frequency, 20, "%d",
  46. local->hw.conf.channel->center_freq);
  47. DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
  48. local->hw.wiphy->rts_threshold);
  49. DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
  50. local->hw.wiphy->frag_threshold);
  51. DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
  52. local->hw.wiphy->retry_short);
  53. DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
  54. local->hw.wiphy->retry_long);
  55. DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
  56. local->total_ps_buffered);
  57. DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
  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. static ssize_t tsf_read(struct file *file, char __user *user_buf,
  62. size_t count, loff_t *ppos)
  63. {
  64. struct ieee80211_local *local = file->private_data;
  65. u64 tsf;
  66. char buf[100];
  67. tsf = drv_get_tsf(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. drv_reset_tsf(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. drv_set_tsf(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. rtnl_lock();
  129. res = drv_get_stats(local, &stats);
  130. rtnl_unlock();
  131. if (res)
  132. return res;
  133. res = printvalue(&stats, buf, sizeof(buf));
  134. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  135. }
  136. #define DEBUGFS_DEVSTATS_FILE(name) \
  137. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  138. char *buf, int buflen) \
  139. { \
  140. return scnprintf(buf, buflen, "%u\n", stats->name); \
  141. } \
  142. static ssize_t stats_ ##name## _read(struct file *file, \
  143. char __user *userbuf, \
  144. size_t count, loff_t *ppos) \
  145. { \
  146. return format_devstat_counter(file->private_data, \
  147. userbuf, \
  148. count, \
  149. ppos, \
  150. print_devstats_##name); \
  151. } \
  152. \
  153. static const struct file_operations stats_ ##name## _ops = { \
  154. .read = stats_ ##name## _read, \
  155. .open = mac80211_open_file_generic, \
  156. };
  157. #define DEBUGFS_STATS_ADD(name) \
  158. local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
  159. local, &stats_ ##name## _ops);
  160. #define DEBUGFS_STATS_DEL(name) \
  161. debugfs_remove(local->debugfs.stats.name); \
  162. local->debugfs.stats.name = NULL;
  163. DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
  164. local->dot11TransmittedFragmentCount);
  165. DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
  166. local->dot11MulticastTransmittedFrameCount);
  167. DEBUGFS_STATS_FILE(failed_count, 20, "%u",
  168. local->dot11FailedCount);
  169. DEBUGFS_STATS_FILE(retry_count, 20, "%u",
  170. local->dot11RetryCount);
  171. DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
  172. local->dot11MultipleRetryCount);
  173. DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
  174. local->dot11FrameDuplicateCount);
  175. DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
  176. local->dot11ReceivedFragmentCount);
  177. DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
  178. local->dot11MulticastReceivedFrameCount);
  179. DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
  180. local->dot11TransmittedFrameCount);
  181. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  182. DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
  183. local->tx_handlers_drop);
  184. DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
  185. local->tx_handlers_queued);
  186. DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
  187. local->tx_handlers_drop_unencrypted);
  188. DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
  189. local->tx_handlers_drop_fragment);
  190. DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
  191. local->tx_handlers_drop_wep);
  192. DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
  193. local->tx_handlers_drop_not_assoc);
  194. DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
  195. local->tx_handlers_drop_unauth_port);
  196. DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
  197. local->rx_handlers_drop);
  198. DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
  199. local->rx_handlers_queued);
  200. DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
  201. local->rx_handlers_drop_nullfunc);
  202. DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
  203. local->rx_handlers_drop_defrag);
  204. DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
  205. local->rx_handlers_drop_short);
  206. DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
  207. local->rx_handlers_drop_passive_scan);
  208. DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
  209. local->tx_expand_skb_head);
  210. DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
  211. local->tx_expand_skb_head_cloned);
  212. DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
  213. local->rx_expand_skb_head);
  214. DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
  215. local->rx_expand_skb_head2);
  216. DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
  217. local->rx_handlers_fragments);
  218. DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
  219. local->tx_status_drop);
  220. #endif
  221. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  222. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  223. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  224. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  225. void debugfs_hw_add(struct ieee80211_local *local)
  226. {
  227. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  228. struct dentry *statsd;
  229. if (!phyd)
  230. return;
  231. local->debugfs.stations = debugfs_create_dir("stations", phyd);
  232. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  233. DEBUGFS_ADD(frequency);
  234. DEBUGFS_ADD(rts_threshold);
  235. DEBUGFS_ADD(fragmentation_threshold);
  236. DEBUGFS_ADD(short_retry_limit);
  237. DEBUGFS_ADD(long_retry_limit);
  238. DEBUGFS_ADD(total_ps_buffered);
  239. DEBUGFS_ADD(wep_iv);
  240. DEBUGFS_ADD(tsf);
  241. DEBUGFS_ADD_MODE(reset, 0200);
  242. statsd = debugfs_create_dir("statistics", phyd);
  243. local->debugfs.statistics = statsd;
  244. /* if the dir failed, don't put all the other things into the root! */
  245. if (!statsd)
  246. return;
  247. DEBUGFS_STATS_ADD(transmitted_fragment_count);
  248. DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
  249. DEBUGFS_STATS_ADD(failed_count);
  250. DEBUGFS_STATS_ADD(retry_count);
  251. DEBUGFS_STATS_ADD(multiple_retry_count);
  252. DEBUGFS_STATS_ADD(frame_duplicate_count);
  253. DEBUGFS_STATS_ADD(received_fragment_count);
  254. DEBUGFS_STATS_ADD(multicast_received_frame_count);
  255. DEBUGFS_STATS_ADD(transmitted_frame_count);
  256. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  257. DEBUGFS_STATS_ADD(tx_handlers_drop);
  258. DEBUGFS_STATS_ADD(tx_handlers_queued);
  259. DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
  260. DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
  261. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  262. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  263. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  264. DEBUGFS_STATS_ADD(rx_handlers_drop);
  265. DEBUGFS_STATS_ADD(rx_handlers_queued);
  266. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  267. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  268. DEBUGFS_STATS_ADD(rx_handlers_drop_short);
  269. DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
  270. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  271. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  272. DEBUGFS_STATS_ADD(rx_expand_skb_head);
  273. DEBUGFS_STATS_ADD(rx_expand_skb_head2);
  274. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  275. DEBUGFS_STATS_ADD(tx_status_drop);
  276. #endif
  277. DEBUGFS_STATS_ADD(dot11ACKFailureCount);
  278. DEBUGFS_STATS_ADD(dot11RTSFailureCount);
  279. DEBUGFS_STATS_ADD(dot11FCSErrorCount);
  280. DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
  281. }
  282. void debugfs_hw_del(struct ieee80211_local *local)
  283. {
  284. DEBUGFS_DEL(frequency);
  285. DEBUGFS_DEL(rts_threshold);
  286. DEBUGFS_DEL(fragmentation_threshold);
  287. DEBUGFS_DEL(short_retry_limit);
  288. DEBUGFS_DEL(long_retry_limit);
  289. DEBUGFS_DEL(total_ps_buffered);
  290. DEBUGFS_DEL(wep_iv);
  291. DEBUGFS_DEL(tsf);
  292. DEBUGFS_DEL(reset);
  293. DEBUGFS_STATS_DEL(transmitted_fragment_count);
  294. DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
  295. DEBUGFS_STATS_DEL(failed_count);
  296. DEBUGFS_STATS_DEL(retry_count);
  297. DEBUGFS_STATS_DEL(multiple_retry_count);
  298. DEBUGFS_STATS_DEL(frame_duplicate_count);
  299. DEBUGFS_STATS_DEL(received_fragment_count);
  300. DEBUGFS_STATS_DEL(multicast_received_frame_count);
  301. DEBUGFS_STATS_DEL(transmitted_frame_count);
  302. DEBUGFS_STATS_DEL(num_scans);
  303. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  304. DEBUGFS_STATS_DEL(tx_handlers_drop);
  305. DEBUGFS_STATS_DEL(tx_handlers_queued);
  306. DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
  307. DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
  308. DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
  309. DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
  310. DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
  311. DEBUGFS_STATS_DEL(rx_handlers_drop);
  312. DEBUGFS_STATS_DEL(rx_handlers_queued);
  313. DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
  314. DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
  315. DEBUGFS_STATS_DEL(rx_handlers_drop_short);
  316. DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
  317. DEBUGFS_STATS_DEL(tx_expand_skb_head);
  318. DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
  319. DEBUGFS_STATS_DEL(rx_expand_skb_head);
  320. DEBUGFS_STATS_DEL(rx_expand_skb_head2);
  321. DEBUGFS_STATS_DEL(rx_handlers_fragments);
  322. DEBUGFS_STATS_DEL(tx_status_drop);
  323. #endif
  324. DEBUGFS_STATS_DEL(dot11ACKFailureCount);
  325. DEBUGFS_STATS_DEL(dot11RTSFailureCount);
  326. DEBUGFS_STATS_DEL(dot11FCSErrorCount);
  327. DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
  328. debugfs_remove(local->debugfs.statistics);
  329. local->debugfs.statistics = NULL;
  330. debugfs_remove(local->debugfs.stations);
  331. local->debugfs.stations = NULL;
  332. debugfs_remove(local->debugfs.keys);
  333. local->debugfs.keys = NULL;
  334. }