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. #undef FLAG
  185. };
  186. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  187. size_t count, loff_t *ppos)
  188. {
  189. struct ieee80211_local *local = file->private_data;
  190. size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
  191. char *buf = kzalloc(bufsz, GFP_KERNEL);
  192. char *pos = buf, *end = buf + bufsz - 1;
  193. ssize_t rv;
  194. int i;
  195. if (!buf)
  196. return -ENOMEM;
  197. /* fail compilation if somebody adds or removes
  198. * a flag without updating the name array above
  199. */
  200. BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
  201. for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
  202. if (test_bit(i, local->hw.flags))
  203. pos += scnprintf(pos, end - pos, "%s\n",
  204. hw_flag_names[i]);
  205. }
  206. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  207. kfree(buf);
  208. return rv;
  209. }
  210. static ssize_t queues_read(struct file *file, char __user *user_buf,
  211. size_t count, loff_t *ppos)
  212. {
  213. struct ieee80211_local *local = file->private_data;
  214. unsigned long flags;
  215. char buf[IEEE80211_MAX_QUEUES * 20];
  216. int q, res = 0;
  217. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  218. for (q = 0; q < local->hw.queues; q++)
  219. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  220. local->queue_stop_reasons[q],
  221. skb_queue_len(&local->pending[q]));
  222. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  223. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  224. }
  225. DEBUGFS_READONLY_FILE_OPS(hwflags);
  226. DEBUGFS_READONLY_FILE_OPS(queues);
  227. /* statistics stuff */
  228. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  229. char __user *userbuf,
  230. size_t count, loff_t *ppos,
  231. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  232. int buflen))
  233. {
  234. struct ieee80211_low_level_stats stats;
  235. char buf[20];
  236. int res;
  237. rtnl_lock();
  238. res = drv_get_stats(local, &stats);
  239. rtnl_unlock();
  240. if (res)
  241. return res;
  242. res = printvalue(&stats, buf, sizeof(buf));
  243. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  244. }
  245. #define DEBUGFS_DEVSTATS_FILE(name) \
  246. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  247. char *buf, int buflen) \
  248. { \
  249. return scnprintf(buf, buflen, "%u\n", stats->name); \
  250. } \
  251. static ssize_t stats_ ##name## _read(struct file *file, \
  252. char __user *userbuf, \
  253. size_t count, loff_t *ppos) \
  254. { \
  255. return format_devstat_counter(file->private_data, \
  256. userbuf, \
  257. count, \
  258. ppos, \
  259. print_devstats_##name); \
  260. } \
  261. \
  262. static const struct file_operations stats_ ##name## _ops = { \
  263. .read = stats_ ##name## _read, \
  264. .open = simple_open, \
  265. .llseek = generic_file_llseek, \
  266. };
  267. #define DEBUGFS_STATS_ADD(name) \
  268. debugfs_create_u32(#name, 0400, statsd, &local->name);
  269. #define DEBUGFS_DEVSTATS_ADD(name) \
  270. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  271. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  272. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  273. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  274. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  275. void debugfs_hw_add(struct ieee80211_local *local)
  276. {
  277. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  278. struct dentry *statsd;
  279. if (!phyd)
  280. return;
  281. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  282. DEBUGFS_ADD(total_ps_buffered);
  283. DEBUGFS_ADD(wep_iv);
  284. DEBUGFS_ADD(queues);
  285. #ifdef CONFIG_PM
  286. DEBUGFS_ADD_MODE(reset, 0200);
  287. #endif
  288. DEBUGFS_ADD(hwflags);
  289. DEBUGFS_ADD(user_power);
  290. DEBUGFS_ADD(power);
  291. if (local->ops->wake_tx_queue)
  292. DEBUGFS_ADD_MODE(aqm, 0600);
  293. statsd = debugfs_create_dir("statistics", phyd);
  294. /* if the dir failed, don't put all the other things into the root! */
  295. if (!statsd)
  296. return;
  297. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  298. DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
  299. DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
  300. DEBUGFS_STATS_ADD(dot11FailedCount);
  301. DEBUGFS_STATS_ADD(dot11RetryCount);
  302. DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
  303. DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
  304. DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
  305. DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
  306. DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
  307. DEBUGFS_STATS_ADD(tx_handlers_drop);
  308. DEBUGFS_STATS_ADD(tx_handlers_queued);
  309. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  310. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  311. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  312. DEBUGFS_STATS_ADD(rx_handlers_drop);
  313. DEBUGFS_STATS_ADD(rx_handlers_queued);
  314. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  315. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  316. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  317. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  318. DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
  319. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  320. DEBUGFS_STATS_ADD(tx_status_drop);
  321. #endif
  322. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  323. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  324. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  325. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  326. }