debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. int mac80211_open_file_generic(struct inode *inode, struct file *file)
  16. {
  17. file->private_data = inode->i_private;
  18. return 0;
  19. }
  20. #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
  21. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  22. size_t count, loff_t *ppos) \
  23. { \
  24. struct ieee80211_local *local = file->private_data; \
  25. char buf[buflen]; \
  26. int res; \
  27. \
  28. res = scnprintf(buf, buflen, fmt "\n", ##value); \
  29. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  30. } \
  31. \
  32. static const struct file_operations name## _ops = { \
  33. .read = name## _read, \
  34. .open = mac80211_open_file_generic, \
  35. };
  36. #define DEBUGFS_ADD(name) \
  37. local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
  38. local, &name## _ops);
  39. #define DEBUGFS_ADD_MODE(name, mode) \
  40. local->debugfs.name = debugfs_create_file(#name, mode, phyd, \
  41. local, &name## _ops);
  42. #define DEBUGFS_DEL(name) \
  43. debugfs_remove(local->debugfs.name); \
  44. local->debugfs.name = NULL;
  45. DEBUGFS_READONLY_FILE(frequency, 20, "%d",
  46. local->hw.conf.channel->center_freq);
  47. DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
  48. local->total_ps_buffered);
  49. DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
  50. local->wep_iv & 0xffffff);
  51. DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
  52. local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
  53. static ssize_t tsf_read(struct file *file, char __user *user_buf,
  54. size_t count, loff_t *ppos)
  55. {
  56. struct ieee80211_local *local = file->private_data;
  57. u64 tsf;
  58. char buf[100];
  59. tsf = drv_get_tsf(local);
  60. snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
  61. return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
  62. }
  63. static ssize_t tsf_write(struct file *file,
  64. const char __user *user_buf,
  65. size_t count, loff_t *ppos)
  66. {
  67. struct ieee80211_local *local = file->private_data;
  68. unsigned long long tsf;
  69. char buf[100];
  70. size_t len;
  71. len = min(count, sizeof(buf) - 1);
  72. if (copy_from_user(buf, user_buf, len))
  73. return -EFAULT;
  74. buf[len] = '\0';
  75. if (strncmp(buf, "reset", 5) == 0) {
  76. if (local->ops->reset_tsf) {
  77. drv_reset_tsf(local);
  78. printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
  79. }
  80. } else {
  81. tsf = simple_strtoul(buf, NULL, 0);
  82. if (local->ops->set_tsf) {
  83. drv_set_tsf(local, tsf);
  84. printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
  85. }
  86. }
  87. return count;
  88. }
  89. static const struct file_operations tsf_ops = {
  90. .read = tsf_read,
  91. .write = tsf_write,
  92. .open = mac80211_open_file_generic
  93. };
  94. static ssize_t reset_write(struct file *file, const char __user *user_buf,
  95. size_t count, loff_t *ppos)
  96. {
  97. struct ieee80211_local *local = file->private_data;
  98. rtnl_lock();
  99. __ieee80211_suspend(&local->hw);
  100. __ieee80211_resume(&local->hw);
  101. rtnl_unlock();
  102. return count;
  103. }
  104. static const struct file_operations reset_ops = {
  105. .write = reset_write,
  106. .open = mac80211_open_file_generic,
  107. };
  108. static ssize_t noack_read(struct file *file, char __user *user_buf,
  109. size_t count, loff_t *ppos)
  110. {
  111. struct ieee80211_local *local = file->private_data;
  112. int res;
  113. char buf[10];
  114. res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
  115. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  116. }
  117. static ssize_t noack_write(struct file *file,
  118. const char __user *user_buf,
  119. size_t count, loff_t *ppos)
  120. {
  121. struct ieee80211_local *local = file->private_data;
  122. char buf[10];
  123. size_t len;
  124. len = min(count, sizeof(buf) - 1);
  125. if (copy_from_user(buf, user_buf, len))
  126. return -EFAULT;
  127. buf[len] = '\0';
  128. local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
  129. return count;
  130. }
  131. static const struct file_operations noack_ops = {
  132. .read = noack_read,
  133. .write = noack_write,
  134. .open = mac80211_open_file_generic
  135. };
  136. static ssize_t queues_read(struct file *file, char __user *user_buf,
  137. size_t count, loff_t *ppos)
  138. {
  139. struct ieee80211_local *local = file->private_data;
  140. unsigned long flags;
  141. char buf[IEEE80211_MAX_QUEUES * 20];
  142. int q, res = 0;
  143. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  144. for (q = 0; q < local->hw.queues; q++)
  145. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  146. local->queue_stop_reasons[q],
  147. __netif_subqueue_stopped(local->mdev, q));
  148. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  149. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  150. }
  151. static const struct file_operations queues_ops = {
  152. .read = queues_read,
  153. .open = mac80211_open_file_generic
  154. };
  155. /* statistics stuff */
  156. #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
  157. DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
  158. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  159. char __user *userbuf,
  160. size_t count, loff_t *ppos,
  161. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  162. int buflen))
  163. {
  164. struct ieee80211_low_level_stats stats;
  165. char buf[20];
  166. int res;
  167. rtnl_lock();
  168. res = drv_get_stats(local, &stats);
  169. rtnl_unlock();
  170. if (res)
  171. return res;
  172. res = printvalue(&stats, buf, sizeof(buf));
  173. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  174. }
  175. #define DEBUGFS_DEVSTATS_FILE(name) \
  176. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  177. char *buf, int buflen) \
  178. { \
  179. return scnprintf(buf, buflen, "%u\n", stats->name); \
  180. } \
  181. static ssize_t stats_ ##name## _read(struct file *file, \
  182. char __user *userbuf, \
  183. size_t count, loff_t *ppos) \
  184. { \
  185. return format_devstat_counter(file->private_data, \
  186. userbuf, \
  187. count, \
  188. ppos, \
  189. print_devstats_##name); \
  190. } \
  191. \
  192. static const struct file_operations stats_ ##name## _ops = { \
  193. .read = stats_ ##name## _read, \
  194. .open = mac80211_open_file_generic, \
  195. };
  196. #define DEBUGFS_STATS_ADD(name) \
  197. local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
  198. local, &stats_ ##name## _ops);
  199. #define DEBUGFS_STATS_DEL(name) \
  200. debugfs_remove(local->debugfs.stats.name); \
  201. local->debugfs.stats.name = NULL;
  202. DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
  203. local->dot11TransmittedFragmentCount);
  204. DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
  205. local->dot11MulticastTransmittedFrameCount);
  206. DEBUGFS_STATS_FILE(failed_count, 20, "%u",
  207. local->dot11FailedCount);
  208. DEBUGFS_STATS_FILE(retry_count, 20, "%u",
  209. local->dot11RetryCount);
  210. DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
  211. local->dot11MultipleRetryCount);
  212. DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
  213. local->dot11FrameDuplicateCount);
  214. DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
  215. local->dot11ReceivedFragmentCount);
  216. DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
  217. local->dot11MulticastReceivedFrameCount);
  218. DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
  219. local->dot11TransmittedFrameCount);
  220. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  221. DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
  222. local->tx_handlers_drop);
  223. DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
  224. local->tx_handlers_queued);
  225. DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
  226. local->tx_handlers_drop_unencrypted);
  227. DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
  228. local->tx_handlers_drop_fragment);
  229. DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
  230. local->tx_handlers_drop_wep);
  231. DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
  232. local->tx_handlers_drop_not_assoc);
  233. DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
  234. local->tx_handlers_drop_unauth_port);
  235. DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
  236. local->rx_handlers_drop);
  237. DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
  238. local->rx_handlers_queued);
  239. DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
  240. local->rx_handlers_drop_nullfunc);
  241. DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
  242. local->rx_handlers_drop_defrag);
  243. DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
  244. local->rx_handlers_drop_short);
  245. DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
  246. local->rx_handlers_drop_passive_scan);
  247. DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
  248. local->tx_expand_skb_head);
  249. DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
  250. local->tx_expand_skb_head_cloned);
  251. DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
  252. local->rx_expand_skb_head);
  253. DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
  254. local->rx_expand_skb_head2);
  255. DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
  256. local->rx_handlers_fragments);
  257. DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
  258. local->tx_status_drop);
  259. #endif
  260. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  261. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  262. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  263. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  264. void debugfs_hw_add(struct ieee80211_local *local)
  265. {
  266. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  267. struct dentry *statsd;
  268. if (!phyd)
  269. return;
  270. local->debugfs.stations = debugfs_create_dir("stations", phyd);
  271. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  272. DEBUGFS_ADD(frequency);
  273. DEBUGFS_ADD(total_ps_buffered);
  274. DEBUGFS_ADD(wep_iv);
  275. DEBUGFS_ADD(tsf);
  276. DEBUGFS_ADD(queues);
  277. DEBUGFS_ADD_MODE(reset, 0200);
  278. DEBUGFS_ADD(noack);
  279. statsd = debugfs_create_dir("statistics", phyd);
  280. local->debugfs.statistics = statsd;
  281. /* if the dir failed, don't put all the other things into the root! */
  282. if (!statsd)
  283. return;
  284. DEBUGFS_STATS_ADD(transmitted_fragment_count);
  285. DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
  286. DEBUGFS_STATS_ADD(failed_count);
  287. DEBUGFS_STATS_ADD(retry_count);
  288. DEBUGFS_STATS_ADD(multiple_retry_count);
  289. DEBUGFS_STATS_ADD(frame_duplicate_count);
  290. DEBUGFS_STATS_ADD(received_fragment_count);
  291. DEBUGFS_STATS_ADD(multicast_received_frame_count);
  292. DEBUGFS_STATS_ADD(transmitted_frame_count);
  293. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  294. DEBUGFS_STATS_ADD(tx_handlers_drop);
  295. DEBUGFS_STATS_ADD(tx_handlers_queued);
  296. DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
  297. DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
  298. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  299. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  300. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  301. DEBUGFS_STATS_ADD(rx_handlers_drop);
  302. DEBUGFS_STATS_ADD(rx_handlers_queued);
  303. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  304. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  305. DEBUGFS_STATS_ADD(rx_handlers_drop_short);
  306. DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
  307. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  308. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  309. DEBUGFS_STATS_ADD(rx_expand_skb_head);
  310. DEBUGFS_STATS_ADD(rx_expand_skb_head2);
  311. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  312. DEBUGFS_STATS_ADD(tx_status_drop);
  313. #endif
  314. DEBUGFS_STATS_ADD(dot11ACKFailureCount);
  315. DEBUGFS_STATS_ADD(dot11RTSFailureCount);
  316. DEBUGFS_STATS_ADD(dot11FCSErrorCount);
  317. DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
  318. }
  319. void debugfs_hw_del(struct ieee80211_local *local)
  320. {
  321. DEBUGFS_DEL(frequency);
  322. DEBUGFS_DEL(total_ps_buffered);
  323. DEBUGFS_DEL(wep_iv);
  324. DEBUGFS_DEL(tsf);
  325. DEBUGFS_DEL(queues);
  326. DEBUGFS_DEL(reset);
  327. DEBUGFS_DEL(noack);
  328. DEBUGFS_STATS_DEL(transmitted_fragment_count);
  329. DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
  330. DEBUGFS_STATS_DEL(failed_count);
  331. DEBUGFS_STATS_DEL(retry_count);
  332. DEBUGFS_STATS_DEL(multiple_retry_count);
  333. DEBUGFS_STATS_DEL(frame_duplicate_count);
  334. DEBUGFS_STATS_DEL(received_fragment_count);
  335. DEBUGFS_STATS_DEL(multicast_received_frame_count);
  336. DEBUGFS_STATS_DEL(transmitted_frame_count);
  337. DEBUGFS_STATS_DEL(num_scans);
  338. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  339. DEBUGFS_STATS_DEL(tx_handlers_drop);
  340. DEBUGFS_STATS_DEL(tx_handlers_queued);
  341. DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
  342. DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
  343. DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
  344. DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
  345. DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
  346. DEBUGFS_STATS_DEL(rx_handlers_drop);
  347. DEBUGFS_STATS_DEL(rx_handlers_queued);
  348. DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
  349. DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
  350. DEBUGFS_STATS_DEL(rx_handlers_drop_short);
  351. DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
  352. DEBUGFS_STATS_DEL(tx_expand_skb_head);
  353. DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
  354. DEBUGFS_STATS_DEL(rx_expand_skb_head);
  355. DEBUGFS_STATS_DEL(rx_expand_skb_head2);
  356. DEBUGFS_STATS_DEL(rx_handlers_fragments);
  357. DEBUGFS_STATS_DEL(tx_status_drop);
  358. #endif
  359. DEBUGFS_STATS_DEL(dot11ACKFailureCount);
  360. DEBUGFS_STATS_DEL(dot11RTSFailureCount);
  361. DEBUGFS_STATS_DEL(dot11FCSErrorCount);
  362. DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
  363. debugfs_remove(local->debugfs.statistics);
  364. local->debugfs.statistics = NULL;
  365. debugfs_remove(local->debugfs.stations);
  366. local->debugfs.stations = NULL;
  367. debugfs_remove(local->debugfs.keys);
  368. local->debugfs.keys = NULL;
  369. }