debugfs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * mac80211 debugfs for wireless PHYs
  4. *
  5. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  6. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. * Copyright (C) 2018 - 2019, 2021-2025 Intel Corporation
  8. */
  9. #include <linux/debugfs.h>
  10. #include <linux/rtnetlink.h>
  11. #include <linux/vmalloc.h>
  12. #include "ieee80211_i.h"
  13. #include "driver-ops.h"
  14. #include "rate.h"
  15. #include "debugfs.h"
  16. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  17. int mac80211_format_buffer(char __user *userbuf, size_t count,
  18. loff_t *ppos, char *fmt, ...)
  19. {
  20. va_list args;
  21. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  22. int res;
  23. va_start(args, fmt);
  24. res = vscnprintf(buf, sizeof(buf), fmt, args);
  25. va_end(args);
  26. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  27. }
  28. #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
  29. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  30. size_t count, loff_t *ppos) \
  31. { \
  32. struct ieee80211_local *local = file->private_data; \
  33. \
  34. return mac80211_format_buffer(userbuf, count, ppos, \
  35. fmt "\n", ##value); \
  36. }
  37. #define DEBUGFS_READONLY_FILE_OPS(name) \
  38. static const struct debugfs_short_fops name## _ops = { \
  39. .read = name## _read, \
  40. .llseek = generic_file_llseek, \
  41. };
  42. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  43. DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
  44. DEBUGFS_READONLY_FILE_OPS(name)
  45. #define DEBUGFS_ADD(name) \
  46. debugfs_create_file(#name, 0400, phyd, local, &name## _ops)
  47. #define DEBUGFS_ADD_MODE(name, mode) \
  48. debugfs_create_file(#name, mode, phyd, local, &name## _ops);
  49. DEBUGFS_READONLY_FILE(hw_conf, "%x",
  50. local->hw.conf.flags);
  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(total_ps_buffered, "%d",
  56. local->total_ps_buffered);
  57. DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
  58. local->wep_iv & 0xffffff);
  59. DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
  60. local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
  61. static ssize_t aqm_read(struct file *file,
  62. char __user *user_buf,
  63. size_t count,
  64. loff_t *ppos)
  65. {
  66. struct ieee80211_local *local = file->private_data;
  67. struct fq *fq = &local->fq;
  68. char buf[200];
  69. int len = 0;
  70. spin_lock_bh(&local->fq.lock);
  71. len = scnprintf(buf, sizeof(buf),
  72. "access name value\n"
  73. "R fq_flows_cnt %u\n"
  74. "R fq_backlog %u\n"
  75. "R fq_overlimit %u\n"
  76. "R fq_overmemory %u\n"
  77. "R fq_collisions %u\n"
  78. "R fq_memory_usage %u\n"
  79. "RW fq_memory_limit %u\n"
  80. "RW fq_limit %u\n"
  81. "RW fq_quantum %u\n",
  82. fq->flows_cnt,
  83. fq->backlog,
  84. fq->overmemory,
  85. fq->overlimit,
  86. fq->collisions,
  87. fq->memory_usage,
  88. fq->memory_limit,
  89. fq->limit,
  90. fq->quantum);
  91. spin_unlock_bh(&local->fq.lock);
  92. return simple_read_from_buffer(user_buf, count, ppos,
  93. buf, len);
  94. }
  95. static ssize_t aqm_write(struct file *file,
  96. const char __user *user_buf,
  97. size_t count,
  98. loff_t *ppos)
  99. {
  100. struct ieee80211_local *local = file->private_data;
  101. char buf[100];
  102. if (count >= sizeof(buf))
  103. return -EINVAL;
  104. if (copy_from_user(buf, user_buf, count))
  105. return -EFAULT;
  106. if (count && buf[count - 1] == '\n')
  107. buf[count - 1] = '\0';
  108. else
  109. buf[count] = '\0';
  110. if (sscanf(buf, "fq_limit %u", &local->fq.limit) == 1)
  111. return count;
  112. else if (sscanf(buf, "fq_memory_limit %u", &local->fq.memory_limit) == 1)
  113. return count;
  114. else if (sscanf(buf, "fq_quantum %u", &local->fq.quantum) == 1)
  115. return count;
  116. return -EINVAL;
  117. }
  118. static const struct debugfs_short_fops aqm_ops = {
  119. .write = aqm_write,
  120. .read = aqm_read,
  121. .llseek = default_llseek,
  122. };
  123. static ssize_t airtime_flags_read(struct file *file,
  124. char __user *user_buf,
  125. size_t count, loff_t *ppos)
  126. {
  127. struct ieee80211_local *local = file->private_data;
  128. char buf[128] = {}, *pos, *end;
  129. pos = buf;
  130. end = pos + sizeof(buf) - 1;
  131. if (local->airtime_flags & AIRTIME_USE_TX)
  132. pos += scnprintf(pos, end - pos, "AIRTIME_TX\t(%lx)\n",
  133. AIRTIME_USE_TX);
  134. if (local->airtime_flags & AIRTIME_USE_RX)
  135. pos += scnprintf(pos, end - pos, "AIRTIME_RX\t(%lx)\n",
  136. AIRTIME_USE_RX);
  137. return simple_read_from_buffer(user_buf, count, ppos, buf,
  138. strlen(buf));
  139. }
  140. static ssize_t airtime_flags_write(struct file *file,
  141. const char __user *user_buf,
  142. size_t count, loff_t *ppos)
  143. {
  144. struct ieee80211_local *local = file->private_data;
  145. char buf[16];
  146. if (count >= sizeof(buf))
  147. return -EINVAL;
  148. if (copy_from_user(buf, user_buf, count))
  149. return -EFAULT;
  150. if (count && buf[count - 1] == '\n')
  151. buf[count - 1] = '\0';
  152. else
  153. buf[count] = '\0';
  154. if (kstrtou16(buf, 0, &local->airtime_flags))
  155. return -EINVAL;
  156. return count;
  157. }
  158. static const struct debugfs_short_fops airtime_flags_ops = {
  159. .write = airtime_flags_write,
  160. .read = airtime_flags_read,
  161. .llseek = default_llseek,
  162. };
  163. static ssize_t aql_pending_read(struct file *file,
  164. char __user *user_buf,
  165. size_t count, loff_t *ppos)
  166. {
  167. struct ieee80211_local *local = file->private_data;
  168. char buf[400];
  169. int len = 0;
  170. len = scnprintf(buf, sizeof(buf),
  171. "AC AQL pending\n"
  172. "VO %u us\n"
  173. "VI %u us\n"
  174. "BE %u us\n"
  175. "BK %u us\n"
  176. "total %u us\n",
  177. atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_VO]),
  178. atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_VI]),
  179. atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_BE]),
  180. atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_BK]),
  181. atomic_read(&local->aql_total_pending_airtime));
  182. return simple_read_from_buffer(user_buf, count, ppos,
  183. buf, len);
  184. }
  185. static const struct debugfs_short_fops aql_pending_ops = {
  186. .read = aql_pending_read,
  187. .llseek = default_llseek,
  188. };
  189. static ssize_t aql_txq_limit_read(struct file *file,
  190. char __user *user_buf,
  191. size_t count,
  192. loff_t *ppos)
  193. {
  194. struct ieee80211_local *local = file->private_data;
  195. char buf[400];
  196. int len = 0;
  197. len = scnprintf(buf, sizeof(buf),
  198. "AC AQL limit low AQL limit high\n"
  199. "VO %u %u\n"
  200. "VI %u %u\n"
  201. "BE %u %u\n"
  202. "BK %u %u\n",
  203. local->aql_txq_limit_low[IEEE80211_AC_VO],
  204. local->aql_txq_limit_high[IEEE80211_AC_VO],
  205. local->aql_txq_limit_low[IEEE80211_AC_VI],
  206. local->aql_txq_limit_high[IEEE80211_AC_VI],
  207. local->aql_txq_limit_low[IEEE80211_AC_BE],
  208. local->aql_txq_limit_high[IEEE80211_AC_BE],
  209. local->aql_txq_limit_low[IEEE80211_AC_BK],
  210. local->aql_txq_limit_high[IEEE80211_AC_BK]);
  211. return simple_read_from_buffer(user_buf, count, ppos,
  212. buf, len);
  213. }
  214. static ssize_t aql_txq_limit_write(struct file *file,
  215. const char __user *user_buf,
  216. size_t count,
  217. loff_t *ppos)
  218. {
  219. struct ieee80211_local *local = file->private_data;
  220. char buf[100];
  221. u32 ac, q_limit_low, q_limit_high, q_limit_low_old, q_limit_high_old;
  222. struct sta_info *sta;
  223. if (count >= sizeof(buf))
  224. return -EINVAL;
  225. if (copy_from_user(buf, user_buf, count))
  226. return -EFAULT;
  227. if (count && buf[count - 1] == '\n')
  228. buf[count - 1] = '\0';
  229. else
  230. buf[count] = '\0';
  231. if (sscanf(buf, "%u %u %u", &ac, &q_limit_low, &q_limit_high) != 3)
  232. return -EINVAL;
  233. if (ac >= IEEE80211_NUM_ACS)
  234. return -EINVAL;
  235. q_limit_low_old = local->aql_txq_limit_low[ac];
  236. q_limit_high_old = local->aql_txq_limit_high[ac];
  237. guard(wiphy)(local->hw.wiphy);
  238. local->aql_txq_limit_low[ac] = q_limit_low;
  239. local->aql_txq_limit_high[ac] = q_limit_high;
  240. list_for_each_entry(sta, &local->sta_list, list) {
  241. /* If a sta has customized queue limits, keep it */
  242. if (sta->airtime[ac].aql_limit_low == q_limit_low_old &&
  243. sta->airtime[ac].aql_limit_high == q_limit_high_old) {
  244. sta->airtime[ac].aql_limit_low = q_limit_low;
  245. sta->airtime[ac].aql_limit_high = q_limit_high;
  246. }
  247. }
  248. return count;
  249. }
  250. static const struct debugfs_short_fops aql_txq_limit_ops = {
  251. .write = aql_txq_limit_write,
  252. .read = aql_txq_limit_read,
  253. .llseek = default_llseek,
  254. };
  255. static ssize_t aql_enable_read(struct file *file, char __user *user_buf,
  256. size_t count, loff_t *ppos)
  257. {
  258. char buf[3];
  259. int len;
  260. len = scnprintf(buf, sizeof(buf), "%d\n",
  261. !static_key_false(&aql_disable.key));
  262. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  263. }
  264. static ssize_t aql_enable_write(struct file *file, const char __user *user_buf,
  265. size_t count, loff_t *ppos)
  266. {
  267. char buf[3];
  268. size_t len;
  269. if (count > sizeof(buf))
  270. return -EINVAL;
  271. if (copy_from_user(buf, user_buf, count))
  272. return -EFAULT;
  273. buf[sizeof(buf) - 1] = '\0';
  274. len = strlen(buf);
  275. if (len > 0 && buf[len - 1] == '\n')
  276. buf[len - 1] = 0;
  277. if (buf[0] == '0' && buf[1] == '\0')
  278. static_branch_enable(&aql_disable);
  279. else if (buf[0] == '1' && buf[1] == '\0')
  280. static_branch_disable(&aql_disable);
  281. else
  282. return -EINVAL;
  283. return count;
  284. }
  285. static const struct debugfs_short_fops aql_enable_ops = {
  286. .write = aql_enable_write,
  287. .read = aql_enable_read,
  288. .llseek = default_llseek,
  289. };
  290. static ssize_t force_tx_status_read(struct file *file,
  291. char __user *user_buf,
  292. size_t count,
  293. loff_t *ppos)
  294. {
  295. struct ieee80211_local *local = file->private_data;
  296. char buf[3];
  297. int len = 0;
  298. len = scnprintf(buf, sizeof(buf), "%d\n", (int)local->force_tx_status);
  299. return simple_read_from_buffer(user_buf, count, ppos,
  300. buf, len);
  301. }
  302. static ssize_t force_tx_status_write(struct file *file,
  303. const char __user *user_buf,
  304. size_t count,
  305. loff_t *ppos)
  306. {
  307. struct ieee80211_local *local = file->private_data;
  308. char buf[3];
  309. if (count >= sizeof(buf))
  310. return -EINVAL;
  311. if (copy_from_user(buf, user_buf, count))
  312. return -EFAULT;
  313. if (count && buf[count - 1] == '\n')
  314. buf[count - 1] = '\0';
  315. else
  316. buf[count] = '\0';
  317. if (buf[0] == '0' && buf[1] == '\0')
  318. local->force_tx_status = 0;
  319. else if (buf[0] == '1' && buf[1] == '\0')
  320. local->force_tx_status = 1;
  321. else
  322. return -EINVAL;
  323. return count;
  324. }
  325. static const struct debugfs_short_fops force_tx_status_ops = {
  326. .write = force_tx_status_write,
  327. .read = force_tx_status_read,
  328. .llseek = default_llseek,
  329. };
  330. #ifdef CONFIG_PM
  331. static ssize_t reset_write(struct file *file, const char __user *user_buf,
  332. size_t count, loff_t *ppos)
  333. {
  334. struct ieee80211_local *local = file->private_data;
  335. int ret;
  336. rtnl_lock();
  337. wiphy_lock(local->hw.wiphy);
  338. __ieee80211_suspend(&local->hw, NULL);
  339. ret = __ieee80211_resume(&local->hw);
  340. wiphy_unlock(local->hw.wiphy);
  341. if (ret)
  342. cfg80211_shutdown_all_interfaces(local->hw.wiphy);
  343. rtnl_unlock();
  344. return count;
  345. }
  346. static const struct debugfs_short_fops reset_ops = {
  347. .write = reset_write,
  348. .llseek = noop_llseek,
  349. };
  350. #endif
  351. static const char *hw_flag_names[] = {
  352. #define FLAG(F) [IEEE80211_HW_##F] = #F
  353. FLAG(HAS_RATE_CONTROL),
  354. FLAG(RX_INCLUDES_FCS),
  355. FLAG(HOST_BROADCAST_PS_BUFFERING),
  356. FLAG(SIGNAL_UNSPEC),
  357. FLAG(SIGNAL_DBM),
  358. FLAG(NEED_DTIM_BEFORE_ASSOC),
  359. FLAG(SPECTRUM_MGMT),
  360. FLAG(AMPDU_AGGREGATION),
  361. FLAG(SUPPORTS_PS),
  362. FLAG(PS_NULLFUNC_STACK),
  363. FLAG(SUPPORTS_DYNAMIC_PS),
  364. FLAG(MFP_CAPABLE),
  365. FLAG(WANT_MONITOR_VIF),
  366. FLAG(NO_VIRTUAL_MONITOR),
  367. FLAG(NO_AUTO_VIF),
  368. FLAG(SW_CRYPTO_CONTROL),
  369. FLAG(SUPPORT_FAST_XMIT),
  370. FLAG(REPORTS_TX_ACK_STATUS),
  371. FLAG(CONNECTION_MONITOR),
  372. FLAG(QUEUE_CONTROL),
  373. FLAG(SUPPORTS_PER_STA_GTK),
  374. FLAG(AP_LINK_PS),
  375. FLAG(TX_AMPDU_SETUP_IN_HW),
  376. FLAG(SUPPORTS_RC_TABLE),
  377. FLAG(P2P_DEV_ADDR_FOR_INTF),
  378. FLAG(TIMING_BEACON_ONLY),
  379. FLAG(SUPPORTS_HT_CCK_RATES),
  380. FLAG(CHANCTX_STA_CSA),
  381. FLAG(SUPPORTS_CLONED_SKBS),
  382. FLAG(SINGLE_SCAN_ON_ALL_BANDS),
  383. FLAG(TDLS_WIDER_BW),
  384. FLAG(SUPPORTS_AMSDU_IN_AMPDU),
  385. FLAG(BEACON_TX_STATUS),
  386. FLAG(NEEDS_UNIQUE_STA_ADDR),
  387. FLAG(SUPPORTS_REORDERING_BUFFER),
  388. FLAG(USES_RSS),
  389. FLAG(TX_AMSDU),
  390. FLAG(TX_FRAG_LIST),
  391. FLAG(REPORTS_LOW_ACK),
  392. FLAG(SUPPORTS_TX_FRAG),
  393. FLAG(SUPPORTS_TDLS_BUFFER_STA),
  394. FLAG(DOESNT_SUPPORT_QOS_NDP),
  395. FLAG(BUFF_MMPDU_TXQ),
  396. FLAG(SUPPORTS_VHT_EXT_NSS_BW),
  397. FLAG(STA_MMPDU_TXQ),
  398. FLAG(TX_STATUS_NO_AMPDU_LEN),
  399. FLAG(SUPPORTS_MULTI_BSSID),
  400. FLAG(SUPPORTS_ONLY_HE_MULTI_BSSID),
  401. FLAG(AMPDU_KEYBORDER_SUPPORT),
  402. FLAG(SUPPORTS_TX_ENCAP_OFFLOAD),
  403. FLAG(SUPPORTS_RX_DECAP_OFFLOAD),
  404. FLAG(SUPPORTS_CONC_MON_RX_DECAP),
  405. FLAG(DETECTS_COLOR_COLLISION),
  406. FLAG(MLO_MCAST_MULTI_LINK_TX),
  407. FLAG(DISALLOW_PUNCTURING),
  408. FLAG(HANDLES_QUIET_CSA),
  409. FLAG(STRICT),
  410. #undef FLAG
  411. };
  412. static ssize_t hwflags_read(struct file *file, char __user *user_buf,
  413. size_t count, loff_t *ppos)
  414. {
  415. struct ieee80211_local *local = file->private_data;
  416. size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
  417. char *buf = kzalloc(bufsz, GFP_KERNEL);
  418. char *pos = buf, *end = buf + bufsz - 1;
  419. ssize_t rv;
  420. int i;
  421. if (!buf)
  422. return -ENOMEM;
  423. /* fail compilation if somebody adds or removes
  424. * a flag without updating the name array above
  425. */
  426. BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
  427. for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
  428. if (test_bit(i, local->hw.flags))
  429. pos += scnprintf(pos, end - pos, "%s\n",
  430. hw_flag_names[i]);
  431. }
  432. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  433. kfree(buf);
  434. return rv;
  435. }
  436. static ssize_t hwflags_write(struct file *file, const char __user *user_buf,
  437. size_t count, loff_t *ppos)
  438. {
  439. struct ieee80211_local *local = file->private_data;
  440. char buf[100];
  441. int val;
  442. if (count >= sizeof(buf))
  443. return -EINVAL;
  444. if (copy_from_user(buf, user_buf, count))
  445. return -EFAULT;
  446. if (count && buf[count - 1] == '\n')
  447. buf[count - 1] = '\0';
  448. else
  449. buf[count] = '\0';
  450. if (sscanf(buf, "strict=%d", &val) == 1) {
  451. switch (val) {
  452. case 0:
  453. ieee80211_hw_set(&local->hw, STRICT);
  454. return count;
  455. case 1:
  456. __clear_bit(IEEE80211_HW_STRICT, local->hw.flags);
  457. return count;
  458. default:
  459. return -EINVAL;
  460. }
  461. }
  462. return -EINVAL;
  463. }
  464. static const struct file_operations hwflags_ops = {
  465. .open = simple_open,
  466. .read = hwflags_read,
  467. .write = hwflags_write,
  468. };
  469. static ssize_t misc_read(struct file *file, char __user *user_buf,
  470. size_t count, loff_t *ppos)
  471. {
  472. struct ieee80211_local *local = file->private_data;
  473. /* Max len of each line is 16 characters, plus 9 for 'pending:\n' */
  474. size_t bufsz = IEEE80211_MAX_QUEUES * 16 + 9;
  475. char *buf;
  476. char *pos, *end;
  477. ssize_t rv;
  478. int i;
  479. int ln;
  480. buf = kzalloc(bufsz, GFP_KERNEL);
  481. if (!buf)
  482. return -ENOMEM;
  483. pos = buf;
  484. end = buf + bufsz - 1;
  485. pos += scnprintf(pos, end - pos, "pending:\n");
  486. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  487. ln = skb_queue_len(&local->pending[i]);
  488. pos += scnprintf(pos, end - pos, "[%i] %d\n",
  489. i, ln);
  490. }
  491. rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  492. kfree(buf);
  493. return rv;
  494. }
  495. static ssize_t queues_read(struct file *file, char __user *user_buf,
  496. size_t count, loff_t *ppos)
  497. {
  498. struct ieee80211_local *local = file->private_data;
  499. unsigned long flags;
  500. char buf[IEEE80211_MAX_QUEUES * 20];
  501. int q, res = 0;
  502. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  503. for (q = 0; q < local->hw.queues; q++)
  504. res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
  505. local->queue_stop_reasons[q],
  506. skb_queue_len(&local->pending[q]));
  507. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  508. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  509. }
  510. DEBUGFS_READONLY_FILE_OPS(queues);
  511. DEBUGFS_READONLY_FILE_OPS(misc);
  512. /* statistics stuff */
  513. static ssize_t format_devstat_counter(struct ieee80211_local *local,
  514. char __user *userbuf,
  515. size_t count, loff_t *ppos,
  516. int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
  517. int buflen))
  518. {
  519. struct ieee80211_low_level_stats stats;
  520. char buf[20];
  521. int res;
  522. wiphy_lock(local->hw.wiphy);
  523. res = drv_get_stats(local, &stats);
  524. wiphy_unlock(local->hw.wiphy);
  525. if (res)
  526. return res;
  527. res = printvalue(&stats, buf, sizeof(buf));
  528. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  529. }
  530. #define DEBUGFS_DEVSTATS_FILE(name) \
  531. static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
  532. char *buf, int buflen) \
  533. { \
  534. return scnprintf(buf, buflen, "%u\n", stats->name); \
  535. } \
  536. static ssize_t stats_ ##name## _read(struct file *file, \
  537. char __user *userbuf, \
  538. size_t count, loff_t *ppos) \
  539. { \
  540. return format_devstat_counter(file->private_data, \
  541. userbuf, \
  542. count, \
  543. ppos, \
  544. print_devstats_##name); \
  545. } \
  546. \
  547. static const struct debugfs_short_fops stats_ ##name## _ops = { \
  548. .read = stats_ ##name## _read, \
  549. .llseek = generic_file_llseek, \
  550. };
  551. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  552. #define DEBUGFS_STATS_ADD(name) \
  553. debugfs_create_u32(#name, 0400, statsd, &local->name);
  554. #endif
  555. #define DEBUGFS_DEVSTATS_ADD(name) \
  556. debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
  557. DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
  558. DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
  559. DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
  560. DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
  561. void debugfs_hw_add(struct ieee80211_local *local)
  562. {
  563. struct dentry *phyd = local->hw.wiphy->debugfsdir;
  564. struct dentry *statsd;
  565. if (!phyd)
  566. return;
  567. local->debugfs.keys = debugfs_create_dir("keys", phyd);
  568. DEBUGFS_ADD(total_ps_buffered);
  569. DEBUGFS_ADD(wep_iv);
  570. DEBUGFS_ADD(rate_ctrl_alg);
  571. DEBUGFS_ADD(queues);
  572. DEBUGFS_ADD(misc);
  573. #ifdef CONFIG_PM
  574. DEBUGFS_ADD_MODE(reset, 0200);
  575. #endif
  576. DEBUGFS_ADD_MODE(hwflags, 0600);
  577. DEBUGFS_ADD(user_power);
  578. DEBUGFS_ADD(power);
  579. DEBUGFS_ADD(hw_conf);
  580. DEBUGFS_ADD_MODE(force_tx_status, 0600);
  581. DEBUGFS_ADD_MODE(aql_enable, 0600);
  582. DEBUGFS_ADD(aql_pending);
  583. DEBUGFS_ADD_MODE(aqm, 0600);
  584. DEBUGFS_ADD_MODE(airtime_flags, 0600);
  585. DEBUGFS_ADD(aql_txq_limit);
  586. debugfs_create_u32("aql_threshold", 0600,
  587. phyd, &local->aql_threshold);
  588. statsd = debugfs_create_dir("statistics", phyd);
  589. #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
  590. DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
  591. DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
  592. DEBUGFS_STATS_ADD(dot11FailedCount);
  593. DEBUGFS_STATS_ADD(dot11RetryCount);
  594. DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
  595. DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
  596. DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
  597. DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
  598. DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
  599. DEBUGFS_STATS_ADD(tx_handlers_queued);
  600. DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
  601. DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
  602. DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
  603. DEBUGFS_STATS_ADD(rx_handlers_drop);
  604. DEBUGFS_STATS_ADD(rx_handlers_queued);
  605. DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
  606. DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
  607. DEBUGFS_STATS_ADD(tx_expand_skb_head);
  608. DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
  609. DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
  610. DEBUGFS_STATS_ADD(rx_handlers_fragments);
  611. DEBUGFS_STATS_ADD(tx_status_drop);
  612. #endif
  613. DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
  614. DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
  615. DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
  616. DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
  617. }