debugfs.c 15 KB

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