debugfs.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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[NUM_IEEE80211_HW_FLAGS + 1] = {
  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. /* keep last for the build bug below */
  109. (void *)0x1
  110. #undef FLAG
  111. };
  112. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  113. size_t count, loff_t *ppos)
  114. {
  115. struct ieee80211_local *local = file->private_data;
  116. size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
  117. char *buf = kzalloc(bufsz, GFP_KERNEL);
  118. char *pos = buf, *end = buf + bufsz - 1;
  119. ssize_t rv;
  120. int i;
  121. if (!buf)
  122. return -ENOMEM;
  123. /* fail compilation if somebody adds or removes
  124. * a flag without updating the name array above
  125. */
  126. BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1);
  127. for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
  128. if (test_bit(i, local->hw.flags))
  129. pos += scnprintf(pos, end - pos, "%s",
  130. hw_flag_names[i]);
  131. }
  132. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  133. kfree(buf);
  134. return rv;
  135. }
  136. static ssize_t queues_read(struct file *file, char __user *user_buf,
  137. size_t count, loff_t *ppos)
  138. {
  139. struct ieee80211_local *local = file->private_data;
  140. unsigned long flags;
  141. char buf[IEEE80211_MAX_QUEUES * 20];
  142. int q, res = 0;
  143. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  144. for (q = 0; q < local->hw.queues; q++)
  145. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  146. local->queue_stop_reasons[q],
  147. skb_queue_len(&local->pending[q]));
  148. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  149. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  150. }
  151. DEBUGFS_READONLY_FILE_OPS(hwflags);
  152. DEBUGFS_READONLY_FILE_OPS(queues);
  153. /* statistics stuff */
  154. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  155. char __user *userbuf,
  156. size_t count, loff_t *ppos,
  157. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  158. int buflen))
  159. {
  160. struct ieee80211_low_level_stats stats;
  161. char buf[20];
  162. int res;
  163. rtnl_lock();
  164. res = drv_get_stats(local, &stats);
  165. rtnl_unlock();
  166. if (res)
  167. return res;
  168. res = printvalue(&stats, buf, sizeof(buf));
  169. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  170. }
  171. #define DEBUGFS_DEVSTATS_FILE(name) \
  172. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  173. char *buf, int buflen) \
  174. { \
  175. return scnprintf(buf, buflen, "%u\n", stats->name); \
  176. } \
  177. static ssize_t stats_ ##name## _read(struct file *file, \
  178. char __user *userbuf, \
  179. size_t count, loff_t *ppos) \
  180. { \
  181. return format_devstat_counter(file->private_data, \
  182. userbuf, \
  183. count, \
  184. ppos, \
  185. print_devstats_##name); \
  186. } \
  187. \
  188. static const struct file_operations stats_ ##name## _ops = { \
  189. .read = stats_ ##name## _read, \
  190. .open = simple_open, \
  191. .llseek = generic_file_llseek, \
  192. };
  193. #define DEBUGFS_STATS_ADD(name) \
  194. debugfs_create_u32(#name, 0400, statsd, &local->name);
  195. #define DEBUGFS_DEVSTATS_ADD(name) \
  196. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  197. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  198. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  199. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  200. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  201. void debugfs_hw_add(struct ieee80211_local *local)
  202. {
  203. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  204. struct dentry *statsd;
  205. if (!phyd)
  206. return;
  207. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  208. DEBUGFS_ADD(total_ps_buffered);
  209. DEBUGFS_ADD(wep_iv);
  210. DEBUGFS_ADD(queues);
  211. #ifdef CONFIG_PM
  212. DEBUGFS_ADD_MODE(reset, 0200);
  213. #endif
  214. DEBUGFS_ADD(hwflags);
  215. DEBUGFS_ADD(user_power);
  216. DEBUGFS_ADD(power);
  217. statsd = debugfs_create_dir("statistics", phyd);
  218. /* if the dir failed, don't put all the other things into the root! */
  219. if (!statsd)
  220. return;
  221. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  222. DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
  223. DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
  224. DEBUGFS_STATS_ADD(dot11FailedCount);
  225. DEBUGFS_STATS_ADD(dot11RetryCount);
  226. DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
  227. DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
  228. DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
  229. DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
  230. DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
  231. DEBUGFS_STATS_ADD(tx_handlers_drop);
  232. DEBUGFS_STATS_ADD(tx_handlers_queued);
  233. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  234. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  235. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  236. DEBUGFS_STATS_ADD(rx_handlers_drop);
  237. DEBUGFS_STATS_ADD(rx_handlers_queued);
  238. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  239. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  240. DEBUGFS_STATS_ADD(rx_handlers_drop_short);
  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. }