debugfs.c 14 KB

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