debugfs_sta.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/debugfs.h>
  12. #include <linux/ieee80211.h>
  13. #include "ieee80211_i.h"
  14. #include "debugfs.h"
  15. #include "debugfs_sta.h"
  16. #include "sta_info.h"
  17. #include "driver-ops.h"
  18. /* sta attributtes */
  19. #define STA_READ(name, field, format_string) \
  20. static ssize_t sta_ ##name## _read(struct file *file, \
  21. char __user *userbuf, \
  22. size_t count, loff_t *ppos) \
  23. { \
  24. struct sta_info *sta = file->private_data; \
  25. return mac80211_format_buffer(userbuf, count, ppos, \
  26. format_string, sta->field); \
  27. }
  28. #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
  29. #define STA_READ_U(name, field) STA_READ(name, field, "%u\n")
  30. #define STA_READ_S(name, field) STA_READ(name, field, "%s\n")
  31. #define STA_OPS(name) \
  32. static const struct file_operations sta_ ##name## _ops = { \
  33. .read = sta_##name##_read, \
  34. .open = simple_open, \
  35. .llseek = generic_file_llseek, \
  36. }
  37. #define STA_OPS_W(name) \
  38. static const struct file_operations sta_ ##name## _ops = { \
  39. .write = sta_##name##_write, \
  40. .open = simple_open, \
  41. .llseek = generic_file_llseek, \
  42. }
  43. #define STA_OPS_RW(name) \
  44. static const struct file_operations sta_ ##name## _ops = { \
  45. .read = sta_##name##_read, \
  46. .write = sta_##name##_write, \
  47. .open = simple_open, \
  48. .llseek = generic_file_llseek, \
  49. }
  50. #define STA_FILE(name, field, format) \
  51. STA_READ_##format(name, field) \
  52. STA_OPS(name)
  53. STA_FILE(aid, sta.aid, D);
  54. STA_FILE(dev, sdata->name, S);
  55. STA_FILE(last_signal, last_signal, D);
  56. STA_FILE(last_ack_signal, last_ack_signal, D);
  57. STA_FILE(beacon_loss_count, beacon_loss_count, D);
  58. static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
  59. size_t count, loff_t *ppos)
  60. {
  61. char buf[121];
  62. struct sta_info *sta = file->private_data;
  63. #define TEST(flg) \
  64. test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
  65. int res = scnprintf(buf, sizeof(buf),
  66. "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  67. TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
  68. TEST(PS_DRIVER), TEST(AUTHORIZED),
  69. TEST(SHORT_PREAMBLE),
  70. sta->sta.wme ? "WME\n" : "",
  71. TEST(WDS), TEST(CLEAR_PS_FILT),
  72. TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
  73. TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
  74. TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
  75. TEST(INSERTED), TEST(RATE_CONTROL),
  76. TEST(TOFFSET_KNOWN), TEST(MPSP_OWNER),
  77. TEST(MPSP_RECIPIENT));
  78. #undef TEST
  79. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  80. }
  81. STA_OPS(flags);
  82. static ssize_t sta_num_ps_buf_frames_read(struct file *file,
  83. char __user *userbuf,
  84. size_t count, loff_t *ppos)
  85. {
  86. struct sta_info *sta = file->private_data;
  87. char buf[17*IEEE80211_NUM_ACS], *p = buf;
  88. int ac;
  89. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  90. p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
  91. skb_queue_len(&sta->ps_tx_buf[ac]) +
  92. skb_queue_len(&sta->tx_filtered[ac]));
  93. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  94. }
  95. STA_OPS(num_ps_buf_frames);
  96. static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
  97. size_t count, loff_t *ppos)
  98. {
  99. struct sta_info *sta = file->private_data;
  100. return mac80211_format_buffer(userbuf, count, ppos, "%d\n",
  101. jiffies_to_msecs(jiffies - sta->last_rx));
  102. }
  103. STA_OPS(inactive_ms);
  104. static ssize_t sta_connected_time_read(struct file *file, char __user *userbuf,
  105. size_t count, loff_t *ppos)
  106. {
  107. struct sta_info *sta = file->private_data;
  108. struct timespec uptime;
  109. struct tm result;
  110. long connected_time_secs;
  111. char buf[100];
  112. int res;
  113. ktime_get_ts(&uptime);
  114. connected_time_secs = uptime.tv_sec - sta->last_connected;
  115. time_to_tm(connected_time_secs, 0, &result);
  116. result.tm_year -= 70;
  117. result.tm_mday -= 1;
  118. res = scnprintf(buf, sizeof(buf),
  119. "years - %ld\nmonths - %d\ndays - %d\nclock - %d:%d:%d\n\n",
  120. result.tm_year, result.tm_mon, result.tm_mday,
  121. result.tm_hour, result.tm_min, result.tm_sec);
  122. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  123. }
  124. STA_OPS(connected_time);
  125. static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
  126. size_t count, loff_t *ppos)
  127. {
  128. char buf[15*IEEE80211_NUM_TIDS], *p = buf;
  129. int i;
  130. struct sta_info *sta = file->private_data;
  131. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  132. p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
  133. le16_to_cpu(sta->last_seq_ctrl[i]));
  134. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  135. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  136. }
  137. STA_OPS(last_seq_ctrl);
  138. static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
  139. size_t count, loff_t *ppos)
  140. {
  141. char buf[71 + IEEE80211_NUM_TIDS * 40], *p = buf;
  142. int i;
  143. struct sta_info *sta = file->private_data;
  144. struct tid_ampdu_rx *tid_rx;
  145. struct tid_ampdu_tx *tid_tx;
  146. rcu_read_lock();
  147. p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
  148. sta->ampdu_mlme.dialog_token_allocator + 1);
  149. p += scnprintf(p, sizeof(buf) + buf - p,
  150. "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
  151. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  152. tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
  153. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
  154. p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
  155. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_rx);
  156. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  157. tid_rx ? tid_rx->dialog_token : 0);
  158. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
  159. tid_rx ? tid_rx->ssn : 0);
  160. p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
  161. p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
  162. tid_tx ? tid_tx->dialog_token : 0);
  163. p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
  164. tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
  165. p += scnprintf(p, sizeof(buf) + buf - p, "\n");
  166. }
  167. rcu_read_unlock();
  168. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  169. }
  170. static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
  171. size_t count, loff_t *ppos)
  172. {
  173. char _buf[12] = {}, *buf = _buf;
  174. struct sta_info *sta = file->private_data;
  175. bool start, tx;
  176. unsigned long tid;
  177. int ret;
  178. if (count > sizeof(_buf))
  179. return -EINVAL;
  180. if (copy_from_user(buf, userbuf, count))
  181. return -EFAULT;
  182. buf[sizeof(_buf) - 1] = '\0';
  183. if (strncmp(buf, "tx ", 3) == 0) {
  184. buf += 3;
  185. tx = true;
  186. } else if (strncmp(buf, "rx ", 3) == 0) {
  187. buf += 3;
  188. tx = false;
  189. } else
  190. return -EINVAL;
  191. if (strncmp(buf, "start ", 6) == 0) {
  192. buf += 6;
  193. start = true;
  194. if (!tx)
  195. return -EINVAL;
  196. } else if (strncmp(buf, "stop ", 5) == 0) {
  197. buf += 5;
  198. start = false;
  199. } else
  200. return -EINVAL;
  201. ret = kstrtoul(buf, 0, &tid);
  202. if (ret)
  203. return ret;
  204. if (tid >= IEEE80211_NUM_TIDS)
  205. return -EINVAL;
  206. if (tx) {
  207. if (start)
  208. ret = ieee80211_start_tx_ba_session(&sta->sta, tid, 5000);
  209. else
  210. ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
  211. } else {
  212. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
  213. 3, true);
  214. ret = 0;
  215. }
  216. return ret ?: count;
  217. }
  218. STA_OPS_RW(agg_status);
  219. static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
  220. size_t count, loff_t *ppos)
  221. {
  222. #define PRINT_HT_CAP(_cond, _str) \
  223. do { \
  224. if (_cond) \
  225. p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
  226. } while (0)
  227. char buf[512], *p = buf;
  228. int i;
  229. struct sta_info *sta = file->private_data;
  230. struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
  231. p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
  232. htc->ht_supported ? "" : "not ");
  233. if (htc->ht_supported) {
  234. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
  235. PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
  236. PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
  237. PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
  238. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
  239. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
  240. PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
  241. PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
  242. PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
  243. PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
  244. PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
  245. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
  246. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
  247. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
  248. PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
  249. PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
  250. PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
  251. "3839 bytes");
  252. PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
  253. "7935 bytes");
  254. /*
  255. * For beacons and probe response this would mean the BSS
  256. * does or does not allow the usage of DSSS/CCK HT40.
  257. * Otherwise it means the STA does or does not use
  258. * DSSS/CCK HT40.
  259. */
  260. PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
  261. PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
  262. /* BIT(13) is reserved */
  263. PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
  264. PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
  265. p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
  266. htc->ampdu_factor, htc->ampdu_density);
  267. p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
  268. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  269. p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
  270. htc->mcs.rx_mask[i]);
  271. p += scnprintf(p, sizeof(buf)+buf-p, "\n");
  272. /* If not set this is meaningless */
  273. if (le16_to_cpu(htc->mcs.rx_highest)) {
  274. p += scnprintf(p, sizeof(buf)+buf-p,
  275. "MCS rx highest: %d Mbps\n",
  276. le16_to_cpu(htc->mcs.rx_highest));
  277. }
  278. p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
  279. htc->mcs.tx_params);
  280. }
  281. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  282. }
  283. STA_OPS(ht_capa);
  284. static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
  285. size_t count, loff_t *ppos)
  286. {
  287. char buf[128], *p = buf;
  288. struct sta_info *sta = file->private_data;
  289. struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
  290. p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
  291. vhtc->vht_supported ? "" : "not ");
  292. if (vhtc->vht_supported) {
  293. p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.8x\n", vhtc->cap);
  294. p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
  295. le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
  296. if (vhtc->vht_mcs.rx_highest)
  297. p += scnprintf(p, sizeof(buf)+buf-p,
  298. "MCS RX highest: %d Mbps\n",
  299. le16_to_cpu(vhtc->vht_mcs.rx_highest));
  300. p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
  301. le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
  302. if (vhtc->vht_mcs.tx_highest)
  303. p += scnprintf(p, sizeof(buf)+buf-p,
  304. "MCS TX highest: %d Mbps\n",
  305. le16_to_cpu(vhtc->vht_mcs.tx_highest));
  306. }
  307. return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
  308. }
  309. STA_OPS(vht_capa);
  310. static ssize_t sta_current_tx_rate_read(struct file *file, char __user *userbuf,
  311. size_t count, loff_t *ppos)
  312. {
  313. struct sta_info *sta = file->private_data;
  314. struct rate_info rinfo;
  315. u16 rate;
  316. sta_set_rate_info_tx(sta, &sta->last_tx_rate, &rinfo);
  317. rate = cfg80211_calculate_bitrate(&rinfo);
  318. return mac80211_format_buffer(userbuf, count, ppos,
  319. "%d.%d MBit/s\n",
  320. rate/10, rate%10);
  321. }
  322. STA_OPS(current_tx_rate);
  323. static ssize_t sta_last_rx_rate_read(struct file *file, char __user *userbuf,
  324. size_t count, loff_t *ppos)
  325. {
  326. struct sta_info *sta = file->private_data;
  327. struct rate_info rinfo;
  328. u16 rate;
  329. sta_set_rate_info_rx(sta, &rinfo);
  330. rate = cfg80211_calculate_bitrate(&rinfo);
  331. return mac80211_format_buffer(userbuf, count, ppos,
  332. "%d.%d MBit/s\n",
  333. rate/10, rate%10);
  334. }
  335. STA_OPS(last_rx_rate);
  336. static int
  337. sta_tx_latency_stat_header(struct ieee80211_tx_latency_bin_ranges *tx_latency,
  338. char *buf, int pos, int bufsz)
  339. {
  340. int i;
  341. int range_count = tx_latency->n_ranges;
  342. u32 *bin_ranges = tx_latency->ranges;
  343. pos += scnprintf(buf + pos, bufsz - pos,
  344. "Station\t\t\tTID\tMax\tAvg");
  345. if (range_count) {
  346. pos += scnprintf(buf + pos, bufsz - pos,
  347. "\t<=%d", bin_ranges[0]);
  348. for (i = 0; i < range_count - 1; i++)
  349. pos += scnprintf(buf + pos, bufsz - pos, "\t%d-%d",
  350. bin_ranges[i], bin_ranges[i+1]);
  351. pos += scnprintf(buf + pos, bufsz - pos,
  352. "\t%d<", bin_ranges[range_count - 1]);
  353. }
  354. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  355. return pos;
  356. }
  357. static int
  358. sta_tx_latency_stat_table(struct ieee80211_tx_latency_bin_ranges *tx_lat_range,
  359. struct ieee80211_tx_latency_stat *tx_lat,
  360. char *buf, int pos, int bufsz, int tid)
  361. {
  362. u32 avg = 0;
  363. int j;
  364. int bin_count = tx_lat->bin_count;
  365. pos += scnprintf(buf + pos, bufsz - pos, "\t\t\t%d", tid);
  366. /* make sure you don't divide in 0 */
  367. if (tx_lat->counter)
  368. avg = tx_lat->sum / tx_lat->counter;
  369. pos += scnprintf(buf + pos, bufsz - pos, "\t%d\t%d",
  370. tx_lat->max, avg);
  371. if (tx_lat_range->n_ranges && tx_lat->bins)
  372. for (j = 0; j < bin_count; j++)
  373. pos += scnprintf(buf + pos, bufsz - pos,
  374. "\t%d", tx_lat->bins[j]);
  375. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  376. return pos;
  377. }
  378. /*
  379. * Output Tx latency statistics station && restart all statistics information
  380. */
  381. static ssize_t sta_tx_latency_stat_read(struct file *file,
  382. char __user *userbuf,
  383. size_t count, loff_t *ppos)
  384. {
  385. struct sta_info *sta = file->private_data;
  386. struct ieee80211_local *local = sta->local;
  387. struct ieee80211_tx_latency_bin_ranges *tx_latency;
  388. char *buf;
  389. int bufsz, ret, i;
  390. int pos = 0;
  391. bufsz = 20 * IEEE80211_NUM_TIDS *
  392. sizeof(struct ieee80211_tx_latency_stat);
  393. buf = kzalloc(bufsz, GFP_KERNEL);
  394. if (!buf)
  395. return -ENOMEM;
  396. rcu_read_lock();
  397. tx_latency = rcu_dereference(local->tx_latency);
  398. if (!sta->tx_lat) {
  399. pos += scnprintf(buf + pos, bufsz - pos,
  400. "Tx latency statistics are not enabled\n");
  401. goto unlock;
  402. }
  403. pos = sta_tx_latency_stat_header(tx_latency, buf, pos, bufsz);
  404. pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", sta->sta.addr);
  405. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  406. pos = sta_tx_latency_stat_table(tx_latency, &sta->tx_lat[i],
  407. buf, pos, bufsz, i);
  408. unlock:
  409. rcu_read_unlock();
  410. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  411. kfree(buf);
  412. return ret;
  413. }
  414. STA_OPS(tx_latency_stat);
  415. static ssize_t sta_tx_latency_stat_reset_write(struct file *file,
  416. const char __user *userbuf,
  417. size_t count, loff_t *ppos)
  418. {
  419. u32 *bins;
  420. int bin_count;
  421. struct sta_info *sta = file->private_data;
  422. int i;
  423. if (!sta->tx_lat)
  424. return -EINVAL;
  425. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  426. bins = sta->tx_lat[i].bins;
  427. bin_count = sta->tx_lat[i].bin_count;
  428. sta->tx_lat[i].max = 0;
  429. sta->tx_lat[i].sum = 0;
  430. sta->tx_lat[i].counter = 0;
  431. if (bin_count)
  432. memset(bins, 0, bin_count * sizeof(u32));
  433. }
  434. return count;
  435. }
  436. STA_OPS_W(tx_latency_stat_reset);
  437. #define DEBUGFS_ADD(name) \
  438. debugfs_create_file(#name, 0400, \
  439. sta->debugfs.dir, sta, &sta_ ##name## _ops);
  440. #define DEBUGFS_ADD_COUNTER(name, field) \
  441. if (sizeof(sta->field) == sizeof(u32)) \
  442. debugfs_create_u32(#name, 0400, sta->debugfs.dir, \
  443. (u32 *) &sta->field); \
  444. else \
  445. debugfs_create_u64(#name, 0400, sta->debugfs.dir, \
  446. (u64 *) &sta->field);
  447. void ieee80211_sta_debugfs_add(struct sta_info *sta)
  448. {
  449. struct ieee80211_local *local = sta->local;
  450. struct ieee80211_sub_if_data *sdata = sta->sdata;
  451. struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
  452. u8 mac[3*ETH_ALEN];
  453. sta->debugfs.add_has_run = true;
  454. if (!stations_dir)
  455. return;
  456. snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
  457. /*
  458. * This might fail due to a race condition:
  459. * When mac80211 unlinks a station, the debugfs entries
  460. * remain, but it is already possible to link a new
  461. * station with the same address which triggers adding
  462. * it to debugfs; therefore, if the old station isn't
  463. * destroyed quickly enough the old station's debugfs
  464. * dir might still be around.
  465. */
  466. sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
  467. if (!sta->debugfs.dir)
  468. return;
  469. DEBUGFS_ADD(flags);
  470. DEBUGFS_ADD(num_ps_buf_frames);
  471. DEBUGFS_ADD(inactive_ms);
  472. DEBUGFS_ADD(connected_time);
  473. DEBUGFS_ADD(last_seq_ctrl);
  474. DEBUGFS_ADD(agg_status);
  475. DEBUGFS_ADD(dev);
  476. DEBUGFS_ADD(last_signal);
  477. DEBUGFS_ADD(beacon_loss_count);
  478. DEBUGFS_ADD(ht_capa);
  479. DEBUGFS_ADD(vht_capa);
  480. DEBUGFS_ADD(last_ack_signal);
  481. DEBUGFS_ADD(current_tx_rate);
  482. DEBUGFS_ADD(last_rx_rate);
  483. DEBUGFS_ADD(tx_latency_stat);
  484. DEBUGFS_ADD(tx_latency_stat_reset);
  485. DEBUGFS_ADD_COUNTER(rx_packets, rx_packets);
  486. DEBUGFS_ADD_COUNTER(tx_packets, tx_packets);
  487. DEBUGFS_ADD_COUNTER(rx_bytes, rx_bytes);
  488. DEBUGFS_ADD_COUNTER(tx_bytes, tx_bytes);
  489. DEBUGFS_ADD_COUNTER(rx_duplicates, num_duplicates);
  490. DEBUGFS_ADD_COUNTER(rx_fragments, rx_fragments);
  491. DEBUGFS_ADD_COUNTER(rx_dropped, rx_dropped);
  492. DEBUGFS_ADD_COUNTER(tx_fragments, tx_fragments);
  493. DEBUGFS_ADD_COUNTER(tx_filtered, tx_filtered_count);
  494. DEBUGFS_ADD_COUNTER(tx_retry_failed, tx_retry_failed);
  495. DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
  496. if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
  497. debugfs_create_x32("driver_buffered_tids", 0400,
  498. sta->debugfs.dir,
  499. (u32 *)&sta->driver_buffered_tids);
  500. else
  501. debugfs_create_x64("driver_buffered_tids", 0400,
  502. sta->debugfs.dir,
  503. (u64 *)&sta->driver_buffered_tids);
  504. drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
  505. }
  506. void ieee80211_sta_debugfs_remove(struct sta_info *sta)
  507. {
  508. struct ieee80211_local *local = sta->local;
  509. struct ieee80211_sub_if_data *sdata = sta->sdata;
  510. drv_sta_remove_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
  511. debugfs_remove_recursive(sta->debugfs.dir);
  512. sta->debugfs.dir = NULL;
  513. }