18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright (C) 2018 Intel Corporation
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Contact Information:
88c2ecf20Sopenharmony_ci *  Intel Linux Wireless <linuxwifi@intel.com>
98c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
108c2ecf20Sopenharmony_ci *****************************************************************************/
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/slab.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
168c2ecf20Sopenharmony_ci#include <linux/ieee80211.h>
178c2ecf20Sopenharmony_ci#include <net/mac80211.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "iwl-debug.h"
208c2ecf20Sopenharmony_ci#include "iwl-trans.h"
218c2ecf20Sopenharmony_ci#include "iwl-io.h"
228c2ecf20Sopenharmony_ci#include "dev.h"
238c2ecf20Sopenharmony_ci#include "agn.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* create and remove of files */
268c2ecf20Sopenharmony_ci#define DEBUGFS_ADD_FILE(name, parent, mode) do {			\
278c2ecf20Sopenharmony_ci	debugfs_create_file(#name, mode, parent, priv,			\
288c2ecf20Sopenharmony_ci			    &iwl_dbgfs_##name##_ops);			\
298c2ecf20Sopenharmony_ci} while (0)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* file operation */
328c2ecf20Sopenharmony_ci#define DEBUGFS_READ_FILE_OPS(name)                                     \
338c2ecf20Sopenharmony_cistatic const struct file_operations iwl_dbgfs_##name##_ops = {          \
348c2ecf20Sopenharmony_ci	.read = iwl_dbgfs_##name##_read,				\
358c2ecf20Sopenharmony_ci	.open = simple_open,						\
368c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,					\
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define DEBUGFS_WRITE_FILE_OPS(name)                                    \
408c2ecf20Sopenharmony_cistatic const struct file_operations iwl_dbgfs_##name##_ops = {          \
418c2ecf20Sopenharmony_ci	.write = iwl_dbgfs_##name##_write,                              \
428c2ecf20Sopenharmony_ci	.open = simple_open,						\
438c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,					\
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define DEBUGFS_READ_WRITE_FILE_OPS(name)                               \
488c2ecf20Sopenharmony_cistatic const struct file_operations iwl_dbgfs_##name##_ops = {          \
498c2ecf20Sopenharmony_ci	.write = iwl_dbgfs_##name##_write,                              \
508c2ecf20Sopenharmony_ci	.read = iwl_dbgfs_##name##_read,                                \
518c2ecf20Sopenharmony_ci	.open = simple_open,						\
528c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,					\
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_sram_read(struct file *file,
568c2ecf20Sopenharmony_ci					char __user *user_buf,
578c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	u32 val = 0;
608c2ecf20Sopenharmony_ci	char *buf;
618c2ecf20Sopenharmony_ci	ssize_t ret;
628c2ecf20Sopenharmony_ci	int i = 0;
638c2ecf20Sopenharmony_ci	bool device_format = false;
648c2ecf20Sopenharmony_ci	int offset = 0;
658c2ecf20Sopenharmony_ci	int len = 0;
668c2ecf20Sopenharmony_ci	int pos = 0;
678c2ecf20Sopenharmony_ci	int sram;
688c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
698c2ecf20Sopenharmony_ci	const struct fw_img *img;
708c2ecf20Sopenharmony_ci	size_t bufsz;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	if (!iwl_is_ready_rf(priv))
738c2ecf20Sopenharmony_ci		return -EAGAIN;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	/* default is to dump the entire data segment */
768c2ecf20Sopenharmony_ci	if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
778c2ecf20Sopenharmony_ci		priv->dbgfs_sram_offset = 0x800000;
788c2ecf20Sopenharmony_ci		if (!priv->ucode_loaded)
798c2ecf20Sopenharmony_ci			return -EINVAL;
808c2ecf20Sopenharmony_ci		img = &priv->fw->img[priv->cur_ucode];
818c2ecf20Sopenharmony_ci		priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
828c2ecf20Sopenharmony_ci	}
838c2ecf20Sopenharmony_ci	len = priv->dbgfs_sram_len;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	if (len == -4) {
868c2ecf20Sopenharmony_ci		device_format = true;
878c2ecf20Sopenharmony_ci		len = 4;
888c2ecf20Sopenharmony_ci	}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	bufsz =  50 + len * 4;
918c2ecf20Sopenharmony_ci	buf = kmalloc(bufsz, GFP_KERNEL);
928c2ecf20Sopenharmony_ci	if (!buf)
938c2ecf20Sopenharmony_ci		return -ENOMEM;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
968c2ecf20Sopenharmony_ci			 len);
978c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
988c2ecf20Sopenharmony_ci			priv->dbgfs_sram_offset);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	/* adjust sram address since reads are only on even u32 boundaries */
1018c2ecf20Sopenharmony_ci	offset = priv->dbgfs_sram_offset & 0x3;
1028c2ecf20Sopenharmony_ci	sram = priv->dbgfs_sram_offset & ~0x3;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	/* read the first u32 from sram */
1058c2ecf20Sopenharmony_ci	val = iwl_trans_read_mem32(priv->trans, sram);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	for (; len; len--) {
1088c2ecf20Sopenharmony_ci		/* put the address at the start of every line */
1098c2ecf20Sopenharmony_ci		if (i == 0)
1108c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
1118c2ecf20Sopenharmony_ci				"%08X: ", sram + offset);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci		if (device_format)
1148c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
1158c2ecf20Sopenharmony_ci				"%02x", (val >> (8 * (3 - offset))) & 0xff);
1168c2ecf20Sopenharmony_ci		else
1178c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
1188c2ecf20Sopenharmony_ci				"%02x ", (val >> (8 * offset)) & 0xff);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci		/* if all bytes processed, read the next u32 from sram */
1218c2ecf20Sopenharmony_ci		if (++offset == 4) {
1228c2ecf20Sopenharmony_ci			sram += 4;
1238c2ecf20Sopenharmony_ci			offset = 0;
1248c2ecf20Sopenharmony_ci			val = iwl_trans_read_mem32(priv->trans, sram);
1258c2ecf20Sopenharmony_ci		}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci		/* put in extra spaces and split lines for human readability */
1288c2ecf20Sopenharmony_ci		if (++i == 16) {
1298c2ecf20Sopenharmony_ci			i = 0;
1308c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos, "\n");
1318c2ecf20Sopenharmony_ci		} else if (!(i & 7)) {
1328c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos, "   ");
1338c2ecf20Sopenharmony_ci		} else if (!(i & 3)) {
1348c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos, " ");
1358c2ecf20Sopenharmony_ci		}
1368c2ecf20Sopenharmony_ci	}
1378c2ecf20Sopenharmony_ci	if (i)
1388c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "\n");
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1418c2ecf20Sopenharmony_ci	kfree(buf);
1428c2ecf20Sopenharmony_ci	return ret;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_sram_write(struct file *file,
1468c2ecf20Sopenharmony_ci					const char __user *user_buf,
1478c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
1508c2ecf20Sopenharmony_ci	char buf[64];
1518c2ecf20Sopenharmony_ci	int buf_size;
1528c2ecf20Sopenharmony_ci	u32 offset, len;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
1558c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
1568c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
1578c2ecf20Sopenharmony_ci		return -EFAULT;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
1608c2ecf20Sopenharmony_ci		priv->dbgfs_sram_offset = offset;
1618c2ecf20Sopenharmony_ci		priv->dbgfs_sram_len = len;
1628c2ecf20Sopenharmony_ci	} else if (sscanf(buf, "%x", &offset) == 1) {
1638c2ecf20Sopenharmony_ci		priv->dbgfs_sram_offset = offset;
1648c2ecf20Sopenharmony_ci		priv->dbgfs_sram_len = -4;
1658c2ecf20Sopenharmony_ci	} else {
1668c2ecf20Sopenharmony_ci		priv->dbgfs_sram_offset = 0;
1678c2ecf20Sopenharmony_ci		priv->dbgfs_sram_len = 0;
1688c2ecf20Sopenharmony_ci	}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	return count;
1718c2ecf20Sopenharmony_ci}
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
1748c2ecf20Sopenharmony_ci					  char __user *user_buf,
1758c2ecf20Sopenharmony_ci					  size_t count, loff_t *ppos)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
1788c2ecf20Sopenharmony_ci	const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN];
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	if (!priv->wowlan_sram)
1818c2ecf20Sopenharmony_ci		return -ENODATA;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos,
1848c2ecf20Sopenharmony_ci				       priv->wowlan_sram,
1858c2ecf20Sopenharmony_ci				       img->sec[IWL_UCODE_SECTION_DATA].len);
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
1888c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
1918c2ecf20Sopenharmony_ci	struct iwl_station_entry *station;
1928c2ecf20Sopenharmony_ci	struct iwl_tid_data *tid_data;
1938c2ecf20Sopenharmony_ci	char *buf;
1948c2ecf20Sopenharmony_ci	int i, j, pos = 0;
1958c2ecf20Sopenharmony_ci	ssize_t ret;
1968c2ecf20Sopenharmony_ci	/* Add 30 for initial string */
1978c2ecf20Sopenharmony_ci	const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	buf = kmalloc(bufsz, GFP_KERNEL);
2008c2ecf20Sopenharmony_ci	if (!buf)
2018c2ecf20Sopenharmony_ci		return -ENOMEM;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
2048c2ecf20Sopenharmony_ci			priv->num_stations);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
2078c2ecf20Sopenharmony_ci		station = &priv->stations[i];
2088c2ecf20Sopenharmony_ci		if (!station->used)
2098c2ecf20Sopenharmony_ci			continue;
2108c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
2118c2ecf20Sopenharmony_ci				 "station %d - addr: %pM, flags: %#x\n",
2128c2ecf20Sopenharmony_ci				 i, station->sta.sta.addr,
2138c2ecf20Sopenharmony_ci				 station->sta.station_flags_msk);
2148c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
2158c2ecf20Sopenharmony_ci				"TID seqno  next_rclmd "
2168c2ecf20Sopenharmony_ci				"rate_n_flags state txq\n");
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci		for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
2198c2ecf20Sopenharmony_ci			tid_data = &priv->tid_data[i][j];
2208c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
2218c2ecf20Sopenharmony_ci				"%d:  0x%.4x 0x%.4x     0x%.8x   "
2228c2ecf20Sopenharmony_ci				"%d     %.2d",
2238c2ecf20Sopenharmony_ci				j, tid_data->seq_number,
2248c2ecf20Sopenharmony_ci				tid_data->next_reclaimed,
2258c2ecf20Sopenharmony_ci				tid_data->agg.rate_n_flags,
2268c2ecf20Sopenharmony_ci				tid_data->agg.state,
2278c2ecf20Sopenharmony_ci				tid_data->agg.txq_id);
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci			if (tid_data->agg.wait_for_ba)
2308c2ecf20Sopenharmony_ci				pos += scnprintf(buf + pos, bufsz - pos,
2318c2ecf20Sopenharmony_ci						 " - waitforba");
2328c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos, "\n");
2338c2ecf20Sopenharmony_ci		}
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "\n");
2368c2ecf20Sopenharmony_ci	}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2398c2ecf20Sopenharmony_ci	kfree(buf);
2408c2ecf20Sopenharmony_ci	return ret;
2418c2ecf20Sopenharmony_ci}
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_nvm_read(struct file *file,
2448c2ecf20Sopenharmony_ci				       char __user *user_buf,
2458c2ecf20Sopenharmony_ci				       size_t count,
2468c2ecf20Sopenharmony_ci				       loff_t *ppos)
2478c2ecf20Sopenharmony_ci{
2488c2ecf20Sopenharmony_ci	ssize_t ret;
2498c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
2508c2ecf20Sopenharmony_ci	int pos = 0, ofs = 0, buf_size = 0;
2518c2ecf20Sopenharmony_ci	const u8 *ptr;
2528c2ecf20Sopenharmony_ci	char *buf;
2538c2ecf20Sopenharmony_ci	u16 nvm_ver;
2548c2ecf20Sopenharmony_ci	size_t eeprom_len = priv->eeprom_blob_size;
2558c2ecf20Sopenharmony_ci	buf_size = 4 * eeprom_len + 256;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	if (eeprom_len % 16)
2588c2ecf20Sopenharmony_ci		return -ENODATA;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	ptr = priv->eeprom_blob;
2618c2ecf20Sopenharmony_ci	if (!ptr)
2628c2ecf20Sopenharmony_ci		return -ENOMEM;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	/* 4 characters for byte 0xYY */
2658c2ecf20Sopenharmony_ci	buf = kzalloc(buf_size, GFP_KERNEL);
2668c2ecf20Sopenharmony_ci	if (!buf)
2678c2ecf20Sopenharmony_ci		return -ENOMEM;
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	nvm_ver = priv->nvm_data->nvm_version;
2708c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, buf_size - pos,
2718c2ecf20Sopenharmony_ci			 "NVM version: 0x%x\n", nvm_ver);
2728c2ecf20Sopenharmony_ci	for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
2738c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
2748c2ecf20Sopenharmony_ci				 ofs, ptr + ofs);
2758c2ecf20Sopenharmony_ci	}
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2788c2ecf20Sopenharmony_ci	kfree(buf);
2798c2ecf20Sopenharmony_ci	return ret;
2808c2ecf20Sopenharmony_ci}
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
2838c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
2848c2ecf20Sopenharmony_ci{
2858c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
2868c2ecf20Sopenharmony_ci	struct ieee80211_channel *channels = NULL;
2878c2ecf20Sopenharmony_ci	const struct ieee80211_supported_band *supp_band = NULL;
2888c2ecf20Sopenharmony_ci	int pos = 0, i, bufsz = PAGE_SIZE;
2898c2ecf20Sopenharmony_ci	char *buf;
2908c2ecf20Sopenharmony_ci	ssize_t ret;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
2938c2ecf20Sopenharmony_ci	if (!buf)
2948c2ecf20Sopenharmony_ci		return -ENOMEM;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	supp_band = iwl_get_hw_mode(priv, NL80211_BAND_2GHZ);
2978c2ecf20Sopenharmony_ci	if (supp_band) {
2988c2ecf20Sopenharmony_ci		channels = supp_band->channels;
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
3018c2ecf20Sopenharmony_ci				"Displaying %d channels in 2.4GHz band 802.11bg):\n",
3028c2ecf20Sopenharmony_ci				supp_band->n_channels);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci		for (i = 0; i < supp_band->n_channels; i++)
3058c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
3068c2ecf20Sopenharmony_ci					"%d: %ddBm: BSS%s%s, %s.\n",
3078c2ecf20Sopenharmony_ci					channels[i].hw_value,
3088c2ecf20Sopenharmony_ci					channels[i].max_power,
3098c2ecf20Sopenharmony_ci					channels[i].flags & IEEE80211_CHAN_RADAR ?
3108c2ecf20Sopenharmony_ci					" (IEEE 802.11h required)" : "",
3118c2ecf20Sopenharmony_ci					((channels[i].flags & IEEE80211_CHAN_NO_IR)
3128c2ecf20Sopenharmony_ci					|| (channels[i].flags &
3138c2ecf20Sopenharmony_ci					IEEE80211_CHAN_RADAR)) ? "" :
3148c2ecf20Sopenharmony_ci					", IBSS",
3158c2ecf20Sopenharmony_ci					channels[i].flags &
3168c2ecf20Sopenharmony_ci					IEEE80211_CHAN_NO_IR ?
3178c2ecf20Sopenharmony_ci					"passive only" : "active/passive");
3188c2ecf20Sopenharmony_ci	}
3198c2ecf20Sopenharmony_ci	supp_band = iwl_get_hw_mode(priv, NL80211_BAND_5GHZ);
3208c2ecf20Sopenharmony_ci	if (supp_band) {
3218c2ecf20Sopenharmony_ci		channels = supp_band->channels;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
3248c2ecf20Sopenharmony_ci				"Displaying %d channels in 5.2GHz band (802.11a)\n",
3258c2ecf20Sopenharmony_ci				supp_band->n_channels);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci		for (i = 0; i < supp_band->n_channels; i++)
3288c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
3298c2ecf20Sopenharmony_ci					"%d: %ddBm: BSS%s%s, %s.\n",
3308c2ecf20Sopenharmony_ci					channels[i].hw_value,
3318c2ecf20Sopenharmony_ci					channels[i].max_power,
3328c2ecf20Sopenharmony_ci					channels[i].flags & IEEE80211_CHAN_RADAR ?
3338c2ecf20Sopenharmony_ci					" (IEEE 802.11h required)" : "",
3348c2ecf20Sopenharmony_ci					((channels[i].flags & IEEE80211_CHAN_NO_IR)
3358c2ecf20Sopenharmony_ci					|| (channels[i].flags &
3368c2ecf20Sopenharmony_ci					IEEE80211_CHAN_RADAR)) ? "" :
3378c2ecf20Sopenharmony_ci					", IBSS",
3388c2ecf20Sopenharmony_ci					channels[i].flags &
3398c2ecf20Sopenharmony_ci					IEEE80211_CHAN_NO_IR ?
3408c2ecf20Sopenharmony_ci					"passive only" : "active/passive");
3418c2ecf20Sopenharmony_ci	}
3428c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
3438c2ecf20Sopenharmony_ci	kfree(buf);
3448c2ecf20Sopenharmony_ci	return ret;
3458c2ecf20Sopenharmony_ci}
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_status_read(struct file *file,
3488c2ecf20Sopenharmony_ci						char __user *user_buf,
3498c2ecf20Sopenharmony_ci						size_t count, loff_t *ppos) {
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
3528c2ecf20Sopenharmony_ci	char buf[512];
3538c2ecf20Sopenharmony_ci	int pos = 0;
3548c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
3578c2ecf20Sopenharmony_ci		test_bit(STATUS_RF_KILL_HW, &priv->status));
3588c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
3598c2ecf20Sopenharmony_ci		test_bit(STATUS_CT_KILL, &priv->status));
3608c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
3618c2ecf20Sopenharmony_ci		test_bit(STATUS_ALIVE, &priv->status));
3628c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
3638c2ecf20Sopenharmony_ci		test_bit(STATUS_READY, &priv->status));
3648c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
3658c2ecf20Sopenharmony_ci		test_bit(STATUS_EXIT_PENDING, &priv->status));
3668c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
3678c2ecf20Sopenharmony_ci		test_bit(STATUS_STATISTICS, &priv->status));
3688c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
3698c2ecf20Sopenharmony_ci		test_bit(STATUS_SCANNING, &priv->status));
3708c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
3718c2ecf20Sopenharmony_ci		test_bit(STATUS_SCAN_ABORTING, &priv->status));
3728c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
3738c2ecf20Sopenharmony_ci		test_bit(STATUS_SCAN_HW, &priv->status));
3748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
3758c2ecf20Sopenharmony_ci		test_bit(STATUS_POWER_PMI, &priv->status));
3768c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
3778c2ecf20Sopenharmony_ci		test_bit(STATUS_FW_ERROR, &priv->status));
3788c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
3798c2ecf20Sopenharmony_ci}
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
3828c2ecf20Sopenharmony_ci					char __user *user_buf,
3838c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	int pos = 0;
3888c2ecf20Sopenharmony_ci	int cnt = 0;
3898c2ecf20Sopenharmony_ci	char *buf;
3908c2ecf20Sopenharmony_ci	int bufsz = 24 * 64; /* 24 items * 64 char per item */
3918c2ecf20Sopenharmony_ci	ssize_t ret;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
3948c2ecf20Sopenharmony_ci	if (!buf)
3958c2ecf20Sopenharmony_ci		return -ENOMEM;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < REPLY_MAX; cnt++) {
3988c2ecf20Sopenharmony_ci		if (priv->rx_handlers_stats[cnt] > 0)
3998c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
4008c2ecf20Sopenharmony_ci				"\tRx handler[%36s]:\t\t %u\n",
4018c2ecf20Sopenharmony_ci				iwl_get_cmd_string(priv->trans, (u32)cnt),
4028c2ecf20Sopenharmony_ci				priv->rx_handlers_stats[cnt]);
4038c2ecf20Sopenharmony_ci	}
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
4068c2ecf20Sopenharmony_ci	kfree(buf);
4078c2ecf20Sopenharmony_ci	return ret;
4088c2ecf20Sopenharmony_ci}
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
4118c2ecf20Sopenharmony_ci					 const char __user *user_buf,
4128c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	char buf[8];
4178c2ecf20Sopenharmony_ci	int buf_size;
4188c2ecf20Sopenharmony_ci	u32 reset_flag;
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
4218c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
4228c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
4238c2ecf20Sopenharmony_ci		return -EFAULT;
4248c2ecf20Sopenharmony_ci	if (sscanf(buf, "%x", &reset_flag) != 1)
4258c2ecf20Sopenharmony_ci		return -EFAULT;
4268c2ecf20Sopenharmony_ci	if (reset_flag == 0)
4278c2ecf20Sopenharmony_ci		memset(&priv->rx_handlers_stats[0], 0,
4288c2ecf20Sopenharmony_ci			sizeof(priv->rx_handlers_stats));
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	return count;
4318c2ecf20Sopenharmony_ci}
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
4348c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
4358c2ecf20Sopenharmony_ci{
4368c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
4378c2ecf20Sopenharmony_ci	struct iwl_rxon_context *ctx;
4388c2ecf20Sopenharmony_ci	int pos = 0, i;
4398c2ecf20Sopenharmony_ci	char buf[256 * NUM_IWL_RXON_CTX];
4408c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	for_each_context(priv, ctx) {
4438c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
4448c2ecf20Sopenharmony_ci				 ctx->ctxid);
4458c2ecf20Sopenharmony_ci		for (i = 0; i < AC_NUM; i++) {
4468c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
4478c2ecf20Sopenharmony_ci				"\tcw_min\tcw_max\taifsn\ttxop\n");
4488c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
4498c2ecf20Sopenharmony_ci				"AC[%d]\t%u\t%u\t%u\t%u\n", i,
4508c2ecf20Sopenharmony_ci				ctx->qos_data.def_qos_parm.ac[i].cw_min,
4518c2ecf20Sopenharmony_ci				ctx->qos_data.def_qos_parm.ac[i].cw_max,
4528c2ecf20Sopenharmony_ci				ctx->qos_data.def_qos_parm.ac[i].aifsn,
4538c2ecf20Sopenharmony_ci				ctx->qos_data.def_qos_parm.ac[i].edca_txop);
4548c2ecf20Sopenharmony_ci		}
4558c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "\n");
4568c2ecf20Sopenharmony_ci	}
4578c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
4588c2ecf20Sopenharmony_ci}
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
4618c2ecf20Sopenharmony_ci				char __user *user_buf,
4628c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
4658c2ecf20Sopenharmony_ci	struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
4668c2ecf20Sopenharmony_ci	struct iwl_tt_restriction *restriction;
4678c2ecf20Sopenharmony_ci	char buf[100];
4688c2ecf20Sopenharmony_ci	int pos = 0;
4698c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
4728c2ecf20Sopenharmony_ci			"Thermal Throttling Mode: %s\n",
4738c2ecf20Sopenharmony_ci			tt->advanced_tt ? "Advance" : "Legacy");
4748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
4758c2ecf20Sopenharmony_ci			"Thermal Throttling State: %d\n",
4768c2ecf20Sopenharmony_ci			tt->state);
4778c2ecf20Sopenharmony_ci	if (tt->advanced_tt) {
4788c2ecf20Sopenharmony_ci		restriction = tt->restriction + tt->state;
4798c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
4808c2ecf20Sopenharmony_ci				"Tx mode: %d\n",
4818c2ecf20Sopenharmony_ci				restriction->tx_stream);
4828c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
4838c2ecf20Sopenharmony_ci				"Rx mode: %d\n",
4848c2ecf20Sopenharmony_ci				restriction->rx_stream);
4858c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
4868c2ecf20Sopenharmony_ci				"HT mode: %d\n",
4878c2ecf20Sopenharmony_ci				restriction->is_ht);
4888c2ecf20Sopenharmony_ci	}
4898c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
4908c2ecf20Sopenharmony_ci}
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
4938c2ecf20Sopenharmony_ci					 const char __user *user_buf,
4948c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
4958c2ecf20Sopenharmony_ci{
4968c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
4978c2ecf20Sopenharmony_ci	char buf[8];
4988c2ecf20Sopenharmony_ci	int buf_size;
4998c2ecf20Sopenharmony_ci	int ht40;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
5028c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
5038c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
5048c2ecf20Sopenharmony_ci		return -EFAULT;
5058c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &ht40) != 1)
5068c2ecf20Sopenharmony_ci		return -EFAULT;
5078c2ecf20Sopenharmony_ci	if (!iwl_is_any_associated(priv))
5088c2ecf20Sopenharmony_ci		priv->disable_ht40 = ht40 ? true : false;
5098c2ecf20Sopenharmony_ci	else
5108c2ecf20Sopenharmony_ci		return -EINVAL;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	return count;
5138c2ecf20Sopenharmony_ci}
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
5168c2ecf20Sopenharmony_ci					 char __user *user_buf,
5178c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
5188c2ecf20Sopenharmony_ci{
5198c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
5208c2ecf20Sopenharmony_ci	char buf[100];
5218c2ecf20Sopenharmony_ci	int pos = 0;
5228c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
5258c2ecf20Sopenharmony_ci			"11n 40MHz Mode: %s\n",
5268c2ecf20Sopenharmony_ci			priv->disable_ht40 ? "Disabled" : "Enabled");
5278c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
5288c2ecf20Sopenharmony_ci}
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_temperature_read(struct file *file,
5318c2ecf20Sopenharmony_ci					 char __user *user_buf,
5328c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
5358c2ecf20Sopenharmony_ci	char buf[8];
5368c2ecf20Sopenharmony_ci	int pos = 0;
5378c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
5408c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
5418c2ecf20Sopenharmony_ci}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
5458c2ecf20Sopenharmony_ci						    const char __user *user_buf,
5468c2ecf20Sopenharmony_ci						    size_t count, loff_t *ppos)
5478c2ecf20Sopenharmony_ci{
5488c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
5498c2ecf20Sopenharmony_ci	char buf[8];
5508c2ecf20Sopenharmony_ci	int buf_size;
5518c2ecf20Sopenharmony_ci	int value;
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
5548c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
5558c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
5568c2ecf20Sopenharmony_ci		return -EFAULT;
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &value) != 1)
5598c2ecf20Sopenharmony_ci		return -EINVAL;
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	/*
5628c2ecf20Sopenharmony_ci	 * Our users expect 0 to be "CAM", but 0 isn't actually
5638c2ecf20Sopenharmony_ci	 * valid here. However, let's not confuse them and present
5648c2ecf20Sopenharmony_ci	 * IWL_POWER_INDEX_1 as "1", not "0".
5658c2ecf20Sopenharmony_ci	 */
5668c2ecf20Sopenharmony_ci	if (value == 0)
5678c2ecf20Sopenharmony_ci		return -EINVAL;
5688c2ecf20Sopenharmony_ci	else if (value > 0)
5698c2ecf20Sopenharmony_ci		value -= 1;
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci	if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
5728c2ecf20Sopenharmony_ci		return -EINVAL;
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	if (!iwl_is_ready_rf(priv))
5758c2ecf20Sopenharmony_ci		return -EAGAIN;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	priv->power_data.debug_sleep_level_override = value;
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci	mutex_lock(&priv->mutex);
5808c2ecf20Sopenharmony_ci	iwl_power_update_mode(priv, true);
5818c2ecf20Sopenharmony_ci	mutex_unlock(&priv->mutex);
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	return count;
5848c2ecf20Sopenharmony_ci}
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
5878c2ecf20Sopenharmony_ci						   char __user *user_buf,
5888c2ecf20Sopenharmony_ci						   size_t count, loff_t *ppos)
5898c2ecf20Sopenharmony_ci{
5908c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
5918c2ecf20Sopenharmony_ci	char buf[10];
5928c2ecf20Sopenharmony_ci	int pos, value;
5938c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci	/* see the write function */
5968c2ecf20Sopenharmony_ci	value = priv->power_data.debug_sleep_level_override;
5978c2ecf20Sopenharmony_ci	if (value >= 0)
5988c2ecf20Sopenharmony_ci		value += 1;
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	pos = scnprintf(buf, bufsz, "%d\n", value);
6018c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
6028c2ecf20Sopenharmony_ci}
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
6058c2ecf20Sopenharmony_ci						    char __user *user_buf,
6068c2ecf20Sopenharmony_ci						    size_t count, loff_t *ppos)
6078c2ecf20Sopenharmony_ci{
6088c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
6098c2ecf20Sopenharmony_ci	char buf[200];
6108c2ecf20Sopenharmony_ci	int pos = 0, i;
6118c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
6128c2ecf20Sopenharmony_ci	struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
6158c2ecf20Sopenharmony_ci			 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
6168c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
6178c2ecf20Sopenharmony_ci			 "RX/TX timeout: %d/%d usec\n",
6188c2ecf20Sopenharmony_ci			 le32_to_cpu(cmd->rx_data_timeout),
6198c2ecf20Sopenharmony_ci			 le32_to_cpu(cmd->tx_data_timeout));
6208c2ecf20Sopenharmony_ci	for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
6218c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
6228c2ecf20Sopenharmony_ci				 "sleep_interval[%d]: %d\n", i,
6238c2ecf20Sopenharmony_ci				 le32_to_cpu(cmd->sleep_interval[i]));
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
6268c2ecf20Sopenharmony_ci}
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(sram);
6298c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(wowlan_sram);
6308c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(nvm);
6318c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(stations);
6328c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(channels);
6338c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(status);
6348c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
6358c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(qos);
6368c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(thermal_throttling);
6378c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
6388c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(temperature);
6398c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
6408c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(current_sleep_command);
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci#define fmt_value	"  %-30s %10u\n"
6438c2ecf20Sopenharmony_ci#define fmt_hex		"  %-30s       0x%02X\n"
6448c2ecf20Sopenharmony_ci#define fmt_table	"  %-30s %10u  %10u  %10u  %10u\n"
6458c2ecf20Sopenharmony_ci#define fmt_header	"%-32s    current  cumulative       delta         max\n"
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_cistatic int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
6488c2ecf20Sopenharmony_ci{
6498c2ecf20Sopenharmony_ci	int p = 0;
6508c2ecf20Sopenharmony_ci	u32 flag;
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci	lockdep_assert_held(&priv->statistics.lock);
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	flag = le32_to_cpu(priv->statistics.flag);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
6578c2ecf20Sopenharmony_ci	if (flag & UCODE_STATISTICS_CLEAR_MSK)
6588c2ecf20Sopenharmony_ci		p += scnprintf(buf + p, bufsz - p,
6598c2ecf20Sopenharmony_ci		"\tStatistics have been cleared\n");
6608c2ecf20Sopenharmony_ci	p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
6618c2ecf20Sopenharmony_ci		(flag & UCODE_STATISTICS_FREQUENCY_MSK)
6628c2ecf20Sopenharmony_ci		? "2.4 GHz" : "5.2 GHz");
6638c2ecf20Sopenharmony_ci	p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
6648c2ecf20Sopenharmony_ci		(flag & UCODE_STATISTICS_NARROW_BAND_MSK)
6658c2ecf20Sopenharmony_ci		 ? "enabled" : "disabled");
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci	return p;
6688c2ecf20Sopenharmony_ci}
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
6718c2ecf20Sopenharmony_ci					char __user *user_buf,
6728c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
6758c2ecf20Sopenharmony_ci	int pos = 0;
6768c2ecf20Sopenharmony_ci	char *buf;
6778c2ecf20Sopenharmony_ci	int bufsz = sizeof(struct statistics_rx_phy) * 40 +
6788c2ecf20Sopenharmony_ci		    sizeof(struct statistics_rx_non_phy) * 40 +
6798c2ecf20Sopenharmony_ci		    sizeof(struct statistics_rx_ht_phy) * 40 + 400;
6808c2ecf20Sopenharmony_ci	ssize_t ret;
6818c2ecf20Sopenharmony_ci	struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
6828c2ecf20Sopenharmony_ci	struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
6838c2ecf20Sopenharmony_ci	struct statistics_rx_non_phy *general, *accum_general;
6848c2ecf20Sopenharmony_ci	struct statistics_rx_non_phy *delta_general, *max_general;
6858c2ecf20Sopenharmony_ci	struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci	if (!iwl_is_alive(priv))
6888c2ecf20Sopenharmony_ci		return -EAGAIN;
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
6918c2ecf20Sopenharmony_ci	if (!buf)
6928c2ecf20Sopenharmony_ci		return -ENOMEM;
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	/*
6958c2ecf20Sopenharmony_ci	 * the statistic information display here is based on
6968c2ecf20Sopenharmony_ci	 * the last statistics notification from uCode
6978c2ecf20Sopenharmony_ci	 * might not reflect the current uCode activity
6988c2ecf20Sopenharmony_ci	 */
6998c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->statistics.lock);
7008c2ecf20Sopenharmony_ci	ofdm = &priv->statistics.rx_ofdm;
7018c2ecf20Sopenharmony_ci	cck = &priv->statistics.rx_cck;
7028c2ecf20Sopenharmony_ci	general = &priv->statistics.rx_non_phy;
7038c2ecf20Sopenharmony_ci	ht = &priv->statistics.rx_ofdm_ht;
7048c2ecf20Sopenharmony_ci	accum_ofdm = &priv->accum_stats.rx_ofdm;
7058c2ecf20Sopenharmony_ci	accum_cck = &priv->accum_stats.rx_cck;
7068c2ecf20Sopenharmony_ci	accum_general = &priv->accum_stats.rx_non_phy;
7078c2ecf20Sopenharmony_ci	accum_ht = &priv->accum_stats.rx_ofdm_ht;
7088c2ecf20Sopenharmony_ci	delta_ofdm = &priv->delta_stats.rx_ofdm;
7098c2ecf20Sopenharmony_ci	delta_cck = &priv->delta_stats.rx_cck;
7108c2ecf20Sopenharmony_ci	delta_general = &priv->delta_stats.rx_non_phy;
7118c2ecf20Sopenharmony_ci	delta_ht = &priv->delta_stats.rx_ofdm_ht;
7128c2ecf20Sopenharmony_ci	max_ofdm = &priv->max_delta_stats.rx_ofdm;
7138c2ecf20Sopenharmony_ci	max_cck = &priv->max_delta_stats.rx_cck;
7148c2ecf20Sopenharmony_ci	max_general = &priv->max_delta_stats.rx_non_phy;
7158c2ecf20Sopenharmony_ci	max_ht = &priv->max_delta_stats.rx_ofdm_ht;
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci	pos += iwl_statistics_flag(priv, buf, bufsz);
7188c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7198c2ecf20Sopenharmony_ci			 fmt_header, "Statistics_Rx - OFDM:");
7208c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7218c2ecf20Sopenharmony_ci			 fmt_table, "ina_cnt:",
7228c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->ina_cnt),
7238c2ecf20Sopenharmony_ci			 accum_ofdm->ina_cnt,
7248c2ecf20Sopenharmony_ci			 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
7258c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7268c2ecf20Sopenharmony_ci			 fmt_table, "fina_cnt:",
7278c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
7288c2ecf20Sopenharmony_ci			 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
7298c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7308c2ecf20Sopenharmony_ci			 fmt_table, "plcp_err:",
7318c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
7328c2ecf20Sopenharmony_ci			 delta_ofdm->plcp_err, max_ofdm->plcp_err);
7338c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7348c2ecf20Sopenharmony_ci			 fmt_table, "crc32_err:",
7358c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
7368c2ecf20Sopenharmony_ci			 delta_ofdm->crc32_err, max_ofdm->crc32_err);
7378c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7388c2ecf20Sopenharmony_ci			 fmt_table, "overrun_err:",
7398c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->overrun_err),
7408c2ecf20Sopenharmony_ci			 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
7418c2ecf20Sopenharmony_ci			 max_ofdm->overrun_err);
7428c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7438c2ecf20Sopenharmony_ci			 fmt_table, "early_overrun_err:",
7448c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->early_overrun_err),
7458c2ecf20Sopenharmony_ci			 accum_ofdm->early_overrun_err,
7468c2ecf20Sopenharmony_ci			 delta_ofdm->early_overrun_err,
7478c2ecf20Sopenharmony_ci			 max_ofdm->early_overrun_err);
7488c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7498c2ecf20Sopenharmony_ci			 fmt_table, "crc32_good:",
7508c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->crc32_good),
7518c2ecf20Sopenharmony_ci			 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
7528c2ecf20Sopenharmony_ci			 max_ofdm->crc32_good);
7538c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7548c2ecf20Sopenharmony_ci			 fmt_table, "false_alarm_cnt:",
7558c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->false_alarm_cnt),
7568c2ecf20Sopenharmony_ci			 accum_ofdm->false_alarm_cnt,
7578c2ecf20Sopenharmony_ci			 delta_ofdm->false_alarm_cnt,
7588c2ecf20Sopenharmony_ci			 max_ofdm->false_alarm_cnt);
7598c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7608c2ecf20Sopenharmony_ci			 fmt_table, "fina_sync_err_cnt:",
7618c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->fina_sync_err_cnt),
7628c2ecf20Sopenharmony_ci			 accum_ofdm->fina_sync_err_cnt,
7638c2ecf20Sopenharmony_ci			 delta_ofdm->fina_sync_err_cnt,
7648c2ecf20Sopenharmony_ci			 max_ofdm->fina_sync_err_cnt);
7658c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7668c2ecf20Sopenharmony_ci			 fmt_table, "sfd_timeout:",
7678c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->sfd_timeout),
7688c2ecf20Sopenharmony_ci			 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
7698c2ecf20Sopenharmony_ci			 max_ofdm->sfd_timeout);
7708c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7718c2ecf20Sopenharmony_ci			 fmt_table, "fina_timeout:",
7728c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->fina_timeout),
7738c2ecf20Sopenharmony_ci			 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
7748c2ecf20Sopenharmony_ci			 max_ofdm->fina_timeout);
7758c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7768c2ecf20Sopenharmony_ci			 fmt_table, "unresponded_rts:",
7778c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->unresponded_rts),
7788c2ecf20Sopenharmony_ci			 accum_ofdm->unresponded_rts,
7798c2ecf20Sopenharmony_ci			 delta_ofdm->unresponded_rts,
7808c2ecf20Sopenharmony_ci			 max_ofdm->unresponded_rts);
7818c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7828c2ecf20Sopenharmony_ci			 fmt_table, "rxe_frame_lmt_ovrun:",
7838c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
7848c2ecf20Sopenharmony_ci			 accum_ofdm->rxe_frame_limit_overrun,
7858c2ecf20Sopenharmony_ci			 delta_ofdm->rxe_frame_limit_overrun,
7868c2ecf20Sopenharmony_ci			 max_ofdm->rxe_frame_limit_overrun);
7878c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7888c2ecf20Sopenharmony_ci			 fmt_table, "sent_ack_cnt:",
7898c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->sent_ack_cnt),
7908c2ecf20Sopenharmony_ci			 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
7918c2ecf20Sopenharmony_ci			 max_ofdm->sent_ack_cnt);
7928c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7938c2ecf20Sopenharmony_ci			 fmt_table, "sent_cts_cnt:",
7948c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->sent_cts_cnt),
7958c2ecf20Sopenharmony_ci			 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
7968c2ecf20Sopenharmony_ci			 max_ofdm->sent_cts_cnt);
7978c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
7988c2ecf20Sopenharmony_ci			 fmt_table, "sent_ba_rsp_cnt:",
7998c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
8008c2ecf20Sopenharmony_ci			 accum_ofdm->sent_ba_rsp_cnt,
8018c2ecf20Sopenharmony_ci			 delta_ofdm->sent_ba_rsp_cnt,
8028c2ecf20Sopenharmony_ci			 max_ofdm->sent_ba_rsp_cnt);
8038c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8048c2ecf20Sopenharmony_ci			 fmt_table, "dsp_self_kill:",
8058c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->dsp_self_kill),
8068c2ecf20Sopenharmony_ci			 accum_ofdm->dsp_self_kill,
8078c2ecf20Sopenharmony_ci			 delta_ofdm->dsp_self_kill,
8088c2ecf20Sopenharmony_ci			 max_ofdm->dsp_self_kill);
8098c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8108c2ecf20Sopenharmony_ci			 fmt_table, "mh_format_err:",
8118c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->mh_format_err),
8128c2ecf20Sopenharmony_ci			 accum_ofdm->mh_format_err,
8138c2ecf20Sopenharmony_ci			 delta_ofdm->mh_format_err,
8148c2ecf20Sopenharmony_ci			 max_ofdm->mh_format_err);
8158c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8168c2ecf20Sopenharmony_ci			 fmt_table, "re_acq_main_rssi_sum:",
8178c2ecf20Sopenharmony_ci			 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
8188c2ecf20Sopenharmony_ci			 accum_ofdm->re_acq_main_rssi_sum,
8198c2ecf20Sopenharmony_ci			 delta_ofdm->re_acq_main_rssi_sum,
8208c2ecf20Sopenharmony_ci			 max_ofdm->re_acq_main_rssi_sum);
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8238c2ecf20Sopenharmony_ci			 fmt_header, "Statistics_Rx - CCK:");
8248c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8258c2ecf20Sopenharmony_ci			 fmt_table, "ina_cnt:",
8268c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
8278c2ecf20Sopenharmony_ci			 delta_cck->ina_cnt, max_cck->ina_cnt);
8288c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8298c2ecf20Sopenharmony_ci			 fmt_table, "fina_cnt:",
8308c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
8318c2ecf20Sopenharmony_ci			 delta_cck->fina_cnt, max_cck->fina_cnt);
8328c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8338c2ecf20Sopenharmony_ci			 fmt_table, "plcp_err:",
8348c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
8358c2ecf20Sopenharmony_ci			 delta_cck->plcp_err, max_cck->plcp_err);
8368c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8378c2ecf20Sopenharmony_ci			 fmt_table, "crc32_err:",
8388c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
8398c2ecf20Sopenharmony_ci			 delta_cck->crc32_err, max_cck->crc32_err);
8408c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8418c2ecf20Sopenharmony_ci			 fmt_table, "overrun_err:",
8428c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->overrun_err),
8438c2ecf20Sopenharmony_ci			 accum_cck->overrun_err, delta_cck->overrun_err,
8448c2ecf20Sopenharmony_ci			 max_cck->overrun_err);
8458c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8468c2ecf20Sopenharmony_ci			 fmt_table, "early_overrun_err:",
8478c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->early_overrun_err),
8488c2ecf20Sopenharmony_ci			 accum_cck->early_overrun_err,
8498c2ecf20Sopenharmony_ci			 delta_cck->early_overrun_err,
8508c2ecf20Sopenharmony_ci			 max_cck->early_overrun_err);
8518c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8528c2ecf20Sopenharmony_ci			 fmt_table, "crc32_good:",
8538c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
8548c2ecf20Sopenharmony_ci			 delta_cck->crc32_good, max_cck->crc32_good);
8558c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8568c2ecf20Sopenharmony_ci			 fmt_table, "false_alarm_cnt:",
8578c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->false_alarm_cnt),
8588c2ecf20Sopenharmony_ci			 accum_cck->false_alarm_cnt,
8598c2ecf20Sopenharmony_ci			 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
8608c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8618c2ecf20Sopenharmony_ci			 fmt_table, "fina_sync_err_cnt:",
8628c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->fina_sync_err_cnt),
8638c2ecf20Sopenharmony_ci			 accum_cck->fina_sync_err_cnt,
8648c2ecf20Sopenharmony_ci			 delta_cck->fina_sync_err_cnt,
8658c2ecf20Sopenharmony_ci			 max_cck->fina_sync_err_cnt);
8668c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8678c2ecf20Sopenharmony_ci			 fmt_table, "sfd_timeout:",
8688c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->sfd_timeout),
8698c2ecf20Sopenharmony_ci			 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
8708c2ecf20Sopenharmony_ci			 max_cck->sfd_timeout);
8718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8728c2ecf20Sopenharmony_ci			 fmt_table, "fina_timeout:",
8738c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->fina_timeout),
8748c2ecf20Sopenharmony_ci			 accum_cck->fina_timeout, delta_cck->fina_timeout,
8758c2ecf20Sopenharmony_ci			 max_cck->fina_timeout);
8768c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8778c2ecf20Sopenharmony_ci			 fmt_table, "unresponded_rts:",
8788c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->unresponded_rts),
8798c2ecf20Sopenharmony_ci			 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
8808c2ecf20Sopenharmony_ci			 max_cck->unresponded_rts);
8818c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8828c2ecf20Sopenharmony_ci			 fmt_table, "rxe_frame_lmt_ovrun:",
8838c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->rxe_frame_limit_overrun),
8848c2ecf20Sopenharmony_ci			 accum_cck->rxe_frame_limit_overrun,
8858c2ecf20Sopenharmony_ci			 delta_cck->rxe_frame_limit_overrun,
8868c2ecf20Sopenharmony_ci			 max_cck->rxe_frame_limit_overrun);
8878c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8888c2ecf20Sopenharmony_ci			 fmt_table, "sent_ack_cnt:",
8898c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->sent_ack_cnt),
8908c2ecf20Sopenharmony_ci			 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
8918c2ecf20Sopenharmony_ci			 max_cck->sent_ack_cnt);
8928c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8938c2ecf20Sopenharmony_ci			 fmt_table, "sent_cts_cnt:",
8948c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->sent_cts_cnt),
8958c2ecf20Sopenharmony_ci			 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
8968c2ecf20Sopenharmony_ci			 max_cck->sent_cts_cnt);
8978c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
8988c2ecf20Sopenharmony_ci			 fmt_table, "sent_ba_rsp_cnt:",
8998c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->sent_ba_rsp_cnt),
9008c2ecf20Sopenharmony_ci			 accum_cck->sent_ba_rsp_cnt,
9018c2ecf20Sopenharmony_ci			 delta_cck->sent_ba_rsp_cnt,
9028c2ecf20Sopenharmony_ci			 max_cck->sent_ba_rsp_cnt);
9038c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9048c2ecf20Sopenharmony_ci			 fmt_table, "dsp_self_kill:",
9058c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->dsp_self_kill),
9068c2ecf20Sopenharmony_ci			 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
9078c2ecf20Sopenharmony_ci			 max_cck->dsp_self_kill);
9088c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9098c2ecf20Sopenharmony_ci			 fmt_table, "mh_format_err:",
9108c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->mh_format_err),
9118c2ecf20Sopenharmony_ci			 accum_cck->mh_format_err, delta_cck->mh_format_err,
9128c2ecf20Sopenharmony_ci			 max_cck->mh_format_err);
9138c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9148c2ecf20Sopenharmony_ci			 fmt_table, "re_acq_main_rssi_sum:",
9158c2ecf20Sopenharmony_ci			 le32_to_cpu(cck->re_acq_main_rssi_sum),
9168c2ecf20Sopenharmony_ci			 accum_cck->re_acq_main_rssi_sum,
9178c2ecf20Sopenharmony_ci			 delta_cck->re_acq_main_rssi_sum,
9188c2ecf20Sopenharmony_ci			 max_cck->re_acq_main_rssi_sum);
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9218c2ecf20Sopenharmony_ci			 fmt_header, "Statistics_Rx - GENERAL:");
9228c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9238c2ecf20Sopenharmony_ci			 fmt_table, "bogus_cts:",
9248c2ecf20Sopenharmony_ci			 le32_to_cpu(general->bogus_cts),
9258c2ecf20Sopenharmony_ci			 accum_general->bogus_cts, delta_general->bogus_cts,
9268c2ecf20Sopenharmony_ci			 max_general->bogus_cts);
9278c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9288c2ecf20Sopenharmony_ci			 fmt_table, "bogus_ack:",
9298c2ecf20Sopenharmony_ci			 le32_to_cpu(general->bogus_ack),
9308c2ecf20Sopenharmony_ci			 accum_general->bogus_ack, delta_general->bogus_ack,
9318c2ecf20Sopenharmony_ci			 max_general->bogus_ack);
9328c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9338c2ecf20Sopenharmony_ci			 fmt_table, "non_bssid_frames:",
9348c2ecf20Sopenharmony_ci			 le32_to_cpu(general->non_bssid_frames),
9358c2ecf20Sopenharmony_ci			 accum_general->non_bssid_frames,
9368c2ecf20Sopenharmony_ci			 delta_general->non_bssid_frames,
9378c2ecf20Sopenharmony_ci			 max_general->non_bssid_frames);
9388c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9398c2ecf20Sopenharmony_ci			 fmt_table, "filtered_frames:",
9408c2ecf20Sopenharmony_ci			 le32_to_cpu(general->filtered_frames),
9418c2ecf20Sopenharmony_ci			 accum_general->filtered_frames,
9428c2ecf20Sopenharmony_ci			 delta_general->filtered_frames,
9438c2ecf20Sopenharmony_ci			 max_general->filtered_frames);
9448c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9458c2ecf20Sopenharmony_ci			 fmt_table, "non_channel_beacons:",
9468c2ecf20Sopenharmony_ci			 le32_to_cpu(general->non_channel_beacons),
9478c2ecf20Sopenharmony_ci			 accum_general->non_channel_beacons,
9488c2ecf20Sopenharmony_ci			 delta_general->non_channel_beacons,
9498c2ecf20Sopenharmony_ci			 max_general->non_channel_beacons);
9508c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9518c2ecf20Sopenharmony_ci			 fmt_table, "channel_beacons:",
9528c2ecf20Sopenharmony_ci			 le32_to_cpu(general->channel_beacons),
9538c2ecf20Sopenharmony_ci			 accum_general->channel_beacons,
9548c2ecf20Sopenharmony_ci			 delta_general->channel_beacons,
9558c2ecf20Sopenharmony_ci			 max_general->channel_beacons);
9568c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9578c2ecf20Sopenharmony_ci			 fmt_table, "num_missed_bcon:",
9588c2ecf20Sopenharmony_ci			 le32_to_cpu(general->num_missed_bcon),
9598c2ecf20Sopenharmony_ci			 accum_general->num_missed_bcon,
9608c2ecf20Sopenharmony_ci			 delta_general->num_missed_bcon,
9618c2ecf20Sopenharmony_ci			 max_general->num_missed_bcon);
9628c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9638c2ecf20Sopenharmony_ci			 fmt_table, "adc_rx_saturation_time:",
9648c2ecf20Sopenharmony_ci			 le32_to_cpu(general->adc_rx_saturation_time),
9658c2ecf20Sopenharmony_ci			 accum_general->adc_rx_saturation_time,
9668c2ecf20Sopenharmony_ci			 delta_general->adc_rx_saturation_time,
9678c2ecf20Sopenharmony_ci			 max_general->adc_rx_saturation_time);
9688c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9698c2ecf20Sopenharmony_ci			 fmt_table, "ina_detect_search_tm:",
9708c2ecf20Sopenharmony_ci			 le32_to_cpu(general->ina_detection_search_time),
9718c2ecf20Sopenharmony_ci			 accum_general->ina_detection_search_time,
9728c2ecf20Sopenharmony_ci			 delta_general->ina_detection_search_time,
9738c2ecf20Sopenharmony_ci			 max_general->ina_detection_search_time);
9748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9758c2ecf20Sopenharmony_ci			 fmt_table, "beacon_silence_rssi_a:",
9768c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_silence_rssi_a),
9778c2ecf20Sopenharmony_ci			 accum_general->beacon_silence_rssi_a,
9788c2ecf20Sopenharmony_ci			 delta_general->beacon_silence_rssi_a,
9798c2ecf20Sopenharmony_ci			 max_general->beacon_silence_rssi_a);
9808c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9818c2ecf20Sopenharmony_ci			 fmt_table, "beacon_silence_rssi_b:",
9828c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_silence_rssi_b),
9838c2ecf20Sopenharmony_ci			 accum_general->beacon_silence_rssi_b,
9848c2ecf20Sopenharmony_ci			 delta_general->beacon_silence_rssi_b,
9858c2ecf20Sopenharmony_ci			 max_general->beacon_silence_rssi_b);
9868c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9878c2ecf20Sopenharmony_ci			 fmt_table, "beacon_silence_rssi_c:",
9888c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_silence_rssi_c),
9898c2ecf20Sopenharmony_ci			 accum_general->beacon_silence_rssi_c,
9908c2ecf20Sopenharmony_ci			 delta_general->beacon_silence_rssi_c,
9918c2ecf20Sopenharmony_ci			 max_general->beacon_silence_rssi_c);
9928c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9938c2ecf20Sopenharmony_ci			 fmt_table, "interference_data_flag:",
9948c2ecf20Sopenharmony_ci			 le32_to_cpu(general->interference_data_flag),
9958c2ecf20Sopenharmony_ci			 accum_general->interference_data_flag,
9968c2ecf20Sopenharmony_ci			 delta_general->interference_data_flag,
9978c2ecf20Sopenharmony_ci			 max_general->interference_data_flag);
9988c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
9998c2ecf20Sopenharmony_ci			 fmt_table, "channel_load:",
10008c2ecf20Sopenharmony_ci			 le32_to_cpu(general->channel_load),
10018c2ecf20Sopenharmony_ci			 accum_general->channel_load,
10028c2ecf20Sopenharmony_ci			 delta_general->channel_load,
10038c2ecf20Sopenharmony_ci			 max_general->channel_load);
10048c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10058c2ecf20Sopenharmony_ci			 fmt_table, "dsp_false_alarms:",
10068c2ecf20Sopenharmony_ci			 le32_to_cpu(general->dsp_false_alarms),
10078c2ecf20Sopenharmony_ci			 accum_general->dsp_false_alarms,
10088c2ecf20Sopenharmony_ci			 delta_general->dsp_false_alarms,
10098c2ecf20Sopenharmony_ci			 max_general->dsp_false_alarms);
10108c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10118c2ecf20Sopenharmony_ci			 fmt_table, "beacon_rssi_a:",
10128c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_rssi_a),
10138c2ecf20Sopenharmony_ci			 accum_general->beacon_rssi_a,
10148c2ecf20Sopenharmony_ci			 delta_general->beacon_rssi_a,
10158c2ecf20Sopenharmony_ci			 max_general->beacon_rssi_a);
10168c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10178c2ecf20Sopenharmony_ci			 fmt_table, "beacon_rssi_b:",
10188c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_rssi_b),
10198c2ecf20Sopenharmony_ci			 accum_general->beacon_rssi_b,
10208c2ecf20Sopenharmony_ci			 delta_general->beacon_rssi_b,
10218c2ecf20Sopenharmony_ci			 max_general->beacon_rssi_b);
10228c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10238c2ecf20Sopenharmony_ci			 fmt_table, "beacon_rssi_c:",
10248c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_rssi_c),
10258c2ecf20Sopenharmony_ci			 accum_general->beacon_rssi_c,
10268c2ecf20Sopenharmony_ci			 delta_general->beacon_rssi_c,
10278c2ecf20Sopenharmony_ci			 max_general->beacon_rssi_c);
10288c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10298c2ecf20Sopenharmony_ci			 fmt_table, "beacon_energy_a:",
10308c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_energy_a),
10318c2ecf20Sopenharmony_ci			 accum_general->beacon_energy_a,
10328c2ecf20Sopenharmony_ci			 delta_general->beacon_energy_a,
10338c2ecf20Sopenharmony_ci			 max_general->beacon_energy_a);
10348c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10358c2ecf20Sopenharmony_ci			 fmt_table, "beacon_energy_b:",
10368c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_energy_b),
10378c2ecf20Sopenharmony_ci			 accum_general->beacon_energy_b,
10388c2ecf20Sopenharmony_ci			 delta_general->beacon_energy_b,
10398c2ecf20Sopenharmony_ci			 max_general->beacon_energy_b);
10408c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10418c2ecf20Sopenharmony_ci			 fmt_table, "beacon_energy_c:",
10428c2ecf20Sopenharmony_ci			 le32_to_cpu(general->beacon_energy_c),
10438c2ecf20Sopenharmony_ci			 accum_general->beacon_energy_c,
10448c2ecf20Sopenharmony_ci			 delta_general->beacon_energy_c,
10458c2ecf20Sopenharmony_ci			 max_general->beacon_energy_c);
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10488c2ecf20Sopenharmony_ci			 fmt_header, "Statistics_Rx - OFDM_HT:");
10498c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10508c2ecf20Sopenharmony_ci			 fmt_table, "plcp_err:",
10518c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
10528c2ecf20Sopenharmony_ci			 delta_ht->plcp_err, max_ht->plcp_err);
10538c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10548c2ecf20Sopenharmony_ci			 fmt_table, "overrun_err:",
10558c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
10568c2ecf20Sopenharmony_ci			 delta_ht->overrun_err, max_ht->overrun_err);
10578c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10588c2ecf20Sopenharmony_ci			 fmt_table, "early_overrun_err:",
10598c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->early_overrun_err),
10608c2ecf20Sopenharmony_ci			 accum_ht->early_overrun_err,
10618c2ecf20Sopenharmony_ci			 delta_ht->early_overrun_err,
10628c2ecf20Sopenharmony_ci			 max_ht->early_overrun_err);
10638c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10648c2ecf20Sopenharmony_ci			 fmt_table, "crc32_good:",
10658c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
10668c2ecf20Sopenharmony_ci			 delta_ht->crc32_good, max_ht->crc32_good);
10678c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10688c2ecf20Sopenharmony_ci			 fmt_table, "crc32_err:",
10698c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
10708c2ecf20Sopenharmony_ci			 delta_ht->crc32_err, max_ht->crc32_err);
10718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10728c2ecf20Sopenharmony_ci			 fmt_table, "mh_format_err:",
10738c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->mh_format_err),
10748c2ecf20Sopenharmony_ci			 accum_ht->mh_format_err,
10758c2ecf20Sopenharmony_ci			 delta_ht->mh_format_err, max_ht->mh_format_err);
10768c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10778c2ecf20Sopenharmony_ci			 fmt_table, "agg_crc32_good:",
10788c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->agg_crc32_good),
10798c2ecf20Sopenharmony_ci			 accum_ht->agg_crc32_good,
10808c2ecf20Sopenharmony_ci			 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
10818c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10828c2ecf20Sopenharmony_ci			 fmt_table, "agg_mpdu_cnt:",
10838c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->agg_mpdu_cnt),
10848c2ecf20Sopenharmony_ci			 accum_ht->agg_mpdu_cnt,
10858c2ecf20Sopenharmony_ci			 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
10868c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10878c2ecf20Sopenharmony_ci			 fmt_table, "agg_cnt:",
10888c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
10898c2ecf20Sopenharmony_ci			 delta_ht->agg_cnt, max_ht->agg_cnt);
10908c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
10918c2ecf20Sopenharmony_ci			 fmt_table, "unsupport_mcs:",
10928c2ecf20Sopenharmony_ci			 le32_to_cpu(ht->unsupport_mcs),
10938c2ecf20Sopenharmony_ci			 accum_ht->unsupport_mcs,
10948c2ecf20Sopenharmony_ci			 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_ci	spin_unlock_bh(&priv->statistics.lock);
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
10998c2ecf20Sopenharmony_ci	kfree(buf);
11008c2ecf20Sopenharmony_ci	return ret;
11018c2ecf20Sopenharmony_ci}
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
11048c2ecf20Sopenharmony_ci					char __user *user_buf,
11058c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
11068c2ecf20Sopenharmony_ci{
11078c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
11088c2ecf20Sopenharmony_ci	int pos = 0;
11098c2ecf20Sopenharmony_ci	char *buf;
11108c2ecf20Sopenharmony_ci	int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
11118c2ecf20Sopenharmony_ci	ssize_t ret;
11128c2ecf20Sopenharmony_ci	struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
11138c2ecf20Sopenharmony_ci
11148c2ecf20Sopenharmony_ci	if (!iwl_is_alive(priv))
11158c2ecf20Sopenharmony_ci		return -EAGAIN;
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
11188c2ecf20Sopenharmony_ci	if (!buf)
11198c2ecf20Sopenharmony_ci		return -ENOMEM;
11208c2ecf20Sopenharmony_ci
11218c2ecf20Sopenharmony_ci	/* the statistic information display here is based on
11228c2ecf20Sopenharmony_ci	 * the last statistics notification from uCode
11238c2ecf20Sopenharmony_ci	 * might not reflect the current uCode activity
11248c2ecf20Sopenharmony_ci	 */
11258c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->statistics.lock);
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci	tx = &priv->statistics.tx;
11288c2ecf20Sopenharmony_ci	accum_tx = &priv->accum_stats.tx;
11298c2ecf20Sopenharmony_ci	delta_tx = &priv->delta_stats.tx;
11308c2ecf20Sopenharmony_ci	max_tx = &priv->max_delta_stats.tx;
11318c2ecf20Sopenharmony_ci
11328c2ecf20Sopenharmony_ci	pos += iwl_statistics_flag(priv, buf, bufsz);
11338c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11348c2ecf20Sopenharmony_ci			 fmt_header, "Statistics_Tx:");
11358c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11368c2ecf20Sopenharmony_ci			 fmt_table, "preamble:",
11378c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->preamble_cnt),
11388c2ecf20Sopenharmony_ci			 accum_tx->preamble_cnt,
11398c2ecf20Sopenharmony_ci			 delta_tx->preamble_cnt, max_tx->preamble_cnt);
11408c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11418c2ecf20Sopenharmony_ci			 fmt_table, "rx_detected_cnt:",
11428c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->rx_detected_cnt),
11438c2ecf20Sopenharmony_ci			 accum_tx->rx_detected_cnt,
11448c2ecf20Sopenharmony_ci			 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
11458c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11468c2ecf20Sopenharmony_ci			 fmt_table, "bt_prio_defer_cnt:",
11478c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->bt_prio_defer_cnt),
11488c2ecf20Sopenharmony_ci			 accum_tx->bt_prio_defer_cnt,
11498c2ecf20Sopenharmony_ci			 delta_tx->bt_prio_defer_cnt,
11508c2ecf20Sopenharmony_ci			 max_tx->bt_prio_defer_cnt);
11518c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11528c2ecf20Sopenharmony_ci			 fmt_table, "bt_prio_kill_cnt:",
11538c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->bt_prio_kill_cnt),
11548c2ecf20Sopenharmony_ci			 accum_tx->bt_prio_kill_cnt,
11558c2ecf20Sopenharmony_ci			 delta_tx->bt_prio_kill_cnt,
11568c2ecf20Sopenharmony_ci			 max_tx->bt_prio_kill_cnt);
11578c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11588c2ecf20Sopenharmony_ci			 fmt_table, "few_bytes_cnt:",
11598c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->few_bytes_cnt),
11608c2ecf20Sopenharmony_ci			 accum_tx->few_bytes_cnt,
11618c2ecf20Sopenharmony_ci			 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
11628c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11638c2ecf20Sopenharmony_ci			 fmt_table, "cts_timeout:",
11648c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
11658c2ecf20Sopenharmony_ci			 delta_tx->cts_timeout, max_tx->cts_timeout);
11668c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11678c2ecf20Sopenharmony_ci			 fmt_table, "ack_timeout:",
11688c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->ack_timeout),
11698c2ecf20Sopenharmony_ci			 accum_tx->ack_timeout,
11708c2ecf20Sopenharmony_ci			 delta_tx->ack_timeout, max_tx->ack_timeout);
11718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11728c2ecf20Sopenharmony_ci			 fmt_table, "expected_ack_cnt:",
11738c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->expected_ack_cnt),
11748c2ecf20Sopenharmony_ci			 accum_tx->expected_ack_cnt,
11758c2ecf20Sopenharmony_ci			 delta_tx->expected_ack_cnt,
11768c2ecf20Sopenharmony_ci			 max_tx->expected_ack_cnt);
11778c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11788c2ecf20Sopenharmony_ci			 fmt_table, "actual_ack_cnt:",
11798c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->actual_ack_cnt),
11808c2ecf20Sopenharmony_ci			 accum_tx->actual_ack_cnt,
11818c2ecf20Sopenharmony_ci			 delta_tx->actual_ack_cnt,
11828c2ecf20Sopenharmony_ci			 max_tx->actual_ack_cnt);
11838c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11848c2ecf20Sopenharmony_ci			 fmt_table, "dump_msdu_cnt:",
11858c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->dump_msdu_cnt),
11868c2ecf20Sopenharmony_ci			 accum_tx->dump_msdu_cnt,
11878c2ecf20Sopenharmony_ci			 delta_tx->dump_msdu_cnt,
11888c2ecf20Sopenharmony_ci			 max_tx->dump_msdu_cnt);
11898c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11908c2ecf20Sopenharmony_ci			 fmt_table, "abort_nxt_frame_mismatch:",
11918c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
11928c2ecf20Sopenharmony_ci			 accum_tx->burst_abort_next_frame_mismatch_cnt,
11938c2ecf20Sopenharmony_ci			 delta_tx->burst_abort_next_frame_mismatch_cnt,
11948c2ecf20Sopenharmony_ci			 max_tx->burst_abort_next_frame_mismatch_cnt);
11958c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
11968c2ecf20Sopenharmony_ci			 fmt_table, "abort_missing_nxt_frame:",
11978c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
11988c2ecf20Sopenharmony_ci			 accum_tx->burst_abort_missing_next_frame_cnt,
11998c2ecf20Sopenharmony_ci			 delta_tx->burst_abort_missing_next_frame_cnt,
12008c2ecf20Sopenharmony_ci			 max_tx->burst_abort_missing_next_frame_cnt);
12018c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12028c2ecf20Sopenharmony_ci			 fmt_table, "cts_timeout_collision:",
12038c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->cts_timeout_collision),
12048c2ecf20Sopenharmony_ci			 accum_tx->cts_timeout_collision,
12058c2ecf20Sopenharmony_ci			 delta_tx->cts_timeout_collision,
12068c2ecf20Sopenharmony_ci			 max_tx->cts_timeout_collision);
12078c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12088c2ecf20Sopenharmony_ci			 fmt_table, "ack_ba_timeout_collision:",
12098c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->ack_or_ba_timeout_collision),
12108c2ecf20Sopenharmony_ci			 accum_tx->ack_or_ba_timeout_collision,
12118c2ecf20Sopenharmony_ci			 delta_tx->ack_or_ba_timeout_collision,
12128c2ecf20Sopenharmony_ci			 max_tx->ack_or_ba_timeout_collision);
12138c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12148c2ecf20Sopenharmony_ci			 fmt_table, "agg ba_timeout:",
12158c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.ba_timeout),
12168c2ecf20Sopenharmony_ci			 accum_tx->agg.ba_timeout,
12178c2ecf20Sopenharmony_ci			 delta_tx->agg.ba_timeout,
12188c2ecf20Sopenharmony_ci			 max_tx->agg.ba_timeout);
12198c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12208c2ecf20Sopenharmony_ci			 fmt_table, "agg ba_resched_frames:",
12218c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.ba_reschedule_frames),
12228c2ecf20Sopenharmony_ci			 accum_tx->agg.ba_reschedule_frames,
12238c2ecf20Sopenharmony_ci			 delta_tx->agg.ba_reschedule_frames,
12248c2ecf20Sopenharmony_ci			 max_tx->agg.ba_reschedule_frames);
12258c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12268c2ecf20Sopenharmony_ci			 fmt_table, "agg scd_query_agg_frame:",
12278c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
12288c2ecf20Sopenharmony_ci			 accum_tx->agg.scd_query_agg_frame_cnt,
12298c2ecf20Sopenharmony_ci			 delta_tx->agg.scd_query_agg_frame_cnt,
12308c2ecf20Sopenharmony_ci			 max_tx->agg.scd_query_agg_frame_cnt);
12318c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12328c2ecf20Sopenharmony_ci			 fmt_table, "agg scd_query_no_agg:",
12338c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.scd_query_no_agg),
12348c2ecf20Sopenharmony_ci			 accum_tx->agg.scd_query_no_agg,
12358c2ecf20Sopenharmony_ci			 delta_tx->agg.scd_query_no_agg,
12368c2ecf20Sopenharmony_ci			 max_tx->agg.scd_query_no_agg);
12378c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12388c2ecf20Sopenharmony_ci			 fmt_table, "agg scd_query_agg:",
12398c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.scd_query_agg),
12408c2ecf20Sopenharmony_ci			 accum_tx->agg.scd_query_agg,
12418c2ecf20Sopenharmony_ci			 delta_tx->agg.scd_query_agg,
12428c2ecf20Sopenharmony_ci			 max_tx->agg.scd_query_agg);
12438c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12448c2ecf20Sopenharmony_ci			 fmt_table, "agg scd_query_mismatch:",
12458c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.scd_query_mismatch),
12468c2ecf20Sopenharmony_ci			 accum_tx->agg.scd_query_mismatch,
12478c2ecf20Sopenharmony_ci			 delta_tx->agg.scd_query_mismatch,
12488c2ecf20Sopenharmony_ci			 max_tx->agg.scd_query_mismatch);
12498c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12508c2ecf20Sopenharmony_ci			 fmt_table, "agg frame_not_ready:",
12518c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.frame_not_ready),
12528c2ecf20Sopenharmony_ci			 accum_tx->agg.frame_not_ready,
12538c2ecf20Sopenharmony_ci			 delta_tx->agg.frame_not_ready,
12548c2ecf20Sopenharmony_ci			 max_tx->agg.frame_not_ready);
12558c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12568c2ecf20Sopenharmony_ci			 fmt_table, "agg underrun:",
12578c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.underrun),
12588c2ecf20Sopenharmony_ci			 accum_tx->agg.underrun,
12598c2ecf20Sopenharmony_ci			 delta_tx->agg.underrun, max_tx->agg.underrun);
12608c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12618c2ecf20Sopenharmony_ci			 fmt_table, "agg bt_prio_kill:",
12628c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.bt_prio_kill),
12638c2ecf20Sopenharmony_ci			 accum_tx->agg.bt_prio_kill,
12648c2ecf20Sopenharmony_ci			 delta_tx->agg.bt_prio_kill,
12658c2ecf20Sopenharmony_ci			 max_tx->agg.bt_prio_kill);
12668c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
12678c2ecf20Sopenharmony_ci			 fmt_table, "agg rx_ba_rsp_cnt:",
12688c2ecf20Sopenharmony_ci			 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
12698c2ecf20Sopenharmony_ci			 accum_tx->agg.rx_ba_rsp_cnt,
12708c2ecf20Sopenharmony_ci			 delta_tx->agg.rx_ba_rsp_cnt,
12718c2ecf20Sopenharmony_ci			 max_tx->agg.rx_ba_rsp_cnt);
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci	if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
12748c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
12758c2ecf20Sopenharmony_ci			"tx power: (1/2 dB step)\n");
12768c2ecf20Sopenharmony_ci		if ((priv->nvm_data->valid_tx_ant & ANT_A) &&
12778c2ecf20Sopenharmony_ci		    tx->tx_power.ant_a)
12788c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
12798c2ecf20Sopenharmony_ci					fmt_hex, "antenna A:",
12808c2ecf20Sopenharmony_ci					tx->tx_power.ant_a);
12818c2ecf20Sopenharmony_ci		if ((priv->nvm_data->valid_tx_ant & ANT_B) &&
12828c2ecf20Sopenharmony_ci		    tx->tx_power.ant_b)
12838c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
12848c2ecf20Sopenharmony_ci					fmt_hex, "antenna B:",
12858c2ecf20Sopenharmony_ci					tx->tx_power.ant_b);
12868c2ecf20Sopenharmony_ci		if ((priv->nvm_data->valid_tx_ant & ANT_C) &&
12878c2ecf20Sopenharmony_ci		    tx->tx_power.ant_c)
12888c2ecf20Sopenharmony_ci			pos += scnprintf(buf + pos, bufsz - pos,
12898c2ecf20Sopenharmony_ci					fmt_hex, "antenna C:",
12908c2ecf20Sopenharmony_ci					tx->tx_power.ant_c);
12918c2ecf20Sopenharmony_ci	}
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_ci	spin_unlock_bh(&priv->statistics.lock);
12948c2ecf20Sopenharmony_ci
12958c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
12968c2ecf20Sopenharmony_ci	kfree(buf);
12978c2ecf20Sopenharmony_ci	return ret;
12988c2ecf20Sopenharmony_ci}
12998c2ecf20Sopenharmony_ci
13008c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
13018c2ecf20Sopenharmony_ci					char __user *user_buf,
13028c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
13038c2ecf20Sopenharmony_ci{
13048c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
13058c2ecf20Sopenharmony_ci	int pos = 0;
13068c2ecf20Sopenharmony_ci	char *buf;
13078c2ecf20Sopenharmony_ci	int bufsz = sizeof(struct statistics_general) * 10 + 300;
13088c2ecf20Sopenharmony_ci	ssize_t ret;
13098c2ecf20Sopenharmony_ci	struct statistics_general_common *general, *accum_general;
13108c2ecf20Sopenharmony_ci	struct statistics_general_common *delta_general, *max_general;
13118c2ecf20Sopenharmony_ci	struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
13128c2ecf20Sopenharmony_ci	struct statistics_div *div, *accum_div, *delta_div, *max_div;
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ci	if (!iwl_is_alive(priv))
13158c2ecf20Sopenharmony_ci		return -EAGAIN;
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
13188c2ecf20Sopenharmony_ci	if (!buf)
13198c2ecf20Sopenharmony_ci		return -ENOMEM;
13208c2ecf20Sopenharmony_ci
13218c2ecf20Sopenharmony_ci	/* the statistic information display here is based on
13228c2ecf20Sopenharmony_ci	 * the last statistics notification from uCode
13238c2ecf20Sopenharmony_ci	 * might not reflect the current uCode activity
13248c2ecf20Sopenharmony_ci	 */
13258c2ecf20Sopenharmony_ci
13268c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->statistics.lock);
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci	general = &priv->statistics.common;
13298c2ecf20Sopenharmony_ci	dbg = &priv->statistics.common.dbg;
13308c2ecf20Sopenharmony_ci	div = &priv->statistics.common.div;
13318c2ecf20Sopenharmony_ci	accum_general = &priv->accum_stats.common;
13328c2ecf20Sopenharmony_ci	accum_dbg = &priv->accum_stats.common.dbg;
13338c2ecf20Sopenharmony_ci	accum_div = &priv->accum_stats.common.div;
13348c2ecf20Sopenharmony_ci	delta_general = &priv->delta_stats.common;
13358c2ecf20Sopenharmony_ci	max_general = &priv->max_delta_stats.common;
13368c2ecf20Sopenharmony_ci	delta_dbg = &priv->delta_stats.common.dbg;
13378c2ecf20Sopenharmony_ci	max_dbg = &priv->max_delta_stats.common.dbg;
13388c2ecf20Sopenharmony_ci	delta_div = &priv->delta_stats.common.div;
13398c2ecf20Sopenharmony_ci	max_div = &priv->max_delta_stats.common.div;
13408c2ecf20Sopenharmony_ci
13418c2ecf20Sopenharmony_ci	pos += iwl_statistics_flag(priv, buf, bufsz);
13428c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13438c2ecf20Sopenharmony_ci			 fmt_header, "Statistics_General:");
13448c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13458c2ecf20Sopenharmony_ci			 fmt_value, "temperature:",
13468c2ecf20Sopenharmony_ci			 le32_to_cpu(general->temperature));
13478c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13488c2ecf20Sopenharmony_ci			 fmt_value, "temperature_m:",
13498c2ecf20Sopenharmony_ci			 le32_to_cpu(general->temperature_m));
13508c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13518c2ecf20Sopenharmony_ci			 fmt_value, "ttl_timestamp:",
13528c2ecf20Sopenharmony_ci			 le32_to_cpu(general->ttl_timestamp));
13538c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13548c2ecf20Sopenharmony_ci			 fmt_table, "burst_check:",
13558c2ecf20Sopenharmony_ci			 le32_to_cpu(dbg->burst_check),
13568c2ecf20Sopenharmony_ci			 accum_dbg->burst_check,
13578c2ecf20Sopenharmony_ci			 delta_dbg->burst_check, max_dbg->burst_check);
13588c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13598c2ecf20Sopenharmony_ci			 fmt_table, "burst_count:",
13608c2ecf20Sopenharmony_ci			 le32_to_cpu(dbg->burst_count),
13618c2ecf20Sopenharmony_ci			 accum_dbg->burst_count,
13628c2ecf20Sopenharmony_ci			 delta_dbg->burst_count, max_dbg->burst_count);
13638c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13648c2ecf20Sopenharmony_ci			 fmt_table, "wait_for_silence_timeout_count:",
13658c2ecf20Sopenharmony_ci			 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
13668c2ecf20Sopenharmony_ci			 accum_dbg->wait_for_silence_timeout_cnt,
13678c2ecf20Sopenharmony_ci			 delta_dbg->wait_for_silence_timeout_cnt,
13688c2ecf20Sopenharmony_ci			 max_dbg->wait_for_silence_timeout_cnt);
13698c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13708c2ecf20Sopenharmony_ci			 fmt_table, "sleep_time:",
13718c2ecf20Sopenharmony_ci			 le32_to_cpu(general->sleep_time),
13728c2ecf20Sopenharmony_ci			 accum_general->sleep_time,
13738c2ecf20Sopenharmony_ci			 delta_general->sleep_time, max_general->sleep_time);
13748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13758c2ecf20Sopenharmony_ci			 fmt_table, "slots_out:",
13768c2ecf20Sopenharmony_ci			 le32_to_cpu(general->slots_out),
13778c2ecf20Sopenharmony_ci			 accum_general->slots_out,
13788c2ecf20Sopenharmony_ci			 delta_general->slots_out, max_general->slots_out);
13798c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13808c2ecf20Sopenharmony_ci			 fmt_table, "slots_idle:",
13818c2ecf20Sopenharmony_ci			 le32_to_cpu(general->slots_idle),
13828c2ecf20Sopenharmony_ci			 accum_general->slots_idle,
13838c2ecf20Sopenharmony_ci			 delta_general->slots_idle, max_general->slots_idle);
13848c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13858c2ecf20Sopenharmony_ci			 fmt_table, "tx_on_a:",
13868c2ecf20Sopenharmony_ci			 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
13878c2ecf20Sopenharmony_ci			 delta_div->tx_on_a, max_div->tx_on_a);
13888c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13898c2ecf20Sopenharmony_ci			 fmt_table, "tx_on_b:",
13908c2ecf20Sopenharmony_ci			 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
13918c2ecf20Sopenharmony_ci			 delta_div->tx_on_b, max_div->tx_on_b);
13928c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13938c2ecf20Sopenharmony_ci			 fmt_table, "exec_time:",
13948c2ecf20Sopenharmony_ci			 le32_to_cpu(div->exec_time), accum_div->exec_time,
13958c2ecf20Sopenharmony_ci			 delta_div->exec_time, max_div->exec_time);
13968c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
13978c2ecf20Sopenharmony_ci			 fmt_table, "probe_time:",
13988c2ecf20Sopenharmony_ci			 le32_to_cpu(div->probe_time), accum_div->probe_time,
13998c2ecf20Sopenharmony_ci			 delta_div->probe_time, max_div->probe_time);
14008c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14018c2ecf20Sopenharmony_ci			 fmt_table, "rx_enable_counter:",
14028c2ecf20Sopenharmony_ci			 le32_to_cpu(general->rx_enable_counter),
14038c2ecf20Sopenharmony_ci			 accum_general->rx_enable_counter,
14048c2ecf20Sopenharmony_ci			 delta_general->rx_enable_counter,
14058c2ecf20Sopenharmony_ci			 max_general->rx_enable_counter);
14068c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14078c2ecf20Sopenharmony_ci			 fmt_table, "num_of_sos_states:",
14088c2ecf20Sopenharmony_ci			 le32_to_cpu(general->num_of_sos_states),
14098c2ecf20Sopenharmony_ci			 accum_general->num_of_sos_states,
14108c2ecf20Sopenharmony_ci			 delta_general->num_of_sos_states,
14118c2ecf20Sopenharmony_ci			 max_general->num_of_sos_states);
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci	spin_unlock_bh(&priv->statistics.lock);
14148c2ecf20Sopenharmony_ci
14158c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
14168c2ecf20Sopenharmony_ci	kfree(buf);
14178c2ecf20Sopenharmony_ci	return ret;
14188c2ecf20Sopenharmony_ci}
14198c2ecf20Sopenharmony_ci
14208c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
14218c2ecf20Sopenharmony_ci					char __user *user_buf,
14228c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
14238c2ecf20Sopenharmony_ci{
14248c2ecf20Sopenharmony_ci	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
14258c2ecf20Sopenharmony_ci	int pos = 0;
14268c2ecf20Sopenharmony_ci	char *buf;
14278c2ecf20Sopenharmony_ci	int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
14288c2ecf20Sopenharmony_ci	ssize_t ret;
14298c2ecf20Sopenharmony_ci	struct statistics_bt_activity *bt, *accum_bt;
14308c2ecf20Sopenharmony_ci
14318c2ecf20Sopenharmony_ci	if (!iwl_is_alive(priv))
14328c2ecf20Sopenharmony_ci		return -EAGAIN;
14338c2ecf20Sopenharmony_ci
14348c2ecf20Sopenharmony_ci	if (!priv->bt_enable_flag)
14358c2ecf20Sopenharmony_ci		return -EINVAL;
14368c2ecf20Sopenharmony_ci
14378c2ecf20Sopenharmony_ci	/* make request to uCode to retrieve statistics information */
14388c2ecf20Sopenharmony_ci	mutex_lock(&priv->mutex);
14398c2ecf20Sopenharmony_ci	ret = iwl_send_statistics_request(priv, 0, false);
14408c2ecf20Sopenharmony_ci	mutex_unlock(&priv->mutex);
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci	if (ret)
14438c2ecf20Sopenharmony_ci		return -EAGAIN;
14448c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
14458c2ecf20Sopenharmony_ci	if (!buf)
14468c2ecf20Sopenharmony_ci		return -ENOMEM;
14478c2ecf20Sopenharmony_ci
14488c2ecf20Sopenharmony_ci	/*
14498c2ecf20Sopenharmony_ci	 * the statistic information display here is based on
14508c2ecf20Sopenharmony_ci	 * the last statistics notification from uCode
14518c2ecf20Sopenharmony_ci	 * might not reflect the current uCode activity
14528c2ecf20Sopenharmony_ci	 */
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->statistics.lock);
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_ci	bt = &priv->statistics.bt_activity;
14578c2ecf20Sopenharmony_ci	accum_bt = &priv->accum_stats.bt_activity;
14588c2ecf20Sopenharmony_ci
14598c2ecf20Sopenharmony_ci	pos += iwl_statistics_flag(priv, buf, bufsz);
14608c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
14618c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14628c2ecf20Sopenharmony_ci			"\t\t\tcurrent\t\t\taccumulative\n");
14638c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14648c2ecf20Sopenharmony_ci			 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
14658c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->hi_priority_tx_req_cnt),
14668c2ecf20Sopenharmony_ci			 accum_bt->hi_priority_tx_req_cnt);
14678c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14688c2ecf20Sopenharmony_ci			 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
14698c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
14708c2ecf20Sopenharmony_ci			 accum_bt->hi_priority_tx_denied_cnt);
14718c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14728c2ecf20Sopenharmony_ci			 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
14738c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->lo_priority_tx_req_cnt),
14748c2ecf20Sopenharmony_ci			 accum_bt->lo_priority_tx_req_cnt);
14758c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14768c2ecf20Sopenharmony_ci			 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
14778c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
14788c2ecf20Sopenharmony_ci			 accum_bt->lo_priority_tx_denied_cnt);
14798c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14808c2ecf20Sopenharmony_ci			 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
14818c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->hi_priority_rx_req_cnt),
14828c2ecf20Sopenharmony_ci			 accum_bt->hi_priority_rx_req_cnt);
14838c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14848c2ecf20Sopenharmony_ci			 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
14858c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
14868c2ecf20Sopenharmony_ci			 accum_bt->hi_priority_rx_denied_cnt);
14878c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14888c2ecf20Sopenharmony_ci			 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
14898c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->lo_priority_rx_req_cnt),
14908c2ecf20Sopenharmony_ci			 accum_bt->lo_priority_rx_req_cnt);
14918c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14928c2ecf20Sopenharmony_ci			 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
14938c2ecf20Sopenharmony_ci			 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
14948c2ecf20Sopenharmony_ci			 accum_bt->lo_priority_rx_denied_cnt);
14958c2ecf20Sopenharmony_ci
14968c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
14978c2ecf20Sopenharmony_ci			 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
14988c2ecf20Sopenharmony_ci			 le32_to_cpu(priv->statistics.num_bt_kills),
14998c2ecf20Sopenharmony_ci			 priv->statistics.accum_num_bt_kills);
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci	spin_unlock_bh(&priv->statistics.lock);
15028c2ecf20Sopenharmony_ci
15038c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
15048c2ecf20Sopenharmony_ci	kfree(buf);
15058c2ecf20Sopenharmony_ci	return ret;
15068c2ecf20Sopenharmony_ci}
15078c2ecf20Sopenharmony_ci
15088c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
15098c2ecf20Sopenharmony_ci					char __user *user_buf,
15108c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
15118c2ecf20Sopenharmony_ci{
15128c2ecf20Sopenharmony_ci	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
15138c2ecf20Sopenharmony_ci	int pos = 0;
15148c2ecf20Sopenharmony_ci	char *buf;
15158c2ecf20Sopenharmony_ci	int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
15168c2ecf20Sopenharmony_ci		(sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
15178c2ecf20Sopenharmony_ci	ssize_t ret;
15188c2ecf20Sopenharmony_ci
15198c2ecf20Sopenharmony_ci	if (!iwl_is_alive(priv))
15208c2ecf20Sopenharmony_ci		return -EAGAIN;
15218c2ecf20Sopenharmony_ci
15228c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
15238c2ecf20Sopenharmony_ci	if (!buf)
15248c2ecf20Sopenharmony_ci		return -ENOMEM;
15258c2ecf20Sopenharmony_ci
15268c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
15278c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
15288c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
15298c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.pp_delay);
15308c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15318c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
15328c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.pp_few_bytes);
15338c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15348c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
15358c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.pp_bt_prio);
15368c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15378c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
15388c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.pp_quiet_period);
15398c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15408c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
15418c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.pp_calc_ttak);
15428c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
15438c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(
15448c2ecf20Sopenharmony_ci				TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
15458c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.int_crossed_retry);
15468c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15478c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
15488c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.short_limit);
15498c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15508c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
15518c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.long_limit);
15528c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15538c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
15548c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.fifo_underrun);
15558c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15568c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
15578c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.drain_flow);
15588c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15598c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
15608c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.rfkill_flush);
15618c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15628c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
15638c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.life_expire);
15648c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15658c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
15668c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.dest_ps);
15678c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15688c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
15698c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.host_abort);
15708c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15718c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
15728c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.pp_delay);
15738c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15748c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
15758c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.sta_invalid);
15768c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15778c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
15788c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.frag_drop);
15798c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15808c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
15818c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.tid_disable);
15828c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15838c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
15848c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.fifo_flush);
15858c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
15868c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(
15878c2ecf20Sopenharmony_ci				TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
15888c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.insuff_cf_poll);
15898c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
15908c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
15918c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.fail_hw_drop);
15928c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
15938c2ecf20Sopenharmony_ci			 iwl_get_tx_fail_reason(
15948c2ecf20Sopenharmony_ci				TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
15958c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.sta_color_mismatch);
15968c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
15978c2ecf20Sopenharmony_ci			 priv->reply_tx_stats.unknown);
15988c2ecf20Sopenharmony_ci
15998c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
16008c2ecf20Sopenharmony_ci			 "\nStatistics_Agg_TX_Error:\n");
16018c2ecf20Sopenharmony_ci
16028c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16038c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
16048c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.underrun);
16058c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16068c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
16078c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.bt_prio);
16088c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16098c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
16108c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.few_bytes);
16118c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16128c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
16138c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.abort);
16148c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
16158c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(
16168c2ecf20Sopenharmony_ci				AGG_TX_STATE_LAST_SENT_TTL_MSK),
16178c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.last_sent_ttl);
16188c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
16198c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(
16208c2ecf20Sopenharmony_ci				AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
16218c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.last_sent_try);
16228c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
16238c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(
16248c2ecf20Sopenharmony_ci				AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
16258c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.last_sent_bt_kill);
16268c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16278c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
16288c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.scd_query);
16298c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
16308c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(
16318c2ecf20Sopenharmony_ci				AGG_TX_STATE_TEST_BAD_CRC32_MSK),
16328c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.bad_crc32);
16338c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16348c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
16358c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.response);
16368c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16378c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
16388c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.dump_tx);
16398c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
16408c2ecf20Sopenharmony_ci			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
16418c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.delay_tx);
16428c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
16438c2ecf20Sopenharmony_ci			 priv->reply_agg_tx_stats.unknown);
16448c2ecf20Sopenharmony_ci
16458c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
16468c2ecf20Sopenharmony_ci	kfree(buf);
16478c2ecf20Sopenharmony_ci	return ret;
16488c2ecf20Sopenharmony_ci}
16498c2ecf20Sopenharmony_ci
16508c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
16518c2ecf20Sopenharmony_ci					char __user *user_buf,
16528c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
16538c2ecf20Sopenharmony_ci
16548c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
16558c2ecf20Sopenharmony_ci	int pos = 0;
16568c2ecf20Sopenharmony_ci	int cnt = 0;
16578c2ecf20Sopenharmony_ci	char *buf;
16588c2ecf20Sopenharmony_ci	int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
16598c2ecf20Sopenharmony_ci	ssize_t ret;
16608c2ecf20Sopenharmony_ci	struct iwl_sensitivity_data *data;
16618c2ecf20Sopenharmony_ci
16628c2ecf20Sopenharmony_ci	data = &priv->sensitivity_data;
16638c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
16648c2ecf20Sopenharmony_ci	if (!buf)
16658c2ecf20Sopenharmony_ci		return -ENOMEM;
16668c2ecf20Sopenharmony_ci
16678c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
16688c2ecf20Sopenharmony_ci			data->auto_corr_ofdm);
16698c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
16708c2ecf20Sopenharmony_ci			"auto_corr_ofdm_mrc:\t\t %u\n",
16718c2ecf20Sopenharmony_ci			data->auto_corr_ofdm_mrc);
16728c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
16738c2ecf20Sopenharmony_ci			data->auto_corr_ofdm_x1);
16748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
16758c2ecf20Sopenharmony_ci			"auto_corr_ofdm_mrc_x1:\t\t %u\n",
16768c2ecf20Sopenharmony_ci			data->auto_corr_ofdm_mrc_x1);
16778c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
16788c2ecf20Sopenharmony_ci			data->auto_corr_cck);
16798c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
16808c2ecf20Sopenharmony_ci			data->auto_corr_cck_mrc);
16818c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
16828c2ecf20Sopenharmony_ci			"last_bad_plcp_cnt_ofdm:\t\t %u\n",
16838c2ecf20Sopenharmony_ci			data->last_bad_plcp_cnt_ofdm);
16848c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
16858c2ecf20Sopenharmony_ci			data->last_fa_cnt_ofdm);
16868c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
16878c2ecf20Sopenharmony_ci			"last_bad_plcp_cnt_cck:\t\t %u\n",
16888c2ecf20Sopenharmony_ci			data->last_bad_plcp_cnt_cck);
16898c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
16908c2ecf20Sopenharmony_ci			data->last_fa_cnt_cck);
16918c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
16928c2ecf20Sopenharmony_ci			data->nrg_curr_state);
16938c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
16948c2ecf20Sopenharmony_ci			data->nrg_prev_state);
16958c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
16968c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < 10; cnt++) {
16978c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, " %u",
16988c2ecf20Sopenharmony_ci				data->nrg_value[cnt]);
16998c2ecf20Sopenharmony_ci	}
17008c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
17018c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
17028c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
17038c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, " %u",
17048c2ecf20Sopenharmony_ci				data->nrg_silence_rssi[cnt]);
17058c2ecf20Sopenharmony_ci	}
17068c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
17078c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
17088c2ecf20Sopenharmony_ci			data->nrg_silence_ref);
17098c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
17108c2ecf20Sopenharmony_ci			data->nrg_energy_idx);
17118c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
17128c2ecf20Sopenharmony_ci			data->nrg_silence_idx);
17138c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
17148c2ecf20Sopenharmony_ci			data->nrg_th_cck);
17158c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
17168c2ecf20Sopenharmony_ci			"nrg_auto_corr_silence_diff:\t %u\n",
17178c2ecf20Sopenharmony_ci			data->nrg_auto_corr_silence_diff);
17188c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
17198c2ecf20Sopenharmony_ci			data->num_in_cck_no_fa);
17208c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
17218c2ecf20Sopenharmony_ci			data->nrg_th_ofdm);
17228c2ecf20Sopenharmony_ci
17238c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
17248c2ecf20Sopenharmony_ci	kfree(buf);
17258c2ecf20Sopenharmony_ci	return ret;
17268c2ecf20Sopenharmony_ci}
17278c2ecf20Sopenharmony_ci
17288c2ecf20Sopenharmony_ci
17298c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
17308c2ecf20Sopenharmony_ci					char __user *user_buf,
17318c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
17328c2ecf20Sopenharmony_ci
17338c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
17348c2ecf20Sopenharmony_ci	int pos = 0;
17358c2ecf20Sopenharmony_ci	int cnt = 0;
17368c2ecf20Sopenharmony_ci	char *buf;
17378c2ecf20Sopenharmony_ci	int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
17388c2ecf20Sopenharmony_ci	ssize_t ret;
17398c2ecf20Sopenharmony_ci	struct iwl_chain_noise_data *data;
17408c2ecf20Sopenharmony_ci
17418c2ecf20Sopenharmony_ci	data = &priv->chain_noise_data;
17428c2ecf20Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
17438c2ecf20Sopenharmony_ci	if (!buf)
17448c2ecf20Sopenharmony_ci		return -ENOMEM;
17458c2ecf20Sopenharmony_ci
17468c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
17478c2ecf20Sopenharmony_ci			data->active_chains);
17488c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
17498c2ecf20Sopenharmony_ci			data->chain_noise_a);
17508c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
17518c2ecf20Sopenharmony_ci			data->chain_noise_b);
17528c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
17538c2ecf20Sopenharmony_ci			data->chain_noise_c);
17548c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
17558c2ecf20Sopenharmony_ci			data->chain_signal_a);
17568c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
17578c2ecf20Sopenharmony_ci			data->chain_signal_b);
17588c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
17598c2ecf20Sopenharmony_ci			data->chain_signal_c);
17608c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
17618c2ecf20Sopenharmony_ci			data->beacon_count);
17628c2ecf20Sopenharmony_ci
17638c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
17648c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
17658c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, " %u",
17668c2ecf20Sopenharmony_ci				data->disconn_array[cnt]);
17678c2ecf20Sopenharmony_ci	}
17688c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
17698c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
17708c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
17718c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, " %u",
17728c2ecf20Sopenharmony_ci				data->delta_gain_code[cnt]);
17738c2ecf20Sopenharmony_ci	}
17748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "\n");
17758c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
17768c2ecf20Sopenharmony_ci			data->radio_write);
17778c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
17788c2ecf20Sopenharmony_ci			data->state);
17798c2ecf20Sopenharmony_ci
17808c2ecf20Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
17818c2ecf20Sopenharmony_ci	kfree(buf);
17828c2ecf20Sopenharmony_ci	return ret;
17838c2ecf20Sopenharmony_ci}
17848c2ecf20Sopenharmony_ci
17858c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
17868c2ecf20Sopenharmony_ci						    char __user *user_buf,
17878c2ecf20Sopenharmony_ci						    size_t count, loff_t *ppos)
17888c2ecf20Sopenharmony_ci{
17898c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
17908c2ecf20Sopenharmony_ci	char buf[60];
17918c2ecf20Sopenharmony_ci	int pos = 0;
17928c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
17938c2ecf20Sopenharmony_ci	u32 pwrsave_status;
17948c2ecf20Sopenharmony_ci
17958c2ecf20Sopenharmony_ci	pwrsave_status = iwl_read32(priv->trans, CSR_GP_CNTRL) &
17968c2ecf20Sopenharmony_ci			CSR_GP_REG_POWER_SAVE_STATUS_MSK;
17978c2ecf20Sopenharmony_ci
17988c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
17998c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
18008c2ecf20Sopenharmony_ci		(pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
18018c2ecf20Sopenharmony_ci		(pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
18028c2ecf20Sopenharmony_ci		(pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
18038c2ecf20Sopenharmony_ci		"error");
18048c2ecf20Sopenharmony_ci
18058c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
18068c2ecf20Sopenharmony_ci}
18078c2ecf20Sopenharmony_ci
18088c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
18098c2ecf20Sopenharmony_ci					 const char __user *user_buf,
18108c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
18118c2ecf20Sopenharmony_ci{
18128c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
18138c2ecf20Sopenharmony_ci	char buf[8];
18148c2ecf20Sopenharmony_ci	int buf_size;
18158c2ecf20Sopenharmony_ci	int clear;
18168c2ecf20Sopenharmony_ci
18178c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
18188c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
18198c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
18208c2ecf20Sopenharmony_ci		return -EFAULT;
18218c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &clear) != 1)
18228c2ecf20Sopenharmony_ci		return -EFAULT;
18238c2ecf20Sopenharmony_ci
18248c2ecf20Sopenharmony_ci	/* make request to uCode to retrieve statistics information */
18258c2ecf20Sopenharmony_ci	mutex_lock(&priv->mutex);
18268c2ecf20Sopenharmony_ci	iwl_send_statistics_request(priv, 0, true);
18278c2ecf20Sopenharmony_ci	mutex_unlock(&priv->mutex);
18288c2ecf20Sopenharmony_ci
18298c2ecf20Sopenharmony_ci	return count;
18308c2ecf20Sopenharmony_ci}
18318c2ecf20Sopenharmony_ci
18328c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
18338c2ecf20Sopenharmony_ci					char __user *user_buf,
18348c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
18358c2ecf20Sopenharmony_ci
18368c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
18378c2ecf20Sopenharmony_ci	int pos = 0;
18388c2ecf20Sopenharmony_ci	char buf[128];
18398c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
18408c2ecf20Sopenharmony_ci
18418c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
18428c2ecf20Sopenharmony_ci			priv->event_log.ucode_trace ? "On" : "Off");
18438c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
18448c2ecf20Sopenharmony_ci			priv->event_log.non_wraps_count);
18458c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
18468c2ecf20Sopenharmony_ci			priv->event_log.wraps_once_count);
18478c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
18488c2ecf20Sopenharmony_ci			priv->event_log.wraps_more_count);
18498c2ecf20Sopenharmony_ci
18508c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
18518c2ecf20Sopenharmony_ci}
18528c2ecf20Sopenharmony_ci
18538c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
18548c2ecf20Sopenharmony_ci					 const char __user *user_buf,
18558c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
18568c2ecf20Sopenharmony_ci{
18578c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
18588c2ecf20Sopenharmony_ci	char buf[8];
18598c2ecf20Sopenharmony_ci	int buf_size;
18608c2ecf20Sopenharmony_ci	int trace;
18618c2ecf20Sopenharmony_ci
18628c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
18638c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
18648c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
18658c2ecf20Sopenharmony_ci		return -EFAULT;
18668c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &trace) != 1)
18678c2ecf20Sopenharmony_ci		return -EFAULT;
18688c2ecf20Sopenharmony_ci
18698c2ecf20Sopenharmony_ci	if (trace) {
18708c2ecf20Sopenharmony_ci		priv->event_log.ucode_trace = true;
18718c2ecf20Sopenharmony_ci		if (iwl_is_alive(priv)) {
18728c2ecf20Sopenharmony_ci			/* start collecting data now */
18738c2ecf20Sopenharmony_ci			mod_timer(&priv->ucode_trace, jiffies);
18748c2ecf20Sopenharmony_ci		}
18758c2ecf20Sopenharmony_ci	} else {
18768c2ecf20Sopenharmony_ci		priv->event_log.ucode_trace = false;
18778c2ecf20Sopenharmony_ci		del_timer_sync(&priv->ucode_trace);
18788c2ecf20Sopenharmony_ci	}
18798c2ecf20Sopenharmony_ci
18808c2ecf20Sopenharmony_ci	return count;
18818c2ecf20Sopenharmony_ci}
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
18848c2ecf20Sopenharmony_ci					 char __user *user_buf,
18858c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos) {
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
18888c2ecf20Sopenharmony_ci	int len = 0;
18898c2ecf20Sopenharmony_ci	char buf[20];
18908c2ecf20Sopenharmony_ci
18918c2ecf20Sopenharmony_ci	len = sprintf(buf, "0x%04X\n",
18928c2ecf20Sopenharmony_ci		le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
18938c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
18948c2ecf20Sopenharmony_ci}
18958c2ecf20Sopenharmony_ci
18968c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
18978c2ecf20Sopenharmony_ci						char __user *user_buf,
18988c2ecf20Sopenharmony_ci						size_t count, loff_t *ppos) {
18998c2ecf20Sopenharmony_ci
19008c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
19018c2ecf20Sopenharmony_ci	int len = 0;
19028c2ecf20Sopenharmony_ci	char buf[20];
19038c2ecf20Sopenharmony_ci
19048c2ecf20Sopenharmony_ci	len = sprintf(buf, "0x%04X\n",
19058c2ecf20Sopenharmony_ci		le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
19068c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
19078c2ecf20Sopenharmony_ci}
19088c2ecf20Sopenharmony_ci
19098c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
19108c2ecf20Sopenharmony_ci					char __user *user_buf,
19118c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
19128c2ecf20Sopenharmony_ci
19138c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
19148c2ecf20Sopenharmony_ci	int pos = 0;
19158c2ecf20Sopenharmony_ci	char buf[12];
19168c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
19178c2ecf20Sopenharmony_ci
19188c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
19198c2ecf20Sopenharmony_ci			priv->missed_beacon_threshold);
19208c2ecf20Sopenharmony_ci
19218c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
19228c2ecf20Sopenharmony_ci}
19238c2ecf20Sopenharmony_ci
19248c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
19258c2ecf20Sopenharmony_ci					 const char __user *user_buf,
19268c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
19278c2ecf20Sopenharmony_ci{
19288c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
19298c2ecf20Sopenharmony_ci	char buf[8];
19308c2ecf20Sopenharmony_ci	int buf_size;
19318c2ecf20Sopenharmony_ci	int missed;
19328c2ecf20Sopenharmony_ci
19338c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
19348c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
19358c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
19368c2ecf20Sopenharmony_ci		return -EFAULT;
19378c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &missed) != 1)
19388c2ecf20Sopenharmony_ci		return -EINVAL;
19398c2ecf20Sopenharmony_ci
19408c2ecf20Sopenharmony_ci	if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
19418c2ecf20Sopenharmony_ci	    missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
19428c2ecf20Sopenharmony_ci		priv->missed_beacon_threshold =
19438c2ecf20Sopenharmony_ci			IWL_MISSED_BEACON_THRESHOLD_DEF;
19448c2ecf20Sopenharmony_ci	else
19458c2ecf20Sopenharmony_ci		priv->missed_beacon_threshold = missed;
19468c2ecf20Sopenharmony_ci
19478c2ecf20Sopenharmony_ci	return count;
19488c2ecf20Sopenharmony_ci}
19498c2ecf20Sopenharmony_ci
19508c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
19518c2ecf20Sopenharmony_ci					char __user *user_buf,
19528c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
19538c2ecf20Sopenharmony_ci
19548c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
19558c2ecf20Sopenharmony_ci	int pos = 0;
19568c2ecf20Sopenharmony_ci	char buf[12];
19578c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
19588c2ecf20Sopenharmony_ci
19598c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
19608c2ecf20Sopenharmony_ci			priv->plcp_delta_threshold);
19618c2ecf20Sopenharmony_ci
19628c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
19638c2ecf20Sopenharmony_ci}
19648c2ecf20Sopenharmony_ci
19658c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
19668c2ecf20Sopenharmony_ci					const char __user *user_buf,
19678c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
19688c2ecf20Sopenharmony_ci
19698c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
19708c2ecf20Sopenharmony_ci	char buf[8];
19718c2ecf20Sopenharmony_ci	int buf_size;
19728c2ecf20Sopenharmony_ci	int plcp;
19738c2ecf20Sopenharmony_ci
19748c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
19758c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
19768c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
19778c2ecf20Sopenharmony_ci		return -EFAULT;
19788c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &plcp) != 1)
19798c2ecf20Sopenharmony_ci		return -EINVAL;
19808c2ecf20Sopenharmony_ci	if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
19818c2ecf20Sopenharmony_ci		(plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
19828c2ecf20Sopenharmony_ci		priv->plcp_delta_threshold =
19838c2ecf20Sopenharmony_ci			IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
19848c2ecf20Sopenharmony_ci	else
19858c2ecf20Sopenharmony_ci		priv->plcp_delta_threshold = plcp;
19868c2ecf20Sopenharmony_ci	return count;
19878c2ecf20Sopenharmony_ci}
19888c2ecf20Sopenharmony_ci
19898c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_rf_reset_read(struct file *file,
19908c2ecf20Sopenharmony_ci				       char __user *user_buf,
19918c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
19928c2ecf20Sopenharmony_ci{
19938c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
19948c2ecf20Sopenharmony_ci	int pos = 0;
19958c2ecf20Sopenharmony_ci	char buf[300];
19968c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
19978c2ecf20Sopenharmony_ci	struct iwl_rf_reset *rf_reset = &priv->rf_reset;
19988c2ecf20Sopenharmony_ci
19998c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
20008c2ecf20Sopenharmony_ci			"RF reset statistics\n");
20018c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
20028c2ecf20Sopenharmony_ci			"\tnumber of reset request: %d\n",
20038c2ecf20Sopenharmony_ci			rf_reset->reset_request_count);
20048c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
20058c2ecf20Sopenharmony_ci			"\tnumber of reset request success: %d\n",
20068c2ecf20Sopenharmony_ci			rf_reset->reset_success_count);
20078c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
20088c2ecf20Sopenharmony_ci			"\tnumber of reset request reject: %d\n",
20098c2ecf20Sopenharmony_ci			rf_reset->reset_reject_count);
20108c2ecf20Sopenharmony_ci
20118c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
20128c2ecf20Sopenharmony_ci}
20138c2ecf20Sopenharmony_ci
20148c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_rf_reset_write(struct file *file,
20158c2ecf20Sopenharmony_ci					const char __user *user_buf,
20168c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
20178c2ecf20Sopenharmony_ci
20188c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
20198c2ecf20Sopenharmony_ci	int ret;
20208c2ecf20Sopenharmony_ci
20218c2ecf20Sopenharmony_ci	ret = iwl_force_rf_reset(priv, true);
20228c2ecf20Sopenharmony_ci	return ret ? ret : count;
20238c2ecf20Sopenharmony_ci}
20248c2ecf20Sopenharmony_ci
20258c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
20268c2ecf20Sopenharmony_ci					const char __user *user_buf,
20278c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
20288c2ecf20Sopenharmony_ci
20298c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
20308c2ecf20Sopenharmony_ci	char buf[8];
20318c2ecf20Sopenharmony_ci	int buf_size;
20328c2ecf20Sopenharmony_ci	int flush;
20338c2ecf20Sopenharmony_ci
20348c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
20358c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
20368c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
20378c2ecf20Sopenharmony_ci		return -EFAULT;
20388c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &flush) != 1)
20398c2ecf20Sopenharmony_ci		return -EINVAL;
20408c2ecf20Sopenharmony_ci
20418c2ecf20Sopenharmony_ci	if (iwl_is_rfkill(priv))
20428c2ecf20Sopenharmony_ci		return -EFAULT;
20438c2ecf20Sopenharmony_ci
20448c2ecf20Sopenharmony_ci	iwlagn_dev_txfifo_flush(priv);
20458c2ecf20Sopenharmony_ci
20468c2ecf20Sopenharmony_ci	return count;
20478c2ecf20Sopenharmony_ci}
20488c2ecf20Sopenharmony_ci
20498c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
20508c2ecf20Sopenharmony_ci					char __user *user_buf,
20518c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
20528c2ecf20Sopenharmony_ci
20538c2ecf20Sopenharmony_ci	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
20548c2ecf20Sopenharmony_ci	int pos = 0;
20558c2ecf20Sopenharmony_ci	char buf[200];
20568c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
20578c2ecf20Sopenharmony_ci
20588c2ecf20Sopenharmony_ci	if (!priv->bt_enable_flag) {
20598c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
20608c2ecf20Sopenharmony_ci		return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
20618c2ecf20Sopenharmony_ci	}
20628c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
20638c2ecf20Sopenharmony_ci		priv->bt_enable_flag);
20648c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
20658c2ecf20Sopenharmony_ci		priv->bt_full_concurrent ? "full concurrency" : "3-wire");
20668c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
20678c2ecf20Sopenharmony_ci			 "last traffic notif: %d\n",
20688c2ecf20Sopenharmony_ci		priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
20698c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
20708c2ecf20Sopenharmony_ci			 "kill_ack_mask: %x, kill_cts_mask: %x\n",
20718c2ecf20Sopenharmony_ci		priv->bt_ch_announce, priv->kill_ack_mask,
20728c2ecf20Sopenharmony_ci		priv->kill_cts_mask);
20738c2ecf20Sopenharmony_ci
20748c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
20758c2ecf20Sopenharmony_ci	switch (priv->bt_traffic_load) {
20768c2ecf20Sopenharmony_ci	case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
20778c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
20788c2ecf20Sopenharmony_ci		break;
20798c2ecf20Sopenharmony_ci	case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
20808c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "High\n");
20818c2ecf20Sopenharmony_ci		break;
20828c2ecf20Sopenharmony_ci	case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
20838c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
20848c2ecf20Sopenharmony_ci		break;
20858c2ecf20Sopenharmony_ci	case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
20868c2ecf20Sopenharmony_ci	default:
20878c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "None\n");
20888c2ecf20Sopenharmony_ci		break;
20898c2ecf20Sopenharmony_ci	}
20908c2ecf20Sopenharmony_ci
20918c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
20928c2ecf20Sopenharmony_ci}
20938c2ecf20Sopenharmony_ci
20948c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
20958c2ecf20Sopenharmony_ci					char __user *user_buf,
20968c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
20978c2ecf20Sopenharmony_ci{
20988c2ecf20Sopenharmony_ci	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
20998c2ecf20Sopenharmony_ci
21008c2ecf20Sopenharmony_ci	int pos = 0;
21018c2ecf20Sopenharmony_ci	char buf[40];
21028c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
21038c2ecf20Sopenharmony_ci
21048c2ecf20Sopenharmony_ci	if (priv->cfg->ht_params)
21058c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos,
21068c2ecf20Sopenharmony_ci			 "use %s for aggregation\n",
21078c2ecf20Sopenharmony_ci			 (priv->hw_params.use_rts_for_aggregation) ?
21088c2ecf20Sopenharmony_ci				"rts/cts" : "cts-to-self");
21098c2ecf20Sopenharmony_ci	else
21108c2ecf20Sopenharmony_ci		pos += scnprintf(buf + pos, bufsz - pos, "N/A");
21118c2ecf20Sopenharmony_ci
21128c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
21138c2ecf20Sopenharmony_ci}
21148c2ecf20Sopenharmony_ci
21158c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
21168c2ecf20Sopenharmony_ci					const char __user *user_buf,
21178c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos) {
21188c2ecf20Sopenharmony_ci
21198c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
21208c2ecf20Sopenharmony_ci	char buf[8];
21218c2ecf20Sopenharmony_ci	int buf_size;
21228c2ecf20Sopenharmony_ci	int rts;
21238c2ecf20Sopenharmony_ci
21248c2ecf20Sopenharmony_ci	if (!priv->cfg->ht_params)
21258c2ecf20Sopenharmony_ci		return -EINVAL;
21268c2ecf20Sopenharmony_ci
21278c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
21288c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
21298c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
21308c2ecf20Sopenharmony_ci		return -EFAULT;
21318c2ecf20Sopenharmony_ci	if (sscanf(buf, "%d", &rts) != 1)
21328c2ecf20Sopenharmony_ci		return -EINVAL;
21338c2ecf20Sopenharmony_ci	if (rts)
21348c2ecf20Sopenharmony_ci		priv->hw_params.use_rts_for_aggregation = true;
21358c2ecf20Sopenharmony_ci	else
21368c2ecf20Sopenharmony_ci		priv->hw_params.use_rts_for_aggregation = false;
21378c2ecf20Sopenharmony_ci	return count;
21388c2ecf20Sopenharmony_ci}
21398c2ecf20Sopenharmony_ci
21408c2ecf20Sopenharmony_cistatic int iwl_cmd_echo_test(struct iwl_priv *priv)
21418c2ecf20Sopenharmony_ci{
21428c2ecf20Sopenharmony_ci	int ret;
21438c2ecf20Sopenharmony_ci	struct iwl_host_cmd cmd = {
21448c2ecf20Sopenharmony_ci		.id = REPLY_ECHO,
21458c2ecf20Sopenharmony_ci		.len = { 0 },
21468c2ecf20Sopenharmony_ci	};
21478c2ecf20Sopenharmony_ci
21488c2ecf20Sopenharmony_ci	ret = iwl_dvm_send_cmd(priv, &cmd);
21498c2ecf20Sopenharmony_ci	if (ret)
21508c2ecf20Sopenharmony_ci		IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
21518c2ecf20Sopenharmony_ci	else
21528c2ecf20Sopenharmony_ci		IWL_DEBUG_INFO(priv, "echo testing pass\n");
21538c2ecf20Sopenharmony_ci	return ret;
21548c2ecf20Sopenharmony_ci}
21558c2ecf20Sopenharmony_ci
21568c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_echo_test_write(struct file *file,
21578c2ecf20Sopenharmony_ci					const char __user *user_buf,
21588c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
21598c2ecf20Sopenharmony_ci{
21608c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
21618c2ecf20Sopenharmony_ci	char buf[8];
21628c2ecf20Sopenharmony_ci	int buf_size;
21638c2ecf20Sopenharmony_ci
21648c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
21658c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
21668c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
21678c2ecf20Sopenharmony_ci		return -EFAULT;
21688c2ecf20Sopenharmony_ci
21698c2ecf20Sopenharmony_ci	iwl_cmd_echo_test(priv);
21708c2ecf20Sopenharmony_ci	return count;
21718c2ecf20Sopenharmony_ci}
21728c2ecf20Sopenharmony_ci
21738c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
21748c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_log_event_read(struct file *file,
21758c2ecf20Sopenharmony_ci					 char __user *user_buf,
21768c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
21778c2ecf20Sopenharmony_ci{
21788c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
21798c2ecf20Sopenharmony_ci	char *buf = NULL;
21808c2ecf20Sopenharmony_ci	ssize_t ret;
21818c2ecf20Sopenharmony_ci
21828c2ecf20Sopenharmony_ci	ret = iwl_dump_nic_event_log(priv, true, &buf);
21838c2ecf20Sopenharmony_ci	if (ret > 0)
21848c2ecf20Sopenharmony_ci		ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
21858c2ecf20Sopenharmony_ci	kfree(buf);
21868c2ecf20Sopenharmony_ci	return ret;
21878c2ecf20Sopenharmony_ci}
21888c2ecf20Sopenharmony_ci
21898c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_log_event_write(struct file *file,
21908c2ecf20Sopenharmony_ci					const char __user *user_buf,
21918c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)
21928c2ecf20Sopenharmony_ci{
21938c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
21948c2ecf20Sopenharmony_ci	u32 event_log_flag;
21958c2ecf20Sopenharmony_ci	char buf[8];
21968c2ecf20Sopenharmony_ci	int buf_size;
21978c2ecf20Sopenharmony_ci
21988c2ecf20Sopenharmony_ci	/* check that the interface is up */
21998c2ecf20Sopenharmony_ci	if (!iwl_is_ready(priv))
22008c2ecf20Sopenharmony_ci		return -EAGAIN;
22018c2ecf20Sopenharmony_ci
22028c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
22038c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) -  1);
22048c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
22058c2ecf20Sopenharmony_ci		return -EFAULT;
22068c2ecf20Sopenharmony_ci	if (sscanf(buf, "%u", &event_log_flag) != 1)
22078c2ecf20Sopenharmony_ci		return -EFAULT;
22088c2ecf20Sopenharmony_ci	if (event_log_flag == 1)
22098c2ecf20Sopenharmony_ci		iwl_dump_nic_event_log(priv, true, NULL);
22108c2ecf20Sopenharmony_ci
22118c2ecf20Sopenharmony_ci	return count;
22128c2ecf20Sopenharmony_ci}
22138c2ecf20Sopenharmony_ci#endif
22148c2ecf20Sopenharmony_ci
22158c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_calib_disabled_read(struct file *file,
22168c2ecf20Sopenharmony_ci					 char __user *user_buf,
22178c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)
22188c2ecf20Sopenharmony_ci{
22198c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
22208c2ecf20Sopenharmony_ci	char buf[120];
22218c2ecf20Sopenharmony_ci	int pos = 0;
22228c2ecf20Sopenharmony_ci	const size_t bufsz = sizeof(buf);
22238c2ecf20Sopenharmony_ci
22248c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
22258c2ecf20Sopenharmony_ci			 "Sensitivity calibrations %s\n",
22268c2ecf20Sopenharmony_ci			 (priv->calib_disabled &
22278c2ecf20Sopenharmony_ci					IWL_SENSITIVITY_CALIB_DISABLED) ?
22288c2ecf20Sopenharmony_ci			 "DISABLED" : "ENABLED");
22298c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
22308c2ecf20Sopenharmony_ci			 "Chain noise calibrations %s\n",
22318c2ecf20Sopenharmony_ci			 (priv->calib_disabled &
22328c2ecf20Sopenharmony_ci					IWL_CHAIN_NOISE_CALIB_DISABLED) ?
22338c2ecf20Sopenharmony_ci			 "DISABLED" : "ENABLED");
22348c2ecf20Sopenharmony_ci	pos += scnprintf(buf + pos, bufsz - pos,
22358c2ecf20Sopenharmony_ci			 "Tx power calibrations %s\n",
22368c2ecf20Sopenharmony_ci			 (priv->calib_disabled &
22378c2ecf20Sopenharmony_ci					IWL_TX_POWER_CALIB_DISABLED) ?
22388c2ecf20Sopenharmony_ci			 "DISABLED" : "ENABLED");
22398c2ecf20Sopenharmony_ci
22408c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
22418c2ecf20Sopenharmony_ci}
22428c2ecf20Sopenharmony_ci
22438c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
22448c2ecf20Sopenharmony_ci					      const char __user *user_buf,
22458c2ecf20Sopenharmony_ci					      size_t count, loff_t *ppos)
22468c2ecf20Sopenharmony_ci{
22478c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
22488c2ecf20Sopenharmony_ci	char buf[8];
22498c2ecf20Sopenharmony_ci	u32 calib_disabled;
22508c2ecf20Sopenharmony_ci	int buf_size;
22518c2ecf20Sopenharmony_ci
22528c2ecf20Sopenharmony_ci	memset(buf, 0, sizeof(buf));
22538c2ecf20Sopenharmony_ci	buf_size = min(count, sizeof(buf) - 1);
22548c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, buf_size))
22558c2ecf20Sopenharmony_ci		return -EFAULT;
22568c2ecf20Sopenharmony_ci	if (sscanf(buf, "%x", &calib_disabled) != 1)
22578c2ecf20Sopenharmony_ci		return -EFAULT;
22588c2ecf20Sopenharmony_ci
22598c2ecf20Sopenharmony_ci	priv->calib_disabled = calib_disabled;
22608c2ecf20Sopenharmony_ci
22618c2ecf20Sopenharmony_ci	return count;
22628c2ecf20Sopenharmony_ci}
22638c2ecf20Sopenharmony_ci
22648c2ecf20Sopenharmony_cistatic ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
22658c2ecf20Sopenharmony_ci					  const char __user *user_buf,
22668c2ecf20Sopenharmony_ci					  size_t count, loff_t *ppos)
22678c2ecf20Sopenharmony_ci{
22688c2ecf20Sopenharmony_ci	struct iwl_priv *priv = file->private_data;
22698c2ecf20Sopenharmony_ci	bool fw_restart = iwlwifi_mod_params.fw_restart;
22708c2ecf20Sopenharmony_ci	int __maybe_unused ret;
22718c2ecf20Sopenharmony_ci
22728c2ecf20Sopenharmony_ci	iwlwifi_mod_params.fw_restart = true;
22738c2ecf20Sopenharmony_ci
22748c2ecf20Sopenharmony_ci	mutex_lock(&priv->mutex);
22758c2ecf20Sopenharmony_ci
22768c2ecf20Sopenharmony_ci	/* take the return value to make compiler happy - it will fail anyway */
22778c2ecf20Sopenharmony_ci	ret = iwl_dvm_send_cmd_pdu(priv, REPLY_ERROR, 0, 0, NULL);
22788c2ecf20Sopenharmony_ci
22798c2ecf20Sopenharmony_ci	mutex_unlock(&priv->mutex);
22808c2ecf20Sopenharmony_ci
22818c2ecf20Sopenharmony_ci	iwlwifi_mod_params.fw_restart = fw_restart;
22828c2ecf20Sopenharmony_ci
22838c2ecf20Sopenharmony_ci	return count;
22848c2ecf20Sopenharmony_ci}
22858c2ecf20Sopenharmony_ci
22868c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_rx_stats);
22878c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_tx_stats);
22888c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_general_stats);
22898c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(sensitivity);
22908c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(chain_noise);
22918c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(power_save_status);
22928c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
22938c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
22948c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
22958c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
22968c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(rf_reset);
22978c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(rxon_flags);
22988c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(rxon_filter_flags);
22998c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(txfifo_flush);
23008c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(ucode_bt_stats);
23018c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(bt_traffic);
23028c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
23038c2ecf20Sopenharmony_ciDEBUGFS_READ_FILE_OPS(reply_tx_error);
23048c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(echo_test);
23058c2ecf20Sopenharmony_ciDEBUGFS_WRITE_FILE_OPS(fw_restart);
23068c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
23078c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(log_event);
23088c2ecf20Sopenharmony_ci#endif
23098c2ecf20Sopenharmony_ciDEBUGFS_READ_WRITE_FILE_OPS(calib_disabled);
23108c2ecf20Sopenharmony_ci
23118c2ecf20Sopenharmony_ci/*
23128c2ecf20Sopenharmony_ci * Create the debugfs files and directories
23138c2ecf20Sopenharmony_ci *
23148c2ecf20Sopenharmony_ci */
23158c2ecf20Sopenharmony_civoid iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir)
23168c2ecf20Sopenharmony_ci{
23178c2ecf20Sopenharmony_ci	struct dentry *dir_data, *dir_rf, *dir_debug;
23188c2ecf20Sopenharmony_ci
23198c2ecf20Sopenharmony_ci	priv->debugfs_dir = dbgfs_dir;
23208c2ecf20Sopenharmony_ci
23218c2ecf20Sopenharmony_ci	dir_data = debugfs_create_dir("data", dbgfs_dir);
23228c2ecf20Sopenharmony_ci	dir_rf = debugfs_create_dir("rf", dbgfs_dir);
23238c2ecf20Sopenharmony_ci	dir_debug = debugfs_create_dir("debug", dbgfs_dir);
23248c2ecf20Sopenharmony_ci
23258c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(nvm, dir_data, 0400);
23268c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(sram, dir_data, 0600);
23278c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(wowlan_sram, dir_data, 0400);
23288c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(stations, dir_data, 0400);
23298c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(channels, dir_data, 0400);
23308c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(status, dir_data, 0400);
23318c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rx_handlers, dir_data, 0600);
23328c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(qos, dir_data, 0400);
23338c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(sleep_level_override, dir_data, 0600);
23348c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(current_sleep_command, dir_data, 0400);
23358c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(thermal_throttling, dir_data, 0400);
23368c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(disable_ht40, dir_data, 0600);
23378c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(temperature, dir_data, 0400);
23388c2ecf20Sopenharmony_ci
23398c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(power_save_status, dir_debug, 0400);
23408c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, 0200);
23418c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(missed_beacon, dir_debug, 0200);
23428c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(plcp_delta, dir_debug, 0600);
23438c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rf_reset, dir_debug, 0600);
23448c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, 0400);
23458c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, 0400);
23468c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, 0400);
23478c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, 0200);
23488c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(protection_mode, dir_debug, 0600);
23498c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(sensitivity, dir_debug, 0400);
23508c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(chain_noise, dir_debug, 0400);
23518c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, 0600);
23528c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, 0400);
23538c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, 0400);
23548c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rxon_flags, dir_debug, 0200);
23558c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, 0200);
23568c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(echo_test, dir_debug, 0200);
23578c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(fw_restart, dir_debug, 0200);
23588c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
23598c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(log_event, dir_debug, 0600);
23608c2ecf20Sopenharmony_ci#endif
23618c2ecf20Sopenharmony_ci
23628c2ecf20Sopenharmony_ci	if (iwl_advanced_bt_coexist(priv))
23638c2ecf20Sopenharmony_ci		DEBUGFS_ADD_FILE(bt_traffic, dir_debug, 0400);
23648c2ecf20Sopenharmony_ci
23658c2ecf20Sopenharmony_ci	/* Calibrations disabled/enabled status*/
23668c2ecf20Sopenharmony_ci	DEBUGFS_ADD_FILE(calib_disabled, dir_rf, 0600);
23678c2ecf20Sopenharmony_ci
23688c2ecf20Sopenharmony_ci	/*
23698c2ecf20Sopenharmony_ci	 * Create a symlink with mac80211. This is not very robust, as it does
23708c2ecf20Sopenharmony_ci	 * not remove the symlink created. The implicit assumption is that
23718c2ecf20Sopenharmony_ci	 * when the opmode exits, mac80211 will also exit, and will remove
23728c2ecf20Sopenharmony_ci	 * this symlink as part of its cleanup.
23738c2ecf20Sopenharmony_ci	 */
23748c2ecf20Sopenharmony_ci	if (priv->mac80211_registered) {
23758c2ecf20Sopenharmony_ci		char buf[100];
23768c2ecf20Sopenharmony_ci		struct dentry *mac80211_dir, *dev_dir;
23778c2ecf20Sopenharmony_ci
23788c2ecf20Sopenharmony_ci		dev_dir = dbgfs_dir->d_parent;
23798c2ecf20Sopenharmony_ci		mac80211_dir = priv->hw->wiphy->debugfsdir;
23808c2ecf20Sopenharmony_ci
23818c2ecf20Sopenharmony_ci		snprintf(buf, 100, "../../%pd2", dev_dir);
23828c2ecf20Sopenharmony_ci
23838c2ecf20Sopenharmony_ci		debugfs_create_symlink("iwlwifi", mac80211_dir, buf);
23848c2ecf20Sopenharmony_ci	}
23858c2ecf20Sopenharmony_ci}
2386