debugfs.c 12 KB

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