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