18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Contact Information:
78c2ecf20Sopenharmony_ci *  Intel Linux Wireless <ilw@linux.intel.com>
88c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
98c2ecf20Sopenharmony_ci *****************************************************************************/
108c2ecf20Sopenharmony_ci#include <linux/ieee80211.h>
118c2ecf20Sopenharmony_ci#include <linux/export.h>
128c2ecf20Sopenharmony_ci#include <net/mac80211.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "common.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic void
178c2ecf20Sopenharmony_ciil_clear_traffic_stats(struct il_priv *il)
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
208c2ecf20Sopenharmony_ci	memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
218c2ecf20Sopenharmony_ci}
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * il_update_stats function record all the MGMT, CTRL and DATA pkt for
258c2ecf20Sopenharmony_ci * both TX and Rx . Use debugfs to display the rx/rx_stats
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_civoid
288c2ecf20Sopenharmony_ciil_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	struct traffic_stats *stats;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	if (is_tx)
338c2ecf20Sopenharmony_ci		stats = &il->tx_stats;
348c2ecf20Sopenharmony_ci	else
358c2ecf20Sopenharmony_ci		stats = &il->rx_stats;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	if (ieee80211_is_mgmt(fc)) {
388c2ecf20Sopenharmony_ci		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
398c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
408c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
418c2ecf20Sopenharmony_ci			break;
428c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
438c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
448c2ecf20Sopenharmony_ci			break;
458c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
468c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
478c2ecf20Sopenharmony_ci			break;
488c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
498c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
508c2ecf20Sopenharmony_ci			break;
518c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
528c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_PROBE_REQ]++;
538c2ecf20Sopenharmony_ci			break;
548c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
558c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_PROBE_RESP]++;
568c2ecf20Sopenharmony_ci			break;
578c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_BEACON):
588c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_BEACON]++;
598c2ecf20Sopenharmony_ci			break;
608c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_ATIM):
618c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_ATIM]++;
628c2ecf20Sopenharmony_ci			break;
638c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
648c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_DISASSOC]++;
658c2ecf20Sopenharmony_ci			break;
668c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_AUTH):
678c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_AUTH]++;
688c2ecf20Sopenharmony_ci			break;
698c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
708c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_DEAUTH]++;
718c2ecf20Sopenharmony_ci			break;
728c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_ACTION):
738c2ecf20Sopenharmony_ci			stats->mgmt[MANAGEMENT_ACTION]++;
748c2ecf20Sopenharmony_ci			break;
758c2ecf20Sopenharmony_ci		}
768c2ecf20Sopenharmony_ci	} else if (ieee80211_is_ctl(fc)) {
778c2ecf20Sopenharmony_ci		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
788c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
798c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_BACK_REQ]++;
808c2ecf20Sopenharmony_ci			break;
818c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_BACK):
828c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_BACK]++;
838c2ecf20Sopenharmony_ci			break;
848c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
858c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_PSPOLL]++;
868c2ecf20Sopenharmony_ci			break;
878c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_RTS):
888c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_RTS]++;
898c2ecf20Sopenharmony_ci			break;
908c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_CTS):
918c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_CTS]++;
928c2ecf20Sopenharmony_ci			break;
938c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_ACK):
948c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_ACK]++;
958c2ecf20Sopenharmony_ci			break;
968c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_CFEND):
978c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_CFEND]++;
988c2ecf20Sopenharmony_ci			break;
998c2ecf20Sopenharmony_ci		case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
1008c2ecf20Sopenharmony_ci			stats->ctrl[CONTROL_CFENDACK]++;
1018c2ecf20Sopenharmony_ci			break;
1028c2ecf20Sopenharmony_ci		}
1038c2ecf20Sopenharmony_ci	} else {
1048c2ecf20Sopenharmony_ci		/* data */
1058c2ecf20Sopenharmony_ci		stats->data_cnt++;
1068c2ecf20Sopenharmony_ci		stats->data_bytes += len;
1078c2ecf20Sopenharmony_ci	}
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ciEXPORT_SYMBOL(il_update_stats);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/* create and remove of files */
1128c2ecf20Sopenharmony_ci#define DEBUGFS_ADD_FILE(name, parent, mode) do {			\
1138c2ecf20Sopenharmony_ci	debugfs_create_file(#name, mode, parent, il,			\
1148c2ecf20Sopenharmony_ci			    &il_dbgfs_##name##_ops);			\
1158c2ecf20Sopenharmony_ci} while (0)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define DEBUGFS_ADD_BOOL(name, parent, ptr) do {			\
1188c2ecf20Sopenharmony_ci	debugfs_create_bool(#name, 0600, parent, ptr);			\
1198c2ecf20Sopenharmony_ci} while (0)
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* file operation */
1228c2ecf20Sopenharmony_ci#define DEBUGFS_READ_FUNC(name)                                         \
1238c2ecf20Sopenharmony_cistatic ssize_t il_dbgfs_##name##_read(struct file *file,               \
1248c2ecf20Sopenharmony_ci					char __user *user_buf,          \
1258c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define DEBUGFS_WRITE_FUNC(name)                                        \
1288c2ecf20Sopenharmony_cistatic ssize_t il_dbgfs_##name##_write(struct file *file,              \
1298c2ecf20Sopenharmony_ci					const char __user *user_buf,    \
1308c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define DEBUGFS_READ_FILE_OPS(name)				\
1348c2ecf20Sopenharmony_ci	DEBUGFS_READ_FUNC(name);				\
1358c2ecf20Sopenharmony_cistatic const struct file_operations il_dbgfs_##name##_ops = {	\
1368c2ecf20Sopenharmony_ci	.read = il_dbgfs_##name##_read,				\
1378c2ecf20Sopenharmony_ci	.open = simple_open,					\
1388c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,				\
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define DEBUGFS_WRITE_FILE_OPS(name)				\
1428c2ecf20Sopenharmony_ci	DEBUGFS_WRITE_FUNC(name);				\
1438c2ecf20Sopenharmony_cistatic const struct file_operations il_dbgfs_##name##_ops = {	\
1448c2ecf20Sopenharmony_ci	.write = il_dbgfs_##name##_write,			\
1458c2ecf20Sopenharmony_ci	.open = simple_open,					\
1468c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,				\
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define DEBUGFS_READ_WRITE_FILE_OPS(name)			\
1508c2ecf20Sopenharmony_ci	DEBUGFS_READ_FUNC(name);				\
1518c2ecf20Sopenharmony_ci	DEBUGFS_WRITE_FUNC(name);				\
1528c2ecf20Sopenharmony_cistatic const struct file_operations il_dbgfs_##name##_ops = {	\
1538c2ecf20Sopenharmony_ci	.write = il_dbgfs_##name##_write,			\
1548c2ecf20Sopenharmony_ci	.read = il_dbgfs_##name##_read,				\
1558c2ecf20Sopenharmony_ci	.open = simple_open,					\
1568c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,				\
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistatic const char *
1608c2ecf20Sopenharmony_ciil_get_mgmt_string(int cmd)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	switch (cmd) {
1638c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_ASSOC_REQ);
1648c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_ASSOC_RESP);
1658c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_REASSOC_REQ);
1668c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_REASSOC_RESP);
1678c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_PROBE_REQ);
1688c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_PROBE_RESP);
1698c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_BEACON);
1708c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_ATIM);
1718c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_DISASSOC);
1728c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_AUTH);
1738c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_DEAUTH);
1748c2ecf20Sopenharmony_ci	IL_CMD(MANAGEMENT_ACTION);
1758c2ecf20Sopenharmony_ci	default:
1768c2ecf20Sopenharmony_ci		return "UNKNOWN";
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	}
1798c2ecf20Sopenharmony_ci}
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_cistatic const char *
1828c2ecf20Sopenharmony_ciil_get_ctrl_string(int cmd)
1838c2ecf20Sopenharmony_ci{
1848c2ecf20Sopenharmony_ci	switch (cmd) {
1858c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_BACK_REQ);
1868c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_BACK);
1878c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_PSPOLL);
1888c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_RTS);
1898c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_CTS);
1908c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_ACK);
1918c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_CFEND);
1928c2ecf20Sopenharmony_ci	IL_CMD(CONTROL_CFENDACK);
1938c2ecf20Sopenharmony_ci	default:
1948c2ecf20Sopenharmony_ci		return "UNKNOWN";
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	}
1978c2ecf20Sopenharmony_ci}
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic ssize_t
2008c2ecf20Sopenharmony_ciil_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
2018c2ecf20Sopenharmony_ci		       loff_t *ppos)
2028c2ecf20Sopenharmony_ci{
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
2058c2ecf20Sopenharmony_ci	char *buf;
2068c2ecf20Sopenharmony_ci	int pos = 0;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	int cnt;
2098c2ecf20Sopenharmony_ci	ssize_t ret;
2108c2ecf20Sopenharmony_ci	const size_t bufsz =
2118c2ecf20Sopenharmony_ci	    100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
2128c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
2138c2ecf20Sopenharmony_ci	if (!buf)
2148c2ecf20Sopenharmony_ci		return -ENOMEM;
2158c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
2168c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
2178c2ecf20Sopenharmony_ci		pos +=
2188c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
2198c2ecf20Sopenharmony_ci			      il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
2208c2ecf20Sopenharmony_ci	}
2218c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
2228c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
2238c2ecf20Sopenharmony_ci		pos +=
2248c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
2258c2ecf20Sopenharmony_ci			      il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
2268c2ecf20Sopenharmony_ci	}
2278c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
2288c2ecf20Sopenharmony_ci	pos +=
2298c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
2308c2ecf20Sopenharmony_ci		      il->tx_stats.data_cnt);
2318c2ecf20Sopenharmony_ci	pos +=
2328c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
2338c2ecf20Sopenharmony_ci		      il->tx_stats.data_bytes);
2348c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2358c2ecf20Sopenharmony_ci	kfree(buf);
2368c2ecf20Sopenharmony_ci	return ret;
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistatic ssize_t
2408c2ecf20Sopenharmony_ciil_dbgfs_clear_traffic_stats_write(struct file *file,
2418c2ecf20Sopenharmony_ci				   const char __user *user_buf, size_t count,
2428c2ecf20Sopenharmony_ci				   loff_t *ppos)
2438c2ecf20Sopenharmony_ci{
2448c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
2458c2ecf20Sopenharmony_ci	u32 clear_flag;
2468c2ecf20Sopenharmony_ci	char buf[8];
2478c2ecf20Sopenharmony_ci	int buf_size;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
2508c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
2518c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
2528c2ecf20Sopenharmony_ci		return -EFAULT;
2538c2ecf20Sopenharmony_ci	if (sscanf(buf, "%x", &clear_flag) != 1)
2548c2ecf20Sopenharmony_ci		return -EFAULT;
2558c2ecf20Sopenharmony_ci	il_clear_traffic_stats(il);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	return count;
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistatic ssize_t
2618c2ecf20Sopenharmony_ciil_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
2628c2ecf20Sopenharmony_ci		       loff_t *ppos)
2638c2ecf20Sopenharmony_ci{
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
2668c2ecf20Sopenharmony_ci	char *buf;
2678c2ecf20Sopenharmony_ci	int pos = 0;
2688c2ecf20Sopenharmony_ci	int cnt;
2698c2ecf20Sopenharmony_ci	ssize_t ret;
2708c2ecf20Sopenharmony_ci	const size_t bufsz =
2718c2ecf20Sopenharmony_ci	    100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
2728c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
2738c2ecf20Sopenharmony_ci	if (!buf)
2748c2ecf20Sopenharmony_ci		return -ENOMEM;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
2778c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
2788c2ecf20Sopenharmony_ci		pos +=
2798c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
2808c2ecf20Sopenharmony_ci			      il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
2818c2ecf20Sopenharmony_ci	}
2828c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
2838c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
2848c2ecf20Sopenharmony_ci		pos +=
2858c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
2868c2ecf20Sopenharmony_ci			      il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
2878c2ecf20Sopenharmony_ci	}
2888c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
2898c2ecf20Sopenharmony_ci	pos +=
2908c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
2918c2ecf20Sopenharmony_ci		      il->rx_stats.data_cnt);
2928c2ecf20Sopenharmony_ci	pos +=
2938c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
2948c2ecf20Sopenharmony_ci		      il->rx_stats.data_bytes);
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2978c2ecf20Sopenharmony_ci	kfree(buf);
2988c2ecf20Sopenharmony_ci	return ret;
2998c2ecf20Sopenharmony_ci}
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci#define BYTE1_MASK 0x000000ff;
3028c2ecf20Sopenharmony_ci#define BYTE2_MASK 0x0000ffff;
3038c2ecf20Sopenharmony_ci#define BYTE3_MASK 0x00ffffff;
3048c2ecf20Sopenharmony_cistatic ssize_t
3058c2ecf20Sopenharmony_ciil_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
3068c2ecf20Sopenharmony_ci		   loff_t *ppos)
3078c2ecf20Sopenharmony_ci{
3088c2ecf20Sopenharmony_ci	u32 val;
3098c2ecf20Sopenharmony_ci	char *buf;
3108c2ecf20Sopenharmony_ci	ssize_t ret;
3118c2ecf20Sopenharmony_ci	int i;
3128c2ecf20Sopenharmony_ci	int pos = 0;
3138c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
3148c2ecf20Sopenharmony_ci	size_t bufsz;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	/* default is to dump the entire data segment */
3178c2ecf20Sopenharmony_ci	if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
3188c2ecf20Sopenharmony_ci		il->dbgfs_sram_offset = 0x800000;
3198c2ecf20Sopenharmony_ci		if (il->ucode_type == UCODE_INIT)
3208c2ecf20Sopenharmony_ci			il->dbgfs_sram_len = il->ucode_init_data.len;
3218c2ecf20Sopenharmony_ci		else
3228c2ecf20Sopenharmony_ci			il->dbgfs_sram_len = il->ucode_data.len;
3238c2ecf20Sopenharmony_ci	}
3248c2ecf20Sopenharmony_ci	bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
3258c2ecf20Sopenharmony_ci	buf = kmalloc(bufsz, GFP_KERNEL);
3268c2ecf20Sopenharmony_ci	if (!buf)
3278c2ecf20Sopenharmony_ci		return -ENOMEM;
3288c2ecf20Sopenharmony_ci	pos +=
3298c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
3308c2ecf20Sopenharmony_ci		      il->dbgfs_sram_len);
3318c2ecf20Sopenharmony_ci	pos +=
3328c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
3338c2ecf20Sopenharmony_ci		      il->dbgfs_sram_offset);
3348c2ecf20Sopenharmony_ci	for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
3358c2ecf20Sopenharmony_ci		val =
3368c2ecf20Sopenharmony_ci		    il_read_targ_mem(il,
3378c2ecf20Sopenharmony_ci				     il->dbgfs_sram_offset +
3388c2ecf20Sopenharmony_ci				     il->dbgfs_sram_len - i);
3398c2ecf20Sopenharmony_ci		if (i < 4) {
3408c2ecf20Sopenharmony_ci			switch (i) {
3418c2ecf20Sopenharmony_ci			case 1:
3428c2ecf20Sopenharmony_ci				val &= BYTE1_MASK;
3438c2ecf20Sopenharmony_ci				break;
3448c2ecf20Sopenharmony_ci			case 2:
3458c2ecf20Sopenharmony_ci				val &= BYTE2_MASK;
3468c2ecf20Sopenharmony_ci				break;
3478c2ecf20Sopenharmony_ci			case 3:
3488c2ecf20Sopenharmony_ci				val &= BYTE3_MASK;
3498c2ecf20Sopenharmony_ci				break;
3508c2ecf20Sopenharmony_ci			}
3518c2ecf20Sopenharmony_ci		}
3528c2ecf20Sopenharmony_ci		if (!(i % 16))
3538c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos, "\n");
3548c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
3558c2ecf20Sopenharmony_ci	}
3568c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
3598c2ecf20Sopenharmony_ci	kfree(buf);
3608c2ecf20Sopenharmony_ci	return ret;
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_cistatic ssize_t
3648c2ecf20Sopenharmony_ciil_dbgfs_sram_write(struct file *file, const char __user *user_buf,
3658c2ecf20Sopenharmony_ci		    size_t count, loff_t *ppos)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
3688c2ecf20Sopenharmony_ci	char buf[64];
3698c2ecf20Sopenharmony_ci	int buf_size;
3708c2ecf20Sopenharmony_ci	u32 offset, len;
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
3738c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
3748c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
3758c2ecf20Sopenharmony_ci		return -EFAULT;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
3788c2ecf20Sopenharmony_ci		il->dbgfs_sram_offset = offset;
3798c2ecf20Sopenharmony_ci		il->dbgfs_sram_len = len;
3808c2ecf20Sopenharmony_ci	} else {
3818c2ecf20Sopenharmony_ci		il->dbgfs_sram_offset = 0;
3828c2ecf20Sopenharmony_ci		il->dbgfs_sram_len = 0;
3838c2ecf20Sopenharmony_ci	}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	return count;
3868c2ecf20Sopenharmony_ci}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_cistatic ssize_t
3898c2ecf20Sopenharmony_ciil_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
3908c2ecf20Sopenharmony_ci		       loff_t *ppos)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
3938c2ecf20Sopenharmony_ci	struct il_station_entry *station;
3948c2ecf20Sopenharmony_ci	int max_sta = il->hw_params.max_stations;
3958c2ecf20Sopenharmony_ci	char *buf;
3968c2ecf20Sopenharmony_ci	int i, j, pos = 0;
3978c2ecf20Sopenharmony_ci	ssize_t ret;
3988c2ecf20Sopenharmony_ci	/* Add 30 for initial string */
3998c2ecf20Sopenharmony_ci	const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	buf = kmalloc(bufsz, GFP_KERNEL);
4028c2ecf20Sopenharmony_ci	if (!buf)
4038c2ecf20Sopenharmony_ci		return -ENOMEM;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	pos +=
4068c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
4078c2ecf20Sopenharmony_ci		      il->num_stations);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	for (i = 0; i < max_sta; i++) {
4108c2ecf20Sopenharmony_ci		station = &il->stations[i];
4118c2ecf20Sopenharmony_ci		if (!station->used)
4128c2ecf20Sopenharmony_ci			continue;
4138c2ecf20Sopenharmony_ci		pos +=
4148c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
4158c2ecf20Sopenharmony_ci			      "station %d - addr: %pM, flags: %#x\n", i,
4168c2ecf20Sopenharmony_ci			      station->sta.sta.addr,
4178c2ecf20Sopenharmony_ci			      station->sta.station_flags_msk);
4188c2ecf20Sopenharmony_ci		pos +=
4198c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
4208c2ecf20Sopenharmony_ci			      "TID\tseq_num\ttxq_id\tframes\ttfds\t");
4218c2ecf20Sopenharmony_ci		pos +=
4228c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
4238c2ecf20Sopenharmony_ci			      "start_idx\tbitmap\t\t\trate_n_flags\n");
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci		for (j = 0; j < MAX_TID_COUNT; j++) {
4268c2ecf20Sopenharmony_ci			pos +=
4278c2ecf20Sopenharmony_ci			    scnprintf(buf + pos, bufsz - pos,
4288c2ecf20Sopenharmony_ci				      "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
4298c2ecf20Sopenharmony_ci				      j, station->tid[j].seq_number,
4308c2ecf20Sopenharmony_ci				      station->tid[j].agg.txq_id,
4318c2ecf20Sopenharmony_ci				      station->tid[j].agg.frame_count,
4328c2ecf20Sopenharmony_ci				      station->tid[j].tfds_in_queue,
4338c2ecf20Sopenharmony_ci				      station->tid[j].agg.start_idx,
4348c2ecf20Sopenharmony_ci				      station->tid[j].agg.bitmap,
4358c2ecf20Sopenharmony_ci				      station->tid[j].agg.rate_n_flags);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci			if (station->tid[j].agg.wait_for_ba)
4388c2ecf20Sopenharmony_ci				pos +=
4398c2ecf20Sopenharmony_ci				    scnprintf(buf + pos, bufsz - pos,
4408c2ecf20Sopenharmony_ci					      " - waitforba");
4418c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos, "\n");
4428c2ecf20Sopenharmony_ci		}
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "\n");
4458c2ecf20Sopenharmony_ci	}
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
4488c2ecf20Sopenharmony_ci	kfree(buf);
4498c2ecf20Sopenharmony_ci	return ret;
4508c2ecf20Sopenharmony_ci}
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_cistatic ssize_t
4538c2ecf20Sopenharmony_ciil_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
4548c2ecf20Sopenharmony_ci		  loff_t *ppos)
4558c2ecf20Sopenharmony_ci{
4568c2ecf20Sopenharmony_ci	ssize_t ret;
4578c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
4588c2ecf20Sopenharmony_ci	int pos = 0, ofs = 0, buf_size = 0;
4598c2ecf20Sopenharmony_ci	const u8 *ptr;
4608c2ecf20Sopenharmony_ci	char *buf;
4618c2ecf20Sopenharmony_ci	u16 eeprom_ver;
4628c2ecf20Sopenharmony_ci	size_t eeprom_len = il->cfg->eeprom_size;
4638c2ecf20Sopenharmony_ci	buf_size = 4 * eeprom_len + 256;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	if (eeprom_len % 16) {
4668c2ecf20Sopenharmony_ci		IL_ERR("NVM size is not multiple of 16.\n");
4678c2ecf20Sopenharmony_ci		return -ENODATA;
4688c2ecf20Sopenharmony_ci	}
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	ptr = il->eeprom;
4718c2ecf20Sopenharmony_ci	if (!ptr) {
4728c2ecf20Sopenharmony_ci		IL_ERR("Invalid EEPROM memory\n");
4738c2ecf20Sopenharmony_ci		return -ENOMEM;
4748c2ecf20Sopenharmony_ci	}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci	/* 4 characters for byte 0xYY */
4778c2ecf20Sopenharmony_ci	buf = kzalloc(buf_size, GFP_KERNEL);
4788c2ecf20Sopenharmony_ci	if (!buf) {
4798c2ecf20Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
4808c2ecf20Sopenharmony_ci		return -ENOMEM;
4818c2ecf20Sopenharmony_ci	}
4828c2ecf20Sopenharmony_ci	eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
4838c2ecf20Sopenharmony_ci	pos +=
4848c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
4858c2ecf20Sopenharmony_ci		      eeprom_ver);
4868c2ecf20Sopenharmony_ci	for (ofs = 0; ofs < eeprom_len; ofs += 16) {
4878c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
4888c2ecf20Sopenharmony_ci				 ofs, ptr + ofs);
4898c2ecf20Sopenharmony_ci	}
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
4928c2ecf20Sopenharmony_ci	kfree(buf);
4938c2ecf20Sopenharmony_ci	return ret;
4948c2ecf20Sopenharmony_ci}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_cistatic ssize_t
4978c2ecf20Sopenharmony_ciil_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
4988c2ecf20Sopenharmony_ci		       loff_t *ppos)
4998c2ecf20Sopenharmony_ci{
5008c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
5018c2ecf20Sopenharmony_ci	struct ieee80211_channel *channels = NULL;
5028c2ecf20Sopenharmony_ci	const struct ieee80211_supported_band *supp_band = NULL;
5038c2ecf20Sopenharmony_ci	int pos = 0, i, bufsz = PAGE_SIZE;
5048c2ecf20Sopenharmony_ci	char *buf;
5058c2ecf20Sopenharmony_ci	ssize_t ret;
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci	if (!test_bit(S_GEO_CONFIGURED, &il->status))
5088c2ecf20Sopenharmony_ci		return -EAGAIN;
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
5118c2ecf20Sopenharmony_ci	if (!buf) {
5128c2ecf20Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
5138c2ecf20Sopenharmony_ci		return -ENOMEM;
5148c2ecf20Sopenharmony_ci	}
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	supp_band = il_get_hw_mode(il, NL80211_BAND_2GHZ);
5178c2ecf20Sopenharmony_ci	if (supp_band) {
5188c2ecf20Sopenharmony_ci		channels = supp_band->channels;
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci		pos +=
5218c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
5228c2ecf20Sopenharmony_ci			      "Displaying %d channels in 2.4GHz band 802.11bg):\n",
5238c2ecf20Sopenharmony_ci			      supp_band->n_channels);
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci		for (i = 0; i < supp_band->n_channels; i++)
5268c2ecf20Sopenharmony_ci			pos +=
5278c2ecf20Sopenharmony_ci			    scnprintf(buf + pos, bufsz - pos,
5288c2ecf20Sopenharmony_ci				      "%d: %ddBm: BSS%s%s, %s.\n",
5298c2ecf20Sopenharmony_ci				      channels[i].hw_value,
5308c2ecf20Sopenharmony_ci				      channels[i].max_power,
5318c2ecf20Sopenharmony_ci				      channels[i].
5328c2ecf20Sopenharmony_ci				      flags & IEEE80211_CHAN_RADAR ?
5338c2ecf20Sopenharmony_ci				      " (IEEE 802.11h required)" : "",
5348c2ecf20Sopenharmony_ci				      ((channels[i].
5358c2ecf20Sopenharmony_ci					flags & IEEE80211_CHAN_NO_IR) ||
5368c2ecf20Sopenharmony_ci				       (channels[i].
5378c2ecf20Sopenharmony_ci					flags & IEEE80211_CHAN_RADAR)) ? "" :
5388c2ecf20Sopenharmony_ci				      ", IBSS",
5398c2ecf20Sopenharmony_ci				      channels[i].
5408c2ecf20Sopenharmony_ci				      flags & IEEE80211_CHAN_NO_IR ?
5418c2ecf20Sopenharmony_ci				      "passive only" : "active/passive");
5428c2ecf20Sopenharmony_ci	}
5438c2ecf20Sopenharmony_ci	supp_band = il_get_hw_mode(il, NL80211_BAND_5GHZ);
5448c2ecf20Sopenharmony_ci	if (supp_band) {
5458c2ecf20Sopenharmony_ci		channels = supp_band->channels;
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci		pos +=
5488c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
5498c2ecf20Sopenharmony_ci			      "Displaying %d channels in 5.2GHz band (802.11a)\n",
5508c2ecf20Sopenharmony_ci			      supp_band->n_channels);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci		for (i = 0; i < supp_band->n_channels; i++)
5538c2ecf20Sopenharmony_ci			pos +=
5548c2ecf20Sopenharmony_ci			    scnprintf(buf + pos, bufsz - pos,
5558c2ecf20Sopenharmony_ci				      "%d: %ddBm: BSS%s%s, %s.\n",
5568c2ecf20Sopenharmony_ci				      channels[i].hw_value,
5578c2ecf20Sopenharmony_ci				      channels[i].max_power,
5588c2ecf20Sopenharmony_ci				      channels[i].
5598c2ecf20Sopenharmony_ci				      flags & IEEE80211_CHAN_RADAR ?
5608c2ecf20Sopenharmony_ci				      " (IEEE 802.11h required)" : "",
5618c2ecf20Sopenharmony_ci				      ((channels[i].
5628c2ecf20Sopenharmony_ci					flags & IEEE80211_CHAN_NO_IR) ||
5638c2ecf20Sopenharmony_ci				       (channels[i].
5648c2ecf20Sopenharmony_ci					flags & IEEE80211_CHAN_RADAR)) ? "" :
5658c2ecf20Sopenharmony_ci				      ", IBSS",
5668c2ecf20Sopenharmony_ci				      channels[i].
5678c2ecf20Sopenharmony_ci				      flags & IEEE80211_CHAN_NO_IR ?
5688c2ecf20Sopenharmony_ci				      "passive only" : "active/passive");
5698c2ecf20Sopenharmony_ci	}
5708c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
5718c2ecf20Sopenharmony_ci	kfree(buf);
5728c2ecf20Sopenharmony_ci	return ret;
5738c2ecf20Sopenharmony_ci}
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_cistatic ssize_t
5768c2ecf20Sopenharmony_ciil_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
5778c2ecf20Sopenharmony_ci		     loff_t *ppos)
5788c2ecf20Sopenharmony_ci{
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
5818c2ecf20Sopenharmony_ci	char buf[512];
5828c2ecf20Sopenharmony_ci	int pos = 0;
5838c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci	pos +=
5868c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
5878c2ecf20Sopenharmony_ci		      test_bit(S_HCMD_ACTIVE, &il->status));
5888c2ecf20Sopenharmony_ci	pos +=
5898c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
5908c2ecf20Sopenharmony_ci		      test_bit(S_INT_ENABLED, &il->status));
5918c2ecf20Sopenharmony_ci	pos +=
5928c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_RFKILL:\t %d\n",
5938c2ecf20Sopenharmony_ci		      test_bit(S_RFKILL, &il->status));
5948c2ecf20Sopenharmony_ci	pos +=
5958c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
5968c2ecf20Sopenharmony_ci		      test_bit(S_CT_KILL, &il->status));
5978c2ecf20Sopenharmony_ci	pos +=
5988c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
5998c2ecf20Sopenharmony_ci		      test_bit(S_INIT, &il->status));
6008c2ecf20Sopenharmony_ci	pos +=
6018c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
6028c2ecf20Sopenharmony_ci		      test_bit(S_ALIVE, &il->status));
6038c2ecf20Sopenharmony_ci	pos +=
6048c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
6058c2ecf20Sopenharmony_ci		      test_bit(S_READY, &il->status));
6068c2ecf20Sopenharmony_ci	pos +=
6078c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
6088c2ecf20Sopenharmony_ci		      test_bit(S_TEMPERATURE, &il->status));
6098c2ecf20Sopenharmony_ci	pos +=
6108c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
6118c2ecf20Sopenharmony_ci		      test_bit(S_GEO_CONFIGURED, &il->status));
6128c2ecf20Sopenharmony_ci	pos +=
6138c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
6148c2ecf20Sopenharmony_ci		      test_bit(S_EXIT_PENDING, &il->status));
6158c2ecf20Sopenharmony_ci	pos +=
6168c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
6178c2ecf20Sopenharmony_ci		      test_bit(S_STATS, &il->status));
6188c2ecf20Sopenharmony_ci	pos +=
6198c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
6208c2ecf20Sopenharmony_ci		      test_bit(S_SCANNING, &il->status));
6218c2ecf20Sopenharmony_ci	pos +=
6228c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
6238c2ecf20Sopenharmony_ci		      test_bit(S_SCAN_ABORTING, &il->status));
6248c2ecf20Sopenharmony_ci	pos +=
6258c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
6268c2ecf20Sopenharmony_ci		      test_bit(S_SCAN_HW, &il->status));
6278c2ecf20Sopenharmony_ci	pos +=
6288c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
6298c2ecf20Sopenharmony_ci		      test_bit(S_POWER_PMI, &il->status));
6308c2ecf20Sopenharmony_ci	pos +=
6318c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
6328c2ecf20Sopenharmony_ci		      test_bit(S_FW_ERROR, &il->status));
6338c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
6348c2ecf20Sopenharmony_ci}
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_cistatic ssize_t
6378c2ecf20Sopenharmony_ciil_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
6388c2ecf20Sopenharmony_ci			loff_t *ppos)
6398c2ecf20Sopenharmony_ci{
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
6428c2ecf20Sopenharmony_ci	int pos = 0;
6438c2ecf20Sopenharmony_ci	int cnt = 0;
6448c2ecf20Sopenharmony_ci	char *buf;
6458c2ecf20Sopenharmony_ci	int bufsz = 24 * 64;	/* 24 items * 64 char per item */
6468c2ecf20Sopenharmony_ci	ssize_t ret;
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
6498c2ecf20Sopenharmony_ci	if (!buf) {
6508c2ecf20Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
6518c2ecf20Sopenharmony_ci		return -ENOMEM;
6528c2ecf20Sopenharmony_ci	}
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	pos +=
6558c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Interrupt Statistics Report:\n");
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci	pos +=
6588c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
6598c2ecf20Sopenharmony_ci		      il->isr_stats.hw);
6608c2ecf20Sopenharmony_ci	pos +=
6618c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
6628c2ecf20Sopenharmony_ci		      il->isr_stats.sw);
6638c2ecf20Sopenharmony_ci	if (il->isr_stats.sw || il->isr_stats.hw) {
6648c2ecf20Sopenharmony_ci		pos +=
6658c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
6668c2ecf20Sopenharmony_ci			      "\tLast Restarting Code:  0x%X\n",
6678c2ecf20Sopenharmony_ci			      il->isr_stats.err_code);
6688c2ecf20Sopenharmony_ci	}
6698c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLEGACY_DEBUG
6708c2ecf20Sopenharmony_ci	pos +=
6718c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
6728c2ecf20Sopenharmony_ci		      il->isr_stats.sch);
6738c2ecf20Sopenharmony_ci	pos +=
6748c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
6758c2ecf20Sopenharmony_ci		      il->isr_stats.alive);
6768c2ecf20Sopenharmony_ci#endif
6778c2ecf20Sopenharmony_ci	pos +=
6788c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
6798c2ecf20Sopenharmony_ci		      "HW RF KILL switch toggled:\t %u\n",
6808c2ecf20Sopenharmony_ci		      il->isr_stats.rfkill);
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	pos +=
6838c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
6848c2ecf20Sopenharmony_ci		      il->isr_stats.ctkill);
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	pos +=
6878c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
6888c2ecf20Sopenharmony_ci		      il->isr_stats.wakeup);
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	pos +=
6918c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
6928c2ecf20Sopenharmony_ci		      il->isr_stats.rx);
6938c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
6948c2ecf20Sopenharmony_ci		if (il->isr_stats.handlers[cnt] > 0)
6958c2ecf20Sopenharmony_ci			pos +=
6968c2ecf20Sopenharmony_ci			    scnprintf(buf + pos, bufsz - pos,
6978c2ecf20Sopenharmony_ci				      "\tRx handler[%36s]:\t\t %u\n",
6988c2ecf20Sopenharmony_ci				      il_get_cmd_string(cnt),
6998c2ecf20Sopenharmony_ci				      il->isr_stats.handlers[cnt]);
7008c2ecf20Sopenharmony_ci	}
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci	pos +=
7038c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
7048c2ecf20Sopenharmony_ci		      il->isr_stats.tx);
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	pos +=
7078c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
7088c2ecf20Sopenharmony_ci		      il->isr_stats.unhandled);
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
7118c2ecf20Sopenharmony_ci	kfree(buf);
7128c2ecf20Sopenharmony_ci	return ret;
7138c2ecf20Sopenharmony_ci}
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_cistatic ssize_t
7168c2ecf20Sopenharmony_ciil_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
7178c2ecf20Sopenharmony_ci			 size_t count, loff_t *ppos)
7188c2ecf20Sopenharmony_ci{
7198c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
7208c2ecf20Sopenharmony_ci	char buf[8];
7218c2ecf20Sopenharmony_ci	int buf_size;
7228c2ecf20Sopenharmony_ci	u32 reset_flag;
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
7258c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
7268c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
7278c2ecf20Sopenharmony_ci		return -EFAULT;
7288c2ecf20Sopenharmony_ci	if (sscanf(buf, "%x", &reset_flag) != 1)
7298c2ecf20Sopenharmony_ci		return -EFAULT;
7308c2ecf20Sopenharmony_ci	if (reset_flag == 0)
7318c2ecf20Sopenharmony_ci		il_clear_isr_stats(il);
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci	return count;
7348c2ecf20Sopenharmony_ci}
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_cistatic ssize_t
7378c2ecf20Sopenharmony_ciil_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
7388c2ecf20Sopenharmony_ci		  loff_t *ppos)
7398c2ecf20Sopenharmony_ci{
7408c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
7418c2ecf20Sopenharmony_ci	int pos = 0, i;
7428c2ecf20Sopenharmony_ci	char buf[256];
7438c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_ci	for (i = 0; i < AC_NUM; i++) {
7468c2ecf20Sopenharmony_ci		pos +=
7478c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
7488c2ecf20Sopenharmony_ci			      "\tcw_min\tcw_max\taifsn\ttxop\n");
7498c2ecf20Sopenharmony_ci		pos +=
7508c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
7518c2ecf20Sopenharmony_ci			      "AC[%d]\t%u\t%u\t%u\t%u\n", i,
7528c2ecf20Sopenharmony_ci			      il->qos_data.def_qos_parm.ac[i].cw_min,
7538c2ecf20Sopenharmony_ci			      il->qos_data.def_qos_parm.ac[i].cw_max,
7548c2ecf20Sopenharmony_ci			      il->qos_data.def_qos_parm.ac[i].aifsn,
7558c2ecf20Sopenharmony_ci			      il->qos_data.def_qos_parm.ac[i].edca_txop);
7568c2ecf20Sopenharmony_ci	}
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
7598c2ecf20Sopenharmony_ci}
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_cistatic ssize_t
7628c2ecf20Sopenharmony_ciil_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
7638c2ecf20Sopenharmony_ci			    size_t count, loff_t *ppos)
7648c2ecf20Sopenharmony_ci{
7658c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
7668c2ecf20Sopenharmony_ci	char buf[8];
7678c2ecf20Sopenharmony_ci	int buf_size;
7688c2ecf20Sopenharmony_ci	int ht40;
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
7718c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
7728c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
7738c2ecf20Sopenharmony_ci		return -EFAULT;
7748c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &ht40) != 1)
7758c2ecf20Sopenharmony_ci		return -EFAULT;
7768c2ecf20Sopenharmony_ci	if (!il_is_any_associated(il))
7778c2ecf20Sopenharmony_ci		il->disable_ht40 = ht40 ? true : false;
7788c2ecf20Sopenharmony_ci	else {
7798c2ecf20Sopenharmony_ci		IL_ERR("Sta associated with AP - "
7808c2ecf20Sopenharmony_ci		       "Change to 40MHz channel support is not allowed\n");
7818c2ecf20Sopenharmony_ci		return -EINVAL;
7828c2ecf20Sopenharmony_ci	}
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci	return count;
7858c2ecf20Sopenharmony_ci}
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_cistatic ssize_t
7888c2ecf20Sopenharmony_ciil_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
7898c2ecf20Sopenharmony_ci			   size_t count, loff_t *ppos)
7908c2ecf20Sopenharmony_ci{
7918c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
7928c2ecf20Sopenharmony_ci	char buf[100];
7938c2ecf20Sopenharmony_ci	int pos = 0;
7948c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci	pos +=
7978c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
7988c2ecf20Sopenharmony_ci		      il->disable_ht40 ? "Disabled" : "Enabled");
7998c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8008c2ecf20Sopenharmony_ci}
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(sram);
8038c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(nvm);
8048c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(stations);
8058c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(channels);
8068c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(status);
8078c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(interrupt);
8088c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(qos);
8098c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_cistatic ssize_t
8128c2ecf20Sopenharmony_ciil_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
8138c2ecf20Sopenharmony_ci		       loff_t *ppos)
8148c2ecf20Sopenharmony_ci{
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
8178c2ecf20Sopenharmony_ci	struct il_tx_queue *txq;
8188c2ecf20Sopenharmony_ci	struct il_queue *q;
8198c2ecf20Sopenharmony_ci	char *buf;
8208c2ecf20Sopenharmony_ci	int pos = 0;
8218c2ecf20Sopenharmony_ci	int cnt;
8228c2ecf20Sopenharmony_ci	int ret;
8238c2ecf20Sopenharmony_ci	const size_t bufsz =
8248c2ecf20Sopenharmony_ci	    sizeof(char) * 64 * il->cfg->num_of_queues;
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_ci	if (!il->txq) {
8278c2ecf20Sopenharmony_ci		IL_ERR("txq not ready\n");
8288c2ecf20Sopenharmony_ci		return -EAGAIN;
8298c2ecf20Sopenharmony_ci	}
8308c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
8318c2ecf20Sopenharmony_ci	if (!buf)
8328c2ecf20Sopenharmony_ci		return -ENOMEM;
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
8358c2ecf20Sopenharmony_ci		txq = &il->txq[cnt];
8368c2ecf20Sopenharmony_ci		q = &txq->q;
8378c2ecf20Sopenharmony_ci		pos +=
8388c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
8398c2ecf20Sopenharmony_ci			      "hwq %.2d: read=%u write=%u stop=%d"
8408c2ecf20Sopenharmony_ci			      " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
8418c2ecf20Sopenharmony_ci			      q->read_ptr, q->write_ptr,
8428c2ecf20Sopenharmony_ci			      !!test_bit(cnt, il->queue_stopped),
8438c2ecf20Sopenharmony_ci			      txq->swq_id, txq->swq_id & 3,
8448c2ecf20Sopenharmony_ci			      (txq->swq_id >> 2) & 0x1f);
8458c2ecf20Sopenharmony_ci		if (cnt >= 4)
8468c2ecf20Sopenharmony_ci			continue;
8478c2ecf20Sopenharmony_ci		/* for the ACs, display the stop count too */
8488c2ecf20Sopenharmony_ci		pos +=
8498c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
8508c2ecf20Sopenharmony_ci			      "        stop-count: %d\n",
8518c2ecf20Sopenharmony_ci			      atomic_read(&il->queue_stop_count[cnt]));
8528c2ecf20Sopenharmony_ci	}
8538c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8548c2ecf20Sopenharmony_ci	kfree(buf);
8558c2ecf20Sopenharmony_ci	return ret;
8568c2ecf20Sopenharmony_ci}
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_cistatic ssize_t
8598c2ecf20Sopenharmony_ciil_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
8608c2ecf20Sopenharmony_ci		       loff_t *ppos)
8618c2ecf20Sopenharmony_ci{
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
8648c2ecf20Sopenharmony_ci	struct il_rx_queue *rxq = &il->rxq;
8658c2ecf20Sopenharmony_ci	char buf[256];
8668c2ecf20Sopenharmony_ci	int pos = 0;
8678c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", rxq->read);
8708c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", rxq->write);
8718c2ecf20Sopenharmony_ci	pos +=
8728c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
8738c2ecf20Sopenharmony_ci		      rxq->free_count);
8748c2ecf20Sopenharmony_ci	if (rxq->rb_stts) {
8758c2ecf20Sopenharmony_ci		pos +=
8768c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
8778c2ecf20Sopenharmony_ci			      le16_to_cpu(rxq->rb_stts->
8788c2ecf20Sopenharmony_ci					  closed_rb_num) & 0x0FFF);
8798c2ecf20Sopenharmony_ci	} else {
8808c2ecf20Sopenharmony_ci		pos +=
8818c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos,
8828c2ecf20Sopenharmony_ci			      "closed_rb_num: Not Allocated\n");
8838c2ecf20Sopenharmony_ci	}
8848c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8858c2ecf20Sopenharmony_ci}
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_cistatic ssize_t
8888c2ecf20Sopenharmony_ciil_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
8898c2ecf20Sopenharmony_ci			     size_t count, loff_t *ppos)
8908c2ecf20Sopenharmony_ci{
8918c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_ci	return il->debugfs_ops->rx_stats_read(file, user_buf, count, ppos);
8948c2ecf20Sopenharmony_ci}
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_cistatic ssize_t
8978c2ecf20Sopenharmony_ciil_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
8988c2ecf20Sopenharmony_ci			     size_t count, loff_t *ppos)
8998c2ecf20Sopenharmony_ci{
9008c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci	return il->debugfs_ops->tx_stats_read(file, user_buf, count, ppos);
9038c2ecf20Sopenharmony_ci}
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_cistatic ssize_t
9068c2ecf20Sopenharmony_ciil_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
9078c2ecf20Sopenharmony_ci				  size_t count, loff_t *ppos)
9088c2ecf20Sopenharmony_ci{
9098c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci	return il->debugfs_ops->general_stats_read(file, user_buf, count, ppos);
9128c2ecf20Sopenharmony_ci}
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_cistatic ssize_t
9158c2ecf20Sopenharmony_ciil_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
9168c2ecf20Sopenharmony_ci			  size_t count, loff_t *ppos)
9178c2ecf20Sopenharmony_ci{
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
9208c2ecf20Sopenharmony_ci	int pos = 0;
9218c2ecf20Sopenharmony_ci	int cnt = 0;
9228c2ecf20Sopenharmony_ci	char *buf;
9238c2ecf20Sopenharmony_ci	int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
9248c2ecf20Sopenharmony_ci	ssize_t ret;
9258c2ecf20Sopenharmony_ci	struct il_sensitivity_data *data;
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci	data = &il->sensitivity_data;
9288c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
9298c2ecf20Sopenharmony_ci	if (!buf) {
9308c2ecf20Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
9318c2ecf20Sopenharmony_ci		return -ENOMEM;
9328c2ecf20Sopenharmony_ci	}
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci	pos +=
9358c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
9368c2ecf20Sopenharmony_ci		      data->auto_corr_ofdm);
9378c2ecf20Sopenharmony_ci	pos +=
9388c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc:\t\t %u\n",
9398c2ecf20Sopenharmony_ci		      data->auto_corr_ofdm_mrc);
9408c2ecf20Sopenharmony_ci	pos +=
9418c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
9428c2ecf20Sopenharmony_ci		      data->auto_corr_ofdm_x1);
9438c2ecf20Sopenharmony_ci	pos +=
9448c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc_x1:\t\t %u\n",
9458c2ecf20Sopenharmony_ci		      data->auto_corr_ofdm_mrc_x1);
9468c2ecf20Sopenharmony_ci	pos +=
9478c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
9488c2ecf20Sopenharmony_ci		      data->auto_corr_cck);
9498c2ecf20Sopenharmony_ci	pos +=
9508c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
9518c2ecf20Sopenharmony_ci		      data->auto_corr_cck_mrc);
9528c2ecf20Sopenharmony_ci	pos +=
9538c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
9548c2ecf20Sopenharmony_ci		      "last_bad_plcp_cnt_ofdm:\t\t %u\n",
9558c2ecf20Sopenharmony_ci		      data->last_bad_plcp_cnt_ofdm);
9568c2ecf20Sopenharmony_ci	pos +=
9578c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
9588c2ecf20Sopenharmony_ci		      data->last_fa_cnt_ofdm);
9598c2ecf20Sopenharmony_ci	pos +=
9608c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "last_bad_plcp_cnt_cck:\t\t %u\n",
9618c2ecf20Sopenharmony_ci		      data->last_bad_plcp_cnt_cck);
9628c2ecf20Sopenharmony_ci	pos +=
9638c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
9648c2ecf20Sopenharmony_ci		      data->last_fa_cnt_cck);
9658c2ecf20Sopenharmony_ci	pos +=
9668c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
9678c2ecf20Sopenharmony_ci		      data->nrg_curr_state);
9688c2ecf20Sopenharmony_ci	pos +=
9698c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
9708c2ecf20Sopenharmony_ci		      data->nrg_prev_state);
9718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
9728c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < 10; cnt++) {
9738c2ecf20Sopenharmony_ci		pos +=
9748c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, " %u",
9758c2ecf20Sopenharmony_ci			      data->nrg_value[cnt]);
9768c2ecf20Sopenharmony_ci	}
9778c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
9788c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
9798c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
9808c2ecf20Sopenharmony_ci		pos +=
9818c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, " %u",
9828c2ecf20Sopenharmony_ci			      data->nrg_silence_rssi[cnt]);
9838c2ecf20Sopenharmony_ci	}
9848c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
9858c2ecf20Sopenharmony_ci	pos +=
9868c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
9878c2ecf20Sopenharmony_ci		      data->nrg_silence_ref);
9888c2ecf20Sopenharmony_ci	pos +=
9898c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
9908c2ecf20Sopenharmony_ci		      data->nrg_energy_idx);
9918c2ecf20Sopenharmony_ci	pos +=
9928c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
9938c2ecf20Sopenharmony_ci		      data->nrg_silence_idx);
9948c2ecf20Sopenharmony_ci	pos +=
9958c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
9968c2ecf20Sopenharmony_ci		      data->nrg_th_cck);
9978c2ecf20Sopenharmony_ci	pos +=
9988c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
9998c2ecf20Sopenharmony_ci		      "nrg_auto_corr_silence_diff:\t %u\n",
10008c2ecf20Sopenharmony_ci		      data->nrg_auto_corr_silence_diff);
10018c2ecf20Sopenharmony_ci	pos +=
10028c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
10038c2ecf20Sopenharmony_ci		      data->num_in_cck_no_fa);
10048c2ecf20Sopenharmony_ci	pos +=
10058c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
10068c2ecf20Sopenharmony_ci		      data->nrg_th_ofdm);
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
10098c2ecf20Sopenharmony_ci	kfree(buf);
10108c2ecf20Sopenharmony_ci	return ret;
10118c2ecf20Sopenharmony_ci}
10128c2ecf20Sopenharmony_ci
10138c2ecf20Sopenharmony_cistatic ssize_t
10148c2ecf20Sopenharmony_ciil_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
10158c2ecf20Sopenharmony_ci			  size_t count, loff_t *ppos)
10168c2ecf20Sopenharmony_ci{
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
10198c2ecf20Sopenharmony_ci	int pos = 0;
10208c2ecf20Sopenharmony_ci	int cnt = 0;
10218c2ecf20Sopenharmony_ci	char *buf;
10228c2ecf20Sopenharmony_ci	int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
10238c2ecf20Sopenharmony_ci	ssize_t ret;
10248c2ecf20Sopenharmony_ci	struct il_chain_noise_data *data;
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci	data = &il->chain_noise_data;
10278c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
10288c2ecf20Sopenharmony_ci	if (!buf) {
10298c2ecf20Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
10308c2ecf20Sopenharmony_ci		return -ENOMEM;
10318c2ecf20Sopenharmony_ci	}
10328c2ecf20Sopenharmony_ci
10338c2ecf20Sopenharmony_ci	pos +=
10348c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
10358c2ecf20Sopenharmony_ci		      data->active_chains);
10368c2ecf20Sopenharmony_ci	pos +=
10378c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
10388c2ecf20Sopenharmony_ci		      data->chain_noise_a);
10398c2ecf20Sopenharmony_ci	pos +=
10408c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
10418c2ecf20Sopenharmony_ci		      data->chain_noise_b);
10428c2ecf20Sopenharmony_ci	pos +=
10438c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
10448c2ecf20Sopenharmony_ci		      data->chain_noise_c);
10458c2ecf20Sopenharmony_ci	pos +=
10468c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
10478c2ecf20Sopenharmony_ci		      data->chain_signal_a);
10488c2ecf20Sopenharmony_ci	pos +=
10498c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
10508c2ecf20Sopenharmony_ci		      data->chain_signal_b);
10518c2ecf20Sopenharmony_ci	pos +=
10528c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
10538c2ecf20Sopenharmony_ci		      data->chain_signal_c);
10548c2ecf20Sopenharmony_ci	pos +=
10558c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
10568c2ecf20Sopenharmony_ci		      data->beacon_count);
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
10598c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
10608c2ecf20Sopenharmony_ci		pos +=
10618c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, " %u",
10628c2ecf20Sopenharmony_ci			      data->disconn_array[cnt]);
10638c2ecf20Sopenharmony_ci	}
10648c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
10658c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
10668c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
10678c2ecf20Sopenharmony_ci		pos +=
10688c2ecf20Sopenharmony_ci		    scnprintf(buf + pos, bufsz - pos, " %u",
10698c2ecf20Sopenharmony_ci			      data->delta_gain_code[cnt]);
10708c2ecf20Sopenharmony_ci	}
10718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
10728c2ecf20Sopenharmony_ci	pos +=
10738c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
10748c2ecf20Sopenharmony_ci		      data->radio_write);
10758c2ecf20Sopenharmony_ci	pos +=
10768c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
10778c2ecf20Sopenharmony_ci		      data->state);
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
10808c2ecf20Sopenharmony_ci	kfree(buf);
10818c2ecf20Sopenharmony_ci	return ret;
10828c2ecf20Sopenharmony_ci}
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_cistatic ssize_t
10858c2ecf20Sopenharmony_ciil_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
10868c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
10878c2ecf20Sopenharmony_ci{
10888c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
10898c2ecf20Sopenharmony_ci	char buf[60];
10908c2ecf20Sopenharmony_ci	int pos = 0;
10918c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
10928c2ecf20Sopenharmony_ci	u32 pwrsave_status;
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci	pwrsave_status =
10958c2ecf20Sopenharmony_ci	    _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
10968c2ecf20Sopenharmony_ci
10978c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
10988c2ecf20Sopenharmony_ci	pos +=
10998c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "%s\n",
11008c2ecf20Sopenharmony_ci		      (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
11018c2ecf20Sopenharmony_ci		      (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
11028c2ecf20Sopenharmony_ci		      (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
11038c2ecf20Sopenharmony_ci		      "error");
11048c2ecf20Sopenharmony_ci
11058c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
11068c2ecf20Sopenharmony_ci}
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_cistatic ssize_t
11098c2ecf20Sopenharmony_ciil_dbgfs_clear_ucode_stats_write(struct file *file,
11108c2ecf20Sopenharmony_ci				 const char __user *user_buf, size_t count,
11118c2ecf20Sopenharmony_ci				 loff_t *ppos)
11128c2ecf20Sopenharmony_ci{
11138c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
11148c2ecf20Sopenharmony_ci	char buf[8];
11158c2ecf20Sopenharmony_ci	int buf_size;
11168c2ecf20Sopenharmony_ci	int clear;
11178c2ecf20Sopenharmony_ci
11188c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
11198c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
11208c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
11218c2ecf20Sopenharmony_ci		return -EFAULT;
11228c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &clear) != 1)
11238c2ecf20Sopenharmony_ci		return -EFAULT;
11248c2ecf20Sopenharmony_ci
11258c2ecf20Sopenharmony_ci	/* make request to uCode to retrieve stats information */
11268c2ecf20Sopenharmony_ci	mutex_lock(&il->mutex);
11278c2ecf20Sopenharmony_ci	il_send_stats_request(il, CMD_SYNC, true);
11288c2ecf20Sopenharmony_ci	mutex_unlock(&il->mutex);
11298c2ecf20Sopenharmony_ci
11308c2ecf20Sopenharmony_ci	return count;
11318c2ecf20Sopenharmony_ci}
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_cistatic ssize_t
11348c2ecf20Sopenharmony_ciil_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
11358c2ecf20Sopenharmony_ci			 size_t count, loff_t *ppos)
11368c2ecf20Sopenharmony_ci{
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
11398c2ecf20Sopenharmony_ci	int len = 0;
11408c2ecf20Sopenharmony_ci	char buf[20];
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci	len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.flags));
11438c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
11448c2ecf20Sopenharmony_ci}
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_cistatic ssize_t
11478c2ecf20Sopenharmony_ciil_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
11488c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
11498c2ecf20Sopenharmony_ci{
11508c2ecf20Sopenharmony_ci
11518c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
11528c2ecf20Sopenharmony_ci	int len = 0;
11538c2ecf20Sopenharmony_ci	char buf[20];
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	len =
11568c2ecf20Sopenharmony_ci	    sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags));
11578c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
11588c2ecf20Sopenharmony_ci}
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_cistatic ssize_t
11618c2ecf20Sopenharmony_ciil_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
11628c2ecf20Sopenharmony_ci		     loff_t *ppos)
11638c2ecf20Sopenharmony_ci{
11648c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
11658c2ecf20Sopenharmony_ci	char *buf;
11668c2ecf20Sopenharmony_ci	int pos = 0;
11678c2ecf20Sopenharmony_ci	ssize_t ret = -EFAULT;
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_ci	if (il->ops->dump_fh) {
11708c2ecf20Sopenharmony_ci		ret = pos = il->ops->dump_fh(il, &buf, true);
11718c2ecf20Sopenharmony_ci		if (buf) {
11728c2ecf20Sopenharmony_ci			ret =
11738c2ecf20Sopenharmony_ci			    simple_read_from_buffer(user_buf, count, ppos, buf,
11748c2ecf20Sopenharmony_ci						    pos);
11758c2ecf20Sopenharmony_ci			kfree(buf);
11768c2ecf20Sopenharmony_ci		}
11778c2ecf20Sopenharmony_ci	}
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci	return ret;
11808c2ecf20Sopenharmony_ci}
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_cistatic ssize_t
11838c2ecf20Sopenharmony_ciil_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
11848c2ecf20Sopenharmony_ci			    size_t count, loff_t *ppos)
11858c2ecf20Sopenharmony_ci{
11868c2ecf20Sopenharmony_ci
11878c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
11888c2ecf20Sopenharmony_ci	int pos = 0;
11898c2ecf20Sopenharmony_ci	char buf[12];
11908c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci	pos +=
11938c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "%d\n",
11948c2ecf20Sopenharmony_ci		      il->missed_beacon_threshold);
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
11978c2ecf20Sopenharmony_ci}
11988c2ecf20Sopenharmony_ci
11998c2ecf20Sopenharmony_cistatic ssize_t
12008c2ecf20Sopenharmony_ciil_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
12018c2ecf20Sopenharmony_ci			     size_t count, loff_t *ppos)
12028c2ecf20Sopenharmony_ci{
12038c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
12048c2ecf20Sopenharmony_ci	char buf[8];
12058c2ecf20Sopenharmony_ci	int buf_size;
12068c2ecf20Sopenharmony_ci	int missed;
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
12098c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
12108c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
12118c2ecf20Sopenharmony_ci		return -EFAULT;
12128c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &missed) != 1)
12138c2ecf20Sopenharmony_ci		return -EINVAL;
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci	if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
12168c2ecf20Sopenharmony_ci	    missed > IL_MISSED_BEACON_THRESHOLD_MAX)
12178c2ecf20Sopenharmony_ci		il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
12188c2ecf20Sopenharmony_ci	else
12198c2ecf20Sopenharmony_ci		il->missed_beacon_threshold = missed;
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci	return count;
12228c2ecf20Sopenharmony_ci}
12238c2ecf20Sopenharmony_ci
12248c2ecf20Sopenharmony_cistatic ssize_t
12258c2ecf20Sopenharmony_ciil_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
12268c2ecf20Sopenharmony_ci			  size_t count, loff_t *ppos)
12278c2ecf20Sopenharmony_ci{
12288c2ecf20Sopenharmony_ci
12298c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
12308c2ecf20Sopenharmony_ci	int pos = 0;
12318c2ecf20Sopenharmony_ci	char buf[300];
12328c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
12338c2ecf20Sopenharmony_ci	struct il_force_reset *force_reset;
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci	force_reset = &il->force_reset;
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci	pos +=
12388c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "\tnumber of reset request: %d\n",
12398c2ecf20Sopenharmony_ci		      force_reset->reset_request_count);
12408c2ecf20Sopenharmony_ci	pos +=
12418c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
12428c2ecf20Sopenharmony_ci		      "\tnumber of reset request success: %d\n",
12438c2ecf20Sopenharmony_ci		      force_reset->reset_success_count);
12448c2ecf20Sopenharmony_ci	pos +=
12458c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
12468c2ecf20Sopenharmony_ci		      "\tnumber of reset request reject: %d\n",
12478c2ecf20Sopenharmony_ci		      force_reset->reset_reject_count);
12488c2ecf20Sopenharmony_ci	pos +=
12498c2ecf20Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "\treset duration: %lu\n",
12508c2ecf20Sopenharmony_ci		      force_reset->reset_duration);
12518c2ecf20Sopenharmony_ci
12528c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
12538c2ecf20Sopenharmony_ci}
12548c2ecf20Sopenharmony_ci
12558c2ecf20Sopenharmony_cistatic ssize_t
12568c2ecf20Sopenharmony_ciil_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
12578c2ecf20Sopenharmony_ci			   size_t count, loff_t *ppos)
12588c2ecf20Sopenharmony_ci{
12598c2ecf20Sopenharmony_ci
12608c2ecf20Sopenharmony_ci	int ret;
12618c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_ci	ret = il_force_reset(il, true);
12648c2ecf20Sopenharmony_ci
12658c2ecf20Sopenharmony_ci	return ret ? ret : count;
12668c2ecf20Sopenharmony_ci}
12678c2ecf20Sopenharmony_ci
12688c2ecf20Sopenharmony_cistatic ssize_t
12698c2ecf20Sopenharmony_ciil_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
12708c2ecf20Sopenharmony_ci			  size_t count, loff_t *ppos)
12718c2ecf20Sopenharmony_ci{
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci	struct il_priv *il = file->private_data;
12748c2ecf20Sopenharmony_ci	char buf[8];
12758c2ecf20Sopenharmony_ci	int buf_size;
12768c2ecf20Sopenharmony_ci	int timeout;
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
12798c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
12808c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
12818c2ecf20Sopenharmony_ci		return -EFAULT;
12828c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &timeout) != 1)
12838c2ecf20Sopenharmony_ci		return -EINVAL;
12848c2ecf20Sopenharmony_ci	if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
12858c2ecf20Sopenharmony_ci		timeout = IL_DEF_WD_TIMEOUT;
12868c2ecf20Sopenharmony_ci
12878c2ecf20Sopenharmony_ci	il->cfg->wd_timeout = timeout;
12888c2ecf20Sopenharmony_ci	il_setup_watchdog(il);
12898c2ecf20Sopenharmony_ci	return count;
12908c2ecf20Sopenharmony_ci}
12918c2ecf20Sopenharmony_ci
12928c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(rx_stats);
12938c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(tx_stats);
12948c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(rx_queue);
12958c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(tx_queue);
12968c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_rx_stats);
12978c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_tx_stats);
12988c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_general_stats);
12998c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(sensitivity);
13008c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(chain_noise);
13018c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(power_save_status);
13028c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
13038c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
13048c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(fh_reg);
13058c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
13068c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(force_reset);
13078c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(rxon_flags);
13088c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(rxon_filter_flags);
13098c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(wd_timeout);
13108c2ecf20Sopenharmony_ci
13118c2ecf20Sopenharmony_ci/*
13128c2ecf20Sopenharmony_ci * Create the debugfs files and directories
13138c2ecf20Sopenharmony_ci *
13148c2ecf20Sopenharmony_ci */
13158c2ecf20Sopenharmony_civoid
13168c2ecf20Sopenharmony_ciil_dbgfs_register(struct il_priv *il, const char *name)
13178c2ecf20Sopenharmony_ci{
13188c2ecf20Sopenharmony_ci	struct dentry *phyd = il->hw->wiphy->debugfsdir;
13198c2ecf20Sopenharmony_ci	struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
13208c2ecf20Sopenharmony_ci
13218c2ecf20Sopenharmony_ci	dir_drv = debugfs_create_dir(name, phyd);
13228c2ecf20Sopenharmony_ci	il->debugfs_dir = dir_drv;
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci	dir_data = debugfs_create_dir("data", dir_drv);
13258c2ecf20Sopenharmony_ci	dir_rf = debugfs_create_dir("rf", dir_drv);
13268c2ecf20Sopenharmony_ci	dir_debug = debugfs_create_dir("debug", dir_drv);
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(nvm, dir_data, 0400);
13298c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(sram, dir_data, 0600);
13308c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(stations, dir_data, 0400);
13318c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(channels, dir_data, 0400);
13328c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(status, dir_data, 0400);
13338c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(interrupt, dir_data, 0600);
13348c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(qos, dir_data, 0400);
13358c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(disable_ht40, dir_data, 0600);
13368c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rx_stats, dir_debug, 0400);
13378c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(tx_stats, dir_debug, 0400);
13388c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rx_queue, dir_debug, 0400);
13398c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(tx_queue, dir_debug, 0400);
13408c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(power_save_status, dir_debug, 0400);
13418c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, 0200);
13428c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, 0200);
13438c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(fh_reg, dir_debug, 0400);
13448c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(missed_beacon, dir_debug, 0200);
13458c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(force_reset, dir_debug, 0600);
13468c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, 0400);
13478c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, 0400);
13488c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, 0400);
13498c2ecf20Sopenharmony_ci
13508c2ecf20Sopenharmony_ci	if (il->cfg->sensitivity_calib_by_driver)
13518c2ecf20Sopenharmony_ci		DEBUGFS_ADD_FILE(sensitivity, dir_debug, 0400);
13528c2ecf20Sopenharmony_ci	if (il->cfg->chain_noise_calib_by_driver)
13538c2ecf20Sopenharmony_ci		DEBUGFS_ADD_FILE(chain_noise, dir_debug, 0400);
13548c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rxon_flags, dir_debug, 0200);
13558c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, 0200);
13568c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(wd_timeout, dir_debug, 0200);
13578c2ecf20Sopenharmony_ci	if (il->cfg->sensitivity_calib_by_driver)
13588c2ecf20Sopenharmony_ci		DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
13598c2ecf20Sopenharmony_ci				 &il->disable_sens_cal);
13608c2ecf20Sopenharmony_ci	if (il->cfg->chain_noise_calib_by_driver)
13618c2ecf20Sopenharmony_ci		DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
13628c2ecf20Sopenharmony_ci				 &il->disable_chain_noise_cal);
13638c2ecf20Sopenharmony_ci	DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
13648c2ecf20Sopenharmony_ci}
13658c2ecf20Sopenharmony_ciEXPORT_SYMBOL(il_dbgfs_register);
13668c2ecf20Sopenharmony_ci
13678c2ecf20Sopenharmony_ci/*
13688c2ecf20Sopenharmony_ci * Remove the debugfs files and directories
13698c2ecf20Sopenharmony_ci */
13708c2ecf20Sopenharmony_civoid
13718c2ecf20Sopenharmony_ciil_dbgfs_unregister(struct il_priv *il)
13728c2ecf20Sopenharmony_ci{
13738c2ecf20Sopenharmony_ci	if (!il->debugfs_dir)
13748c2ecf20Sopenharmony_ci		return;
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_ci	debugfs_remove_recursive(il->debugfs_dir);
13778c2ecf20Sopenharmony_ci	il->debugfs_dir = NULL;
13788c2ecf20Sopenharmony_ci}
13798c2ecf20Sopenharmony_ciEXPORT_SYMBOL(il_dbgfs_unregister);
1380