debugfs.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * mac80211 debugfs for wireless PHYs
  3. *
  4. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. *
  7. * GPLv2
  8. *
  9. */
  10. #include <linux/debugfs.h>
  11. #include <linux/rtnetlink.h>
  12. #include "ieee80211_i.h"
  13. #include "driver-ops.h"
  14. #include "rate.h"
  15. #include "debugfs.h"
  16. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  17. int mac80211_format_buffer(char __user *userbuf, size_t count,
  18. loff_t *ppos, char *fmt, ...)
  19. {
  20. va_list args;
  21. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  22. int res;
  23. va_start(args, fmt);
  24. res = vscnprintf(buf, sizeof(buf), fmt, args);
  25. va_end(args);
  26. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  27. }
  28. #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
  29. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  30. size_t count, loff_t *ppos) \
  31. { \
  32. struct ieee80211_local *local = file->private_data; \
  33. \
  34. return mac80211_format_buffer(userbuf, count, ppos, \
  35. fmt "\n", ##value); \
  36. }
  37. #define DEBUGFS_READONLY_FILE_OPS(name) \
  38. static const struct file_operations name## _ops = { \
  39. .read = name## _read, \
  40. .open = simple_open, \
  41. .llseek = generic_file_llseek, \
  42. };
  43. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  44. DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
  45. DEBUGFS_READONLY_FILE_OPS(name)
  46. #define DEBUGFS_ADD(name) \
  47. debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
  48. #define DEBUGFS_ADD_MODE(name, mode) \
  49. debugfs_create_file(#name, mode, phyd, local, &name## _ops);
  50. DEBUGFS_READONLY_FILE(user_power, "%d",
  51. local->user_power_level);
  52. DEBUGFS_READONLY_FILE(power, "%d",
  53. local->hw.conf.power_level);
  54. DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
  55. local->total_ps_buffered);
  56. DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
  57. local->wep_iv & 0xffffff);
  58. DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
  59. local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
  60. #ifdef CONFIG_PM
  61. static ssize_t reset_write(struct file *file, const char __user *user_buf,
  62. size_t count, loff_t *ppos)
  63. {
  64. struct ieee80211_local *local = file->private_data;
  65. rtnl_lock();
  66. __ieee80211_suspend(&local->hw, NULL);
  67. __ieee80211_resume(&local->hw);
  68. rtnl_unlock();
  69. return count;
  70. }
  71. static const struct file_operations reset_ops = {
  72. .write = reset_write,
  73. .open = simple_open,
  74. .llseek = noop_llseek,
  75. };
  76. #endif
  77. static const char *hw_flag_names[] = {
  78. #define FLAG(F) [IEEE80211_HW_##F] = #F
  79. FLAG(HAS_RATE_CONTROL),
  80. FLAG(RX_INCLUDES_FCS),
  81. FLAG(HOST_BROADCAST_PS_BUFFERING),
  82. FLAG(SIGNAL_UNSPEC),
  83. FLAG(SIGNAL_DBM),
  84. FLAG(NEED_DTIM_BEFORE_ASSOC),
  85. FLAG(SPECTRUM_MGMT),
  86. FLAG(AMPDU_AGGREGATION),
  87. FLAG(SUPPORTS_PS),
  88. FLAG(PS_NULLFUNC_STACK),
  89. FLAG(SUPPORTS_DYNAMIC_PS),
  90. FLAG(MFP_CAPABLE),
  91. FLAG(WANT_MONITOR_VIF),
  92. FLAG(NO_AUTO_VIF),
  93. FLAG(SW_CRYPTO_CONTROL),
  94. FLAG(SUPPORT_FAST_XMIT),
  95. FLAG(REPORTS_TX_ACK_STATUS),
  96. FLAG(CONNECTION_MONITOR),
  97. FLAG(QUEUE_CONTROL),
  98. FLAG(SUPPORTS_PER_STA_GTK),
  99. FLAG(AP_LINK_PS),
  100. FLAG(TX_AMPDU_SETUP_IN_HW),
  101. FLAG(SUPPORTS_RC_TABLE),
  102. FLAG(P2P_DEV_ADDR_FOR_INTF),
  103. FLAG(TIMING_BEACON_ONLY),
  104. FLAG(SUPPORTS_HT_CCK_RATES),
  105. FLAG(CHANCTX_STA_CSA),
  106. FLAG(SUPPORTS_CLONED_SKBS),
  107. FLAG(SINGLE_SCAN_ON_ALL_BANDS),
  108. FLAG(TDLS_WIDER_BW),
  109. FLAG(SUPPORTS_AMSDU_IN_AMPDU),
  110. FLAG(BEACON_TX_STATUS),
  111. #undef FLAG
  112. };
  113. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  114. size_t count, loff_t *ppos)
  115. {
  116. struct ieee80211_local *local = file->private_data;
  117. size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
  118. char *buf = kzalloc(bufsz, GFP_KERNEL);
  119. char *pos = buf, *end = buf + bufsz - 1;
  120. ssize_t rv;
  121. int i;
  122. if (!buf)
  123. return -ENOMEM;
  124. /* fail compilation if somebody adds or removes
  125. * a flag without updating the name array above
  126. */
  127. BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
  128. for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
  129. if (test_bit(i, local->hw.flags))
  130. pos += scnprintf(pos, end - pos, "%s\n",
  131. hw_flag_names[i]);
  132. }
  133. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  134. kfree(buf);
  135. return rv;
  136. }
  137. static ssize_t queues_read(struct file *file, char __user *user_buf,
  138. size_t count, loff_t *ppos)
  139. {
  140. struct ieee80211_local *local = file->private_data;
  141. unsigned long flags;
  142. char buf[IEEE80211_MAX_QUEUES * 20];
  143. int q, res = 0;
  144. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  145. for (q = 0; q < local->hw.queues; q++)
  146. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  147. local->queue_stop_reasons[q],
  148. skb_queue_len(&local->pending[q]));
  149. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  150. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  151. }
  152. DEBUGFS_READONLY_FILE_OPS(hwflags);
  153. DEBUGFS_READONLY_FILE_OPS(queues);
  154. /* statistics stuff */
  155. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  156. char __user *userbuf,
  157. size_t count, loff_t *ppos,
  158. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  159. int buflen))
  160. {
  161. struct ieee80211_low_level_stats stats;
  162. char buf[20];
  163. int res;
  164. rtnl_lock();
  165. res = drv_get_stats(local, &stats);
  166. rtnl_unlock();
  167. if (res)
  168. return res;
  169. res = printvalue(&stats, buf, sizeof(buf));
  170. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  171. }
  172. #define DEBUGFS_DEVSTATS_FILE(name) \
  173. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  174. char *buf, int buflen) \
  175. { \
  176. return scnprintf(buf, buflen, "%u\n", stats->name); \
  177. } \
  178. static ssize_t stats_ ##name## _read(struct file *file, \
  179. char __user *userbuf, \
  180. size_t count, loff_t *ppos) \
  181. { \
  182. return format_devstat_counter(file->private_data, \
  183. userbuf, \
  184. count, \
  185. ppos, \
  186. print_devstats_##name); \
  187. } \
  188. \
  189. static const struct file_operations stats_ ##name## _ops = { \
  190. .read = stats_ ##name## _read, \
  191. .open = simple_open, \
  192. .llseek = generic_file_llseek, \
  193. };
  194. #define DEBUGFS_STATS_ADD(name) \
  195. debugfs_create_u32(#name, 0400, statsd, &local->name);
  196. #define DEBUGFS_DEVSTATS_ADD(name) \
  197. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  198. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  199. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  200. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  201. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  202. void debugfs_hw_add(struct ieee80211_local *local)
  203. {
  204. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  205. struct dentry *statsd;
  206. if (!phyd)
  207. return;
  208. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  209. DEBUGFS_ADD(total_ps_buffered);
  210. DEBUGFS_ADD(wep_iv);
  211. DEBUGFS_ADD(queues);
  212. #ifdef CONFIG_PM
  213. DEBUGFS_ADD_MODE(reset, 0200);
  214. #endif
  215. DEBUGFS_ADD(hwflags);
  216. DEBUGFS_ADD(user_power);
  217. DEBUGFS_ADD(power);
  218. statsd = debugfs_create_dir("statistics", phyd);
  219. /* if the dir failed, don't put all the other things into the root! */
  220. if (!statsd)
  221. return;
  222. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  223. DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
  224. DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
  225. DEBUGFS_STATS_ADD(dot11FailedCount);
  226. DEBUGFS_STATS_ADD(dot11RetryCount);
  227. DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
  228. DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
  229. DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
  230. DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
  231. DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
  232. DEBUGFS_STATS_ADD(tx_handlers_drop);
  233. DEBUGFS_STATS_ADD(tx_handlers_queued);
  234. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  235. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  236. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  237. DEBUGFS_STATS_ADD(rx_handlers_drop);
  238. DEBUGFS_STATS_ADD(rx_handlers_queued);
  239. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  240. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  241. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  242. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  243. DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
  244. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  245. DEBUGFS_STATS_ADD(tx_status_drop);
  246. #endif
  247. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  248. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  249. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  250. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  251. }