debugfs.c 12 KB

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