debugfs.c 11 KB

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