debugfs.c 12 KB

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