blob: 3d0713dfe3b9197b772eb15fa74eb262741a371b [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
Vasanthakumar Thiagarajan1b2df402012-02-06 20:15:53 +05303 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
Kalle Valobdcd8172011-07-18 00:22:30 +03004 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "core.h"
Kalle Valobdf53962011-09-02 10:32:04 +030019
Kalle Valo9b9a4f22012-02-06 08:23:27 +020020#include <linux/skbuff.h>
Kalle Valo939f1cc2011-09-02 10:32:04 +030021#include <linux/fs.h>
Kalle Valo62c83ac2011-10-03 13:44:40 +030022#include <linux/vmalloc.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -040023#include <linux/export.h>
Kalle Valobdf53962011-09-02 10:32:04 +030024
Kalle Valobdcd8172011-07-18 00:22:30 +030025#include "debug.h"
Kalle Valobdf53962011-09-02 10:32:04 +030026#include "target.h"
27
28struct ath6kl_fwlog_slot {
29 __le32 timestamp;
30 __le32 length;
31
32 /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
33 u8 payload[0];
34};
35
Kalle Valo9b9a4f22012-02-06 08:23:27 +020036#define ATH6KL_FWLOG_MAX_ENTRIES 20
37
Kalle Valo939f1cc2011-09-02 10:32:04 +030038#define ATH6KL_FWLOG_VALID_MASK 0x1ffff
Kalle Valobdcd8172011-07-18 00:22:30 +030039
40int ath6kl_printk(const char *level, const char *fmt, ...)
41{
42 struct va_format vaf;
43 va_list args;
44 int rtn;
45
46 va_start(args, fmt);
47
48 vaf.fmt = fmt;
49 vaf.va = &args;
50
51 rtn = printk("%sath6kl: %pV", level, &vaf);
52
53 va_end(args);
54
55 return rtn;
56}
Kalle Valod6a434d2012-01-17 20:09:36 +020057EXPORT_SYMBOL(ath6kl_printk);
Kalle Valobdcd8172011-07-18 00:22:30 +030058
59#ifdef CONFIG_ATH6KL_DEBUG
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +030060
Kalle Valo3b1b7d02012-01-17 20:09:27 +020061void ath6kl_dbg(enum ATH6K_DEBUG_MASK mask, const char *fmt, ...)
62{
63 struct va_format vaf;
64 va_list args;
65
66 if (!(debug_mask & mask))
67 return;
68
69 va_start(args, fmt);
70
71 vaf.fmt = fmt;
72 vaf.va = &args;
73
74 ath6kl_printk(KERN_DEBUG, "%pV", &vaf);
75
76 va_end(args);
77}
Kalle Valod6a434d2012-01-17 20:09:36 +020078EXPORT_SYMBOL(ath6kl_dbg);
Kalle Valo3b1b7d02012-01-17 20:09:27 +020079
80void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
81 const char *msg, const char *prefix,
82 const void *buf, size_t len)
83{
84 if (debug_mask & mask) {
85 if (msg)
86 ath6kl_dbg(mask, "%s\n", msg);
87
88 print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len);
89 }
90}
Kalle Valod6a434d2012-01-17 20:09:36 +020091EXPORT_SYMBOL(ath6kl_dbg_dump);
Kalle Valo3b1b7d02012-01-17 20:09:27 +020092
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +030093#define REG_OUTPUT_LEN_PER_LINE 25
94#define REGTYPE_STR_LEN 100
95
96struct ath6kl_diag_reg_info {
97 u32 reg_start;
98 u32 reg_end;
99 const char *reg_info;
100};
101
102static const struct ath6kl_diag_reg_info diag_reg[] = {
103 { 0x20000, 0x200fc, "General DMA and Rx registers" },
104 { 0x28000, 0x28900, "MAC PCU register & keycache" },
105 { 0x20800, 0x20a40, "QCU" },
106 { 0x21000, 0x212f0, "DCU" },
107 { 0x4000, 0x42e4, "RTC" },
108 { 0x540000, 0x540000 + (256 * 1024), "RAM" },
109 { 0x29800, 0x2B210, "Base Band" },
110 { 0x1C000, 0x1C748, "Analog" },
111};
112
Kalle Valobdcd8172011-07-18 00:22:30 +0300113void ath6kl_dump_registers(struct ath6kl_device *dev,
114 struct ath6kl_irq_proc_registers *irq_proc_reg,
115 struct ath6kl_irq_enable_reg *irq_enable_reg)
116{
117
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200118 ath6kl_dbg(ATH6KL_DBG_IRQ, ("<------- Register Table -------->\n"));
Kalle Valobdcd8172011-07-18 00:22:30 +0300119
120 if (irq_proc_reg != NULL) {
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200121 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300122 "Host Int status: 0x%x\n",
123 irq_proc_reg->host_int_status);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200124 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300125 "CPU Int status: 0x%x\n",
126 irq_proc_reg->cpu_int_status);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200127 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300128 "Error Int status: 0x%x\n",
129 irq_proc_reg->error_int_status);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200130 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300131 "Counter Int status: 0x%x\n",
132 irq_proc_reg->counter_int_status);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200133 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300134 "Mbox Frame: 0x%x\n",
135 irq_proc_reg->mbox_frame);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200136 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300137 "Rx Lookahead Valid: 0x%x\n",
138 irq_proc_reg->rx_lkahd_valid);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200139 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300140 "Rx Lookahead 0: 0x%x\n",
141 irq_proc_reg->rx_lkahd[0]);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200142 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300143 "Rx Lookahead 1: 0x%x\n",
144 irq_proc_reg->rx_lkahd[1]);
145
146 if (dev->ar->mbox_info.gmbox_addr != 0) {
147 /*
148 * If the target supports GMBOX hardware, dump some
149 * additional state.
150 */
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200151 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300152 "GMBOX Host Int status 2: 0x%x\n",
153 irq_proc_reg->host_int_status2);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200154 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300155 "GMBOX RX Avail: 0x%x\n",
156 irq_proc_reg->gmbox_rx_avail);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200157 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300158 "GMBOX lookahead alias 0: 0x%x\n",
159 irq_proc_reg->rx_gmbox_lkahd_alias[0]);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200160 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300161 "GMBOX lookahead alias 1: 0x%x\n",
162 irq_proc_reg->rx_gmbox_lkahd_alias[1]);
163 }
164
165 }
166
167 if (irq_enable_reg != NULL) {
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200168 ath6kl_dbg(ATH6KL_DBG_IRQ,
Kalle Valobdcd8172011-07-18 00:22:30 +0300169 "Int status Enable: 0x%x\n",
170 irq_enable_reg->int_status_en);
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200171 ath6kl_dbg(ATH6KL_DBG_IRQ, "Counter Int status Enable: 0x%x\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300172 irq_enable_reg->cntr_int_status_en);
173 }
Kalle Valo5afa5aa2012-01-17 20:09:19 +0200174 ath6kl_dbg(ATH6KL_DBG_IRQ, "<------------------------------->\n");
Kalle Valobdcd8172011-07-18 00:22:30 +0300175}
176
177static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
178{
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300179 ath6kl_dbg(ATH6KL_DBG_CREDIT,
Kalle Valobdcd8172011-07-18 00:22:30 +0300180 "--- endpoint: %d svc_id: 0x%X ---\n",
181 ep_dist->endpoint, ep_dist->svc_id);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300182 ath6kl_dbg(ATH6KL_DBG_CREDIT, " dist_flags : 0x%X\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300183 ep_dist->dist_flags);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300184 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_norm : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300185 ep_dist->cred_norm);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300186 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_min : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300187 ep_dist->cred_min);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300188 ath6kl_dbg(ATH6KL_DBG_CREDIT, " credits : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300189 ep_dist->credits);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300190 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_assngd : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300191 ep_dist->cred_assngd);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300192 ath6kl_dbg(ATH6KL_DBG_CREDIT, " seek_cred : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300193 ep_dist->seek_cred);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300194 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_sz : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300195 ep_dist->cred_sz);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300196 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_per_msg : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300197 ep_dist->cred_per_msg);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300198 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_to_dist : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300199 ep_dist->cred_to_dist);
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300200 ath6kl_dbg(ATH6KL_DBG_CREDIT, " txq_depth : %d\n",
Kalle Valoe8c39792011-10-24 12:17:04 +0300201 get_queue_depth(&ep_dist->htc_ep->txq));
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300202 ath6kl_dbg(ATH6KL_DBG_CREDIT,
Kalle Valobdcd8172011-07-18 00:22:30 +0300203 "----------------------------------\n");
204}
205
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300206/* FIXME: move to htc.c */
Kalle Valobdcd8172011-07-18 00:22:30 +0300207void dump_cred_dist_stats(struct htc_target *target)
208{
209 struct htc_endpoint_credit_dist *ep_list;
210
Kalle Valobdcd8172011-07-18 00:22:30 +0300211 list_for_each_entry(ep_list, &target->cred_dist_list, list)
212 dump_cred_dist(ep_list);
213
Kalle Valo02f0d6f2011-10-24 12:17:59 +0300214 ath6kl_dbg(ATH6KL_DBG_CREDIT,
215 "credit distribution total %d free %d\n",
Kalle Valo3c370392011-10-24 12:17:12 +0300216 target->credit_info->total_avail_credits,
217 target->credit_info->cur_free_credits);
Kalle Valobdcd8172011-07-18 00:22:30 +0300218}
219
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530220static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
221{
222 file->private_data = inode->i_private;
223 return 0;
224}
225
Kalle Valo9a730832011-09-27 23:33:28 +0300226void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
227{
228 switch (war) {
229 case ATH6KL_WAR_INVALID_RATE:
230 ar->debug.war_stats.invalid_rate++;
231 break;
232 }
233}
234
235static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
236 size_t count, loff_t *ppos)
237{
238 struct ath6kl *ar = file->private_data;
239 char *buf;
240 unsigned int len = 0, buf_len = 1500;
241 ssize_t ret_cnt;
242
243 buf = kzalloc(buf_len, GFP_KERNEL);
244 if (!buf)
245 return -ENOMEM;
246
247 len += scnprintf(buf + len, buf_len - len, "\n");
248 len += scnprintf(buf + len, buf_len - len, "%25s\n",
249 "Workaround stats");
250 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
251 "=================");
252 len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
253 "Invalid rates", ar->debug.war_stats.invalid_rate);
254
255 if (WARN_ON(len > buf_len))
256 len = buf_len;
257
258 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
259
260 kfree(buf);
261 return ret_cnt;
262}
263
264static const struct file_operations fops_war_stats = {
265 .read = read_file_war_stats,
266 .open = ath6kl_debugfs_open,
267 .owner = THIS_MODULE,
268 .llseek = default_llseek,
269};
270
Kalle Valobdf53962011-09-02 10:32:04 +0300271void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
272{
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200273 struct ath6kl_fwlog_slot *slot;
274 struct sk_buff *skb;
Kalle Valobdf53962011-09-02 10:32:04 +0300275 size_t slot_len;
276
277 if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
278 return;
279
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200280 slot_len = sizeof(*slot) + len;
Kalle Valobdf53962011-09-02 10:32:04 +0300281
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200282 skb = alloc_skb(slot_len, GFP_KERNEL);
283 if (!skb)
284 return;
285
286 slot = (struct ath6kl_fwlog_slot *) skb_put(skb, slot_len);
Kalle Valobdf53962011-09-02 10:32:04 +0300287 slot->timestamp = cpu_to_le32(jiffies);
288 slot->length = cpu_to_le32(len);
289 memcpy(slot->payload, buf, len);
290
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200291 spin_lock(&ar->debug.fwlog_queue.lock);
Kalle Valobdf53962011-09-02 10:32:04 +0300292
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200293 __skb_queue_tail(&ar->debug.fwlog_queue, skb);
Kalle Valoc807b302012-02-06 08:23:40 +0200294 complete(&ar->debug.fwlog_completion);
Kalle Valobdf53962011-09-02 10:32:04 +0300295
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200296 /* drop oldest entries */
297 while (skb_queue_len(&ar->debug.fwlog_queue) >
298 ATH6KL_FWLOG_MAX_ENTRIES) {
299 skb = __skb_dequeue(&ar->debug.fwlog_queue);
300 kfree_skb(skb);
301 }
Kalle Valobdf53962011-09-02 10:32:04 +0300302
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200303 spin_unlock(&ar->debug.fwlog_queue.lock);
Kalle Valobdf53962011-09-02 10:32:04 +0300304
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200305 return;
Kalle Valobdf53962011-09-02 10:32:04 +0300306}
307
Kalle Valoc807b302012-02-06 08:23:40 +0200308static int ath6kl_fwlog_open(struct inode *inode, struct file *file)
309{
310 struct ath6kl *ar = inode->i_private;
311
312 if (ar->debug.fwlog_open)
313 return -EBUSY;
314
315 ar->debug.fwlog_open = true;
316
317 file->private_data = inode->i_private;
318 return 0;
319}
320
321static int ath6kl_fwlog_release(struct inode *inode, struct file *file)
322{
323 struct ath6kl *ar = inode->i_private;
324
325 ar->debug.fwlog_open = false;
326
327 return 0;
328}
329
Kalle Valobdf53962011-09-02 10:32:04 +0300330static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
331 size_t count, loff_t *ppos)
332{
333 struct ath6kl *ar = file->private_data;
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200334 struct sk_buff *skb;
Kalle Valobdf53962011-09-02 10:32:04 +0300335 ssize_t ret_cnt;
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200336 size_t len = 0;
Kalle Valobdf53962011-09-02 10:32:04 +0300337 char *buf;
Kalle Valobdf53962011-09-02 10:32:04 +0300338
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200339 buf = vmalloc(count);
Kalle Valobdf53962011-09-02 10:32:04 +0300340 if (!buf)
341 return -ENOMEM;
342
Kalle Valobc07ddb2011-09-02 10:32:05 +0300343 /* read undelivered logs from firmware */
344 ath6kl_read_fwlogs(ar);
345
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200346 spin_lock(&ar->debug.fwlog_queue.lock);
Kalle Valobdf53962011-09-02 10:32:04 +0300347
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200348 while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
349 if (skb->len > count - len) {
350 /* not enough space, put skb back and leave */
351 __skb_queue_head(&ar->debug.fwlog_queue, skb);
352 break;
353 }
Kalle Valobdf53962011-09-02 10:32:04 +0300354
Kalle Valobdf53962011-09-02 10:32:04 +0300355
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200356 memcpy(buf + len, skb->data, skb->len);
357 len += skb->len;
Kalle Valobdf53962011-09-02 10:32:04 +0300358
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200359 kfree_skb(skb);
Kalle Valobdf53962011-09-02 10:32:04 +0300360 }
361
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200362 spin_unlock(&ar->debug.fwlog_queue.lock);
Kalle Valobdf53962011-09-02 10:32:04 +0300363
Kalle Valo9b9a4f22012-02-06 08:23:27 +0200364 /* FIXME: what to do if len == 0? */
Kalle Valobdf53962011-09-02 10:32:04 +0300365
366 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
367
368 vfree(buf);
369
370 return ret_cnt;
371}
372
373static const struct file_operations fops_fwlog = {
Kalle Valoc807b302012-02-06 08:23:40 +0200374 .open = ath6kl_fwlog_open,
375 .release = ath6kl_fwlog_release,
Kalle Valobdf53962011-09-02 10:32:04 +0300376 .read = ath6kl_fwlog_read,
377 .owner = THIS_MODULE,
378 .llseek = default_llseek,
379};
380
Kalle Valoc807b302012-02-06 08:23:40 +0200381static ssize_t ath6kl_fwlog_block_read(struct file *file,
382 char __user *user_buf,
383 size_t count,
384 loff_t *ppos)
385{
386 struct ath6kl *ar = file->private_data;
387 struct sk_buff *skb;
388 ssize_t ret_cnt;
389 size_t len = 0, not_copied;
390 char *buf;
391 int ret;
392
393 buf = vmalloc(count);
394 if (!buf)
395 return -ENOMEM;
396
397 spin_lock(&ar->debug.fwlog_queue.lock);
398
399 if (skb_queue_len(&ar->debug.fwlog_queue) == 0) {
400 /* we must init under queue lock */
401 init_completion(&ar->debug.fwlog_completion);
402
403 spin_unlock(&ar->debug.fwlog_queue.lock);
404
405 ret = wait_for_completion_interruptible(
406 &ar->debug.fwlog_completion);
407 if (ret == -ERESTARTSYS)
408 return ret;
409
410 spin_lock(&ar->debug.fwlog_queue.lock);
411 }
412
413 while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
414 if (skb->len > count - len) {
415 /* not enough space, put skb back and leave */
416 __skb_queue_head(&ar->debug.fwlog_queue, skb);
417 break;
418 }
419
420
421 memcpy(buf + len, skb->data, skb->len);
422 len += skb->len;
423
424 kfree_skb(skb);
425 }
426
427 spin_unlock(&ar->debug.fwlog_queue.lock);
428
429 /* FIXME: what to do if len == 0? */
430
431 not_copied = copy_to_user(user_buf, buf, len);
432 if (not_copied != 0) {
433 ret_cnt = -EFAULT;
434 goto out;
435 }
436
437 *ppos = *ppos + len;
438
439 ret_cnt = len;
440
441out:
442 vfree(buf);
443
444 return ret_cnt;
445}
446
447static const struct file_operations fops_fwlog_block = {
448 .open = ath6kl_fwlog_open,
449 .release = ath6kl_fwlog_release,
450 .read = ath6kl_fwlog_block_read,
451 .owner = THIS_MODULE,
452 .llseek = default_llseek,
453};
454
Kalle Valo939f1cc2011-09-02 10:32:04 +0300455static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
456 size_t count, loff_t *ppos)
457{
458 struct ath6kl *ar = file->private_data;
459 char buf[16];
460 int len;
461
462 len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
463
464 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
465}
466
467static ssize_t ath6kl_fwlog_mask_write(struct file *file,
468 const char __user *user_buf,
469 size_t count, loff_t *ppos)
470{
471 struct ath6kl *ar = file->private_data;
472 int ret;
473
474 ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
475 if (ret)
476 return ret;
477
478 ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
479 ATH6KL_FWLOG_VALID_MASK,
480 ar->debug.fwlog_mask);
481 if (ret)
482 return ret;
483
484 return count;
485}
486
487static const struct file_operations fops_fwlog_mask = {
488 .open = ath6kl_debugfs_open,
489 .read = ath6kl_fwlog_mask_read,
490 .write = ath6kl_fwlog_mask_write,
491 .owner = THIS_MODULE,
492 .llseek = default_llseek,
493};
494
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530495static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
496 size_t count, loff_t *ppos)
497{
498 struct ath6kl *ar = file->private_data;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530499 struct ath6kl_vif *vif;
500 struct target_stats *tgt_stats;
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530501 char *buf;
502 unsigned int len = 0, buf_len = 1500;
503 int i;
504 long left;
505 ssize_t ret_cnt;
506
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530507 vif = ath6kl_vif_first(ar);
508 if (!vif)
509 return -EIO;
510
511 tgt_stats = &vif->target_stats;
512
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530513 buf = kzalloc(buf_len, GFP_KERNEL);
514 if (!buf)
515 return -ENOMEM;
516
517 if (down_interruptible(&ar->sem)) {
518 kfree(buf);
519 return -EBUSY;
520 }
521
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530522 set_bit(STATS_UPDATE_PEND, &vif->flags);
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530523
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530524 if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) {
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530525 up(&ar->sem);
526 kfree(buf);
527 return -EIO;
528 }
529
530 left = wait_event_interruptible_timeout(ar->event_wq,
531 !test_bit(STATS_UPDATE_PEND,
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530532 &vif->flags), WMI_TIMEOUT);
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530533
534 up(&ar->sem);
535
536 if (left <= 0) {
537 kfree(buf);
538 return -ETIMEDOUT;
539 }
540
541 len += scnprintf(buf + len, buf_len - len, "\n");
542 len += scnprintf(buf + len, buf_len - len, "%25s\n",
543 "Target Tx stats");
544 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
545 "=================");
546 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
547 "Ucast packets", tgt_stats->tx_ucast_pkt);
548 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
549 "Bcast packets", tgt_stats->tx_bcast_pkt);
550 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
551 "Ucast byte", tgt_stats->tx_ucast_byte);
552 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
553 "Bcast byte", tgt_stats->tx_bcast_byte);
554 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
555 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
556 for (i = 0; i < 4; i++)
557 len += scnprintf(buf + len, buf_len - len,
558 "%18s %d %10llu\n", "PER on ac",
559 i, tgt_stats->tx_pkt_per_ac[i]);
560 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
561 "Error", tgt_stats->tx_err);
562 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
563 "Fail count", tgt_stats->tx_fail_cnt);
564 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
565 "Retry count", tgt_stats->tx_retry_cnt);
566 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
567 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
568 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
569 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
570 len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
571 "TKIP counter measure used",
572 tgt_stats->tkip_cnter_measures_invoked);
573
574 len += scnprintf(buf + len, buf_len - len, "%25s\n",
575 "Target Rx stats");
576 len += scnprintf(buf + len, buf_len - len, "%25s\n",
577 "=================");
578
579 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
580 "Ucast packets", tgt_stats->rx_ucast_pkt);
581 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
582 "Ucast Rate", tgt_stats->rx_ucast_rate);
583 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
584 "Bcast packets", tgt_stats->rx_bcast_pkt);
585 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
586 "Ucast byte", tgt_stats->rx_ucast_byte);
587 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
588 "Bcast byte", tgt_stats->rx_bcast_byte);
589 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
590 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
591 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
592 "Error", tgt_stats->rx_err);
593 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
594 "CRC Err", tgt_stats->rx_crc_err);
595 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
596 "Key chache miss", tgt_stats->rx_key_cache_miss);
597 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
598 "Decrypt Err", tgt_stats->rx_decrypt_err);
599 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
600 "Duplicate frame", tgt_stats->rx_dupl_frame);
601 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
602 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
603 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
604 "TKIP format err", tgt_stats->tkip_fmt_err);
605 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
606 "CCMP format Err", tgt_stats->ccmp_fmt_err);
607 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
608 "CCMP Replay Err", tgt_stats->ccmp_replays);
609
610 len += scnprintf(buf + len, buf_len - len, "%25s\n",
611 "Misc Target stats");
612 len += scnprintf(buf + len, buf_len - len, "%25s\n",
613 "=================");
614 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
615 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
616 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
617 "Num Connects", tgt_stats->cs_connect_cnt);
618 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
619 "Num disconnects", tgt_stats->cs_discon_cnt);
620 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
621 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
622
623 if (len > buf_len)
624 len = buf_len;
625
626 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
627
628 kfree(buf);
629 return ret_cnt;
630}
631
632static const struct file_operations fops_tgt_stats = {
633 .read = read_file_tgt_stats,
634 .open = ath6kl_debugfs_open,
635 .owner = THIS_MODULE,
636 .llseek = default_llseek,
637};
638
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530639#define print_credit_info(fmt_str, ep_list_field) \
640 (len += scnprintf(buf + len, buf_len - len, fmt_str, \
641 ep_list->ep_list_field))
642#define CREDIT_INFO_DISPLAY_STRING_LEN 200
643#define CREDIT_INFO_LEN 128
644
645static ssize_t read_file_credit_dist_stats(struct file *file,
646 char __user *user_buf,
647 size_t count, loff_t *ppos)
648{
649 struct ath6kl *ar = file->private_data;
650 struct htc_target *target = ar->htc_target;
651 struct htc_endpoint_credit_dist *ep_list;
652 char *buf;
653 unsigned int buf_len, len = 0;
654 ssize_t ret_cnt;
655
656 buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
657 get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
658 buf = kzalloc(buf_len, GFP_KERNEL);
659 if (!buf)
660 return -ENOMEM;
661
662 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
663 "Total Avail Credits: ",
Kalle Valo3c370392011-10-24 12:17:12 +0300664 target->credit_info->total_avail_credits);
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530665 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
666 "Free credits :",
Kalle Valo3c370392011-10-24 12:17:12 +0300667 target->credit_info->cur_free_credits);
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530668
669 len += scnprintf(buf + len, buf_len - len,
670 " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
671 " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
672 " qdepth\n");
673
674 list_for_each_entry(ep_list, &target->cred_dist_list, list) {
675 print_credit_info(" %2d", endpoint);
676 print_credit_info("%10x", dist_flags);
677 print_credit_info("%8d", cred_norm);
678 print_credit_info("%9d", cred_min);
679 print_credit_info("%9d", credits);
680 print_credit_info("%10d", cred_assngd);
681 print_credit_info("%13d", seek_cred);
682 print_credit_info("%12d", cred_sz);
683 print_credit_info("%9d", cred_per_msg);
684 print_credit_info("%14d", cred_to_dist);
685 len += scnprintf(buf + len, buf_len - len, "%12d\n",
Kalle Valoe8c39792011-10-24 12:17:04 +0300686 get_queue_depth(&ep_list->htc_ep->txq));
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530687 }
688
689 if (len > buf_len)
690 len = buf_len;
691
692 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
693 kfree(buf);
694 return ret_cnt;
695}
696
697static const struct file_operations fops_credit_dist_stats = {
698 .read = read_file_credit_dist_stats,
699 .open = ath6kl_debugfs_open,
700 .owner = THIS_MODULE,
701 .llseek = default_llseek,
702};
703
Jouni Malinene8091282011-10-11 17:31:53 +0300704static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
705 unsigned int buf_len, unsigned int len,
706 int offset, const char *name)
707{
708 int i;
709 struct htc_endpoint_stats *ep_st;
710 u32 *counter;
711
712 len += scnprintf(buf + len, buf_len - len, "%s:", name);
713 for (i = 0; i < ENDPOINT_MAX; i++) {
714 ep_st = &target->endpoint[i].ep_st;
715 counter = ((u32 *) ep_st) + (offset / 4);
716 len += scnprintf(buf + len, buf_len - len, " %u", *counter);
717 }
718 len += scnprintf(buf + len, buf_len - len, "\n");
719
720 return len;
721}
722
723static ssize_t ath6kl_endpoint_stats_read(struct file *file,
724 char __user *user_buf,
725 size_t count, loff_t *ppos)
726{
727 struct ath6kl *ar = file->private_data;
728 struct htc_target *target = ar->htc_target;
729 char *buf;
730 unsigned int buf_len, len = 0;
731 ssize_t ret_cnt;
732
Jouni Malinen17169322011-10-11 22:08:21 +0300733 buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
734 (25 + ENDPOINT_MAX * 11);
735 buf = kmalloc(buf_len, GFP_KERNEL);
Jouni Malinene8091282011-10-11 17:31:53 +0300736 if (!buf)
737 return -ENOMEM;
738
739#define EPSTAT(name) \
740 len = print_endpoint_stat(target, buf, buf_len, len, \
741 offsetof(struct htc_endpoint_stats, name), \
742 #name)
743 EPSTAT(cred_low_indicate);
744 EPSTAT(tx_issued);
745 EPSTAT(tx_pkt_bundled);
746 EPSTAT(tx_bundles);
747 EPSTAT(tx_dropped);
748 EPSTAT(tx_cred_rpt);
749 EPSTAT(cred_rpt_from_rx);
Jouni Malinen17169322011-10-11 22:08:21 +0300750 EPSTAT(cred_rpt_from_other);
Jouni Malinene8091282011-10-11 17:31:53 +0300751 EPSTAT(cred_rpt_ep0);
752 EPSTAT(cred_from_rx);
753 EPSTAT(cred_from_other);
754 EPSTAT(cred_from_ep0);
755 EPSTAT(cred_cosumd);
756 EPSTAT(cred_retnd);
757 EPSTAT(rx_pkts);
758 EPSTAT(rx_lkahds);
759 EPSTAT(rx_bundl);
760 EPSTAT(rx_bundle_lkahd);
761 EPSTAT(rx_bundle_from_hdr);
762 EPSTAT(rx_alloc_thresh_hit);
763 EPSTAT(rxalloc_thresh_byte);
764#undef EPSTAT
765
766 if (len > buf_len)
767 len = buf_len;
768
769 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
770 kfree(buf);
771 return ret_cnt;
772}
773
774static ssize_t ath6kl_endpoint_stats_write(struct file *file,
775 const char __user *user_buf,
776 size_t count, loff_t *ppos)
777{
778 struct ath6kl *ar = file->private_data;
779 struct htc_target *target = ar->htc_target;
780 int ret, i;
781 u32 val;
782 struct htc_endpoint_stats *ep_st;
783
784 ret = kstrtou32_from_user(user_buf, count, 0, &val);
785 if (ret)
786 return ret;
787 if (val == 0) {
788 for (i = 0; i < ENDPOINT_MAX; i++) {
789 ep_st = &target->endpoint[i].ep_st;
790 memset(ep_st, 0, sizeof(*ep_st));
791 }
792 }
793
794 return count;
795}
796
797static const struct file_operations fops_endpoint_stats = {
798 .open = ath6kl_debugfs_open,
799 .read = ath6kl_endpoint_stats_read,
800 .write = ath6kl_endpoint_stats_write,
801 .owner = THIS_MODULE,
802 .llseek = default_llseek,
803};
804
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +0300805static unsigned long ath6kl_get_num_reg(void)
806{
807 int i;
808 unsigned long n_reg = 0;
809
810 for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
811 n_reg = n_reg +
812 (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
813
814 return n_reg;
815}
816
817static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
818{
819 int i;
820
821 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
822 if (reg_addr >= diag_reg[i].reg_start &&
823 reg_addr <= diag_reg[i].reg_end)
824 return true;
825 }
826
827 return false;
828}
829
830static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
831 size_t count, loff_t *ppos)
832{
833 struct ath6kl *ar = file->private_data;
834 u8 buf[50];
835 unsigned int len = 0;
836
837 if (ar->debug.dbgfs_diag_reg)
838 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
839 ar->debug.dbgfs_diag_reg);
840 else
841 len += scnprintf(buf + len, sizeof(buf) - len,
842 "All diag registers\n");
843
844 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
845}
846
847static ssize_t ath6kl_regread_write(struct file *file,
848 const char __user *user_buf,
849 size_t count, loff_t *ppos)
850{
851 struct ath6kl *ar = file->private_data;
852 u8 buf[50];
853 unsigned int len;
854 unsigned long reg_addr;
855
856 len = min(count, sizeof(buf) - 1);
857 if (copy_from_user(buf, user_buf, len))
858 return -EFAULT;
859
860 buf[len] = '\0';
861
862 if (strict_strtoul(buf, 0, &reg_addr))
863 return -EINVAL;
864
865 if ((reg_addr % 4) != 0)
866 return -EINVAL;
867
868 if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
869 return -EINVAL;
870
871 ar->debug.dbgfs_diag_reg = reg_addr;
872
873 return count;
874}
875
876static const struct file_operations fops_diag_reg_read = {
877 .read = ath6kl_regread_read,
878 .write = ath6kl_regread_write,
879 .open = ath6kl_debugfs_open,
880 .owner = THIS_MODULE,
881 .llseek = default_llseek,
882};
883
884static int ath6kl_regdump_open(struct inode *inode, struct file *file)
885{
886 struct ath6kl *ar = inode->i_private;
887 u8 *buf;
888 unsigned long int reg_len;
889 unsigned int len = 0, n_reg;
890 u32 addr;
891 __le32 reg_val;
892 int i, status;
893
894 /* Dump all the registers if no register is specified */
895 if (!ar->debug.dbgfs_diag_reg)
896 n_reg = ath6kl_get_num_reg();
897 else
898 n_reg = 1;
899
900 reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
901 if (n_reg > 1)
902 reg_len += REGTYPE_STR_LEN;
903
904 buf = vmalloc(reg_len);
905 if (!buf)
906 return -ENOMEM;
907
908 if (n_reg == 1) {
909 addr = ar->debug.dbgfs_diag_reg;
910
911 status = ath6kl_diag_read32(ar,
912 TARG_VTOP(ar->target_type, addr),
913 (u32 *)&reg_val);
914 if (status)
915 goto fail_reg_read;
916
917 len += scnprintf(buf + len, reg_len - len,
918 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
919 goto done;
920 }
921
922 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
923 len += scnprintf(buf + len, reg_len - len,
924 "%s\n", diag_reg[i].reg_info);
925 for (addr = diag_reg[i].reg_start;
926 addr <= diag_reg[i].reg_end; addr += 4) {
927 status = ath6kl_diag_read32(ar,
928 TARG_VTOP(ar->target_type, addr),
929 (u32 *)&reg_val);
930 if (status)
931 goto fail_reg_read;
932
933 len += scnprintf(buf + len, reg_len - len,
934 "0x%06x 0x%08x\n",
935 addr, le32_to_cpu(reg_val));
936 }
937 }
938
939done:
940 file->private_data = buf;
941 return 0;
942
943fail_reg_read:
944 ath6kl_warn("Unable to read memory:%u\n", addr);
945 vfree(buf);
946 return -EIO;
947}
948
949static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
950 size_t count, loff_t *ppos)
951{
952 u8 *buf = file->private_data;
953 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
954}
955
956static int ath6kl_regdump_release(struct inode *inode, struct file *file)
957{
958 vfree(file->private_data);
959 return 0;
960}
961
962static const struct file_operations fops_reg_dump = {
963 .open = ath6kl_regdump_open,
964 .read = ath6kl_regdump_read,
965 .release = ath6kl_regdump_release,
966 .owner = THIS_MODULE,
967 .llseek = default_llseek,
968};
969
Vivek Natarajane5090442011-08-31 15:02:19 +0530970static ssize_t ath6kl_lrssi_roam_write(struct file *file,
971 const char __user *user_buf,
972 size_t count, loff_t *ppos)
973{
974 struct ath6kl *ar = file->private_data;
975 unsigned long lrssi_roam_threshold;
976 char buf[32];
977 ssize_t len;
978
979 len = min(count, sizeof(buf) - 1);
980 if (copy_from_user(buf, user_buf, len))
981 return -EFAULT;
982
983 buf[len] = '\0';
984 if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
985 return -EINVAL;
986
987 ar->lrssi_roam_threshold = lrssi_roam_threshold;
988
989 ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
990
991 return count;
992}
993
994static ssize_t ath6kl_lrssi_roam_read(struct file *file,
995 char __user *user_buf,
996 size_t count, loff_t *ppos)
997{
998 struct ath6kl *ar = file->private_data;
999 char buf[32];
1000 unsigned int len;
1001
1002 len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
1003
1004 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1005}
1006
1007static const struct file_operations fops_lrssi_roam_threshold = {
1008 .read = ath6kl_lrssi_roam_read,
1009 .write = ath6kl_lrssi_roam_write,
1010 .open = ath6kl_debugfs_open,
1011 .owner = THIS_MODULE,
1012 .llseek = default_llseek,
1013};
1014
Vasanthakumar Thiagarajan252c0682011-09-05 11:19:46 +03001015static ssize_t ath6kl_regwrite_read(struct file *file,
1016 char __user *user_buf,
1017 size_t count, loff_t *ppos)
1018{
1019 struct ath6kl *ar = file->private_data;
1020 u8 buf[32];
1021 unsigned int len = 0;
1022
1023 len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
1024 ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
1025
1026 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1027}
1028
1029static ssize_t ath6kl_regwrite_write(struct file *file,
1030 const char __user *user_buf,
1031 size_t count, loff_t *ppos)
1032{
1033 struct ath6kl *ar = file->private_data;
1034 char buf[32];
1035 char *sptr, *token;
1036 unsigned int len = 0;
1037 u32 reg_addr, reg_val;
1038
1039 len = min(count, sizeof(buf) - 1);
1040 if (copy_from_user(buf, user_buf, len))
1041 return -EFAULT;
1042
1043 buf[len] = '\0';
1044 sptr = buf;
1045
1046 token = strsep(&sptr, "=");
1047 if (!token)
1048 return -EINVAL;
1049
1050 if (kstrtou32(token, 0, &reg_addr))
1051 return -EINVAL;
1052
1053 if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
1054 return -EINVAL;
1055
1056 if (kstrtou32(sptr, 0, &reg_val))
1057 return -EINVAL;
1058
1059 ar->debug.diag_reg_addr_wr = reg_addr;
1060 ar->debug.diag_reg_val_wr = reg_val;
1061
1062 if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
1063 cpu_to_le32(ar->debug.diag_reg_val_wr)))
1064 return -EIO;
1065
1066 return count;
1067}
1068
1069static const struct file_operations fops_diag_reg_write = {
1070 .read = ath6kl_regwrite_read,
1071 .write = ath6kl_regwrite_write,
1072 .open = ath6kl_debugfs_open,
1073 .owner = THIS_MODULE,
1074 .llseek = default_llseek,
1075};
1076
Jouni Malinen4b28a802011-10-11 17:31:54 +03001077int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
1078 size_t len)
1079{
1080 const struct wmi_target_roam_tbl *tbl;
1081 u16 num_entries;
1082
1083 if (len < sizeof(*tbl))
1084 return -EINVAL;
1085
1086 tbl = (const struct wmi_target_roam_tbl *) buf;
1087 num_entries = le16_to_cpu(tbl->num_entries);
1088 if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
1089 len)
1090 return -EINVAL;
1091
1092 if (ar->debug.roam_tbl == NULL ||
1093 ar->debug.roam_tbl_len < (unsigned int) len) {
1094 kfree(ar->debug.roam_tbl);
1095 ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
1096 if (ar->debug.roam_tbl == NULL)
1097 return -ENOMEM;
1098 }
1099
1100 memcpy(ar->debug.roam_tbl, buf, len);
1101 ar->debug.roam_tbl_len = len;
1102
1103 if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
1104 clear_bit(ROAM_TBL_PEND, &ar->flag);
1105 wake_up(&ar->event_wq);
1106 }
1107
1108 return 0;
1109}
1110
1111static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
1112 size_t count, loff_t *ppos)
1113{
1114 struct ath6kl *ar = file->private_data;
1115 int ret;
1116 long left;
1117 struct wmi_target_roam_tbl *tbl;
1118 u16 num_entries, i;
1119 char *buf;
1120 unsigned int len, buf_len;
1121 ssize_t ret_cnt;
1122
1123 if (down_interruptible(&ar->sem))
1124 return -EBUSY;
1125
1126 set_bit(ROAM_TBL_PEND, &ar->flag);
1127
1128 ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
1129 if (ret) {
1130 up(&ar->sem);
1131 return ret;
1132 }
1133
1134 left = wait_event_interruptible_timeout(
1135 ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
1136 up(&ar->sem);
1137
1138 if (left <= 0)
1139 return -ETIMEDOUT;
1140
1141 if (ar->debug.roam_tbl == NULL)
1142 return -ENOMEM;
1143
1144 tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
1145 num_entries = le16_to_cpu(tbl->num_entries);
1146
1147 buf_len = 100 + num_entries * 100;
1148 buf = kzalloc(buf_len, GFP_KERNEL);
1149 if (buf == NULL)
1150 return -ENOMEM;
1151 len = 0;
1152 len += scnprintf(buf + len, buf_len - len,
1153 "roam_mode=%u\n\n"
1154 "# roam_util bssid rssi rssidt last_rssi util bias\n",
1155 le16_to_cpu(tbl->roam_mode));
1156
1157 for (i = 0; i < num_entries; i++) {
1158 struct wmi_bss_roam_info *info = &tbl->info[i];
1159 len += scnprintf(buf + len, buf_len - len,
1160 "%d %pM %d %d %d %d %d\n",
1161 a_sle32_to_cpu(info->roam_util), info->bssid,
1162 info->rssi, info->rssidt, info->last_rssi,
1163 info->util, info->bias);
1164 }
1165
1166 if (len > buf_len)
1167 len = buf_len;
1168
1169 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1170
1171 kfree(buf);
1172 return ret_cnt;
1173}
1174
1175static const struct file_operations fops_roam_table = {
1176 .read = ath6kl_roam_table_read,
1177 .open = ath6kl_debugfs_open,
1178 .owner = THIS_MODULE,
1179 .llseek = default_llseek,
1180};
1181
Jouni Malinen12618752011-10-11 17:31:55 +03001182static ssize_t ath6kl_force_roam_write(struct file *file,
1183 const char __user *user_buf,
1184 size_t count, loff_t *ppos)
1185{
1186 struct ath6kl *ar = file->private_data;
1187 int ret;
1188 char buf[20];
1189 size_t len;
1190 u8 bssid[ETH_ALEN];
1191 int i;
1192 int addr[ETH_ALEN];
1193
1194 len = min(count, sizeof(buf) - 1);
1195 if (copy_from_user(buf, user_buf, len))
1196 return -EFAULT;
1197 buf[len] = '\0';
1198
1199 if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
1200 &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
1201 != ETH_ALEN)
1202 return -EINVAL;
1203 for (i = 0; i < ETH_ALEN; i++)
1204 bssid[i] = addr[i];
1205
1206 ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
1207 if (ret)
1208 return ret;
1209
1210 return count;
1211}
1212
1213static const struct file_operations fops_force_roam = {
1214 .write = ath6kl_force_roam_write,
1215 .open = ath6kl_debugfs_open,
1216 .owner = THIS_MODULE,
1217 .llseek = default_llseek,
1218};
1219
1220static ssize_t ath6kl_roam_mode_write(struct file *file,
1221 const char __user *user_buf,
1222 size_t count, loff_t *ppos)
1223{
1224 struct ath6kl *ar = file->private_data;
1225 int ret;
1226 char buf[20];
1227 size_t len;
1228 enum wmi_roam_mode mode;
1229
1230 len = min(count, sizeof(buf) - 1);
1231 if (copy_from_user(buf, user_buf, len))
1232 return -EFAULT;
1233 buf[len] = '\0';
1234 if (len > 0 && buf[len - 1] == '\n')
1235 buf[len - 1] = '\0';
1236
1237 if (strcasecmp(buf, "default") == 0)
1238 mode = WMI_DEFAULT_ROAM_MODE;
1239 else if (strcasecmp(buf, "bssbias") == 0)
1240 mode = WMI_HOST_BIAS_ROAM_MODE;
1241 else if (strcasecmp(buf, "lock") == 0)
1242 mode = WMI_LOCK_BSS_MODE;
1243 else
1244 return -EINVAL;
1245
1246 ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
1247 if (ret)
1248 return ret;
1249
1250 return count;
1251}
1252
1253static const struct file_operations fops_roam_mode = {
1254 .write = ath6kl_roam_mode_write,
1255 .open = ath6kl_debugfs_open,
1256 .owner = THIS_MODULE,
1257 .llseek = default_llseek,
1258};
1259
Jouni Malinenff0b0072011-10-11 17:31:56 +03001260void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1261{
1262 ar->debug.keepalive = keepalive;
1263}
1264
1265static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1266 size_t count, loff_t *ppos)
1267{
1268 struct ath6kl *ar = file->private_data;
1269 char buf[16];
1270 int len;
1271
1272 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1273
1274 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1275}
1276
1277static ssize_t ath6kl_keepalive_write(struct file *file,
1278 const char __user *user_buf,
1279 size_t count, loff_t *ppos)
1280{
1281 struct ath6kl *ar = file->private_data;
1282 int ret;
1283 u8 val;
1284
1285 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1286 if (ret)
1287 return ret;
1288
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05301289 ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val);
Jouni Malinenff0b0072011-10-11 17:31:56 +03001290 if (ret)
1291 return ret;
1292
1293 return count;
1294}
1295
1296static const struct file_operations fops_keepalive = {
1297 .open = ath6kl_debugfs_open,
1298 .read = ath6kl_keepalive_read,
1299 .write = ath6kl_keepalive_write,
1300 .owner = THIS_MODULE,
1301 .llseek = default_llseek,
1302};
1303
1304void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1305{
1306 ar->debug.disc_timeout = timeout;
1307}
1308
1309static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1310 char __user *user_buf,
1311 size_t count, loff_t *ppos)
1312{
1313 struct ath6kl *ar = file->private_data;
1314 char buf[16];
1315 int len;
1316
1317 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1318
1319 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1320}
1321
1322static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1323 const char __user *user_buf,
1324 size_t count, loff_t *ppos)
1325{
1326 struct ath6kl *ar = file->private_data;
1327 int ret;
1328 u8 val;
1329
1330 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1331 if (ret)
1332 return ret;
1333
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05301334 ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val);
Jouni Malinenff0b0072011-10-11 17:31:56 +03001335 if (ret)
1336 return ret;
1337
1338 return count;
1339}
1340
1341static const struct file_operations fops_disconnect_timeout = {
1342 .open = ath6kl_debugfs_open,
1343 .read = ath6kl_disconnect_timeout_read,
1344 .write = ath6kl_disconnect_timeout_write,
1345 .owner = THIS_MODULE,
1346 .llseek = default_llseek,
1347};
1348
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001349static ssize_t ath6kl_create_qos_write(struct file *file,
1350 const char __user *user_buf,
1351 size_t count, loff_t *ppos)
1352{
1353
1354 struct ath6kl *ar = file->private_data;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301355 struct ath6kl_vif *vif;
Vasanthakumar Thiagarajan8cb6d992011-11-04 18:34:55 +05301356 char buf[200];
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001357 ssize_t len;
1358 char *sptr, *token;
1359 struct wmi_create_pstream_cmd pstream;
1360 u32 val32;
1361 u16 val16;
1362
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301363 vif = ath6kl_vif_first(ar);
1364 if (!vif)
1365 return -EIO;
1366
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001367 len = min(count, sizeof(buf) - 1);
1368 if (copy_from_user(buf, user_buf, len))
1369 return -EFAULT;
1370 buf[len] = '\0';
1371 sptr = buf;
1372
1373 token = strsep(&sptr, " ");
1374 if (!token)
1375 return -EINVAL;
1376 if (kstrtou8(token, 0, &pstream.user_pri))
1377 return -EINVAL;
1378
1379 token = strsep(&sptr, " ");
1380 if (!token)
1381 return -EINVAL;
1382 if (kstrtou8(token, 0, &pstream.traffic_direc))
1383 return -EINVAL;
1384
1385 token = strsep(&sptr, " ");
1386 if (!token)
1387 return -EINVAL;
1388 if (kstrtou8(token, 0, &pstream.traffic_class))
1389 return -EINVAL;
1390
1391 token = strsep(&sptr, " ");
1392 if (!token)
1393 return -EINVAL;
1394 if (kstrtou8(token, 0, &pstream.traffic_type))
1395 return -EINVAL;
1396
1397 token = strsep(&sptr, " ");
1398 if (!token)
1399 return -EINVAL;
1400 if (kstrtou8(token, 0, &pstream.voice_psc_cap))
1401 return -EINVAL;
1402
1403 token = strsep(&sptr, " ");
1404 if (!token)
1405 return -EINVAL;
1406 if (kstrtou32(token, 0, &val32))
1407 return -EINVAL;
1408 pstream.min_service_int = cpu_to_le32(val32);
1409
1410 token = strsep(&sptr, " ");
1411 if (!token)
1412 return -EINVAL;
1413 if (kstrtou32(token, 0, &val32))
1414 return -EINVAL;
1415 pstream.max_service_int = cpu_to_le32(val32);
1416
1417 token = strsep(&sptr, " ");
1418 if (!token)
1419 return -EINVAL;
1420 if (kstrtou32(token, 0, &val32))
1421 return -EINVAL;
1422 pstream.inactivity_int = cpu_to_le32(val32);
1423
1424 token = strsep(&sptr, " ");
1425 if (!token)
1426 return -EINVAL;
1427 if (kstrtou32(token, 0, &val32))
1428 return -EINVAL;
1429 pstream.suspension_int = cpu_to_le32(val32);
1430
1431 token = strsep(&sptr, " ");
1432 if (!token)
1433 return -EINVAL;
1434 if (kstrtou32(token, 0, &val32))
1435 return -EINVAL;
1436 pstream.service_start_time = cpu_to_le32(val32);
1437
1438 token = strsep(&sptr, " ");
1439 if (!token)
1440 return -EINVAL;
1441 if (kstrtou8(token, 0, &pstream.tsid))
1442 return -EINVAL;
1443
1444 token = strsep(&sptr, " ");
1445 if (!token)
1446 return -EINVAL;
1447 if (kstrtou16(token, 0, &val16))
1448 return -EINVAL;
1449 pstream.nominal_msdu = cpu_to_le16(val16);
1450
1451 token = strsep(&sptr, " ");
1452 if (!token)
1453 return -EINVAL;
1454 if (kstrtou16(token, 0, &val16))
1455 return -EINVAL;
1456 pstream.max_msdu = cpu_to_le16(val16);
1457
1458 token = strsep(&sptr, " ");
1459 if (!token)
1460 return -EINVAL;
1461 if (kstrtou32(token, 0, &val32))
1462 return -EINVAL;
1463 pstream.min_data_rate = cpu_to_le32(val32);
1464
1465 token = strsep(&sptr, " ");
1466 if (!token)
1467 return -EINVAL;
1468 if (kstrtou32(token, 0, &val32))
1469 return -EINVAL;
1470 pstream.mean_data_rate = cpu_to_le32(val32);
1471
1472 token = strsep(&sptr, " ");
1473 if (!token)
1474 return -EINVAL;
1475 if (kstrtou32(token, 0, &val32))
1476 return -EINVAL;
1477 pstream.peak_data_rate = cpu_to_le32(val32);
1478
1479 token = strsep(&sptr, " ");
1480 if (!token)
1481 return -EINVAL;
1482 if (kstrtou32(token, 0, &val32))
1483 return -EINVAL;
1484 pstream.max_burst_size = cpu_to_le32(val32);
1485
1486 token = strsep(&sptr, " ");
1487 if (!token)
1488 return -EINVAL;
1489 if (kstrtou32(token, 0, &val32))
1490 return -EINVAL;
1491 pstream.delay_bound = cpu_to_le32(val32);
1492
1493 token = strsep(&sptr, " ");
1494 if (!token)
1495 return -EINVAL;
1496 if (kstrtou32(token, 0, &val32))
1497 return -EINVAL;
1498 pstream.min_phy_rate = cpu_to_le32(val32);
1499
1500 token = strsep(&sptr, " ");
1501 if (!token)
1502 return -EINVAL;
1503 if (kstrtou32(token, 0, &val32))
1504 return -EINVAL;
1505 pstream.sba = cpu_to_le32(val32);
1506
1507 token = strsep(&sptr, " ");
1508 if (!token)
1509 return -EINVAL;
1510 if (kstrtou32(token, 0, &val32))
1511 return -EINVAL;
1512 pstream.medium_time = cpu_to_le32(val32);
1513
Chilam Ng5fbea5d2012-02-01 01:03:37 -08001514 pstream.nominal_phy = le32_to_cpu(pstream.min_phy_rate) / 1000000;
1515
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301516 ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001517
1518 return count;
1519}
1520
1521static const struct file_operations fops_create_qos = {
1522 .write = ath6kl_create_qos_write,
1523 .open = ath6kl_debugfs_open,
1524 .owner = THIS_MODULE,
1525 .llseek = default_llseek,
1526};
1527
1528static ssize_t ath6kl_delete_qos_write(struct file *file,
1529 const char __user *user_buf,
1530 size_t count, loff_t *ppos)
1531{
1532
1533 struct ath6kl *ar = file->private_data;
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301534 struct ath6kl_vif *vif;
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001535 char buf[100];
1536 ssize_t len;
1537 char *sptr, *token;
1538 u8 traffic_class;
1539 u8 tsid;
1540
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301541 vif = ath6kl_vif_first(ar);
1542 if (!vif)
1543 return -EIO;
1544
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001545 len = min(count, sizeof(buf) - 1);
1546 if (copy_from_user(buf, user_buf, len))
1547 return -EFAULT;
1548 buf[len] = '\0';
1549 sptr = buf;
1550
1551 token = strsep(&sptr, " ");
1552 if (!token)
1553 return -EINVAL;
1554 if (kstrtou8(token, 0, &traffic_class))
1555 return -EINVAL;
1556
1557 token = strsep(&sptr, " ");
1558 if (!token)
1559 return -EINVAL;
1560 if (kstrtou8(token, 0, &tsid))
1561 return -EINVAL;
1562
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301563 ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
1564 traffic_class, tsid);
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001565
1566 return count;
1567}
1568
1569static const struct file_operations fops_delete_qos = {
1570 .write = ath6kl_delete_qos_write,
1571 .open = ath6kl_debugfs_open,
1572 .owner = THIS_MODULE,
1573 .llseek = default_llseek,
1574};
1575
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001576static ssize_t ath6kl_bgscan_int_write(struct file *file,
1577 const char __user *user_buf,
1578 size_t count, loff_t *ppos)
1579{
1580 struct ath6kl *ar = file->private_data;
1581 u16 bgscan_int;
1582 char buf[32];
1583 ssize_t len;
1584
1585 len = min(count, sizeof(buf) - 1);
1586 if (copy_from_user(buf, user_buf, len))
1587 return -EFAULT;
1588
1589 buf[len] = '\0';
1590 if (kstrtou16(buf, 0, &bgscan_int))
1591 return -EINVAL;
1592
1593 if (bgscan_int == 0)
1594 bgscan_int = 0xffff;
1595
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301596 ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001597 0, 0, 0);
1598
1599 return count;
1600}
1601
1602static const struct file_operations fops_bgscan_int = {
1603 .write = ath6kl_bgscan_int_write,
1604 .open = ath6kl_debugfs_open,
1605 .owner = THIS_MODULE,
1606 .llseek = default_llseek,
1607};
1608
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001609static ssize_t ath6kl_listen_int_write(struct file *file,
Sujith Manoharan82327362012-01-10 09:54:10 +05301610 const char __user *user_buf,
1611 size_t count, loff_t *ppos)
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001612{
1613 struct ath6kl *ar = file->private_data;
Sujith Manoharan82327362012-01-10 09:54:10 +05301614 struct ath6kl_vif *vif;
1615 u16 listen_interval;
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001616 char buf[32];
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001617 ssize_t len;
1618
Sujith Manoharan82327362012-01-10 09:54:10 +05301619 vif = ath6kl_vif_first(ar);
1620 if (!vif)
1621 return -EIO;
1622
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001623 len = min(count, sizeof(buf) - 1);
1624 if (copy_from_user(buf, user_buf, len))
1625 return -EFAULT;
1626
1627 buf[len] = '\0';
Sujith Manoharan82327362012-01-10 09:54:10 +05301628 if (kstrtou16(buf, 0, &listen_interval))
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001629 return -EINVAL;
1630
Sujith Manoharan82327362012-01-10 09:54:10 +05301631 if ((listen_interval < 1) || (listen_interval > 50))
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001632 return -EINVAL;
1633
Sujith Manoharan82327362012-01-10 09:54:10 +05301634 ar->listen_intvl_b = listen_interval;
1635 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx, 0,
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001636 ar->listen_intvl_b);
1637
1638 return count;
1639}
1640
1641static ssize_t ath6kl_listen_int_read(struct file *file,
Sujith Manoharan82327362012-01-10 09:54:10 +05301642 char __user *user_buf,
1643 size_t count, loff_t *ppos)
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001644{
1645 struct ath6kl *ar = file->private_data;
Dan Carpenter50553c22011-11-23 09:34:50 +03001646 char buf[32];
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001647 int len;
1648
Sujith Manoharan82327362012-01-10 09:54:10 +05301649 len = scnprintf(buf, sizeof(buf), "%u\n", ar->listen_intvl_b);
Rishi Panjwanief8f0eb2011-10-25 17:26:29 -07001650
1651 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1652}
1653
1654static const struct file_operations fops_listen_int = {
1655 .read = ath6kl_listen_int_read,
1656 .write = ath6kl_listen_int_write,
1657 .open = ath6kl_debugfs_open,
1658 .owner = THIS_MODULE,
1659 .llseek = default_llseek,
1660};
1661
Rishi Panjwania24fc7c2011-10-25 19:52:41 -07001662static ssize_t ath6kl_power_params_write(struct file *file,
1663 const char __user *user_buf,
1664 size_t count, loff_t *ppos)
1665{
1666 struct ath6kl *ar = file->private_data;
1667 u8 buf[100];
1668 unsigned int len = 0;
1669 char *sptr, *token;
1670 u16 idle_period, ps_poll_num, dtim,
1671 tx_wakeup, num_tx;
1672
1673 len = min(count, sizeof(buf) - 1);
1674 if (copy_from_user(buf, user_buf, len))
1675 return -EFAULT;
1676 buf[len] = '\0';
1677 sptr = buf;
1678
1679 token = strsep(&sptr, " ");
1680 if (!token)
1681 return -EINVAL;
1682 if (kstrtou16(token, 0, &idle_period))
1683 return -EINVAL;
1684
1685 token = strsep(&sptr, " ");
1686 if (!token)
1687 return -EINVAL;
1688 if (kstrtou16(token, 0, &ps_poll_num))
1689 return -EINVAL;
1690
1691 token = strsep(&sptr, " ");
1692 if (!token)
1693 return -EINVAL;
1694 if (kstrtou16(token, 0, &dtim))
1695 return -EINVAL;
1696
1697 token = strsep(&sptr, " ");
1698 if (!token)
1699 return -EINVAL;
1700 if (kstrtou16(token, 0, &tx_wakeup))
1701 return -EINVAL;
1702
1703 token = strsep(&sptr, " ");
1704 if (!token)
1705 return -EINVAL;
1706 if (kstrtou16(token, 0, &num_tx))
1707 return -EINVAL;
1708
1709 ath6kl_wmi_pmparams_cmd(ar->wmi, 0, idle_period, ps_poll_num,
1710 dtim, tx_wakeup, num_tx, 0);
1711
1712 return count;
1713}
1714
1715static const struct file_operations fops_power_params = {
1716 .write = ath6kl_power_params_write,
1717 .open = ath6kl_debugfs_open,
1718 .owner = THIS_MODULE,
1719 .llseek = default_llseek,
1720};
1721
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301722int ath6kl_debug_init(struct ath6kl *ar)
1723{
Kalle Valo9b9a4f22012-02-06 08:23:27 +02001724 skb_queue_head_init(&ar->debug.fwlog_queue);
Kalle Valoc807b302012-02-06 08:23:40 +02001725 init_completion(&ar->debug.fwlog_completion);
Kalle Valobdf53962011-09-02 10:32:04 +03001726
Kalle Valo939f1cc2011-09-02 10:32:04 +03001727 /*
1728 * Actually we are lying here but don't know how to read the mask
1729 * value from the firmware.
1730 */
1731 ar->debug.fwlog_mask = 0;
1732
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301733 ar->debugfs_phy = debugfs_create_dir("ath6kl",
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301734 ar->wiphy->debugfsdir);
Kalle Valo9b9a4f22012-02-06 08:23:27 +02001735 if (!ar->debugfs_phy)
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301736 return -ENOMEM;
1737
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +05301738 debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
1739 &fops_tgt_stats);
1740
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +05301741 debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
1742 &fops_credit_dist_stats);
1743
Jouni Malinene8091282011-10-11 17:31:53 +03001744 debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
1745 ar->debugfs_phy, ar, &fops_endpoint_stats);
1746
Kalle Valobdf53962011-09-02 10:32:04 +03001747 debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
1748 &fops_fwlog);
1749
Kalle Valoc807b302012-02-06 08:23:40 +02001750 debugfs_create_file("fwlog_block", S_IRUSR, ar->debugfs_phy, ar,
1751 &fops_fwlog_block);
1752
Kalle Valo939f1cc2011-09-02 10:32:04 +03001753 debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
1754 ar, &fops_fwlog_mask);
1755
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +03001756 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1757 &fops_diag_reg_read);
1758
1759 debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
1760 &fops_reg_dump);
1761
Vivek Natarajane5090442011-08-31 15:02:19 +05301762 debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
1763 ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
Vasanthakumar Thiagarajan252c0682011-09-05 11:19:46 +03001764
1765 debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
1766 ar->debugfs_phy, ar, &fops_diag_reg_write);
1767
Kalle Valo9a730832011-09-27 23:33:28 +03001768 debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
1769 &fops_war_stats);
1770
Jouni Malinen4b28a802011-10-11 17:31:54 +03001771 debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
1772 &fops_roam_table);
1773
Jouni Malinen12618752011-10-11 17:31:55 +03001774 debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
1775 &fops_force_roam);
1776
1777 debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
1778 &fops_roam_mode);
1779
Jouni Malinenff0b0072011-10-11 17:31:56 +03001780 debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1781 &fops_keepalive);
1782
1783 debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
1784 ar->debugfs_phy, ar, &fops_disconnect_timeout);
1785
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001786 debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
1787 &fops_create_qos);
1788
1789 debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
1790 &fops_delete_qos);
1791
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001792 debugfs_create_file("bgscan_interval", S_IWUSR,
1793 ar->debugfs_phy, ar, &fops_bgscan_int);
1794
Sujith Manoharan82327362012-01-10 09:54:10 +05301795 debugfs_create_file("listen_interval", S_IRUSR | S_IWUSR,
1796 ar->debugfs_phy, ar, &fops_listen_int);
1797
Rishi Panjwania24fc7c2011-10-25 19:52:41 -07001798 debugfs_create_file("power_params", S_IWUSR, ar->debugfs_phy, ar,
1799 &fops_power_params);
1800
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301801 return 0;
1802}
Kalle Valobdf53962011-09-02 10:32:04 +03001803
1804void ath6kl_debug_cleanup(struct ath6kl *ar)
1805{
Kalle Valo9b9a4f22012-02-06 08:23:27 +02001806 skb_queue_purge(&ar->debug.fwlog_queue);
Jouni Malinen4b28a802011-10-11 17:31:54 +03001807 kfree(ar->debug.roam_tbl);
Kalle Valobdf53962011-09-02 10:32:04 +03001808}
1809
Kalle Valobdcd8172011-07-18 00:22:30 +03001810#endif