debugfs.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  16. int mac80211_format_buffer(char __user *userbuf, size_t count,
  17. loff_t *ppos, char *fmt, ...)
  18. {
  19. va_list args;
  20. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  21. int res;
  22. va_start(args, fmt);
  23. res = vscnprintf(buf, sizeof(buf), fmt, args);
  24. va_end(args);
  25. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  26. }
  27. #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
  28. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  29. size_t count, loff_t *ppos) \
  30. { \
  31. struct ieee80211_local *local = file->private_data; \
  32. \
  33. return mac80211_format_buffer(userbuf, count, ppos, \
  34. fmt "\n", ##value); \
  35. }
  36. #define DEBUGFS_READONLY_FILE_OPS(name) \
  37. static const struct file_operations name## _ops = { \
  38. .read = name## _read, \
  39. .open = simple_open, \
  40. .llseek = generic_file_llseek, \
  41. };
  42. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  43. DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
  44. DEBUGFS_READONLY_FILE_OPS(name)
  45. #define DEBUGFS_ADD(name) \
  46. debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
  47. #define DEBUGFS_ADD_MODE(name, mode) \
  48. debugfs_create_file(#name, mode, phyd, local, &name## _ops);
  49. DEBUGFS_READONLY_FILE(user_power, "%d",
  50. local->user_power_level);
  51. DEBUGFS_READONLY_FILE(power, "%d",
  52. local->hw.conf.power_level);
  53. DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
  54. local->total_ps_buffered);
  55. DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
  56. local->wep_iv & 0xffffff);
  57. DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
  58. local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
  59. #ifdef CONFIG_PM
  60. static ssize_t reset_write(struct file *file, const char __user *user_buf,
  61. size_t count, loff_t *ppos)
  62. {
  63. struct ieee80211_local *local = file->private_data;
  64. rtnl_lock();
  65. __ieee80211_suspend(&local->hw, NULL);
  66. __ieee80211_resume(&local->hw);
  67. rtnl_unlock();
  68. return count;
  69. }
  70. static const struct file_operations reset_ops = {
  71. .write = reset_write,
  72. .open = simple_open,
  73. .llseek = noop_llseek,
  74. };
  75. #endif
  76. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  77. size_t count, loff_t *ppos)
  78. {
  79. struct ieee80211_local *local = file->private_data;
  80. int mxln = 500;
  81. ssize_t rv;
  82. char *buf = kzalloc(mxln, GFP_KERNEL);
  83. int sf = 0; /* how many written so far */
  84. if (!buf)
  85. return 0;
  86. sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
  87. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  88. sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
  89. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  90. sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
  91. if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
  92. sf += scnprintf(buf + sf, mxln - sf,
  93. "HOST_BCAST_PS_BUFFERING\n");
  94. if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
  95. sf += scnprintf(buf + sf, mxln - sf,
  96. "2GHZ_SHORT_SLOT_INCAPABLE\n");
  97. if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
  98. sf += scnprintf(buf + sf, mxln - sf,
  99. "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
  100. if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
  101. sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
  102. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  103. sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
  104. if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
  105. sf += scnprintf(buf + sf, mxln - sf,
  106. "NEED_DTIM_BEFORE_ASSOC\n");
  107. if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
  108. sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
  109. if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
  110. sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
  111. if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
  112. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
  113. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  114. sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
  115. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  116. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
  117. if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
  118. sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
  119. if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
  120. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
  121. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
  122. sf += scnprintf(buf + sf, mxln - sf,
  123. "SUPPORTS_DYNAMIC_SMPS\n");
  124. if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
  125. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
  126. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  127. sf += scnprintf(buf + sf, mxln - sf,
  128. "REPORTS_TX_ACK_STATUS\n");
  129. if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  130. sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
  131. if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
  132. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
  133. if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  134. sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
  135. if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
  136. sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
  137. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  138. kfree(buf);
  139. return rv;
  140. }
  141. static ssize_t queues_read(struct file *file, char __user *user_buf,
  142. size_t count, loff_t *ppos)
  143. {
  144. struct ieee80211_local *local = file->private_data;
  145. unsigned long flags;
  146. char buf[IEEE80211_MAX_QUEUES * 20];
  147. int q, res = 0;
  148. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  149. for (q = 0; q < local->hw.queues; q++)
  150. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  151. local->queue_stop_reasons[q],
  152. skb_queue_len(&local->pending[q]));
  153. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  154. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  155. }
  156. DEBUGFS_READONLY_FILE_OPS(hwflags);
  157. DEBUGFS_READONLY_FILE_OPS(queues);
  158. /* statistics stuff */
  159. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  160. char __user *userbuf,
  161. size_t count, loff_t *ppos,
  162. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  163. int buflen))
  164. {
  165. struct ieee80211_low_level_stats stats;
  166. char buf[20];
  167. int res;
  168. rtnl_lock();
  169. res = drv_get_stats(local, &stats);
  170. rtnl_unlock();
  171. if (res)
  172. return res;
  173. res = printvalue(&stats, buf, sizeof(buf));
  174. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  175. }
  176. #define DEBUGFS_DEVSTATS_FILE(name) \
  177. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  178. char *buf, int buflen) \
  179. { \
  180. return scnprintf(buf, buflen, "%u\n", stats->name); \
  181. } \
  182. static ssize_t stats_ ##name## _read(struct file *file, \
  183. char __user *userbuf, \
  184. size_t count, loff_t *ppos) \
  185. { \
  186. return format_devstat_counter(file->private_data, \
  187. userbuf, \
  188. count, \
  189. ppos, \
  190. print_devstats_##name); \
  191. } \
  192. \
  193. static const struct file_operations stats_ ##name## _ops = { \
  194. .read = stats_ ##name## _read, \
  195. .open = simple_open, \
  196. .llseek = generic_file_llseek, \
  197. };
  198. #define DEBUGFS_STATS_ADD(name, field) \
  199. debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
  200. #define DEBUGFS_DEVSTATS_ADD(name) \
  201. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  202. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  203. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  204. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  205. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  206. void debugfs_hw_add(struct ieee80211_local *local)
  207. {
  208. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  209. struct dentry *statsd;
  210. if (!phyd)
  211. return;
  212. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  213. DEBUGFS_ADD(total_ps_buffered);
  214. DEBUGFS_ADD(wep_iv);
  215. DEBUGFS_ADD(queues);
  216. #ifdef CONFIG_PM
  217. DEBUGFS_ADD_MODE(reset, 0200);
  218. #endif
  219. DEBUGFS_ADD(hwflags);
  220. DEBUGFS_ADD(user_power);
  221. DEBUGFS_ADD(power);
  222. statsd = debugfs_create_dir("statistics", phyd);
  223. /* if the dir failed, don't put all the other things into the root! */
  224. if (!statsd)
  225. return;
  226. DEBUGFS_STATS_ADD(transmitted_fragment_count,
  227. local->dot11TransmittedFragmentCount);
  228. DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
  229. local->dot11MulticastTransmittedFrameCount);
  230. DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
  231. DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
  232. DEBUGFS_STATS_ADD(multiple_retry_count,
  233. local->dot11MultipleRetryCount);
  234. DEBUGFS_STATS_ADD(frame_duplicate_count,
  235. local->dot11FrameDuplicateCount);
  236. DEBUGFS_STATS_ADD(received_fragment_count,
  237. local->dot11ReceivedFragmentCount);
  238. DEBUGFS_STATS_ADD(multicast_received_frame_count,
  239. local->dot11MulticastReceivedFrameCount);
  240. DEBUGFS_STATS_ADD(transmitted_frame_count,
  241. local->dot11TransmittedFrameCount);
  242. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  243. DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
  244. DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
  245. DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
  246. local->tx_handlers_drop_unencrypted);
  247. DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
  248. local->tx_handlers_drop_fragment);
  249. DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
  250. local->tx_handlers_drop_wep);
  251. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
  252. local->tx_handlers_drop_not_assoc);
  253. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
  254. local->tx_handlers_drop_unauth_port);
  255. DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
  256. DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
  257. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
  258. local->rx_handlers_drop_nullfunc);
  259. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
  260. local->rx_handlers_drop_defrag);
  261. DEBUGFS_STATS_ADD(rx_handlers_drop_short,
  262. local->rx_handlers_drop_short);
  263. DEBUGFS_STATS_ADD(tx_expand_skb_head,
  264. local->tx_expand_skb_head);
  265. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
  266. local->tx_expand_skb_head_cloned);
  267. DEBUGFS_STATS_ADD(rx_expand_skb_head,
  268. local->rx_expand_skb_head);
  269. DEBUGFS_STATS_ADD(rx_expand_skb_head2,
  270. local->rx_expand_skb_head2);
  271. DEBUGFS_STATS_ADD(rx_handlers_fragments,
  272. local->rx_handlers_fragments);
  273. DEBUGFS_STATS_ADD(tx_status_drop,
  274. local->tx_status_drop);
  275. #endif
  276. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  277. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  278. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  279. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  280. }