xref: /linux/net/mac80211/debugfs_sta.c (revision b68fc09be48edbc47de1a0f3d42ef8adf6c0ac55)
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  * Copyright (C) 2018 Intel Corporation
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 
14 #include <linux/debugfs.h>
15 #include <linux/ieee80211.h>
16 #include "ieee80211_i.h"
17 #include "debugfs.h"
18 #include "debugfs_sta.h"
19 #include "sta_info.h"
20 #include "driver-ops.h"
21 
22 /* sta attributtes */
23 
24 #define STA_READ(name, field, format_string)				\
25 static ssize_t sta_ ##name## _read(struct file *file,			\
26 				   char __user *userbuf,		\
27 				   size_t count, loff_t *ppos)		\
28 {									\
29 	struct sta_info *sta = file->private_data;			\
30 	return mac80211_format_buffer(userbuf, count, ppos, 		\
31 				      format_string, sta->field);	\
32 }
33 #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
34 
35 #define STA_OPS(name)							\
36 static const struct file_operations sta_ ##name## _ops = {		\
37 	.read = sta_##name##_read,					\
38 	.open = simple_open,						\
39 	.llseek = generic_file_llseek,					\
40 }
41 
42 #define STA_OPS_RW(name)						\
43 static const struct file_operations sta_ ##name## _ops = {		\
44 	.read = sta_##name##_read,					\
45 	.write = sta_##name##_write,					\
46 	.open = simple_open,						\
47 	.llseek = generic_file_llseek,					\
48 }
49 
50 #define STA_FILE(name, field, format)					\
51 		STA_READ_##format(name, field)				\
52 		STA_OPS(name)
53 
54 STA_FILE(aid, sta.aid, D);
55 
56 static const char * const sta_flag_names[] = {
57 #define FLAG(F) [WLAN_STA_##F] = #F
58 	FLAG(AUTH),
59 	FLAG(ASSOC),
60 	FLAG(PS_STA),
61 	FLAG(AUTHORIZED),
62 	FLAG(SHORT_PREAMBLE),
63 	FLAG(WDS),
64 	FLAG(CLEAR_PS_FILT),
65 	FLAG(MFP),
66 	FLAG(BLOCK_BA),
67 	FLAG(PS_DRIVER),
68 	FLAG(PSPOLL),
69 	FLAG(TDLS_PEER),
70 	FLAG(TDLS_PEER_AUTH),
71 	FLAG(TDLS_INITIATOR),
72 	FLAG(TDLS_CHAN_SWITCH),
73 	FLAG(TDLS_OFF_CHANNEL),
74 	FLAG(TDLS_WIDER_BW),
75 	FLAG(UAPSD),
76 	FLAG(SP),
77 	FLAG(4ADDR_EVENT),
78 	FLAG(INSERTED),
79 	FLAG(RATE_CONTROL),
80 	FLAG(TOFFSET_KNOWN),
81 	FLAG(MPSP_OWNER),
82 	FLAG(MPSP_RECIPIENT),
83 	FLAG(PS_DELIVER),
84 #undef FLAG
85 };
86 
87 static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
88 			      size_t count, loff_t *ppos)
89 {
90 	char buf[16 * NUM_WLAN_STA_FLAGS], *pos = buf;
91 	char *end = buf + sizeof(buf) - 1;
92 	struct sta_info *sta = file->private_data;
93 	unsigned int flg;
94 
95 	BUILD_BUG_ON(ARRAY_SIZE(sta_flag_names) != NUM_WLAN_STA_FLAGS);
96 
97 	for (flg = 0; flg < NUM_WLAN_STA_FLAGS; flg++) {
98 		if (test_sta_flag(sta, flg))
99 			pos += scnprintf(pos, end - pos, "%s\n",
100 					 sta_flag_names[flg]);
101 	}
102 
103 	return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
104 }
105 STA_OPS(flags);
106 
107 static ssize_t sta_num_ps_buf_frames_read(struct file *file,
108 					  char __user *userbuf,
109 					  size_t count, loff_t *ppos)
110 {
111 	struct sta_info *sta = file->private_data;
112 	char buf[17*IEEE80211_NUM_ACS], *p = buf;
113 	int ac;
114 
115 	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
116 		p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
117 			       skb_queue_len(&sta->ps_tx_buf[ac]) +
118 			       skb_queue_len(&sta->tx_filtered[ac]));
119 	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
120 }
121 STA_OPS(num_ps_buf_frames);
122 
123 static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
124 				      size_t count, loff_t *ppos)
125 {
126 	char buf[15*IEEE80211_NUM_TIDS], *p = buf;
127 	int i;
128 	struct sta_info *sta = file->private_data;
129 	for (i = 0; i < IEEE80211_NUM_TIDS; i++)
130 		p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
131 			       le16_to_cpu(sta->last_seq_ctrl[i]));
132 	p += scnprintf(p, sizeof(buf)+buf-p, "\n");
133 	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
134 }
135 STA_OPS(last_seq_ctrl);
136 
137 #define AQM_TXQ_ENTRY_LEN 130
138 
139 static ssize_t sta_aqm_read(struct file *file, char __user *userbuf,
140 			size_t count, loff_t *ppos)
141 {
142 	struct sta_info *sta = file->private_data;
143 	struct ieee80211_local *local = sta->local;
144 	size_t bufsz = AQM_TXQ_ENTRY_LEN * (IEEE80211_NUM_TIDS + 2);
145 	char *buf = kzalloc(bufsz, GFP_KERNEL), *p = buf;
146 	struct txq_info *txqi;
147 	ssize_t rv;
148 	int i;
149 
150 	if (!buf)
151 		return -ENOMEM;
152 
153 	spin_lock_bh(&local->fq.lock);
154 	rcu_read_lock();
155 
156 	p += scnprintf(p,
157 		       bufsz+buf-p,
158 		       "target %uus interval %uus ecn %s\n",
159 		       codel_time_to_us(sta->cparams.target),
160 		       codel_time_to_us(sta->cparams.interval),
161 		       sta->cparams.ecn ? "yes" : "no");
162 	p += scnprintf(p,
163 		       bufsz+buf-p,
164 		       "tid ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets flags\n");
165 
166 	for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
167 		if (!sta->sta.txq[i])
168 			continue;
169 		txqi = to_txq_info(sta->sta.txq[i]);
170 		p += scnprintf(p, bufsz+buf-p,
171 			       "%d %d %u %u %u %u %u %u %u %u %u 0x%lx(%s%s%s)\n",
172 			       txqi->txq.tid,
173 			       txqi->txq.ac,
174 			       txqi->tin.backlog_bytes,
175 			       txqi->tin.backlog_packets,
176 			       txqi->tin.flows,
177 			       txqi->cstats.drop_count,
178 			       txqi->cstats.ecn_mark,
179 			       txqi->tin.overlimit,
180 			       txqi->tin.collisions,
181 			       txqi->tin.tx_bytes,
182 			       txqi->tin.tx_packets,
183 			       txqi->flags,
184 			       txqi->flags & (1<<IEEE80211_TXQ_STOP) ? "STOP" : "RUN",
185 			       txqi->flags & (1<<IEEE80211_TXQ_AMPDU) ? " AMPDU" : "",
186 			       txqi->flags & (1<<IEEE80211_TXQ_NO_AMSDU) ? " NO-AMSDU" : "");
187 	}
188 
189 	rcu_read_unlock();
190 	spin_unlock_bh(&local->fq.lock);
191 
192 	rv = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
193 	kfree(buf);
194 	return rv;
195 }
196 STA_OPS(aqm);
197 
198 static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
199 					size_t count, loff_t *ppos)
200 {
201 	char buf[71 + IEEE80211_NUM_TIDS * 40], *p = buf;
202 	int i;
203 	struct sta_info *sta = file->private_data;
204 	struct tid_ampdu_rx *tid_rx;
205 	struct tid_ampdu_tx *tid_tx;
206 
207 	rcu_read_lock();
208 
209 	p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
210 			sta->ampdu_mlme.dialog_token_allocator + 1);
211 	p += scnprintf(p, sizeof(buf) + buf - p,
212 		       "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
213 
214 	for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
215 		bool tid_rx_valid;
216 
217 		tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
218 		tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
219 		tid_rx_valid = test_bit(i, sta->ampdu_mlme.agg_session_valid);
220 
221 		p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
222 		p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
223 			       tid_rx_valid);
224 		p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
225 			       tid_rx_valid ?
226 					sta->ampdu_mlme.tid_rx_token[i] : 0);
227 		p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
228 				tid_rx ? tid_rx->ssn : 0);
229 
230 		p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
231 		p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
232 				tid_tx ? tid_tx->dialog_token : 0);
233 		p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
234 				tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
235 		p += scnprintf(p, sizeof(buf) + buf - p, "\n");
236 	}
237 	rcu_read_unlock();
238 
239 	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
240 }
241 
242 static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
243 				    size_t count, loff_t *ppos)
244 {
245 	char _buf[25] = {}, *buf = _buf;
246 	struct sta_info *sta = file->private_data;
247 	bool start, tx;
248 	unsigned long tid;
249 	char *pos;
250 	int ret, timeout = 5000;
251 
252 	if (count > sizeof(_buf))
253 		return -EINVAL;
254 
255 	if (copy_from_user(buf, userbuf, count))
256 		return -EFAULT;
257 
258 	buf[sizeof(_buf) - 1] = '\0';
259 	pos = buf;
260 	buf = strsep(&pos, " ");
261 	if (!buf)
262 		return -EINVAL;
263 
264 	if (!strcmp(buf, "tx"))
265 		tx = true;
266 	else if (!strcmp(buf, "rx"))
267 		tx = false;
268 	else
269 		return -EINVAL;
270 
271 	buf = strsep(&pos, " ");
272 	if (!buf)
273 		return -EINVAL;
274 	if (!strcmp(buf, "start")) {
275 		start = true;
276 		if (!tx)
277 			return -EINVAL;
278 	} else if (!strcmp(buf, "stop")) {
279 		start = false;
280 	} else {
281 		return -EINVAL;
282 	}
283 
284 	buf = strsep(&pos, " ");
285 	if (!buf)
286 		return -EINVAL;
287 	if (sscanf(buf, "timeout=%d", &timeout) == 1) {
288 		buf = strsep(&pos, " ");
289 		if (!buf || !tx || !start)
290 			return -EINVAL;
291 	}
292 
293 	ret = kstrtoul(buf, 0, &tid);
294 	if (ret || tid >= IEEE80211_NUM_TIDS)
295 		return -EINVAL;
296 
297 	if (tx) {
298 		if (start)
299 			ret = ieee80211_start_tx_ba_session(&sta->sta, tid,
300 							    timeout);
301 		else
302 			ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
303 	} else {
304 		__ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
305 					       3, true);
306 		ret = 0;
307 	}
308 
309 	return ret ?: count;
310 }
311 STA_OPS_RW(agg_status);
312 
313 static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
314 				size_t count, loff_t *ppos)
315 {
316 #define PRINT_HT_CAP(_cond, _str) \
317 	do { \
318 	if (_cond) \
319 			p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
320 	} while (0)
321 	char buf[512], *p = buf;
322 	int i;
323 	struct sta_info *sta = file->private_data;
324 	struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
325 
326 	p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
327 			htc->ht_supported ? "" : "not ");
328 	if (htc->ht_supported) {
329 		p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
330 
331 		PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
332 		PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
333 		PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
334 
335 		PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
336 		PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
337 		PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
338 
339 		PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
340 		PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
341 		PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
342 		PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
343 
344 		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
345 		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
346 		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
347 		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
348 
349 		PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
350 
351 		PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
352 			     "3839 bytes");
353 		PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
354 			     "7935 bytes");
355 
356 		/*
357 		 * For beacons and probe response this would mean the BSS
358 		 * does or does not allow the usage of DSSS/CCK HT40.
359 		 * Otherwise it means the STA does or does not use
360 		 * DSSS/CCK HT40.
361 		 */
362 		PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
363 		PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
364 
365 		/* BIT(13) is reserved */
366 
367 		PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
368 
369 		PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
370 
371 		p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
372 				htc->ampdu_factor, htc->ampdu_density);
373 		p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
374 
375 		for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
376 			p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
377 					htc->mcs.rx_mask[i]);
378 		p += scnprintf(p, sizeof(buf)+buf-p, "\n");
379 
380 		/* If not set this is meaningless */
381 		if (le16_to_cpu(htc->mcs.rx_highest)) {
382 			p += scnprintf(p, sizeof(buf)+buf-p,
383 				       "MCS rx highest: %d Mbps\n",
384 				       le16_to_cpu(htc->mcs.rx_highest));
385 		}
386 
387 		p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
388 				htc->mcs.tx_params);
389 	}
390 
391 	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
392 }
393 STA_OPS(ht_capa);
394 
395 static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
396 				 size_t count, loff_t *ppos)
397 {
398 	char buf[512], *p = buf;
399 	struct sta_info *sta = file->private_data;
400 	struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
401 
402 	p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
403 			vhtc->vht_supported ? "" : "not ");
404 	if (vhtc->vht_supported) {
405 		p += scnprintf(p, sizeof(buf) + buf - p, "cap: %#.8x\n",
406 			       vhtc->cap);
407 #define PFLAG(a, b)							\
408 		do {							\
409 			if (vhtc->cap & IEEE80211_VHT_CAP_ ## a)	\
410 				p += scnprintf(p, sizeof(buf) + buf - p, \
411 					       "\t\t%s\n", b);		\
412 		} while (0)
413 
414 		switch (vhtc->cap & 0x3) {
415 		case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
416 			p += scnprintf(p, sizeof(buf) + buf - p,
417 				       "\t\tMAX-MPDU-3895\n");
418 			break;
419 		case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
420 			p += scnprintf(p, sizeof(buf) + buf - p,
421 				       "\t\tMAX-MPDU-7991\n");
422 			break;
423 		case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
424 			p += scnprintf(p, sizeof(buf) + buf - p,
425 				       "\t\tMAX-MPDU-11454\n");
426 			break;
427 		default:
428 			p += scnprintf(p, sizeof(buf) + buf - p,
429 				       "\t\tMAX-MPDU-UNKNOWN\n");
430 		}
431 		switch (vhtc->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
432 		case 0:
433 			p += scnprintf(p, sizeof(buf) + buf - p,
434 				       "\t\t80Mhz\n");
435 			break;
436 		case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
437 			p += scnprintf(p, sizeof(buf) + buf - p,
438 				       "\t\t160Mhz\n");
439 			break;
440 		case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
441 			p += scnprintf(p, sizeof(buf) + buf - p,
442 				       "\t\t80+80Mhz\n");
443 			break;
444 		default:
445 			p += scnprintf(p, sizeof(buf) + buf - p,
446 				       "\t\tUNKNOWN-MHZ: 0x%x\n",
447 				       (vhtc->cap >> 2) & 0x3);
448 		}
449 		PFLAG(RXLDPC, "RXLDPC");
450 		PFLAG(SHORT_GI_80, "SHORT-GI-80");
451 		PFLAG(SHORT_GI_160, "SHORT-GI-160");
452 		PFLAG(TXSTBC, "TXSTBC");
453 		p += scnprintf(p, sizeof(buf) + buf - p,
454 			       "\t\tRXSTBC_%d\n", (vhtc->cap >> 8) & 0x7);
455 		PFLAG(SU_BEAMFORMER_CAPABLE, "SU-BEAMFORMER-CAPABLE");
456 		PFLAG(SU_BEAMFORMEE_CAPABLE, "SU-BEAMFORMEE-CAPABLE");
457 		p += scnprintf(p, sizeof(buf) + buf - p,
458 			"\t\tBEAMFORMEE-STS: 0x%x\n",
459 			(vhtc->cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK) >>
460 			IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
461 		p += scnprintf(p, sizeof(buf) + buf - p,
462 			"\t\tSOUNDING-DIMENSIONS: 0x%x\n",
463 			(vhtc->cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK)
464 			>> IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
465 		PFLAG(MU_BEAMFORMER_CAPABLE, "MU-BEAMFORMER-CAPABLE");
466 		PFLAG(MU_BEAMFORMEE_CAPABLE, "MU-BEAMFORMEE-CAPABLE");
467 		PFLAG(VHT_TXOP_PS, "TXOP-PS");
468 		PFLAG(HTC_VHT, "HTC-VHT");
469 		p += scnprintf(p, sizeof(buf) + buf - p,
470 			"\t\tMPDU-LENGTH-EXPONENT: 0x%x\n",
471 			(vhtc->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
472 			IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
473 		PFLAG(VHT_LINK_ADAPTATION_VHT_UNSOL_MFB,
474 		      "LINK-ADAPTATION-VHT-UNSOL-MFB");
475 		p += scnprintf(p, sizeof(buf) + buf - p,
476 			"\t\tLINK-ADAPTATION-VHT-MRQ-MFB: 0x%x\n",
477 			(vhtc->cap & IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB) >> 26);
478 		PFLAG(RX_ANTENNA_PATTERN, "RX-ANTENNA-PATTERN");
479 		PFLAG(TX_ANTENNA_PATTERN, "TX-ANTENNA-PATTERN");
480 
481 		p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
482 			       le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
483 		if (vhtc->vht_mcs.rx_highest)
484 			p += scnprintf(p, sizeof(buf)+buf-p,
485 				       "MCS RX highest: %d Mbps\n",
486 				       le16_to_cpu(vhtc->vht_mcs.rx_highest));
487 		p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
488 			       le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
489 		if (vhtc->vht_mcs.tx_highest)
490 			p += scnprintf(p, sizeof(buf)+buf-p,
491 				       "MCS TX highest: %d Mbps\n",
492 				       le16_to_cpu(vhtc->vht_mcs.tx_highest));
493 #undef PFLAG
494 	}
495 
496 	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
497 }
498 STA_OPS(vht_capa);
499 
500 static ssize_t sta_he_capa_read(struct file *file, char __user *userbuf,
501 				size_t count, loff_t *ppos)
502 {
503 	char *buf, *p;
504 	size_t buf_sz = PAGE_SIZE;
505 	struct sta_info *sta = file->private_data;
506 	struct ieee80211_sta_he_cap *hec = &sta->sta.he_cap;
507 	struct ieee80211_he_mcs_nss_supp *nss = &hec->he_mcs_nss_supp;
508 	u8 ppe_size;
509 	u8 *cap;
510 	int i;
511 	ssize_t ret;
512 
513 	buf = kmalloc(buf_sz, GFP_KERNEL);
514 	if (!buf)
515 		return -ENOMEM;
516 	p = buf;
517 
518 	p += scnprintf(p, buf_sz + buf - p, "HE %ssupported\n",
519 		       hec->has_he ? "" : "not ");
520 	if (!hec->has_he)
521 		goto out;
522 
523 	cap = hec->he_cap_elem.mac_cap_info;
524 	p += scnprintf(p, buf_sz + buf - p,
525 		       "MAC-CAP: %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x\n",
526 		       cap[0], cap[1], cap[2], cap[3], cap[4], cap[5]);
527 
528 #define PRINT(fmt, ...)							\
529 	p += scnprintf(p, buf_sz + buf - p, "\t\t" fmt "\n",		\
530 		       ##__VA_ARGS__)
531 
532 #define PFLAG(t, n, a, b)						\
533 	do {								\
534 		if (cap[n] & IEEE80211_HE_##t##_CAP##n##_##a)		\
535 			PRINT("%s", b);					\
536 	} while (0)
537 
538 #define PFLAG_RANGE(t, i, n, s, m, off, fmt)				\
539 	do {								\
540 		u8 msk = IEEE80211_HE_##t##_CAP##i##_##n##_MASK;	\
541 		u8 idx = ((cap[i] & msk) >> (ffs(msk) - 1)) + off;	\
542 		PRINT(fmt, (s << idx) + (m * idx));			\
543 	} while (0)
544 
545 #define PFLAG_RANGE_DEFAULT(t, i, n, s, m, off, fmt, a, b)		\
546 	do {								\
547 		if (cap[i] == IEEE80211_HE_##t ##_CAP##i##_##n##_##a) {	\
548 			PRINT("%s", b);					\
549 			break;						\
550 		}							\
551 		PFLAG_RANGE(t, i, n, s, m, off, fmt);			\
552 	} while (0)
553 
554 	PFLAG(MAC, 0, HTC_HE, "HTC-HE");
555 	PFLAG(MAC, 0, TWT_REQ, "TWT-REQ");
556 	PFLAG(MAC, 0, TWT_RES, "TWT-RES");
557 	PFLAG_RANGE_DEFAULT(MAC, 0, DYNAMIC_FRAG, 0, 1, 0,
558 			    "DYNAMIC-FRAG-LEVEL-%d", NOT_SUPP, "NOT-SUPP");
559 	PFLAG_RANGE_DEFAULT(MAC, 0, MAX_NUM_FRAG_MSDU, 1, 0, 0,
560 			    "MAX-NUM-FRAG-MSDU-%d", UNLIMITED, "UNLIMITED");
561 
562 	PFLAG_RANGE_DEFAULT(MAC, 1, MIN_FRAG_SIZE, 128, 0, -1,
563 			    "MIN-FRAG-SIZE-%d", UNLIMITED, "UNLIMITED");
564 	PFLAG_RANGE_DEFAULT(MAC, 1, TF_MAC_PAD_DUR, 0, 8, 0,
565 			    "TF-MAC-PAD-DUR-%dUS", MASK, "UNKNOWN");
566 	PFLAG_RANGE(MAC, 1, MULTI_TID_AGG_RX_QOS, 0, 1, 1,
567 		    "MULTI-TID-AGG-RX-QOS-%d");
568 
569 	if (cap[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) {
570 		switch (((cap[2] << 1) | (cap[1] >> 7)) & 0x3) {
571 		case 0:
572 			PRINT("LINK-ADAPTATION-NO-FEEDBACK");
573 			break;
574 		case 1:
575 			PRINT("LINK-ADAPTATION-RESERVED");
576 			break;
577 		case 2:
578 			PRINT("LINK-ADAPTATION-UNSOLICITED-FEEDBACK");
579 			break;
580 		case 3:
581 			PRINT("LINK-ADAPTATION-BOTH");
582 			break;
583 		}
584 	}
585 
586 	PFLAG(MAC, 2, ALL_ACK, "ALL-ACK");
587 	PFLAG(MAC, 2, TRS, "TRS");
588 	PFLAG(MAC, 2, BSR, "BSR");
589 	PFLAG(MAC, 2, BCAST_TWT, "BCAST-TWT");
590 	PFLAG(MAC, 2, 32BIT_BA_BITMAP, "32BIT-BA-BITMAP");
591 	PFLAG(MAC, 2, MU_CASCADING, "MU-CASCADING");
592 	PFLAG(MAC, 2, ACK_EN, "ACK-EN");
593 
594 	PFLAG(MAC, 3, OMI_CONTROL, "OMI-CONTROL");
595 	PFLAG(MAC, 3, OFDMA_RA, "OFDMA-RA");
596 
597 	switch (cap[3] & IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) {
598 	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_USE_VHT:
599 		PRINT("MAX-AMPDU-LEN-EXP-USE-VHT");
600 		break;
601 	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_1:
602 		PRINT("MAX-AMPDU-LEN-EXP-VHT-1");
603 		break;
604 	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2:
605 		PRINT("MAX-AMPDU-LEN-EXP-VHT-2");
606 		break;
607 	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_RESERVED:
608 		PRINT("MAX-AMPDU-LEN-EXP-RESERVED");
609 		break;
610 	}
611 
612 	PFLAG(MAC, 3, AMSDU_FRAG, "AMSDU-FRAG");
613 	PFLAG(MAC, 3, FLEX_TWT_SCHED, "FLEX-TWT-SCHED");
614 	PFLAG(MAC, 3, RX_CTRL_FRAME_TO_MULTIBSS, "RX-CTRL-FRAME-TO-MULTIBSS");
615 
616 	PFLAG(MAC, 4, BSRP_BQRP_A_MPDU_AGG, "BSRP-BQRP-A-MPDU-AGG");
617 	PFLAG(MAC, 4, QTP, "QTP");
618 	PFLAG(MAC, 4, BQR, "BQR");
619 	PFLAG(MAC, 4, SRP_RESP, "SRP-RESP");
620 	PFLAG(MAC, 4, NDP_FB_REP, "NDP-FB-REP");
621 	PFLAG(MAC, 4, OPS, "OPS");
622 	PFLAG(MAC, 4, AMDSU_IN_AMPDU, "AMSDU-IN-AMPDU");
623 
624 	PRINT("MULTI-TID-AGG-TX-QOS-%d", ((cap[5] << 1) | (cap[4] >> 7)) & 0x7);
625 
626 	PFLAG(MAC, 5, SUBCHAN_SELECVITE_TRANSMISSION,
627 	      "SUBCHAN-SELECVITE-TRANSMISSION");
628 	PFLAG(MAC, 5, UL_2x996_TONE_RU, "UL-2x996-TONE-RU");
629 	PFLAG(MAC, 5, OM_CTRL_UL_MU_DATA_DIS_RX, "OM-CTRL-UL-MU-DATA-DIS-RX");
630 
631 	cap = hec->he_cap_elem.phy_cap_info;
632 	p += scnprintf(p, buf_sz + buf - p,
633 		       "PHY CAP: %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x\n",
634 		       cap[0], cap[1], cap[2], cap[3], cap[4], cap[5], cap[6],
635 		       cap[7], cap[8], cap[9], cap[10]);
636 
637 	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_40MHZ_IN_2G,
638 	      "CHANNEL-WIDTH-SET-40MHZ-IN-2G");
639 	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G,
640 	      "CHANNEL-WIDTH-SET-40MHZ-80MHZ-IN-5G");
641 	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_160MHZ_IN_5G,
642 	      "CHANNEL-WIDTH-SET-160MHZ-IN-5G");
643 	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
644 	      "CHANNEL-WIDTH-SET-80PLUS80-MHZ-IN-5G");
645 	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G,
646 	      "CHANNEL-WIDTH-SET-RU-MAPPING-IN-2G");
647 	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G,
648 	      "CHANNEL-WIDTH-SET-RU-MAPPING-IN-5G");
649 
650 	switch (cap[1] & IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK) {
651 	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_20MHZ:
652 		PRINT("PREAMBLE-PUNC-RX-80MHZ-ONLY-SECOND-20MHZ");
653 		break;
654 	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_40MHZ:
655 		PRINT("PREAMBLE-PUNC-RX-80MHZ-ONLY-SECOND-40MHZ");
656 		break;
657 	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_160MHZ_ONLY_SECOND_20MHZ:
658 		PRINT("PREAMBLE-PUNC-RX-160MHZ-ONLY-SECOND-20MHZ");
659 		break;
660 	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_160MHZ_ONLY_SECOND_40MHZ:
661 		PRINT("PREAMBLE-PUNC-RX-160MHZ-ONLY-SECOND-40MHZ");
662 		break;
663 	}
664 
665 	PFLAG(PHY, 1, DEVICE_CLASS_A,
666 	      "IEEE80211-HE-PHY-CAP1-DEVICE-CLASS-A");
667 	PFLAG(PHY, 1, LDPC_CODING_IN_PAYLOAD,
668 	      "LDPC-CODING-IN-PAYLOAD");
669 	PFLAG(PHY, 1, HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US,
670 	      "HY-CAP1-HE-LTF-AND-GI-FOR-HE-PPDUS-0-8US");
671 	PRINT("MIDAMBLE-RX-MAX-NSTS-%d", ((cap[2] << 1) | (cap[1] >> 7)) & 0x3);
672 
673 	PFLAG(PHY, 2, NDP_4x_LTF_AND_3_2US, "NDP-4X-LTF-AND-3-2US");
674 	PFLAG(PHY, 2, STBC_TX_UNDER_80MHZ, "STBC-TX-UNDER-80MHZ");
675 	PFLAG(PHY, 2, STBC_RX_UNDER_80MHZ, "STBC-RX-UNDER-80MHZ");
676 	PFLAG(PHY, 2, DOPPLER_TX, "DOPPLER-TX");
677 	PFLAG(PHY, 2, DOPPLER_RX, "DOPPLER-RX");
678 	PFLAG(PHY, 2, UL_MU_FULL_MU_MIMO, "UL-MU-FULL-MU-MIMO");
679 	PFLAG(PHY, 2, UL_MU_PARTIAL_MU_MIMO, "UL-MU-PARTIAL-MU-MIMO");
680 
681 	switch (cap[3] & IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK) {
682 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_NO_DCM:
683 		PRINT("DCM-MAX-CONST-TX-NO-DCM");
684 		break;
685 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK:
686 		PRINT("DCM-MAX-CONST-TX-BPSK");
687 		break;
688 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK:
689 		PRINT("DCM-MAX-CONST-TX-QPSK");
690 		break;
691 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_16_QAM:
692 		PRINT("DCM-MAX-CONST-TX-16-QAM");
693 		break;
694 	}
695 
696 	PFLAG(PHY, 3, DCM_MAX_TX_NSS_1, "DCM-MAX-TX-NSS-1");
697 	PFLAG(PHY, 3, DCM_MAX_TX_NSS_2, "DCM-MAX-TX-NSS-2");
698 
699 	switch (cap[3] & IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK) {
700 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_NO_DCM:
701 		PRINT("DCM-MAX-CONST-RX-NO-DCM");
702 		break;
703 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK:
704 		PRINT("DCM-MAX-CONST-RX-BPSK");
705 		break;
706 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK:
707 		PRINT("DCM-MAX-CONST-RX-QPSK");
708 		break;
709 	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM:
710 		PRINT("DCM-MAX-CONST-RX-16-QAM");
711 		break;
712 	}
713 
714 	PFLAG(PHY, 3, DCM_MAX_RX_NSS_1, "DCM-MAX-RX-NSS-1");
715 	PFLAG(PHY, 3, DCM_MAX_RX_NSS_2, "DCM-MAX-RX-NSS-2");
716 	PFLAG(PHY, 3, RX_HE_MU_PPDU_FROM_NON_AP_STA,
717 	      "RX-HE-MU-PPDU-FROM-NON-AP-STA");
718 	PFLAG(PHY, 3, SU_BEAMFORMER, "SU-BEAMFORMER");
719 
720 	PFLAG(PHY, 4, SU_BEAMFORMEE, "SU-BEAMFORMEE");
721 	PFLAG(PHY, 4, MU_BEAMFORMER, "MU-BEAMFORMER");
722 
723 	PFLAG_RANGE(PHY, 4, BEAMFORMEE_MAX_STS_UNDER_80MHZ, 0, 1, 4,
724 		    "BEAMFORMEE-MAX-STS-UNDER-%d");
725 	PFLAG_RANGE(PHY, 4, BEAMFORMEE_MAX_STS_ABOVE_80MHZ, 0, 1, 4,
726 		    "BEAMFORMEE-MAX-STS-ABOVE-%d");
727 
728 	PFLAG_RANGE(PHY, 5, BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ, 0, 1, 1,
729 		    "NUM-SND-DIM-UNDER-80MHZ-%d");
730 	PFLAG_RANGE(PHY, 5, BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ, 0, 1, 1,
731 		    "NUM-SND-DIM-ABOVE-80MHZ-%d");
732 	PFLAG(PHY, 5, NG16_SU_FEEDBACK, "NG16-SU-FEEDBACK");
733 	PFLAG(PHY, 5, NG16_MU_FEEDBACK, "NG16-MU-FEEDBACK");
734 
735 	PFLAG(PHY, 6, CODEBOOK_SIZE_42_SU, "CODEBOOK-SIZE-42-SU");
736 	PFLAG(PHY, 6, CODEBOOK_SIZE_75_MU, "CODEBOOK-SIZE-75-MU");
737 	PFLAG(PHY, 6, TRIG_SU_BEAMFORMER_FB, "TRIG-SU-BEAMFORMER-FB");
738 	PFLAG(PHY, 6, TRIG_MU_BEAMFORMER_FB, "TRIG-MU-BEAMFORMER-FB");
739 	PFLAG(PHY, 6, TRIG_CQI_FB, "TRIG-CQI-FB");
740 	PFLAG(PHY, 6, PARTIAL_BW_EXT_RANGE, "PARTIAL-BW-EXT-RANGE");
741 	PFLAG(PHY, 6, PARTIAL_BANDWIDTH_DL_MUMIMO,
742 	      "PARTIAL-BANDWIDTH-DL-MUMIMO");
743 	PFLAG(PHY, 6, PPE_THRESHOLD_PRESENT, "PPE-THRESHOLD-PRESENT");
744 
745 	PFLAG(PHY, 7, SRP_BASED_SR, "SRP-BASED-SR");
746 	PFLAG(PHY, 7, POWER_BOOST_FACTOR_AR, "POWER-BOOST-FACTOR-AR");
747 	PFLAG(PHY, 7, HE_SU_MU_PPDU_4XLTF_AND_08_US_GI,
748 	      "HE-SU-MU-PPDU-4XLTF-AND-08-US-GI");
749 	PFLAG_RANGE(PHY, 7, MAX_NC, 0, 1, 1, "MAX-NC-%d");
750 	PFLAG(PHY, 7, STBC_TX_ABOVE_80MHZ, "STBC-TX-ABOVE-80MHZ");
751 	PFLAG(PHY, 7, STBC_RX_ABOVE_80MHZ, "STBC-RX-ABOVE-80MHZ");
752 
753 	PFLAG(PHY, 8, HE_ER_SU_PPDU_4XLTF_AND_08_US_GI,
754 	      "HE-ER-SU-PPDU-4XLTF-AND-08-US-GI");
755 	PFLAG(PHY, 8, 20MHZ_IN_40MHZ_HE_PPDU_IN_2G,
756 	      "20MHZ-IN-40MHZ-HE-PPDU-IN-2G");
757 	PFLAG(PHY, 8, 20MHZ_IN_160MHZ_HE_PPDU, "20MHZ-IN-160MHZ-HE-PPDU");
758 	PFLAG(PHY, 8, 80MHZ_IN_160MHZ_HE_PPDU, "80MHZ-IN-160MHZ-HE-PPDU");
759 	PFLAG(PHY, 8, HE_ER_SU_1XLTF_AND_08_US_GI,
760 	      "HE-ER-SU-1XLTF-AND-08-US-GI");
761 	PFLAG(PHY, 8, MIDAMBLE_RX_TX_2X_AND_1XLTF,
762 	      "MIDAMBLE-RX-TX-2X-AND-1XLTF");
763 
764 	switch (cap[8] & IEEE80211_HE_PHY_CAP8_DCM_MAX_BW_MASK) {
765 	case IEEE80211_HE_PHY_CAP8_DCM_MAX_BW_20MHZ:
766 		PRINT("DDCM-MAX-BW-20MHZ");
767 		break;
768 	case IEEE80211_HE_PHY_CAP8_DCM_MAX_BW_40MHZ:
769 		PRINT("DCM-MAX-BW-40MHZ");
770 		break;
771 	case IEEE80211_HE_PHY_CAP8_DCM_MAX_BW_80MHZ:
772 		PRINT("DCM-MAX-BW-80MHZ");
773 		break;
774 	case IEEE80211_HE_PHY_CAP8_DCM_MAX_BW_160_OR_80P80_MHZ:
775 		PRINT("DCM-MAX-BW-160-OR-80P80-MHZ");
776 		break;
777 	}
778 
779 	PFLAG(PHY, 9, LONGER_THAN_16_SIGB_OFDM_SYM,
780 	      "LONGER-THAN-16-SIGB-OFDM-SYM");
781 	PFLAG(PHY, 9, NON_TRIGGERED_CQI_FEEDBACK,
782 	      "NON-TRIGGERED-CQI-FEEDBACK");
783 	PFLAG(PHY, 9, TX_1024_QAM_LESS_THAN_242_TONE_RU,
784 	      "TX-1024-QAM-LESS-THAN-242-TONE-RU");
785 	PFLAG(PHY, 9, RX_1024_QAM_LESS_THAN_242_TONE_RU,
786 	      "RX-1024-QAM-LESS-THAN-242-TONE-RU");
787 	PFLAG(PHY, 9, RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB,
788 	      "RX-FULL-BW-SU-USING-MU-WITH-COMP-SIGB");
789 	PFLAG(PHY, 9, RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB,
790 	      "RX-FULL-BW-SU-USING-MU-WITH-NON-COMP-SIGB");
791 
792 #undef PFLAG_RANGE_DEFAULT
793 #undef PFLAG_RANGE
794 #undef PFLAG
795 
796 #define PRINT_NSS_SUPP(f, n)						\
797 	do {								\
798 		int i;							\
799 		u16 v = le16_to_cpu(nss->f);				\
800 		p += scnprintf(p, buf_sz + buf - p, n ": %#.4x\n", v);	\
801 		for (i = 0; i < 8; i += 2) {				\
802 			switch ((v >> i) & 0x3) {			\
803 			case 0:						\
804 				PRINT(n "-%d-SUPPORT-0-7", i / 2);	\
805 				break;					\
806 			case 1:						\
807 				PRINT(n "-%d-SUPPORT-0-9", i / 2);	\
808 				break;					\
809 			case 2:						\
810 				PRINT(n "-%d-SUPPORT-0-11", i / 2);	\
811 				break;					\
812 			case 3:						\
813 				PRINT(n "-%d-NOT-SUPPORTED", i / 2);	\
814 				break;					\
815 			}						\
816 		}							\
817 	} while (0)
818 
819 	PRINT_NSS_SUPP(rx_mcs_80, "RX-MCS-80");
820 	PRINT_NSS_SUPP(tx_mcs_80, "TX-MCS-80");
821 
822 	if (cap[0] & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) {
823 		PRINT_NSS_SUPP(rx_mcs_160, "RX-MCS-160");
824 		PRINT_NSS_SUPP(tx_mcs_160, "TX-MCS-160");
825 	}
826 
827 	if (cap[0] &
828 	    IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
829 		PRINT_NSS_SUPP(rx_mcs_80p80, "RX-MCS-80P80");
830 		PRINT_NSS_SUPP(tx_mcs_80p80, "TX-MCS-80P80");
831 	}
832 
833 #undef PRINT_NSS_SUPP
834 #undef PRINT
835 
836 	if (!(cap[6] & IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT))
837 		goto out;
838 
839 	p += scnprintf(p, buf_sz + buf - p, "PPE-THRESHOLDS: %#.2x",
840 		       hec->ppe_thres[0]);
841 
842 	ppe_size = ieee80211_he_ppe_size(hec->ppe_thres[0], cap);
843 	for (i = 1; i < ppe_size; i++) {
844 		p += scnprintf(p, buf_sz + buf - p, " %#.2x",
845 			       hec->ppe_thres[i]);
846 	}
847 	p += scnprintf(p, buf_sz + buf - p, "\n");
848 
849 out:
850 	ret = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
851 	kfree(buf);
852 	return ret;
853 }
854 STA_OPS(he_capa);
855 
856 #define DEBUGFS_ADD(name) \
857 	debugfs_create_file(#name, 0400, \
858 		sta->debugfs_dir, sta, &sta_ ##name## _ops);
859 
860 #define DEBUGFS_ADD_COUNTER(name, field)				\
861 	if (sizeof(sta->field) == sizeof(u32))				\
862 		debugfs_create_u32(#name, 0400, sta->debugfs_dir,	\
863 			(u32 *) &sta->field);				\
864 	else								\
865 		debugfs_create_u64(#name, 0400, sta->debugfs_dir,	\
866 			(u64 *) &sta->field);
867 
868 void ieee80211_sta_debugfs_add(struct sta_info *sta)
869 {
870 	struct ieee80211_local *local = sta->local;
871 	struct ieee80211_sub_if_data *sdata = sta->sdata;
872 	struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
873 	u8 mac[3*ETH_ALEN];
874 
875 	if (!stations_dir)
876 		return;
877 
878 	snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
879 
880 	/*
881 	 * This might fail due to a race condition:
882 	 * When mac80211 unlinks a station, the debugfs entries
883 	 * remain, but it is already possible to link a new
884 	 * station with the same address which triggers adding
885 	 * it to debugfs; therefore, if the old station isn't
886 	 * destroyed quickly enough the old station's debugfs
887 	 * dir might still be around.
888 	 */
889 	sta->debugfs_dir = debugfs_create_dir(mac, stations_dir);
890 	if (!sta->debugfs_dir)
891 		return;
892 
893 	DEBUGFS_ADD(flags);
894 	DEBUGFS_ADD(aid);
895 	DEBUGFS_ADD(num_ps_buf_frames);
896 	DEBUGFS_ADD(last_seq_ctrl);
897 	DEBUGFS_ADD(agg_status);
898 	DEBUGFS_ADD(ht_capa);
899 	DEBUGFS_ADD(vht_capa);
900 	DEBUGFS_ADD(he_capa);
901 
902 	DEBUGFS_ADD_COUNTER(rx_duplicates, rx_stats.num_duplicates);
903 	DEBUGFS_ADD_COUNTER(rx_fragments, rx_stats.fragments);
904 	DEBUGFS_ADD_COUNTER(tx_filtered, status_stats.filtered);
905 
906 	if (local->ops->wake_tx_queue)
907 		DEBUGFS_ADD(aqm);
908 
909 	if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
910 		debugfs_create_x32("driver_buffered_tids", 0400,
911 				   sta->debugfs_dir,
912 				   (u32 *)&sta->driver_buffered_tids);
913 	else
914 		debugfs_create_x64("driver_buffered_tids", 0400,
915 				   sta->debugfs_dir,
916 				   (u64 *)&sta->driver_buffered_tids);
917 
918 	drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs_dir);
919 }
920 
921 void ieee80211_sta_debugfs_remove(struct sta_info *sta)
922 {
923 	debugfs_remove_recursive(sta->debugfs_dir);
924 	sta->debugfs_dir = NULL;
925 }
926