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