debugfs.c 12 KB

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