18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2003-2005	Devicescape Software, Inc.
48c2ecf20Sopenharmony_ci * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
58c2ecf20Sopenharmony_ci * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
68c2ecf20Sopenharmony_ci * Copyright 2013-2014  Intel Mobile Communications GmbH
78c2ecf20Sopenharmony_ci * Copyright(c) 2016 Intel Deutschland GmbH
88c2ecf20Sopenharmony_ci * Copyright (C) 2018 - 2020 Intel Corporation
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
128c2ecf20Sopenharmony_ci#include <linux/ieee80211.h>
138c2ecf20Sopenharmony_ci#include "ieee80211_i.h"
148c2ecf20Sopenharmony_ci#include "debugfs.h"
158c2ecf20Sopenharmony_ci#include "debugfs_sta.h"
168c2ecf20Sopenharmony_ci#include "sta_info.h"
178c2ecf20Sopenharmony_ci#include "driver-ops.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* sta attributtes */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define STA_READ(name, field, format_string)				\
228c2ecf20Sopenharmony_cistatic ssize_t sta_ ##name## _read(struct file *file,			\
238c2ecf20Sopenharmony_ci				   char __user *userbuf,		\
248c2ecf20Sopenharmony_ci				   size_t count, loff_t *ppos)		\
258c2ecf20Sopenharmony_ci{									\
268c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;			\
278c2ecf20Sopenharmony_ci	return mac80211_format_buffer(userbuf, count, ppos, 		\
288c2ecf20Sopenharmony_ci				      format_string, sta->field);	\
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci#define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define STA_OPS(name)							\
338c2ecf20Sopenharmony_cistatic const struct file_operations sta_ ##name## _ops = {		\
348c2ecf20Sopenharmony_ci	.read = sta_##name##_read,					\
358c2ecf20Sopenharmony_ci	.open = simple_open,						\
368c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,					\
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define STA_OPS_RW(name)						\
408c2ecf20Sopenharmony_cistatic const struct file_operations sta_ ##name## _ops = {		\
418c2ecf20Sopenharmony_ci	.read = sta_##name##_read,					\
428c2ecf20Sopenharmony_ci	.write = sta_##name##_write,					\
438c2ecf20Sopenharmony_ci	.open = simple_open,						\
448c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,					\
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define STA_FILE(name, field, format)					\
488c2ecf20Sopenharmony_ci		STA_READ_##format(name, field)				\
498c2ecf20Sopenharmony_ci		STA_OPS(name)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciSTA_FILE(aid, sta.aid, D);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic const char * const sta_flag_names[] = {
548c2ecf20Sopenharmony_ci#define FLAG(F) [WLAN_STA_##F] = #F
558c2ecf20Sopenharmony_ci	FLAG(AUTH),
568c2ecf20Sopenharmony_ci	FLAG(ASSOC),
578c2ecf20Sopenharmony_ci	FLAG(PS_STA),
588c2ecf20Sopenharmony_ci	FLAG(AUTHORIZED),
598c2ecf20Sopenharmony_ci	FLAG(SHORT_PREAMBLE),
608c2ecf20Sopenharmony_ci	FLAG(WDS),
618c2ecf20Sopenharmony_ci	FLAG(CLEAR_PS_FILT),
628c2ecf20Sopenharmony_ci	FLAG(MFP),
638c2ecf20Sopenharmony_ci	FLAG(BLOCK_BA),
648c2ecf20Sopenharmony_ci	FLAG(PS_DRIVER),
658c2ecf20Sopenharmony_ci	FLAG(PSPOLL),
668c2ecf20Sopenharmony_ci	FLAG(TDLS_PEER),
678c2ecf20Sopenharmony_ci	FLAG(TDLS_PEER_AUTH),
688c2ecf20Sopenharmony_ci	FLAG(TDLS_INITIATOR),
698c2ecf20Sopenharmony_ci	FLAG(TDLS_CHAN_SWITCH),
708c2ecf20Sopenharmony_ci	FLAG(TDLS_OFF_CHANNEL),
718c2ecf20Sopenharmony_ci	FLAG(TDLS_WIDER_BW),
728c2ecf20Sopenharmony_ci	FLAG(UAPSD),
738c2ecf20Sopenharmony_ci	FLAG(SP),
748c2ecf20Sopenharmony_ci	FLAG(4ADDR_EVENT),
758c2ecf20Sopenharmony_ci	FLAG(INSERTED),
768c2ecf20Sopenharmony_ci	FLAG(RATE_CONTROL),
778c2ecf20Sopenharmony_ci	FLAG(TOFFSET_KNOWN),
788c2ecf20Sopenharmony_ci	FLAG(MPSP_OWNER),
798c2ecf20Sopenharmony_ci	FLAG(MPSP_RECIPIENT),
808c2ecf20Sopenharmony_ci	FLAG(PS_DELIVER),
818c2ecf20Sopenharmony_ci	FLAG(USES_ENCRYPTION),
828c2ecf20Sopenharmony_ci#undef FLAG
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic ssize_t sta_flags_read(struct file *file, char __user *userbuf,
868c2ecf20Sopenharmony_ci			      size_t count, loff_t *ppos)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	char buf[16 * NUM_WLAN_STA_FLAGS], *pos = buf;
898c2ecf20Sopenharmony_ci	char *end = buf + sizeof(buf) - 1;
908c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
918c2ecf20Sopenharmony_ci	unsigned int flg;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	BUILD_BUG_ON(ARRAY_SIZE(sta_flag_names) != NUM_WLAN_STA_FLAGS);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	for (flg = 0; flg < NUM_WLAN_STA_FLAGS; flg++) {
968c2ecf20Sopenharmony_ci		if (test_sta_flag(sta, flg))
978c2ecf20Sopenharmony_ci			pos += scnprintf(pos, end - pos, "%s\n",
988c2ecf20Sopenharmony_ci					 sta_flag_names[flg]);
998c2ecf20Sopenharmony_ci	}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ciSTA_OPS(flags);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic ssize_t sta_num_ps_buf_frames_read(struct file *file,
1068c2ecf20Sopenharmony_ci					  char __user *userbuf,
1078c2ecf20Sopenharmony_ci					  size_t count, loff_t *ppos)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
1108c2ecf20Sopenharmony_ci	char buf[17*IEEE80211_NUM_ACS], *p = buf;
1118c2ecf20Sopenharmony_ci	int ac;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1148c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
1158c2ecf20Sopenharmony_ci			       skb_queue_len(&sta->ps_tx_buf[ac]) +
1168c2ecf20Sopenharmony_ci			       skb_queue_len(&sta->tx_filtered[ac]));
1178c2ecf20Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ciSTA_OPS(num_ps_buf_frames);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
1228c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	char buf[15*IEEE80211_NUM_TIDS], *p = buf;
1258c2ecf20Sopenharmony_ci	int i;
1268c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
1278c2ecf20Sopenharmony_ci	for (i = 0; i < IEEE80211_NUM_TIDS; i++)
1288c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
1298c2ecf20Sopenharmony_ci			       le16_to_cpu(sta->last_seq_ctrl[i]));
1308c2ecf20Sopenharmony_ci	p += scnprintf(p, sizeof(buf)+buf-p, "\n");
1318c2ecf20Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ciSTA_OPS(last_seq_ctrl);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define AQM_TXQ_ENTRY_LEN 130
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic ssize_t sta_aqm_read(struct file *file, char __user *userbuf,
1388c2ecf20Sopenharmony_ci			size_t count, loff_t *ppos)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
1418c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sta->local;
1428c2ecf20Sopenharmony_ci	size_t bufsz = AQM_TXQ_ENTRY_LEN * (IEEE80211_NUM_TIDS + 2);
1438c2ecf20Sopenharmony_ci	char *buf = kzalloc(bufsz, GFP_KERNEL), *p = buf;
1448c2ecf20Sopenharmony_ci	struct txq_info *txqi;
1458c2ecf20Sopenharmony_ci	ssize_t rv;
1468c2ecf20Sopenharmony_ci	int i;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	if (!buf)
1498c2ecf20Sopenharmony_ci		return -ENOMEM;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	spin_lock_bh(&local->fq.lock);
1528c2ecf20Sopenharmony_ci	rcu_read_lock();
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	p += scnprintf(p,
1558c2ecf20Sopenharmony_ci		       bufsz+buf-p,
1568c2ecf20Sopenharmony_ci		       "target %uus interval %uus ecn %s\n",
1578c2ecf20Sopenharmony_ci		       codel_time_to_us(sta->cparams.target),
1588c2ecf20Sopenharmony_ci		       codel_time_to_us(sta->cparams.interval),
1598c2ecf20Sopenharmony_ci		       sta->cparams.ecn ? "yes" : "no");
1608c2ecf20Sopenharmony_ci	p += scnprintf(p,
1618c2ecf20Sopenharmony_ci		       bufsz+buf-p,
1628c2ecf20Sopenharmony_ci		       "tid ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets flags\n");
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1658c2ecf20Sopenharmony_ci		if (!sta->sta.txq[i])
1668c2ecf20Sopenharmony_ci			continue;
1678c2ecf20Sopenharmony_ci		txqi = to_txq_info(sta->sta.txq[i]);
1688c2ecf20Sopenharmony_ci		p += scnprintf(p, bufsz+buf-p,
1698c2ecf20Sopenharmony_ci			       "%d %d %u %u %u %u %u %u %u %u %u 0x%lx(%s%s%s)\n",
1708c2ecf20Sopenharmony_ci			       txqi->txq.tid,
1718c2ecf20Sopenharmony_ci			       txqi->txq.ac,
1728c2ecf20Sopenharmony_ci			       txqi->tin.backlog_bytes,
1738c2ecf20Sopenharmony_ci			       txqi->tin.backlog_packets,
1748c2ecf20Sopenharmony_ci			       txqi->tin.flows,
1758c2ecf20Sopenharmony_ci			       txqi->cstats.drop_count,
1768c2ecf20Sopenharmony_ci			       txqi->cstats.ecn_mark,
1778c2ecf20Sopenharmony_ci			       txqi->tin.overlimit,
1788c2ecf20Sopenharmony_ci			       txqi->tin.collisions,
1798c2ecf20Sopenharmony_ci			       txqi->tin.tx_bytes,
1808c2ecf20Sopenharmony_ci			       txqi->tin.tx_packets,
1818c2ecf20Sopenharmony_ci			       txqi->flags,
1828c2ecf20Sopenharmony_ci			       test_bit(IEEE80211_TXQ_STOP, &txqi->flags) ? "STOP" : "RUN",
1838c2ecf20Sopenharmony_ci			       test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags) ? " AMPDU" : "",
1848c2ecf20Sopenharmony_ci			       test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags) ? " NO-AMSDU" : "");
1858c2ecf20Sopenharmony_ci	}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	rcu_read_unlock();
1888c2ecf20Sopenharmony_ci	spin_unlock_bh(&local->fq.lock);
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	rv = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
1918c2ecf20Sopenharmony_ci	kfree(buf);
1928c2ecf20Sopenharmony_ci	return rv;
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ciSTA_OPS(aqm);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistatic ssize_t sta_airtime_read(struct file *file, char __user *userbuf,
1978c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
2008c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sta->sdata->local;
2018c2ecf20Sopenharmony_ci	size_t bufsz = 400;
2028c2ecf20Sopenharmony_ci	char *buf = kzalloc(bufsz, GFP_KERNEL), *p = buf;
2038c2ecf20Sopenharmony_ci	u64 rx_airtime = 0, tx_airtime = 0;
2048c2ecf20Sopenharmony_ci	s64 deficit[IEEE80211_NUM_ACS];
2058c2ecf20Sopenharmony_ci	ssize_t rv;
2068c2ecf20Sopenharmony_ci	int ac;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	if (!buf)
2098c2ecf20Sopenharmony_ci		return -ENOMEM;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2128c2ecf20Sopenharmony_ci		spin_lock_bh(&local->active_txq_lock[ac]);
2138c2ecf20Sopenharmony_ci		rx_airtime += sta->airtime[ac].rx_airtime;
2148c2ecf20Sopenharmony_ci		tx_airtime += sta->airtime[ac].tx_airtime;
2158c2ecf20Sopenharmony_ci		deficit[ac] = sta->airtime[ac].deficit;
2168c2ecf20Sopenharmony_ci		spin_unlock_bh(&local->active_txq_lock[ac]);
2178c2ecf20Sopenharmony_ci	}
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	p += scnprintf(p, bufsz + buf - p,
2208c2ecf20Sopenharmony_ci		"RX: %llu us\nTX: %llu us\nWeight: %u\n"
2218c2ecf20Sopenharmony_ci		"Deficit: VO: %lld us VI: %lld us BE: %lld us BK: %lld us\n",
2228c2ecf20Sopenharmony_ci		rx_airtime, tx_airtime, sta->airtime_weight,
2238c2ecf20Sopenharmony_ci		deficit[0], deficit[1], deficit[2], deficit[3]);
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	rv = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
2268c2ecf20Sopenharmony_ci	kfree(buf);
2278c2ecf20Sopenharmony_ci	return rv;
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistatic ssize_t sta_airtime_write(struct file *file, const char __user *userbuf,
2318c2ecf20Sopenharmony_ci				 size_t count, loff_t *ppos)
2328c2ecf20Sopenharmony_ci{
2338c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
2348c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sta->sdata->local;
2358c2ecf20Sopenharmony_ci	int ac;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2388c2ecf20Sopenharmony_ci		spin_lock_bh(&local->active_txq_lock[ac]);
2398c2ecf20Sopenharmony_ci		sta->airtime[ac].rx_airtime = 0;
2408c2ecf20Sopenharmony_ci		sta->airtime[ac].tx_airtime = 0;
2418c2ecf20Sopenharmony_ci		sta->airtime[ac].deficit = sta->airtime_weight;
2428c2ecf20Sopenharmony_ci		spin_unlock_bh(&local->active_txq_lock[ac]);
2438c2ecf20Sopenharmony_ci	}
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	return count;
2468c2ecf20Sopenharmony_ci}
2478c2ecf20Sopenharmony_ciSTA_OPS_RW(airtime);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic ssize_t sta_aql_read(struct file *file, char __user *userbuf,
2508c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
2518c2ecf20Sopenharmony_ci{
2528c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
2538c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sta->sdata->local;
2548c2ecf20Sopenharmony_ci	size_t bufsz = 400;
2558c2ecf20Sopenharmony_ci	char *buf = kzalloc(bufsz, GFP_KERNEL), *p = buf;
2568c2ecf20Sopenharmony_ci	u32 q_depth[IEEE80211_NUM_ACS];
2578c2ecf20Sopenharmony_ci	u32 q_limit_l[IEEE80211_NUM_ACS], q_limit_h[IEEE80211_NUM_ACS];
2588c2ecf20Sopenharmony_ci	ssize_t rv;
2598c2ecf20Sopenharmony_ci	int ac;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	if (!buf)
2628c2ecf20Sopenharmony_ci		return -ENOMEM;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2658c2ecf20Sopenharmony_ci		spin_lock_bh(&local->active_txq_lock[ac]);
2668c2ecf20Sopenharmony_ci		q_limit_l[ac] = sta->airtime[ac].aql_limit_low;
2678c2ecf20Sopenharmony_ci		q_limit_h[ac] = sta->airtime[ac].aql_limit_high;
2688c2ecf20Sopenharmony_ci		spin_unlock_bh(&local->active_txq_lock[ac]);
2698c2ecf20Sopenharmony_ci		q_depth[ac] = atomic_read(&sta->airtime[ac].aql_tx_pending);
2708c2ecf20Sopenharmony_ci	}
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	p += scnprintf(p, bufsz + buf - p,
2738c2ecf20Sopenharmony_ci		"Q depth: VO: %u us VI: %u us BE: %u us BK: %u us\n"
2748c2ecf20Sopenharmony_ci		"Q limit[low/high]: VO: %u/%u VI: %u/%u BE: %u/%u BK: %u/%u\n",
2758c2ecf20Sopenharmony_ci		q_depth[0], q_depth[1], q_depth[2], q_depth[3],
2768c2ecf20Sopenharmony_ci		q_limit_l[0], q_limit_h[0], q_limit_l[1], q_limit_h[1],
2778c2ecf20Sopenharmony_ci		q_limit_l[2], q_limit_h[2], q_limit_l[3], q_limit_h[3]),
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	rv = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
2808c2ecf20Sopenharmony_ci	kfree(buf);
2818c2ecf20Sopenharmony_ci	return rv;
2828c2ecf20Sopenharmony_ci}
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistatic ssize_t sta_aql_write(struct file *file, const char __user *userbuf,
2858c2ecf20Sopenharmony_ci				 size_t count, loff_t *ppos)
2868c2ecf20Sopenharmony_ci{
2878c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
2888c2ecf20Sopenharmony_ci	u32 ac, q_limit_l, q_limit_h;
2898c2ecf20Sopenharmony_ci	char _buf[100] = {}, *buf = _buf;
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	if (count > sizeof(_buf))
2928c2ecf20Sopenharmony_ci		return -EINVAL;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	if (copy_from_user(buf, userbuf, count))
2958c2ecf20Sopenharmony_ci		return -EFAULT;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	buf[sizeof(_buf) - 1] = '\0';
2988c2ecf20Sopenharmony_ci	if (sscanf(buf, "limit %u %u %u", &ac, &q_limit_l, &q_limit_h)
2998c2ecf20Sopenharmony_ci	    != 3)
3008c2ecf20Sopenharmony_ci		return -EINVAL;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	if (ac >= IEEE80211_NUM_ACS)
3038c2ecf20Sopenharmony_ci		return -EINVAL;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	sta->airtime[ac].aql_limit_low = q_limit_l;
3068c2ecf20Sopenharmony_ci	sta->airtime[ac].aql_limit_high = q_limit_h;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	return count;
3098c2ecf20Sopenharmony_ci}
3108c2ecf20Sopenharmony_ciSTA_OPS_RW(aql);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
3148c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	char buf[71 + IEEE80211_NUM_TIDS * 40], *p = buf;
3178c2ecf20Sopenharmony_ci	int i;
3188c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
3198c2ecf20Sopenharmony_ci	struct tid_ampdu_rx *tid_rx;
3208c2ecf20Sopenharmony_ci	struct tid_ampdu_tx *tid_tx;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	rcu_read_lock();
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci	p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
3258c2ecf20Sopenharmony_ci			sta->ampdu_mlme.dialog_token_allocator + 1);
3268c2ecf20Sopenharmony_ci	p += scnprintf(p, sizeof(buf) + buf - p,
3278c2ecf20Sopenharmony_ci		       "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
3308c2ecf20Sopenharmony_ci		bool tid_rx_valid;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci		tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
3338c2ecf20Sopenharmony_ci		tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
3348c2ecf20Sopenharmony_ci		tid_rx_valid = test_bit(i, sta->ampdu_mlme.agg_session_valid);
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
3378c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
3388c2ecf20Sopenharmony_ci			       tid_rx_valid);
3398c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
3408c2ecf20Sopenharmony_ci			       tid_rx_valid ?
3418c2ecf20Sopenharmony_ci					sta->ampdu_mlme.tid_rx_token[i] : 0);
3428c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
3438c2ecf20Sopenharmony_ci				tid_rx ? tid_rx->ssn : 0);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
3468c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
3478c2ecf20Sopenharmony_ci				tid_tx ? tid_tx->dialog_token : 0);
3488c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
3498c2ecf20Sopenharmony_ci				tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
3508c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "\n");
3518c2ecf20Sopenharmony_ci	}
3528c2ecf20Sopenharmony_ci	rcu_read_unlock();
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
3558c2ecf20Sopenharmony_ci}
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_cistatic ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
3588c2ecf20Sopenharmony_ci				    size_t count, loff_t *ppos)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	char _buf[25] = {}, *buf = _buf;
3618c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
3628c2ecf20Sopenharmony_ci	bool start, tx;
3638c2ecf20Sopenharmony_ci	unsigned long tid;
3648c2ecf20Sopenharmony_ci	char *pos;
3658c2ecf20Sopenharmony_ci	int ret, timeout = 5000;
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	if (count > sizeof(_buf))
3688c2ecf20Sopenharmony_ci		return -EINVAL;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	if (copy_from_user(buf, userbuf, count))
3718c2ecf20Sopenharmony_ci		return -EFAULT;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	buf[sizeof(_buf) - 1] = '\0';
3748c2ecf20Sopenharmony_ci	pos = buf;
3758c2ecf20Sopenharmony_ci	buf = strsep(&pos, " ");
3768c2ecf20Sopenharmony_ci	if (!buf)
3778c2ecf20Sopenharmony_ci		return -EINVAL;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	if (!strcmp(buf, "tx"))
3808c2ecf20Sopenharmony_ci		tx = true;
3818c2ecf20Sopenharmony_ci	else if (!strcmp(buf, "rx"))
3828c2ecf20Sopenharmony_ci		tx = false;
3838c2ecf20Sopenharmony_ci	else
3848c2ecf20Sopenharmony_ci		return -EINVAL;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	buf = strsep(&pos, " ");
3878c2ecf20Sopenharmony_ci	if (!buf)
3888c2ecf20Sopenharmony_ci		return -EINVAL;
3898c2ecf20Sopenharmony_ci	if (!strcmp(buf, "start")) {
3908c2ecf20Sopenharmony_ci		start = true;
3918c2ecf20Sopenharmony_ci		if (!tx)
3928c2ecf20Sopenharmony_ci			return -EINVAL;
3938c2ecf20Sopenharmony_ci	} else if (!strcmp(buf, "stop")) {
3948c2ecf20Sopenharmony_ci		start = false;
3958c2ecf20Sopenharmony_ci	} else {
3968c2ecf20Sopenharmony_ci		return -EINVAL;
3978c2ecf20Sopenharmony_ci	}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	buf = strsep(&pos, " ");
4008c2ecf20Sopenharmony_ci	if (!buf)
4018c2ecf20Sopenharmony_ci		return -EINVAL;
4028c2ecf20Sopenharmony_ci	if (sscanf(buf, "timeout=%d", &timeout) == 1) {
4038c2ecf20Sopenharmony_ci		buf = strsep(&pos, " ");
4048c2ecf20Sopenharmony_ci		if (!buf || !tx || !start)
4058c2ecf20Sopenharmony_ci			return -EINVAL;
4068c2ecf20Sopenharmony_ci	}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	ret = kstrtoul(buf, 0, &tid);
4098c2ecf20Sopenharmony_ci	if (ret || tid >= IEEE80211_NUM_TIDS)
4108c2ecf20Sopenharmony_ci		return -EINVAL;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	if (tx) {
4138c2ecf20Sopenharmony_ci		if (start)
4148c2ecf20Sopenharmony_ci			ret = ieee80211_start_tx_ba_session(&sta->sta, tid,
4158c2ecf20Sopenharmony_ci							    timeout);
4168c2ecf20Sopenharmony_ci		else
4178c2ecf20Sopenharmony_ci			ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
4188c2ecf20Sopenharmony_ci	} else {
4198c2ecf20Sopenharmony_ci		__ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
4208c2ecf20Sopenharmony_ci					       3, true);
4218c2ecf20Sopenharmony_ci		ret = 0;
4228c2ecf20Sopenharmony_ci	}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	return ret ?: count;
4258c2ecf20Sopenharmony_ci}
4268c2ecf20Sopenharmony_ciSTA_OPS_RW(agg_status);
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_cistatic ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
4298c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
4308c2ecf20Sopenharmony_ci{
4318c2ecf20Sopenharmony_ci#define PRINT_HT_CAP(_cond, _str) \
4328c2ecf20Sopenharmony_ci	do { \
4338c2ecf20Sopenharmony_ci	if (_cond) \
4348c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
4358c2ecf20Sopenharmony_ci	} while (0)
4368c2ecf20Sopenharmony_ci	char buf[512], *p = buf;
4378c2ecf20Sopenharmony_ci	int i;
4388c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
4398c2ecf20Sopenharmony_ci	struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
4428c2ecf20Sopenharmony_ci			htc->ht_supported ? "" : "not ");
4438c2ecf20Sopenharmony_ci	if (htc->ht_supported) {
4448c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
4478c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
4488c2ecf20Sopenharmony_ci		PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
4518c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
4528c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
4558c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
4568c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
4578c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
4608c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
4618c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
4628c2ecf20Sopenharmony_ci		PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci		PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
4678c2ecf20Sopenharmony_ci			     "3839 bytes");
4688c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
4698c2ecf20Sopenharmony_ci			     "7935 bytes");
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci		/*
4728c2ecf20Sopenharmony_ci		 * For beacons and probe response this would mean the BSS
4738c2ecf20Sopenharmony_ci		 * does or does not allow the usage of DSSS/CCK HT40.
4748c2ecf20Sopenharmony_ci		 * Otherwise it means the STA does or does not use
4758c2ecf20Sopenharmony_ci		 * DSSS/CCK HT40.
4768c2ecf20Sopenharmony_ci		 */
4778c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
4788c2ecf20Sopenharmony_ci		PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci		/* BIT(13) is reserved */
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci		PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
4878c2ecf20Sopenharmony_ci				htc->ampdu_factor, htc->ampdu_density);
4888c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci		for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4918c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
4928c2ecf20Sopenharmony_ci					htc->mcs.rx_mask[i]);
4938c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "\n");
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci		/* If not set this is meaningless */
4968c2ecf20Sopenharmony_ci		if (le16_to_cpu(htc->mcs.rx_highest)) {
4978c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf)+buf-p,
4988c2ecf20Sopenharmony_ci				       "MCS rx highest: %d Mbps\n",
4998c2ecf20Sopenharmony_ci				       le16_to_cpu(htc->mcs.rx_highest));
5008c2ecf20Sopenharmony_ci		}
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
5038c2ecf20Sopenharmony_ci				htc->mcs.tx_params);
5048c2ecf20Sopenharmony_ci	}
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
5078c2ecf20Sopenharmony_ci}
5088c2ecf20Sopenharmony_ciSTA_OPS(ht_capa);
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_cistatic ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
5118c2ecf20Sopenharmony_ci				 size_t count, loff_t *ppos)
5128c2ecf20Sopenharmony_ci{
5138c2ecf20Sopenharmony_ci	char buf[512], *p = buf;
5148c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
5158c2ecf20Sopenharmony_ci	struct ieee80211_sta_vht_cap *vhtc = &sta->sta.vht_cap;
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	p += scnprintf(p, sizeof(buf) + buf - p, "VHT %ssupported\n",
5188c2ecf20Sopenharmony_ci			vhtc->vht_supported ? "" : "not ");
5198c2ecf20Sopenharmony_ci	if (vhtc->vht_supported) {
5208c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p, "cap: %#.8x\n",
5218c2ecf20Sopenharmony_ci			       vhtc->cap);
5228c2ecf20Sopenharmony_ci#define PFLAG(a, b)							\
5238c2ecf20Sopenharmony_ci		do {							\
5248c2ecf20Sopenharmony_ci			if (vhtc->cap & IEEE80211_VHT_CAP_ ## a)	\
5258c2ecf20Sopenharmony_ci				p += scnprintf(p, sizeof(buf) + buf - p, \
5268c2ecf20Sopenharmony_ci					       "\t\t%s\n", b);		\
5278c2ecf20Sopenharmony_ci		} while (0)
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci		switch (vhtc->cap & 0x3) {
5308c2ecf20Sopenharmony_ci		case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
5318c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5328c2ecf20Sopenharmony_ci				       "\t\tMAX-MPDU-3895\n");
5338c2ecf20Sopenharmony_ci			break;
5348c2ecf20Sopenharmony_ci		case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
5358c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5368c2ecf20Sopenharmony_ci				       "\t\tMAX-MPDU-7991\n");
5378c2ecf20Sopenharmony_ci			break;
5388c2ecf20Sopenharmony_ci		case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
5398c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5408c2ecf20Sopenharmony_ci				       "\t\tMAX-MPDU-11454\n");
5418c2ecf20Sopenharmony_ci			break;
5428c2ecf20Sopenharmony_ci		default:
5438c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5448c2ecf20Sopenharmony_ci				       "\t\tMAX-MPDU-UNKNOWN\n");
5458c2ecf20Sopenharmony_ci		}
5468c2ecf20Sopenharmony_ci		switch (vhtc->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
5478c2ecf20Sopenharmony_ci		case 0:
5488c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5498c2ecf20Sopenharmony_ci				       "\t\t80Mhz\n");
5508c2ecf20Sopenharmony_ci			break;
5518c2ecf20Sopenharmony_ci		case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
5528c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5538c2ecf20Sopenharmony_ci				       "\t\t160Mhz\n");
5548c2ecf20Sopenharmony_ci			break;
5558c2ecf20Sopenharmony_ci		case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
5568c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5578c2ecf20Sopenharmony_ci				       "\t\t80+80Mhz\n");
5588c2ecf20Sopenharmony_ci			break;
5598c2ecf20Sopenharmony_ci		default:
5608c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf) + buf - p,
5618c2ecf20Sopenharmony_ci				       "\t\tUNKNOWN-MHZ: 0x%x\n",
5628c2ecf20Sopenharmony_ci				       (vhtc->cap >> 2) & 0x3);
5638c2ecf20Sopenharmony_ci		}
5648c2ecf20Sopenharmony_ci		PFLAG(RXLDPC, "RXLDPC");
5658c2ecf20Sopenharmony_ci		PFLAG(SHORT_GI_80, "SHORT-GI-80");
5668c2ecf20Sopenharmony_ci		PFLAG(SHORT_GI_160, "SHORT-GI-160");
5678c2ecf20Sopenharmony_ci		PFLAG(TXSTBC, "TXSTBC");
5688c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p,
5698c2ecf20Sopenharmony_ci			       "\t\tRXSTBC_%d\n", (vhtc->cap >> 8) & 0x7);
5708c2ecf20Sopenharmony_ci		PFLAG(SU_BEAMFORMER_CAPABLE, "SU-BEAMFORMER-CAPABLE");
5718c2ecf20Sopenharmony_ci		PFLAG(SU_BEAMFORMEE_CAPABLE, "SU-BEAMFORMEE-CAPABLE");
5728c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p,
5738c2ecf20Sopenharmony_ci			"\t\tBEAMFORMEE-STS: 0x%x\n",
5748c2ecf20Sopenharmony_ci			(vhtc->cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK) >>
5758c2ecf20Sopenharmony_ci			IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
5768c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p,
5778c2ecf20Sopenharmony_ci			"\t\tSOUNDING-DIMENSIONS: 0x%x\n",
5788c2ecf20Sopenharmony_ci			(vhtc->cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK)
5798c2ecf20Sopenharmony_ci			>> IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
5808c2ecf20Sopenharmony_ci		PFLAG(MU_BEAMFORMER_CAPABLE, "MU-BEAMFORMER-CAPABLE");
5818c2ecf20Sopenharmony_ci		PFLAG(MU_BEAMFORMEE_CAPABLE, "MU-BEAMFORMEE-CAPABLE");
5828c2ecf20Sopenharmony_ci		PFLAG(VHT_TXOP_PS, "TXOP-PS");
5838c2ecf20Sopenharmony_ci		PFLAG(HTC_VHT, "HTC-VHT");
5848c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p,
5858c2ecf20Sopenharmony_ci			"\t\tMPDU-LENGTH-EXPONENT: 0x%x\n",
5868c2ecf20Sopenharmony_ci			(vhtc->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
5878c2ecf20Sopenharmony_ci			IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
5888c2ecf20Sopenharmony_ci		PFLAG(VHT_LINK_ADAPTATION_VHT_UNSOL_MFB,
5898c2ecf20Sopenharmony_ci		      "LINK-ADAPTATION-VHT-UNSOL-MFB");
5908c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf) + buf - p,
5918c2ecf20Sopenharmony_ci			"\t\tLINK-ADAPTATION-VHT-MRQ-MFB: 0x%x\n",
5928c2ecf20Sopenharmony_ci			(vhtc->cap & IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB) >> 26);
5938c2ecf20Sopenharmony_ci		PFLAG(RX_ANTENNA_PATTERN, "RX-ANTENNA-PATTERN");
5948c2ecf20Sopenharmony_ci		PFLAG(TX_ANTENNA_PATTERN, "TX-ANTENNA-PATTERN");
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "RX MCS: %.4x\n",
5978c2ecf20Sopenharmony_ci			       le16_to_cpu(vhtc->vht_mcs.rx_mcs_map));
5988c2ecf20Sopenharmony_ci		if (vhtc->vht_mcs.rx_highest)
5998c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf)+buf-p,
6008c2ecf20Sopenharmony_ci				       "MCS RX highest: %d Mbps\n",
6018c2ecf20Sopenharmony_ci				       le16_to_cpu(vhtc->vht_mcs.rx_highest));
6028c2ecf20Sopenharmony_ci		p += scnprintf(p, sizeof(buf)+buf-p, "TX MCS: %.4x\n",
6038c2ecf20Sopenharmony_ci			       le16_to_cpu(vhtc->vht_mcs.tx_mcs_map));
6048c2ecf20Sopenharmony_ci		if (vhtc->vht_mcs.tx_highest)
6058c2ecf20Sopenharmony_ci			p += scnprintf(p, sizeof(buf)+buf-p,
6068c2ecf20Sopenharmony_ci				       "MCS TX highest: %d Mbps\n",
6078c2ecf20Sopenharmony_ci				       le16_to_cpu(vhtc->vht_mcs.tx_highest));
6088c2ecf20Sopenharmony_ci#undef PFLAG
6098c2ecf20Sopenharmony_ci	}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
6128c2ecf20Sopenharmony_ci}
6138c2ecf20Sopenharmony_ciSTA_OPS(vht_capa);
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_cistatic ssize_t sta_he_capa_read(struct file *file, char __user *userbuf,
6168c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
6178c2ecf20Sopenharmony_ci{
6188c2ecf20Sopenharmony_ci	char *buf, *p;
6198c2ecf20Sopenharmony_ci	size_t buf_sz = PAGE_SIZE;
6208c2ecf20Sopenharmony_ci	struct sta_info *sta = file->private_data;
6218c2ecf20Sopenharmony_ci	struct ieee80211_sta_he_cap *hec = &sta->sta.he_cap;
6228c2ecf20Sopenharmony_ci	struct ieee80211_he_mcs_nss_supp *nss = &hec->he_mcs_nss_supp;
6238c2ecf20Sopenharmony_ci	u8 ppe_size;
6248c2ecf20Sopenharmony_ci	u8 *cap;
6258c2ecf20Sopenharmony_ci	int i;
6268c2ecf20Sopenharmony_ci	ssize_t ret;
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci	buf = kmalloc(buf_sz, GFP_KERNEL);
6298c2ecf20Sopenharmony_ci	if (!buf)
6308c2ecf20Sopenharmony_ci		return -ENOMEM;
6318c2ecf20Sopenharmony_ci	p = buf;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	p += scnprintf(p, buf_sz + buf - p, "HE %ssupported\n",
6348c2ecf20Sopenharmony_ci		       hec->has_he ? "" : "not ");
6358c2ecf20Sopenharmony_ci	if (!hec->has_he)
6368c2ecf20Sopenharmony_ci		goto out;
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	cap = hec->he_cap_elem.mac_cap_info;
6398c2ecf20Sopenharmony_ci	p += scnprintf(p, buf_sz + buf - p,
6408c2ecf20Sopenharmony_ci		       "MAC-CAP: %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x\n",
6418c2ecf20Sopenharmony_ci		       cap[0], cap[1], cap[2], cap[3], cap[4], cap[5]);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci#define PRINT(fmt, ...)							\
6448c2ecf20Sopenharmony_ci	p += scnprintf(p, buf_sz + buf - p, "\t\t" fmt "\n",		\
6458c2ecf20Sopenharmony_ci		       ##__VA_ARGS__)
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci#define PFLAG(t, n, a, b)						\
6488c2ecf20Sopenharmony_ci	do {								\
6498c2ecf20Sopenharmony_ci		if (cap[n] & IEEE80211_HE_##t##_CAP##n##_##a)		\
6508c2ecf20Sopenharmony_ci			PRINT("%s", b);					\
6518c2ecf20Sopenharmony_ci	} while (0)
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci#define PFLAG_RANGE(t, i, n, s, m, off, fmt)				\
6548c2ecf20Sopenharmony_ci	do {								\
6558c2ecf20Sopenharmony_ci		u8 msk = IEEE80211_HE_##t##_CAP##i##_##n##_MASK;	\
6568c2ecf20Sopenharmony_ci		u8 idx = ((cap[i] & msk) >> (ffs(msk) - 1)) + off;	\
6578c2ecf20Sopenharmony_ci		PRINT(fmt, (s << idx) + (m * idx));			\
6588c2ecf20Sopenharmony_ci	} while (0)
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci#define PFLAG_RANGE_DEFAULT(t, i, n, s, m, off, fmt, a, b)		\
6618c2ecf20Sopenharmony_ci	do {								\
6628c2ecf20Sopenharmony_ci		if (cap[i] == IEEE80211_HE_##t ##_CAP##i##_##n##_##a) {	\
6638c2ecf20Sopenharmony_ci			PRINT("%s", b);					\
6648c2ecf20Sopenharmony_ci			break;						\
6658c2ecf20Sopenharmony_ci		}							\
6668c2ecf20Sopenharmony_ci		PFLAG_RANGE(t, i, n, s, m, off, fmt);			\
6678c2ecf20Sopenharmony_ci	} while (0)
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci	PFLAG(MAC, 0, HTC_HE, "HTC-HE");
6708c2ecf20Sopenharmony_ci	PFLAG(MAC, 0, TWT_REQ, "TWT-REQ");
6718c2ecf20Sopenharmony_ci	PFLAG(MAC, 0, TWT_RES, "TWT-RES");
6728c2ecf20Sopenharmony_ci	PFLAG_RANGE_DEFAULT(MAC, 0, DYNAMIC_FRAG, 0, 1, 0,
6738c2ecf20Sopenharmony_ci			    "DYNAMIC-FRAG-LEVEL-%d", NOT_SUPP, "NOT-SUPP");
6748c2ecf20Sopenharmony_ci	PFLAG_RANGE_DEFAULT(MAC, 0, MAX_NUM_FRAG_MSDU, 1, 0, 0,
6758c2ecf20Sopenharmony_ci			    "MAX-NUM-FRAG-MSDU-%d", UNLIMITED, "UNLIMITED");
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci	PFLAG_RANGE_DEFAULT(MAC, 1, MIN_FRAG_SIZE, 128, 0, -1,
6788c2ecf20Sopenharmony_ci			    "MIN-FRAG-SIZE-%d", UNLIMITED, "UNLIMITED");
6798c2ecf20Sopenharmony_ci	PFLAG_RANGE_DEFAULT(MAC, 1, TF_MAC_PAD_DUR, 0, 8, 0,
6808c2ecf20Sopenharmony_ci			    "TF-MAC-PAD-DUR-%dUS", MASK, "UNKNOWN");
6818c2ecf20Sopenharmony_ci	PFLAG_RANGE(MAC, 1, MULTI_TID_AGG_RX_QOS, 0, 1, 1,
6828c2ecf20Sopenharmony_ci		    "MULTI-TID-AGG-RX-QOS-%d");
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	if (cap[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) {
6858c2ecf20Sopenharmony_ci		switch (((cap[2] << 1) | (cap[1] >> 7)) & 0x3) {
6868c2ecf20Sopenharmony_ci		case 0:
6878c2ecf20Sopenharmony_ci			PRINT("LINK-ADAPTATION-NO-FEEDBACK");
6888c2ecf20Sopenharmony_ci			break;
6898c2ecf20Sopenharmony_ci		case 1:
6908c2ecf20Sopenharmony_ci			PRINT("LINK-ADAPTATION-RESERVED");
6918c2ecf20Sopenharmony_ci			break;
6928c2ecf20Sopenharmony_ci		case 2:
6938c2ecf20Sopenharmony_ci			PRINT("LINK-ADAPTATION-UNSOLICITED-FEEDBACK");
6948c2ecf20Sopenharmony_ci			break;
6958c2ecf20Sopenharmony_ci		case 3:
6968c2ecf20Sopenharmony_ci			PRINT("LINK-ADAPTATION-BOTH");
6978c2ecf20Sopenharmony_ci			break;
6988c2ecf20Sopenharmony_ci		}
6998c2ecf20Sopenharmony_ci	}
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, ALL_ACK, "ALL-ACK");
7028c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, TRS, "TRS");
7038c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, BSR, "BSR");
7048c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, BCAST_TWT, "BCAST-TWT");
7058c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, 32BIT_BA_BITMAP, "32BIT-BA-BITMAP");
7068c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, MU_CASCADING, "MU-CASCADING");
7078c2ecf20Sopenharmony_ci	PFLAG(MAC, 2, ACK_EN, "ACK-EN");
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	PFLAG(MAC, 3, OMI_CONTROL, "OMI-CONTROL");
7108c2ecf20Sopenharmony_ci	PFLAG(MAC, 3, OFDMA_RA, "OFDMA-RA");
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	switch (cap[3] & IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) {
7138c2ecf20Sopenharmony_ci	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_USE_VHT:
7148c2ecf20Sopenharmony_ci		PRINT("MAX-AMPDU-LEN-EXP-USE-VHT");
7158c2ecf20Sopenharmony_ci		break;
7168c2ecf20Sopenharmony_ci	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_1:
7178c2ecf20Sopenharmony_ci		PRINT("MAX-AMPDU-LEN-EXP-VHT-1");
7188c2ecf20Sopenharmony_ci		break;
7198c2ecf20Sopenharmony_ci	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2:
7208c2ecf20Sopenharmony_ci		PRINT("MAX-AMPDU-LEN-EXP-VHT-2");
7218c2ecf20Sopenharmony_ci		break;
7228c2ecf20Sopenharmony_ci	case IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_RESERVED:
7238c2ecf20Sopenharmony_ci		PRINT("MAX-AMPDU-LEN-EXP-RESERVED");
7248c2ecf20Sopenharmony_ci		break;
7258c2ecf20Sopenharmony_ci	}
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	PFLAG(MAC, 3, AMSDU_FRAG, "AMSDU-FRAG");
7288c2ecf20Sopenharmony_ci	PFLAG(MAC, 3, FLEX_TWT_SCHED, "FLEX-TWT-SCHED");
7298c2ecf20Sopenharmony_ci	PFLAG(MAC, 3, RX_CTRL_FRAME_TO_MULTIBSS, "RX-CTRL-FRAME-TO-MULTIBSS");
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, BSRP_BQRP_A_MPDU_AGG, "BSRP-BQRP-A-MPDU-AGG");
7328c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, QTP, "QTP");
7338c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, BQR, "BQR");
7348c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, SRP_RESP, "SRP-RESP");
7358c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, NDP_FB_REP, "NDP-FB-REP");
7368c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, OPS, "OPS");
7378c2ecf20Sopenharmony_ci	PFLAG(MAC, 4, AMDSU_IN_AMPDU, "AMSDU-IN-AMPDU");
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	PRINT("MULTI-TID-AGG-TX-QOS-%d", ((cap[5] << 1) | (cap[4] >> 7)) & 0x7);
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	PFLAG(MAC, 5, SUBCHAN_SELECVITE_TRANSMISSION,
7428c2ecf20Sopenharmony_ci	      "SUBCHAN-SELECVITE-TRANSMISSION");
7438c2ecf20Sopenharmony_ci	PFLAG(MAC, 5, UL_2x996_TONE_RU, "UL-2x996-TONE-RU");
7448c2ecf20Sopenharmony_ci	PFLAG(MAC, 5, OM_CTRL_UL_MU_DATA_DIS_RX, "OM-CTRL-UL-MU-DATA-DIS-RX");
7458c2ecf20Sopenharmony_ci	PFLAG(MAC, 5, HE_DYNAMIC_SM_PS, "HE-DYNAMIC-SM-PS");
7468c2ecf20Sopenharmony_ci	PFLAG(MAC, 5, PUNCTURED_SOUNDING, "PUNCTURED-SOUNDING");
7478c2ecf20Sopenharmony_ci	PFLAG(MAC, 5, HT_VHT_TRIG_FRAME_RX, "HT-VHT-TRIG-FRAME-RX");
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci	cap = hec->he_cap_elem.phy_cap_info;
7508c2ecf20Sopenharmony_ci	p += scnprintf(p, buf_sz + buf - p,
7518c2ecf20Sopenharmony_ci		       "PHY CAP: %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x %#.2x\n",
7528c2ecf20Sopenharmony_ci		       cap[0], cap[1], cap[2], cap[3], cap[4], cap[5], cap[6],
7538c2ecf20Sopenharmony_ci		       cap[7], cap[8], cap[9], cap[10]);
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_40MHZ_IN_2G,
7568c2ecf20Sopenharmony_ci	      "CHANNEL-WIDTH-SET-40MHZ-IN-2G");
7578c2ecf20Sopenharmony_ci	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G,
7588c2ecf20Sopenharmony_ci	      "CHANNEL-WIDTH-SET-40MHZ-80MHZ-IN-5G");
7598c2ecf20Sopenharmony_ci	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_160MHZ_IN_5G,
7608c2ecf20Sopenharmony_ci	      "CHANNEL-WIDTH-SET-160MHZ-IN-5G");
7618c2ecf20Sopenharmony_ci	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
7628c2ecf20Sopenharmony_ci	      "CHANNEL-WIDTH-SET-80PLUS80-MHZ-IN-5G");
7638c2ecf20Sopenharmony_ci	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G,
7648c2ecf20Sopenharmony_ci	      "CHANNEL-WIDTH-SET-RU-MAPPING-IN-2G");
7658c2ecf20Sopenharmony_ci	PFLAG(PHY, 0, CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G,
7668c2ecf20Sopenharmony_ci	      "CHANNEL-WIDTH-SET-RU-MAPPING-IN-5G");
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci	switch (cap[1] & IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK) {
7698c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_20MHZ:
7708c2ecf20Sopenharmony_ci		PRINT("PREAMBLE-PUNC-RX-80MHZ-ONLY-SECOND-20MHZ");
7718c2ecf20Sopenharmony_ci		break;
7728c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_40MHZ:
7738c2ecf20Sopenharmony_ci		PRINT("PREAMBLE-PUNC-RX-80MHZ-ONLY-SECOND-40MHZ");
7748c2ecf20Sopenharmony_ci		break;
7758c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_160MHZ_ONLY_SECOND_20MHZ:
7768c2ecf20Sopenharmony_ci		PRINT("PREAMBLE-PUNC-RX-160MHZ-ONLY-SECOND-20MHZ");
7778c2ecf20Sopenharmony_ci		break;
7788c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_160MHZ_ONLY_SECOND_40MHZ:
7798c2ecf20Sopenharmony_ci		PRINT("PREAMBLE-PUNC-RX-160MHZ-ONLY-SECOND-40MHZ");
7808c2ecf20Sopenharmony_ci		break;
7818c2ecf20Sopenharmony_ci	}
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	PFLAG(PHY, 1, DEVICE_CLASS_A,
7848c2ecf20Sopenharmony_ci	      "IEEE80211-HE-PHY-CAP1-DEVICE-CLASS-A");
7858c2ecf20Sopenharmony_ci	PFLAG(PHY, 1, LDPC_CODING_IN_PAYLOAD,
7868c2ecf20Sopenharmony_ci	      "LDPC-CODING-IN-PAYLOAD");
7878c2ecf20Sopenharmony_ci	PFLAG(PHY, 1, HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US,
7888c2ecf20Sopenharmony_ci	      "HY-CAP1-HE-LTF-AND-GI-FOR-HE-PPDUS-0-8US");
7898c2ecf20Sopenharmony_ci	PRINT("MIDAMBLE-RX-MAX-NSTS-%d", ((cap[2] << 1) | (cap[1] >> 7)) & 0x3);
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, NDP_4x_LTF_AND_3_2US, "NDP-4X-LTF-AND-3-2US");
7928c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, STBC_TX_UNDER_80MHZ, "STBC-TX-UNDER-80MHZ");
7938c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, STBC_RX_UNDER_80MHZ, "STBC-RX-UNDER-80MHZ");
7948c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, DOPPLER_TX, "DOPPLER-TX");
7958c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, DOPPLER_RX, "DOPPLER-RX");
7968c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, UL_MU_FULL_MU_MIMO, "UL-MU-FULL-MU-MIMO");
7978c2ecf20Sopenharmony_ci	PFLAG(PHY, 2, UL_MU_PARTIAL_MU_MIMO, "UL-MU-PARTIAL-MU-MIMO");
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_ci	switch (cap[3] & IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK) {
8008c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_NO_DCM:
8018c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-TX-NO-DCM");
8028c2ecf20Sopenharmony_ci		break;
8038c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK:
8048c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-TX-BPSK");
8058c2ecf20Sopenharmony_ci		break;
8068c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK:
8078c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-TX-QPSK");
8088c2ecf20Sopenharmony_ci		break;
8098c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_16_QAM:
8108c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-TX-16-QAM");
8118c2ecf20Sopenharmony_ci		break;
8128c2ecf20Sopenharmony_ci	}
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	PFLAG(PHY, 3, DCM_MAX_TX_NSS_1, "DCM-MAX-TX-NSS-1");
8158c2ecf20Sopenharmony_ci	PFLAG(PHY, 3, DCM_MAX_TX_NSS_2, "DCM-MAX-TX-NSS-2");
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci	switch (cap[3] & IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK) {
8188c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_NO_DCM:
8198c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-RX-NO-DCM");
8208c2ecf20Sopenharmony_ci		break;
8218c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK:
8228c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-RX-BPSK");
8238c2ecf20Sopenharmony_ci		break;
8248c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK:
8258c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-RX-QPSK");
8268c2ecf20Sopenharmony_ci		break;
8278c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM:
8288c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-CONST-RX-16-QAM");
8298c2ecf20Sopenharmony_ci		break;
8308c2ecf20Sopenharmony_ci	}
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	PFLAG(PHY, 3, DCM_MAX_RX_NSS_1, "DCM-MAX-RX-NSS-1");
8338c2ecf20Sopenharmony_ci	PFLAG(PHY, 3, DCM_MAX_RX_NSS_2, "DCM-MAX-RX-NSS-2");
8348c2ecf20Sopenharmony_ci	PFLAG(PHY, 3, RX_HE_MU_PPDU_FROM_NON_AP_STA,
8358c2ecf20Sopenharmony_ci	      "RX-HE-MU-PPDU-FROM-NON-AP-STA");
8368c2ecf20Sopenharmony_ci	PFLAG(PHY, 3, SU_BEAMFORMER, "SU-BEAMFORMER");
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_ci	PFLAG(PHY, 4, SU_BEAMFORMEE, "SU-BEAMFORMEE");
8398c2ecf20Sopenharmony_ci	PFLAG(PHY, 4, MU_BEAMFORMER, "MU-BEAMFORMER");
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	PFLAG_RANGE(PHY, 4, BEAMFORMEE_MAX_STS_UNDER_80MHZ, 0, 1, 4,
8428c2ecf20Sopenharmony_ci		    "BEAMFORMEE-MAX-STS-UNDER-%d");
8438c2ecf20Sopenharmony_ci	PFLAG_RANGE(PHY, 4, BEAMFORMEE_MAX_STS_ABOVE_80MHZ, 0, 1, 4,
8448c2ecf20Sopenharmony_ci		    "BEAMFORMEE-MAX-STS-ABOVE-%d");
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	PFLAG_RANGE(PHY, 5, BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ, 0, 1, 1,
8478c2ecf20Sopenharmony_ci		    "NUM-SND-DIM-UNDER-80MHZ-%d");
8488c2ecf20Sopenharmony_ci	PFLAG_RANGE(PHY, 5, BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ, 0, 1, 1,
8498c2ecf20Sopenharmony_ci		    "NUM-SND-DIM-ABOVE-80MHZ-%d");
8508c2ecf20Sopenharmony_ci	PFLAG(PHY, 5, NG16_SU_FEEDBACK, "NG16-SU-FEEDBACK");
8518c2ecf20Sopenharmony_ci	PFLAG(PHY, 5, NG16_MU_FEEDBACK, "NG16-MU-FEEDBACK");
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, CODEBOOK_SIZE_42_SU, "CODEBOOK-SIZE-42-SU");
8548c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, CODEBOOK_SIZE_75_MU, "CODEBOOK-SIZE-75-MU");
8558c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, TRIG_SU_BEAMFORMER_FB, "TRIG-SU-BEAMFORMER-FB");
8568c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, TRIG_MU_BEAMFORMER_FB, "TRIG-MU-BEAMFORMER-FB");
8578c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, TRIG_CQI_FB, "TRIG-CQI-FB");
8588c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, PARTIAL_BW_EXT_RANGE, "PARTIAL-BW-EXT-RANGE");
8598c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, PARTIAL_BANDWIDTH_DL_MUMIMO,
8608c2ecf20Sopenharmony_ci	      "PARTIAL-BANDWIDTH-DL-MUMIMO");
8618c2ecf20Sopenharmony_ci	PFLAG(PHY, 6, PPE_THRESHOLD_PRESENT, "PPE-THRESHOLD-PRESENT");
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	PFLAG(PHY, 7, SRP_BASED_SR, "SRP-BASED-SR");
8648c2ecf20Sopenharmony_ci	PFLAG(PHY, 7, POWER_BOOST_FACTOR_AR, "POWER-BOOST-FACTOR-AR");
8658c2ecf20Sopenharmony_ci	PFLAG(PHY, 7, HE_SU_MU_PPDU_4XLTF_AND_08_US_GI,
8668c2ecf20Sopenharmony_ci	      "HE-SU-MU-PPDU-4XLTF-AND-08-US-GI");
8678c2ecf20Sopenharmony_ci	PFLAG_RANGE(PHY, 7, MAX_NC, 0, 1, 1, "MAX-NC-%d");
8688c2ecf20Sopenharmony_ci	PFLAG(PHY, 7, STBC_TX_ABOVE_80MHZ, "STBC-TX-ABOVE-80MHZ");
8698c2ecf20Sopenharmony_ci	PFLAG(PHY, 7, STBC_RX_ABOVE_80MHZ, "STBC-RX-ABOVE-80MHZ");
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci	PFLAG(PHY, 8, HE_ER_SU_PPDU_4XLTF_AND_08_US_GI,
8728c2ecf20Sopenharmony_ci	      "HE-ER-SU-PPDU-4XLTF-AND-08-US-GI");
8738c2ecf20Sopenharmony_ci	PFLAG(PHY, 8, 20MHZ_IN_40MHZ_HE_PPDU_IN_2G,
8748c2ecf20Sopenharmony_ci	      "20MHZ-IN-40MHZ-HE-PPDU-IN-2G");
8758c2ecf20Sopenharmony_ci	PFLAG(PHY, 8, 20MHZ_IN_160MHZ_HE_PPDU, "20MHZ-IN-160MHZ-HE-PPDU");
8768c2ecf20Sopenharmony_ci	PFLAG(PHY, 8, 80MHZ_IN_160MHZ_HE_PPDU, "80MHZ-IN-160MHZ-HE-PPDU");
8778c2ecf20Sopenharmony_ci	PFLAG(PHY, 8, HE_ER_SU_1XLTF_AND_08_US_GI,
8788c2ecf20Sopenharmony_ci	      "HE-ER-SU-1XLTF-AND-08-US-GI");
8798c2ecf20Sopenharmony_ci	PFLAG(PHY, 8, MIDAMBLE_RX_TX_2X_AND_1XLTF,
8808c2ecf20Sopenharmony_ci	      "MIDAMBLE-RX-TX-2X-AND-1XLTF");
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_ci	switch (cap[8] & IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_MASK) {
8838c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_242:
8848c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-RU-242");
8858c2ecf20Sopenharmony_ci		break;
8868c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484:
8878c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-RU-484");
8888c2ecf20Sopenharmony_ci		break;
8898c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_996:
8908c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-RU-996");
8918c2ecf20Sopenharmony_ci		break;
8928c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_2x996:
8938c2ecf20Sopenharmony_ci		PRINT("DCM-MAX-RU-2x996");
8948c2ecf20Sopenharmony_ci		break;
8958c2ecf20Sopenharmony_ci	}
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	PFLAG(PHY, 9, LONGER_THAN_16_SIGB_OFDM_SYM,
8988c2ecf20Sopenharmony_ci	      "LONGER-THAN-16-SIGB-OFDM-SYM");
8998c2ecf20Sopenharmony_ci	PFLAG(PHY, 9, NON_TRIGGERED_CQI_FEEDBACK,
9008c2ecf20Sopenharmony_ci	      "NON-TRIGGERED-CQI-FEEDBACK");
9018c2ecf20Sopenharmony_ci	PFLAG(PHY, 9, TX_1024_QAM_LESS_THAN_242_TONE_RU,
9028c2ecf20Sopenharmony_ci	      "TX-1024-QAM-LESS-THAN-242-TONE-RU");
9038c2ecf20Sopenharmony_ci	PFLAG(PHY, 9, RX_1024_QAM_LESS_THAN_242_TONE_RU,
9048c2ecf20Sopenharmony_ci	      "RX-1024-QAM-LESS-THAN-242-TONE-RU");
9058c2ecf20Sopenharmony_ci	PFLAG(PHY, 9, RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB,
9068c2ecf20Sopenharmony_ci	      "RX-FULL-BW-SU-USING-MU-WITH-COMP-SIGB");
9078c2ecf20Sopenharmony_ci	PFLAG(PHY, 9, RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB,
9088c2ecf20Sopenharmony_ci	      "RX-FULL-BW-SU-USING-MU-WITH-NON-COMP-SIGB");
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	switch (cap[9] & IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
9118c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
9128c2ecf20Sopenharmony_ci		PRINT("NOMINAL-PACKET-PADDING-0US");
9138c2ecf20Sopenharmony_ci		break;
9148c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
9158c2ecf20Sopenharmony_ci		PRINT("NOMINAL-PACKET-PADDING-8US");
9168c2ecf20Sopenharmony_ci		break;
9178c2ecf20Sopenharmony_ci	case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
9188c2ecf20Sopenharmony_ci		PRINT("NOMINAL-PACKET-PADDING-16US");
9198c2ecf20Sopenharmony_ci		break;
9208c2ecf20Sopenharmony_ci	}
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci#undef PFLAG_RANGE_DEFAULT
9238c2ecf20Sopenharmony_ci#undef PFLAG_RANGE
9248c2ecf20Sopenharmony_ci#undef PFLAG
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci#define PRINT_NSS_SUPP(f, n)						\
9278c2ecf20Sopenharmony_ci	do {								\
9288c2ecf20Sopenharmony_ci		int _i;							\
9298c2ecf20Sopenharmony_ci		u16 v = le16_to_cpu(nss->f);				\
9308c2ecf20Sopenharmony_ci		p += scnprintf(p, buf_sz + buf - p, n ": %#.4x\n", v);	\
9318c2ecf20Sopenharmony_ci		for (_i = 0; _i < 8; _i += 2) {				\
9328c2ecf20Sopenharmony_ci			switch ((v >> _i) & 0x3) {			\
9338c2ecf20Sopenharmony_ci			case 0:						\
9348c2ecf20Sopenharmony_ci				PRINT(n "-%d-SUPPORT-0-7", _i / 2);	\
9358c2ecf20Sopenharmony_ci				break;					\
9368c2ecf20Sopenharmony_ci			case 1:						\
9378c2ecf20Sopenharmony_ci				PRINT(n "-%d-SUPPORT-0-9", _i / 2);	\
9388c2ecf20Sopenharmony_ci				break;					\
9398c2ecf20Sopenharmony_ci			case 2:						\
9408c2ecf20Sopenharmony_ci				PRINT(n "-%d-SUPPORT-0-11", _i / 2);	\
9418c2ecf20Sopenharmony_ci				break;					\
9428c2ecf20Sopenharmony_ci			case 3:						\
9438c2ecf20Sopenharmony_ci				PRINT(n "-%d-NOT-SUPPORTED", _i / 2);	\
9448c2ecf20Sopenharmony_ci				break;					\
9458c2ecf20Sopenharmony_ci			}						\
9468c2ecf20Sopenharmony_ci		}							\
9478c2ecf20Sopenharmony_ci	} while (0)
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	PRINT_NSS_SUPP(rx_mcs_80, "RX-MCS-80");
9508c2ecf20Sopenharmony_ci	PRINT_NSS_SUPP(tx_mcs_80, "TX-MCS-80");
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	if (cap[0] & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) {
9538c2ecf20Sopenharmony_ci		PRINT_NSS_SUPP(rx_mcs_160, "RX-MCS-160");
9548c2ecf20Sopenharmony_ci		PRINT_NSS_SUPP(tx_mcs_160, "TX-MCS-160");
9558c2ecf20Sopenharmony_ci	}
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	if (cap[0] &
9588c2ecf20Sopenharmony_ci	    IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
9598c2ecf20Sopenharmony_ci		PRINT_NSS_SUPP(rx_mcs_80p80, "RX-MCS-80P80");
9608c2ecf20Sopenharmony_ci		PRINT_NSS_SUPP(tx_mcs_80p80, "TX-MCS-80P80");
9618c2ecf20Sopenharmony_ci	}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci#undef PRINT_NSS_SUPP
9648c2ecf20Sopenharmony_ci#undef PRINT
9658c2ecf20Sopenharmony_ci
9668c2ecf20Sopenharmony_ci	if (!(cap[6] & IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT))
9678c2ecf20Sopenharmony_ci		goto out;
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	p += scnprintf(p, buf_sz + buf - p, "PPE-THRESHOLDS: %#.2x",
9708c2ecf20Sopenharmony_ci		       hec->ppe_thres[0]);
9718c2ecf20Sopenharmony_ci
9728c2ecf20Sopenharmony_ci	ppe_size = ieee80211_he_ppe_size(hec->ppe_thres[0], cap);
9738c2ecf20Sopenharmony_ci	for (i = 1; i < ppe_size; i++) {
9748c2ecf20Sopenharmony_ci		p += scnprintf(p, buf_sz + buf - p, " %#.2x",
9758c2ecf20Sopenharmony_ci			       hec->ppe_thres[i]);
9768c2ecf20Sopenharmony_ci	}
9778c2ecf20Sopenharmony_ci	p += scnprintf(p, buf_sz + buf - p, "\n");
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_ciout:
9808c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
9818c2ecf20Sopenharmony_ci	kfree(buf);
9828c2ecf20Sopenharmony_ci	return ret;
9838c2ecf20Sopenharmony_ci}
9848c2ecf20Sopenharmony_ciSTA_OPS(he_capa);
9858c2ecf20Sopenharmony_ci
9868c2ecf20Sopenharmony_ci#define DEBUGFS_ADD(name) \
9878c2ecf20Sopenharmony_ci	debugfs_create_file(#name, 0400, \
9888c2ecf20Sopenharmony_ci		sta->debugfs_dir, sta, &sta_ ##name## _ops);
9898c2ecf20Sopenharmony_ci
9908c2ecf20Sopenharmony_ci#define DEBUGFS_ADD_COUNTER(name, field)				\
9918c2ecf20Sopenharmony_ci	debugfs_create_ulong(#name, 0400, sta->debugfs_dir, &sta->field);
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_civoid ieee80211_sta_debugfs_add(struct sta_info *sta)
9948c2ecf20Sopenharmony_ci{
9958c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sta->local;
9968c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata = sta->sdata;
9978c2ecf20Sopenharmony_ci	struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
9988c2ecf20Sopenharmony_ci	u8 mac[3*ETH_ALEN];
9998c2ecf20Sopenharmony_ci
10008c2ecf20Sopenharmony_ci	if (!stations_dir)
10018c2ecf20Sopenharmony_ci		return;
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci	snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
10048c2ecf20Sopenharmony_ci
10058c2ecf20Sopenharmony_ci	/*
10068c2ecf20Sopenharmony_ci	 * This might fail due to a race condition:
10078c2ecf20Sopenharmony_ci	 * When mac80211 unlinks a station, the debugfs entries
10088c2ecf20Sopenharmony_ci	 * remain, but it is already possible to link a new
10098c2ecf20Sopenharmony_ci	 * station with the same address which triggers adding
10108c2ecf20Sopenharmony_ci	 * it to debugfs; therefore, if the old station isn't
10118c2ecf20Sopenharmony_ci	 * destroyed quickly enough the old station's debugfs
10128c2ecf20Sopenharmony_ci	 * dir might still be around.
10138c2ecf20Sopenharmony_ci	 */
10148c2ecf20Sopenharmony_ci	sta->debugfs_dir = debugfs_create_dir(mac, stations_dir);
10158c2ecf20Sopenharmony_ci
10168c2ecf20Sopenharmony_ci	DEBUGFS_ADD(flags);
10178c2ecf20Sopenharmony_ci	DEBUGFS_ADD(aid);
10188c2ecf20Sopenharmony_ci	DEBUGFS_ADD(num_ps_buf_frames);
10198c2ecf20Sopenharmony_ci	DEBUGFS_ADD(last_seq_ctrl);
10208c2ecf20Sopenharmony_ci	DEBUGFS_ADD(agg_status);
10218c2ecf20Sopenharmony_ci	DEBUGFS_ADD(ht_capa);
10228c2ecf20Sopenharmony_ci	DEBUGFS_ADD(vht_capa);
10238c2ecf20Sopenharmony_ci	DEBUGFS_ADD(he_capa);
10248c2ecf20Sopenharmony_ci
10258c2ecf20Sopenharmony_ci	DEBUGFS_ADD_COUNTER(rx_duplicates, rx_stats.num_duplicates);
10268c2ecf20Sopenharmony_ci	DEBUGFS_ADD_COUNTER(rx_fragments, rx_stats.fragments);
10278c2ecf20Sopenharmony_ci	DEBUGFS_ADD_COUNTER(tx_filtered, status_stats.filtered);
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci	if (local->ops->wake_tx_queue) {
10308c2ecf20Sopenharmony_ci		DEBUGFS_ADD(aqm);
10318c2ecf20Sopenharmony_ci		DEBUGFS_ADD(airtime);
10328c2ecf20Sopenharmony_ci	}
10338c2ecf20Sopenharmony_ci
10348c2ecf20Sopenharmony_ci	if (wiphy_ext_feature_isset(local->hw.wiphy,
10358c2ecf20Sopenharmony_ci				    NL80211_EXT_FEATURE_AQL))
10368c2ecf20Sopenharmony_ci		DEBUGFS_ADD(aql);
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_ci	debugfs_create_xul("driver_buffered_tids", 0400, sta->debugfs_dir,
10398c2ecf20Sopenharmony_ci			   &sta->driver_buffered_tids);
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci	drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs_dir);
10428c2ecf20Sopenharmony_ci}
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_civoid ieee80211_sta_debugfs_remove(struct sta_info *sta)
10458c2ecf20Sopenharmony_ci{
10468c2ecf20Sopenharmony_ci	debugfs_remove_recursive(sta->debugfs_dir);
10478c2ecf20Sopenharmony_ci	sta->debugfs_dir = NULL;
10488c2ecf20Sopenharmony_ci}
1049