debugfs.c 12 KB

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