debugfs.c 13 KB

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