blob: f067c7b1b1219caf7bc4ed2ffa8a7aab3130db44 [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;
400 struct target_stats *tgt_stats = &ar->target_stats;
401 char *buf;
402 unsigned int len = 0, buf_len = 1500;
403 int i;
404 long left;
405 ssize_t ret_cnt;
406
407 buf = kzalloc(buf_len, GFP_KERNEL);
408 if (!buf)
409 return -ENOMEM;
410
411 if (down_interruptible(&ar->sem)) {
412 kfree(buf);
413 return -EBUSY;
414 }
415
416 set_bit(STATS_UPDATE_PEND, &ar->flag);
417
418 if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
419 up(&ar->sem);
420 kfree(buf);
421 return -EIO;
422 }
423
424 left = wait_event_interruptible_timeout(ar->event_wq,
425 !test_bit(STATS_UPDATE_PEND,
426 &ar->flag), WMI_TIMEOUT);
427
428 up(&ar->sem);
429
430 if (left <= 0) {
431 kfree(buf);
432 return -ETIMEDOUT;
433 }
434
435 len += scnprintf(buf + len, buf_len - len, "\n");
436 len += scnprintf(buf + len, buf_len - len, "%25s\n",
437 "Target Tx stats");
438 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
439 "=================");
440 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
441 "Ucast packets", tgt_stats->tx_ucast_pkt);
442 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
443 "Bcast packets", tgt_stats->tx_bcast_pkt);
444 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
445 "Ucast byte", tgt_stats->tx_ucast_byte);
446 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
447 "Bcast byte", tgt_stats->tx_bcast_byte);
448 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
449 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
450 for (i = 0; i < 4; i++)
451 len += scnprintf(buf + len, buf_len - len,
452 "%18s %d %10llu\n", "PER on ac",
453 i, tgt_stats->tx_pkt_per_ac[i]);
454 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
455 "Error", tgt_stats->tx_err);
456 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
457 "Fail count", tgt_stats->tx_fail_cnt);
458 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
459 "Retry count", tgt_stats->tx_retry_cnt);
460 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
461 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
462 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
463 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
464 len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
465 "TKIP counter measure used",
466 tgt_stats->tkip_cnter_measures_invoked);
467
468 len += scnprintf(buf + len, buf_len - len, "%25s\n",
469 "Target Rx stats");
470 len += scnprintf(buf + len, buf_len - len, "%25s\n",
471 "=================");
472
473 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
474 "Ucast packets", tgt_stats->rx_ucast_pkt);
475 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
476 "Ucast Rate", tgt_stats->rx_ucast_rate);
477 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
478 "Bcast packets", tgt_stats->rx_bcast_pkt);
479 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
480 "Ucast byte", tgt_stats->rx_ucast_byte);
481 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
482 "Bcast byte", tgt_stats->rx_bcast_byte);
483 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
484 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
485 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
486 "Error", tgt_stats->rx_err);
487 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
488 "CRC Err", tgt_stats->rx_crc_err);
489 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
490 "Key chache miss", tgt_stats->rx_key_cache_miss);
491 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
492 "Decrypt Err", tgt_stats->rx_decrypt_err);
493 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
494 "Duplicate frame", tgt_stats->rx_dupl_frame);
495 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
496 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
497 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
498 "TKIP format err", tgt_stats->tkip_fmt_err);
499 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
500 "CCMP format Err", tgt_stats->ccmp_fmt_err);
501 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
502 "CCMP Replay Err", tgt_stats->ccmp_replays);
503
504 len += scnprintf(buf + len, buf_len - len, "%25s\n",
505 "Misc Target stats");
506 len += scnprintf(buf + len, buf_len - len, "%25s\n",
507 "=================");
508 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
509 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
510 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
511 "Num Connects", tgt_stats->cs_connect_cnt);
512 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
513 "Num disconnects", tgt_stats->cs_discon_cnt);
514 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
515 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
516
517 if (len > buf_len)
518 len = buf_len;
519
520 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
521
522 kfree(buf);
523 return ret_cnt;
524}
525
526static const struct file_operations fops_tgt_stats = {
527 .read = read_file_tgt_stats,
528 .open = ath6kl_debugfs_open,
529 .owner = THIS_MODULE,
530 .llseek = default_llseek,
531};
532
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530533#define print_credit_info(fmt_str, ep_list_field) \
534 (len += scnprintf(buf + len, buf_len - len, fmt_str, \
535 ep_list->ep_list_field))
536#define CREDIT_INFO_DISPLAY_STRING_LEN 200
537#define CREDIT_INFO_LEN 128
538
539static ssize_t read_file_credit_dist_stats(struct file *file,
540 char __user *user_buf,
541 size_t count, loff_t *ppos)
542{
543 struct ath6kl *ar = file->private_data;
544 struct htc_target *target = ar->htc_target;
545 struct htc_endpoint_credit_dist *ep_list;
546 char *buf;
547 unsigned int buf_len, len = 0;
548 ssize_t ret_cnt;
549
550 buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
551 get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
552 buf = kzalloc(buf_len, GFP_KERNEL);
553 if (!buf)
554 return -ENOMEM;
555
556 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
557 "Total Avail Credits: ",
558 target->cred_dist_cntxt->total_avail_credits);
559 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
560 "Free credits :",
561 target->cred_dist_cntxt->cur_free_credits);
562
563 len += scnprintf(buf + len, buf_len - len,
564 " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
565 " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
566 " qdepth\n");
567
568 list_for_each_entry(ep_list, &target->cred_dist_list, list) {
569 print_credit_info(" %2d", endpoint);
570 print_credit_info("%10x", dist_flags);
571 print_credit_info("%8d", cred_norm);
572 print_credit_info("%9d", cred_min);
573 print_credit_info("%9d", credits);
574 print_credit_info("%10d", cred_assngd);
575 print_credit_info("%13d", seek_cred);
576 print_credit_info("%12d", cred_sz);
577 print_credit_info("%9d", cred_per_msg);
578 print_credit_info("%14d", cred_to_dist);
579 len += scnprintf(buf + len, buf_len - len, "%12d\n",
580 get_queue_depth(&((struct htc_endpoint *)
581 ep_list->htc_rsvd)->txq));
582 }
583
584 if (len > buf_len)
585 len = buf_len;
586
587 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
588 kfree(buf);
589 return ret_cnt;
590}
591
592static const struct file_operations fops_credit_dist_stats = {
593 .read = read_file_credit_dist_stats,
594 .open = ath6kl_debugfs_open,
595 .owner = THIS_MODULE,
596 .llseek = default_llseek,
597};
598
Jouni Malinene8091282011-10-11 17:31:53 +0300599static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
600 unsigned int buf_len, unsigned int len,
601 int offset, const char *name)
602{
603 int i;
604 struct htc_endpoint_stats *ep_st;
605 u32 *counter;
606
607 len += scnprintf(buf + len, buf_len - len, "%s:", name);
608 for (i = 0; i < ENDPOINT_MAX; i++) {
609 ep_st = &target->endpoint[i].ep_st;
610 counter = ((u32 *) ep_st) + (offset / 4);
611 len += scnprintf(buf + len, buf_len - len, " %u", *counter);
612 }
613 len += scnprintf(buf + len, buf_len - len, "\n");
614
615 return len;
616}
617
618static ssize_t ath6kl_endpoint_stats_read(struct file *file,
619 char __user *user_buf,
620 size_t count, loff_t *ppos)
621{
622 struct ath6kl *ar = file->private_data;
623 struct htc_target *target = ar->htc_target;
624 char *buf;
625 unsigned int buf_len, len = 0;
626 ssize_t ret_cnt;
627
Jouni Malinen17169322011-10-11 22:08:21 +0300628 buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
629 (25 + ENDPOINT_MAX * 11);
630 buf = kmalloc(buf_len, GFP_KERNEL);
Jouni Malinene8091282011-10-11 17:31:53 +0300631 if (!buf)
632 return -ENOMEM;
633
634#define EPSTAT(name) \
635 len = print_endpoint_stat(target, buf, buf_len, len, \
636 offsetof(struct htc_endpoint_stats, name), \
637 #name)
638 EPSTAT(cred_low_indicate);
639 EPSTAT(tx_issued);
640 EPSTAT(tx_pkt_bundled);
641 EPSTAT(tx_bundles);
642 EPSTAT(tx_dropped);
643 EPSTAT(tx_cred_rpt);
644 EPSTAT(cred_rpt_from_rx);
Jouni Malinen17169322011-10-11 22:08:21 +0300645 EPSTAT(cred_rpt_from_other);
Jouni Malinene8091282011-10-11 17:31:53 +0300646 EPSTAT(cred_rpt_ep0);
647 EPSTAT(cred_from_rx);
648 EPSTAT(cred_from_other);
649 EPSTAT(cred_from_ep0);
650 EPSTAT(cred_cosumd);
651 EPSTAT(cred_retnd);
652 EPSTAT(rx_pkts);
653 EPSTAT(rx_lkahds);
654 EPSTAT(rx_bundl);
655 EPSTAT(rx_bundle_lkahd);
656 EPSTAT(rx_bundle_from_hdr);
657 EPSTAT(rx_alloc_thresh_hit);
658 EPSTAT(rxalloc_thresh_byte);
659#undef EPSTAT
660
661 if (len > buf_len)
662 len = buf_len;
663
664 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
665 kfree(buf);
666 return ret_cnt;
667}
668
669static ssize_t ath6kl_endpoint_stats_write(struct file *file,
670 const char __user *user_buf,
671 size_t count, loff_t *ppos)
672{
673 struct ath6kl *ar = file->private_data;
674 struct htc_target *target = ar->htc_target;
675 int ret, i;
676 u32 val;
677 struct htc_endpoint_stats *ep_st;
678
679 ret = kstrtou32_from_user(user_buf, count, 0, &val);
680 if (ret)
681 return ret;
682 if (val == 0) {
683 for (i = 0; i < ENDPOINT_MAX; i++) {
684 ep_st = &target->endpoint[i].ep_st;
685 memset(ep_st, 0, sizeof(*ep_st));
686 }
687 }
688
689 return count;
690}
691
692static const struct file_operations fops_endpoint_stats = {
693 .open = ath6kl_debugfs_open,
694 .read = ath6kl_endpoint_stats_read,
695 .write = ath6kl_endpoint_stats_write,
696 .owner = THIS_MODULE,
697 .llseek = default_llseek,
698};
699
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +0300700static unsigned long ath6kl_get_num_reg(void)
701{
702 int i;
703 unsigned long n_reg = 0;
704
705 for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
706 n_reg = n_reg +
707 (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
708
709 return n_reg;
710}
711
712static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
713{
714 int i;
715
716 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
717 if (reg_addr >= diag_reg[i].reg_start &&
718 reg_addr <= diag_reg[i].reg_end)
719 return true;
720 }
721
722 return false;
723}
724
725static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
726 size_t count, loff_t *ppos)
727{
728 struct ath6kl *ar = file->private_data;
729 u8 buf[50];
730 unsigned int len = 0;
731
732 if (ar->debug.dbgfs_diag_reg)
733 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
734 ar->debug.dbgfs_diag_reg);
735 else
736 len += scnprintf(buf + len, sizeof(buf) - len,
737 "All diag registers\n");
738
739 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
740}
741
742static ssize_t ath6kl_regread_write(struct file *file,
743 const char __user *user_buf,
744 size_t count, loff_t *ppos)
745{
746 struct ath6kl *ar = file->private_data;
747 u8 buf[50];
748 unsigned int len;
749 unsigned long reg_addr;
750
751 len = min(count, sizeof(buf) - 1);
752 if (copy_from_user(buf, user_buf, len))
753 return -EFAULT;
754
755 buf[len] = '\0';
756
757 if (strict_strtoul(buf, 0, &reg_addr))
758 return -EINVAL;
759
760 if ((reg_addr % 4) != 0)
761 return -EINVAL;
762
763 if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
764 return -EINVAL;
765
766 ar->debug.dbgfs_diag_reg = reg_addr;
767
768 return count;
769}
770
771static const struct file_operations fops_diag_reg_read = {
772 .read = ath6kl_regread_read,
773 .write = ath6kl_regread_write,
774 .open = ath6kl_debugfs_open,
775 .owner = THIS_MODULE,
776 .llseek = default_llseek,
777};
778
779static int ath6kl_regdump_open(struct inode *inode, struct file *file)
780{
781 struct ath6kl *ar = inode->i_private;
782 u8 *buf;
783 unsigned long int reg_len;
784 unsigned int len = 0, n_reg;
785 u32 addr;
786 __le32 reg_val;
787 int i, status;
788
789 /* Dump all the registers if no register is specified */
790 if (!ar->debug.dbgfs_diag_reg)
791 n_reg = ath6kl_get_num_reg();
792 else
793 n_reg = 1;
794
795 reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
796 if (n_reg > 1)
797 reg_len += REGTYPE_STR_LEN;
798
799 buf = vmalloc(reg_len);
800 if (!buf)
801 return -ENOMEM;
802
803 if (n_reg == 1) {
804 addr = ar->debug.dbgfs_diag_reg;
805
806 status = ath6kl_diag_read32(ar,
807 TARG_VTOP(ar->target_type, addr),
808 (u32 *)&reg_val);
809 if (status)
810 goto fail_reg_read;
811
812 len += scnprintf(buf + len, reg_len - len,
813 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
814 goto done;
815 }
816
817 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
818 len += scnprintf(buf + len, reg_len - len,
819 "%s\n", diag_reg[i].reg_info);
820 for (addr = diag_reg[i].reg_start;
821 addr <= diag_reg[i].reg_end; addr += 4) {
822 status = ath6kl_diag_read32(ar,
823 TARG_VTOP(ar->target_type, addr),
824 (u32 *)&reg_val);
825 if (status)
826 goto fail_reg_read;
827
828 len += scnprintf(buf + len, reg_len - len,
829 "0x%06x 0x%08x\n",
830 addr, le32_to_cpu(reg_val));
831 }
832 }
833
834done:
835 file->private_data = buf;
836 return 0;
837
838fail_reg_read:
839 ath6kl_warn("Unable to read memory:%u\n", addr);
840 vfree(buf);
841 return -EIO;
842}
843
844static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
845 size_t count, loff_t *ppos)
846{
847 u8 *buf = file->private_data;
848 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
849}
850
851static int ath6kl_regdump_release(struct inode *inode, struct file *file)
852{
853 vfree(file->private_data);
854 return 0;
855}
856
857static const struct file_operations fops_reg_dump = {
858 .open = ath6kl_regdump_open,
859 .read = ath6kl_regdump_read,
860 .release = ath6kl_regdump_release,
861 .owner = THIS_MODULE,
862 .llseek = default_llseek,
863};
864
Vivek Natarajane5090442011-08-31 15:02:19 +0530865static ssize_t ath6kl_lrssi_roam_write(struct file *file,
866 const char __user *user_buf,
867 size_t count, loff_t *ppos)
868{
869 struct ath6kl *ar = file->private_data;
870 unsigned long lrssi_roam_threshold;
871 char buf[32];
872 ssize_t len;
873
874 len = min(count, sizeof(buf) - 1);
875 if (copy_from_user(buf, user_buf, len))
876 return -EFAULT;
877
878 buf[len] = '\0';
879 if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
880 return -EINVAL;
881
882 ar->lrssi_roam_threshold = lrssi_roam_threshold;
883
884 ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
885
886 return count;
887}
888
889static ssize_t ath6kl_lrssi_roam_read(struct file *file,
890 char __user *user_buf,
891 size_t count, loff_t *ppos)
892{
893 struct ath6kl *ar = file->private_data;
894 char buf[32];
895 unsigned int len;
896
897 len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
898
899 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
900}
901
902static const struct file_operations fops_lrssi_roam_threshold = {
903 .read = ath6kl_lrssi_roam_read,
904 .write = ath6kl_lrssi_roam_write,
905 .open = ath6kl_debugfs_open,
906 .owner = THIS_MODULE,
907 .llseek = default_llseek,
908};
909
Vasanthakumar Thiagarajan252c0682011-09-05 11:19:46 +0300910static ssize_t ath6kl_regwrite_read(struct file *file,
911 char __user *user_buf,
912 size_t count, loff_t *ppos)
913{
914 struct ath6kl *ar = file->private_data;
915 u8 buf[32];
916 unsigned int len = 0;
917
918 len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
919 ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
920
921 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
922}
923
924static ssize_t ath6kl_regwrite_write(struct file *file,
925 const char __user *user_buf,
926 size_t count, loff_t *ppos)
927{
928 struct ath6kl *ar = file->private_data;
929 char buf[32];
930 char *sptr, *token;
931 unsigned int len = 0;
932 u32 reg_addr, reg_val;
933
934 len = min(count, sizeof(buf) - 1);
935 if (copy_from_user(buf, user_buf, len))
936 return -EFAULT;
937
938 buf[len] = '\0';
939 sptr = buf;
940
941 token = strsep(&sptr, "=");
942 if (!token)
943 return -EINVAL;
944
945 if (kstrtou32(token, 0, &reg_addr))
946 return -EINVAL;
947
948 if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
949 return -EINVAL;
950
951 if (kstrtou32(sptr, 0, &reg_val))
952 return -EINVAL;
953
954 ar->debug.diag_reg_addr_wr = reg_addr;
955 ar->debug.diag_reg_val_wr = reg_val;
956
957 if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
958 cpu_to_le32(ar->debug.diag_reg_val_wr)))
959 return -EIO;
960
961 return count;
962}
963
964static const struct file_operations fops_diag_reg_write = {
965 .read = ath6kl_regwrite_read,
966 .write = ath6kl_regwrite_write,
967 .open = ath6kl_debugfs_open,
968 .owner = THIS_MODULE,
969 .llseek = default_llseek,
970};
971
Jouni Malinen4b28a802011-10-11 17:31:54 +0300972int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
973 size_t len)
974{
975 const struct wmi_target_roam_tbl *tbl;
976 u16 num_entries;
977
978 if (len < sizeof(*tbl))
979 return -EINVAL;
980
981 tbl = (const struct wmi_target_roam_tbl *) buf;
982 num_entries = le16_to_cpu(tbl->num_entries);
983 if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
984 len)
985 return -EINVAL;
986
987 if (ar->debug.roam_tbl == NULL ||
988 ar->debug.roam_tbl_len < (unsigned int) len) {
989 kfree(ar->debug.roam_tbl);
990 ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
991 if (ar->debug.roam_tbl == NULL)
992 return -ENOMEM;
993 }
994
995 memcpy(ar->debug.roam_tbl, buf, len);
996 ar->debug.roam_tbl_len = len;
997
998 if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
999 clear_bit(ROAM_TBL_PEND, &ar->flag);
1000 wake_up(&ar->event_wq);
1001 }
1002
1003 return 0;
1004}
1005
1006static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
1007 size_t count, loff_t *ppos)
1008{
1009 struct ath6kl *ar = file->private_data;
1010 int ret;
1011 long left;
1012 struct wmi_target_roam_tbl *tbl;
1013 u16 num_entries, i;
1014 char *buf;
1015 unsigned int len, buf_len;
1016 ssize_t ret_cnt;
1017
1018 if (down_interruptible(&ar->sem))
1019 return -EBUSY;
1020
1021 set_bit(ROAM_TBL_PEND, &ar->flag);
1022
1023 ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
1024 if (ret) {
1025 up(&ar->sem);
1026 return ret;
1027 }
1028
1029 left = wait_event_interruptible_timeout(
1030 ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
1031 up(&ar->sem);
1032
1033 if (left <= 0)
1034 return -ETIMEDOUT;
1035
1036 if (ar->debug.roam_tbl == NULL)
1037 return -ENOMEM;
1038
1039 tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
1040 num_entries = le16_to_cpu(tbl->num_entries);
1041
1042 buf_len = 100 + num_entries * 100;
1043 buf = kzalloc(buf_len, GFP_KERNEL);
1044 if (buf == NULL)
1045 return -ENOMEM;
1046 len = 0;
1047 len += scnprintf(buf + len, buf_len - len,
1048 "roam_mode=%u\n\n"
1049 "# roam_util bssid rssi rssidt last_rssi util bias\n",
1050 le16_to_cpu(tbl->roam_mode));
1051
1052 for (i = 0; i < num_entries; i++) {
1053 struct wmi_bss_roam_info *info = &tbl->info[i];
1054 len += scnprintf(buf + len, buf_len - len,
1055 "%d %pM %d %d %d %d %d\n",
1056 a_sle32_to_cpu(info->roam_util), info->bssid,
1057 info->rssi, info->rssidt, info->last_rssi,
1058 info->util, info->bias);
1059 }
1060
1061 if (len > buf_len)
1062 len = buf_len;
1063
1064 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1065
1066 kfree(buf);
1067 return ret_cnt;
1068}
1069
1070static const struct file_operations fops_roam_table = {
1071 .read = ath6kl_roam_table_read,
1072 .open = ath6kl_debugfs_open,
1073 .owner = THIS_MODULE,
1074 .llseek = default_llseek,
1075};
1076
Jouni Malinen12618752011-10-11 17:31:55 +03001077static ssize_t ath6kl_force_roam_write(struct file *file,
1078 const char __user *user_buf,
1079 size_t count, loff_t *ppos)
1080{
1081 struct ath6kl *ar = file->private_data;
1082 int ret;
1083 char buf[20];
1084 size_t len;
1085 u8 bssid[ETH_ALEN];
1086 int i;
1087 int addr[ETH_ALEN];
1088
1089 len = min(count, sizeof(buf) - 1);
1090 if (copy_from_user(buf, user_buf, len))
1091 return -EFAULT;
1092 buf[len] = '\0';
1093
1094 if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
1095 &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
1096 != ETH_ALEN)
1097 return -EINVAL;
1098 for (i = 0; i < ETH_ALEN; i++)
1099 bssid[i] = addr[i];
1100
1101 ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
1102 if (ret)
1103 return ret;
1104
1105 return count;
1106}
1107
1108static const struct file_operations fops_force_roam = {
1109 .write = ath6kl_force_roam_write,
1110 .open = ath6kl_debugfs_open,
1111 .owner = THIS_MODULE,
1112 .llseek = default_llseek,
1113};
1114
1115static ssize_t ath6kl_roam_mode_write(struct file *file,
1116 const char __user *user_buf,
1117 size_t count, loff_t *ppos)
1118{
1119 struct ath6kl *ar = file->private_data;
1120 int ret;
1121 char buf[20];
1122 size_t len;
1123 enum wmi_roam_mode mode;
1124
1125 len = min(count, sizeof(buf) - 1);
1126 if (copy_from_user(buf, user_buf, len))
1127 return -EFAULT;
1128 buf[len] = '\0';
1129 if (len > 0 && buf[len - 1] == '\n')
1130 buf[len - 1] = '\0';
1131
1132 if (strcasecmp(buf, "default") == 0)
1133 mode = WMI_DEFAULT_ROAM_MODE;
1134 else if (strcasecmp(buf, "bssbias") == 0)
1135 mode = WMI_HOST_BIAS_ROAM_MODE;
1136 else if (strcasecmp(buf, "lock") == 0)
1137 mode = WMI_LOCK_BSS_MODE;
1138 else
1139 return -EINVAL;
1140
1141 ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
1142 if (ret)
1143 return ret;
1144
1145 return count;
1146}
1147
1148static const struct file_operations fops_roam_mode = {
1149 .write = ath6kl_roam_mode_write,
1150 .open = ath6kl_debugfs_open,
1151 .owner = THIS_MODULE,
1152 .llseek = default_llseek,
1153};
1154
Jouni Malinenff0b0072011-10-11 17:31:56 +03001155void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1156{
1157 ar->debug.keepalive = keepalive;
1158}
1159
1160static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1161 size_t count, loff_t *ppos)
1162{
1163 struct ath6kl *ar = file->private_data;
1164 char buf[16];
1165 int len;
1166
1167 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1168
1169 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1170}
1171
1172static ssize_t ath6kl_keepalive_write(struct file *file,
1173 const char __user *user_buf,
1174 size_t count, loff_t *ppos)
1175{
1176 struct ath6kl *ar = file->private_data;
1177 int ret;
1178 u8 val;
1179
1180 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1181 if (ret)
1182 return ret;
1183
1184 ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, val);
1185 if (ret)
1186 return ret;
1187
1188 return count;
1189}
1190
1191static const struct file_operations fops_keepalive = {
1192 .open = ath6kl_debugfs_open,
1193 .read = ath6kl_keepalive_read,
1194 .write = ath6kl_keepalive_write,
1195 .owner = THIS_MODULE,
1196 .llseek = default_llseek,
1197};
1198
1199void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1200{
1201 ar->debug.disc_timeout = timeout;
1202}
1203
1204static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1205 char __user *user_buf,
1206 size_t count, loff_t *ppos)
1207{
1208 struct ath6kl *ar = file->private_data;
1209 char buf[16];
1210 int len;
1211
1212 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1213
1214 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1215}
1216
1217static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1218 const char __user *user_buf,
1219 size_t count, loff_t *ppos)
1220{
1221 struct ath6kl *ar = file->private_data;
1222 int ret;
1223 u8 val;
1224
1225 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1226 if (ret)
1227 return ret;
1228
1229 ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, val);
1230 if (ret)
1231 return ret;
1232
1233 return count;
1234}
1235
1236static const struct file_operations fops_disconnect_timeout = {
1237 .open = ath6kl_debugfs_open,
1238 .read = ath6kl_disconnect_timeout_read,
1239 .write = ath6kl_disconnect_timeout_write,
1240 .owner = THIS_MODULE,
1241 .llseek = default_llseek,
1242};
1243
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001244static ssize_t ath6kl_create_qos_write(struct file *file,
1245 const char __user *user_buf,
1246 size_t count, loff_t *ppos)
1247{
1248
1249 struct ath6kl *ar = file->private_data;
1250 char buf[100];
1251 ssize_t len;
1252 char *sptr, *token;
1253 struct wmi_create_pstream_cmd pstream;
1254 u32 val32;
1255 u16 val16;
1256
1257 len = min(count, sizeof(buf) - 1);
1258 if (copy_from_user(buf, user_buf, len))
1259 return -EFAULT;
1260 buf[len] = '\0';
1261 sptr = buf;
1262
1263 token = strsep(&sptr, " ");
1264 if (!token)
1265 return -EINVAL;
1266 if (kstrtou8(token, 0, &pstream.user_pri))
1267 return -EINVAL;
1268
1269 token = strsep(&sptr, " ");
1270 if (!token)
1271 return -EINVAL;
1272 if (kstrtou8(token, 0, &pstream.traffic_direc))
1273 return -EINVAL;
1274
1275 token = strsep(&sptr, " ");
1276 if (!token)
1277 return -EINVAL;
1278 if (kstrtou8(token, 0, &pstream.traffic_class))
1279 return -EINVAL;
1280
1281 token = strsep(&sptr, " ");
1282 if (!token)
1283 return -EINVAL;
1284 if (kstrtou8(token, 0, &pstream.traffic_type))
1285 return -EINVAL;
1286
1287 token = strsep(&sptr, " ");
1288 if (!token)
1289 return -EINVAL;
1290 if (kstrtou8(token, 0, &pstream.voice_psc_cap))
1291 return -EINVAL;
1292
1293 token = strsep(&sptr, " ");
1294 if (!token)
1295 return -EINVAL;
1296 if (kstrtou32(token, 0, &val32))
1297 return -EINVAL;
1298 pstream.min_service_int = cpu_to_le32(val32);
1299
1300 token = strsep(&sptr, " ");
1301 if (!token)
1302 return -EINVAL;
1303 if (kstrtou32(token, 0, &val32))
1304 return -EINVAL;
1305 pstream.max_service_int = cpu_to_le32(val32);
1306
1307 token = strsep(&sptr, " ");
1308 if (!token)
1309 return -EINVAL;
1310 if (kstrtou32(token, 0, &val32))
1311 return -EINVAL;
1312 pstream.inactivity_int = cpu_to_le32(val32);
1313
1314 token = strsep(&sptr, " ");
1315 if (!token)
1316 return -EINVAL;
1317 if (kstrtou32(token, 0, &val32))
1318 return -EINVAL;
1319 pstream.suspension_int = cpu_to_le32(val32);
1320
1321 token = strsep(&sptr, " ");
1322 if (!token)
1323 return -EINVAL;
1324 if (kstrtou32(token, 0, &val32))
1325 return -EINVAL;
1326 pstream.service_start_time = cpu_to_le32(val32);
1327
1328 token = strsep(&sptr, " ");
1329 if (!token)
1330 return -EINVAL;
1331 if (kstrtou8(token, 0, &pstream.tsid))
1332 return -EINVAL;
1333
1334 token = strsep(&sptr, " ");
1335 if (!token)
1336 return -EINVAL;
1337 if (kstrtou16(token, 0, &val16))
1338 return -EINVAL;
1339 pstream.nominal_msdu = cpu_to_le16(val16);
1340
1341 token = strsep(&sptr, " ");
1342 if (!token)
1343 return -EINVAL;
1344 if (kstrtou16(token, 0, &val16))
1345 return -EINVAL;
1346 pstream.max_msdu = cpu_to_le16(val16);
1347
1348 token = strsep(&sptr, " ");
1349 if (!token)
1350 return -EINVAL;
1351 if (kstrtou32(token, 0, &val32))
1352 return -EINVAL;
1353 pstream.min_data_rate = cpu_to_le32(val32);
1354
1355 token = strsep(&sptr, " ");
1356 if (!token)
1357 return -EINVAL;
1358 if (kstrtou32(token, 0, &val32))
1359 return -EINVAL;
1360 pstream.mean_data_rate = cpu_to_le32(val32);
1361
1362 token = strsep(&sptr, " ");
1363 if (!token)
1364 return -EINVAL;
1365 if (kstrtou32(token, 0, &val32))
1366 return -EINVAL;
1367 pstream.peak_data_rate = cpu_to_le32(val32);
1368
1369 token = strsep(&sptr, " ");
1370 if (!token)
1371 return -EINVAL;
1372 if (kstrtou32(token, 0, &val32))
1373 return -EINVAL;
1374 pstream.max_burst_size = cpu_to_le32(val32);
1375
1376 token = strsep(&sptr, " ");
1377 if (!token)
1378 return -EINVAL;
1379 if (kstrtou32(token, 0, &val32))
1380 return -EINVAL;
1381 pstream.delay_bound = cpu_to_le32(val32);
1382
1383 token = strsep(&sptr, " ");
1384 if (!token)
1385 return -EINVAL;
1386 if (kstrtou32(token, 0, &val32))
1387 return -EINVAL;
1388 pstream.min_phy_rate = cpu_to_le32(val32);
1389
1390 token = strsep(&sptr, " ");
1391 if (!token)
1392 return -EINVAL;
1393 if (kstrtou32(token, 0, &val32))
1394 return -EINVAL;
1395 pstream.sba = cpu_to_le32(val32);
1396
1397 token = strsep(&sptr, " ");
1398 if (!token)
1399 return -EINVAL;
1400 if (kstrtou32(token, 0, &val32))
1401 return -EINVAL;
1402 pstream.medium_time = cpu_to_le32(val32);
1403
1404 ath6kl_wmi_create_pstream_cmd(ar->wmi, &pstream);
1405
1406 return count;
1407}
1408
1409static const struct file_operations fops_create_qos = {
1410 .write = ath6kl_create_qos_write,
1411 .open = ath6kl_debugfs_open,
1412 .owner = THIS_MODULE,
1413 .llseek = default_llseek,
1414};
1415
1416static ssize_t ath6kl_delete_qos_write(struct file *file,
1417 const char __user *user_buf,
1418 size_t count, loff_t *ppos)
1419{
1420
1421 struct ath6kl *ar = file->private_data;
1422 char buf[100];
1423 ssize_t len;
1424 char *sptr, *token;
1425 u8 traffic_class;
1426 u8 tsid;
1427
1428 len = min(count, sizeof(buf) - 1);
1429 if (copy_from_user(buf, user_buf, len))
1430 return -EFAULT;
1431 buf[len] = '\0';
1432 sptr = buf;
1433
1434 token = strsep(&sptr, " ");
1435 if (!token)
1436 return -EINVAL;
1437 if (kstrtou8(token, 0, &traffic_class))
1438 return -EINVAL;
1439
1440 token = strsep(&sptr, " ");
1441 if (!token)
1442 return -EINVAL;
1443 if (kstrtou8(token, 0, &tsid))
1444 return -EINVAL;
1445
1446 ath6kl_wmi_delete_pstream_cmd(ar->wmi, traffic_class, tsid);
1447
1448 return count;
1449}
1450
1451static const struct file_operations fops_delete_qos = {
1452 .write = ath6kl_delete_qos_write,
1453 .open = ath6kl_debugfs_open,
1454 .owner = THIS_MODULE,
1455 .llseek = default_llseek,
1456};
1457
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001458static ssize_t ath6kl_bgscan_int_write(struct file *file,
1459 const char __user *user_buf,
1460 size_t count, loff_t *ppos)
1461{
1462 struct ath6kl *ar = file->private_data;
1463 u16 bgscan_int;
1464 char buf[32];
1465 ssize_t len;
1466
1467 len = min(count, sizeof(buf) - 1);
1468 if (copy_from_user(buf, user_buf, len))
1469 return -EFAULT;
1470
1471 buf[len] = '\0';
1472 if (kstrtou16(buf, 0, &bgscan_int))
1473 return -EINVAL;
1474
1475 if (bgscan_int == 0)
1476 bgscan_int = 0xffff;
1477
1478 ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, bgscan_int, 0, 0, 0, 3,
1479 0, 0, 0);
1480
1481 return count;
1482}
1483
1484static const struct file_operations fops_bgscan_int = {
1485 .write = ath6kl_bgscan_int_write,
1486 .open = ath6kl_debugfs_open,
1487 .owner = THIS_MODULE,
1488 .llseek = default_llseek,
1489};
1490
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301491int ath6kl_debug_init(struct ath6kl *ar)
1492{
Kalle Valobdf53962011-09-02 10:32:04 +03001493 ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
1494 if (ar->debug.fwlog_buf.buf == NULL)
1495 return -ENOMEM;
1496
1497 ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
1498 if (ar->debug.fwlog_tmp == NULL) {
1499 vfree(ar->debug.fwlog_buf.buf);
1500 return -ENOMEM;
1501 }
1502
1503 spin_lock_init(&ar->debug.fwlog_lock);
1504
Kalle Valo939f1cc2011-09-02 10:32:04 +03001505 /*
1506 * Actually we are lying here but don't know how to read the mask
1507 * value from the firmware.
1508 */
1509 ar->debug.fwlog_mask = 0;
1510
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301511 ar->debugfs_phy = debugfs_create_dir("ath6kl",
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301512 ar->wiphy->debugfsdir);
Kalle Valobdf53962011-09-02 10:32:04 +03001513 if (!ar->debugfs_phy) {
1514 vfree(ar->debug.fwlog_buf.buf);
1515 kfree(ar->debug.fwlog_tmp);
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301516 return -ENOMEM;
Kalle Valobdf53962011-09-02 10:32:04 +03001517 }
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301518
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +05301519 debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
1520 &fops_tgt_stats);
1521
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +05301522 debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
1523 &fops_credit_dist_stats);
1524
Jouni Malinene8091282011-10-11 17:31:53 +03001525 debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
1526 ar->debugfs_phy, ar, &fops_endpoint_stats);
1527
Kalle Valobdf53962011-09-02 10:32:04 +03001528 debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
1529 &fops_fwlog);
1530
Kalle Valo939f1cc2011-09-02 10:32:04 +03001531 debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
1532 ar, &fops_fwlog_mask);
1533
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +03001534 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1535 &fops_diag_reg_read);
1536
1537 debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
1538 &fops_reg_dump);
1539
Vivek Natarajane5090442011-08-31 15:02:19 +05301540 debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
1541 ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
Vasanthakumar Thiagarajan252c0682011-09-05 11:19:46 +03001542
1543 debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
1544 ar->debugfs_phy, ar, &fops_diag_reg_write);
1545
Kalle Valo9a730832011-09-27 23:33:28 +03001546 debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
1547 &fops_war_stats);
1548
Jouni Malinen4b28a802011-10-11 17:31:54 +03001549 debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
1550 &fops_roam_table);
1551
Jouni Malinen12618752011-10-11 17:31:55 +03001552 debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
1553 &fops_force_roam);
1554
1555 debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
1556 &fops_roam_mode);
1557
Jouni Malinenff0b0072011-10-11 17:31:56 +03001558 debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1559 &fops_keepalive);
1560
1561 debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
1562 ar->debugfs_phy, ar, &fops_disconnect_timeout);
1563
Rishi Panjwani8fffd9e2011-10-14 17:48:07 -07001564 debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
1565 &fops_create_qos);
1566
1567 debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
1568 &fops_delete_qos);
1569
Rishi Panjwani116b3a22011-10-18 17:20:06 -07001570 debugfs_create_file("bgscan_interval", S_IWUSR,
1571 ar->debugfs_phy, ar, &fops_bgscan_int);
1572
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +05301573 return 0;
1574}
Kalle Valobdf53962011-09-02 10:32:04 +03001575
1576void ath6kl_debug_cleanup(struct ath6kl *ar)
1577{
1578 vfree(ar->debug.fwlog_buf.buf);
1579 kfree(ar->debug.fwlog_tmp);
Jouni Malinen4b28a802011-10-11 17:31:54 +03001580 kfree(ar->debug.roam_tbl);
Kalle Valobdf53962011-09-02 10:32:04 +03001581}
1582
Kalle Valobdcd8172011-07-18 00:22:30 +03001583#endif