debugfs.c 14 KB

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