debugfs_sta.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. * Copyright 2003-2005 Devicescape Software, Inc.
  3. * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
  4. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. * Copyright(c) 2016 Intel Deutschland GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/debugfs.h>
  13. #include <linux/ieee80211.h>
  14. #include "ieee80211_i.h"
  15. #include "debugfs.h"
  16. #include "debugfs_sta.h"
  17. #include "sta_info.h"
  18. #include "driver-ops.h"
  19. /* sta attributtes */
  20. #define STA_READ(name, field, format_string) \
  21. static ssize_t sta_ ##name## _read(struct file *file, \
  22. char __user *userbuf, \
  23. size_t count, loff_t *ppos) \
  24. { \
  25. struct sta_info *sta = file->private_data; \
  26. return mac80211_format_buffer(userbuf, count, ppos, \
  27. format_string, sta->field); \
  28. }
  29. #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
  30. #define STA_OPS(name) \
  31. static const struct file_operations sta_ ##name## _ops = { \
  32. .read = sta_##name##_read, \
  33. .open = simple_open, \
  34. .llseek = generic_file_llseek, \
  35. }
  36. #define STA_OPS_RW(name) \
  37. static const struct file_operations sta_ ##name## _ops = { \
  38. .read = sta_##name##_read, \
  39. .write = sta_##name##_write, \
  40. .open = simple_open, \
  41. .llseek = generic_file_llseek, \
  42. }
  43. #define STA_FILE(name, field, format) \
  44. STA_READ_##format(name, field) \
  45. STA_OPS(name)
  46. STA_FILE(aid, sta.aid, D);
  47. static const char * const sta_flag_names[] = {
  48. #define FLAG(F) [WLAN_STA_##F] = #F
  49. FLAG(AUTH),
  50. FLAG(ASSOC),
  51. FLAG(PS_STA),
  52. FLAG(AUTHORIZED),
  53. FLAG(SHORT_PREAMBLE),
  54. FLAG(WDS),
  55. FLAG(CLEAR_PS_FILT),
  56. FLAG(MFP),
  57. FLAG(BLOCK_BA),
  58. FLAG(PS_DRIVER),
  59. FLAG(PSPOLL),
  60. FLAG(TDLS_PEER),
  61. FLAG(TDLS_PEER_AUTH),
  62. FLAG(TDLS_INITIATOR),
  63. FLAG(TDLS_CHAN_SWITCH),
  64. FLAG(TDLS_OFF_CHANNEL),
  65. FLAG(TDLS_WIDER_BW),
  66. FLAG(UAPSD),
  67. FLAG(SP),
  68. FLAG(4ADDR_EVENT),
  69. FLAG(INSERTED),
  70. FLAG(RATE_CONTROL),
  71. FLAG(TOFFSET_KNOWN),
  72. FLAG(MPSP_OWNER),
  73. FLAG(MPSP_RECIPIENT),
  74. FLAG(PS_DELIVER),
  75. #undef FLAG
  76. };
  77. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  78. size_t count, loff_t *ppos)
  79. {
  80. char buf[16 * NUM_WLAN_STA_FLAGS], *pos = buf;
  81. char *end = buf + sizeof(buf) - 1;
  82. struct sta_info *sta = file->private_data;
  83. unsigned int flg;
  84. BUILD_BUG_ON(ARRAY_SIZE(sta_flag_names) != NUM_WLAN_STA_FLAGS);
  85. for (flg = 0; flg < NUM_WLAN_STA_FLAGS; flg++) {
  86. if (test_sta_flag(sta, flg))
  87. pos += scnprintf(pos, end - pos, "%s\n",
  88. sta_flag_names[flg]);
  89. }
  90. return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
  91. }
  92. STA_OPS(flags);
  93. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  94. char __user *userbuf,
  95. size_t count, loff_t *ppos)
  96. {
  97. struct sta_info *sta = file->private_data;
  98. char buf[17*IEEE80211_NUM_ACS], *p = buf;
  99. int ac;
  100. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  101. p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
  102. skb_queue_len(&sta->ps_tx_buf[ac]) +
  103. skb_queue_len(&sta->tx_filtered[ac]));
  104. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  105. }
  106. STA_OPS(num_ps_buf_frames);
  107. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  108. size_t count, loff_t *ppos)
  109. {
  110. char buf[15*IEEE80211_NUM_TIDS], *p = buf;
  111. int i;
  112. struct sta_info *sta = file->private_data;
  113. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  114. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  115. le16_to_cpu(sta->last_seq_ctrl[i]));
  116. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  117. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  118. }
  119. STA_OPS(last_seq_ctrl);
  120. #define AQM_TXQ_ENTRY_LEN 130
  121. static ssize_t sta_aqm_read(struct file *file, char __user *userbuf,
  122. size_t count, loff_t *ppos)
  123. {
  124. struct sta_info *sta = file->private_data;
  125. struct ieee80211_local *local = sta->local;
  126. size_t bufsz = AQM_TXQ_ENTRY_LEN*(IEEE80211_NUM_TIDS+1);
  127. char *buf = kzalloc(bufsz, GFP_KERNEL), *p = buf;
  128. struct txq_info *txqi;
  129. ssize_t rv;
  130. int i;
  131. if (!buf)
  132. return -ENOMEM;
  133. spin_lock_bh(&local->fq.lock);
  134. rcu_read_lock();
  135. p += scnprintf(p,
  136. bufsz+buf-p,
  137. "tid ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n");
  138. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  139. txqi = to_txq_info(sta->sta.txq[i]);
  140. p += scnprintf(p, bufsz+buf-p,
  141. "%d %d %u %u %u %u %u %u %u %u %u\n",
  142. txqi->txq.tid,
  143. txqi->txq.ac,
  144. txqi->tin.backlog_bytes,
  145. txqi->tin.backlog_packets,
  146. txqi->tin.flows,
  147. txqi->cstats.drop_count,
  148. txqi->cstats.ecn_mark,
  149. txqi->tin.overlimit,
  150. txqi->tin.collisions,
  151. txqi->tin.tx_bytes,
  152. txqi->tin.tx_packets);
  153. }
  154. rcu_read_unlock();
  155. spin_unlock_bh(&local->fq.lock);
  156. rv = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  157. kfree(buf);
  158. return rv;
  159. }
  160. STA_OPS(aqm);
  161. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  162. size_t count, loff_t *ppos)
  163. {
  164. char buf[71 + IEEE80211_NUM_TIDS * 40], *p = buf;
  165. int i;
  166. struct sta_info *sta = file->private_data;
  167. struct tid_ampdu_rx *tid_rx;
  168. struct tid_ampdu_tx *tid_tx;
  169. rcu_read_lock();
  170. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  171. sta->ampdu_mlme.dialog_token_allocator + 1);
  172. p += scnprintf(p, sizeof(buf) + buf - p,
  173. "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
  174. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  175. tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
  176. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
  177. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  178. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_rx);
  179. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  180. tid_rx ? sta->ampdu_mlme.tid_rx_token[i] : 0);
  181. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  182. tid_rx ? tid_rx->ssn : 0);
  183. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
  184. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  185. tid_tx ? tid_tx->dialog_token : 0);
  186. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  187. tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
  188. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  189. }
  190. rcu_read_unlock();
  191. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  192. }
  193. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  194. size_t count, loff_t *ppos)
  195. {
  196. char _buf[25] = {}, *buf = _buf;
  197. struct sta_info *sta = file->private_data;
  198. bool start, tx;
  199. unsigned long tid;
  200. char *pos;
  201. int ret, timeout = 5000;
  202. if (count > sizeof(_buf))
  203. return -EINVAL;
  204. if (copy_from_user(buf, userbuf, count))
  205. return -EFAULT;
  206. buf[sizeof(_buf) - 1] = '\0';
  207. pos = buf;
  208. buf = strsep(&pos, " ");
  209. if (!buf)
  210. return -EINVAL;
  211. if (!strcmp(buf, "tx"))
  212. tx = true;
  213. else if (!strcmp(buf, "rx"))
  214. tx = false;
  215. else
  216. return -EINVAL;
  217. buf = strsep(&pos, " ");
  218. if (!buf)
  219. return -EINVAL;
  220. if (!strcmp(buf, "start")) {
  221. start = true;
  222. if (!tx)
  223. return -EINVAL;
  224. } else if (!strcmp(buf, "stop")) {
  225. start = false;
  226. } else {
  227. return -EINVAL;
  228. }
  229. buf = strsep(&pos, " ");
  230. if (!buf)
  231. return -EINVAL;
  232. if (sscanf(buf, "timeout=%d", &timeout) == 1) {
  233. buf = strsep(&pos, " ");
  234. if (!buf || !tx || !start)
  235. return -EINVAL;
  236. }
  237. ret = kstrtoul(buf, 0, &tid);
  238. if (ret || tid >= IEEE80211_NUM_TIDS)
  239. return -EINVAL;
  240. if (tx) {
  241. if (start)
  242. ret = ieee80211_start_tx_ba_session(&sta->sta, tid,
  243. timeout);
  244. else
  245. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
  246. } else {
  247. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
  248. 3, true);
  249. ret = 0;
  250. }
  251. return ret ?: count;
  252. }
  253. STA_OPS_RW(agg_status);
  254. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  255. size_t count, loff_t *ppos)
  256. {
  257. #define PRINT_HT_CAP(_cond, _str) \
  258. do { \
  259. if (_cond) \
  260. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  261. } while (0)
  262. char buf[512], *p = buf;
  263. int i;
  264. struct sta_info *sta = file->private_data;
  265. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  266. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  267. htc->ht_supported ? "" : "not ");
  268. if (htc->ht_supported) {
  269. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  270. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  271. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  272. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  273. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  274. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  275. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  276. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  277. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  278. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  279. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  280. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  281. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  282. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  283. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  284. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  285. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  286. "3839 bytes");
  287. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  288. "7935 bytes");
  289. /*
  290. * For beacons and probe response this would mean the BSS
  291. * does or does not allow the usage of DSSS/CCK HT40.
  292. * Otherwise it means the STA does or does not use
  293. * DSSS/CCK HT40.
  294. */
  295. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  296. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  297. /* BIT(13) is reserved */
  298. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  299. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  300. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  301. htc->ampdu_factor, htc->ampdu_density);
  302. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  303. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  304. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  305. htc->mcs.rx_mask[i]);
  306. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  307. /* If not set this is meaningless */
  308. if (le16_to_cpu(htc->mcs.rx_highest)) {
  309. p += scnprintf(p, sizeof(buf)+buf-p,
  310. "MCS rx highest: %d Mbps\n",
  311. le16_to_cpu(htc->mcs.rx_highest));
  312. }
  313. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  314. htc->mcs.tx_params);
  315. }
  316. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  317. }
  318. STA_OPS(ht_capa);
  319. static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
  320. size_t count, loff_t *ppos)
  321. {
  322. char buf[512], *p = buf;
  323. struct sta_info *sta = file->private_data;
  324. struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
  325. p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
  326. vhtc->vht_supported ? "" : "not ");
  327. if (vhtc->vht_supported) {
  328. p += scnprintf(p, sizeof(buf) + buf - p, "cap: %#.8x\n",
  329. vhtc->cap);
  330. #define PFLAG(a, b) \
  331. do { \
  332. if (vhtc->cap & IEEE80211_VHT_CAP_ ## a) \
  333. p += scnprintf(p, sizeof(buf) + buf - p, \
  334. "\t\t%s\n", b); \
  335. } while (0)
  336. switch (vhtc->cap & 0x3) {
  337. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
  338. p += scnprintf(p, sizeof(buf) + buf - p,
  339. "\t\tMAX-MPDU-3895\n");
  340. break;
  341. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
  342. p += scnprintf(p, sizeof(buf) + buf - p,
  343. "\t\tMAX-MPDU-7991\n");
  344. break;
  345. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
  346. p += scnprintf(p, sizeof(buf) + buf - p,
  347. "\t\tMAX-MPDU-11454\n");
  348. break;
  349. default:
  350. p += scnprintf(p, sizeof(buf) + buf - p,
  351. "\t\tMAX-MPDU-UNKNOWN\n");
  352. };
  353. switch (vhtc->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  354. case 0:
  355. p += scnprintf(p, sizeof(buf) + buf - p,
  356. "\t\t80Mhz\n");
  357. break;
  358. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  359. p += scnprintf(p, sizeof(buf) + buf - p,
  360. "\t\t160Mhz\n");
  361. break;
  362. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  363. p += scnprintf(p, sizeof(buf) + buf - p,
  364. "\t\t80+80Mhz\n");
  365. break;
  366. default:
  367. p += scnprintf(p, sizeof(buf) + buf - p,
  368. "\t\tUNKNOWN-MHZ: 0x%x\n",
  369. (vhtc->cap >> 2) & 0x3);
  370. };
  371. PFLAG(RXLDPC, "RXLDPC");
  372. PFLAG(SHORT_GI_80, "SHORT-GI-80");
  373. PFLAG(SHORT_GI_160, "SHORT-GI-160");
  374. PFLAG(TXSTBC, "TXSTBC");
  375. p += scnprintf(p, sizeof(buf) + buf - p,
  376. "\t\tRXSTBC_%d\n", (vhtc->cap >> 8) & 0x7);
  377. PFLAG(SU_BEAMFORMER_CAPABLE, "SU-BEAMFORMER-CAPABLE");
  378. PFLAG(SU_BEAMFORMEE_CAPABLE, "SU-BEAMFORMEE-CAPABLE");
  379. p += scnprintf(p, sizeof(buf) + buf - p,
  380. "\t\tBEAMFORMEE-STS: 0x%x\n",
  381. (vhtc->cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK) >>
  382. IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
  383. p += scnprintf(p, sizeof(buf) + buf - p,
  384. "\t\tSOUNDING-DIMENSIONS: 0x%x\n",
  385. (vhtc->cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK)
  386. >> IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
  387. PFLAG(MU_BEAMFORMER_CAPABLE, "MU-BEAMFORMER-CAPABLE");
  388. PFLAG(MU_BEAMFORMEE_CAPABLE, "MU-BEAMFORMEE-CAPABLE");
  389. PFLAG(VHT_TXOP_PS, "TXOP-PS");
  390. PFLAG(HTC_VHT, "HTC-VHT");
  391. p += scnprintf(p, sizeof(buf) + buf - p,
  392. "\t\tMPDU-LENGTH-EXPONENT: 0x%x\n",
  393. (vhtc->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
  394. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
  395. PFLAG(VHT_LINK_ADAPTATION_VHT_UNSOL_MFB,
  396. "LINK-ADAPTATION-VHT-UNSOL-MFB");
  397. p += scnprintf(p, sizeof(buf) + buf - p,
  398. "\t\tLINK-ADAPTATION-VHT-MRQ-MFB: 0x%x\n",
  399. (vhtc->cap & IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB) >> 26);
  400. PFLAG(RX_ANTENNA_PATTERN, "RX-ANTENNA-PATTERN");
  401. PFLAG(TX_ANTENNA_PATTERN, "TX-ANTENNA-PATTERN");
  402. p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
  403. le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
  404. if (vhtc->vht_mcs.rx_highest)
  405. p += scnprintf(p, sizeof(buf)+buf-p,
  406. "MCS RX highest: %d Mbps\n",
  407. le16_to_cpu(vhtc->vht_mcs.rx_highest));
  408. p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
  409. le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
  410. if (vhtc->vht_mcs.tx_highest)
  411. p += scnprintf(p, sizeof(buf)+buf-p,
  412. "MCS TX highest: %d Mbps\n",
  413. le16_to_cpu(vhtc->vht_mcs.tx_highest));
  414. }
  415. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  416. }
  417. STA_OPS(vht_capa);
  418. #define DEBUGFS_ADD(name) \
  419. debugfs_create_file(#name, 0400, \
  420. sta->debugfs_dir, sta, &sta_ ##name## _ops);
  421. #define DEBUGFS_ADD_COUNTER(name, field) \
  422. if (sizeof(sta->field) == sizeof(u32)) \
  423. debugfs_create_u32(#name, 0400, sta->debugfs_dir, \
  424. (u32 *) &sta->field); \
  425. else \
  426. debugfs_create_u64(#name, 0400, sta->debugfs_dir, \
  427. (u64 *) &sta->field);
  428. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  429. {
  430. struct ieee80211_local *local = sta->local;
  431. struct ieee80211_sub_if_data *sdata = sta->sdata;
  432. struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
  433. u8 mac[3*ETH_ALEN];
  434. if (!stations_dir)
  435. return;
  436. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  437. /*
  438. * This might fail due to a race condition:
  439. * When mac80211 unlinks a station, the debugfs entries
  440. * remain, but it is already possible to link a new
  441. * station with the same address which triggers adding
  442. * it to debugfs; therefore, if the old station isn't
  443. * destroyed quickly enough the old station's debugfs
  444. * dir might still be around.
  445. */
  446. sta->debugfs_dir = debugfs_create_dir(mac, stations_dir);
  447. if (!sta->debugfs_dir)
  448. return;
  449. DEBUGFS_ADD(flags);
  450. DEBUGFS_ADD(num_ps_buf_frames);
  451. DEBUGFS_ADD(last_seq_ctrl);
  452. DEBUGFS_ADD(agg_status);
  453. DEBUGFS_ADD(ht_capa);
  454. DEBUGFS_ADD(vht_capa);
  455. DEBUGFS_ADD_COUNTER(rx_duplicates, rx_stats.num_duplicates);
  456. DEBUGFS_ADD_COUNTER(rx_fragments, rx_stats.fragments);
  457. DEBUGFS_ADD_COUNTER(tx_filtered, status_stats.filtered);
  458. if (local->ops->wake_tx_queue)
  459. DEBUGFS_ADD(aqm);
  460. if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
  461. debugfs_create_x32("driver_buffered_tids", 0400,
  462. sta->debugfs_dir,
  463. (u32 *)&sta->driver_buffered_tids);
  464. else
  465. debugfs_create_x64("driver_buffered_tids", 0400,
  466. sta->debugfs_dir,
  467. (u64 *)&sta->driver_buffered_tids);
  468. drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs_dir);
  469. }
  470. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  471. {
  472. debugfs_remove_recursive(sta->debugfs_dir);
  473. sta->debugfs_dir = NULL;
  474. }