1bdcd8170SKalle Valo /*
2bdcd8170SKalle Valo * Copyright (c) 2004-2011 Atheros Communications Inc.
31b2df407SVasanthakumar Thiagarajan * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
4bdcd8170SKalle Valo *
5bdcd8170SKalle Valo * Permission to use, copy, modify, and/or distribute this software for any
6bdcd8170SKalle Valo * purpose with or without fee is hereby granted, provided that the above
7bdcd8170SKalle Valo * copyright notice and this permission notice appear in all copies.
8bdcd8170SKalle Valo *
9bdcd8170SKalle Valo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10bdcd8170SKalle Valo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11bdcd8170SKalle Valo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12bdcd8170SKalle Valo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13bdcd8170SKalle Valo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14bdcd8170SKalle Valo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15bdcd8170SKalle Valo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16bdcd8170SKalle Valo */
17bdcd8170SKalle Valo
18bdcd8170SKalle Valo #include "core.h"
19bdf5396bSKalle Valo
209b9a4f2aSKalle Valo #include <linux/skbuff.h>
21939f1cceSKalle Valo #include <linux/fs.h>
2262c83ac4SKalle Valo #include <linux/vmalloc.h>
23ee40fa06SPaul Gortmaker #include <linux/export.h>
24bdf5396bSKalle Valo
25bdcd8170SKalle Valo #include "debug.h"
26bdf5396bSKalle Valo #include "target.h"
27bdf5396bSKalle Valo
28bdf5396bSKalle Valo struct ath6kl_fwlog_slot {
29bdf5396bSKalle Valo __le32 timestamp;
30bdf5396bSKalle Valo __le32 length;
31bdf5396bSKalle Valo
32bdf5396bSKalle Valo /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
33ee4dd706SGustavo A. R. Silva u8 payload[];
34bdf5396bSKalle Valo };
35bdf5396bSKalle Valo
369b9a4f2aSKalle Valo #define ATH6KL_FWLOG_MAX_ENTRIES 20
379b9a4f2aSKalle Valo
38939f1cceSKalle Valo #define ATH6KL_FWLOG_VALID_MASK 0x1ffff
39bdcd8170SKalle Valo
ath6kl_printk(const char * level,const char * fmt,...)40babcb3edSJoe Perches void ath6kl_printk(const char *level, const char *fmt, ...)
41bdcd8170SKalle Valo {
42bdcd8170SKalle Valo struct va_format vaf;
43bdcd8170SKalle Valo va_list args;
44bdcd8170SKalle Valo
45bdcd8170SKalle Valo va_start(args, fmt);
46bdcd8170SKalle Valo
47bdcd8170SKalle Valo vaf.fmt = fmt;
48bdcd8170SKalle Valo vaf.va = &args;
49bdcd8170SKalle Valo
50babcb3edSJoe Perches printk("%sath6kl: %pV", level, &vaf);
51bdcd8170SKalle Valo
52bdcd8170SKalle Valo va_end(args);
53bdcd8170SKalle Valo }
54d6a434d6SKalle Valo EXPORT_SYMBOL(ath6kl_printk);
55bdcd8170SKalle Valo
ath6kl_info(const char * fmt,...)56babcb3edSJoe Perches void ath6kl_info(const char *fmt, ...)
57d470b4bcSKalle Valo {
58d470b4bcSKalle Valo struct va_format vaf = {
59d470b4bcSKalle Valo .fmt = fmt,
60d470b4bcSKalle Valo };
61d470b4bcSKalle Valo va_list args;
62d470b4bcSKalle Valo
63d470b4bcSKalle Valo va_start(args, fmt);
64d470b4bcSKalle Valo vaf.va = &args;
65babcb3edSJoe Perches ath6kl_printk(KERN_INFO, "%pV", &vaf);
66da01d53cSKalle Valo trace_ath6kl_log_info(&vaf);
67d470b4bcSKalle Valo va_end(args);
68d470b4bcSKalle Valo }
69d470b4bcSKalle Valo EXPORT_SYMBOL(ath6kl_info);
70d470b4bcSKalle Valo
ath6kl_err(const char * fmt,...)71babcb3edSJoe Perches void ath6kl_err(const char *fmt, ...)
72d470b4bcSKalle Valo {
73d470b4bcSKalle Valo struct va_format vaf = {
74d470b4bcSKalle Valo .fmt = fmt,
75d470b4bcSKalle Valo };
76d470b4bcSKalle Valo va_list args;
77d470b4bcSKalle Valo
78d470b4bcSKalle Valo va_start(args, fmt);
79d470b4bcSKalle Valo vaf.va = &args;
80babcb3edSJoe Perches ath6kl_printk(KERN_ERR, "%pV", &vaf);
81da01d53cSKalle Valo trace_ath6kl_log_err(&vaf);
82d470b4bcSKalle Valo va_end(args);
83d470b4bcSKalle Valo }
84d470b4bcSKalle Valo EXPORT_SYMBOL(ath6kl_err);
85d470b4bcSKalle Valo
ath6kl_warn(const char * fmt,...)86babcb3edSJoe Perches void ath6kl_warn(const char *fmt, ...)
87d470b4bcSKalle Valo {
88d470b4bcSKalle Valo struct va_format vaf = {
89d470b4bcSKalle Valo .fmt = fmt,
90d470b4bcSKalle Valo };
91d470b4bcSKalle Valo va_list args;
92d470b4bcSKalle Valo
93d470b4bcSKalle Valo va_start(args, fmt);
94d470b4bcSKalle Valo vaf.va = &args;
95babcb3edSJoe Perches ath6kl_printk(KERN_WARNING, "%pV", &vaf);
96da01d53cSKalle Valo trace_ath6kl_log_warn(&vaf);
97d470b4bcSKalle Valo va_end(args);
98d470b4bcSKalle Valo }
99d470b4bcSKalle Valo EXPORT_SYMBOL(ath6kl_warn);
100d470b4bcSKalle Valo
ath6kl_read_tgt_stats(struct ath6kl * ar,struct ath6kl_vif * vif)10103702483SBen Greear int ath6kl_read_tgt_stats(struct ath6kl *ar, struct ath6kl_vif *vif)
10203702483SBen Greear {
10303702483SBen Greear long left;
10403702483SBen Greear
10503702483SBen Greear if (down_interruptible(&ar->sem))
10603702483SBen Greear return -EBUSY;
10703702483SBen Greear
10803702483SBen Greear set_bit(STATS_UPDATE_PEND, &vif->flags);
10903702483SBen Greear
11003702483SBen Greear if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) {
11103702483SBen Greear up(&ar->sem);
11203702483SBen Greear return -EIO;
11303702483SBen Greear }
11403702483SBen Greear
11503702483SBen Greear left = wait_event_interruptible_timeout(ar->event_wq,
11603702483SBen Greear !test_bit(STATS_UPDATE_PEND,
11703702483SBen Greear &vif->flags), WMI_TIMEOUT);
11803702483SBen Greear
11903702483SBen Greear up(&ar->sem);
12003702483SBen Greear
12103702483SBen Greear if (left <= 0)
12203702483SBen Greear return -ETIMEDOUT;
12303702483SBen Greear
12403702483SBen Greear return 0;
12503702483SBen Greear }
12603702483SBen Greear EXPORT_SYMBOL(ath6kl_read_tgt_stats);
12703702483SBen Greear
128bdcd8170SKalle Valo #ifdef CONFIG_ATH6KL_DEBUG
12991d57de5SVasanthakumar Thiagarajan
ath6kl_dbg(enum ATH6K_DEBUG_MASK mask,const char * fmt,...)1303b1b7d09SKalle Valo void ath6kl_dbg(enum ATH6K_DEBUG_MASK mask, const char *fmt, ...)
1313b1b7d09SKalle Valo {
1323b1b7d09SKalle Valo struct va_format vaf;
1333b1b7d09SKalle Valo va_list args;
1343b1b7d09SKalle Valo
1353b1b7d09SKalle Valo va_start(args, fmt);
1363b1b7d09SKalle Valo
1373b1b7d09SKalle Valo vaf.fmt = fmt;
1383b1b7d09SKalle Valo vaf.va = &args;
1393b1b7d09SKalle Valo
140aa8705fcSKalle Valo if (debug_mask & mask)
1413b1b7d09SKalle Valo ath6kl_printk(KERN_DEBUG, "%pV", &vaf);
1423b1b7d09SKalle Valo
143aa8705fcSKalle Valo trace_ath6kl_log_dbg(mask, &vaf);
144aa8705fcSKalle Valo
1453b1b7d09SKalle Valo va_end(args);
1463b1b7d09SKalle Valo }
147d6a434d6SKalle Valo EXPORT_SYMBOL(ath6kl_dbg);
1483b1b7d09SKalle Valo
ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,const char * msg,const char * prefix,const void * buf,size_t len)1493b1b7d09SKalle Valo void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
1503b1b7d09SKalle Valo const char *msg, const char *prefix,
1513b1b7d09SKalle Valo const void *buf, size_t len)
1523b1b7d09SKalle Valo {
1533b1b7d09SKalle Valo if (debug_mask & mask) {
1543b1b7d09SKalle Valo if (msg)
1553b1b7d09SKalle Valo ath6kl_dbg(mask, "%s\n", msg);
1563b1b7d09SKalle Valo
1573b1b7d09SKalle Valo print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len);
1583b1b7d09SKalle Valo }
159aa8705fcSKalle Valo
160aa8705fcSKalle Valo /* tracing code doesn't like null strings :/ */
161aa8705fcSKalle Valo trace_ath6kl_log_dbg_dump(msg ? msg : "", prefix ? prefix : "",
162aa8705fcSKalle Valo buf, len);
1633b1b7d09SKalle Valo }
164d6a434d6SKalle Valo EXPORT_SYMBOL(ath6kl_dbg_dump);
1653b1b7d09SKalle Valo
16691d57de5SVasanthakumar Thiagarajan #define REG_OUTPUT_LEN_PER_LINE 25
16791d57de5SVasanthakumar Thiagarajan #define REGTYPE_STR_LEN 100
16891d57de5SVasanthakumar Thiagarajan
16991d57de5SVasanthakumar Thiagarajan struct ath6kl_diag_reg_info {
17091d57de5SVasanthakumar Thiagarajan u32 reg_start;
17191d57de5SVasanthakumar Thiagarajan u32 reg_end;
17291d57de5SVasanthakumar Thiagarajan const char *reg_info;
17391d57de5SVasanthakumar Thiagarajan };
17491d57de5SVasanthakumar Thiagarajan
17591d57de5SVasanthakumar Thiagarajan static const struct ath6kl_diag_reg_info diag_reg[] = {
17691d57de5SVasanthakumar Thiagarajan { 0x20000, 0x200fc, "General DMA and Rx registers" },
17791d57de5SVasanthakumar Thiagarajan { 0x28000, 0x28900, "MAC PCU register & keycache" },
17891d57de5SVasanthakumar Thiagarajan { 0x20800, 0x20a40, "QCU" },
17991d57de5SVasanthakumar Thiagarajan { 0x21000, 0x212f0, "DCU" },
18091d57de5SVasanthakumar Thiagarajan { 0x4000, 0x42e4, "RTC" },
18191d57de5SVasanthakumar Thiagarajan { 0x540000, 0x540000 + (256 * 1024), "RAM" },
18291d57de5SVasanthakumar Thiagarajan { 0x29800, 0x2B210, "Base Band" },
18391d57de5SVasanthakumar Thiagarajan { 0x1C000, 0x1C748, "Analog" },
18491d57de5SVasanthakumar Thiagarajan };
18591d57de5SVasanthakumar Thiagarajan
ath6kl_dump_registers(struct ath6kl_device * dev,struct ath6kl_irq_proc_registers * irq_proc_reg,struct ath6kl_irq_enable_reg * irq_enable_reg)186bdcd8170SKalle Valo void ath6kl_dump_registers(struct ath6kl_device *dev,
187bdcd8170SKalle Valo struct ath6kl_irq_proc_registers *irq_proc_reg,
188bdcd8170SKalle Valo struct ath6kl_irq_enable_reg *irq_enable_reg)
189bdcd8170SKalle Valo {
1905afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ, ("<------- Register Table -------->\n"));
191bdcd8170SKalle Valo
192bdcd8170SKalle Valo if (irq_proc_reg != NULL) {
1935afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
194bdcd8170SKalle Valo "Host Int status: 0x%x\n",
195bdcd8170SKalle Valo irq_proc_reg->host_int_status);
1965afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
197bdcd8170SKalle Valo "CPU Int status: 0x%x\n",
198bdcd8170SKalle Valo irq_proc_reg->cpu_int_status);
1995afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
200bdcd8170SKalle Valo "Error Int status: 0x%x\n",
201bdcd8170SKalle Valo irq_proc_reg->error_int_status);
2025afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
203bdcd8170SKalle Valo "Counter Int status: 0x%x\n",
204bdcd8170SKalle Valo irq_proc_reg->counter_int_status);
2055afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
206bdcd8170SKalle Valo "Mbox Frame: 0x%x\n",
207bdcd8170SKalle Valo irq_proc_reg->mbox_frame);
2085afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
209bdcd8170SKalle Valo "Rx Lookahead Valid: 0x%x\n",
210bdcd8170SKalle Valo irq_proc_reg->rx_lkahd_valid);
2115afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
212bdcd8170SKalle Valo "Rx Lookahead 0: 0x%x\n",
213bdcd8170SKalle Valo irq_proc_reg->rx_lkahd[0]);
2145afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
215bdcd8170SKalle Valo "Rx Lookahead 1: 0x%x\n",
216bdcd8170SKalle Valo irq_proc_reg->rx_lkahd[1]);
217bdcd8170SKalle Valo
218bdcd8170SKalle Valo if (dev->ar->mbox_info.gmbox_addr != 0) {
219bdcd8170SKalle Valo /*
220bdcd8170SKalle Valo * If the target supports GMBOX hardware, dump some
221bdcd8170SKalle Valo * additional state.
222bdcd8170SKalle Valo */
2235afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
224bdcd8170SKalle Valo "GMBOX Host Int status 2: 0x%x\n",
225bdcd8170SKalle Valo irq_proc_reg->host_int_status2);
2265afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
227bdcd8170SKalle Valo "GMBOX RX Avail: 0x%x\n",
228bdcd8170SKalle Valo irq_proc_reg->gmbox_rx_avail);
2295afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
230bdcd8170SKalle Valo "GMBOX lookahead alias 0: 0x%x\n",
231bdcd8170SKalle Valo irq_proc_reg->rx_gmbox_lkahd_alias[0]);
2325afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
233bdcd8170SKalle Valo "GMBOX lookahead alias 1: 0x%x\n",
234bdcd8170SKalle Valo irq_proc_reg->rx_gmbox_lkahd_alias[1]);
235bdcd8170SKalle Valo }
236bdcd8170SKalle Valo }
237bdcd8170SKalle Valo
238bdcd8170SKalle Valo if (irq_enable_reg != NULL) {
2395afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ,
240bdcd8170SKalle Valo "Int status Enable: 0x%x\n",
241bdcd8170SKalle Valo irq_enable_reg->int_status_en);
2425afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ, "Counter Int status Enable: 0x%x\n",
243bdcd8170SKalle Valo irq_enable_reg->cntr_int_status_en);
244bdcd8170SKalle Valo }
2455afa5aa7SKalle Valo ath6kl_dbg(ATH6KL_DBG_IRQ, "<------------------------------->\n");
246bdcd8170SKalle Valo }
247bdcd8170SKalle Valo
dump_cred_dist(struct htc_endpoint_credit_dist * ep_dist)248bdcd8170SKalle Valo static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
249bdcd8170SKalle Valo {
25002f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT,
251bdcd8170SKalle Valo "--- endpoint: %d svc_id: 0x%X ---\n",
252bdcd8170SKalle Valo ep_dist->endpoint, ep_dist->svc_id);
25302f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " dist_flags : 0x%X\n",
254bdcd8170SKalle Valo ep_dist->dist_flags);
25502f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_norm : %d\n",
256bdcd8170SKalle Valo ep_dist->cred_norm);
25702f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_min : %d\n",
258bdcd8170SKalle Valo ep_dist->cred_min);
25902f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " credits : %d\n",
260bdcd8170SKalle Valo ep_dist->credits);
26102f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_assngd : %d\n",
262bdcd8170SKalle Valo ep_dist->cred_assngd);
26302f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " seek_cred : %d\n",
264bdcd8170SKalle Valo ep_dist->seek_cred);
26502f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_sz : %d\n",
266bdcd8170SKalle Valo ep_dist->cred_sz);
26702f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_per_msg : %d\n",
268bdcd8170SKalle Valo ep_dist->cred_per_msg);
26902f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_to_dist : %d\n",
270bdcd8170SKalle Valo ep_dist->cred_to_dist);
27102f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT, " txq_depth : %d\n",
272e8c39790SKalle Valo get_queue_depth(&ep_dist->htc_ep->txq));
27302f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT,
274bdcd8170SKalle Valo "----------------------------------\n");
275bdcd8170SKalle Valo }
276bdcd8170SKalle Valo
27702f0d6fcSKalle Valo /* FIXME: move to htc.c */
dump_cred_dist_stats(struct htc_target * target)278bdcd8170SKalle Valo void dump_cred_dist_stats(struct htc_target *target)
279bdcd8170SKalle Valo {
280bdcd8170SKalle Valo struct htc_endpoint_credit_dist *ep_list;
281bdcd8170SKalle Valo
282bdcd8170SKalle Valo list_for_each_entry(ep_list, &target->cred_dist_list, list)
283bdcd8170SKalle Valo dump_cred_dist(ep_list);
284bdcd8170SKalle Valo
28502f0d6fcSKalle Valo ath6kl_dbg(ATH6KL_DBG_CREDIT,
28602f0d6fcSKalle Valo "credit distribution total %d free %d\n",
2873c370398SKalle Valo target->credit_info->total_avail_credits,
2883c370398SKalle Valo target->credit_info->cur_free_credits);
289bdcd8170SKalle Valo }
290bdcd8170SKalle Valo
ath6kl_debug_war(struct ath6kl * ar,enum ath6kl_war war)2919a730834SKalle Valo void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
2929a730834SKalle Valo {
2939a730834SKalle Valo switch (war) {
2949a730834SKalle Valo case ATH6KL_WAR_INVALID_RATE:
2959a730834SKalle Valo ar->debug.war_stats.invalid_rate++;
2969a730834SKalle Valo break;
2979a730834SKalle Valo }
2989a730834SKalle Valo }
2999a730834SKalle Valo
read_file_war_stats(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)3009a730834SKalle Valo static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
3019a730834SKalle Valo size_t count, loff_t *ppos)
3029a730834SKalle Valo {
3039a730834SKalle Valo struct ath6kl *ar = file->private_data;
3049a730834SKalle Valo char *buf;
3059a730834SKalle Valo unsigned int len = 0, buf_len = 1500;
3069a730834SKalle Valo ssize_t ret_cnt;
3079a730834SKalle Valo
3089a730834SKalle Valo buf = kzalloc(buf_len, GFP_KERNEL);
3099a730834SKalle Valo if (!buf)
3109a730834SKalle Valo return -ENOMEM;
3119a730834SKalle Valo
3129a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n");
3139a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "%25s\n",
3149a730834SKalle Valo "Workaround stats");
3159a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
3169a730834SKalle Valo "=================");
3179a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
3189a730834SKalle Valo "Invalid rates", ar->debug.war_stats.invalid_rate);
3199a730834SKalle Valo
3209a730834SKalle Valo if (WARN_ON(len > buf_len))
3219a730834SKalle Valo len = buf_len;
3229a730834SKalle Valo
3239a730834SKalle Valo ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3249a730834SKalle Valo
3259a730834SKalle Valo kfree(buf);
3269a730834SKalle Valo return ret_cnt;
3279a730834SKalle Valo }
3289a730834SKalle Valo
3299a730834SKalle Valo static const struct file_operations fops_war_stats = {
3309a730834SKalle Valo .read = read_file_war_stats,
331234e3405SStephen Boyd .open = simple_open,
3329a730834SKalle Valo .owner = THIS_MODULE,
3339a730834SKalle Valo .llseek = default_llseek,
3349a730834SKalle Valo };
3359a730834SKalle Valo
ath6kl_debug_fwlog_event(struct ath6kl * ar,const void * buf,size_t len)336bdf5396bSKalle Valo void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
337bdf5396bSKalle Valo {
3389b9a4f2aSKalle Valo struct ath6kl_fwlog_slot *slot;
3399b9a4f2aSKalle Valo struct sk_buff *skb;
340bdf5396bSKalle Valo size_t slot_len;
341bdf5396bSKalle Valo
342bdf5396bSKalle Valo if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
343bdf5396bSKalle Valo return;
344bdf5396bSKalle Valo
3457504a3e1SEtay Luz slot_len = sizeof(*slot) + ATH6KL_FWLOG_PAYLOAD_SIZE;
346bdf5396bSKalle Valo
3479b9a4f2aSKalle Valo skb = alloc_skb(slot_len, GFP_KERNEL);
3489b9a4f2aSKalle Valo if (!skb)
3499b9a4f2aSKalle Valo return;
3509b9a4f2aSKalle Valo
3514df864c1SJohannes Berg slot = skb_put(skb, slot_len);
352bdf5396bSKalle Valo slot->timestamp = cpu_to_le32(jiffies);
353bdf5396bSKalle Valo slot->length = cpu_to_le32(len);
354bdf5396bSKalle Valo memcpy(slot->payload, buf, len);
355bdf5396bSKalle Valo
3567504a3e1SEtay Luz /* Need to pad each record to fixed length ATH6KL_FWLOG_PAYLOAD_SIZE */
3577504a3e1SEtay Luz memset(slot->payload + len, 0, ATH6KL_FWLOG_PAYLOAD_SIZE - len);
3587504a3e1SEtay Luz
3599b9a4f2aSKalle Valo spin_lock(&ar->debug.fwlog_queue.lock);
360bdf5396bSKalle Valo
3619b9a4f2aSKalle Valo __skb_queue_tail(&ar->debug.fwlog_queue, skb);
362c807b30dSKalle Valo complete(&ar->debug.fwlog_completion);
363bdf5396bSKalle Valo
3649b9a4f2aSKalle Valo /* drop oldest entries */
3659b9a4f2aSKalle Valo while (skb_queue_len(&ar->debug.fwlog_queue) >
3669b9a4f2aSKalle Valo ATH6KL_FWLOG_MAX_ENTRIES) {
3679b9a4f2aSKalle Valo skb = __skb_dequeue(&ar->debug.fwlog_queue);
3689b9a4f2aSKalle Valo kfree_skb(skb);
369bdf5396bSKalle Valo }
370bdf5396bSKalle Valo
3719b9a4f2aSKalle Valo spin_unlock(&ar->debug.fwlog_queue.lock);
3729b9a4f2aSKalle Valo
3739b9a4f2aSKalle Valo return;
374bdf5396bSKalle Valo }
375bdf5396bSKalle Valo
ath6kl_fwlog_open(struct inode * inode,struct file * file)376c807b30dSKalle Valo static int ath6kl_fwlog_open(struct inode *inode, struct file *file)
377c807b30dSKalle Valo {
378c807b30dSKalle Valo struct ath6kl *ar = inode->i_private;
379c807b30dSKalle Valo
380c807b30dSKalle Valo if (ar->debug.fwlog_open)
381c807b30dSKalle Valo return -EBUSY;
382c807b30dSKalle Valo
383c807b30dSKalle Valo ar->debug.fwlog_open = true;
384c807b30dSKalle Valo
385c807b30dSKalle Valo file->private_data = inode->i_private;
386c807b30dSKalle Valo return 0;
387c807b30dSKalle Valo }
388c807b30dSKalle Valo
ath6kl_fwlog_release(struct inode * inode,struct file * file)389c807b30dSKalle Valo static int ath6kl_fwlog_release(struct inode *inode, struct file *file)
390c807b30dSKalle Valo {
391c807b30dSKalle Valo struct ath6kl *ar = inode->i_private;
392c807b30dSKalle Valo
393c807b30dSKalle Valo ar->debug.fwlog_open = false;
394c807b30dSKalle Valo
395c807b30dSKalle Valo return 0;
396c807b30dSKalle Valo }
397c807b30dSKalle Valo
ath6kl_fwlog_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)398bdf5396bSKalle Valo static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
399bdf5396bSKalle Valo size_t count, loff_t *ppos)
400bdf5396bSKalle Valo {
401bdf5396bSKalle Valo struct ath6kl *ar = file->private_data;
4029b9a4f2aSKalle Valo struct sk_buff *skb;
403bdf5396bSKalle Valo ssize_t ret_cnt;
4049b9a4f2aSKalle Valo size_t len = 0;
405bdf5396bSKalle Valo char *buf;
406bdf5396bSKalle Valo
4079b9a4f2aSKalle Valo buf = vmalloc(count);
408bdf5396bSKalle Valo if (!buf)
409bdf5396bSKalle Valo return -ENOMEM;
410bdf5396bSKalle Valo
411bc07ddb2SKalle Valo /* read undelivered logs from firmware */
412bc07ddb2SKalle Valo ath6kl_read_fwlogs(ar);
413bc07ddb2SKalle Valo
4149b9a4f2aSKalle Valo spin_lock(&ar->debug.fwlog_queue.lock);
415bdf5396bSKalle Valo
4169b9a4f2aSKalle Valo while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
4179b9a4f2aSKalle Valo if (skb->len > count - len) {
4189b9a4f2aSKalle Valo /* not enough space, put skb back and leave */
4199b9a4f2aSKalle Valo __skb_queue_head(&ar->debug.fwlog_queue, skb);
4209b9a4f2aSKalle Valo break;
421bdf5396bSKalle Valo }
422bdf5396bSKalle Valo
423bdf5396bSKalle Valo
4249b9a4f2aSKalle Valo memcpy(buf + len, skb->data, skb->len);
4259b9a4f2aSKalle Valo len += skb->len;
4269b9a4f2aSKalle Valo
4279b9a4f2aSKalle Valo kfree_skb(skb);
4289b9a4f2aSKalle Valo }
4299b9a4f2aSKalle Valo
4309b9a4f2aSKalle Valo spin_unlock(&ar->debug.fwlog_queue.lock);
4319b9a4f2aSKalle Valo
4329b9a4f2aSKalle Valo /* FIXME: what to do if len == 0? */
433bdf5396bSKalle Valo
434bdf5396bSKalle Valo ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
435bdf5396bSKalle Valo
436bdf5396bSKalle Valo vfree(buf);
437bdf5396bSKalle Valo
438bdf5396bSKalle Valo return ret_cnt;
439bdf5396bSKalle Valo }
440bdf5396bSKalle Valo
441bdf5396bSKalle Valo static const struct file_operations fops_fwlog = {
442c807b30dSKalle Valo .open = ath6kl_fwlog_open,
443c807b30dSKalle Valo .release = ath6kl_fwlog_release,
444bdf5396bSKalle Valo .read = ath6kl_fwlog_read,
445bdf5396bSKalle Valo .owner = THIS_MODULE,
446bdf5396bSKalle Valo .llseek = default_llseek,
447bdf5396bSKalle Valo };
448bdf5396bSKalle Valo
ath6kl_fwlog_block_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)449c807b30dSKalle Valo static ssize_t ath6kl_fwlog_block_read(struct file *file,
450c807b30dSKalle Valo char __user *user_buf,
451c807b30dSKalle Valo size_t count,
452c807b30dSKalle Valo loff_t *ppos)
453c807b30dSKalle Valo {
454c807b30dSKalle Valo struct ath6kl *ar = file->private_data;
455c807b30dSKalle Valo struct sk_buff *skb;
456c807b30dSKalle Valo ssize_t ret_cnt;
457c807b30dSKalle Valo size_t len = 0, not_copied;
458c807b30dSKalle Valo char *buf;
459c807b30dSKalle Valo int ret;
460c807b30dSKalle Valo
461c807b30dSKalle Valo buf = vmalloc(count);
462c807b30dSKalle Valo if (!buf)
463c807b30dSKalle Valo return -ENOMEM;
464c807b30dSKalle Valo
465c807b30dSKalle Valo spin_lock(&ar->debug.fwlog_queue.lock);
466c807b30dSKalle Valo
467c807b30dSKalle Valo if (skb_queue_len(&ar->debug.fwlog_queue) == 0) {
468c807b30dSKalle Valo /* we must init under queue lock */
469c807b30dSKalle Valo init_completion(&ar->debug.fwlog_completion);
470c807b30dSKalle Valo
471c807b30dSKalle Valo spin_unlock(&ar->debug.fwlog_queue.lock);
472c807b30dSKalle Valo
473c807b30dSKalle Valo ret = wait_for_completion_interruptible(
474c807b30dSKalle Valo &ar->debug.fwlog_completion);
475ae9a3405SJesper Juhl if (ret == -ERESTARTSYS) {
476ae9a3405SJesper Juhl vfree(buf);
477c807b30dSKalle Valo return ret;
478ae9a3405SJesper Juhl }
479c807b30dSKalle Valo
480c807b30dSKalle Valo spin_lock(&ar->debug.fwlog_queue.lock);
481c807b30dSKalle Valo }
482c807b30dSKalle Valo
483c807b30dSKalle Valo while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
484c807b30dSKalle Valo if (skb->len > count - len) {
485c807b30dSKalle Valo /* not enough space, put skb back and leave */
486c807b30dSKalle Valo __skb_queue_head(&ar->debug.fwlog_queue, skb);
487c807b30dSKalle Valo break;
488c807b30dSKalle Valo }
489c807b30dSKalle Valo
490c807b30dSKalle Valo
491c807b30dSKalle Valo memcpy(buf + len, skb->data, skb->len);
492c807b30dSKalle Valo len += skb->len;
493c807b30dSKalle Valo
494c807b30dSKalle Valo kfree_skb(skb);
495c807b30dSKalle Valo }
496c807b30dSKalle Valo
497c807b30dSKalle Valo spin_unlock(&ar->debug.fwlog_queue.lock);
498c807b30dSKalle Valo
499c807b30dSKalle Valo /* FIXME: what to do if len == 0? */
500c807b30dSKalle Valo
501c807b30dSKalle Valo not_copied = copy_to_user(user_buf, buf, len);
502c807b30dSKalle Valo if (not_copied != 0) {
503c807b30dSKalle Valo ret_cnt = -EFAULT;
504c807b30dSKalle Valo goto out;
505c807b30dSKalle Valo }
506c807b30dSKalle Valo
507c807b30dSKalle Valo *ppos = *ppos + len;
508c807b30dSKalle Valo
509c807b30dSKalle Valo ret_cnt = len;
510c807b30dSKalle Valo
511c807b30dSKalle Valo out:
512c807b30dSKalle Valo vfree(buf);
513c807b30dSKalle Valo
514c807b30dSKalle Valo return ret_cnt;
515c807b30dSKalle Valo }
516c807b30dSKalle Valo
517c807b30dSKalle Valo static const struct file_operations fops_fwlog_block = {
518c807b30dSKalle Valo .open = ath6kl_fwlog_open,
519c807b30dSKalle Valo .release = ath6kl_fwlog_release,
520c807b30dSKalle Valo .read = ath6kl_fwlog_block_read,
521c807b30dSKalle Valo .owner = THIS_MODULE,
522c807b30dSKalle Valo .llseek = default_llseek,
523c807b30dSKalle Valo };
524c807b30dSKalle Valo
ath6kl_fwlog_mask_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)525939f1cceSKalle Valo static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
526939f1cceSKalle Valo size_t count, loff_t *ppos)
527939f1cceSKalle Valo {
528939f1cceSKalle Valo struct ath6kl *ar = file->private_data;
529939f1cceSKalle Valo char buf[16];
530939f1cceSKalle Valo int len;
531939f1cceSKalle Valo
532939f1cceSKalle Valo len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
533939f1cceSKalle Valo
534939f1cceSKalle Valo return simple_read_from_buffer(user_buf, count, ppos, buf, len);
535939f1cceSKalle Valo }
536939f1cceSKalle Valo
ath6kl_fwlog_mask_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)537939f1cceSKalle Valo static ssize_t ath6kl_fwlog_mask_write(struct file *file,
538939f1cceSKalle Valo const char __user *user_buf,
539939f1cceSKalle Valo size_t count, loff_t *ppos)
540939f1cceSKalle Valo {
541939f1cceSKalle Valo struct ath6kl *ar = file->private_data;
542939f1cceSKalle Valo int ret;
543939f1cceSKalle Valo
544939f1cceSKalle Valo ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
545939f1cceSKalle Valo if (ret)
546939f1cceSKalle Valo return ret;
547939f1cceSKalle Valo
548939f1cceSKalle Valo ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
549939f1cceSKalle Valo ATH6KL_FWLOG_VALID_MASK,
550939f1cceSKalle Valo ar->debug.fwlog_mask);
551939f1cceSKalle Valo if (ret)
552939f1cceSKalle Valo return ret;
553939f1cceSKalle Valo
554939f1cceSKalle Valo return count;
555939f1cceSKalle Valo }
556939f1cceSKalle Valo
557939f1cceSKalle Valo static const struct file_operations fops_fwlog_mask = {
558234e3405SStephen Boyd .open = simple_open,
559939f1cceSKalle Valo .read = ath6kl_fwlog_mask_read,
560939f1cceSKalle Valo .write = ath6kl_fwlog_mask_write,
561939f1cceSKalle Valo .owner = THIS_MODULE,
562939f1cceSKalle Valo .llseek = default_llseek,
563939f1cceSKalle Valo };
564939f1cceSKalle Valo
read_file_tgt_stats(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)56503f68a95SVasanthakumar Thiagarajan static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
56603f68a95SVasanthakumar Thiagarajan size_t count, loff_t *ppos)
56703f68a95SVasanthakumar Thiagarajan {
56803f68a95SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data;
569990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif;
570990bd915SVasanthakumar Thiagarajan struct target_stats *tgt_stats;
57103f68a95SVasanthakumar Thiagarajan char *buf;
57203f68a95SVasanthakumar Thiagarajan unsigned int len = 0, buf_len = 1500;
57303f68a95SVasanthakumar Thiagarajan int i;
57403f68a95SVasanthakumar Thiagarajan ssize_t ret_cnt;
57503702483SBen Greear int rv;
57603f68a95SVasanthakumar Thiagarajan
577990bd915SVasanthakumar Thiagarajan vif = ath6kl_vif_first(ar);
578990bd915SVasanthakumar Thiagarajan if (!vif)
579990bd915SVasanthakumar Thiagarajan return -EIO;
580990bd915SVasanthakumar Thiagarajan
58103f68a95SVasanthakumar Thiagarajan buf = kzalloc(buf_len, GFP_KERNEL);
58203f68a95SVasanthakumar Thiagarajan if (!buf)
58303f68a95SVasanthakumar Thiagarajan return -ENOMEM;
58403f68a95SVasanthakumar Thiagarajan
58503702483SBen Greear rv = ath6kl_read_tgt_stats(ar, vif);
58603702483SBen Greear if (rv < 0) {
58703f68a95SVasanthakumar Thiagarajan kfree(buf);
58803702483SBen Greear return rv;
58903f68a95SVasanthakumar Thiagarajan }
59003f68a95SVasanthakumar Thiagarajan
59103702483SBen Greear tgt_stats = &vif->target_stats;
59203f68a95SVasanthakumar Thiagarajan
59303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "\n");
59403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n",
59503f68a95SVasanthakumar Thiagarajan "Target Tx stats");
59603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
59703f68a95SVasanthakumar Thiagarajan "=================");
59803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
59903f68a95SVasanthakumar Thiagarajan "Ucast packets", tgt_stats->tx_ucast_pkt);
60003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
60103f68a95SVasanthakumar Thiagarajan "Bcast packets", tgt_stats->tx_bcast_pkt);
60203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
60303f68a95SVasanthakumar Thiagarajan "Ucast byte", tgt_stats->tx_ucast_byte);
60403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
60503f68a95SVasanthakumar Thiagarajan "Bcast byte", tgt_stats->tx_bcast_byte);
60603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
60703f68a95SVasanthakumar Thiagarajan "Rts success cnt", tgt_stats->tx_rts_success_cnt);
60803f68a95SVasanthakumar Thiagarajan for (i = 0; i < 4; i++)
60903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len,
61003f68a95SVasanthakumar Thiagarajan "%18s %d %10llu\n", "PER on ac",
61103f68a95SVasanthakumar Thiagarajan i, tgt_stats->tx_pkt_per_ac[i]);
61203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
61303f68a95SVasanthakumar Thiagarajan "Error", tgt_stats->tx_err);
61403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
61503f68a95SVasanthakumar Thiagarajan "Fail count", tgt_stats->tx_fail_cnt);
61603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
61703f68a95SVasanthakumar Thiagarajan "Retry count", tgt_stats->tx_retry_cnt);
61803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
61903f68a95SVasanthakumar Thiagarajan "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
62003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
62103f68a95SVasanthakumar Thiagarajan "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
62203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
62303f68a95SVasanthakumar Thiagarajan "TKIP counter measure used",
62403f68a95SVasanthakumar Thiagarajan tgt_stats->tkip_cnter_measures_invoked);
62503f68a95SVasanthakumar Thiagarajan
62603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n",
62703f68a95SVasanthakumar Thiagarajan "Target Rx stats");
62803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n",
62903f68a95SVasanthakumar Thiagarajan "=================");
63003f68a95SVasanthakumar Thiagarajan
63103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
63203f68a95SVasanthakumar Thiagarajan "Ucast packets", tgt_stats->rx_ucast_pkt);
63303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
63403f68a95SVasanthakumar Thiagarajan "Ucast Rate", tgt_stats->rx_ucast_rate);
63503f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
63603f68a95SVasanthakumar Thiagarajan "Bcast packets", tgt_stats->rx_bcast_pkt);
63703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
63803f68a95SVasanthakumar Thiagarajan "Ucast byte", tgt_stats->rx_ucast_byte);
63903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
64003f68a95SVasanthakumar Thiagarajan "Bcast byte", tgt_stats->rx_bcast_byte);
64103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
64203f68a95SVasanthakumar Thiagarajan "Fragmented pkt", tgt_stats->rx_frgment_pkt);
64303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
64403f68a95SVasanthakumar Thiagarajan "Error", tgt_stats->rx_err);
64503f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
64603f68a95SVasanthakumar Thiagarajan "CRC Err", tgt_stats->rx_crc_err);
64703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
6485072d874SColin Ian King "Key cache miss", tgt_stats->rx_key_cache_miss);
64903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
65003f68a95SVasanthakumar Thiagarajan "Decrypt Err", tgt_stats->rx_decrypt_err);
65103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
65203f68a95SVasanthakumar Thiagarajan "Duplicate frame", tgt_stats->rx_dupl_frame);
65303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
65403f68a95SVasanthakumar Thiagarajan "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
65503f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
65603f68a95SVasanthakumar Thiagarajan "TKIP format err", tgt_stats->tkip_fmt_err);
65703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
65803f68a95SVasanthakumar Thiagarajan "CCMP format Err", tgt_stats->ccmp_fmt_err);
65903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
66003f68a95SVasanthakumar Thiagarajan "CCMP Replay Err", tgt_stats->ccmp_replays);
66103f68a95SVasanthakumar Thiagarajan
66203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n",
66303f68a95SVasanthakumar Thiagarajan "Misc Target stats");
66403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n",
66503f68a95SVasanthakumar Thiagarajan "=================");
66603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
66703f68a95SVasanthakumar Thiagarajan "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
66803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
66903f68a95SVasanthakumar Thiagarajan "Num Connects", tgt_stats->cs_connect_cnt);
67003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
67103f68a95SVasanthakumar Thiagarajan "Num disconnects", tgt_stats->cs_discon_cnt);
67203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
67303f68a95SVasanthakumar Thiagarajan "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
674f0446ea9SRaja Mani len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
675f0446ea9SRaja Mani "ARP pkt received", tgt_stats->arp_received);
676f0446ea9SRaja Mani len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
677f0446ea9SRaja Mani "ARP pkt matched", tgt_stats->arp_matched);
678f0446ea9SRaja Mani len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
679f0446ea9SRaja Mani "ARP pkt replied", tgt_stats->arp_replied);
68003f68a95SVasanthakumar Thiagarajan
68103f68a95SVasanthakumar Thiagarajan if (len > buf_len)
68203f68a95SVasanthakumar Thiagarajan len = buf_len;
68303f68a95SVasanthakumar Thiagarajan
68403f68a95SVasanthakumar Thiagarajan ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
68503f68a95SVasanthakumar Thiagarajan
68603f68a95SVasanthakumar Thiagarajan kfree(buf);
68703f68a95SVasanthakumar Thiagarajan return ret_cnt;
68803f68a95SVasanthakumar Thiagarajan }
68903f68a95SVasanthakumar Thiagarajan
69003f68a95SVasanthakumar Thiagarajan static const struct file_operations fops_tgt_stats = {
69103f68a95SVasanthakumar Thiagarajan .read = read_file_tgt_stats,
692234e3405SStephen Boyd .open = simple_open,
69303f68a95SVasanthakumar Thiagarajan .owner = THIS_MODULE,
69403f68a95SVasanthakumar Thiagarajan .llseek = default_llseek,
69503f68a95SVasanthakumar Thiagarajan };
69603f68a95SVasanthakumar Thiagarajan
69778fc4856SVasanthakumar Thiagarajan #define print_credit_info(fmt_str, ep_list_field) \
69878fc4856SVasanthakumar Thiagarajan (len += scnprintf(buf + len, buf_len - len, fmt_str, \
69978fc4856SVasanthakumar Thiagarajan ep_list->ep_list_field))
70078fc4856SVasanthakumar Thiagarajan #define CREDIT_INFO_DISPLAY_STRING_LEN 200
70178fc4856SVasanthakumar Thiagarajan #define CREDIT_INFO_LEN 128
70278fc4856SVasanthakumar Thiagarajan
read_file_credit_dist_stats(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)70378fc4856SVasanthakumar Thiagarajan static ssize_t read_file_credit_dist_stats(struct file *file,
70478fc4856SVasanthakumar Thiagarajan char __user *user_buf,
70578fc4856SVasanthakumar Thiagarajan size_t count, loff_t *ppos)
70678fc4856SVasanthakumar Thiagarajan {
70778fc4856SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data;
70878fc4856SVasanthakumar Thiagarajan struct htc_target *target = ar->htc_target;
70978fc4856SVasanthakumar Thiagarajan struct htc_endpoint_credit_dist *ep_list;
71078fc4856SVasanthakumar Thiagarajan char *buf;
71178fc4856SVasanthakumar Thiagarajan unsigned int buf_len, len = 0;
71278fc4856SVasanthakumar Thiagarajan ssize_t ret_cnt;
71378fc4856SVasanthakumar Thiagarajan
71478fc4856SVasanthakumar Thiagarajan buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
71578fc4856SVasanthakumar Thiagarajan get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
71678fc4856SVasanthakumar Thiagarajan buf = kzalloc(buf_len, GFP_KERNEL);
71778fc4856SVasanthakumar Thiagarajan if (!buf)
71878fc4856SVasanthakumar Thiagarajan return -ENOMEM;
71978fc4856SVasanthakumar Thiagarajan
72078fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
72178fc4856SVasanthakumar Thiagarajan "Total Avail Credits: ",
7223c370398SKalle Valo target->credit_info->total_avail_credits);
72378fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
72478fc4856SVasanthakumar Thiagarajan "Free credits :",
7253c370398SKalle Valo target->credit_info->cur_free_credits);
72678fc4856SVasanthakumar Thiagarajan
72778fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len,
72878fc4856SVasanthakumar Thiagarajan " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
72978fc4856SVasanthakumar Thiagarajan " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
73078fc4856SVasanthakumar Thiagarajan " qdepth\n");
73178fc4856SVasanthakumar Thiagarajan
73278fc4856SVasanthakumar Thiagarajan list_for_each_entry(ep_list, &target->cred_dist_list, list) {
73378fc4856SVasanthakumar Thiagarajan print_credit_info(" %2d", endpoint);
73478fc4856SVasanthakumar Thiagarajan print_credit_info("%10x", dist_flags);
73578fc4856SVasanthakumar Thiagarajan print_credit_info("%8d", cred_norm);
73678fc4856SVasanthakumar Thiagarajan print_credit_info("%9d", cred_min);
73778fc4856SVasanthakumar Thiagarajan print_credit_info("%9d", credits);
73878fc4856SVasanthakumar Thiagarajan print_credit_info("%10d", cred_assngd);
73978fc4856SVasanthakumar Thiagarajan print_credit_info("%13d", seek_cred);
74078fc4856SVasanthakumar Thiagarajan print_credit_info("%12d", cred_sz);
74178fc4856SVasanthakumar Thiagarajan print_credit_info("%9d", cred_per_msg);
74278fc4856SVasanthakumar Thiagarajan print_credit_info("%14d", cred_to_dist);
74378fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%12d\n",
744e8c39790SKalle Valo get_queue_depth(&ep_list->htc_ep->txq));
74578fc4856SVasanthakumar Thiagarajan }
74678fc4856SVasanthakumar Thiagarajan
74778fc4856SVasanthakumar Thiagarajan if (len > buf_len)
74878fc4856SVasanthakumar Thiagarajan len = buf_len;
74978fc4856SVasanthakumar Thiagarajan
75078fc4856SVasanthakumar Thiagarajan ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
75178fc4856SVasanthakumar Thiagarajan kfree(buf);
75278fc4856SVasanthakumar Thiagarajan return ret_cnt;
75378fc4856SVasanthakumar Thiagarajan }
75478fc4856SVasanthakumar Thiagarajan
75578fc4856SVasanthakumar Thiagarajan static const struct file_operations fops_credit_dist_stats = {
75678fc4856SVasanthakumar Thiagarajan .read = read_file_credit_dist_stats,
757234e3405SStephen Boyd .open = simple_open,
75878fc4856SVasanthakumar Thiagarajan .owner = THIS_MODULE,
75978fc4856SVasanthakumar Thiagarajan .llseek = default_llseek,
76078fc4856SVasanthakumar Thiagarajan };
76178fc4856SVasanthakumar Thiagarajan
print_endpoint_stat(struct htc_target * target,char * buf,unsigned int buf_len,unsigned int len,int offset,const char * name)762e8091281SJouni Malinen static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
763e8091281SJouni Malinen unsigned int buf_len, unsigned int len,
764e8091281SJouni Malinen int offset, const char *name)
765e8091281SJouni Malinen {
766e8091281SJouni Malinen int i;
767e8091281SJouni Malinen struct htc_endpoint_stats *ep_st;
768e8091281SJouni Malinen u32 *counter;
769e8091281SJouni Malinen
770e8091281SJouni Malinen len += scnprintf(buf + len, buf_len - len, "%s:", name);
771e8091281SJouni Malinen for (i = 0; i < ENDPOINT_MAX; i++) {
772e8091281SJouni Malinen ep_st = &target->endpoint[i].ep_st;
773e8091281SJouni Malinen counter = ((u32 *) ep_st) + (offset / 4);
774e8091281SJouni Malinen len += scnprintf(buf + len, buf_len - len, " %u", *counter);
775e8091281SJouni Malinen }
776e8091281SJouni Malinen len += scnprintf(buf + len, buf_len - len, "\n");
777e8091281SJouni Malinen
778e8091281SJouni Malinen return len;
779e8091281SJouni Malinen }
780e8091281SJouni Malinen
ath6kl_endpoint_stats_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)781e8091281SJouni Malinen static ssize_t ath6kl_endpoint_stats_read(struct file *file,
782e8091281SJouni Malinen char __user *user_buf,
783e8091281SJouni Malinen size_t count, loff_t *ppos)
784e8091281SJouni Malinen {
785e8091281SJouni Malinen struct ath6kl *ar = file->private_data;
786e8091281SJouni Malinen struct htc_target *target = ar->htc_target;
787e8091281SJouni Malinen char *buf;
788e8091281SJouni Malinen unsigned int buf_len, len = 0;
789e8091281SJouni Malinen ssize_t ret_cnt;
790e8091281SJouni Malinen
79117169329SJouni Malinen buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
79217169329SJouni Malinen (25 + ENDPOINT_MAX * 11);
79317169329SJouni Malinen buf = kmalloc(buf_len, GFP_KERNEL);
794e8091281SJouni Malinen if (!buf)
795e8091281SJouni Malinen return -ENOMEM;
796e8091281SJouni Malinen
797e8091281SJouni Malinen #define EPSTAT(name) \
798c650538fSKalle Valo do { \
799e8091281SJouni Malinen len = print_endpoint_stat(target, buf, buf_len, len, \
800c650538fSKalle Valo offsetof(struct htc_endpoint_stats, \
801c650538fSKalle Valo name), \
802c650538fSKalle Valo #name); \
803c650538fSKalle Valo } while (0)
804c650538fSKalle Valo
805e8091281SJouni Malinen EPSTAT(cred_low_indicate);
806e8091281SJouni Malinen EPSTAT(tx_issued);
807e8091281SJouni Malinen EPSTAT(tx_pkt_bundled);
808e8091281SJouni Malinen EPSTAT(tx_bundles);
809e8091281SJouni Malinen EPSTAT(tx_dropped);
810e8091281SJouni Malinen EPSTAT(tx_cred_rpt);
811e8091281SJouni Malinen EPSTAT(cred_rpt_from_rx);
81217169329SJouni Malinen EPSTAT(cred_rpt_from_other);
813e8091281SJouni Malinen EPSTAT(cred_rpt_ep0);
814e8091281SJouni Malinen EPSTAT(cred_from_rx);
815e8091281SJouni Malinen EPSTAT(cred_from_other);
816e8091281SJouni Malinen EPSTAT(cred_from_ep0);
817e8091281SJouni Malinen EPSTAT(cred_cosumd);
818e8091281SJouni Malinen EPSTAT(cred_retnd);
819e8091281SJouni Malinen EPSTAT(rx_pkts);
820e8091281SJouni Malinen EPSTAT(rx_lkahds);
821e8091281SJouni Malinen EPSTAT(rx_bundl);
822e8091281SJouni Malinen EPSTAT(rx_bundle_lkahd);
823e8091281SJouni Malinen EPSTAT(rx_bundle_from_hdr);
824e8091281SJouni Malinen EPSTAT(rx_alloc_thresh_hit);
825e8091281SJouni Malinen EPSTAT(rxalloc_thresh_byte);
826e8091281SJouni Malinen #undef EPSTAT
827e8091281SJouni Malinen
828e8091281SJouni Malinen if (len > buf_len)
829e8091281SJouni Malinen len = buf_len;
830e8091281SJouni Malinen
831e8091281SJouni Malinen ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
832e8091281SJouni Malinen kfree(buf);
833e8091281SJouni Malinen return ret_cnt;
834e8091281SJouni Malinen }
835e8091281SJouni Malinen
ath6kl_endpoint_stats_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)836e8091281SJouni Malinen static ssize_t ath6kl_endpoint_stats_write(struct file *file,
837e8091281SJouni Malinen const char __user *user_buf,
838e8091281SJouni Malinen size_t count, loff_t *ppos)
839e8091281SJouni Malinen {
840e8091281SJouni Malinen struct ath6kl *ar = file->private_data;
841e8091281SJouni Malinen struct htc_target *target = ar->htc_target;
842e8091281SJouni Malinen int ret, i;
843e8091281SJouni Malinen u32 val;
844e8091281SJouni Malinen struct htc_endpoint_stats *ep_st;
845e8091281SJouni Malinen
846e8091281SJouni Malinen ret = kstrtou32_from_user(user_buf, count, 0, &val);
847e8091281SJouni Malinen if (ret)
848e8091281SJouni Malinen return ret;
849e8091281SJouni Malinen if (val == 0) {
850e8091281SJouni Malinen for (i = 0; i < ENDPOINT_MAX; i++) {
851e8091281SJouni Malinen ep_st = &target->endpoint[i].ep_st;
852e8091281SJouni Malinen memset(ep_st, 0, sizeof(*ep_st));
853e8091281SJouni Malinen }
854e8091281SJouni Malinen }
855e8091281SJouni Malinen
856e8091281SJouni Malinen return count;
857e8091281SJouni Malinen }
858e8091281SJouni Malinen
859e8091281SJouni Malinen static const struct file_operations fops_endpoint_stats = {
860234e3405SStephen Boyd .open = simple_open,
861e8091281SJouni Malinen .read = ath6kl_endpoint_stats_read,
862e8091281SJouni Malinen .write = ath6kl_endpoint_stats_write,
863e8091281SJouni Malinen .owner = THIS_MODULE,
864e8091281SJouni Malinen .llseek = default_llseek,
865e8091281SJouni Malinen };
866e8091281SJouni Malinen
ath6kl_get_num_reg(void)86791d57de5SVasanthakumar Thiagarajan static unsigned long ath6kl_get_num_reg(void)
86891d57de5SVasanthakumar Thiagarajan {
86991d57de5SVasanthakumar Thiagarajan int i;
87091d57de5SVasanthakumar Thiagarajan unsigned long n_reg = 0;
87191d57de5SVasanthakumar Thiagarajan
87291d57de5SVasanthakumar Thiagarajan for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
87391d57de5SVasanthakumar Thiagarajan n_reg = n_reg +
87491d57de5SVasanthakumar Thiagarajan (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
87591d57de5SVasanthakumar Thiagarajan
87691d57de5SVasanthakumar Thiagarajan return n_reg;
87791d57de5SVasanthakumar Thiagarajan }
87891d57de5SVasanthakumar Thiagarajan
ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)87991d57de5SVasanthakumar Thiagarajan static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
88091d57de5SVasanthakumar Thiagarajan {
88191d57de5SVasanthakumar Thiagarajan int i;
88291d57de5SVasanthakumar Thiagarajan
88391d57de5SVasanthakumar Thiagarajan for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
88491d57de5SVasanthakumar Thiagarajan if (reg_addr >= diag_reg[i].reg_start &&
88591d57de5SVasanthakumar Thiagarajan reg_addr <= diag_reg[i].reg_end)
88691d57de5SVasanthakumar Thiagarajan return true;
88791d57de5SVasanthakumar Thiagarajan }
88891d57de5SVasanthakumar Thiagarajan
88991d57de5SVasanthakumar Thiagarajan return false;
89091d57de5SVasanthakumar Thiagarajan }
89191d57de5SVasanthakumar Thiagarajan
ath6kl_regread_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)89291d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
89391d57de5SVasanthakumar Thiagarajan size_t count, loff_t *ppos)
89491d57de5SVasanthakumar Thiagarajan {
89591d57de5SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data;
89691d57de5SVasanthakumar Thiagarajan u8 buf[50];
89791d57de5SVasanthakumar Thiagarajan unsigned int len = 0;
89891d57de5SVasanthakumar Thiagarajan
89991d57de5SVasanthakumar Thiagarajan if (ar->debug.dbgfs_diag_reg)
90091d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
90191d57de5SVasanthakumar Thiagarajan ar->debug.dbgfs_diag_reg);
90291d57de5SVasanthakumar Thiagarajan else
90391d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, sizeof(buf) - len,
90491d57de5SVasanthakumar Thiagarajan "All diag registers\n");
90591d57de5SVasanthakumar Thiagarajan
90691d57de5SVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, len);
90791d57de5SVasanthakumar Thiagarajan }
90891d57de5SVasanthakumar Thiagarajan
ath6kl_regread_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)90991d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regread_write(struct file *file,
91091d57de5SVasanthakumar Thiagarajan const char __user *user_buf,
91191d57de5SVasanthakumar Thiagarajan size_t count, loff_t *ppos)
91291d57de5SVasanthakumar Thiagarajan {
91391d57de5SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data;
91491d57de5SVasanthakumar Thiagarajan unsigned long reg_addr;
91591d57de5SVasanthakumar Thiagarajan
91606f33f13SKalle Valo if (kstrtoul_from_user(user_buf, count, 0, ®_addr))
91791d57de5SVasanthakumar Thiagarajan return -EINVAL;
91891d57de5SVasanthakumar Thiagarajan
91991d57de5SVasanthakumar Thiagarajan if ((reg_addr % 4) != 0)
92091d57de5SVasanthakumar Thiagarajan return -EINVAL;
92191d57de5SVasanthakumar Thiagarajan
92291d57de5SVasanthakumar Thiagarajan if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
92391d57de5SVasanthakumar Thiagarajan return -EINVAL;
92491d57de5SVasanthakumar Thiagarajan
92591d57de5SVasanthakumar Thiagarajan ar->debug.dbgfs_diag_reg = reg_addr;
92691d57de5SVasanthakumar Thiagarajan
92791d57de5SVasanthakumar Thiagarajan return count;
92891d57de5SVasanthakumar Thiagarajan }
92991d57de5SVasanthakumar Thiagarajan
93091d57de5SVasanthakumar Thiagarajan static const struct file_operations fops_diag_reg_read = {
93191d57de5SVasanthakumar Thiagarajan .read = ath6kl_regread_read,
93291d57de5SVasanthakumar Thiagarajan .write = ath6kl_regread_write,
933234e3405SStephen Boyd .open = simple_open,
93491d57de5SVasanthakumar Thiagarajan .owner = THIS_MODULE,
93591d57de5SVasanthakumar Thiagarajan .llseek = default_llseek,
93691d57de5SVasanthakumar Thiagarajan };
93791d57de5SVasanthakumar Thiagarajan
ath6kl_regdump_open(struct inode * inode,struct file * file)93891d57de5SVasanthakumar Thiagarajan static int ath6kl_regdump_open(struct inode *inode, struct file *file)
93991d57de5SVasanthakumar Thiagarajan {
94091d57de5SVasanthakumar Thiagarajan struct ath6kl *ar = inode->i_private;
94191d57de5SVasanthakumar Thiagarajan u8 *buf;
94291d57de5SVasanthakumar Thiagarajan unsigned long int reg_len;
94391d57de5SVasanthakumar Thiagarajan unsigned int len = 0, n_reg;
94491d57de5SVasanthakumar Thiagarajan u32 addr;
94591d57de5SVasanthakumar Thiagarajan __le32 reg_val;
94691d57de5SVasanthakumar Thiagarajan int i, status;
94791d57de5SVasanthakumar Thiagarajan
94891d57de5SVasanthakumar Thiagarajan /* Dump all the registers if no register is specified */
94991d57de5SVasanthakumar Thiagarajan if (!ar->debug.dbgfs_diag_reg)
95091d57de5SVasanthakumar Thiagarajan n_reg = ath6kl_get_num_reg();
95191d57de5SVasanthakumar Thiagarajan else
95291d57de5SVasanthakumar Thiagarajan n_reg = 1;
95391d57de5SVasanthakumar Thiagarajan
95491d57de5SVasanthakumar Thiagarajan reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
95591d57de5SVasanthakumar Thiagarajan if (n_reg > 1)
95691d57de5SVasanthakumar Thiagarajan reg_len += REGTYPE_STR_LEN;
95791d57de5SVasanthakumar Thiagarajan
95891d57de5SVasanthakumar Thiagarajan buf = vmalloc(reg_len);
95991d57de5SVasanthakumar Thiagarajan if (!buf)
96091d57de5SVasanthakumar Thiagarajan return -ENOMEM;
96191d57de5SVasanthakumar Thiagarajan
96291d57de5SVasanthakumar Thiagarajan if (n_reg == 1) {
96391d57de5SVasanthakumar Thiagarajan addr = ar->debug.dbgfs_diag_reg;
96491d57de5SVasanthakumar Thiagarajan
96591d57de5SVasanthakumar Thiagarajan status = ath6kl_diag_read32(ar,
96691d57de5SVasanthakumar Thiagarajan TARG_VTOP(ar->target_type, addr),
96791d57de5SVasanthakumar Thiagarajan (u32 *)®_val);
96891d57de5SVasanthakumar Thiagarajan if (status)
96991d57de5SVasanthakumar Thiagarajan goto fail_reg_read;
97091d57de5SVasanthakumar Thiagarajan
97191d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, reg_len - len,
97291d57de5SVasanthakumar Thiagarajan "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
97391d57de5SVasanthakumar Thiagarajan goto done;
97491d57de5SVasanthakumar Thiagarajan }
97591d57de5SVasanthakumar Thiagarajan
97691d57de5SVasanthakumar Thiagarajan for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
97791d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, reg_len - len,
97891d57de5SVasanthakumar Thiagarajan "%s\n", diag_reg[i].reg_info);
97991d57de5SVasanthakumar Thiagarajan for (addr = diag_reg[i].reg_start;
98091d57de5SVasanthakumar Thiagarajan addr <= diag_reg[i].reg_end; addr += 4) {
98191d57de5SVasanthakumar Thiagarajan status = ath6kl_diag_read32(ar,
98291d57de5SVasanthakumar Thiagarajan TARG_VTOP(ar->target_type, addr),
98391d57de5SVasanthakumar Thiagarajan (u32 *)®_val);
98491d57de5SVasanthakumar Thiagarajan if (status)
98591d57de5SVasanthakumar Thiagarajan goto fail_reg_read;
98691d57de5SVasanthakumar Thiagarajan
98791d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, reg_len - len,
98891d57de5SVasanthakumar Thiagarajan "0x%06x 0x%08x\n",
98991d57de5SVasanthakumar Thiagarajan addr, le32_to_cpu(reg_val));
99091d57de5SVasanthakumar Thiagarajan }
99191d57de5SVasanthakumar Thiagarajan }
99291d57de5SVasanthakumar Thiagarajan
99391d57de5SVasanthakumar Thiagarajan done:
99491d57de5SVasanthakumar Thiagarajan file->private_data = buf;
99591d57de5SVasanthakumar Thiagarajan return 0;
99691d57de5SVasanthakumar Thiagarajan
99791d57de5SVasanthakumar Thiagarajan fail_reg_read:
99891d57de5SVasanthakumar Thiagarajan ath6kl_warn("Unable to read memory:%u\n", addr);
99991d57de5SVasanthakumar Thiagarajan vfree(buf);
100091d57de5SVasanthakumar Thiagarajan return -EIO;
100191d57de5SVasanthakumar Thiagarajan }
100291d57de5SVasanthakumar Thiagarajan
ath6kl_regdump_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)100391d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
100491d57de5SVasanthakumar Thiagarajan size_t count, loff_t *ppos)
100591d57de5SVasanthakumar Thiagarajan {
100691d57de5SVasanthakumar Thiagarajan u8 *buf = file->private_data;
100791d57de5SVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
100891d57de5SVasanthakumar Thiagarajan }
100991d57de5SVasanthakumar Thiagarajan
ath6kl_regdump_release(struct inode * inode,struct file * file)101091d57de5SVasanthakumar Thiagarajan static int ath6kl_regdump_release(struct inode *inode, struct file *file)
101191d57de5SVasanthakumar Thiagarajan {
101291d57de5SVasanthakumar Thiagarajan vfree(file->private_data);
101391d57de5SVasanthakumar Thiagarajan return 0;
101491d57de5SVasanthakumar Thiagarajan }
101591d57de5SVasanthakumar Thiagarajan
101691d57de5SVasanthakumar Thiagarajan static const struct file_operations fops_reg_dump = {
101791d57de5SVasanthakumar Thiagarajan .open = ath6kl_regdump_open,
101891d57de5SVasanthakumar Thiagarajan .read = ath6kl_regdump_read,
101991d57de5SVasanthakumar Thiagarajan .release = ath6kl_regdump_release,
102091d57de5SVasanthakumar Thiagarajan .owner = THIS_MODULE,
102191d57de5SVasanthakumar Thiagarajan .llseek = default_llseek,
102291d57de5SVasanthakumar Thiagarajan };
102391d57de5SVasanthakumar Thiagarajan
ath6kl_lrssi_roam_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1024e5090444SVivek Natarajan static ssize_t ath6kl_lrssi_roam_write(struct file *file,
1025e5090444SVivek Natarajan const char __user *user_buf,
1026e5090444SVivek Natarajan size_t count, loff_t *ppos)
1027e5090444SVivek Natarajan {
1028e5090444SVivek Natarajan struct ath6kl *ar = file->private_data;
1029e5090444SVivek Natarajan unsigned long lrssi_roam_threshold;
1030*54433367SAnirudh Rayabharam int ret;
1031e5090444SVivek Natarajan
103206f33f13SKalle Valo if (kstrtoul_from_user(user_buf, count, 0, &lrssi_roam_threshold))
1033e5090444SVivek Natarajan return -EINVAL;
1034e5090444SVivek Natarajan
1035e5090444SVivek Natarajan ar->lrssi_roam_threshold = lrssi_roam_threshold;
1036e5090444SVivek Natarajan
1037*54433367SAnirudh Rayabharam ret = ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
1038e5090444SVivek Natarajan
1039*54433367SAnirudh Rayabharam if (ret)
1040*54433367SAnirudh Rayabharam return ret;
1041e5090444SVivek Natarajan return count;
1042e5090444SVivek Natarajan }
1043e5090444SVivek Natarajan
ath6kl_lrssi_roam_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1044e5090444SVivek Natarajan static ssize_t ath6kl_lrssi_roam_read(struct file *file,
1045e5090444SVivek Natarajan char __user *user_buf,
1046e5090444SVivek Natarajan size_t count, loff_t *ppos)
1047e5090444SVivek Natarajan {
1048e5090444SVivek Natarajan struct ath6kl *ar = file->private_data;
1049e5090444SVivek Natarajan char buf[32];
1050e5090444SVivek Natarajan unsigned int len;
1051e5090444SVivek Natarajan
1052e5090444SVivek Natarajan len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
1053e5090444SVivek Natarajan
1054e5090444SVivek Natarajan return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1055e5090444SVivek Natarajan }
1056e5090444SVivek Natarajan
1057e5090444SVivek Natarajan static const struct file_operations fops_lrssi_roam_threshold = {
1058e5090444SVivek Natarajan .read = ath6kl_lrssi_roam_read,
1059e5090444SVivek Natarajan .write = ath6kl_lrssi_roam_write,
1060234e3405SStephen Boyd .open = simple_open,
1061e5090444SVivek Natarajan .owner = THIS_MODULE,
1062e5090444SVivek Natarajan .llseek = default_llseek,
1063e5090444SVivek Natarajan };
1064e5090444SVivek Natarajan
ath6kl_regwrite_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1065252c068bSVasanthakumar Thiagarajan static ssize_t ath6kl_regwrite_read(struct file *file,
1066252c068bSVasanthakumar Thiagarajan char __user *user_buf,
1067252c068bSVasanthakumar Thiagarajan size_t count, loff_t *ppos)
1068252c068bSVasanthakumar Thiagarajan {
1069252c068bSVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data;
1070252c068bSVasanthakumar Thiagarajan u8 buf[32];
1071252c068bSVasanthakumar Thiagarajan unsigned int len = 0;
1072252c068bSVasanthakumar Thiagarajan
1073252c068bSVasanthakumar Thiagarajan len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
1074252c068bSVasanthakumar Thiagarajan ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
1075252c068bSVasanthakumar Thiagarajan
1076252c068bSVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1077252c068bSVasanthakumar Thiagarajan }
1078252c068bSVasanthakumar Thiagarajan
ath6kl_regwrite_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1079252c068bSVasanthakumar Thiagarajan static ssize_t ath6kl_regwrite_write(struct file *file,
1080252c068bSVasanthakumar Thiagarajan const char __user *user_buf,
1081252c068bSVasanthakumar Thiagarajan size_t count, loff_t *ppos)
1082252c068bSVasanthakumar Thiagarajan {
1083252c068bSVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data;
1084252c068bSVasanthakumar Thiagarajan char buf[32];
1085252c068bSVasanthakumar Thiagarajan char *sptr, *token;
1086252c068bSVasanthakumar Thiagarajan unsigned int len = 0;
1087252c068bSVasanthakumar Thiagarajan u32 reg_addr, reg_val;
1088252c068bSVasanthakumar Thiagarajan
1089252c068bSVasanthakumar Thiagarajan len = min(count, sizeof(buf) - 1);
1090252c068bSVasanthakumar Thiagarajan if (copy_from_user(buf, user_buf, len))
1091252c068bSVasanthakumar Thiagarajan return -EFAULT;
1092252c068bSVasanthakumar Thiagarajan
1093252c068bSVasanthakumar Thiagarajan buf[len] = '\0';
1094252c068bSVasanthakumar Thiagarajan sptr = buf;
1095252c068bSVasanthakumar Thiagarajan
1096252c068bSVasanthakumar Thiagarajan token = strsep(&sptr, "=");
1097252c068bSVasanthakumar Thiagarajan if (!token)
1098252c068bSVasanthakumar Thiagarajan return -EINVAL;
1099252c068bSVasanthakumar Thiagarajan
1100252c068bSVasanthakumar Thiagarajan if (kstrtou32(token, 0, ®_addr))
1101252c068bSVasanthakumar Thiagarajan return -EINVAL;
1102252c068bSVasanthakumar Thiagarajan
1103252c068bSVasanthakumar Thiagarajan if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
1104252c068bSVasanthakumar Thiagarajan return -EINVAL;
1105252c068bSVasanthakumar Thiagarajan
1106252c068bSVasanthakumar Thiagarajan if (kstrtou32(sptr, 0, ®_val))
1107252c068bSVasanthakumar Thiagarajan return -EINVAL;
1108252c068bSVasanthakumar Thiagarajan
1109252c068bSVasanthakumar Thiagarajan ar->debug.diag_reg_addr_wr = reg_addr;
1110252c068bSVasanthakumar Thiagarajan ar->debug.diag_reg_val_wr = reg_val;
1111252c068bSVasanthakumar Thiagarajan
1112252c068bSVasanthakumar Thiagarajan if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
1113252c068bSVasanthakumar Thiagarajan cpu_to_le32(ar->debug.diag_reg_val_wr)))
1114252c068bSVasanthakumar Thiagarajan return -EIO;
1115252c068bSVasanthakumar Thiagarajan
1116252c068bSVasanthakumar Thiagarajan return count;
1117252c068bSVasanthakumar Thiagarajan }
1118252c068bSVasanthakumar Thiagarajan
1119252c068bSVasanthakumar Thiagarajan static const struct file_operations fops_diag_reg_write = {
1120252c068bSVasanthakumar Thiagarajan .read = ath6kl_regwrite_read,
1121252c068bSVasanthakumar Thiagarajan .write = ath6kl_regwrite_write,
1122234e3405SStephen Boyd .open = simple_open,
1123252c068bSVasanthakumar Thiagarajan .owner = THIS_MODULE,
1124252c068bSVasanthakumar Thiagarajan .llseek = default_llseek,
1125252c068bSVasanthakumar Thiagarajan };
1126252c068bSVasanthakumar Thiagarajan
ath6kl_debug_roam_tbl_event(struct ath6kl * ar,const void * buf,size_t len)11274b28a80dSJouni Malinen int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
11284b28a80dSJouni Malinen size_t len)
11294b28a80dSJouni Malinen {
11304b28a80dSJouni Malinen const struct wmi_target_roam_tbl *tbl;
11314b28a80dSJouni Malinen u16 num_entries;
11324b28a80dSJouni Malinen
11334b28a80dSJouni Malinen if (len < sizeof(*tbl))
11344b28a80dSJouni Malinen return -EINVAL;
11354b28a80dSJouni Malinen
11364b28a80dSJouni Malinen tbl = (const struct wmi_target_roam_tbl *) buf;
11374b28a80dSJouni Malinen num_entries = le16_to_cpu(tbl->num_entries);
1138df75786bSGustavo A. R. Silva if (struct_size(tbl, info, num_entries) > len)
11394b28a80dSJouni Malinen return -EINVAL;
11404b28a80dSJouni Malinen
11414b28a80dSJouni Malinen if (ar->debug.roam_tbl == NULL ||
11424b28a80dSJouni Malinen ar->debug.roam_tbl_len < (unsigned int) len) {
11434b28a80dSJouni Malinen kfree(ar->debug.roam_tbl);
11444b28a80dSJouni Malinen ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
11454b28a80dSJouni Malinen if (ar->debug.roam_tbl == NULL)
11464b28a80dSJouni Malinen return -ENOMEM;
11474b28a80dSJouni Malinen }
11484b28a80dSJouni Malinen
11494b28a80dSJouni Malinen memcpy(ar->debug.roam_tbl, buf, len);
11504b28a80dSJouni Malinen ar->debug.roam_tbl_len = len;
11514b28a80dSJouni Malinen
11524b28a80dSJouni Malinen if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
11534b28a80dSJouni Malinen clear_bit(ROAM_TBL_PEND, &ar->flag);
11544b28a80dSJouni Malinen wake_up(&ar->event_wq);
11554b28a80dSJouni Malinen }
11564b28a80dSJouni Malinen
11574b28a80dSJouni Malinen return 0;
11584b28a80dSJouni Malinen }
11594b28a80dSJouni Malinen
ath6kl_roam_table_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)11604b28a80dSJouni Malinen static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
11614b28a80dSJouni Malinen size_t count, loff_t *ppos)
11624b28a80dSJouni Malinen {
11634b28a80dSJouni Malinen struct ath6kl *ar = file->private_data;
11644b28a80dSJouni Malinen int ret;
11654b28a80dSJouni Malinen long left;
11664b28a80dSJouni Malinen struct wmi_target_roam_tbl *tbl;
11674b28a80dSJouni Malinen u16 num_entries, i;
11684b28a80dSJouni Malinen char *buf;
11694b28a80dSJouni Malinen unsigned int len, buf_len;
11704b28a80dSJouni Malinen ssize_t ret_cnt;
11714b28a80dSJouni Malinen
11724b28a80dSJouni Malinen if (down_interruptible(&ar->sem))
11734b28a80dSJouni Malinen return -EBUSY;
11744b28a80dSJouni Malinen
11754b28a80dSJouni Malinen set_bit(ROAM_TBL_PEND, &ar->flag);
11764b28a80dSJouni Malinen
11774b28a80dSJouni Malinen ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
11784b28a80dSJouni Malinen if (ret) {
11794b28a80dSJouni Malinen up(&ar->sem);
11804b28a80dSJouni Malinen return ret;
11814b28a80dSJouni Malinen }
11824b28a80dSJouni Malinen
11834b28a80dSJouni Malinen left = wait_event_interruptible_timeout(
11844b28a80dSJouni Malinen ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
11854b28a80dSJouni Malinen up(&ar->sem);
11864b28a80dSJouni Malinen
11874b28a80dSJouni Malinen if (left <= 0)
11884b28a80dSJouni Malinen return -ETIMEDOUT;
11894b28a80dSJouni Malinen
11904b28a80dSJouni Malinen if (ar->debug.roam_tbl == NULL)
11914b28a80dSJouni Malinen return -ENOMEM;
11924b28a80dSJouni Malinen
11934b28a80dSJouni Malinen tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
11944b28a80dSJouni Malinen num_entries = le16_to_cpu(tbl->num_entries);
11954b28a80dSJouni Malinen
11964b28a80dSJouni Malinen buf_len = 100 + num_entries * 100;
11974b28a80dSJouni Malinen buf = kzalloc(buf_len, GFP_KERNEL);
11984b28a80dSJouni Malinen if (buf == NULL)
11994b28a80dSJouni Malinen return -ENOMEM;
12004b28a80dSJouni Malinen len = 0;
12014b28a80dSJouni Malinen len += scnprintf(buf + len, buf_len - len,
12024b28a80dSJouni Malinen "roam_mode=%u\n\n"
12034b28a80dSJouni Malinen "# roam_util bssid rssi rssidt last_rssi util bias\n",
12044b28a80dSJouni Malinen le16_to_cpu(tbl->roam_mode));
12054b28a80dSJouni Malinen
12064b28a80dSJouni Malinen for (i = 0; i < num_entries; i++) {
12074b28a80dSJouni Malinen struct wmi_bss_roam_info *info = &tbl->info[i];
12084b28a80dSJouni Malinen len += scnprintf(buf + len, buf_len - len,
12094b28a80dSJouni Malinen "%d %pM %d %d %d %d %d\n",
12104b28a80dSJouni Malinen a_sle32_to_cpu(info->roam_util), info->bssid,
12114b28a80dSJouni Malinen info->rssi, info->rssidt, info->last_rssi,
12124b28a80dSJouni Malinen info->util, info->bias);
12134b28a80dSJouni Malinen }
12144b28a80dSJouni Malinen
12154b28a80dSJouni Malinen if (len > buf_len)
12164b28a80dSJouni Malinen len = buf_len;
12174b28a80dSJouni Malinen
12184b28a80dSJouni Malinen ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
12194b28a80dSJouni Malinen
12204b28a80dSJouni Malinen kfree(buf);
12214b28a80dSJouni Malinen return ret_cnt;
12224b28a80dSJouni Malinen }
12234b28a80dSJouni Malinen
12244b28a80dSJouni Malinen static const struct file_operations fops_roam_table = {
12254b28a80dSJouni Malinen .read = ath6kl_roam_table_read,
1226234e3405SStephen Boyd .open = simple_open,
12274b28a80dSJouni Malinen .owner = THIS_MODULE,
12284b28a80dSJouni Malinen .llseek = default_llseek,
12294b28a80dSJouni Malinen };
12304b28a80dSJouni Malinen
ath6kl_force_roam_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)12311261875fSJouni Malinen static ssize_t ath6kl_force_roam_write(struct file *file,
12321261875fSJouni Malinen const char __user *user_buf,
12331261875fSJouni Malinen size_t count, loff_t *ppos)
12341261875fSJouni Malinen {
12351261875fSJouni Malinen struct ath6kl *ar = file->private_data;
12361261875fSJouni Malinen int ret;
12371261875fSJouni Malinen char buf[20];
12381261875fSJouni Malinen size_t len;
12391261875fSJouni Malinen u8 bssid[ETH_ALEN];
12401261875fSJouni Malinen
12411261875fSJouni Malinen len = min(count, sizeof(buf) - 1);
12421261875fSJouni Malinen if (copy_from_user(buf, user_buf, len))
12431261875fSJouni Malinen return -EFAULT;
12441261875fSJouni Malinen buf[len] = '\0';
12451261875fSJouni Malinen
1246ade98330SAndy Shevchenko if (!mac_pton(buf, bssid))
12471261875fSJouni Malinen return -EINVAL;
12481261875fSJouni Malinen
12491261875fSJouni Malinen ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
12501261875fSJouni Malinen if (ret)
12511261875fSJouni Malinen return ret;
12521261875fSJouni Malinen
12531261875fSJouni Malinen return count;
12541261875fSJouni Malinen }
12551261875fSJouni Malinen
12561261875fSJouni Malinen static const struct file_operations fops_force_roam = {
12571261875fSJouni Malinen .write = ath6kl_force_roam_write,
1258234e3405SStephen Boyd .open = simple_open,
12591261875fSJouni Malinen .owner = THIS_MODULE,
12601261875fSJouni Malinen .llseek = default_llseek,
12611261875fSJouni Malinen };
12621261875fSJouni Malinen
ath6kl_roam_mode_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)12631261875fSJouni Malinen static ssize_t ath6kl_roam_mode_write(struct file *file,
12641261875fSJouni Malinen const char __user *user_buf,
12651261875fSJouni Malinen size_t count, loff_t *ppos)
12661261875fSJouni Malinen {
12671261875fSJouni Malinen struct ath6kl *ar = file->private_data;
12681261875fSJouni Malinen int ret;
12691261875fSJouni Malinen char buf[20];
12701261875fSJouni Malinen size_t len;
12711261875fSJouni Malinen enum wmi_roam_mode mode;
12721261875fSJouni Malinen
12731261875fSJouni Malinen len = min(count, sizeof(buf) - 1);
12741261875fSJouni Malinen if (copy_from_user(buf, user_buf, len))
12751261875fSJouni Malinen return -EFAULT;
12761261875fSJouni Malinen buf[len] = '\0';
12771261875fSJouni Malinen if (len > 0 && buf[len - 1] == '\n')
12781261875fSJouni Malinen buf[len - 1] = '\0';
12791261875fSJouni Malinen
12801261875fSJouni Malinen if (strcasecmp(buf, "default") == 0)
12811261875fSJouni Malinen mode = WMI_DEFAULT_ROAM_MODE;
12821261875fSJouni Malinen else if (strcasecmp(buf, "bssbias") == 0)
12831261875fSJouni Malinen mode = WMI_HOST_BIAS_ROAM_MODE;
12841261875fSJouni Malinen else if (strcasecmp(buf, "lock") == 0)
12851261875fSJouni Malinen mode = WMI_LOCK_BSS_MODE;
12861261875fSJouni Malinen else
12871261875fSJouni Malinen return -EINVAL;
12881261875fSJouni Malinen
12891261875fSJouni Malinen ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
12901261875fSJouni Malinen if (ret)
12911261875fSJouni Malinen return ret;
12921261875fSJouni Malinen
12931261875fSJouni Malinen return count;
12941261875fSJouni Malinen }
12951261875fSJouni Malinen
12961261875fSJouni Malinen static const struct file_operations fops_roam_mode = {
12971261875fSJouni Malinen .write = ath6kl_roam_mode_write,
1298234e3405SStephen Boyd .open = simple_open,
12991261875fSJouni Malinen .owner = THIS_MODULE,
13001261875fSJouni Malinen .llseek = default_llseek,
13011261875fSJouni Malinen };
13021261875fSJouni Malinen
ath6kl_debug_set_keepalive(struct ath6kl * ar,u8 keepalive)1303ff0b0075SJouni Malinen void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1304ff0b0075SJouni Malinen {
1305ff0b0075SJouni Malinen ar->debug.keepalive = keepalive;
1306ff0b0075SJouni Malinen }
1307ff0b0075SJouni Malinen
ath6kl_keepalive_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1308ff0b0075SJouni Malinen static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1309ff0b0075SJouni Malinen size_t count, loff_t *ppos)
1310ff0b0075SJouni Malinen {
1311ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data;
1312ff0b0075SJouni Malinen char buf[16];
1313ff0b0075SJouni Malinen int len;
1314ff0b0075SJouni Malinen
1315ff0b0075SJouni Malinen len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1316ff0b0075SJouni Malinen
1317ff0b0075SJouni Malinen return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1318ff0b0075SJouni Malinen }
1319ff0b0075SJouni Malinen
ath6kl_keepalive_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1320ff0b0075SJouni Malinen static ssize_t ath6kl_keepalive_write(struct file *file,
1321ff0b0075SJouni Malinen const char __user *user_buf,
1322ff0b0075SJouni Malinen size_t count, loff_t *ppos)
1323ff0b0075SJouni Malinen {
1324ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data;
1325ff0b0075SJouni Malinen int ret;
1326ff0b0075SJouni Malinen u8 val;
1327ff0b0075SJouni Malinen
1328ff0b0075SJouni Malinen ret = kstrtou8_from_user(user_buf, count, 0, &val);
1329ff0b0075SJouni Malinen if (ret)
1330ff0b0075SJouni Malinen return ret;
1331ff0b0075SJouni Malinen
13320ce59445SVasanthakumar Thiagarajan ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val);
1333ff0b0075SJouni Malinen if (ret)
1334ff0b0075SJouni Malinen return ret;
1335ff0b0075SJouni Malinen
1336ff0b0075SJouni Malinen return count;
1337ff0b0075SJouni Malinen }
1338ff0b0075SJouni Malinen
1339ff0b0075SJouni Malinen static const struct file_operations fops_keepalive = {
1340234e3405SStephen Boyd .open = simple_open,
1341ff0b0075SJouni Malinen .read = ath6kl_keepalive_read,
1342ff0b0075SJouni Malinen .write = ath6kl_keepalive_write,
1343ff0b0075SJouni Malinen .owner = THIS_MODULE,
1344ff0b0075SJouni Malinen .llseek = default_llseek,
1345ff0b0075SJouni Malinen };
1346ff0b0075SJouni Malinen
ath6kl_debug_set_disconnect_timeout(struct ath6kl * ar,u8 timeout)1347ff0b0075SJouni Malinen void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1348ff0b0075SJouni Malinen {
1349ff0b0075SJouni Malinen ar->debug.disc_timeout = timeout;
1350ff0b0075SJouni Malinen }
1351ff0b0075SJouni Malinen
ath6kl_disconnect_timeout_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1352ff0b0075SJouni Malinen static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1353ff0b0075SJouni Malinen char __user *user_buf,
1354ff0b0075SJouni Malinen size_t count, loff_t *ppos)
1355ff0b0075SJouni Malinen {
1356ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data;
1357ff0b0075SJouni Malinen char buf[16];
1358ff0b0075SJouni Malinen int len;
1359ff0b0075SJouni Malinen
1360ff0b0075SJouni Malinen len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1361ff0b0075SJouni Malinen
1362ff0b0075SJouni Malinen return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1363ff0b0075SJouni Malinen }
1364ff0b0075SJouni Malinen
ath6kl_disconnect_timeout_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1365ff0b0075SJouni Malinen static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1366ff0b0075SJouni Malinen const char __user *user_buf,
1367ff0b0075SJouni Malinen size_t count, loff_t *ppos)
1368ff0b0075SJouni Malinen {
1369ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data;
1370ff0b0075SJouni Malinen int ret;
1371ff0b0075SJouni Malinen u8 val;
1372ff0b0075SJouni Malinen
1373ff0b0075SJouni Malinen ret = kstrtou8_from_user(user_buf, count, 0, &val);
1374ff0b0075SJouni Malinen if (ret)
1375ff0b0075SJouni Malinen return ret;
1376ff0b0075SJouni Malinen
13770ce59445SVasanthakumar Thiagarajan ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val);
1378ff0b0075SJouni Malinen if (ret)
1379ff0b0075SJouni Malinen return ret;
1380ff0b0075SJouni Malinen
1381ff0b0075SJouni Malinen return count;
1382ff0b0075SJouni Malinen }
1383ff0b0075SJouni Malinen
1384ff0b0075SJouni Malinen static const struct file_operations fops_disconnect_timeout = {
1385234e3405SStephen Boyd .open = simple_open,
1386ff0b0075SJouni Malinen .read = ath6kl_disconnect_timeout_read,
1387ff0b0075SJouni Malinen .write = ath6kl_disconnect_timeout_write,
1388ff0b0075SJouni Malinen .owner = THIS_MODULE,
1389ff0b0075SJouni Malinen .llseek = default_llseek,
1390ff0b0075SJouni Malinen };
1391ff0b0075SJouni Malinen
ath6kl_create_qos_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)13928fffd9e5SRishi Panjwani static ssize_t ath6kl_create_qos_write(struct file *file,
13938fffd9e5SRishi Panjwani const char __user *user_buf,
13948fffd9e5SRishi Panjwani size_t count, loff_t *ppos)
13958fffd9e5SRishi Panjwani {
13968fffd9e5SRishi Panjwani struct ath6kl *ar = file->private_data;
1397990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif;
13988cb6d991SVasanthakumar Thiagarajan char buf[200];
13998fffd9e5SRishi Panjwani ssize_t len;
14008fffd9e5SRishi Panjwani char *sptr, *token;
14018fffd9e5SRishi Panjwani struct wmi_create_pstream_cmd pstream;
14028fffd9e5SRishi Panjwani u32 val32;
14038fffd9e5SRishi Panjwani u16 val16;
14048fffd9e5SRishi Panjwani
1405990bd915SVasanthakumar Thiagarajan vif = ath6kl_vif_first(ar);
1406990bd915SVasanthakumar Thiagarajan if (!vif)
1407990bd915SVasanthakumar Thiagarajan return -EIO;
1408990bd915SVasanthakumar Thiagarajan
14098fffd9e5SRishi Panjwani len = min(count, sizeof(buf) - 1);
14108fffd9e5SRishi Panjwani if (copy_from_user(buf, user_buf, len))
14118fffd9e5SRishi Panjwani return -EFAULT;
14128fffd9e5SRishi Panjwani buf[len] = '\0';
14138fffd9e5SRishi Panjwani sptr = buf;
14148fffd9e5SRishi Panjwani
14158fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14168fffd9e5SRishi Panjwani if (!token)
14178fffd9e5SRishi Panjwani return -EINVAL;
14188fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.user_pri))
14198fffd9e5SRishi Panjwani return -EINVAL;
14208fffd9e5SRishi Panjwani
14218fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14228fffd9e5SRishi Panjwani if (!token)
14238fffd9e5SRishi Panjwani return -EINVAL;
14248fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.traffic_direc))
14258fffd9e5SRishi Panjwani return -EINVAL;
14268fffd9e5SRishi Panjwani
14278fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14288fffd9e5SRishi Panjwani if (!token)
14298fffd9e5SRishi Panjwani return -EINVAL;
14308fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.traffic_class))
14318fffd9e5SRishi Panjwani return -EINVAL;
14328fffd9e5SRishi Panjwani
14338fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14348fffd9e5SRishi Panjwani if (!token)
14358fffd9e5SRishi Panjwani return -EINVAL;
14368fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.traffic_type))
14378fffd9e5SRishi Panjwani return -EINVAL;
14388fffd9e5SRishi Panjwani
14398fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14408fffd9e5SRishi Panjwani if (!token)
14418fffd9e5SRishi Panjwani return -EINVAL;
14428fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.voice_psc_cap))
14438fffd9e5SRishi Panjwani return -EINVAL;
14448fffd9e5SRishi Panjwani
14458fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14468fffd9e5SRishi Panjwani if (!token)
14478fffd9e5SRishi Panjwani return -EINVAL;
14488fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
14498fffd9e5SRishi Panjwani return -EINVAL;
14508fffd9e5SRishi Panjwani pstream.min_service_int = cpu_to_le32(val32);
14518fffd9e5SRishi Panjwani
14528fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14538fffd9e5SRishi Panjwani if (!token)
14548fffd9e5SRishi Panjwani return -EINVAL;
14558fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
14568fffd9e5SRishi Panjwani return -EINVAL;
14578fffd9e5SRishi Panjwani pstream.max_service_int = cpu_to_le32(val32);
14588fffd9e5SRishi Panjwani
14598fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14608fffd9e5SRishi Panjwani if (!token)
14618fffd9e5SRishi Panjwani return -EINVAL;
14628fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
14638fffd9e5SRishi Panjwani return -EINVAL;
14648fffd9e5SRishi Panjwani pstream.inactivity_int = cpu_to_le32(val32);
14658fffd9e5SRishi Panjwani
14668fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14678fffd9e5SRishi Panjwani if (!token)
14688fffd9e5SRishi Panjwani return -EINVAL;
14698fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
14708fffd9e5SRishi Panjwani return -EINVAL;
14718fffd9e5SRishi Panjwani pstream.suspension_int = cpu_to_le32(val32);
14728fffd9e5SRishi Panjwani
14738fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14748fffd9e5SRishi Panjwani if (!token)
14758fffd9e5SRishi Panjwani return -EINVAL;
14768fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
14778fffd9e5SRishi Panjwani return -EINVAL;
14788fffd9e5SRishi Panjwani pstream.service_start_time = cpu_to_le32(val32);
14798fffd9e5SRishi Panjwani
14808fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14818fffd9e5SRishi Panjwani if (!token)
14828fffd9e5SRishi Panjwani return -EINVAL;
14838fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.tsid))
14848fffd9e5SRishi Panjwani return -EINVAL;
14858fffd9e5SRishi Panjwani
14868fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14878fffd9e5SRishi Panjwani if (!token)
14888fffd9e5SRishi Panjwani return -EINVAL;
14898fffd9e5SRishi Panjwani if (kstrtou16(token, 0, &val16))
14908fffd9e5SRishi Panjwani return -EINVAL;
14918fffd9e5SRishi Panjwani pstream.nominal_msdu = cpu_to_le16(val16);
14928fffd9e5SRishi Panjwani
14938fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
14948fffd9e5SRishi Panjwani if (!token)
14958fffd9e5SRishi Panjwani return -EINVAL;
14968fffd9e5SRishi Panjwani if (kstrtou16(token, 0, &val16))
14978fffd9e5SRishi Panjwani return -EINVAL;
14988fffd9e5SRishi Panjwani pstream.max_msdu = cpu_to_le16(val16);
14998fffd9e5SRishi Panjwani
15008fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15018fffd9e5SRishi Panjwani if (!token)
15028fffd9e5SRishi Panjwani return -EINVAL;
15038fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15048fffd9e5SRishi Panjwani return -EINVAL;
15058fffd9e5SRishi Panjwani pstream.min_data_rate = cpu_to_le32(val32);
15068fffd9e5SRishi Panjwani
15078fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15088fffd9e5SRishi Panjwani if (!token)
15098fffd9e5SRishi Panjwani return -EINVAL;
15108fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15118fffd9e5SRishi Panjwani return -EINVAL;
15128fffd9e5SRishi Panjwani pstream.mean_data_rate = cpu_to_le32(val32);
15138fffd9e5SRishi Panjwani
15148fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15158fffd9e5SRishi Panjwani if (!token)
15168fffd9e5SRishi Panjwani return -EINVAL;
15178fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15188fffd9e5SRishi Panjwani return -EINVAL;
15198fffd9e5SRishi Panjwani pstream.peak_data_rate = cpu_to_le32(val32);
15208fffd9e5SRishi Panjwani
15218fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15228fffd9e5SRishi Panjwani if (!token)
15238fffd9e5SRishi Panjwani return -EINVAL;
15248fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15258fffd9e5SRishi Panjwani return -EINVAL;
15268fffd9e5SRishi Panjwani pstream.max_burst_size = cpu_to_le32(val32);
15278fffd9e5SRishi Panjwani
15288fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15298fffd9e5SRishi Panjwani if (!token)
15308fffd9e5SRishi Panjwani return -EINVAL;
15318fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15328fffd9e5SRishi Panjwani return -EINVAL;
15338fffd9e5SRishi Panjwani pstream.delay_bound = cpu_to_le32(val32);
15348fffd9e5SRishi Panjwani
15358fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15368fffd9e5SRishi Panjwani if (!token)
15378fffd9e5SRishi Panjwani return -EINVAL;
15388fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15398fffd9e5SRishi Panjwani return -EINVAL;
15408fffd9e5SRishi Panjwani pstream.min_phy_rate = cpu_to_le32(val32);
15418fffd9e5SRishi Panjwani
15428fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15438fffd9e5SRishi Panjwani if (!token)
15448fffd9e5SRishi Panjwani return -EINVAL;
15458fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15468fffd9e5SRishi Panjwani return -EINVAL;
15478fffd9e5SRishi Panjwani pstream.sba = cpu_to_le32(val32);
15488fffd9e5SRishi Panjwani
15498fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15508fffd9e5SRishi Panjwani if (!token)
15518fffd9e5SRishi Panjwani return -EINVAL;
15528fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32))
15538fffd9e5SRishi Panjwani return -EINVAL;
15548fffd9e5SRishi Panjwani pstream.medium_time = cpu_to_le32(val32);
15558fffd9e5SRishi Panjwani
15565fbea5dcSChilam Ng pstream.nominal_phy = le32_to_cpu(pstream.min_phy_rate) / 1000000;
15575fbea5dcSChilam Ng
1558240d2799SVasanthakumar Thiagarajan ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
15598fffd9e5SRishi Panjwani
15608fffd9e5SRishi Panjwani return count;
15618fffd9e5SRishi Panjwani }
15628fffd9e5SRishi Panjwani
15638fffd9e5SRishi Panjwani static const struct file_operations fops_create_qos = {
15648fffd9e5SRishi Panjwani .write = ath6kl_create_qos_write,
1565234e3405SStephen Boyd .open = simple_open,
15668fffd9e5SRishi Panjwani .owner = THIS_MODULE,
15678fffd9e5SRishi Panjwani .llseek = default_llseek,
15688fffd9e5SRishi Panjwani };
15698fffd9e5SRishi Panjwani
ath6kl_delete_qos_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)15708fffd9e5SRishi Panjwani static ssize_t ath6kl_delete_qos_write(struct file *file,
15718fffd9e5SRishi Panjwani const char __user *user_buf,
15728fffd9e5SRishi Panjwani size_t count, loff_t *ppos)
15738fffd9e5SRishi Panjwani {
15748fffd9e5SRishi Panjwani struct ath6kl *ar = file->private_data;
1575990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif;
15768fffd9e5SRishi Panjwani char buf[100];
15778fffd9e5SRishi Panjwani ssize_t len;
15788fffd9e5SRishi Panjwani char *sptr, *token;
15798fffd9e5SRishi Panjwani u8 traffic_class;
15808fffd9e5SRishi Panjwani u8 tsid;
15818fffd9e5SRishi Panjwani
1582990bd915SVasanthakumar Thiagarajan vif = ath6kl_vif_first(ar);
1583990bd915SVasanthakumar Thiagarajan if (!vif)
1584990bd915SVasanthakumar Thiagarajan return -EIO;
1585990bd915SVasanthakumar Thiagarajan
15868fffd9e5SRishi Panjwani len = min(count, sizeof(buf) - 1);
15878fffd9e5SRishi Panjwani if (copy_from_user(buf, user_buf, len))
15888fffd9e5SRishi Panjwani return -EFAULT;
15898fffd9e5SRishi Panjwani buf[len] = '\0';
15908fffd9e5SRishi Panjwani sptr = buf;
15918fffd9e5SRishi Panjwani
15928fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15938fffd9e5SRishi Panjwani if (!token)
15948fffd9e5SRishi Panjwani return -EINVAL;
15958fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &traffic_class))
15968fffd9e5SRishi Panjwani return -EINVAL;
15978fffd9e5SRishi Panjwani
15988fffd9e5SRishi Panjwani token = strsep(&sptr, " ");
15998fffd9e5SRishi Panjwani if (!token)
16008fffd9e5SRishi Panjwani return -EINVAL;
16018fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &tsid))
16028fffd9e5SRishi Panjwani return -EINVAL;
16038fffd9e5SRishi Panjwani
1604240d2799SVasanthakumar Thiagarajan ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
1605240d2799SVasanthakumar Thiagarajan traffic_class, tsid);
16068fffd9e5SRishi Panjwani
16078fffd9e5SRishi Panjwani return count;
16088fffd9e5SRishi Panjwani }
16098fffd9e5SRishi Panjwani
16108fffd9e5SRishi Panjwani static const struct file_operations fops_delete_qos = {
16118fffd9e5SRishi Panjwani .write = ath6kl_delete_qos_write,
1612234e3405SStephen Boyd .open = simple_open,
16138fffd9e5SRishi Panjwani .owner = THIS_MODULE,
16148fffd9e5SRishi Panjwani .llseek = default_llseek,
16158fffd9e5SRishi Panjwani };
16168fffd9e5SRishi Panjwani
ath6kl_bgscan_int_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1617116b3a2eSRishi Panjwani static ssize_t ath6kl_bgscan_int_write(struct file *file,
1618116b3a2eSRishi Panjwani const char __user *user_buf,
1619116b3a2eSRishi Panjwani size_t count, loff_t *ppos)
1620116b3a2eSRishi Panjwani {
1621116b3a2eSRishi Panjwani struct ath6kl *ar = file->private_data;
1622eb38987eSRaja Mani struct ath6kl_vif *vif;
1623116b3a2eSRishi Panjwani u16 bgscan_int;
1624116b3a2eSRishi Panjwani char buf[32];
1625116b3a2eSRishi Panjwani ssize_t len;
1626116b3a2eSRishi Panjwani
1627eb38987eSRaja Mani vif = ath6kl_vif_first(ar);
1628eb38987eSRaja Mani if (!vif)
1629eb38987eSRaja Mani return -EIO;
1630eb38987eSRaja Mani
1631116b3a2eSRishi Panjwani len = min(count, sizeof(buf) - 1);
1632116b3a2eSRishi Panjwani if (copy_from_user(buf, user_buf, len))
1633116b3a2eSRishi Panjwani return -EFAULT;
1634116b3a2eSRishi Panjwani
1635116b3a2eSRishi Panjwani buf[len] = '\0';
1636116b3a2eSRishi Panjwani if (kstrtou16(buf, 0, &bgscan_int))
1637116b3a2eSRishi Panjwani return -EINVAL;
1638116b3a2eSRishi Panjwani
1639116b3a2eSRishi Panjwani if (bgscan_int == 0)
1640116b3a2eSRishi Panjwani bgscan_int = 0xffff;
1641116b3a2eSRishi Panjwani
1642eb38987eSRaja Mani vif->bg_scan_period = bgscan_int;
1643eb38987eSRaja Mani
1644334234b5SVasanthakumar Thiagarajan ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
1645116b3a2eSRishi Panjwani 0, 0, 0);
1646116b3a2eSRishi Panjwani
1647116b3a2eSRishi Panjwani return count;
1648116b3a2eSRishi Panjwani }
1649116b3a2eSRishi Panjwani
1650116b3a2eSRishi Panjwani static const struct file_operations fops_bgscan_int = {
1651116b3a2eSRishi Panjwani .write = ath6kl_bgscan_int_write,
1652234e3405SStephen Boyd .open = simple_open,
1653116b3a2eSRishi Panjwani .owner = THIS_MODULE,
1654116b3a2eSRishi Panjwani .llseek = default_llseek,
1655116b3a2eSRishi Panjwani };
1656116b3a2eSRishi Panjwani
ath6kl_listen_int_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1657ef8f0ebaSRishi Panjwani static ssize_t ath6kl_listen_int_write(struct file *file,
1658ef8f0ebaSRishi Panjwani const char __user *user_buf,
1659ef8f0ebaSRishi Panjwani size_t count, loff_t *ppos)
1660ef8f0ebaSRishi Panjwani {
1661ef8f0ebaSRishi Panjwani struct ath6kl *ar = file->private_data;
16628232736dSSujith Manoharan struct ath6kl_vif *vif;
16638232736dSSujith Manoharan u16 listen_interval;
1664ef8f0ebaSRishi Panjwani char buf[32];
1665ef8f0ebaSRishi Panjwani ssize_t len;
1666ef8f0ebaSRishi Panjwani
16678232736dSSujith Manoharan vif = ath6kl_vif_first(ar);
16688232736dSSujith Manoharan if (!vif)
16698232736dSSujith Manoharan return -EIO;
16708232736dSSujith Manoharan
1671ef8f0ebaSRishi Panjwani len = min(count, sizeof(buf) - 1);
1672ef8f0ebaSRishi Panjwani if (copy_from_user(buf, user_buf, len))
1673ef8f0ebaSRishi Panjwani return -EFAULT;
1674ef8f0ebaSRishi Panjwani
1675ef8f0ebaSRishi Panjwani buf[len] = '\0';
16768232736dSSujith Manoharan if (kstrtou16(buf, 0, &listen_interval))
1677ef8f0ebaSRishi Panjwani return -EINVAL;
1678ef8f0ebaSRishi Panjwani
16798f46fccdSRaja Mani if ((listen_interval < 15) || (listen_interval > 3000))
1680ef8f0ebaSRishi Panjwani return -EINVAL;
1681ef8f0ebaSRishi Panjwani
16828f46fccdSRaja Mani vif->listen_intvl_t = listen_interval;
16838f46fccdSRaja Mani ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
16848f46fccdSRaja Mani vif->listen_intvl_t, 0);
1685ef8f0ebaSRishi Panjwani
1686ef8f0ebaSRishi Panjwani return count;
1687ef8f0ebaSRishi Panjwani }
1688ef8f0ebaSRishi Panjwani
ath6kl_listen_int_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1689ef8f0ebaSRishi Panjwani static ssize_t ath6kl_listen_int_read(struct file *file,
1690ef8f0ebaSRishi Panjwani char __user *user_buf,
1691ef8f0ebaSRishi Panjwani size_t count, loff_t *ppos)
1692ef8f0ebaSRishi Panjwani {
1693ef8f0ebaSRishi Panjwani struct ath6kl *ar = file->private_data;
16948f46fccdSRaja Mani struct ath6kl_vif *vif;
169550553c2cSDan Carpenter char buf[32];
1696ef8f0ebaSRishi Panjwani int len;
1697ef8f0ebaSRishi Panjwani
16988f46fccdSRaja Mani vif = ath6kl_vif_first(ar);
16998f46fccdSRaja Mani if (!vif)
17008f46fccdSRaja Mani return -EIO;
17018f46fccdSRaja Mani
17028f46fccdSRaja Mani len = scnprintf(buf, sizeof(buf), "%u\n", vif->listen_intvl_t);
1703ef8f0ebaSRishi Panjwani
1704ef8f0ebaSRishi Panjwani return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1705ef8f0ebaSRishi Panjwani }
1706ef8f0ebaSRishi Panjwani
1707ef8f0ebaSRishi Panjwani static const struct file_operations fops_listen_int = {
1708ef8f0ebaSRishi Panjwani .read = ath6kl_listen_int_read,
1709ef8f0ebaSRishi Panjwani .write = ath6kl_listen_int_write,
1710234e3405SStephen Boyd .open = simple_open,
1711ef8f0ebaSRishi Panjwani .owner = THIS_MODULE,
1712ef8f0ebaSRishi Panjwani .llseek = default_llseek,
1713ef8f0ebaSRishi Panjwani };
1714ef8f0ebaSRishi Panjwani
ath6kl_power_params_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1715a24fc7c3SRishi Panjwani static ssize_t ath6kl_power_params_write(struct file *file,
1716a24fc7c3SRishi Panjwani const char __user *user_buf,
1717a24fc7c3SRishi Panjwani size_t count, loff_t *ppos)
1718a24fc7c3SRishi Panjwani {
1719a24fc7c3SRishi Panjwani struct ath6kl *ar = file->private_data;
1720a24fc7c3SRishi Panjwani u8 buf[100];
1721a24fc7c3SRishi Panjwani unsigned int len = 0;
1722a24fc7c3SRishi Panjwani char *sptr, *token;
1723a24fc7c3SRishi Panjwani u16 idle_period, ps_poll_num, dtim,
1724a24fc7c3SRishi Panjwani tx_wakeup, num_tx;
1725a24fc7c3SRishi Panjwani
1726a24fc7c3SRishi Panjwani len = min(count, sizeof(buf) - 1);
1727a24fc7c3SRishi Panjwani if (copy_from_user(buf, user_buf, len))
1728a24fc7c3SRishi Panjwani return -EFAULT;
1729a24fc7c3SRishi Panjwani buf[len] = '\0';
1730a24fc7c3SRishi Panjwani sptr = buf;
1731a24fc7c3SRishi Panjwani
1732a24fc7c3SRishi Panjwani token = strsep(&sptr, " ");
1733a24fc7c3SRishi Panjwani if (!token)
1734a24fc7c3SRishi Panjwani return -EINVAL;
1735a24fc7c3SRishi Panjwani if (kstrtou16(token, 0, &idle_period))
1736a24fc7c3SRishi Panjwani return -EINVAL;
1737a24fc7c3SRishi Panjwani
1738a24fc7c3SRishi Panjwani token = strsep(&sptr, " ");
1739a24fc7c3SRishi Panjwani if (!token)
1740a24fc7c3SRishi Panjwani return -EINVAL;
1741a24fc7c3SRishi Panjwani if (kstrtou16(token, 0, &ps_poll_num))
1742a24fc7c3SRishi Panjwani return -EINVAL;
1743a24fc7c3SRishi Panjwani
1744a24fc7c3SRishi Panjwani token = strsep(&sptr, " ");
1745a24fc7c3SRishi Panjwani if (!token)
1746a24fc7c3SRishi Panjwani return -EINVAL;
1747a24fc7c3SRishi Panjwani if (kstrtou16(token, 0, &dtim))
1748a24fc7c3SRishi Panjwani return -EINVAL;
1749a24fc7c3SRishi Panjwani
1750a24fc7c3SRishi Panjwani token = strsep(&sptr, " ");
1751a24fc7c3SRishi Panjwani if (!token)
1752a24fc7c3SRishi Panjwani return -EINVAL;
1753a24fc7c3SRishi Panjwani if (kstrtou16(token, 0, &tx_wakeup))
1754a24fc7c3SRishi Panjwani return -EINVAL;
1755a24fc7c3SRishi Panjwani
1756a24fc7c3SRishi Panjwani token = strsep(&sptr, " ");
1757a24fc7c3SRishi Panjwani if (!token)
1758a24fc7c3SRishi Panjwani return -EINVAL;
1759a24fc7c3SRishi Panjwani if (kstrtou16(token, 0, &num_tx))
1760a24fc7c3SRishi Panjwani return -EINVAL;
1761a24fc7c3SRishi Panjwani
1762a24fc7c3SRishi Panjwani ath6kl_wmi_pmparams_cmd(ar->wmi, 0, idle_period, ps_poll_num,
1763a24fc7c3SRishi Panjwani dtim, tx_wakeup, num_tx, 0);
1764a24fc7c3SRishi Panjwani
1765a24fc7c3SRishi Panjwani return count;
1766a24fc7c3SRishi Panjwani }
1767a24fc7c3SRishi Panjwani
1768a24fc7c3SRishi Panjwani static const struct file_operations fops_power_params = {
1769a24fc7c3SRishi Panjwani .write = ath6kl_power_params_write,
1770234e3405SStephen Boyd .open = simple_open,
1771a24fc7c3SRishi Panjwani .owner = THIS_MODULE,
1772a24fc7c3SRishi Panjwani .llseek = default_llseek,
1773a24fc7c3SRishi Panjwani };
1774a24fc7c3SRishi Panjwani
ath6kl_debug_init(struct ath6kl * ar)1775068a4633SVasanthakumar Thiagarajan void ath6kl_debug_init(struct ath6kl *ar)
1776d999ba3eSVasanthakumar Thiagarajan {
17779b9a4f2aSKalle Valo skb_queue_head_init(&ar->debug.fwlog_queue);
1778c807b30dSKalle Valo init_completion(&ar->debug.fwlog_completion);
1779bdf5396bSKalle Valo
1780939f1cceSKalle Valo /*
1781939f1cceSKalle Valo * Actually we are lying here but don't know how to read the mask
1782939f1cceSKalle Valo * value from the firmware.
1783939f1cceSKalle Valo */
1784939f1cceSKalle Valo ar->debug.fwlog_mask = 0;
1785068a4633SVasanthakumar Thiagarajan }
1786939f1cceSKalle Valo
1787068a4633SVasanthakumar Thiagarajan /*
1788068a4633SVasanthakumar Thiagarajan * Initialisation needs to happen in two stages as fwlog events can come
1789068a4633SVasanthakumar Thiagarajan * before cfg80211 is initialised, and debugfs depends on cfg80211
1790068a4633SVasanthakumar Thiagarajan * initialisation.
1791068a4633SVasanthakumar Thiagarajan */
ath6kl_debug_init_fs(struct ath6kl * ar)1792068a4633SVasanthakumar Thiagarajan int ath6kl_debug_init_fs(struct ath6kl *ar)
1793068a4633SVasanthakumar Thiagarajan {
1794d999ba3eSVasanthakumar Thiagarajan ar->debugfs_phy = debugfs_create_dir("ath6kl",
1795be98e3a4SVasanthakumar Thiagarajan ar->wiphy->debugfsdir);
1796d999ba3eSVasanthakumar Thiagarajan
17972ef00c53SJoe Perches debugfs_create_file("tgt_stats", 0400, ar->debugfs_phy, ar,
179803f68a95SVasanthakumar Thiagarajan &fops_tgt_stats);
179903f68a95SVasanthakumar Thiagarajan
1800243c0280SMohammed Shafi Shajakhan if (ar->hif_type == ATH6KL_HIF_TYPE_SDIO)
18012ef00c53SJoe Perches debugfs_create_file("credit_dist_stats", 0400,
1802243c0280SMohammed Shafi Shajakhan ar->debugfs_phy, ar,
180378fc4856SVasanthakumar Thiagarajan &fops_credit_dist_stats);
180478fc4856SVasanthakumar Thiagarajan
18052ef00c53SJoe Perches debugfs_create_file("endpoint_stats", 0600,
1806e8091281SJouni Malinen ar->debugfs_phy, ar, &fops_endpoint_stats);
1807e8091281SJouni Malinen
18082ef00c53SJoe Perches debugfs_create_file("fwlog", 0400, ar->debugfs_phy, ar, &fops_fwlog);
1809bdf5396bSKalle Valo
18102ef00c53SJoe Perches debugfs_create_file("fwlog_block", 0400, ar->debugfs_phy, ar,
1811c807b30dSKalle Valo &fops_fwlog_block);
1812c807b30dSKalle Valo
18132ef00c53SJoe Perches debugfs_create_file("fwlog_mask", 0600, ar->debugfs_phy,
1814939f1cceSKalle Valo ar, &fops_fwlog_mask);
1815939f1cceSKalle Valo
18162ef00c53SJoe Perches debugfs_create_file("reg_addr", 0600, ar->debugfs_phy, ar,
181791d57de5SVasanthakumar Thiagarajan &fops_diag_reg_read);
181891d57de5SVasanthakumar Thiagarajan
18192ef00c53SJoe Perches debugfs_create_file("reg_dump", 0400, ar->debugfs_phy, ar,
182091d57de5SVasanthakumar Thiagarajan &fops_reg_dump);
182191d57de5SVasanthakumar Thiagarajan
18222ef00c53SJoe Perches debugfs_create_file("lrssi_roam_threshold", 0600,
1823e5090444SVivek Natarajan ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
1824252c068bSVasanthakumar Thiagarajan
18252ef00c53SJoe Perches debugfs_create_file("reg_write", 0600,
1826252c068bSVasanthakumar Thiagarajan ar->debugfs_phy, ar, &fops_diag_reg_write);
1827252c068bSVasanthakumar Thiagarajan
18282ef00c53SJoe Perches debugfs_create_file("war_stats", 0400, ar->debugfs_phy, ar,
18299a730834SKalle Valo &fops_war_stats);
18309a730834SKalle Valo
18312ef00c53SJoe Perches debugfs_create_file("roam_table", 0400, ar->debugfs_phy, ar,
18324b28a80dSJouni Malinen &fops_roam_table);
18334b28a80dSJouni Malinen
18342ef00c53SJoe Perches debugfs_create_file("force_roam", 0200, ar->debugfs_phy, ar,
18351261875fSJouni Malinen &fops_force_roam);
18361261875fSJouni Malinen
18372ef00c53SJoe Perches debugfs_create_file("roam_mode", 0200, ar->debugfs_phy, ar,
18381261875fSJouni Malinen &fops_roam_mode);
18391261875fSJouni Malinen
18402ef00c53SJoe Perches debugfs_create_file("keepalive", 0600, ar->debugfs_phy, ar,
1841ff0b0075SJouni Malinen &fops_keepalive);
1842ff0b0075SJouni Malinen
18432ef00c53SJoe Perches debugfs_create_file("disconnect_timeout", 0600,
1844ff0b0075SJouni Malinen ar->debugfs_phy, ar, &fops_disconnect_timeout);
1845ff0b0075SJouni Malinen
18462ef00c53SJoe Perches debugfs_create_file("create_qos", 0200, ar->debugfs_phy, ar,
18478fffd9e5SRishi Panjwani &fops_create_qos);
18488fffd9e5SRishi Panjwani
18492ef00c53SJoe Perches debugfs_create_file("delete_qos", 0200, ar->debugfs_phy, ar,
18508fffd9e5SRishi Panjwani &fops_delete_qos);
18518fffd9e5SRishi Panjwani
18522ef00c53SJoe Perches debugfs_create_file("bgscan_interval", 0200,
1853116b3a2eSRishi Panjwani ar->debugfs_phy, ar, &fops_bgscan_int);
1854116b3a2eSRishi Panjwani
18552ef00c53SJoe Perches debugfs_create_file("listen_interval", 0600,
18568232736dSSujith Manoharan ar->debugfs_phy, ar, &fops_listen_int);
18578232736dSSujith Manoharan
18582ef00c53SJoe Perches debugfs_create_file("power_params", 0200, ar->debugfs_phy, ar,
1859a24fc7c3SRishi Panjwani &fops_power_params);
1860a24fc7c3SRishi Panjwani
1861d999ba3eSVasanthakumar Thiagarajan return 0;
1862d999ba3eSVasanthakumar Thiagarajan }
1863bdf5396bSKalle Valo
ath6kl_debug_cleanup(struct ath6kl * ar)1864bdf5396bSKalle Valo void ath6kl_debug_cleanup(struct ath6kl *ar)
1865bdf5396bSKalle Valo {
18669b9a4f2aSKalle Valo skb_queue_purge(&ar->debug.fwlog_queue);
186792ada046SThomas Pedersen complete(&ar->debug.fwlog_completion);
18684b28a80dSJouni Malinen kfree(ar->debug.roam_tbl);
1869bdf5396bSKalle Valo }
1870bdf5396bSKalle Valo
1871bdcd8170SKalle Valo #endif
1872