debugfs.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 <linux/vmalloc.h>
  13. #include "ieee80211_i.h"
  14. #include "driver-ops.h"
  15. #include "rate.h"
  16. #include "debugfs.h"
  17. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  18. int mac80211_format_buffer(char __user *userbuf, size_t count,
  19. loff_t *ppos, char *fmt, ...)
  20. {
  21. va_list args;
  22. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  23. int res;
  24. va_start(args, fmt);
  25. res = vscnprintf(buf, sizeof(buf), fmt, args);
  26. va_end(args);
  27. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  28. }
  29. #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
  30. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  31. size_t count, loff_t *ppos) \
  32. { \
  33. struct ieee80211_local *local = file->private_data; \
  34. \
  35. return mac80211_format_buffer(userbuf, count, ppos, \
  36. fmt "\n", ##value); \
  37. }
  38. #define DEBUGFS_READONLY_FILE_OPS(name) \
  39. static const struct file_operations name## _ops = { \
  40. .read = name## _read, \
  41. .open = simple_open, \
  42. .llseek = generic_file_llseek, \
  43. };
  44. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  45. DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
  46. DEBUGFS_READONLY_FILE_OPS(name)
  47. #define DEBUGFS_ADD(name) \
  48. debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
  49. #define DEBUGFS_ADD_MODE(name, mode) \
  50. debugfs_create_file(#name, mode, phyd, local, &name## _ops);
  51. DEBUGFS_READONLY_FILE(user_power, "%d",
  52. local->user_power_level);
  53. DEBUGFS_READONLY_FILE(power, "%d",
  54. local->hw.conf.power_level);
  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 aqm_read(struct file *file,
  62. char __user *user_buf,
  63. size_t count,
  64. loff_t *ppos)
  65. {
  66. struct ieee80211_local *local = file->private_data;
  67. struct fq *fq = &local->fq;
  68. char buf[200];
  69. int len = 0;
  70. spin_lock_bh(&local->fq.lock);
  71. rcu_read_lock();
  72. len = scnprintf(buf, sizeof(buf),
  73. "access name value\n"
  74. "R fq_flows_cnt %u\n"
  75. "R fq_backlog %u\n"
  76. "R fq_overlimit %u\n"
  77. "R fq_overmemory %u\n"
  78. "R fq_collisions %u\n"
  79. "R fq_memory_usage %u\n"
  80. "RW fq_memory_limit %u\n"
  81. "RW fq_limit %u\n"
  82. "RW fq_quantum %u\n",
  83. fq->flows_cnt,
  84. fq->backlog,
  85. fq->overmemory,
  86. fq->overlimit,
  87. fq->collisions,
  88. fq->memory_usage,
  89. fq->memory_limit,
  90. fq->limit,
  91. fq->quantum);
  92. rcu_read_unlock();
  93. spin_unlock_bh(&local->fq.lock);
  94. return simple_read_from_buffer(user_buf, count, ppos,
  95. buf, len);
  96. }
  97. static ssize_t aqm_write(struct file *file,
  98. const char __user *user_buf,
  99. size_t count,
  100. loff_t *ppos)
  101. {
  102. struct ieee80211_local *local = file->private_data;
  103. char buf[100];
  104. size_t len;
  105. if (count > sizeof(buf))
  106. return -EINVAL;
  107. if (copy_from_user(buf, user_buf, count))
  108. return -EFAULT;
  109. buf[sizeof(buf) - 1] = '\0';
  110. len = strlen(buf);
  111. if (len > 0 && buf[len-1] == '\n')
  112. buf[len-1] = 0;
  113. if (sscanf(buf, "fq_limit %u", &local->fq.limit) == 1)
  114. return count;
  115. else if (sscanf(buf, "fq_memory_limit %u", &local->fq.memory_limit) == 1)
  116. return count;
  117. else if (sscanf(buf, "fq_quantum %u", &local->fq.quantum) == 1)
  118. return count;
  119. return -EINVAL;
  120. }
  121. static const struct file_operations aqm_ops = {
  122. .write = aqm_write,
  123. .read = aqm_read,
  124. .open = simple_open,
  125. .llseek = default_llseek,
  126. };
  127. #ifdef CONFIG_PM
  128. static ssize_t reset_write(struct file *file, const char __user *user_buf,
  129. size_t count, loff_t *ppos)
  130. {
  131. struct ieee80211_local *local = file->private_data;
  132. rtnl_lock();
  133. __ieee80211_suspend(&local->hw, NULL);
  134. __ieee80211_resume(&local->hw);
  135. rtnl_unlock();
  136. return count;
  137. }
  138. static const struct file_operations reset_ops = {
  139. .write = reset_write,
  140. .open = simple_open,
  141. .llseek = noop_llseek,
  142. };
  143. #endif
  144. static const char *hw_flag_names[] = {
  145. #define FLAG(F) [IEEE80211_HW_##F] = #F
  146. FLAG(HAS_RATE_CONTROL),
  147. FLAG(RX_INCLUDES_FCS),
  148. FLAG(HOST_BROADCAST_PS_BUFFERING),
  149. FLAG(SIGNAL_UNSPEC),
  150. FLAG(SIGNAL_DBM),
  151. FLAG(NEED_DTIM_BEFORE_ASSOC),
  152. FLAG(SPECTRUM_MGMT),
  153. FLAG(AMPDU_AGGREGATION),
  154. FLAG(SUPPORTS_PS),
  155. FLAG(PS_NULLFUNC_STACK),
  156. FLAG(SUPPORTS_DYNAMIC_PS),
  157. FLAG(MFP_CAPABLE),
  158. FLAG(WANT_MONITOR_VIF),
  159. FLAG(NO_AUTO_VIF),
  160. FLAG(SW_CRYPTO_CONTROL),
  161. FLAG(SUPPORT_FAST_XMIT),
  162. FLAG(REPORTS_TX_ACK_STATUS),
  163. FLAG(CONNECTION_MONITOR),
  164. FLAG(QUEUE_CONTROL),
  165. FLAG(SUPPORTS_PER_STA_GTK),
  166. FLAG(AP_LINK_PS),
  167. FLAG(TX_AMPDU_SETUP_IN_HW),
  168. FLAG(SUPPORTS_RC_TABLE),
  169. FLAG(P2P_DEV_ADDR_FOR_INTF),
  170. FLAG(TIMING_BEACON_ONLY),
  171. FLAG(SUPPORTS_HT_CCK_RATES),
  172. FLAG(CHANCTX_STA_CSA),
  173. FLAG(SUPPORTS_CLONED_SKBS),
  174. FLAG(SINGLE_SCAN_ON_ALL_BANDS),
  175. FLAG(TDLS_WIDER_BW),
  176. FLAG(SUPPORTS_AMSDU_IN_AMPDU),
  177. FLAG(BEACON_TX_STATUS),
  178. FLAG(NEEDS_UNIQUE_STA_ADDR),
  179. FLAG(SUPPORTS_REORDERING_BUFFER),
  180. FLAG(USES_RSS),
  181. FLAG(TX_AMSDU),
  182. FLAG(TX_FRAG_LIST),
  183. FLAG(REPORTS_LOW_ACK),
  184. FLAG(SUPPORTS_TX_FRAG),
  185. #undef FLAG
  186. };
  187. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  188. size_t count, loff_t *ppos)
  189. {
  190. struct ieee80211_local *local = file->private_data;
  191. size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
  192. char *buf = kzalloc(bufsz, GFP_KERNEL);
  193. char *pos = buf, *end = buf + bufsz - 1;
  194. ssize_t rv;
  195. int i;
  196. if (!buf)
  197. return -ENOMEM;
  198. /* fail compilation if somebody adds or removes
  199. * a flag without updating the name array above
  200. */
  201. BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
  202. for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
  203. if (test_bit(i, local->hw.flags))
  204. pos += scnprintf(pos, end - pos, "%s\n",
  205. hw_flag_names[i]);
  206. }
  207. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  208. kfree(buf);
  209. return rv;
  210. }
  211. static ssize_t queues_read(struct file *file, char __user *user_buf,
  212. size_t count, loff_t *ppos)
  213. {
  214. struct ieee80211_local *local = file->private_data;
  215. unsigned long flags;
  216. char buf[IEEE80211_MAX_QUEUES * 20];
  217. int q, res = 0;
  218. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  219. for (q = 0; q < local->hw.queues; q++)
  220. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  221. local->queue_stop_reasons[q],
  222. skb_queue_len(&local->pending[q]));
  223. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  224. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  225. }
  226. DEBUGFS_READONLY_FILE_OPS(hwflags);
  227. DEBUGFS_READONLY_FILE_OPS(queues);
  228. /* statistics stuff */
  229. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  230. char __user *userbuf,
  231. size_t count, loff_t *ppos,
  232. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  233. int buflen))
  234. {
  235. struct ieee80211_low_level_stats stats;
  236. char buf[20];
  237. int res;
  238. rtnl_lock();
  239. res = drv_get_stats(local, &stats);
  240. rtnl_unlock();
  241. if (res)
  242. return res;
  243. res = printvalue(&stats, buf, sizeof(buf));
  244. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  245. }
  246. #define DEBUGFS_DEVSTATS_FILE(name) \
  247. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  248. char *buf, int buflen) \
  249. { \
  250. return scnprintf(buf, buflen, "%u\n", stats->name); \
  251. } \
  252. static ssize_t stats_ ##name## _read(struct file *file, \
  253. char __user *userbuf, \
  254. size_t count, loff_t *ppos) \
  255. { \
  256. return format_devstat_counter(file->private_data, \
  257. userbuf, \
  258. count, \
  259. ppos, \
  260. print_devstats_##name); \
  261. } \
  262. \
  263. static const struct file_operations stats_ ##name## _ops = { \
  264. .read = stats_ ##name## _read, \
  265. .open = simple_open, \
  266. .llseek = generic_file_llseek, \
  267. };
  268. #define DEBUGFS_STATS_ADD(name) \
  269. debugfs_create_u32(#name, 0400, statsd, &local->name);
  270. #define DEBUGFS_DEVSTATS_ADD(name) \
  271. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  272. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  273. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  274. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  275. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  276. void debugfs_hw_add(struct ieee80211_local *local)
  277. {
  278. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  279. struct dentry *statsd;
  280. if (!phyd)
  281. return;
  282. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  283. DEBUGFS_ADD(total_ps_buffered);
  284. DEBUGFS_ADD(wep_iv);
  285. DEBUGFS_ADD(queues);
  286. #ifdef CONFIG_PM
  287. DEBUGFS_ADD_MODE(reset, 0200);
  288. #endif
  289. DEBUGFS_ADD(hwflags);
  290. DEBUGFS_ADD(user_power);
  291. DEBUGFS_ADD(power);
  292. if (local->ops->wake_tx_queue)
  293. DEBUGFS_ADD_MODE(aqm, 0600);
  294. statsd = debugfs_create_dir("statistics", phyd);
  295. /* if the dir failed, don't put all the other things into the root! */
  296. if (!statsd)
  297. return;
  298. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  299. DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
  300. DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
  301. DEBUGFS_STATS_ADD(dot11FailedCount);
  302. DEBUGFS_STATS_ADD(dot11RetryCount);
  303. DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
  304. DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
  305. DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
  306. DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
  307. DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
  308. DEBUGFS_STATS_ADD(tx_handlers_drop);
  309. DEBUGFS_STATS_ADD(tx_handlers_queued);
  310. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  311. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  312. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  313. DEBUGFS_STATS_ADD(rx_handlers_drop);
  314. DEBUGFS_STATS_ADD(rx_handlers_queued);
  315. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  316. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  317. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  318. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  319. DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
  320. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  321. DEBUGFS_STATS_ADD(tx_status_drop);
  322. #endif
  323. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  324. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  325. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  326. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  327. }