blob: 54faa6b39e9ac9deec71fd07b8a6db2a02bbe27e [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
Kalle Valobdf53962011-09-02 10:32:04 +030018
19#include <linux/circ_buf.h>
Kalle Valo939f1cc2011-09-02 10:32:04 +030020#include <linux/fs.h>
Kalle Valo62c83ac2011-10-03 13:44:40 +030021#include <linux/vmalloc.h>
Kalle Valobdf53962011-09-02 10:32:04 +030022
Kalle Valobdcd8172011-07-18 00:22:30 +030023#include "debug.h"
Kalle Valobdf53962011-09-02 10:32:04 +030024#include "target.h"
25
26struct ath6kl_fwlog_slot {
27 __le32 timestamp;
28 __le32 length;
29
30 /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
31 u8 payload[0];
32};
33
34#define ATH6KL_FWLOG_SIZE 32768
35#define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \
36 ATH6KL_FWLOG_PAYLOAD_SIZE)
Kalle Valo939f1cc2011-09-02 10:32:04 +030037#define ATH6KL_FWLOG_VALID_MASK 0x1ffff
Kalle Valobdcd8172011-07-18 00:22:30 +030038
39int ath6kl_printk(const char *level, const char *fmt, ...)
40{
41 struct va_format vaf;
42 va_list args;
43 int rtn;
44
45 va_start(args, fmt);
46
47 vaf.fmt = fmt;
48 vaf.va = &args;
49
50 rtn = printk("%sath6kl: %pV", level, &vaf);
51
52 va_end(args);
53
54 return rtn;
55}
56
57#ifdef CONFIG_ATH6KL_DEBUG
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +030058
59#define REG_OUTPUT_LEN_PER_LINE 25
60#define REGTYPE_STR_LEN 100
61
62struct ath6kl_diag_reg_info {
63 u32 reg_start;
64 u32 reg_end;
65 const char *reg_info;
66};
67
68static const struct ath6kl_diag_reg_info diag_reg[] = {
69 { 0x20000, 0x200fc, "General DMA and Rx registers" },
70 { 0x28000, 0x28900, "MAC PCU register & keycache" },
71 { 0x20800, 0x20a40, "QCU" },
72 { 0x21000, 0x212f0, "DCU" },
73 { 0x4000, 0x42e4, "RTC" },
74 { 0x540000, 0x540000 + (256 * 1024), "RAM" },
75 { 0x29800, 0x2B210, "Base Band" },
76 { 0x1C000, 0x1C748, "Analog" },
77};
78
Kalle Valobdcd8172011-07-18 00:22:30 +030079void ath6kl_dump_registers(struct ath6kl_device *dev,
80 struct ath6kl_irq_proc_registers *irq_proc_reg,
81 struct ath6kl_irq_enable_reg *irq_enable_reg)
82{
83
84 ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n"));
85
86 if (irq_proc_reg != NULL) {
87 ath6kl_dbg(ATH6KL_DBG_ANY,
88 "Host Int status: 0x%x\n",
89 irq_proc_reg->host_int_status);
90 ath6kl_dbg(ATH6KL_DBG_ANY,
91 "CPU Int status: 0x%x\n",
92 irq_proc_reg->cpu_int_status);
93 ath6kl_dbg(ATH6KL_DBG_ANY,
94 "Error Int status: 0x%x\n",
95 irq_proc_reg->error_int_status);
96 ath6kl_dbg(ATH6KL_DBG_ANY,
97 "Counter Int status: 0x%x\n",
98 irq_proc_reg->counter_int_status);
99 ath6kl_dbg(ATH6KL_DBG_ANY,
100 "Mbox Frame: 0x%x\n",
101 irq_proc_reg->mbox_frame);
102 ath6kl_dbg(ATH6KL_DBG_ANY,
103 "Rx Lookahead Valid: 0x%x\n",
104 irq_proc_reg->rx_lkahd_valid);
105 ath6kl_dbg(ATH6KL_DBG_ANY,
106 "Rx Lookahead 0: 0x%x\n",
107 irq_proc_reg->rx_lkahd[0]);
108 ath6kl_dbg(ATH6KL_DBG_ANY,
109 "Rx Lookahead 1: 0x%x\n",
110 irq_proc_reg->rx_lkahd[1]);
111
112 if (dev->ar->mbox_info.gmbox_addr != 0) {
113 /*
114 * If the target supports GMBOX hardware, dump some
115 * additional state.
116 */
117 ath6kl_dbg(ATH6KL_DBG_ANY,
118 "GMBOX Host Int status 2: 0x%x\n",
119 irq_proc_reg->host_int_status2);
120 ath6kl_dbg(ATH6KL_DBG_ANY,
121 "GMBOX RX Avail: 0x%x\n",
122 irq_proc_reg->gmbox_rx_avail);
123 ath6kl_dbg(ATH6KL_DBG_ANY,
124 "GMBOX lookahead alias 0: 0x%x\n",
125 irq_proc_reg->rx_gmbox_lkahd_alias[0]);
126 ath6kl_dbg(ATH6KL_DBG_ANY,
127 "GMBOX lookahead alias 1: 0x%x\n",
128 irq_proc_reg->rx_gmbox_lkahd_alias[1]);
129 }
130
131 }
132
133 if (irq_enable_reg != NULL) {
134 ath6kl_dbg(ATH6KL_DBG_ANY,
135 "Int status Enable: 0x%x\n",
136 irq_enable_reg->int_status_en);
137 ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n",
138 irq_enable_reg->cntr_int_status_en);
139 }
140 ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n");
141}
142
143static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
144{
145 ath6kl_dbg(ATH6KL_DBG_ANY,
146 "--- endpoint: %d svc_id: 0x%X ---\n",
147 ep_dist->endpoint, ep_dist->svc_id);
148 ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags : 0x%X\n",
149 ep_dist->dist_flags);
150 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm : %d\n",
151 ep_dist->cred_norm);
152 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n",
153 ep_dist->cred_min);
154 ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n",
155 ep_dist->credits);
156 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd : %d\n",
157 ep_dist->cred_assngd);
158 ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred : %d\n",
159 ep_dist->seek_cred);
160 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n",
161 ep_dist->cred_sz);
162 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg : %d\n",
163 ep_dist->cred_per_msg);
164 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist : %d\n",
165 ep_dist->cred_to_dist);
166 ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth : %d\n",
167 get_queue_depth(&((struct htc_endpoint *)
168 ep_dist->htc_rsvd)->txq));
169 ath6kl_dbg(ATH6KL_DBG_ANY,
170 "----------------------------------\n");
171}
172
173void dump_cred_dist_stats(struct htc_target *target)
174{
175 struct htc_endpoint_credit_dist *ep_list;
176
177 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC))
178 return;
179
180 list_for_each_entry(ep_list, &target->cred_dist_list, list)
181 dump_cred_dist(ep_list);
182
Kalle Valoebf29c92011-10-13 15:21:15 +0300183 ath6kl_dbg(ATH6KL_DBG_HTC, "ctxt:%p dist:%p\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300184 target->cred_dist_cntxt, NULL);
Kalle Valoebf29c92011-10-13 15:21:15 +0300185 ath6kl_dbg(ATH6KL_DBG_HTC,
186 "credit distribution, total : %d, free : %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +0300187 target->cred_dist_cntxt->total_avail_credits,
188 target->cred_dist_cntxt->cur_free_credits);
189}
190
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530191static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
192{
193 file->private_data = inode->i_private;
194 return 0;
195}
196
Kalle Valo9a730832011-09-27 23:33:28 +0300197void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
198{
199 switch (war) {
200 case ATH6KL_WAR_INVALID_RATE:
201 ar->debug.war_stats.invalid_rate++;
202 break;
203 }
204}
205
206static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
207 size_t count, loff_t *ppos)
208{
209 struct ath6kl *ar = file->private_data;
210 char *buf;
211 unsigned int len = 0, buf_len = 1500;
212 ssize_t ret_cnt;
213
214 buf = kzalloc(buf_len, GFP_KERNEL);
215 if (!buf)
216 return -ENOMEM;
217
218 len += scnprintf(buf + len, buf_len - len, "\n");
219 len += scnprintf(buf + len, buf_len - len, "%25s\n",
220 "Workaround stats");
221 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
222 "=================");
223 len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
224 "Invalid rates", ar->debug.war_stats.invalid_rate);
225
226 if (WARN_ON(len > buf_len))
227 len = buf_len;
228
229 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
230
231 kfree(buf);
232 return ret_cnt;
233}
234
235static const struct file_operations fops_war_stats = {
236 .read = read_file_war_stats,
237 .open = ath6kl_debugfs_open,
238 .owner = THIS_MODULE,
239 .llseek = default_llseek,
240};
241
Kalle Valobdf53962011-09-02 10:32:04 +0300242static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf,
243 size_t buf_len)
244{
245 struct circ_buf *fwlog = &ar->debug.fwlog_buf;
246 size_t space;
247 int i;
248
249 /* entries must all be equal size */
250 if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE))
251 return;
252
253 space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE);
254 if (space < buf_len)
255 /* discard oldest slot */
256 fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) &
257 (ATH6KL_FWLOG_SIZE - 1);
258
259 for (i = 0; i < buf_len; i += space) {
260 space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail,
261 ATH6KL_FWLOG_SIZE);
262
263 if ((size_t) space > buf_len - i)
264 space = buf_len - i;
265
266 memcpy(&fwlog->buf[fwlog->head], buf, space);
267 fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1);
268 }
269
270}
271
272void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
273{
274 struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp;
275 size_t slot_len;
276
277 if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
278 return;
279
280 spin_lock_bh(&ar->debug.fwlog_lock);
281
282 slot->timestamp = cpu_to_le32(jiffies);
283 slot->length = cpu_to_le32(len);
284 memcpy(slot->payload, buf, len);
285
286 slot_len = sizeof(*slot) + len;
287
288 if (slot_len < ATH6KL_FWLOG_SLOT_SIZE)
289 memset(slot->payload + len, 0,
290 ATH6KL_FWLOG_SLOT_SIZE - slot_len);
291
292 ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE);
293
294 spin_unlock_bh(&ar->debug.fwlog_lock);
295}
296
297static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar)
298{
299 return CIRC_CNT(ar->debug.fwlog_buf.head,
300 ar->debug.fwlog_buf.tail,
301 ATH6KL_FWLOG_SLOT_SIZE) == 0;
302}
303
304static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
305 size_t count, loff_t *ppos)
306{
307 struct ath6kl *ar = file->private_data;
308 struct circ_buf *fwlog = &ar->debug.fwlog_buf;
309 size_t len = 0, buf_len = count;
310 ssize_t ret_cnt;
311 char *buf;
312 int ccnt;
313
314 buf = vmalloc(buf_len);
315 if (!buf)
316 return -ENOMEM;
317
Kalle Valobc07ddb2011-09-02 10:32:05 +0300318 /* read undelivered logs from firmware */
319 ath6kl_read_fwlogs(ar);
320
Kalle Valobdf53962011-09-02 10:32:04 +0300321 spin_lock_bh(&ar->debug.fwlog_lock);
322
323 while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
324 ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail,
325 ATH6KL_FWLOG_SIZE);
326
327 if ((size_t) ccnt > buf_len - len)
328 ccnt = buf_len - len;
329
330 memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt);
331 len += ccnt;
332
333 fwlog->tail = (fwlog->tail + ccnt) &
334 (ATH6KL_FWLOG_SIZE - 1);
335 }
336
337 spin_unlock_bh(&ar->debug.fwlog_lock);
338
339 if (WARN_ON(len > buf_len))
340 len = buf_len;
341
342 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
343
344 vfree(buf);
345
346 return ret_cnt;
347}
348
349static const struct file_operations fops_fwlog = {
350 .open = ath6kl_debugfs_open,
351 .read = ath6kl_fwlog_read,
352 .owner = THIS_MODULE,
353 .llseek = default_llseek,
354};
355
Kalle Valo939f1cc2011-09-02 10:32:04 +0300356static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
357 size_t count, loff_t *ppos)
358{
359 struct ath6kl *ar = file->private_data;
360 char buf[16];
361 int len;
362
363 len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
364
365 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
366}
367
368static ssize_t ath6kl_fwlog_mask_write(struct file *file,
369 const char __user *user_buf,
370 size_t count, loff_t *ppos)
371{
372 struct ath6kl *ar = file->private_data;
373 int ret;
374
375 ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
376 if (ret)
377 return ret;
378
379 ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
380 ATH6KL_FWLOG_VALID_MASK,
381 ar->debug.fwlog_mask);
382 if (ret)
383 return ret;
384
385 return count;
386}
387
388static const struct file_operations fops_fwlog_mask = {
389 .open = ath6kl_debugfs_open,
390 .read = ath6kl_fwlog_mask_read,
391 .write = ath6kl_fwlog_mask_write,
392 .owner = THIS_MODULE,
393 .llseek = default_llseek,
394};
395
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530396static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
397 size_t count, loff_t *ppos)
398{
399 struct ath6kl *ar = file->private_data;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530400 /* TODO: Findout vif */
401 struct ath6kl_vif *vif = ar->vif;
402 struct target_stats *tgt_stats = &vif->target_stats;
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530403 char *buf;
404 unsigned int len = 0, buf_len = 1500;
405 int i;
406 long left;
407 ssize_t ret_cnt;
408
409 buf = kzalloc(buf_len, GFP_KERNEL);
410 if (!buf)
411 return -ENOMEM;
412
413 if (down_interruptible(&ar->sem)) {
414 kfree(buf);
415 return -EBUSY;
416 }
417
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530418 set_bit(STATS_UPDATE_PEND, &vif->flags);
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530419
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530420 if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) {
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530421 up(&ar->sem);
422 kfree(buf);
423 return -EIO;
424 }
425
426 left = wait_event_interruptible_timeout(ar->event_wq,
427 !test_bit(STATS_UPDATE_PEND,
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530428 &vif->flags), WMI_TIMEOUT);
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530429
430 up(&ar->sem);
431
432 if (left <= 0) {
433 kfree(buf);
434 return -ETIMEDOUT;
435 }
436
437 len += scnprintf(buf + len, buf_len - len, "\n");
438 len += scnprintf(buf + len, buf_len - len, "%25s\n",
439 "Target Tx stats");
440 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
441 "=================");
442 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
443 "Ucast packets", tgt_stats->tx_ucast_pkt);
444 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
445 "Bcast packets", tgt_stats->tx_bcast_pkt);
446 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
447 "Ucast byte", tgt_stats->tx_ucast_byte);
448 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
449 "Bcast byte", tgt_stats->tx_bcast_byte);
450 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
451 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
452 for (i = 0; i < 4; i++)
453 len += scnprintf(buf + len, buf_len - len,
454 "%18s %d %10llu\n", "PER on ac",
455 i, tgt_stats->tx_pkt_per_ac[i]);
456 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
457 "Error", tgt_stats->tx_err);
458 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
459 "Fail count", tgt_stats->tx_fail_cnt);
460 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
461 "Retry count", tgt_stats->tx_retry_cnt);
462 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
463 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
464 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
465 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
466 len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
467 "TKIP counter measure used",
468 tgt_stats->tkip_cnter_measures_invoked);
469
470 len += scnprintf(buf + len, buf_len - len, "%25s\n",
471 "Target Rx stats");
472 len += scnprintf(buf + len, buf_len - len, "%25s\n",
473 "=================");
474
475 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
476 "Ucast packets", tgt_stats->rx_ucast_pkt);
477 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
478 "Ucast Rate", tgt_stats->rx_ucast_rate);
479 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
480 "Bcast packets", tgt_stats->rx_bcast_pkt);
481 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
482 "Ucast byte", tgt_stats->rx_ucast_byte);
483 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
484 "Bcast byte", tgt_stats->rx_bcast_byte);
485 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
486 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
487 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
488 "Error", tgt_stats->rx_err);
489 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
490 "CRC Err", tgt_stats->rx_crc_err);
491 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
492 "Key chache miss", tgt_stats->rx_key_cache_miss);
493 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
494 "Decrypt Err", tgt_stats->rx_decrypt_err);
495 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
496 "Duplicate frame", tgt_stats->rx_dupl_frame);
497 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
498 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
499 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
500 "TKIP format err", tgt_stats->tkip_fmt_err);
501 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
502 "CCMP format Err", tgt_stats->ccmp_fmt_err);
503 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
504 "CCMP Replay Err", tgt_stats->ccmp_replays);
505
506 len += scnprintf(buf + len, buf_len - len, "%25s\n",
507 "Misc Target stats");
508 len += scnprintf(buf + len, buf_len - len, "%25s\n",
509 "=================");
510 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
511 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
512 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
513 "Num Connects", tgt_stats->cs_connect_cnt);
514 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
515 "Num disconnects", tgt_stats->cs_discon_cnt);
516 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
517 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
518
519 if (len > buf_len)
520 len = buf_len;
521
522 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
523
524 kfree(buf);
525 return ret_cnt;
526}
527
528static const struct file_operations fops_tgt_stats = {
529 .read = read_file_tgt_stats,
530 .open = ath6kl_debugfs_open,
531 .owner = THIS_MODULE,
532 .llseek = default_llseek,
533};
534
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530535#define print_credit_info(fmt_str, ep_list_field) \
536 (len += scnprintf(buf + len, buf_len - len, fmt_str, \
537 ep_list->ep_list_field))
538#define CREDIT_INFO_DISPLAY_STRING_LEN 200
539#define CREDIT_INFO_LEN 128
540
541static ssize_t read_file_credit_dist_stats(struct file *file,
542 char __user *user_buf,
543 size_t count, loff_t *ppos)
544{
545 struct ath6kl *ar = file->private_data;
546 struct htc_target *target = ar->htc_target;
547 struct htc_endpoint_credit_dist *ep_list;
548 char *buf;
549 unsigned int buf_len, len = 0;
550 ssize_t ret_cnt;
551
552 buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
553 get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
554 buf = kzalloc(buf_len, GFP_KERNEL);
555 if (!buf)
556 return -ENOMEM;
557
558 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
559 "Total Avail Credits: ",
560 target->cred_dist_cntxt->total_avail_credits);
561 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
562 "Free credits :",
563 target->cred_dist_cntxt->cur_free_credits);
564
565 len += scnprintf(buf + len, buf_len - len,
566 " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
567 " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
568 " qdepth\n");
569
570 list_for_each_entry(ep_list, &target->cred_dist_list, list) {
571 print_credit_info(" %2d", endpoint);
572 print_credit_info("%10x", dist_flags);
573 print_credit_info("%8d", cred_norm);
574 print_credit_info("%9d", cred_min);
575 print_credit_info("%9d", credits);
576 print_credit_info("%10d", cred_assngd);
577 print_credit_info("%13d", seek_cred);
578 print_credit_info("%12d", cred_sz);
579 print_credit_info("%9d", cred_per_msg);
580 print_credit_info("%14d", cred_to_dist);
581 len += scnprintf(buf + len, buf_len - len, "%12d\n",
582 get_queue_depth(&((struct htc_endpoint *)
583 ep_list->htc_rsvd)->txq));
584 }
585
586 if (len > buf_len)
587 len = buf_len;
588
589 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
590 kfree(buf);
591 return ret_cnt;
592}
593
594static const struct file_operations fops_credit_dist_stats = {
595 .read = read_file_credit_dist_stats,
596 .open = ath6kl_debugfs_open,
597 .owner = THIS_MODULE,
598 .llseek = default_llseek,
599};
600
Jouni Malinene8091282011-10-11 17:31:53 +0300601static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
602 unsigned int buf_len, unsigned int len,
603 int offset, const char *name)
604{
605 int i;
606 struct htc_endpoint_stats *ep_st;
607 u32 *counter;
608
609 len += scnprintf(buf + len, buf_len - len, "%s:", name);
610 for (i = 0; i < ENDPOINT_MAX; i++) {
611 ep_st = &target->endpoint[i].ep_st;
612 counter = ((u32 *) ep_st) + (offset / 4);
613 len += scnprintf(buf + len, buf_len - len, " %u", *counter);
614 }
615 len += scnprintf(buf + len, buf_len - len, "\n");
616
617 return len;
618}
619
620static ssize_t ath6kl_endpoint_stats_read(struct file *file,
621 char __user *user_buf,
622 size_t count, loff_t *ppos)
623{
624 struct ath6kl *ar = file->private_data;
625 struct htc_target *target = ar->htc_target;
626 char *buf;
627 unsigned int buf_len, len = 0;
628 ssize_t ret_cnt;
629
Jouni Malinen17169322011-10-11 22:08:21 +0300630 buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
631 (25 + ENDPOINT_MAX * 11);
632 buf = kmalloc(buf_len, GFP_KERNEL);
Jouni Malinene8091282011-10-11 17:31:53 +0300633 if (!buf)
634 return -ENOMEM;
635
636#define EPSTAT(name) \
637 len = print_endpoint_stat(target, buf, buf_len, len, \
638 offsetof(struct htc_endpoint_stats, name), \
639 #name)
640 EPSTAT(cred_low_indicate);
641 EPSTAT(tx_issued);
642 EPSTAT(tx_pkt_bundled);
643 EPSTAT(tx_bundles);
644 EPSTAT(tx_dropped);
645 EPSTAT(tx_cred_rpt);
646 EPSTAT(cred_rpt_from_rx);
Jouni Malinen17169322011-10-11 22:08:21 +0300647 EPSTAT(cred_rpt_from_other);
Jouni Malinene8091282011-10-11 17:31:53 +0300648 EPSTAT(cred_rpt_ep0);
649 EPSTAT(cred_from_rx);
650 EPSTAT(cred_from_other);
651 EPSTAT(cred_from_ep0);
652 EPSTAT(cred_cosumd);
653 EPSTAT(cred_retnd);
654 EPSTAT(rx_pkts);
655 EPSTAT(rx_lkahds);
656 EPSTAT(rx_bundl);
657 EPSTAT(rx_bundle_lkahd);
658 EPSTAT(rx_bundle_from_hdr);
659 EPSTAT(rx_alloc_thresh_hit);
660 EPSTAT(rxalloc_thresh_byte);
661#undef EPSTAT
662
663 if (len > buf_len)
664 len = buf_len;
665
666 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
667 kfree(buf);
668 return ret_cnt;
669}
670
671static ssize_t ath6kl_endpoint_stats_write(struct file *file,
672 const char __user *user_buf,
673 size_t count, loff_t *ppos)
674{
675 struct ath6kl *ar = file->private_data;
676 struct htc_target *target = ar->htc_target;
677 int ret, i;
678 u32 val;
679 struct htc_endpoint_stats *ep_st;
680
681 ret = kstrtou32_from_user(user_buf, count, 0, &val);
682 if (ret)
683 return ret;
684 if (val == 0) {
685 for (i = 0; i < ENDPOINT_MAX; i++) {
686 ep_st = &target->endpoint[i].ep_st;
687 memset(ep_st, 0, sizeof(*ep_st));
688 }
689 }
690
691 return count;
692}
693
694static const struct file_operations fops_endpoint_stats = {
695 .open = ath6kl_debugfs_open,
696 .read = ath6kl_endpoint_stats_read,
697 .write = ath6kl_endpoint_stats_write,
698 .owner = THIS_MODULE,
699 .llseek = default_llseek,
700};
701
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +0300702static unsigned long ath6kl_get_num_reg(void)
703{
704 int i;
705 unsigned long n_reg = 0;
706
707 for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
708 n_reg = n_reg +
709 (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
710
711 return n_reg;
712}
713
714static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
715{
716 int i;
717
718 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
719 if (reg_addr >= diag_reg[i].reg_start &&
720 reg_addr <= diag_reg[i].reg_end)
721 return true;
722 }
723
724 return false;
725}
726
727static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
728 size_t count, loff_t *ppos)
729{
730 struct ath6kl *ar = file->private_data;
731 u8 buf[50];
732 unsigned int len = 0;
733
734 if (ar->debug.dbgfs_diag_reg)
735 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
736 ar->debug.dbgfs_diag_reg);
737 else
738 len += scnprintf(buf + len, sizeof(buf) - len,
739 "All diag registers\n");
740
741 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
742}
743
744static ssize_t ath6kl_regread_write(struct file *file,
745 const char __user *user_buf,
746 size_t count, loff_t *ppos)
747{
748 struct ath6kl *ar = file->private_data;
749 u8 buf[50];
750 unsigned int len;
751 unsigned long reg_addr;
752
753 len = min(count, sizeof(buf) - 1);
754 if (copy_from_user(buf, user_buf, len))
755 return -EFAULT;
756
757 buf[len] = '\0';
758
759 if (strict_strtoul(buf, 0, &reg_addr))
760 return -EINVAL;
761
762 if ((reg_addr % 4) != 0)
763 return -EINVAL;
764
765 if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
766 return -EINVAL;
767
768 ar->debug.dbgfs_diag_reg = reg_addr;
769
770 return count;
771}
772
773static const struct file_operations fops_diag_reg_read = {
774 .read = ath6kl_regread_read,
775 .write = ath6kl_regread_write,
776 .open = ath6kl_debugfs_open,
777 .owner = THIS_MODULE,
778 .llseek = default_llseek,
779};
780
781static int ath6kl_regdump_open(struct inode *inode, struct file *file)
782{
783 struct ath6kl *ar = inode->i_private;
784 u8 *buf;
785 unsigned long int reg_len;
786 unsigned int len = 0, n_reg;
787 u32 addr;
788 __le32 reg_val;
789 int i, status;
790
791 /* Dump all the registers if no register is specified */
792 if (!ar->debug.dbgfs_diag_reg)
793 n_reg = ath6kl_get_num_reg();
794 else
795 n_reg = 1;
796
797 reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
798 if (n_reg > 1)
799 reg_len += REGTYPE_STR_LEN;
800
801 buf = vmalloc(reg_len);
802 if (!buf)
803 return -ENOMEM;
804
805 if (n_reg == 1) {
806 addr = ar->debug.dbgfs_diag_reg;
807
808 status = ath6kl_diag_read32(ar,
809 TARG_VTOP(ar->target_type, addr),
810 (u32 *)&reg_val);
811 if (status)
812 goto fail_reg_read;
813
814 len += scnprintf(buf + len, reg_len - len,
815 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
816 goto done;
817 }
818
819 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
820 len += scnprintf(buf + len, reg_len - len,
821 "%s\n", diag_reg[i].reg_info);
822 for (addr = diag_reg[i].reg_start;
823 addr <= diag_reg[i].reg_end; addr += 4) {
824 status = ath6kl_diag_read32(ar,
825 TARG_VTOP(ar->target_type, addr),
826 (u32 *)&reg_val);
827 if (status)
828 goto fail_reg_read;
829
830 len += scnprintf(buf + len, reg_len - len,
831 "0x%06x 0x%08x\n",
832 addr, le32_to_cpu(reg_val));
833 }
834 }
835
836done:
837 file->private_data = buf;
838 return 0;
839
840fail_reg_read:
841 ath6kl_warn("Unable to read memory:%u\n", addr);
842 vfree(buf);
843 return -EIO;
844}
845
846static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
847 size_t count, loff_t *ppos)
848{
849 u8 *buf = file->private_data;
850 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
851}
852
853static int ath6kl_regdump_release(struct inode *inode, struct file *file)
854{
855 vfree(file->private_data);
856 return 0;
857}
858
859static const struct file_operations fops_reg_dump = {
860 .open = ath6kl_regdump_open,
861 .read = ath6kl_regdump_read,
862 .release = ath6kl_regdump_release,
863 .owner = THIS_MODULE,
864 .llseek = default_llseek,
865};
866
Vivek Natarajane5090442011-08-31 15:02:19 +0530867static ssize_t ath6kl_lrssi_roam_write(struct file *file,
868 const char __user *user_buf,
869 size_t count, loff_t *ppos)
870{
871 struct ath6kl *ar = file->private_data;
872 unsigned long lrssi_roam_threshold;
873 char buf[32];
874 ssize_t len;
875
876 len = min(count, sizeof(buf) - 1);
877 if (copy_from_user(buf, user_buf, len))
878 return -EFAULT;
879
880 buf[len] = '\0';
881 if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
882 return -EINVAL;
883
884 ar->lrssi_roam_threshold = lrssi_roam_threshold;
885
886 ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
887
888 return count;
889}
890
891static ssize_t ath6kl_lrssi_roam_read(struct file *file,
892 char __user *user_buf,
893 size_t count, loff_t *ppos)
894{
895 struct ath6kl *ar = file->private_data;
896 char buf[32];
897 unsigned int len;
898
899 len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
900
901 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
902}
903
904static const struct file_operations fops_lrssi_roam_threshold = {
905 .read = ath6kl_lrssi_roam_read,
906 .write = ath6kl_lrssi_roam_write,
907 .open = ath6kl_debugfs_open,
908 .owner = THIS_MODULE,
909 .llseek = default_llseek,
910};
911
Vasanthakumar Thiagarajan252c0682011-09-05 11:19:46 +0300912static ssize_t ath6kl_regwrite_read(struct file *file,
913 char __user *user_buf,
914 size_t count, loff_t *ppos)
915{
916 struct ath6kl *ar = file->private_data;
917 u8 buf[32];
918 unsigned int len = 0;
919
920 len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
921 ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
922
923 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
924}
925
926static ssize_t ath6kl_regwrite_write(struct file *file,
927 const char __user *user_buf,
928 size_t count, loff_t *ppos)
929{
930 struct ath6kl *ar = file->private_data;
931 char buf[32];
932 char *sptr, *token;
933 unsigned int len = 0;
934 u32 reg_addr, reg_val;
935
936 len = min(count, sizeof(buf) - 1);
937 if (copy_from_user(buf, user_buf, len))
938 return -EFAULT;
939
940 buf[len] = '\0';
941 sptr = buf;
942
943 token = strsep(&sptr, "=");
944 if (!token)
945 return -EINVAL;
946
947 if (kstrtou32(token, 0, &reg_addr))
948 return -EINVAL;
949
950 if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
951 return -EINVAL;
952
953 if (kstrtou32(sptr, 0, &reg_val))
954 return -EINVAL;
955
956 ar->debug.diag_reg_addr_wr = reg_addr;
957 ar->debug.diag_reg_val_wr = reg_val;
958
959 if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
960 cpu_to_le32(ar->debug.diag_reg_val_wr)))
961 return -EIO;
962
963 return count;
964}
965
966static const struct file_operations fops_diag_reg_write = {
967 .read = ath6kl_regwrite_read,
968 .write = ath6kl_regwrite_write,
969 .open = ath6kl_debugfs_open,
970 .owner = THIS_MODULE,
971 .llseek = default_llseek,
972};
973
Jouni Malinen4b28a802011-10-11 17:31:54 +0300974int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
975 size_t len)
976{
977 const struct wmi_target_roam_tbl *tbl;
978 u16 num_entries;
979
980 if (len < sizeof(*tbl))
981 return -EINVAL;
982
983 tbl = (const struct wmi_target_roam_tbl *) buf;
984 num_entries = le16_to_cpu(tbl->num_entries);
985 if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
986 len)
987 return -EINVAL;
988
989 if (ar->debug.roam_tbl == NULL ||
990 ar->debug.roam_tbl_len < (unsigned int) len) {
991 kfree(ar->debug.roam_tbl);
992 ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
993 if (ar->debug.roam_tbl == NULL)
994 return -ENOMEM;
995 }
996
997 memcpy(ar->debug.roam_tbl, buf, len);
998 ar->debug.roam_tbl_len = len;
999
1000 if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
1001 clear_bit(ROAM_TBL_PEND, &ar->flag);
1002 wake_up(&ar->event_wq);
1003 }
1004
1005 return 0;
1006}
1007
1008static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
1009 size_t count, loff_t *ppos)
1010{
1011 struct ath6kl *ar = file->private_data;
1012 int ret;
1013 long left;
1014 struct wmi_target_roam_tbl *tbl;
1015 u16 num_entries, i;
1016 char *buf;
1017 unsigned int len, buf_len;
1018 ssize_t ret_cnt;
1019
1020 if (down_interruptible(&ar->sem))
1021 return -EBUSY;
1022
1023 set_bit(ROAM_TBL_PEND, &ar->flag);
1024
1025 ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
1026 if (ret) {
1027 up(&ar->sem);
1028 return ret;
1029 }
1030
1031 left = wait_event_interruptible_timeout(
1032 ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
1033 up(&ar->sem);
1034
1035 if (left <= 0)
1036 return -ETIMEDOUT;
1037
1038 if (ar->debug.roam_tbl == NULL)
1039 return -ENOMEM;
1040
1041 tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
1042 num_entries = le16_to_cpu(tbl->num_entries);
1043
1044 buf_len = 100 + num_entries * 100;
1045 buf = kzalloc(buf_len, GFP_KERNEL);
1046 if (buf == NULL)
1047 return -ENOMEM;
1048 len = 0;
1049 len += scnprintf(buf + len, buf_len - len,
1050 "roam_mode=%u\n\n"
1051 "# roam_util bssid rssi rssidt last_rssi util bias\n",
1052 le16_to_cpu(tbl->roam_mode));
1053
1054 for (i = 0; i < num_entries; i++) {
1055 struct wmi_bss_roam_info *info = &tbl->info[i];
1056 len += scnprintf(buf + len, buf_len - len,
1057 "%d %pM %d %d %d %d %d\n",
1058 a_sle32_to_cpu(info->roam_util), info->bssid,
1059 info->rssi, info->rssidt, info->last_rssi,
1060 info->util, info->bias);
1061 }
1062
1063 if (len > buf_len)
1064 len = buf_len;
1065
1066 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1067
1068 kfree(buf);
1069 return ret_cnt;
1070}
1071
1072static const struct file_operations fops_roam_table = {
1073 .read = ath6kl_roam_table_read,
1074 .open = ath6kl_debugfs_open,
1075 .owner = THIS_MODULE,
1076 .llseek = default_llseek,
1077};
1078
Jouni Malinen12618752011-10-11 17:31:55 +03001079static ssize_t ath6kl_force_roam_write(struct file *file,
1080 const char __user *user_buf,
1081 size_t count, loff_t *ppos)
1082{
1083 struct ath6kl *ar = file->private_data;
1084 int ret;
1085 char buf[20];
1086 size_t len;
1087 u8 bssid[ETH_ALEN];
1088 int i;
1089 int addr[ETH_ALEN];
1090
1091 len = min(count, sizeof(buf) - 1);
1092 if (copy_from_user(buf, user_buf, len))
1093 return -EFAULT;
1094 buf[len] = '\0';
1095
1096 if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
1097 &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
1098 != ETH_ALEN)
1099 return -EINVAL;
1100 for (i = 0; i < ETH_ALEN; i++)
1101 bssid[i] = addr[i];
1102
1103 ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
1104 if (ret)
1105 return ret;
1106
1107 return count;
1108}
1109
1110static const struct file_operations fops_force_roam = {
1111 .write = ath6kl_force_roam_write,
1112 .open = ath6kl_debugfs_open,
1113 .owner = THIS_MODULE,
1114 .llseek = default_llseek,
1115};
1116
1117static ssize_t ath6kl_roam_mode_write(struct file *file,
1118 const char __user *user_buf,
1119 size_t count, loff_t *ppos)
1120{
1121 struct ath6kl *ar = file->private_data;
1122 int ret;
1123 char buf[20];
1124 size_t len;
1125 enum wmi_roam_mode mode;
1126
1127 len = min(count, sizeof(buf) - 1);
1128 if (copy_from_user(buf, user_buf, len))
1129 return -EFAULT;
1130 buf[len] = '\0';
1131 if (len > 0 && buf[len - 1] == '\n')
1132 buf[len - 1] = '\0';
1133
1134 if (strcasecmp(buf, "default") == 0)
1135 mode = WMI_DEFAULT_ROAM_MODE;
1136 else if (strcasecmp(buf, "bssbias") == 0)
1137 mode = WMI_HOST_BIAS_ROAM_MODE;
1138 else if (strcasecmp(buf, "lock") == 0)
1139 mode = WMI_LOCK_BSS_MODE;
1140 else
1141 return -EINVAL;
1142
1143 ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
1144 if (ret)
1145 return ret;
1146
1147 return count;
1148}
1149
1150static const struct file_operations fops_roam_mode = {
1151 .write = ath6kl_roam_mode_write,
1152 .open = ath6kl_debugfs_open,
1153 .owner = THIS_MODULE,
1154 .llseek = default_llseek,
1155};
1156
Jouni Malinenff0b0072011-10-11 17:31:56 +03001157void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1158{
1159 ar->debug.keepalive = keepalive;
1160}
1161
1162static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1163 size_t count, loff_t *ppos)
1164{
1165 struct ath6kl *ar = file->private_data;
1166 char buf[16];
1167 int len;
1168
1169 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1170
1171 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1172}
1173
1174static ssize_t ath6kl_keepalive_write(struct file *file,
1175 const char __user *user_buf,
1176 size_t count, loff_t *ppos)
1177{
1178 struct ath6kl *ar = file->private_data;
1179 int ret;
1180 u8 val;
1181
1182 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1183 if (ret)
1184 return ret;
1185
1186 ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, val);
1187 if (ret)
1188 return ret;
1189
1190 return count;
1191}
1192
1193static const struct file_operations fops_keepalive = {
1194 .open = ath6kl_debugfs_open,
1195 .read = ath6kl_keepalive_read,
1196 .write = ath6kl_keepalive_write,
1197 .owner = THIS_MODULE,
1198 .llseek = default_llseek,
1199};
1200
1201void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1202{
1203 ar->debug.disc_timeout = timeout;
1204}
1205
1206static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1207 char __user *user_buf,
1208 size_t count, loff_t *ppos)
1209{
1210 struct ath6kl *ar = file->private_data;
1211 char buf[16];
1212 int len;
1213
1214 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1215
1216 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1217}
1218
1219static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1220 const char __user *user_buf,
1221 size_t count, loff_t *ppos)
1222{
1223 struct ath6kl *ar = file->private_data;
1224 int ret;
1225 u8 val;
1226
1227 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1228 if (ret)
1229 return ret;
1230
1231 ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, val);
1232 if (ret)
1233 return ret;
1234
1235 return count;
1236}
1237
1238static const struct file_operations fops_disconnect_timeout = {
1239 .open = ath6kl_debugfs_open,
1240 .read = ath6kl_disconnect_timeout_read,
1241 .write = ath6kl_disconnect_timeout_write,
1242 .owner = THIS_MODULE,
1243 .llseek = default_llseek,
1244};
1245
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001246static ssize_t ath6kl_create_qos_write(struct file *file,
1247 const char __user *user_buf,
1248 size_t count, loff_t *ppos)
1249{
1250
1251 struct ath6kl *ar = file->private_data;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301252 /* TODO: Findout vif */
1253 struct ath6kl_vif *vif = ar->vif;
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001254 char buf[100];
1255 ssize_t len;
1256 char *sptr, *token;
1257 struct wmi_create_pstream_cmd pstream;
1258 u32 val32;
1259 u16 val16;
1260
1261 len = min(count, sizeof(buf) - 1);
1262 if (copy_from_user(buf, user_buf, len))
1263 return -EFAULT;
1264 buf[len] = '\0';
1265 sptr = buf;
1266
1267 token = strsep(&sptr, " ");
1268 if (!token)
1269 return -EINVAL;
1270 if (kstrtou8(token, 0, &pstream.user_pri))
1271 return -EINVAL;
1272
1273 token = strsep(&sptr, " ");
1274 if (!token)
1275 return -EINVAL;
1276 if (kstrtou8(token, 0, &pstream.traffic_direc))
1277 return -EINVAL;
1278
1279 token = strsep(&sptr, " ");
1280 if (!token)
1281 return -EINVAL;
1282 if (kstrtou8(token, 0, &pstream.traffic_class))
1283 return -EINVAL;
1284
1285 token = strsep(&sptr, " ");
1286 if (!token)
1287 return -EINVAL;
1288 if (kstrtou8(token, 0, &pstream.traffic_type))
1289 return -EINVAL;
1290
1291 token = strsep(&sptr, " ");
1292 if (!token)
1293 return -EINVAL;
1294 if (kstrtou8(token, 0, &pstream.voice_psc_cap))
1295 return -EINVAL;
1296
1297 token = strsep(&sptr, " ");
1298 if (!token)
1299 return -EINVAL;
1300 if (kstrtou32(token, 0, &val32))
1301 return -EINVAL;
1302 pstream.min_service_int = cpu_to_le32(val32);
1303
1304 token = strsep(&sptr, " ");
1305 if (!token)
1306 return -EINVAL;
1307 if (kstrtou32(token, 0, &val32))
1308 return -EINVAL;
1309 pstream.max_service_int = cpu_to_le32(val32);
1310
1311 token = strsep(&sptr, " ");
1312 if (!token)
1313 return -EINVAL;
1314 if (kstrtou32(token, 0, &val32))
1315 return -EINVAL;
1316 pstream.inactivity_int = cpu_to_le32(val32);
1317
1318 token = strsep(&sptr, " ");
1319 if (!token)
1320 return -EINVAL;
1321 if (kstrtou32(token, 0, &val32))
1322 return -EINVAL;
1323 pstream.suspension_int = cpu_to_le32(val32);
1324
1325 token = strsep(&sptr, " ");
1326 if (!token)
1327 return -EINVAL;
1328 if (kstrtou32(token, 0, &val32))
1329 return -EINVAL;
1330 pstream.service_start_time = cpu_to_le32(val32);
1331
1332 token = strsep(&sptr, " ");
1333 if (!token)
1334 return -EINVAL;
1335 if (kstrtou8(token, 0, &pstream.tsid))
1336 return -EINVAL;
1337
1338 token = strsep(&sptr, " ");
1339 if (!token)
1340 return -EINVAL;
1341 if (kstrtou16(token, 0, &val16))
1342 return -EINVAL;
1343 pstream.nominal_msdu = cpu_to_le16(val16);
1344
1345 token = strsep(&sptr, " ");
1346 if (!token)
1347 return -EINVAL;
1348 if (kstrtou16(token, 0, &val16))
1349 return -EINVAL;
1350 pstream.max_msdu = cpu_to_le16(val16);
1351
1352 token = strsep(&sptr, " ");
1353 if (!token)
1354 return -EINVAL;
1355 if (kstrtou32(token, 0, &val32))
1356 return -EINVAL;
1357 pstream.min_data_rate = cpu_to_le32(val32);
1358
1359 token = strsep(&sptr, " ");
1360 if (!token)
1361 return -EINVAL;
1362 if (kstrtou32(token, 0, &val32))
1363 return -EINVAL;
1364 pstream.mean_data_rate = cpu_to_le32(val32);
1365
1366 token = strsep(&sptr, " ");
1367 if (!token)
1368 return -EINVAL;
1369 if (kstrtou32(token, 0, &val32))
1370 return -EINVAL;
1371 pstream.peak_data_rate = cpu_to_le32(val32);
1372
1373 token = strsep(&sptr, " ");
1374 if (!token)
1375 return -EINVAL;
1376 if (kstrtou32(token, 0, &val32))
1377 return -EINVAL;
1378 pstream.max_burst_size = cpu_to_le32(val32);
1379
1380 token = strsep(&sptr, " ");
1381 if (!token)
1382 return -EINVAL;
1383 if (kstrtou32(token, 0, &val32))
1384 return -EINVAL;
1385 pstream.delay_bound = cpu_to_le32(val32);
1386
1387 token = strsep(&sptr, " ");
1388 if (!token)
1389 return -EINVAL;
1390 if (kstrtou32(token, 0, &val32))
1391 return -EINVAL;
1392 pstream.min_phy_rate = cpu_to_le32(val32);
1393
1394 token = strsep(&sptr, " ");
1395 if (!token)
1396 return -EINVAL;
1397 if (kstrtou32(token, 0, &val32))
1398 return -EINVAL;
1399 pstream.sba = cpu_to_le32(val32);
1400
1401 token = strsep(&sptr, " ");
1402 if (!token)
1403 return -EINVAL;
1404 if (kstrtou32(token, 0, &val32))
1405 return -EINVAL;
1406 pstream.medium_time = cpu_to_le32(val32);
1407
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301408 ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001409
1410 return count;
1411}
1412
1413static const struct file_operations fops_create_qos = {
1414 .write = ath6kl_create_qos_write,
1415 .open = ath6kl_debugfs_open,
1416 .owner = THIS_MODULE,
1417 .llseek = default_llseek,
1418};
1419
1420static ssize_t ath6kl_delete_qos_write(struct file *file,
1421 const char __user *user_buf,
1422 size_t count, loff_t *ppos)
1423{
1424
1425 struct ath6kl *ar = file->private_data;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301426 /* TODO: Findout vif */
1427 struct ath6kl_vif *vif = ar->vif;
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001428 char buf[100];
1429 ssize_t len;
1430 char *sptr, *token;
1431 u8 traffic_class;
1432 u8 tsid;
1433
1434 len = min(count, sizeof(buf) - 1);
1435 if (copy_from_user(buf, user_buf, len))
1436 return -EFAULT;
1437 buf[len] = '\0';
1438 sptr = buf;
1439
1440 token = strsep(&sptr, " ");
1441 if (!token)
1442 return -EINVAL;
1443 if (kstrtou8(token, 0, &traffic_class))
1444 return -EINVAL;
1445
1446 token = strsep(&sptr, " ");
1447 if (!token)
1448 return -EINVAL;
1449 if (kstrtou8(token, 0, &tsid))
1450 return -EINVAL;
1451
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301452 ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
1453 traffic_class, tsid);
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001454
1455 return count;
1456}
1457
1458static const struct file_operations fops_delete_qos = {
1459 .write = ath6kl_delete_qos_write,
1460 .open = ath6kl_debugfs_open,
1461 .owner = THIS_MODULE,
1462 .llseek = default_llseek,
1463};
1464
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001465static ssize_t ath6kl_bgscan_int_write(struct file *file,
1466 const char __user *user_buf,
1467 size_t count, loff_t *ppos)
1468{
1469 struct ath6kl *ar = file->private_data;
1470 u16 bgscan_int;
1471 char buf[32];
1472 ssize_t len;
1473
1474 len = min(count, sizeof(buf) - 1);
1475 if (copy_from_user(buf, user_buf, len))
1476 return -EFAULT;
1477
1478 buf[len] = '\0';
1479 if (kstrtou16(buf, 0, &bgscan_int))
1480 return -EINVAL;
1481
1482 if (bgscan_int == 0)
1483 bgscan_int = 0xffff;
1484
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301485 ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001486 0, 0, 0);
1487
1488 return count;
1489}
1490
1491static const struct file_operations fops_bgscan_int = {
1492 .write = ath6kl_bgscan_int_write,
1493 .open = ath6kl_debugfs_open,
1494 .owner = THIS_MODULE,
1495 .llseek = default_llseek,
1496};
1497
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301498int ath6kl_debug_init(struct ath6kl *ar)
1499{
Kalle Valobdf53962011-09-02 10:32:04 +03001500 ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
1501 if (ar->debug.fwlog_buf.buf == NULL)
1502 return -ENOMEM;
1503
1504 ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
1505 if (ar->debug.fwlog_tmp == NULL) {
1506 vfree(ar->debug.fwlog_buf.buf);
1507 return -ENOMEM;
1508 }
1509
1510 spin_lock_init(&ar->debug.fwlog_lock);
1511
Kalle Valo939f1cc2011-09-02 10:32:04 +03001512 /*
1513 * Actually we are lying here but don't know how to read the mask
1514 * value from the firmware.
1515 */
1516 ar->debug.fwlog_mask = 0;
1517
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301518 ar->debugfs_phy = debugfs_create_dir("ath6kl",
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301519 ar->wiphy->debugfsdir);
Kalle Valobdf53962011-09-02 10:32:04 +03001520 if (!ar->debugfs_phy) {
1521 vfree(ar->debug.fwlog_buf.buf);
1522 kfree(ar->debug.fwlog_tmp);
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301523 return -ENOMEM;
Kalle Valobdf53962011-09-02 10:32:04 +03001524 }
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301525
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +05301526 debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
1527 &fops_tgt_stats);
1528
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +05301529 debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
1530 &fops_credit_dist_stats);
1531
Jouni Malinene8091282011-10-11 17:31:53 +03001532 debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
1533 ar->debugfs_phy, ar, &fops_endpoint_stats);
1534
Kalle Valobdf53962011-09-02 10:32:04 +03001535 debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
1536 &fops_fwlog);
1537
Kalle Valo939f1cc2011-09-02 10:32:04 +03001538 debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
1539 ar, &fops_fwlog_mask);
1540
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +03001541 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1542 &fops_diag_reg_read);
1543
1544 debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
1545 &fops_reg_dump);
1546
Vivek Natarajane5090442011-08-31 15:02:19 +05301547 debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
1548 ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
Vasanthakumar Thiagarajan252c0682011-09-05 11:19:46 +03001549
1550 debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
1551 ar->debugfs_phy, ar, &fops_diag_reg_write);
1552
Kalle Valo9a730832011-09-27 23:33:28 +03001553 debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
1554 &fops_war_stats);
1555
Jouni Malinen4b28a802011-10-11 17:31:54 +03001556 debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
1557 &fops_roam_table);
1558
Jouni Malinen12618752011-10-11 17:31:55 +03001559 debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
1560 &fops_force_roam);
1561
1562 debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
1563 &fops_roam_mode);
1564
Jouni Malinenff0b0072011-10-11 17:31:56 +03001565 debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1566 &fops_keepalive);
1567
1568 debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
1569 ar->debugfs_phy, ar, &fops_disconnect_timeout);
1570
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001571 debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
1572 &fops_create_qos);
1573
1574 debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
1575 &fops_delete_qos);
1576
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001577 debugfs_create_file("bgscan_interval", S_IWUSR,
1578 ar->debugfs_phy, ar, &fops_bgscan_int);
1579
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301580 return 0;
1581}
Kalle Valobdf53962011-09-02 10:32:04 +03001582
1583void ath6kl_debug_cleanup(struct ath6kl *ar)
1584{
1585 vfree(ar->debug.fwlog_buf.buf);
1586 kfree(ar->debug.fwlog_tmp);
Jouni Malinen4b28a802011-10-11 17:31:54 +03001587 kfree(ar->debug.roam_tbl);
Kalle Valobdf53962011-09-02 10:32:04 +03001588}
1589
Kalle Valobdcd8172011-07-18 00:22:30 +03001590#endif