debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 "ieee80211_rate.h"
  13. #include "debugfs.h"
  14. int mac80211_open_file_generic(struct inode *inode, struct file *file)
  15. {
  16. file->private_data = inode->i_private;
  17. return 0;
  18. }
  19. static const char *ieee80211_mode_str(int mode)
  20. {
  21. switch (mode) {
  22. case MODE_IEEE80211A:
  23. return "IEEE 802.11a";
  24. case MODE_IEEE80211B:
  25. return "IEEE 802.11b";
  26. case MODE_IEEE80211G:
  27. return "IEEE 802.11g";
  28. default:
  29. return "UNKNOWN";
  30. }
  31. }
  32. static ssize_t modes_read(struct file *file, char __user *userbuf,
  33. size_t count, loff_t *ppos)
  34. {
  35. struct ieee80211_local *local = file->private_data;
  36. struct ieee80211_hw_mode *mode;
  37. char buf[150], *p = buf;
  38. /* FIXME: locking! */
  39. list_for_each_entry(mode, &local->modes_list, list) {
  40. p += scnprintf(p, sizeof(buf)+buf-p,
  41. "%s\n", ieee80211_mode_str(mode->mode));
  42. }
  43. return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
  44. }
  45. static const struct file_operations modes_ops = {
  46. .read = modes_read,
  47. .open = mac80211_open_file_generic,
  48. };
  49. #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
  50. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  51. size_t count, loff_t *ppos) \
  52. { \
  53. struct ieee80211_local *local = file->private_data; \
  54. char buf[buflen]; \
  55. int res; \
  56. \
  57. res = scnprintf(buf, buflen, fmt "\n", ##value); \
  58. return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
  59. } \
  60. \
  61. static const struct file_operations name## _ops = { \
  62. .read = name## _read, \
  63. .open = mac80211_open_file_generic, \
  64. };
  65. #define DEBUGFS_ADD(name) \
  66. local->debugfs.name = debugfs_create_file(#name, 0444, phyd, \
  67. local, &name## _ops);
  68. #define DEBUGFS_DEL(name) \
  69. debugfs_remove(local->debugfs.name); \
  70. local->debugfs.name = NULL;
  71. DEBUGFS_READONLY_FILE(channel, 20, "%d",
  72. local->hw.conf.channel);
  73. DEBUGFS_READONLY_FILE(frequency, 20, "%d",
  74. local->hw.conf.freq);
  75. DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
  76. local->hw.conf.antenna_sel_tx);
  77. DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
  78. local->hw.conf.antenna_sel_rx);
  79. DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
  80. local->bridge_packets);
  81. DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
  82. local->rts_threshold);
  83. DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
  84. local->fragmentation_threshold);
  85. DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
  86. local->short_retry_limit);
  87. DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
  88. local->long_retry_limit);
  89. DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
  90. local->total_ps_buffered);
  91. DEBUGFS_READONLY_FILE(mode, 20, "%s",
  92. ieee80211_mode_str(local->hw.conf.phymode));
  93. DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
  94. local->wep_iv & 0xffffff);
  95. DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
  96. local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
  97. /* statistics stuff */
  98. static inline int rtnl_lock_local(struct ieee80211_local *local)
  99. {
  100. rtnl_lock();
  101. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
  102. rtnl_unlock();
  103. return -ENODEV;
  104. }
  105. return 0;
  106. }
  107. #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
  108. DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
  109. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  110. char __user *userbuf,
  111. size_t count, loff_t *ppos,
  112. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  113. int buflen))
  114. {
  115. struct ieee80211_low_level_stats stats;
  116. char buf[20];
  117. int res;
  118. if (!local->ops->get_stats)
  119. return -EOPNOTSUPP;
  120. res = rtnl_lock_local(local);
  121. if (res)
  122. return res;
  123. res = local->ops->get_stats(local_to_hw(local), &stats);
  124. rtnl_unlock();
  125. if (!res)
  126. res = printvalue(&stats, buf, sizeof(buf));
  127. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  128. }
  129. #define DEBUGFS_DEVSTATS_FILE(name) \
  130. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  131. char *buf, int buflen) \
  132. { \
  133. return scnprintf(buf, buflen, "%u\n", stats->name); \
  134. } \
  135. static ssize_t stats_ ##name## _read(struct file *file, \
  136. char __user *userbuf, \
  137. size_t count, loff_t *ppos) \
  138. { \
  139. return format_devstat_counter(file->private_data, \
  140. userbuf, \
  141. count, \
  142. ppos, \
  143. print_devstats_##name); \
  144. } \
  145. \
  146. static const struct file_operations stats_ ##name## _ops = { \
  147. .read = stats_ ##name## _read, \
  148. .open = mac80211_open_file_generic, \
  149. };
  150. #define DEBUGFS_STATS_ADD(name) \
  151. local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
  152. local, &stats_ ##name## _ops);
  153. #define DEBUGFS_STATS_DEL(name) \
  154. debugfs_remove(local->debugfs.stats.name); \
  155. local->debugfs.stats.name = NULL;
  156. DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
  157. local->dot11TransmittedFragmentCount);
  158. DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
  159. local->dot11MulticastTransmittedFrameCount);
  160. DEBUGFS_STATS_FILE(failed_count, 20, "%u",
  161. local->dot11FailedCount);
  162. DEBUGFS_STATS_FILE(retry_count, 20, "%u",
  163. local->dot11RetryCount);
  164. DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
  165. local->dot11MultipleRetryCount);
  166. DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
  167. local->dot11FrameDuplicateCount);
  168. DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
  169. local->dot11ReceivedFragmentCount);
  170. DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
  171. local->dot11MulticastReceivedFrameCount);
  172. DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
  173. local->dot11TransmittedFrameCount);
  174. DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
  175. local->dot11WEPUndecryptableCount);
  176. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  177. DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
  178. local->tx_handlers_drop);
  179. DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
  180. local->tx_handlers_queued);
  181. DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
  182. local->tx_handlers_drop_unencrypted);
  183. DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
  184. local->tx_handlers_drop_fragment);
  185. DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
  186. local->tx_handlers_drop_wep);
  187. DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
  188. local->tx_handlers_drop_not_assoc);
  189. DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
  190. local->tx_handlers_drop_unauth_port);
  191. DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
  192. local->rx_handlers_drop);
  193. DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
  194. local->rx_handlers_queued);
  195. DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
  196. local->rx_handlers_drop_nullfunc);
  197. DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
  198. local->rx_handlers_drop_defrag);
  199. DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
  200. local->rx_handlers_drop_short);
  201. DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
  202. local->rx_handlers_drop_passive_scan);
  203. DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
  204. local->tx_expand_skb_head);
  205. DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
  206. local->tx_expand_skb_head_cloned);
  207. DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
  208. local->rx_expand_skb_head);
  209. DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
  210. local->rx_expand_skb_head2);
  211. DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
  212. local->rx_handlers_fragments);
  213. DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
  214. local->tx_status_drop);
  215. static ssize_t stats_wme_rx_queue_read(struct file *file,
  216. char __user *userbuf,
  217. size_t count, loff_t *ppos)
  218. {
  219. struct ieee80211_local *local = file->private_data;
  220. char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
  221. int i;
  222. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  223. p += scnprintf(p, sizeof(buf)+buf-p,
  224. "%u\n", local->wme_rx_queue[i]);
  225. return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
  226. }
  227. static const struct file_operations stats_wme_rx_queue_ops = {
  228. .read = stats_wme_rx_queue_read,
  229. .open = mac80211_open_file_generic,
  230. };
  231. static ssize_t stats_wme_tx_queue_read(struct file *file,
  232. char __user *userbuf,
  233. size_t count, loff_t *ppos)
  234. {
  235. struct ieee80211_local *local = file->private_data;
  236. char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
  237. int i;
  238. for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
  239. p += scnprintf(p, sizeof(buf)+buf-p,
  240. "%u\n", local->wme_tx_queue[i]);
  241. return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
  242. }
  243. static const struct file_operations stats_wme_tx_queue_ops = {
  244. .read = stats_wme_tx_queue_read,
  245. .open = mac80211_open_file_generic,
  246. };
  247. #endif
  248. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  249. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  250. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  251. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  252. void debugfs_hw_add(struct ieee80211_local *local)
  253. {
  254. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  255. struct dentry *statsd;
  256. if (!phyd)
  257. return;
  258. local->debugfs.stations = debugfs_create_dir("stations", phyd);
  259. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  260. DEBUGFS_ADD(channel);
  261. DEBUGFS_ADD(frequency);
  262. DEBUGFS_ADD(antenna_sel_tx);
  263. DEBUGFS_ADD(antenna_sel_rx);
  264. DEBUGFS_ADD(bridge_packets);
  265. DEBUGFS_ADD(rts_threshold);
  266. DEBUGFS_ADD(fragmentation_threshold);
  267. DEBUGFS_ADD(short_retry_limit);
  268. DEBUGFS_ADD(long_retry_limit);
  269. DEBUGFS_ADD(total_ps_buffered);
  270. DEBUGFS_ADD(mode);
  271. DEBUGFS_ADD(wep_iv);
  272. DEBUGFS_ADD(modes);
  273. statsd = debugfs_create_dir("statistics", phyd);
  274. local->debugfs.statistics = statsd;
  275. /* if the dir failed, don't put all the other things into the root! */
  276. if (!statsd)
  277. return;
  278. DEBUGFS_STATS_ADD(transmitted_fragment_count);
  279. DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
  280. DEBUGFS_STATS_ADD(failed_count);
  281. DEBUGFS_STATS_ADD(retry_count);
  282. DEBUGFS_STATS_ADD(multiple_retry_count);
  283. DEBUGFS_STATS_ADD(frame_duplicate_count);
  284. DEBUGFS_STATS_ADD(received_fragment_count);
  285. DEBUGFS_STATS_ADD(multicast_received_frame_count);
  286. DEBUGFS_STATS_ADD(transmitted_frame_count);
  287. DEBUGFS_STATS_ADD(wep_undecryptable_count);
  288. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  289. DEBUGFS_STATS_ADD(tx_handlers_drop);
  290. DEBUGFS_STATS_ADD(tx_handlers_queued);
  291. DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
  292. DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
  293. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  294. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  295. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  296. DEBUGFS_STATS_ADD(rx_handlers_drop);
  297. DEBUGFS_STATS_ADD(rx_handlers_queued);
  298. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  299. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  300. DEBUGFS_STATS_ADD(rx_handlers_drop_short);
  301. DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
  302. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  303. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  304. DEBUGFS_STATS_ADD(rx_expand_skb_head);
  305. DEBUGFS_STATS_ADD(rx_expand_skb_head2);
  306. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  307. DEBUGFS_STATS_ADD(tx_status_drop);
  308. DEBUGFS_STATS_ADD(wme_tx_queue);
  309. DEBUGFS_STATS_ADD(wme_rx_queue);
  310. #endif
  311. DEBUGFS_STATS_ADD(dot11ACKFailureCount);
  312. DEBUGFS_STATS_ADD(dot11RTSFailureCount);
  313. DEBUGFS_STATS_ADD(dot11FCSErrorCount);
  314. DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
  315. }
  316. void debugfs_hw_del(struct ieee80211_local *local)
  317. {
  318. DEBUGFS_DEL(channel);
  319. DEBUGFS_DEL(frequency);
  320. DEBUGFS_DEL(antenna_sel_tx);
  321. DEBUGFS_DEL(antenna_sel_rx);
  322. DEBUGFS_DEL(bridge_packets);
  323. DEBUGFS_DEL(rts_threshold);
  324. DEBUGFS_DEL(fragmentation_threshold);
  325. DEBUGFS_DEL(short_retry_limit);
  326. DEBUGFS_DEL(long_retry_limit);
  327. DEBUGFS_DEL(total_ps_buffered);
  328. DEBUGFS_DEL(mode);
  329. DEBUGFS_DEL(wep_iv);
  330. DEBUGFS_DEL(modes);
  331. DEBUGFS_STATS_DEL(transmitted_fragment_count);
  332. DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
  333. DEBUGFS_STATS_DEL(failed_count);
  334. DEBUGFS_STATS_DEL(retry_count);
  335. DEBUGFS_STATS_DEL(multiple_retry_count);
  336. DEBUGFS_STATS_DEL(frame_duplicate_count);
  337. DEBUGFS_STATS_DEL(received_fragment_count);
  338. DEBUGFS_STATS_DEL(multicast_received_frame_count);
  339. DEBUGFS_STATS_DEL(transmitted_frame_count);
  340. DEBUGFS_STATS_DEL(wep_undecryptable_count);
  341. DEBUGFS_STATS_DEL(num_scans);
  342. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  343. DEBUGFS_STATS_DEL(tx_handlers_drop);
  344. DEBUGFS_STATS_DEL(tx_handlers_queued);
  345. DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
  346. DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
  347. DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
  348. DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
  349. DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
  350. DEBUGFS_STATS_DEL(rx_handlers_drop);
  351. DEBUGFS_STATS_DEL(rx_handlers_queued);
  352. DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
  353. DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
  354. DEBUGFS_STATS_DEL(rx_handlers_drop_short);
  355. DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
  356. DEBUGFS_STATS_DEL(tx_expand_skb_head);
  357. DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
  358. DEBUGFS_STATS_DEL(rx_expand_skb_head);
  359. DEBUGFS_STATS_DEL(rx_expand_skb_head2);
  360. DEBUGFS_STATS_DEL(rx_handlers_fragments);
  361. DEBUGFS_STATS_DEL(tx_status_drop);
  362. DEBUGFS_STATS_DEL(wme_tx_queue);
  363. DEBUGFS_STATS_DEL(wme_rx_queue);
  364. #endif
  365. DEBUGFS_STATS_DEL(dot11ACKFailureCount);
  366. DEBUGFS_STATS_DEL(dot11RTSFailureCount);
  367. DEBUGFS_STATS_DEL(dot11FCSErrorCount);
  368. DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
  369. debugfs_remove(local->debugfs.statistics);
  370. local->debugfs.statistics = NULL;
  371. debugfs_remove(local->debugfs.stations);
  372. local->debugfs.stations = NULL;
  373. debugfs_remove(local->debugfs.keys);
  374. local->debugfs.keys = NULL;
  375. }