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