debugfs.c 15 KB

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