debugfs.c 14 KB

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