18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2004-2011 Atheros Communications Inc.
38c2ecf20Sopenharmony_ci * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
68c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
78c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
108c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
118c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
128c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
138c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
148c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
158c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include "core.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
218c2ecf20Sopenharmony_ci#include <linux/fs.h>
228c2ecf20Sopenharmony_ci#include <linux/vmalloc.h>
238c2ecf20Sopenharmony_ci#include <linux/export.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include "debug.h"
268c2ecf20Sopenharmony_ci#include "target.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistruct ath6kl_fwlog_slot {
298c2ecf20Sopenharmony_ci	__le32 timestamp;
308c2ecf20Sopenharmony_ci	__le32 length;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	/* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
338c2ecf20Sopenharmony_ci	u8 payload[];
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define ATH6KL_FWLOG_MAX_ENTRIES 20
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define ATH6KL_FWLOG_VALID_MASK 0x1ffff
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_civoid ath6kl_printk(const char *level, const char *fmt, ...)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	struct va_format vaf;
438c2ecf20Sopenharmony_ci	va_list args;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	va_start(args, fmt);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	vaf.fmt = fmt;
488c2ecf20Sopenharmony_ci	vaf.va = &args;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	printk("%sath6kl: %pV", level, &vaf);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	va_end(args);
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_printk);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_civoid ath6kl_info(const char *fmt, ...)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	struct va_format vaf = {
598c2ecf20Sopenharmony_ci		.fmt = fmt,
608c2ecf20Sopenharmony_ci	};
618c2ecf20Sopenharmony_ci	va_list args;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	va_start(args, fmt);
648c2ecf20Sopenharmony_ci	vaf.va = &args;
658c2ecf20Sopenharmony_ci	ath6kl_printk(KERN_INFO, "%pV", &vaf);
668c2ecf20Sopenharmony_ci	trace_ath6kl_log_info(&vaf);
678c2ecf20Sopenharmony_ci	va_end(args);
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_info);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_civoid ath6kl_err(const char *fmt, ...)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	struct va_format vaf = {
748c2ecf20Sopenharmony_ci		.fmt = fmt,
758c2ecf20Sopenharmony_ci	};
768c2ecf20Sopenharmony_ci	va_list args;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	va_start(args, fmt);
798c2ecf20Sopenharmony_ci	vaf.va = &args;
808c2ecf20Sopenharmony_ci	ath6kl_printk(KERN_ERR, "%pV", &vaf);
818c2ecf20Sopenharmony_ci	trace_ath6kl_log_err(&vaf);
828c2ecf20Sopenharmony_ci	va_end(args);
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_err);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_civoid ath6kl_warn(const char *fmt, ...)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	struct va_format vaf = {
898c2ecf20Sopenharmony_ci		.fmt = fmt,
908c2ecf20Sopenharmony_ci	};
918c2ecf20Sopenharmony_ci	va_list args;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	va_start(args, fmt);
948c2ecf20Sopenharmony_ci	vaf.va = &args;
958c2ecf20Sopenharmony_ci	ath6kl_printk(KERN_WARNING, "%pV", &vaf);
968c2ecf20Sopenharmony_ci	trace_ath6kl_log_warn(&vaf);
978c2ecf20Sopenharmony_ci	va_end(args);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_warn);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciint ath6kl_read_tgt_stats(struct ath6kl *ar, struct ath6kl_vif *vif)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	long left;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	if (down_interruptible(&ar->sem))
1068c2ecf20Sopenharmony_ci		return -EBUSY;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	set_bit(STATS_UPDATE_PEND, &vif->flags);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) {
1118c2ecf20Sopenharmony_ci		up(&ar->sem);
1128c2ecf20Sopenharmony_ci		return -EIO;
1138c2ecf20Sopenharmony_ci	}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	left = wait_event_interruptible_timeout(ar->event_wq,
1168c2ecf20Sopenharmony_ci						!test_bit(STATS_UPDATE_PEND,
1178c2ecf20Sopenharmony_ci						&vif->flags), WMI_TIMEOUT);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	up(&ar->sem);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	if (left <= 0)
1228c2ecf20Sopenharmony_ci		return -ETIMEDOUT;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	return 0;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_read_tgt_stats);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH6KL_DEBUG
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_civoid ath6kl_dbg(enum ATH6K_DEBUG_MASK mask, const char *fmt, ...)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	struct va_format vaf;
1338c2ecf20Sopenharmony_ci	va_list args;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	va_start(args, fmt);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	vaf.fmt = fmt;
1388c2ecf20Sopenharmony_ci	vaf.va = &args;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	if (debug_mask & mask)
1418c2ecf20Sopenharmony_ci		ath6kl_printk(KERN_DEBUG, "%pV", &vaf);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	trace_ath6kl_log_dbg(mask, &vaf);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	va_end(args);
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_dbg);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_civoid ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
1508c2ecf20Sopenharmony_ci		     const char *msg, const char *prefix,
1518c2ecf20Sopenharmony_ci		     const void *buf, size_t len)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	if (debug_mask & mask) {
1548c2ecf20Sopenharmony_ci		if (msg)
1558c2ecf20Sopenharmony_ci			ath6kl_dbg(mask, "%s\n", msg);
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci		print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len);
1588c2ecf20Sopenharmony_ci	}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	/* tracing code doesn't like null strings :/ */
1618c2ecf20Sopenharmony_ci	trace_ath6kl_log_dbg_dump(msg ? msg : "", prefix ? prefix : "",
1628c2ecf20Sopenharmony_ci				  buf, len);
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath6kl_dbg_dump);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define REG_OUTPUT_LEN_PER_LINE	25
1678c2ecf20Sopenharmony_ci#define REGTYPE_STR_LEN		100
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistruct ath6kl_diag_reg_info {
1708c2ecf20Sopenharmony_ci	u32 reg_start;
1718c2ecf20Sopenharmony_ci	u32 reg_end;
1728c2ecf20Sopenharmony_ci	const char *reg_info;
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic const struct ath6kl_diag_reg_info diag_reg[] = {
1768c2ecf20Sopenharmony_ci	{ 0x20000, 0x200fc, "General DMA and Rx registers" },
1778c2ecf20Sopenharmony_ci	{ 0x28000, 0x28900, "MAC PCU register & keycache" },
1788c2ecf20Sopenharmony_ci	{ 0x20800, 0x20a40, "QCU" },
1798c2ecf20Sopenharmony_ci	{ 0x21000, 0x212f0, "DCU" },
1808c2ecf20Sopenharmony_ci	{ 0x4000,  0x42e4, "RTC" },
1818c2ecf20Sopenharmony_ci	{ 0x540000, 0x540000 + (256 * 1024), "RAM" },
1828c2ecf20Sopenharmony_ci	{ 0x29800, 0x2B210, "Base Band" },
1838c2ecf20Sopenharmony_ci	{ 0x1C000, 0x1C748, "Analog" },
1848c2ecf20Sopenharmony_ci};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_civoid ath6kl_dump_registers(struct ath6kl_device *dev,
1878c2ecf20Sopenharmony_ci			   struct ath6kl_irq_proc_registers *irq_proc_reg,
1888c2ecf20Sopenharmony_ci			   struct ath6kl_irq_enable_reg *irq_enable_reg)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_IRQ, ("<------- Register Table -------->\n"));
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	if (irq_proc_reg != NULL) {
1938c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
1948c2ecf20Sopenharmony_ci			   "Host Int status:           0x%x\n",
1958c2ecf20Sopenharmony_ci			   irq_proc_reg->host_int_status);
1968c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
1978c2ecf20Sopenharmony_ci			   "CPU Int status:            0x%x\n",
1988c2ecf20Sopenharmony_ci			   irq_proc_reg->cpu_int_status);
1998c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2008c2ecf20Sopenharmony_ci			   "Error Int status:          0x%x\n",
2018c2ecf20Sopenharmony_ci			   irq_proc_reg->error_int_status);
2028c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2038c2ecf20Sopenharmony_ci			   "Counter Int status:        0x%x\n",
2048c2ecf20Sopenharmony_ci			   irq_proc_reg->counter_int_status);
2058c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2068c2ecf20Sopenharmony_ci			   "Mbox Frame:                0x%x\n",
2078c2ecf20Sopenharmony_ci			   irq_proc_reg->mbox_frame);
2088c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2098c2ecf20Sopenharmony_ci			   "Rx Lookahead Valid:        0x%x\n",
2108c2ecf20Sopenharmony_ci			   irq_proc_reg->rx_lkahd_valid);
2118c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2128c2ecf20Sopenharmony_ci			   "Rx Lookahead 0:            0x%x\n",
2138c2ecf20Sopenharmony_ci			   irq_proc_reg->rx_lkahd[0]);
2148c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2158c2ecf20Sopenharmony_ci			   "Rx Lookahead 1:            0x%x\n",
2168c2ecf20Sopenharmony_ci			   irq_proc_reg->rx_lkahd[1]);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci		if (dev->ar->mbox_info.gmbox_addr != 0) {
2198c2ecf20Sopenharmony_ci			/*
2208c2ecf20Sopenharmony_ci			 * If the target supports GMBOX hardware, dump some
2218c2ecf20Sopenharmony_ci			 * additional state.
2228c2ecf20Sopenharmony_ci			 */
2238c2ecf20Sopenharmony_ci			ath6kl_dbg(ATH6KL_DBG_IRQ,
2248c2ecf20Sopenharmony_ci				   "GMBOX Host Int status 2:   0x%x\n",
2258c2ecf20Sopenharmony_ci				   irq_proc_reg->host_int_status2);
2268c2ecf20Sopenharmony_ci			ath6kl_dbg(ATH6KL_DBG_IRQ,
2278c2ecf20Sopenharmony_ci				   "GMBOX RX Avail:            0x%x\n",
2288c2ecf20Sopenharmony_ci				   irq_proc_reg->gmbox_rx_avail);
2298c2ecf20Sopenharmony_ci			ath6kl_dbg(ATH6KL_DBG_IRQ,
2308c2ecf20Sopenharmony_ci				   "GMBOX lookahead alias 0:   0x%x\n",
2318c2ecf20Sopenharmony_ci				   irq_proc_reg->rx_gmbox_lkahd_alias[0]);
2328c2ecf20Sopenharmony_ci			ath6kl_dbg(ATH6KL_DBG_IRQ,
2338c2ecf20Sopenharmony_ci				   "GMBOX lookahead alias 1:   0x%x\n",
2348c2ecf20Sopenharmony_ci				   irq_proc_reg->rx_gmbox_lkahd_alias[1]);
2358c2ecf20Sopenharmony_ci		}
2368c2ecf20Sopenharmony_ci	}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	if (irq_enable_reg != NULL) {
2398c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ,
2408c2ecf20Sopenharmony_ci			   "Int status Enable:         0x%x\n",
2418c2ecf20Sopenharmony_ci			   irq_enable_reg->int_status_en);
2428c2ecf20Sopenharmony_ci		ath6kl_dbg(ATH6KL_DBG_IRQ, "Counter Int status Enable: 0x%x\n",
2438c2ecf20Sopenharmony_ci			   irq_enable_reg->cntr_int_status_en);
2448c2ecf20Sopenharmony_ci	}
2458c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_IRQ, "<------------------------------->\n");
2468c2ecf20Sopenharmony_ci}
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT,
2518c2ecf20Sopenharmony_ci		   "--- endpoint: %d  svc_id: 0x%X ---\n",
2528c2ecf20Sopenharmony_ci		   ep_dist->endpoint, ep_dist->svc_id);
2538c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " dist_flags     : 0x%X\n",
2548c2ecf20Sopenharmony_ci		   ep_dist->dist_flags);
2558c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_norm      : %d\n",
2568c2ecf20Sopenharmony_ci		   ep_dist->cred_norm);
2578c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_min       : %d\n",
2588c2ecf20Sopenharmony_ci		   ep_dist->cred_min);
2598c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " credits        : %d\n",
2608c2ecf20Sopenharmony_ci		   ep_dist->credits);
2618c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_assngd    : %d\n",
2628c2ecf20Sopenharmony_ci		   ep_dist->cred_assngd);
2638c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " seek_cred      : %d\n",
2648c2ecf20Sopenharmony_ci		   ep_dist->seek_cred);
2658c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_sz        : %d\n",
2668c2ecf20Sopenharmony_ci		   ep_dist->cred_sz);
2678c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_per_msg   : %d\n",
2688c2ecf20Sopenharmony_ci		   ep_dist->cred_per_msg);
2698c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_to_dist   : %d\n",
2708c2ecf20Sopenharmony_ci		   ep_dist->cred_to_dist);
2718c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT, " txq_depth      : %d\n",
2728c2ecf20Sopenharmony_ci		   get_queue_depth(&ep_dist->htc_ep->txq));
2738c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT,
2748c2ecf20Sopenharmony_ci		   "----------------------------------\n");
2758c2ecf20Sopenharmony_ci}
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci/* FIXME: move to htc.c */
2788c2ecf20Sopenharmony_civoid dump_cred_dist_stats(struct htc_target *target)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	struct htc_endpoint_credit_dist *ep_list;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	list_for_each_entry(ep_list, &target->cred_dist_list, list)
2838c2ecf20Sopenharmony_ci		dump_cred_dist(ep_list);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	ath6kl_dbg(ATH6KL_DBG_CREDIT,
2868c2ecf20Sopenharmony_ci		   "credit distribution total %d free %d\n",
2878c2ecf20Sopenharmony_ci		   target->credit_info->total_avail_credits,
2888c2ecf20Sopenharmony_ci		   target->credit_info->cur_free_credits);
2898c2ecf20Sopenharmony_ci}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_civoid ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
2928c2ecf20Sopenharmony_ci{
2938c2ecf20Sopenharmony_ci	switch (war) {
2948c2ecf20Sopenharmony_ci	case ATH6KL_WAR_INVALID_RATE:
2958c2ecf20Sopenharmony_ci		ar->debug.war_stats.invalid_rate++;
2968c2ecf20Sopenharmony_ci		break;
2978c2ecf20Sopenharmony_ci	}
2988c2ecf20Sopenharmony_ci}
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cistatic ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
3018c2ecf20Sopenharmony_ci				   size_t count, loff_t *ppos)
3028c2ecf20Sopenharmony_ci{
3038c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
3048c2ecf20Sopenharmony_ci	char *buf;
3058c2ecf20Sopenharmony_ci	unsigned int len = 0, buf_len = 1500;
3068c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	buf = kzalloc(buf_len, GFP_KERNEL);
3098c2ecf20Sopenharmony_ci	if (!buf)
3108c2ecf20Sopenharmony_ci		return -ENOMEM;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "\n");
3138c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n",
3148c2ecf20Sopenharmony_ci			 "Workaround stats");
3158c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
3168c2ecf20Sopenharmony_ci			 "=================");
3178c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
3188c2ecf20Sopenharmony_ci			 "Invalid rates", ar->debug.war_stats.invalid_rate);
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	if (WARN_ON(len > buf_len))
3218c2ecf20Sopenharmony_ci		len = buf_len;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	kfree(buf);
3268c2ecf20Sopenharmony_ci	return ret_cnt;
3278c2ecf20Sopenharmony_ci}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic const struct file_operations fops_war_stats = {
3308c2ecf20Sopenharmony_ci	.read = read_file_war_stats,
3318c2ecf20Sopenharmony_ci	.open = simple_open,
3328c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
3338c2ecf20Sopenharmony_ci	.llseek = default_llseek,
3348c2ecf20Sopenharmony_ci};
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_civoid ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	struct ath6kl_fwlog_slot *slot;
3398c2ecf20Sopenharmony_ci	struct sk_buff *skb;
3408c2ecf20Sopenharmony_ci	size_t slot_len;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
3438c2ecf20Sopenharmony_ci		return;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	slot_len = sizeof(*slot) + ATH6KL_FWLOG_PAYLOAD_SIZE;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	skb = alloc_skb(slot_len, GFP_KERNEL);
3488c2ecf20Sopenharmony_ci	if (!skb)
3498c2ecf20Sopenharmony_ci		return;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	slot = skb_put(skb, slot_len);
3528c2ecf20Sopenharmony_ci	slot->timestamp = cpu_to_le32(jiffies);
3538c2ecf20Sopenharmony_ci	slot->length = cpu_to_le32(len);
3548c2ecf20Sopenharmony_ci	memcpy(slot->payload, buf, len);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	/* Need to pad each record to fixed length ATH6KL_FWLOG_PAYLOAD_SIZE */
3578c2ecf20Sopenharmony_ci	memset(slot->payload + len, 0, ATH6KL_FWLOG_PAYLOAD_SIZE - len);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	spin_lock(&ar->debug.fwlog_queue.lock);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	__skb_queue_tail(&ar->debug.fwlog_queue, skb);
3628c2ecf20Sopenharmony_ci	complete(&ar->debug.fwlog_completion);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	/* drop oldest entries */
3658c2ecf20Sopenharmony_ci	while (skb_queue_len(&ar->debug.fwlog_queue) >
3668c2ecf20Sopenharmony_ci	       ATH6KL_FWLOG_MAX_ENTRIES) {
3678c2ecf20Sopenharmony_ci		skb = __skb_dequeue(&ar->debug.fwlog_queue);
3688c2ecf20Sopenharmony_ci		kfree_skb(skb);
3698c2ecf20Sopenharmony_ci	}
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	spin_unlock(&ar->debug.fwlog_queue.lock);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	return;
3748c2ecf20Sopenharmony_ci}
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistatic int ath6kl_fwlog_open(struct inode *inode, struct file *file)
3778c2ecf20Sopenharmony_ci{
3788c2ecf20Sopenharmony_ci	struct ath6kl *ar = inode->i_private;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	if (ar->debug.fwlog_open)
3818c2ecf20Sopenharmony_ci		return -EBUSY;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	ar->debug.fwlog_open = true;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	file->private_data = inode->i_private;
3868c2ecf20Sopenharmony_ci	return 0;
3878c2ecf20Sopenharmony_ci}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_cistatic int ath6kl_fwlog_release(struct inode *inode, struct file *file)
3908c2ecf20Sopenharmony_ci{
3918c2ecf20Sopenharmony_ci	struct ath6kl *ar = inode->i_private;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	ar->debug.fwlog_open = false;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	return 0;
3968c2ecf20Sopenharmony_ci}
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cistatic ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
3998c2ecf20Sopenharmony_ci				 size_t count, loff_t *ppos)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
4028c2ecf20Sopenharmony_ci	struct sk_buff *skb;
4038c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
4048c2ecf20Sopenharmony_ci	size_t len = 0;
4058c2ecf20Sopenharmony_ci	char *buf;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci	buf = vmalloc(count);
4088c2ecf20Sopenharmony_ci	if (!buf)
4098c2ecf20Sopenharmony_ci		return -ENOMEM;
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	/* read undelivered logs from firmware */
4128c2ecf20Sopenharmony_ci	ath6kl_read_fwlogs(ar);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	spin_lock(&ar->debug.fwlog_queue.lock);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
4178c2ecf20Sopenharmony_ci		if (skb->len > count - len) {
4188c2ecf20Sopenharmony_ci			/* not enough space, put skb back and leave */
4198c2ecf20Sopenharmony_ci			__skb_queue_head(&ar->debug.fwlog_queue, skb);
4208c2ecf20Sopenharmony_ci			break;
4218c2ecf20Sopenharmony_ci		}
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci		memcpy(buf + len, skb->data, skb->len);
4258c2ecf20Sopenharmony_ci		len += skb->len;
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci		kfree_skb(skb);
4288c2ecf20Sopenharmony_ci	}
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	spin_unlock(&ar->debug.fwlog_queue.lock);
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	/* FIXME: what to do if len == 0? */
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	vfree(buf);
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	return ret_cnt;
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_cistatic const struct file_operations fops_fwlog = {
4428c2ecf20Sopenharmony_ci	.open = ath6kl_fwlog_open,
4438c2ecf20Sopenharmony_ci	.release = ath6kl_fwlog_release,
4448c2ecf20Sopenharmony_ci	.read = ath6kl_fwlog_read,
4458c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
4468c2ecf20Sopenharmony_ci	.llseek = default_llseek,
4478c2ecf20Sopenharmony_ci};
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_cistatic ssize_t ath6kl_fwlog_block_read(struct file *file,
4508c2ecf20Sopenharmony_ci				       char __user *user_buf,
4518c2ecf20Sopenharmony_ci				       size_t count,
4528c2ecf20Sopenharmony_ci				       loff_t *ppos)
4538c2ecf20Sopenharmony_ci{
4548c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
4558c2ecf20Sopenharmony_ci	struct sk_buff *skb;
4568c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
4578c2ecf20Sopenharmony_ci	size_t len = 0, not_copied;
4588c2ecf20Sopenharmony_ci	char *buf;
4598c2ecf20Sopenharmony_ci	int ret;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	buf = vmalloc(count);
4628c2ecf20Sopenharmony_ci	if (!buf)
4638c2ecf20Sopenharmony_ci		return -ENOMEM;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	spin_lock(&ar->debug.fwlog_queue.lock);
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	if (skb_queue_len(&ar->debug.fwlog_queue) == 0) {
4688c2ecf20Sopenharmony_ci		/* we must init under queue lock */
4698c2ecf20Sopenharmony_ci		init_completion(&ar->debug.fwlog_completion);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci		spin_unlock(&ar->debug.fwlog_queue.lock);
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci		ret = wait_for_completion_interruptible(
4748c2ecf20Sopenharmony_ci			&ar->debug.fwlog_completion);
4758c2ecf20Sopenharmony_ci		if (ret == -ERESTARTSYS) {
4768c2ecf20Sopenharmony_ci			vfree(buf);
4778c2ecf20Sopenharmony_ci			return ret;
4788c2ecf20Sopenharmony_ci		}
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci		spin_lock(&ar->debug.fwlog_queue.lock);
4818c2ecf20Sopenharmony_ci	}
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
4848c2ecf20Sopenharmony_ci		if (skb->len > count - len) {
4858c2ecf20Sopenharmony_ci			/* not enough space, put skb back and leave */
4868c2ecf20Sopenharmony_ci			__skb_queue_head(&ar->debug.fwlog_queue, skb);
4878c2ecf20Sopenharmony_ci			break;
4888c2ecf20Sopenharmony_ci		}
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci		memcpy(buf + len, skb->data, skb->len);
4928c2ecf20Sopenharmony_ci		len += skb->len;
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci		kfree_skb(skb);
4958c2ecf20Sopenharmony_ci	}
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci	spin_unlock(&ar->debug.fwlog_queue.lock);
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci	/* FIXME: what to do if len == 0? */
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	not_copied = copy_to_user(user_buf, buf, len);
5028c2ecf20Sopenharmony_ci	if (not_copied != 0) {
5038c2ecf20Sopenharmony_ci		ret_cnt = -EFAULT;
5048c2ecf20Sopenharmony_ci		goto out;
5058c2ecf20Sopenharmony_ci	}
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci	*ppos = *ppos + len;
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	ret_cnt = len;
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ciout:
5128c2ecf20Sopenharmony_ci	vfree(buf);
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	return ret_cnt;
5158c2ecf20Sopenharmony_ci}
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_cistatic const struct file_operations fops_fwlog_block = {
5188c2ecf20Sopenharmony_ci	.open = ath6kl_fwlog_open,
5198c2ecf20Sopenharmony_ci	.release = ath6kl_fwlog_release,
5208c2ecf20Sopenharmony_ci	.read = ath6kl_fwlog_block_read,
5218c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
5228c2ecf20Sopenharmony_ci	.llseek = default_llseek,
5238c2ecf20Sopenharmony_ci};
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_cistatic ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
5268c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
5278c2ecf20Sopenharmony_ci{
5288c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
5298c2ecf20Sopenharmony_ci	char buf[16];
5308c2ecf20Sopenharmony_ci	int len;
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci	len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
5358c2ecf20Sopenharmony_ci}
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_cistatic ssize_t ath6kl_fwlog_mask_write(struct file *file,
5388c2ecf20Sopenharmony_ci				       const char __user *user_buf,
5398c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
5408c2ecf20Sopenharmony_ci{
5418c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
5428c2ecf20Sopenharmony_ci	int ret;
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci	ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
5458c2ecf20Sopenharmony_ci	if (ret)
5468c2ecf20Sopenharmony_ci		return ret;
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
5498c2ecf20Sopenharmony_ci						 ATH6KL_FWLOG_VALID_MASK,
5508c2ecf20Sopenharmony_ci						 ar->debug.fwlog_mask);
5518c2ecf20Sopenharmony_ci	if (ret)
5528c2ecf20Sopenharmony_ci		return ret;
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	return count;
5558c2ecf20Sopenharmony_ci}
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_cistatic const struct file_operations fops_fwlog_mask = {
5588c2ecf20Sopenharmony_ci	.open = simple_open,
5598c2ecf20Sopenharmony_ci	.read = ath6kl_fwlog_mask_read,
5608c2ecf20Sopenharmony_ci	.write = ath6kl_fwlog_mask_write,
5618c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
5628c2ecf20Sopenharmony_ci	.llseek = default_llseek,
5638c2ecf20Sopenharmony_ci};
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_cistatic ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
5668c2ecf20Sopenharmony_ci				   size_t count, loff_t *ppos)
5678c2ecf20Sopenharmony_ci{
5688c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
5698c2ecf20Sopenharmony_ci	struct ath6kl_vif *vif;
5708c2ecf20Sopenharmony_ci	struct target_stats *tgt_stats;
5718c2ecf20Sopenharmony_ci	char *buf;
5728c2ecf20Sopenharmony_ci	unsigned int len = 0, buf_len = 1500;
5738c2ecf20Sopenharmony_ci	int i;
5748c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
5758c2ecf20Sopenharmony_ci	int rv;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	vif = ath6kl_vif_first(ar);
5788c2ecf20Sopenharmony_ci	if (!vif)
5798c2ecf20Sopenharmony_ci		return -EIO;
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	buf = kzalloc(buf_len, GFP_KERNEL);
5828c2ecf20Sopenharmony_ci	if (!buf)
5838c2ecf20Sopenharmony_ci		return -ENOMEM;
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci	rv = ath6kl_read_tgt_stats(ar, vif);
5868c2ecf20Sopenharmony_ci	if (rv < 0) {
5878c2ecf20Sopenharmony_ci		kfree(buf);
5888c2ecf20Sopenharmony_ci		return rv;
5898c2ecf20Sopenharmony_ci	}
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	tgt_stats = &vif->target_stats;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "\n");
5948c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n",
5958c2ecf20Sopenharmony_ci			 "Target Tx stats");
5968c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
5978c2ecf20Sopenharmony_ci			 "=================");
5988c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
5998c2ecf20Sopenharmony_ci			 "Ucast packets", tgt_stats->tx_ucast_pkt);
6008c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6018c2ecf20Sopenharmony_ci			 "Bcast packets", tgt_stats->tx_bcast_pkt);
6028c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6038c2ecf20Sopenharmony_ci			 "Ucast byte", tgt_stats->tx_ucast_byte);
6048c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6058c2ecf20Sopenharmony_ci			 "Bcast byte", tgt_stats->tx_bcast_byte);
6068c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6078c2ecf20Sopenharmony_ci			 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
6088c2ecf20Sopenharmony_ci	for (i = 0; i < 4; i++)
6098c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buf_len - len,
6108c2ecf20Sopenharmony_ci				 "%18s %d %10llu\n", "PER on ac",
6118c2ecf20Sopenharmony_ci				 i, tgt_stats->tx_pkt_per_ac[i]);
6128c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6138c2ecf20Sopenharmony_ci			 "Error", tgt_stats->tx_err);
6148c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6158c2ecf20Sopenharmony_ci			 "Fail count", tgt_stats->tx_fail_cnt);
6168c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6178c2ecf20Sopenharmony_ci			 "Retry count", tgt_stats->tx_retry_cnt);
6188c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6198c2ecf20Sopenharmony_ci			 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
6208c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6218c2ecf20Sopenharmony_ci			 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
6228c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
6238c2ecf20Sopenharmony_ci			 "TKIP counter measure used",
6248c2ecf20Sopenharmony_ci			 tgt_stats->tkip_cnter_measures_invoked);
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n",
6278c2ecf20Sopenharmony_ci			 "Target Rx stats");
6288c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n",
6298c2ecf20Sopenharmony_ci			 "=================");
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6328c2ecf20Sopenharmony_ci			 "Ucast packets", tgt_stats->rx_ucast_pkt);
6338c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
6348c2ecf20Sopenharmony_ci			 "Ucast Rate", tgt_stats->rx_ucast_rate);
6358c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6368c2ecf20Sopenharmony_ci			 "Bcast packets", tgt_stats->rx_bcast_pkt);
6378c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6388c2ecf20Sopenharmony_ci			 "Ucast byte", tgt_stats->rx_ucast_byte);
6398c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6408c2ecf20Sopenharmony_ci			 "Bcast byte", tgt_stats->rx_bcast_byte);
6418c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6428c2ecf20Sopenharmony_ci			 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
6438c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6448c2ecf20Sopenharmony_ci			 "Error", tgt_stats->rx_err);
6458c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6468c2ecf20Sopenharmony_ci			 "CRC Err", tgt_stats->rx_crc_err);
6478c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6488c2ecf20Sopenharmony_ci			 "Key cache miss", tgt_stats->rx_key_cache_miss);
6498c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6508c2ecf20Sopenharmony_ci			 "Decrypt Err", tgt_stats->rx_decrypt_err);
6518c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6528c2ecf20Sopenharmony_ci			 "Duplicate frame", tgt_stats->rx_dupl_frame);
6538c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6548c2ecf20Sopenharmony_ci			 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
6558c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6568c2ecf20Sopenharmony_ci			 "TKIP format err", tgt_stats->tkip_fmt_err);
6578c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6588c2ecf20Sopenharmony_ci			 "CCMP format Err", tgt_stats->ccmp_fmt_err);
6598c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
6608c2ecf20Sopenharmony_ci			 "CCMP Replay Err", tgt_stats->ccmp_replays);
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n",
6638c2ecf20Sopenharmony_ci			 "Misc Target stats");
6648c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s\n",
6658c2ecf20Sopenharmony_ci			 "=================");
6668c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6678c2ecf20Sopenharmony_ci			 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
6688c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6698c2ecf20Sopenharmony_ci			 "Num Connects", tgt_stats->cs_connect_cnt);
6708c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6718c2ecf20Sopenharmony_ci			 "Num disconnects", tgt_stats->cs_discon_cnt);
6728c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
6738c2ecf20Sopenharmony_ci			 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
6748c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
6758c2ecf20Sopenharmony_ci			 "ARP pkt received", tgt_stats->arp_received);
6768c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
6778c2ecf20Sopenharmony_ci			 "ARP pkt matched", tgt_stats->arp_matched);
6788c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
6798c2ecf20Sopenharmony_ci			 "ARP pkt replied", tgt_stats->arp_replied);
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	if (len > buf_len)
6828c2ecf20Sopenharmony_ci		len = buf_len;
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	kfree(buf);
6878c2ecf20Sopenharmony_ci	return ret_cnt;
6888c2ecf20Sopenharmony_ci}
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_cistatic const struct file_operations fops_tgt_stats = {
6918c2ecf20Sopenharmony_ci	.read = read_file_tgt_stats,
6928c2ecf20Sopenharmony_ci	.open = simple_open,
6938c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
6948c2ecf20Sopenharmony_ci	.llseek = default_llseek,
6958c2ecf20Sopenharmony_ci};
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci#define print_credit_info(fmt_str, ep_list_field)		\
6988c2ecf20Sopenharmony_ci	(len += scnprintf(buf + len, buf_len - len, fmt_str,	\
6998c2ecf20Sopenharmony_ci			 ep_list->ep_list_field))
7008c2ecf20Sopenharmony_ci#define CREDIT_INFO_DISPLAY_STRING_LEN	200
7018c2ecf20Sopenharmony_ci#define CREDIT_INFO_LEN	128
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_cistatic ssize_t read_file_credit_dist_stats(struct file *file,
7048c2ecf20Sopenharmony_ci					   char __user *user_buf,
7058c2ecf20Sopenharmony_ci					   size_t count, loff_t *ppos)
7068c2ecf20Sopenharmony_ci{
7078c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
7088c2ecf20Sopenharmony_ci	struct htc_target *target = ar->htc_target;
7098c2ecf20Sopenharmony_ci	struct htc_endpoint_credit_dist *ep_list;
7108c2ecf20Sopenharmony_ci	char *buf;
7118c2ecf20Sopenharmony_ci	unsigned int buf_len, len = 0;
7128c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci	buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
7158c2ecf20Sopenharmony_ci		  get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
7168c2ecf20Sopenharmony_ci	buf = kzalloc(buf_len, GFP_KERNEL);
7178c2ecf20Sopenharmony_ci	if (!buf)
7188c2ecf20Sopenharmony_ci		return -ENOMEM;
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
7218c2ecf20Sopenharmony_ci			 "Total Avail Credits: ",
7228c2ecf20Sopenharmony_ci			 target->credit_info->total_avail_credits);
7238c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
7248c2ecf20Sopenharmony_ci			 "Free credits :",
7258c2ecf20Sopenharmony_ci			 target->credit_info->cur_free_credits);
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len,
7288c2ecf20Sopenharmony_ci			 " Epid  Flags    Cred_norm  Cred_min  Credits  Cred_assngd"
7298c2ecf20Sopenharmony_ci			 "  Seek_cred  Cred_sz  Cred_per_msg  Cred_to_dist"
7308c2ecf20Sopenharmony_ci			 "  qdepth\n");
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	list_for_each_entry(ep_list, &target->cred_dist_list, list) {
7338c2ecf20Sopenharmony_ci		print_credit_info("  %2d", endpoint);
7348c2ecf20Sopenharmony_ci		print_credit_info("%10x", dist_flags);
7358c2ecf20Sopenharmony_ci		print_credit_info("%8d", cred_norm);
7368c2ecf20Sopenharmony_ci		print_credit_info("%9d", cred_min);
7378c2ecf20Sopenharmony_ci		print_credit_info("%9d", credits);
7388c2ecf20Sopenharmony_ci		print_credit_info("%10d", cred_assngd);
7398c2ecf20Sopenharmony_ci		print_credit_info("%13d", seek_cred);
7408c2ecf20Sopenharmony_ci		print_credit_info("%12d", cred_sz);
7418c2ecf20Sopenharmony_ci		print_credit_info("%9d", cred_per_msg);
7428c2ecf20Sopenharmony_ci		print_credit_info("%14d", cred_to_dist);
7438c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buf_len - len, "%12d\n",
7448c2ecf20Sopenharmony_ci				 get_queue_depth(&ep_list->htc_ep->txq));
7458c2ecf20Sopenharmony_ci	}
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_ci	if (len > buf_len)
7488c2ecf20Sopenharmony_ci		len = buf_len;
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
7518c2ecf20Sopenharmony_ci	kfree(buf);
7528c2ecf20Sopenharmony_ci	return ret_cnt;
7538c2ecf20Sopenharmony_ci}
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_cistatic const struct file_operations fops_credit_dist_stats = {
7568c2ecf20Sopenharmony_ci	.read = read_file_credit_dist_stats,
7578c2ecf20Sopenharmony_ci	.open = simple_open,
7588c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
7598c2ecf20Sopenharmony_ci	.llseek = default_llseek,
7608c2ecf20Sopenharmony_ci};
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_cistatic unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
7638c2ecf20Sopenharmony_ci					unsigned int buf_len, unsigned int len,
7648c2ecf20Sopenharmony_ci					int offset, const char *name)
7658c2ecf20Sopenharmony_ci{
7668c2ecf20Sopenharmony_ci	int i;
7678c2ecf20Sopenharmony_ci	struct htc_endpoint_stats *ep_st;
7688c2ecf20Sopenharmony_ci	u32 *counter;
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "%s:", name);
7718c2ecf20Sopenharmony_ci	for (i = 0; i < ENDPOINT_MAX; i++) {
7728c2ecf20Sopenharmony_ci		ep_st = &target->endpoint[i].ep_st;
7738c2ecf20Sopenharmony_ci		counter = ((u32 *) ep_st) + (offset / 4);
7748c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buf_len - len, " %u", *counter);
7758c2ecf20Sopenharmony_ci	}
7768c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len, "\n");
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci	return len;
7798c2ecf20Sopenharmony_ci}
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_cistatic ssize_t ath6kl_endpoint_stats_read(struct file *file,
7828c2ecf20Sopenharmony_ci					  char __user *user_buf,
7838c2ecf20Sopenharmony_ci					  size_t count, loff_t *ppos)
7848c2ecf20Sopenharmony_ci{
7858c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
7868c2ecf20Sopenharmony_ci	struct htc_target *target = ar->htc_target;
7878c2ecf20Sopenharmony_ci	char *buf;
7888c2ecf20Sopenharmony_ci	unsigned int buf_len, len = 0;
7898c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
7928c2ecf20Sopenharmony_ci		(25 + ENDPOINT_MAX * 11);
7938c2ecf20Sopenharmony_ci	buf = kmalloc(buf_len, GFP_KERNEL);
7948c2ecf20Sopenharmony_ci	if (!buf)
7958c2ecf20Sopenharmony_ci		return -ENOMEM;
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci#define EPSTAT(name)							\
7988c2ecf20Sopenharmony_ci	do {								\
7998c2ecf20Sopenharmony_ci		len = print_endpoint_stat(target, buf, buf_len, len,	\
8008c2ecf20Sopenharmony_ci					  offsetof(struct htc_endpoint_stats, \
8018c2ecf20Sopenharmony_ci						   name),		\
8028c2ecf20Sopenharmony_ci					  #name);			\
8038c2ecf20Sopenharmony_ci	} while (0)
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	EPSTAT(cred_low_indicate);
8068c2ecf20Sopenharmony_ci	EPSTAT(tx_issued);
8078c2ecf20Sopenharmony_ci	EPSTAT(tx_pkt_bundled);
8088c2ecf20Sopenharmony_ci	EPSTAT(tx_bundles);
8098c2ecf20Sopenharmony_ci	EPSTAT(tx_dropped);
8108c2ecf20Sopenharmony_ci	EPSTAT(tx_cred_rpt);
8118c2ecf20Sopenharmony_ci	EPSTAT(cred_rpt_from_rx);
8128c2ecf20Sopenharmony_ci	EPSTAT(cred_rpt_from_other);
8138c2ecf20Sopenharmony_ci	EPSTAT(cred_rpt_ep0);
8148c2ecf20Sopenharmony_ci	EPSTAT(cred_from_rx);
8158c2ecf20Sopenharmony_ci	EPSTAT(cred_from_other);
8168c2ecf20Sopenharmony_ci	EPSTAT(cred_from_ep0);
8178c2ecf20Sopenharmony_ci	EPSTAT(cred_cosumd);
8188c2ecf20Sopenharmony_ci	EPSTAT(cred_retnd);
8198c2ecf20Sopenharmony_ci	EPSTAT(rx_pkts);
8208c2ecf20Sopenharmony_ci	EPSTAT(rx_lkahds);
8218c2ecf20Sopenharmony_ci	EPSTAT(rx_bundl);
8228c2ecf20Sopenharmony_ci	EPSTAT(rx_bundle_lkahd);
8238c2ecf20Sopenharmony_ci	EPSTAT(rx_bundle_from_hdr);
8248c2ecf20Sopenharmony_ci	EPSTAT(rx_alloc_thresh_hit);
8258c2ecf20Sopenharmony_ci	EPSTAT(rxalloc_thresh_byte);
8268c2ecf20Sopenharmony_ci#undef EPSTAT
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci	if (len > buf_len)
8298c2ecf20Sopenharmony_ci		len = buf_len;
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
8328c2ecf20Sopenharmony_ci	kfree(buf);
8338c2ecf20Sopenharmony_ci	return ret_cnt;
8348c2ecf20Sopenharmony_ci}
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_cistatic ssize_t ath6kl_endpoint_stats_write(struct file *file,
8378c2ecf20Sopenharmony_ci					   const char __user *user_buf,
8388c2ecf20Sopenharmony_ci					   size_t count, loff_t *ppos)
8398c2ecf20Sopenharmony_ci{
8408c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
8418c2ecf20Sopenharmony_ci	struct htc_target *target = ar->htc_target;
8428c2ecf20Sopenharmony_ci	int ret, i;
8438c2ecf20Sopenharmony_ci	u32 val;
8448c2ecf20Sopenharmony_ci	struct htc_endpoint_stats *ep_st;
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	ret = kstrtou32_from_user(user_buf, count, 0, &val);
8478c2ecf20Sopenharmony_ci	if (ret)
8488c2ecf20Sopenharmony_ci		return ret;
8498c2ecf20Sopenharmony_ci	if (val == 0) {
8508c2ecf20Sopenharmony_ci		for (i = 0; i < ENDPOINT_MAX; i++) {
8518c2ecf20Sopenharmony_ci			ep_st = &target->endpoint[i].ep_st;
8528c2ecf20Sopenharmony_ci			memset(ep_st, 0, sizeof(*ep_st));
8538c2ecf20Sopenharmony_ci		}
8548c2ecf20Sopenharmony_ci	}
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ci	return count;
8578c2ecf20Sopenharmony_ci}
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_cistatic const struct file_operations fops_endpoint_stats = {
8608c2ecf20Sopenharmony_ci	.open = simple_open,
8618c2ecf20Sopenharmony_ci	.read = ath6kl_endpoint_stats_read,
8628c2ecf20Sopenharmony_ci	.write = ath6kl_endpoint_stats_write,
8638c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
8648c2ecf20Sopenharmony_ci	.llseek = default_llseek,
8658c2ecf20Sopenharmony_ci};
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_cistatic unsigned long ath6kl_get_num_reg(void)
8688c2ecf20Sopenharmony_ci{
8698c2ecf20Sopenharmony_ci	int i;
8708c2ecf20Sopenharmony_ci	unsigned long n_reg = 0;
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
8738c2ecf20Sopenharmony_ci		n_reg = n_reg +
8748c2ecf20Sopenharmony_ci		     (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_ci	return n_reg;
8778c2ecf20Sopenharmony_ci}
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_cistatic bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
8808c2ecf20Sopenharmony_ci{
8818c2ecf20Sopenharmony_ci	int i;
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
8848c2ecf20Sopenharmony_ci		if (reg_addr >= diag_reg[i].reg_start &&
8858c2ecf20Sopenharmony_ci		    reg_addr <= diag_reg[i].reg_end)
8868c2ecf20Sopenharmony_ci			return true;
8878c2ecf20Sopenharmony_ci	}
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci	return false;
8908c2ecf20Sopenharmony_ci}
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_cistatic ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
8938c2ecf20Sopenharmony_ci				    size_t count, loff_t *ppos)
8948c2ecf20Sopenharmony_ci{
8958c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
8968c2ecf20Sopenharmony_ci	u8 buf[50];
8978c2ecf20Sopenharmony_ci	unsigned int len = 0;
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	if (ar->debug.dbgfs_diag_reg)
9008c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
9018c2ecf20Sopenharmony_ci				ar->debug.dbgfs_diag_reg);
9028c2ecf20Sopenharmony_ci	else
9038c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, sizeof(buf) - len,
9048c2ecf20Sopenharmony_ci				 "All diag registers\n");
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
9078c2ecf20Sopenharmony_ci}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_cistatic ssize_t ath6kl_regread_write(struct file *file,
9108c2ecf20Sopenharmony_ci				    const char __user *user_buf,
9118c2ecf20Sopenharmony_ci				    size_t count, loff_t *ppos)
9128c2ecf20Sopenharmony_ci{
9138c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
9148c2ecf20Sopenharmony_ci	unsigned long reg_addr;
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci	if (kstrtoul_from_user(user_buf, count, 0, &reg_addr))
9178c2ecf20Sopenharmony_ci		return -EINVAL;
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci	if ((reg_addr % 4) != 0)
9208c2ecf20Sopenharmony_ci		return -EINVAL;
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
9238c2ecf20Sopenharmony_ci		return -EINVAL;
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci	ar->debug.dbgfs_diag_reg = reg_addr;
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci	return count;
9288c2ecf20Sopenharmony_ci}
9298c2ecf20Sopenharmony_ci
9308c2ecf20Sopenharmony_cistatic const struct file_operations fops_diag_reg_read = {
9318c2ecf20Sopenharmony_ci	.read = ath6kl_regread_read,
9328c2ecf20Sopenharmony_ci	.write = ath6kl_regread_write,
9338c2ecf20Sopenharmony_ci	.open = simple_open,
9348c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
9358c2ecf20Sopenharmony_ci	.llseek = default_llseek,
9368c2ecf20Sopenharmony_ci};
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_cistatic int ath6kl_regdump_open(struct inode *inode, struct file *file)
9398c2ecf20Sopenharmony_ci{
9408c2ecf20Sopenharmony_ci	struct ath6kl *ar = inode->i_private;
9418c2ecf20Sopenharmony_ci	u8 *buf;
9428c2ecf20Sopenharmony_ci	unsigned long int reg_len;
9438c2ecf20Sopenharmony_ci	unsigned int len = 0, n_reg;
9448c2ecf20Sopenharmony_ci	u32 addr;
9458c2ecf20Sopenharmony_ci	__le32 reg_val;
9468c2ecf20Sopenharmony_ci	int i, status;
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci	/* Dump all the registers if no register is specified */
9498c2ecf20Sopenharmony_ci	if (!ar->debug.dbgfs_diag_reg)
9508c2ecf20Sopenharmony_ci		n_reg = ath6kl_get_num_reg();
9518c2ecf20Sopenharmony_ci	else
9528c2ecf20Sopenharmony_ci		n_reg = 1;
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci	reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
9558c2ecf20Sopenharmony_ci	if (n_reg > 1)
9568c2ecf20Sopenharmony_ci		reg_len += REGTYPE_STR_LEN;
9578c2ecf20Sopenharmony_ci
9588c2ecf20Sopenharmony_ci	buf = vmalloc(reg_len);
9598c2ecf20Sopenharmony_ci	if (!buf)
9608c2ecf20Sopenharmony_ci		return -ENOMEM;
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci	if (n_reg == 1) {
9638c2ecf20Sopenharmony_ci		addr = ar->debug.dbgfs_diag_reg;
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci		status = ath6kl_diag_read32(ar,
9668c2ecf20Sopenharmony_ci				TARG_VTOP(ar->target_type, addr),
9678c2ecf20Sopenharmony_ci				(u32 *)&reg_val);
9688c2ecf20Sopenharmony_ci		if (status)
9698c2ecf20Sopenharmony_ci			goto fail_reg_read;
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, reg_len - len,
9728c2ecf20Sopenharmony_ci				 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
9738c2ecf20Sopenharmony_ci		goto done;
9748c2ecf20Sopenharmony_ci	}
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
9778c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, reg_len - len,
9788c2ecf20Sopenharmony_ci				"%s\n", diag_reg[i].reg_info);
9798c2ecf20Sopenharmony_ci		for (addr = diag_reg[i].reg_start;
9808c2ecf20Sopenharmony_ci		     addr <= diag_reg[i].reg_end; addr += 4) {
9818c2ecf20Sopenharmony_ci			status = ath6kl_diag_read32(ar,
9828c2ecf20Sopenharmony_ci					TARG_VTOP(ar->target_type, addr),
9838c2ecf20Sopenharmony_ci					(u32 *)&reg_val);
9848c2ecf20Sopenharmony_ci			if (status)
9858c2ecf20Sopenharmony_ci				goto fail_reg_read;
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci			len += scnprintf(buf + len, reg_len - len,
9888c2ecf20Sopenharmony_ci					"0x%06x 0x%08x\n",
9898c2ecf20Sopenharmony_ci					addr, le32_to_cpu(reg_val));
9908c2ecf20Sopenharmony_ci		}
9918c2ecf20Sopenharmony_ci	}
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_cidone:
9948c2ecf20Sopenharmony_ci	file->private_data = buf;
9958c2ecf20Sopenharmony_ci	return 0;
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_cifail_reg_read:
9988c2ecf20Sopenharmony_ci	ath6kl_warn("Unable to read memory:%u\n", addr);
9998c2ecf20Sopenharmony_ci	vfree(buf);
10008c2ecf20Sopenharmony_ci	return -EIO;
10018c2ecf20Sopenharmony_ci}
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_cistatic ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
10048c2ecf20Sopenharmony_ci				  size_t count, loff_t *ppos)
10058c2ecf20Sopenharmony_ci{
10068c2ecf20Sopenharmony_ci	u8 *buf = file->private_data;
10078c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
10088c2ecf20Sopenharmony_ci}
10098c2ecf20Sopenharmony_ci
10108c2ecf20Sopenharmony_cistatic int ath6kl_regdump_release(struct inode *inode, struct file *file)
10118c2ecf20Sopenharmony_ci{
10128c2ecf20Sopenharmony_ci	vfree(file->private_data);
10138c2ecf20Sopenharmony_ci	return 0;
10148c2ecf20Sopenharmony_ci}
10158c2ecf20Sopenharmony_ci
10168c2ecf20Sopenharmony_cistatic const struct file_operations fops_reg_dump = {
10178c2ecf20Sopenharmony_ci	.open = ath6kl_regdump_open,
10188c2ecf20Sopenharmony_ci	.read = ath6kl_regdump_read,
10198c2ecf20Sopenharmony_ci	.release = ath6kl_regdump_release,
10208c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
10218c2ecf20Sopenharmony_ci	.llseek = default_llseek,
10228c2ecf20Sopenharmony_ci};
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_cistatic ssize_t ath6kl_lrssi_roam_write(struct file *file,
10258c2ecf20Sopenharmony_ci				       const char __user *user_buf,
10268c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
10278c2ecf20Sopenharmony_ci{
10288c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
10298c2ecf20Sopenharmony_ci	unsigned long lrssi_roam_threshold;
10308c2ecf20Sopenharmony_ci	int ret;
10318c2ecf20Sopenharmony_ci
10328c2ecf20Sopenharmony_ci	if (kstrtoul_from_user(user_buf, count, 0, &lrssi_roam_threshold))
10338c2ecf20Sopenharmony_ci		return -EINVAL;
10348c2ecf20Sopenharmony_ci
10358c2ecf20Sopenharmony_ci	ar->lrssi_roam_threshold = lrssi_roam_threshold;
10368c2ecf20Sopenharmony_ci
10378c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_ci	if (ret)
10408c2ecf20Sopenharmony_ci		return ret;
10418c2ecf20Sopenharmony_ci	return count;
10428c2ecf20Sopenharmony_ci}
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_cistatic ssize_t ath6kl_lrssi_roam_read(struct file *file,
10458c2ecf20Sopenharmony_ci				      char __user *user_buf,
10468c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
10478c2ecf20Sopenharmony_ci{
10488c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
10498c2ecf20Sopenharmony_ci	char buf[32];
10508c2ecf20Sopenharmony_ci	unsigned int len;
10518c2ecf20Sopenharmony_ci
10528c2ecf20Sopenharmony_ci	len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
10538c2ecf20Sopenharmony_ci
10548c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10558c2ecf20Sopenharmony_ci}
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_cistatic const struct file_operations fops_lrssi_roam_threshold = {
10588c2ecf20Sopenharmony_ci	.read = ath6kl_lrssi_roam_read,
10598c2ecf20Sopenharmony_ci	.write = ath6kl_lrssi_roam_write,
10608c2ecf20Sopenharmony_ci	.open = simple_open,
10618c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
10628c2ecf20Sopenharmony_ci	.llseek = default_llseek,
10638c2ecf20Sopenharmony_ci};
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_cistatic ssize_t ath6kl_regwrite_read(struct file *file,
10668c2ecf20Sopenharmony_ci				    char __user *user_buf,
10678c2ecf20Sopenharmony_ci				    size_t count, loff_t *ppos)
10688c2ecf20Sopenharmony_ci{
10698c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
10708c2ecf20Sopenharmony_ci	u8 buf[32];
10718c2ecf20Sopenharmony_ci	unsigned int len = 0;
10728c2ecf20Sopenharmony_ci
10738c2ecf20Sopenharmony_ci	len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
10748c2ecf20Sopenharmony_ci			ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
10758c2ecf20Sopenharmony_ci
10768c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
10778c2ecf20Sopenharmony_ci}
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_cistatic ssize_t ath6kl_regwrite_write(struct file *file,
10808c2ecf20Sopenharmony_ci				     const char __user *user_buf,
10818c2ecf20Sopenharmony_ci				     size_t count, loff_t *ppos)
10828c2ecf20Sopenharmony_ci{
10838c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
10848c2ecf20Sopenharmony_ci	char buf[32];
10858c2ecf20Sopenharmony_ci	char *sptr, *token;
10868c2ecf20Sopenharmony_ci	unsigned int len = 0;
10878c2ecf20Sopenharmony_ci	u32 reg_addr, reg_val;
10888c2ecf20Sopenharmony_ci
10898c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
10908c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
10918c2ecf20Sopenharmony_ci		return -EFAULT;
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci	buf[len] = '\0';
10948c2ecf20Sopenharmony_ci	sptr = buf;
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_ci	token = strsep(&sptr, "=");
10978c2ecf20Sopenharmony_ci	if (!token)
10988c2ecf20Sopenharmony_ci		return -EINVAL;
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &reg_addr))
11018c2ecf20Sopenharmony_ci		return -EINVAL;
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
11048c2ecf20Sopenharmony_ci		return -EINVAL;
11058c2ecf20Sopenharmony_ci
11068c2ecf20Sopenharmony_ci	if (kstrtou32(sptr, 0, &reg_val))
11078c2ecf20Sopenharmony_ci		return -EINVAL;
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ci	ar->debug.diag_reg_addr_wr = reg_addr;
11108c2ecf20Sopenharmony_ci	ar->debug.diag_reg_val_wr = reg_val;
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_ci	if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
11138c2ecf20Sopenharmony_ci				cpu_to_le32(ar->debug.diag_reg_val_wr)))
11148c2ecf20Sopenharmony_ci		return -EIO;
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci	return count;
11178c2ecf20Sopenharmony_ci}
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_cistatic const struct file_operations fops_diag_reg_write = {
11208c2ecf20Sopenharmony_ci	.read = ath6kl_regwrite_read,
11218c2ecf20Sopenharmony_ci	.write = ath6kl_regwrite_write,
11228c2ecf20Sopenharmony_ci	.open = simple_open,
11238c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
11248c2ecf20Sopenharmony_ci	.llseek = default_llseek,
11258c2ecf20Sopenharmony_ci};
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ciint ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
11288c2ecf20Sopenharmony_ci				size_t len)
11298c2ecf20Sopenharmony_ci{
11308c2ecf20Sopenharmony_ci	const struct wmi_target_roam_tbl *tbl;
11318c2ecf20Sopenharmony_ci	u16 num_entries;
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_ci	if (len < sizeof(*tbl))
11348c2ecf20Sopenharmony_ci		return -EINVAL;
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci	tbl = (const struct wmi_target_roam_tbl *) buf;
11378c2ecf20Sopenharmony_ci	num_entries = le16_to_cpu(tbl->num_entries);
11388c2ecf20Sopenharmony_ci	if (struct_size(tbl, info, num_entries) > len)
11398c2ecf20Sopenharmony_ci		return -EINVAL;
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci	if (ar->debug.roam_tbl == NULL ||
11428c2ecf20Sopenharmony_ci	    ar->debug.roam_tbl_len < (unsigned int) len) {
11438c2ecf20Sopenharmony_ci		kfree(ar->debug.roam_tbl);
11448c2ecf20Sopenharmony_ci		ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
11458c2ecf20Sopenharmony_ci		if (ar->debug.roam_tbl == NULL)
11468c2ecf20Sopenharmony_ci			return -ENOMEM;
11478c2ecf20Sopenharmony_ci	}
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_ci	memcpy(ar->debug.roam_tbl, buf, len);
11508c2ecf20Sopenharmony_ci	ar->debug.roam_tbl_len = len;
11518c2ecf20Sopenharmony_ci
11528c2ecf20Sopenharmony_ci	if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
11538c2ecf20Sopenharmony_ci		clear_bit(ROAM_TBL_PEND, &ar->flag);
11548c2ecf20Sopenharmony_ci		wake_up(&ar->event_wq);
11558c2ecf20Sopenharmony_ci	}
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci	return 0;
11588c2ecf20Sopenharmony_ci}
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_cistatic ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
11618c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
11628c2ecf20Sopenharmony_ci{
11638c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
11648c2ecf20Sopenharmony_ci	int ret;
11658c2ecf20Sopenharmony_ci	long left;
11668c2ecf20Sopenharmony_ci	struct wmi_target_roam_tbl *tbl;
11678c2ecf20Sopenharmony_ci	u16 num_entries, i;
11688c2ecf20Sopenharmony_ci	char *buf;
11698c2ecf20Sopenharmony_ci	unsigned int len, buf_len;
11708c2ecf20Sopenharmony_ci	ssize_t ret_cnt;
11718c2ecf20Sopenharmony_ci
11728c2ecf20Sopenharmony_ci	if (down_interruptible(&ar->sem))
11738c2ecf20Sopenharmony_ci		return -EBUSY;
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_ci	set_bit(ROAM_TBL_PEND, &ar->flag);
11768c2ecf20Sopenharmony_ci
11778c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
11788c2ecf20Sopenharmony_ci	if (ret) {
11798c2ecf20Sopenharmony_ci		up(&ar->sem);
11808c2ecf20Sopenharmony_ci		return ret;
11818c2ecf20Sopenharmony_ci	}
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci	left = wait_event_interruptible_timeout(
11848c2ecf20Sopenharmony_ci		ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
11858c2ecf20Sopenharmony_ci	up(&ar->sem);
11868c2ecf20Sopenharmony_ci
11878c2ecf20Sopenharmony_ci	if (left <= 0)
11888c2ecf20Sopenharmony_ci		return -ETIMEDOUT;
11898c2ecf20Sopenharmony_ci
11908c2ecf20Sopenharmony_ci	if (ar->debug.roam_tbl == NULL)
11918c2ecf20Sopenharmony_ci		return -ENOMEM;
11928c2ecf20Sopenharmony_ci
11938c2ecf20Sopenharmony_ci	tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
11948c2ecf20Sopenharmony_ci	num_entries = le16_to_cpu(tbl->num_entries);
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci	buf_len = 100 + num_entries * 100;
11978c2ecf20Sopenharmony_ci	buf = kzalloc(buf_len, GFP_KERNEL);
11988c2ecf20Sopenharmony_ci	if (buf == NULL)
11998c2ecf20Sopenharmony_ci		return -ENOMEM;
12008c2ecf20Sopenharmony_ci	len = 0;
12018c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buf_len - len,
12028c2ecf20Sopenharmony_ci			 "roam_mode=%u\n\n"
12038c2ecf20Sopenharmony_ci			 "# roam_util bssid rssi rssidt last_rssi util bias\n",
12048c2ecf20Sopenharmony_ci			 le16_to_cpu(tbl->roam_mode));
12058c2ecf20Sopenharmony_ci
12068c2ecf20Sopenharmony_ci	for (i = 0; i < num_entries; i++) {
12078c2ecf20Sopenharmony_ci		struct wmi_bss_roam_info *info = &tbl->info[i];
12088c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buf_len - len,
12098c2ecf20Sopenharmony_ci				 "%d %pM %d %d %d %d %d\n",
12108c2ecf20Sopenharmony_ci				 a_sle32_to_cpu(info->roam_util), info->bssid,
12118c2ecf20Sopenharmony_ci				 info->rssi, info->rssidt, info->last_rssi,
12128c2ecf20Sopenharmony_ci				 info->util, info->bias);
12138c2ecf20Sopenharmony_ci	}
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci	if (len > buf_len)
12168c2ecf20Sopenharmony_ci		len = buf_len;
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
12198c2ecf20Sopenharmony_ci
12208c2ecf20Sopenharmony_ci	kfree(buf);
12218c2ecf20Sopenharmony_ci	return ret_cnt;
12228c2ecf20Sopenharmony_ci}
12238c2ecf20Sopenharmony_ci
12248c2ecf20Sopenharmony_cistatic const struct file_operations fops_roam_table = {
12258c2ecf20Sopenharmony_ci	.read = ath6kl_roam_table_read,
12268c2ecf20Sopenharmony_ci	.open = simple_open,
12278c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
12288c2ecf20Sopenharmony_ci	.llseek = default_llseek,
12298c2ecf20Sopenharmony_ci};
12308c2ecf20Sopenharmony_ci
12318c2ecf20Sopenharmony_cistatic ssize_t ath6kl_force_roam_write(struct file *file,
12328c2ecf20Sopenharmony_ci				       const char __user *user_buf,
12338c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
12348c2ecf20Sopenharmony_ci{
12358c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
12368c2ecf20Sopenharmony_ci	int ret;
12378c2ecf20Sopenharmony_ci	char buf[20];
12388c2ecf20Sopenharmony_ci	size_t len;
12398c2ecf20Sopenharmony_ci	u8 bssid[ETH_ALEN];
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
12428c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
12438c2ecf20Sopenharmony_ci		return -EFAULT;
12448c2ecf20Sopenharmony_ci	buf[len] = '\0';
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_ci	if (!mac_pton(buf, bssid))
12478c2ecf20Sopenharmony_ci		return -EINVAL;
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
12508c2ecf20Sopenharmony_ci	if (ret)
12518c2ecf20Sopenharmony_ci		return ret;
12528c2ecf20Sopenharmony_ci
12538c2ecf20Sopenharmony_ci	return count;
12548c2ecf20Sopenharmony_ci}
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_cistatic const struct file_operations fops_force_roam = {
12578c2ecf20Sopenharmony_ci	.write = ath6kl_force_roam_write,
12588c2ecf20Sopenharmony_ci	.open = simple_open,
12598c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
12608c2ecf20Sopenharmony_ci	.llseek = default_llseek,
12618c2ecf20Sopenharmony_ci};
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_cistatic ssize_t ath6kl_roam_mode_write(struct file *file,
12648c2ecf20Sopenharmony_ci				      const char __user *user_buf,
12658c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
12668c2ecf20Sopenharmony_ci{
12678c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
12688c2ecf20Sopenharmony_ci	int ret;
12698c2ecf20Sopenharmony_ci	char buf[20];
12708c2ecf20Sopenharmony_ci	size_t len;
12718c2ecf20Sopenharmony_ci	enum wmi_roam_mode mode;
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
12748c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
12758c2ecf20Sopenharmony_ci		return -EFAULT;
12768c2ecf20Sopenharmony_ci	buf[len] = '\0';
12778c2ecf20Sopenharmony_ci	if (len > 0 && buf[len - 1] == '\n')
12788c2ecf20Sopenharmony_ci		buf[len - 1] = '\0';
12798c2ecf20Sopenharmony_ci
12808c2ecf20Sopenharmony_ci	if (strcasecmp(buf, "default") == 0)
12818c2ecf20Sopenharmony_ci		mode = WMI_DEFAULT_ROAM_MODE;
12828c2ecf20Sopenharmony_ci	else if (strcasecmp(buf, "bssbias") == 0)
12838c2ecf20Sopenharmony_ci		mode = WMI_HOST_BIAS_ROAM_MODE;
12848c2ecf20Sopenharmony_ci	else if (strcasecmp(buf, "lock") == 0)
12858c2ecf20Sopenharmony_ci		mode = WMI_LOCK_BSS_MODE;
12868c2ecf20Sopenharmony_ci	else
12878c2ecf20Sopenharmony_ci		return -EINVAL;
12888c2ecf20Sopenharmony_ci
12898c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
12908c2ecf20Sopenharmony_ci	if (ret)
12918c2ecf20Sopenharmony_ci		return ret;
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_ci	return count;
12948c2ecf20Sopenharmony_ci}
12958c2ecf20Sopenharmony_ci
12968c2ecf20Sopenharmony_cistatic const struct file_operations fops_roam_mode = {
12978c2ecf20Sopenharmony_ci	.write = ath6kl_roam_mode_write,
12988c2ecf20Sopenharmony_ci	.open = simple_open,
12998c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
13008c2ecf20Sopenharmony_ci	.llseek = default_llseek,
13018c2ecf20Sopenharmony_ci};
13028c2ecf20Sopenharmony_ci
13038c2ecf20Sopenharmony_civoid ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
13048c2ecf20Sopenharmony_ci{
13058c2ecf20Sopenharmony_ci	ar->debug.keepalive = keepalive;
13068c2ecf20Sopenharmony_ci}
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_cistatic ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
13098c2ecf20Sopenharmony_ci				     size_t count, loff_t *ppos)
13108c2ecf20Sopenharmony_ci{
13118c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
13128c2ecf20Sopenharmony_ci	char buf[16];
13138c2ecf20Sopenharmony_ci	int len;
13148c2ecf20Sopenharmony_ci
13158c2ecf20Sopenharmony_ci	len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
13188c2ecf20Sopenharmony_ci}
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_cistatic ssize_t ath6kl_keepalive_write(struct file *file,
13218c2ecf20Sopenharmony_ci				      const char __user *user_buf,
13228c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
13238c2ecf20Sopenharmony_ci{
13248c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
13258c2ecf20Sopenharmony_ci	int ret;
13268c2ecf20Sopenharmony_ci	u8 val;
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci	ret = kstrtou8_from_user(user_buf, count, 0, &val);
13298c2ecf20Sopenharmony_ci	if (ret)
13308c2ecf20Sopenharmony_ci		return ret;
13318c2ecf20Sopenharmony_ci
13328c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val);
13338c2ecf20Sopenharmony_ci	if (ret)
13348c2ecf20Sopenharmony_ci		return ret;
13358c2ecf20Sopenharmony_ci
13368c2ecf20Sopenharmony_ci	return count;
13378c2ecf20Sopenharmony_ci}
13388c2ecf20Sopenharmony_ci
13398c2ecf20Sopenharmony_cistatic const struct file_operations fops_keepalive = {
13408c2ecf20Sopenharmony_ci	.open = simple_open,
13418c2ecf20Sopenharmony_ci	.read = ath6kl_keepalive_read,
13428c2ecf20Sopenharmony_ci	.write = ath6kl_keepalive_write,
13438c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
13448c2ecf20Sopenharmony_ci	.llseek = default_llseek,
13458c2ecf20Sopenharmony_ci};
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_civoid ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
13488c2ecf20Sopenharmony_ci{
13498c2ecf20Sopenharmony_ci	ar->debug.disc_timeout = timeout;
13508c2ecf20Sopenharmony_ci}
13518c2ecf20Sopenharmony_ci
13528c2ecf20Sopenharmony_cistatic ssize_t ath6kl_disconnect_timeout_read(struct file *file,
13538c2ecf20Sopenharmony_ci					      char __user *user_buf,
13548c2ecf20Sopenharmony_ci					      size_t count, loff_t *ppos)
13558c2ecf20Sopenharmony_ci{
13568c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
13578c2ecf20Sopenharmony_ci	char buf[16];
13588c2ecf20Sopenharmony_ci	int len;
13598c2ecf20Sopenharmony_ci
13608c2ecf20Sopenharmony_ci	len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
13638c2ecf20Sopenharmony_ci}
13648c2ecf20Sopenharmony_ci
13658c2ecf20Sopenharmony_cistatic ssize_t ath6kl_disconnect_timeout_write(struct file *file,
13668c2ecf20Sopenharmony_ci					       const char __user *user_buf,
13678c2ecf20Sopenharmony_ci					       size_t count, loff_t *ppos)
13688c2ecf20Sopenharmony_ci{
13698c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
13708c2ecf20Sopenharmony_ci	int ret;
13718c2ecf20Sopenharmony_ci	u8 val;
13728c2ecf20Sopenharmony_ci
13738c2ecf20Sopenharmony_ci	ret = kstrtou8_from_user(user_buf, count, 0, &val);
13748c2ecf20Sopenharmony_ci	if (ret)
13758c2ecf20Sopenharmony_ci		return ret;
13768c2ecf20Sopenharmony_ci
13778c2ecf20Sopenharmony_ci	ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val);
13788c2ecf20Sopenharmony_ci	if (ret)
13798c2ecf20Sopenharmony_ci		return ret;
13808c2ecf20Sopenharmony_ci
13818c2ecf20Sopenharmony_ci	return count;
13828c2ecf20Sopenharmony_ci}
13838c2ecf20Sopenharmony_ci
13848c2ecf20Sopenharmony_cistatic const struct file_operations fops_disconnect_timeout = {
13858c2ecf20Sopenharmony_ci	.open = simple_open,
13868c2ecf20Sopenharmony_ci	.read = ath6kl_disconnect_timeout_read,
13878c2ecf20Sopenharmony_ci	.write = ath6kl_disconnect_timeout_write,
13888c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
13898c2ecf20Sopenharmony_ci	.llseek = default_llseek,
13908c2ecf20Sopenharmony_ci};
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_cistatic ssize_t ath6kl_create_qos_write(struct file *file,
13938c2ecf20Sopenharmony_ci						const char __user *user_buf,
13948c2ecf20Sopenharmony_ci						size_t count, loff_t *ppos)
13958c2ecf20Sopenharmony_ci{
13968c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
13978c2ecf20Sopenharmony_ci	struct ath6kl_vif *vif;
13988c2ecf20Sopenharmony_ci	char buf[200];
13998c2ecf20Sopenharmony_ci	ssize_t len;
14008c2ecf20Sopenharmony_ci	char *sptr, *token;
14018c2ecf20Sopenharmony_ci	struct wmi_create_pstream_cmd pstream;
14028c2ecf20Sopenharmony_ci	u32 val32;
14038c2ecf20Sopenharmony_ci	u16 val16;
14048c2ecf20Sopenharmony_ci
14058c2ecf20Sopenharmony_ci	vif = ath6kl_vif_first(ar);
14068c2ecf20Sopenharmony_ci	if (!vif)
14078c2ecf20Sopenharmony_ci		return -EIO;
14088c2ecf20Sopenharmony_ci
14098c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
14108c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
14118c2ecf20Sopenharmony_ci		return -EFAULT;
14128c2ecf20Sopenharmony_ci	buf[len] = '\0';
14138c2ecf20Sopenharmony_ci	sptr = buf;
14148c2ecf20Sopenharmony_ci
14158c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14168c2ecf20Sopenharmony_ci	if (!token)
14178c2ecf20Sopenharmony_ci		return -EINVAL;
14188c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &pstream.user_pri))
14198c2ecf20Sopenharmony_ci		return -EINVAL;
14208c2ecf20Sopenharmony_ci
14218c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14228c2ecf20Sopenharmony_ci	if (!token)
14238c2ecf20Sopenharmony_ci		return -EINVAL;
14248c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &pstream.traffic_direc))
14258c2ecf20Sopenharmony_ci		return -EINVAL;
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14288c2ecf20Sopenharmony_ci	if (!token)
14298c2ecf20Sopenharmony_ci		return -EINVAL;
14308c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &pstream.traffic_class))
14318c2ecf20Sopenharmony_ci		return -EINVAL;
14328c2ecf20Sopenharmony_ci
14338c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14348c2ecf20Sopenharmony_ci	if (!token)
14358c2ecf20Sopenharmony_ci		return -EINVAL;
14368c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &pstream.traffic_type))
14378c2ecf20Sopenharmony_ci		return -EINVAL;
14388c2ecf20Sopenharmony_ci
14398c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14408c2ecf20Sopenharmony_ci	if (!token)
14418c2ecf20Sopenharmony_ci		return -EINVAL;
14428c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &pstream.voice_psc_cap))
14438c2ecf20Sopenharmony_ci		return -EINVAL;
14448c2ecf20Sopenharmony_ci
14458c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14468c2ecf20Sopenharmony_ci	if (!token)
14478c2ecf20Sopenharmony_ci		return -EINVAL;
14488c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
14498c2ecf20Sopenharmony_ci		return -EINVAL;
14508c2ecf20Sopenharmony_ci	pstream.min_service_int = cpu_to_le32(val32);
14518c2ecf20Sopenharmony_ci
14528c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14538c2ecf20Sopenharmony_ci	if (!token)
14548c2ecf20Sopenharmony_ci		return -EINVAL;
14558c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
14568c2ecf20Sopenharmony_ci		return -EINVAL;
14578c2ecf20Sopenharmony_ci	pstream.max_service_int = cpu_to_le32(val32);
14588c2ecf20Sopenharmony_ci
14598c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14608c2ecf20Sopenharmony_ci	if (!token)
14618c2ecf20Sopenharmony_ci		return -EINVAL;
14628c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
14638c2ecf20Sopenharmony_ci		return -EINVAL;
14648c2ecf20Sopenharmony_ci	pstream.inactivity_int = cpu_to_le32(val32);
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14678c2ecf20Sopenharmony_ci	if (!token)
14688c2ecf20Sopenharmony_ci		return -EINVAL;
14698c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
14708c2ecf20Sopenharmony_ci		return -EINVAL;
14718c2ecf20Sopenharmony_ci	pstream.suspension_int = cpu_to_le32(val32);
14728c2ecf20Sopenharmony_ci
14738c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14748c2ecf20Sopenharmony_ci	if (!token)
14758c2ecf20Sopenharmony_ci		return -EINVAL;
14768c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
14778c2ecf20Sopenharmony_ci		return -EINVAL;
14788c2ecf20Sopenharmony_ci	pstream.service_start_time = cpu_to_le32(val32);
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14818c2ecf20Sopenharmony_ci	if (!token)
14828c2ecf20Sopenharmony_ci		return -EINVAL;
14838c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &pstream.tsid))
14848c2ecf20Sopenharmony_ci		return -EINVAL;
14858c2ecf20Sopenharmony_ci
14868c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14878c2ecf20Sopenharmony_ci	if (!token)
14888c2ecf20Sopenharmony_ci		return -EINVAL;
14898c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &val16))
14908c2ecf20Sopenharmony_ci		return -EINVAL;
14918c2ecf20Sopenharmony_ci	pstream.nominal_msdu = cpu_to_le16(val16);
14928c2ecf20Sopenharmony_ci
14938c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
14948c2ecf20Sopenharmony_ci	if (!token)
14958c2ecf20Sopenharmony_ci		return -EINVAL;
14968c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &val16))
14978c2ecf20Sopenharmony_ci		return -EINVAL;
14988c2ecf20Sopenharmony_ci	pstream.max_msdu = cpu_to_le16(val16);
14998c2ecf20Sopenharmony_ci
15008c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15018c2ecf20Sopenharmony_ci	if (!token)
15028c2ecf20Sopenharmony_ci		return -EINVAL;
15038c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15048c2ecf20Sopenharmony_ci		return -EINVAL;
15058c2ecf20Sopenharmony_ci	pstream.min_data_rate = cpu_to_le32(val32);
15068c2ecf20Sopenharmony_ci
15078c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15088c2ecf20Sopenharmony_ci	if (!token)
15098c2ecf20Sopenharmony_ci		return -EINVAL;
15108c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15118c2ecf20Sopenharmony_ci		return -EINVAL;
15128c2ecf20Sopenharmony_ci	pstream.mean_data_rate = cpu_to_le32(val32);
15138c2ecf20Sopenharmony_ci
15148c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15158c2ecf20Sopenharmony_ci	if (!token)
15168c2ecf20Sopenharmony_ci		return -EINVAL;
15178c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15188c2ecf20Sopenharmony_ci		return -EINVAL;
15198c2ecf20Sopenharmony_ci	pstream.peak_data_rate = cpu_to_le32(val32);
15208c2ecf20Sopenharmony_ci
15218c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15228c2ecf20Sopenharmony_ci	if (!token)
15238c2ecf20Sopenharmony_ci		return -EINVAL;
15248c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15258c2ecf20Sopenharmony_ci		return -EINVAL;
15268c2ecf20Sopenharmony_ci	pstream.max_burst_size = cpu_to_le32(val32);
15278c2ecf20Sopenharmony_ci
15288c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15298c2ecf20Sopenharmony_ci	if (!token)
15308c2ecf20Sopenharmony_ci		return -EINVAL;
15318c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15328c2ecf20Sopenharmony_ci		return -EINVAL;
15338c2ecf20Sopenharmony_ci	pstream.delay_bound = cpu_to_le32(val32);
15348c2ecf20Sopenharmony_ci
15358c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15368c2ecf20Sopenharmony_ci	if (!token)
15378c2ecf20Sopenharmony_ci		return -EINVAL;
15388c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15398c2ecf20Sopenharmony_ci		return -EINVAL;
15408c2ecf20Sopenharmony_ci	pstream.min_phy_rate = cpu_to_le32(val32);
15418c2ecf20Sopenharmony_ci
15428c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15438c2ecf20Sopenharmony_ci	if (!token)
15448c2ecf20Sopenharmony_ci		return -EINVAL;
15458c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15468c2ecf20Sopenharmony_ci		return -EINVAL;
15478c2ecf20Sopenharmony_ci	pstream.sba = cpu_to_le32(val32);
15488c2ecf20Sopenharmony_ci
15498c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15508c2ecf20Sopenharmony_ci	if (!token)
15518c2ecf20Sopenharmony_ci		return -EINVAL;
15528c2ecf20Sopenharmony_ci	if (kstrtou32(token, 0, &val32))
15538c2ecf20Sopenharmony_ci		return -EINVAL;
15548c2ecf20Sopenharmony_ci	pstream.medium_time = cpu_to_le32(val32);
15558c2ecf20Sopenharmony_ci
15568c2ecf20Sopenharmony_ci	pstream.nominal_phy = le32_to_cpu(pstream.min_phy_rate) / 1000000;
15578c2ecf20Sopenharmony_ci
15588c2ecf20Sopenharmony_ci	ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
15598c2ecf20Sopenharmony_ci
15608c2ecf20Sopenharmony_ci	return count;
15618c2ecf20Sopenharmony_ci}
15628c2ecf20Sopenharmony_ci
15638c2ecf20Sopenharmony_cistatic const struct file_operations fops_create_qos = {
15648c2ecf20Sopenharmony_ci	.write = ath6kl_create_qos_write,
15658c2ecf20Sopenharmony_ci	.open = simple_open,
15668c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
15678c2ecf20Sopenharmony_ci	.llseek = default_llseek,
15688c2ecf20Sopenharmony_ci};
15698c2ecf20Sopenharmony_ci
15708c2ecf20Sopenharmony_cistatic ssize_t ath6kl_delete_qos_write(struct file *file,
15718c2ecf20Sopenharmony_ci				const char __user *user_buf,
15728c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
15738c2ecf20Sopenharmony_ci{
15748c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
15758c2ecf20Sopenharmony_ci	struct ath6kl_vif *vif;
15768c2ecf20Sopenharmony_ci	char buf[100];
15778c2ecf20Sopenharmony_ci	ssize_t len;
15788c2ecf20Sopenharmony_ci	char *sptr, *token;
15798c2ecf20Sopenharmony_ci	u8 traffic_class;
15808c2ecf20Sopenharmony_ci	u8 tsid;
15818c2ecf20Sopenharmony_ci
15828c2ecf20Sopenharmony_ci	vif = ath6kl_vif_first(ar);
15838c2ecf20Sopenharmony_ci	if (!vif)
15848c2ecf20Sopenharmony_ci		return -EIO;
15858c2ecf20Sopenharmony_ci
15868c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
15878c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
15888c2ecf20Sopenharmony_ci		return -EFAULT;
15898c2ecf20Sopenharmony_ci	buf[len] = '\0';
15908c2ecf20Sopenharmony_ci	sptr = buf;
15918c2ecf20Sopenharmony_ci
15928c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15938c2ecf20Sopenharmony_ci	if (!token)
15948c2ecf20Sopenharmony_ci		return -EINVAL;
15958c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &traffic_class))
15968c2ecf20Sopenharmony_ci		return -EINVAL;
15978c2ecf20Sopenharmony_ci
15988c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
15998c2ecf20Sopenharmony_ci	if (!token)
16008c2ecf20Sopenharmony_ci		return -EINVAL;
16018c2ecf20Sopenharmony_ci	if (kstrtou8(token, 0, &tsid))
16028c2ecf20Sopenharmony_ci		return -EINVAL;
16038c2ecf20Sopenharmony_ci
16048c2ecf20Sopenharmony_ci	ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
16058c2ecf20Sopenharmony_ci				      traffic_class, tsid);
16068c2ecf20Sopenharmony_ci
16078c2ecf20Sopenharmony_ci	return count;
16088c2ecf20Sopenharmony_ci}
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_cistatic const struct file_operations fops_delete_qos = {
16118c2ecf20Sopenharmony_ci	.write = ath6kl_delete_qos_write,
16128c2ecf20Sopenharmony_ci	.open = simple_open,
16138c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
16148c2ecf20Sopenharmony_ci	.llseek = default_llseek,
16158c2ecf20Sopenharmony_ci};
16168c2ecf20Sopenharmony_ci
16178c2ecf20Sopenharmony_cistatic ssize_t ath6kl_bgscan_int_write(struct file *file,
16188c2ecf20Sopenharmony_ci				const char __user *user_buf,
16198c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
16208c2ecf20Sopenharmony_ci{
16218c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
16228c2ecf20Sopenharmony_ci	struct ath6kl_vif *vif;
16238c2ecf20Sopenharmony_ci	u16 bgscan_int;
16248c2ecf20Sopenharmony_ci	char buf[32];
16258c2ecf20Sopenharmony_ci	ssize_t len;
16268c2ecf20Sopenharmony_ci
16278c2ecf20Sopenharmony_ci	vif = ath6kl_vif_first(ar);
16288c2ecf20Sopenharmony_ci	if (!vif)
16298c2ecf20Sopenharmony_ci		return -EIO;
16308c2ecf20Sopenharmony_ci
16318c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
16328c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
16338c2ecf20Sopenharmony_ci		return -EFAULT;
16348c2ecf20Sopenharmony_ci
16358c2ecf20Sopenharmony_ci	buf[len] = '\0';
16368c2ecf20Sopenharmony_ci	if (kstrtou16(buf, 0, &bgscan_int))
16378c2ecf20Sopenharmony_ci		return -EINVAL;
16388c2ecf20Sopenharmony_ci
16398c2ecf20Sopenharmony_ci	if (bgscan_int == 0)
16408c2ecf20Sopenharmony_ci		bgscan_int = 0xffff;
16418c2ecf20Sopenharmony_ci
16428c2ecf20Sopenharmony_ci	vif->bg_scan_period = bgscan_int;
16438c2ecf20Sopenharmony_ci
16448c2ecf20Sopenharmony_ci	ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
16458c2ecf20Sopenharmony_ci				  0, 0, 0);
16468c2ecf20Sopenharmony_ci
16478c2ecf20Sopenharmony_ci	return count;
16488c2ecf20Sopenharmony_ci}
16498c2ecf20Sopenharmony_ci
16508c2ecf20Sopenharmony_cistatic const struct file_operations fops_bgscan_int = {
16518c2ecf20Sopenharmony_ci	.write = ath6kl_bgscan_int_write,
16528c2ecf20Sopenharmony_ci	.open = simple_open,
16538c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
16548c2ecf20Sopenharmony_ci	.llseek = default_llseek,
16558c2ecf20Sopenharmony_ci};
16568c2ecf20Sopenharmony_ci
16578c2ecf20Sopenharmony_cistatic ssize_t ath6kl_listen_int_write(struct file *file,
16588c2ecf20Sopenharmony_ci				       const char __user *user_buf,
16598c2ecf20Sopenharmony_ci				       size_t count, loff_t *ppos)
16608c2ecf20Sopenharmony_ci{
16618c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
16628c2ecf20Sopenharmony_ci	struct ath6kl_vif *vif;
16638c2ecf20Sopenharmony_ci	u16 listen_interval;
16648c2ecf20Sopenharmony_ci	char buf[32];
16658c2ecf20Sopenharmony_ci	ssize_t len;
16668c2ecf20Sopenharmony_ci
16678c2ecf20Sopenharmony_ci	vif = ath6kl_vif_first(ar);
16688c2ecf20Sopenharmony_ci	if (!vif)
16698c2ecf20Sopenharmony_ci		return -EIO;
16708c2ecf20Sopenharmony_ci
16718c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
16728c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
16738c2ecf20Sopenharmony_ci		return -EFAULT;
16748c2ecf20Sopenharmony_ci
16758c2ecf20Sopenharmony_ci	buf[len] = '\0';
16768c2ecf20Sopenharmony_ci	if (kstrtou16(buf, 0, &listen_interval))
16778c2ecf20Sopenharmony_ci		return -EINVAL;
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci	if ((listen_interval < 15) || (listen_interval > 3000))
16808c2ecf20Sopenharmony_ci		return -EINVAL;
16818c2ecf20Sopenharmony_ci
16828c2ecf20Sopenharmony_ci	vif->listen_intvl_t = listen_interval;
16838c2ecf20Sopenharmony_ci	ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
16848c2ecf20Sopenharmony_ci				      vif->listen_intvl_t, 0);
16858c2ecf20Sopenharmony_ci
16868c2ecf20Sopenharmony_ci	return count;
16878c2ecf20Sopenharmony_ci}
16888c2ecf20Sopenharmony_ci
16898c2ecf20Sopenharmony_cistatic ssize_t ath6kl_listen_int_read(struct file *file,
16908c2ecf20Sopenharmony_ci				      char __user *user_buf,
16918c2ecf20Sopenharmony_ci				      size_t count, loff_t *ppos)
16928c2ecf20Sopenharmony_ci{
16938c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
16948c2ecf20Sopenharmony_ci	struct ath6kl_vif *vif;
16958c2ecf20Sopenharmony_ci	char buf[32];
16968c2ecf20Sopenharmony_ci	int len;
16978c2ecf20Sopenharmony_ci
16988c2ecf20Sopenharmony_ci	vif = ath6kl_vif_first(ar);
16998c2ecf20Sopenharmony_ci	if (!vif)
17008c2ecf20Sopenharmony_ci		return -EIO;
17018c2ecf20Sopenharmony_ci
17028c2ecf20Sopenharmony_ci	len = scnprintf(buf, sizeof(buf), "%u\n", vif->listen_intvl_t);
17038c2ecf20Sopenharmony_ci
17048c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
17058c2ecf20Sopenharmony_ci}
17068c2ecf20Sopenharmony_ci
17078c2ecf20Sopenharmony_cistatic const struct file_operations fops_listen_int = {
17088c2ecf20Sopenharmony_ci	.read = ath6kl_listen_int_read,
17098c2ecf20Sopenharmony_ci	.write = ath6kl_listen_int_write,
17108c2ecf20Sopenharmony_ci	.open = simple_open,
17118c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
17128c2ecf20Sopenharmony_ci	.llseek = default_llseek,
17138c2ecf20Sopenharmony_ci};
17148c2ecf20Sopenharmony_ci
17158c2ecf20Sopenharmony_cistatic ssize_t ath6kl_power_params_write(struct file *file,
17168c2ecf20Sopenharmony_ci						const char __user *user_buf,
17178c2ecf20Sopenharmony_ci						size_t count, loff_t *ppos)
17188c2ecf20Sopenharmony_ci{
17198c2ecf20Sopenharmony_ci	struct ath6kl *ar = file->private_data;
17208c2ecf20Sopenharmony_ci	u8 buf[100];
17218c2ecf20Sopenharmony_ci	unsigned int len = 0;
17228c2ecf20Sopenharmony_ci	char *sptr, *token;
17238c2ecf20Sopenharmony_ci	u16 idle_period, ps_poll_num, dtim,
17248c2ecf20Sopenharmony_ci		tx_wakeup, num_tx;
17258c2ecf20Sopenharmony_ci
17268c2ecf20Sopenharmony_ci	len = min(count, sizeof(buf) - 1);
17278c2ecf20Sopenharmony_ci	if (copy_from_user(buf, user_buf, len))
17288c2ecf20Sopenharmony_ci		return -EFAULT;
17298c2ecf20Sopenharmony_ci	buf[len] = '\0';
17308c2ecf20Sopenharmony_ci	sptr = buf;
17318c2ecf20Sopenharmony_ci
17328c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
17338c2ecf20Sopenharmony_ci	if (!token)
17348c2ecf20Sopenharmony_ci		return -EINVAL;
17358c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &idle_period))
17368c2ecf20Sopenharmony_ci		return -EINVAL;
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
17398c2ecf20Sopenharmony_ci	if (!token)
17408c2ecf20Sopenharmony_ci		return -EINVAL;
17418c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &ps_poll_num))
17428c2ecf20Sopenharmony_ci		return -EINVAL;
17438c2ecf20Sopenharmony_ci
17448c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
17458c2ecf20Sopenharmony_ci	if (!token)
17468c2ecf20Sopenharmony_ci		return -EINVAL;
17478c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &dtim))
17488c2ecf20Sopenharmony_ci		return -EINVAL;
17498c2ecf20Sopenharmony_ci
17508c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
17518c2ecf20Sopenharmony_ci	if (!token)
17528c2ecf20Sopenharmony_ci		return -EINVAL;
17538c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &tx_wakeup))
17548c2ecf20Sopenharmony_ci		return -EINVAL;
17558c2ecf20Sopenharmony_ci
17568c2ecf20Sopenharmony_ci	token = strsep(&sptr, " ");
17578c2ecf20Sopenharmony_ci	if (!token)
17588c2ecf20Sopenharmony_ci		return -EINVAL;
17598c2ecf20Sopenharmony_ci	if (kstrtou16(token, 0, &num_tx))
17608c2ecf20Sopenharmony_ci		return -EINVAL;
17618c2ecf20Sopenharmony_ci
17628c2ecf20Sopenharmony_ci	ath6kl_wmi_pmparams_cmd(ar->wmi, 0, idle_period, ps_poll_num,
17638c2ecf20Sopenharmony_ci				dtim, tx_wakeup, num_tx, 0);
17648c2ecf20Sopenharmony_ci
17658c2ecf20Sopenharmony_ci	return count;
17668c2ecf20Sopenharmony_ci}
17678c2ecf20Sopenharmony_ci
17688c2ecf20Sopenharmony_cistatic const struct file_operations fops_power_params = {
17698c2ecf20Sopenharmony_ci	.write = ath6kl_power_params_write,
17708c2ecf20Sopenharmony_ci	.open = simple_open,
17718c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
17728c2ecf20Sopenharmony_ci	.llseek = default_llseek,
17738c2ecf20Sopenharmony_ci};
17748c2ecf20Sopenharmony_ci
17758c2ecf20Sopenharmony_civoid ath6kl_debug_init(struct ath6kl *ar)
17768c2ecf20Sopenharmony_ci{
17778c2ecf20Sopenharmony_ci	skb_queue_head_init(&ar->debug.fwlog_queue);
17788c2ecf20Sopenharmony_ci	init_completion(&ar->debug.fwlog_completion);
17798c2ecf20Sopenharmony_ci
17808c2ecf20Sopenharmony_ci	/*
17818c2ecf20Sopenharmony_ci	 * Actually we are lying here but don't know how to read the mask
17828c2ecf20Sopenharmony_ci	 * value from the firmware.
17838c2ecf20Sopenharmony_ci	 */
17848c2ecf20Sopenharmony_ci	ar->debug.fwlog_mask = 0;
17858c2ecf20Sopenharmony_ci}
17868c2ecf20Sopenharmony_ci
17878c2ecf20Sopenharmony_ci/*
17888c2ecf20Sopenharmony_ci * Initialisation needs to happen in two stages as fwlog events can come
17898c2ecf20Sopenharmony_ci * before cfg80211 is initialised, and debugfs depends on cfg80211
17908c2ecf20Sopenharmony_ci * initialisation.
17918c2ecf20Sopenharmony_ci */
17928c2ecf20Sopenharmony_ciint ath6kl_debug_init_fs(struct ath6kl *ar)
17938c2ecf20Sopenharmony_ci{
17948c2ecf20Sopenharmony_ci	ar->debugfs_phy = debugfs_create_dir("ath6kl",
17958c2ecf20Sopenharmony_ci					     ar->wiphy->debugfsdir);
17968c2ecf20Sopenharmony_ci	if (!ar->debugfs_phy)
17978c2ecf20Sopenharmony_ci		return -ENOMEM;
17988c2ecf20Sopenharmony_ci
17998c2ecf20Sopenharmony_ci	debugfs_create_file("tgt_stats", 0400, ar->debugfs_phy, ar,
18008c2ecf20Sopenharmony_ci			    &fops_tgt_stats);
18018c2ecf20Sopenharmony_ci
18028c2ecf20Sopenharmony_ci	if (ar->hif_type == ATH6KL_HIF_TYPE_SDIO)
18038c2ecf20Sopenharmony_ci		debugfs_create_file("credit_dist_stats", 0400,
18048c2ecf20Sopenharmony_ci				    ar->debugfs_phy, ar,
18058c2ecf20Sopenharmony_ci				    &fops_credit_dist_stats);
18068c2ecf20Sopenharmony_ci
18078c2ecf20Sopenharmony_ci	debugfs_create_file("endpoint_stats", 0600,
18088c2ecf20Sopenharmony_ci			    ar->debugfs_phy, ar, &fops_endpoint_stats);
18098c2ecf20Sopenharmony_ci
18108c2ecf20Sopenharmony_ci	debugfs_create_file("fwlog", 0400, ar->debugfs_phy, ar, &fops_fwlog);
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_ci	debugfs_create_file("fwlog_block", 0400, ar->debugfs_phy, ar,
18138c2ecf20Sopenharmony_ci			    &fops_fwlog_block);
18148c2ecf20Sopenharmony_ci
18158c2ecf20Sopenharmony_ci	debugfs_create_file("fwlog_mask", 0600, ar->debugfs_phy,
18168c2ecf20Sopenharmony_ci			    ar, &fops_fwlog_mask);
18178c2ecf20Sopenharmony_ci
18188c2ecf20Sopenharmony_ci	debugfs_create_file("reg_addr", 0600, ar->debugfs_phy, ar,
18198c2ecf20Sopenharmony_ci			    &fops_diag_reg_read);
18208c2ecf20Sopenharmony_ci
18218c2ecf20Sopenharmony_ci	debugfs_create_file("reg_dump", 0400, ar->debugfs_phy, ar,
18228c2ecf20Sopenharmony_ci			    &fops_reg_dump);
18238c2ecf20Sopenharmony_ci
18248c2ecf20Sopenharmony_ci	debugfs_create_file("lrssi_roam_threshold", 0600,
18258c2ecf20Sopenharmony_ci			    ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
18268c2ecf20Sopenharmony_ci
18278c2ecf20Sopenharmony_ci	debugfs_create_file("reg_write", 0600,
18288c2ecf20Sopenharmony_ci			    ar->debugfs_phy, ar, &fops_diag_reg_write);
18298c2ecf20Sopenharmony_ci
18308c2ecf20Sopenharmony_ci	debugfs_create_file("war_stats", 0400, ar->debugfs_phy, ar,
18318c2ecf20Sopenharmony_ci			    &fops_war_stats);
18328c2ecf20Sopenharmony_ci
18338c2ecf20Sopenharmony_ci	debugfs_create_file("roam_table", 0400, ar->debugfs_phy, ar,
18348c2ecf20Sopenharmony_ci			    &fops_roam_table);
18358c2ecf20Sopenharmony_ci
18368c2ecf20Sopenharmony_ci	debugfs_create_file("force_roam", 0200, ar->debugfs_phy, ar,
18378c2ecf20Sopenharmony_ci			    &fops_force_roam);
18388c2ecf20Sopenharmony_ci
18398c2ecf20Sopenharmony_ci	debugfs_create_file("roam_mode", 0200, ar->debugfs_phy, ar,
18408c2ecf20Sopenharmony_ci			    &fops_roam_mode);
18418c2ecf20Sopenharmony_ci
18428c2ecf20Sopenharmony_ci	debugfs_create_file("keepalive", 0600, ar->debugfs_phy, ar,
18438c2ecf20Sopenharmony_ci			    &fops_keepalive);
18448c2ecf20Sopenharmony_ci
18458c2ecf20Sopenharmony_ci	debugfs_create_file("disconnect_timeout", 0600,
18468c2ecf20Sopenharmony_ci			    ar->debugfs_phy, ar, &fops_disconnect_timeout);
18478c2ecf20Sopenharmony_ci
18488c2ecf20Sopenharmony_ci	debugfs_create_file("create_qos", 0200, ar->debugfs_phy, ar,
18498c2ecf20Sopenharmony_ci			    &fops_create_qos);
18508c2ecf20Sopenharmony_ci
18518c2ecf20Sopenharmony_ci	debugfs_create_file("delete_qos", 0200, ar->debugfs_phy, ar,
18528c2ecf20Sopenharmony_ci			    &fops_delete_qos);
18538c2ecf20Sopenharmony_ci
18548c2ecf20Sopenharmony_ci	debugfs_create_file("bgscan_interval", 0200,
18558c2ecf20Sopenharmony_ci			    ar->debugfs_phy, ar, &fops_bgscan_int);
18568c2ecf20Sopenharmony_ci
18578c2ecf20Sopenharmony_ci	debugfs_create_file("listen_interval", 0600,
18588c2ecf20Sopenharmony_ci			    ar->debugfs_phy, ar, &fops_listen_int);
18598c2ecf20Sopenharmony_ci
18608c2ecf20Sopenharmony_ci	debugfs_create_file("power_params", 0200, ar->debugfs_phy, ar,
18618c2ecf20Sopenharmony_ci			    &fops_power_params);
18628c2ecf20Sopenharmony_ci
18638c2ecf20Sopenharmony_ci	return 0;
18648c2ecf20Sopenharmony_ci}
18658c2ecf20Sopenharmony_ci
18668c2ecf20Sopenharmony_civoid ath6kl_debug_cleanup(struct ath6kl *ar)
18678c2ecf20Sopenharmony_ci{
18688c2ecf20Sopenharmony_ci	skb_queue_purge(&ar->debug.fwlog_queue);
18698c2ecf20Sopenharmony_ci	complete(&ar->debug.fwlog_completion);
18708c2ecf20Sopenharmony_ci	kfree(ar->debug.roam_tbl);
18718c2ecf20Sopenharmony_ci}
18728c2ecf20Sopenharmony_ci
18738c2ecf20Sopenharmony_ci#endif
1874