debugfs.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. #define TX_LATENCY_BIN_DELIMTER_C ','
  18. #define TX_LATENCY_BIN_DELIMTER_S ","
  19. #define TX_LATENCY_BINS_DISABLED "enable(bins disabled)\n"
  20. #define TX_LATENCY_DISABLED "disable\n"
  21. /*
  22. * Display if Tx latency statistics & bins are enabled/disabled
  23. */
  24. static ssize_t sta_tx_latency_stat_read(struct file *file,
  25. char __user *userbuf,
  26. size_t count, loff_t *ppos)
  27. {
  28. struct ieee80211_local *local = file->private_data;
  29. struct ieee80211_tx_latency_bin_ranges *tx_latency;
  30. char *buf;
  31. int bufsz, i, ret;
  32. int pos = 0;
  33. rcu_read_lock();
  34. tx_latency = rcu_dereference(local->tx_latency);
  35. if (tx_latency && tx_latency->n_ranges) {
  36. bufsz = tx_latency->n_ranges * 15;
  37. buf = kzalloc(bufsz, GFP_ATOMIC);
  38. if (!buf)
  39. goto err;
  40. for (i = 0; i < tx_latency->n_ranges; i++)
  41. pos += scnprintf(buf + pos, bufsz - pos, "%d,",
  42. tx_latency->ranges[i]);
  43. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  44. } else if (tx_latency) {
  45. bufsz = sizeof(TX_LATENCY_BINS_DISABLED) + 1;
  46. buf = kzalloc(bufsz, GFP_ATOMIC);
  47. if (!buf)
  48. goto err;
  49. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  50. TX_LATENCY_BINS_DISABLED);
  51. } else {
  52. bufsz = sizeof(TX_LATENCY_DISABLED) + 1;
  53. buf = kzalloc(bufsz, GFP_ATOMIC);
  54. if (!buf)
  55. goto err;
  56. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  57. TX_LATENCY_DISABLED);
  58. }
  59. rcu_read_unlock();
  60. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  61. kfree(buf);
  62. return ret;
  63. err:
  64. rcu_read_unlock();
  65. return -ENOMEM;
  66. }
  67. /*
  68. * Receive input from user regarding Tx latency statistics
  69. * The input should indicate if Tx latency statistics and bins are
  70. * enabled/disabled.
  71. * If bins are enabled input should indicate the amount of different bins and
  72. * their ranges. Each bin will count how many Tx frames transmitted within the
  73. * appropriate latency.
  74. * Legal input is:
  75. * a) "enable(bins disabled)" - to enable only general statistics
  76. * b) "a,b,c,d,...z" - to enable general statistics and bins, where all are
  77. * numbers and a < b < c < d.. < z
  78. * c) "disable" - disable all statistics
  79. * NOTE: must configure Tx latency statistics bins before stations connected.
  80. */
  81. static ssize_t sta_tx_latency_stat_write(struct file *file,
  82. const char __user *userbuf,
  83. size_t count, loff_t *ppos)
  84. {
  85. struct ieee80211_local *local = file->private_data;
  86. char buf[128] = {};
  87. char *bins = buf;
  88. char *token;
  89. int buf_size, i, alloc_size;
  90. int prev_bin = 0;
  91. int n_ranges = 0;
  92. int ret = count;
  93. struct ieee80211_tx_latency_bin_ranges *tx_latency;
  94. if (sizeof(buf) <= count)
  95. return -EINVAL;
  96. buf_size = count;
  97. if (copy_from_user(buf, userbuf, buf_size))
  98. return -EFAULT;
  99. mutex_lock(&local->sta_mtx);
  100. /* cannot change config once we have stations */
  101. if (local->num_sta)
  102. goto unlock;
  103. tx_latency =
  104. rcu_dereference_protected(local->tx_latency,
  105. lockdep_is_held(&local->sta_mtx));
  106. /* disable Tx statistics */
  107. if (!strcmp(buf, TX_LATENCY_DISABLED)) {
  108. if (!tx_latency)
  109. goto unlock;
  110. RCU_INIT_POINTER(local->tx_latency, NULL);
  111. synchronize_rcu();
  112. kfree(tx_latency);
  113. goto unlock;
  114. }
  115. /* Tx latency already enabled */
  116. if (tx_latency)
  117. goto unlock;
  118. if (strcmp(TX_LATENCY_BINS_DISABLED, buf)) {
  119. /* check how many bins and between what ranges user requested */
  120. token = buf;
  121. while (*token != '\0') {
  122. if (*token == TX_LATENCY_BIN_DELIMTER_C)
  123. n_ranges++;
  124. token++;
  125. }
  126. n_ranges++;
  127. }
  128. alloc_size = sizeof(struct ieee80211_tx_latency_bin_ranges) +
  129. n_ranges * sizeof(u32);
  130. tx_latency = kzalloc(alloc_size, GFP_ATOMIC);
  131. if (!tx_latency) {
  132. ret = -ENOMEM;
  133. goto unlock;
  134. }
  135. tx_latency->n_ranges = n_ranges;
  136. for (i = 0; i < n_ranges; i++) { /* setting bin ranges */
  137. token = strsep(&bins, TX_LATENCY_BIN_DELIMTER_S);
  138. sscanf(token, "%d", &tx_latency->ranges[i]);
  139. /* bins values should be in ascending order */
  140. if (prev_bin >= tx_latency->ranges[i]) {
  141. ret = -EINVAL;
  142. kfree(tx_latency);
  143. goto unlock;
  144. }
  145. prev_bin = tx_latency->ranges[i];
  146. }
  147. rcu_assign_pointer(local->tx_latency, tx_latency);
  148. unlock:
  149. mutex_unlock(&local->sta_mtx);
  150. return ret;
  151. }
  152. static const struct file_operations stats_tx_latency_ops = {
  153. .write = sta_tx_latency_stat_write,
  154. .read = sta_tx_latency_stat_read,
  155. .open = simple_open,
  156. .llseek = generic_file_llseek,
  157. };
  158. int mac80211_format_buffer(char __user *userbuf, size_t count,
  159. loff_t *ppos, char *fmt, ...)
  160. {
  161. va_list args;
  162. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  163. int res;
  164. va_start(args, fmt);
  165. res = vscnprintf(buf, sizeof(buf), fmt, args);
  166. va_end(args);
  167. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  168. }
  169. #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
  170. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  171. size_t count, loff_t *ppos) \
  172. { \
  173. struct ieee80211_local *local = file->private_data; \
  174. \
  175. return mac80211_format_buffer(userbuf, count, ppos, \
  176. fmt "\n", ##value); \
  177. }
  178. #define DEBUGFS_READONLY_FILE_OPS(name) \
  179. static const struct file_operations name## _ops = { \
  180. .read = name## _read, \
  181. .open = simple_open, \
  182. .llseek = generic_file_llseek, \
  183. };
  184. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  185. DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
  186. DEBUGFS_READONLY_FILE_OPS(name)
  187. #define DEBUGFS_ADD(name) \
  188. debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
  189. #define DEBUGFS_ADD_MODE(name, mode) \
  190. debugfs_create_file(#name, mode, phyd, local, &name## _ops);
  191. DEBUGFS_READONLY_FILE(user_power, "%d",
  192. local->user_power_level);
  193. DEBUGFS_READONLY_FILE(power, "%d",
  194. local->hw.conf.power_level);
  195. DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
  196. local->total_ps_buffered);
  197. DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
  198. local->wep_iv & 0xffffff);
  199. DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
  200. local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
  201. #ifdef CONFIG_PM
  202. static ssize_t reset_write(struct file *file, const char __user *user_buf,
  203. size_t count, loff_t *ppos)
  204. {
  205. struct ieee80211_local *local = file->private_data;
  206. rtnl_lock();
  207. __ieee80211_suspend(&local->hw, NULL);
  208. __ieee80211_resume(&local->hw);
  209. rtnl_unlock();
  210. return count;
  211. }
  212. static const struct file_operations reset_ops = {
  213. .write = reset_write,
  214. .open = simple_open,
  215. .llseek = noop_llseek,
  216. };
  217. #endif
  218. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  219. size_t count, loff_t *ppos)
  220. {
  221. struct ieee80211_local *local = file->private_data;
  222. int mxln = 500;
  223. ssize_t rv;
  224. char *buf = kzalloc(mxln, GFP_KERNEL);
  225. int sf = 0; /* how many written so far */
  226. if (!buf)
  227. return 0;
  228. sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
  229. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  230. sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
  231. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  232. sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
  233. if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
  234. sf += scnprintf(buf + sf, mxln - sf,
  235. "HOST_BCAST_PS_BUFFERING\n");
  236. if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
  237. sf += scnprintf(buf + sf, mxln - sf,
  238. "2GHZ_SHORT_SLOT_INCAPABLE\n");
  239. if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
  240. sf += scnprintf(buf + sf, mxln - sf,
  241. "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
  242. if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
  243. sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
  244. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  245. sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
  246. if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
  247. sf += scnprintf(buf + sf, mxln - sf,
  248. "NEED_DTIM_BEFORE_ASSOC\n");
  249. if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
  250. sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
  251. if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
  252. sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
  253. if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
  254. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
  255. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  256. sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
  257. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  258. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
  259. if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
  260. sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
  261. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  262. sf += scnprintf(buf + sf, mxln - sf,
  263. "REPORTS_TX_ACK_STATUS\n");
  264. if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  265. sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
  266. if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
  267. sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
  268. if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  269. sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
  270. if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
  271. sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
  272. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  273. kfree(buf);
  274. return rv;
  275. }
  276. static ssize_t queues_read(struct file *file, char __user *user_buf,
  277. size_t count, loff_t *ppos)
  278. {
  279. struct ieee80211_local *local = file->private_data;
  280. unsigned long flags;
  281. char buf[IEEE80211_MAX_QUEUES * 20];
  282. int q, res = 0;
  283. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  284. for (q = 0; q < local->hw.queues; q++)
  285. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  286. local->queue_stop_reasons[q],
  287. skb_queue_len(&local->pending[q]));
  288. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  289. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  290. }
  291. DEBUGFS_READONLY_FILE_OPS(hwflags);
  292. DEBUGFS_READONLY_FILE_OPS(queues);
  293. /* statistics stuff */
  294. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  295. char __user *userbuf,
  296. size_t count, loff_t *ppos,
  297. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  298. int buflen))
  299. {
  300. struct ieee80211_low_level_stats stats;
  301. char buf[20];
  302. int res;
  303. rtnl_lock();
  304. res = drv_get_stats(local, &stats);
  305. rtnl_unlock();
  306. if (res)
  307. return res;
  308. res = printvalue(&stats, buf, sizeof(buf));
  309. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  310. }
  311. #define DEBUGFS_DEVSTATS_FILE(name) \
  312. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  313. char *buf, int buflen) \
  314. { \
  315. return scnprintf(buf, buflen, "%u\n", stats->name); \
  316. } \
  317. static ssize_t stats_ ##name## _read(struct file *file, \
  318. char __user *userbuf, \
  319. size_t count, loff_t *ppos) \
  320. { \
  321. return format_devstat_counter(file->private_data, \
  322. userbuf, \
  323. count, \
  324. ppos, \
  325. print_devstats_##name); \
  326. } \
  327. \
  328. static const struct file_operations stats_ ##name## _ops = { \
  329. .read = stats_ ##name## _read, \
  330. .open = simple_open, \
  331. .llseek = generic_file_llseek, \
  332. };
  333. #define DEBUGFS_STATS_ADD(name, field) \
  334. debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
  335. #define DEBUGFS_DEVSTATS_ADD(name) \
  336. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  337. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  338. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  339. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  340. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  341. void debugfs_hw_add(struct ieee80211_local *local)
  342. {
  343. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  344. struct dentry *statsd;
  345. if (!phyd)
  346. return;
  347. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  348. DEBUGFS_ADD(total_ps_buffered);
  349. DEBUGFS_ADD(wep_iv);
  350. DEBUGFS_ADD(queues);
  351. #ifdef CONFIG_PM
  352. DEBUGFS_ADD_MODE(reset, 0200);
  353. #endif
  354. DEBUGFS_ADD(hwflags);
  355. DEBUGFS_ADD(user_power);
  356. DEBUGFS_ADD(power);
  357. statsd = debugfs_create_dir("statistics", phyd);
  358. /* if the dir failed, don't put all the other things into the root! */
  359. if (!statsd)
  360. return;
  361. DEBUGFS_STATS_ADD(transmitted_fragment_count,
  362. local->dot11TransmittedFragmentCount);
  363. DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
  364. local->dot11MulticastTransmittedFrameCount);
  365. DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
  366. DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
  367. DEBUGFS_STATS_ADD(multiple_retry_count,
  368. local->dot11MultipleRetryCount);
  369. DEBUGFS_STATS_ADD(frame_duplicate_count,
  370. local->dot11FrameDuplicateCount);
  371. DEBUGFS_STATS_ADD(received_fragment_count,
  372. local->dot11ReceivedFragmentCount);
  373. DEBUGFS_STATS_ADD(multicast_received_frame_count,
  374. local->dot11MulticastReceivedFrameCount);
  375. DEBUGFS_STATS_ADD(transmitted_frame_count,
  376. local->dot11TransmittedFrameCount);
  377. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  378. DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
  379. DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
  380. DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
  381. local->tx_handlers_drop_unencrypted);
  382. DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
  383. local->tx_handlers_drop_fragment);
  384. DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
  385. local->tx_handlers_drop_wep);
  386. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
  387. local->tx_handlers_drop_not_assoc);
  388. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
  389. local->tx_handlers_drop_unauth_port);
  390. DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
  391. DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
  392. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
  393. local->rx_handlers_drop_nullfunc);
  394. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
  395. local->rx_handlers_drop_defrag);
  396. DEBUGFS_STATS_ADD(rx_handlers_drop_short,
  397. local->rx_handlers_drop_short);
  398. DEBUGFS_STATS_ADD(tx_expand_skb_head,
  399. local->tx_expand_skb_head);
  400. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
  401. local->tx_expand_skb_head_cloned);
  402. DEBUGFS_STATS_ADD(rx_expand_skb_head,
  403. local->rx_expand_skb_head);
  404. DEBUGFS_STATS_ADD(rx_expand_skb_head2,
  405. local->rx_expand_skb_head2);
  406. DEBUGFS_STATS_ADD(rx_handlers_fragments,
  407. local->rx_handlers_fragments);
  408. DEBUGFS_STATS_ADD(tx_status_drop,
  409. local->tx_status_drop);
  410. #endif
  411. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  412. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  413. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  414. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  415. DEBUGFS_DEVSTATS_ADD(tx_latency);
  416. }