1bdcd8170SKalle Valo /*
2bdcd8170SKalle Valo  * Copyright (c) 2004-2011 Atheros Communications Inc.
3bdcd8170SKalle Valo  *
4bdcd8170SKalle Valo  * Permission to use, copy, modify, and/or distribute this software for any
5bdcd8170SKalle Valo  * purpose with or without fee is hereby granted, provided that the above
6bdcd8170SKalle Valo  * copyright notice and this permission notice appear in all copies.
7bdcd8170SKalle Valo  *
8bdcd8170SKalle Valo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9bdcd8170SKalle Valo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10bdcd8170SKalle Valo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11bdcd8170SKalle Valo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12bdcd8170SKalle Valo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13bdcd8170SKalle Valo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14bdcd8170SKalle Valo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15bdcd8170SKalle Valo  */
16bdcd8170SKalle Valo 
17bdcd8170SKalle Valo #include "core.h"
18bdf5396bSKalle Valo 
19bdf5396bSKalle Valo #include <linux/circ_buf.h>
20939f1cceSKalle Valo #include <linux/fs.h>
2162c83ac4SKalle Valo #include <linux/vmalloc.h>
22bdf5396bSKalle Valo 
23bdcd8170SKalle Valo #include "debug.h"
24bdf5396bSKalle Valo #include "target.h"
25bdf5396bSKalle Valo 
26bdf5396bSKalle Valo struct ath6kl_fwlog_slot {
27bdf5396bSKalle Valo 	__le32 timestamp;
28bdf5396bSKalle Valo 	__le32 length;
29bdf5396bSKalle Valo 
30bdf5396bSKalle Valo 	/* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
31bdf5396bSKalle Valo 	u8 payload[0];
32bdf5396bSKalle Valo };
33bdf5396bSKalle Valo 
34bdf5396bSKalle Valo #define ATH6KL_FWLOG_SIZE 32768
35bdf5396bSKalle Valo #define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \
36bdf5396bSKalle Valo 				ATH6KL_FWLOG_PAYLOAD_SIZE)
37939f1cceSKalle Valo #define ATH6KL_FWLOG_VALID_MASK 0x1ffff
38bdcd8170SKalle Valo 
39bdcd8170SKalle Valo int ath6kl_printk(const char *level, const char *fmt, ...)
40bdcd8170SKalle Valo {
41bdcd8170SKalle Valo 	struct va_format vaf;
42bdcd8170SKalle Valo 	va_list args;
43bdcd8170SKalle Valo 	int rtn;
44bdcd8170SKalle Valo 
45bdcd8170SKalle Valo 	va_start(args, fmt);
46bdcd8170SKalle Valo 
47bdcd8170SKalle Valo 	vaf.fmt = fmt;
48bdcd8170SKalle Valo 	vaf.va = &args;
49bdcd8170SKalle Valo 
50bdcd8170SKalle Valo 	rtn = printk("%sath6kl: %pV", level, &vaf);
51bdcd8170SKalle Valo 
52bdcd8170SKalle Valo 	va_end(args);
53bdcd8170SKalle Valo 
54bdcd8170SKalle Valo 	return rtn;
55bdcd8170SKalle Valo }
56bdcd8170SKalle Valo 
57bdcd8170SKalle Valo #ifdef CONFIG_ATH6KL_DEBUG
5891d57de5SVasanthakumar Thiagarajan 
5991d57de5SVasanthakumar Thiagarajan #define REG_OUTPUT_LEN_PER_LINE	25
6091d57de5SVasanthakumar Thiagarajan #define REGTYPE_STR_LEN		100
6191d57de5SVasanthakumar Thiagarajan 
6291d57de5SVasanthakumar Thiagarajan struct ath6kl_diag_reg_info {
6391d57de5SVasanthakumar Thiagarajan 	u32 reg_start;
6491d57de5SVasanthakumar Thiagarajan 	u32 reg_end;
6591d57de5SVasanthakumar Thiagarajan 	const char *reg_info;
6691d57de5SVasanthakumar Thiagarajan };
6791d57de5SVasanthakumar Thiagarajan 
6891d57de5SVasanthakumar Thiagarajan static const struct ath6kl_diag_reg_info diag_reg[] = {
6991d57de5SVasanthakumar Thiagarajan 	{ 0x20000, 0x200fc, "General DMA and Rx registers" },
7091d57de5SVasanthakumar Thiagarajan 	{ 0x28000, 0x28900, "MAC PCU register & keycache" },
7191d57de5SVasanthakumar Thiagarajan 	{ 0x20800, 0x20a40, "QCU" },
7291d57de5SVasanthakumar Thiagarajan 	{ 0x21000, 0x212f0, "DCU" },
7391d57de5SVasanthakumar Thiagarajan 	{ 0x4000,  0x42e4, "RTC" },
7491d57de5SVasanthakumar Thiagarajan 	{ 0x540000, 0x540000 + (256 * 1024), "RAM" },
7591d57de5SVasanthakumar Thiagarajan 	{ 0x29800, 0x2B210, "Base Band" },
7691d57de5SVasanthakumar Thiagarajan 	{ 0x1C000, 0x1C748, "Analog" },
7791d57de5SVasanthakumar Thiagarajan };
7891d57de5SVasanthakumar Thiagarajan 
79bdcd8170SKalle Valo void ath6kl_dump_registers(struct ath6kl_device *dev,
80bdcd8170SKalle Valo 			   struct ath6kl_irq_proc_registers *irq_proc_reg,
81bdcd8170SKalle Valo 			   struct ath6kl_irq_enable_reg *irq_enable_reg)
82bdcd8170SKalle Valo {
83bdcd8170SKalle Valo 
84bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n"));
85bdcd8170SKalle Valo 
86bdcd8170SKalle Valo 	if (irq_proc_reg != NULL) {
87bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
88bdcd8170SKalle Valo 			"Host Int status:           0x%x\n",
89bdcd8170SKalle Valo 			irq_proc_reg->host_int_status);
90bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
91bdcd8170SKalle Valo 			   "CPU Int status:            0x%x\n",
92bdcd8170SKalle Valo 			irq_proc_reg->cpu_int_status);
93bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
94bdcd8170SKalle Valo 			   "Error Int status:          0x%x\n",
95bdcd8170SKalle Valo 			irq_proc_reg->error_int_status);
96bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
97bdcd8170SKalle Valo 			   "Counter Int status:        0x%x\n",
98bdcd8170SKalle Valo 			irq_proc_reg->counter_int_status);
99bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
100bdcd8170SKalle Valo 			   "Mbox Frame:                0x%x\n",
101bdcd8170SKalle Valo 			irq_proc_reg->mbox_frame);
102bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
103bdcd8170SKalle Valo 			   "Rx Lookahead Valid:        0x%x\n",
104bdcd8170SKalle Valo 			irq_proc_reg->rx_lkahd_valid);
105bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
106bdcd8170SKalle Valo 			   "Rx Lookahead 0:            0x%x\n",
107bdcd8170SKalle Valo 			irq_proc_reg->rx_lkahd[0]);
108bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
109bdcd8170SKalle Valo 			   "Rx Lookahead 1:            0x%x\n",
110bdcd8170SKalle Valo 			irq_proc_reg->rx_lkahd[1]);
111bdcd8170SKalle Valo 
112bdcd8170SKalle Valo 		if (dev->ar->mbox_info.gmbox_addr != 0) {
113bdcd8170SKalle Valo 			/*
114bdcd8170SKalle Valo 			 * If the target supports GMBOX hardware, dump some
115bdcd8170SKalle Valo 			 * additional state.
116bdcd8170SKalle Valo 			 */
117bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_ANY,
118bdcd8170SKalle Valo 				"GMBOX Host Int status 2:   0x%x\n",
119bdcd8170SKalle Valo 				irq_proc_reg->host_int_status2);
120bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_ANY,
121bdcd8170SKalle Valo 				"GMBOX RX Avail:            0x%x\n",
122bdcd8170SKalle Valo 				irq_proc_reg->gmbox_rx_avail);
123bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_ANY,
124bdcd8170SKalle Valo 				"GMBOX lookahead alias 0:   0x%x\n",
125bdcd8170SKalle Valo 				irq_proc_reg->rx_gmbox_lkahd_alias[0]);
126bdcd8170SKalle Valo 			ath6kl_dbg(ATH6KL_DBG_ANY,
127bdcd8170SKalle Valo 				"GMBOX lookahead alias 1:   0x%x\n",
128bdcd8170SKalle Valo 				irq_proc_reg->rx_gmbox_lkahd_alias[1]);
129bdcd8170SKalle Valo 		}
130bdcd8170SKalle Valo 
131bdcd8170SKalle Valo 	}
132bdcd8170SKalle Valo 
133bdcd8170SKalle Valo 	if (irq_enable_reg != NULL) {
134bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY,
135bdcd8170SKalle Valo 			"Int status Enable:         0x%x\n",
136bdcd8170SKalle Valo 			irq_enable_reg->int_status_en);
137bdcd8170SKalle Valo 		ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n",
138bdcd8170SKalle Valo 			irq_enable_reg->cntr_int_status_en);
139bdcd8170SKalle Valo 	}
140bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n");
141bdcd8170SKalle Valo }
142bdcd8170SKalle Valo 
143bdcd8170SKalle Valo static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
144bdcd8170SKalle Valo {
145bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY,
146bdcd8170SKalle Valo 		   "--- endpoint: %d  svc_id: 0x%X ---\n",
147bdcd8170SKalle Valo 		   ep_dist->endpoint, ep_dist->svc_id);
148bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags     : 0x%X\n",
149bdcd8170SKalle Valo 		   ep_dist->dist_flags);
150bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm      : %d\n",
151bdcd8170SKalle Valo 		   ep_dist->cred_norm);
152bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min       : %d\n",
153bdcd8170SKalle Valo 		   ep_dist->cred_min);
154bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " credits        : %d\n",
155bdcd8170SKalle Valo 		   ep_dist->credits);
156bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd    : %d\n",
157bdcd8170SKalle Valo 		   ep_dist->cred_assngd);
158bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred      : %d\n",
159bdcd8170SKalle Valo 		   ep_dist->seek_cred);
160bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz        : %d\n",
161bdcd8170SKalle Valo 		   ep_dist->cred_sz);
162bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg   : %d\n",
163bdcd8170SKalle Valo 		   ep_dist->cred_per_msg);
164bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist   : %d\n",
165bdcd8170SKalle Valo 		   ep_dist->cred_to_dist);
166bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth      : %d\n",
167bdcd8170SKalle Valo 		   get_queue_depth(&((struct htc_endpoint *)
168bdcd8170SKalle Valo 				     ep_dist->htc_rsvd)->txq));
169bdcd8170SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_ANY,
170bdcd8170SKalle Valo 		   "----------------------------------\n");
171bdcd8170SKalle Valo }
172bdcd8170SKalle Valo 
173bdcd8170SKalle Valo void dump_cred_dist_stats(struct htc_target *target)
174bdcd8170SKalle Valo {
175bdcd8170SKalle Valo 	struct htc_endpoint_credit_dist *ep_list;
176bdcd8170SKalle Valo 
177bdcd8170SKalle Valo 	if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC))
178bdcd8170SKalle Valo 		return;
179bdcd8170SKalle Valo 
180bdcd8170SKalle Valo 	list_for_each_entry(ep_list, &target->cred_dist_list, list)
181bdcd8170SKalle Valo 		dump_cred_dist(ep_list);
182bdcd8170SKalle Valo 
183ebf29c95SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_HTC, "ctxt:%p dist:%p\n",
184bdcd8170SKalle Valo 		   target->cred_dist_cntxt, NULL);
185ebf29c95SKalle Valo 	ath6kl_dbg(ATH6KL_DBG_HTC,
186ebf29c95SKalle Valo 		   "credit distribution, total : %d, free : %d\n",
187bdcd8170SKalle Valo 		   target->cred_dist_cntxt->total_avail_credits,
188bdcd8170SKalle Valo 		   target->cred_dist_cntxt->cur_free_credits);
189bdcd8170SKalle Valo }
190bdcd8170SKalle Valo 
19103f68a95SVasanthakumar Thiagarajan static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
19203f68a95SVasanthakumar Thiagarajan {
19303f68a95SVasanthakumar Thiagarajan 	file->private_data = inode->i_private;
19403f68a95SVasanthakumar Thiagarajan 	return 0;
19503f68a95SVasanthakumar Thiagarajan }
19603f68a95SVasanthakumar Thiagarajan 
1979a730834SKalle Valo void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
1989a730834SKalle Valo {
1999a730834SKalle Valo 	switch (war) {
2009a730834SKalle Valo 	case ATH6KL_WAR_INVALID_RATE:
2019a730834SKalle Valo 		ar->debug.war_stats.invalid_rate++;
2029a730834SKalle Valo 		break;
2039a730834SKalle Valo 	}
2049a730834SKalle Valo }
2059a730834SKalle Valo 
2069a730834SKalle Valo static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
2079a730834SKalle Valo 				   size_t count, loff_t *ppos)
2089a730834SKalle Valo {
2099a730834SKalle Valo 	struct ath6kl *ar = file->private_data;
2109a730834SKalle Valo 	char *buf;
2119a730834SKalle Valo 	unsigned int len = 0, buf_len = 1500;
2129a730834SKalle Valo 	ssize_t ret_cnt;
2139a730834SKalle Valo 
2149a730834SKalle Valo 	buf = kzalloc(buf_len, GFP_KERNEL);
2159a730834SKalle Valo 	if (!buf)
2169a730834SKalle Valo 		return -ENOMEM;
2179a730834SKalle Valo 
2189a730834SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
2199a730834SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%25s\n",
2209a730834SKalle Valo 			 "Workaround stats");
2219a730834SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
2229a730834SKalle Valo 			 "=================");
2239a730834SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
2249a730834SKalle Valo 			 "Invalid rates", ar->debug.war_stats.invalid_rate);
2259a730834SKalle Valo 
2269a730834SKalle Valo 	if (WARN_ON(len > buf_len))
2279a730834SKalle Valo 		len = buf_len;
2289a730834SKalle Valo 
2299a730834SKalle Valo 	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2309a730834SKalle Valo 
2319a730834SKalle Valo 	kfree(buf);
2329a730834SKalle Valo 	return ret_cnt;
2339a730834SKalle Valo }
2349a730834SKalle Valo 
2359a730834SKalle Valo static const struct file_operations fops_war_stats = {
2369a730834SKalle Valo 	.read = read_file_war_stats,
2379a730834SKalle Valo 	.open = ath6kl_debugfs_open,
2389a730834SKalle Valo 	.owner = THIS_MODULE,
2399a730834SKalle Valo 	.llseek = default_llseek,
2409a730834SKalle Valo };
2419a730834SKalle Valo 
242bdf5396bSKalle Valo static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf,
243bdf5396bSKalle Valo 				   size_t buf_len)
244bdf5396bSKalle Valo {
245bdf5396bSKalle Valo 	struct circ_buf *fwlog = &ar->debug.fwlog_buf;
246bdf5396bSKalle Valo 	size_t space;
247bdf5396bSKalle Valo 	int i;
248bdf5396bSKalle Valo 
249bdf5396bSKalle Valo 	/* entries must all be equal size */
250bdf5396bSKalle Valo 	if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE))
251bdf5396bSKalle Valo 		return;
252bdf5396bSKalle Valo 
253bdf5396bSKalle Valo 	space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE);
254bdf5396bSKalle Valo 	if (space < buf_len)
255bdf5396bSKalle Valo 		/* discard oldest slot */
256bdf5396bSKalle Valo 		fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) &
257bdf5396bSKalle Valo 			(ATH6KL_FWLOG_SIZE - 1);
258bdf5396bSKalle Valo 
259bdf5396bSKalle Valo 	for (i = 0; i < buf_len; i += space) {
260bdf5396bSKalle Valo 		space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail,
261bdf5396bSKalle Valo 					  ATH6KL_FWLOG_SIZE);
262bdf5396bSKalle Valo 
263bdf5396bSKalle Valo 		if ((size_t) space > buf_len - i)
264bdf5396bSKalle Valo 			space = buf_len - i;
265bdf5396bSKalle Valo 
266bdf5396bSKalle Valo 		memcpy(&fwlog->buf[fwlog->head], buf, space);
267bdf5396bSKalle Valo 		fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1);
268bdf5396bSKalle Valo 	}
269bdf5396bSKalle Valo 
270bdf5396bSKalle Valo }
271bdf5396bSKalle Valo 
272bdf5396bSKalle Valo void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
273bdf5396bSKalle Valo {
274bdf5396bSKalle Valo 	struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp;
275bdf5396bSKalle Valo 	size_t slot_len;
276bdf5396bSKalle Valo 
277bdf5396bSKalle Valo 	if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
278bdf5396bSKalle Valo 		return;
279bdf5396bSKalle Valo 
280bdf5396bSKalle Valo 	spin_lock_bh(&ar->debug.fwlog_lock);
281bdf5396bSKalle Valo 
282bdf5396bSKalle Valo 	slot->timestamp = cpu_to_le32(jiffies);
283bdf5396bSKalle Valo 	slot->length = cpu_to_le32(len);
284bdf5396bSKalle Valo 	memcpy(slot->payload, buf, len);
285bdf5396bSKalle Valo 
286bdf5396bSKalle Valo 	slot_len = sizeof(*slot) + len;
287bdf5396bSKalle Valo 
288bdf5396bSKalle Valo 	if (slot_len < ATH6KL_FWLOG_SLOT_SIZE)
289bdf5396bSKalle Valo 		memset(slot->payload + len, 0,
290bdf5396bSKalle Valo 		       ATH6KL_FWLOG_SLOT_SIZE - slot_len);
291bdf5396bSKalle Valo 
292bdf5396bSKalle Valo 	ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE);
293bdf5396bSKalle Valo 
294bdf5396bSKalle Valo 	spin_unlock_bh(&ar->debug.fwlog_lock);
295bdf5396bSKalle Valo }
296bdf5396bSKalle Valo 
297bdf5396bSKalle Valo static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar)
298bdf5396bSKalle Valo {
299bdf5396bSKalle Valo 	return CIRC_CNT(ar->debug.fwlog_buf.head,
300bdf5396bSKalle Valo 			ar->debug.fwlog_buf.tail,
301bdf5396bSKalle Valo 			ATH6KL_FWLOG_SLOT_SIZE) == 0;
302bdf5396bSKalle Valo }
303bdf5396bSKalle Valo 
304bdf5396bSKalle Valo static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
305bdf5396bSKalle Valo 				 size_t count, loff_t *ppos)
306bdf5396bSKalle Valo {
307bdf5396bSKalle Valo 	struct ath6kl *ar = file->private_data;
308bdf5396bSKalle Valo 	struct circ_buf *fwlog = &ar->debug.fwlog_buf;
309bdf5396bSKalle Valo 	size_t len = 0, buf_len = count;
310bdf5396bSKalle Valo 	ssize_t ret_cnt;
311bdf5396bSKalle Valo 	char *buf;
312bdf5396bSKalle Valo 	int ccnt;
313bdf5396bSKalle Valo 
314bdf5396bSKalle Valo 	buf = vmalloc(buf_len);
315bdf5396bSKalle Valo 	if (!buf)
316bdf5396bSKalle Valo 		return -ENOMEM;
317bdf5396bSKalle Valo 
318bc07ddb2SKalle Valo 	/* read undelivered logs from firmware */
319bc07ddb2SKalle Valo 	ath6kl_read_fwlogs(ar);
320bc07ddb2SKalle Valo 
321bdf5396bSKalle Valo 	spin_lock_bh(&ar->debug.fwlog_lock);
322bdf5396bSKalle Valo 
323bdf5396bSKalle Valo 	while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
324bdf5396bSKalle Valo 		ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail,
325bdf5396bSKalle Valo 				       ATH6KL_FWLOG_SIZE);
326bdf5396bSKalle Valo 
327bdf5396bSKalle Valo 		if ((size_t) ccnt > buf_len - len)
328bdf5396bSKalle Valo 			ccnt = buf_len - len;
329bdf5396bSKalle Valo 
330bdf5396bSKalle Valo 		memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt);
331bdf5396bSKalle Valo 		len += ccnt;
332bdf5396bSKalle Valo 
333bdf5396bSKalle Valo 		fwlog->tail = (fwlog->tail + ccnt) &
334bdf5396bSKalle Valo 			(ATH6KL_FWLOG_SIZE - 1);
335bdf5396bSKalle Valo 	}
336bdf5396bSKalle Valo 
337bdf5396bSKalle Valo 	spin_unlock_bh(&ar->debug.fwlog_lock);
338bdf5396bSKalle Valo 
339bdf5396bSKalle Valo 	if (WARN_ON(len > buf_len))
340bdf5396bSKalle Valo 		len = buf_len;
341bdf5396bSKalle Valo 
342bdf5396bSKalle Valo 	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
343bdf5396bSKalle Valo 
344bdf5396bSKalle Valo 	vfree(buf);
345bdf5396bSKalle Valo 
346bdf5396bSKalle Valo 	return ret_cnt;
347bdf5396bSKalle Valo }
348bdf5396bSKalle Valo 
349bdf5396bSKalle Valo static const struct file_operations fops_fwlog = {
350bdf5396bSKalle Valo 	.open = ath6kl_debugfs_open,
351bdf5396bSKalle Valo 	.read = ath6kl_fwlog_read,
352bdf5396bSKalle Valo 	.owner = THIS_MODULE,
353bdf5396bSKalle Valo 	.llseek = default_llseek,
354bdf5396bSKalle Valo };
355bdf5396bSKalle Valo 
356939f1cceSKalle Valo static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
357939f1cceSKalle Valo 				      size_t count, loff_t *ppos)
358939f1cceSKalle Valo {
359939f1cceSKalle Valo 	struct ath6kl *ar = file->private_data;
360939f1cceSKalle Valo 	char buf[16];
361939f1cceSKalle Valo 	int len;
362939f1cceSKalle Valo 
363939f1cceSKalle Valo 	len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
364939f1cceSKalle Valo 
365939f1cceSKalle Valo 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
366939f1cceSKalle Valo }
367939f1cceSKalle Valo 
368939f1cceSKalle Valo static ssize_t ath6kl_fwlog_mask_write(struct file *file,
369939f1cceSKalle Valo 				       const char __user *user_buf,
370939f1cceSKalle Valo 				       size_t count, loff_t *ppos)
371939f1cceSKalle Valo {
372939f1cceSKalle Valo 	struct ath6kl *ar = file->private_data;
373939f1cceSKalle Valo 	int ret;
374939f1cceSKalle Valo 
375939f1cceSKalle Valo 	ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
376939f1cceSKalle Valo 	if (ret)
377939f1cceSKalle Valo 		return ret;
378939f1cceSKalle Valo 
379939f1cceSKalle Valo 	ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
380939f1cceSKalle Valo 						 ATH6KL_FWLOG_VALID_MASK,
381939f1cceSKalle Valo 						 ar->debug.fwlog_mask);
382939f1cceSKalle Valo 	if (ret)
383939f1cceSKalle Valo 		return ret;
384939f1cceSKalle Valo 
385939f1cceSKalle Valo 	return count;
386939f1cceSKalle Valo }
387939f1cceSKalle Valo 
388939f1cceSKalle Valo static const struct file_operations fops_fwlog_mask = {
389939f1cceSKalle Valo 	.open = ath6kl_debugfs_open,
390939f1cceSKalle Valo 	.read = ath6kl_fwlog_mask_read,
391939f1cceSKalle Valo 	.write = ath6kl_fwlog_mask_write,
392939f1cceSKalle Valo 	.owner = THIS_MODULE,
393939f1cceSKalle Valo 	.llseek = default_llseek,
394939f1cceSKalle Valo };
395939f1cceSKalle Valo 
39603f68a95SVasanthakumar Thiagarajan static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
39703f68a95SVasanthakumar Thiagarajan 				   size_t count, loff_t *ppos)
39803f68a95SVasanthakumar Thiagarajan {
39903f68a95SVasanthakumar Thiagarajan 	struct ath6kl *ar = file->private_data;
40003f68a95SVasanthakumar Thiagarajan 	struct target_stats *tgt_stats = &ar->target_stats;
40103f68a95SVasanthakumar Thiagarajan 	char *buf;
40203f68a95SVasanthakumar Thiagarajan 	unsigned int len = 0, buf_len = 1500;
40303f68a95SVasanthakumar Thiagarajan 	int i;
40403f68a95SVasanthakumar Thiagarajan 	long left;
40503f68a95SVasanthakumar Thiagarajan 	ssize_t ret_cnt;
40603f68a95SVasanthakumar Thiagarajan 
40703f68a95SVasanthakumar Thiagarajan 	buf = kzalloc(buf_len, GFP_KERNEL);
40803f68a95SVasanthakumar Thiagarajan 	if (!buf)
40903f68a95SVasanthakumar Thiagarajan 		return -ENOMEM;
41003f68a95SVasanthakumar Thiagarajan 
41103f68a95SVasanthakumar Thiagarajan 	if (down_interruptible(&ar->sem)) {
41203f68a95SVasanthakumar Thiagarajan 		kfree(buf);
41303f68a95SVasanthakumar Thiagarajan 		return -EBUSY;
41403f68a95SVasanthakumar Thiagarajan 	}
41503f68a95SVasanthakumar Thiagarajan 
41603f68a95SVasanthakumar Thiagarajan 	set_bit(STATS_UPDATE_PEND, &ar->flag);
41703f68a95SVasanthakumar Thiagarajan 
41803f68a95SVasanthakumar Thiagarajan 	if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
41903f68a95SVasanthakumar Thiagarajan 		up(&ar->sem);
42003f68a95SVasanthakumar Thiagarajan 		kfree(buf);
42103f68a95SVasanthakumar Thiagarajan 		return -EIO;
42203f68a95SVasanthakumar Thiagarajan 	}
42303f68a95SVasanthakumar Thiagarajan 
42403f68a95SVasanthakumar Thiagarajan 	left = wait_event_interruptible_timeout(ar->event_wq,
42503f68a95SVasanthakumar Thiagarajan 						!test_bit(STATS_UPDATE_PEND,
42603f68a95SVasanthakumar Thiagarajan 						&ar->flag), WMI_TIMEOUT);
42703f68a95SVasanthakumar Thiagarajan 
42803f68a95SVasanthakumar Thiagarajan 	up(&ar->sem);
42903f68a95SVasanthakumar Thiagarajan 
43003f68a95SVasanthakumar Thiagarajan 	if (left <= 0) {
43103f68a95SVasanthakumar Thiagarajan 		kfree(buf);
43203f68a95SVasanthakumar Thiagarajan 		return -ETIMEDOUT;
43303f68a95SVasanthakumar Thiagarajan 	}
43403f68a95SVasanthakumar Thiagarajan 
43503f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "\n");
43603f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s\n",
43703f68a95SVasanthakumar Thiagarajan 			 "Target Tx stats");
43803f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
43903f68a95SVasanthakumar Thiagarajan 			 "=================");
44003f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
44103f68a95SVasanthakumar Thiagarajan 			 "Ucast packets", tgt_stats->tx_ucast_pkt);
44203f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
44303f68a95SVasanthakumar Thiagarajan 			 "Bcast packets", tgt_stats->tx_bcast_pkt);
44403f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
44503f68a95SVasanthakumar Thiagarajan 			 "Ucast byte", tgt_stats->tx_ucast_byte);
44603f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
44703f68a95SVasanthakumar Thiagarajan 			 "Bcast byte", tgt_stats->tx_bcast_byte);
44803f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
44903f68a95SVasanthakumar Thiagarajan 			 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
45003f68a95SVasanthakumar Thiagarajan 	for (i = 0; i < 4; i++)
45103f68a95SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, buf_len - len,
45203f68a95SVasanthakumar Thiagarajan 				 "%18s %d %10llu\n", "PER on ac",
45303f68a95SVasanthakumar Thiagarajan 				 i, tgt_stats->tx_pkt_per_ac[i]);
45403f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
45503f68a95SVasanthakumar Thiagarajan 			 "Error", tgt_stats->tx_err);
45603f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
45703f68a95SVasanthakumar Thiagarajan 			 "Fail count", tgt_stats->tx_fail_cnt);
45803f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
45903f68a95SVasanthakumar Thiagarajan 			 "Retry count", tgt_stats->tx_retry_cnt);
46003f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
46103f68a95SVasanthakumar Thiagarajan 			 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
46203f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
46303f68a95SVasanthakumar Thiagarajan 			 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
46403f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
46503f68a95SVasanthakumar Thiagarajan 			 "TKIP counter measure used",
46603f68a95SVasanthakumar Thiagarajan 			 tgt_stats->tkip_cnter_measures_invoked);
46703f68a95SVasanthakumar Thiagarajan 
46803f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s\n",
46903f68a95SVasanthakumar Thiagarajan 			 "Target Rx stats");
47003f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s\n",
47103f68a95SVasanthakumar Thiagarajan 			 "=================");
47203f68a95SVasanthakumar Thiagarajan 
47303f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
47403f68a95SVasanthakumar Thiagarajan 			 "Ucast packets", tgt_stats->rx_ucast_pkt);
47503f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
47603f68a95SVasanthakumar Thiagarajan 			 "Ucast Rate", tgt_stats->rx_ucast_rate);
47703f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
47803f68a95SVasanthakumar Thiagarajan 			 "Bcast packets", tgt_stats->rx_bcast_pkt);
47903f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
48003f68a95SVasanthakumar Thiagarajan 			 "Ucast byte", tgt_stats->rx_ucast_byte);
48103f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
48203f68a95SVasanthakumar Thiagarajan 			 "Bcast byte", tgt_stats->rx_bcast_byte);
48303f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
48403f68a95SVasanthakumar Thiagarajan 			 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
48503f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
48603f68a95SVasanthakumar Thiagarajan 			 "Error", tgt_stats->rx_err);
48703f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
48803f68a95SVasanthakumar Thiagarajan 			 "CRC Err", tgt_stats->rx_crc_err);
48903f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
49003f68a95SVasanthakumar Thiagarajan 			 "Key chache miss", tgt_stats->rx_key_cache_miss);
49103f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
49203f68a95SVasanthakumar Thiagarajan 			 "Decrypt Err", tgt_stats->rx_decrypt_err);
49303f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
49403f68a95SVasanthakumar Thiagarajan 			 "Duplicate frame", tgt_stats->rx_dupl_frame);
49503f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
49603f68a95SVasanthakumar Thiagarajan 			 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
49703f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
49803f68a95SVasanthakumar Thiagarajan 			 "TKIP format err", tgt_stats->tkip_fmt_err);
49903f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
50003f68a95SVasanthakumar Thiagarajan 			 "CCMP format Err", tgt_stats->ccmp_fmt_err);
50103f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
50203f68a95SVasanthakumar Thiagarajan 			 "CCMP Replay Err", tgt_stats->ccmp_replays);
50303f68a95SVasanthakumar Thiagarajan 
50403f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s\n",
50503f68a95SVasanthakumar Thiagarajan 			 "Misc Target stats");
50603f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s\n",
50703f68a95SVasanthakumar Thiagarajan 			 "=================");
50803f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
50903f68a95SVasanthakumar Thiagarajan 			 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
51003f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
51103f68a95SVasanthakumar Thiagarajan 			 "Num Connects", tgt_stats->cs_connect_cnt);
51203f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
51303f68a95SVasanthakumar Thiagarajan 			 "Num disconnects", tgt_stats->cs_discon_cnt);
51403f68a95SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
51503f68a95SVasanthakumar Thiagarajan 			 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
51603f68a95SVasanthakumar Thiagarajan 
51703f68a95SVasanthakumar Thiagarajan 	if (len > buf_len)
51803f68a95SVasanthakumar Thiagarajan 		len = buf_len;
51903f68a95SVasanthakumar Thiagarajan 
52003f68a95SVasanthakumar Thiagarajan 	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
52103f68a95SVasanthakumar Thiagarajan 
52203f68a95SVasanthakumar Thiagarajan 	kfree(buf);
52303f68a95SVasanthakumar Thiagarajan 	return ret_cnt;
52403f68a95SVasanthakumar Thiagarajan }
52503f68a95SVasanthakumar Thiagarajan 
52603f68a95SVasanthakumar Thiagarajan static const struct file_operations fops_tgt_stats = {
52703f68a95SVasanthakumar Thiagarajan 	.read = read_file_tgt_stats,
52803f68a95SVasanthakumar Thiagarajan 	.open = ath6kl_debugfs_open,
52903f68a95SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
53003f68a95SVasanthakumar Thiagarajan 	.llseek = default_llseek,
53103f68a95SVasanthakumar Thiagarajan };
53203f68a95SVasanthakumar Thiagarajan 
53378fc4856SVasanthakumar Thiagarajan #define print_credit_info(fmt_str, ep_list_field)		\
53478fc4856SVasanthakumar Thiagarajan 	(len += scnprintf(buf + len, buf_len - len, fmt_str,	\
53578fc4856SVasanthakumar Thiagarajan 			 ep_list->ep_list_field))
53678fc4856SVasanthakumar Thiagarajan #define CREDIT_INFO_DISPLAY_STRING_LEN	200
53778fc4856SVasanthakumar Thiagarajan #define CREDIT_INFO_LEN	128
53878fc4856SVasanthakumar Thiagarajan 
53978fc4856SVasanthakumar Thiagarajan static ssize_t read_file_credit_dist_stats(struct file *file,
54078fc4856SVasanthakumar Thiagarajan 					   char __user *user_buf,
54178fc4856SVasanthakumar Thiagarajan 					   size_t count, loff_t *ppos)
54278fc4856SVasanthakumar Thiagarajan {
54378fc4856SVasanthakumar Thiagarajan 	struct ath6kl *ar = file->private_data;
54478fc4856SVasanthakumar Thiagarajan 	struct htc_target *target = ar->htc_target;
54578fc4856SVasanthakumar Thiagarajan 	struct htc_endpoint_credit_dist *ep_list;
54678fc4856SVasanthakumar Thiagarajan 	char *buf;
54778fc4856SVasanthakumar Thiagarajan 	unsigned int buf_len, len = 0;
54878fc4856SVasanthakumar Thiagarajan 	ssize_t ret_cnt;
54978fc4856SVasanthakumar Thiagarajan 
55078fc4856SVasanthakumar Thiagarajan 	buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
55178fc4856SVasanthakumar Thiagarajan 		  get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
55278fc4856SVasanthakumar Thiagarajan 	buf = kzalloc(buf_len, GFP_KERNEL);
55378fc4856SVasanthakumar Thiagarajan 	if (!buf)
55478fc4856SVasanthakumar Thiagarajan 		return -ENOMEM;
55578fc4856SVasanthakumar Thiagarajan 
55678fc4856SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
55778fc4856SVasanthakumar Thiagarajan 			 "Total Avail Credits: ",
55878fc4856SVasanthakumar Thiagarajan 			 target->cred_dist_cntxt->total_avail_credits);
55978fc4856SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
56078fc4856SVasanthakumar Thiagarajan 			 "Free credits :",
56178fc4856SVasanthakumar Thiagarajan 			 target->cred_dist_cntxt->cur_free_credits);
56278fc4856SVasanthakumar Thiagarajan 
56378fc4856SVasanthakumar Thiagarajan 	len += scnprintf(buf + len, buf_len - len,
56478fc4856SVasanthakumar Thiagarajan 			 " Epid  Flags    Cred_norm  Cred_min  Credits  Cred_assngd"
56578fc4856SVasanthakumar Thiagarajan 			 "  Seek_cred  Cred_sz  Cred_per_msg  Cred_to_dist"
56678fc4856SVasanthakumar Thiagarajan 			 "  qdepth\n");
56778fc4856SVasanthakumar Thiagarajan 
56878fc4856SVasanthakumar Thiagarajan 	list_for_each_entry(ep_list, &target->cred_dist_list, list) {
56978fc4856SVasanthakumar Thiagarajan 		print_credit_info("  %2d", endpoint);
57078fc4856SVasanthakumar Thiagarajan 		print_credit_info("%10x", dist_flags);
57178fc4856SVasanthakumar Thiagarajan 		print_credit_info("%8d", cred_norm);
57278fc4856SVasanthakumar Thiagarajan 		print_credit_info("%9d", cred_min);
57378fc4856SVasanthakumar Thiagarajan 		print_credit_info("%9d", credits);
57478fc4856SVasanthakumar Thiagarajan 		print_credit_info("%10d", cred_assngd);
57578fc4856SVasanthakumar Thiagarajan 		print_credit_info("%13d", seek_cred);
57678fc4856SVasanthakumar Thiagarajan 		print_credit_info("%12d", cred_sz);
57778fc4856SVasanthakumar Thiagarajan 		print_credit_info("%9d", cred_per_msg);
57878fc4856SVasanthakumar Thiagarajan 		print_credit_info("%14d", cred_to_dist);
57978fc4856SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, buf_len - len, "%12d\n",
58078fc4856SVasanthakumar Thiagarajan 				 get_queue_depth(&((struct htc_endpoint *)
58178fc4856SVasanthakumar Thiagarajan 						 ep_list->htc_rsvd)->txq));
58278fc4856SVasanthakumar Thiagarajan 	}
58378fc4856SVasanthakumar Thiagarajan 
58478fc4856SVasanthakumar Thiagarajan 	if (len > buf_len)
58578fc4856SVasanthakumar Thiagarajan 		len = buf_len;
58678fc4856SVasanthakumar Thiagarajan 
58778fc4856SVasanthakumar Thiagarajan 	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
58878fc4856SVasanthakumar Thiagarajan 	kfree(buf);
58978fc4856SVasanthakumar Thiagarajan 	return ret_cnt;
59078fc4856SVasanthakumar Thiagarajan }
59178fc4856SVasanthakumar Thiagarajan 
59278fc4856SVasanthakumar Thiagarajan static const struct file_operations fops_credit_dist_stats = {
59378fc4856SVasanthakumar Thiagarajan 	.read = read_file_credit_dist_stats,
59478fc4856SVasanthakumar Thiagarajan 	.open = ath6kl_debugfs_open,
59578fc4856SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
59678fc4856SVasanthakumar Thiagarajan 	.llseek = default_llseek,
59778fc4856SVasanthakumar Thiagarajan };
59878fc4856SVasanthakumar Thiagarajan 
599e8091281SJouni Malinen static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
600e8091281SJouni Malinen 					unsigned int buf_len, unsigned int len,
601e8091281SJouni Malinen 					int offset, const char *name)
602e8091281SJouni Malinen {
603e8091281SJouni Malinen 	int i;
604e8091281SJouni Malinen 	struct htc_endpoint_stats *ep_st;
605e8091281SJouni Malinen 	u32 *counter;
606e8091281SJouni Malinen 
607e8091281SJouni Malinen 	len += scnprintf(buf + len, buf_len - len, "%s:", name);
608e8091281SJouni Malinen 	for (i = 0; i < ENDPOINT_MAX; i++) {
609e8091281SJouni Malinen 		ep_st = &target->endpoint[i].ep_st;
610e8091281SJouni Malinen 		counter = ((u32 *) ep_st) + (offset / 4);
611e8091281SJouni Malinen 		len += scnprintf(buf + len, buf_len - len, " %u", *counter);
612e8091281SJouni Malinen 	}
613e8091281SJouni Malinen 	len += scnprintf(buf + len, buf_len - len, "\n");
614e8091281SJouni Malinen 
615e8091281SJouni Malinen 	return len;
616e8091281SJouni Malinen }
617e8091281SJouni Malinen 
618e8091281SJouni Malinen static ssize_t ath6kl_endpoint_stats_read(struct file *file,
619e8091281SJouni Malinen 					  char __user *user_buf,
620e8091281SJouni Malinen 					  size_t count, loff_t *ppos)
621e8091281SJouni Malinen {
622e8091281SJouni Malinen 	struct ath6kl *ar = file->private_data;
623e8091281SJouni Malinen 	struct htc_target *target = ar->htc_target;
624e8091281SJouni Malinen 	char *buf;
625e8091281SJouni Malinen 	unsigned int buf_len, len = 0;
626e8091281SJouni Malinen 	ssize_t ret_cnt;
627e8091281SJouni Malinen 
62817169329SJouni Malinen 	buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
62917169329SJouni Malinen 		(25 + ENDPOINT_MAX * 11);
63017169329SJouni Malinen 	buf = kmalloc(buf_len, GFP_KERNEL);
631e8091281SJouni Malinen 	if (!buf)
632e8091281SJouni Malinen 		return -ENOMEM;
633e8091281SJouni Malinen 
634e8091281SJouni Malinen #define EPSTAT(name)							\
635e8091281SJouni Malinen 	len = print_endpoint_stat(target, buf, buf_len, len,		\
636e8091281SJouni Malinen 				  offsetof(struct htc_endpoint_stats, name), \
637e8091281SJouni Malinen 				  #name)
638e8091281SJouni Malinen 	EPSTAT(cred_low_indicate);
639e8091281SJouni Malinen 	EPSTAT(tx_issued);
640e8091281SJouni Malinen 	EPSTAT(tx_pkt_bundled);
641e8091281SJouni Malinen 	EPSTAT(tx_bundles);
642e8091281SJouni Malinen 	EPSTAT(tx_dropped);
643e8091281SJouni Malinen 	EPSTAT(tx_cred_rpt);
644e8091281SJouni Malinen 	EPSTAT(cred_rpt_from_rx);
64517169329SJouni Malinen 	EPSTAT(cred_rpt_from_other);
646e8091281SJouni Malinen 	EPSTAT(cred_rpt_ep0);
647e8091281SJouni Malinen 	EPSTAT(cred_from_rx);
648e8091281SJouni Malinen 	EPSTAT(cred_from_other);
649e8091281SJouni Malinen 	EPSTAT(cred_from_ep0);
650e8091281SJouni Malinen 	EPSTAT(cred_cosumd);
651e8091281SJouni Malinen 	EPSTAT(cred_retnd);
652e8091281SJouni Malinen 	EPSTAT(rx_pkts);
653e8091281SJouni Malinen 	EPSTAT(rx_lkahds);
654e8091281SJouni Malinen 	EPSTAT(rx_bundl);
655e8091281SJouni Malinen 	EPSTAT(rx_bundle_lkahd);
656e8091281SJouni Malinen 	EPSTAT(rx_bundle_from_hdr);
657e8091281SJouni Malinen 	EPSTAT(rx_alloc_thresh_hit);
658e8091281SJouni Malinen 	EPSTAT(rxalloc_thresh_byte);
659e8091281SJouni Malinen #undef EPSTAT
660e8091281SJouni Malinen 
661e8091281SJouni Malinen 	if (len > buf_len)
662e8091281SJouni Malinen 		len = buf_len;
663e8091281SJouni Malinen 
664e8091281SJouni Malinen 	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
665e8091281SJouni Malinen 	kfree(buf);
666e8091281SJouni Malinen 	return ret_cnt;
667e8091281SJouni Malinen }
668e8091281SJouni Malinen 
669e8091281SJouni Malinen static ssize_t ath6kl_endpoint_stats_write(struct file *file,
670e8091281SJouni Malinen 					   const char __user *user_buf,
671e8091281SJouni Malinen 					   size_t count, loff_t *ppos)
672e8091281SJouni Malinen {
673e8091281SJouni Malinen 	struct ath6kl *ar = file->private_data;
674e8091281SJouni Malinen 	struct htc_target *target = ar->htc_target;
675e8091281SJouni Malinen 	int ret, i;
676e8091281SJouni Malinen 	u32 val;
677e8091281SJouni Malinen 	struct htc_endpoint_stats *ep_st;
678e8091281SJouni Malinen 
679e8091281SJouni Malinen 	ret = kstrtou32_from_user(user_buf, count, 0, &val);
680e8091281SJouni Malinen 	if (ret)
681e8091281SJouni Malinen 		return ret;
682e8091281SJouni Malinen 	if (val == 0) {
683e8091281SJouni Malinen 		for (i = 0; i < ENDPOINT_MAX; i++) {
684e8091281SJouni Malinen 			ep_st = &target->endpoint[i].ep_st;
685e8091281SJouni Malinen 			memset(ep_st, 0, sizeof(*ep_st));
686e8091281SJouni Malinen 		}
687e8091281SJouni Malinen 	}
688e8091281SJouni Malinen 
689e8091281SJouni Malinen 	return count;
690e8091281SJouni Malinen }
691e8091281SJouni Malinen 
692e8091281SJouni Malinen static const struct file_operations fops_endpoint_stats = {
693e8091281SJouni Malinen 	.open = ath6kl_debugfs_open,
694e8091281SJouni Malinen 	.read = ath6kl_endpoint_stats_read,
695e8091281SJouni Malinen 	.write = ath6kl_endpoint_stats_write,
696e8091281SJouni Malinen 	.owner = THIS_MODULE,
697e8091281SJouni Malinen 	.llseek = default_llseek,
698e8091281SJouni Malinen };
699e8091281SJouni Malinen 
70091d57de5SVasanthakumar Thiagarajan static unsigned long ath6kl_get_num_reg(void)
70191d57de5SVasanthakumar Thiagarajan {
70291d57de5SVasanthakumar Thiagarajan 	int i;
70391d57de5SVasanthakumar Thiagarajan 	unsigned long n_reg = 0;
70491d57de5SVasanthakumar Thiagarajan 
70591d57de5SVasanthakumar Thiagarajan 	for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
70691d57de5SVasanthakumar Thiagarajan 		n_reg = n_reg +
70791d57de5SVasanthakumar Thiagarajan 		     (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
70891d57de5SVasanthakumar Thiagarajan 
70991d57de5SVasanthakumar Thiagarajan 	return n_reg;
71091d57de5SVasanthakumar Thiagarajan }
71191d57de5SVasanthakumar Thiagarajan 
71291d57de5SVasanthakumar Thiagarajan static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
71391d57de5SVasanthakumar Thiagarajan {
71491d57de5SVasanthakumar Thiagarajan 	int i;
71591d57de5SVasanthakumar Thiagarajan 
71691d57de5SVasanthakumar Thiagarajan 	for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
71791d57de5SVasanthakumar Thiagarajan 		if (reg_addr >= diag_reg[i].reg_start &&
71891d57de5SVasanthakumar Thiagarajan 		    reg_addr <= diag_reg[i].reg_end)
71991d57de5SVasanthakumar Thiagarajan 			return true;
72091d57de5SVasanthakumar Thiagarajan 	}
72191d57de5SVasanthakumar Thiagarajan 
72291d57de5SVasanthakumar Thiagarajan 	return false;
72391d57de5SVasanthakumar Thiagarajan }
72491d57de5SVasanthakumar Thiagarajan 
72591d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
72691d57de5SVasanthakumar Thiagarajan 				    size_t count, loff_t *ppos)
72791d57de5SVasanthakumar Thiagarajan {
72891d57de5SVasanthakumar Thiagarajan 	struct ath6kl *ar = file->private_data;
72991d57de5SVasanthakumar Thiagarajan 	u8 buf[50];
73091d57de5SVasanthakumar Thiagarajan 	unsigned int len = 0;
73191d57de5SVasanthakumar Thiagarajan 
73291d57de5SVasanthakumar Thiagarajan 	if (ar->debug.dbgfs_diag_reg)
73391d57de5SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
73491d57de5SVasanthakumar Thiagarajan 				ar->debug.dbgfs_diag_reg);
73591d57de5SVasanthakumar Thiagarajan 	else
73691d57de5SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, sizeof(buf) - len,
73791d57de5SVasanthakumar Thiagarajan 				 "All diag registers\n");
73891d57de5SVasanthakumar Thiagarajan 
73991d57de5SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
74091d57de5SVasanthakumar Thiagarajan }
74191d57de5SVasanthakumar Thiagarajan 
74291d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regread_write(struct file *file,
74391d57de5SVasanthakumar Thiagarajan 				    const char __user *user_buf,
74491d57de5SVasanthakumar Thiagarajan 				    size_t count, loff_t *ppos)
74591d57de5SVasanthakumar Thiagarajan {
74691d57de5SVasanthakumar Thiagarajan 	struct ath6kl *ar = file->private_data;
74791d57de5SVasanthakumar Thiagarajan 	u8 buf[50];
74891d57de5SVasanthakumar Thiagarajan 	unsigned int len;
74991d57de5SVasanthakumar Thiagarajan 	unsigned long reg_addr;
75091d57de5SVasanthakumar Thiagarajan 
75191d57de5SVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
75291d57de5SVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
75391d57de5SVasanthakumar Thiagarajan 		return -EFAULT;
75491d57de5SVasanthakumar Thiagarajan 
75591d57de5SVasanthakumar Thiagarajan 	buf[len] = '\0';
75691d57de5SVasanthakumar Thiagarajan 
75791d57de5SVasanthakumar Thiagarajan 	if (strict_strtoul(buf, 0, &reg_addr))
75891d57de5SVasanthakumar Thiagarajan 		return -EINVAL;
75991d57de5SVasanthakumar Thiagarajan 
76091d57de5SVasanthakumar Thiagarajan 	if ((reg_addr % 4) != 0)
76191d57de5SVasanthakumar Thiagarajan 		return -EINVAL;
76291d57de5SVasanthakumar Thiagarajan 
76391d57de5SVasanthakumar Thiagarajan 	if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
76491d57de5SVasanthakumar Thiagarajan 		return -EINVAL;
76591d57de5SVasanthakumar Thiagarajan 
76691d57de5SVasanthakumar Thiagarajan 	ar->debug.dbgfs_diag_reg = reg_addr;
76791d57de5SVasanthakumar Thiagarajan 
76891d57de5SVasanthakumar Thiagarajan 	return count;
76991d57de5SVasanthakumar Thiagarajan }
77091d57de5SVasanthakumar Thiagarajan 
77191d57de5SVasanthakumar Thiagarajan static const struct file_operations fops_diag_reg_read = {
77291d57de5SVasanthakumar Thiagarajan 	.read = ath6kl_regread_read,
77391d57de5SVasanthakumar Thiagarajan 	.write = ath6kl_regread_write,
77491d57de5SVasanthakumar Thiagarajan 	.open = ath6kl_debugfs_open,
77591d57de5SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
77691d57de5SVasanthakumar Thiagarajan 	.llseek = default_llseek,
77791d57de5SVasanthakumar Thiagarajan };
77891d57de5SVasanthakumar Thiagarajan 
77991d57de5SVasanthakumar Thiagarajan static int ath6kl_regdump_open(struct inode *inode, struct file *file)
78091d57de5SVasanthakumar Thiagarajan {
78191d57de5SVasanthakumar Thiagarajan 	struct ath6kl *ar = inode->i_private;
78291d57de5SVasanthakumar Thiagarajan 	u8 *buf;
78391d57de5SVasanthakumar Thiagarajan 	unsigned long int reg_len;
78491d57de5SVasanthakumar Thiagarajan 	unsigned int len = 0, n_reg;
78591d57de5SVasanthakumar Thiagarajan 	u32 addr;
78691d57de5SVasanthakumar Thiagarajan 	__le32 reg_val;
78791d57de5SVasanthakumar Thiagarajan 	int i, status;
78891d57de5SVasanthakumar Thiagarajan 
78991d57de5SVasanthakumar Thiagarajan 	/* Dump all the registers if no register is specified */
79091d57de5SVasanthakumar Thiagarajan 	if (!ar->debug.dbgfs_diag_reg)
79191d57de5SVasanthakumar Thiagarajan 		n_reg = ath6kl_get_num_reg();
79291d57de5SVasanthakumar Thiagarajan 	else
79391d57de5SVasanthakumar Thiagarajan 		n_reg = 1;
79491d57de5SVasanthakumar Thiagarajan 
79591d57de5SVasanthakumar Thiagarajan 	reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
79691d57de5SVasanthakumar Thiagarajan 	if (n_reg > 1)
79791d57de5SVasanthakumar Thiagarajan 		reg_len += REGTYPE_STR_LEN;
79891d57de5SVasanthakumar Thiagarajan 
79991d57de5SVasanthakumar Thiagarajan 	buf = vmalloc(reg_len);
80091d57de5SVasanthakumar Thiagarajan 	if (!buf)
80191d57de5SVasanthakumar Thiagarajan 		return -ENOMEM;
80291d57de5SVasanthakumar Thiagarajan 
80391d57de5SVasanthakumar Thiagarajan 	if (n_reg == 1) {
80491d57de5SVasanthakumar Thiagarajan 		addr = ar->debug.dbgfs_diag_reg;
80591d57de5SVasanthakumar Thiagarajan 
80691d57de5SVasanthakumar Thiagarajan 		status = ath6kl_diag_read32(ar,
80791d57de5SVasanthakumar Thiagarajan 				TARG_VTOP(ar->target_type, addr),
80891d57de5SVasanthakumar Thiagarajan 				(u32 *)&reg_val);
80991d57de5SVasanthakumar Thiagarajan 		if (status)
81091d57de5SVasanthakumar Thiagarajan 			goto fail_reg_read;
81191d57de5SVasanthakumar Thiagarajan 
81291d57de5SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, reg_len - len,
81391d57de5SVasanthakumar Thiagarajan 				 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
81491d57de5SVasanthakumar Thiagarajan 		goto done;
81591d57de5SVasanthakumar Thiagarajan 	}
81691d57de5SVasanthakumar Thiagarajan 
81791d57de5SVasanthakumar Thiagarajan 	for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
81891d57de5SVasanthakumar Thiagarajan 		len += scnprintf(buf + len, reg_len - len,
81991d57de5SVasanthakumar Thiagarajan 				"%s\n", diag_reg[i].reg_info);
82091d57de5SVasanthakumar Thiagarajan 		for (addr = diag_reg[i].reg_start;
82191d57de5SVasanthakumar Thiagarajan 		     addr <= diag_reg[i].reg_end; addr += 4) {
82291d57de5SVasanthakumar Thiagarajan 			status = ath6kl_diag_read32(ar,
82391d57de5SVasanthakumar Thiagarajan 					TARG_VTOP(ar->target_type, addr),
82491d57de5SVasanthakumar Thiagarajan 					(u32 *)&reg_val);
82591d57de5SVasanthakumar Thiagarajan 			if (status)
82691d57de5SVasanthakumar Thiagarajan 				goto fail_reg_read;
82791d57de5SVasanthakumar Thiagarajan 
82891d57de5SVasanthakumar Thiagarajan 			len += scnprintf(buf + len, reg_len - len,
82991d57de5SVasanthakumar Thiagarajan 					"0x%06x 0x%08x\n",
83091d57de5SVasanthakumar Thiagarajan 					addr, le32_to_cpu(reg_val));
83191d57de5SVasanthakumar Thiagarajan 		}
83291d57de5SVasanthakumar Thiagarajan 	}
83391d57de5SVasanthakumar Thiagarajan 
83491d57de5SVasanthakumar Thiagarajan done:
83591d57de5SVasanthakumar Thiagarajan 	file->private_data = buf;
83691d57de5SVasanthakumar Thiagarajan 	return 0;
83791d57de5SVasanthakumar Thiagarajan 
83891d57de5SVasanthakumar Thiagarajan fail_reg_read:
83991d57de5SVasanthakumar Thiagarajan 	ath6kl_warn("Unable to read memory:%u\n", addr);
84091d57de5SVasanthakumar Thiagarajan 	vfree(buf);
84191d57de5SVasanthakumar Thiagarajan 	return -EIO;
84291d57de5SVasanthakumar Thiagarajan }
84391d57de5SVasanthakumar Thiagarajan 
84491d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
84591d57de5SVasanthakumar Thiagarajan 				  size_t count, loff_t *ppos)
84691d57de5SVasanthakumar Thiagarajan {
84791d57de5SVasanthakumar Thiagarajan 	u8 *buf = file->private_data;
84891d57de5SVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
84991d57de5SVasanthakumar Thiagarajan }
85091d57de5SVasanthakumar Thiagarajan 
85191d57de5SVasanthakumar Thiagarajan static int ath6kl_regdump_release(struct inode *inode, struct file *file)
85291d57de5SVasanthakumar Thiagarajan {
85391d57de5SVasanthakumar Thiagarajan 	vfree(file->private_data);
85491d57de5SVasanthakumar Thiagarajan 	return 0;
85591d57de5SVasanthakumar Thiagarajan }
85691d57de5SVasanthakumar Thiagarajan 
85791d57de5SVasanthakumar Thiagarajan static const struct file_operations fops_reg_dump = {
85891d57de5SVasanthakumar Thiagarajan 	.open = ath6kl_regdump_open,
85991d57de5SVasanthakumar Thiagarajan 	.read = ath6kl_regdump_read,
86091d57de5SVasanthakumar Thiagarajan 	.release = ath6kl_regdump_release,
86191d57de5SVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
86291d57de5SVasanthakumar Thiagarajan 	.llseek = default_llseek,
86391d57de5SVasanthakumar Thiagarajan };
86491d57de5SVasanthakumar Thiagarajan 
865e5090444SVivek Natarajan static ssize_t ath6kl_lrssi_roam_write(struct file *file,
866e5090444SVivek Natarajan 				       const char __user *user_buf,
867e5090444SVivek Natarajan 				       size_t count, loff_t *ppos)
868e5090444SVivek Natarajan {
869e5090444SVivek Natarajan 	struct ath6kl *ar = file->private_data;
870e5090444SVivek Natarajan 	unsigned long lrssi_roam_threshold;
871e5090444SVivek Natarajan 	char buf[32];
872e5090444SVivek Natarajan 	ssize_t len;
873e5090444SVivek Natarajan 
874e5090444SVivek Natarajan 	len = min(count, sizeof(buf) - 1);
875e5090444SVivek Natarajan 	if (copy_from_user(buf, user_buf, len))
876e5090444SVivek Natarajan 		return -EFAULT;
877e5090444SVivek Natarajan 
878e5090444SVivek Natarajan 	buf[len] = '\0';
879e5090444SVivek Natarajan 	if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
880e5090444SVivek Natarajan 		return -EINVAL;
881e5090444SVivek Natarajan 
882e5090444SVivek Natarajan 	ar->lrssi_roam_threshold = lrssi_roam_threshold;
883e5090444SVivek Natarajan 
884e5090444SVivek Natarajan 	ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
885e5090444SVivek Natarajan 
886e5090444SVivek Natarajan 	return count;
887e5090444SVivek Natarajan }
888e5090444SVivek Natarajan 
889e5090444SVivek Natarajan static ssize_t ath6kl_lrssi_roam_read(struct file *file,
890e5090444SVivek Natarajan 				      char __user *user_buf,
891e5090444SVivek Natarajan 				      size_t count, loff_t *ppos)
892e5090444SVivek Natarajan {
893e5090444SVivek Natarajan 	struct ath6kl *ar = file->private_data;
894e5090444SVivek Natarajan 	char buf[32];
895e5090444SVivek Natarajan 	unsigned int len;
896e5090444SVivek Natarajan 
897e5090444SVivek Natarajan 	len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
898e5090444SVivek Natarajan 
899e5090444SVivek Natarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
900e5090444SVivek Natarajan }
901e5090444SVivek Natarajan 
902e5090444SVivek Natarajan static const struct file_operations fops_lrssi_roam_threshold = {
903e5090444SVivek Natarajan 	.read = ath6kl_lrssi_roam_read,
904e5090444SVivek Natarajan 	.write = ath6kl_lrssi_roam_write,
905e5090444SVivek Natarajan 	.open = ath6kl_debugfs_open,
906e5090444SVivek Natarajan 	.owner = THIS_MODULE,
907e5090444SVivek Natarajan 	.llseek = default_llseek,
908e5090444SVivek Natarajan };
909e5090444SVivek Natarajan 
910252c068bSVasanthakumar Thiagarajan static ssize_t ath6kl_regwrite_read(struct file *file,
911252c068bSVasanthakumar Thiagarajan 				    char __user *user_buf,
912252c068bSVasanthakumar Thiagarajan 				    size_t count, loff_t *ppos)
913252c068bSVasanthakumar Thiagarajan {
914252c068bSVasanthakumar Thiagarajan 	struct ath6kl *ar = file->private_data;
915252c068bSVasanthakumar Thiagarajan 	u8 buf[32];
916252c068bSVasanthakumar Thiagarajan 	unsigned int len = 0;
917252c068bSVasanthakumar Thiagarajan 
918252c068bSVasanthakumar Thiagarajan 	len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
919252c068bSVasanthakumar Thiagarajan 			ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
920252c068bSVasanthakumar Thiagarajan 
921252c068bSVasanthakumar Thiagarajan 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
922252c068bSVasanthakumar Thiagarajan }
923252c068bSVasanthakumar Thiagarajan 
924252c068bSVasanthakumar Thiagarajan static ssize_t ath6kl_regwrite_write(struct file *file,
925252c068bSVasanthakumar Thiagarajan 				     const char __user *user_buf,
926252c068bSVasanthakumar Thiagarajan 				     size_t count, loff_t *ppos)
927252c068bSVasanthakumar Thiagarajan {
928252c068bSVasanthakumar Thiagarajan 	struct ath6kl *ar = file->private_data;
929252c068bSVasanthakumar Thiagarajan 	char buf[32];
930252c068bSVasanthakumar Thiagarajan 	char *sptr, *token;
931252c068bSVasanthakumar Thiagarajan 	unsigned int len = 0;
932252c068bSVasanthakumar Thiagarajan 	u32 reg_addr, reg_val;
933252c068bSVasanthakumar Thiagarajan 
934252c068bSVasanthakumar Thiagarajan 	len = min(count, sizeof(buf) - 1);
935252c068bSVasanthakumar Thiagarajan 	if (copy_from_user(buf, user_buf, len))
936252c068bSVasanthakumar Thiagarajan 		return -EFAULT;
937252c068bSVasanthakumar Thiagarajan 
938252c068bSVasanthakumar Thiagarajan 	buf[len] = '\0';
939252c068bSVasanthakumar Thiagarajan 	sptr = buf;
940252c068bSVasanthakumar Thiagarajan 
941252c068bSVasanthakumar Thiagarajan 	token = strsep(&sptr, "=");
942252c068bSVasanthakumar Thiagarajan 	if (!token)
943252c068bSVasanthakumar Thiagarajan 		return -EINVAL;
944252c068bSVasanthakumar Thiagarajan 
945252c068bSVasanthakumar Thiagarajan 	if (kstrtou32(token, 0, &reg_addr))
946252c068bSVasanthakumar Thiagarajan 		return -EINVAL;
947252c068bSVasanthakumar Thiagarajan 
948252c068bSVasanthakumar Thiagarajan 	if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
949252c068bSVasanthakumar Thiagarajan 		return -EINVAL;
950252c068bSVasanthakumar Thiagarajan 
951252c068bSVasanthakumar Thiagarajan 	if (kstrtou32(sptr, 0, &reg_val))
952252c068bSVasanthakumar Thiagarajan 		return -EINVAL;
953252c068bSVasanthakumar Thiagarajan 
954252c068bSVasanthakumar Thiagarajan 	ar->debug.diag_reg_addr_wr = reg_addr;
955252c068bSVasanthakumar Thiagarajan 	ar->debug.diag_reg_val_wr = reg_val;
956252c068bSVasanthakumar Thiagarajan 
957252c068bSVasanthakumar Thiagarajan 	if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
958252c068bSVasanthakumar Thiagarajan 				cpu_to_le32(ar->debug.diag_reg_val_wr)))
959252c068bSVasanthakumar Thiagarajan 		return -EIO;
960252c068bSVasanthakumar Thiagarajan 
961252c068bSVasanthakumar Thiagarajan 	return count;
962252c068bSVasanthakumar Thiagarajan }
963252c068bSVasanthakumar Thiagarajan 
964252c068bSVasanthakumar Thiagarajan static const struct file_operations fops_diag_reg_write = {
965252c068bSVasanthakumar Thiagarajan 	.read = ath6kl_regwrite_read,
966252c068bSVasanthakumar Thiagarajan 	.write = ath6kl_regwrite_write,
967252c068bSVasanthakumar Thiagarajan 	.open = ath6kl_debugfs_open,
968252c068bSVasanthakumar Thiagarajan 	.owner = THIS_MODULE,
969252c068bSVasanthakumar Thiagarajan 	.llseek = default_llseek,
970252c068bSVasanthakumar Thiagarajan };
971252c068bSVasanthakumar Thiagarajan 
9724b28a80dSJouni Malinen int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
9734b28a80dSJouni Malinen 				size_t len)
9744b28a80dSJouni Malinen {
9754b28a80dSJouni Malinen 	const struct wmi_target_roam_tbl *tbl;
9764b28a80dSJouni Malinen 	u16 num_entries;
9774b28a80dSJouni Malinen 
9784b28a80dSJouni Malinen 	if (len < sizeof(*tbl))
9794b28a80dSJouni Malinen 		return -EINVAL;
9804b28a80dSJouni Malinen 
9814b28a80dSJouni Malinen 	tbl = (const struct wmi_target_roam_tbl *) buf;
9824b28a80dSJouni Malinen 	num_entries = le16_to_cpu(tbl->num_entries);
9834b28a80dSJouni Malinen 	if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
9844b28a80dSJouni Malinen 	    len)
9854b28a80dSJouni Malinen 		return -EINVAL;
9864b28a80dSJouni Malinen 
9874b28a80dSJouni Malinen 	if (ar->debug.roam_tbl == NULL ||
9884b28a80dSJouni Malinen 	    ar->debug.roam_tbl_len < (unsigned int) len) {
9894b28a80dSJouni Malinen 		kfree(ar->debug.roam_tbl);
9904b28a80dSJouni Malinen 		ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
9914b28a80dSJouni Malinen 		if (ar->debug.roam_tbl == NULL)
9924b28a80dSJouni Malinen 			return -ENOMEM;
9934b28a80dSJouni Malinen 	}
9944b28a80dSJouni Malinen 
9954b28a80dSJouni Malinen 	memcpy(ar->debug.roam_tbl, buf, len);
9964b28a80dSJouni Malinen 	ar->debug.roam_tbl_len = len;
9974b28a80dSJouni Malinen 
9984b28a80dSJouni Malinen 	if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
9994b28a80dSJouni Malinen 		clear_bit(ROAM_TBL_PEND, &ar->flag);
10004b28a80dSJouni Malinen 		wake_up(&ar->event_wq);
10014b28a80dSJouni Malinen 	}
10024b28a80dSJouni Malinen 
10034b28a80dSJouni Malinen 	return 0;
10044b28a80dSJouni Malinen }
10054b28a80dSJouni Malinen 
10064b28a80dSJouni Malinen static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
10074b28a80dSJouni Malinen 				      size_t count, loff_t *ppos)
10084b28a80dSJouni Malinen {
10094b28a80dSJouni Malinen 	struct ath6kl *ar = file->private_data;
10104b28a80dSJouni Malinen 	int ret;
10114b28a80dSJouni Malinen 	long left;
10124b28a80dSJouni Malinen 	struct wmi_target_roam_tbl *tbl;
10134b28a80dSJouni Malinen 	u16 num_entries, i;
10144b28a80dSJouni Malinen 	char *buf;
10154b28a80dSJouni Malinen 	unsigned int len, buf_len;
10164b28a80dSJouni Malinen 	ssize_t ret_cnt;
10174b28a80dSJouni Malinen 
10184b28a80dSJouni Malinen 	if (down_interruptible(&ar->sem))
10194b28a80dSJouni Malinen 		return -EBUSY;
10204b28a80dSJouni Malinen 
10214b28a80dSJouni Malinen 	set_bit(ROAM_TBL_PEND, &ar->flag);
10224b28a80dSJouni Malinen 
10234b28a80dSJouni Malinen 	ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
10244b28a80dSJouni Malinen 	if (ret) {
10254b28a80dSJouni Malinen 		up(&ar->sem);
10264b28a80dSJouni Malinen 		return ret;
10274b28a80dSJouni Malinen 	}
10284b28a80dSJouni Malinen 
10294b28a80dSJouni Malinen 	left = wait_event_interruptible_timeout(
10304b28a80dSJouni Malinen 		ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
10314b28a80dSJouni Malinen 	up(&ar->sem);
10324b28a80dSJouni Malinen 
10334b28a80dSJouni Malinen 	if (left <= 0)
10344b28a80dSJouni Malinen 		return -ETIMEDOUT;
10354b28a80dSJouni Malinen 
10364b28a80dSJouni Malinen 	if (ar->debug.roam_tbl == NULL)
10374b28a80dSJouni Malinen 		return -ENOMEM;
10384b28a80dSJouni Malinen 
10394b28a80dSJouni Malinen 	tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
10404b28a80dSJouni Malinen 	num_entries = le16_to_cpu(tbl->num_entries);
10414b28a80dSJouni Malinen 
10424b28a80dSJouni Malinen 	buf_len = 100 + num_entries * 100;
10434b28a80dSJouni Malinen 	buf = kzalloc(buf_len, GFP_KERNEL);
10444b28a80dSJouni Malinen 	if (buf == NULL)
10454b28a80dSJouni Malinen 		return -ENOMEM;
10464b28a80dSJouni Malinen 	len = 0;
10474b28a80dSJouni Malinen 	len += scnprintf(buf + len, buf_len - len,
10484b28a80dSJouni Malinen 			 "roam_mode=%u\n\n"
10494b28a80dSJouni Malinen 			 "# roam_util bssid rssi rssidt last_rssi util bias\n",
10504b28a80dSJouni Malinen 			 le16_to_cpu(tbl->roam_mode));
10514b28a80dSJouni Malinen 
10524b28a80dSJouni Malinen 	for (i = 0; i < num_entries; i++) {
10534b28a80dSJouni Malinen 		struct wmi_bss_roam_info *info = &tbl->info[i];
10544b28a80dSJouni Malinen 		len += scnprintf(buf + len, buf_len - len,
10554b28a80dSJouni Malinen 				 "%d %pM %d %d %d %d %d\n",
10564b28a80dSJouni Malinen 				 a_sle32_to_cpu(info->roam_util), info->bssid,
10574b28a80dSJouni Malinen 				 info->rssi, info->rssidt, info->last_rssi,
10584b28a80dSJouni Malinen 				 info->util, info->bias);
10594b28a80dSJouni Malinen 	}
10604b28a80dSJouni Malinen 
10614b28a80dSJouni Malinen 	if (len > buf_len)
10624b28a80dSJouni Malinen 		len = buf_len;
10634b28a80dSJouni Malinen 
10644b28a80dSJouni Malinen 	ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
10654b28a80dSJouni Malinen 
10664b28a80dSJouni Malinen 	kfree(buf);
10674b28a80dSJouni Malinen 	return ret_cnt;
10684b28a80dSJouni Malinen }
10694b28a80dSJouni Malinen 
10704b28a80dSJouni Malinen static const struct file_operations fops_roam_table = {
10714b28a80dSJouni Malinen 	.read = ath6kl_roam_table_read,
10724b28a80dSJouni Malinen 	.open = ath6kl_debugfs_open,
10734b28a80dSJouni Malinen 	.owner = THIS_MODULE,
10744b28a80dSJouni Malinen 	.llseek = default_llseek,
10754b28a80dSJouni Malinen };
10764b28a80dSJouni Malinen 
10771261875fSJouni Malinen static ssize_t ath6kl_force_roam_write(struct file *file,
10781261875fSJouni Malinen 				       const char __user *user_buf,
10791261875fSJouni Malinen 				       size_t count, loff_t *ppos)
10801261875fSJouni Malinen {
10811261875fSJouni Malinen 	struct ath6kl *ar = file->private_data;
10821261875fSJouni Malinen 	int ret;
10831261875fSJouni Malinen 	char buf[20];
10841261875fSJouni Malinen 	size_t len;
10851261875fSJouni Malinen 	u8 bssid[ETH_ALEN];
10861261875fSJouni Malinen 	int i;
10871261875fSJouni Malinen 	int addr[ETH_ALEN];
10881261875fSJouni Malinen 
10891261875fSJouni Malinen 	len = min(count, sizeof(buf) - 1);
10901261875fSJouni Malinen 	if (copy_from_user(buf, user_buf, len))
10911261875fSJouni Malinen 		return -EFAULT;
10921261875fSJouni Malinen 	buf[len] = '\0';
10931261875fSJouni Malinen 
10941261875fSJouni Malinen 	if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
10951261875fSJouni Malinen 		   &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
10961261875fSJouni Malinen 	    != ETH_ALEN)
10971261875fSJouni Malinen 		return -EINVAL;
10981261875fSJouni Malinen 	for (i = 0; i < ETH_ALEN; i++)
10991261875fSJouni Malinen 		bssid[i] = addr[i];
11001261875fSJouni Malinen 
11011261875fSJouni Malinen 	ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
11021261875fSJouni Malinen 	if (ret)
11031261875fSJouni Malinen 		return ret;
11041261875fSJouni Malinen 
11051261875fSJouni Malinen 	return count;
11061261875fSJouni Malinen }
11071261875fSJouni Malinen 
11081261875fSJouni Malinen static const struct file_operations fops_force_roam = {
11091261875fSJouni Malinen 	.write = ath6kl_force_roam_write,
11101261875fSJouni Malinen 	.open = ath6kl_debugfs_open,
11111261875fSJouni Malinen 	.owner = THIS_MODULE,
11121261875fSJouni Malinen 	.llseek = default_llseek,
11131261875fSJouni Malinen };
11141261875fSJouni Malinen 
11151261875fSJouni Malinen static ssize_t ath6kl_roam_mode_write(struct file *file,
11161261875fSJouni Malinen 				      const char __user *user_buf,
11171261875fSJouni Malinen 				      size_t count, loff_t *ppos)
11181261875fSJouni Malinen {
11191261875fSJouni Malinen 	struct ath6kl *ar = file->private_data;
11201261875fSJouni Malinen 	int ret;
11211261875fSJouni Malinen 	char buf[20];
11221261875fSJouni Malinen 	size_t len;
11231261875fSJouni Malinen 	enum wmi_roam_mode mode;
11241261875fSJouni Malinen 
11251261875fSJouni Malinen 	len = min(count, sizeof(buf) - 1);
11261261875fSJouni Malinen 	if (copy_from_user(buf, user_buf, len))
11271261875fSJouni Malinen 		return -EFAULT;
11281261875fSJouni Malinen 	buf[len] = '\0';
11291261875fSJouni Malinen 	if (len > 0 && buf[len - 1] == '\n')
11301261875fSJouni Malinen 		buf[len - 1] = '\0';
11311261875fSJouni Malinen 
11321261875fSJouni Malinen 	if (strcasecmp(buf, "default") == 0)
11331261875fSJouni Malinen 		mode = WMI_DEFAULT_ROAM_MODE;
11341261875fSJouni Malinen 	else if (strcasecmp(buf, "bssbias") == 0)
11351261875fSJouni Malinen 		mode = WMI_HOST_BIAS_ROAM_MODE;
11361261875fSJouni Malinen 	else if (strcasecmp(buf, "lock") == 0)
11371261875fSJouni Malinen 		mode = WMI_LOCK_BSS_MODE;
11381261875fSJouni Malinen 	else
11391261875fSJouni Malinen 		return -EINVAL;
11401261875fSJouni Malinen 
11411261875fSJouni Malinen 	ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
11421261875fSJouni Malinen 	if (ret)
11431261875fSJouni Malinen 		return ret;
11441261875fSJouni Malinen 
11451261875fSJouni Malinen 	return count;
11461261875fSJouni Malinen }
11471261875fSJouni Malinen 
11481261875fSJouni Malinen static const struct file_operations fops_roam_mode = {
11491261875fSJouni Malinen 	.write = ath6kl_roam_mode_write,
11501261875fSJouni Malinen 	.open = ath6kl_debugfs_open,
11511261875fSJouni Malinen 	.owner = THIS_MODULE,
11521261875fSJouni Malinen 	.llseek = default_llseek,
11531261875fSJouni Malinen };
11541261875fSJouni Malinen 
1155ff0b0075SJouni Malinen void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1156ff0b0075SJouni Malinen {
1157ff0b0075SJouni Malinen 	ar->debug.keepalive = keepalive;
1158ff0b0075SJouni Malinen }
1159ff0b0075SJouni Malinen 
1160ff0b0075SJouni Malinen static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1161ff0b0075SJouni Malinen 				     size_t count, loff_t *ppos)
1162ff0b0075SJouni Malinen {
1163ff0b0075SJouni Malinen 	struct ath6kl *ar = file->private_data;
1164ff0b0075SJouni Malinen 	char buf[16];
1165ff0b0075SJouni Malinen 	int len;
1166ff0b0075SJouni Malinen 
1167ff0b0075SJouni Malinen 	len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1168ff0b0075SJouni Malinen 
1169ff0b0075SJouni Malinen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1170ff0b0075SJouni Malinen }
1171ff0b0075SJouni Malinen 
1172ff0b0075SJouni Malinen static ssize_t ath6kl_keepalive_write(struct file *file,
1173ff0b0075SJouni Malinen 				      const char __user *user_buf,
1174ff0b0075SJouni Malinen 				      size_t count, loff_t *ppos)
1175ff0b0075SJouni Malinen {
1176ff0b0075SJouni Malinen 	struct ath6kl *ar = file->private_data;
1177ff0b0075SJouni Malinen 	int ret;
1178ff0b0075SJouni Malinen 	u8 val;
1179ff0b0075SJouni Malinen 
1180ff0b0075SJouni Malinen 	ret = kstrtou8_from_user(user_buf, count, 0, &val);
1181ff0b0075SJouni Malinen 	if (ret)
1182ff0b0075SJouni Malinen 		return ret;
1183ff0b0075SJouni Malinen 
1184ff0b0075SJouni Malinen 	ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, val);
1185ff0b0075SJouni Malinen 	if (ret)
1186ff0b0075SJouni Malinen 		return ret;
1187ff0b0075SJouni Malinen 
1188ff0b0075SJouni Malinen 	return count;
1189ff0b0075SJouni Malinen }
1190ff0b0075SJouni Malinen 
1191ff0b0075SJouni Malinen static const struct file_operations fops_keepalive = {
1192ff0b0075SJouni Malinen 	.open = ath6kl_debugfs_open,
1193ff0b0075SJouni Malinen 	.read = ath6kl_keepalive_read,
1194ff0b0075SJouni Malinen 	.write = ath6kl_keepalive_write,
1195ff0b0075SJouni Malinen 	.owner = THIS_MODULE,
1196ff0b0075SJouni Malinen 	.llseek = default_llseek,
1197ff0b0075SJouni Malinen };
1198ff0b0075SJouni Malinen 
1199ff0b0075SJouni Malinen void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1200ff0b0075SJouni Malinen {
1201ff0b0075SJouni Malinen 	ar->debug.disc_timeout = timeout;
1202ff0b0075SJouni Malinen }
1203ff0b0075SJouni Malinen 
1204ff0b0075SJouni Malinen static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1205ff0b0075SJouni Malinen 					      char __user *user_buf,
1206ff0b0075SJouni Malinen 					      size_t count, loff_t *ppos)
1207ff0b0075SJouni Malinen {
1208ff0b0075SJouni Malinen 	struct ath6kl *ar = file->private_data;
1209ff0b0075SJouni Malinen 	char buf[16];
1210ff0b0075SJouni Malinen 	int len;
1211ff0b0075SJouni Malinen 
1212ff0b0075SJouni Malinen 	len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1213ff0b0075SJouni Malinen 
1214ff0b0075SJouni Malinen 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1215ff0b0075SJouni Malinen }
1216ff0b0075SJouni Malinen 
1217ff0b0075SJouni Malinen static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1218ff0b0075SJouni Malinen 					       const char __user *user_buf,
1219ff0b0075SJouni Malinen 					       size_t count, loff_t *ppos)
1220ff0b0075SJouni Malinen {
1221ff0b0075SJouni Malinen 	struct ath6kl *ar = file->private_data;
1222ff0b0075SJouni Malinen 	int ret;
1223ff0b0075SJouni Malinen 	u8 val;
1224ff0b0075SJouni Malinen 
1225ff0b0075SJouni Malinen 	ret = kstrtou8_from_user(user_buf, count, 0, &val);
1226ff0b0075SJouni Malinen 	if (ret)
1227ff0b0075SJouni Malinen 		return ret;
1228ff0b0075SJouni Malinen 
1229ff0b0075SJouni Malinen 	ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, val);
1230ff0b0075SJouni Malinen 	if (ret)
1231ff0b0075SJouni Malinen 		return ret;
1232ff0b0075SJouni Malinen 
1233ff0b0075SJouni Malinen 	return count;
1234ff0b0075SJouni Malinen }
1235ff0b0075SJouni Malinen 
1236ff0b0075SJouni Malinen static const struct file_operations fops_disconnect_timeout = {
1237ff0b0075SJouni Malinen 	.open = ath6kl_debugfs_open,
1238ff0b0075SJouni Malinen 	.read = ath6kl_disconnect_timeout_read,
1239ff0b0075SJouni Malinen 	.write = ath6kl_disconnect_timeout_write,
1240ff0b0075SJouni Malinen 	.owner = THIS_MODULE,
1241ff0b0075SJouni Malinen 	.llseek = default_llseek,
1242ff0b0075SJouni Malinen };
1243ff0b0075SJouni Malinen 
12448fffd9e5SRishi Panjwani static ssize_t ath6kl_create_qos_write(struct file *file,
12458fffd9e5SRishi Panjwani 						const char __user *user_buf,
12468fffd9e5SRishi Panjwani 						size_t count, loff_t *ppos)
12478fffd9e5SRishi Panjwani {
12488fffd9e5SRishi Panjwani 
12498fffd9e5SRishi Panjwani 	struct ath6kl *ar = file->private_data;
12508fffd9e5SRishi Panjwani 	char buf[100];
12518fffd9e5SRishi Panjwani 	ssize_t len;
12528fffd9e5SRishi Panjwani 	char *sptr, *token;
12538fffd9e5SRishi Panjwani 	struct wmi_create_pstream_cmd pstream;
12548fffd9e5SRishi Panjwani 	u32 val32;
12558fffd9e5SRishi Panjwani 	u16 val16;
12568fffd9e5SRishi Panjwani 
12578fffd9e5SRishi Panjwani 	len = min(count, sizeof(buf) - 1);
12588fffd9e5SRishi Panjwani 	if (copy_from_user(buf, user_buf, len))
12598fffd9e5SRishi Panjwani 		return -EFAULT;
12608fffd9e5SRishi Panjwani 	buf[len] = '\0';
12618fffd9e5SRishi Panjwani 	sptr = buf;
12628fffd9e5SRishi Panjwani 
12638fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
12648fffd9e5SRishi Panjwani 	if (!token)
12658fffd9e5SRishi Panjwani 		return -EINVAL;
12668fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &pstream.user_pri))
12678fffd9e5SRishi Panjwani 		return -EINVAL;
12688fffd9e5SRishi Panjwani 
12698fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
12708fffd9e5SRishi Panjwani 	if (!token)
12718fffd9e5SRishi Panjwani 		return -EINVAL;
12728fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &pstream.traffic_direc))
12738fffd9e5SRishi Panjwani 		return -EINVAL;
12748fffd9e5SRishi Panjwani 
12758fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
12768fffd9e5SRishi Panjwani 	if (!token)
12778fffd9e5SRishi Panjwani 		return -EINVAL;
12788fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &pstream.traffic_class))
12798fffd9e5SRishi Panjwani 		return -EINVAL;
12808fffd9e5SRishi Panjwani 
12818fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
12828fffd9e5SRishi Panjwani 	if (!token)
12838fffd9e5SRishi Panjwani 		return -EINVAL;
12848fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &pstream.traffic_type))
12858fffd9e5SRishi Panjwani 		return -EINVAL;
12868fffd9e5SRishi Panjwani 
12878fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
12888fffd9e5SRishi Panjwani 	if (!token)
12898fffd9e5SRishi Panjwani 		return -EINVAL;
12908fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &pstream.voice_psc_cap))
12918fffd9e5SRishi Panjwani 		return -EINVAL;
12928fffd9e5SRishi Panjwani 
12938fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
12948fffd9e5SRishi Panjwani 	if (!token)
12958fffd9e5SRishi Panjwani 		return -EINVAL;
12968fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
12978fffd9e5SRishi Panjwani 		return -EINVAL;
12988fffd9e5SRishi Panjwani 	pstream.min_service_int = cpu_to_le32(val32);
12998fffd9e5SRishi Panjwani 
13008fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13018fffd9e5SRishi Panjwani 	if (!token)
13028fffd9e5SRishi Panjwani 		return -EINVAL;
13038fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13048fffd9e5SRishi Panjwani 		return -EINVAL;
13058fffd9e5SRishi Panjwani 	pstream.max_service_int = cpu_to_le32(val32);
13068fffd9e5SRishi Panjwani 
13078fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13088fffd9e5SRishi Panjwani 	if (!token)
13098fffd9e5SRishi Panjwani 		return -EINVAL;
13108fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13118fffd9e5SRishi Panjwani 		return -EINVAL;
13128fffd9e5SRishi Panjwani 	pstream.inactivity_int = cpu_to_le32(val32);
13138fffd9e5SRishi Panjwani 
13148fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13158fffd9e5SRishi Panjwani 	if (!token)
13168fffd9e5SRishi Panjwani 		return -EINVAL;
13178fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13188fffd9e5SRishi Panjwani 		return -EINVAL;
13198fffd9e5SRishi Panjwani 	pstream.suspension_int = cpu_to_le32(val32);
13208fffd9e5SRishi Panjwani 
13218fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13228fffd9e5SRishi Panjwani 	if (!token)
13238fffd9e5SRishi Panjwani 		return -EINVAL;
13248fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13258fffd9e5SRishi Panjwani 		return -EINVAL;
13268fffd9e5SRishi Panjwani 	pstream.service_start_time = cpu_to_le32(val32);
13278fffd9e5SRishi Panjwani 
13288fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13298fffd9e5SRishi Panjwani 	if (!token)
13308fffd9e5SRishi Panjwani 		return -EINVAL;
13318fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &pstream.tsid))
13328fffd9e5SRishi Panjwani 		return -EINVAL;
13338fffd9e5SRishi Panjwani 
13348fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13358fffd9e5SRishi Panjwani 	if (!token)
13368fffd9e5SRishi Panjwani 		return -EINVAL;
13378fffd9e5SRishi Panjwani 	if (kstrtou16(token, 0, &val16))
13388fffd9e5SRishi Panjwani 		return -EINVAL;
13398fffd9e5SRishi Panjwani 	pstream.nominal_msdu = cpu_to_le16(val16);
13408fffd9e5SRishi Panjwani 
13418fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13428fffd9e5SRishi Panjwani 	if (!token)
13438fffd9e5SRishi Panjwani 		return -EINVAL;
13448fffd9e5SRishi Panjwani 	if (kstrtou16(token, 0, &val16))
13458fffd9e5SRishi Panjwani 		return -EINVAL;
13468fffd9e5SRishi Panjwani 	pstream.max_msdu = cpu_to_le16(val16);
13478fffd9e5SRishi Panjwani 
13488fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13498fffd9e5SRishi Panjwani 	if (!token)
13508fffd9e5SRishi Panjwani 		return -EINVAL;
13518fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13528fffd9e5SRishi Panjwani 		return -EINVAL;
13538fffd9e5SRishi Panjwani 	pstream.min_data_rate = cpu_to_le32(val32);
13548fffd9e5SRishi Panjwani 
13558fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13568fffd9e5SRishi Panjwani 	if (!token)
13578fffd9e5SRishi Panjwani 		return -EINVAL;
13588fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13598fffd9e5SRishi Panjwani 		return -EINVAL;
13608fffd9e5SRishi Panjwani 	pstream.mean_data_rate = cpu_to_le32(val32);
13618fffd9e5SRishi Panjwani 
13628fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13638fffd9e5SRishi Panjwani 	if (!token)
13648fffd9e5SRishi Panjwani 		return -EINVAL;
13658fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13668fffd9e5SRishi Panjwani 		return -EINVAL;
13678fffd9e5SRishi Panjwani 	pstream.peak_data_rate = cpu_to_le32(val32);
13688fffd9e5SRishi Panjwani 
13698fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13708fffd9e5SRishi Panjwani 	if (!token)
13718fffd9e5SRishi Panjwani 		return -EINVAL;
13728fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13738fffd9e5SRishi Panjwani 		return -EINVAL;
13748fffd9e5SRishi Panjwani 	pstream.max_burst_size = cpu_to_le32(val32);
13758fffd9e5SRishi Panjwani 
13768fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13778fffd9e5SRishi Panjwani 	if (!token)
13788fffd9e5SRishi Panjwani 		return -EINVAL;
13798fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13808fffd9e5SRishi Panjwani 		return -EINVAL;
13818fffd9e5SRishi Panjwani 	pstream.delay_bound = cpu_to_le32(val32);
13828fffd9e5SRishi Panjwani 
13838fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13848fffd9e5SRishi Panjwani 	if (!token)
13858fffd9e5SRishi Panjwani 		return -EINVAL;
13868fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13878fffd9e5SRishi Panjwani 		return -EINVAL;
13888fffd9e5SRishi Panjwani 	pstream.min_phy_rate = cpu_to_le32(val32);
13898fffd9e5SRishi Panjwani 
13908fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13918fffd9e5SRishi Panjwani 	if (!token)
13928fffd9e5SRishi Panjwani 		return -EINVAL;
13938fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
13948fffd9e5SRishi Panjwani 		return -EINVAL;
13958fffd9e5SRishi Panjwani 	pstream.sba = cpu_to_le32(val32);
13968fffd9e5SRishi Panjwani 
13978fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
13988fffd9e5SRishi Panjwani 	if (!token)
13998fffd9e5SRishi Panjwani 		return -EINVAL;
14008fffd9e5SRishi Panjwani 	if (kstrtou32(token, 0, &val32))
14018fffd9e5SRishi Panjwani 		return -EINVAL;
14028fffd9e5SRishi Panjwani 	pstream.medium_time = cpu_to_le32(val32);
14038fffd9e5SRishi Panjwani 
14048fffd9e5SRishi Panjwani 	ath6kl_wmi_create_pstream_cmd(ar->wmi, &pstream);
14058fffd9e5SRishi Panjwani 
14068fffd9e5SRishi Panjwani 	return count;
14078fffd9e5SRishi Panjwani }
14088fffd9e5SRishi Panjwani 
14098fffd9e5SRishi Panjwani static const struct file_operations fops_create_qos = {
14108fffd9e5SRishi Panjwani 	.write = ath6kl_create_qos_write,
14118fffd9e5SRishi Panjwani 	.open = ath6kl_debugfs_open,
14128fffd9e5SRishi Panjwani 	.owner = THIS_MODULE,
14138fffd9e5SRishi Panjwani 	.llseek = default_llseek,
14148fffd9e5SRishi Panjwani };
14158fffd9e5SRishi Panjwani 
14168fffd9e5SRishi Panjwani static ssize_t ath6kl_delete_qos_write(struct file *file,
14178fffd9e5SRishi Panjwani 				const char __user *user_buf,
14188fffd9e5SRishi Panjwani 				size_t count, loff_t *ppos)
14198fffd9e5SRishi Panjwani {
14208fffd9e5SRishi Panjwani 
14218fffd9e5SRishi Panjwani 	struct ath6kl *ar = file->private_data;
14228fffd9e5SRishi Panjwani 	char buf[100];
14238fffd9e5SRishi Panjwani 	ssize_t len;
14248fffd9e5SRishi Panjwani 	char *sptr, *token;
14258fffd9e5SRishi Panjwani 	u8 traffic_class;
14268fffd9e5SRishi Panjwani 	u8 tsid;
14278fffd9e5SRishi Panjwani 
14288fffd9e5SRishi Panjwani 	len = min(count, sizeof(buf) - 1);
14298fffd9e5SRishi Panjwani 	if (copy_from_user(buf, user_buf, len))
14308fffd9e5SRishi Panjwani 		return -EFAULT;
14318fffd9e5SRishi Panjwani 	buf[len] = '\0';
14328fffd9e5SRishi Panjwani 	sptr = buf;
14338fffd9e5SRishi Panjwani 
14348fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
14358fffd9e5SRishi Panjwani 	if (!token)
14368fffd9e5SRishi Panjwani 		return -EINVAL;
14378fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &traffic_class))
14388fffd9e5SRishi Panjwani 		return -EINVAL;
14398fffd9e5SRishi Panjwani 
14408fffd9e5SRishi Panjwani 	token = strsep(&sptr, " ");
14418fffd9e5SRishi Panjwani 	if (!token)
14428fffd9e5SRishi Panjwani 		return -EINVAL;
14438fffd9e5SRishi Panjwani 	if (kstrtou8(token, 0, &tsid))
14448fffd9e5SRishi Panjwani 		return -EINVAL;
14458fffd9e5SRishi Panjwani 
14468fffd9e5SRishi Panjwani 	ath6kl_wmi_delete_pstream_cmd(ar->wmi, traffic_class, tsid);
14478fffd9e5SRishi Panjwani 
14488fffd9e5SRishi Panjwani 	return count;
14498fffd9e5SRishi Panjwani }
14508fffd9e5SRishi Panjwani 
14518fffd9e5SRishi Panjwani static const struct file_operations fops_delete_qos = {
14528fffd9e5SRishi Panjwani 	.write = ath6kl_delete_qos_write,
14538fffd9e5SRishi Panjwani 	.open = ath6kl_debugfs_open,
14548fffd9e5SRishi Panjwani 	.owner = THIS_MODULE,
14558fffd9e5SRishi Panjwani 	.llseek = default_llseek,
14568fffd9e5SRishi Panjwani };
14578fffd9e5SRishi Panjwani 
1458116b3a2eSRishi Panjwani static ssize_t ath6kl_bgscan_int_write(struct file *file,
1459116b3a2eSRishi Panjwani 				const char __user *user_buf,
1460116b3a2eSRishi Panjwani 				size_t count, loff_t *ppos)
1461116b3a2eSRishi Panjwani {
1462116b3a2eSRishi Panjwani 	struct ath6kl *ar = file->private_data;
1463116b3a2eSRishi Panjwani 	u16 bgscan_int;
1464116b3a2eSRishi Panjwani 	char buf[32];
1465116b3a2eSRishi Panjwani 	ssize_t len;
1466116b3a2eSRishi Panjwani 
1467116b3a2eSRishi Panjwani 	len = min(count, sizeof(buf) - 1);
1468116b3a2eSRishi Panjwani 	if (copy_from_user(buf, user_buf, len))
1469116b3a2eSRishi Panjwani 		return -EFAULT;
1470116b3a2eSRishi Panjwani 
1471116b3a2eSRishi Panjwani 	buf[len] = '\0';
1472116b3a2eSRishi Panjwani 	if (kstrtou16(buf, 0, &bgscan_int))
1473116b3a2eSRishi Panjwani 		return -EINVAL;
1474116b3a2eSRishi Panjwani 
1475116b3a2eSRishi Panjwani 	if (bgscan_int == 0)
1476116b3a2eSRishi Panjwani 		bgscan_int = 0xffff;
1477116b3a2eSRishi Panjwani 
1478116b3a2eSRishi Panjwani 	ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, bgscan_int, 0, 0, 0, 3,
1479116b3a2eSRishi Panjwani 				  0, 0, 0);
1480116b3a2eSRishi Panjwani 
1481116b3a2eSRishi Panjwani 	return count;
1482116b3a2eSRishi Panjwani }
1483116b3a2eSRishi Panjwani 
1484116b3a2eSRishi Panjwani static const struct file_operations fops_bgscan_int = {
1485116b3a2eSRishi Panjwani 	.write = ath6kl_bgscan_int_write,
1486116b3a2eSRishi Panjwani 	.open = ath6kl_debugfs_open,
1487116b3a2eSRishi Panjwani 	.owner = THIS_MODULE,
1488116b3a2eSRishi Panjwani 	.llseek = default_llseek,
1489116b3a2eSRishi Panjwani };
1490116b3a2eSRishi Panjwani 
1491d999ba3eSVasanthakumar Thiagarajan int ath6kl_debug_init(struct ath6kl *ar)
1492d999ba3eSVasanthakumar Thiagarajan {
1493bdf5396bSKalle Valo 	ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
1494bdf5396bSKalle Valo 	if (ar->debug.fwlog_buf.buf == NULL)
1495bdf5396bSKalle Valo 		return -ENOMEM;
1496bdf5396bSKalle Valo 
1497bdf5396bSKalle Valo 	ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
1498bdf5396bSKalle Valo 	if (ar->debug.fwlog_tmp == NULL) {
1499bdf5396bSKalle Valo 		vfree(ar->debug.fwlog_buf.buf);
1500bdf5396bSKalle Valo 		return -ENOMEM;
1501bdf5396bSKalle Valo 	}
1502bdf5396bSKalle Valo 
1503bdf5396bSKalle Valo 	spin_lock_init(&ar->debug.fwlog_lock);
1504bdf5396bSKalle Valo 
1505939f1cceSKalle Valo 	/*
1506939f1cceSKalle Valo 	 * Actually we are lying here but don't know how to read the mask
1507939f1cceSKalle Valo 	 * value from the firmware.
1508939f1cceSKalle Valo 	 */
1509939f1cceSKalle Valo 	ar->debug.fwlog_mask = 0;
1510939f1cceSKalle Valo 
1511d999ba3eSVasanthakumar Thiagarajan 	ar->debugfs_phy = debugfs_create_dir("ath6kl",
1512be98e3a4SVasanthakumar Thiagarajan 					     ar->wiphy->debugfsdir);
1513bdf5396bSKalle Valo 	if (!ar->debugfs_phy) {
1514bdf5396bSKalle Valo 		vfree(ar->debug.fwlog_buf.buf);
1515bdf5396bSKalle Valo 		kfree(ar->debug.fwlog_tmp);
1516d999ba3eSVasanthakumar Thiagarajan 		return -ENOMEM;
1517bdf5396bSKalle Valo 	}
1518d999ba3eSVasanthakumar Thiagarajan 
151903f68a95SVasanthakumar Thiagarajan 	debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
152003f68a95SVasanthakumar Thiagarajan 			    &fops_tgt_stats);
152103f68a95SVasanthakumar Thiagarajan 
152278fc4856SVasanthakumar Thiagarajan 	debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
152378fc4856SVasanthakumar Thiagarajan 			    &fops_credit_dist_stats);
152478fc4856SVasanthakumar Thiagarajan 
1525e8091281SJouni Malinen 	debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
1526e8091281SJouni Malinen 			    ar->debugfs_phy, ar, &fops_endpoint_stats);
1527e8091281SJouni Malinen 
1528bdf5396bSKalle Valo 	debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
1529bdf5396bSKalle Valo 			    &fops_fwlog);
1530bdf5396bSKalle Valo 
1531939f1cceSKalle Valo 	debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
1532939f1cceSKalle Valo 			    ar, &fops_fwlog_mask);
1533939f1cceSKalle Valo 
153491d57de5SVasanthakumar Thiagarajan 	debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
153591d57de5SVasanthakumar Thiagarajan 			    &fops_diag_reg_read);
153691d57de5SVasanthakumar Thiagarajan 
153791d57de5SVasanthakumar Thiagarajan 	debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
153891d57de5SVasanthakumar Thiagarajan 			    &fops_reg_dump);
153991d57de5SVasanthakumar Thiagarajan 
1540e5090444SVivek Natarajan 	debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
1541e5090444SVivek Natarajan 			    ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
1542252c068bSVasanthakumar Thiagarajan 
1543252c068bSVasanthakumar Thiagarajan 	debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
1544252c068bSVasanthakumar Thiagarajan 			    ar->debugfs_phy, ar, &fops_diag_reg_write);
1545252c068bSVasanthakumar Thiagarajan 
15469a730834SKalle Valo 	debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
15479a730834SKalle Valo 			    &fops_war_stats);
15489a730834SKalle Valo 
15494b28a80dSJouni Malinen 	debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
15504b28a80dSJouni Malinen 			    &fops_roam_table);
15514b28a80dSJouni Malinen 
15521261875fSJouni Malinen 	debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
15531261875fSJouni Malinen 			    &fops_force_roam);
15541261875fSJouni Malinen 
15551261875fSJouni Malinen 	debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
15561261875fSJouni Malinen 			    &fops_roam_mode);
15571261875fSJouni Malinen 
1558ff0b0075SJouni Malinen 	debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1559ff0b0075SJouni Malinen 			    &fops_keepalive);
1560ff0b0075SJouni Malinen 
1561ff0b0075SJouni Malinen 	debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
1562ff0b0075SJouni Malinen 			    ar->debugfs_phy, ar, &fops_disconnect_timeout);
1563ff0b0075SJouni Malinen 
15648fffd9e5SRishi Panjwani 	debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
15658fffd9e5SRishi Panjwani 				&fops_create_qos);
15668fffd9e5SRishi Panjwani 
15678fffd9e5SRishi Panjwani 	debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
15688fffd9e5SRishi Panjwani 				&fops_delete_qos);
15698fffd9e5SRishi Panjwani 
1570116b3a2eSRishi Panjwani 	debugfs_create_file("bgscan_interval", S_IWUSR,
1571116b3a2eSRishi Panjwani 				ar->debugfs_phy, ar, &fops_bgscan_int);
1572116b3a2eSRishi Panjwani 
1573d999ba3eSVasanthakumar Thiagarajan 	return 0;
1574d999ba3eSVasanthakumar Thiagarajan }
1575bdf5396bSKalle Valo 
1576bdf5396bSKalle Valo void ath6kl_debug_cleanup(struct ath6kl *ar)
1577bdf5396bSKalle Valo {
1578bdf5396bSKalle Valo 	vfree(ar->debug.fwlog_buf.buf);
1579bdf5396bSKalle Valo 	kfree(ar->debug.fwlog_tmp);
15804b28a80dSJouni Malinen 	kfree(ar->debug.roam_tbl);
1581bdf5396bSKalle Valo }
1582bdf5396bSKalle Valo 
1583bdcd8170SKalle Valo #endif
1584