debugfs.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 ssize_t hwflags_read(struct file *file, char __user *user_buf,
  78. size_t count, loff_t *ppos)
  79. {
  80. struct ieee80211_local *local = file->private_data;
  81. int mxln = 500;
  82. ssize_t rv;
  83. char *buf = kzalloc(mxln, GFP_KERNEL);
  84. int sf = 0; /* how many written so far */
  85. if (!buf)
  86. return 0;
  87. sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
  88. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  89. sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
  90. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  91. sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
  92. if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
  93. sf += scnprintf(buf + sf, mxln - sf,
  94. "HOST_BCAST_PS_BUFFERING\n");
  95. if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
  96. sf += scnprintf(buf + sf, mxln - sf,
  97. "2GHZ_SHORT_SLOT_INCAPABLE\n");
  98. if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
  99. sf += scnprintf(buf + sf, mxln - sf,
  100. "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
  101. if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
  102. sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
  103. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  104. sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
  105. if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
  106. sf += scnprintf(buf + sf, mxln - sf,
  107. "NEED_DTIM_BEFORE_ASSOC\n");
  108. if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
  109. sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
  110. if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
  111. sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
  112. if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
  113. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
  114. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  115. sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
  116. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  117. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
  118. if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
  119. sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
  120. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  121. sf += scnprintf(buf + sf, mxln - sf,
  122. "REPORTS_TX_ACK_STATUS\n");
  123. if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  124. sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
  125. if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
  126. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
  127. if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  128. sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
  129. if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
  130. sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
  131. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  132. kfree(buf);
  133. return rv;
  134. }
  135. static ssize_t queues_read(struct file *file, char __user *user_buf,
  136. size_t count, loff_t *ppos)
  137. {
  138. struct ieee80211_local *local = file->private_data;
  139. unsigned long flags;
  140. char buf[IEEE80211_MAX_QUEUES * 20];
  141. int q, res = 0;
  142. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  143. for (q = 0; q < local->hw.queues; q++)
  144. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  145. local->queue_stop_reasons[q],
  146. skb_queue_len(&local->pending[q]));
  147. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  148. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  149. }
  150. DEBUGFS_READONLY_FILE_OPS(hwflags);
  151. DEBUGFS_READONLY_FILE_OPS(queues);
  152. /* statistics stuff */
  153. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  154. char __user *userbuf,
  155. size_t count, loff_t *ppos,
  156. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  157. int buflen))
  158. {
  159. struct ieee80211_low_level_stats stats;
  160. char buf[20];
  161. int res;
  162. rtnl_lock();
  163. res = drv_get_stats(local, &stats);
  164. rtnl_unlock();
  165. if (res)
  166. return res;
  167. res = printvalue(&stats, buf, sizeof(buf));
  168. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  169. }
  170. #define DEBUGFS_DEVSTATS_FILE(name) \
  171. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  172. char *buf, int buflen) \
  173. { \
  174. return scnprintf(buf, buflen, "%u\n", stats->name); \
  175. } \
  176. static ssize_t stats_ ##name## _read(struct file *file, \
  177. char __user *userbuf, \
  178. size_t count, loff_t *ppos) \
  179. { \
  180. return format_devstat_counter(file->private_data, \
  181. userbuf, \
  182. count, \
  183. ppos, \
  184. print_devstats_##name); \
  185. } \
  186. \
  187. static const struct file_operations stats_ ##name## _ops = { \
  188. .read = stats_ ##name## _read, \
  189. .open = simple_open, \
  190. .llseek = generic_file_llseek, \
  191. };
  192. #define DEBUGFS_STATS_ADD(name, field) \
  193. debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
  194. #define DEBUGFS_DEVSTATS_ADD(name) \
  195. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  196. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  197. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  198. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  199. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  200. void debugfs_hw_add(struct ieee80211_local *local)
  201. {
  202. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  203. struct dentry *statsd;
  204. if (!phyd)
  205. return;
  206. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  207. DEBUGFS_ADD(total_ps_buffered);
  208. DEBUGFS_ADD(wep_iv);
  209. DEBUGFS_ADD(queues);
  210. #ifdef CONFIG_PM
  211. DEBUGFS_ADD_MODE(reset, 0200);
  212. #endif
  213. DEBUGFS_ADD(hwflags);
  214. DEBUGFS_ADD(user_power);
  215. DEBUGFS_ADD(power);
  216. statsd = debugfs_create_dir("statistics", phyd);
  217. /* if the dir failed, don't put all the other things into the root! */
  218. if (!statsd)
  219. return;
  220. DEBUGFS_STATS_ADD(transmitted_fragment_count,
  221. local->dot11TransmittedFragmentCount);
  222. DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
  223. local->dot11MulticastTransmittedFrameCount);
  224. DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
  225. DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
  226. DEBUGFS_STATS_ADD(multiple_retry_count,
  227. local->dot11MultipleRetryCount);
  228. DEBUGFS_STATS_ADD(frame_duplicate_count,
  229. local->dot11FrameDuplicateCount);
  230. DEBUGFS_STATS_ADD(received_fragment_count,
  231. local->dot11ReceivedFragmentCount);
  232. DEBUGFS_STATS_ADD(multicast_received_frame_count,
  233. local->dot11MulticastReceivedFrameCount);
  234. DEBUGFS_STATS_ADD(transmitted_frame_count,
  235. local->dot11TransmittedFrameCount);
  236. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  237. DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
  238. DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
  239. DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
  240. local->tx_handlers_drop_fragment);
  241. DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
  242. local->tx_handlers_drop_wep);
  243. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
  244. local->tx_handlers_drop_not_assoc);
  245. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
  246. local->tx_handlers_drop_unauth_port);
  247. DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
  248. DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
  249. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
  250. local->rx_handlers_drop_nullfunc);
  251. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
  252. local->rx_handlers_drop_defrag);
  253. DEBUGFS_STATS_ADD(rx_handlers_drop_short,
  254. local->rx_handlers_drop_short);
  255. DEBUGFS_STATS_ADD(tx_expand_skb_head,
  256. local->tx_expand_skb_head);
  257. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
  258. local->tx_expand_skb_head_cloned);
  259. DEBUGFS_STATS_ADD(rx_expand_skb_head,
  260. local->rx_expand_skb_head);
  261. DEBUGFS_STATS_ADD(rx_expand_skb_head2,
  262. local->rx_expand_skb_head2);
  263. DEBUGFS_STATS_ADD(rx_handlers_fragments,
  264. local->rx_handlers_fragments);
  265. DEBUGFS_STATS_ADD(tx_status_drop,
  266. local->tx_status_drop);
  267. #endif
  268. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  269. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  270. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  271. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  272. }