debugfs.c 12 KB

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